Class HybridRACFKeyStore
This KeyStore makes use of the "JCERACFKS" and "JCECCARACFKS" keystore types to interact with the SAF security backend. It will allow a user to load a single SAF keyring as both a JCECCARACFKS and JCERACFKS keystore representation. When loaded the new JCEHYBRIDRACFKS will contain a mashup of the available key and certificate material from both the JCECCARACFKS and JCERACFKS keystore representations of the same SAF keyring.
Before this keystore can be accessed, it must be
loaded
similar to below:
KeyStore ks = KeyStore.getInstance("JCEHYBRIDRACFKS","IBMJCEHYBRID"); //Get input stream to a SAF keyring and load the keystore. HybridRACFInputStream his = new HybridRACFInputStream(userid, keyring, passwordChars); ks.load(his, passwordChars);
After the keystore has been
loaded
various keys and certificates will be available to the
caller. Available keys depend on what key material was
available in the SAF keyring at the time it was loaded. The
working state of ICSF may determine what types of key
material will
be available. Please see the IBM JCE Hybrid Provider
Reference Guide for more information.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionLists all the alias names of this keystore.boolean
engineContainsAlias
(String alias) Checks if the given alias exists in this keystore.void
engineDeleteEntry
(String alias) Deletes the entry identified by the given alias from this keystore.engineGetCertificate
(String alias) Returns the certificate associated with the given alias.Returns the (alias) name of the first keystore entry whose certificate matches the given certificate.engineGetCertificateChain
(String alias) Returns the certificate chain associated with the given alias.engineGetCreationDate
(String alias) Fetch the time at which the certificate object was created.engineGetKey
(String alias, char[] password) Returns theHybridRACFPrivateKey
associated with the given alias, using the given password to recover it.boolean
engineIsCertificateEntry
(String alias) Returns true if the entry identified by the given alias was created by a call tosetCertificateEntry
.boolean
engineIsKeyEntry
(String alias) Returns true if the entry identified by the given alias was created by a call tosetKeyEntry
.void
engineLoad
(InputStream stream, char[] password) Loads this KeyStore from the givenHybridRACFOutputStream
stream.void
engineSetCertificateEntry
(String alias, Certificate cert) Assigns the given trusted certificate to the given alias.void
engineSetKeyEntry
(String alias, byte[] key, Certificate[] chain) This method is not supported by the JCEHYBRIDRACFKS keystore.void
engineSetKeyEntry
(String alias, Key key, char[] password, Certificate[] chain) Assigns the given key to the given alias, protecting it with the given password.int
Retrieves the number of entries in this keystore.void
engineStore
(OutputStream stream, char[] password) Stores this keystore to the givenHybridRACFOutputStream
stream, and protects its integrity with the given password.Methods inherited from class java.security.KeyStoreSpi
engineEntryInstanceOf, engineGetEntry, engineLoad, engineProbe, engineSetEntry, engineStore
-
Constructor Details
-
HybridRACFKeyStore
public HybridRACFKeyStore()Constructor
-
-
Method Details
-
engineGetKey
public Key engineGetKey(String alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException Returns theHybridRACFPrivateKey
associated with the given alias, using the given password to recover it. The key must have been associated with the alias by a call tosetKeyEntry
.- Specified by:
engineGetKey
in classKeyStoreSpi
- Parameters:
alias
- the alias namepassword
- the password for recovering the key- Returns:
- the requested
HybridRACFPrivateKey
key, or null if the given alias does not exist or does not identify a key-related entry. - Throws:
KeyStoreException
- if the keystore has not been initialized (loaded).NoSuchAlgorithmException
- if the algorithm for recovering the key cannot be foundUnrecoverableKeyException
- if the key cannot be recovered (e.g., the given password is wrong).
-
engineGetCertificateChain
Returns the certificate chain associated with the given alias. The certificate chain must have been associated with the alias by a call tosetKeyEntry
.- Specified by:
engineGetCertificateChain
in classKeyStoreSpi
- Parameters:
alias
- the alias name- Returns:
- the certificate chain (ordered with the user's certificate first and the root certificate authority last), or null if the given alias does not exist or does not contain a certificate chain
- Throws:
KeyStoreException
- if the keystore has not been initialized (loaded).
-
engineGetCertificate
Returns the certificate associated with the given alias.If the given alias name identifies an entry created by a call to
setCertificateEntry
then the trusted certificate contained in that entry is returned.If the given alias name identifies an entry created by a call to
setKeyEntry
then the first element of the certificate chain in that entry is returned.- Specified by:
engineGetCertificate
in classKeyStoreSpi
- Parameters:
alias
- the alias name- Returns:
- the certificate, or null if the given alias does not exist or does not contain a certificate.
- Throws:
KeyStoreException
- if the keystore has not been initialized (loaded).
-
engineGetCreationDate
Fetch the time at which the certificate object was created.- Specified by:
engineGetCreationDate
in classKeyStoreSpi
- Parameters:
alias
- the alias name- Returns:
- null if the alias is null, and empty sting, or not found in the underlying keystore. Return the date at which the certificate object was created.
- Throws:
KeyStoreException
- if the keystore has not been initialized (loaded).
-
engineSetKeyEntry
public void engineSetKeyEntry(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreException Assigns the given key to the given alias, protecting it with the given password.If the given key is of type
java.security.PrivateKey
, it must be accompanied by a certificate chain certifying the corresponding public key.If the given alias already exists, the keystore information associated with it is overridden by the given key (and possibly certificate chain).
If the key being inserted is derived from the IBMJCECCA provider and is a ECPrivateHWKey or RSAPrivateHWKey, it will be placed into the underlying JCECCARACFKS keystore along with inserting it into the local keystore cache.
If the key being inserted is derived from the IBMZSecurity provider and is an ECPrivateKey, RSAPrivateKey or RSAPrivateCrtKey it will be placed into the underlying JCERACFKS keystore along with inserting it into the local keystore cache.
- Specified by:
engineSetKeyEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias namekey
- the key to be associated with the aliaspassword
- the password to protect the keychain
- the certificate chain for the corresponding public key (only required if the given key is of typejava.security.PrivateKey
).- Throws:
KeyStoreException
- if the keystore has not been initialized (loaded), the given key cannot be protected, or this operation fails for some other reason
-
engineSetKeyEntry
public void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain) throws KeyStoreException This method is not supported by the JCEHYBRIDRACFKS keystore. A KeyStoreException will always be thrown.- Specified by:
engineSetKeyEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias namekey
- the key to be associated with the aliaschain
- the certificate chain for the corresponding to the key.- Throws:
KeyStoreException
- will always be thrown.
-
engineSetCertificateEntry
Assigns the given trusted certificate to the given alias.If the given alias identifies an existing entry created by a call to
setCertificateEntry
the trusted certificate in the existing entry is overridden by the given certificate.- Specified by:
engineSetCertificateEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias namecert
- the certificate- Throws:
KeyStoreException
- if the keystore has not been initialized, or the given alias already exists and does not identify an entry containing a trusted certificate, or this operation fails for some other reason.
-
engineDeleteEntry
Deletes the entry identified by the given alias from this keystore.- Specified by:
engineDeleteEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias name- Throws:
KeyStoreException
- if the keystore has not been initialized, or if the entry cannot be removed.
-
engineAliases
Lists all the alias names of this keystore.- Specified by:
engineAliases
in classKeyStoreSpi
- Returns:
- enumeration of the alias names
- Throws:
KeyStoreException
- if the keystore has not been initialized (loaded).
-
engineContainsAlias
Checks if the given alias exists in this keystore.- Specified by:
engineContainsAlias
in classKeyStoreSpi
- Parameters:
alias
- the alias name- Returns:
- true if the alias exists, false otherwise
- Throws:
KeyStoreException
- if the keystore has not been initialized (loaded).
-
engineSize
public int engineSize()Retrieves the number of entries in this keystore.- Specified by:
engineSize
in classKeyStoreSpi
- Returns:
- the number of entries in this keystore
- Throws:
KeyStoreException
- if the keystore has not been initialized (loaded).
-
engineIsKeyEntry
Returns true if the entry identified by the given alias was created by a call tosetKeyEntry
.- Specified by:
engineIsKeyEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias for the keystore entry to be checked- Returns:
- true if the entry identified by the given alias is a key-related entry, false otherwise.
- Throws:
KeyStoreException
- if the keystore has not been initialized (loaded).IllegalArgumentException
- if the alias name is null.
-
engineIsCertificateEntry
Returns true if the entry identified by the given alias was created by a call tosetCertificateEntry
.- Specified by:
engineIsCertificateEntry
in classKeyStoreSpi
- Parameters:
alias
- the alias for the keystore entry to be checked- Returns:
- true if the entry identified by the given alias contains a trusted certificate, false otherwise.
- Throws:
KeyStoreException
- if the keystore has not been initialized (loaded).
-
engineGetCertificateAlias
Returns the (alias) name of the first keystore entry whose certificate matches the given certificate.This method attempts to match the given certificate with each keystore entry. If the entry being considered was created by a call to
setCertificateEntry
then the given certificate is compared to that entry's certificate.If the entry being considered was created by a call to
setKeyEntry
then the given certificate is compared to the first element of that entry's certificate chain.- Specified by:
engineGetCertificateAlias
in classKeyStoreSpi
- Parameters:
cert
- the certificate to match with.- Returns:
- the alias name of the first entry with a matching certificate, or null if no such entry exists in this keystore.
- Throws:
KeyStoreException
- if the keystore has not been initialized (loaded).
-
engineStore
public void engineStore(OutputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException Stores this keystore to the givenHybridRACFOutputStream
stream, and protects its integrity with the given password.- Specified by:
engineStore
in classKeyStoreSpi
- Parameters:
stream
- the output stream to which this keystore is written.password
- the password to generate the keystore integrity check- Throws:
KeyStoreException
- if the keystore has not been initialized (loaded).IOException
- if there was an I/O problem with dataNoSuchAlgorithmException
- if the appropriate data integrity algorithm could not be foundCertificateException
- if any of the certificates included in the keystore data could not be stored
-
engineLoad
public void engineLoad(InputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException Loads this KeyStore from the givenHybridRACFOutputStream
stream.In order to create an empty keystore, or if the keystore cannot be initialized from a stream, pass
null
as thestream
argument.Note that if this keystore has already been loaded, it is reinitialized and loaded again from the given input stream.
- Specified by:
engineLoad
in classKeyStoreSpi
- Parameters:
stream
- theHybridRACFOutputStream
stream from which the keystore is loaded, ornull
password
- the password used to check the integrity of the keystore, the password used to unlock the keystore, ornull
- Throws:
IOException
- if there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrectNoSuchAlgorithmException
- if the algorithm used to check the integrity of the keystore cannot be foundCertificateException
- if any of the certificates in the keystore could not be loaded
-