Package com.azure.security.keyvault.jca
Class KeyVaultKeyStore
- java.lang.Object
-
- java.security.KeyStoreSpi
-
- com.azure.security.keyvault.jca.KeyVaultKeyStore
-
public final class KeyVaultKeyStore extends KeyStoreSpi
The Azure Key Vault implementation of the KeyStoreSpi.- See Also:
KeyStoreSpi
-
-
Field Summary
Fields Modifier and Type Field Description static StringALGORITHM_NAMEStores the algorithm name.static StringKEY_STORE_TYPEStores the key-store name.
-
Constructor Summary
Constructors Constructor Description KeyVaultKeyStore()Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Enumeration<String>engineAliases()Lists all the alias names of this keystore.booleanengineContainsAlias(String alias)Checks if the given alias exists in this keystore.voidengineDeleteEntry(String alias)Deletes the entry identified by the given alias from this keystore.booleanengineEntryInstanceOf(String alias, Class<? extends KeyStore.Entry> entryClass)Determines if the keystoreEntryfor the specifiedaliasis an instance or subclass of the specifiedentryClass.CertificateengineGetCertificate(String alias)Get the certificate associated with the given alias.StringengineGetCertificateAlias(Certificate cert)Get the (alias) name of the first keystore entry whose certificate matches the given certificate.Certificate[]engineGetCertificateChain(String alias)Get the certificate chain associated with the given alias.DateengineGetCreationDate(String alias)Get the creation date of the entry identified by the given alias.KeyStore.EntryengineGetEntry(String alias, KeyStore.ProtectionParameter protParam)Gets aKeyStore.Entryfor the specified alias with the specified protection parameter.KeyengineGetKey(String alias, char[] password)Get key associated with the given alias.booleanengineIsCertificateEntry(String alias)Check whether the entry identified by the given alias contains a trusted certificate.booleanengineIsKeyEntry(String alias)Check whether the entry identified by the given alias is a key-related.voidengineLoad(InputStream stream, char[] password)Loads the keystore from the given input stream.voidengineLoad(KeyStore.LoadStoreParameter param)Loads the keystore using the givenKeyStore.LoadStoreParameter.voidengineSetCertificateEntry(String alias, Certificate certificate)Assigns the given certificate to the given alias.voidengineSetEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam)Saves aKeyStore.Entryunder the specified alias.voidengineSetKeyEntry(String alias, byte[] key, Certificate[] chain)Assigns the given key (that has already been protected) to the given alias.voidengineSetKeyEntry(String alias, Key key, char[] password, Certificate[] chain)Assigns the given key to the given alias, protecting it with the given password.intengineSize()Retrieves the number of entries in this keystore.voidengineStore(OutputStream stream, char[] password)Stores this keystore to the given output stream, and protects its integrity with the given password.voidengineStore(KeyStore.LoadStoreParameter param)Stores this keystore using the given.static KeyStoregetKeyVaultKeyStoreBySystemProperty()get key vault key store by system property-
Methods inherited from class java.security.KeyStoreSpi
engineProbe
-
-
-
-
Field Detail
-
KEY_STORE_TYPE
public static final String KEY_STORE_TYPE
Stores the key-store name.- See Also:
- Constant Field Values
-
ALGORITHM_NAME
public static final String ALGORITHM_NAME
Stores the algorithm name.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
KeyVaultKeyStore
public KeyVaultKeyStore()
Constructor.The constructor uses System.getProperty for
azure.keyvault.uri,azure.keyvault.aadAuthenticationUrl,azure.keyvault.tenantId,azure.keyvault.clientId,azure.keyvault.clientSecretandazure.keyvault.managedIdentityto initialize the Key Vault client.
-
-
Method Detail
-
getKeyVaultKeyStoreBySystemProperty
public static KeyStore getKeyVaultKeyStoreBySystemProperty() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, IOException
get key vault key store by system property- Returns:
- KeyVault key store
- Throws:
CertificateException- if any of the certificates in the keystore could not be loadedNoSuchAlgorithmException- when algorithm is unavailable.KeyStoreException- when no Provider supports a KeyStoreSpi implementation for the specified typeIOException- when an I/O error occurs.
-
engineAliases
public Enumeration<String> engineAliases()
Lists all the alias names of this keystore.- Specified by:
engineAliasesin classKeyStoreSpi- Returns:
- enumeration of the alias names
-
engineContainsAlias
public boolean engineContainsAlias(String alias)
Checks if the given alias exists in this keystore.- Specified by:
engineContainsAliasin classKeyStoreSpi- Parameters:
alias- the alias name- Returns:
- true if the alias exists, false otherwise
-
engineDeleteEntry
public void engineDeleteEntry(String alias)
Deletes the entry identified by the given alias from this keystore.- Specified by:
engineDeleteEntryin classKeyStoreSpi- Parameters:
alias- the alias name
-
engineEntryInstanceOf
public boolean engineEntryInstanceOf(String alias, Class<? extends KeyStore.Entry> entryClass)
Determines if the keystoreEntryfor the specifiedaliasis an instance or subclass of the specifiedentryClass.- Overrides:
engineEntryInstanceOfin classKeyStoreSpi- Parameters:
alias- the alias nameentryClass- the entry class- Returns:
- true if the keystore
Entryfor the specifiedaliasis an instance or subclass of the specifiedentryClass, false otherwise
-
engineGetCertificate
public Certificate engineGetCertificate(String alias)
Get the certificate associated with the given alias.- Specified by:
engineGetCertificatein classKeyStoreSpi- Parameters:
alias- the alias name- Returns:
- the certificate, or null if the given alias does not exist or does not contain a certificate
-
engineGetCertificateAlias
public String engineGetCertificateAlias(Certificate cert)
Get the (alias) name of the first keystore entry whose certificate matches the given certificate.- Specified by:
engineGetCertificateAliasin classKeyStoreSpi- 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
-
engineGetCertificateChain
public Certificate[] engineGetCertificateChain(String alias)
Get the certificate chain associated with the given alias.- Specified by:
engineGetCertificateChainin classKeyStoreSpi- 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
-
engineGetCreationDate
public Date engineGetCreationDate(String alias)
Get the creation date of the entry identified by the given alias.- Specified by:
engineGetCreationDatein classKeyStoreSpi- Parameters:
alias- the alias name- Returns:
- the creation date of this entry, or null if the given alias does not exist
-
engineGetEntry
public KeyStore.Entry engineGetEntry(String alias, KeyStore.ProtectionParameter protParam) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException
Gets aKeyStore.Entryfor the specified alias with the specified protection parameter.- Overrides:
engineGetEntryin classKeyStoreSpi- Parameters:
alias- the alias nameprotParam- the protParam- Returns:
- the
KeyStore.Entryfor the specified alias,ornullif there is no such entry - Throws:
KeyStoreException- if the operation failedNoSuchAlgorithmException- if the algorithm for recovering the entry cannot be foundUnrecoverableEntryException- if the specifiedprotParamwere insufficient or invalid
-
engineGetKey
public Key engineGetKey(String alias, char[] password)
Get key associated with the given alias.- Specified by:
engineGetKeyin classKeyStoreSpi- Parameters:
alias- the alias namepassword- the password for recovering the key- Returns:
- the requested key, or null if the given alias does not exist or does not identify a key-related entry
-
engineIsCertificateEntry
public boolean engineIsCertificateEntry(String alias)
Check whether the entry identified by the given alias contains a trusted certificate.- Specified by:
engineIsCertificateEntryin classKeyStoreSpi- Parameters:
alias- the alias name- Returns:
- true if the entry identified by the given alias contains a trusted certificate, false otherwise
-
engineIsKeyEntry
public boolean engineIsKeyEntry(String alias)
Check whether the entry identified by the given alias is a key-related.- Specified by:
engineIsKeyEntryin classKeyStoreSpi- 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, false otherwise
-
engineLoad
public void engineLoad(KeyStore.LoadStoreParameter param)
Loads the keystore using the givenKeyStore.LoadStoreParameter.- Overrides:
engineLoadin classKeyStoreSpi- Parameters:
param- theKeyStore.LoadStoreParameterthat specifies how to load the keystore, which may benull
-
engineLoad
public void engineLoad(InputStream stream, char[] password)
Loads the keystore from the given input stream.- Specified by:
engineLoadin classKeyStoreSpi- Parameters:
stream- the input stream from which the keystore is loaded,ornullpassword- the password
-
engineSetCertificateEntry
public void engineSetCertificateEntry(String alias, Certificate certificate)
Assigns the given certificate to the given alias.- Specified by:
engineSetCertificateEntryin classKeyStoreSpi- Parameters:
alias- the alias namecertificate- the certificate
-
engineSetEntry
public void engineSetEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam) throws KeyStoreException
Saves aKeyStore.Entryunder the specified alias. The specified protection parameter is used to protect theEntry.- Overrides:
engineSetEntryin classKeyStoreSpi- Parameters:
alias- the alias nameentry- the entryprotParam- the protParam- Throws:
KeyStoreException- if this operation fails
-
engineSetKeyEntry
public void engineSetKeyEntry(String alias, Key key, char[] password, Certificate[] chain)
Assigns the given key to the given alias, protecting it with the given password.- Specified by:
engineSetKeyEntryin classKeyStoreSpi- Parameters:
alias- the alias namekey- the key to be associated with the aliaspassword- the password to protect the keychain- the certificate chain
-
engineSetKeyEntry
public void engineSetKeyEntry(String alias, byte[] key, Certificate[] chain)
Assigns the given key (that has already been protected) to the given alias.- Specified by:
engineSetKeyEntryin classKeyStoreSpi- Parameters:
alias- the alias namekey- the keychain- the certificate chain
-
engineSize
public int engineSize()
Retrieves the number of entries in this keystore.- Specified by:
engineSizein classKeyStoreSpi- Returns:
- the number of entries in this keystore
-
engineStore
public void engineStore(OutputStream stream, char[] password)
Stores this keystore to the given output stream, and protects its integrity with the given password.- Specified by:
engineStorein classKeyStoreSpi- Parameters:
stream- the output stream to which this keystore is writtenpassword- the password to generate the keystore integrity check
-
engineStore
public void engineStore(KeyStore.LoadStoreParameter param)
Stores this keystore using the given.- Overrides:
engineStorein classKeyStoreSpi- Parameters:
param- the param
-
-