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

feat: Add option to disable certificate pinning #495

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static Certificate generateCertificate(CertificateFactory certificateFac

private boolean shouldDisablePinning() {
NetworkOptions networkOptions = mConfigManager.getNetworkOptions();
return ConfigManager.getEnvironment() == MParticle.Environment.Development && networkOptions.pinningDisabledInDevelopment;
return networkOptions.pinningDisabled || (ConfigManager.getEnvironment() == MParticle.Environment.Development && networkOptions.pinningDisabledInDevelopment);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class NetworkOptions {

Map<Endpoint, DomainMapping> domainMappings = new HashMap<Endpoint, DomainMapping>();
boolean pinningDisabledInDevelopment = false;
boolean pinningDisabled = false;

private NetworkOptions() {
}
Expand All @@ -36,6 +37,10 @@ private NetworkOptions(Builder builder) {
if (builder.pinningDisabledInDevelopment != null) {
pinningDisabledInDevelopment = builder.pinningDisabledInDevelopment;
}

if (builder.pinningDisabled != null) {
pinningDisabled = builder.pinningDisabled;
}
}

@NonNull
Expand All @@ -52,6 +57,7 @@ public static NetworkOptions withNetworkOptions(@Nullable String jsonString) {
try {
JSONObject jsonObject = new JSONObject(jsonString);
builder.setPinningDisabledInDevelopment(jsonObject.optBoolean("disableDevPinning", false));
builder.setPinningDisabled(jsonObject.optBoolean("disablePinning", false));
JSONArray domainMappingsJson = jsonObject.getJSONArray("domainMappings");
for (int i = 0; i < domainMappingsJson.length(); i++) {
builder.addDomainMapping(DomainMapping
Expand Down Expand Up @@ -93,6 +99,10 @@ public boolean isPinningDisabledInDevelopment() {
return pinningDisabledInDevelopment;
}

public boolean isPinningDisabled() {
return pinningDisabled;
}

DomainMapping getDomain(Endpoint endpoint) {
return domainMappings.get(endpoint);
}
Expand All @@ -109,6 +119,7 @@ private JSONObject toJson() {
try {
JSONArray domainMappingsJson = new JSONArray();
networkOptions.put("disableDevPinning", pinningDisabledInDevelopment);
networkOptions.put("disablePinning", pinningDisabled);
networkOptions.put("domainMappings", domainMappingsJson);
for (DomainMapping domainMapping : domainMappings.values()) {
domainMappingsJson.put(domainMapping.toString());
Expand All @@ -122,6 +133,7 @@ private JSONObject toJson() {
public static class Builder {
private Map<Endpoint, DomainMapping> domainMappings = new HashMap<Endpoint, DomainMapping>();
private Boolean pinningDisabledInDevelopment;
private Boolean pinningDisabled;

private Builder() {
}
Expand Down Expand Up @@ -163,6 +175,12 @@ public Builder setPinningDisabledInDevelopment(boolean disabledInDevelopment) {
return this;
}

@NonNull
public Builder setPinningDisabled(boolean disabled) {
this.pinningDisabled = disabled;
return this;
}

@NonNull
public NetworkOptions build() {
return new NetworkOptions(this);
Expand Down
Loading