Blame SOURCES/pr3083-rh1346460-for_ssl_debug_return_null_instead_of_exception_when_theres_no_ecc_provider.patch

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