Skip to content

Commit ae4cd66

Browse files
committed
Improve Ed448 logic in WebAuthnCodecs
1 parent f04c0a5 commit ae4cd66

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

webauthn-server-core/src/main/java/com/yubico/webauthn/WebAuthnCodecs.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ final class WebAuthnCodecs {
7474
112
7575
});
7676

77+
private static final ByteArray ED448_ALG_ID =
78+
new ByteArray(
79+
new byte[] {
80+
// SEQUENCE (5 bytes)
81+
0x30,
82+
5,
83+
// OID (3 bytes)
84+
0x06,
85+
3,
86+
// OID 1.3.101.113
87+
0x2B,
88+
101,
89+
113
90+
});
91+
7792
static ByteArray ecPublicKeyToRaw(ECPublicKey key) {
7893

7994
final int fieldSizeBytes =
@@ -218,6 +233,8 @@ private static PublicKey importCoseEdDsaPublicKey(CBORObject cose)
218233
switch (curveId) {
219234
case 6:
220235
return importCoseEd25519PublicKey(cose);
236+
case 7:
237+
return importCoseEd448PublicKey(cose);
221238
default:
222239
throw new IllegalArgumentException("Unsupported EdDSA curve: " + curveId);
223240
}
@@ -234,6 +251,17 @@ private static PublicKey importCoseEd25519PublicKey(CBORObject cose)
234251
return kFact.generatePublic(new X509EncodedKeySpec(x509Key));
235252
}
236253

254+
private static PublicKey importCoseEd448PublicKey(CBORObject cose)
255+
throws InvalidKeySpecException, NoSuchAlgorithmException {
256+
final byte[] rawKey = cose.get(CBORObject.FromObject(-2)).GetByteString();
257+
final byte[] x509Key =
258+
BinaryUtil.encodeDerSequence(
259+
ED448_ALG_ID.getBytes(), BinaryUtil.encodeDerBitStringWithZeroUnused(rawKey));
260+
261+
KeyFactory kFact = KeyFactory.getInstance("EdDSA");
262+
return kFact.generatePublic(new X509EncodedKeySpec(x509Key));
263+
}
264+
237265
static String getJavaAlgorithmName(COSEAlgorithmIdentifier alg) {
238266
switch (alg) {
239267
case EdDSA:

webauthn-server-core/src/main/java/com/yubico/webauthn/data/PublicKeyCredentialCreationOptions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ private static List<PublicKeyCredentialParameters> filterAvailableAlgorithms(
521521
param -> {
522522
try {
523523
switch (param.getAlg()) {
524+
case Ed448:
524525
case EdDSA:
525526
KeyFactory.getInstance("EdDSA");
526527
break;

0 commit comments

Comments
 (0)