summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2014-03-10 19:32:48 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2014-03-10 19:32:48 +0000
commit28c889f6de4d9822050e5ce06d367e74b7feb8b4 (patch)
treecd8353b1e9866d073169ee3786560fe9c35b25fe /luni
parentefa075cb4c3d51560c12c7b3808e5e7e084b5808 (diff)
parent9f7c676c1937bdafce079cf02a67ac121296a335 (diff)
downloadlibcore-28c889f6de4d9822050e5ce06d367e74b7feb8b4.zip
libcore-28c889f6de4d9822050e5ce06d367e74b7feb8b4.tar.gz
libcore-28c889f6de4d9822050e5ce06d367e74b7feb8b4.tar.bz2
Merge "SSLSocketTest: test NPN/ALPN socket reuse"
Diffstat (limited to 'luni')
-rw-r--r--luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
index fa101f0..3316643 100644
--- a/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
+++ b/luni/src/test/java/libcore/javax/net/ssl/SSLSocketTest.java
@@ -22,6 +22,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Method;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
@@ -49,6 +50,7 @@ import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLParameters;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLProtocolException;
+import javax.net.ssl.SSLServerSocket;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
@@ -1197,6 +1199,81 @@ public class SSLSocketTest extends TestCase {
c.close();
}
+ public void test_SSLSocket_reusedNpnSocket() throws Exception {
+ if (StandardNames.IS_RI) {
+ // RI does not support NPN/ALPN
+ return;
+ }
+
+ byte[] npnProtocols = new byte[] {
+ 8, 'h', 't', 't', 'p', '/', '1', '.', '1'
+ };
+
+ final TestSSLContext c = TestSSLContext.create();
+ SSLSocket client = (SSLSocket) c.clientContext.getSocketFactory().createSocket();
+
+ // Reflection is used so this can compile on the RI
+ String expectedClassName = "com.android.org.conscrypt.OpenSSLSocketImpl";
+ Class<?> actualClass = client.getClass();
+ assertEquals(expectedClassName, actualClass.getName());
+ Method setNpnProtocols = actualClass.getMethod("setNpnProtocols", byte[].class);
+
+ ExecutorService executor = Executors.newSingleThreadExecutor();
+
+ // First connection with NPN set on client and server
+ {
+ setNpnProtocols.invoke(client, npnProtocols);
+ client.connect(new InetSocketAddress(c.host, c.port));
+
+ final SSLSocket server = (SSLSocket) c.serverSocket.accept();
+ assertEquals(expectedClassName, server.getClass().getName());
+ setNpnProtocols.invoke(server, npnProtocols);
+
+ Future<Void> future = executor.submit(new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ server.startHandshake();
+ return null;
+ }
+ });
+ client.startHandshake();
+
+ future.get();
+ client.close();
+ server.close();
+ }
+
+ // Second connection with client NPN already set on the SSL context, but
+ // without server NPN set.
+ {
+ SSLServerSocket serverSocket = (SSLServerSocket) c.serverContext
+ .getServerSocketFactory().createServerSocket(0);
+ InetAddress host = InetAddress.getLocalHost();
+ int port = serverSocket.getLocalPort();
+
+ client = (SSLSocket) c.clientContext.getSocketFactory().createSocket();
+ client.connect(new InetSocketAddress(host, port));
+
+ final SSLSocket server = (SSLSocket) serverSocket.accept();
+
+ Future<Void> future = executor.submit(new Callable<Void>() {
+ @Override
+ public Void call() throws Exception {
+ server.startHandshake();
+ return null;
+ }
+ });
+ client.startHandshake();
+
+ future.get();
+ client.close();
+ server.close();
+ serverSocket.close();
+ }
+
+ c.close();
+ }
+
public void test_SSLSocket_interrupt() throws Exception {
test_SSLSocket_interrupt_case(true, true);
test_SSLSocket_interrupt_case(true, false);