Class SmartCardProtocol

java.lang.Object
com.yubico.yubikit.core.smartcard.SmartCardProtocol
All Implemented Interfaces:
Closeable, AutoCloseable

public class SmartCardProtocol extends Object implements Closeable
Support class for communication over a SmartCardConnection.

This class handles APDU encoding and chaining, and implements workarounds for known issues.

  • Constructor Details

    • SmartCardProtocol

      public SmartCardProtocol(SmartCardConnection connection)
      Create new instance of SmartCardProtocol and selects the application for use
      Parameters:
      connection - connection to the YubiKey
    • SmartCardProtocol

      public SmartCardProtocol(SmartCardConnection connection, byte insSendRemaining)
  • Method Details

    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • configure

      public void configure(Version firmwareVersion) throws IOException
      Enable all relevant settings and workarounds given the firmware version of the YubiKey.
      Parameters:
      firmwareVersion - the firmware version to use to configure relevant settings
      Throws:
      IOException
    • enableWorkarounds

      @Deprecated public void enableWorkarounds(Version firmwareVersion)
      Deprecated.
      use configure(Version) instead.
      Enable all relevant workarounds given the firmware version of the YubiKey.
      Parameters:
      firmwareVersion - the firmware version to use for detection to enable the workarounds
    • setEnableTouchWorkaround

      @Deprecated public void setEnableTouchWorkaround(boolean enableTouchWorkaround)
      Deprecated.
      use configure(Version) instead.
      YubiKey 4.2.0 - 4.2.6 have an issue with the touch timeout being too short in certain cases. Enable this workaround on such devices to trigger sending a dummy command which mitigates the issue.
      Parameters:
      enableTouchWorkaround - true to enable the workaround, false to disable it
    • setApduFormat

      @Deprecated public void setApduFormat(ApduFormat apduFormat)
      Deprecated.
      use configure(Version) instead.
      YubiKey NEO doesn't support extended APDU's for most applications.
      Parameters:
      apduFormat - the APDU encoding to use when sending commands
    • getConnection

      public SmartCardConnection getConnection()
      Returns:
      the underlying connection
    • select

      public byte[] select(byte[] aid) throws IOException, ApplicationNotAvailableException
      Sends an APDU to SELECT an Application.
      Parameters:
      aid - the AID to select.
      Returns:
      the response data from selecting the Application
      Throws:
      IOException - in case of connection or communication error
      ApplicationNotAvailableException - in case the AID doesn't match an available application
    • sendAndReceive

      public byte[] sendAndReceive(Apdu command) throws IOException, ApduException
      Sends APDU command and receives byte array from connection In case if output has status code that it has remaining info sends another APDU command to receive what's remaining
      Parameters:
      command - well structured command that needs to be send
      Returns:
      data blob concatenated from all APDU commands that were sent *set of output commands and send remaining commands)
      Throws:
      IOException - in case of connection and communication error
      ApduException - in case if received error in APDU response
    • initScp

      @Nullable public DataEncryptor initScp(ScpKeyParams keyParams) throws IOException, ApduException, BadResponseException
      Throws:
      IOException
      ApduException
      BadResponseException