2016-12-24 177 views
2

我收到谷歌通知说: 安全警报Google Play警告:如何修复HostnameVerifier的错误实施?

您的应用程序正在使用不安全的HostnameVerifier实现。有关详细信息,请参阅此Google帮助中心文章,其中包括修复漏洞的最后期限。

有没有人收到此警报,如果是的话,你是如何解决它?

我有HostnameVeriefier类,如下所示:

public class NullHostNameVerifier implements HostnameVerifier { 
    public boolean verify(String hostname, SSLSession session) { 
     Log.i("UtilImpl", "Approving certificate for " + hostname); 
     return true; 
    } 
} 

请帮我找到什么是错用此代码?以及如何解决它?

+0

https://stackoverflow.com/a/41004368/115145 – CommonsWare

回答

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,所以自动检查将无法检测到它

+1

这是一个可怕的想法。你所做的只是让你的用户更容易受到攻击。 – 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; 
    } 
    });