forked from gilb/smart_card_TLS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleAPDU.java
More file actions
81 lines (62 loc) · 3.45 KB
/
Copy pathSimpleAPDU.java
File metadata and controls
81 lines (62 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package simpleapdu;
import applets.eapengine;
import cardTools.CardManager;
import cardTools.RunConfig;
import cardTools.Util;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
public class SimpleAPDU {
private static String APPLET_AID = "73696D706C656170706C6574";
private static byte APPLET_AID_BYTE[] = Util.hexStringToByteArray(APPLET_AID);
private static final String STR_APDU_USER_PIN_VERIFY = "A02000000830303030FFFFFFFF";//
private static final String STR_APDU_OPER_PIN_VERIFY = "A0200001083030303030303030";
private static final String STR_APDU_CHANGE_OPER_PIN = "A02400011030303030303030300101000901030100";
private static final String STR_APDU_CHANGE_USER_PIN = "A02400001030303030FFFFFFFF0103010001010009";
private static final String STR_APDU_USER_PIN1_VERIFY = "A0200000080103010001010009";//
private static final String STR_APDU_OPER_PIN1_VERIFY = "A0200001080101000901030100";
private static final String STR_EAP_START = "A08000000601A500060D20";//This is giving default response
/**
* Main entry point.
*
* @param args
*/
public static void main(String[] args) {
try {
SimpleAPDU main = new SimpleAPDU();
main.sign_data_sim();//call this to run applet on simulated card
}catch (Exception ex) {
System.out.println("Exception : " + ex);
}
}
public void sign_data_sim() throws Exception {
final CardManager cardMngr = new CardManager(true, APPLET_AID_BYTE);
final RunConfig runCfg = RunConfig.getDefaultConfig();
//B) If running in the simulator
runCfg.setAppletToSimulate(eapengine.class); // main class of applet to simulate
runCfg.setTestCardType(RunConfig.CARD_TYPE.JCARDSIMLOCAL); // Use local simulator
//physical
//runCfg.setTestCardType(RunConfig.CARD_TYPE.PHYSICAL);
System.out.print("Connecting to card...");
if (!cardMngr.Connect(runCfg)) {
System.out.println(" Failed.");
}
System.out.println(" Done.");
long countTIME=0;
final ResponseAPDU response_UserPIN = cardMngr.transmit(new CommandAPDU(Util.hexStringToByteArray(STR_APDU_USER_PIN_VERIFY)));
System.out.println(response_UserPIN);
final ResponseAPDU response_OPER_PIN = cardMngr.transmit(new CommandAPDU(Util.hexStringToByteArray(STR_APDU_OPER_PIN_VERIFY)));
System.out.println(response_OPER_PIN);
final ResponseAPDU response_CH_USER = cardMngr.transmit(new CommandAPDU(Util.hexStringToByteArray(STR_APDU_CHANGE_USER_PIN)));
System.out.println(response_CH_USER);
final ResponseAPDU response_CH_OPER = cardMngr.transmit(new CommandAPDU(Util.hexStringToByteArray(STR_APDU_CHANGE_OPER_PIN)));
System.out.println(response_CH_OPER);
//TO TEST THE CHANGED PIN
final ResponseAPDU response_UserPIN1 = cardMngr.transmit(new CommandAPDU(Util.hexStringToByteArray(STR_APDU_USER_PIN1_VERIFY)));
System.out.println(response_UserPIN1);
final ResponseAPDU response_OPER_PIN1 = cardMngr.transmit(new CommandAPDU(Util.hexStringToByteArray(STR_APDU_OPER_PIN1_VERIFY)));
System.out.println(response_OPER_PIN1);
// final ResponseAPDU response_EAP_START = cardMngr.transmit(new CommandAPDU(Util.hexStringToByteArray(STR_EAP_START)));
// System.out.println(response_EAP_START);
cardMngr.Disconnect(true);
}
}