我正在做一个与HTTPS服务器连接的应用程序。我已经阅读了很多教程,但我没有一个理想的解决方案。
在服务器中,我有一个自签名证书。我在客户端部分做了什么?我阅读了官方教程:http://developer.android.com/training/articles/security-ssl.html但是,如果我加载相同的证书应用程序崩溃此异常javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
有些想法或例子吗?
由于
答案 0 :(得分:0)
您需要将其添加到您的请求中。
例如改装
OkHttpClient client = new OkHttpClient();
try {
KeyStore keyStore = readKeyStore(this);
SSLContext sslContext = SSLContext.getInstance("SSL");
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(keyStore);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, "keystore_pass".toCharArray());
sslContext.init(keyManagerFactory.getKeyManagers(),trustManagerFactory.getTrustManagers(), new SecureRandom());
client.setSslSocketFactory(sslContext.getSocketFactory());
} catch (Exception e) {
e.printStackTrace();
}
然后
.setClient(new OkClient(client))
到RestAdapter.Builder()