Blame SOURCES/pr3083-rh1346460-for_ssl_debug_return_null_instead_of_exception_when_theres_no_ecc_provider.patch

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