From 884dc5883eee4ce60ac909337f0c0cd1e44b4d0b Mon Sep 17 00:00:00 2001 From: JinhangZhang Date: Wed, 27 Mar 2024 13:15:22 -0400 Subject: [PATCH] Implement the ECKeyPairGenerator initialize func Aim to solve openj9 issue 18320. DefaultSignatureAlgorithm test run in those Redhat OS based machines, FIPS version of openssl is used in those machines. So, a 192 size of EC key pair generator is not allowed by the native code in FIPS version of openssl , then a Java implementation is used. However, there are lacking of implementation of initialize function in ECKeyPairGenerator file. This PR implements the initialize function in ECKeyPairGenerator file. --- .../fakegen/DefaultSignatureAlgorithm.java | 3 ++- .../sun/security/ec/ECKeyPairGenerator.java | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/test/jdk/sun/security/tools/keytool/fakegen/DefaultSignatureAlgorithm.java b/test/jdk/sun/security/tools/keytool/fakegen/DefaultSignatureAlgorithm.java index 6f2d918093b..78929c3bc71 100644 --- a/test/jdk/sun/security/tools/keytool/fakegen/DefaultSignatureAlgorithm.java +++ b/test/jdk/sun/security/tools/keytool/fakegen/DefaultSignatureAlgorithm.java @@ -74,8 +74,9 @@ private static void check(String keyAlg, int keySize, String sigAlgParam = requestedSigAlg == null ? "" : (" -sigalg " + requestedSigAlg); + System.out.println("starting..."); genkeypair(alias, - "-keyalg " + keyAlg + " -keysize " + keySize + sigAlgParam) + "-keyalg " + keyAlg + " -keysize " + keySize + sigAlgParam + " -debug -J-Djdk.nativeCryptoTrace=true") .shouldHaveExitValue(0); KeyStore ks = KeyStore.getInstance( diff --git a/test/jdk/sun/security/tools/keytool/fakegen/jdk.crypto.ec/sun/security/ec/ECKeyPairGenerator.java b/test/jdk/sun/security/tools/keytool/fakegen/jdk.crypto.ec/sun/security/ec/ECKeyPairGenerator.java index 68da125087f..40263f26c85 100644 --- a/test/jdk/sun/security/tools/keytool/fakegen/jdk.crypto.ec/sun/security/ec/ECKeyPairGenerator.java +++ b/test/jdk/sun/security/tools/keytool/fakegen/jdk.crypto.ec/sun/security/ec/ECKeyPairGenerator.java @@ -27,6 +27,7 @@ import java.security.*; import java.security.spec.AlgorithmParameterSpec; import java.security.spec.ECParameterSpec; +import java.security.spec.ECGenParameterSpec; import java.security.spec.ECPoint; import sun.security.util.ECUtil; @@ -51,7 +52,28 @@ public void initialize(int keySize, SecureRandom random) { @Override public void initialize(AlgorithmParameterSpec params, SecureRandom random) throws InvalidAlgorithmParameterException { - throw new UnsupportedOperationException(); + ECParameterSpec ecSpec = null; + + if (params instanceof ECParameterSpec) { + ECParameterSpec ecParams = (ECParameterSpec) params; + ecSpec = ECUtil.getECParameterSpec(null, ecParams); + if (ecSpec == null) { + throw new InvalidAlgorithmParameterException( + "Unsupported curve: " + params); + } + } else if (params instanceof ECGenParameterSpec) { + String name = ((ECGenParameterSpec) params).getName(); + ecSpec = ECUtil.getECParameterSpec(null, name); + if (ecSpec == null) { + throw new InvalidAlgorithmParameterException( + "Unknown curve name: " + name); + } + } else { + throw new InvalidAlgorithmParameterException( + "ECParameterSpec or ECGenParameterSpec required for EC"); + } + + this.keySize = ecSpec.getCurve().getField().getFieldSize(); } @Override