FreeCalypso > hg > fc-sim-tools
annotate simtool/chvfunc.c @ 31:cca7d0528f89
fc-simtool sws-auth-adm1 implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 17 Mar 2021 00:42:47 +0000 |
parents | |
children | c83ec3bd9d67 |
rev | line source |
---|---|
31
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements a functional interface to CHV commands, |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * intended for high-level wrappers like sws-*. |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "simresp.h" |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 verify_chv_func(p2, pin) |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 unsigned p2; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 char *pin; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 { |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 u_char cmd[13]; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int rc; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 /* VERIFY CHV command APDU */ |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 cmd[0] = 0xA0; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 cmd[1] = 0x20; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 cmd[2] = 0x00; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 cmd[3] = p2; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 cmd[4] = 8; |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 rc = encode_pin_entry(pin, cmd + 5); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (rc < 0) |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 return(rc); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 rc = apdu_exchange(cmd, 13); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (rc < 0) |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(rc); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 if (sim_resp_sw != 0x9000) { |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 fprintf(stderr, "bad SW response to VERIFY CHV: %04X\n", |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 sim_resp_sw); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return(-1); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 return(0); |
cca7d0528f89
fc-simtool sws-auth-adm1 implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |