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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...