Class SmartCardProtocol

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

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

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

  • Constructor Summary

    Constructors 
    Constructor Description
    SmartCardProtocol​(SmartCardConnection connection)
    Create new instance of SmartCardProtocol and selects the application for use
    SmartCardProtocol​(SmartCardConnection connection, byte insSendRemaining)  
  • Method Summary

    Modifier and Type Method Description
    void close()  
    void enableWorkarounds​(Version firmwareVersion)
    Enable all relevant workarounds given the firmware version of the YubiKey.
    SmartCardConnection getConnection()  
    byte[] select​(byte[] aid)
    Sends an APDU to SELECT an Application.
    byte[] sendAndReceive​(Apdu command)
    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
    void setApduFormat​(ApduFormat apduFormat)
    YubiKey NEO doesn't support extended APDU's for most applications.
    void setEnableTouchWorkaround​(boolean enableTouchWorkaround)
    YubiKey 4.2.0 - 4.2.6 have an issue with the touch timeout being too short in certain cases.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • close

      public void close() throws java.io.IOException
      Specified by:
      close in interface java.lang.AutoCloseable
      Specified by:
      close in interface java.io.Closeable
      Throws:
      java.io.IOException
    • enableWorkarounds

      public void enableWorkarounds​(Version firmwareVersion)
      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

      public void setEnableTouchWorkaround​(boolean enableTouchWorkaround)
      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

      public void setApduFormat​(ApduFormat apduFormat)
      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 java.io.IOException, ApplicationNotAvailableException
      Sends an APDU to SELECT an Application.
      Parameters:
      aid - the AID to select.
      Returns:
      the response data from selecting the Application
      Throws:
      java.io.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 java.io.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:
      java.io.IOException - in case of connection and communication error
      ApduException - in case if received error in APDU response