【问题标题】:Google rejected app because of HostnameVerifier issue由于 HostnameVerifier 问题,Google 拒绝了应用
【发布时间】: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


    【解决方案1】:

    删除所有这些代码。您将无法通过多次 Play 商店检查(HostnameVerifier 和全部接受 TrustManager)。另外,Play 商店拒绝您的应用的原因是,通过此代码,您正在削弱应用的安全性

    【讨论】:

    • 但是在删除我的应用程序时将无法在低于 API 17 的设备上运行
    • @aishrauto:要么将您的 minSdkVersion 设置为 17,要么找到其他不涉及削弱应用程序安全性的解决方案。例如,如果您尝试对特定服务器使用 HTTPS,而 Android 无法识别该服务器的根 SSL 证书,teach your HTTP client to trust your server's certificate
    【解决方案2】:

    我不建议您使用不安全的 HTTP 请求继续开发您的应用程序

    但是,如果您根本不关心安全性,您可以使用以下代码代替Volley 并在PlayStore 获得批准:

    private static void disableSSLCertificateChecking() {
        TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
    
            @Override
            public void checkClientTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                // Not implemented
            }
    
            @Override
            public void checkServerTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                // Not implemented
            }
        }};
    
        try {
            SSLContext sc = SSLContext.getInstance("TLS");
    
            sc.init(null, trustAllCerts, new java.security.SecureRandom());
    
            HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
        } catch (KeyManagementException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-12-17
      • 1970-01-01
      • 2022-06-16
      • 1970-01-01
      • 2017-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多