【发布时间】:2018-01-24 10:45:17
【问题描述】:
更新了我的应用程序以信任 sdk 17 及以下版本的 volley 中的所有证书,因为 volley 在没有更高 sdk 的主机名验证器的情况下可以正常工作。它运行良好,但谷歌拒绝了我的应用更新说
您的应用正在使用 HostnameVerifier 接口的不安全实现。
我正在使用以下代码
TrustManager[] trustAllCertsc = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
SSLContext scc = null;
try {
scc = SSLContext.getInstance("SSL");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
try {
scc.init(null, trustAllCertsc, new java.security.SecureRandom());
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(scc.getSocketFactory());
// Create all-trusting host name verifier
HostnameVerifier allHostsValidc = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValidc);
【问题讨论】:
标签: android ssl-certificate android-volley hostname android-security