Your app(s) are using an unsafe implementation of the HostnameVerifier interface.

最近在把APP上架到Google Play的时候,被拒了,提示如下:

HostnameVerifier
Your app(s) are using an unsafe implementation of the HostnameVerifier interface. You can find more information about how resolve the issue in this Google Help Center article.

原因:

以下来自谷歌官方的介绍:

在与使用 setDefaultHostnameVerifier API 的远程主机建立 HTTPS 连接时,这种实施方式会接受所有主机名,从而使您的应用容易受到中间人攻击。攻击者可能会读取传输的数据(例如登录凭据),甚至更改通过 HTTPS 连接传输的数据。

从 2017 年 3 月 1 日起,只要新应用或应用更新采用的 HostnameVerifier 的实施方式不安全,一律禁止在 Google Play 发布。您已发布的 APK 版本不会受到影响,但是,如果不解决此漏洞,您将无法为应用发布任何更新。

为了正确处理主机名验证,请更改您的自定义 HostnameVerifier 接口中的验证方法,指定在服务器的主机名不符合您的预期时返回 False。

解决

根据谷歌的提示,解决方法,就是代码中判断https连接的主机名,是否是自己期待的。防止中间人攻击。

 HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                //可以这样判断
                if (hostname.equals("xx.xx.xx.xx")) {
                    return true;
                } else {
                    return false;
                }
            }
});

如果你自己的代码中,没有使用过setDefaultHostnameVerifier 这样的函数,检查一下你的第三方网络请求库,有没有HostnameVerifier的地方。

例如:xUtils3 在这次提交中, 添加了HostnameVerifier参数,在代码中,实现相应的函数,就可以解决这个问题了

之前在网上看到有人说,直接返回true,但是上架后还是被拒

参考:

Google Play Security Alert - Your app is using an unsafe implementation of the HostnameVerifier

https://support.google.com/faqs/answer/7188426

xUtils3 添加HostnameVerifier参数

猜你喜欢

转载自blog.csdn.net/xx326664162/article/details/81109976