Android HTTPS SNI support using SSLCertificateSocketFactory

做~自己de王妃 提交于 2019-12-01 04:43:56

You can use the NetCipher library to get a modern TLS config when using Android's HttpsURLConnection including SNI support. NetCipher configures the HttpsURLConnection instance to use the best supported TLS version, as well as the best suite of ciphers for that TLS version. First, add it to your build.gradle:

compile 'info.guardianproject.netcipher:netcipher:2.0.0-alpha1'

Or you can download the netcipher.jar and include it directly in your app. Then instead of calling:

HttpURLConnection connection = (HttpURLConnection) sourceUrl.openConnection();

Call this:

HttpsURLConnection connection = NetCipher.getHttpsURLConnection(sourceUrl);

If you want to see how its done in the code, look at TlsOnlySocketFactory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!