3

I reference this page and implement trust slef-certificate as follows,

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

The EasySSLSocketFactory is here, and the EasyX509TrustManager is here.

I found that it would have a lot of SSL hello handshake.

After my studies, this situation may be reduced by using SSLSessionCache.

I search in the forum, but the solution almost using normal ssl connecting not using trust self-certificate.

How can I use SSLSessionCache when I implement trust self-certificate in HttpClient?

Community
  • 1
  • 1
YuChin
  • 43
  • 5
  • Have you checked this sample on [Socket factory for Android supporting SSLSessionCache and custom TrustManager?](https://gist.github.com/codebutler/5565971) Unrelated, but HttpClient in Android is deprecated and may be removed in a future release. – asgs May 21 '15 at 06:58
  • Thanks, I will check the sample. The reason I use HttpClient because the HttpsURLConnection seems hard to reuse SSL Session to reduce many handshake. A lot of articles are used HttpClient to solve this problem. – YuChin May 21 '15 at 07:56
  • The sample code you provide that can work, but it still make many handshake. Is my direction right? – YuChin May 22 '15 at 09:27

0 Answers0