Search in sources :

Example 6 with TlsConfiguration

use of org.mule.runtime.core.privileged.security.tls.TlsConfiguration in project mule by mulesoft.

the class TlsConfigurationTestCase method defaultProtocolFromConfigFile.

@Test
public void defaultProtocolFromConfigFile() throws Exception {
    File configFile = createDefaultProtocolConfigFile();
    try {
        TlsConfiguration tlsConfiguration = new TlsConfiguration(DEFAULT_KEYSTORE);
        tlsConfiguration.initialise(true, JSSE_NAMESPACE);
        SSLSocketFactory socketFactory = tlsConfiguration.getSocketFactory();
        SSLServerSocketFactory serverSocketFactory = tlsConfiguration.getServerSocketFactory();
        SSLContext sslContext = SSLContext.getInstance(SUPPORTED_PROTOCOL);
        sslContext.init(null, null, null);
        SSLSocketFactory protocolSocketFactory = sslContext.getSocketFactory();
        SSLServerSocketFactory protocolServerSocketFactory = sslContext.getServerSocketFactory();
        assertThat(socketFactory.getDefaultCipherSuites(), arrayWithSize(protocolSocketFactory.getDefaultCipherSuites().length));
        assertThat(socketFactory.getDefaultCipherSuites(), is(arrayContainingInAnyOrder(protocolSocketFactory.getDefaultCipherSuites())));
        assertThat(serverSocketFactory.getDefaultCipherSuites(), arrayWithSize(protocolServerSocketFactory.getDefaultCipherSuites().length));
        assertThat(serverSocketFactory.getDefaultCipherSuites(), is(arrayContainingInAnyOrder(protocolServerSocketFactory.getDefaultCipherSuites())));
    } finally {
        configFile.delete();
    }
}
Also used : SSLServerSocketFactory(javax.net.ssl.SSLServerSocketFactory) TlsConfiguration(org.mule.runtime.core.privileged.security.tls.TlsConfiguration) SSLContext(javax.net.ssl.SSLContext) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) File(java.io.File) Test(org.junit.Test)

Example 7 with TlsConfiguration

use of org.mule.runtime.core.privileged.security.tls.TlsConfiguration in project mule by mulesoft.

the class TlsConfigurationTestCase method testEmptyConfiguration.

@Test
public void testEmptyConfiguration() throws Exception {
    TlsConfiguration configuration = new TlsConfiguration(DEFAULT_KEYSTORE);
    try {
        configuration.initialise(false, JSSE_NAMESPACE);
        fail("no key password");
    } catch (IllegalArgumentException e) {
        assertNotNull("expected", e);
    }
    configuration.setKeyPassword("mulepassword");
    try {
        configuration.initialise(false, JSSE_NAMESPACE);
        fail("no store password");
    } catch (IllegalArgumentException e) {
        assertNotNull("expected", e);
    }
    configuration.setKeyStorePassword("mulepassword");
    // guaranteed to not exist
    configuration.setKeyStore("");
    try {
        configuration.initialise(false, JSSE_NAMESPACE);
        fail("no keystore");
    } catch (Exception e) {
        assertNotNull("expected", e);
    }
}
Also used : TlsConfiguration(org.mule.runtime.core.privileged.security.tls.TlsConfiguration) CreateException(org.mule.runtime.api.lifecycle.CreateException) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with TlsConfiguration

use of org.mule.runtime.core.privileged.security.tls.TlsConfiguration in project mule by mulesoft.

the class TlsPropertiesSocketTestCase method testSimpleSocket.

@Test
public void testSimpleSocket() throws Exception {
    TlsConfiguration configuration = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE);
    configuration.setKeyPassword("mulepassword");
    configuration.setKeyStorePassword("mulepassword");
    configuration.setKeyStore("clientKeystore");
    configuration.initialise(false, TlsConfiguration.JSSE_NAMESPACE);
    TlsPropertiesSocketFactory socketFactory = new TlsPropertiesSocketFactory(true, TlsConfiguration.JSSE_NAMESPACE);
    assertTrue("socket is useless", socketFactory.getSupportedCipherSuites().length > 0);
}
Also used : TlsPropertiesSocketFactory(org.mule.runtime.core.internal.secutiry.tls.TlsPropertiesSocketFactory) TlsConfiguration(org.mule.runtime.core.privileged.security.tls.TlsConfiguration) Test(org.junit.Test)

Example 9 with TlsConfiguration

use of org.mule.runtime.core.privileged.security.tls.TlsConfiguration in project mule by mulesoft.

the class TlsPropertiesSocketFactory method getFactory.

private synchronized SSLSocketFactory getFactory() throws IOException {
    if (null == factory) {
        logger.debug("creating factory");
        TlsPropertiesMapper propertiesMapper = new TlsPropertiesMapper(namespace);
        TlsConfiguration configuration = new TlsConfiguration(TlsConfiguration.DEFAULT_KEYSTORE);
        propertiesMapper.readFromProperties(configuration, System.getProperties());
        try {
            configuration.initialise(anon, namespace);
            factory = configuration.getSocketFactory();
        } catch (Exception e) {
            throw (IOException) new IOException(e.getMessage()).initCause(e);
        }
    }
    return factory;
}
Also used : TlsConfiguration(org.mule.runtime.core.privileged.security.tls.TlsConfiguration) IOException(java.io.IOException) IOException(java.io.IOException)

Example 10 with TlsConfiguration

use of org.mule.runtime.core.privileged.security.tls.TlsConfiguration in project mule by mulesoft.

the class RestrictedSSLSocketFactory method getDefault.

public static synchronized SocketFactory getDefault() {
    if (defaultSocketFactory == null) {
        try {
            TlsConfiguration configuration = new TlsConfiguration(null);
            configuration.initialise(true, null);
            defaultSocketFactory = new RestrictedSSLSocketFactory(configuration.getSslContext(), configuration.getEnabledCipherSuites(), configuration.getEnabledProtocols());
        } catch (Exception e) {
            throw new MuleRuntimeException(createStaticMessage("Could not create the default RestrictedSSLSocketFactory"), e);
        }
    }
    return defaultSocketFactory;
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) TlsConfiguration(org.mule.runtime.core.privileged.security.tls.TlsConfiguration) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IOException(java.io.IOException)

Aggregations

TlsConfiguration (org.mule.runtime.core.privileged.security.tls.TlsConfiguration)12 Test (org.junit.Test)10 File (java.io.File)6 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)4 IOException (java.io.IOException)3 SSLContext (javax.net.ssl.SSLContext)3 SSLServerSocket (javax.net.ssl.SSLServerSocket)2 SSLServerSocketFactory (javax.net.ssl.SSLServerSocketFactory)2 SSLSocket (javax.net.ssl.SSLSocket)2 CreateException (org.mule.runtime.api.lifecycle.CreateException)2 URL (java.net.URL)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 TlsPropertiesSocketFactory (org.mule.runtime.core.internal.secutiry.tls.TlsPropertiesSocketFactory)1