Skip to content

Commit

Permalink
feat: Add option to disable certificate pinning
Browse files Browse the repository at this point in the history
  • Loading branch information
Mansi-mParticle committed Jun 25, 2024
1 parent ee1525c commit af031e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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

0 comments on commit af031e8

Please sign in to comment.