You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2013/11/23 12:09:04 UTC

svn commit: r1544769 - in /httpcomponents/httpclient/trunk: RELEASE_NOTES.txt httpclient/src/main/java/org/apache/http/conn/ssl/SSLConnectionSocketFactory.java httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java

Author: olegk
Date: Sat Nov 23 11:09:04 2013
New Revision: 1544769

URL: http://svn.apache.org/r1544769
Log:
HTTPCLIENT-1119: SNI support (Oracle Java 1.7+ only).
Contributed by Bruno Harbulot <bruno at distributedmatter.net>

Modified:
    httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
    httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLConnectionSocketFactory.java
    httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java

Modified: httpcomponents/httpclient/trunk/RELEASE_NOTES.txt
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/RELEASE_NOTES.txt?rev=1544769&r1=1544768&r2=1544769&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/RELEASE_NOTES.txt (original)
+++ httpcomponents/httpclient/trunk/RELEASE_NOTES.txt Sat Nov 23 11:09:04 2013
@@ -1,6 +1,9 @@
 Changes since 4.3.1
 -------------------
 
+* [HTTPCLIENT-1119] SNI support (Oracle Java 1.7+ only).
+  Contributed by Bruno Harbulot <bruno at distributedmatter.net>  
+
 * [HTTPCLIENT-1435] Fluent Executor ignores custom request properties.
   Contributed by Oleg Kalnichevski <olegk at apache.org>
 

Modified: httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLConnectionSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLConnectionSocketFactory.java?rev=1544769&r1=1544768&r2=1544769&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLConnectionSocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java/org/apache/http/conn/ssl/SSLConnectionSocketFactory.java Sat Nov 23 11:09:04 2013
@@ -34,6 +34,7 @@ import org.apache.http.protocol.HttpCont
 import org.apache.http.util.Args;
 import org.apache.http.util.TextUtils;
 
+import javax.net.SocketFactory;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLSocket;
 import java.io.IOException;
@@ -217,20 +218,8 @@ public class SSLConnectionSocketFactory 
     protected void prepareSocket(final SSLSocket socket) throws IOException {
     }
 
-    private void internalPrepareSocket(final SSLSocket socket) throws IOException {
-        if (supportedProtocols != null) {
-            socket.setEnabledProtocols(supportedProtocols);
-        }
-        if (supportedCipherSuites != null) {
-            socket.setEnabledCipherSuites(supportedCipherSuites);
-        }
-        prepareSocket(socket);
-    }
-
     public Socket createSocket(final HttpContext context) throws IOException {
-        final SSLSocket sock = (SSLSocket) this.socketfactory.createSocket();
-        internalPrepareSocket(sock);
-        return sock;
+        return SocketFactory.getDefault().createSocket();
     }
 
     public Socket connectSocket(
@@ -276,7 +265,13 @@ public class SSLConnectionSocketFactory 
                 target,
                 port,
                 true);
-        internalPrepareSocket(sslsock);
+        if (supportedProtocols != null) {
+            sslsock.setEnabledProtocols(supportedProtocols);
+        }
+        if (supportedCipherSuites != null) {
+            sslsock.setEnabledCipherSuites(supportedCipherSuites);
+        }
+        prepareSocket(sslsock);
         sslsock.startHandshake();
         verifyHostname(sslsock, target);
         return sslsock;

Modified: httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java?rev=1544769&r1=1544768&r2=1544769&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java (original)
+++ httpcomponents/httpclient/trunk/httpclient/src/test/java/org/apache/http/conn/ssl/TestSSLSocketFactory.java Sat Nov 23 11:09:04 2013
@@ -126,10 +126,10 @@ public class TestSSLSocketFactory extend
         final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
                 clientSSLContext, hostVerifier);
-        SSLSocket socket = (SSLSocket) socketFactory.createSocket(context);
+        final Socket socket = socketFactory.createSocket(context);
         final InetSocketAddress remoteAddress = this.localServer.getServiceAddress();
-        socket = (SSLSocket) socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
-        final SSLSession sslsession = socket.getSession();
+        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
+        final SSLSession sslsession = sslSocket.getSession();
 
         Assert.assertNotNull(sslsession);
         Assert.assertTrue(hostVerifier.isFired());
@@ -156,10 +156,10 @@ public class TestSSLSocketFactory extend
         final HttpContext context = new BasicHttpContext();
         final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(clientSSLContext, hostVerifier);
-        SSLSocket socket = (SSLSocket) socketFactory.createSocket(context);
+        final Socket socket = socketFactory.createSocket(context);
         final InetSocketAddress remoteAddress = this.localServer.getServiceAddress();
-        socket = (SSLSocket) socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
-        final SSLSession sslsession = socket.getSession();
+        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
+        final SSLSession sslsession = sslSocket.getSession();
 
         Assert.assertNotNull(sslsession);
         Assert.assertTrue(hostVerifier.isFired());
@@ -185,10 +185,10 @@ public class TestSSLSocketFactory extend
         final HttpContext context = new BasicHttpContext();
         final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(clientSSLContext, hostVerifier);
-        SSLSocket socket = (SSLSocket) socketFactory.createSocket(context);
+        final Socket socket = socketFactory.createSocket(context);
         final InetSocketAddress remoteAddress = this.localServer.getServiceAddress();
-        socket = (SSLSocket) socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
-        final SSLSession sslsession = socket.getSession();
+        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
+        final SSLSession sslsession = sslSocket.getSession();
 
         Assert.assertNotNull(sslsession);
         Assert.assertTrue(hostVerifier.isFired());
@@ -227,10 +227,10 @@ public class TestSSLSocketFactory extend
         final HttpContext context = new BasicHttpContext();
         final TestX509HostnameVerifier hostVerifier = new TestX509HostnameVerifier();
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(clientSSLContext, hostVerifier);
-        SSLSocket socket = (SSLSocket) socketFactory.createSocket(context);
+        final Socket socket = socketFactory.createSocket(context);
         final InetSocketAddress remoteAddress = this.localServer.getServiceAddress();
-        socket = (SSLSocket) socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
-        final SSLSession sslsession = socket.getSession();
+        final SSLSocket sslSocket = (SSLSocket) socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
+        final SSLSession sslsession = sslSocket.getSession();
 
         Assert.assertNotNull(sslsession);
         Assert.assertTrue(hostVerifier.isFired());
@@ -243,10 +243,6 @@ public class TestSSLSocketFactory extend
                 .loadTrustMaterial(keystore)
                 .loadKeyMaterial(keystore, "nopassword".toCharArray())
                 .build();
-        final SSLContext clientSSLContext = SSLContexts.custom()
-                .useProtocol("TLS")
-                .loadTrustMaterial(keystore)
-                .build();
 
         this.localServer = new LocalTestServer(serverSSLContext);
         this.localServer.registerDefaultHandlers();
@@ -260,7 +256,7 @@ public class TestSSLSocketFactory extend
         final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(defaultsslcontext,
                 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
 
-        final SSLSocket socket = (SSLSocket) socketFactory.createSocket(context);
+        final Socket socket = socketFactory.createSocket(context);
         final InetSocketAddress remoteAddress = this.localServer.getServiceAddress();
         socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
     }
@@ -295,7 +291,7 @@ public class TestSSLSocketFactory extend
                 sslcontext,
                 SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
 
-        final SSLSocket socket = (SSLSocket) socketFactory.createSocket(context);
+        final Socket socket = socketFactory.createSocket(context);
         final InetSocketAddress remoteAddress = this.localServer.getServiceAddress();
         socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
     }