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 //-----------------------------------------------------------------------------
13 #include "proxmark3.h"
15 #include "cmdparser.h"
22 static int CmdHelp(const char *Cmd
);
24 // Perform (part of) the PACE protocol
25 int CmdHFEPACollectPACENonces(const char *Cmd
)
27 // requested nonce size
29 // requested number of Nonces
31 // delay between requests
34 sscanf(Cmd
, "%hhu %u %u", &m
, &n
, &d
);
36 // values are expected to be > 0
40 PrintAndLog("Collecting %u %hhu-byte nonces", n
, m
);
41 PrintAndLog("Start: %u", time(NULL
));
43 for (unsigned int i
= 0; i
< n
; i
++) {
45 UsbCommand c
= {CMD_EPA_PACE_COLLECT_NONCE
, {(int)m
, 0, 0}};
49 WaitForResponse(CMD_ACK
,&resp
);
51 // check if command failed
52 if (resp
.arg
[0] != 0) {
53 PrintAndLog("Error in step %d, Return code: %d",resp
.arg
[0],(int)resp
.arg
[1]);
55 size_t nonce_length
= resp
.arg
[1];
56 char *nonce
= (char *) malloc(2 * nonce_length
+ 1);
57 for(int j
= 0; j
< nonce_length
; j
++) {
58 snprintf(nonce
+ (2 * j
), 3, "%02X", resp
.d
.asBytes
[j
]);
61 PrintAndLog("Length: %d, Nonce: %s",resp
.arg
[1], nonce
);
67 PrintAndLog("End: %u", time(NULL
));
74 static const command_t CommandTable
[] =
76 {"help", CmdHelp
, 1, "This help"},
77 {"cnonces", CmdHFEPACollectPACENonces
, 0,
78 "<m> <n> <d> Acquire n>0 encrypted PACE nonces of size m>0 with d sec pauses"},
82 int CmdHelp(const char *Cmd
)
84 CmdsHelp(CommandTable
);
88 int CmdHFEPA(const char *Cmd
)
91 WaitForResponseTimeout(CMD_ACK
,NULL
,100);
94 CmdsParse(CommandTable
, Cmd
);