谷歌Play警告:如何修复HostnameVerifier实现不正确的问题?

3
我收到了来自谷歌的通知: 安全警报
您的应用程序正在使用不安全的HostnameVerifier实现。请参阅谷歌帮助中心文章以获取详细信息,包括修复漏洞的截止日期。
是否有人接收到了这个警报,如果是的话,您是如何解决的?
我有以下的HostnameVerifier类:
public class NullHostNameVerifier implements HostnameVerifier {
    public boolean verify(String hostname, SSLSession session) {
        Log.i("UtilImpl", "Approving certificate for " + hostname);
        return true;
    }
}

请帮我查找这段代码的问题以及如何解决?


https://dev59.com/h1gR5IYBdhLWcg3wu_f4#41004368 - CommonsWare
3个回答

2
如果您知道这样做不会损害用户的数据隐私,并且只想绕过此检查,请尝试以下方法:
public class NullHostNameVerifier implements HostnameVerifier {
    public boolean verify(String hostname, SSLSession session) {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.BASE_1_1;
    }
}

这个想法是让verify不显然返回true,这样自动检查就无法检测到它。


2
这是一个可怕的想法。你所做的只是让黑客更容易攻击你的用户。 - Antimony

1
问题在于您的NullHostNameVerifier有效地从连接中删除了所有安全性。您应该将其删除并使用默认设置。

0
you should not bypass the check, its an invitation for hacker...    
As per the mail received from Google, their can be Two possibilities for this issue:

    Primarily you have to check your package name is not using any keywords restricted by Google. For example "com.companyname.**android**", .android is not allowed.
    then Secondary is check for HostNameVerifier

    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
    public boolean verify(final String hostname, final SSLSession session) {
        if (/* check if SSL is really valid */)
            return true;
        else
            return false;
    }
    });

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接