Created
March 27, 2011 17:25
-
-
Save aembleton/889392 to your computer and use it in GitHub Desktop.
The following code disables SSL certificate checking for any new instances of HttpsUrlConnection
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
/** | |
* Disables the SSL certificate checking for new instances of {@link HttpsURLConnection} This has been created to | |
* aid testing on a local box, not for use on production. | |
*/ | |
private static void disableSSLCertificateChecking() { | |
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() { | |
public X509Certificate[] getAcceptedIssuers() { | |
return null; | |
} | |
@Override | |
public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { | |
// Not implemented | |
} | |
@Override | |
public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException { | |
// Not implemented | |
} | |
} }; | |
try { | |
SSLContext sc = SSLContext.getInstance("TLS"); | |
sc.init(null, trustAllCerts, new java.security.SecureRandom()); | |
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); | |
} catch (KeyManagementException e) { | |
e.printStackTrace(); | |
} catch (NoSuchAlgorithmException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this works for me, im using a bareworkflow react native expo
i create a file called IgnoreSSLFactory.kt in the same path as MainApplication.kt
package your package
import com.facebook.react.modules.network.OkHttpClientFactory
import com.facebook.react.modules.network.ReactCookieJarContainer
import okhttp3.OkHttpClient
import java.security.cert.X509Certificate
import java.util.concurrent.TimeUnit
import javax.net.ssl.*
class IgnoreSSLFactory : OkHttpClientFactory {
}
and then i use in MainApplication.kt
override fun onCreate() {
super.onCreate()
SoLoader.init(this, false)
OkHttpClientProvider.setOkHttpClientFactory(IgnoreSSLFactory()); // HERE
}
then just run gradlew clean, and run your application