mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-20 03:48:33 +08:00
make select-and-authenticate function
This commit is contained in:
parent
40aa8fbc16
commit
55b6ff8e05
3 changed files with 41 additions and 75 deletions
|
@ -5213,30 +5213,14 @@ static int CmdHF14ADesChKeySettings(const char *Cmd) {
|
|||
CLIParserFree(ctx);
|
||||
|
||||
if (verbose) {
|
||||
DesfirePrintContext(&dctx);
|
||||
PrintAndLogEx(SUCCESS, "\nNew key settings:");
|
||||
PrintKeySettings(ksett32, 0, (appid != 0x000000), false);
|
||||
}
|
||||
|
||||
res = DesfireSelectAIDHex(&dctx, appid, false, 0);
|
||||
res = DesfireSelectAndAuthenticate(&dctx, securechann, appid, verbose);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Desfire select " _RED_("error") ".");
|
||||
DropField();
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
res = DesfireAuthenticate(&dctx, securechann);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Desfire authenticate " _RED_("error") ". Result: %d", res);
|
||||
DropField();
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
if (DesfireIsAuthenticated(&dctx)) {
|
||||
if (verbose)
|
||||
PrintAndLogEx(INFO, "Desfire " _GREEN_("authenticated"));
|
||||
} else {
|
||||
return PM3_ESOFT;
|
||||
return res;
|
||||
}
|
||||
|
||||
uint8_t keysett = ksett32 & 0x0f;
|
||||
|
@ -5252,6 +5236,11 @@ static int CmdHF14ADesChKeySettings(const char *Cmd) {
|
|||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int CmdHF14ADesGetKeyVersions(const char *Cmd) {
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int CmdHF14ADesGetKeySettings(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf mfdes getkeysetings",
|
||||
|
@ -5291,28 +5280,10 @@ static int CmdHF14ADesGetKeySettings(const char *Cmd) {
|
|||
SetAPDULogging(APDULogging);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (verbose)
|
||||
DesfirePrintContext(&dctx);
|
||||
|
||||
res = DesfireSelectAIDHex(&dctx, appid, false, 0);
|
||||
res = DesfireSelectAndAuthenticate(&dctx, securechann, appid, verbose);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Desfire select " _RED_("error") ".");
|
||||
DropField();
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
res = DesfireAuthenticate(&dctx, securechann);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Desfire authenticate " _RED_("error") ". Result: %d", res);
|
||||
DropField();
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
if (DesfireIsAuthenticated(&dctx)) {
|
||||
if (verbose)
|
||||
PrintAndLogEx(INFO, "Desfire " _GREEN_("authenticated"));
|
||||
} else {
|
||||
return PM3_ESOFT;
|
||||
return res;
|
||||
}
|
||||
|
||||
uint8_t buf[APDU_RES_LEN] = {0};
|
||||
|
@ -5385,28 +5356,10 @@ static int CmdHF14ADesGetAIDs(const char *Cmd) {
|
|||
SetAPDULogging(APDULogging);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (verbose)
|
||||
DesfirePrintContext(&dctx);
|
||||
|
||||
res = DesfireSelectAIDHex(&dctx, 0x000000, false, 0);
|
||||
res = DesfireSelectAndAuthenticate(&dctx, securechann, 0x000000, verbose);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Desfire select " _RED_("error") ".");
|
||||
DropField();
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
res = DesfireAuthenticate(&dctx, securechann);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Desfire authenticate " _RED_("error") ". Result: %d", res);
|
||||
DropField();
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
if (DesfireIsAuthenticated(&dctx)) {
|
||||
if (verbose)
|
||||
PrintAndLogEx(INFO, "Desfire " _GREEN_("authenticated"));
|
||||
} else {
|
||||
return PM3_ESOFT;
|
||||
return res;
|
||||
}
|
||||
|
||||
uint8_t buf[APDU_RES_LEN] = {0};
|
||||
|
@ -5470,25 +5423,10 @@ static int CmdHF14ADesGetAppNames(const char *Cmd) {
|
|||
if (verbose)
|
||||
DesfirePrintContext(&dctx);
|
||||
|
||||
res = DesfireSelectAIDHex(&dctx, 0x000000, false, 0);
|
||||
res = DesfireSelectAndAuthenticate(&dctx, securechann, 0x000000, verbose);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Desfire select " _RED_("error") ".");
|
||||
DropField();
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
res = DesfireAuthenticate(&dctx, securechann);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Desfire authenticate " _RED_("error") ". Result: %d", res);
|
||||
DropField();
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
if (DesfireIsAuthenticated(&dctx)) {
|
||||
if (verbose)
|
||||
PrintAndLogEx(INFO, "Desfire " _GREEN_("authenticated"));
|
||||
} else {
|
||||
return PM3_ESOFT;
|
||||
return res;
|
||||
}
|
||||
|
||||
uint8_t buf[APDU_RES_LEN] = {0};
|
||||
|
@ -5540,6 +5478,7 @@ static command_t CommandTable[] = {
|
|||
{"changekey", CmdHF14ADesChangeKey, IfPm3Iso14443a, "Change Key"},
|
||||
{"chkeysetings", CmdHF14ADesChKeySettings, IfPm3Iso14443a, "[new]Change Key Settings"},
|
||||
{"getkeysetings", CmdHF14ADesGetKeySettings, IfPm3Iso14443a, "[new]Get Key Settings"},
|
||||
{"getkeyversions", CmdHF14ADesGetKeyVersions, IfPm3Iso14443a, "[new]Get Key Versions"},
|
||||
{"-----------", CmdHelp, IfPm3Iso14443a, "-------------------- " _CYAN_("Applications") " -------------------"},
|
||||
{"bruteaid", CmdHF14ADesBruteApps, IfPm3Iso14443a, "Recover AIDs by bruteforce"},
|
||||
{"createaid", CmdHF14ADesCreateApp, IfPm3Iso14443a, "Create Application ID"},
|
||||
|
|
|
@ -602,6 +602,32 @@ int DesfireSelectAIDHex(DesfireContext *ctx, uint32_t aid1, bool select_two, uin
|
|||
return DesfireSelectAID(ctx, data, (select_two) ? &data[3] : NULL);
|
||||
}
|
||||
|
||||
int DesfireSelectAndAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool verbose) {
|
||||
if (verbose)
|
||||
DesfirePrintContext(dctx);
|
||||
|
||||
int res = DesfireSelectAIDHex(dctx, aid, false, 0);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Desfire select " _RED_("error") ".");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
res = DesfireAuthenticate(dctx, secureChannel);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Desfire authenticate " _RED_("error") ". Result: %d", res);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
if (DesfireIsAuthenticated(dctx)) {
|
||||
if (verbose)
|
||||
PrintAndLogEx(INFO, "Desfire " _GREEN_("authenticated"));
|
||||
} else {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
int DesfireAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel) {
|
||||
// 3 different way to authenticate AUTH (CRC16) , AUTH_ISO (CRC32) , AUTH_AES (CRC32)
|
||||
// 4 different crypto arg1 DES, 3DES, 3K3DES, AES
|
||||
|
|
|
@ -37,6 +37,7 @@ int DesfireExchangeEx(bool activate_field, DesfireContext *ctx, uint8_t cmd, uin
|
|||
int DesfireSelectAID(DesfireContext *ctx, uint8_t *aid1, uint8_t *aid2);
|
||||
int DesfireSelectAIDHex(DesfireContext *ctx, uint32_t aid1, bool select_two, uint32_t aid2);
|
||||
|
||||
int DesfireSelectAndAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel, uint32_t aid, bool verbose);
|
||||
int DesfireAuthenticate(DesfireContext *dctx, DesfireSecureChannel secureChannel);
|
||||
|
||||
int DesfireGetUID(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
||||
|
|
Loading…
Add table
Reference in a new issue