Uploaded image for project: 'HttpComponents HttpClient'
  1. HttpComponents HttpClient
  2. HTTPCLIENT-1346

SSL handshake exceptions are hidden from application

    XMLWordPrintableJSON

Details

    Description

      When the SSL handshake fails for some reason, (e.g. TCP connection reset, socket read timeout, no common cipher suite found, expired certificate, untrusted certificate, server sends non-SSL garbage, etc.), all the application sees is "javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated" (without any cause chain). This is rather unhelpful for troubleshooting SSL errors.

      According to the SSLSocket Javadocs, the SSL handshake can be initiated in three ways: calling startHandshake(), attempting to read or write data, or calling getSession(). The first two of these throw appropriate exceptions on failure (usually with cause chains indicating the root cause), while the third just returns a special session handshake with invalid ciphersuite SSL_NULL_WITH_NULL_NULL (and the actual cause of handshake failure is lost).

      Currently org.apache.http.conn.ssl.SSLSocketFactory uses the third approach (and does not even check for the invalid ciphersuite).

      Proposed fix: add call "sslsock.startHandshake();" after call to prepareSocket but before hostnameVerifier (which calls getSession). This requires also one-line change to TestSSLSocketFactory.java (change SSLPeerUnverifiedException to SSLHandshakeException).

      I tested this fix with five different cases (TCP connection reset, socket read timeout, expired certificate, self-signed certificate, and non-SSL server), and in all five cases, I now get a reasonably correct exception text (and a cause chain).

      Attachments

        1. httpclient-1346-for-4.3-alpha1.patch
          2 kB
          Pasi Eronen
        2. httpclient-1346-for-4.2.3.patch
          2 kB
          Pasi Eronen

        Activity

          People

            Unassigned Unassigned
            peronen Pasi Eronen
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: