frankmorgner / vsmartcard

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

Running vpicc On Windows #27

Closed panqjhust closed 9 years ago

panqjhust commented 9 years ago

In my hostmachine(win7 32bit), BixVReader has been installed. Then python2.7, pyscard-1.6.12.win32-py2.7.msi,PIL-1.1.7.win32-py2.7.exe, are installed too.When i want to make a virtualsmartcard, the result is ImportError: No module named readline

After i install pyreadline, ImportError readline disappear. But ImportError cipher is coming. After python setup.py build , according to url https://pypi.python.org/pypi/pycrypto/2.6.1

Then copy C:\Users\Administrator\MyProject\pycrypto-2.6.1\build\lib.win32-2.7\Crypto to C:\Python27\Lib\site-packages\Crypto, importError cipher is disappearing. But SwError is coming

D:\kp\sc\vsmartcard-master\virtualsmartcard>python.exe src/vpicc/vicc.in Traceback (most recent call last): File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\VirtualSmartcard.py", line 337, in execute sw, result = self.ins2handler.get(c.ins, notImplemented)(c.p1, c.p2, c.data) File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\SmartcardFilesystem.py", line 683, in selectFile file = self._selectFile(p1, p2, data) File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\SmartcardFilesystem.py", line 661, in _selectFile REF["REFERENCE_CONTROL_SELECT"], index_current) File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\SmartcardFilesystem.py", line 481, in select raise SwError(SW["ERR_FILENOTFOUND"]) SwError

But through private card reader, can connect to , and send atr, the answer is 3B 95 13 81 01 80 73 FF 01 00 0B.

If use this start command, python.exe src/vpicc/vicc.in --type=cryptoflex, SwError disappear.

Any help would be appreciated. Thank you.

frankmorgner commented 9 years ago

Readline is a Python module that you need to install

Am 12. Oktober 2014 03:00:21 MESZ, schrieb panqjhust notifications@github.com:

In my hostmachine(win7 32bit), BixVReader has been installed. Then python2.7, pyscard-1.6.12.win32-py2.7.msi,PIL-1.1.7.win32-py2.7.exe, are installed too.When i want to make a virtualsmartcard, the result is following:

D:\kp\sc\vsmartcard-master\virtualsmartcard>python.exe src/vpicc/vicc.in --hostname=192.169.1.109 --port=35963 --reader=0 Traceback (most recent call last): File "src/vpicc/vicc.in", line 104, in from virtualsmartcard.VirtualSmartcard import VirtualICC File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\VirtualSmartcard.py", line 24, in from virtualsmartcard.CardGenerator import CardGenerator File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\CardGenerator.py", line 20, in import sys, getpass, anydbm, readline, logging ImportError: No module named readline

Any help would be appreciated. Thank you.


Reply to this email directly or view it on GitHub: https://github.com/frankmorgner/vsmartcard/issues/27

Frank Morgner

panqjhust commented 9 years ago

when i input 00 A4 00 00 02 3F 00, the answer is 00 00 FF FF 3F 00 38 00 00 00 00 01 05 00 01 00 00 00 9000. It looks like, that there is a EF in card. But 3F00 should be MF, cannot be seen. My question is, how to select MF with 7816 command?

frankmorgner commented 9 years ago

Which card are you using? If I use the default card type (iso7816) I get the following output::

17.10.2014 18:39:57  [WARNING] Using default SAM parameters. PIN=1234, Card Nr=1234567890
17.10.2014 18:39:57  [INFO] Connected to virtual PCD at localhost:35963
17.10.2014 18:39:57  [INFO] Parsed APDU:
C_APDU(CLA=0x00, INS=0xA4, P1=0x00, P2=0x00, Lc=0x02) with 2 (0x02) bytes of data:
0000:  3f 00                                             ?.              
17.10.2014 18:39:57  [INFO] Response APDU (14 Bytes):
0000:  6f 0a 83 02 3f 00 8a 01 05 82 01 38 61 0c         o...?......8a.

On Friday, October 17 at 08:33AM, panqjhust wrote:

when i input 00 A4 00 00 02 3F 00, the answer is 00 00 FF FF 3F 00 38 00 00 00 00 01 05 00 01 00 00 00 9000. It looks like, that there is a EF in card. But 3F00 should be MF, cannot be seen. My question is, how to select MF with 7816 command?


Reply to this email directly or view it on GitHub:

https://github.com/frankmorgner/vsmartcard/issues/27#issuecomment-59530745

Frank Morgner

Virtual Smart Card Architecture http://vsmartcard.sourceforge.net OpenPACE http://openpace.sourceforge.net IFD Handler for libnfc Devices http://sourceforge.net/projects/ifdnfc

panqjhust commented 9 years ago

It seems that when card reset, the select cmd isnot same as your SAM default. I just start this card, does it need a card reader before the below python?

D:\kp\sc\vsmartcard-master\virtualsmartcard>python.exe src/vpicc/vicc.in -v -v -v -v 18.10.2014 21:55:57 [WARNING] Using default SAM parameters. PIN=1234, Card Nr=1234567890 18.10.2014 21:55:57 [INFO] Connected to virtual PCD at localhost:35963 18.10.2014 21:55:57 [INFO] Reset 18.10.2014 21:55:57 [INFO] Reset 18.10.2014 21:55:57 [INFO] Reset 18.10.2014 21:55:57 [INFO] Parsed APDU: C_APDU(CLA=0x00, INS=0xA4, P1=0x04, P2=0x00, Lc=0x09) with 9 (0x09) bytes of data: 0000: a0 00 00 03 97 42 54 46 59 .....BTFY 18.10.2014 21:55:57 [DEBUG] file (dfname='\xa0\x00\x00\x03\x97BTFY') not found in: {MF at 0x20da8f0}: _filedescriptor 0x38 _secondSFT length 1: 0000: 01 . extra_fci_data length 0:

_fid 0x3f00 _content _lifecycle 0x5 _data length 0:

_firstSFT length 1: 0000: ff . 18.10.2014 21:55:57 [INFO] Checking error (Wrong parameters P1-P2): File or application not found

frankmorgner commented 9 years ago

First of all, the cryptoflex emulation is still incomplete as stated on the website. Some bits may be missing or not 100% accurate.

Secondly, the select you want should look like this 'C0 A4 00 00 02 3F 00' according to the cryptoflex programmers guide. However, our emulator ignores the different class byte.

Third, a cryptoflex does not respond with FCI or FCP templates as defined in ISO 7816-4. Instead, it returns the file properties in its own formatting (see Cryptoflex PG, 177pp). And these file properties are returned when you select the MF. Do you see a specific problem with the returned buffer?

On Saturday, October 18 at 06:28AM, panqjhust wrote:

choices=['iso7816', 'cryptoflex', 'ePass', 'nPA', 'relay', 'handler_test'], I use " python.exe src/vpicc/vicc.in --type=cryptoflex ", to start a card simulating.


Reply to this email directly or view it on GitHub:

https://github.com/frankmorgner/vsmartcard/issues/27#issuecomment-59612939

Frank Morgner

Virtual Smart Card Architecture http://vsmartcard.sourceforge.net OpenPACE http://openpace.sourceforge.net IFD Handler for libnfc Devices http://sourceforge.net/projects/ifdnfc

panqjhust commented 9 years ago

At my last question, the simulation is not cryptoflex, but iso7816. I'm sorry that i'm not familar with cryptoflex. Recently, You refer to several old questions, and maybe answer the question two days ago. Please look at new recovers. My question now becomes, from the difference below:(all can be find at this web page, use Goolge Chrome )

your select cmd: 17.10.2014 18:39:57 [INFO] Parsed APDU: C_APDU(CLA=0x00, INS=0xA4, P1=0x00, P2=0x00, Lc=0x02) with 2 (0x02) bytes of data: 0000: 3f 00

my select cmd: 18.10.2014 21:55:57 [INFO] Parsed APDU: C_APDU(CLA=0x00, INS=0xA4, P1=0x04, P2=0x00, Lc=0x09) with 9 (0x09) bytes of data: 0000: a0 00 00 03 97 42 54 46 59 .....BTFY

frankmorgner commented 9 years ago

I am confused this time you are not selecting MF (3f00) but an application by DF name... There is no such application under this application identifier by default.

Please be clear:

  1. What is the exact error you get?
  2. What would the expected output be?
  3. What configuration are you using?
  4. How can I reproduce the error?

On Sunday, October 19 at 04:11AM, panqjhust wrote:

This time, my simulation is not cryptoflex, but iso7816. You reference my old question, please look at new recovers.

My question now becomes, from the difference below

your select cmd: 17.10.2014 18:39:57 [INFO] Parsed APDU: C_APDU(CLA=0x00, INS=0xA4, P1=0x00, P2=0x00, Lc=0x02) with 2 (0x02) bytes of data: 0000: 3f 00

my select cmd: 18.10.2014 21:55:57 [INFO] Parsed APDU: C_APDU(CLA=0x00, INS=0xA4, P1=0x04, P2=0x00, Lc=0x09) with 9 (0x09) bytes of data: 0000: a0 00 00 03 97 42 54 46 59 .....BTFY


Reply to this email directly or view it on GitHub:

https://github.com/frankmorgner/vsmartcard/issues/27#issuecomment-59646469

Frank Morgner

Virtual Smart Card Architecture http://vsmartcard.sourceforge.net OpenPACE http://openpace.sourceforge.net IFD Handler for libnfc Devices http://sourceforge.net/projects/ifdnfc

panqjhust commented 9 years ago

This is my configuration. python.exe src/vpicc/vicc.in -v -v -v -v

You can see that this simulation is SAM, so it would be iso7816 state. In your simulte, the output is selecting 3f00, but mine is select 9 byte. This is not expected.

And from your log,default simulating: 17.10.2014 18:39:57 [INFO] Connected to virtual PCD at localhost:35963 17.10.2014 18:39:57 [INFO] Parsed APDU: There is no 3 reset, this also different from mine. Whether it is due to different vpcd driver on windows or other platforms.

Although first time select is not same as your, but second time, with connecting to a reader, the result of select is same. 6F 0A 83 02 3F 00 8A 01 05 82 01 38 610C.

I want to find the reason why card start from simulationg, select different.

The log including error is listed below: D:\kp\sc\vsmartcard-master\virtualsmartcard>python.exe src/vpicc/vicc.in -v -v -v -v 19.10.2014 21:05:34 [WARNING] Using default SAM parameters. PIN=1234, Card Nr=1234567890 19.10.2014 21:05:34 [INFO] Connected to virtual PCD at localhost:35963 19.10.2014 21:05:34 [INFO] Reset 19.10.2014 21:05:34 [INFO] Reset 19.10.2014 21:05:34 [INFO] Reset 19.10.2014 21:05:34 [INFO] Parsed APDU: C_APDU(CLA=0x00, INS=0xA4, P1=0x04, P2=0x00, Lc=0x09) with 9 (0x09) bytes of data: 0000: a0 00 00 03 97 42 54 46 59 .....BTFY 19.10.2014 21:05:34 [DEBUG] file (dfname='\xa0\x00\x00\x03\x97BTFY') not found in: {MF at 0x220f890}: _filedescriptor 0x38 _secondSFT length 1: 0000: 01 . extra_fci_data length 0:

_fid 0x3f00 _content _lifecycle 0x5 _data length 0:

_firstSFT length 1: 0000: ff . 19.10.2014 21:05:34 [INFO] Checking error (Wrong parameters P1-P2): File or application not found Traceback (most recent call last): File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\VirtualSmartcard.py", line 337, in execute sw, result = self.ins2handler.get(c.ins, notImplemented)(c.p1, c.p2, c.data) File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\SmartcardFilesystem.py", line 683, in selectFile file = self._selectFile(p1, p2, data) File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\SmartcardFilesystem.py", line 661, in _selectFile REF["REFERENCE_CONTROL_SELECT"], index_current) File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\SmartcardFilesystem.py", line 481, in select raise SwError(SW["ERR_FILENOTFOUND"]) SwError 19.10.2014 21:05:34 [INFO] Response APDU (2 Bytes): 0000: 6a 82 j.

frankmorgner commented 9 years ago

This behavior is expected. There is no such df by default. If you need it, you should first create it either with a CREATE FILE APDU or directly n the python code.

Am 19. Oktober 2014 15:06:21 MESZ, schrieb panqjhust notifications@github.com:

This is my configuration. python.exe src/vpicc/vicc.in -v -v -v -v

You can see that the simulation is SAM, so it is iso7816 state. In your simulte, the output is selecting 3f00, but mine is select 9 byte. This is not expected.

Although first time select is not same as your, but second time it is the same.

The log including error is listed below: D:\kp\sc\vsmartcard-master\virtualsmartcard>python.exe src/vpicc/vicc.in -v -v -v -v 19.10.2014 21:05:34 [WARNING] Using default SAM parameters. PIN=1234, Card Nr=1234567890 19.10.2014 21:05:34 [INFO] Connected to virtual PCD at localhost:35963 19.10.2014 21:05:34 [INFO] Reset 19.10.2014 21:05:34 [INFO] Reset 19.10.2014 21:05:34 [INFO] Reset 19.10.2014 21:05:34 [INFO] Parsed APDU: C_APDU(CLA=0x00, INS=0xA4, P1=0x04, P2=0x00, Lc=0x09) with 9 (0x09) bytes of data: 0000: a0 00 00 03 97 42 54 46 59 .....BTFY 19.10.2014 21:05:34 [DEBUG] file (dfname='\xa0\x00\x00\x03\x97BTFY') not found in: {MF at 0x220f890}: _filedescriptor 0x38 _secondSFT length 1: 0000: 01 . extra_fci_data length 0:

_fid 0x3f00 _content _lifecycle 0x5 _data length 0:

_firstSFT length 1: 0000: ff . 19.10.2014 21:05:34 [INFO] Checking error (Wrong parameters P1-P2): File or application not found Traceback (most recent call last): File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\VirtualSmartcard.py", line 337, in execute sw, result = self.ins2handler.get(c.ins, notImplemented)(c.p1, c.p2, c.data) File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\SmartcardFilesystem.py", line 683, in selectFile file = self._selectFile(p1, p2, data) File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\SmartcardFilesystem.py", line 661, in _selectFile REF["REFERENCE_CONTROL_SELECT"], index_current) File "D:\kp\sc\vsmartcard-master\virtualsmartcard\src\vpicc\virtualsmartcard\SmartcardFilesystem.py", line 481, in select raise SwError(SW["ERR_FILENOTFOUND"]) SwError 19.10.2014 21:05:34 [INFO] Response APDU (2 Bytes): 0000: 6a 82 j.


Reply to this email directly or view it on GitHub: https://github.com/frankmorgner/vsmartcard/issues/27#issuecomment-59649229

Frank Morgner

panqjhust commented 9 years ago

But how to explain the three reset at start? when i expose the transmit, the log show that card has always receive command 04, which menas VPCD_CTRL_ATR.

card starting log is below:

19.10.2014 22:42:27 [INFO] from cardGenerator, card_type is iso7816. 19.10.2014 22:42:27 [INFO] Connected to virtual PCD at localhost:35963 19.10.2014 22:42:27 [INFO] __recvFromVPICC msg:

19.10.2014 22:42:27 [INFO] 04 19.10.2014 22:42:27 [INFO] __sendToVPICC msg:

19.10.2014 22:42:27 [INFO] 3b 19.10.2014 22:42:27 [INFO] 95 19.10.2014 22:42:27 [INFO] 13 19.10.2014 22:42:27 [INFO] 81 19.10.2014 22:42:27 [INFO] 01 19.10.2014 22:42:27 [INFO] 80 19.10.2014 22:42:27 [INFO] 73 19.10.2014 22:42:27 [INFO] ff 19.10.2014 22:42:27 [INFO] 01 19.10.2014 22:42:27 [INFO] 00 19.10.2014 22:42:27 [INFO] 0b 19.10.2014 22:42:27 [INFO] __recvFromVPICC msg:

19.10.2014 22:42:27 [INFO] 04 19.10.2014 22:42:27 [INFO] __sendToVPICC msg:

19.10.2014 22:42:27 [INFO] 3b 19.10.2014 22:42:27 [INFO] 95 19.10.2014 22:42:27 [INFO] 13 19.10.2014 22:42:27 [INFO] 81 19.10.2014 22:42:27 [INFO] 01 19.10.2014 22:42:27 [INFO] 80 19.10.2014 22:42:27 [INFO] 73 19.10.2014 22:42:27 [INFO] ff 19.10.2014 22:42:27 [INFO] 01 19.10.2014 22:42:27 [INFO] 00 19.10.2014 22:42:27 [INFO] 0b 19.10.2014 22:42:27 [INFO] __recvFromVPICC msg:

19.10.2014 22:42:27 [INFO] 02 19.10.2014 22:42:27 [INFO] Reset 19.10.2014 22:42:27 [INFO] __recvFromVPICC msg:

19.10.2014 22:42:27 [INFO] 04 19.10.2014 22:42:27 [INFO] __sendToVPICC msg:

frankmorgner commented 9 years ago

The reset command is propably sent by your smart card application or maybe by some Windows background task.

vpcd uses the get atr command to check if the card is still present. So it's OK that this happens multiple times without even transceiving any data