Class KeyStoreCredential
java.lang.Object
se.swedenconnect.security.credential.AbstractPkiCredential
se.swedenconnect.security.credential.AbstractReloadablePkiCredential
se.swedenconnect.security.credential.KeyStoreCredential
- All Implemented Interfaces:
PkiCredential,ReloadablePkiCredential
A
KeyStore implementation of the PkiCredential and
ReloadablePkiCredential interfaces.
The constructors expect a loaded, and unlocked, KeyStore. See
KeyStoreFactory for methods to load a KeyStore.
- Author:
- Martin Lindström (martin@idsec.se), Stefan Santesson (stefan@idsec.se)
-
Nested Class Summary
Nested classes/interfaces inherited from interface se.swedenconnect.security.credential.PkiCredential
PkiCredential.Metadata -
Constructor Summary
ConstructorsConstructorDescriptionKeyStoreCredential(KeyStore keyStore, String alias, char[] keyPassword) Constructor taking aKeyStoreand the key entry alias and a key password.KeyStoreCredential(KeyStore keyStore, String alias, char[] keyPassword, List<X509Certificate> certificateChain) When using a PKCS#11KeyStorea variant is to only access the private key from the HSM, and have the corresponding certificate stored outside the HSM. -
Method Summary
Modifier and TypeMethodDescriptionvoiddestroy()Optional destroy method for credentials that need to perform cleaning up.Gets a certificate chain for the credential, where the first element is the entity certificate (PkiCredential.getCertificate()).protected StringIf the credentialnameproperty is not explicitly assigned usingAbstractPkiCredential.setName(String)a name is calculated based on a credential's properties.Returns the underlyingKeyStore.Gets the private key.booleanPredicate that tells whether this credential resides in a hardware module.voidreload()If theKeyStoreCredentialis of PKCS#11 type, and aKeyStoreReloaderhas been installed, the method will reload the private key.voidsetReloader(KeyStoreReloader reloader) Assigns aKeyStoreReloaderfor supporting reload of a hardware based credential.Methods inherited from class se.swedenconnect.security.credential.AbstractReloadablePkiCredential
getTestFunction, setTestFunctionMethods inherited from class se.swedenconnect.security.credential.AbstractPkiCredential
getMetadata, getName, getPublicKey, getStandalonePublicKey, setName, updateMetadataValidityPropertiesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface se.swedenconnect.security.credential.PkiCredential
getCertificate, getMetadata, getName, getPublicKey, transform
-
Constructor Details
-
KeyStoreCredential
public KeyStoreCredential(@Nonnull KeyStore keyStore, @Nonnull String alias, @Nullable char[] keyPassword) throws KeyStoreException Constructor taking aKeyStoreand the key entry alias and a key password.- Parameters:
keyStore- the keystore to read the key pair fromalias- the alias to the entry holding the key pairkeyPassword- the password to unlock the key pair (may benull)- Throws:
KeyStoreException- for errors loading the contents
-
KeyStoreCredential
public KeyStoreCredential(@Nonnull KeyStore keyStore, @Nonnull String alias, @Nullable char[] keyPassword, @Nullable List<X509Certificate> certificateChain) throws KeyStoreException When using a PKCS#11KeyStorea variant is to only access the private key from the HSM, and have the corresponding certificate stored outside the HSM. This constructor creates an instance where certificates are not read from theKeyStore.- Parameters:
keyStore- the keystore to read the key pair fromalias- the alias to the entry holding the key pairkeyPassword- the password to unlock the key pair (may benull)certificateChain- a non-empty list of certificates, where the entity certificate must be placed first in the list- Throws:
KeyStoreException- for errors loading the contents
-
-
Method Details
-
getKeyStore
Returns the underlyingKeyStore.- Returns:
- the
KeyStore
-
getPrivateKey
Gets the private key.- Returns:
- the private key
-
getCertificateChain
Gets a certificate chain for the credential, where the first element is the entity certificate (PkiCredential.getCertificate()). If no certificate is configured for the credential an empty list is returned.- Returns:
- a list of certificates, or an empty list
-
destroy
@PreDestroy public void destroy()Description copied from interface:PkiCredentialOptional destroy method for credentials that need to perform cleaning up. -
isHardwareCredential
public boolean isHardwareCredential()Predicate that tells whether this credential resides in a hardware module.- Returns:
trueif the credential resides in a hardware module andfalseotherwise
-
setReloader
Assigns aKeyStoreReloaderfor supporting reload of a hardware based credential.- Parameters:
reloader- the reloader instance
-
reload
If theKeyStoreCredentialis of PKCS#11 type, and aKeyStoreReloaderhas been installed, the method will reload the private key.- Throws:
Exception- for reloading errors
-
getDefaultName
If the credentialnameproperty is not explicitly assigned usingAbstractPkiCredential.setName(String)a name is calculated based on a credential's properties.- Specified by:
getDefaultNamein classAbstractPkiCredential- Returns:
- the credential name
-