Class Pkcs11Credential
java.lang.Object
se.swedenconnect.security.credential.AbstractPkiCredential
se.swedenconnect.security.credential.AbstractReloadablePkiCredential
se.swedenconnect.security.credential.pkcs11.Pkcs11Credential
- All Implemented Interfaces:
PkiCredential
,ReloadablePkiCredential
A PKCS#11 credential implementation of the
PkiCredential
and ReloadablePkiCredential
interfaces.
Note: In all cases where the SunPKCS11 security provider is used, it is recommended to use the
KeyStoreCredential
implementation instead.
- 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
ConstructorDescriptionPkcs11Credential
(Pkcs11Configuration configuration, String alias, char[] pin, Pkcs11PrivateKeyAccessor privateKeyAccessor, List<X509Certificate> certificates) Constructor that takes a list of X.509 certificates as an argument instead of aPkcs11CertificatesAccessor
.Pkcs11Credential
(Pkcs11Configuration configuration, String alias, char[] pin, Pkcs11PrivateKeyAccessor privateKeyAccessor, Pkcs11CertificatesAccessor certificatesAccessor) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Clears the saved PIN code.Gets a certificate chain for the credential, where the first element is the entity certificate (PkiCredential.getCertificate()
).protected String
If the credentialname
property is not explicitly assigned usingAbstractPkiCredential.setName(String)
a name is calculated based on a credential's properties.Gets the private key.boolean
Returnstrue
.void
reload()
Is called if the connection to the device has been lost.Methods inherited from class se.swedenconnect.security.credential.AbstractReloadablePkiCredential
getTestFunction, setTestFunction
Methods inherited from class se.swedenconnect.security.credential.AbstractPkiCredential
getMetadata, getName, getPublicKey, getStandalonePublicKey, setName, updateMetadataValidityProperties
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface se.swedenconnect.security.credential.PkiCredential
getCertificate, getMetadata, getName, getPublicKey, transform
-
Constructor Details
-
Pkcs11Credential
public Pkcs11Credential(@Nonnull Pkcs11Configuration configuration, @Nonnull String alias, @Nonnull char[] pin, @Nonnull Pkcs11PrivateKeyAccessor privateKeyAccessor, @Nonnull Pkcs11CertificatesAccessor certificatesAccessor) throws Pkcs11ConfigurationException Constructor.- Parameters:
configuration
- the PKCS#11 configurationalias
- the token entry from where to load the private key and certificatepin
- the PIN to unlock the tokenprivateKeyAccessor
- thePkcs11PrivateKeyAccessor
certificatesAccessor
- thePkcs11CertificatesAccessor
- Throws:
Pkcs11ConfigurationException
- for configuration errors
-
Pkcs11Credential
public Pkcs11Credential(@Nonnull Pkcs11Configuration configuration, @Nonnull String alias, @Nonnull char[] pin, @Nonnull Pkcs11PrivateKeyAccessor privateKeyAccessor, @Nonnull List<X509Certificate> certificates) throws Pkcs11ConfigurationException Constructor that takes a list of X.509 certificates as an argument instead of aPkcs11CertificatesAccessor
. This constructor should be used if we know that the certificate chain is not placed on the device (only the private key).- Parameters:
configuration
- the PKCS#11 configurationalias
- the token entry from where to load the private key and certificatepin
- the PIN to unlock the tokenprivateKeyAccessor
- thePkcs11PrivateKeyAccessor
certificates
- the certificate chain (entity certificate placed first)- Throws:
Pkcs11ConfigurationException
- for configuration errors
-
-
Method Details
-
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
-
isHardwareCredential
public boolean isHardwareCredential()Returnstrue
.- Returns:
true
if the credential resides in a hardware module andfalse
otherwise
-
reload
Is called if the connection to the device has been lost. In those cases we reload the private key.- Throws:
Exception
- for reloading errors
-
destroy
@PreDestroy public void destroy()Clears the saved PIN code. -
getDefaultName
If the credentialname
property is not explicitly assigned usingAbstractPkiCredential.setName(String)
a name is calculated based on a credential's properties.- Specified by:
getDefaultName
in classAbstractPkiCredential
- Returns:
- the credential name
-