From 102e3cb093cd7380ffaf5ebff80a8fe64485c22b Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Tue, 3 Feb 2015 10:37:28 -0500 Subject: [PATCH] NIFI-310: Fixed NPE --- .../nifi/processors/standard/PostHTTP.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PostHTTP.java b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PostHTTP.java index fd486b0efd..f8a33bc8e7 100644 --- a/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PostHTTP.java +++ b/nifi/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PostHTTP.java @@ -68,6 +68,7 @@ import org.apache.http.conn.HttpClientConnectionManager; import org.apache.http.conn.ManagedHttpClientConnection; import org.apache.http.conn.socket.ConnectionSocketFactory; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; import org.apache.http.conn.ssl.SSLContexts; import org.apache.http.conn.ssl.TrustSelfSignedStrategy; import org.apache.http.entity.ContentProducer; @@ -352,21 +353,26 @@ public class PostHTTP extends AbstractProcessor { private SSLContext createSSLContext(final SSLContextService service) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, KeyManagementException, UnrecoverableKeyException { - final KeyStore truststore = KeyStore.getInstance(service.getTrustStoreType()); - try (final InputStream in = new FileInputStream(new File(service.getTrustStoreFile()))) { - truststore.load(in, service.getTrustStorePassword().toCharArray()); + SSLContextBuilder builder = SSLContexts.custom(); + final String trustFilename = service.getTrustStoreFile(); + if ( trustFilename != null ) { + final KeyStore truststore = KeyStore.getInstance(service.getTrustStoreType()); + try (final InputStream in = new FileInputStream(new File(service.getTrustStoreFile()))) { + truststore.load(in, service.getTrustStorePassword().toCharArray()); + } + builder = builder.loadTrustMaterial(truststore, new TrustSelfSignedStrategy()); + } + + final String keyFilename = service.getKeyStoreFile(); + if ( keyFilename != null ) { + final KeyStore keystore = KeyStore.getInstance(service.getKeyStoreType()); + try (final InputStream in = new FileInputStream(new File(service.getKeyStoreFile()))) { + keystore.load(in, service.getKeyStorePassword().toCharArray()); + } + builder = builder.loadKeyMaterial(keystore, service.getKeyStorePassword().toCharArray()); } - final KeyStore keystore = KeyStore.getInstance(service.getKeyStoreType()); - try (final InputStream in = new FileInputStream(new File(service.getKeyStoreFile()))) { - keystore.load(in, service.getKeyStorePassword().toCharArray()); - } - - SSLContext sslContext = SSLContexts.custom() - .loadTrustMaterial(truststore, new TrustSelfSignedStrategy()) - .loadKeyMaterial(keystore, service.getKeyStorePassword().toCharArray()) - .build(); - + SSLContext sslContext = builder.build(); return sslContext; }