简体   繁体   English

SSL证书问题:“无对等证书”

[英]Issue with SSL certificate: “No peer certificate”

I'm trying to authenticate through Last.fm's API . 我正在尝试通过Last.fm的API进行身份验证。

On Android 4.3 it works just by doing 在Android 4.3上,它只能通过以下方式工作

HttpPost post = new HttpPost("https://ws.audioscrobbler.com/2.0/");
post.setEntity(new UrlEncodedFormEntity(params));

HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(post);

but on 2.3.3 I get 但是在2.3.3上我得到了

javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

Then I tried the solution given here : 然后我尝试了这里给出的解决方案:

HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;

DefaultHttpClient client = new DefaultHttpClient();

SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
registry.register(new Scheme("https", socketFactory, 443));
SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());

// Set verifier     
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);        

HttpPost post = new HttpPost("https://ws.audioscrobbler.com/2.0/");
post.setEntity(new UrlEncodedFormEntity(params));

HttpResponse response = httpClient.execute(post);

but I still get the same error. 但我仍然遇到相同的错误。

Then I tried that : 然后我尝试

HttpParams httpParams = new BasicHttpParams();
HttpProtocolParams.setVersion(httpParams, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(httpParams, HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(httpParams, true);

SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
schReg.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager conMgr = new ThreadSafeClientConnManager(httpParams, schReg);

DefaultHttpClient httpClient = new DefaultHttpClient(conMgr, httpParams);

HttpPost post = new HttpPost("https://ws.audioscrobbler.com/2.0/");
post.setEntity(new UrlEncodedFormEntity(params));

HttpResponse response = httpClient.execute(post);

and failed again. 并再次失败。

Anybody can help? 有人可以帮忙吗?

There seems to be some problem with the way the certificates are returned from the server OR may be android system keystore does not have the relevant root certs to validate and complete the handshake. 从服务器返回证书的方式似乎存在问题,或者可能是android系统密钥库没有相关的根证书来验证和完成握手。

Looking at the certificate chain information for the site mentioned in the question, it seems to me that the chain is not correctly sorted. 查看问题中提到的站点的证书链信息 ,在我看来,该链未正确排序。

You can try the answer here 您可以在这里尝试答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM