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());
}
use of javax.net.ssl.SSLServerSocket in project robovm by robovm.
the class SSLServerSocketTest method getSSLServerSocket.
private SSLServerSocket getSSLServerSocket() throws Exception {
SSLContext context = SSLContext.getInstance("TLS");
context.init(getKeyManagers(), null, null);
SSLServerSocket sss = (SSLServerSocket) context.getServerSocketFactory().createServerSocket();
return sss;
}
use of javax.net.ssl.SSLServerSocket in project robovm by robovm.
the class SSLServerSocketTest method test_EnabledProtocols.
/**
* @throws IOException
* javax.net.ssl.SSLServerSocket#getEnabledProtocols()
* javax.net.ssl.SSLServerSocket#setEnabledProtocols(String[] protocols)
*/
public void test_EnabledProtocols() throws Exception {
SSLServerSocket sss = getSSLServerSocket();
try {
sss.setEnabledProtocols(null);
} catch (IllegalArgumentException iae) {
//expected
}
String[] unsupportedProtocols = { "unsupported" };
try {
sss.setEnabledProtocols(unsupportedProtocols);
} catch (IllegalArgumentException iae) {
//expected
}
int count = sss.getSupportedProtocols().length;
assertTrue("No supported protocols", count > 0);
sss.setEnabledProtocols(sss.getSupportedProtocols());
String[] res = sss.getEnabledProtocols();
assertNotNull("NULL result", res);
assertTrue("no enabled protocols.", res.length == count);
}
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 HttpsURLConnectionTest method testSetSSLSocketFactory.
/**
* Tests possibility to set up the SSLSocketFactory
* to be used by HttpsURLConnection.
*/
public void testSetSSLSocketFactory() throws Throwable {
// create the SSLServerSocket which will be used by server side
SSLContext ctx = getContext();
SSLServerSocket ss = (SSLServerSocket) ctx.getServerSocketFactory().createServerSocket(0);
// create the HostnameVerifier to check hostname verification
TestHostnameVerifier hnv = new TestHostnameVerifier();
HttpsURLConnection.setDefaultHostnameVerifier(hnv);
// create HttpsURLConnection to be tested
URL url = new URL("https://localhost:" + ss.getLocalPort());
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
SSLSocketFactory socketFactory = (SSLSocketFactory) ctx.getSocketFactory();
connection.setSSLSocketFactory(socketFactory);
TestHostnameVerifier hnv_late = new TestHostnameVerifier();
// late initialization: should not be used for created connection
HttpsURLConnection.setDefaultHostnameVerifier(hnv_late);
// perform the interaction between the peers
SSLSocket peerSocket = (SSLSocket) doInteraction(connection, ss);
// check the connection state
checkConnectionStateParameters(connection, peerSocket);
// check the verification process
assertTrue("Hostname verification was not done", hnv.verified);
assertFalse("Hostname verification should not be done by this verifier", hnv_late.verified);
// check the used SSLSocketFactory
assertNotSame("Default SSLSocketFactory should not be used", HttpsURLConnection.getDefaultSSLSocketFactory(), connection.getSSLSocketFactory());
assertSame("Result differs from expected", socketFactory, connection.getSSLSocketFactory());
// should silently exit
connection.connect();
}
Aggregations