Class BetterSSLFactory


  • public class BetterSSLFactory
    extends java.lang.Object
    SSL Socket factory. Provides more authentication than the naive one and allows stored (custom) certificates to be added into the trust chain. The ability to also use Client Certificates is provided by the alternative constructor

    This work is based on http://codyaray.com/2013/04/java-ssl-with-multiple-keystores and common sense.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static org.apache.http.conn.ssl.SSLSocketFactory createSocketFactory​(java.security.KeyStore keystore, java.lang.String keystorePassword, java.util.Collection<java.security.KeyStore> extraStores)
      Creates a new SSL socket factory which supports client certificate authentication, and validation against both system-installed keys and all additional keys in the provided keystores.
      static org.apache.http.conn.ssl.SSLSocketFactory createSocketFactory​(java.util.Collection<java.security.KeyStore> extraStores)
      Creates a new SSL socket factory which supports both system-installed keys and all additional keys in the provided keystores.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • BetterSSLFactory

        public BetterSSLFactory()
    • Method Detail

      • createSocketFactory

        public static org.apache.http.conn.ssl.SSLSocketFactory createSocketFactory​(java.util.Collection<java.security.KeyStore> extraStores)
                                                                             throws java.security.KeyStoreException,
                                                                                    java.security.KeyManagementException
        Creates a new SSL socket factory which supports both system-installed keys and all additional keys in the provided keystores.
        Parameters:
        extraStores - extra keystores containing root certificate authorities.
        Returns:
        Socket factory supporting authorization for both system (default) keystores and all the extraStores.
        Throws:
        java.security.KeyStoreException - if key store have problems.
        java.security.KeyManagementException - if new SSL context could not be initialized.
      • createSocketFactory

        public static org.apache.http.conn.ssl.SSLSocketFactory createSocketFactory​(java.security.KeyStore keystore,
                                                                                    java.lang.String keystorePassword,
                                                                                    java.util.Collection<java.security.KeyStore> extraStores)
                                                                             throws java.security.KeyStoreException,
                                                                                    java.security.KeyManagementException
        Creates a new SSL socket factory which supports client certificate authentication, and validation against both system-installed keys and all additional keys in the provided keystores.
        Parameters:
        keystore - KeyStore object containing a Private and Public Key pair for client authentication.
        keystorePassword - Password used to unlock keystore.
        extraStores - extra keystores containing root certificate authorities.
        Returns:
        Socket factory supporting authorization for both system (default) keystores and all the extraStores.
        Throws:
        java.security.KeyStoreException - if key store have problems.
        java.security.KeyManagementException - if new SSL context could not be initialized.