Search in sources :

Example 71 with SSLContextService

use of org.apache.nifi.ssl.SSLContextService in project nifi by apache.

the class TestHandleHttpRequest method useSSLContextService.

private static SSLContext useSSLContextService(final TestRunner controller, final Map<String, String> sslProperties) {
    final SSLContextService service = new StandardRestrictedSSLContextService();
    try {
        controller.addControllerService("ssl-service", service, sslProperties);
        controller.enableControllerService(service);
    } catch (InitializationException ex) {
        ex.printStackTrace();
        Assert.fail("Could not create SSL Context Service");
    }
    controller.setProperty(HandleHttpRequest.SSL_CONTEXT, "ssl-service");
    return service.createSSLContext(SSLContextService.ClientAuth.WANT);
}
Also used : StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService) InitializationException(org.apache.nifi.reporting.InitializationException)

Example 72 with SSLContextService

use of org.apache.nifi.ssl.SSLContextService in project nifi by apache.

the class TestPostHTTP method testTwoWaySSL.

@Test
public void testTwoWaySSL() throws Exception {
    final Map<String, String> sslProps = new HashMap<>();
    sslProps.put(StandardSSLContextService.KEYSTORE.getName(), "src/test/resources/localhost-ks.jks");
    sslProps.put(StandardSSLContextService.KEYSTORE_PASSWORD.getName(), "localtest");
    sslProps.put(StandardSSLContextService.KEYSTORE_TYPE.getName(), "JKS");
    sslProps.put(StandardSSLContextService.TRUSTSTORE.getName(), "src/test/resources/localhost-ts.jks");
    sslProps.put(StandardSSLContextService.TRUSTSTORE_PASSWORD.getName(), "localtest");
    sslProps.put(StandardSSLContextService.TRUSTSTORE_TYPE.getName(), "JKS");
    sslProps.put(TestServer.NEED_CLIENT_AUTH, "true");
    setup(sslProps);
    final SSLContextService sslContextService = new StandardSSLContextService();
    runner.addControllerService("ssl-context", sslContextService);
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE, "src/test/resources/localhost-ks.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_TYPE, "JKS");
    runner.enableControllerService(sslContextService);
    runner.setProperty(PostHTTP.URL, server.getSecureUrl());
    runner.setProperty(PostHTTP.SSL_CONTEXT_SERVICE, "ssl-context");
    runner.setProperty(PostHTTP.CHUNKED_ENCODING, "false");
    runner.enqueue("Hello world".getBytes());
    runner.run();
    runner.assertAllFlowFilesTransferred(PostHTTP.REL_SUCCESS, 1);
}
Also used : HashMap(java.util.HashMap) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) Test(org.junit.Test)

Example 73 with SSLContextService

use of org.apache.nifi.ssl.SSLContextService in project nifi by apache.

the class ITListenAndPutSyslog method configureSSLContextService.

private SSLContextService configureSSLContextService(TestRunner runner) throws InitializationException {
    final SSLContextService sslContextService = new StandardSSLContextService();
    runner.addControllerService("ssl-context", sslContextService);
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE, "src/test/resources/localhost-ts.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.TRUSTSTORE_TYPE, "JKS");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE, "src/test/resources/localhost-ks.jks");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_PASSWORD, "localtest");
    runner.setProperty(sslContextService, StandardSSLContextService.KEYSTORE_TYPE, "JKS");
    runner.enableControllerService(sslContextService);
    return sslContextService;
}
Also used : SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService)

Example 74 with SSLContextService

use of org.apache.nifi.ssl.SSLContextService in project nifi by apache.

the class AbstractAMQPProcessorTest method testConnectToCassandraWithSSLBadClientAuth.

@Test(expected = ProviderCreationException.class)
public void testConnectToCassandraWithSSLBadClientAuth() throws Exception {
    SSLContextService sslService = mock(SSLContextService.class);
    when(sslService.getIdentifier()).thenReturn("ssl-context");
    testRunner.addControllerService("ssl-context", sslService);
    testRunner.enableControllerService(sslService);
    testRunner.setProperty(AbstractAMQPProcessor.SSL_CONTEXT_SERVICE, "ssl-context");
    testRunner.setProperty(AbstractAMQPProcessor.USE_CERT_AUTHENTICATION, "false");
    testRunner.setProperty(AbstractAMQPProcessor.HOST, "test");
    testRunner.setProperty(AbstractAMQPProcessor.PORT, "9999");
    testRunner.setProperty(AbstractAMQPProcessor.USER, "test");
    testRunner.setProperty(AbstractAMQPProcessor.PASSWORD, "test");
    testRunner.assertValid(sslService);
    testRunner.setProperty(AbstractAMQPProcessor.CLIENT_AUTH, "BAD");
    processor.onTrigger(testRunner.getProcessContext(), testRunner.getProcessSessionFactory());
}
Also used : SSLContextService(org.apache.nifi.ssl.SSLContextService) Test(org.junit.Test)

Example 75 with SSLContextService

use of org.apache.nifi.ssl.SSLContextService in project nifi by apache.

the class AbstractAWSProcessor method createConfiguration.

protected ClientConfiguration createConfiguration(final ProcessContext context) {
    final ClientConfiguration config = new ClientConfiguration();
    config.setMaxConnections(context.getMaxConcurrentTasks());
    config.setMaxErrorRetry(0);
    config.setUserAgent(DEFAULT_USER_AGENT);
    // If this is changed to be a property, ensure other uses are also changed
    config.setProtocol(DEFAULT_PROTOCOL);
    final int commsTimeout = context.getProperty(TIMEOUT).asTimePeriod(TimeUnit.MILLISECONDS).intValue();
    config.setConnectionTimeout(commsTimeout);
    config.setSocketTimeout(commsTimeout);
    final SSLContextService sslContextService = context.getProperty(SSL_CONTEXT_SERVICE).asControllerService(SSLContextService.class);
    if (sslContextService != null) {
        final SSLContext sslContext = sslContextService.createSSLContext(SSLContextService.ClientAuth.NONE);
        // NIFI-3788: Changed hostnameVerifier from null to DHV (BrowserCompatibleHostnameVerifier is deprecated)
        SdkTLSSocketFactory sdkTLSSocketFactory = new SdkTLSSocketFactory(sslContext, new DefaultHostnameVerifier());
        config.getApacheHttpClientConfig().setSslSocketFactory(sdkTLSSocketFactory);
    }
    if (context.getProperty(PROXY_HOST).isSet()) {
        String proxyHost = context.getProperty(PROXY_HOST).evaluateAttributeExpressions().getValue();
        config.setProxyHost(proxyHost);
        Integer proxyPort = context.getProperty(PROXY_HOST_PORT).evaluateAttributeExpressions().asInteger();
        config.setProxyPort(proxyPort);
    }
    return config;
}
Also used : SdkTLSSocketFactory(com.amazonaws.http.conn.ssl.SdkTLSSocketFactory) DefaultHostnameVerifier(org.apache.http.conn.ssl.DefaultHostnameVerifier) SSLContextService(org.apache.nifi.ssl.SSLContextService) SSLContext(javax.net.ssl.SSLContext) ClientConfiguration(com.amazonaws.ClientConfiguration)

Aggregations

SSLContextService (org.apache.nifi.ssl.SSLContextService)84 SSLContext (javax.net.ssl.SSLContext)29 Test (org.junit.Test)23 StandardSSLContextService (org.apache.nifi.ssl.StandardSSLContextService)22 RestrictedSSLContextService (org.apache.nifi.ssl.RestrictedSSLContextService)18 ArrayList (java.util.ArrayList)12 StandardRestrictedSSLContextService (org.apache.nifi.ssl.StandardRestrictedSSLContextService)12 IOException (java.io.IOException)11 ValidationResult (org.apache.nifi.components.ValidationResult)10 ComponentLog (org.apache.nifi.logging.ComponentLog)9 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)7 InetSocketAddress (java.net.InetSocketAddress)6 ProcessException (org.apache.nifi.processor.exception.ProcessException)6 Charset (java.nio.charset.Charset)5 InitializationException (org.apache.nifi.reporting.InitializationException)5 MalformedURLException (java.net.MalformedURLException)4 URI (java.net.URI)4 ByteBuffer (java.nio.ByteBuffer)4 ProviderCreationException (org.apache.nifi.authentication.exception.ProviderCreationException)4 PropertyDescriptor (org.apache.nifi.components.PropertyDescriptor)4