Skip to content

Commit a43a888

Browse files
authored
js: Wrap Web Crypto and other JS Browser APIs (#1477)
This includes changing functions in `Crypto`, `Compression`, and elsewhere to be suspend which in turn slightly changes the shape of other APIs to also be suspend. We implemented just enough to get all unit tests to pass and doesn't include browser-specific implementations of `Storage` or `SecureArea`. As part of this, implement PEM parsing and generation entirely in KMP and remove internal platform-specific wrappers in `Crypto`. Also add unit tests for platform-specific implementation of `X509CertChain` signature checking. Since we can't easily change multipaz-android-legacy to be suspend, make copies of old non-suspend APIs from multipaz `Crypto`, `Hkdf`, and `SessionEncryption` APIs there. Code-duplication is not optimal but this library is going away fairly soon as the consuming downstream is in the process of switching away from it to mainline Multipaz libraries Test: All tests pass. Test: Manually tested testapp on both Android and iOS. Signed-off-by: David Zeuthen <zeuthen@google.com>
1 parent f6f7dd7 commit a43a888

151 files changed

Lines changed: 3284 additions & 1134 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎gradle/libs.versions.toml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ semver = "3.0.0"
4949
skie = "0.10.8"
5050
process-phoenix = "3.0.0"
5151
coil = "3.3.0"
52+
kotlin-wrappers-web = "2025.12.1"
5253

5354
[libraries]
5455
androidx-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview", version.ref = "uiToolingPreview" }
@@ -119,6 +120,7 @@ coil-core = { module = "io.coil-kt.coil3:coil-core", version.ref = "coil" }
119120
coil-compose-core = { module = "io.coil-kt.coil3:coil-compose-core", version.ref = "coil" }
120121
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
121122
coil-ktor3 = { module = "io.coil-kt.coil3:coil-network-ktor3", version.ref = "coil" }
123+
kotlin-wrappers-web = { module = "org.jetbrains.kotlin-wrappers:kotlin-web", version.ref="kotlin-wrappers-web" }
122124

123125
[plugins]
124126
androidApplication = { id = "com.android.application", version.ref = "agp" }

‎multipaz-android-legacy/src/androidTest/java/com/android/identity/android/document/AndroidKeystoreSecureAreaDocumentStoreTest.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ class AndroidKeystoreSecureAreaDocumentStoreTest {
135135
override val credentialType: String
136136
get() = CREDENTIAL_TYPE
137137

138-
override fun getClaims(documentTypeRepository: DocumentTypeRepository?): List<Claim> {
138+
override suspend fun getClaims(documentTypeRepository: DocumentTypeRepository?): List<Claim> {
139139
throw NotImplementedError()
140140
}
141141
}

‎multipaz-android-legacy/src/androidTest/java/com/android/identity/android/legacy/MigrateFromKeystoreICStoreTest.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.android.identity.android.legacy
1818
import androidx.test.platform.app.InstrumentationRegistry
1919
import co.nstant.`in`.cbor.CborBuilder
2020
import co.nstant.`in`.cbor.model.UnicodeString
21+
import com.android.identity.android.legacy.Crypto.checkSignature
2122
import com.android.identity.android.legacy.Util.cborEncode
2223
import com.android.identity.android.legacy.Util.cborEncodeBytestring
2324
import com.android.identity.android.legacy.Util.cborEncodeNumber
@@ -27,7 +28,6 @@ import org.multipaz.cbor.Cbor.toDiagnostics
2728
import org.multipaz.cbor.DiagnosticOption
2829
import org.multipaz.context.initializeApplication
2930
import org.multipaz.crypto.Algorithm
30-
import org.multipaz.crypto.Crypto.checkSignature
3131
import org.multipaz.crypto.EcCurve
3232
import org.multipaz.crypto.toEcPublicKey
3333
import org.multipaz.storage.android.AndroidStorage

‎multipaz-android-legacy/src/androidTest/java/com/android/identity/android/mdoc/deviceretrieval/DeviceRetrievalHelperTest.kt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ package com.android.identity.android.mdoc.deviceretrieval
1717

1818
import android.os.ConditionVariable
1919
import androidx.test.platform.app.InstrumentationRegistry
20+
import com.android.identity.android.legacy.Crypto.createEcPrivateKey
2021
import com.android.identity.android.mdoc.engagement.QrEngagementHelper
22+
import com.android.identity.android.mdoc.sessionencryption.SessionEncryption
2123
import com.android.identity.android.mdoc.transport.DataTransport
2224
import com.android.identity.android.mdoc.transport.DataTransportOptions
2325
import com.android.identity.android.mdoc.transport.DataTransportTcp
@@ -39,7 +41,6 @@ import org.multipaz.document.Document
3941
import org.multipaz.document.DocumentStore
4042
import org.multipaz.document.NameSpacedData
4143
import org.multipaz.crypto.Algorithm
42-
import org.multipaz.crypto.Crypto.createEcPrivateKey
4344
import org.multipaz.crypto.EcCurve
4445
import org.multipaz.crypto.EcPrivateKey
4546
import org.multipaz.crypto.EcPublicKey
@@ -57,7 +58,6 @@ import org.multipaz.mdoc.request.DeviceRequestParser.DocRequest
5758
import org.multipaz.mdoc.response.DeviceResponseGenerator
5859
import org.multipaz.mdoc.response.DeviceResponseParser
5960
import org.multipaz.mdoc.response.DocumentGenerator
60-
import org.multipaz.mdoc.sessionencryption.SessionEncryption
6161
import org.multipaz.mdoc.util.MdocUtil.calculateDigestsForNameSpace
6262
import org.multipaz.mdoc.util.MdocUtil.generateDocumentRequest
6363
import org.multipaz.mdoc.util.MdocUtil.generateIssuerNameSpaces

‎multipaz-android-legacy/src/androidTest/java/com/android/identity/android/mdoc/engagement/NfcEnagementHelperTest.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package com.android.identity.android.mdoc.engagement
1717

1818
import androidx.test.filters.SmallTest
1919
import androidx.test.platform.app.InstrumentationRegistry
20+
import com.android.identity.android.legacy.Crypto
2021
import com.android.identity.android.mdoc.transport.DataTransport
2122
import com.android.identity.android.mdoc.transport.DataTransportOptions
2223
import com.android.identity.android.util.NfcUtil
@@ -25,7 +26,6 @@ import org.multipaz.cbor.Cbor
2526
import org.multipaz.cbor.CborArray
2627
import org.multipaz.cbor.CborMap
2728
import org.multipaz.cbor.Simple
28-
import org.multipaz.crypto.Crypto
2929
import org.multipaz.crypto.EcCurve
3030
import org.multipaz.mdoc.connectionmethod.MdocConnectionMethod
3131
import org.multipaz.mdoc.connectionmethod.MdocConnectionMethodBle

0 commit comments

Comments
 (0)