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