summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2014-03-10 11:47:40 -0700
committerKenny Root <kroot@google.com>2014-03-10 12:16:24 -0700
commit9f7c676c1937bdafce079cf02a67ac121296a335 (patch)
treee24c822b29c82b66c1ae2a9cc0d3d4316fcb3d41 /luni
parente73215161ba2089ebc8ff22bfaf07b1585705915 (diff)
downloadlibcore-9f7c676c1937bdafce079cf02a67ac121296a335.zip
libcore-9f7c676c1937bdafce079cf02a67ac121296a335.tar.gz
libcore-9f7c676c1937bdafce079cf02a67ac121296a335.tar.bz2
SSLSocketTest: test NPN/ALPN socket reuse
Bug: https://code.google.com/p/android/issues/detail?id=66562 Change-Id: I393b281e3a67a621b51cb124c9275e664091d424
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);