Skip to content

Commit 093f877

Browse files
committed
Change getAlgorithm value for EdDsa keys
1 parent 5179440 commit 093f877

File tree

5 files changed

+24
-5
lines changed

5 files changed

+24
-5
lines changed

common/src/main/java/org/conscrypt/OpenSslEdDsaKeyFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ protected <T extends KeySpec> T engineGetKeySpec(Key key, Class<T> keySpec)
6565
if (keySpec == null) {
6666
throw new InvalidKeySpecException("keySpec == null");
6767
}
68-
if (!key.getAlgorithm().equals("EdDSA") && !key.getAlgorithm().equals("Ed25519")) {
68+
if (!key.getAlgorithm().equals("EdDSA") && !key.getAlgorithm().equals("Ed25519")
69+
&& !key.getAlgorithm().equals("1.3.101.112")) {
6970
throw new InvalidKeySpecException("Key must be an EdDSA or Ed25519 key");
7071
}
7172
if (key.getEncoded() == null) {

common/src/main/java/org/conscrypt/OpenSslEdDsaPrivateKey.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ public OpenSslEdDsaPrivateKey(byte[] raw) {
6565
}
6666
}
6767

68+
// This intentionally diverges from the OpenJDK implementation and JEP 339 (which return
69+
// "EdDSA") to achieve backwards compatibility with the "AndroidKeyStore" provider, which
70+
// supported generation of Ed25519 keys before Conscrypt did. Conscrypt's `getSigAlgName()`
71+
// method returns the OID if there is no mapping to an algorithm name and the "AndroidKeyStore"
72+
// provider therefore expects the OID as the algorithm name, even if Conscrypt now supports
73+
// Ed25519 key generation (which otherwise aligns with JEP 339).
6874
@Override
6975
public String getAlgorithm() {
70-
return "EdDSA";
76+
return "1.3.101.112";
7177
}
7278

7379
@Override

common/src/main/java/org/conscrypt/OpenSslEdDsaPublicKey.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ public OpenSslEdDsaPublicKey(byte[] coordinateBytes) {
6565
}
6666
}
6767

68+
// This intentionally diverges from the OpenJDK implementation and JEP 339 (which return
69+
// "EdDSA") to achieve backwards compatibility with the "AndroidKeyStore" provider, which
70+
// supported generation of Ed25519 keys before Conscrypt did. Conscrypt's `getSigAlgName()`
71+
// method returns the OID if there is no mapping to an algorithm name and the "AndroidKeyStore"
72+
// provider therefore expects the OID as the algorithm name, even if Conscrypt now supports
73+
// Ed25519 key generation (which otherwise aligns with JEP 339).
6874
@Override
6975
public String getAlgorithm() {
70-
return "EdDSA";
76+
return "1.3.101.112";
7177
}
7278

7379
@Override

common/src/test/java/org/conscrypt/EdDsaTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public void convertPrivateKeyToAndFromKeySpec_works() throws Exception {
236236
decodeHex("9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60");
237237
KeyFactory keyFactory = KeyFactory.getInstance("Ed25519", conscryptProvider);
238238
PrivateKey privateKey = keyFactory.generatePrivate(new RawKeySpec(rawPrivateKey));
239-
assertEquals("EdDSA", privateKey.getAlgorithm());
239+
assertEquals("1.3.101.112", privateKey.getAlgorithm());
240240

241241
// RawKeySpec returns the raw private key.
242242
RawKeySpec rawPrivateKeySpec = keyFactory.getKeySpec(privateKey, RawKeySpec.class);
@@ -269,7 +269,7 @@ public void convertPublicKeyToFromRawKeySpec_works() throws Exception {
269269
decodeHex("d75a980182b10ab7d54bfed3c964073a0ee172f3daa62325af021a68f707511a");
270270
KeyFactory keyFactory = KeyFactory.getInstance("Ed25519", conscryptProvider);
271271
PublicKey publicKey = keyFactory.generatePublic(new RawKeySpec(rawPublicKey));
272-
assertEquals("EdDSA", publicKey.getAlgorithm());
272+
assertEquals("1.3.101.112", publicKey.getAlgorithm());
273273

274274
// RawKeySpec returns the raw public key.
275275
RawKeySpec rawPublicKeySpec = keyFactory.getKeySpec(publicKey, RawKeySpec.class);

common/src/test/java/org/conscrypt/java/security/KeyPairGeneratorTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ private void test_Key(KeyPairGenerator kpg, Key k) throws Exception {
244244
// have algorithm "ML-DSA".
245245
expectedAlgorithm = "ML-DSA";
246246
}
247+
if (expectedAlgorithm.startsWith("EDDSA")) {
248+
// This intentionally diverges from the OpenJDK implementation and JEP 339 (which return
249+
// "EdDSA") to achieve backwards compatibility with the "AndroidKeyStore" provider,
250+
// which supported generation of Ed25519 keys before Conscrypt did.
251+
expectedAlgorithm = "1.3.101.112";
252+
}
247253
assertEquals(expectedAlgorithm, k.getAlgorithm().toUpperCase(Locale.ROOT));
248254
if (expectedAlgorithm.equals("DH")) {
249255
if (k instanceof DHPublicKey) {

0 commit comments

Comments
 (0)