Search in sources :

Example 1 with TlsConfiguration

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

the class TlsConfigurationTestCase method testExceptionOnInvalidKeyAlias.

@Test
public void testExceptionOnInvalidKeyAlias() throws Exception {
    URL keystoreUrl = getClass().getClassLoader().getResource("serverKeystore");
    File keystoreFile = new File(keystoreUrl.toURI());
    TlsConfiguration config = new TlsConfiguration(keystoreFile.getAbsolutePath());
    config.setKeyStorePassword("mulepassword");
    config.setKeyPassword("mulepassword");
    config.setKeyAlias("this_key_does_not_exist_in_the_keystore");
    try {
        config.initialise(false, JSSE_NAMESPACE);
    } catch (CreateException ce) {
        assertTrue(ce.getCause() instanceof IllegalStateException);
    }
}
Also used : TlsConfiguration(org.mule.runtime.core.privileged.security.tls.TlsConfiguration) File(java.io.File) CreateException(org.mule.runtime.api.lifecycle.CreateException) URL(java.net.URL) Test(org.junit.Test)

Example 2 with TlsConfiguration

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

the class TlsConfigurationTestCase method testSecurityModelProperty.

@Test
public void testSecurityModelProperty() throws Exception {
    String previousSecurityModel = SecurityUtils.getSecurityModel();
    System.setProperty(MuleProperties.MULE_SECURITY_SYSTEM_PROPERTY, TEST_SECURITY_MODEL);
    File file = createConfigFile(TEST_SECURITY_MODEL, "enabledCipherSuites=TEST");
    try {
        TlsConfiguration tlsConfiguration = new TlsConfiguration(DEFAULT_KEYSTORE);
        tlsConfiguration.initialise(true, JSSE_NAMESPACE);
        assertArrayEquals(new String[] { "TEST" }, tlsConfiguration.getEnabledCipherSuites());
    } finally {
        System.setProperty(MuleProperties.MULE_SECURITY_SYSTEM_PROPERTY, previousSecurityModel);
        file.delete();
    }
}
Also used : TlsConfiguration(org.mule.runtime.core.privileged.security.tls.TlsConfiguration) File(java.io.File) Test(org.junit.Test)

Example 3 with TlsConfiguration

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

the class TlsConfigurationTestCase method testCipherSuitesFromConfigFile.

@Test
public void testCipherSuitesFromConfigFile() throws Exception {
    File configFile = createDefaultConfigFile();
    try {
        TlsConfiguration tlsConfiguration = new TlsConfiguration(DEFAULT_KEYSTORE);
        tlsConfiguration.initialise(true, JSSE_NAMESPACE);
        SSLSocket socket = (SSLSocket) tlsConfiguration.getSocketFactory().createSocket();
        SSLServerSocket serverSocket = (SSLServerSocket) tlsConfiguration.getServerSocketFactory().createServerSocket();
        assertArrayEquals(new String[] { SUPPORTED_CIPHER_SUITE }, socket.getEnabledCipherSuites());
        assertArrayEquals(new String[] { SUPPORTED_CIPHER_SUITE }, serverSocket.getEnabledCipherSuites());
    } finally {
        configFile.delete();
    }
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) TlsConfiguration(org.mule.runtime.core.privileged.security.tls.TlsConfiguration) SSLServerSocket(javax.net.ssl.SSLServerSocket) File(java.io.File) Test(org.junit.Test)

Example 4 with TlsConfiguration

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

the class TlsConfigurationTestCase method overrideDefaultProtocolFromConfigFile.

@Test
public void overrideDefaultProtocolFromConfigFile() throws Exception {
    File configFile = createDefaultProtocolConfigFile();
    try {
        TlsConfiguration tlsConfiguration = new TlsConfiguration(DEFAULT_KEYSTORE);
        tlsConfiguration.setSslType("TLSv1.2");
        tlsConfiguration.initialise(true, JSSE_NAMESPACE);
        SSLSocketFactory socketFactory = tlsConfiguration.getSocketFactory();
        SSLContext sslContext = SSLContext.getInstance(SUPPORTED_PROTOCOL);
        sslContext.init(null, null, null);
        SSLSocketFactory protocolSocketFactory = sslContext.getSocketFactory();
        assertThat(socketFactory.getDefaultCipherSuites(), not(arrayWithSize(protocolSocketFactory.getDefaultCipherSuites().length)));
    } finally {
        configFile.delete();
    }
}
Also used : 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 5 with TlsConfiguration

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

the class TlsConfigurationTestCase method testProtocolsFromConfigFile.

@Test
public void testProtocolsFromConfigFile() throws Exception {
    File configFile = createDefaultConfigFile();
    try {
        TlsConfiguration tlsConfiguration = new TlsConfiguration(DEFAULT_KEYSTORE);
        tlsConfiguration.initialise(true, JSSE_NAMESPACE);
        SSLSocket socket = (SSLSocket) tlsConfiguration.getSocketFactory().createSocket();
        SSLServerSocket serverSocket = (SSLServerSocket) tlsConfiguration.getServerSocketFactory().createServerSocket();
        assertArrayEquals(new String[] { SUPPORTED_PROTOCOL }, socket.getEnabledProtocols());
        assertArrayEquals(new String[] { SUPPORTED_PROTOCOL }, serverSocket.getEnabledProtocols());
    } finally {
        configFile.delete();
    }
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) TlsConfiguration(org.mule.runtime.core.privileged.security.tls.TlsConfiguration) SSLServerSocket(javax.net.ssl.SSLServerSocket) File(java.io.File) Test(org.junit.Test)

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