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 //-----------------------------------------------------------------------------
14 #include "cmdparser.h"
20 static int CmdHelp(const char *Cmd
);
22 // Perform (part of) the PACE protocol
23 int CmdHFEPACollectPACENonces(const char *Cmd
)
25 // requested nonce size
27 // requested number of Nonces
30 sscanf(Cmd
, "%hhu %u", &m
, &n
);
32 // values are expected to be > 0
36 PrintAndLog("Collecting %u %hhu-byte nonces", n
, m
);
37 PrintAndLog("Start: %u", time(NULL
));
39 for (unsigned int i
= 0; i
< n
; i
++) {
41 UsbCommand c
= {CMD_EPA_PACE_COLLECT_NONCE
, {(int)m
, 0, 0}};
43 UsbCommand
*resp
= WaitForResponse(CMD_ACK
);
45 // check if command failed
46 if (resp
->arg
[0] != 0) {
47 PrintAndLog("Error in step %d, Return code: %d",
51 size_t nonce_length
= resp
->arg
[1];
52 char *nonce
= (char *) malloc(2 * nonce_length
+ 1);
53 for(int j
= 0; j
< nonce_length
; j
++) {
54 snprintf(nonce
+ (2 * j
), 3, "%02X", resp
->d
.asBytes
[j
]);
57 PrintAndLog("Length: %d, Nonce: %s",
61 PrintAndLog("End: %u", time(NULL
));
68 static const command_t CommandTable
[] =
70 {"help", CmdHelp
, 1, "This help"},
71 {"cnonces", CmdHFEPACollectPACENonces
, 0, "<m> <n> Acquire n>0 encrypted PACE nonces of size m>0"},
75 int CmdHelp(const char *Cmd
)
77 CmdsHelp(CommandTable
);
81 int CmdHFEPA(const char *Cmd
)
84 while (WaitForResponseTimeout(CMD_ACK
, 500) != NULL
) ;
87 CmdsParse(CommandTable
, Cmd
);