【发布时间】:2016-02-20 23:53:54
【问题描述】:
Google 已告知我在我的 Android 应用程序中有一个不安全的接口 X509TrustManager 实现,需要按如下方式更改我的代码:
要正确处理 SSL 证书验证,请在 自定义 X509TrustManager 接口的 checkServerTrusted 方法 无论何时引发 CertificateException 或 IllegalArgumentException 服务器提供的证书不符合您的要求 期望。对于技术问题,您可以发布到 Stack Overflow 并使用标签“android-security”和“TrustManager”。
如何修改以下代码来解决上述问题?
public EasySSLSocketFactory(KeyStore truststore) throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
super(truststore);
TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
mContext.init(null, new TrustManager[] { tm }, null);
}
【问题讨论】:
-
我也遇到这个问题,请问有解决办法吗?
-
"如何修改以下代码来解决上述问题?" -- 你删除它。
标签: android-security trustmanager