Class SSLUtils

java.lang.Object
at.gv.egovernment.moaspss.util.SSLUtils

public class SSLUtils extends Object
Utility for connecting to server applications via SSL.
  • Constructor Details

    • SSLUtils

      public SSLUtils()
  • Method Details

    • getSSLSocketFactory

      public static SSLSocketFactory getSSLSocketFactory(String trustStoreType, InputStream trustStoreInputStream, String trustStorePassword) throws IOException, GeneralSecurityException
      Creates an SSLSocketFactory which utilizes the given trust store.
      Parameters:
      trustStoreType - key store type of trust store
      trustStoreInputStream - input stream for reading JKS trust store containing trusted server certificates; if null, the default trust store will be utilized
      trustStorePassword - if provided, it will be used to check the integrity of the trust store; if omitted, it will not be checked
      Returns:
      SSLSocketFactory to be used by an HttpsURLConnection
      Throws:
      IOException - thrown while reading from the input stream
      GeneralSecurityException - thrown while creating the socket factory
    • getSSLSocketFactory

      public static SSLSocketFactory getSSLSocketFactory(KeyStore trustStore, String clientKeyStoreType, String clientKeyStoreURL, String clientKeyStorePassword) throws IOException, GeneralSecurityException
      Creates an SSLSocketFactory which utilizes the given trust store and keystore.
      Parameters:
      trustStore - trust store containing trusted server certificates; if null, the default trust store will be utilized
      clientKeyStoreType - key store type of clientKeyStore
      clientKeyStoreURL - URL of key store containing keys to be used for client authentication; if null, the default key store will be utilized
      clientKeyStorePassword - if provided, it will be used to check the integrity of the client key store; if omitted, it will not be checked
      Returns:
      SSLSocketFactory to be used by an HttpsURLConnection
      Throws:
      IOException - thrown while reading key store file
      GeneralSecurityException - thrown while creating the socket factory
    • getSSLContext

      public static SSLContext getSSLContext(KeyStore trustStore, String clientKeyStoreType, String clientKeyStoreURL, String clientKeyStorePassword) throws IOException, GeneralSecurityException
      Creates an SSLContext initialized for the given trust store and keystore.
      Parameters:
      trustStore - trust store containing trusted server certificates; if null, the default trust store will be utilized
      clientKeyStoreType - key store type of clientKeyStore
      clientKeyStoreURL - URL of key store containing keys to be used for client authentication; if null, the default key store will be utilized
      clientKeyStorePassword - if provided, it will be used to check the integrity of the client key store; if omitted, it will not be checked
      Returns:
      SSLContext to be used for creating an SSLSocketFactory
      Throws:
      IOException - thrown while reading key store file
      GeneralSecurityException - thrown while creating the SSL context
    • getTrustManagers

      protected static TrustManager[] getTrustManagers(String trustStoreType, InputStream trustStoreInputStream, String trustStorePassword) throws IOException, GeneralSecurityException
      Loads the trust store from an input stream and gets the TrustManagers from a default TrustManagerFactory, initialized from the given trust store.
      Parameters:
      trustStoreType - key store type of trust store
      trustStoreInputStream - input stream for reading JKS trust store containing trusted server certificates; if null, the default trust store will be utilized
      trustStorePassword - if provided, it will be used to check the integrity of the trust store; if omitted, it will not be checked
      Returns:
      TrustManagers to be used for creating an SSLSocketFactory utilizing the given trust store
      Throws:
      IOException - thrown while reading from the input stream
      GeneralSecurityException - thrown while initializing the default TrustManagerFactory
    • getTrustManagers

      protected static TrustManager[] getTrustManagers(KeyStore trustStore) throws GeneralSecurityException
      Gets the TrustManagers from a default TrustManagerFactory, initialized from the given trust store.
      Parameters:
      trustStore - the trust store to use
      Returns:
      TrustManagers to be used for creating an SSLSocketFactory utilizing the given trust store
      Throws:
      GeneralSecurityException - thrown while initializing the default TrustManagerFactory
    • getKeyManagers

      public static KeyManager[] getKeyManagers(String clientKeyStoreType, String clientKeyStoreURL, String clientKeyStorePassword) throws IOException, GeneralSecurityException
      Loads the client key store from file and gets the KeyManagers from a default KeyManagerFactory, initialized from the given client key store.
      Parameters:
      clientKeyStoreType - key store type of clientKeyStore
      clientKeyStoreURL - URL of key store containing keys to be used for client authentication; if null, the default key store will be utilized
      clientKeyStorePassword - password used to check the integrity of the client key store; if null, it will not be checked
      Returns:
      KeyManagers to be used for creating an SSLSocketFactory utilizing the given client key store
      Throws:
      IOException - thrown while reading from the key store file
      GeneralSecurityException - thrown while initializing the default KeyManagerFactory
    • getKeyManagers

      public static KeyManager[] getKeyManagers(KeyStore clientKeyStore, String clientKeyStorePassword) throws GeneralSecurityException
      Gets the KeyManagers from a default KeyManagerFactory, initialized from the given client key store.
      Parameters:
      clientKeyStore - client key store
      clientKeyStorePassword - if provided, it will be used to check the integrity of the client key store; if omitted, it will not be checked
      Returns:
      KeyManagers to be used for creating an SSLSocketFactory utilizing the given client key store
      Throws:
      GeneralSecurityException - thrown while initializing the default KeyManagerFactory