Search in sources :

Example 46 with SSLEngine

use of javax.net.ssl.SSLEngine in project robovm by robovm.

the class SSLEngineTest method test_SSLEngine_setSSLParameters.

public void test_SSLEngine_setSSLParameters() throws Exception {
    TestSSLContext c = TestSSLContext.create();
    SSLEngine e = c.clientContext.createSSLEngine();
    String[] defaultCipherSuites = e.getEnabledCipherSuites();
    String[] defaultProtocols = e.getEnabledProtocols();
    String[] supportedCipherSuites = e.getSupportedCipherSuites();
    String[] supportedProtocols = e.getSupportedProtocols();
    {
        SSLParameters p = new SSLParameters();
        e.setSSLParameters(p);
        assertEquals(Arrays.asList(defaultCipherSuites), Arrays.asList(e.getEnabledCipherSuites()));
        assertEquals(Arrays.asList(defaultProtocols), Arrays.asList(e.getEnabledProtocols()));
    }
    {
        SSLParameters p = new SSLParameters(supportedCipherSuites, supportedProtocols);
        e.setSSLParameters(p);
        assertEquals(Arrays.asList(supportedCipherSuites), Arrays.asList(e.getEnabledCipherSuites()));
        assertEquals(Arrays.asList(supportedProtocols), Arrays.asList(e.getEnabledProtocols()));
    }
    {
        SSLParameters p = new SSLParameters();
        p.setNeedClientAuth(true);
        assertFalse(e.getNeedClientAuth());
        assertFalse(e.getWantClientAuth());
        e.setSSLParameters(p);
        assertTrue(e.getNeedClientAuth());
        assertFalse(e.getWantClientAuth());
        p.setWantClientAuth(true);
        assertTrue(e.getNeedClientAuth());
        assertFalse(e.getWantClientAuth());
        e.setSSLParameters(p);
        assertFalse(e.getNeedClientAuth());
        assertTrue(e.getWantClientAuth());
        p.setWantClientAuth(false);
        assertFalse(e.getNeedClientAuth());
        assertTrue(e.getWantClientAuth());
        e.setSSLParameters(p);
        assertFalse(e.getNeedClientAuth());
        assertFalse(e.getWantClientAuth());
    }
    c.close();
}
Also used : SSLParameters(javax.net.ssl.SSLParameters) SSLEngine(javax.net.ssl.SSLEngine)

Example 47 with SSLEngine

use of javax.net.ssl.SSLEngine in project robovm by robovm.

the class SSLEngineTest method test_SSLEngine_setEnabledCipherSuites.

public void test_SSLEngine_setEnabledCipherSuites() throws Exception {
    TestSSLContext c = TestSSLContext.create();
    SSLEngine e = c.clientContext.createSSLEngine();
    try {
        e.setEnabledCipherSuites(null);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    try {
        e.setEnabledCipherSuites(new String[1]);
        fail();
    } catch (IllegalArgumentException expected) {
    }
    try {
        e.setEnabledCipherSuites(new String[] { "Bogus" });
        fail();
    } catch (IllegalArgumentException expected) {
    }
    e.setEnabledCipherSuites(new String[0]);
    e.setEnabledCipherSuites(e.getEnabledCipherSuites());
    e.setEnabledCipherSuites(e.getSupportedCipherSuites());
    c.close();
}
Also used : SSLEngine(javax.net.ssl.SSLEngine)

Example 48 with SSLEngine

use of javax.net.ssl.SSLEngine in project robovm by robovm.

the class SSLEngineTest method test_SSLEngine_clientAuth.

public void test_SSLEngine_clientAuth() throws Exception {
    TestSSLContext c = TestSSLContext.create();
    SSLEngine e = c.clientContext.createSSLEngine();
    assertFalse(e.getWantClientAuth());
    assertFalse(e.getNeedClientAuth());
    // confirm turning one on by itself
    e.setWantClientAuth(true);
    assertTrue(e.getWantClientAuth());
    assertFalse(e.getNeedClientAuth());
    // confirm turning setting on toggles the other
    e.setNeedClientAuth(true);
    assertFalse(e.getWantClientAuth());
    assertTrue(e.getNeedClientAuth());
    // confirm toggling back
    e.setWantClientAuth(true);
    assertTrue(e.getWantClientAuth());
    assertFalse(e.getNeedClientAuth());
    // TODO Fix KnownFailure "init - invalid private key"
    TestSSLContext clientAuthContext = TestSSLContext.create(TestKeyStore.getClientCertificate(), TestKeyStore.getServer());
    TestSSLEnginePair p = TestSSLEnginePair.create(clientAuthContext, new TestSSLEnginePair.Hooks() {

        @Override
        void beforeBeginHandshake(SSLEngine client, SSLEngine server) {
            server.setWantClientAuth(true);
        }
    });
    assertConnected(p);
    assertNotNull(p.client.getSession().getLocalCertificates());
    TestKeyStore.assertChainLength(p.client.getSession().getLocalCertificates());
    TestSSLContext.assertClientCertificateChain(clientAuthContext.clientTrustManager, p.client.getSession().getLocalCertificates());
    clientAuthContext.close();
    c.close();
}
Also used : SSLEngine(javax.net.ssl.SSLEngine)

Example 49 with SSLEngine

use of javax.net.ssl.SSLEngine in project robovm by robovm.

the class SSLEngineTest method test_SSLEngine_getEnabledCipherSuites.

public void test_SSLEngine_getEnabledCipherSuites() throws Exception {
    TestSSLContext c = TestSSLContext.create();
    SSLEngine e = c.clientContext.createSSLEngine();
    String[] cipherSuites = e.getEnabledCipherSuites();
    StandardNames.assertValidCipherSuites(StandardNames.CIPHER_SUITES, cipherSuites);
    assertNotSame(cipherSuites, e.getEnabledCipherSuites());
    c.close();
}
Also used : SSLEngine(javax.net.ssl.SSLEngine)

Example 50 with SSLEngine

use of javax.net.ssl.SSLEngine in project robovm by robovm.

the class SSLEngineTest method test_SSLEngine_getSupportedCipherSuites_names.

public void test_SSLEngine_getSupportedCipherSuites_names() throws Exception {
    TestSSLContext c = TestSSLContext.create();
    SSLEngine e = c.clientContext.createSSLEngine();
    String[] cipherSuites = e.getSupportedCipherSuites();
    StandardNames.assertSupportedCipherSuites(StandardNames.CIPHER_SUITES_SSLENGINE, cipherSuites);
    assertNotSame(cipherSuites, e.getSupportedCipherSuites());
    c.close();
}
Also used : SSLEngine(javax.net.ssl.SSLEngine)

Aggregations

SSLEngine (javax.net.ssl.SSLEngine)494 IOException (java.io.IOException)97 SSLContext (javax.net.ssl.SSLContext)97 ByteBuffer (java.nio.ByteBuffer)91 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)75 SSLException (javax.net.ssl.SSLException)71 Test (org.junit.Test)64 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)54 SslHandler (io.netty.handler.ssl.SslHandler)52 SSLEngineResult (javax.net.ssl.SSLEngineResult)50 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)47 MethodSource (org.junit.jupiter.params.provider.MethodSource)44 SSLParameters (javax.net.ssl.SSLParameters)43 InetSocketAddress (java.net.InetSocketAddress)42 KeyManagementException (java.security.KeyManagementException)42 ReadOnlyBufferException (java.nio.ReadOnlyBufferException)35 KeyStore (java.security.KeyStore)28 Test (org.junit.jupiter.api.Test)22 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)21 Socket (java.net.Socket)21