Skip to content

Commit b0d4fb7

Browse files
committed
Merge pull request android-async-http#819 from nullEuro/patch-1
Make SecureSocketFactory verify hostnames
2 parents 69ec185 + 0861aad commit b0d4fb7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sample/src/main/java/com/loopj/android/http/sample/util/SecureSocketFactory.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.security.cert.X509Certificate;
4646

4747
import javax.net.ssl.SSLContext;
48+
import javax.net.ssl.SSLSocket;
4849
import javax.net.ssl.TrustManager;
4950
import javax.net.ssl.X509TrustManager;
5051

@@ -166,7 +167,12 @@ public Socket createSocket(Socket socket, String host, int port, boolean autoClo
166167
throws IOException {
167168

168169
injectHostname(socket, host);
169-
return sslCtx.getSocketFactory().createSocket(socket, host, port, autoClose);
170+
Socket sslSocket = sslCtx.getSocketFactory().createSocket(socket, host, port, autoClose);
171+
172+
// throw an exception if the hostname does not match the certificate
173+
getHostnameVerifier().verify(host, (SSLSocket) sslSocket);
174+
175+
return sslSocket;
170176
}
171177

172178
@Override

0 commit comments

Comments
 (0)