mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-05-12 00:03:02 +08:00
remove explicit host name verification setting on Android
This commit is contained in:
@@ -302,10 +302,13 @@ public class HttpRequest {
|
|||||||
try {
|
try {
|
||||||
if (mode == CERT_MODE_TRUSTALL) {
|
if (mode == CERT_MODE_TRUSTALL) {
|
||||||
SOCKET_FACTORY = createSocketFactory(getNoopTrustManagers());
|
SOCKET_FACTORY = createSocketFactory(getNoopTrustManagers());
|
||||||
|
HOSTNAME_VERIFIER = getTrustedVerifier();
|
||||||
} else if (mode == CERT_MODE_PINNED) {
|
} else if (mode == CERT_MODE_PINNED) {
|
||||||
SOCKET_FACTORY = createSocketFactory(getPinnedTrustManagers());
|
SOCKET_FACTORY = createSocketFactory(getPinnedTrustManagers());
|
||||||
|
HOSTNAME_VERIFIER = null;
|
||||||
} else {
|
} else {
|
||||||
SOCKET_FACTORY = null;
|
SOCKET_FACTORY = null;
|
||||||
|
HOSTNAME_VERIFIER = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
CURRENT_CERT_MODE = mode;
|
CURRENT_CERT_MODE = mode;
|
||||||
@@ -314,19 +317,6 @@ public class HttpRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Configure host name verification for all future HTTPS connections
|
|
||||||
*
|
|
||||||
* @param enabled
|
|
||||||
*/
|
|
||||||
public static void setHostnameVerification(boolean enabled) {
|
|
||||||
if (enabled) {
|
|
||||||
HOSTNAME_VERIFIER = null;
|
|
||||||
} else {
|
|
||||||
HOSTNAME_VERIFIER = getTrustedVerifier();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TrustManager[] getPinnedTrustManagers() throws IOException {
|
private static TrustManager[] getPinnedTrustManagers() throws IOException {
|
||||||
if (PINNED_CERTS == null) {
|
if (PINNED_CERTS == null) {
|
||||||
throw new IOException("You must add at least 1 certificate in order to pin to certificates");
|
throw new IOException("You must add at least 1 certificate in order to pin to certificates");
|
||||||
|
|||||||
@@ -100,10 +100,8 @@ public class CordovaHttpPlugin extends CordovaPlugin {
|
|||||||
|
|
||||||
if (accept) {
|
if (accept) {
|
||||||
HttpRequest.setSSLCertMode(HttpRequest.CERT_MODE_TRUSTALL);
|
HttpRequest.setSSLCertMode(HttpRequest.CERT_MODE_TRUSTALL);
|
||||||
HttpRequest.setHostnameVerification(false);
|
|
||||||
} else {
|
} else {
|
||||||
HttpRequest.setSSLCertMode(HttpRequest.CERT_MODE_DEFAULT);
|
HttpRequest.setSSLCertMode(HttpRequest.CERT_MODE_DEFAULT);
|
||||||
HttpRequest.setHostnameVerification(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
callbackContext.success();
|
callbackContext.success();
|
||||||
@@ -169,10 +167,8 @@ public class CordovaHttpPlugin extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HttpRequest.setSSLCertMode(HttpRequest.CERT_MODE_PINNED);
|
HttpRequest.setSSLCertMode(HttpRequest.CERT_MODE_PINNED);
|
||||||
HttpRequest.setHostnameVerification(true);
|
|
||||||
} else {
|
} else {
|
||||||
HttpRequest.setSSLCertMode(HttpRequest.CERT_MODE_DEFAULT);
|
HttpRequest.setSSLCertMode(HttpRequest.CERT_MODE_DEFAULT);
|
||||||
HttpRequest.setHostnameVerification(true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user