au.gov.nehta.vendorlibrary.common.security
Class KeystoreUtil

java.lang.Object
  extended by au.gov.nehta.vendorlibrary.common.security.KeystoreUtil

public final class KeystoreUtil
extends java.lang.Object

KeystoreUtil class to load keystore from a file, and obtain X509 certificates and private keys from key stores.


Method Summary
static java.security.cert.X509Certificate getSigningCertificate(java.security.KeyStore keystore, java.lang.String certificateAlias)
          Returns the X509Certificate object for the provided keystore and certificateAlias values.
static java.security.cert.X509Certificate getSigningCertificate(java.lang.String keystoreType, java.lang.String keystorePassword, java.lang.String keystorePathname, java.lang.String certificateAlias)
          Returns the X509Certificate object for the provided keystorePathname, keystorePassword keystoreType and certificateAlias values.
static java.security.PrivateKey getSigningPrivateKey(java.security.KeyStore keystore, java.lang.String keystorePassword, java.lang.String privateKeyAlias)
          Returns the PrivateKey object for the provided keystore, privateKeyAlias, keystorePassword values.
static java.security.PrivateKey getSigningPrivateKey(java.lang.String keystoreType, java.lang.String keystorePassword, java.lang.String keystorePathname, java.lang.String privateKeyAlias)
          Returns the PrivateKey object for the provided keystorepathname, keystorePassword and privateKeyAlias values.
static javax.net.ssl.SSLSocketFactory getSslSocketFactory(java.lang.String privateKeyStoreType, java.lang.String privateKeyStoreFile, java.lang.String privateKeyStorePassword, java.lang.String privateKeyPassword, java.lang.String privateKeyAlias, java.lang.String trustStoreType, java.lang.String trustStoreFile, java.lang.String trustStorePassword)
           
static java.security.KeyStore loadKeyStore(java.lang.String keystoreType, java.lang.String keystorePassword, java.lang.String keystorePathname)
          Returns the Keystore object for the provided keystorePathname, keystorePassword, keystoreType values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadKeyStore

public static java.security.KeyStore loadKeyStore(java.lang.String keystoreType,
                                                  java.lang.String keystorePassword,
                                                  java.lang.String keystorePathname)
                                           throws java.security.GeneralSecurityException
Returns the Keystore object for the provided keystorePathname, keystorePassword, keystoreType values.

Parameters:
keystoreType - the type of keystore
See Java Cryptography Architecture API Specification for information about standard keystore types.
keystorePassword - the password used to check the integrity of the keystore, the password used to unlock the keystore
keystorePathname - a pathname string
Returns:
a keystore object of the specified type.
Throws:
java.security.GeneralSecurityException - if either of the keystorePassword, keystorePathname or keystoreType is invalid.

getSigningCertificate

public static java.security.cert.X509Certificate getSigningCertificate(java.lang.String keystoreType,
                                                                       java.lang.String keystorePassword,
                                                                       java.lang.String keystorePathname,
                                                                       java.lang.String certificateAlias)
                                                                throws java.security.GeneralSecurityException
Returns the X509Certificate object for the provided keystorePathname, keystorePassword keystoreType and certificateAlias values.
Note:
TODO address this issue with AliasForcingKeyManager The provided keystore must only contain one private key entry

Parameters:
keystoreType - the type of keystore
See Java Cryptography Architecture API Specification for information about standard keystore types.
keystorePassword - the password used to check the integrity of the keystore, the password used to unlock the keystore
keystorePathname - the abstract pathname string
certificateAlias - the alias name of the certificate
Returns:
Null or the X509Certificate from the provided private Keystore.
Throws:
{@link - java.security.GeneralSecurityException}
java.security.GeneralSecurityException

getSigningCertificate

public static java.security.cert.X509Certificate getSigningCertificate(java.security.KeyStore keystore,
                                                                       java.lang.String certificateAlias)
                                                                throws java.security.GeneralSecurityException
Returns the X509Certificate object for the provided keystore and certificateAlias values.

Parameters:
keystore - the type of keystore
See Java Cryptography Architecture API Specification for information about standard keystore types.
certificateAlias - the alias name of the certificate
Returns:
the signing certificate as X509Certificate
Throws:
java.security.GeneralSecurityException

getSigningPrivateKey

public static java.security.PrivateKey getSigningPrivateKey(java.lang.String keystoreType,
                                                            java.lang.String keystorePassword,
                                                            java.lang.String keystorePathname,
                                                            java.lang.String privateKeyAlias)
                                                     throws java.security.GeneralSecurityException
Returns the PrivateKey object for the provided keystorepathname, keystorePassword and privateKeyAlias values.

Parameters:
keystoreType - the type of keystore
See Java Cryptography Architecture API Specification for information about standard keystore types.
keystorePassword - the password used to check the integrity of the keystore, the password used to unlock the keystore
keystorePathname - the abstract pathname string
privateKeyAlias - the alias name of the privateKey.
Returns:
the signing key as PrivateKey
Throws:
java.security.GeneralSecurityException - if keystoreType, KeystorePathname, privateKeyAlias doesnot exists or invalid.

getSigningPrivateKey

public static java.security.PrivateKey getSigningPrivateKey(java.security.KeyStore keystore,
                                                            java.lang.String keystorePassword,
                                                            java.lang.String privateKeyAlias)
                                                     throws java.security.GeneralSecurityException
Returns the PrivateKey object for the provided keystore, privateKeyAlias, keystorePassword values.

Parameters:
keystore - keystore object of type KeyStore
keystorePassword - the password for recovering the key from the keystore
privateKeyAlias - the alias name of the privateKey.
Returns:
the requested key, or null if the given alias does not exist or does not identify a key-related entry.
Throws:
java.security.GeneralSecurityException - if keystore, privateKeyAlias or keystorePassword deosnot exists or invalid.

getSslSocketFactory

public static javax.net.ssl.SSLSocketFactory getSslSocketFactory(java.lang.String privateKeyStoreType,
                                                                 java.lang.String privateKeyStoreFile,
                                                                 java.lang.String privateKeyStorePassword,
                                                                 java.lang.String privateKeyPassword,
                                                                 java.lang.String privateKeyAlias,
                                                                 java.lang.String trustStoreType,
                                                                 java.lang.String trustStoreFile,
                                                                 java.lang.String trustStorePassword)
                                                          throws java.security.GeneralSecurityException,
                                                                 java.io.IOException
Throws:
java.security.GeneralSecurityException
java.io.IOException