diff --git a/src/main/java/org/acra/config/ACRAConfiguration.java b/src/main/java/org/acra/config/ACRAConfiguration.java index ab4c3be7b2..8a2bc76c2e 100644 --- a/src/main/java/org/acra/config/ACRAConfiguration.java +++ b/src/main/java/org/acra/config/ACRAConfiguration.java @@ -1085,6 +1085,7 @@ public Class[] reportSenderFactoryClasses() { } @SuppressWarnings("unused") + @Nullable public KeyStoreFactory keyStoreFactory() { return keyStoreFactory; } diff --git a/src/main/java/org/acra/config/ConfigurationBuilder.java b/src/main/java/org/acra/config/ConfigurationBuilder.java index ca8853bee1..dc9556a1c6 100644 --- a/src/main/java/org/acra/config/ConfigurationBuilder.java +++ b/src/main/java/org/acra/config/ConfigurationBuilder.java @@ -756,19 +756,25 @@ public ConfigurationBuilder setReportType(@NonNull Type type) { * Set this to a factory which creates a the keystore that contains the trusted certificates */ @SuppressWarnings("unused") - public void setKeyStoreFactory(KeyStoreFactory keyStoreFactory) { + @NonNull + public ConfigurationBuilder setKeyStoreFactory(KeyStoreFactory keyStoreFactory) { this.keyStoreFactory = keyStoreFactory; + return this; } @SuppressWarnings("unused") - public void setReportSenderFactoryClasses(@NonNull Class[] reportSenderFactoryClasses) { + @NonNull + public ConfigurationBuilder setReportSenderFactoryClasses(@NonNull Class[] reportSenderFactoryClasses) { this.reportSenderFactoryClasses = reportSenderFactoryClasses; + return this; } @SuppressWarnings("unused") - public void setReportPrimerClass(@NonNull Class reportPrimerClass) { + @NonNull + public ConfigurationBuilder setReportPrimerClass(@NonNull Class reportPrimerClass) { this.reportPrimerClass = reportPrimerClass; + return this; } @@ -1163,6 +1169,7 @@ Class[] reportSenderFactoryClasses() { } @SuppressWarnings("unused") + @Nullable KeyStoreFactory keyStoreFactory() { return keyStoreFactory; } diff --git a/src/main/java/org/acra/util/HttpRequest.java b/src/main/java/org/acra/util/HttpRequest.java index 0b9e439da1..3f6a06906d 100644 --- a/src/main/java/org/acra/util/HttpRequest.java +++ b/src/main/java/org/acra/util/HttpRequest.java @@ -12,6 +12,7 @@ import org.acra.ACRA; import org.acra.config.ACRAConfiguration; +import org.acra.security.KeyStoreFactory; import org.acra.sender.HttpSender.Method; import org.acra.sender.HttpSender.Type; @@ -23,6 +24,7 @@ import java.net.URL; import java.net.URLEncoder; import java.security.GeneralSecurityException; +import java.security.KeyStore; import java.util.Map; import javax.net.ssl.HttpsURLConnection; @@ -91,10 +93,10 @@ public void send(@NonNull Context context, @NonNull URL url, @NonNull Method met final String algorithm = TrustManagerFactory.getDefaultAlgorithm(); final TrustManagerFactory tmf = TrustManagerFactory.getInstance(algorithm); + final KeyStoreFactory keyStoreFactory = config.keyStoreFactory(); + final KeyStore keyStore = keyStoreFactory == null ? null : keyStoreFactory.create(context); - if (config.keyStoreFactory() != null) { - tmf.init(config.keyStoreFactory().create(context)); - } + tmf.init(keyStore); final SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, tmf.getTrustManagers(), null);