annotate uicc/pins.c @ 118:5d45cde6e4b2

fc-uicc-tool: verify-pin command family implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 19 Feb 2021 23:23:13 +0000
parents simtool/chvext.c@ae3342497fea
children 0ac0aee0df11
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
118
5d45cde6e4b2 fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
2 * This module implements the standard set of commands for working
5d45cde6e4b2 fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
3 * with UICC PINs; because all of these commands take a user-specified
5d45cde6e4b2 fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
4 * P2 key ID, they should work with ADM PINs as well.
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/types.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "simresp.h"
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
118
5d45cde6e4b2 fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
11 cmd_verify_pin(argc, argv)
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 u_char cmd[13];
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
118
5d45cde6e4b2 fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
17 /* VERIFY PIN command APDU */
5d45cde6e4b2 fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
18 cmd[0] = 0x00;
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 cmd[1] = 0x20;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 cmd[2] = 0x00;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 cmd[3] = strtoul(argv[1], 0, 0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 cmd[4] = 8;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 rc = encode_pin_entry(argv[2], cmd + 5);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 rc = apdu_exchange(cmd, 13);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (sim_resp_sw != 0x9000) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 return(0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
47
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
35
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
36 cmd_verify_hex(argc, argv)
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
37 char **argv;
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
38 {
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
39 u_char cmd[13];
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
40 int rc;
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
41
118
5d45cde6e4b2 fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
42 /* VERIFY PIN command APDU */
5d45cde6e4b2 fc-uicc-tool: verify-pin command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 47
diff changeset
43 cmd[0] = 0x00;
47
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
44 cmd[1] = 0x20;
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
45 cmd[2] = 0x00;
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
46 cmd[3] = strtoul(argv[1], 0, 0);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
47 cmd[4] = 8;
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
48 rc = decode_hex_data_from_string(argv[2], cmd + 5, 8, 8);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
49 if (rc < 0)
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
50 return(rc);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
51 rc = apdu_exchange(cmd, 13);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
52 if (rc < 0)
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
53 return(rc);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
54 if (sim_resp_sw != 0x9000) {
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
55 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
56 return(-1);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
57 }
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
58 return(0);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
59 }