Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TrustManagerFactory not initialized when no KeyStore provided #403

Merged
merged 1 commit into from
Mar 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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