本文介绍了安全固定:javax.net.ssl​​.SSLPeerUnverifiedException:没有对方的证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有几十个帖子对这个问题(javax.net.ssl​​.SSLPeerUnverifiedException:没有对方的证书),但我还没有发现任何东西,对我的作品

There are dozens of posts about this issue (javax.net.ssl.SSLPeerUnverifiedException: No peer certificate) but I haven't found anything that works for me.

许多职位(如this,和this) 解决这允许所有证书被接受​​,但是,当然,这不是以外的其他测试一个很好的解决方案。

Many posts (like this, and this) "solve" this by allowing all certificates to be accepted but, of course, this is not a good solution for anything other than testing.

在别人看来很本地化,并没有为我工作。我真的很希望有人有一些是我缺乏洞察力。

Others seem quite localized and don't work for me. I really hope that someone has some insight that I lack.

所以,我的问题:我测试只能通过本地网络的服务器上,通过HTTPS连接。使我通过浏览器需要调用工作正常。无抱怨的证书,如果你检查证书,这一切看起来不错。

So, my problem: I'm testing on a server accessible only through the local network, connecting via HTTPS. Making the call I need to through the browser works fine. No complaining about certificates and if you check the certificates, it all looks good.

当我尝试我的Andr​​oid设备上,我得到 javax.net.ssl​​.SSLPeerUnverifiedException:没有对方的证书

When I try on my Android device, I get javax.net.ssl.SSLPeerUnverifiedException: No peer certificate

这里的code调用它:

Here's the code that calls it:

StringBuilder builder = new StringBuilder();
builder.append( /* stuff goes here*/ );

httpGet.setEntity(new UrlEncodedFormEntity(nameValuePairs));
ResponseHandler<String> responseHandler = new BasicResponseHandler();

// Execute HTTP Post Request. Response body returned as a string
HttpClient httpClient = MyActivity.getHttpClient();
HttpGet httpGet = new HttpGet(builder.toString());

String jsonResponse = httpClient.execute(httpGet, responseHandler); //Line causing the Exception

我的$ C $下 MyActivity.getHttpClient()

protected synchronized static HttpClient getHttpClient(){
    if (httpClient != null)
        return httpClient;

    HttpParams httpParameters = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpParameters, TIMEOUT_CONNECTION);
    HttpConnectionParams.setSoTimeout(httpParameters, TIMEOUT_SOCKET);
    HttpProtocolParams.setVersion(httpParameters, HttpVersion.HTTP_1_1);

    //Thread safe in case various AsyncTasks try to access it concurrently
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(httpParameters, schemeRegistry);

    httpClient = new DefaultHttpClient(cm, httpParameters);

    CookieStore cookieStore = httpClient.getCookieStore();
    HttpContext localContext = new BasicHttpContext();
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    return httpClient;
}

任何帮助将是非常美联社preciated。

Any help would be much appreciated.

修改

也只提我有其他SSL的问题与其他应用程序,但添加 SchemeRegistry 部分之前修复它为我。

Also just to mention I've had other SSL issues with another app but adding the SchemeRegistry portion fixed it for me before.

编辑2

到目前为止,我只测试了在Android 3.1,但我需要这个工作在Android 2.2+不管。我只是测试浏览器在我的Andr​​oid选项卡(安卓3.1),并抱怨证书。它的罚款在我的电脑的浏览器,但不是在Android浏览器或我的应用程序。

So far I've only tested on Android 3.1, but I need this to work on Android 2.2+ regardless. I just tested on the browser on my Android tab (Android 3.1) and it complains about the certificate. It's fine on my pc browser, but not on the Android browser or in my app.

修改3

原来iOS的浏览器还抱怨它。我开始认为这是这里所描述的证书链问题( SSL证书不被信任 - 在移动仅

Turns out the iOS browser also complains about it. I'm starting to think it's a certificate chain issue described here (SSL certificate is not trusted - on mobile only)

推荐答案

原来,我的code是好的,问题是,服务器没有返回完整的证书链。欲了解更多信息,请参阅本SO张贴这超级用户后:

It turns out my code was fine and the problem was that the server was not returning the full certificate chain. For more information see this SO post and this superuser post:

SSL证书不被信任 - 在移动仅

http://superuser.com/questions/347588/how-do-ssl-chains-work

这篇关于安全固定:javax.net.ssl​​.SSLPeerUnverifiedException:没有对方的证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 23:34