且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

信任锚找不到为Android SSL连接

更新时间:2022-10-16 11:14:34

@Chrispix的解决方案是很危险的!信任所有证书允许任何人做了中间人攻击!只需发送任何证书给客户端,它会接受它!

添加您证书就像在这篇文章中描述的自定义信任管理器:Trusting使用HttpClient的所有证书通过HTTPS

此外,它是比较复杂的,建立一个自定义证书的安全连接的一点,它会带给你不男人在中间攻击的危险通缉的SSL加密的安全性!

I am trying to connect to an IIS6 box running a godaddy 256bit SSL cert, and I am getting the error :

java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.

Been trying to determine what could be causing that, but drawing blanks right now.

Here is how I am connecting :

HttpsURLConnection conn;              
conn = (HttpsURLConnection) (new URL(mURL)).openConnection();
conn.setConnectTimeout(20000);
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
String tempString = toString(conn.getInputStream()); 

The solution of @Chrispix is dangerous! Trusting all certificates allows anybody to do a man in the middle attack!!! Just send ANY certificate to the client and it will accept it!!!

Add you certificate to a custom trust manager like described in this post: Trusting all certificates using HttpClient over HTTPS

Also it is a bit more complex to establish a secure connection with a custom certificate, it will bring you the wanted ssl encryption security without the danger of man in the middle attack!