【问题标题】:Issue with SSL certificate: "No peer certificate"SSL 证书问题:“无对等证书”
【发布时间】:2013-09-05 02:13:43
【问题描述】:

我正在尝试通过Last.fm's API 进行身份验证。

在 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);

但是在 2.3.3 我得到了

javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

然后我尝试了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);

但我仍然遇到同样的错误。

然后我尝试了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);

又失败了。

有人可以帮忙吗?

【问题讨论】:

  • 使用 2.3.3 模拟器或设备?
  • 设备:三星 Galaxy S1
  • 快速测试。你能在 Galaxy S 浏览器中打开网址吗?ws.audioscrobbler.com/2.0 前面有https://
  • 网页不可用。 https://ws.audioscrobbler.com:445/2.0/ 的网页可能会暂时关闭...
  • 哎呀。没有端口号

标签: android ssl apache-commons-httpclient


【解决方案1】:

从服务器返回证书的方式似乎存在一些问题,或者可能是 android 系统密钥库没有相关的根证书来验证和完成握手。

查看问题中提到的站点的certificate chain information,在我看来,链没有正确排序。

你可以试试答案here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-20
    • 2012-02-07
    • 1970-01-01
    • 2015-11-21
    • 2015-05-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多