--- a/src/java.base/share/classes/sun/security/util/SignatureUtil.java Thu Jul 11 12:13:52 2019 -0700
+++ b/src/java.base/share/classes/sun/security/util/SignatureUtil.java Thu Jul 11 20:11:47 2019 +0000
@@ -28,6 +28,7 @@
import java.io.IOException;
import java.security.*;
import java.security.spec.*;
+import java.util.Locale;
import sun.security.rsa.RSAUtil;
import jdk.internal.access.SharedSecrets;
@@ -74,14 +75,9 @@
AlgorithmParameters params)
throws ProviderException {
- sigName = checkName(sigName);
+ sigName = checkName(sigName).toUpperCase(Locale.ENGLISH);
AlgorithmParameterSpec paramSpec = null;
if (params != null) {
- if (sigName.toUpperCase().indexOf("RSA") == -1) {
- throw new ProviderException
- ("Unrecognized algorithm for signature parameters " +
- sigName);
- }
// AlgorithmParameters.getAlgorithm() may returns oid if it's
// created during DER decoding. Convert to use the standard name
// before passing it to RSAUtil
@@ -93,7 +89,20 @@
throw new ProviderException(e);
}
}
- paramSpec = RSAUtil.getParamSpec(params);
+
+ if (sigName.indexOf("RSA") != -1) {
+ paramSpec = RSAUtil.getParamSpec(params);
+ } else if (sigName.indexOf("ECDSA") != -1) {
+ try {
+ paramSpec = params.getParameterSpec(ECParameterSpec.class);
+ } catch (Exception e) {
+ throw new ProviderException("Error handling EC parameters", e);
+ }
+ } else {
+ throw new ProviderException
+ ("Unrecognized algorithm for signature parameters " +
+ sigName);
+ }
}
return paramSpec;
}
@@ -103,17 +112,31 @@
public static AlgorithmParameterSpec getParamSpec(String sigName,
byte[] paramBytes)
throws ProviderException {
- sigName = checkName(sigName);
+ sigName = checkName(sigName).toUpperCase(Locale.ENGLISH);
AlgorithmParameterSpec paramSpec = null;
+
if (paramBytes != null) {
- if (sigName.toUpperCase().indexOf("RSA") == -1) {
+ if (sigName.indexOf("RSA") != -1) {
+ AlgorithmParameters params =
+ createAlgorithmParameters(sigName, paramBytes);
+ paramSpec = RSAUtil.getParamSpec(params);
+ } else if (sigName.indexOf("ECDSA") != -1) {
+ try {
+ Provider p = Signature.getInstance(sigName).getProvider();
+ paramSpec = ECUtil.getECParameterSpec(p, paramBytes);
+ } catch (Exception e) {
+ throw new ProviderException("Error handling EC parameters", e);
+ }
+ // ECUtil discards exception and returns null, so we need to check
+ // the returned value
+ if (paramSpec == null) {
+ throw new ProviderException("Error handling EC parameters");
+ }
+ } else {
throw new ProviderException
("Unrecognized algorithm for signature parameters " +
sigName);
}
- AlgorithmParameters params =
- createAlgorithmParameters(sigName, paramBytes);
- paramSpec = RSAUtil.getParamSpec(params);
}
return paramSpec;
}