mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-24 15:15:39 -07:00
add setup oldkey if we change the same key
This commit is contained in:
parent
bbc4f378ab
commit
a35e185b5b
1 changed files with 13 additions and 6 deletions
|
@ -4932,14 +4932,14 @@ static int CmdHF14ADesChangeKey(const char *Cmd) {
|
|||
|
||||
uint8_t oldkey[DESFIRE_MAX_KEY_SIZE] = {0};
|
||||
uint8_t keydata[200] = {0};
|
||||
int keylen = sizeof(keydata);
|
||||
CLIGetHexWithReturn(ctx, 13, keydata, &keylen);
|
||||
if (keylen && keylen != desfire_get_key_length(oldkeytype)) {
|
||||
PrintAndLogEx(ERR, "%s old key must have %d bytes length instead of %d.", CLIGetOptionListStr(DesfireAlgoOpts, oldkeytype), desfire_get_key_length(oldkeytype), keylen);
|
||||
int oldkeylen = sizeof(keydata);
|
||||
CLIGetHexWithReturn(ctx, 13, keydata, &oldkeylen);
|
||||
if (oldkeylen && oldkeylen != desfire_get_key_length(oldkeytype)) {
|
||||
PrintAndLogEx(ERR, "%s old key must have %d bytes length instead of %d.", CLIGetOptionListStr(DesfireAlgoOpts, oldkeytype), desfire_get_key_length(oldkeytype), oldkeylen);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
if (keylen)
|
||||
memcpy(oldkey, keydata, keylen);
|
||||
if (oldkeylen)
|
||||
memcpy(oldkey, keydata, oldkeylen);
|
||||
|
||||
uint8_t newkeynum = arg_get_int_def(ctx, 14, 0);
|
||||
|
||||
|
@ -4949,6 +4949,7 @@ static int CmdHF14ADesChangeKey(const char *Cmd) {
|
|||
|
||||
uint8_t newkey[DESFIRE_MAX_KEY_SIZE] = {0};
|
||||
memset(keydata, 0x00, sizeof(keydata));
|
||||
int keylen = sizeof(keydata);
|
||||
CLIGetHexWithReturn(ctx, 16, keydata, &keylen);
|
||||
if (keylen && keylen != desfire_get_key_length(newkeytype)) {
|
||||
PrintAndLogEx(ERR, "%s new key must have %d bytes length instead of %d.", CLIGetOptionListStr(DesfireAlgoOpts, newkeytype), desfire_get_key_length(newkeytype), keylen);
|
||||
|
@ -4968,6 +4969,12 @@ static int CmdHF14ADesChangeKey(const char *Cmd) {
|
|||
SetAPDULogging(APDULogging);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// if we change the same key
|
||||
if (oldkeylen == 0 && newkeynum == dctx.keyNum) {
|
||||
oldkeytype = dctx.keyType;
|
||||
memcpy(oldkey, dctx.key, desfire_get_key_length(dctx.keyType));
|
||||
}
|
||||
|
||||
if (appid == 0x000000) {
|
||||
PrintAndLogEx(WARNING, "Changing the root aid (0x000000)");
|
||||
return PM3_ESOFT; // TODO!!!!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue