Adding support for this Watchdata token

Mandar Joshi <[email protected]> Thu, 1 Feb 2018 04:59:03 +0530
Newsgroups gmane.comp.encryption.opensc.devel
Message-ID <CAC9_qu3W9iePgmhsjc5NB90KnGNpYTKp33TJjKGV9OWsFs4CRg@mail.gmail.com>
Hello everyone,

There are these tokens from CCID compliant (I think so) Watchdata
available in the Indian market which are not yet supported in OpenSC.
I would like to work on adding support for them in OpenSC.
I read https://github.com/OpenSC/OpenSC/wiki/Adding-a-new-card-driver
and that's where I'll begin.

What I would like to know is whether I'll make significant progress
without any documentation from Watchdata. Will trying to implement the
driver using data from a USB Sniffer really work ?

Which card driver do you suggest I use as skeleton for this new driver?

Here is debug information about the token.

$ opensc-tool -l
Detected readers (pcsc)
Nr. Card Features Name
0 Yes TrustKey [WDIND USB CCID Key] 00 00

$ pkcs11-tool -L
Available slots:
Slot 0 (0xffffffffffffffff): Virtual hotplug slot
(empty)
Slot 1 (0x1): TrustKey [WDIND USB CCID Key] 00 00
(empty)

$ opensc-tool -n
Using reader with a card: TrustKey [WDIND USB CCID Key] 00 00
Unsupported card

--------------------------------------------------------------------------------------------------------
Output of Pykcs11 with proprietary driver:

# PYKCS11LIB=/usr/lib/WatchData/TRUSTKEY/lib/libwdpkcs_TRUSTKEY.so
python getinfo.py -p abcd1234
cryptokiVersion: 2.10
flags:
libraryDescription: PKCS#11 cryptoki module
libraryVersion: 1.0
manufacturerID: WatchData
Available Slots: 3 [1, 2, 3]
Slot n.: 1
 firmwareVersion: 1.00
 flags: CKF_REMOVABLE_DEVICE, CKF_HW_SLOT
 hardwareVersion: 1.00
 manufacturerID: Watchdata Technologies Pte.Ltd
 slotDescription: WatchData IC CARD Reader/Writer 0
 SessionInfo Error: CKR_SLOT_ID_INVALID (0x00000003)
Slot n.: 2
 firmwareVersion: 1.00
 flags: CKF_REMOVABLE_DEVICE, CKF_HW_SLOT
 hardwareVersion: 1.00
 manufacturerID: Watchdata Technologies Pte.Ltd
 slotDescription: WatchData IC CARD Reader/Writer 1
 SessionInfo Error: CKR_SLOT_ID_INVALID (0x00000003)
Slot n.: 3
 firmwareVersion: 1.00
 flags: CKF_REMOVABLE_DEVICE, CKF_HW_SLOT
 hardwareVersion: 1.00
 manufacturerID: Watchdata Technologies Pte.Ltd
 slotDescription: WatchData IC CARD Reader/Writer 2
 SessionInfo Error: CKR_SLOT_ID_INVALID (0x00000003)

--------------------------------------------------------------------------------------------------------
~$ lsusb -d 163c:0418 -v
Bus 003 Device 009: ID 163c:0418
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 (Defined at Interface level)
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor           0x163c
  idProduct          0x0418
  bcdDevice            0.01
  iManufacturer           1
  iProduct                2
  iSerial                 0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength          109
    bNumInterfaces          2
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         8 Mass Storage
      bInterfaceSubClass      6 SCSI
      bInterfaceProtocol     80 Bulk-Only
      iInterface              4
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        1
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass        11 Chip/SmartCard
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              5
      ChipCard Interface Descriptor:
        bLength                54
        bDescriptorType        33
        bcdCCID              1.10  (Warning: Only accurate for version 1.0)
        nMaxSlotIndex           0
        bVoltageSupport         1  5.0V
        dwProtocols             1  T=0
        dwDefaultClock       3580
        dwMaxiumumClock     14320
        bNumClockSupported      0
        dwDataRate           9600 bps
        dwMaxDataRate      115200 bps
        bNumDataRatesSupp.      0
        dwMaxIFSD             254
        dwSyncProtocols  00000000
        dwMechanical     00000000
        dwFeatures       00010030
          Auto clock change
          Auto baud rate change
          TPDU level exchange
        dwMaxCCIDMsgLen       271
        bClassGetResponse      00
        bClassEnvelope         00
        wlcdLayout           none
        bPINSupport             0
        bMaxCCIDBusySlots       1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0

------------------------------------------------------------------------------------------------------------

ccid-1.4.28# cat output.txt
 idVendor: 0x163C
  iManufacturer: Watchdata
 idProduct: 0x0418
  iProduct: USB Key
 bcdDevice: 0.01 (firmware release?)
 bLength: 9
 bDescriptorType: 4
 bInterfaceNumber: 1
 bAlternateSetting: 0
 bNumEndpoints: 2
  bulk-IN and bulk-OUT
 bInterfaceClass: 0x0B [Chip Card Interface Device Class (CCID)]
 bInterfaceSubClass: 0
 bInterfaceProtocol: 0
  bulk transfer, optional interrupt-IN (CCID)
 iInterface: WDIND USB CCID Key
 CCID Class Descriptor
  bLength: 0x36
  bDescriptorType: 0x21
  bcdCCID: 1.10
  bMaxSlotIndex: 0x00
  bVoltageSupport: 0x01
   5.0V
  dwProtocols: 0x0000 0x0001
   T=0
  dwDefaultClock: 3.580 MHz
  dwMaximumClock: 14.320 MHz
  bNumClockSupported: 0 (will use whatever is returned)
   IFD does not support GET CLOCK FREQUENCIES request: Resource
temporarily unavailable
  dwDataRate: 9600 bps
  dwMaxDataRate: 115200 bps
  bNumDataRatesSupported: 0 (will use whatever is returned)
   IFD does not support GET_DATA_RATES request: Resource temporarily unavailable
  dwMaxIFSD: 254
  dwSynchProtocols: 0x00000000
  dwMechanical: 0x00000000
   No special characteristics
  dwFeatures: 0x00010030
   ....10 Automatic ICC clock frequency change according to parameters
   ....20 Automatic baud rate change according to frequency and Fi, Di params
   01.... TPDU level exchange
  dwMaxCCIDMessageLength: 271 bytes
  bClassGetResponse: 0x00
  bClassEnvelope: 0x00
  wLcdLayout: 0x0000
  bPINSupport: 0x00
  bMaxCCIDBusySlots: 1

------------------------------------------------------------------------------------------------------------------

Thanks for reading through.

Regards
Mandar Joshi

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot