Search in sources :

Example 1 with SSLHandshakeCallbacks

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);
}
Also used : SSLHandshakeCallbacks(org.conscrypt.NativeCrypto.SSLHandshakeCallbacks) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) FileDescriptor(java.io.FileDescriptor)

Example 2 with SSLHandshakeCallbacks

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);
    }
}
Also used : SSLHandshakeCallbacks(org.conscrypt.NativeCrypto.SSLHandshakeCallbacks) Future(java.util.concurrent.Future) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) FileDescriptor(java.io.FileDescriptor) SocketTimeoutException(java.net.SocketTimeoutException) SSLProtocolException(javax.net.ssl.SSLProtocolException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) ExecutionException(java.util.concurrent.ExecutionException) SSLException(javax.net.ssl.SSLException)

Example 3 with SSLHandshakeCallbacks

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);
}
Also used : SSLHandshakeCallbacks(org.conscrypt.NativeCrypto.SSLHandshakeCallbacks) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) FileDescriptor(java.io.FileDescriptor)

Example 4 with SSLHandshakeCallbacks

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);
}
Also used : SSLHandshakeCallbacks(org.conscrypt.NativeCrypto.SSLHandshakeCallbacks) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) FileDescriptor(java.io.FileDescriptor) SocketTimeoutException(java.net.SocketTimeoutException) SSLProtocolException(javax.net.ssl.SSLProtocolException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) ExecutionException(java.util.concurrent.ExecutionException) SSLException(javax.net.ssl.SSLException)

Example 5 with SSLHandshakeCallbacks

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);
}
Also used : SSLHandshakeCallbacks(org.conscrypt.NativeCrypto.SSLHandshakeCallbacks) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) FileDescriptor(java.io.FileDescriptor)

Aggregations

FileDescriptor (java.io.FileDescriptor)15 ServerSocket (java.net.ServerSocket)15 Socket (java.net.Socket)15 SSLHandshakeCallbacks (org.conscrypt.NativeCrypto.SSLHandshakeCallbacks)15 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)4 SSLException (javax.net.ssl.SSLException)4 SocketTimeoutException (java.net.SocketTimeoutException)3 CertificateException (java.security.cert.CertificateException)3 SSLProtocolException (javax.net.ssl.SSLProtocolException)3 Future (java.util.concurrent.Future)2