mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-02-13 02:34:48 +08:00
Use printandlogex
This commit is contained in:
parent
436910605b
commit
002e6b23fe
1 changed files with 105 additions and 113 deletions
|
@ -52,13 +52,13 @@ static int CmdHelp(const char *Cmd);
|
|||
static int CmdHFFidoInfo(const char *cmd) {
|
||||
|
||||
if (cmd && strlen(cmd) > 0)
|
||||
PrintAndLog("WARNING: command don't have any parameters.\n");
|
||||
PrintAndLogEx(WARNING, "WARNING: command don't have any parameters.\n");
|
||||
|
||||
// info about 14a part
|
||||
infoHF14A(false, false);
|
||||
|
||||
// FIDO info
|
||||
PrintAndLog("--------------------------------------------");
|
||||
PrintAndLogEx(NORMAL, "--------------------------------------------");
|
||||
SetAPDULogging(false);
|
||||
|
||||
uint8_t buf[APDU_RES_LEN] = {0};
|
||||
|
@ -73,9 +73,9 @@ static int CmdHFFidoInfo(const char *cmd) {
|
|||
|
||||
if (sw != 0x9000) {
|
||||
if (sw)
|
||||
PrintAndLog("Not a FIDO card! APDU response: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
PrintAndLogEx(INFO, "Not a FIDO card! APDU response: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
else
|
||||
PrintAndLog("APDU exchange error. Card returns 0x0000.");
|
||||
PrintAndLogEx(ERROR, "APDU exchange error. Card returns 0x0000.");
|
||||
|
||||
DropField();
|
||||
return 0;
|
||||
|
@ -83,14 +83,14 @@ static int CmdHFFidoInfo(const char *cmd) {
|
|||
|
||||
if (!strncmp((char *)buf, "U2F_V2", 7)) {
|
||||
if (!strncmp((char *)buf, "FIDO_2_0", 8)) {
|
||||
PrintAndLog("FIDO2 authenricator detected. Version: %.*s", len, buf);
|
||||
PrintAndLogEx(INFO, "FIDO2 authenricator detected. Version: %.*s", len, buf);
|
||||
} else {
|
||||
PrintAndLog("FIDO authenricator detected (not standard U2F).");
|
||||
PrintAndLog("Non U2F authenticator version:");
|
||||
PrintAndLogEx(INFO, "FIDO authenricator detected (not standard U2F).");
|
||||
PrintAndLogEx(INFO, "Non U2F authenticator version:");
|
||||
dump_buffer((const unsigned char *)buf, len, NULL, 0);
|
||||
}
|
||||
} else {
|
||||
PrintAndLog("FIDO U2F authenricator detected. Version: %.*s", len, buf);
|
||||
PrintAndLogEx(INFO, "FIDO U2F authenricator detected. Version: %.*s", len, buf);
|
||||
}
|
||||
|
||||
res = FIDO2GetInfo(buf, sizeof(buf), &len, &sw);
|
||||
|
@ -99,28 +99,22 @@ static int CmdHFFidoInfo(const char *cmd) {
|
|||
return res;
|
||||
}
|
||||
if (sw != 0x9000) {
|
||||
PrintAndLog("FIDO2 version not exists (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
PrintAndLogEx(ERR, "FIDO2 version not exists (%04x - %s).", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (buf[0]) {
|
||||
PrintAndLog("FIDO2 ger version error: %d - %s", buf[0], fido2GetCmdErrorDescription(buf[0]));
|
||||
PrintAndLogEx(ERR, "FIDO2 ger version error: %d - %s", buf[0], fido2GetCmdErrorDescription(buf[0]));
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (len > 1) {
|
||||
// if (false) {
|
||||
// PrintAndLog("FIDO2 version: (len=%d)", len);
|
||||
// dump_buffer((const unsigned char *)buf, len, NULL, 0);
|
||||
// }
|
||||
|
||||
PrintAndLog("FIDO2 version CBOR decoded:");
|
||||
PrintAndLogEx(SUCCESS, "FIDO2 version CBOR decoded:");
|
||||
TinyCborPrintFIDOPackage(fido2CmdGetInfo, true, &buf[1], len - 1);
|
||||
} else {
|
||||
PrintAndLog("FIDO2 version length error");
|
||||
PrintAndLogEx(ERR, "FIDO2 version length error");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -149,13 +143,13 @@ static json_t *OpenJson(int paramnum, char *fname, void *argtable[], bool *err)
|
|||
if (access(fname, F_OK) != -1) {
|
||||
root = json_load_file(fname, 0, &error);
|
||||
if (!root) {
|
||||
PrintAndLog("ERROR: json error on line %d: %s", error.line, error.text);
|
||||
PrintAndLogEx(ERR, "ERROR: json error on line %d: %s", error.line, error.text);
|
||||
*err = true;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!json_is_object(root)) {
|
||||
PrintAndLog("ERROR: Invalid json format. root must be an object.");
|
||||
PrintAndLogEx(ERR, "ERROR: Invalid json format. root must be an object.");
|
||||
json_decref(root);
|
||||
*err = true;
|
||||
return NULL;
|
||||
|
@ -216,13 +210,13 @@ static int CmdHFFidoRegister(const char *cmd) {
|
|||
memset(cdata, 0x00, 32);
|
||||
CLIGetStrWithReturn(6, cdata, &chlen);
|
||||
if (chlen > 16) {
|
||||
PrintAndLog("ERROR: challenge parameter length in ASCII mode must be less than 16 chars instead of: %d", chlen);
|
||||
PrintAndLogEx(ERR, "ERROR: challenge parameter length in ASCII mode must be less than 16 chars instead of: %d", chlen);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
CLIGetHexWithReturn(6, cdata, &chlen);
|
||||
if (chlen && chlen != 32) {
|
||||
PrintAndLog("ERROR: challenge parameter length must be 32 bytes only.");
|
||||
PrintAndLogEx(ERR, "ERROR: challenge parameter length must be 32 bytes only.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -234,13 +228,13 @@ static int CmdHFFidoRegister(const char *cmd) {
|
|||
memset(adata, 0x00, 32);
|
||||
CLIGetStrWithReturn(7, adata, &applen);
|
||||
if (applen > 16) {
|
||||
PrintAndLog("ERROR: application parameter length in ASCII mode must be less than 16 chars instead of: %d", applen);
|
||||
PrintAndLogEx(ERR, "ERROR: application parameter length in ASCII mode must be less than 16 chars instead of: %d", applen);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
CLIGetHexWithReturn(7, adata, &applen);
|
||||
if (applen && applen != 32) {
|
||||
PrintAndLog("ERROR: application parameter length must be 32 bytes only.");
|
||||
PrintAndLogEx(ERR, "ERROR: application parameter length must be 32 bytes only.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -262,13 +256,13 @@ static int CmdHFFidoRegister(const char *cmd) {
|
|||
int res = FIDOSelect(true, true, buf, sizeof(buf), &len, &sw);
|
||||
|
||||
if (res) {
|
||||
PrintAndLog("Can't select authenticator. res=%x. Exit...", res);
|
||||
PrintAndLogEx(ERR, "Can't select authenticator. res=%x. Exit...", res);
|
||||
DropField();
|
||||
return res;
|
||||
}
|
||||
|
||||
if (sw != 0x9000) {
|
||||
PrintAndLog("Can't select FIDO application. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
PrintAndLogEx(ERR, "Can't select FIDO application. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
DropField();
|
||||
return 2;
|
||||
}
|
||||
|
@ -276,44 +270,44 @@ static int CmdHFFidoRegister(const char *cmd) {
|
|||
res = FIDORegister(data, buf, sizeof(buf), &len, &sw);
|
||||
DropField();
|
||||
if (res) {
|
||||
PrintAndLog("Can't execute register command. res=%x. Exit...", res);
|
||||
PrintAndLogEx(ERR, "Can't execute register command. res=%x. Exit...", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
if (sw != 0x9000) {
|
||||
PrintAndLog("ERROR execute register command. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
PrintAndLogEx(ERR, "ERROR execute register command. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
return 3;
|
||||
}
|
||||
|
||||
PrintAndLog("");
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
if (APDULogging)
|
||||
PrintAndLog("---------------------------------------------------------------");
|
||||
PrintAndLog("data len: %d", len);
|
||||
PrintAndLogEx(NORMAL, "---------------------------------------------------------------");
|
||||
PrintAndLogEx(NORMAL, "data len: %d", len);
|
||||
if (verbose2) {
|
||||
PrintAndLog("--------------data----------------------");
|
||||
PrintAndLogEx(NORMAL, "--------------data----------------------");
|
||||
dump_buffer((const unsigned char *)buf, len, NULL, 0);
|
||||
PrintAndLog("--------------data----------------------");
|
||||
PrintAndLogEx(NORMAL, "--------------data----------------------");
|
||||
}
|
||||
|
||||
if (buf[0] != 0x05) {
|
||||
PrintAndLog("ERROR: First byte must be 0x05, but it %2x", buf[0]);
|
||||
PrintAndLogEx(ERR, "ERROR: First byte must be 0x05, but it %2x", buf[0]);
|
||||
return 5;
|
||||
}
|
||||
PrintAndLog("User public key: %s", sprint_hex(&buf[1], 65));
|
||||
PrintAndLogEx(SUCCESS, "User public key: %s", sprint_hex(&buf[1], 65));
|
||||
|
||||
uint8_t keyHandleLen = buf[66];
|
||||
PrintAndLog("Key handle[%d]: %s", keyHandleLen, sprint_hex(&buf[67], keyHandleLen));
|
||||
PrintAndLogEx(SUCCESS, "Key handle[%d]: %s", keyHandleLen, sprint_hex(&buf[67], keyHandleLen));
|
||||
|
||||
int derp = 67 + keyHandleLen;
|
||||
int derLen = (buf[derp + 2] << 8) + buf[derp + 3] + 4;
|
||||
if (verbose2) {
|
||||
PrintAndLog("DER certificate[%d]:\n------------------DER-------------------", derLen);
|
||||
PrintAndLogEx(NORMAL, "DER certificate[%d]:\n------------------DER-------------------", derLen);
|
||||
dump_buffer_simple((const unsigned char *)&buf[derp], derLen, NULL);
|
||||
PrintAndLog("\n----------------DER---------------------");
|
||||
PrintAndLogEx(NORMAL, "\n----------------DER---------------------");
|
||||
} else {
|
||||
if (verbose)
|
||||
PrintAndLog("------------------DER-------------------");
|
||||
PrintAndLog("DER certificate[%d]: %s...", derLen, sprint_hex(&buf[derp], 20));
|
||||
PrintAndLogEx(NORMAL, "------------------DER-------------------");
|
||||
PrintAndLogEx(NORMAL, "DER certificate[%d]: %s...", derLen, sprint_hex(&buf[derp], 20));
|
||||
}
|
||||
|
||||
// check and print DER certificate
|
||||
|
@ -321,16 +315,16 @@ static int CmdHFFidoRegister(const char *cmd) {
|
|||
|
||||
// print DER certificate in TLV view
|
||||
if (showDERTLV) {
|
||||
PrintAndLog("----------------DER TLV-----------------");
|
||||
PrintAndLogEx(NORMAL, "----------------DER TLV-----------------");
|
||||
asn1_print(&buf[derp], derLen, " ");
|
||||
PrintAndLog("----------------DER TLV-----------------");
|
||||
PrintAndLogEx(NORMAL, "----------------DER TLV-----------------");
|
||||
}
|
||||
|
||||
FIDOCheckDERAndGetKey(&buf[derp], derLen, verbose, public_key, sizeof(public_key));
|
||||
|
||||
// get hash
|
||||
int hashp = 1 + 65 + 1 + keyHandleLen + derLen;
|
||||
PrintAndLog("Hash[%d]: %s", len - hashp, sprint_hex(&buf[hashp], len - hashp));
|
||||
PrintAndLogEx(SUCCESS, "Hash[%d]: %s", len - hashp, sprint_hex(&buf[hashp], len - hashp));
|
||||
|
||||
// check ANSI X9.62 format ECDSA signature (on P-256)
|
||||
uint8_t rval[300] = {0};
|
||||
|
@ -338,8 +332,8 @@ static int CmdHFFidoRegister(const char *cmd) {
|
|||
res = ecdsa_asn1_get_signature(&buf[hashp], len - hashp, rval, sval);
|
||||
if (!res) {
|
||||
if (verbose) {
|
||||
PrintAndLog(" r: %s", sprint_hex(rval, 32));
|
||||
PrintAndLog(" s: %s", sprint_hex(sval, 32));
|
||||
PrintAndLogEx(NORMAL, " r: %s", sprint_hex(rval, 32));
|
||||
PrintAndLogEx(NORMAL, " s: %s", sprint_hex(sval, 32));
|
||||
}
|
||||
|
||||
uint8_t xbuf[4096] = {0};
|
||||
|
@ -351,23 +345,23 @@ static int CmdHFFidoRegister(const char *cmd) {
|
|||
&buf[67], keyHandleLen, // keyHandle
|
||||
&buf[1], 65, // user public key
|
||||
NULL, 0);
|
||||
//PrintAndLog("--xbuf(%d)[%d]: %s", res, xbuflen, sprint_hex(xbuf, xbuflen));
|
||||
//PrintAndLogEx(NORMAL, "--xbuf(%d)[%d]: %s", res, xbuflen, sprint_hex(xbuf, xbuflen));
|
||||
res = ecdsa_signature_verify(public_key, xbuf, xbuflen, &buf[hashp], len - hashp);
|
||||
if (res) {
|
||||
if (res == -0x4e00) {
|
||||
PrintAndLog("Signature is NOT VALID.");
|
||||
PrintAndLogEx(WARNING, "Signature is NOT VALID.");
|
||||
} else {
|
||||
PrintAndLog("Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res));
|
||||
PrintAndLogEx(WARNING, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res));
|
||||
}
|
||||
} else {
|
||||
PrintAndLog("Signature is OK.");
|
||||
PrintAndLogEx(SUCCESS, "Signature is OK.");
|
||||
}
|
||||
|
||||
} else {
|
||||
PrintAndLog("Invalid signature. res=%d.", res);
|
||||
PrintAndLogEx(WARNING, "Invalid signature. res = %d.", res);
|
||||
}
|
||||
|
||||
PrintAndLog("\nauth command: ");
|
||||
PrintAndLogEx(INFO, "\nauth command: ");
|
||||
printf("hf fido auth %s%s", paramsPlain ? "-p " : "", sprint_hex_inrow(&buf[67], keyHandleLen));
|
||||
if (chlen || applen)
|
||||
printf(" %s", paramsPlain ? (char *)cdata : sprint_hex_inrow(cdata, 32));
|
||||
|
@ -385,10 +379,10 @@ static int CmdHFFidoRegister(const char *cmd) {
|
|||
|
||||
res = json_dump_file(root, fname, JSON_INDENT(2));
|
||||
if (res) {
|
||||
PrintAndLog("ERROR: can't save the file: %s", fname);
|
||||
PrintAndLogEx(ERR, "ERROR: can't save the file: %s", fname);
|
||||
return 200;
|
||||
}
|
||||
PrintAndLog("File `%s` saved.", fname);
|
||||
PrintAndLogEx(SUCCESS, "File " _YELLOW_("`%s`") " saved.", fname);
|
||||
|
||||
// free json object
|
||||
json_decref(root);
|
||||
|
@ -457,7 +451,7 @@ static int CmdHFFidoAuthenticate(const char *cmd) {
|
|||
// public key
|
||||
CLIGetHexWithReturn(8, hdata, &hdatalen);
|
||||
if (hdatalen && hdatalen != 65) {
|
||||
PrintAndLog("ERROR: public key length must be 65 bytes only.");
|
||||
PrintAndLogEx(ERR, "ERROR: public key length must be 65 bytes only.");
|
||||
return 1;
|
||||
}
|
||||
if (hdatalen) {
|
||||
|
@ -467,7 +461,7 @@ static int CmdHFFidoAuthenticate(const char *cmd) {
|
|||
|
||||
CLIGetHexWithReturn(9, hdata, &hdatalen);
|
||||
if (hdatalen > 255) {
|
||||
PrintAndLog("ERROR: application parameter length must be less than 255.");
|
||||
PrintAndLogEx(ERR, "ERROR: application parameter length must be less than 255.");
|
||||
return 1;
|
||||
}
|
||||
if (hdatalen) {
|
||||
|
@ -480,13 +474,13 @@ static int CmdHFFidoAuthenticate(const char *cmd) {
|
|||
memset(hdata, 0x00, 32);
|
||||
CLIGetStrWithReturn(9, hdata, &hdatalen);
|
||||
if (hdatalen > 16) {
|
||||
PrintAndLog("ERROR: challenge parameter length in ASCII mode must be less than 16 chars instead of: %d", hdatalen);
|
||||
PrintAndLogEx(ERR, "ERROR: challenge parameter length in ASCII mode must be less than 16 chars instead of: %d", hdatalen);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
CLIGetHexWithReturn(10, hdata, &hdatalen);
|
||||
if (hdatalen && hdatalen != 32) {
|
||||
PrintAndLog("ERROR: challenge parameter length must be 32 bytes only.");
|
||||
PrintAndLogEx(ERR, "ERROR: challenge parameter length must be 32 bytes only.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -497,13 +491,13 @@ static int CmdHFFidoAuthenticate(const char *cmd) {
|
|||
memset(hdata, 0x00, 32);
|
||||
CLIGetStrWithReturn(11, hdata, &hdatalen);
|
||||
if (hdatalen > 16) {
|
||||
PrintAndLog("ERROR: application parameter length in ASCII mode must be less than 16 chars instead of: %d", hdatalen);
|
||||
PrintAndLogEx(ERR, "ERROR: application parameter length in ASCII mode must be less than 16 chars instead of: %d", hdatalen);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
CLIGetHexWithReturn(10, hdata, &hdatalen);
|
||||
if (hdatalen && hdatalen != 32) {
|
||||
PrintAndLog("ERROR: application parameter length must be 32 bytes only.");
|
||||
PrintAndLogEx(ERR, "ERROR: application parameter length must be 32 bytes only.");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -530,13 +524,13 @@ static int CmdHFFidoAuthenticate(const char *cmd) {
|
|||
int res = FIDOSelect(true, true, buf, sizeof(buf), &len, &sw);
|
||||
|
||||
if (res) {
|
||||
PrintAndLog("Can't select authenticator. res=%x. Exit...", res);
|
||||
PrintAndLogEx(ERR, "Can't select authenticator. res=%x. Exit...", res);
|
||||
DropField();
|
||||
return res;
|
||||
}
|
||||
|
||||
if (sw != 0x9000) {
|
||||
PrintAndLog("Can't select FIDO application. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
PrintAndLogEx(ERR, "Can't select FIDO application. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
DropField();
|
||||
return 2;
|
||||
}
|
||||
|
@ -544,20 +538,20 @@ static int CmdHFFidoAuthenticate(const char *cmd) {
|
|||
res = FIDOAuthentication(data, datalen, controlByte, buf, sizeof(buf), &len, &sw);
|
||||
DropField();
|
||||
if (res) {
|
||||
PrintAndLog("Can't execute authentication command. res=%x. Exit...", res);
|
||||
PrintAndLogEx(ERR, "Can't execute authentication command. res=%x. Exit...", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
if (sw != 0x9000) {
|
||||
PrintAndLog("ERROR execute authentication command. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
PrintAndLogEx(ERR, "ERROR execute authentication command. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
return 3;
|
||||
}
|
||||
|
||||
PrintAndLog("---------------------------------------------------------------");
|
||||
PrintAndLog("User presence: %s", (buf[0] ? "verified" : "not verified"));
|
||||
PrintAndLogEx(NORMAL, "---------------------------------------------------------------");
|
||||
PrintAndLogEx(SUCCESS, "User presence: %s", (buf[0] ? "verified" : "not verified"));
|
||||
uint32_t cntr = (uint32_t)bytes_to_num(&buf[1], 4);
|
||||
PrintAndLog("Counter: %d", cntr);
|
||||
PrintAndLog("Hash[%d]: %s", len - 5, sprint_hex(&buf[5], len - 5));
|
||||
PrintAndLogEx(SUCCESS, "Counter: %d", cntr);
|
||||
PrintAndLogEx(SUCCESS, "Hash[%d]: %s", len - 5, sprint_hex(&buf[5], len - 5));
|
||||
|
||||
// check ANSI X9.62 format ECDSA signature (on P-256)
|
||||
uint8_t rval[300] = {0};
|
||||
|
@ -565,8 +559,8 @@ static int CmdHFFidoAuthenticate(const char *cmd) {
|
|||
res = ecdsa_asn1_get_signature(&buf[5], len - 5, rval, sval);
|
||||
if (!res) {
|
||||
if (verbose) {
|
||||
PrintAndLog(" r: %s", sprint_hex(rval, 32));
|
||||
PrintAndLog(" s: %s", sprint_hex(sval, 32));
|
||||
PrintAndLogEx(NORMAL, " r: %s", sprint_hex(rval, 32));
|
||||
PrintAndLogEx(NORMAL, " s: %s", sprint_hex(sval, 32));
|
||||
}
|
||||
if (public_key_loaded) {
|
||||
uint8_t xbuf[4096] = {0};
|
||||
|
@ -577,22 +571,22 @@ static int CmdHFFidoAuthenticate(const char *cmd) {
|
|||
&buf[1], 4, // counter
|
||||
data, 32, // challenge parameter
|
||||
NULL, 0);
|
||||
//PrintAndLog("--xbuf(%d)[%d]: %s", res, xbuflen, sprint_hex(xbuf, xbuflen));
|
||||
//PrintAndLogEx(NORMAL, "--xbuf(%d)[%d]: %s", res, xbuflen, sprint_hex(xbuf, xbuflen));
|
||||
res = ecdsa_signature_verify(public_key, xbuf, xbuflen, &buf[5], len - 5);
|
||||
if (res) {
|
||||
if (res == -0x4e00) {
|
||||
PrintAndLog("Signature is NOT VALID.");
|
||||
PrintAndLogEx(WARNING, "Signature is NOT VALID.");
|
||||
} else {
|
||||
PrintAndLog("Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res));
|
||||
PrintAndLogEx(WARNING, "Other signature check error: %x %s", (res < 0) ? -res : res, ecdsa_get_error(res));
|
||||
}
|
||||
} else {
|
||||
PrintAndLog("Signature is OK.");
|
||||
PrintAndLogEx(SUCCESS, "Signature is OK.");
|
||||
}
|
||||
} else {
|
||||
PrintAndLog("No public key provided. can't check signature.");
|
||||
PrintAndLogEx(WARNING, "No public key provided. can't check signature.");
|
||||
}
|
||||
} else {
|
||||
PrintAndLog("Invalid signature. res=%d.", res);
|
||||
PrintAndLogEx(ERR, "Invalid signature. res = %d.", res);
|
||||
}
|
||||
|
||||
if (root) {
|
||||
|
@ -604,10 +598,10 @@ static int CmdHFFidoAuthenticate(const char *cmd) {
|
|||
|
||||
res = json_dump_file(root, fname, JSON_INDENT(2));
|
||||
if (res) {
|
||||
PrintAndLog("ERROR: can't save the file: %s", fname);
|
||||
PrintAndLogEx(ERR, "ERROR: can't save the file: %s", fname);
|
||||
return 200;
|
||||
}
|
||||
PrintAndLog("File `%s` saved.", fname);
|
||||
PrintAndLogEx(SUCCESS, "File " _YELLOW_("`%s`") " saved.", fname);
|
||||
|
||||
// free json object
|
||||
json_decref(root);
|
||||
|
@ -691,13 +685,13 @@ static int CmdHFFido2MakeCredential(const char *cmd) {
|
|||
|
||||
int res = GetExistsFileNameJson("fido", cjsonname, fname);
|
||||
if (res) {
|
||||
PrintAndLog("ERROR: Can't found the json file.");
|
||||
PrintAndLogEx(ERR, "ERROR: Can't found the json file.");
|
||||
return res;
|
||||
}
|
||||
PrintAndLog("fname: %s\n", fname);
|
||||
PrintAndLogEx(NORMAL, "fname: %s\n", fname);
|
||||
root = json_load_file(fname, 0, &error);
|
||||
if (!root) {
|
||||
PrintAndLog("ERROR: json error on line %d: %s", error.line, error.text);
|
||||
PrintAndLogEx(ERR, "ERROR: json error on line %d: %s", error.line, error.text);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -711,13 +705,13 @@ static int CmdHFFido2MakeCredential(const char *cmd) {
|
|||
res = FIDOSelect(true, true, buf, sizeof(buf), &len, &sw);
|
||||
|
||||
if (res) {
|
||||
PrintAndLog("Can't select authenticator. res=%x. Exit...", res);
|
||||
PrintAndLogEx(ERR, "Can't select authenticator. res=%x. Exit...", res);
|
||||
DropField();
|
||||
return res;
|
||||
}
|
||||
|
||||
if (sw != 0x9000) {
|
||||
PrintAndLog("Can't select FIDO application. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
PrintAndLogEx(ERR, "Can't select FIDO application. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
DropField();
|
||||
return 2;
|
||||
}
|
||||
|
@ -727,35 +721,35 @@ static int CmdHFFido2MakeCredential(const char *cmd) {
|
|||
return res;
|
||||
|
||||
if (showCBOR) {
|
||||
PrintAndLog("CBOR make credentional request:");
|
||||
PrintAndLog("---------------- CBOR ------------------");
|
||||
PrintAndLogEx(INFO, "CBOR make credentional request:");
|
||||
PrintAndLogEx(NORMAL, "---------------- CBOR ------------------");
|
||||
TinyCborPrintFIDOPackage(fido2CmdMakeCredential, false, data, datalen);
|
||||
PrintAndLog("---------------- CBOR ------------------");
|
||||
PrintAndLogEx(NORMAL, "---------------- CBOR ------------------");
|
||||
}
|
||||
|
||||
res = FIDO2MakeCredential(data, datalen, buf, sizeof(buf), &len, &sw);
|
||||
DropField();
|
||||
if (res) {
|
||||
PrintAndLog("Can't execute make credential command. res=%x. Exit...", res);
|
||||
PrintAndLogEx(ERR, "Can't execute make credential command. res=%x. Exit...", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
if (sw != 0x9000) {
|
||||
PrintAndLog("ERROR execute make credential command. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
PrintAndLogEx(ERR, "ERROR execute make credential command. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (buf[0]) {
|
||||
PrintAndLog("FIDO2 make credential error: %d - %s", buf[0], fido2GetCmdErrorDescription(buf[0]));
|
||||
PrintAndLogEx(ERR, "FIDO2 make credential error: %d - %s", buf[0], fido2GetCmdErrorDescription(buf[0]));
|
||||
return 0;
|
||||
}
|
||||
|
||||
PrintAndLog("MakeCredential result (%d b) OK.", len);
|
||||
PrintAndLogEx(SUCCESS, "MakeCredential result (%d b) OK.", len);
|
||||
if (showCBOR) {
|
||||
PrintAndLog("CBOR make credentional response:");
|
||||
PrintAndLog("---------------- CBOR ------------------");
|
||||
PrintAndLogEx(SUCCESS, "CBOR make credentional response:");
|
||||
PrintAndLogEx(NORMAL, "---------------- CBOR ------------------");
|
||||
TinyCborPrintFIDOPackage(fido2CmdMakeCredential, true, &buf[1], len - 1);
|
||||
PrintAndLog("---------------- CBOR ------------------");
|
||||
PrintAndLogEx(NORMAL, "---------------- CBOR ------------------");
|
||||
}
|
||||
|
||||
// parse returned cbor
|
||||
|
@ -764,14 +758,13 @@ static int CmdHFFido2MakeCredential(const char *cmd) {
|
|||
if (root) {
|
||||
res = json_dump_file(root, fname, JSON_INDENT(2));
|
||||
if (res) {
|
||||
PrintAndLog("ERROR: can't save the file: %s", fname);
|
||||
PrintAndLogEx(ERR, "ERROR: can't save the file: %s", fname);
|
||||
return 200;
|
||||
}
|
||||
PrintAndLog("File `%s` saved.", fname);
|
||||
PrintAndLogEx(SUCCESS, "File " _YELLOW_("`%s`") " saved.", fname);
|
||||
}
|
||||
|
||||
json_decref(root);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
@ -818,13 +811,13 @@ static int CmdHFFido2GetAssertion(const char *cmd) {
|
|||
|
||||
int res = GetExistsFileNameJson("fido", "fido2", fname);
|
||||
if (res) {
|
||||
PrintAndLog("ERROR: Can't found the json file.");
|
||||
PrintAndLogEx(ERR, "ERROR: Can't found the json file.");
|
||||
return res;
|
||||
}
|
||||
PrintAndLog("fname: %s\n", fname);
|
||||
PrintAndLogEx(NORMAL, "fname: %s\n", fname);
|
||||
root = json_load_file(fname, 0, &error);
|
||||
if (!root) {
|
||||
PrintAndLog("ERROR: json error on line %d: %s", error.line, error.text);
|
||||
PrintAndLogEx(ERR, "ERROR: json error on line %d: %s", error.line, error.text);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -838,13 +831,13 @@ static int CmdHFFido2GetAssertion(const char *cmd) {
|
|||
res = FIDOSelect(true, true, buf, sizeof(buf), &len, &sw);
|
||||
|
||||
if (res) {
|
||||
PrintAndLog("Can't select authenticator. res=%x. Exit...", res);
|
||||
PrintAndLogEx(ERR, "Can't select authenticator. res=%x. Exit...", res);
|
||||
DropField();
|
||||
return res;
|
||||
}
|
||||
|
||||
if (sw != 0x9000) {
|
||||
PrintAndLog("Can't select FIDO application. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
PrintAndLogEx(ERR, "Can't select FIDO application. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
DropField();
|
||||
return 2;
|
||||
}
|
||||
|
@ -854,35 +847,35 @@ static int CmdHFFido2GetAssertion(const char *cmd) {
|
|||
return res;
|
||||
|
||||
if (showCBOR) {
|
||||
PrintAndLog("CBOR get assertion request:");
|
||||
PrintAndLog("---------------- CBOR ------------------");
|
||||
PrintAndLogEx(SUCCESS, "CBOR get assertion request:");
|
||||
PrintAndLogEx(NORMAL, "---------------- CBOR ------------------");
|
||||
TinyCborPrintFIDOPackage(fido2CmdGetAssertion, false, data, datalen);
|
||||
PrintAndLog("---------------- CBOR ------------------");
|
||||
PrintAndLogEx(NORMAL, "---------------- CBOR ------------------");
|
||||
}
|
||||
|
||||
res = FIDO2GetAssertion(data, datalen, buf, sizeof(buf), &len, &sw);
|
||||
DropField();
|
||||
if (res) {
|
||||
PrintAndLog("Can't execute get assertion command. res=%x. Exit...", res);
|
||||
PrintAndLogEx(ERR, "Can't execute get assertion command. res=%x. Exit...", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
if (sw != 0x9000) {
|
||||
PrintAndLog("ERROR execute get assertion command. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
PrintAndLogEx(ERR, "ERROR execute get assertion command. APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (buf[0]) {
|
||||
PrintAndLog("FIDO2 get assertion error: %d - %s", buf[0], fido2GetCmdErrorDescription(buf[0]));
|
||||
PrintAndLogEx(ERR, "FIDO2 get assertion error: %d - %s", buf[0], fido2GetCmdErrorDescription(buf[0]));
|
||||
return 0;
|
||||
}
|
||||
|
||||
PrintAndLog("GetAssertion result (%d b) OK.", len);
|
||||
PrintAndLogEx(SUCCESS, "GetAssertion result (%d b) OK.", len);
|
||||
if (showCBOR) {
|
||||
PrintAndLog("CBOR get assertion response:");
|
||||
PrintAndLog("---------------- CBOR ------------------");
|
||||
PrintAndLogEx(SUCCESS, "CBOR get assertion response:");
|
||||
PrintAndLogEx(NORMAL, "---------------- CBOR ------------------");
|
||||
TinyCborPrintFIDOPackage(fido2CmdGetAssertion, true, &buf[1], len - 1);
|
||||
PrintAndLog("---------------- CBOR ------------------");
|
||||
PrintAndLogEx(NORMAL, "---------------- CBOR ------------------");
|
||||
}
|
||||
|
||||
// parse returned cbor
|
||||
|
@ -891,14 +884,13 @@ static int CmdHFFido2GetAssertion(const char *cmd) {
|
|||
if (root) {
|
||||
res = json_dump_file(root, fname, JSON_INDENT(2));
|
||||
if (res) {
|
||||
PrintAndLog("ERROR: can't save the file: %s", fname);
|
||||
PrintAndLogEx(ERR, "ERROR: can't save the file: %s", fname);
|
||||
return 200;
|
||||
}
|
||||
PrintAndLog("File `%s` saved.", fname);
|
||||
PrintAndLogEx(SUCCESS, "File " _YELLOW_("`%s`") " saved.", fname);
|
||||
}
|
||||
|
||||
json_decref(root);
|
||||
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue