如何解决TrustManager 和自签名证书:从 Play 商店中删除的应用
Google 在圣诞节没有警告的情况下从 Play 商店中删除了我的应用!
原因是使用了自己的 TrustManager。 我的应用连接到使用自签名证书的互联网路由器 (FRITZ!Box)。
这是我的 TrustManager 的实现:
public class TrustAllManager implements x509trustmanager {
...
@Override
public void checkServerTrusted(X509Certificate[] chain,String authType) throws CertificateException {
// read prevIoUs stored cert fingerprint hash from Preferences
String fingerprintStored = readCertFromPreferences(...)
// get hash string from server cert
String fingerprintServer = null;
for (X509Certificate cert : chain) {
fingerprintServer = certificateFingerprint(cert);
break;
}
// compare server cert with stored cert. If not equal,throw Exception!
if (fingerprintStored != null && fingerprintServer != null && !fingerprintServer.equals(fingerprintStored))
throw new CertificateException("error cert");
}
}
在 https://support.google.com/faqs/answer/6346016?hl=en,Google 说:
确保方法中未捕获由 checkServerTrusted 引发的异常。这会导致 checkServerTrusted 正常退出,导致应用信任有害证书。
这个我不明白。否则,我应该在什么时候检查证书是否有效?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。