Skip to content

Commit

Permalink
Updated OpenSSLProvider to use Alg.Alias for X25519
Browse files Browse the repository at this point in the history
  • Loading branch information
exceptionfactory committed Aug 15, 2023
1 parent 9ec5c8e commit 1c6e83e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 66 deletions.
10 changes: 3 additions & 7 deletions common/src/main/java/org/conscrypt/OpenSSLProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ public OpenSSLProvider(String providerName) {
put("Alg.Alias.KeyPairGenerator.1.2.840.10045.2.1", "EC");
put("Alg.Alias.KeyPairGenerator.1.3.133.16.840.63.0.2", "EC");

put("KeyPairGenerator.X25519", PREFIX + "OpenSSLXDHKeyPairGenerator");
put("KeyPairGenerator.XDH", PREFIX + "OpenSSLXDHKeyPairGenerator");
put("Alg.Alias.KeyPairGenerator.1.3.101.110", "XDH");
put("Alg.Alias.KeyPairGenerator.X25519", "XDH");

/* == KeyFactory == */
put("KeyFactory.RSA", PREFIX + "OpenSSLRSAKeyFactory");
Expand All @@ -210,9 +210,9 @@ public OpenSSLProvider(String providerName) {
put("Alg.Alias.KeyFactory.1.2.840.10045.2.1", "EC");
put("Alg.Alias.KeyFactory.1.3.133.16.840.63.0.2", "EC");

put("KeyFactory.X25519", PREFIX + "OpenSSLXDHKeyFactory");
put("KeyFactory.XDH", PREFIX + "OpenSSLXDHKeyFactory");
put("Alg.Alias.KeyFactory.1.3.101.110", "XDH");
put("Alg.Alias.KeyFactory.X25519", "XDH");

/* == SecretKeyFactory == */
put("SecretKeyFactory.DESEDE", PREFIX + "DESEDESecretKeyFactory");
Expand Down Expand Up @@ -627,11 +627,7 @@ private void putXDHKeyAgreementImplClass(String className) {
supportedKeyClasses,
supportedKeyFormats);

putImplClassWithKeyConstraints(
"KeyAgreement.X25519",
PREFIX + className,
supportedKeyClasses,
supportedKeyFormats);
put("Alg.Alias.KeyAgreement.X25519", "XDH");
}

private void putImplClassWithKeyConstraints(String typeAndAlgName,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,12 @@ public class KeyFactoryTestXDH extends
AbstractKeyFactoryTest<X509EncodedKeySpec, PKCS8EncodedKeySpec> {

public KeyFactoryTestXDH() {
this("XDH");
}

public KeyFactoryTestXDH(final String algorithmName) {
super(algorithmName, X509EncodedKeySpec.class, PKCS8EncodedKeySpec.class);
super("XDH", X509EncodedKeySpec.class, PKCS8EncodedKeySpec.class);
}

@Override
protected void check(KeyPair keyPair) throws Exception {
new KeyAgreementHelper(algorithmName).test(keyPair);
new KeyAgreementHelper("XDH").test(keyPair);
}

@Override
Expand All @@ -53,12 +49,12 @@ protected ServiceTester customizeTester(ServiceTester tester) {
protected List<KeyPair> getKeys() throws NoSuchAlgorithmException, InvalidKeySpecException {
return Arrays.asList(
new KeyPair(
DefaultKeys.getPublicKey(algorithmName),
DefaultKeys.getPrivateKey(algorithmName)
DefaultKeys.getPublicKey("XDH"),
DefaultKeys.getPrivateKey("XDH")
),
new KeyPair(
new TestPublicKey(DefaultKeys.getPublicKey(algorithmName)),
new TestPrivateKey(DefaultKeys.getPrivateKey(algorithmName))
new TestPublicKey(DefaultKeys.getPublicKey("XDH")),
new TestPrivateKey(DefaultKeys.getPrivateKey("XDH"))
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public void test(Provider provider, String algorithm) throws Exception {
}
// KeyPairGenerator.getInstance(String)
KeyPairGenerator kpg1 = KeyPairGenerator.getInstance(algorithm);
assertAlgorithmMatched(algorithm, kpg1);
assertEquals(algorithm, kpg1.getAlgorithm());
if (params != null) {
kpg1.initialize(params);
}
test_KeyPairGenerator(kpg1);

// KeyPairGenerator.getInstance(String, Provider)
KeyPairGenerator kpg2 = KeyPairGenerator.getInstance(algorithm, provider);
assertAlgorithmMatched(algorithm, kpg2);
assertEquals(algorithm, kpg2.getAlgorithm());
assertEquals(provider, kpg2.getProvider());
if (params != null) {
kpg2.initialize(params);
Expand All @@ -107,7 +107,7 @@ public void test(Provider provider, String algorithm) throws Exception {
// KeyPairGenerator.getInstance(String, String)
KeyPairGenerator kpg3 = KeyPairGenerator.getInstance(algorithm,
provider.getName());
assertAlgorithmMatched(algorithm, kpg3);
assertEquals(algorithm, kpg3.getAlgorithm());
assertEquals(provider, kpg3.getProvider());
if (params != null) {
kpg3.initialize(params);
Expand Down Expand Up @@ -361,17 +361,6 @@ private static void assertECParametersEquals(ECParameterSpec expected, ECParamet
assertEquals(expected.getCofactor(), actual.getCofactor());
}

private static void assertAlgorithmMatched(final String algorithm, final KeyPairGenerator keyPairGenerator) {
final String expectedAlgorithm;
// X25519 KeyPairGenerator is an alias for XDH requiring this alternative expected algorithm
if ("X25519".equals(algorithm)) {
expectedAlgorithm = "XDH";
} else {
expectedAlgorithm = algorithm;
}
assertEquals(expectedAlgorithm, keyPairGenerator.getAlgorithm());
}

/**
* DH parameters pre-generated so that the test doesn't take too long.
* These parameters were generated with:
Expand Down

0 comments on commit 1c6e83e

Please sign in to comment.