annotate simtool/chvext.c @ 229:ed8cb3c0d312 default tip

new README, indicating repository move
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 18:26:13 +0000
parents ae3342497fea
children
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 /*
46
32d6186668cf simtool code: chvext.c split from chv.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
2 * This module implements some commands for extended (non-standard)
32d6186668cf simtool code: chvext.c split from chv.c
Mychaela Falconia <falcon@freecalypso.org>
parents: 3
diff changeset
3 * CHV-like operations which some cards use for ADM access control.
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
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 #include <sys/types.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include "simresp.h"
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 cmd_verify_ext(argc, argv)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 u_char cmd[13];
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 /* VERIFY CHV command APDU */
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 cmd[0] = 0xA0;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 cmd[1] = 0x20;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 cmd[2] = 0x00;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 cmd[3] = strtoul(argv[1], 0, 0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 cmd[4] = 8;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 rc = encode_pin_entry(argv[2], cmd + 5);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 rc = apdu_exchange(cmd, 13);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (sim_resp_sw != 0x9000) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return(0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
47
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
34
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
35 cmd_verify_hex(argc, argv)
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
36 char **argv;
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
37 {
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
38 u_char cmd[13];
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
39 int rc;
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
40
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
41 /* VERIFY CHV command APDU */
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
42 cmd[0] = 0xA0;
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
43 cmd[1] = 0x20;
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
44 cmd[2] = 0x00;
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
45 cmd[3] = strtoul(argv[1], 0, 0);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
46 cmd[4] = 8;
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
47 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
48 if (rc < 0)
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
49 return(rc);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
50 rc = apdu_exchange(cmd, 13);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
51 if (rc < 0)
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
52 return(rc);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
53 if (sim_resp_sw != 0x9000) {
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
54 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
55 return(-1);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
56 }
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
57 return(0);
ae3342497fea fc-simtool verify-hex command added
Mychaela Falconia <falcon@freecalypso.org>
parents: 46
diff changeset
58 }