FreeCalypso > hg > fc-sim-tools
comparison uicc/pins.c @ 15:b70d35f5476f
fc-uicc-tool ported over
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 07:41:09 +0000 |
parents | |
children | a4ffd4e44b76 |
comparison
equal
deleted
inserted
replaced
14:b7ee2e85686b | 15:b70d35f5476f |
---|---|
1 /* | |
2 * This module implements the standard set of commands for working | |
3 * with UICC PINs; because all of these commands take a user-specified | |
4 * P2 key ID, they should work with ADM PINs as well. | |
5 */ | |
6 | |
7 #include <sys/types.h> | |
8 #include <stdio.h> | |
9 #include "simresp.h" | |
10 | |
11 cmd_verify_pin(argc, argv) | |
12 char **argv; | |
13 { | |
14 u_char cmd[13]; | |
15 int rc; | |
16 | |
17 /* VERIFY PIN command APDU */ | |
18 cmd[0] = 0x00; | |
19 cmd[1] = 0x20; | |
20 cmd[2] = 0x00; | |
21 cmd[3] = strtoul(argv[1], 0, 0); | |
22 cmd[4] = 8; | |
23 rc = encode_pin_entry(argv[2], cmd + 5); | |
24 if (rc < 0) | |
25 return(rc); | |
26 rc = apdu_exchange(cmd, 13); | |
27 if (rc < 0) | |
28 return(rc); | |
29 if (sim_resp_sw != 0x9000) { | |
30 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); | |
31 return(-1); | |
32 } | |
33 return(0); | |
34 } | |
35 | |
36 cmd_verify_hex(argc, argv) | |
37 char **argv; | |
38 { | |
39 u_char cmd[13]; | |
40 int rc; | |
41 | |
42 /* VERIFY PIN command APDU */ | |
43 cmd[0] = 0x00; | |
44 cmd[1] = 0x20; | |
45 cmd[2] = 0x00; | |
46 cmd[3] = strtoul(argv[1], 0, 0); | |
47 cmd[4] = 8; | |
48 rc = decode_hex_data_from_string(argv[2], cmd + 5, 8, 8); | |
49 if (rc < 0) | |
50 return(rc); | |
51 rc = apdu_exchange(cmd, 13); | |
52 if (rc < 0) | |
53 return(rc); | |
54 if (sim_resp_sw != 0x9000) { | |
55 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); | |
56 return(-1); | |
57 } | |
58 return(0); | |
59 } | |
60 | |
61 cmd_change_pin(argc, argv) | |
62 char **argv; | |
63 { | |
64 u_char cmd[21]; | |
65 int rc; | |
66 | |
67 /* CHANGE PIN command APDU */ | |
68 cmd[0] = 0x00; | |
69 cmd[1] = 0x24; | |
70 cmd[2] = 0x00; | |
71 cmd[3] = strtoul(argv[1], 0, 0); | |
72 cmd[4] = 16; | |
73 rc = encode_pin_entry(argv[2], cmd + 5); | |
74 if (rc < 0) | |
75 return(rc); | |
76 rc = encode_pin_entry(argv[3], cmd + 13); | |
77 if (rc < 0) | |
78 return(rc); | |
79 rc = apdu_exchange(cmd, 21); | |
80 if (rc < 0) | |
81 return(rc); | |
82 if (sim_resp_sw != 0x9000) { | |
83 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); | |
84 return(-1); | |
85 } | |
86 return(0); | |
87 } | |
88 | |
89 cmd_disable_pin(argc, argv) | |
90 char **argv; | |
91 { | |
92 u_char cmd[13]; | |
93 int rc; | |
94 | |
95 /* DISABLE PIN command APDU */ | |
96 cmd[0] = 0x00; | |
97 cmd[1] = 0x26; | |
98 cmd[2] = 0x00; | |
99 cmd[3] = strtoul(argv[1], 0, 0); | |
100 cmd[4] = 8; | |
101 rc = encode_pin_entry(argv[2], cmd + 5); | |
102 if (rc < 0) | |
103 return(rc); | |
104 rc = apdu_exchange(cmd, 13); | |
105 if (rc < 0) | |
106 return(rc); | |
107 if (sim_resp_sw != 0x9000) { | |
108 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); | |
109 return(-1); | |
110 } | |
111 return(0); | |
112 } | |
113 | |
114 cmd_enable_pin(argc, argv) | |
115 char **argv; | |
116 { | |
117 u_char cmd[13]; | |
118 int rc; | |
119 | |
120 /* ENABLE PIN command APDU */ | |
121 cmd[0] = 0x00; | |
122 cmd[1] = 0x28; | |
123 cmd[2] = 0x00; | |
124 cmd[3] = strtoul(argv[1], 0, 0); | |
125 cmd[4] = 8; | |
126 rc = encode_pin_entry(argv[2], cmd + 5); | |
127 if (rc < 0) | |
128 return(rc); | |
129 rc = apdu_exchange(cmd, 13); | |
130 if (rc < 0) | |
131 return(rc); | |
132 if (sim_resp_sw != 0x9000) { | |
133 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); | |
134 return(-1); | |
135 } | |
136 return(0); | |
137 } | |
138 | |
139 cmd_unblock_pin(argc, argv) | |
140 char **argv; | |
141 { | |
142 u_char cmd[21]; | |
143 int rc; | |
144 | |
145 /* UNBLOCK PIN command APDU */ | |
146 cmd[0] = 0x00; | |
147 cmd[1] = 0x2C; | |
148 cmd[2] = 0x00; | |
149 cmd[3] = strtoul(argv[1], 0, 0); | |
150 cmd[4] = 16; | |
151 rc = encode_pin_entry(argv[2], cmd + 5); | |
152 if (rc < 0) | |
153 return(rc); | |
154 rc = encode_pin_entry(argv[3], cmd + 13); | |
155 if (rc < 0) | |
156 return(rc); | |
157 rc = apdu_exchange(cmd, 21); | |
158 if (rc < 0) | |
159 return(rc); | |
160 if (sim_resp_sw != 0x9000) { | |
161 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); | |
162 return(-1); | |
163 } | |
164 return(0); | |
165 } | |
166 | |
167 /* retrieving PIN attempt counters from the card */ | |
168 | |
169 cmd_pin_attempt_cnt(argc, argv) | |
170 char **argv; | |
171 { | |
172 u_char cmd[5]; | |
173 int rc; | |
174 | |
175 /* VERIFY PIN command APDU */ | |
176 cmd[0] = 0x00; | |
177 cmd[1] = 0x20; | |
178 cmd[2] = 0x00; | |
179 cmd[3] = strtoul(argv[1], 0, 0); | |
180 cmd[4] = 0; | |
181 rc = apdu_exchange(cmd, 5); | |
182 if (rc < 0) | |
183 return(rc); | |
184 printf("%04X\n", sim_resp_sw); | |
185 return(0); | |
186 } | |
187 | |
188 cmd_puk_attempt_cnt(argc, argv) | |
189 char **argv; | |
190 { | |
191 u_char cmd[5]; | |
192 int rc; | |
193 | |
194 /* UNBLOCK PIN command APDU */ | |
195 cmd[0] = 0x00; | |
196 cmd[1] = 0x2C; | |
197 cmd[2] = 0x00; | |
198 cmd[3] = strtoul(argv[1], 0, 0); | |
199 cmd[4] = 0; | |
200 rc = apdu_exchange(cmd, 5); | |
201 if (rc < 0) | |
202 return(rc); | |
203 printf("%04X\n", sim_resp_sw); | |
204 return(0); | |
205 } |