mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
Merge pull request #1424 from merlokk/desf_chkey_ev2
desfire changekey ev2
This commit is contained in:
commit
f0faa1d84c
3 changed files with 12 additions and 9 deletions
|
@ -1255,6 +1255,7 @@ static int CmdHF14ADesInfo(const char *Cmd) {
|
||||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
CLIParserFree(ctx);
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
|
SetAPDULogging(false);
|
||||||
DropField();
|
DropField();
|
||||||
|
|
||||||
mfdes_info_res_t info;
|
mfdes_info_res_t info;
|
||||||
|
|
|
@ -2510,7 +2510,7 @@ int DesfireChangeKey(DesfireContext *dctx, bool change_master_key, uint8_t newke
|
||||||
iso14443a_crc(nkeybuf, nkeylen, &cdata[cdatalen]);
|
iso14443a_crc(nkeybuf, nkeylen, &cdata[cdatalen]);
|
||||||
cdatalen += 2;
|
cdatalen += 2;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (dctx->secureChannel == DACEV1) {
|
||||||
// EV1 Checksum must cover : <KeyNo> <PrevKey XOR Newkey> [<AES NewKeyVer>]
|
// EV1 Checksum must cover : <KeyNo> <PrevKey XOR Newkey> [<AES NewKeyVer>]
|
||||||
desfire_crc32_append(pckcdata, cdatalen + 2);
|
desfire_crc32_append(pckcdata, cdatalen + 2);
|
||||||
cdatalen += 4;
|
cdatalen += 4;
|
||||||
|
@ -2518,12 +2518,19 @@ int DesfireChangeKey(DesfireContext *dctx, bool change_master_key, uint8_t newke
|
||||||
desfire_crc32(nkeybuf, nkeylen, &cdata[cdatalen]);
|
desfire_crc32(nkeybuf, nkeylen, &cdata[cdatalen]);
|
||||||
cdatalen += 4;
|
cdatalen += 4;
|
||||||
}
|
}
|
||||||
|
} else if (dctx->secureChannel == DACEV2) {
|
||||||
|
// EV2 : <PrevKey XOR Newkey> [<AES NewKeyVer>]
|
||||||
|
if (newkeynum != dctx->keyNum) {
|
||||||
|
desfire_crc32(nkeybuf, nkeylen, &cdata[cdatalen]);
|
||||||
|
cdatalen += 4;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// send command
|
// send command
|
||||||
uint8_t resp[257] = {0};
|
uint8_t resp[257] = {0};
|
||||||
size_t resplen = 0;
|
size_t resplen = 0;
|
||||||
int res = DesfireChangeKeyCmd(dctx, &pckcdata[1], cdatalen, resp, &resplen);
|
PrintAndLogEx(SUCCESS, "Change key [%d] %s", cdatalen + 1, sprint_hex(&pckcdata[1], cdatalen + 1));
|
||||||
|
int res = DesfireChangeKeyCmd(dctx, &pckcdata[1], cdatalen + 1, resp, &resplen);
|
||||||
|
|
||||||
// check response
|
// check response
|
||||||
if (res == 0 && resplen > 0)
|
if (res == 0 && resplen > 0)
|
||||||
|
|
|
@ -311,7 +311,7 @@ static void DesfireSecureChannelEncodeEV2(DesfireContext *ctx, uint8_t cmd, uint
|
||||||
|
|
||||||
memcpy(&dstdata[srcdatalen], cmac, DesfireGetMACLength(ctx));
|
memcpy(&dstdata[srcdatalen], cmac, DesfireGetMACLength(ctx));
|
||||||
*dstdatalen = srcdatalen + DesfireGetMACLength(ctx);
|
*dstdatalen = srcdatalen + DesfireGetMACLength(ctx);
|
||||||
} else if (ctx->commMode == DCMEncrypted || ctx->commMode == DCMEncryptedWithPadding) {
|
} else if (ctx->commMode == DCMEncrypted || ctx->commMode == DCMEncryptedWithPadding || ctx->commMode == DCMEncryptedPlain) {
|
||||||
memcpy(dstdata, srcdata, hdrlen);
|
memcpy(dstdata, srcdata, hdrlen);
|
||||||
|
|
||||||
if (srcdatalen > hdrlen) {
|
if (srcdatalen > hdrlen) {
|
||||||
|
@ -330,11 +330,6 @@ static void DesfireSecureChannelEncodeEV2(DesfireContext *ctx, uint8_t cmd, uint
|
||||||
|
|
||||||
*dstdatalen = hdrlen + rlen + DesfireGetMACLength(ctx);
|
*dstdatalen = hdrlen + rlen + DesfireGetMACLength(ctx);
|
||||||
ctx->commMode = DCMEncrypted;
|
ctx->commMode = DCMEncrypted;
|
||||||
} else if (ctx->commMode == DCMEncryptedPlain) {
|
|
||||||
if (srcdatalen <= hdrlen)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// TODO !!!
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue