Class HybridRACFKeyStore

java.lang.Object
java.security.KeyStoreSpi
com.ibm.crypto.ibmjcehybrid.provider.HybridRACFKeyStore

public class HybridRACFKeyStore extends KeyStoreSpi
This class represents a storage facility for cryptographic keys and certificates stored in a SAF security backend such as a RACF keyring. This class provides the keystore implementation referred to as "JCEHYBRIDRACFKS".

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 Details

    • HybridRACFKeyStore

      public HybridRACFKeyStore()
      Constructor
  • Method Details

    • engineGetKey

      public Key engineGetKey(String alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException
      Returns the HybridRACFPrivateKey associated with the given alias, using the given password to recover it. The key must have been associated with the alias by a call to setKeyEntry.
      Specified by:
      engineGetKey in class KeyStoreSpi
      Parameters:
      alias - the alias name
      password - 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 found
      UnrecoverableKeyException - if the key cannot be recovered (e.g., the given password is wrong).
    • engineGetCertificateChain

      public Certificate[] engineGetCertificateChain(String alias)
      Returns the certificate chain associated with the given alias. The certificate chain must have been associated with the alias by a call to setKeyEntry.
      Specified by:
      engineGetCertificateChain in class KeyStoreSpi
      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

      public Certificate engineGetCertificate(String alias)
      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 class KeyStoreSpi
      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

      public Date engineGetCreationDate(String alias)
      Fetch the time at which the certificate object was created.
      Specified by:
      engineGetCreationDate in class KeyStoreSpi
      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 class KeyStoreSpi
      Parameters:
      alias - the alias name
      key - the key to be associated with the alias
      password - the password to protect the key
      chain - the certificate chain for the corresponding public key (only required if the given key is of type java.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 class KeyStoreSpi
      Parameters:
      alias - the alias name
      key - the key to be associated with the alias
      chain - the certificate chain for the corresponding to the key.
      Throws:
      KeyStoreException - will always be thrown.
    • engineSetCertificateEntry

      public void engineSetCertificateEntry(String alias, Certificate cert) throws KeyStoreException
      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 class KeyStoreSpi
      Parameters:
      alias - the alias name
      cert - 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

      public void engineDeleteEntry(String alias) throws KeyStoreException
      Deletes the entry identified by the given alias from this keystore.
      Specified by:
      engineDeleteEntry in class KeyStoreSpi
      Parameters:
      alias - the alias name
      Throws:
      KeyStoreException - if the keystore has not been initialized, or if the entry cannot be removed.
    • engineAliases

      public Enumeration<String> engineAliases()
      Lists all the alias names of this keystore.
      Specified by:
      engineAliases in class KeyStoreSpi
      Returns:
      enumeration of the alias names
      Throws:
      KeyStoreException - if the keystore has not been initialized (loaded).
    • engineContainsAlias

      public boolean engineContainsAlias(String alias)
      Checks if the given alias exists in this keystore.
      Specified by:
      engineContainsAlias in class KeyStoreSpi
      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 class KeyStoreSpi
      Returns:
      the number of entries in this keystore
      Throws:
      KeyStoreException - if the keystore has not been initialized (loaded).
    • engineIsKeyEntry

      public boolean engineIsKeyEntry(String alias)
      Returns true if the entry identified by the given alias was created by a call to setKeyEntry.
      Specified by:
      engineIsKeyEntry in class KeyStoreSpi
      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

      public boolean engineIsCertificateEntry(String alias)
      Returns true if the entry identified by the given alias was created by a call to setCertificateEntry.
      Specified by:
      engineIsCertificateEntry in class KeyStoreSpi
      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

      public String engineGetCertificateAlias(Certificate cert)
      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 class KeyStoreSpi
      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 given HybridRACFOutputStream stream, and protects its integrity with the given password.
      Specified by:
      engineStore in class KeyStoreSpi
      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 data
      NoSuchAlgorithmException - if the appropriate data integrity algorithm could not be found
      CertificateException - 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 given HybridRACFOutputStream stream.

      In order to create an empty keystore, or if the keystore cannot be initialized from a stream, pass null as the stream 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 class KeyStoreSpi
      Parameters:
      stream - the HybridRACFOutputStream stream from which the keystore is loaded, or null
      password - the password used to check the integrity of the keystore, the password used to unlock the keystore, or null
      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 incorrect
      NoSuchAlgorithmException - if the algorithm used to check the integrity of the keystore cannot be found
      CertificateException - if any of the certificates in the keystore could not be loaded