]> git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhfepa.c
2787b9695745bf94b491186390eb65d04b30077b
[proxmark3-svn] / client / cmdhfepa.c
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"
13 #include "ui.h"
14 #include "cmdparser.h"
15 #include "common.h"
16 #include "cmdmain.h"
17
18 #include "cmdhfepa.h"
19
20 static int CmdHelp(const char *Cmd);
21
22 // Perform (part of) the PACE protocol
23 int CmdHFEPACollectPACENonces(const char *Cmd)
24 {
25 // requested nonce size
26 uint8_t m = 0;
27 // requested number of Nonces
28 unsigned int n = 0;
29 // delay between requests
30 unsigned int d = 0;
31
32 sscanf(Cmd, "%hhu %u %u", &m, &n, &d);
33
34 // values are expected to be > 0
35 m = m > 0 ? m : 1;
36 n = n > 0 ? n : 1;
37
38 PrintAndLog("Collecting %u %hhu-byte nonces", n, m);
39 PrintAndLog("Start: %u", time(NULL));
40 // repeat n times
41 for (unsigned int i = 0; i < n; i++) {
42 // execute PACE
43 UsbCommand c = {CMD_EPA_PACE_COLLECT_NONCE, {(int)m, 0, 0}};
44 SendCommand(&c);
45 UsbCommand *resp = WaitForResponse(CMD_ACK);
46
47 // check if command failed
48 if (resp->arg[0] != 0) {
49 PrintAndLog("Error in step %d, Return code: %d",
50 resp->arg[0],
51 (int)resp->arg[1]);
52 } else {
53 size_t nonce_length = resp->arg[1];
54 char *nonce = (char *) malloc(2 * nonce_length + 1);
55 for(int j = 0; j < nonce_length; j++) {
56 snprintf(nonce + (2 * j), 3, "%02X", resp->d.asBytes[j]);
57 }
58 // print nonce
59 PrintAndLog("Length: %d, Nonce: %s",
60 resp->arg[1], nonce);
61 }
62 if (i < n - 1) {
63 sleep(d);
64 }
65 }
66 PrintAndLog("End: %u", time(NULL));
67
68 return 1;
69 }
70
71 // UI-related stuff
72
73 static const command_t CommandTable[] =
74 {
75 {"help", CmdHelp, 1, "This help"},
76 {"cnonces", CmdHFEPACollectPACENonces, 0,
77 "<m> <n> <d> Acquire n>0 encrypted PACE nonces of size m>0 with d sec pauses"},
78 {NULL, NULL, 0, NULL}
79 };
80
81 int CmdHelp(const char *Cmd)
82 {
83 CmdsHelp(CommandTable);
84 return 0;
85 }
86
87 int CmdHFEPA(const char *Cmd)
88 {
89 // flush
90 while (WaitForResponseTimeout(CMD_ACK, 500) != NULL) ;
91
92 // parse
93 CmdsParse(CommandTable, Cmd);
94 return 0;
95 }
Impressum, Datenschutz