]> git.zerfleddert.de Git - proxmark3-svn/blame - client/cmdhfepa.c
Fixed compiler error
[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"
28fdb04f 12//#include "proxusb.h"
902cb3c0 13#include "proxmark3.h"
5acd09bd 14#include "ui.h"
15#include "cmdparser.h"
16#include "common.h"
17#include "cmdmain.h"
d0b14ad5 18#include "sleep.h"
5acd09bd 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
a0bbdb76 27 unsigned int m = 0;
5acd09bd 28 // requested number of Nonces
29 unsigned int n = 0;
69f8a37b 30 // delay between requests
31 unsigned int d = 0;
5acd09bd 32
a0bbdb76 33 sscanf(Cmd, "%u %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
1a07fd51 39 PrintAndLog("Collecting %u %"hhu"-byte nonces", n, m);
5acd09bd 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);
902cb3c0 46 UsbCommand resp;
47
3fe4ff4f 48 WaitForResponse(CMD_ACK,&resp);
5acd09bd 49
50 // check if command failed
902cb3c0 51 if (resp.arg[0] != 0) {
52 PrintAndLog("Error in step %d, Return code: %d",resp.arg[0],(int)resp.arg[1]);
5acd09bd 53 } else {
902cb3c0 54 size_t nonce_length = resp.arg[1];
5acd09bd 55 char *nonce = (char *) malloc(2 * nonce_length + 1);
56 for(int j = 0; j < nonce_length; j++) {
57642f63 57 sprintf(nonce + (2 * j), "%02X", resp.d.asBytes[j]);
5acd09bd 58 }
59 // print nonce
57642f63 60 PrintAndLog("Length: %d, Nonce: %s", nonce_length, nonce);
5acd09bd 61 }
69f8a37b 62 if (i < n - 1) {
63 sleep(d);
64 }
5acd09bd 65 }
66 PrintAndLog("End: %u", time(NULL));
67
68 return 1;
69}
70
71// UI-related stuff
72
73static const command_t CommandTable[] =
74{
75 {"help", CmdHelp, 1, "This help"},
69f8a37b 76 {"cnonces", CmdHFEPACollectPACENonces, 0,
77 "<m> <n> <d> Acquire n>0 encrypted PACE nonces of size m>0 with d sec pauses"},
5acd09bd 78 {NULL, NULL, 0, NULL}
79};
80
81int CmdHelp(const char *Cmd)
82{
83 CmdsHelp(CommandTable);
84 return 0;
85}
86
87int CmdHFEPA(const char *Cmd)
88{
89 // flush
7dd1908b 90 WaitForResponseTimeout(CMD_ACK,NULL,100);
5acd09bd 91
92 // parse
93 CmdsParse(CommandTable, Cmd);
94 return 0;
95}
Impressum, Datenschutz