Class OpenPGPSmartCard
- Direct Known Subclasses:
SimulatorOpenPGPSmartCard, YubikeyOpenPGPSmartCard
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturn theauthentication keyof the card.Return theOpenPGPSmartCardBackendthat manages this smart card.abstract StringReturn aStringrepresenting the card type.Return thedecryption keyof the card.getKeyByFingerprint(byte[] fingerprint) Return theOpenPGPHardwareKeyfrom the slot that contains the given fingerprint.getKeyByKeyRef(byte keyRef) Return theOpenPGPHardwareKeyidentified by the given key reference.getKeys()Return a list of allkeyson the card.abstract IntegerReturn the serial number of this smart card.Return thesigning keyof the card.abstract StringReturn the version number of this smart card.booleanReturn true if the card has an authentication key (with keyRefOpenPGPHardwareKey.KEY_REF_AUTHENTICATION).booleanReturn true if the card has a decryption key (with keyRefOpenPGPHardwareKey.KEY_REF_DECRYPTION).booleanhasKey(byte keyRef) Return true, if the card has a key with the given key reference.booleanhasKeyWithFingerprint(byte[] fingerprint) Returns true, if the card has a key with the given fingerprint.booleanReturn true, if the card has a signature key (with keyRefOpenPGPHardwareKey.KEY_REF_SIGNATURE).abstract booleanisKeySupported(byte keyRef, org.bouncycastle.openpgp.api.OpenPGPCertificate.OpenPGPComponentKey key) Return true, if the smart card supports the givenOpenPGPCertificate.OpenPGPComponentKey.protected voidputKey(OpenPGPHardwareKey key) abstract org.bouncycastle.openpgp.PGPPublicKeyreconstructPGPPublicKey(byte keyRef) Return thePGPPublicKeycomponent of the key in the slot identified by keyRef.abstract OpenPGPSmartCardreset()Reset the smart card, clearing all key slots and resetting the admin PIN, user PIN to their defaults.toString()uploadAuthenticationKey(org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey key, char[] adminPin) Upload the givenOpenPGPKey.OpenPGPPrivateKeyto the authentication key slot on the card.uploadDecryptionKey(org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey key, char[] adminPin) Upload the givenOpenPGPKey.OpenPGPPrivateKeyto the decryption key slot on the card.abstract OpenPGPSmartCarduploadKey(byte keyRef, org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey key, char[] adminPin) Upload the givenOpenPGPKey.OpenPGPPrivateKeyto the given keyRef slot on the card.uploadSigningKey(org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey key, char[] adminPin) Upload the givenOpenPGPKey.OpenPGPPrivateKeyto the signing key slot on the card.
-
Field Details
-
keys
-
-
Constructor Details
-
OpenPGPSmartCard
-
-
Method Details
-
getBackend
Return theOpenPGPSmartCardBackendthat manages this smart card.- Returns:
- backend
-
getSerialNumber
Return the serial number of this smart card.- Returns:
- serial number
-
getVersion
Return the version number of this smart card.- Returns:
- version number
-
putKey
-
isKeySupported
public abstract boolean isKeySupported(byte keyRef, org.bouncycastle.openpgp.api.OpenPGPCertificate.OpenPGPComponentKey key) throws CardException Return true, if the smart card supports the givenOpenPGPCertificate.OpenPGPComponentKey.- Parameters:
keyRef- key referencekey- OpenPGP key- Returns:
- true if the card supports the key
- Throws:
CardException- if communication with the card fails
-
getKeyByKeyRef
Return theOpenPGPHardwareKeyidentified by the given key reference. If the card does not contain a key for the given keyRef, this method throws aNoSuchElementException.- Parameters:
keyRef- key reference- Returns:
- hardware key
-
getKeyByFingerprint
Return theOpenPGPHardwareKeyfrom the slot that contains the given fingerprint. If no such key is found, this method throws aNoSuchElementException.Note: The fingerprint field of OpenPGP smart cards is a 20-octet field that can contain arbitrary data. Since the smart card does not make use of this field and does not validate its contents, you MUST NOT rely on this field to identify keys. Notably OpenPGP v6 keys, which have a 32-octet fingerprint, will cause mismatches with the 20-octet field.
- Parameters:
fingerprint- fingerprint- Returns:
- hardware key
-
getKeys
Return a list of allkeyson the card.- Returns:
- list of all keys
-
hasKey
public boolean hasKey(byte keyRef) Return true, if the card has a key with the given key reference.- Parameters:
keyRef- key reference- Returns:
- true if card has a key for keyRef, false otherwise
-
hasKeyWithFingerprint
public boolean hasKeyWithFingerprint(byte[] fingerprint) Returns true, if the card has a key with the given fingerprint.Note: The fingerprint field of OpenPGP smart cards is a 20-octet field that can contain arbitrary data. Since the smart card does not make use of this field and does not validate its contents, you MUST NOT rely on this field to identify keys. Notably OpenPGP v6 keys, which have a 32-octet fingerprint, will cause mismatches with the 20-octet field.
- Parameters:
fingerprint- fingerprint- Returns:
- true if the card has a key with a matching fingerprint field
-
hasSignatureKey
public boolean hasSignatureKey()Return true, if the card has a signature key (with keyRefOpenPGPHardwareKey.KEY_REF_SIGNATURE).- Returns:
- true if card has signature key
-
getSignatureKey
Return thesigning keyof the card.- Returns:
- signing key
- Throws:
NoSuchElementException- if the card has no signing key
-
hasDecryptionKey
public boolean hasDecryptionKey()Return true if the card has a decryption key (with keyRefOpenPGPHardwareKey.KEY_REF_DECRYPTION).- Returns:
- true if card has decryption key
-
getDecryptionKey
Return thedecryption keyof the card.- Returns:
- decryption key
- Throws:
NoSuchElementException- if the card has no decryption key
-
hasAuthenticationKey
public boolean hasAuthenticationKey()Return true if the card has an authentication key (with keyRefOpenPGPHardwareKey.KEY_REF_AUTHENTICATION).- Returns:
- true if card has authentication key
-
getAuthenticationKey
Return theauthentication keyof the card.- Returns:
- authentication key
- Throws:
NoSuchElementException- if the card has no authentication key
-
reset
Reset the smart card, clearing all key slots and resetting the admin PIN, user PIN to their defaults.- Returns:
- this
- Throws:
CardException- if communication with the card failed
-
uploadSigningKey
public OpenPGPSmartCard uploadSigningKey(org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey key, char[] adminPin) throws CardException, org.bouncycastle.openpgp.PGPException Upload the givenOpenPGPKey.OpenPGPPrivateKeyto the signing key slot on the card.- Parameters:
key- OpenPGP private keyadminPin- admin pin of the card- Returns:
- card
- Throws:
CardException- if communication with the card failsorg.bouncycastle.openpgp.PGPException- if the key cannot be prepared for the card
-
uploadDecryptionKey
public OpenPGPSmartCard uploadDecryptionKey(org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey key, char[] adminPin) throws CardException, org.bouncycastle.openpgp.PGPException Upload the givenOpenPGPKey.OpenPGPPrivateKeyto the decryption key slot on the card.- Parameters:
key- OpenPGP private keyadminPin- admin pin of the card- Returns:
- card
- Throws:
CardException- if communication with the card failsorg.bouncycastle.openpgp.PGPException- if the key cannot be prepared for the card
-
uploadAuthenticationKey
public OpenPGPSmartCard uploadAuthenticationKey(org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey key, char[] adminPin) throws CardException, org.bouncycastle.openpgp.PGPException Upload the givenOpenPGPKey.OpenPGPPrivateKeyto the authentication key slot on the card.- Parameters:
key- OpenPGP private keyadminPin- admin pin of the card- Returns:
- card
- Throws:
CardException- if communication with the card failsorg.bouncycastle.openpgp.PGPException- if the key cannot be prepared for the card
-
uploadKey
public abstract OpenPGPSmartCard uploadKey(byte keyRef, org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey key, char[] adminPin) throws CardException, org.bouncycastle.openpgp.PGPException Upload the givenOpenPGPKey.OpenPGPPrivateKeyto the given keyRef slot on the card.- Parameters:
keyRef- keyRefkey- OpenPGP private keyadminPin- admin pin of the card- Returns:
- card
- Throws:
CardException- if communication with the card failsorg.bouncycastle.openpgp.PGPException- if the key cannot be prepared for the card
-
reconstructPGPPublicKey
public abstract org.bouncycastle.openpgp.PGPPublicKey reconstructPGPPublicKey(byte keyRef) throws CardException, org.bouncycastle.openpgp.PGPException Return thePGPPublicKeycomponent of the key in the slot identified by keyRef.Note: The key might be reconstructed on the fly. In this case,
Public key algorithmand version number might be brute-forced by comparing the resultingkeysfingerprint to the contents of the cardsOpenPGPHardwareKey.getFingerprint()field.- Parameters:
keyRef- key reference- Returns:
- PGPPublicKey representation
- Throws:
CardException- if communication with the card failsorg.bouncycastle.openpgp.PGPException- if the key cannot be reconstructed
-
getCardType
-
toString
-