Package org.certificateservices.messages
Class PKCS11MessageSecurityProvider
- java.lang.Object
-
- org.certificateservices.messages.PKCS11MessageSecurityProvider
-
- All Implemented Interfaces:
ContextMessageSecurityProvider,MessageSecurityProvider
public class PKCS11MessageSecurityProvider extends java.lang.Object implements ContextMessageSecurityProvider
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.certificateservices.messages.ContextMessageSecurityProvider
ContextMessageSecurityProvider.Context
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringSETTING_PREFIXstatic java.lang.StringSETTING_TRUSTSTORE_PASSWORDSetting indicating the password to the trust JKS key store (required)static java.lang.StringSETTING_TRUSTSTORE_PATHSetting indicating the path to the trust JKS key store (required)protected TruststoreHelpertruststoreHelper-
Fields inherited from interface org.certificateservices.messages.ContextMessageSecurityProvider
DEFAULT_CONTEXT
-
Fields inherited from interface org.certificateservices.messages.MessageSecurityProvider
DEFAULT_DECRYPTIONKEY
-
-
Constructor Summary
Constructors Constructor Description PKCS11MessageSecurityProvider(java.util.Properties config)PKCS11MessageSecurityProvider(java.util.Properties config, PKCS11ProviderManager providerManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.security.cert.X509CertificategetDecryptionCertificate(java.lang.String keyId)Fetches the decryption certificate of related key id.java.security.cert.X509CertificategetDecryptionCertificate(ContextMessageSecurityProvider.Context context, java.lang.String keyId)Fetches the decryption certificate of related key id.java.security.cert.X509Certificate[]getDecryptionCertificateChain(java.lang.String keyId)Fetches the decryption certificate chain of related key id can be one or more in size..java.security.cert.X509Certificate[]getDecryptionCertificateChain(ContextMessageSecurityProvider.Context context, java.lang.String keyId)Fetches the decryption certificate chain of related key id can be one or more in size.java.security.PrivateKeygetDecryptionKey(java.lang.String keyId)Fetches a private key given it's unique identifier.java.security.PrivateKeygetDecryptionKey(ContextMessageSecurityProvider.Context context, java.lang.String keyId)Fetches a private key given it's unique identifier.java.util.Set<java.lang.String>getDecryptionKeyIds()Returns key identifiers of all available decryption keys.java.util.Set<java.lang.String>getDecryptionKeyIds(ContextMessageSecurityProvider.Context context)Returns key identifiers of all available decryption keys.EncryptionAlgorithmSchemegetEncryptionAlgorithmScheme()Method to fetch the EncryptionAlgorithmScheme to use when encrypting messages.EncryptionAlgorithmSchemegetEncryptionAlgorithmScheme(ContextMessageSecurityProvider.Context context)Method to fetch the EncryptionAlgorithmScheme to use when encrypting messages.protected java.security.KeyStoregetPKCS11Keystore(java.lang.String pkcs11Library, int slot, java.lang.String slotPassword)Create Sun PKCS#11 keystore with given parameters.java.lang.StringgetPKCS11Provider()Deprecated.java.lang.StringgetProvider()Method to retrieve JCE provider that should be used with keys provided by this provider.java.lang.StringgetProvider(ContextMessageSecurityProvider.Context context)Method to retrieve JCE provider that should be used with keys provided by this provider.SigningAlgorithmSchemegetSigningAlgorithmScheme()Method to fetch the SigningAlgorithmScheme to use when signing messages.SigningAlgorithmSchemegetSigningAlgorithmScheme(ContextMessageSecurityProvider.Context context)Method to fetch the SigningAlgorithmScheme to use when signing messages.java.security.cert.X509CertificategetSigningCertificate()Fetches the signing certificate used to create the digital signatures of the XML file.java.security.cert.X509CertificategetSigningCertificate(ContextMessageSecurityProvider.Context context)Fetches the signing certificate used to create the digital signatures of the XML file.java.security.PrivateKeygetSigningKey()Fetches the signing key used to create the digital signatures of the XML file.java.security.PrivateKeygetSigningKey(ContextMessageSecurityProvider.Context context)Fetches the signing key used to create the digital signatures of the XML file.booleanisValidAndAuthorized(java.security.cert.X509Certificate signCertificate, java.lang.String organisation)Method that checks if a sign certificate is in the trust store, the certificate itself have to be imported and not just the CA certificate.booleanisValidAndAuthorized(ContextMessageSecurityProvider.Context context, java.security.cert.X509Certificate signCertificate, java.lang.String organisation)Method in charge of validating a certificate used to sign a PKI message and also check if the certificate is authorized to generate messages.
-
-
-
Field Detail
-
SETTING_PREFIX
public static final java.lang.String SETTING_PREFIX
- See Also:
- Constant Field Values
-
SETTING_TRUSTSTORE_PATH
public static final java.lang.String SETTING_TRUSTSTORE_PATH
Setting indicating the path to the trust JKS key store (required)- See Also:
- Constant Field Values
-
SETTING_TRUSTSTORE_PASSWORD
public static final java.lang.String SETTING_TRUSTSTORE_PASSWORD
Setting indicating the password to the trust JKS key store (required)- See Also:
- Constant Field Values
-
truststoreHelper
protected TruststoreHelper truststoreHelper
-
-
Constructor Detail
-
PKCS11MessageSecurityProvider
public PKCS11MessageSecurityProvider(java.util.Properties config) throws MessageProcessingException- Throws:
MessageProcessingException
-
PKCS11MessageSecurityProvider
public PKCS11MessageSecurityProvider(java.util.Properties config, PKCS11ProviderManager providerManager) throws MessageProcessingException- Throws:
MessageProcessingException
-
-
Method Detail
-
getSigningKey
public java.security.PrivateKey getSigningKey() throws MessageProcessingExceptionFetches the signing key used to create the digital signatures of the XML file.- Specified by:
getSigningKeyin interfaceMessageSecurityProvider- Returns:
- the signing key used.
- Throws:
MessageProcessingException- if key isn't accessible or activated.
-
getSigningKey
public java.security.PrivateKey getSigningKey(ContextMessageSecurityProvider.Context context) throws MessageProcessingException
Fetches the signing key used to create the digital signatures of the XML file.- Specified by:
getSigningKeyin interfaceContextMessageSecurityProvider- Parameters:
context- the related context, null for default context. (Parameter is currently ignored)- Returns:
- the signing key used.
- Throws:
MessageProcessingException- if key isn't accessible or activated.
-
getSigningCertificate
public java.security.cert.X509Certificate getSigningCertificate() throws MessageProcessingExceptionFetches the signing certificate used to create the digital signatures of the XML file.- Specified by:
getSigningCertificatein interfaceMessageSecurityProvider- Returns:
- the signing certificate used.
- Throws:
MessageProcessingException- if certificate isn't accessible.
-
getSigningCertificate
public java.security.cert.X509Certificate getSigningCertificate(ContextMessageSecurityProvider.Context context) throws MessageProcessingException
Fetches the signing certificate used to create the digital signatures of the XML file.- Specified by:
getSigningCertificatein interfaceContextMessageSecurityProvider- Parameters:
context- the related context, null for default context. (Parameter is currently ignored)- Returns:
- the signing certificate used.
- Throws:
MessageProcessingException- if certificate isn't accessible.
-
getDecryptionKey
public java.security.PrivateKey getDecryptionKey(java.lang.String keyId) throws MessageProcessingExceptionFetches a private key given it's unique identifier.- Specified by:
getDecryptionKeyin interfaceMessageSecurityProvider- Parameters:
keyId- unique identifier of the key, if null should a default key be retrieved- Returns:
- the related decryption key.
- Throws:
MessageProcessingException
-
getDecryptionKey
public java.security.PrivateKey getDecryptionKey(ContextMessageSecurityProvider.Context context, java.lang.String keyId) throws MessageProcessingException
Fetches a private key given it's unique identifier.- Specified by:
getDecryptionKeyin interfaceContextMessageSecurityProvider- Parameters:
context- the related context, null for default context. (Parameter is currently ignored)keyId- unique identifier of the key, if null should a default key be retrieved- Returns:
- the related decryption key.
- Throws:
MessageProcessingException
-
getDecryptionCertificate
public java.security.cert.X509Certificate getDecryptionCertificate(java.lang.String keyId) throws MessageProcessingExceptionFetches the decryption certificate of related key id.- Specified by:
getDecryptionCertificatein interfaceMessageSecurityProvider- Parameters:
keyId- unique identifier of the key, if null should a default key certificate be retrieved- Returns:
- the related decryption certificate.
- Throws:
MessageProcessingException- if certificate isn't accessible.
-
getDecryptionCertificate
public java.security.cert.X509Certificate getDecryptionCertificate(ContextMessageSecurityProvider.Context context, java.lang.String keyId) throws MessageProcessingException
Fetches the decryption certificate of related key id.- Specified by:
getDecryptionCertificatein interfaceContextMessageSecurityProvider- Parameters:
context- the related context, null for default context. (Parameter is currently ignored)keyId- unique identifier of the key, if null should a default key certificate be retrieved- Returns:
- the related decryption certificate.
- Throws:
MessageProcessingException- if certificate isn't accessible.
-
getDecryptionCertificateChain
public java.security.cert.X509Certificate[] getDecryptionCertificateChain(java.lang.String keyId) throws MessageProcessingExceptionFetches the decryption certificate chain of related key id can be one or more in size..- Specified by:
getDecryptionCertificateChainin interfaceMessageSecurityProvider- Parameters:
keyId- unique identifier of the key, if null should a default key certificate be retrieved- Returns:
- the related decryption certificate chain
- Throws:
MessageProcessingException- if certificate isn't accessible.
-
getDecryptionCertificateChain
public java.security.cert.X509Certificate[] getDecryptionCertificateChain(ContextMessageSecurityProvider.Context context, java.lang.String keyId) throws MessageProcessingException
Fetches the decryption certificate chain of related key id can be one or more in size.- Specified by:
getDecryptionCertificateChainin interfaceContextMessageSecurityProvider- Parameters:
context- the related context, null for default context. (Parameter is currently ignored)keyId- unique identifier of the key, if null should a default key certificate be retrieved- Returns:
- the related decryption certificate chain
- Throws:
MessageProcessingException- if certificate isn't accessible.
-
getDecryptionKeyIds
public java.util.Set<java.lang.String> getDecryptionKeyIds() throws MessageProcessingExceptionReturns key identifiers of all available decryption keys.- Specified by:
getDecryptionKeyIdsin interfaceMessageSecurityProvider- Returns:
- key identifiers of all available decryption keys.
- Throws:
MessageProcessingException
-
getDecryptionKeyIds
public java.util.Set<java.lang.String> getDecryptionKeyIds(ContextMessageSecurityProvider.Context context) throws MessageProcessingException
Returns key identifiers of all available decryption keys.- Specified by:
getDecryptionKeyIdsin interfaceContextMessageSecurityProvider- Parameters:
context- the related context, null for default context. (Parameter is currently ignored)- Returns:
- key identifiers of all available decryption keys.
- Throws:
MessageProcessingException
-
isValidAndAuthorized
public boolean isValidAndAuthorized(java.security.cert.X509Certificate signCertificate, java.lang.String organisation) throws java.lang.IllegalArgumentException, MessageProcessingExceptionMethod that checks if a sign certificate is in the trust store, the certificate itself have to be imported and not just the CA certificate.The certificate also have to have key usage digital signature
Organisation name is ignored
- Specified by:
isValidAndAuthorizedin interfaceMessageSecurityProvider- Parameters:
signCertificate- the certificate used to sign the message.organisation- the related organisation to the message, null if no organisation lookup should be done.- Returns:
- true if the sign certificate is valid and authorized to sign messages.
- Throws:
java.lang.IllegalArgumentException- if arguments were invalid.MessageProcessingException- if internal error occurred validating the certificate.- See Also:
MessageSecurityProvider.isValidAndAuthorized(java.security.cert.X509Certificate, java.lang.String)
-
isValidAndAuthorized
public boolean isValidAndAuthorized(ContextMessageSecurityProvider.Context context, java.security.cert.X509Certificate signCertificate, java.lang.String organisation) throws java.lang.IllegalArgumentException, MessageProcessingException
Method in charge of validating a certificate used to sign a PKI message and also check if the certificate is authorized to generate messages.- Specified by:
isValidAndAuthorizedin interfaceContextMessageSecurityProvider- Parameters:
context- the related context, null for default context. (Parameter is currently ignored)signCertificate- the certificate used to sign the message.organisation- the related organisation to the message, null if no organisation lookup should be done.- Returns:
- true if the sign certificate is valid and authorized to sign messages.
- Throws:
java.lang.IllegalArgumentException- if arguments were invalid.MessageProcessingException- if internal error occurred validating the certificate.
-
getEncryptionAlgorithmScheme
public EncryptionAlgorithmScheme getEncryptionAlgorithmScheme() throws MessageProcessingException
Method to fetch the EncryptionAlgorithmScheme to use when encrypting messages.- Specified by:
getEncryptionAlgorithmSchemein interfaceMessageSecurityProvider- Returns:
- Configured EncryptionAlgorithmScheme to use.
- Throws:
MessageProcessingException- if internal error determining algorithm scheme to use
-
getEncryptionAlgorithmScheme
public EncryptionAlgorithmScheme getEncryptionAlgorithmScheme(ContextMessageSecurityProvider.Context context) throws MessageProcessingException
Method to fetch the EncryptionAlgorithmScheme to use when encrypting messages.- Specified by:
getEncryptionAlgorithmSchemein interfaceContextMessageSecurityProvider- Parameters:
context- (Parameter is currently ignored)- Returns:
- Configured EncryptionAlgorithmScheme to use.
- Throws:
MessageProcessingException- if internal error determining algorithm scheme to use
-
getSigningAlgorithmScheme
public SigningAlgorithmScheme getSigningAlgorithmScheme() throws MessageProcessingException
Method to fetch the SigningAlgorithmScheme to use when signing messages.- Specified by:
getSigningAlgorithmSchemein interfaceMessageSecurityProvider- Returns:
- Configured SigningAlgorithmScheme to use.
- Throws:
MessageProcessingException- if internal error determining algorithm scheme to use
-
getProvider
public java.lang.String getProvider()
Method to retrieve JCE provider that should be used with keys provided by this provider.- Specified by:
getProviderin interfaceMessageSecurityProvider- Returns:
- name of an JCE Provider that should be installed prior to usage of this MessageSecurityProvider if null should the JRE configured list of security providers be used.
-
getSigningAlgorithmScheme
public SigningAlgorithmScheme getSigningAlgorithmScheme(ContextMessageSecurityProvider.Context context) throws MessageProcessingException
Method to fetch the SigningAlgorithmScheme to use when signing messages.- Specified by:
getSigningAlgorithmSchemein interfaceContextMessageSecurityProvider- Parameters:
context- the related context, null for default context. (Parameter is currently ignored)- Returns:
- Configured SigningAlgorithmScheme to use.
- Throws:
MessageProcessingException- if internal error determining algorithm scheme to use
-
getProvider
public java.lang.String getProvider(ContextMessageSecurityProvider.Context context)
Method to retrieve JCE provider that should be used with keys provided by this provider.- Specified by:
getProviderin interfaceContextMessageSecurityProvider- Returns:
- name of an JCE Provider that should be installed prior to usage of this MessageSecurityProvider if null should the JRE configured list of security providers be used.
-
getPKCS11Keystore
protected java.security.KeyStore getPKCS11Keystore(java.lang.String pkcs11Library, int slot, java.lang.String slotPassword) throws java.io.IOException, java.security.KeyStoreException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateExceptionCreate Sun PKCS#11 keystore with given parameters.- Parameters:
pkcs11Library- PKCS#11 library to use when accessing the tokenslot- PKCS#11 Slot to use when accessing the tokenslotPassword- Password that protects the slot- Returns:
- PKCS#11 keystore instance.
- Throws:
java.io.IOException- If library could not be found or could not be accessible due to invalid passwordjava.security.KeyStoreException- If there were problems creating the keystorejava.security.NoSuchAlgorithmException- If the algorithm used to check the integrity of the keystore cannot be foundjava.security.cert.CertificateException- If any of the certificates in the keystore could not be loaded
-
getPKCS11Provider
@Deprecated public java.lang.String getPKCS11Provider()
Deprecated.
-
-