验证SSL认证Java/Android

验证SSL认证Java/Android,java,android,security,ssl,Java,Android,Security,Ssl,我让我的android应用程序与受SSL证书保护的服务器通信。下面是代码 final HttpPost httppost = new HttpPost("https://www.myurl.com"); final List<NameValuePair> postlist = Utils.HttpGetToHttpPost(Arguments); httppost.setEntity(new UrlEncodedFormEntity(postlist)); final HttpRes

我让我的android应用程序与受SSL证书保护的服务器通信。下面是代码

final HttpPost httppost = new HttpPost("https://www.myurl.com");
final List<NameValuePair> postlist = Utils.HttpGetToHttpPost(Arguments);
httppost.setEntity(new UrlEncodedFormEntity(postlist));
final HttpResponse response = httpclient.execute(httppost);
final-HttpPost-HttpPost=新的HttpPost(“https://www.myurl.com");
final List postlist=Utils.httpgettohtppost(参数);
setEntity(新的UrlEncodedFormEntity(postlist));
最终HttpResponse response=httpclient.execute(httppost);

现在我的问题是如何防止MITM攻击。如何确保我与myurl.com交谈而不是与其他url交谈。

您可以通过以下方式限制HTTPS主机名验证:

SSLSocketFactory sf = new SSLSocketFactory(SSLContext.getInstance("TLS"));
sf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);

有关使用Java SSL连接进行自定义的详细信息,请参阅。

经过快速研究后

使用java和仅使用SSL通信的信任存储库,可能是您在中间攻击中最好的保护。如果Java不能信任服务器提供的证书,它将立即抛出异常

根据我读到的内容,黑客很难模拟证书颁发机构给站点的密钥

不过我可能错了