我在 Google Play Store 上上传的 Android Build 收到了安全警报。
“您的应用在 Apache HTTP 客户端上使用了不安全的 X509TrustManager 接口实现,从而导致了安全漏洞。请参阅此 Google 帮助中心文章了解详细信息,包括修复漏洞的截止日期。”
我尝试通过实现以下代码来修复它并更新我的构建
public class MySSLSocketFactory extends SSLSocketFactory {
SSLContext sslContext = SSLContext.getInstance("TLS");
public MySSLSocketFactory(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;
}
};
sslContext.init(null, new TrustManager[] { tm }, null);
}
@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
return sslContext.getSocketFactory().createSocket(socket, host, port, autoClose);
}
@Override
public Socket createSocket() throws IOException {
return sslContext.getSocketFactory().createSocket();
}
}
但我仍然收到安全警报。
还有一个问题是我不想一次又一次地更新我的实时应用程序以删除此安全警报。有什么方法可以上传我的构建并检查更改是否完美完成并且可以使用相同的应用程序。
更新:我还在 checkServerTrusted() 中添加以下行
try {
chain[0].checkValidity();
} catch (CertificateExpiredException e) {
Logger.e(TAG, "CertificateExpiredException");
throw new CertificateException("CertificateExpiredException");
} catch (CertificateNotYetValidException e) {
Logger.e(TAG, "CertificateNotYetValidException");
throw new CertificateException("CertificateNotYetValidException");
}