Package at.gv.egovernment.moaspss.util
Class SSLUtils
java.lang.Object
at.gv.egovernment.moaspss.util.SSLUtils
Utility for connecting to server applications via SSL.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic KeyManager[]getKeyManagers(String clientKeyStoreType, String clientKeyStoreURL, String clientKeyStorePassword) Loads the client key store from file and gets theKeyManagers from a defaultKeyManagerFactory, initialized from the given client key store.static KeyManager[]getKeyManagers(KeyStore clientKeyStore, String clientKeyStorePassword) Gets theKeyManagers from a defaultKeyManagerFactory, initialized from the given client key store.static SSLContextgetSSLContext(KeyStore trustStore, String clientKeyStoreType, String clientKeyStoreURL, String clientKeyStorePassword) Creates anSSLContextinitialized for the given trust store and keystore.static SSLSocketFactorygetSSLSocketFactory(String trustStoreType, InputStream trustStoreInputStream, String trustStorePassword) Creates anSSLSocketFactorywhich utilizes the given trust store.static SSLSocketFactorygetSSLSocketFactory(KeyStore trustStore, String clientKeyStoreType, String clientKeyStoreURL, String clientKeyStorePassword) Creates anSSLSocketFactorywhich utilizes the given trust store and keystore.protected static TrustManager[]getTrustManagers(String trustStoreType, InputStream trustStoreInputStream, String trustStorePassword) Loads the trust store from an input stream and gets theTrustManagers from a defaultTrustManagerFactory, initialized from the given trust store.protected static TrustManager[]getTrustManagers(KeyStore trustStore) Gets theTrustManagers from a defaultTrustManagerFactory, initialized from the given trust store.
-
Constructor Details
-
SSLUtils
public SSLUtils()
-
-
Method Details
-
getSSLSocketFactory
public static SSLSocketFactory getSSLSocketFactory(String trustStoreType, InputStream trustStoreInputStream, String trustStorePassword) throws IOException, GeneralSecurityException Creates anSSLSocketFactorywhich utilizes the given trust store.- Parameters:
trustStoreType- key store type of trust storetrustStoreInputStream- input stream for reading JKS trust store containing trusted server certificates; ifnull, the default trust store will be utilizedtrustStorePassword- if provided, it will be used to check the integrity of the trust store; if omitted, it will not be checked- Returns:
SSLSocketFactoryto be used by anHttpsURLConnection- Throws:
IOException- thrown while reading from the input streamGeneralSecurityException- thrown while creating the socket factory
-
getSSLSocketFactory
public static SSLSocketFactory getSSLSocketFactory(KeyStore trustStore, String clientKeyStoreType, String clientKeyStoreURL, String clientKeyStorePassword) throws IOException, GeneralSecurityException Creates anSSLSocketFactorywhich utilizes the given trust store and keystore.- Parameters:
trustStore- trust store containing trusted server certificates; ifnull, the default trust store will be utilizedclientKeyStoreType- key store type ofclientKeyStoreclientKeyStoreURL- URL of key store containing keys to be used for client authentication; ifnull, the default key store will be utilizedclientKeyStorePassword- if provided, it will be used to check the integrity of the client key store; if omitted, it will not be checked- Returns:
SSLSocketFactoryto be used by anHttpsURLConnection- Throws:
IOException- thrown while reading key store fileGeneralSecurityException- thrown while creating the socket factory
-
getSSLContext
public static SSLContext getSSLContext(KeyStore trustStore, String clientKeyStoreType, String clientKeyStoreURL, String clientKeyStorePassword) throws IOException, GeneralSecurityException Creates anSSLContextinitialized for the given trust store and keystore.- Parameters:
trustStore- trust store containing trusted server certificates; ifnull, the default trust store will be utilizedclientKeyStoreType- key store type ofclientKeyStoreclientKeyStoreURL- URL of key store containing keys to be used for client authentication; ifnull, the default key store will be utilizedclientKeyStorePassword- if provided, it will be used to check the integrity of the client key store; if omitted, it will not be checked- Returns:
SSLContextto be used for creating anSSLSocketFactory- Throws:
IOException- thrown while reading key store fileGeneralSecurityException- 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 theTrustManagers from a defaultTrustManagerFactory, initialized from the given trust store.- Parameters:
trustStoreType- key store type of trust storetrustStoreInputStream- input stream for reading JKS trust store containing trusted server certificates; ifnull, the default trust store will be utilizedtrustStorePassword- 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 anSSLSocketFactoryutilizing the given trust store- Throws:
IOException- thrown while reading from the input streamGeneralSecurityException- thrown while initializing the defaultTrustManagerFactory
-
getTrustManagers
protected static TrustManager[] getTrustManagers(KeyStore trustStore) throws GeneralSecurityException Gets theTrustManagers from a defaultTrustManagerFactory, initialized from the given trust store.- Parameters:
trustStore- the trust store to use- Returns:
TrustManagers to be used for creating anSSLSocketFactoryutilizing the given trust store- Throws:
GeneralSecurityException- thrown while initializing the defaultTrustManagerFactory
-
getKeyManagers
public static KeyManager[] getKeyManagers(String clientKeyStoreType, String clientKeyStoreURL, String clientKeyStorePassword) throws IOException, GeneralSecurityException Loads the client key store from file and gets theKeyManagers from a defaultKeyManagerFactory, initialized from the given client key store.- Parameters:
clientKeyStoreType- key store type ofclientKeyStoreclientKeyStoreURL- URL of key store containing keys to be used for client authentication; ifnull, the default key store will be utilizedclientKeyStorePassword- password used to check the integrity of the client key store; ifnull, it will not be checked- Returns:
KeyManagers to be used for creating anSSLSocketFactoryutilizing the given client key store- Throws:
IOException- thrown while reading from the key store fileGeneralSecurityException- thrown while initializing the defaultKeyManagerFactory
-
getKeyManagers
public static KeyManager[] getKeyManagers(KeyStore clientKeyStore, String clientKeyStorePassword) throws GeneralSecurityException Gets theKeyManagers from a defaultKeyManagerFactory, initialized from the given client key store.- Parameters:
clientKeyStore- client key storeclientKeyStorePassword- 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 anSSLSocketFactoryutilizing the given client key store- Throws:
GeneralSecurityException- thrown while initializing the defaultKeyManagerFactory
-