Blame SOURCES/jss-ObjectNotFoundException-message.patch

a7067b
# HG changeset patch
a7067b
# User "Endi S. Dewata" <edewata@redhat.com>
a7067b
# Date 1509154719 -7200
a7067b
#      Sat Oct 28 03:38:39 2017 +0200
a7067b
# Node ID 19a0e2146a929173757e6ccbb61a035ec9426f43
a7067b
# Parent  b1a3c3cc6b3584948d251d3bfcfe6630d8970db5
a7067b
Added certificate nickname into ObjectNotFoundException message.
a7067b
The code that generates ObjectNotFoundException has been modified
a7067b
to include the certificate nickname to help troubleshooting.
a7067b
a7067b
https://bugzilla.mozilla.org/show_bug.cgi?id=1408057
a7067b
a7067b
diff --git a/org/mozilla/jss/PK11Finder.c b/org/mozilla/jss/PK11Finder.c
a7067b
--- a/org/mozilla/jss/PK11Finder.c
a7067b
+++ b/org/mozilla/jss/PK11Finder.c
a7067b
@@ -54,7 +54,9 @@
a7067b
     cert = JSS_PK11_findCertAndSlotFromNickname(nick, NULL, &slot);
a7067b
 
a7067b
     if(cert == NULL) {
a7067b
-        JSS_nativeThrow(env, OBJECT_NOT_FOUND_EXCEPTION);
a7067b
+        char *message = PR_smprintf("Certificate not found: %s", nick);
a7067b
+        JSS_throwMsg(env, OBJECT_NOT_FOUND_EXCEPTION, message);
a7067b
+        PR_smprintf_free(message);
a7067b
         goto finish;
a7067b
     }
a7067b
 
a7067b
@@ -1577,7 +1579,9 @@
a7067b
     cert = CERT_FindCertByNickname(CERT_GetDefaultCertDB(), nickname);
a7067b
 
a7067b
     if (cert == NULL) {
a7067b
-        JSS_throw(env, OBJECT_NOT_FOUND_EXCEPTION);
a7067b
+        char *message = PR_smprintf("Certificate not found: %s", nickname);
a7067b
+        JSS_throwMsg(env, OBJECT_NOT_FOUND_EXCEPTION, message);
a7067b
+        PR_smprintf_free(message);
a7067b
         goto finish;
a7067b
     } else {
a7067b
     /* 0 for certificateUsage in call to CERT_VerifyCertificateNow will
a7067b
@@ -1640,7 +1644,9 @@
a7067b
     cert = CERT_FindCertByNickname(CERT_GetDefaultCertDB(), nickname);
a7067b
 
a7067b
     if (cert == NULL) {
a7067b
-        JSS_throw(env, OBJECT_NOT_FOUND_EXCEPTION);
a7067b
+        char *message = PR_smprintf("Certificate not found: %s", nickname);
a7067b
+        JSS_throwMsg(env, OBJECT_NOT_FOUND_EXCEPTION, message);
a7067b
+        PR_smprintf_free(message);
a7067b
         goto finish;
a7067b
     } else {
a7067b
     /* 0 for certificateUsage in call to CERT_VerifyCertificateNow to
a7067b
@@ -1801,7 +1807,9 @@
a7067b
     cert = CERT_FindCertByNickname(CERT_GetDefaultCertDB(), nickname);
a7067b
 
a7067b
     if (cert == NULL) {
a7067b
-        JSS_throw(env, OBJECT_NOT_FOUND_EXCEPTION);
a7067b
+        char *message = PR_smprintf("Certificate not found: %s", nickname);
a7067b
+        JSS_throwMsg(env, OBJECT_NOT_FOUND_EXCEPTION, message);
a7067b
+        PR_smprintf_free(message);
a7067b
         goto finish;
a7067b
     } else {
a7067b
         rv = CERT_VerifyCertNow(CERT_GetDefaultCertDB(), cert,
a7067b
# HG changeset patch
a7067b
# User "Endi S. Dewata" <edewata@redhat.com>
a7067b
# Date 1509154819 -7200
a7067b
#      Sat Oct 28 03:40:19 2017 +0200
a7067b
# Node ID 837c79476110ecd4bf6b507faad50edb9eed7e7e
a7067b
# Parent  19a0e2146a929173757e6ccbb61a035ec9426f43
a7067b
Reformatted SocketBase.java.
a7067b
The SocketBase.java has been auto-formatted using Eclipse to
a7067b
simplify further changes on the file.
a7067b
a7067b
https://bugzilla.mozilla.org/show_bug.cgi?id=1408057
a7067b
a7067b
diff --git a/org/mozilla/jss/ssl/SocketBase.java b/org/mozilla/jss/ssl/SocketBase.java
a7067b
--- a/org/mozilla/jss/ssl/SocketBase.java
a7067b
+++ b/org/mozilla/jss/ssl/SocketBase.java
a7067b
@@ -27,6 +27,7 @@
a7067b
     int getTimeout() {
a7067b
         return timeout;
a7067b
     }
a7067b
+
a7067b
     void setTimeout(int timeout) {
a7067b
         this.timeout = timeout;
a7067b
     }
a7067b
@@ -36,18 +37,17 @@
a7067b
     }
a7067b
 
a7067b
     native byte[] socketCreate(Object socketObject,
a7067b
-        SSLCertificateApprovalCallback certApprovalCallback,
a7067b
-        SSLClientCertificateSelectionCallback clientCertSelectionCallback,
a7067b
-        java.net.Socket javaSock, String host,int family)
a7067b
+            SSLCertificateApprovalCallback certApprovalCallback,
a7067b
+            SSLClientCertificateSelectionCallback clientCertSelectionCallback,
a7067b
+            java.net.Socket javaSock, String host, int family)
a7067b
             throws SocketException;
a7067b
 
a7067b
     byte[] socketCreate(Object socketObject,
a7067b
-        SSLCertificateApprovalCallback certApprovalCallback,
a7067b
-        SSLClientCertificateSelectionCallback clientCertSelectionCallback, int family)
a7067b
-            throws SocketException
a7067b
-    {
a7067b
+            SSLCertificateApprovalCallback certApprovalCallback,
a7067b
+            SSLClientCertificateSelectionCallback clientCertSelectionCallback, int family)
a7067b
+            throws SocketException {
a7067b
         return socketCreate(socketObject, certApprovalCallback,
a7067b
-            clientCertSelectionCallback, null, null, family);
a7067b
+                clientCertSelectionCallback, null, null, family);
a7067b
     }
a7067b
 
a7067b
     native void socketBind(byte[] addrBA, int port) throws SocketException;
a7067b
@@ -57,7 +57,7 @@
a7067b
      * safer than copying the values of the C constants, which are subject
a7067b
      * to change, into Java code.
a7067b
      * Note to developer these constants are not all related! i.e. you cannot
a7067b
-     * pass in PR_SHUTDOWN_RCV to setSSLOption etc! Check their usage 
a7067b
+     * pass in PR_SHUTDOWN_RCV to setSSLOption etc! Check their usage
a7067b
      * in NSS and NSPR before using.
a7067b
      */
a7067b
     static final int SSL_ENABLE_SSL2 = 0;
a7067b
@@ -73,7 +73,7 @@
a7067b
     static final int SSL_POLICY_DOMESTIC = 10;
a7067b
     static final int SSL_POLICY_EXPORT = 11;
a7067b
     static final int SSL_POLICY_FRANCE = 12;
a7067b
-    static final int SSL_ROLLBACK_DETECTION = 13; 
a7067b
+    static final int SSL_ROLLBACK_DETECTION = 13;
a7067b
     static final int SSL_NO_STEP_DOWN = 14;
a7067b
     static final int SSL_ENABLE_FDX = 15;
a7067b
     static final int SSL_V2_COMPATIBLE_HELLO = 16;
a7067b
@@ -98,7 +98,7 @@
a7067b
     static final int SSL_Variant_Stream = 33;
a7067b
     static final int SSL_Variant_Datagram = 34;
a7067b
 
a7067b
-    static final int SSL_AF_INET  = 50;
a7067b
+    static final int SSL_AF_INET = 50;
a7067b
     static final int SSL_AF_INET6 = 51;
a7067b
 
a7067b
     void close() throws IOException {
a7067b
@@ -106,7 +106,7 @@
a7067b
     }
a7067b
 
a7067b
     // SSLServerSocket and SSLSocket close methods
a7067b
-    // have their own synchronization control that 
a7067b
+    // have their own synchronization control that
a7067b
     // protects SocketBase.socketClose.
a7067b
     native void socketClose() throws IOException;
a7067b
 
a7067b
@@ -118,14 +118,13 @@
a7067b
     }
a7067b
 
a7067b
     public void requestClientAuthNoExpiryCheck(boolean b)
a7067b
-        throws SocketException
a7067b
-    {
a7067b
+            throws SocketException {
a7067b
         requestingClientAuth = b;
a7067b
         requestClientAuthNoExpiryCheckNative(b);
a7067b
     }
a7067b
 
a7067b
     private native void requestClientAuthNoExpiryCheckNative(boolean b)
a7067b
-        throws SocketException;
a7067b
+            throws SocketException;
a7067b
 
a7067b
     void enableSSL2(boolean enable) throws SocketException {
a7067b
         setSSLOption(SSL_ENABLE_SSL2, enable);
a7067b
@@ -144,8 +143,7 @@
a7067b
     }
a7067b
 
a7067b
     void enableRenegotiation(int mode)
a7067b
-            throws SocketException
a7067b
-    {
a7067b
+            throws SocketException {
a7067b
         setSSLOptionMode(SocketBase.SSL_ENABLE_RENEGOTIATION, mode);
a7067b
     }
a7067b
 
a7067b
@@ -168,23 +166,21 @@
a7067b
     void enableV2CompatibleHello(boolean enable) throws SocketException {
a7067b
         setSSLOption(SSL_V2_COMPATIBLE_HELLO, enable);
a7067b
     }
a7067b
-    
a7067b
+
a7067b
     void setSSLOption(int option, boolean on)
a7067b
-        throws SocketException
a7067b
-    {
a7067b
+            throws SocketException {
a7067b
         setSSLOption(option, on ? 1 : 0);
a7067b
     }
a7067b
 
a7067b
-    /** 
a7067b
-     * Sets SSL options for this socket that have simple 
a7067b
+    /**
a7067b
+     * Sets SSL options for this socket that have simple
a7067b
      * enable/disable values.
a7067b
      */
a7067b
     native void setSSLOption(int option, int on)
a7067b
-        throws SocketException;
a7067b
+            throws SocketException;
a7067b
 
a7067b
     void setSSLVersionRange(org.mozilla.jss.ssl.SSLSocket.SSLVersionRange range)
a7067b
-        throws SocketException
a7067b
-    {
a7067b
+            throws SocketException {
a7067b
         setSSLVersionRange(range.getMinEnum(), range.getMaxEnum());
a7067b
     }
a7067b
 
a7067b
@@ -192,93 +188,101 @@
a7067b
      * Sets SSL Version Range for this socket to support TLS v1.1 and v1.2
a7067b
      */
a7067b
     native void setSSLVersionRange(int min, int max)
a7067b
-        throws SocketException;
a7067b
+            throws SocketException;
a7067b
 
a7067b
-    /** 
a7067b
+    /**
a7067b
      * Sets the SSL option setting mode value use for options
a7067b
      * that have more values than just enable/disable.
a7067b
      */
a7067b
     native void setSSLOptionMode(int option, int option2)
a7067b
-        throws SocketException; 
a7067b
+            throws SocketException;
a7067b
 
a7067b
-    
a7067b
     /* return 0 for option disabled 1 for option enabled. */
a7067b
     native int getSSLOption(int option)
a7067b
-        throws SocketException;
a7067b
-    
a7067b
+            throws SocketException;
a7067b
+
a7067b
     public String getSSLOptions() {
a7067b
         StringBuffer buf = new StringBuffer();
a7067b
         try {
a7067b
             buf.append("SSL Options configured for this SSLSocket:");
a7067b
-            buf.append("\nSSL_ENABLE_SSL2" + 
a7067b
-                ((getSSLOption(SocketBase.SSL_ENABLE_SSL2) != 0)
a7067b
-                ? "=on" :  "=off"));
a7067b
-            buf.append("\nSSL_ENABLE_SSL3"  + 
a7067b
-                ((getSSLOption(SocketBase.SSL_ENABLE_SSL3) != 0) 
a7067b
-                ? "=on" :  "=off"));
a7067b
-            buf.append("\nSSL_ENABLE_TLS"  + 
a7067b
-                ((getSSLOption(SocketBase.SSL_ENABLE_TLS) != 0) 
a7067b
-                ? "=on" :  "=off"));
a7067b
-            buf.append("\nSSL_REQUIRE_CERTIFICATE"); 
a7067b
+            buf.append("\nSSL_ENABLE_SSL2" +
a7067b
+                    ((getSSLOption(SocketBase.SSL_ENABLE_SSL2) != 0)
a7067b
+                            ? "=on"
a7067b
+                            : "=off"));
a7067b
+            buf.append("\nSSL_ENABLE_SSL3" +
a7067b
+                    ((getSSLOption(SocketBase.SSL_ENABLE_SSL3) != 0)
a7067b
+                            ? "=on"
a7067b
+                            : "=off"));
a7067b
+            buf.append("\nSSL_ENABLE_TLS" +
a7067b
+                    ((getSSLOption(SocketBase.SSL_ENABLE_TLS) != 0)
a7067b
+                            ? "=on"
a7067b
+                            : "=off"));
a7067b
+            buf.append("\nSSL_REQUIRE_CERTIFICATE");
a7067b
             switch (getSSLOption(SocketBase.SSL_REQUIRE_CERTIFICATE)) {
a7067b
-                case 0:
a7067b
-                    buf.append("=Never");
a7067b
-                    break;
a7067b
-                case 1:
a7067b
-                    buf.append("=Always");
a7067b
-                    break;
a7067b
-                case 2:
a7067b
-                    buf.append("=First Handshake");
a7067b
-                    break;
a7067b
-                case 3:
a7067b
-                    buf.append("=No Error");
a7067b
-                    break;
a7067b
-                default:
a7067b
-                    buf.append("=Report JSS Bug this option has a status.");
a7067b
-                    break;
a7067b
+            case 0:
a7067b
+                buf.append("=Never");
a7067b
+                break;
a7067b
+            case 1:
a7067b
+                buf.append("=Always");
a7067b
+                break;
a7067b
+            case 2:
a7067b
+                buf.append("=First Handshake");
a7067b
+                break;
a7067b
+            case 3:
a7067b
+                buf.append("=No Error");
a7067b
+                break;
a7067b
+            default:
a7067b
+                buf.append("=Report JSS Bug this option has a status.");
a7067b
+                break;
a7067b
             } //end switch
a7067b
-            buf.append("\nSSL_REQUEST_CERTIFICATE"  + 
a7067b
-                ((getSSLOption(SocketBase.SSL_REQUEST_CERTIFICATE) != 0) 
a7067b
-                ? "=on" :  "=off"));
a7067b
-            buf.append("\nSSL_NO_CACHE"  + 
a7067b
-                ((getSSLOption(SocketBase.SSL_NO_CACHE) != 0)
a7067b
-                ? "=on" :  "=off"));
a7067b
-            buf.append("\nSSL_ROLLBACK_DETECTION"  + 
a7067b
-                ((getSSLOption(SocketBase.SSL_ROLLBACK_DETECTION) != 0)
a7067b
-                ? "=on" :  "=off"));
a7067b
-            buf.append("\nSSL_NO_STEP_DOWN"  + 
a7067b
-                ((getSSLOption(SocketBase.SSL_NO_STEP_DOWN) != 0)
a7067b
-                ? "=on" :  "=off"));
a7067b
-            buf.append("\nSSL_ENABLE_FDX"  + 
a7067b
-                ((getSSLOption(SocketBase.SSL_ENABLE_FDX) != 0)
a7067b
-                ? "=on" :  "=off"));
a7067b
-            buf.append("\nSSL_V2_COMPATIBLE_HELLO"  + 
a7067b
-                ((getSSLOption(SocketBase.SSL_V2_COMPATIBLE_HELLO) != 0) 
a7067b
-                ? "=on" :  "=off"));
a7067b
-            buf.append("\nSSL_ENABLE_SESSION_TICKETS"  +
a7067b
-                ((getSSLOption(SocketBase.SSL_ENABLE_SESSION_TICKETS)
a7067b
-                != 0) ? "=on" :  "=off"));
a7067b
+            buf.append("\nSSL_REQUEST_CERTIFICATE" +
a7067b
+                    ((getSSLOption(SocketBase.SSL_REQUEST_CERTIFICATE) != 0)
a7067b
+                            ? "=on"
a7067b
+                            : "=off"));
a7067b
+            buf.append("\nSSL_NO_CACHE" +
a7067b
+                    ((getSSLOption(SocketBase.SSL_NO_CACHE) != 0)
a7067b
+                            ? "=on"
a7067b
+                            : "=off"));
a7067b
+            buf.append("\nSSL_ROLLBACK_DETECTION" +
a7067b
+                    ((getSSLOption(SocketBase.SSL_ROLLBACK_DETECTION) != 0)
a7067b
+                            ? "=on"
a7067b
+                            : "=off"));
a7067b
+            buf.append("\nSSL_NO_STEP_DOWN" +
a7067b
+                    ((getSSLOption(SocketBase.SSL_NO_STEP_DOWN) != 0)
a7067b
+                            ? "=on"
a7067b
+                            : "=off"));
a7067b
+            buf.append("\nSSL_ENABLE_FDX" +
a7067b
+                    ((getSSLOption(SocketBase.SSL_ENABLE_FDX) != 0)
a7067b
+                            ? "=on"
a7067b
+                            : "=off"));
a7067b
+            buf.append("\nSSL_V2_COMPATIBLE_HELLO" +
a7067b
+                    ((getSSLOption(SocketBase.SSL_V2_COMPATIBLE_HELLO) != 0)
a7067b
+                            ? "=on"
a7067b
+                            : "=off"));
a7067b
+            buf.append("\nSSL_ENABLE_SESSION_TICKETS" +
a7067b
+                    ((getSSLOption(SocketBase.SSL_ENABLE_SESSION_TICKETS) != 0) ? "=on" : "=off"));
a7067b
             buf.append("\nSSL_ENABLE_RENEGOTIATION");
a7067b
             switch (getSSLOption(SocketBase.SSL_ENABLE_RENEGOTIATION)) {
a7067b
-                case 0:
a7067b
-                    buf.append("=SSL_RENEGOTIATE_NEVER");
a7067b
-                    break;
a7067b
-                case 1:
a7067b
-                    buf.append("=SSL_RENEGOTIATE_UNRESTRICTED");
a7067b
-                    break;
a7067b
-                case 2:
a7067b
-                    buf.append("=SSL_RENEGOTIATE_REQUIRES_XTN");
a7067b
-                    break;
a7067b
-                case 3:
a7067b
-                    buf.append("=SSL_RENEGOTIATE_TRANSITIONAL");
a7067b
-                    break;
a7067b
-                default:
a7067b
-                    buf.append("=Report JSS Bug this option has a status.");
a7067b
-                    break;
a7067b
+            case 0:
a7067b
+                buf.append("=SSL_RENEGOTIATE_NEVER");
a7067b
+                break;
a7067b
+            case 1:
a7067b
+                buf.append("=SSL_RENEGOTIATE_UNRESTRICTED");
a7067b
+                break;
a7067b
+            case 2:
a7067b
+                buf.append("=SSL_RENEGOTIATE_REQUIRES_XTN");
a7067b
+                break;
a7067b
+            case 3:
a7067b
+                buf.append("=SSL_RENEGOTIATE_TRANSITIONAL");
a7067b
+                break;
a7067b
+            default:
a7067b
+                buf.append("=Report JSS Bug this option has a status.");
a7067b
+                break;
a7067b
             } //end switch
a7067b
-            buf.append("\nSSL_REQUIRE_SAFE_NEGOTIATION"  +
a7067b
-                ((getSSLOption(SocketBase.SSL_REQUIRE_SAFE_NEGOTIATION) != 0)
a7067b
-                ? "=on" :  "=off"));
a7067b
+            buf.append("\nSSL_REQUIRE_SAFE_NEGOTIATION" +
a7067b
+                    ((getSSLOption(SocketBase.SSL_REQUIRE_SAFE_NEGOTIATION) != 0)
a7067b
+                            ? "=on"
a7067b
+                            : "=off"));
a7067b
 
a7067b
         } catch (SocketException e) {
a7067b
             buf.append("\ngetSSLOptions exception " + e.getMessage());
a7067b
@@ -292,19 +296,18 @@
a7067b
      * of construction than getByName(), and it is final.
a7067b
      *
a7067b
      * @return The InetAddress corresponding to the given integer,
a7067b
-     *      or <tt>null</tt> if the InetAddress could not be constructed.
a7067b
+     *         or <tt>null</tt> if the InetAddress could not be constructed.
a7067b
      */
a7067b
-    private static InetAddress
a7067b
-    convertIntToInetAddress(int intAddr) {
a7067b
+    private static InetAddress convertIntToInetAddress(int intAddr) {
a7067b
         InetAddress in;
a7067b
         int[] addr = new int[4];
a7067b
         addr[0] = ((intAddr >>> 24) & 0xff);
a7067b
         addr[1] = ((intAddr >>> 16) & 0xff);
a7067b
-        addr[2] = ((intAddr >>>  8) & 0xff);
a7067b
-        addr[3] = ((intAddr       ) & 0xff);
a7067b
+        addr[2] = ((intAddr >>> 8) & 0xff);
a7067b
+        addr[3] = ((intAddr) & 0xff);
a7067b
         try {
a7067b
             in = InetAddress.getByName(
a7067b
-                addr[0] + "." + addr[1] + "." + addr[2] + "." + addr[3] );
a7067b
+                    addr[0] + "." + addr[1] + "." + addr[2] + "." + addr[3]);
a7067b
         } catch (java.net.UnknownHostException e) {
a7067b
             in = null;
a7067b
         }
a7067b
@@ -312,12 +315,13 @@
a7067b
     }
a7067b
 
a7067b
     private native byte[] getLocalAddressByteArrayNative() throws SocketException;
a7067b
+
a7067b
     private native byte[] getPeerAddressByteArrayNative() throws SocketException;
a7067b
+
a7067b
     /**
a7067b
      * @return the InetAddress of the peer end of the socket.
a7067b
      */
a7067b
-    InetAddress getInetAddress()
a7067b
-    {
a7067b
+    InetAddress getInetAddress() {
a7067b
         try {
a7067b
             byte[] address = getPeerAddressByteArrayNative();
a7067b
 
a7067b
@@ -326,14 +330,15 @@
a7067b
             try {
a7067b
 
a7067b
                 iAddr = InetAddress.getByAddress(address);
a7067b
-            }   catch(UnknownHostException e) {
a7067b
+            } catch (UnknownHostException e) {
a7067b
             }
a7067b
 
a7067b
             return iAddr;
a7067b
-        } catch(SocketException e) {
a7067b
+        } catch (SocketException e) {
a7067b
             return null;
a7067b
         }
a7067b
     }
a7067b
+
a7067b
     private native int getPeerAddressNative() throws SocketException;
a7067b
 
a7067b
     /**
a7067b
@@ -348,20 +353,21 @@
a7067b
             try {
a7067b
 
a7067b
                 lAddr = InetAddress.getByAddress(address);
a7067b
-            }   catch(UnknownHostException e) {
a7067b
+            } catch (UnknownHostException e) {
a7067b
             }
a7067b
 
a7067b
             return lAddr;
a7067b
-        } catch(SocketException e) {
a7067b
+        } catch (SocketException e) {
a7067b
             return null;
a7067b
         }
a7067b
     }
a7067b
+
a7067b
     private native int getLocalAddressNative() throws SocketException;
a7067b
 
a7067b
     public int getLocalPort() {
a7067b
         try {
a7067b
             return getLocalPortNative();
a7067b
-        } catch(SocketException e) {
a7067b
+        } catch (SocketException e) {
a7067b
             return 0;
a7067b
         }
a7067b
     }
a7067b
@@ -369,18 +375,16 @@
a7067b
     private native int getLocalPortNative() throws SocketException;
a7067b
 
a7067b
     void requireClientAuth(boolean require, boolean onRedo)
a7067b
-            throws SocketException
a7067b
-    {
a7067b
-        if( require && !requestingClientAuth ) {
a7067b
+            throws SocketException {
a7067b
+        if (require && !requestingClientAuth) {
a7067b
             requestClientAuth(true);
a7067b
         }
a7067b
         setSSLOption(SSL_REQUIRE_CERTIFICATE, require ? (onRedo ? 1 : 2) : 0);
a7067b
     }
a7067b
 
a7067b
     void requireClientAuth(int mode)
a7067b
-            throws SocketException
a7067b
-    {
a7067b
-        if(mode > 0 && !requestingClientAuth ) {
a7067b
+            throws SocketException {
a7067b
+        if (mode > 0 && !requestingClientAuth) {
a7067b
             requestClientAuth(true);
a7067b
         }
a7067b
         setSSLOptionMode(SocketBase.SSL_REQUIRE_CERTIFICATE, mode);
a7067b
@@ -390,52 +394,52 @@
a7067b
      * Sets the nickname of the certificate to use for client authentication.
a7067b
      */
a7067b
     public void setClientCertNickname(String nick) throws SocketException {
a7067b
-      try {
a7067b
-        setClientCert( CryptoManager.getInstance().findCertByNickname(nick) );
a7067b
-      } catch(CryptoManager.NotInitializedException nie) {
a7067b
-        throw new SocketException("CryptoManager not initialized");
a7067b
-      } catch(ObjectNotFoundException onfe) {
a7067b
-        throw new SocketException("Object not found: " + onfe);
a7067b
-      } catch(TokenException te) {
a7067b
-        throw new SocketException("Token Exception: " + te);
a7067b
-      }
a7067b
+        try {
a7067b
+            setClientCert(CryptoManager.getInstance().findCertByNickname(nick));
a7067b
+        } catch (CryptoManager.NotInitializedException nie) {
a7067b
+            throw new SocketException("CryptoManager not initialized");
a7067b
+        } catch (ObjectNotFoundException onfe) {
a7067b
+            throw new SocketException("Object not found: " + onfe);
a7067b
+        } catch (TokenException te) {
a7067b
+            throw new SocketException("Token Exception: " + te);
a7067b
+        }
a7067b
     }
a7067b
 
a7067b
     native void setClientCert(org.mozilla.jss.crypto.X509Certificate cert)
a7067b
-        throws SocketException;
a7067b
+            throws SocketException;
a7067b
 
a7067b
     void useCache(boolean b) throws SocketException {
a7067b
         setSSLOption(SSL_NO_CACHE, !b);
a7067b
     }
a7067b
 
a7067b
     static Throwable processExceptions(Throwable topException,
a7067b
-        Throwable bottomException)
a7067b
-    {
a7067b
-      try {
a7067b
-        StringBuffer strBuf;
a7067b
-        strBuf = new StringBuffer( topException.toString() );
a7067b
+            Throwable bottomException) {
a7067b
+        try {
a7067b
+            StringBuffer strBuf;
a7067b
+            strBuf = new StringBuffer(topException.toString());
a7067b
 
a7067b
-        if( bottomException != null ) {
a7067b
-            strBuf.append(" --> ");
a7067b
-            strBuf.append( bottomException.toString() );
a7067b
+            if (bottomException != null) {
a7067b
+                strBuf.append(" --> ");
a7067b
+                strBuf.append(bottomException.toString());
a7067b
+            }
a7067b
+
a7067b
+            Class excepClass = topException.getClass();
a7067b
+            Class stringClass = java.lang.String.class;
a7067b
+            Constructor cons = excepClass.getConstructor(new Class[] { stringClass });
a7067b
+
a7067b
+            return (Throwable) cons.newInstance(new Object[] { strBuf.toString() });
a7067b
+        } catch (Exception e) {
a7067b
+            Assert.notReached("Problem constructing exception container");
a7067b
+            return topException;
a7067b
         }
a7067b
-
a7067b
-        Class excepClass = topException.getClass();
a7067b
-        Class stringClass = java.lang.String.class;
a7067b
-        Constructor cons = excepClass.getConstructor(new Class[] {stringClass});
a7067b
-
a7067b
-        return (Throwable) cons.newInstance(new Object[] { strBuf.toString() });
a7067b
-      } catch(Exception e ) {
a7067b
-        Assert.notReached("Problem constructing exception container");
a7067b
-        return topException;
a7067b
-      }
a7067b
     }
a7067b
 
a7067b
     static private int supportsIPV6 = -1;
a7067b
+
a7067b
     static boolean supportsIPV6() {
a7067b
 
a7067b
-        if(supportsIPV6 >= 0) {
a7067b
-            if(supportsIPV6 > 0) {
a7067b
+        if (supportsIPV6 >= 0) {
a7067b
+            if (supportsIPV6 > 0) {
a7067b
                 return true;
a7067b
             } else {
a7067b
                 return false;
a7067b
@@ -444,28 +448,25 @@
a7067b
 
a7067b
         Enumeration netInter;
a7067b
         try {
a7067b
-                 netInter = NetworkInterface.getNetworkInterfaces();
a7067b
-        }  catch (SocketException e) {
a7067b
+            netInter = NetworkInterface.getNetworkInterfaces();
a7067b
+        } catch (SocketException e) {
a7067b
 
a7067b
-                 return false;
a7067b
+            return false;
a7067b
         }
a7067b
-        while ( netInter.hasMoreElements() )
a7067b
-        {
a7067b
-            NetworkInterface ni = (NetworkInterface)netInter.nextElement();
a7067b
+        while (netInter.hasMoreElements()) {
a7067b
+            NetworkInterface ni = (NetworkInterface) netInter.nextElement();
a7067b
             Enumeration addrs = ni.getInetAddresses();
a7067b
-            while ( addrs.hasMoreElements() )
a7067b
-            {
a7067b
-                 Object o = addrs.nextElement();
a7067b
-                 if ( o.getClass() == InetAddress.class ||
a7067b
-                     o.getClass() == Inet4Address.class ||
a7067b
-                     o.getClass() == Inet6Address.class )
a7067b
-                 {
a7067b
-                      InetAddress iaddr = (InetAddress) o;
a7067b
-                      if(o.getClass() == Inet6Address.class) {
a7067b
-                          supportsIPV6 = 1;
a7067b
-                          return true;
a7067b
-                      }
a7067b
-                 }
a7067b
+            while (addrs.hasMoreElements()) {
a7067b
+                Object o = addrs.nextElement();
a7067b
+                if (o.getClass() == InetAddress.class ||
a7067b
+                        o.getClass() == Inet4Address.class ||
a7067b
+                        o.getClass() == Inet6Address.class) {
a7067b
+                    InetAddress iaddr = (InetAddress) o;
a7067b
+                    if (o.getClass() == Inet6Address.class) {
a7067b
+                        supportsIPV6 = 1;
a7067b
+                        return true;
a7067b
+                    }
a7067b
+                }
a7067b
             }
a7067b
         }
a7067b
         supportsIPV6 = 0;
a7067b
# HG changeset patch
a7067b
# User "Endi S. Dewata" <edewata@redhat.com>
a7067b
# Date 1509154824 -7200
a7067b
#      Sat Oct 28 03:40:24 2017 +0200
a7067b
# Node ID ca2c2fcfaf207f87c3c69e493f2b30fd0a088e95
a7067b
# Parent  837c79476110ecd4bf6b507faad50edb9eed7e7e
a7067b
Fixed SocketBase.setClientCertNickname() exception handling.
a7067b
Previously the SocketBase.setClientCertNickname() would catch
a7067b
the original exception and throw a SocketException instead.
a7067b
The original stack trace was lost since SocketException does not
a7067b
support chaining.
a7067b
a7067b
The code has been modified to throw a RuntimeException instead
a7067b
and chain the original exception. This way the original stack
a7067b
trace can be preserved to help troubleshooting.
a7067b
a7067b
https://bugzilla.mozilla.org/show_bug.cgi?id=1408057
a7067b
a7067b
diff --git a/org/mozilla/jss/ssl/SocketBase.java b/org/mozilla/jss/ssl/SocketBase.java
a7067b
--- a/org/mozilla/jss/ssl/SocketBase.java
a7067b
+++ b/org/mozilla/jss/ssl/SocketBase.java
a7067b
@@ -4,17 +4,21 @@
a7067b
 
a7067b
 package org.mozilla.jss.ssl;
a7067b
 
a7067b
-import java.net.*;
a7067b
+import java.io.IOException;
a7067b
+import java.lang.reflect.Constructor;
a7067b
+import java.net.Inet4Address;
a7067b
+import java.net.Inet6Address;
a7067b
+import java.net.InetAddress;
a7067b
+import java.net.NetworkInterface;
a7067b
 import java.net.SocketException;
a7067b
-import java.io.*;
a7067b
-import java.io.IOException;
a7067b
-import java.util.Vector;
a7067b
+import java.net.UnknownHostException;
a7067b
 import java.util.Enumeration;
a7067b
-import java.lang.reflect.Constructor;
a7067b
-import org.mozilla.jss.util.Assert;
a7067b
+
a7067b
 import org.mozilla.jss.CryptoManager;
a7067b
 import org.mozilla.jss.crypto.ObjectNotFoundException;
a7067b
 import org.mozilla.jss.crypto.TokenException;
a7067b
+import org.mozilla.jss.crypto.X509Certificate;
a7067b
+import org.mozilla.jss.util.Assert;
a7067b
 
a7067b
 class SocketBase {
a7067b
 
a7067b
@@ -395,13 +399,18 @@
a7067b
      */
a7067b
     public void setClientCertNickname(String nick) throws SocketException {
a7067b
         try {
a7067b
-            setClientCert(CryptoManager.getInstance().findCertByNickname(nick));
a7067b
+            CryptoManager cm = CryptoManager.getInstance();
a7067b
+            X509Certificate cert = cm.findCertByNickname(nick);
a7067b
+            setClientCert(cert);
a7067b
+
a7067b
         } catch (CryptoManager.NotInitializedException nie) {
a7067b
-            throw new SocketException("CryptoManager not initialized");
a7067b
+            throw new RuntimeException(nie);
a7067b
+
a7067b
         } catch (ObjectNotFoundException onfe) {
a7067b
-            throw new SocketException("Object not found: " + onfe);
a7067b
+            throw new RuntimeException(onfe);
a7067b
+
a7067b
         } catch (TokenException te) {
a7067b
-            throw new SocketException("Token Exception: " + te);
a7067b
+            throw new RuntimeException(te);
a7067b
         }
a7067b
     }
a7067b