Skip to content

Commit

Permalink
Address test failures on Java 11. (#1189)
Browse files Browse the repository at this point in the history
xecPrivateKeySpec failure was a copy pasta bug but only
shows up on 11 due to missing XEC classes on earlier Java.

The other failure in keyspec_Fail(), looks like it
was due to the KeyFactory implementation iterating over
SPIs on failure, and in OpenJDK 11 there is an XDH
KeyFactory, although I'm unsure why it was rejecting
what should be valid PKCS#8 data...
  • Loading branch information
prbprbprb authored Dec 15, 2023
1 parent 79b06e5 commit 2c06a25
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public class XdhKeyFactoryTest {
decodeBase64("MCowBQYDK2VuAyEAeNH3ZKS7SCZT495bvIvoyYB9PNIFefUSTfi6eNhFYXA=");
private final byte[] privateKeyPkcs8Bytes =
decodeBase64("MC4CAQAwBQYDK2VuBCIEIADBSHEZer+X0ZdqReHuMDx61nQwWwNHOnx9HHRNJBJK");
private final KeyFactory factory = KeyFactory.getInstance("XDH");
private final KeyFactory factory =
KeyFactory.getInstance("XDH", TestUtils.getConscryptProvider());
private final PublicKey publicKey =
factory.generatePublic(new X509EncodedKeySpec(publicKeyX509Bytes));
private final PrivateKey privateKey =
Expand Down Expand Up @@ -143,8 +144,6 @@ public void privateKeySpec_Success() throws Exception {
public void keySpec_Fail() throws Exception {
assertThrows(InvalidKeySpecException.class,
() -> factory.getKeySpec(publicKey, PKCS8EncodedKeySpec.class));
PrivateKey privateKey = factory.generatePrivate(
new PKCS8EncodedKeySpec(privateKeyPkcs8Bytes));
assertThrows(InvalidKeySpecException.class,
() -> factory.getKeySpec(privateKey, X509EncodedKeySpec.class));

Expand Down Expand Up @@ -187,7 +186,7 @@ public void xecPrivateKeySpec() throws Exception {
@SuppressWarnings("unchecked")
Class<? extends KeySpec> javaClass = (Class<? extends KeySpec>)
TestUtils.findClass("java.security.spec.XECPrivateKeySpec");
PrivateKey key = factory.generatePrivate(new X509EncodedKeySpec(privateKeyPkcs8Bytes));
PrivateKey key = factory.generatePrivate(new PKCS8EncodedKeySpec(privateKeyPkcs8Bytes));
KeySpec spec = factory.getKeySpec(key, javaClass);
assertNotNull(spec);
}
Expand Down

0 comments on commit 2c06a25

Please sign in to comment.