Skip to content

Commit

Permalink
feat(android): add check for excluded domains before ssl request
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsChaceD authored Jun 29, 2023
1 parent 7f5f0ca commit 7906d36
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URI;
Expand Down Expand Up @@ -396,7 +397,7 @@ public static JSObject request(PluginCall call, String httpMethod, Bridge bridge

CapacitorHttpUrlConnection connection = connectionBuilder.build();

if (null != bridge) {
if (null != bridge && !isDomainExcludedFromSSL(bridge, url)) {
connection.setSSLSocketFactory(bridge);
}

Expand All @@ -414,6 +415,16 @@ public static JSObject request(PluginCall call, String httpMethod, Bridge bridge
return buildResponse(connection, responseType);
}

private static Boolean isDomainExcludedFromSSL(Bridge bridge, URL url) {
try {
Class<?> sslPinningImpl = Class.forName("io.ionic.sslpinning.SSLPinning");
Method method = sslPinningImpl.getDeclaredMethod("isDomainExcluded", Bridge.class, URL.class);
return (Boolean) method.invoke(sslPinningImpl.newInstance(), bridge, url);
} catch (Exception ignored) {
return false;
}
}

@FunctionalInterface
public interface ProgressEmitter {
void emit(Integer bytes, Integer contentLength);
Expand Down

0 comments on commit 7906d36

Please sign in to comment.