use of javax.net.ssl.SSLSocket in project robovm by robovm.
the class SSLSocketTest method test_SSLSocket_interrupt_read.
/**
* b/7014266 Test to confirm that an SSLSocket.close() on one
* thread will interupt another thread blocked reading on the same
* socket.
*/
public void test_SSLSocket_interrupt_read() throws Exception {
TestSSLContext c = TestSSLContext.create();
final Socket underlying = new Socket(c.host, c.port);
final SSLSocket wrapping = (SSLSocket) c.clientContext.getSocketFactory().createSocket(underlying, c.host.getHostName(), c.port, false);
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Void> clientFuture = executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
wrapping.startHandshake();
assertFalse(StandardNames.IS_RI);
wrapping.setSoTimeout(5 * 1000);
assertEquals(-1, wrapping.getInputStream().read());
} catch (Exception e) {
assertTrue(StandardNames.IS_RI);
}
return null;
}
});
executor.shutdown();
SSLSocket server = (SSLSocket) c.serverSocket.accept();
server.startHandshake();
wrapping.close();
clientFuture.get();
server.close();
}
use of javax.net.ssl.SSLSocket in project robovm by robovm.
the class SSLSocketTest method test_SSLSocket_getSupportedCipherSuites_names.
public void test_SSLSocket_getSupportedCipherSuites_names() throws Exception {
SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket ssl = (SSLSocket) sf.createSocket();
String[] cipherSuites = ssl.getSupportedCipherSuites();
StandardNames.assertSupportedCipherSuites(StandardNames.CIPHER_SUITES, cipherSuites);
assertNotSame(cipherSuites, ssl.getSupportedCipherSuites());
}
use of javax.net.ssl.SSLSocket in project robovm by robovm.
the class SSLSocketTest method test_SSLSocket_untrustedServer.
public void test_SSLSocket_untrustedServer() throws Exception {
TestSSLContext c = TestSSLContext.create(TestKeyStore.getClientCA2(), TestKeyStore.getServer());
SSLSocket client = (SSLSocket) c.clientContext.getSocketFactory().createSocket(c.host, c.port);
final SSLSocket server = (SSLSocket) c.serverSocket.accept();
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Void> future = executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
server.startHandshake();
assertFalse(StandardNames.IS_RI);
} catch (SSLHandshakeException expected) {
assertTrue(StandardNames.IS_RI);
}
return null;
}
});
executor.shutdown();
try {
client.startHandshake();
fail();
} catch (SSLHandshakeException expected) {
assertTrue(expected.getCause() instanceof CertificateException);
}
client.close();
server.close();
future.get();
}
use of javax.net.ssl.SSLSocket in project robovm by robovm.
the class SSLSocketTest method test_SSLSocket_startHandshake_noKeyStore.
public void test_SSLSocket_startHandshake_noKeyStore() throws Exception {
TestSSLContext c = TestSSLContext.create(null, null, null, null, null, null, null, null, SSLContext.getDefault(), SSLContext.getDefault());
SSLSocket client = (SSLSocket) c.clientContext.getSocketFactory().createSocket(c.host, c.port);
// RI used to throw SSLException on accept, now throws on startHandshake
if (StandardNames.IS_RI) {
final SSLSocket server = (SSLSocket) c.serverSocket.accept();
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Void> future = executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
server.startHandshake();
fail();
} catch (SSLHandshakeException expected) {
}
return null;
}
});
executor.shutdown();
try {
client.startHandshake();
fail();
} catch (SSLHandshakeException expected) {
}
future.get();
server.close();
} else {
try {
c.serverSocket.accept();
fail();
} catch (SSLException expected) {
}
}
client.close();
c.close();
}
use of javax.net.ssl.SSLSocket in project robovm by robovm.
the class SSLSocketTest method test_SSLSocket_reusedNpnSocket.
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();
}
Aggregations