Class SimulatorOpenPGPSmartCard

java.lang.Object
org.bouncycastle.openpgp.smartcard.OpenPGPSmartCard
org.bouncycastle.openpgp.smartcard.simulator.SimulatorOpenPGPSmartCard

public class SimulatorOpenPGPSmartCard extends OpenPGPSmartCard
In-memory stand-in for an OpenPGP smart card, backed by ordinary software keys.

Test and development use only. Unlike a real card this offers no isolation whatsoever: the uploaded secret keys are held in the heap of the calling process and getSoftwareKey(OpenPGPCertificate.OpenPGPComponentKey, KeyPassphraseProvider) hands the private key straight back. It exists so that the smart-card API can be exercised without hardware; never use it as a substitute for a token in production.

  • Constructor Details

  • Method Details

    • createSimulatedCardFrom

      public static SimulatorOpenPGPSmartCard createSimulatedCardFrom(SimulatorSmartCardBackend backend, org.bouncycastle.openpgp.api.OpenPGPKey softwareKey) throws org.bouncycastle.openpgp.PGPException
      Throws:
      org.bouncycastle.openpgp.PGPException
    • createSimulatedCardFrom

      public static SimulatorOpenPGPSmartCard createSimulatedCardFrom(SimulatorSmartCardBackend backend, Integer serialNumber, org.bouncycastle.openpgp.api.OpenPGPKey softwareKey) throws org.bouncycastle.openpgp.PGPException
      Throws:
      org.bouncycastle.openpgp.PGPException
    • getSerialNumber

      public Integer getSerialNumber()
      Description copied from class: OpenPGPSmartCard
      Return the serial number of this smart card.
      Specified by:
      getSerialNumber in class OpenPGPSmartCard
      Returns:
      serial number
    • getVersion

      public String getVersion()
      Description copied from class: OpenPGPSmartCard
      Return the version number of this smart card.
      Specified by:
      getVersion in class OpenPGPSmartCard
      Returns:
      version number
    • isKeySupported

      public boolean isKeySupported(byte keyRef, org.bouncycastle.openpgp.api.OpenPGPCertificate.OpenPGPComponentKey key)
      Description copied from class: OpenPGPSmartCard
      Return true, if the smart card supports the given OpenPGPCertificate.OpenPGPComponentKey.
      Specified by:
      isKeySupported in class OpenPGPSmartCard
      Parameters:
      keyRef - key reference
      key - OpenPGP key
      Returns:
      true if the card supports the key
    • reset

      public SimulatorOpenPGPSmartCard reset()
      Description copied from class: OpenPGPSmartCard
      Reset the smart card, clearing all key slots and resetting the admin PIN, user PIN to their defaults.
      Specified by:
      reset in class OpenPGPSmartCard
      Returns:
      this
    • uploadKey

      public SimulatorOpenPGPSmartCard uploadKey(byte keyRef, org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey key, char[] adminPin)
      Upload the given OpenPGPKey.OpenPGPPrivateKey to the given keyRef slot on the card.

      The simulator enforces no admin PIN, so adminPin is ignored.

      Specified by:
      uploadKey in class OpenPGPSmartCard
      Parameters:
      keyRef - keyRef
      key - OpenPGP private key
      adminPin - admin pin of the card
      Returns:
      card
    • reconstructPGPPublicKey

      public org.bouncycastle.openpgp.PGPPublicKey reconstructPGPPublicKey(byte keyRef)
      Return the PGPPublicKey component of the key in the slot identified by keyRef.

      Note: The key might be reconstructed on the fly. In this case, Public key algorithm and version number might be brute-forced by comparing the resulting keys fingerprint to the contents of the cards OpenPGPHardwareKey.getFingerprint() field.

      Returns null if the given slot is empty, matching the hardware implementations.

      Specified by:
      reconstructPGPPublicKey in class OpenPGPSmartCard
      Parameters:
      keyRef - key reference
      Returns:
      PGPPublicKey representation
    • getSoftwareKey

      public org.bouncycastle.openpgp.PGPPrivateKey getSoftwareKey(org.bouncycastle.openpgp.api.OpenPGPCertificate.OpenPGPComponentKey key, org.bouncycastle.openpgp.api.KeyPassphraseProvider passphraseProvider) throws org.bouncycastle.openpgp.PGPException
      Throws:
      org.bouncycastle.openpgp.PGPException
    • getCardType

      public String getCardType()
      Description copied from class: OpenPGPSmartCard
      Return a String representing the card type. This is an informative description of the device.
      Specified by:
      getCardType in class OpenPGPSmartCard
      Returns:
      card type