frankmorgner / vsmartcard

umbrella project for emulation of smart card readers or smart cards
http://frankmorgner.github.io/vsmartcard/
712 stars 200 forks source link

vicc -t=relay MyEID smart card cannot connect #129

Closed iris-yue-wang closed 5 years ago

iris-yue-wang commented 5 years ago

Expected behaviour

Hi, I tried using vicc -t=relay to relay a local MyEID smart card but I couldn't get it working. I installed both vpcd and vicc on the same Ubuntu machine, without relay, I could use opensc-explorer to send APDU commands to the virtual smart card. I would expect it to work the same with vicc -t=relay relaying a local MyEID smart card.

Actual behaviour

However when I ran opensc-explorer with vicc in relay mode, I got the following error:

OpenSC Explorer version 0.17.0
Using reader with a card: Virtual PCD 00 00
Failed to connect to card: Generic reader error

pcsc_scan shows the virtual smart card as a memory card, which is strange to me.

Steps to reproduce

  1. Install vpcd and vicc on Ubuntu
  2. Insert MyEID card into a local smart card reader
  3. Run vicc -t=relay
  4. Run opensc-explorer

Logs

pcsc_scan output of virtual smart card in relay mode:

Reader 0: Virtual PCD 00 00
  Card state: Card inserted, 
  ATR: 35 39 32 34 35 31 35 30 30 30 31 32 39 34 39 32 35 34 36 39 37 37 31 32 31 36 39 37 33 36 38 32 30

ATR: 35 39 32 34 35 31 35 30 30 30 31 32 39 34 39 32 35 34 36 39 37 37 31 32 31 36 39 37 33 36 38 32 30
+ TS = 35 --> UNDEFINED
+ T0 = 39, Y(1): 0011, K: 9 (historical bytes)
  TA(1) = 32 --> Fi=744, Di=2, 372 cycles/ETU
    10752 bits/s at 4 MHz, fMax for Fi = 8 MHz => 21505 bits/s
  TB(1) = 34 --> Programming Param P: 20 Volts, I: 1 milliamperes
+ Historical bytes: 35 31 35 30 30 30 31 32 39 34 39 32 35 34 36 39 37 37 31 32 31 36 39 37 33 36 38 32 30
 ERROR! ATR is too long: 20 extra byte(s). Truncating.
  Category indicator byte: 35 (proprietary format)
Your card is not a microprocessor card. It seems to be memory card.

pcsc_scan output of MyEID card:

Reader 2: Broadcom Corp 5880 [Contacted SmartCard] (0123456789ABCD) 00 00
  Card state: Card inserted, Shared Mode, 
  ATR: 3B F5 96 00 00 81 31 FE 45 4D 79 45 49 44 14

ATR: 3B F5 96 00 00 81 31 FE 45 4D 79 45 49 44 14
+ TS = 3B --> Direct Convention
+ T0 = F5, Y(1): 1111, K: 5 (historical bytes)
  TA(1) = 96 --> Fi=512, Di=32, 16 cycles/ETU
    250000 bits/s at 4 MHz, fMax for Fi = 5 MHz => 312500 bits/s
  TB(1) = 00 --> VPP is not electrically connected
  TC(1) = 00 --> Extra guard time: 0
  TD(1) = 81 --> Y(i+1) = 1000, Protocol T = 1 
-----
  TD(2) = 31 --> Y(i+1) = 0011, Protocol T = 1 
-----
  TA(3) = FE --> IFSC: 254
  TB(3) = 45 --> Block Waiting Integer: 4 - Character Waiting Integer: 5
+ Historical bytes: 4D 79 45 49 44
  Category indicator byte: 4D (proprietary format)
+ TCK = 14 (correct checksum)

Possibly identified card (using /home/zuhlke/.cache/smartcard_list.txt):
3B F5 96 00 00 81 31 FE 45 4D 79 45 49 44 14
3B F5 96 00 00 8. 31 FE 45 4D 79 45 49 44 1.
MyEID card (Infineon chip) (PKI)
https://services.aventra.fi/English/products_MyEID_E.php

Running vicc -t=relay in verbose shows it connected to MyEID smart card:

18.10.2018 15:27:21  [INFO] Connected to card in 'Broadcom Corp 5880 [Contacted SmartCard] (0123456789ABCD) 00 00'
18.10.2018 15:27:21  [INFO] Connected to virtual PCD at localhost:35963

Is there anything I'm missing here? Is there a list of smart cards vicc -t=relay supports?

Thanks!

Iris

frankmorgner commented 5 years ago

Sorry, I don't see what's going wrong. You could add debug code in virtualsmartcard/src/vpicc/virtualsmartcard/cards/Relay.py.

Alternatively you may use http://frankmorgner.github.io/vsmartcard/pcsc-relay/README.html (something like pcsc-relay --connector=pcsc --emulator=vpcd)

iris-yue-wang commented 5 years ago

Thank you very much for your quick reply.

I tried pcsc-relay --connector=pcsc --emulator=vpcd, but I got the following error:

pcsc-relay --connector=pcsc --emulator=vpcd --reader=2
Could not connect to Broadcom Corp 5880 [Contacted SmartCard] (0123456789ABCD) 00 00
Sharing violation.

Without specifying reader number got a different result:

 pcsc-relay --connector=pcsc --emulator=vpcd
Card's ATR: 3B 95 13 81 01 80 73 FF 01 00 0B 
Address already in use
Could not initialize connection to VPCD

opensc-tool --list-readers shows:

# Detected readers (pcsc)
Nr.  Card  Features  Name
0    No              Virtual PCD 00 00
1    No              Virtual PCD 00 01
2    Yes             Broadcom Corp 5880 [Contacted SmartCard] (0123456789ABCD) 00 00

Could you see anything I have missed?

Also what is the expected behaviour on opensc-explorer when relaying a local smart card? Should we be able to send APDU command in the same way as connecting to a real smart card directly?

Btw, is there any Ubuntu version requirement? I'm using Ubunbu 17.10.

Thanks!

Iris

frankmorgner commented 5 years ago

I've added an option to pcsc-relay to set the atr and fixed the atr in vicc