at.gv.egovernment.moa.util
Class SSLUtils

java.lang.Object
  |
  +--at.gv.egovernment.moa.util.SSLUtils

public class SSLUtils
extends Object

Utility for connecting to server applications via SSL.

Version:
$Id$
Author:
Paul Ivancsics

Constructor Summary
SSLUtils()
           
 
Method Summary
static com.sun.net.ssl.KeyManager[] getKeyManagers(KeyStore clientKeyStore, String clientKeyStorePassword)
          Gets the KeyManagers from a default KeyManagerFactory, initialized from the given client key store.
static com.sun.net.ssl.KeyManager[] getKeyManagers(String clientKeyStoreType, String clientKeyStoreURL, String clientKeyStorePassword)
          Loads the client key store from file and gets the KeyManagers from a default KeyManagerFactory, initialized from the given client key store.
static com.sun.net.ssl.SSLContext getSSLContext(KeyStore trustStore, String clientKeyStoreType, String clientKeyStoreURL, String clientKeyStorePassword)
          Creates an SSLContext initialized for the given trust store and keystore.
static javax.net.ssl.SSLSocketFactory getSSLSocketFactory(KeyStore trustStore, String clientKeyStoreType, String clientKeyStoreURL, String clientKeyStorePassword)
          Creates an SSLSocketFactory which utilizes the given trust store and keystore.
static javax.net.ssl.SSLSocketFactory getSSLSocketFactory(String trustStoreType, InputStream trustStoreInputStream, String trustStorePassword)
          Creates an SSLSocketFactory which utilizes the given trust store.
protected static com.sun.net.ssl.TrustManager[] getTrustManagers(KeyStore trustStore)
          Gets the TrustManagers from a default TrustManagerFactory, initialized from the given trust store.
protected static com.sun.net.ssl.TrustManager[] getTrustManagers(String trustStoreType, InputStream trustStoreInputStream, String trustStorePassword)
          Loads the trust store from an input stream and gets the TrustManagers from a default TrustManagerFactory, initialized from the given trust store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SSLUtils

public SSLUtils()
Method Detail

getSSLSocketFactory

public static javax.net.ssl.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 javax.net.ssl.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 com.sun.net.ssl.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 com.sun.net.ssl.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 com.sun.net.ssl.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
trustStorePassword - password protecting the given trust store
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 com.sun.net.ssl.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 com.sun.net.ssl.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