licel / jcardsim

https://jcardsim.org
221 stars 124 forks source link

Using the jcardsim in CLI mode #58

Open LeoCardus opened 9 years ago

LeoCardus commented 9 years ago

Hi, First I would like to thank you and your team for this great work. I am using this solution in CLI mode in connection with virtual smart card reader to be able to test the applet before I actually put in on real card.

I have follow the instructions as explains and everything is working fine using the example you have reference HelloWorldApplet.

I am using the Eclipse JavaCard plugin to develop the Applet, as result of this it is generates Applet Class (name ID.class), I try to load the applets as follow:

  1. copy the ID.class to the same folder of the jcardsim.
  2. update the jcardsim.cfg as follow: com.licel.jcardsim.card.applet.0.AID=D2760000604104 com.licel.jcardsim.card.applet.0.Class=ID
  3. run the following command from the command line: java -cp jcardsim-2.2.1-all.jar com.licel.jcardsim.utils.APDUScriptTool jcardsim.cfg test.apdu out.apdu Then I get an error: Unable to execute test.apdu due to: null I believe there is a problem to load my ID.class, can you please support me with this. Best Regards. AS
LeoCardus commented 9 years ago

Hi, I just try to extract the jcardsim-2.2.1-all.jar to a location in my desktop and I try to reference HelloWorldApplet in direct way not as part of package as follow:

  1. in the jcardsim.cfg >>> com.licel.jcardsim.card.applet.0.Class=HelloWorldApplet
  2. the command will be (all in one line): java -cp /root/Desktop/JavaCardSim/javasim/com/licel/jcardsim/samples; /root/Desktop/JavaCardSim/jcardsim-2.2.1-all.jar com.licel.jcardsim.utils.APDUScriptTool jcardsim.cfg helloworld.apdu

it gives me an error, /root/Desktop/JavaCardSim/jcardsim-2.2.1-all.jar: Permission denied

I am running on Linux, what I have to do to correct reference the applet class.

Best Regards, AS

licel commented 9 years ago

Hi!

You need to add a classpath with your ID.class to java classpath. For example, if your class is located in the current directory:

win

java -cp jcardsim-2.2.1-all.jar;. com.licel.jcardsim.utils.APDUScriptTool jcardsim.cfg test.apdu out.apdu

in linux you have to use ':' as separator instead of ';'.

LeoCardus commented 9 years ago

Hi, It is works, thank you very much for your support. here is the summary of what I had to do to make it work as expected:-

  1. Export the whole package including all reffernces to custom_pakage.jar
  2. Copy the package to the same folder of the jcardsim
  3. Edit the jcardsim.cfg: com.licel.jcardsim.card.applet.0.Class=custom_pakage.target_class
  4. start the jcardsim form the command line as follow: Linux: java -cp jcardsim-2.2.1-all.jar:packtangen.jar com.licel.jcardsim.utils.APDUScriptTool jcardsim.cfg helloworld.apdu Please note: there is no space between the jcardsim-2.2.1-all.jar:packtangen.jar

Windows: java -cp jcardsim-2.2.1-all.jar;packtangen.jar com.licel.jcardsim.utils.APDUScriptTool jcardsim.cfg helloworld.apdu Please note: there is no space between jcardsim-2.2.1-all.jar;packtangen.jar

There is however an issue with the following command: 0x00 0xCA 0x00 0x56 0x02 which I pass through hellowarld.apdu it should be give me back 00 00 90 00 Apdu Script: 0x80 0xB8 0x00 0x00 0x09 0x07 0xD2 0x76 0x00 0x00 0x60 0x41 0x04 0x00 0x7F; powerdown; powerup; 0x00 0xA4 0x04 0x00 0x07 0xD2 0x76 0x00 0x00 0x60 0x41 0x04 0x00; 0x00 0x20 0x00 0x02 0x03 0x22 0x22 0x22 0x00; 0x00 0xDA 0x00 0x50 0x04 0x12 0x34 0x56 0x78 0x00; 0x00 0xDA 0x00 0x55 0x08 0x12 0x34 0x12 0x34 0x12 0x34 0x12 0x34 0x00; 0x00 0xDA 0x00 0x54 0x08 0xAA 0xBB 0xCC 0xDD 0xEE 0xFF 0xAA 0xBB 0x00; 0x00 0xDA 0x00 0x56 0x02 0x00 0x00 0x00; 0x00 0xDA 0x00 0x51 0x02 0x12 0x34 0x00; 0x00 0xCA 0x00 0x56 0x02;

output is CLA: 80, INS: b8, P1: 00, P2: 00, Lc: 09, 07, d2, 76, 00, 00, 60, 41, 04, 00, Le: 07, d2, 76, 00, 00, 60, 41, 04, SW1: 90, SW2: 00 CLA: 00, INS: a4, P1: 04, P2: 00, Lc: 07, d2, 76, 00, 00, 60, 41, 04, Le: 00, SW1: 90, SW2: 00 CLA: 00, INS: 20, P1: 00, P2: 02, Lc: 03, 22, 22, 22, Le: 00, SW1: 90, SW2: 00 CLA: 00, INS: da, P1: 00, P2: 50, Lc: 04, 12, 34, 56, 78, Le: 00, SW1: 90, SW2: 00 CLA: 00, INS: da, P1: 00, P2: 55, Lc: 08, 12, 34, 12, 34, 12, 34, 12, 34, Le: 00, SW1: 90, SW2: 00 CLA: 00, INS: da, P1: 00, P2: 54, Lc: 08, aa, bb, cc, dd, ee, ff, aa, bb, Le: 00, SW1: 90, SW2: 00 CLA: 00, INS: da, P1: 00, P2: 56, Lc: 02, 00, 00, Le: 00, SW1: 90, SW2: 00 CLA: 00, INS: da, P1: 00, P2: 51, Lc: 02, 12, 34, Le: 00, SW1: 90, SW2: 00

so the command doesn't show at all and doesn't show any response! Any idea why?

Also how I can force T=0 or T=1 protocol in the CLI mode or jcardsim.cfg? Last question: how I can change the ATR value to custom ATR in CLI mode.

Regards, AS

licel commented 9 years ago

so the command doesn't show at all and doesn't show any response! Any idea why?

Do you mean that your applet returns data while selecting? Support of this function is implemented in trunk. Checkout git trunk and run mvn clean install.

Last question: how I can change the ATR value to custom ATR in CLI mode.

You can use com.licel.jcardsim.card.ATR property

LeoCardus commented 9 years ago

Hi, I am running the jcardsim with Virtual Smart Card Reader in windows 7. I have a strange issue, when I am trying to connect to the Card using Java Program which use apdu jar, there is no problem at all, and everything is working well. But when I am using other script program which use wincard dll, during the connection I get an error "Failed SCardConnect 8010000F".

any idea why?

Best Regards, AS

LeoCardus commented 9 years ago

Hi, I found the problem, which is the ATR value. I change the ATR to a value from a card I know as follow: Orginal ATR: 3B FA 18 00 00 81 31 FE 45 4A 43 4F 50 33 31 56 32 33 32 98 TS : 3B Direct logic TO : FA K = 10 byte [historical characters] TA1 : 18 Fi/f = 372/ 5 [clock rate conversion factor / max. frequency (MHz)] Di = 12 [bit rate conversion factor] TB1 : 00 pa = 4 % [programming voltage accurancy] I = 25 mA [maximum current] P = 0 V [programming voltage] TC1 : 00 N = 0 etu [extra guardtime] TD1 : 81 T = T=1 [protocol type] TD2 : 31 T = T=1 [protocol type] TA3 : FE IFSC = 254 [information field size] TB3 : 45 CWT = 43 etu [character waiting time] BWT = 15371 etu [block waiting time] 4A434F50333156323332

New ATR: 3B 16 96 41 73 74 72 69 64 TS : 3B Direct logic TO : 16 K = 6 byte [historical characters] TA1 : 96 Fi/f = 512/ 5 [clock rate conversion factor / max. frequency (MHz)] Di = 32 [bit rate conversion factor] 417374726964

now it is working... Thanks, AS