Class Ccid

java.lang.Object
com.aurelienpierre.sioul.Ccid

final class Ccid extends Object
A smart card's messages over USB (CCID, the USB Integrated Circuit(s) Cards Interface Device class, revision 1.1, ยง6), for your security key plugged into the phone (SecurityKeyLink.java). Pure Java over a Ccid.Pipe, the key's two bulk endpoints, so that android/jvm-checks runs it against a stand-in reader.
  • Messages: PC_to_RDR_IccPowerOn (0x62) answered by the card's ATR, PC_to_RDR_XfrBlock (0x6F) carrying one APDU, PC_to_RDR_IccPowerOff (0x63); each with a sequence number its answer must repeat, slot 0.
  • Sent in packets of the endpoint's size, with a zero-length packet when a message fills its last packet exactly, so that the key knows it ended.
  • A key waiting for a touch says so with a time extension (status 0x80), or stays silent: Sioul reads again, as long as WAIT_MS at most (a YubiKey waits 15 seconds for a touch), while the band asks for the touch, so that no touch setting breaks the operation; a key unplugged meanwhile fails at once. Any other failure is said as a code, never bytes.
  • Nothing kept: each message's buffer is wiped once sent or read.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) static final class 
    The key's answer that said nothing sensible, or a failure of its own: a code, never its bytes.
    (package private) static interface 
    The key's two bulk endpoints.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final byte
     
    (package private) static final int
    A message's header.
    (package private) static final int
    The longest answer read: an extended APDU's, with room.
    private final int
     
    private final Ccid.Pipe
     
    (package private) static final byte
     
    (package private) static final byte
     
    private byte
     
    (package private) static final byte
     
    (package private) static final int
    One bulk transfer at most.
    (package private) static final int
    How long a key may keep Sioul waiting for an answer, a touch included: a YubiKey gives up waiting for one after 15 seconds; ten more as a margin.
    (package private) static final byte
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Ccid(Ccid.Pipe pipe, int packet)
    Messages over pipe, whose endpoints take packet bytes a packet.
  • Method Summary

    Modifier and Type
    Method
    Description
    private byte[]
    exchange(byte type, byte[] data, byte expected)
     
    (package private) static byte[]
    message(byte type, byte[] data, byte sequence)
    The header and the data of one message to the key.
    (package private) void
    The key powered off, its state with it.
    (package private) byte[]
    The key powered on: its ATR.
    private byte[]
    receive(long until)
    One whole message from the key, its header first.
    private void
    send(byte[] message)
     
    (package private) byte[]
    transmit(byte[] apdu)
    One APDU to the key: its answer, status words included.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait