|
31 | 31 | import com.yubico.webauthn.data.ByteArray;
|
32 | 32 | import com.yubico.webauthn.data.COSEAlgorithmIdentifier;
|
33 | 33 | import java.io.IOException;
|
34 |
| -import java.math.BigInteger; |
35 | 34 | import java.security.KeyFactory;
|
36 | 35 | import java.security.NoSuchAlgorithmException;
|
37 | 36 | import java.security.PublicKey;
|
38 | 37 | import java.security.interfaces.ECPublicKey;
|
39 | 38 | import java.security.spec.InvalidKeySpecException;
|
40 |
| -import java.security.spec.RSAPublicKeySpec; |
41 | 39 | import java.security.spec.X509EncodedKeySpec;
|
42 | 40 | import java.util.Arrays;
|
43 | 41 | import java.util.HashMap;
|
@@ -125,29 +123,17 @@ static PublicKey importCosePublicKey(ByteArray key)
|
125 | 123 | final int kty = cose.get(CBORObject.FromObject(1)).AsInt32();
|
126 | 124 | switch (kty) {
|
127 | 125 | case 1:
|
| 126 | + // COSE-JAVA is hardcoded to ed25519-java provider ("EdDSA") which would require an |
| 127 | + // additional dependency to parse EdDSA keys via the OneKey constructor |
128 | 128 | return importCoseEdDsaPublicKey(cose);
|
129 |
| - case 2: |
130 |
| - return importCoseP256PublicKey(cose); |
| 129 | + case 2: // Fall through |
131 | 130 | case 3:
|
132 |
| - return importCoseRsaPublicKey(cose); |
| 131 | + return new OneKey(cose).AsPublicKey(); |
133 | 132 | default:
|
134 | 133 | throw new IllegalArgumentException("Unsupported key type: " + kty);
|
135 | 134 | }
|
136 | 135 | }
|
137 | 136 |
|
138 |
| - private static PublicKey importCoseRsaPublicKey(CBORObject cose) |
139 |
| - throws NoSuchAlgorithmException, InvalidKeySpecException { |
140 |
| - RSAPublicKeySpec spec = |
141 |
| - new RSAPublicKeySpec( |
142 |
| - new BigInteger(1, cose.get(CBORObject.FromObject(-1)).GetByteString()), |
143 |
| - new BigInteger(1, cose.get(CBORObject.FromObject(-2)).GetByteString())); |
144 |
| - return KeyFactory.getInstance("RSA").generatePublic(spec); |
145 |
| - } |
146 |
| - |
147 |
| - private static ECPublicKey importCoseP256PublicKey(CBORObject cose) throws CoseException { |
148 |
| - return (ECPublicKey) new OneKey(cose).AsPublicKey(); |
149 |
| - } |
150 |
| - |
151 | 137 | private static PublicKey importCoseEdDsaPublicKey(CBORObject cose)
|
152 | 138 | throws InvalidKeySpecException, NoSuchAlgorithmException {
|
153 | 139 | final int curveId = cose.get(CBORObject.FromObject(-1)).AsInt32();
|
|
0 commit comments