Blame SOURCES/pr3083-rh1346460-for_ssl_debug_return_null_instead_of_exception_when_theres_no_ecc_provider.patch

53c576
# HG changeset patch
53c576
# User andrew
53c576
# Date 1467652889 -3600
53c576
#      Mon Jul 04 18:21:29 2016 +0100
53c576
# Node ID a4541d1d8609cadb08d3e31b40b9184ff32dd6c3
53c576
# Parent  bc6eab2038c603afb2eb2b4644f3b900c8fd0c46
53c576
PR3083, RH1346460: Regression in SSL debug output without an ECC provider
53c576
Summary: Return null rather than throwing an exception when there's no ECC provider.
53c576
53c576
diff --git openjdk.orig/jdk/src/share/classes/sun/security/ec/ECKeyPairGenerator.java openjdk/jdk/src/share/classes/sun/security/ec/ECKeyPairGenerator.java
53c576
--- openjdk.orig/jdk/src/share/classes/sun/security/ec/ECKeyPairGenerator.java
53c576
+++ openjdk/jdk/src/share/classes/sun/security/ec/ECKeyPairGenerator.java
53c576
@@ -121,7 +121,7 @@
53c576
     private static void ensureCurveIsSupported(ECParameterSpec ecSpec)
53c576
         throws InvalidAlgorithmParameterException {
53c576
 
53c576
-        AlgorithmParameters ecParams = ECUtil.getECParameters(null);
53c576
+        AlgorithmParameters ecParams = ECUtil.getECParameters(null, true);
53c576
         byte[] encodedParams;
53c576
         try {
53c576
             ecParams.init(ecSpec);
53c576
diff --git openjdk.orig/jdk/src/share/classes/sun/security/util/Debug.java openjdk/jdk/src/share/classes/sun/security/util/Debug.java
53c576
--- openjdk.orig/jdk/src/share/classes/sun/security/util/Debug.java
53c576
+++ openjdk/jdk/src/share/classes/sun/security/util/Debug.java
53c576
@@ -73,6 +73,7 @@
53c576
         System.err.println("certpath      PKIX CertPathBuilder and");
53c576
         System.err.println("              CertPathValidator debugging");
53c576
         System.err.println("combiner      SubjectDomainCombiner debugging");
53c576
+        System.err.println("ecc           Elliptic Curve Cryptography debugging");
53c576
         System.err.println("gssloginconfig");
53c576
         System.err.println("              GSS LoginConfigImpl debugging");
53c576
         System.err.println("configfile    JAAS ConfigFile loading");
53c576
diff --git openjdk.orig/jdk/src/share/classes/sun/security/util/ECUtil.java openjdk/jdk/src/share/classes/sun/security/util/ECUtil.java
53c576
--- openjdk.orig/jdk/src/share/classes/sun/security/util/ECUtil.java
53c576
+++ openjdk/jdk/src/share/classes/sun/security/util/ECUtil.java
53c576
@@ -41,6 +41,9 @@
53c576
 
53c576
 public final class ECUtil {
53c576
 
53c576
+    /* Are we debugging ? */
53c576
+    private static final Debug debug = Debug.getInstance("ecc");
53c576
+
53c576
     // Used by SunPKCS11 and SunJSSE.
53c576
     public static ECPoint decodePoint(byte[] data, EllipticCurve curve)
53c576
             throws IOException {
53c576
@@ -90,6 +93,10 @@
53c576
     }
53c576
 
53c576
     public static AlgorithmParameters getECParameters(Provider p) {
53c576
+        return getECParameters(p, false);
53c576
+    }
53c576
+
53c576
+    public static AlgorithmParameters getECParameters(Provider p, boolean throwException) {
53c576
         try {
53c576
             if (p != null) {
53c576
                 return AlgorithmParameters.getInstance("EC", p);
53c576
@@ -97,13 +104,21 @@
53c576
 
53c576
             return AlgorithmParameters.getInstance("EC");
53c576
         } catch (NoSuchAlgorithmException nsae) {
53c576
-            throw new RuntimeException(nsae);
53c576
+            if (throwException) {
53c576
+                throw new RuntimeException(nsae);
53c576
+            } else {
53c576
+                // ECC provider is optional so just return null
53c576
+                if (debug != null) {
53c576
+                    debug.println("Provider unavailable: " + nsae);
53c576
+                }
53c576
+                return null;
53c576
+            }
53c576
         }
53c576
     }
53c576
 
53c576
     public static byte[] encodeECParameterSpec(Provider p,
53c576
                                                ECParameterSpec spec) {
53c576
-        AlgorithmParameters parameters = getECParameters(p);
53c576
+        AlgorithmParameters parameters = getECParameters(p, true);
53c576
 
53c576
         try {
53c576
             parameters.init(spec);
53c576
@@ -122,11 +137,16 @@
53c576
     public static ECParameterSpec getECParameterSpec(Provider p,
53c576
                                                      ECParameterSpec spec) {
53c576
         AlgorithmParameters parameters = getECParameters(p);
53c576
+        if (parameters == null)
53c576
+            return null;
53c576
 
53c576
         try {
53c576
             parameters.init(spec);
53c576
             return parameters.getParameterSpec(ECParameterSpec.class);
53c576
         } catch (InvalidParameterSpecException ipse) {
53c576
+            if (debug != null) {
53c576
+                debug.println("Invalid parameter specification: " + ipse);
53c576
+            }
53c576
             return null;
53c576
         }
53c576
     }
53c576
@@ -135,34 +155,49 @@
53c576
                                                      byte[] params)
53c576
             throws IOException {
53c576
         AlgorithmParameters parameters = getECParameters(p);
53c576
+        if (parameters == null)
53c576
+            return null;
53c576
 
53c576
         parameters.init(params);
53c576
 
53c576
         try {
53c576
             return parameters.getParameterSpec(ECParameterSpec.class);
53c576
         } catch (InvalidParameterSpecException ipse) {
53c576
+            if (debug != null) {
53c576
+                debug.println("Invalid parameter specification: " + ipse);
53c576
+            }
53c576
             return null;
53c576
         }
53c576
     }
53c576
 
53c576
     public static ECParameterSpec getECParameterSpec(Provider p, String name) {
53c576
         AlgorithmParameters parameters = getECParameters(p);
53c576
+        if (parameters == null)
53c576
+            return null;
53c576
 
53c576
         try {
53c576
             parameters.init(new ECGenParameterSpec(name));
53c576
             return parameters.getParameterSpec(ECParameterSpec.class);
53c576
         } catch (InvalidParameterSpecException ipse) {
53c576
+            if (debug != null) {
53c576
+                debug.println("Invalid parameter specification: " + ipse);
53c576
+            }
53c576
             return null;
53c576
         }
53c576
     }
53c576
 
53c576
     public static ECParameterSpec getECParameterSpec(Provider p, int keySize) {
53c576
         AlgorithmParameters parameters = getECParameters(p);
53c576
+        if (parameters == null)
53c576
+            return null;
53c576
 
53c576
         try {
53c576
             parameters.init(new ECKeySizeParameterSpec(keySize));
53c576
             return parameters.getParameterSpec(ECParameterSpec.class);
53c576
         } catch (InvalidParameterSpecException ipse) {
53c576
+            if (debug != null) {
53c576
+                debug.println("Invalid parameter specification: " + ipse);
53c576
+            }
53c576
             return null;
53c576
         }
53c576
 
53c576
@@ -171,11 +206,16 @@
53c576
     public static String getCurveName(Provider p, ECParameterSpec spec) {
53c576
         ECGenParameterSpec nameSpec;
53c576
         AlgorithmParameters parameters = getECParameters(p);
53c576
+        if (parameters == null)
53c576
+            return null;
53c576
 
53c576
         try {
53c576
             parameters.init(spec);
53c576
             nameSpec = parameters.getParameterSpec(ECGenParameterSpec.class);
53c576
         } catch (InvalidParameterSpecException ipse) {
53c576
+            if (debug != null) {
53c576
+                debug.println("Invalid parameter specification: " + ipse);
53c576
+            }
53c576
             return null;
53c576
         }
53c576