Blame SOURCES/jss-ObjectNotFoundException-message.patch

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