]>
Commit | Line | Data |
---|---|---|
5acd09bd | 1 | //----------------------------------------------------------------------------- |
2 | // Copyright (C) 2012 Frederik Möllers | |
3 | // | |
4 | // This code is licensed to you under the terms of the GNU GPL, version 2 or, | |
5 | // at your option, any later version. See the LICENSE.txt file for the text of | |
6 | // the license. | |
7 | //----------------------------------------------------------------------------- | |
8 | // Commands related to the German electronic Identification Card | |
9 | //----------------------------------------------------------------------------- | |
10 | ||
11 | #include "util.h" | |
12 | #include "proxusb.h" | |
902cb3c0 | 13 | #include "proxmark3.h" |
5acd09bd | 14 | #include "ui.h" |
15 | #include "cmdparser.h" | |
16 | #include "common.h" | |
17 | #include "cmdmain.h" | |
d0b14ad5 | 18 | #include "sleep.h" |
5acd09bd | 19 | |
20 | #include "cmdhfepa.h" | |
21 | ||
22 | static int CmdHelp(const char *Cmd); | |
23 | ||
24 | // Perform (part of) the PACE protocol | |
25 | int CmdHFEPACollectPACENonces(const char *Cmd) | |
26 | { | |
27 | // requested nonce size | |
28 | uint8_t m = 0; | |
29 | // requested number of Nonces | |
30 | unsigned int n = 0; | |
69f8a37b | 31 | // delay between requests |
32 | unsigned int d = 0; | |
5acd09bd | 33 | |
69f8a37b | 34 | sscanf(Cmd, "%hhu %u %u", &m, &n, &d); |
5acd09bd | 35 | |
36 | // values are expected to be > 0 | |
37 | m = m > 0 ? m : 1; | |
38 | n = n > 0 ? n : 1; | |
39 | ||
40 | PrintAndLog("Collecting %u %hhu-byte nonces", n, m); | |
41 | PrintAndLog("Start: %u", time(NULL)); | |
42 | // repeat n times | |
43 | for (unsigned int i = 0; i < n; i++) { | |
44 | // execute PACE | |
45 | UsbCommand c = {CMD_EPA_PACE_COLLECT_NONCE, {(int)m, 0, 0}}; | |
46 | SendCommand(&c); | |
902cb3c0 | 47 | UsbCommand resp; |
48 | ||
49 | WaitForResponse(CMD_ACK,&resp); | |
5acd09bd | 50 | |
51 | // check if command failed | |
902cb3c0 | 52 | if (resp.arg[0] != 0) { |
53 | PrintAndLog("Error in step %d, Return code: %d",resp.arg[0],(int)resp.arg[1]); | |
5acd09bd | 54 | } else { |
902cb3c0 | 55 | size_t nonce_length = resp.arg[1]; |
5acd09bd | 56 | char *nonce = (char *) malloc(2 * nonce_length + 1); |
57 | for(int j = 0; j < nonce_length; j++) { | |
902cb3c0 | 58 | snprintf(nonce + (2 * j), 3, "%02X", resp.d.asBytes[j]); |
5acd09bd | 59 | } |
60 | // print nonce | |
902cb3c0 | 61 | PrintAndLog("Length: %d, Nonce: %s",resp.arg[1], nonce); |
5acd09bd | 62 | } |
69f8a37b | 63 | if (i < n - 1) { |
64 | sleep(d); | |
65 | } | |
5acd09bd | 66 | } |
67 | PrintAndLog("End: %u", time(NULL)); | |
68 | ||
69 | return 1; | |
70 | } | |
71 | ||
72 | // UI-related stuff | |
73 | ||
74 | static const command_t CommandTable[] = | |
75 | { | |
76 | {"help", CmdHelp, 1, "This help"}, | |
69f8a37b | 77 | {"cnonces", CmdHFEPACollectPACENonces, 0, |
78 | "<m> <n> <d> Acquire n>0 encrypted PACE nonces of size m>0 with d sec pauses"}, | |
5acd09bd | 79 | {NULL, NULL, 0, NULL} |
80 | }; | |
81 | ||
82 | int CmdHelp(const char *Cmd) | |
83 | { | |
84 | CmdsHelp(CommandTable); | |
85 | return 0; | |
86 | } | |
87 | ||
88 | int CmdHFEPA(const char *Cmd) | |
89 | { | |
90 | // flush | |
7dd1908b | 91 | WaitForResponseTimeout(CMD_ACK,NULL,100); |
5acd09bd | 92 | |
93 | // parse | |
94 | CmdsParse(CommandTable, Cmd); | |
95 | return 0; | |
96 | } |