Last active
January 6, 2024 07:32
-
-
Save manniru/577b031acc3a6146339930720cdc23ca to your computer and use it in GitHub Desktop.
Disable SSL Certificate on Android Volley for Testing only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class NukeSSLCerts { | |
protected static final String TAG = "NukeSSLCerts"; | |
public static void nuke() { | |
try { | |
TrustManager[] trustAllCerts = new TrustManager[] { | |
new X509TrustManager() { | |
public X509Certificate[] getAcceptedIssuers() { | |
X509Certificate[] myTrustedAnchors = new X509Certificate[0]; | |
return myTrustedAnchors; | |
} | |
@Override | |
public void checkClientTrusted(X509Certificate[] certs, String authType) {} | |
@Override | |
public void checkServerTrusted(X509Certificate[] certs, String authType) {} | |
} | |
}; | |
SSLContext sc = SSLContext.getInstance("SSL"); | |
sc.init(null, trustAllCerts, new SecureRandom()); | |
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); | |
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { | |
@Override | |
public boolean verify(String arg0, SSLSession arg1) { | |
return true; | |
} | |
}); | |
} catch (Exception e) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Working for me, Thanks :)