Class YubikeyOpenPGPSmartCard

java.lang.Object
org.bouncycastle.openpgp.smartcard.OpenPGPSmartCard
org.bouncycastle.openpgp.smartcard.yubikey.YubikeyOpenPGPSmartCard

public class YubikeyOpenPGPSmartCard extends OpenPGPSmartCard
  • Constructor Details

  • Method Details

    • openSession

      public com.yubico.yubikit.openpgp.OpenPgpSession openSession() throws IOException, com.yubico.yubikit.core.smartcard.ApduException, CardException
      Throws:
      IOException
      com.yubico.yubikit.core.smartcard.ApduException
      CardException
    • 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) throws CardException
      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
      Throws:
      CardException - if communication with the card fails
    • getSupportedAlgorithms

      public SupportedAlgorithms getSupportedAlgorithms(byte keyRef)
      Return all supported key algorithms of the slot identified by keyRef.

      NOTE: yubikit's AlgorithmAttributes.Rsa / .Ec subclasses and their getAlgorithmId() / getNLen() / getCurve() accessors are all package-private in com.yubico.yubikit.openpgp, so the only way to read the attributes from outside that package is to parse the toString() rendering. That rendering is not API and may change in any yubikit release, so every field here is optional: an attribute that cannot be parsed is skipped rather than allowed to throw, which degrades isKeySupported(byte, OpenPGPCertificate.OpenPGPComponentKey) to "not supported" instead of failing the whole card. Replace this with the typed accessors if yubikit ever publishes them.

      Parameters:
      keyRef - key reference
      Returns:
      SupportedAlgorithms
    • reset

      public YubikeyOpenPGPSmartCard reset() throws CardException
      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
      Throws:
      CardException - if communication with the card failed
    • getBackend

      public YubikeySmartCardBackend getBackend()
      Description copied from class: OpenPGPSmartCard
      Return the OpenPGPSmartCardBackend that manages this smart card.
      Overrides:
      getBackend in class OpenPGPSmartCard
      Returns:
      backend
    • uploadKey

      public YubikeyOpenPGPSmartCard uploadKey(byte keyRefByte, org.bouncycastle.openpgp.api.OpenPGPKey.OpenPGPPrivateKey key, char[] adminPin) throws CardException, org.bouncycastle.openpgp.PGPException
      Description copied from class: OpenPGPSmartCard
      Upload the given OpenPGPKey.OpenPGPPrivateKey to the given keyRef slot on the card.
      Specified by:
      uploadKey in class OpenPGPSmartCard
      Parameters:
      keyRefByte - keyRef
      key - OpenPGP private key
      adminPin - admin pin of the card
      Returns:
      card
      Throws:
      CardException - if communication with the card fails
      org.bouncycastle.openpgp.PGPException - if the key cannot be prepared for the card
    • uploadKey

      public YubikeyOpenPGPSmartCard uploadKey(byte keyRefByte, org.bouncycastle.openpgp.PGPKeyPair keyPair, char[] adminPin) throws CardException, org.bouncycastle.openpgp.PGPException
      Throws:
      CardException
      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
    • convertPublicKey

      public com.yubico.yubikit.core.keys.PublicKeyValues convertPublicKey(org.bouncycastle.openpgp.PGPPublicKey pgpPublicKey) throws org.bouncycastle.openpgp.PGPException
      Throws:
      org.bouncycastle.openpgp.PGPException
    • reconstructPGPPublicKey

      public org.bouncycastle.openpgp.PGPPublicKey reconstructPGPPublicKey(byte keyRefByte) throws CardException, org.bouncycastle.openpgp.PGPException
      Description copied from class: OpenPGPSmartCard
      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.

      Specified by:
      reconstructPGPPublicKey in class OpenPGPSmartCard
      Parameters:
      keyRefByte - key reference
      Returns:
      PGPPublicKey representation
      Throws:
      CardException - if communication with the card fails
      org.bouncycastle.openpgp.PGPException - if the key cannot be reconstructed