Class HybridRACFKeyStore


  • public class HybridRACFKeyStore
    extends java.security.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:
    KeyStoreSpi
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Enumeration engineAliases()
      Lists all the alias names of this keystore.
      boolean engineContainsAlias​(java.lang.String alias)
      Checks if the given alias exists in this keystore.
      void engineDeleteEntry​(java.lang.String alias)
      Deletes the entry identified by the given alias from this keystore.
      java.security.cert.Certificate engineGetCertificate​(java.lang.String alias)
      Returns the certificate associated with the given alias.
      java.lang.String engineGetCertificateAlias​(java.security.cert.Certificate cert)
      Returns the (alias) name of the first keystore entry whose certificate matches the given certificate.
      java.security.cert.Certificate[] engineGetCertificateChain​(java.lang.String alias)
      Returns the certificate chain associated with the given alias.
      java.util.Date engineGetCreationDate​(java.lang.String alias)
      Fetch the time at which the certificate object was created.
      java.security.Key engineGetKey​(java.lang.String alias, char[] password)
      Returns the HybridRACFPrivateKey associated with the given alias, using the given password to recover it.
      boolean engineIsCertificateEntry​(java.lang.String alias)
      Returns true if the entry identified by the given alias was created by a call to setCertificateEntry.
      boolean engineIsKeyEntry​(java.lang.String alias)
      Returns true if the entry identified by the given alias was created by a call to setKeyEntry.
      void engineLoad​(java.io.InputStream stream, char[] password)
      Loads this KeyStore from the given HybridRACFOutputStream stream.
      void engineSetCertificateEntry​(java.lang.String alias, java.security.cert.Certificate cert)
      Assigns the given trusted certificate to the given alias.
      void engineSetKeyEntry​(java.lang.String alias, byte[] key, java.security.cert.Certificate[] chain)
      This method is not supported by the JCEHYBRIDRACFKS keystore.
      void engineSetKeyEntry​(java.lang.String alias, java.security.Key key, char[] password, java.security.cert.Certificate[] chain)
      Assigns the given key to the given alias, protecting it with the given password.
      int engineSize()
      Retrieves the number of entries in this keystore.
      void engineStore​(java.io.OutputStream stream, char[] password)
      Stores this keystore to the given HybridRACFOutputStream stream, and protects its integrity with the given password.
      • Methods inherited from class java.security.KeyStoreSpi

        engineEntryInstanceOf, engineGetEntry, engineLoad, engineProbe, engineSetEntry, engineStore
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HybridRACFKeyStore

        public HybridRACFKeyStore()
    • Method Detail

      • engineGetKey

        public java.security.Key engineGetKey​(java.lang.String alias,
                                              char[] password)
                                       throws java.security.NoSuchAlgorithmException,
                                              java.security.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 java.security.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:
        java.security.KeyStoreException - if the keystore has not been initialized (loaded).
        java.security.NoSuchAlgorithmException - if the algorithm for recovering the key cannot be found
        java.security.UnrecoverableKeyException - if the key cannot be recovered (e.g., the given password is wrong).
      • engineGetCertificateChain

        public java.security.cert.Certificate[] engineGetCertificateChain​(java.lang.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 java.security.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:
        java.security.KeyStoreException - if the keystore has not been initialized (loaded).
      • engineGetCertificate

        public java.security.cert.Certificate engineGetCertificate​(java.lang.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 java.security.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:
        java.security.KeyStoreException - if the keystore has not been initialized (loaded).
      • engineGetCreationDate

        public java.util.Date engineGetCreationDate​(java.lang.String alias)
        Fetch the time at which the certificate object was created.
        Specified by:
        engineGetCreationDate in class java.security.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:
        java.security.KeyStoreException - if the keystore has not been initialized (loaded).
      • engineSetKeyEntry

        public void engineSetKeyEntry​(java.lang.String alias,
                                      java.security.Key key,
                                      char[] password,
                                      java.security.cert.Certificate[] chain)
                               throws java.security.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 java.security.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:
        java.security.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​(java.lang.String alias,
                                      byte[] key,
                                      java.security.cert.Certificate[] chain)
                               throws java.security.KeyStoreException
        This method is not supported by the JCEHYBRIDRACFKS keystore. A KeyStoreException will always be thrown.
        Specified by:
        engineSetKeyEntry in class java.security.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:
        java.security.KeyStoreException - will always be thrown.
      • engineSetCertificateEntry

        public void engineSetCertificateEntry​(java.lang.String alias,
                                              java.security.cert.Certificate cert)
                                       throws java.security.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 java.security.KeyStoreSpi
        Parameters:
        alias - the alias name
        cert - the certificate
        Throws:
        java.security.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​(java.lang.String alias)
                               throws java.security.KeyStoreException
        Deletes the entry identified by the given alias from this keystore.
        Specified by:
        engineDeleteEntry in class java.security.KeyStoreSpi
        Parameters:
        alias - the alias name
        Throws:
        java.security.KeyStoreException - if the keystore has not been initialized, or if the entry cannot be removed.
      • engineAliases

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

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

        public boolean engineIsKeyEntry​(java.lang.String alias)
        Returns true if the entry identified by the given alias was created by a call to setKeyEntry.
        Specified by:
        engineIsKeyEntry in class java.security.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:
        java.security.KeyStoreException - if the keystore has not been initialized (loaded).
        java.lang.IllegalArgumentException - if the alias name is null.
      • engineIsCertificateEntry

        public boolean engineIsCertificateEntry​(java.lang.String alias)
        Returns true if the entry identified by the given alias was created by a call to setCertificateEntry.
        Specified by:
        engineIsCertificateEntry in class java.security.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:
        java.security.KeyStoreException - if the keystore has not been initialized (loaded).
      • engineGetCertificateAlias

        public java.lang.String engineGetCertificateAlias​(java.security.cert.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 java.security.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:
        java.security.KeyStoreException - if the keystore has not been initialized (loaded).
      • engineStore

        public void engineStore​(java.io.OutputStream stream,
                                char[] password)
                         throws java.io.IOException,
                                java.security.NoSuchAlgorithmException,
                                java.security.cert.CertificateException
        Stores this keystore to the given HybridRACFOutputStream stream, and protects its integrity with the given password.
        Specified by:
        engineStore in class java.security.KeyStoreSpi
        Parameters:
        stream - the output stream to which this keystore is written.
        password - the password to generate the keystore integrity check
        Throws:
        java.security.KeyStoreException - if the keystore has not been initialized (loaded).
        java.io.IOException - if there was an I/O problem with data
        java.security.NoSuchAlgorithmException - if the appropriate data integrity algorithm could not be found
        java.security.cert.CertificateException - if any of the certificates included in the keystore data could not be stored
      • engineLoad

        public void engineLoad​(java.io.InputStream stream,
                               char[] password)
                        throws java.io.IOException,
                               java.security.NoSuchAlgorithmException,
                               java.security.cert.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 java.security.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:
        java.io.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
        java.security.NoSuchAlgorithmException - if the algorithm used to check the integrity of the keystore cannot be found
        java.security.cert.CertificateException - if any of the certificates in the keystore could not be loaded