Search in sources :

Example 51 with SSLContext

use of javax.net.ssl.SSLContext in project flink by apache.

the class SSLUtilsTest method testCreateSSLServerContextWithMultiProtocols.

/**
	 * Tests if SSL Server Context creation fails with bad SSL configuration
	 */
@Test
public void testCreateSSLServerContextWithMultiProtocols() {
    Configuration serverConfig = new Configuration();
    serverConfig.setBoolean(ConfigConstants.SECURITY_SSL_ENABLED, true);
    serverConfig.setString(ConfigConstants.SECURITY_SSL_KEYSTORE, "src/test/resources/local127.keystore");
    serverConfig.setString(ConfigConstants.SECURITY_SSL_KEYSTORE_PASSWORD, "password");
    serverConfig.setString(ConfigConstants.SECURITY_SSL_KEY_PASSWORD, "password");
    serverConfig.setString(ConfigConstants.SECURITY_SSL_PROTOCOL, "TLSv1,TLSv1.2");
    try {
        SSLContext serverContext = SSLUtils.createSSLServerContext(serverConfig);
        Assert.fail("SSL server context created even with multiple protocols set ");
    } catch (Exception e) {
    // Exception here is valid
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.Test)

Example 52 with SSLContext

use of javax.net.ssl.SSLContext in project flink by apache.

the class SSLUtilsTest method testCreateSSLClientContextWithSSLDisabled.

/**
	 * Tests if SSL Client Context is not created if SSL is not configured
	 */
@Test
public void testCreateSSLClientContextWithSSLDisabled() throws Exception {
    Configuration clientConfig = new Configuration();
    clientConfig.setBoolean(ConfigConstants.SECURITY_SSL_ENABLED, false);
    SSLContext clientContext = SSLUtils.createSSLClientContext(clientConfig);
    Assert.assertNull(clientContext);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.Test)

Example 53 with SSLContext

use of javax.net.ssl.SSLContext in project flink by apache.

the class SSLUtilsTest method testCreateSSLClientContext.

/**
	 * Tests if SSL Client Context is created given a valid SSL configuration
	 */
@Test
public void testCreateSSLClientContext() throws Exception {
    Configuration clientConfig = new Configuration();
    clientConfig.setBoolean(ConfigConstants.SECURITY_SSL_ENABLED, true);
    clientConfig.setString(ConfigConstants.SECURITY_SSL_TRUSTSTORE, "src/test/resources/local127.truststore");
    clientConfig.setString(ConfigConstants.SECURITY_SSL_TRUSTSTORE_PASSWORD, "password");
    SSLContext clientContext = SSLUtils.createSSLClientContext(clientConfig);
    Assert.assertNotNull(clientContext);
}
Also used : Configuration(org.apache.flink.configuration.Configuration) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.Test)

Example 54 with SSLContext

use of javax.net.ssl.SSLContext in project flink by apache.

the class SSLUtilsTest method testCreateSSLClientContextMisconfiguration.

/**
	 * Tests if SSL Client Context creation fails with bad SSL configuration
	 */
@Test
public void testCreateSSLClientContextMisconfiguration() {
    Configuration clientConfig = new Configuration();
    clientConfig.setBoolean(ConfigConstants.SECURITY_SSL_ENABLED, true);
    clientConfig.setString(ConfigConstants.SECURITY_SSL_TRUSTSTORE, "src/test/resources/local127.truststore");
    clientConfig.setString(ConfigConstants.SECURITY_SSL_TRUSTSTORE_PASSWORD, "badpassword");
    try {
        SSLContext clientContext = SSLUtils.createSSLClientContext(clientConfig);
        Assert.fail("SSL client context created even with bad SSL configuration ");
    } catch (Exception e) {
    // Exception here is valid
    }
}
Also used : Configuration(org.apache.flink.configuration.Configuration) SSLContext(javax.net.ssl.SSLContext) Test(org.junit.Test)

Example 55 with SSLContext

use of javax.net.ssl.SSLContext in project camel by apache.

the class HttpsServerTestSupport method getSSLContext.

@Override
protected SSLContext getSSLContext() throws Exception {
    KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    keyStore.load(new FileInputStream(KEYSTORE), PASSWORD.toCharArray());
    KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    keyManagerFactory.init(keyStore, PASSWORD.toCharArray());
    KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
    trustStore.load(new FileInputStream(KEYSTORE), PASSWORD.toCharArray());
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(trustStore);
    SSLContext sslcontext = SSLContext.getInstance(SECURE_SOCKET_PROTOCOL);
    sslcontext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
    return sslcontext;
}
Also used : TrustManagerFactory(javax.net.ssl.TrustManagerFactory) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) KeyManagerFactory(javax.net.ssl.KeyManagerFactory)

Aggregations

SSLContext (javax.net.ssl.SSLContext)745 IOException (java.io.IOException)171 TrustManager (javax.net.ssl.TrustManager)139 KeyStore (java.security.KeyStore)130 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)112 SecureRandom (java.security.SecureRandom)110 X509TrustManager (javax.net.ssl.X509TrustManager)107 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)106 KeyManagementException (java.security.KeyManagementException)92 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)92 CertificateException (java.security.cert.CertificateException)84 X509Certificate (java.security.cert.X509Certificate)84 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)69 Test (org.junit.Test)65 SSLSocket (javax.net.ssl.SSLSocket)64 InputStream (java.io.InputStream)59 FileInputStream (java.io.FileInputStream)56 SSLEngine (javax.net.ssl.SSLEngine)54 KeyManager (javax.net.ssl.KeyManager)52 KeyStoreException (java.security.KeyStoreException)45