Skip to content

Commit 0b12b1c

Browse files
p1gp1gmar-v-in
authored andcommitted
Fix COSE decoding with x-only keys
1 parent eb173c1 commit 0b12b1c

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

  • play-services-fido/core/src/main/kotlin/org/microg/gms/fido/core/protocol

play-services-fido/core/src/main/kotlin/org/microg/gms/fido/core/protocol/CoseKey.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import java.security.spec.ECPublicKeySpec
2222
class CoseKey(
2323
val algorithm: Algorithm,
2424
val x: ByteArray,
25-
val y: ByteArray,
25+
val y: ByteArray?,
2626
val curveId: Int
2727
) {
2828
constructor(algorithm: Algorithm, x: BigInteger, y: BigInteger, curveId: Int, curvePointSize: Int) :
@@ -35,7 +35,9 @@ class CoseKey(
3535
set(ALG, algorithm.algoValue.encodeAsCbor())
3636
set(CRV, curveId.encodeAsCbor())
3737
set(X, x.encodeAsCbor())
38-
set(Y, y.encodeAsCbor())
38+
y?.let {
39+
set(Y, y.encodeAsCbor())
40+
}
3941
}
4042

4143
fun asCryptoKey(): PublicKey? {
@@ -74,7 +76,7 @@ class CoseKey(
7476
fun decodeFromCbor(obj: CBORObject): CoseKey = CoseKey(
7577
getAlgorithm(obj.get(CoseKey.ALG).AsInt32Value()),
7678
obj.get(CoseKey.X).GetByteString(),
77-
obj.get(CoseKey.Y).GetByteString(),
79+
runCatching { obj.get(CoseKey.Y).GetByteString() }.getOrNull(),
7880
obj.get(CoseKey.CRV).AsInt32Value()
7981
)
8082

0 commit comments

Comments
 (0)