some refactoring and add new commands for fido u2f

This commit is contained in:
merlokk 2018-10-16 19:02:14 +03:00
commit fbd3f981c6

View file

@ -37,7 +37,13 @@
static int CmdHelp(const char *Cmd);
int CmdHFMFPInfo(const char *cmd) {
int FIDOSelect(bool ActivateField, bool LeaveFieldON, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw) {
uint8_t data[] = {0xA0, 0x00, 0x00, 0x06, 0x47, 0x2F, 0x00, 0x01};
return EMVSelect(ActivateField, LeaveFieldON, data, sizeof(data), Result, MaxResultLen, ResultLen, sw, NULL);
}
int CmdHFFidoInfo(const char *cmd) {
if (cmd && strlen(cmd) > 0)
PrintAndLog("WARNING: command don't have any parameters.\n");
@ -49,14 +55,10 @@ int CmdHFMFPInfo(const char *cmd) {
PrintAndLog("--------------------------------------------");
SetAPDULogging(false);
uint8_t data[APDU_AID_LEN] = {0};
int datalen = 0;
param_gethex_to_eol("A0000006472F0001", 0, data, sizeof(data), &datalen);
uint8_t buf[APDU_RES_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res = EMVSelect(true, false, data, datalen, buf, sizeof(buf), &len, &sw, NULL);
int res = FIDOSelect(true, false, buf, sizeof(buf), &len, &sw);
if (res)
return res;
@ -84,10 +86,46 @@ int CmdHFMFPInfo(const char *cmd) {
return 0;
}
int CmdHFFidoRegister(const char *cmd) {
// here will be command extraction
// challenge parameter [32 bytes] - The challenge parameter is the SHA-256 hash of the Client Data, a stringified JSON data structure that the FIDO Client prepares
// application parameter [32 bytes] - The application parameter is the SHA-256 hash of the UTF-8 encoding of the application identity
SetAPDULogging(true);
uint8_t buf[APDU_RES_LEN] = {0};
size_t len = 0;
uint16_t sw = 0;
int res = FIDOSelect(true, false, buf, sizeof(buf), &len, &sw);
if (res) {
PrintAndLog("Can't select authenticator. Exit...");
return res;
}
if (sw != 0x9000) {
PrintAndLog("APDU response status: %04x - %s", sw, GetAPDUCodeDescription(sw >> 8, sw & 0xff));
return 2;
}
return 0;
};
int CmdHFFidoAuthenticate(const char *cmd) {
return 0;
};
static command_t CommandTable[] =
{
{"help", CmdHelp, 1, "This help"},
{"info", CmdHFMFPInfo, 0, "Info about FIDO tag"},
{"help", CmdHelp, 1, "This help."},
{"info", CmdHFFidoInfo, 0, "Info about FIDO tag."},
{"reg", CmdHFFidoRegister, 0, "FIDO U2F Registration Message."},
{"auth", CmdHFFidoAuthenticate, 0, "FIDO U2F Authentication Message."},
{NULL, NULL, 0, NULL}
};