Class OpenPGPSmartCardBackend<T extends OpenPGPSmartCard>
java.lang.Object
org.bouncycastle.openpgp.smartcard.OpenPGPSmartCardBackend<T>
- Direct Known Subclasses:
SimulatorSmartCardBackend, YubikeySmartCardBackend
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intNumber of leading octets of a v6 fingerprint carried by a shortened legacy-hardware identifier.protected static final intSize of the fingerprint field of an OpenPGP smart card. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindSmartCard(Integer serialNumber) booleanfingerprintMatches(byte[] storedFingerprint, byte[] fullFingerprint) Return true if the full fingerprint matches the stored fingerprint.abstract StringgetName()Return the name of the backend.Return aListof allsmart cardsmanaged by this backend.org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactoryprovidePublicKeyDataDecryptorFactory(org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPSecretKey secretKey, org.bouncycastle.openpgp.api.KeyPassphraseProvider userPinProvider) Provide aPublicKeyDataDecryptorFactoryfor the givenOpenPGPKey.OpenPGPSecretKeywhich has its private key material stored on aOpenPGPSmartCardmanaged by this backend.abstract org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactoryprovidePublicKeyDataDecryptorFactory(org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPSecretKey secretKey, T card, org.bouncycastle.openpgp.api.KeyPassphraseProvider userPinProvider) protected booleanshortenedIdentifierForLegacyHardwareMatches(byte[] storedFingerprint, byte[] fullFingerprint) Compare the full OpenPGP key fingerprint to the 20-octets fingerprint field of a smart card according to the method described in the draft "Shortened OpenPGP identifiers for legacy hardware devices".byte[]toStoredFingerprint(byte[] fullFingerprint, int version) Convert the keys full fingerprint into a potentially shortened, 20-octets fingerprint.byte[]toStoredFingerprint(org.bouncycastle.openpgp.api.OpenPGPCertificate.OpenPGPComponentKey key) Convert the keys full fingerprint into a potentially shortened, 20-octets fingerprint.byte[]toStoredFingerprint(org.bouncycastle.openpgp.PGPPublicKey key) Convert the keys full fingerprint into a potentially shortened, 20-octets fingerprint.
-
Field Details
-
STORED_FINGERPRINT_LENGTH
protected static final int STORED_FINGERPRINT_LENGTHSize of the fingerprint field of an OpenPGP smart card.- See Also:
-
SHORTENED_IDENTIFIER_LENGTH
protected static final int SHORTENED_IDENTIFIER_LENGTHNumber of leading octets of a v6 fingerprint carried by a shortened legacy-hardware identifier.- See Also:
-
-
Constructor Details
-
OpenPGPSmartCardBackend
public OpenPGPSmartCardBackend()
-
-
Method Details
-
getName
-
listSmartCards
Return aListof allsmart cardsmanaged by this backend.- Returns:
- list of smart cards
- Throws:
CardException- if communication with a smart card failsIOException- if an IO error occurs while communicating with a card
-
providePublicKeyDataDecryptorFactory
public org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory providePublicKeyDataDecryptorFactory(org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPSecretKey secretKey, org.bouncycastle.openpgp.api.KeyPassphraseProvider userPinProvider) throws org.bouncycastle.openpgp.PGPException Provide aPublicKeyDataDecryptorFactoryfor the givenOpenPGPKey.OpenPGPSecretKeywhich has its private key material stored on aOpenPGPSmartCardmanaged by this backend.- Parameters:
secretKey- OpenPGP secret keyuserPinProvider- callback to provide the keys user pin- Returns:
- public key data decryptor factory using the decryption key, or null if no matching key or card is available.
- Throws:
org.bouncycastle.openpgp.PGPException- if the key is not usable or if communication with the card fails
-
providePublicKeyDataDecryptorFactory
public abstract org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory providePublicKeyDataDecryptorFactory(org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPSecretKey secretKey, T card, org.bouncycastle.openpgp.api.KeyPassphraseProvider userPinProvider) throws org.bouncycastle.openpgp.PGPException - Throws:
org.bouncycastle.openpgp.PGPException
-
fingerprintMatches
public boolean fingerprintMatches(byte[] storedFingerprint, byte[] fullFingerprint) Return true if the full fingerprint matches the stored fingerprint.Note: The stored fingerprint (
OpenPGPHardwareKey.getFingerprint()) is a 20-octet field. OpenPGP v6 keys have a 32-octet fingerprint, so they will not match exactly and therefore need to be compared in a standardized way. This method has not yet been decided upon, see the links below.- Parameters:
storedFingerprint- 20 octet fingerprint from the cards fingerprint field.fullFingerprint- full fingerprint of the key (v4 keys have 20, v6 keys 32 octets)- Returns:
- true if fingerprints match, false otherwise
- See Also:
-
shortenedIdentifierForLegacyHardwareMatches
protected boolean shortenedIdentifierForLegacyHardwareMatches(byte[] storedFingerprint, byte[] fullFingerprint) Compare the full OpenPGP key fingerprint to the 20-octets fingerprint field of a smart card according to the method described in the draft "Shortened OpenPGP identifiers for legacy hardware devices".- Parameters:
storedFingerprint- 20 octets stored fingerprint from smart cardfullFingerprint- calculated, full OpenPGP key fingerprint- Returns:
- true if the fingerprint matches according to the comparison method described in
- See Also:
-
toStoredFingerprint
public byte[] toStoredFingerprint(org.bouncycastle.openpgp.api.OpenPGPCertificate.OpenPGPComponentKey key) Convert the keys full fingerprint into a potentially shortened, 20-octets fingerprint. If the keys fingerprint is already 20 octets long, return it as is. Otherwise, shorten it according to the method described in the draft linked below.- Parameters:
key- OpenPGP key- Returns:
- 20 octets fingerprint
- See Also:
-
toStoredFingerprint
public byte[] toStoredFingerprint(org.bouncycastle.openpgp.PGPPublicKey key) Convert the keys full fingerprint into a potentially shortened, 20-octets fingerprint. If the keys fingerprint is already 20 octets long, return it as is. Otherwise, shorten it according to the method described in the draft linked below.- Parameters:
key- OpenPGP key- Returns:
- 20 octets fingerprint
- See Also:
-
toStoredFingerprint
public byte[] toStoredFingerprint(byte[] fullFingerprint, int version) Convert the keys full fingerprint into a potentially shortened, 20-octets fingerprint. If the keys fingerprint is already 20 octets long, return it as is. Otherwise, shorten it according to the method described in the draft linked below.- Parameters:
fullFingerprint- full key fingerprintversion- key version- Returns:
- 20 octets fingerprint
- See Also:
-
findSmartCard
- Throws:
CardExceptionIOException
-