From 8ffdccffa0e7ec45c785495116b77b3f0b85bd49 Mon Sep 17 00:00:00 2001 From: merlokk Date: Wed, 12 Sep 2018 20:20:27 +0300 Subject: [PATCH] `hf emv challenge` works --- client/emv/cmdemv.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/client/emv/cmdemv.c b/client/emv/cmdemv.c index 030eaa0b..3114c46a 100644 --- a/client/emv/cmdemv.c +++ b/client/emv/cmdemv.c @@ -321,6 +321,41 @@ int CmdHFEMVAC(const char *cmd) { int CmdHFEMVGenerateChallenge(const char *cmd) { + CLIParserInit("hf 14a challenge", + "Executes Generate Challenge command. It returns 4-byte random number from card:\n", + "Usage:\n\thf emv challenge -> get challenge\n\thf emv challenge -k -> get challenge, keep fileld ON\n"); + + void* argtable[] = { + arg_param_begin, + arg_lit0("kK", "keep", "keep field ON for next command"), + arg_lit0("aA", "apdu", "show APDU reqests and responses"), + arg_param_end + }; + CLIExecWithReturn(cmd, argtable, true); + + bool leaveSignalON = arg_get_lit(1); + bool APDULogging = arg_get_lit(2); + CLIParserFree(); + + SetAPDULogging(APDULogging); + + // exec + uint8_t buf[APDU_RES_LEN] = {0}; + size_t len = 0; + uint16_t sw = 0; + int res = EMVGenerateChallenge(leaveSignalON, buf, sizeof(buf), &len, &sw, NULL); + + if (sw) + PrintAndLog("APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff)); + + if (res) + return res; + + PrintAndLog("Challenge: %s", sprint_hex(buf, len)); + + if (len != 4 && len != 8) + PrintAndLog("WARNING: length of challenge must be 4 or 8, but it %d", len); + return 0; } -- 2.39.5