Android上的自签名SSL接受 [英] Self-signed SSL acceptance on Android

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

问题描述

如何在Android上的Java中接受自签名证书?

How do I accept a self-signed certificate in Java on Android?

一个代码示例将是完美的.

A code sample would be perfect.

我在Internet上到处都是,虽然有人声称找到了该解决方案,但它要么不起作用,要么没有示例代码来备份它.

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.

推荐答案

exchangeIt中具有此功能,该功能可通过WebDav连接到Microsoft Exchange.这是创建HttpClient的一些代码,该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是此处,而EasyX509TrustManager是

The EasySSLSocketFactory is here, and the EasyX509TrustManager is here.

用于交换的代码它是开源的,托管在googlecode 此处(如果有)任何问题.我不再积极从事此工作,但是代码应该可以工作.

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以来,此过程有所更改,因此请检查

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

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

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