public class LunaKeyStore extends KeyStoreSpi
When no InputStream is specified, the KeyStore acts essentially as a front- end to the default HSM slot.
KeyStore ks = KeyStore.getInstance("Luna");
ks.load(null, "mypasswd".toCharArray());
The code above is the bare minimum necessary to get a Luna KeyStore up and
running. This KeyStore is backed by the HSM partition that is at the
currently specified default slot in LunaSlotManager. If no password
is supplied in load, the user must log in via LunaSlotManager
before using the keystore.
When the InputStream is backed by a file, the file should specify the slot to use in one of two formats. Using the string "tokenlabel:label" will attempt to open the KeyStore against the token with the provided label. Using "slot:<slotNum>" will attempt to open the KeyStore against the token at the provided slot. It is recommended that the token label be used, as the slot number of a given token may change but the label will not. As well, the user type can be specified by adding a line with "usertype:<user type>" with possible values of CKU_CRYPTO_USER or CKU_CRYPTO_OFFICER.
Using a file to back the InputStream in the load() method is optional. If there is no existing KeyStore file, a new KeyStore can be loaded by creating an InputStream backed by a String in one of the two formats above.
ByteArrayInputStream slot = new ByteArrayInputStream("slot:2".getBytes());
KeyStore ks = KeyStore.getInstance("Luna");
ks.load(slot, "mypasswd".toCharArray());
The code above will attempt to open a KeyStore on slot 2 with the partition password "mypasswd". Multiple KeyStores can be opened on the same slot, but they are not guaranteed to be thread-safe. External synchronization is recommended.
If an InputStream is provided that contains anything other than a string in one of the two formats above, the KeyStore will attempt to use the default slot.
| Modifier and Type | Field and Description |
|---|---|
static String |
CKU_CRYPTO_OFFICER |
static String |
CKU_CRYPTO_USER |
static String |
LABEL_TAG |
static String |
SLOT_TAG |
static String |
USER_TYPE_TAG |
| Constructor and Description |
|---|
LunaKeyStore()
Creates a new LunaKeyStore
|
| Modifier and Type | Method and Description |
|---|---|
Enumeration<String> |
engineAliases() |
boolean |
engineContainsAlias(String alias) |
void |
engineDeleteEntry(String alias) |
Certificate |
engineGetCertificate(String alias) |
String |
engineGetCertificateAlias(Certificate certificate) |
Certificate[] |
engineGetCertificateChain(String alias) |
Date |
engineGetCreationDate(String alias) |
Key |
engineGetKey(String alias,
char[] password) |
boolean |
engineIsCertificateEntry(String alias) |
boolean |
engineIsKeyEntry(String alias) |
void |
engineLoad(InputStream inputStream,
char[] password)
The Luna KeyStore reads data from one PKCS11 slot.
|
void |
engineSetCertificateEntry(String alias,
Certificate certificate) |
void |
engineSetKeyEntry(String alias,
byte[] key,
Certificate[] certificate) |
void |
engineSetKeyEntry(String alias,
Key key,
char[] password,
Certificate[] certificateChain) |
int |
engineSize() |
void |
engineStore(OutputStream outputStream,
char[] password) |
engineEntryInstanceOf, engineGetEntry, engineLoad, engineSetEntry, engineStorepublic static final String LABEL_TAG
public static final String SLOT_TAG
public static final String USER_TYPE_TAG
public static final String CKU_CRYPTO_OFFICER
public static final String CKU_CRYPTO_USER
public Enumeration<String> engineAliases()
engineAliases in class KeyStoreSpipublic boolean engineContainsAlias(String alias)
engineContainsAlias in class KeyStoreSpipublic void engineDeleteEntry(String alias) throws KeyStoreException
engineDeleteEntry in class KeyStoreSpiKeyStoreExceptionpublic Certificate engineGetCertificate(String alias)
engineGetCertificate in class KeyStoreSpipublic String engineGetCertificateAlias(Certificate certificate)
engineGetCertificateAlias in class KeyStoreSpipublic Certificate[] engineGetCertificateChain(String alias)
engineGetCertificateChain in class KeyStoreSpipublic Date engineGetCreationDate(String alias)
engineGetCreationDate in class KeyStoreSpipublic Key engineGetKey(String alias, char[] password) throws NoSuchAlgorithmException, UnrecoverableKeyException
engineGetKey in class KeyStoreSpialias - key labelpassword - per-key password (unused by Luna)NoSuchAlgorithmException - exceptionUnrecoverableKeyException - exceptionpublic boolean engineIsCertificateEntry(String alias)
engineIsCertificateEntry in class KeyStoreSpipublic boolean engineIsKeyEntry(String alias)
engineIsKeyEntry in class KeyStoreSpipublic void engineSetCertificateEntry(String alias, Certificate certificate) throws KeyStoreException
engineSetCertificateEntry in class KeyStoreSpiKeyStoreExceptionpublic void engineSetKeyEntry(String alias, byte[] key, Certificate[] certificate) throws KeyStoreException
engineSetKeyEntry in class KeyStoreSpiKeyStoreExceptionpublic void engineSetKeyEntry(String alias, Key key, char[] password, Certificate[] certificateChain) throws KeyStoreException
engineSetKeyEntry in class KeyStoreSpialias - key labelkey - key object to be associated with the aliaspassword - per-key password (unused by Luna)certificateChain - the certificate chain for the corresponding public key (only required if the given key is of type java.security.PrivateKey).KeyStoreException - exceptionpublic int engineSize()
engineSize in class KeyStoreSpipublic void engineLoad(InputStream inputStream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException
engineLoad in class KeyStoreSpiinputStream - Determines the slot the keystore is loaded against
as described abovepassword - Password for the slot. If no password is given,
keystore operations will fail unless the user logs in to the slot
directly using LunaSlotManager, or is already logged inIOExceptionNoSuchAlgorithmExceptionCertificateExceptionpublic void engineStore(OutputStream outputStream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException
engineStore in class KeyStoreSpiIOExceptionNoSuchAlgorithmExceptionCertificateExceptionCopyright 2014-2016 SafeNet Inc