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();
}
}
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);
}
}
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);
}
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;
}
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;
}
Aggregations