public class EntrustKeyStoreSpi
extends java.security.KeyStoreSpi
EntrustKeyStoreSpi class provides a common interface for the
user to work with a variety of credentials.
Create a key store as follows:
KeyStore.getInstance("Entrust");
Load(InputStream input, char[] password);
The InputStream argument must be set to one of the following:
ini fileepf filepkcs12 fileExample:
// Create a key store ini file using the KSIniFileCreator class
KeyStore entrustKeyStore = KeyStore.getInstance("Entrust");
char[] pwd = ...;
FileInputStream input = new FileInputStream("C:\\ksIniFile.kst");
entrust.load(input, pwd);
// Retrieve keys and certificates from the key store
Certificate verificationCert = entrustKeyStore.getCertificate("signing");
Certificate encryptionCert = entrustKeyStore.getCertificate("encryption");
Certificate caCert = entrustKeyStore.getCertificate("CA");
PrivateKey signingKey = entrustKeyStore.getKey("signing", null);
PrivateKey decryptionKey = entrustKeyStore.getKey("encryption", null);
When an Entrust key store is loaded from an Entrust key store INI file, a
User object is automatically created and logged in. In the case
were the user's credentials reside on a Cryptoki device, a PKCS11 connection is
also created and opened. Once the key store is no longer needed, the user
SHOULD be logged off and the PKCS11 connection SHOULD be closed (if one was
opened) - this is called the close routine. Unfortunately the KeyStore API
does not provide any methods to invoke a close routine.
The close routine can be invoked though a special usage of the
engineStore(OutputStream, char[]) method. When the key store was
loaded from an Entrust key store INI file, and the store method is called with
"close" as the password, the close routine is invoked.
entrustKeyStore.store(null, EntrustKeyStoreSpi.CLOSE_KEY_STORE);
Once this is done, the key store SHOULD no longer be used. In case a designer forgets to call the close routine manually, it will also be invoked in the finalizer when a PKCS11 connection is used, but this is not guaranteed to ever be run.
For compatibility with keystores created using Release 5.1 of the Toolkit,
it is still possible to retrieve keys and certificates using the "RSA" alias.
The aliases "signing" and "encryption" can also be used. If a key store is
instantiated using the getInstance() method, only the aliases
"signing" and "encryption" are supported the alias "RSA" cannot be used
in this case.
| Modifier and Type | Field and Description |
|---|---|
static char[] |
CLOSE_KEY_STORE
A special indicator designed to be used as the password parameter in the
engineStore(OutputStream, char[]) method to indicate that the
key store should be closed. |
static boolean |
DEBUG |
| Modifier | Constructor and Description |
|---|---|
|
EntrustKeyStoreSpi()
Creates an empty key store initialized by the
load method. |
protected |
EntrustKeyStoreSpi(User user,
boolean clientMode)
This constructor is used only by the
EntrustKeyStore class. |
| Modifier and Type | Method and Description |
|---|---|
java.util.Enumeration |
engineAliases()
Returns all aliases that have matching keys or certificates.
|
boolean |
engineContainsAlias(java.lang.String name)
Determines whether the given alias maps to a key or to
a certificate.
|
void |
engineDeleteEntry(java.lang.String name)
Deletes only those certificates from the read/write certificate
store (if they are available).
|
java.security.cert.Certificate |
engineGetCertificate(java.lang.String name)
Returns the certificate corresponding to the specified alias.
|
java.lang.String |
engineGetCertificateAlias(java.security.cert.Certificate cert)
Returns the certificate alias corresponding to the given certificate.
|
java.security.cert.Certificate[] |
engineGetCertificateChain(java.lang.String name)
Returns the certificate chain corresponding to the specified
alias.
|
java.util.Date |
engineGetCreationDate(java.lang.String name)
The key store does not contain the information regarding the
creation date of each entry, the following is returned for each
case.
|
java.security.Key |
engineGetKey(java.lang.String name,
char[] password)
Returns the key corresponding to the specified alias.
|
boolean |
engineIsCertificateEntry(java.lang.String name)
Determines whether the given alias maps to a certificate.
|
boolean |
engineIsKeyEntry(java.lang.String name)
Determines whether the given alias maps to a key.
|
void |
engineLoad(java.io.InputStream input,
char[] password)
Reads an Entrust Profile from the specified input stream.
|
void |
engineSetCertificateEntry(java.lang.String name,
java.security.cert.Certificate c)
Adds certificates to the Entrust key store.
|
void |
engineSetKeyEntry(java.lang.String name,
byte[] key,
java.security.cert.Certificate[] certChain)
Adding keys to the Entrust key store is not permitted.
|
void |
engineSetKeyEntry(java.lang.String name,
java.security.Key key,
java.security.cert.Certificate[] certChain)
Adding keys to the Entrust key store is not permitted.
|
void |
engineSetKeyEntry(java.lang.String name,
java.security.Key key,
char[] pass,
java.security.cert.Certificate[] c)
Adding keys to the Entrust key store is not permitted.
|
int |
engineSize()
Returns the number of entries in a key store.
|
void |
engineStore(java.io.OutputStream output,
char[] password)
Write the read-write certificate store to the given output stream.
|
protected void |
finalize()
When using a cryptoki device, make sure the device is closed otherwise
exceptions are thrown.
|
User |
getUser()
Returns the
User object wrapped by this key store. |
public static final boolean DEBUG
public static final char[] CLOSE_KEY_STORE
engineStore(OutputStream, char[]) method to indicate that the
key store should be closed. It should be used with key stores that were
loaded from an Entrust key store INI file to log-off the internally created
user, and close an internally created PKCS11 connection. Following this
call, the key store should no longer be used.public EntrustKeyStoreSpi()
load method.protected EntrustKeyStoreSpi(User user, boolean clientMode)
EntrustKeyStore class.
The constructor allows a key store to be initialized with a User
object, so that the user has to log in only once for both the key source
and the verification source.
user - a logged-in User objectclientMode - false if this class is intended to be used
with an SSL server true if intended
to be used with a client. This argument determines whether
the signing or encryption key pair is used (encryption for
server, signing for client).public User getUser()
User object wrapped by this key store.
User object.public void engineLoad(java.io.InputStream input,
char[] password)
throws java.security.cert.CertificateException,
java.io.IOException
engineLoad in class java.security.KeyStoreSpiinput - the stream from which to read the profilepassword - the password protecting the profile. It will be
wiped.java.security.cert.CertificateExceptionjava.io.IOExceptionpublic void engineStore(java.io.OutputStream output,
char[] password)
throws java.io.IOException,
java.security.cert.CertificateException
If the key store is loaded through a key store ini
file, the output and password arguments
are ignored, and only the read/write credential store is written
to the files specified in the key store ini file.
If the key store is loaded from an epf file or
from a p12 file, the read-write certificate store
is written to the given output stream.
engineStore in class java.security.KeyStoreSpioutput - ignored if the key store has been loaded
from a key store ini file. In this case,
only the changed read/write certificate store is
written to the files specified by the ini
file.
If the key store has been loaded from memory, only the
read-write certificate stores are written to the
given output stream in p12 format.password - Ignored if the key store has been loaded
from a key store ini file. In this case, the password specified
in the ini file is used.
If the key store has been loaded from memory, the given password
is used to protect the certificate stores.java.io.IOException - thrown if the key store has been loaded from
memory, and the given output stream is nulljava.security.cert.CertificateException - thrown if there is an error in writing
the key store informationpublic java.lang.String engineGetCertificateAlias(java.security.cert.Certificate cert)
The aliases are searched in the following order:
If the certificate is not found, the method returns null.
engineGetCertificateAlias in class java.security.KeyStoreSpicert - the cert for which the alias is to be returnednull
if the certificate cannot be foundpublic boolean engineIsCertificateEntry(java.lang.String name)
Searches the certificate in the following order:
true if name is "verificationCertificate",
"encryptionCertificate", "CA", "ROOTCA" or "SUBCA{1..N}" and the appropriate
certificate is availablename is "signing" or
"encryption".
true if name is "RSA" and
the appropriate certificate is available. "RSA" is checked
only if the key store was created with the
EntrustKeyStore constructor. This is done to
maintain compatibility with release 5.1.true if name found in
read/write certificate store (if available)true if name found in
read-only certificate store (if available)engineIsCertificateEntry in class java.security.KeyStoreSpiname - the alias to check against matching certificatestrue if certificate is found,
otherwise falsepublic boolean engineIsKeyEntry(java.lang.String name)
Searches the key in the following order:
true if name is "signingKey"
or "decryptionKey" and the appropriate key is availablename is "signing" or
"encryption".
true if name is "RSA" and the
appropriate key is available
"RSA" is checked only if the key store was created with the
EntrustKeyStore constructor. This is
done to maintain compatibility with applications created using
release 5.1 of the Toolkit
engineIsKeyEntry in class java.security.KeyStoreSpiname - the alias to check against matching keystrue if key is found, otherwise
falsepublic int engineSize()
The number is calculated as follows:
The certificates in the directory (if available) are disregarded.
engineSize in class java.security.KeyStoreSpipublic boolean engineContainsAlias(java.lang.String name)
Refer to the documentation for the
engineIsCertificateEntry and
engineIsKeyEntry methods.
true only if name is "RSA".
engineContainsAlias in class java.security.KeyStoreSpiname - the alias to check against matching keys
or certificatestrue if entry exists, otherwise
falsepublic java.util.Enumeration engineAliases()
The Enumeration return value contains the following:
The aliases of the certificates in the directory (if available) are disregarded.
engineAliases in class java.security.KeyStoreSpiEnumeration containing the aliasespublic void engineDeleteEntry(java.lang.String name)
throws java.security.KeyStoreException
The method deletes entrys in all read/write certificate stores containing an appropriate entry.
Deleting keys from the Entrust key store is not permitted.
engineDeleteEntry in class java.security.KeyStoreSpiKeyStoreException - thrown if entry does not exist or cannot be deletedjava.security.KeyStoreExceptionpublic void engineSetKeyEntry(java.lang.String name,
byte[] key,
java.security.cert.Certificate[] certChain)
throws java.security.KeyStoreException
engineSetKeyEntry in class java.security.KeyStoreSpiKeyStoreException - thrown if this method is calledjava.security.KeyStoreExceptionpublic void engineSetKeyEntry(java.lang.String name,
java.security.Key key,
java.security.cert.Certificate[] certChain)
throws java.security.KeyStoreException
KeyStoreException - thrown if this method is calledjava.security.KeyStoreExceptionpublic java.security.cert.Certificate engineGetCertificate(java.lang.String name)
The certificate is searched in the following order:
name is "verificationCertificate",
"encryptionCertificate","CA","ROOTCA" or "SUBCA{1.N}" the appropriate certificate is
returned if available.
name is "signing" or
"encryption".
EntrustKeyStore constructor and the name
is "RSA", the appropriate certificate is returned if
available. This is done to maintain compatibility with
applications build using release 5.1 of the Toolkit.
If the certificate is not found, null is returned.
engineGetCertificate in class java.security.KeyStoreSpiname - the alias of the certificate being searched fornullpublic java.security.Key engineGetKey(java.lang.String name,
char[] password)
The key is searched as follows:
If the name is "signingKey" or "decryptionKey", the appropriate key is returned if available.
name is "signing" or
"encryption".
EntrustKeyStore constructor and the name
is "RSA", the appropriate key is returned if available.
This is done to maintain compatibility with applications
built using release 5.1 of the Toolkit.engineGetKey in class java.security.KeyStoreSpiname - the alias of the key being searched forpassword - ignorednullpublic java.security.cert.Certificate[] engineGetCertificateChain(java.lang.String name)
The certificate chain is searched as follows:
If the name is "CA", the CA certificate chain is returned. The first element of the array is the immediate CA certificate and the last element is the top level trusted root certificate.
If the name is "signingKey", "decryptionKey", "verificationCertificate" or "encryptionCertificate", the appropriate certificate chain is returned if available.
name is "signing" or
"encryption".
EntrustKeyStore constructor and the name
is "RSA", the appropriate certificate chain is returned
if available. This is done to maintain compatibility
with applications built using release 5.1 of the
Toolkit.engineGetCertificateChain in class java.security.KeyStoreSpiname - the alias to be searched forpublic void engineSetCertificateEntry(java.lang.String name,
java.security.cert.Certificate c)
throws java.security.KeyStoreException
If the key store is loaded from a key store ini file,
this method adds certicates to the key store only if a read/write
certificate store is available. If an entry already exists in the
read/write certificate store with the given alias, the entry is
overwritten.
If the key store is loaded from a source other than a key store
ini file, and no read/write certificate store exists,
a new read/write store will be created.
engineSetCertificateEntry in class java.security.KeyStoreSpiname - the alias namec - the certificateKeyStoreException - thrown if the key store is loaded from an ini
file and no read/write certificate store is availablejava.security.KeyStoreExceptionpublic void engineSetKeyEntry(java.lang.String name,
java.security.Key key,
char[] pass,
java.security.cert.Certificate[] c)
throws java.security.KeyStoreException
engineSetKeyEntry in class java.security.KeyStoreSpiKeyStoreException - thrown if this method is calledjava.security.KeyStoreExceptionpublic java.util.Date engineGetCreationDate(java.lang.String name)
null if no entry is found with the given name.
engineGetCreationDate in class java.security.KeyStoreSpinull if
no entry is found.protected void finalize()
throws java.lang.Throwable
finalize in class java.lang.Objectjava.lang.Throwable