use of javax.net.ssl.SSLServerSocket in project robovm by robovm.
the class HttpsURLConnectionTest method testConsequentProxyConnection.
/**
* Tests HTTPS connection process made through the proxy server.
* 2 HTTPS connections are opened for one URL. For the first time
* the connection is opened through one proxy,
* for the second time through another.
*/
public void testConsequentProxyConnection() throws Throwable {
// setting up the properties pointing to the key/trust stores
setUpStoreProperties();
// create the SSLServerSocket which will be used by server side
ServerSocket ss = new ServerSocket(0);
// create the HostnameVerifier to check that Hostname verification
// is done
TestHostnameVerifier hnv = new TestHostnameVerifier();
HttpsURLConnection.setDefaultHostnameVerifier(hnv);
// create HttpsURLConnection to be tested
URL url = new URL("https://requested.host:55555/requested.data");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", ss.getLocalPort())));
connection.setSSLSocketFactory(getContext().getSocketFactory());
// perform the interaction between the peers and check the results
SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
checkConnectionStateParameters(connection, peerSocket);
// create another SSLServerSocket which will be used by server side
ss = new ServerSocket(0);
connection = (HttpsURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", ss.getLocalPort())));
connection.setSSLSocketFactory(getContext().getSocketFactory());
// perform the interaction between the peers and check the results
peerSocket = (SSLSocket) doInteraction(connection, ss);
checkConnectionStateParameters(connection, peerSocket);
}
use of javax.net.ssl.SSLServerSocket in project robovm by robovm.
the class HttpsURLConnectionTest method testProxyAuthConnection.
/**
* Tests HTTPS connection process made through the proxy server.
* Proxy server needs authentication.
*/
public void testProxyAuthConnection() throws Throwable {
// setting up the properties pointing to the key/trust stores
setUpStoreProperties();
// create the SSLServerSocket which will be used by server side
ServerSocket ss = new ServerSocket(0);
// create the HostnameVerifier to check that Hostname verification
// is done
TestHostnameVerifier hnv = new TestHostnameVerifier();
HttpsURLConnection.setDefaultHostnameVerifier(hnv);
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("user", "password".toCharArray());
}
});
// create HttpsURLConnection to be tested
URL url = new URL("https://requested.host:55555/requested.data");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", ss.getLocalPort())));
connection.setSSLSocketFactory(getContext().getSocketFactory());
// perform the interaction between the peers and check the results
SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
checkConnectionStateParameters(connection, peerSocket);
// should silently exit
connection.connect();
}
use of javax.net.ssl.SSLServerSocket 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();
}
use of javax.net.ssl.SSLServerSocket in project robovm by robovm.
the class SSLServerSocketTest method test_getSupportedProtocols.
/**
* @throws IOException
* javax.net.ssl.SSLServerSocket#getSupportedProtocols()
*/
public void test_getSupportedProtocols() throws Exception {
SSLServerSocket sss = getSSLServerSocket();
String[] res = sss.getSupportedCipherSuites();
assertNotNull("NULL result", res);
assertTrue("no supported protocols available.", res.length > 0);
}
use of javax.net.ssl.SSLServerSocket in project robovm by robovm.
the class SSLServerSocketTest method test_WantClientAuth.
/**
* @throws IOException
* javax.net.ssl.SSLServerSocket#setWantClientAuth(boolean want)
* javax.net.ssl.SSLServerSocket#getWantClientAuthCreation()
*/
public void test_WantClientAuth() throws Exception {
SSLServerSocket sss = getSSLServerSocket();
sss.setWantClientAuth(true);
assertTrue(sss.getWantClientAuth());
sss.setWantClientAuth(false);
assertFalse(sss.getWantClientAuth());
}
Aggregations