use of java.net.ServerSocket in project robovm by robovm.
the class NativeCryptoTest method test_SSL_do_handshake_with_channel_id_not_enabled_by_client.
public void test_SSL_do_handshake_with_channel_id_not_enabled_by_client() throws Exception {
initChannelIdKey();
// Client does not use TLS Channel ID when the server has the extension enabled/offered.
final ServerSocket listener = new ServerSocket(0);
Hooks cHooks = new Hooks();
cHooks.channelIdPrivateKey = null;
ServerHooks sHooks = new ServerHooks(getServerPrivateKey(), getServerCertificates());
sHooks.channelIdEnabled = true;
Future<TestSSLHandshakeCallbacks> client = handshake(listener, 0, true, cHooks, null, null);
Future<TestSSLHandshakeCallbacks> server = handshake(listener, 0, false, sHooks, null, null);
TestSSLHandshakeCallbacks clientCallback = client.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
TestSSLHandshakeCallbacks serverCallback = server.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
assertTrue(clientCallback.verifyCertificateChainCalled);
assertEqualCertificateChains(getServerCertificates(), clientCallback.asn1DerEncodedCertificateChain);
assertEquals("RSA", clientCallback.authMethod);
assertFalse(serverCallback.verifyCertificateChainCalled);
assertFalse(clientCallback.clientCertificateRequestedCalled);
assertFalse(serverCallback.clientCertificateRequestedCalled);
assertTrue(clientCallback.handshakeCompletedCalled);
assertTrue(serverCallback.handshakeCompletedCalled);
assertNull(sHooks.channelIdAfterHandshakeException);
assertNull(sHooks.channelIdAfterHandshake);
}
use of java.net.ServerSocket in project robovm by robovm.
the class NativeCryptoTest method test_SSL_SESSION_session_id.
public void test_SSL_SESSION_session_id() throws Exception {
try {
NativeCrypto.SSL_SESSION_session_id(NULL);
fail();
} catch (NullPointerException expected) {
}
final ServerSocket listener = new ServerSocket(0);
Hooks cHooks = new Hooks() {
@Override
public void afterHandshake(long session, long s, long c, Socket sock, FileDescriptor fd, SSLHandshakeCallbacks callback) throws Exception {
byte[] id = NativeCrypto.SSL_SESSION_session_id(session);
assertNotNull(id);
assertEquals(32, id.length);
super.afterHandshake(session, s, c, sock, fd, callback);
}
};
Hooks sHooks = new ServerHooks(getServerPrivateKey(), getServerCertificates());
Future<TestSSLHandshakeCallbacks> client = handshake(listener, 0, true, cHooks, null, null);
Future<TestSSLHandshakeCallbacks> server = handshake(listener, 0, false, sHooks, null, null);
client.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
server.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
use of java.net.ServerSocket in project robovm by robovm.
the class NativeCryptoTest method test_SSL_SESSION_get_time.
public void test_SSL_SESSION_get_time() throws Exception {
try {
NativeCrypto.SSL_SESSION_get_time(NULL);
fail();
} catch (NullPointerException expected) {
}
final ServerSocket listener = new ServerSocket(0);
{
Hooks cHooks = new Hooks() {
@Override
public void afterHandshake(long session, long s, long c, Socket sock, FileDescriptor fd, SSLHandshakeCallbacks callback) throws Exception {
long time = NativeCrypto.SSL_SESSION_get_time(session);
assertTrue(time != 0);
assertTrue(time < System.currentTimeMillis());
super.afterHandshake(session, s, c, sock, fd, callback);
}
};
Hooks sHooks = new ServerHooks(getServerPrivateKey(), getServerCertificates());
Future<TestSSLHandshakeCallbacks> client = handshake(listener, 0, true, cHooks, null, null);
Future<TestSSLHandshakeCallbacks> server = handshake(listener, 0, false, sHooks, null, null);
client.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
server.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
}
}
use of java.net.ServerSocket in project robovm by robovm.
the class NativeCryptoTest method test_SSL_do_handshake_server_timeout.
public void test_SSL_do_handshake_server_timeout() throws Exception {
// server timeout
final ServerSocket listener = new ServerSocket(0);
Socket clientSocket = null;
try {
Hooks cHooks = new Hooks();
Hooks sHooks = new ServerHooks(getServerPrivateKey(), getServerCertificates());
Future<TestSSLHandshakeCallbacks> client = handshake(listener, -1, true, cHooks, null, null);
Future<TestSSLHandshakeCallbacks> server = handshake(listener, 1, false, sHooks, null, null);
clientSocket = client.get(TIMEOUT_SECONDS, TimeUnit.SECONDS).getSocket();
server.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
fail();
} catch (ExecutionException expected) {
assertEquals(SocketTimeoutException.class, expected.getCause().getClass());
} finally {
// Manually close peer socket when testing timeout
IoUtils.closeQuietly(clientSocket);
}
}
use of java.net.ServerSocket in project robovm by robovm.
the class NativeCryptoTest method test_SSL_do_handshake_missing_required_certificate.
public void test_SSL_do_handshake_missing_required_certificate() throws Exception {
// required client certificate negative case
final ServerSocket listener = new ServerSocket(0);
try {
Hooks cHooks = new Hooks();
Hooks sHooks = new ServerHooks(getServerPrivateKey(), getServerCertificates()) {
@Override
public long beforeHandshake(long c) throws SSLException {
long s = super.beforeHandshake(c);
NativeCrypto.SSL_set_client_CA_list(s, getCaPrincipals());
NativeCrypto.SSL_set_verify(s, NativeCrypto.SSL_VERIFY_PEER | NativeCrypto.SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
return s;
}
};
Future<TestSSLHandshakeCallbacks> client = handshake(listener, 0, true, cHooks, null, null);
Future<TestSSLHandshakeCallbacks> server = handshake(listener, 0, false, sHooks, null, null);
server.get(TIMEOUT_SECONDS, TimeUnit.SECONDS);
fail();
} catch (ExecutionException expected) {
assertEquals(SSLProtocolException.class, expected.getCause().getClass());
}
}
Aggregations