public class KeyStoreManager extends Object implements KeyAccessor
| Constructor and Description |
|---|
KeyStoreManager(KeyStore keyStore,
KeyStoreManagerCallback callback)
Creates a new KeyStoreManager instance for the given KeyStore.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsAlias(String alias)
Returns true if keystore contains the given alias.
|
X509Certificate |
getCertificate(String alias)
Returns the X509Certificate associated with the given alias.
|
static CertificateEntry[] |
getCertificates(KeyStore keyStore,
String usageIdentifier)
Utility method for internal use.
|
CertificateEntry[] |
getClientAuthenticationCertificateEntries()
Returns the CertificateEntry array containing available client authentication certificates.
|
CertificateEntry[] |
getDocumentSigningCertificateEntries()
Returns the CertificateEntry array containing available signing certificates.
|
KeyStore.Builder |
getKeyStoreBuilder(String alias)
Returns KeyStore.Builder instance for KeyStore containing the given alias.
|
PrivateKey |
getPrivateKey(String alias)
Returns the PrivateKey associated with the given alias.
|
static KeyStore |
loadWindowsTrustStore()
Returns KeyStore containg the native Windows ROOT and CA certificates.
|
static KeyStoreManager |
manageJavaKeyStore(String file,
char[] password,
KeyStoreManagerCallback callback)
Returns an instance of KeyStoreManager providing access to the Java keystore.
|
static KeyStoreManager |
managePKCS12KeyStore(String file,
char[] password,
KeyStoreManagerCallback callback)
Returns an instance of KeyStoreManager providing access to the PKCS12 format (.p12, .pfx) keystore.
|
static KeyStoreManager |
manageWindowsMyKeyStore(KeyStoreManagerCallback callback)
Returns an instance of KeyStoreManager providing access to the native Microsoft Windows MY keystore.
|
static KeyStoreManager |
manageWindowsRootKeyStore(KeyStoreManagerCallback callback)
Returns an instance of KeyStoreManager providing access to the native Microsoft Windows ROOT keystore.
|
String |
selectClientAuthenticationCertificate()
Requests user to select the client authentication certificate
and returns the alias name of the selected item, or null if action is cancelled.
|
String |
selectDocumentSigningCertificate()
Requests user to select the signing certificate
and returns the alias name of the selected item, or null if action is cancelled.
|
byte[] |
signData(byte[] data,
PrivateKey privateKey)
Returns the signature bytes of all the given data.
|
byte[] |
signData(byte[] data,
String alias)
Returns the signature bytes of all the given data.
|
public KeyStoreManager(KeyStore keyStore, KeyStoreManagerCallback callback)
keyStore - an initialized keystore.callback - a callback used to interact with the user while accessing the keystore.public static KeyStoreManager manageWindowsMyKeyStore(KeyStoreManagerCallback callback) throws KeyStoreException
callback - a callback used to interact with the user while accessing the keystore.KeyStoreException - if the native Microsoft Windows MY keystore cannot be accessed.public static KeyStoreManager manageWindowsRootKeyStore(KeyStoreManagerCallback callback) throws KeyStoreException
callback - a callback used to interact with the user while accessing the keystore.KeyStoreException - if the native Microsoft Windows ROOT keystore cannot be accessed.public static KeyStore loadWindowsTrustStore() throws KeyStoreException
KeyStoreException - if the native Microsoft Windows keystore cannot be accessed.public static KeyStoreManager manageJavaKeyStore(String file, char[] password, KeyStoreManagerCallback callback) throws KeyStoreException
file - the file from which the keystore is loaded.password - the password used to unlock the keystore.callback - callback a callback used to interact with the user while accessing the keystore.KeyStoreException - if the keystore cannot be accessed.public static KeyStoreManager managePKCS12KeyStore(String file, char[] password, KeyStoreManagerCallback callback) throws KeyStoreException
file - the file from which the keystore is loaded.password - the password used to unlock the keystore.callback - callback a callback used to interact with the user while accessing the keystore.KeyStoreException - if the keystore cannot be accessed.public boolean containsAlias(String alias) throws KeyStoreException
KeyAccessorcontainsAlias in interface KeyAccessoralias - the alias name.KeyStoreException - if keystore cannot be accessed.public X509Certificate getCertificate(String alias) throws KeyStoreException
KeyAccessor
An alias of the certificate can be obtained from the CertificateEntry object
returned by either KeyAccessor.getDocumentSigningCertificateEntries()
or KeyAccessor.getClientAuthenticationCertificateEntries() method.
getCertificate in interface KeyAccessoralias - the alias name.KeyStoreException - if certificate data cannot be accessed.public PrivateKey getPrivateKey(String alias) throws KeyStoreException
KeyAccessor
An alias of the key can be obtained from the CertificateEntry object
returned by either KeyAccessor.getDocumentSigningCertificateEntries()
or KeyAccessor.getClientAuthenticationCertificateEntries() method.
getPrivateKey in interface KeyAccessoralias - the alias name.KeyStoreException - if key data cannot be accessed.public CertificateEntry[] getDocumentSigningCertificateEntries() throws KeyStoreException
KeyAccessorDocument signing certificates are resolved by the Extended Key Usage extension, containing the "Document signing" object identifier (OID 1.3.6.1.4.1.311.10.3.12).
getDocumentSigningCertificateEntries in interface KeyAccessorKeyStoreException - if certificate data cannot be retrieved.public CertificateEntry[] getClientAuthenticationCertificateEntries() throws KeyStoreException
KeyAccessorClient authentication certificates are resolved by the Extended Key Usage extension, containing the "Client Authentication" object identifier (OID 1.3.6.1.5.5.7.3.2).
getClientAuthenticationCertificateEntries in interface KeyAccessorKeyStoreException - if certificate data cannot be retrieved.public String selectDocumentSigningCertificate() throws KeyStoreException
KeyAccessorselectDocumentSigningCertificate in interface KeyAccessorKeyStoreException - if keystore cannot be accessed.public String selectClientAuthenticationCertificate() throws KeyStoreException
KeyAccessorselectClientAuthenticationCertificate in interface KeyAccessorKeyStoreException - if keystore cannot be accessed.public byte[] signData(byte[] data,
String alias)
throws KeyStoreException,
SignatureException
KeyAccessorsignData in interface KeyAccessordata - the byte array to use for the signature calculation.alias - the alias name representing a private key of the identity whose signature is going to be generated.
An alias of the key can be obtained from the CertificateEntry object
returned by either KeyAccessor.getDocumentSigningCertificateEntries()
or KeyAccessor.getClientAuthenticationCertificateEntries() method.
KeyStoreException - if key data cannot be accessed.SignatureException - if the given data cannot be signed.public byte[] signData(byte[] data,
PrivateKey privateKey)
throws SignatureException
data - the byte array to use for the signature calculation.privateKey - the private key of the identity whose signature is going to be generated.
The private can be obtained using the KeyAccessor.getPrivateKey(String) method.
SignatureException - if the given data cannot be signed.public KeyStore.Builder getKeyStoreBuilder(String alias) throws KeyStoreException
KeyAccessorgetKeyStoreBuilder in interface KeyAccessoralias - the alias name.KeyStoreException - if KeyStore cannot be accessed.public static CertificateEntry[] getCertificates(KeyStore keyStore, String usageIdentifier) throws KeyStoreException
keyStore - keystore.usageIdentifier - certificate usage identifier.KeyStoreException - if certificate data cannot be retrieved.