Bra*_*bra 5 ssl https android ssl-certificate httpsurlconnection
那里.我需要与https://free.temafon.ru建立https连接,但我在Android 2.3及更低版本上有CertPathValidatorException.我做了什么.
Init ssl上下文:
final KeyStore keystore = KeyStore.getInstance("BKS");
keystore.load(getResources().openRawResource(R.raw.temafon),
"W0d3Uoa5PkED".toCharArray());
final TrustManager trustManager = new TemafonTrustManager(keystore);
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { trustManager }, null);
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext
.getSocketFactory());
Run Code Online (Sandbox Code Playgroud)
在这里,我使用自定义TrustManager,因为服务器以错误的顺序发送证书.
这段代码在Android 4.0上工作正常,但2.3在 java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.我正在做的事情上失败了吗?
我已经创建了一个测试项目,可以在这里找到.