Search in sources :

Example 1 with DefaultTlsContextFactory

use of org.mule.runtime.module.tls.internal.DefaultTlsContextFactory in project mule by mulesoft.

the class DefaultTlsContextFactoryObjectFactory method doGetObject.

@Override
public DefaultTlsContextFactory doGetObject() throws Exception {
    DefaultTlsContextFactory tlsContextFactory = new DefaultTlsContextFactory(getAnnotations());
    tlsContextFactory.setName(name);
    tlsContextFactory.setEnabledProtocols(enabledProtocols);
    tlsContextFactory.setEnabledCipherSuites(enabledCipherSuites);
    if (keyStore != null) {
        tlsContextFactory.setKeyAlias(keyStore.getAlias());
        tlsContextFactory.setKeyPassword(keyStore.getKeyPassword());
        if (keyStore.getPath() != null) {
            tlsContextFactory.setKeyStorePath(keyStore.getPath());
        }
        tlsContextFactory.setKeyStorePassword(keyStore.getPassword());
        if (keyStore.getType() != null) {
            tlsContextFactory.setKeyStoreType(keyStore.getType());
        }
        if (keyStore.getAlgorithm() != null) {
            tlsContextFactory.setKeyManagerAlgorithm(keyStore.getAlgorithm());
        }
    }
    if (trustStore != null) {
        if (trustStore.getPath() != null) {
            tlsContextFactory.setTrustStorePath(trustStore.getPath());
        }
        tlsContextFactory.setTrustStorePassword(trustStore.getPassword());
        if (trustStore.getType() != null) {
            tlsContextFactory.setTrustStoreType(trustStore.getType());
        }
        if (trustStore.getAlgorithm() != null) {
            tlsContextFactory.setTrustManagerAlgorithm(trustStore.getAlgorithm());
        }
        tlsContextFactory.setTrustStoreInsecure(trustStore.isInsecure());
    }
    if (revocationCheck != null) {
        tlsContextFactory.setRevocationCheck(revocationCheck);
    }
    return tlsContextFactory;
}
Also used : DefaultTlsContextFactory(org.mule.runtime.module.tls.internal.DefaultTlsContextFactory)

Example 2 with DefaultTlsContextFactory

use of org.mule.runtime.module.tls.internal.DefaultTlsContextFactory in project mule by mulesoft.

the class DefaultTlsContextFactoryTestCase method defaultIncludesTls12Ciphers.

@Test
public void defaultIncludesTls12Ciphers() throws Exception {
    DefaultTlsContextFactory tlsContextFactory = new DefaultTlsContextFactory(emptyMap());
    tlsContextFactory.initialise();
    SSLSocketFactory defaultFactory = tlsContextFactory.createSslContext().getSocketFactory();
    SSLContext tls12Context = SSLContext.getInstance("TLSv1.2");
    tls12Context.init(null, null, null);
    SSLSocketFactory tls12Factory = tls12Context.getSocketFactory();
    assertThat(defaultFactory.getDefaultCipherSuites(), arrayContainingInAnyOrder(tls12Factory.getDefaultCipherSuites()));
}
Also used : DefaultTlsContextFactory(org.mule.runtime.module.tls.internal.DefaultTlsContextFactory) SSLContext(javax.net.ssl.SSLContext) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Test(org.junit.Test)

Example 3 with DefaultTlsContextFactory

use of org.mule.runtime.module.tls.internal.DefaultTlsContextFactory in project mule by mulesoft.

the class DefaultTlsContextFactoryTestCase method failIfCipherSuitesDoNotMatchConfigFile.

@Test
public void failIfCipherSuitesDoNotMatchConfigFile() throws Exception {
    DefaultTlsContextFactory tlsContextFactory = new DefaultTlsContextFactory(emptyMap());
    tlsContextFactory.setEnabledCipherSuites("SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA");
    expectedException.expect(InitialisationException.class);
    expectedException.expectMessage(containsString("cipher suites are invalid"));
    tlsContextFactory.initialise();
}
Also used : DefaultTlsContextFactory(org.mule.runtime.module.tls.internal.DefaultTlsContextFactory) Test(org.junit.Test)

Example 4 with DefaultTlsContextFactory

use of org.mule.runtime.module.tls.internal.DefaultTlsContextFactory in project mule by mulesoft.

the class DefaultTlsContextFactoryTestCase method overrideConfigFile.

@Test
public void overrideConfigFile() throws Exception {
    DefaultTlsContextFactory tlsContextFactory = new DefaultTlsContextFactory(emptyMap());
    tlsContextFactory.setEnabledCipherSuites("TLS_DHE_DSS_WITH_AES_128_CBC_SHA");
    tlsContextFactory.setEnabledProtocols("TLSv1.1");
    tlsContextFactory.initialise();
    String[] enabledCipherSuites = tlsContextFactory.getEnabledCipherSuites();
    assertThat(enabledCipherSuites.length, is(1));
    assertThat(enabledCipherSuites, is(arrayContaining("TLS_DHE_DSS_WITH_AES_128_CBC_SHA")));
    String[] enabledProtocols = tlsContextFactory.getEnabledProtocols();
    assertThat(enabledProtocols.length, is(1));
    assertThat(enabledProtocols, is(arrayContaining("TLSv1.1")));
}
Also used : DefaultTlsContextFactory(org.mule.runtime.module.tls.internal.DefaultTlsContextFactory) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 5 with DefaultTlsContextFactory

use of org.mule.runtime.module.tls.internal.DefaultTlsContextFactory in project mule by mulesoft.

the class DefaultTlsContextFactoryTestCase method failIfProtocolsDoNotMatchConfigFile.

@Test
public void failIfProtocolsDoNotMatchConfigFile() throws Exception {
    DefaultTlsContextFactory tlsContextFactory = new DefaultTlsContextFactory(emptyMap());
    tlsContextFactory.setEnabledProtocols("TLSv1,SSLv3");
    expectedException.expect(InitialisationException.class);
    expectedException.expectMessage(containsString("protocols are invalid"));
    tlsContextFactory.initialise();
}
Also used : DefaultTlsContextFactory(org.mule.runtime.module.tls.internal.DefaultTlsContextFactory) Test(org.junit.Test)

Aggregations

DefaultTlsContextFactory (org.mule.runtime.module.tls.internal.DefaultTlsContextFactory)9 Test (org.junit.Test)8 TlsContextFactory (org.mule.runtime.api.tls.TlsContextFactory)2 SSLContext (javax.net.ssl.SSLContext)1 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1