]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdhfepa.c
Basic support for EAC documents (e.g. German Identification Card)
[proxmark3-svn] / client / cmdhfepa.c
CommitLineData
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"
13#include "ui.h"
14#include "cmdparser.h"
15#include "common.h"
16#include "cmdmain.h"
17
18#include "cmdhfepa.h"
19
20static int CmdHelp(const char *Cmd);
21
22// Perform (part of) the PACE protocol
23int 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
30 sscanf(Cmd, "%hhu %u", &m, &n);
31
32 // values are expected to be > 0
33 m = m > 0 ? m : 1;
34 n = n > 0 ? n : 1;
35
36 PrintAndLog("Collecting %u %hhu-byte nonces", n, m);
37 PrintAndLog("Start: %u", time(NULL));
38 // repeat n times
39 for (unsigned int i = 0; i < n; i++) {
40 // execute PACE
41 UsbCommand c = {CMD_EPA_PACE_COLLECT_NONCE, {(int)m, 0, 0}};
42 SendCommand(&c);
43 UsbCommand *resp = WaitForResponse(CMD_ACK);
44
45 // check if command failed
46 if (resp->arg[0] != 0) {
47 PrintAndLog("Error in step %d, Return code: %d",
48 resp->arg[0],
49 (int)resp->arg[1]);
50 } else {
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]);
55 }
56 // print nonce
57 PrintAndLog("Length: %d, Nonce: %s",
58 resp->arg[1], nonce);
59 }
60 }
61 PrintAndLog("End: %u", time(NULL));
62
63 return 1;
64}
65
66// UI-related stuff
67
68static const command_t CommandTable[] =
69{
70 {"help", CmdHelp, 1, "This help"},
71 {"cnonces", CmdHFEPACollectPACENonces, 0, "<m> <n> Acquire n>0 encrypted PACE nonces of size m>0"},
72 {NULL, NULL, 0, NULL}
73};
74
75int CmdHelp(const char *Cmd)
76{
77 CmdsHelp(CommandTable);
78 return 0;
79}
80
81int CmdHFEPA(const char *Cmd)
82{
83 // flush
84 while (WaitForResponseTimeout(CMD_ACK, 500) != NULL) ;
85
86 // parse
87 CmdsParse(CommandTable, Cmd);
88 return 0;
89}
Impressum, Datenschutz