Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpComponents Custom SSLSocketFactory

Per the example at http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientCustomSSL.java

SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore);

Should instantiate a SSLSocketFactory using my custom trust store, yet when I try to build my project, I get the error

javax.net.ssl.SSLSocketFactory is abstract; cannot be intantiated

Is the example out of date? Does it work for other people?

like image 544
ItinerantEngineer Avatar asked Aug 20 '12 23:08

ItinerantEngineer


People also ask

What is SSLSocketFactory?

SSLSocketFactory acts as a factory for creating secure sockets. This class is an abstract subclass of javax. net. SocketFactory . Secure socket factories encapsulate the details of creating and initially configuring secure sockets.

What is SSLConnectionSocketFactory?

SSLConnectionSocketFactory is a layered socket factory for TSL and SSL connections. Using this, you can verify the Https server using a list of trusted certificates and authenticate the given Https server. You can create this in many ways.

What is TrustSelfSignedStrategy?

The TrustSelfSignedStrategy works as follows: @Override public boolean isTrusted( final X509Certificate[] chain, final String authType) throws CertificateException { return chain.length == 1; } A self singed certificate is issued by the target of the certificate.

What is Truststrategy?

A strategy to establish trustworthiness of certificates without consulting the trust manager configured in the actual SSL context. This interface can be used to override the standard JSSE certificate verification process.


1 Answers

It's a org.apache.http.conn.ssl.SSLSocketFactory you should use, not a javax.net.ssl.SSLSocketFactory (see import directive in the example file you're using).

Note that the former has constructors that can use the latter if you already have existing code for this. However, you would generally get a custom javax.net.ssl.SSLSocketFactory from an SSLContext, so you might as well use the SSLContext-based constructor in this case.

like image 104
Bruno Avatar answered Nov 09 '22 14:11

Bruno