public class PKCS11Credential extends BasicX509Credential
BasicX509Credential
and provides an auto-reloadable credential for
PKCS#11 keys.
The class stores the necessary data to reload the key in case the connection to the key in the PKCS"11 token has been disrupted or lost.
Each time the private key is read from this credential, the private key reference is tested. If the private key can not be used, an attempt to reload the key is made.
Modifier and Type | Field and Description |
---|---|
protected Map<String,PrivateKey> |
privateKeyMap |
Constructor and Description |
---|
PKCS11Credential(X509Certificate entityCertificate,
List<String> providerNameList,
String alias,
CustomKeyExtractor customKeyExtractor)
Initializes the PKCS#11 credential.
|
PKCS11Credential(X509Certificate entityCertificate,
List<String> providerNameList,
String alias,
String pin)
Initializes the PKCS#11 credential.
|
Modifier and Type | Method and Description |
---|---|
String |
getCurrentKeyProvider()
Get the provider of the most recently selected private key.
|
PrivateKey |
getPrivateKey()
Overrides the default method to get the private key and adds a key test before the private key is extracted and
returned.
|
protected String |
getRandomProviderFromPool() |
getCredentialType, getCRLs, getEntityCertificate, getEntityCertificateChain, getPublicKey, getSecretKey, setCRLs, setEntityCertificate, setEntityCertificateChain, setPublicKey, setSecretKey
setEntityId, setPrivateKey, setUsageType
getCredentialContextSet, getEntityId, getKeyNames, getUsageType
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCredentialContextSet, getEntityId, getKeyNames, getUsageType
protected Map<String,PrivateKey> privateKeyMap
public PKCS11Credential(X509Certificate entityCertificate, List<String> providerNameList, String alias, CustomKeyExtractor customKeyExtractor) throws Exception
entityCertificate
- The entity certificate for this credentialproviderNameList
- The name of the security provider holding the private key objectcustomKeyExtractor
- A custom function for extracting the private key from the providerUnrecoverableKeyException
- if the private key can not be recoveredNoSuchAlgorithmException
- if the selected algorithm is not supportedKeyStoreException
- general keystore exceptionNoSuchProviderException
- if no provider for PKCS11 is availableIOException
- general IO errorsException
public PKCS11Credential(X509Certificate entityCertificate, List<String> providerNameList, String alias, String pin) throws Exception
entityCertificate
- The entity certificate for this credentialproviderNameList
- The name of the security provider holding the private key objectalias
- The alias of the private keypin
- The pin for the private keyUnrecoverableKeyException
- if the private key can not be recoveredNoSuchAlgorithmException
- if the selected algorithm is not supportedKeyStoreException
- general keystore exceptionNoSuchProviderException
- if no provider for PKCS11 is availableIOException
- general IO errorsException
protected String getRandomProviderFromPool()
public PrivateKey getPrivateKey()
getPrivateKey
in interface Credential
getPrivateKey
in class AbstractCredential
public String getCurrentKeyProvider()
Note: This method is mainly intended for logging purposes. It may not be thread safe to rely on this method unless it is called from within a synchronized method after loading the private key.
Copyright © 2018 Sweden Connect. All rights reserved.