use of org.conscrypt.NativeCrypto.SSLHandshakeCallbacks 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 org.conscrypt.NativeCrypto.SSLHandshakeCallbacks 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 org.conscrypt.NativeCrypto.SSLHandshakeCallbacks in project robovm by robovm.
the class NativeCryptoTest method test_i2d_SSL_SESSION.
public void test_i2d_SSL_SESSION() throws Exception {
try {
NativeCrypto.i2d_SSL_SESSION(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[] b = NativeCrypto.i2d_SSL_SESSION(session);
assertNotNull(b);
long session2 = NativeCrypto.d2i_SSL_SESSION(b);
assertTrue(session2 != NULL);
// Make sure d2i_SSL_SESSION retores SSL_SESSION_cipher value http://b/7091840
assertTrue(NativeCrypto.SSL_SESSION_cipher(session2) != null);
assertEquals(NativeCrypto.SSL_SESSION_cipher(session), NativeCrypto.SSL_SESSION_cipher(session2));
NativeCrypto.SSL_SESSION_free(session2);
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 org.conscrypt.NativeCrypto.SSLHandshakeCallbacks in project robovm by robovm.
the class NativeCryptoTest method test_SSL_interrupt.
public void test_SSL_interrupt() throws Exception {
// SSL_interrupt is a rare case that tolerates a null SSL argument
NativeCrypto.SSL_interrupt(NULL);
// also works without handshaking
{
long c = NativeCrypto.SSL_CTX_new();
long s = NativeCrypto.SSL_new(c);
NativeCrypto.SSL_interrupt(s);
NativeCrypto.SSL_free(s);
NativeCrypto.SSL_CTX_free(c);
}
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 {
NativeCrypto.SSL_read(s, fd, callback, new byte[1], 0, 1, 0);
super.afterHandshake(session, s, c, sock, fd, callback);
}
};
Hooks sHooks = new ServerHooks(getServerPrivateKey(), getServerCertificates()) {
@Override
public void afterHandshake(long session, final long s, long c, Socket sock, FileDescriptor fd, SSLHandshakeCallbacks callback) throws Exception {
new Thread() {
public void run() {
try {
Thread.sleep(1 * 1000);
NativeCrypto.SSL_interrupt(s);
} catch (Exception e) {
}
}
}.start();
assertEquals(-1, NativeCrypto.SSL_read(s, fd, callback, new byte[1], 0, 1, 0));
super.afterHandshake(session, s, c, sock, fd, callback);
}
};
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 org.conscrypt.NativeCrypto.SSLHandshakeCallbacks in project robovm by robovm.
the class NativeCryptoTest method test_SSL_SESSION_cipher.
public void test_SSL_SESSION_cipher() throws Exception {
try {
NativeCrypto.SSL_SESSION_cipher(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 {
String a = NativeCrypto.SSL_SESSION_cipher(session);
assertTrue(NativeCrypto.OPENSSL_TO_STANDARD_CIPHER_SUITES.containsKey(a));
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);
}
Aggregations