自签名的SSL接受Android的 [英] Self Signed SSL acceptance Android

查看:189
本文介绍了自签名的SSL接受Android的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处找在互联网上,而另一些人声称已经找到了解决方案,它要么不工作或没有样品code来支持它。
有谁知道如何接受在Java中对Android的自签名的证书?
A code样品将是完美的。

I've looked everywhere on the internet and while some people claim to have found the solution, it either does not work or there is no sample code to back it up.
Does anyone know how to accept a self signed cert in Java on the Android?
A code sample would be perfect.

推荐答案

我有这样的功能在exchangeIt,其中通过WebDAV连接到Microsoft Exchange。下面是一些code创建一个HttpClient的,将通过SSL连接到自签名证书的:

I have this functionality in exchangeIt, which connects to Microsoft exchange via WebDav. Here's some code to create an HttpClient which will connect to self signed cert's via SSL:

SchemeRegistry schemeRegistry = new SchemeRegistry();
// http scheme
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
// https scheme
schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));

HttpParams params = new BasicHttpParams();
params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);
params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));
params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);

ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);

该EasySSLSocketFactory是<一个href="http://$c$c.google.com/p/exchangeit/source/browse/trunk/src/com/byarger/exchangeit/EasySSLSocketFactory.java?spec=svn23&r=23">here,而EasyX509TrustManager是<一个href="http://$c$c.google.com/p/exchangeit/source/browse/trunk/src/com/byarger/exchangeit/EasyX509TrustManager.java?spec=svn23&r=23">here.

The EasySSLSocketFactory is here, and the EasyX509TrustManager is here.

在$ C $下exchangeIt是开源的,并托管在谷歌code 这里如果你有任何问题。我不积极就可以了,但code应该工作。

The code for exchangeIt is open source, and hosted on googlecode here, if you have any issues. I'm not actively working on it anymore, but the code should work.

请注意,由于Android 2.2的过程中已经改变了一点,所以检查<一href="http://stackoverflow.com/questions/2899079/custom-ssl-handling-stopped-working-on-android-2-2-froyo">this使code以上的工作。

Note that since Android 2.2 the process has changed a bit, so check this to make the code above work.

这篇关于自签名的SSL接受Android的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆