Search in sources :

Example 1 with StandardRestrictedSSLContextService

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

the class TestListenTCP method configureProcessorSslContextService.

private SSLContextService configureProcessorSslContextService() throws InitializationException {
    final SSLContextService sslContextService = new StandardRestrictedSSLContextService();
    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(ListenTCP.SSL_CONTEXT_SERVICE, "ssl-context");
    return sslContextService;
}
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)

Example 2 with StandardRestrictedSSLContextService

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

the class TestListenTCPRecord method configureProcessorSslContextService.

private SSLContextService configureProcessorSslContextService() throws InitializationException {
    final SSLContextService sslContextService = new StandardRestrictedSSLContextService();
    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(ListenTCPRecord.SSL_CONTEXT_SERVICE, "ssl-context");
    return sslContextService;
}
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)

Example 3 with StandardRestrictedSSLContextService

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

the class TestListenSMTP method validateSuccessfulInteractionWithTls.

@Test
public void validateSuccessfulInteractionWithTls() throws Exception, EmailException {
    System.setProperty("mail.smtp.ssl.trust", "*");
    System.setProperty("javax.net.ssl.keyStore", "src/test/resources/localhost-ks.jks");
    System.setProperty("javax.net.ssl.keyStorePassword", "localtest");
    int port = NetworkUtils.availablePort();
    TestRunner runner = TestRunners.newTestRunner(ListenSMTP.class);
    runner.setProperty(ListenSMTP.SMTP_PORT, String.valueOf(port));
    runner.setProperty(ListenSMTP.SMTP_MAXIMUM_CONNECTIONS, "3");
    // Setup the SSL Context
    SSLContextService sslContextService = new StandardRestrictedSSLContextService();
    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);
    // and add the SSL context to the runner
    runner.setProperty(ListenSMTP.SSL_CONTEXT_SERVICE, "ssl-context");
    runner.setProperty(ListenSMTP.CLIENT_AUTH, SSLContextService.ClientAuth.NONE.name());
    runner.assertValid();
    int messageCount = 5;
    CountDownLatch latch = new CountDownLatch(messageCount);
    runner.run(messageCount, false);
    this.executor.schedule(() -> {
        for (int i = 0; i < messageCount; i++) {
            try {
                Email email = new SimpleEmail();
                email.setHostName("localhost");
                email.setSmtpPort(port);
                email.setFrom("alice@nifi.apache.org");
                email.setSubject("This is a test");
                email.setMsg("MSG-" + i);
                email.addTo("bob@nifi.apache.org");
                // Enable STARTTLS but ignore the cert
                email.setStartTLSEnabled(true);
                email.setStartTLSRequired(true);
                email.setSSLCheckServerIdentity(false);
                email.send();
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException(e);
            } finally {
                latch.countDown();
            }
        }
    }, 1500, TimeUnit.MILLISECONDS);
    boolean complete = latch.await(5000, TimeUnit.MILLISECONDS);
    runner.shutdown();
    assertTrue(complete);
    runner.assertAllFlowFilesTransferred("success", messageCount);
}
Also used : Email(org.apache.commons.mail.Email) SimpleEmail(org.apache.commons.mail.SimpleEmail) TestRunner(org.apache.nifi.util.TestRunner) StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService) CountDownLatch(java.util.concurrent.CountDownLatch) SimpleEmail(org.apache.commons.mail.SimpleEmail) EmailException(org.apache.commons.mail.EmailException) Test(org.junit.Test)

Example 4 with StandardRestrictedSSLContextService

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

the class TestListenHTTP method configureProcessorSslContextService.

private SSLContextService configureProcessorSslContextService() throws InitializationException {
    final SSLContextService sslContextService = new StandardRestrictedSSLContextService();
    runner.addControllerService(SSL_CONTEXT_SERVICE_IDENTIFIER, 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.setProperty(ListenHTTP.SSL_CONTEXT_SERVICE, SSL_CONTEXT_SERVICE_IDENTIFIER);
    return sslContextService;
}
Also used : StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService) SSLContextService(org.apache.nifi.ssl.SSLContextService) StandardSSLContextService(org.apache.nifi.ssl.StandardSSLContextService) StandardRestrictedSSLContextService(org.apache.nifi.ssl.StandardRestrictedSSLContextService)

Example 5 with StandardRestrictedSSLContextService

use of org.apache.nifi.ssl.StandardRestrictedSSLContextService 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)

Aggregations

SSLContextService (org.apache.nifi.ssl.SSLContextService)5 StandardRestrictedSSLContextService (org.apache.nifi.ssl.StandardRestrictedSSLContextService)5 StandardSSLContextService (org.apache.nifi.ssl.StandardSSLContextService)5 CountDownLatch (java.util.concurrent.CountDownLatch)1 Email (org.apache.commons.mail.Email)1 EmailException (org.apache.commons.mail.EmailException)1 SimpleEmail (org.apache.commons.mail.SimpleEmail)1 InitializationException (org.apache.nifi.reporting.InitializationException)1 TestRunner (org.apache.nifi.util.TestRunner)1 Test (org.junit.Test)1