public abstract class CardAccessor extends Object implements KeyAccessor
getInstance(CardAccessorCallback) method.
As of the version 1.3.3, this class was adjusted to implement the KeyAccessor interface.
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsAlias(String alias)
Returns true if keystore contains the given alias.
|
CardAccessorCallback |
getCardAccessorCallback()
Returns the current CardAccessorCallback object.
|
X509Certificate |
getCertificate(String alias)
Returns the X509Certificate associated with the given alias.
|
CertificateEntry[] |
getClientAuthenticationCertificateEntries()
Returns the CertificateEntry array containing available client authentication certificates.
|
CertificateEntry[] |
getDocumentSigningCertificateEntries()
Returns the CertificateEntry array containing available signing certificates.
|
static CardAccessor |
getInstance(CardAccessorCallback cardAccessorCallback)
Creates a CardAccessor object using the given CardAccessorCallback handler.
|
KeyStore.Builder |
getKeyStoreBuilder()
Returns KeyStore builder instance for KeyStore representing the smart card's content.
|
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.
|
abstract void |
refreshKeyStore()
Attempts to reload the smart card's content.
|
void |
reset()
Resets any resources used by this CardAccessor.
|
String |
selectClientAuthenticationCertificate()
Requests user to select the client authentication certificate retrieved from the smart card
and returns the alias name of the selected item, or null if action is cancelled.
|
String |
selectDocumentSigningCertificate()
Requests user to select the signing certificate retrieved from the smart card
and returns the alias name of the selected item, or null if action is cancelled.
|
void |
setCardAccessorCallback(CardAccessorCallback cardAccessorCallback)
Sets the current CardAccessorCallback object.
|
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 static CardAccessor getInstance(CardAccessorCallback cardAccessorCallback)
In some cases CardAccessor must communicate with the user to obtain PIN code
or get some other input, therefore to create a CardAccessor, you must specify
an instance of CardAccessorCallback object which implements the required callback methods.
cardAccessorCallback - callback object used to retrieve smart card's information.public CertificateEntry[] getDocumentSigningCertificateEntries() throws KeyStoreException
Document 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
Client 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 boolean containsAlias(String alias) throws KeyStoreException
containsAlias in interface KeyAccessoralias - the alias name.KeyStoreException - if smartcard cannot be accessed.public X509Certificate getCertificate(String alias) throws KeyStoreException
An alias of the certificate can be obtained from the CertificateEntry object
returned by either getDocumentSigningCertificateEntries()
or getClientAuthenticationCertificateEntries() method.
getCertificate in interface KeyAccessoralias - the alias name.KeyStoreException - if smart card cannot be accessed.public PrivateKey getPrivateKey(String alias) throws KeyStoreException
An alias of the key can be obtained from the CertificateEntry object
returned by either getDocumentSigningCertificateEntries()
or getClientAuthenticationCertificateEntries() method.
getPrivateKey in interface KeyAccessoralias - the alias name.KeyStoreException - if smart card cannot be accessed.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 getPrivateKey(String) method.
SignatureException - if the given data cannot be signed.public byte[] signData(byte[] data,
String alias)
throws KeyStoreException,
SignatureException
signData 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 getDocumentSigningCertificateEntries()
or getClientAuthenticationCertificateEntries() method.
KeyStoreException - if smart card cannot be accessed.SignatureException - if the given data cannot be signed.public KeyStore.Builder getKeyStoreBuilder() throws KeyStoreException
KeyStoreException - if smart card cannot be accessed.public KeyStore.Builder getKeyStoreBuilder(String alias) throws KeyStoreException
getKeyStoreBuilder in interface KeyAccessoralias - the alias name.KeyStoreException - if KeyStore cannot be accessed.public void reset()
public abstract void refreshKeyStore()
throws KeyStoreException
KeyStoreException - if KeyStore cannot be accessed.public String selectDocumentSigningCertificate() throws KeyStoreException
selectDocumentSigningCertificate in interface KeyAccessorKeyStoreException - if smart card cannot be accessed.public String selectClientAuthenticationCertificate() throws KeyStoreException
selectClientAuthenticationCertificate in interface KeyAccessorKeyStoreException - if smart card cannot be accessed.public CardAccessorCallback getCardAccessorCallback()
public void setCardAccessorCallback(CardAccessorCallback cardAccessorCallback)
cardAccessorCallback - callback object used to retrieve smart card's information.