annotate simtool/chvext.c @ 46:32d6186668cf

simtool code: chvext.c split from chv.c
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 13 Feb 2021 00:01:38 +0000
parents simtool/chv.c@e9e8ce12f5a5
children ae3342497fea
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 }