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 Details

    • OpenPGPSmartCardManager

      public OpenPGPSmartCardManager()
  • Method Details

    • getBackends

      public Set<OpenPGPSmartCardBackend<?>> getBackends()
      Return a Set of all registered backends.
      Returns:
      set of backends
    • addBackend

      public OpenPGPSmartCardManager addBackend(OpenPGPSmartCardBackend<?> backend)
      Add a OpenPGPSmartCardBackend to the manager.
      Parameters:
      backend - OpenPGP smart card backend
      Returns:
      this
    • listSmartCards

      public List<OpenPGPSmartCard> listSmartCards() throws CardException, IOException
      List all available smart cards across all backends.
      Returns:
      list of all smart cards
      Throws:
      CardException - if communication with some card fails
      IOException - in case of an IO error
    • findSmartCard

      public OpenPGPSmartCard findSmartCard(Integer serialNumber) throws CardException, IOException
      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 number
      CardException - if communication with a card fails
      IOException - 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:
      providePublicKeyDataDecryptorFactory in interface org.bouncycastle.openpgp.api.PublicKeyDataDecryptorFactoryProvider
      Parameters:
      secretKey - secret key the message was encrypted to
      passphraseProvider - 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