Slide 1

Slide 1 text

Kotlin NativeͰCryptoKit࢖͍ ͔ͨͬͨɾɾɾɾɾ 2022.11.27 Mobileษڧձ Wantedly × νʔϜϥϘ #7 Bunjiro Miyoshi

Slide 2

Slide 2 text

About Me • νʔϜϥϘॴଐ • (ࣗশ)ϚϧνϓϥοτϑΥʔϜܳਓ • Jetpack Compose࠷ߴʂʂ

Slide 3

Slide 3 text

࿩͢͜ͱɾ࿩͞ͳ͍͜ͱ • ࿩͢͜ͱ • CryptoKitͱ͸ • ͳͥCryptoKitΛ࢖͍͍͔ͨ • Kotlin NativeͷSwift/Obj-C Interop • ࿩͞ͳ͍͜ͱ • KMMͱ͸(͕࣌ؒ଍Γͳ͘ͳΔ) • androidଆʹدΓఴͬͨ಺༰(΄΅androidؔ܎ͳ͍࿩͔͠͠ͳ͍) • ඇରশ҉߸पΓ(K/NͰSecurity Framework࢖͑Δ)

Slide 4

Slide 4 text

CryptoKitͱ͸ • Appleެࣜͷ҉߸ԽϥΠϒϥϦ • iOS13͔Β࢖༻Ͱ͖Δ • LinuxͰ΋࢖͑ΔΑ͏ʹಛघͳϋʔυ΢ΣΞॲཧΛඞཁͱ͠ͳ͍APIΛ ൈ͖ग़ͨ͠OSS൛΋͋Δ • ݱࡏiOSͰAES΍Hash౳ͷ࣮૷Λ͍ͨ͠ͳΒ͜ΕΛ࢖͏ͷ͕σϑΝΫ τ

Slide 5

Slide 5 text

ͳͥCryptoKitΛ࢖͍͍͔ͨ#Tink • KMMͰ҉߸ԽॲཧΛԿͰ࣮૷͢Δ͔໎ͬͨ • Google/TinkΛinterop͢Δ༧ఆͩͬͨ • androidͷ҉߸Խॲཧ͸ݱࡏTinkҰ୒ͳঢ়ଶͩ͠ɾɾɾɾ • arm64ରԠʹۤ͠ΜͰ͍ΔΒ͘͠ରԠΛ଴͍ͬͯΒΕͳ͍ • → https://github.com/google/tink/issues/554

Slide 6

Slide 6 text

ͳͥCryptoKitΛ࢖͍͍͔ͨ#CommonCrypto • iOSʹ͸RuntimeʹCommonCrypto͕ಉࠝ͞Ε͍ͯΔ • → https://opensource.apple.com/source/CommonCrypto • CͰ࣮૷͞Ε͍ͯΔFramework • ରশ҉߸(AES-CBC, AES-ECB)ɺϋογϡؔ਺ɺμΠδΣετؔ਺ͳ Ͳ͕࢖༻Ͱ͖Δ

Slide 7

Slide 7 text

ͳͥCryptoKitΛ࢖͍͍͔ͨ#CommonCrypto

Slide 8

Slide 8 text

ͳͥCryptoKitΛ࢖͍͍͔ͨ • CryptoKit͡Όͳ͍ͱͰ͖ͳ͍͜ͱ • AEAD(AES-GCM)ͳͲͷೝূϞʔυ • ॺ໊पΓͷॲཧ • ٯʹCryptoKitͩͱͰ͖ͳ͍ॲཧ΋͋Δ • MD2ɺ4ͳͲͷڧ౓ͷ௿͍μΠδΣετ΍͋·Γ࢖༻͠ͳ͍΋ͷͳ ͷͰؾʹ͠ͳͯ͘Α͍

Slide 9

Slide 9 text

AES-GCM͕࢖͍͍ͨ • CommonCryptoʹ΋GCM࣮૷ͷϔομʔϑΝΠϧ͸͋Δɾɾɾɾ • https://opensource.apple.com/source/CommonCrypto/ CommonCrypto-60061/lib/CommonCryptorGCM.c.auto.html • ඇެ։APIʹͳ͍ͬͯͯK/NͰ࢖͑ͳ͍ɾɾɾɾɾ

Slide 10

Slide 10 text

Ͳ͏ͤϥούʔΛͭ͘ΔͳΒCryptoKitʹ͍ͨ͠ • ͖ͬͱJetBrainsͷK/NνʔϜ΋࢖͍͍ͨͱࢥͬͯͨΜ͡Όͳ͍͔ͳͱ अਪ • ͓΋ΉΖʹKotlinͷϦϙδτϦΛோΊͯΈΔ • K/N͕औΓࠐΉDarwinͷAPI͸👇ʹ͓͍ͯ͋Δ • https://github.com/JetBrains/kotlin/tree/master/kotlin-native/ platformLibs/src/platform/ios

Slide 11

Slide 11 text

Μɾɾɾɾɾʁ

Slide 12

Slide 12 text

Μɾɾɾɾɾʁ

Slide 13

Slide 13 text

͋ɺ͋Δʂʂʂ

Slide 14

Slide 14 text

Swift/Objective-C Interop • def.disabledͱ͍͏ෆԺͳϑΝΠϧ໊ʹͳ͍ͬͯΔ • obj-c͔Βݺͼग़ͤΔΑ͏ʹͳͬͯΔSwift Framework͸࢖͑Δ͕pure SwiftͷFramework͸K/NʹऔΓࠐΊͳ੍͍໿͕͋ΔͨΊdisable

Slide 15

Slide 15 text

Swift/Objective-C Interop • def.disabledͱ͍͏ෆԺͳϑΝΠϧ໊ʹͳ͍ͬͯΔ • obj-c͔Βݺͼग़ͤΔΑ͏ʹͳͬͯΔSwift Framework͸࢖͑Δ͕pure SwiftͷFramework͸K/NʹऔΓࠐΊͳ੍͍໿͕͋ΔͨΊdisable ཁ͢Δʹͦͷ··Ͱ͸࢖͑ͳ͍

Slide 16

Slide 16 text

Swift/Objective-C Interop • ࢖͏ʹ͸@objc͕෇༩͞Ε͍ͯΔϥούʔͷϥΠϒϥϦΛ࡞੒͠ɺͦ ΕΛK/NʹऔΓࠐΉඞཁ͕͋Δ • ಉ͜͡ͱΛߟ͍͑ͯΔਓ͸͍Δ • https://youtrack.jetbrains.com/issue/KT-54729/KMM-Native-iOS- use-CryptoKit

Slide 17

Slide 17 text

Ͳ͏͍͏ϥούʔϥΠϒϥϦ͕΄͍͔͠ • K/NϥΠϒϥϦͱͯ͠ެ։͞Ε͍ͯΔ • -> KMMʹ௥Ճ͢Δ͚ͩͰCryptoKit࢖͑ΔΑ͏ʹͳͬͯ΄͍͠ • ϥούʔϥΠϒϥϦ͸dynamic libraryͱͯ͠CryptoKitΛͱΓ͜ΜͰ΄͍͠ • -> όΠφϦຊମʹCryptoKitͷϏϧυੜ੒෺ΛؚΜͰ΄͘͠ͳ͍ • (౰ͨΓલ͕ͩ)CryptoKit͔ΒͷΤϥʔΛͪΌΜͱϋϯυϦϯάͰ͖ΔIFʹ ͳͬͯͯ΄͍͠

Slide 18

Slide 18 text

ϥούʔϥΠϒϥϦΛ࡞Δ • Swift Interopʹ͸error఻ൖपΓʹ᠘͕͋Δ • Swift/Objective-C error-throwing methods aren't imported to Kotlin as exception- throwing • https://kotlinlang.org/docs/native-objc-interop.html#errors-and-exceptions • Kotlin -> Obj-CɺObj-C -> Kotlinͷ྆ํʹ੍໿͕͋Δ • ࠓճͷϢʔεέʔεͩͱSwift -> Obj-C ->KotlinͷܗʹͳΔͨΊͦΕͧΕͷݴޠײͷนΛߟྀͯ͠ ࣮૷͢Δඞཁ͕͋Δ • iOSͷ։ൃݴޠͷσϑΝΫτ͕Obj-C͔ΒSwiftʹ੾ΓସΘͬͨλΠϛϯάͷࢿྉ͕໾ʹཱͪͦ͏

Slide 19

Slide 19 text

·ͱΊ • ࠓճ༻ҙͰ͖ͨ෦෼͸͜͜·Ͱ • ࢲࣗ਎͸ࠓճඞཁ෼ͷΈͷఆ͔ٛ͠ߦΘͣɺCryptoKitશମͷϥοϓʹ͸ͨͲΓண͔ͳ ͔ͬͨ(୭͔Ұॹʹ΍Γ·ͤΜ͔ɾɾɾ) • Swift InteropपΓʹ͸Τϥʔ఻ൖͷ᠘͕͋Δ • Swift/Kotlin௚ޓ׵ରԠͷissue͸͋Δ͕͕͔͔࣌ؒΓͦ͏ͳͷͰϥούʔϥΠϒϥϦΛ ࡞ΔҎ֎ʹݱঢ়͸खஈ͕ͳͦ͞͏ • https://youtrack.jetbrains.com/issue/KT-49521/Support-direct-interoperability-with- Swift

Slide 20

Slide 20 text

12݄10೔ͷKotlin Festొஃ͠·͢ ͓࣌ؒ͋Δ͔ͨͥͻ