Class OpenPGPSmartCardManager
java.lang.Object
org.bouncycastle.openpgp.smartcard.OpenPGPSmartCardManager
- All Implemented Interfaces:
org.bouncycastle.openpgp.api.PublicKeyDataDecryptorFactoryProvider
public class OpenPGPSmartCardManager
extends Object
implements org.bouncycastle.openpgp.api.PublicKeyDataDecryptorFactoryProvider
Manager aggregating one or more
backends.
This class implements PublicKeyDataDecryptorFactoryProvider, so it can be registered with
OpenPGPMessageProcessor.addPublicKeyDataDecryptorFactoryProvider(PublicKeyDataDecryptorFactoryProvider)
to add smart-card message decryption to BC's high-level OpenPGP API. Note that the (stubbed, external)
OpenPGPKey still has to be added as a decryption key.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddBackend(OpenPGPSmartCardBackend<?> backend) Add aOpenPGPSmartCardBackendto the manager.findSmartCard(Integer serialNumber) Return the smart card with the given serial number.List all availablesmart cardsacross all backends.org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactoryprovidePublicKeyDataDecryptorFactory(org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPSecretKey secretKey, org.bouncycastle.openpgp.api.KeyPassphraseProvider passphraseProvider) Ask each registered backend in turn for a decryptor factory, returning the first one produced.
-
Constructor Details
-
OpenPGPSmartCardManager
public OpenPGPSmartCardManager()
-
-
Method Details
-
getBackends
- Returns:
- set of backends
-
addBackend
Add aOpenPGPSmartCardBackendto the manager.- Parameters:
backend- OpenPGP smart card backend- Returns:
- this
-
listSmartCards
List all availablesmart cardsacross all backends.- Returns:
- list of all smart cards
- Throws:
CardException- if communication with some card failsIOException- in case of an IO error
-
findSmartCard
Return the smart card with the given serial number.- Parameters:
serialNumber- device serial number- Returns:
- matching smart card
- Throws:
NoSuchElementException- if no backend reports a card with that serial numberCardException- if communication with a card failsIOException- in case of an IO error
-
providePublicKeyDataDecryptorFactory
public org.bouncycastle.openpgp.operator.PublicKeyDataDecryptorFactory providePublicKeyDataDecryptorFactory(org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPSecretKey secretKey, org.bouncycastle.openpgp.api.KeyPassphraseProvider passphraseProvider) throws org.bouncycastle.openpgp.PGPException Ask each registered backend in turn for a decryptor factory, returning the first one produced. A backend that has no card for this key contributes null and the next backend is tried; a backend that fails outright does not stop the remaining backends from being asked, but its exception is kept and rethrown if no backend can serve the key - so the caller sees the real reason (wrong PIN, card locked, communication failure) rather than a bare "no factory".- Specified by:
providePublicKeyDataDecryptorFactoryin interfaceorg.bouncycastle.openpgp.api.PublicKeyDataDecryptorFactoryProvider- Parameters:
secretKey- secret key the message was encrypted topassphraseProvider- callback supplying the device PIN- Returns:
- a decryptor factory, or null if no backend has a matching card
- Throws:
org.bouncycastle.openpgp.PGPException- if every backend that recognised the key failed to produce a factory
-