Skip to content

Commit

Permalink
Merge pull request #403 from F43nd1r/issue_402
Browse files Browse the repository at this point in the history
Fix TrustManagerFactory not initialized when no KeyStoreFactory provided
  • Loading branch information
william-ferguson-au committed Mar 16, 2016
2 parents e3c879c + 8688e54 commit 9d348fe
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/acra/config/ACRAConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,7 @@ public Class<? extends ReportSenderFactory>[] reportSenderFactoryClasses() {
}

@SuppressWarnings("unused")
@Nullable
public KeyStoreFactory keyStoreFactory() {
return keyStoreFactory;
}
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/org/acra/config/ConfigurationBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<? extends ReportSenderFactory>[] reportSenderFactoryClasses) {
@NonNull
public ConfigurationBuilder setReportSenderFactoryClasses(@NonNull Class<? extends ReportSenderFactory>[] reportSenderFactoryClasses) {
this.reportSenderFactoryClasses = reportSenderFactoryClasses;
return this;
}

@SuppressWarnings("unused")
public void setReportPrimerClass(@NonNull Class<? extends ReportPrimer> reportPrimerClass) {
@NonNull
public ConfigurationBuilder setReportPrimerClass(@NonNull Class<? extends ReportPrimer> reportPrimerClass) {
this.reportPrimerClass = reportPrimerClass;
return this;
}


Expand Down Expand Up @@ -1163,6 +1169,7 @@ Class<? extends ReportSenderFactory>[] reportSenderFactoryClasses() {
}

@SuppressWarnings("unused")
@Nullable
KeyStoreFactory keyStoreFactory() {
return keyStoreFactory;
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/org/acra/util/HttpRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9d348fe

Please sign in to comment.