httpclient ssl certificate on android(android上的httpclient ssl证书)
问题描述
我在使用 ssl 在 android 上使用 httpclient 时遇到了一些问题我正在尝试详细访问自签名证书我希望我的应用程序信任所有证书(我将仅使用 ssl 进行数据加密).首先我尝试使用本指南 http://hc.apache.org/httpclient-桌面上的 3.x/sslguide.html 工作正常,但在 android 上我仍然得到 javax.net.ssl.SSLException: Not trust server certificate.在谷歌搜索后,我发现了一些其他如何启用 ssl 的示例.
http://groups.google.com/group/android-developers/browse_thread/thread/62d856cdcfa9f16e - 当我使用 URLConnection 但使用 HttpClient 时工作仍然出现异常.
http://www.discursive.com/books/cjcook/reference/http-webdav-sect-self-signed.html - 在桌面上使用来自 apache 的 jar 可以正常工作,但在 android 中使用 SDK 类中包含的无法使其工作.p>
http://mail-archives.apache.org/mod_mbox/hc-httpclient-users/200808.mbox/%3C1218824624.6561.14.camel@ubuntu%3E - 也得到同样的例外
所以任何想法我如何使用 HttpClient 信任 android 上的所有证书
如果你碰巧看到 DefaultHttpClient 的代码是这样的:
@Override受保护的 ClientConnectionManager createClientConnectionManager() {SchemeRegistry 注册表 = new SchemeRegistry();注册表.注册(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));注册表.注册(新方案(https",SSLSocketFactory.getSocketFactory(),443));ClientConnectionManager connManager = null;HttpParams 参数 = getParams();...}注意 https 方案到 org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory() 的映射.
您可以为 org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory 接口(http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/protocol/SecureProtocolSocketFactory.html) 其中,您可以使用接受所有证书的自定义 TrustManager 创建 java.net.SSLSocket.
您可能希望在 http://java.sun.com/j2se/1.4.2/docs/guide/security/jsse/JSSERefGuide.html
I have some troubles with ssl using httpclient on android i am trying to access self signed certificate in details i want my app to trust all certificates ( i will use ssl only for data encryption). First i tried using this guide http://hc.apache.org/httpclient-3.x/sslguide.html on Desktop is working fine but on android i still got javax.net.ssl.SSLException: Not trusted server certificate. After searching in google i found some other examples how to enable ssl.
http://groups.google.com/group/android-developers/browse_thread/thread/62d856cdcfa9f16e - Working when i use URLConnection but with HttpClient still got the exception.
http://www.discursive.com/books/cjcook/reference/http-webdav-sect-self-signed.html - on Desktop using jars from apache is working but in android using included in SDK classes can't make it work.
http://mail-archives.apache.org/mod_mbox/hc-httpclient-users/200808.mbox/%3C1218824624.6561.14.camel@ubuntu%3E - also get the same exception
So any ideas how can i trust all certificates on android using HttpClient
If you happen to look at the code of DefaultHttpClient, it looks something like this:
@Override
protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(
new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(
new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));
ClientConnectionManager connManager = null;
HttpParams params = getParams();
...
}
Notice the mapping of https scheme to org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory().
You can create a custom implementation for org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory interface (http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/protocol/SecureProtocolSocketFactory.html) wherein, you can create java.net.SSLSocket with a custom TrustManager that accepts all certificate.
You may want to look into JSSE for more details at http://java.sun.com/j2se/1.4.2/docs/guide/security/jsse/JSSERefGuide.html
这篇关于android上的httpclient ssl证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:android上的httpclient ssl证书
基础教程推荐
- NSString intValue 不能用于检索电话号码 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
