From acca0090fbf1ee95f98c6bdc975a1ffbea2a592d Mon Sep 17 00:00:00 2001 From: Adam Vartanian Date: Tue, 31 Jul 2018 16:51:45 +0100 Subject: Clarify which methods return connected sockets Some methods in SSLCertificateSocketFactory return connected sockets and some return unconnected sockets. Be explicit in each method's documentation about whether it returns a connected or unconnected socket. Bug: 37618511 Test: cts -m CtsNetTestCases -t android.net.cts.SSLCertificateSocketFactoryTest Change-Id: Ia9c6c8bec15a2d3fbd0d86f8accff13627c79565 --- .../android/net/SSLCertificateSocketFactory.java | 30 ++++++++++++++++------ 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/core/java/android/net/SSLCertificateSocketFactory.java b/core/java/android/net/SSLCertificateSocketFactory.java index a7aa380214d5..259eefe815f0 100644 --- a/core/java/android/net/SSLCertificateSocketFactory.java +++ b/core/java/android/net/SSLCertificateSocketFactory.java @@ -68,10 +68,14 @@ import javax.net.ssl.X509TrustManager; * use {@link InetAddress} or which return an unconnected socket, you MUST * verify the server's identity yourself to ensure a secure connection.

* - *

One way to verify the server's identity is to use + *

The recommended way to verify the server's identity is to use * {@link HttpsURLConnection#getDefaultHostnameVerifier()} to get a * {@link HostnameVerifier} to verify the certificate hostname. * + *

Warning: Some methods on this class return connected sockets and some return + * unconnected sockets. For the methods that return connected sockets, setting + * connection- or handshake-related properties on those sockets will have no effect. + * *

On development devices, "setprop socket.relaxsslcheck yes" bypasses all * SSL certificate and hostname checks for testing purposes. This setting * requires root access. @@ -437,8 +441,10 @@ public class SSLCertificateSocketFactory extends SSLSocketFactory { /** * {@inheritDoc} * - *

This method verifies the peer's certificate hostname after connecting - * (unless created with {@link #getInsecure(int, SSLSessionCache)}). + *

By default, this method returns a connected socket and verifies the peer's + * certificate hostname after connecting; if this instance was created with + * {@link #getInsecure(int, SSLSessionCache)}, it returns a socket that is not connected + * instead. */ @Override public Socket createSocket(Socket k, String host, int port, boolean close) throws IOException { @@ -454,7 +460,7 @@ public class SSLCertificateSocketFactory extends SSLSocketFactory { } /** - * Creates a new socket which is not connected to any remote host. + * Creates a new socket which is not connected to any remote host. * You must use {@link Socket#connect} to connect the socket. * *

Warning: Hostname verification is not performed @@ -474,6 +480,8 @@ public class SSLCertificateSocketFactory extends SSLSocketFactory { /** * {@inheritDoc} * + *

This method returns a socket that is not connected. + * *

Warning: Hostname verification is not performed * with this method. You MUST verify the server's identity after connecting * the socket to avoid man-in-the-middle attacks.

@@ -493,6 +501,8 @@ public class SSLCertificateSocketFactory extends SSLSocketFactory { /** * {@inheritDoc} * + *

This method returns a socket that is not connected. + * *

Warning: Hostname verification is not performed * with this method. You MUST verify the server's identity after connecting * the socket to avoid man-in-the-middle attacks.

@@ -510,8 +520,10 @@ public class SSLCertificateSocketFactory extends SSLSocketFactory { /** * {@inheritDoc} * - *

This method verifies the peer's certificate hostname after connecting - * (unless created with {@link #getInsecure(int, SSLSessionCache)}). + *

By default, this method returns a connected socket and verifies the peer's + * certificate hostname after connecting; if this instance was created with + * {@link #getInsecure(int, SSLSessionCache)}, it returns a socket that is not connected + * instead. */ @Override public Socket createSocket(String host, int port, InetAddress localAddr, int localPort) @@ -531,8 +543,10 @@ public class SSLCertificateSocketFactory extends SSLSocketFactory { /** * {@inheritDoc} * - *

This method verifies the peer's certificate hostname after connecting - * (unless created with {@link #getInsecure(int, SSLSessionCache)}). + *

By default, this method returns a connected socket and verifies the peer's + * certificate hostname after connecting; if this instance was created with + * {@link #getInsecure(int, SSLSessionCache)}, it returns a socket that is not connected + * instead. */ @Override public Socket createSocket(String host, int port) throws IOException { -- cgit v1.2.3-59-g8ed1b