1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2012 Frederik Möllers
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
7 //-----------------------------------------------------------------------------
8 // Commands related to the German electronic Identification Card
9 //-----------------------------------------------------------------------------
12 //#include "proxusb.h"
13 #include "proxmark3.h"
15 #include "cmdparser.h"
21 static int CmdHelp(const char *Cmd
);
23 // Perform (part of) the PACE protocol
24 int CmdHFEPACollectPACENonces(const char *Cmd
)
26 // requested nonce size
28 // requested number of Nonces
30 // delay between requests
33 sscanf(Cmd
, "%u %u %u", &m
, &n
, &d
);
35 // values are expected to be > 0
39 PrintAndLog("Collecting %u %"hhu
"-byte nonces", n
, m
);
40 PrintAndLog("Start: %u", time(NULL
));
42 for (unsigned int i
= 0; i
< n
; i
++) {
44 UsbCommand c
= {CMD_EPA_PACE_COLLECT_NONCE
, {(int)m
, 0, 0}};
48 WaitForResponse(CMD_ACK
,&resp
);
50 // check if command failed
51 if (resp
.arg
[0] != 0) {
52 PrintAndLog("Error in step %d, Return code: %d",resp
.arg
[0],(int)resp
.arg
[1]);
54 size_t nonce_length
= resp
.arg
[1];
55 char *nonce
= (char *) malloc(2 * nonce_length
+ 1);
56 for(int j
= 0; j
< nonce_length
; j
++) {
57 sprintf(nonce
+ (2 * j
), "%02X", resp
.d
.asBytes
[j
]);
60 PrintAndLog("Length: %d, Nonce: %s", nonce_length
, nonce
);
66 PrintAndLog("End: %u", time(NULL
));
73 static const command_t CommandTable
[] =
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"},
81 int CmdHelp(const char *Cmd
)
83 CmdsHelp(CommandTable
);
87 int CmdHFEPA(const char *Cmd
)
90 WaitForResponseTimeout(CMD_ACK
,NULL
,100);
93 CmdsParse(CommandTable
, Cmd
);