微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

更新我的应用程序时出现 TrustManager 漏洞错误

如何解决更新我的应用程序时出现 TrustManager 漏洞错误

我正在更新 Playstore 上已有的应用程序,但未更改 SSL 代码,但更新被拒绝。我收到 TrustManager 漏洞的错误。下面是实现 TrustManager 的代码。该应用正在使用来自两个基本网址的数据,对此有任何破解吗?

公共类 SSLTrust {

public static void nuke() {
    try {
        TrustManager[] trustAllCerts = new TrustManager[] {
                new x509trustmanager() {
                    public X509Certificate[] getAcceptedissuers() {
                        X509Certificate[] myTrustedAnchors = new X509Certificate[0];
                        return myTrustedAnchors;
                    }

                    @Override
                    public void checkClientTrusted(X509Certificate[] certs,String authType) throws CertificateException  {
                        try {
                            certs[0].checkValidity();
                        } catch (Exception e) {
                            throw new CertificateException("Certificate not valid or trusted.");
                        }

                    }

                    @Override
                    public void checkServerTrusted(X509Certificate[] certs,String authType) throws CertificateException{
                        try {
                            certs[0].checkValidity();

                        } catch (Exception e) {
                            throw new CertificateException("Certificate not valid or trusted.");
                        }

                    }
                }
        };

        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null,trustAllCerts,new SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String hostname,SSLSession arg1) {

                String text    =
                        "This is the text to be searched " +
                                "for occurrences of the http:// pattern.";

                String patternString = ".*https://.*";

                Pattern pattern = Pattern.compile(patternString);

                Matcher matcher = pattern.matcher(text);

                if(!hostname.equalsIgnoreCase(Config.GETAFFILIATION_URL)
                        ||!hostname.equalsIgnoreCase(Config.SENDDATATODB_URL2)
                        
                        ||!hostname.equalsIgnoreCase(Config.GETUSERMFLCODE_URL)){

                    return true;

                }
                else{

                    return false;
                }

            }
        });
    } catch (Exception e) {
    }
}

}

解决方法

正如我所见,你没有信任任何东西。 如果您想自己信任 URL 的 SSL。 首先,您必须下载该站点的证书。它是一个 .cer 文件,然后将该文件保存在源代码中的 /res/raw 文件夹中。 在您的信任 SSL 功能中,您需要使用此文件与应用程序打开的 URL 进行比较。 检查以下链接: https://developer.android.com/training/articles/security-ssl#SelfSigned

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。