Blame pr3083-rh1346460-for_ssl_debug_return_null_instead_of_exception_when_theres_no_ecc_provider.patch

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