Skip to content

Commit 1c82f82

Browse files
committed
fix(mobile): encode platform did keys as raw public keys
1 parent 27f58c4 commit 1c82f82

3 files changed

Lines changed: 13 additions & 2 deletions

File tree

waltid-libraries/crypto/waltid-crypto/src/androidDeviceTest/kotlin/id/walt/crypto/AndroidKeyTest.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,17 @@ class AndroidKeyTest {
4545
assertFailsWith<IllegalStateException>("public platform key should not sign for $type") {
4646
publicKey.signRaw("nope".encodeToByteArray())
4747
}
48+
49+
val publicKeyRepresentation = publicKey.getPublicKeyRepresentation()
50+
when (type) {
51+
KeyType.secp256r1 -> assertEquals(65, publicKeyRepresentation.size)
52+
KeyType.secp384r1 -> assertEquals(97, publicKeyRepresentation.size)
53+
KeyType.secp521r1 -> assertEquals(133, publicKeyRepresentation.size)
54+
else -> Unit
55+
}
56+
if (type != KeyType.RSA) {
57+
assertEquals(0x04, publicKeyRepresentation.first().toInt())
58+
}
4859
}
4960
}
5061

waltid-libraries/crypto/waltid-crypto/src/androidMain/kotlin/id/walt/crypto/AndroidKey.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ sealed class AndroidKey : Key() {
100100
}
101101

102102
override suspend fun getPublicKey(): Key = Platform(options, hasPrivateKey = false)
103-
override suspend fun getPublicKeyRepresentation(): ByteArray = signer().publicKey.encodeToTlv().derEncoded
103+
override suspend fun getPublicKeyRepresentation(): ByteArray = signer().publicKey.iosEncoded
104104
override suspend fun getMeta(): KeyMeta = JwkKeyMeta(getKeyId())
105105
override suspend fun deleteKey(): Boolean = runCatching {
106106
AndroidKeyStoreProvider.deleteSigningKey(options.kid).getOrThrow()

waltid-libraries/crypto/waltid-crypto/src/iosMain/kotlin/id/walt/crypto/IosKey.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ sealed class IosKey : Key() {
110110
}
111111

112112
override suspend fun getPublicKey(): Key = Platform(options, hasPrivateKey = false)
113-
override suspend fun getPublicKeyRepresentation(): ByteArray = signer().publicKey.encodeToTlv().derEncoded
113+
override suspend fun getPublicKeyRepresentation(): ByteArray = signer().publicKey.iosEncoded
114114
override suspend fun getMeta(): KeyMeta = JwkKeyMeta(getKeyId())
115115
override suspend fun deleteKey(): Boolean = runCatching {
116116
IosKeychainProvider.deleteSigningKey(options.kid).getOrThrow()

0 commit comments

Comments
 (0)