Class PKCS11KeyStore
- java.lang.Object
-
- java.security.KeyStoreSpi
-
- com.ibm.crypto.pkcs11impl.provider.PKCS11KeyStore
-
public final class PKCS11KeyStore extends java.security.KeyStoreSpiThis class provides the keystore implementation of PKCS #11.- See Also:
KeyStoreSpi
-
-
Constructor Summary
Constructors Constructor and Description PKCS11KeyStore()Creates an instance of this classPKCS11KeyStore(java.security.Provider provider)Creates an instance of this class
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.security.PrivateKeybuildPrivateKey(Session session, com.ibm.pkcs11.PKCS11Object pobj)booleandoesPublicKeyMatchPrivateKey(java.security.PublicKey publicKey, java.security.PrivateKey privateKey, java.lang.String providerName)voiddumpKeyStoreEntries()java.util.EnumerationengineAliases()Lists all the alias names of this keystore.booleanengineContainsAlias(java.lang.String alias)Checks if the given alias exists in this keystore.voidengineDeleteEntry(java.lang.String alias)Deletes the entry identified by the given alias from this keystore and the token.java.security.cert.CertificateengineGetCertificate(java.lang.String alias)Returns the certificate associated with the given alias.java.lang.StringengineGetCertificateAlias(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.DateengineGetCreationDate(java.lang.String alias)This method is suppose to return the creation date of the entry identified by the given alias.java.security.KeyStore.EntryengineGetEntry(java.lang.String alias, java.security.KeyStore.ProtectionParameter protParam)Get aKeyStore.Entryfor the specified aliasjava.security.KeyengineGetKey(java.lang.String alias, char[] password)Returns the key associated with the given alias.booleanengineIsCertificateEntry(java.lang.String alias)Returns true if the entry identified by the given alias is a trusted certificate entry, and false otherwise.booleanengineIsKeyEntry(java.lang.String alias)Returns true if the entry identified by the given alias is a key entry, and false otherwise.voidengineLoad(java.io.InputStream stream, char[] password)Loads the keystore from the session associated with the IBMPKCS11Impl provider.voidengineLoad(java.security.KeyStore.LoadStoreParameter param)Loads the keystore from the session associated with the IBMPKCS11Impl provider.voidengineSetCertificateEntry(java.lang.String alias, java.security.cert.Certificate cert)Assigns the given certificate to the given alias.voidengineSetEntry(java.lang.String alias, java.security.KeyStore.Entry entry, java.security.KeyStore.ProtectionParameter protParam)Save aKeyStore.Entryunder the specified alias.voidengineSetKeyEntry(java.lang.String alias, byte[] key, java.security.cert.Certificate[] chain)Assigns the given key (that has already been protected) to the given alias.voidengineSetKeyEntry(java.lang.String alias, java.security.Key key, char[] password, java.security.cert.Certificate[] chain)Assigns the given key to the given alias.intengineSize()Retrieves the number of entries in this keystore.voidengineStore(java.io.OutputStream stream, char[] password)Stores this keystore to the given output stream, and protects its integrity with the given password.static byte[]getMagnitude(java.math.BigInteger bi)java.security.PrivateKeygetPrivateKey(Session session, byte[] id, java.lang.String label)booleanisSigner(java.security.cert.X509Certificate signerCert, java.security.cert.X509Certificate signedCert, java.lang.String providerName)static java.lang.StringtoHexString(byte[] block)Converts a byte array to hex string
-
-
-
Constructor Detail
-
PKCS11KeyStore
public PKCS11KeyStore()
Creates an instance of this class
-
PKCS11KeyStore
public PKCS11KeyStore(java.security.Provider provider)
Creates an instance of this class
-
-
Method Detail
-
engineGetKey
public java.security.Key engineGetKey(java.lang.String alias, char[] password) throws java.security.NoSuchAlgorithmException, java.security.UnrecoverableKeyExceptionReturns the key associated with the given alias.- Specified by:
engineGetKeyin classjava.security.KeyStoreSpi- Parameters:
alias- the alias namepassword- is not used by this key store.- Returns:
- the requested key, or null if the given alias does not exist or does not identify a key entry.
- Throws:
java.security.NoSuchAlgorithmException- if the algorithm for recovering the key cannot be foundjava.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.- Specified by:
engineGetCertificateChainin classjava.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 (i.e., the given alias identifies either a trusted certificate entry or a key entry without a certificate chain).
-
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 a trusted certificate entry, the certificate associated with that entry is returned. If the given alias name identifies a key entry, the first element of the certificate chain of that entry is returned, or null if that entry does not have a certificate chain.
- Specified by:
engineGetCertificatein classjava.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.
-
engineGetEntry
public java.security.KeyStore.Entry engineGetEntry(java.lang.String alias, java.security.KeyStore.ProtectionParameter protParam) throws java.security.KeyStoreException, java.security.NoSuchAlgorithmException, java.security.UnrecoverableEntryExceptionGet aKeyStore.Entryfor the specified alias- Overrides:
engineGetEntryin classjava.security.KeyStoreSpi- Parameters:
alias- get theKeyStore.Entryfor this aliasprotParam- this must benull- Returns:
- the
KeyStore.Entryfor the specified alias, ornullif there is no such entry - Throws:
java.security.KeyStoreException- if the operation failedjava.security.NoSuchAlgorithmException- if the algorithm for recovering the entry cannot be foundjava.security.UnrecoverableEntryException- if the specifiedprotParamwere insufficient or invalid- Since:
- 1.5
-
engineSetEntry
public void engineSetEntry(java.lang.String alias, java.security.KeyStore.Entry entry, java.security.KeyStore.ProtectionParameter protParam) throws java.security.KeyStoreExceptionSave aKeyStore.Entryunder the specified alias.If an entry already exists for the specified alias, it is overridden.
This KeyStore implementation only supports the standard entry types, This implementation does not support a protection Parameter, it will be ignored. The password will be the one associated with the token.
Entries are immediately stored on the token.
see engineSetKeyEntry and engineSetCertificateEntry for more information on adding keys and certificates using this keystore.
- Overrides:
engineSetEntryin classjava.security.KeyStoreSpi- Parameters:
alias- save theKeyStore.Entryunder this aliasentry- theEntryto saveprotParam- this must benull- Throws:
java.security.KeyStoreException- if this operation fails- Since:
- 1.5
-
engineGetCreationDate
public java.util.Date engineGetCreationDate(java.lang.String alias)
This method is suppose to return the creation date of the entry identified by the given alias.- Specified by:
engineGetCreationDatein classjava.security.KeyStoreSpi- Parameters:
alias- the alias name- Returns:
- the start date of the certificate or key entry, otherwise, return
nullif the start date is not set, or the specified alias is not found in this keystore.
-
engineSetKeyEntry
public void engineSetKeyEntry(java.lang.String alias, java.security.Key key, char[] password, java.security.cert.Certificate[] chain) throws java.security.KeyStoreExceptionAssigns the given key to the given alias.If the given key is of type
java.security.PrivateKey, it must be accompanied by a certificate chain certifying the corresponding public key.If a key entry already exists with that alias than that key entry will be replaced with the new one.
If the key is already a PKCS11 session key than this function will try and make the key a token key. Basically save the key on the card permanently.
If the key to be associated with alias is not a PKCS11Key than the code will try to translate the key to a PKCS11Key using the KeyFactory for than type of key. Therefore, if a configuration file was used to initialize the provider than attributes from that will be used to import the key to the card. If not, than the key will be created as a session key only and not be actually stored on the token permanently.
Note: The certificates in the certificate chain are not added or deleted from the token. This should be done using certificate entries.
- Specified by:
engineSetKeyEntryin classjava.security.KeyStoreSpi- Parameters:
alias- the alias namekey- the key to be associated with the aliaspassword- this parameter has no meaning currently for PKCS11 and there is not used.chain- the certificate chain for the corresponding public key (only required if the given key is of typejava.security.PrivateKey).- Throws:
java.security.KeyStoreException- if 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.KeyStoreExceptionAssigns the given key (that has already been protected) to the given alias. This key store does not not support this method and a KeyStoreException is always thrown if this method is called.- Specified by:
engineSetKeyEntryin classjava.security.KeyStoreSpi- Parameters:
alias- the alias namekey- the key (in protected format) to be associated with the aliaschain- the certificate chain for the corresponding public key (only useful if the protected key is of typejava.security.PrivateKey).- Throws:
java.security.KeyStoreException- is always thrown.
-
engineSetCertificateEntry
public void engineSetCertificateEntry(java.lang.String alias, java.security.cert.Certificate cert) throws java.security.KeyStoreExceptionAssigns the given certificate to the given alias.If a trusted certificate entry already exists with that alias than that entry may be replaced with the new one. To make sure that this keystore matchs, what is currently associated with the token than use
loadto reload the key store.Note: This method will add the certificate to the token as a token object.
- Specified by:
engineSetCertificateEntryin classjava.security.KeyStoreSpi- Parameters:
alias- the alias namecert- the certificate- Throws:
java.security.KeyStoreException- if the given alias already exists and does not identify a trusted certificate entry, or this operation fails for some other reason.
-
engineDeleteEntry
public void engineDeleteEntry(java.lang.String alias) throws java.security.KeyStoreExceptionDeletes the entry identified by the given alias from this keystore and the token.- Specified by:
engineDeleteEntryin classjava.security.KeyStoreSpi- Parameters:
alias- the alias name- Throws:
java.security.KeyStoreException- if the entry cannot be removed.
-
engineAliases
public java.util.Enumeration engineAliases()
Lists all the alias names of this keystore.- Specified by:
engineAliasesin classjava.security.KeyStoreSpi- Returns:
- enumeration of the alias names
-
engineContainsAlias
public boolean engineContainsAlias(java.lang.String alias)
Checks if the given alias exists in this keystore.- Specified by:
engineContainsAliasin classjava.security.KeyStoreSpi- Parameters:
alias- the alias name- Returns:
- true if the alias exists, false otherwise
-
engineSize
public int engineSize()
Retrieves the number of entries in this keystore.- Specified by:
engineSizein classjava.security.KeyStoreSpi- Returns:
- the number of entries in this keystore
-
engineIsKeyEntry
public boolean engineIsKeyEntry(java.lang.String alias)
Returns true if the entry identified by the given alias is a key entry, and false otherwise.- Specified by:
engineIsKeyEntryin classjava.security.KeyStoreSpi- Returns:
- true if the entry identified by the given alias is a key entry, false otherwise.
-
engineIsCertificateEntry
public boolean engineIsCertificateEntry(java.lang.String alias)
Returns true if the entry identified by the given alias is a trusted certificate entry, and false otherwise.- Specified by:
engineIsCertificateEntryin classjava.security.KeyStoreSpi- Returns:
- true if the entry identified by the given alias is a trusted certificate entry, false otherwise.
-
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 is a trusted certificate entry, the given certificate is compared to that entry's certificate. If the entry being considered is a key entry, the given certificate is compared to the first element of that entry's certificate chain (if a chain exists).
- Specified by:
engineGetCertificateAliasin classjava.security.KeyStoreSpi- Parameters:
cert- the certificate to match with.- Returns:
- the (alias) name of the first entry with matching certificate, or null if no such entry exists in this keystore.
-
engineStore
public void engineStore(java.io.OutputStream stream, char[] password) throws java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateExceptionStores this keystore to the given output stream, and protects its integrity with the given password.This method is not supported by this key store and will always throw a IOException
- Specified by:
engineStorein classjava.security.KeyStoreSpi- Parameters:
stream- the output stream to which this keystore is written.password- the password to generate the keystore integrity check- Throws:
java.io.IOException- always thrownjava.security.NoSuchAlgorithmException- is here for compatability.java.security.cert.CertificateException- is here for compatability.
-
engineLoad
public void engineLoad(java.security.KeyStore.LoadStoreParameter param) throws java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateExceptionLoads the keystore from the session associated with the IBMPKCS11Impl provider. This loads all private keys, secret keys and certificates.- Overrides:
engineLoadin classjava.security.KeyStoreSpi- Parameters:
stream- this parameter is not used by the method and can be any valuepassword- this parameter is not used by the method and can be any value- Throws:
java.io.IOException- if there is an I/O or format problem with the keystore datajava.security.NoSuchAlgorithmException- if the algorithm used to check the integrity of the keystore cannot be foundjava.security.cert.CertificateException- if any of the certificates in the keystore could not be loaded
-
getMagnitude
public static byte[] getMagnitude(java.math.BigInteger bi)
-
toHexString
public static java.lang.String toHexString(byte[] block)
Converts a byte array to hex string
-
doesPublicKeyMatchPrivateKey
public boolean doesPublicKeyMatchPrivateKey(java.security.PublicKey publicKey, java.security.PrivateKey privateKey, java.lang.String providerName) throws java.security.NoSuchAlgorithmException- Throws:
java.security.NoSuchAlgorithmException
-
isSigner
public boolean isSigner(java.security.cert.X509Certificate signerCert, java.security.cert.X509Certificate signedCert, java.lang.String providerName)
-
engineLoad
public void engineLoad(java.io.InputStream stream, char[] password) throws java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateExceptionLoads the keystore from the session associated with the IBMPKCS11Impl provider. This loads all private keys, secret keys and certificates.- Specified by:
engineLoadin classjava.security.KeyStoreSpi- Parameters:
stream- this parameter is not used by the method and can be any valuepassword- this parameter is not used by the method and can be any value- Throws:
java.io.IOException- if there is an I/O or format problem with the keystore datajava.security.NoSuchAlgorithmException- if the algorithm used to check the integrity of the keystore cannot be foundjava.security.cert.CertificateException- if any of the certificates in the keystore could not be loaded
-
buildPrivateKey
public java.security.PrivateKey buildPrivateKey(Session session, com.ibm.pkcs11.PKCS11Object pobj)
-
getPrivateKey
public java.security.PrivateKey getPrivateKey(Session session, byte[] id, java.lang.String label)
-
dumpKeyStoreEntries
public void dumpKeyStoreEntries()
-
-