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