hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1528447 - in /httpcomponents/httpclient/trunk/httpclient/src: main/java-deprecated/org/apache/http/conn/ssl/ main/java/org/apache/http/conn/ssl/ test/java/org/apache/http/conn/ssl/
Date Wed, 02 Oct 2013 12:41:38 GMT
Author: olegk
Date: Wed Oct  2 12:41:38 2013
New Revision: 1528447

URL: http://svn.apache.org/r1528447
Log:
Ensure X509HostnameVerifier is never null

Modified:
    httpcomponents/httpclient/trunk/httpclient/src/main/java-deprecated/org/apache/http/conn/ssl/SSLSocketFactory.java
    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/httpclient/src/main/java-deprecated/org/apache/http/conn/ssl/SSLSocketFactory.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpclient/trunk/httpclient/src/main/java-deprecated/org/apache/http/conn/ssl/SSLSocketFactory.java?rev=1528447&r1=1528446&r2=1528447&view=diff
==============================================================================
--- httpcomponents/httpclient/trunk/httpclient/src/main/java-deprecated/org/apache/http/conn/ssl/SSLSocketFactory.java
(original)
+++ httpcomponents/httpclient/trunk/httpclient/src/main/java-deprecated/org/apache/http/conn/ssl/SSLSocketFactory.java
Wed Oct  2 12:41:38 2013
@@ -361,11 +361,10 @@ public class SSLSocketFactory implements
             final String[] supportedProtocols,
             final String[] supportedCipherSuites,
             final X509HostnameVerifier hostnameVerifier) {
-        Args.notNull(socketfactory, "SSL socket factory");
-        this.socketfactory = socketfactory;
+        this.socketfactory = Args.notNull(socketfactory, "SSL socket factory");
         this.supportedProtocols = supportedProtocols;
         this.supportedCipherSuites = supportedCipherSuites;
-        this.hostnameVerifier = hostnameVerifier;
+        this.hostnameVerifier = hostnameVerifier != null ? hostnameVerifier : BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
         this.nameResolver = null;
     }
 
@@ -556,15 +555,13 @@ public class SSLSocketFactory implements
     }
 
     private void verifyHostname(final SSLSocket sslsock, final String hostname) throws IOException
{
-        if (this.hostnameVerifier != null) {
-            try {
-                this.hostnameVerifier.verify(hostname, sslsock);
-                // verifyHostName() didn't blowup - good!
-            } catch (final IOException iox) {
-                // close the socket before re-throwing the exception
-                try { sslsock.close(); } catch (final Exception x) { /*ignore*/ }
-                throw iox;
-            }
+        try {
+            this.hostnameVerifier.verify(hostname, sslsock);
+            // verifyHostName() didn't blowup - good!
+        } catch (final IOException iox) {
+            // close the socket before re-throwing the exception
+            try { sslsock.close(); } catch (final Exception x) { /*ignore*/ }
+            throw iox;
         }
     }
 

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=1528447&r1=1528446&r2=1528447&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
Wed Oct  2 12:41:38 2013
@@ -201,11 +201,10 @@ public class SSLConnectionSocketFactory 
             final String[] supportedProtocols,
             final String[] supportedCipherSuites,
             final X509HostnameVerifier hostnameVerifier) {
-        Args.notNull(socketfactory, "SSL socket factory");
-        this.socketfactory = socketfactory;
+        this.socketfactory = Args.notNull(socketfactory, "SSL socket factory");
         this.supportedProtocols = supportedProtocols;
         this.supportedCipherSuites = supportedCipherSuites;
-        this.hostnameVerifier = hostnameVerifier;
+        this.hostnameVerifier = hostnameVerifier != null ? hostnameVerifier : BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
     }
 
     /**
@@ -283,16 +282,18 @@ public class SSLConnectionSocketFactory 
         return sslsock;
     }
 
+    X509HostnameVerifier getHostnameVerifier() {
+        return this.hostnameVerifier;
+    }
+
     private void verifyHostname(final SSLSocket sslsock, final String hostname) throws IOException
{
-        if (this.hostnameVerifier != null) {
-            try {
-                this.hostnameVerifier.verify(hostname, sslsock);
-                // verifyHostName() didn't blowup - good!
-            } catch (final IOException iox) {
-                // close the socket before re-throwing the exception
-                try { sslsock.close(); } catch (final Exception x) { /*ignore*/ }
-                throw iox;
-            }
+        try {
+            this.hostnameVerifier.verify(hostname, sslsock);
+            // verifyHostName() didn't blowup - good!
+        } catch (final IOException iox) {
+            // close the socket before re-throwing the exception
+            try { sslsock.close(); } catch (final Exception x) { /*ignore*/ }
+            throw iox;
         }
     }
 

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=1528447&r1=1528446&r2=1528447&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
Wed Oct  2 12:41:38 2013
@@ -300,4 +300,12 @@ public class TestSSLSocketFactory extend
         socketFactory.connectSocket(0, socket, host, remoteAddress, null, context);
     }
 
+    @Test
+    public void testDefaultHostnameVerifier() throws Exception {
+        final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(
+                SSLContexts.createDefault(),
+                null);
+        Assert.assertNotNull(socketFactory.getHostnameVerifier());
+    }
+
 }



Mime
View raw message