This commit is contained in:
merlokk 2021-07-11 18:57:44 +03:00
commit e4bdecf30e
2 changed files with 31 additions and 31 deletions

View file

@ -523,7 +523,7 @@ static void DesfireSplitBytesToBlock(uint8_t *blockdata, size_t *blockdatacount,
int DesfireExchangeEx(bool activate_field, DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen, bool enable_chaining, size_t splitbysize) { int DesfireExchangeEx(bool activate_field, DesfireContext *ctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *respcode, uint8_t *resp, size_t *resplen, bool enable_chaining, size_t splitbysize) {
int res = PM3_SUCCESS; int res = PM3_SUCCESS;
if (!PrintChannelModeWarning(cmd, ctx->secureChannel, ctx->cmdSet, ctx->commMode)) if (!PrintChannelModeWarning(cmd, ctx->secureChannel, ctx->cmdSet, ctx->commMode))
DesfirePrintContext(ctx); DesfirePrintContext(ctx);
@ -964,19 +964,19 @@ int DesfireChangeKeySettings(DesfireContext *dctx, uint8_t *data, size_t len) {
} }
static void PrintKeyType(uint8_t keytype) { static void PrintKeyType(uint8_t keytype) {
switch(keytype) { switch (keytype) {
case 00: case 00:
PrintAndLogEx(SUCCESS, "Key: 2TDEA"); PrintAndLogEx(SUCCESS, "Key: 2TDEA");
break; break;
case 01: case 01:
PrintAndLogEx(SUCCESS, "Key: 3TDEA"); PrintAndLogEx(SUCCESS, "Key: 3TDEA");
break; break;
case 02: case 02:
PrintAndLogEx(SUCCESS, "Key: AES"); PrintAndLogEx(SUCCESS, "Key: AES");
break; break;
default: default:
PrintAndLogEx(SUCCESS, "Key: unknown: 0x%02x", keytype); PrintAndLogEx(SUCCESS, "Key: unknown: 0x%02x", keytype);
break; break;
} }
} }
@ -1014,7 +1014,7 @@ static void PrintKeySettingsApp(uint8_t keysettings, uint8_t numkeys, bool print
); );
break; break;
} }
PrintAndLogEx(SUCCESS, "[%c...] AMK Configuration changeable : %s", (keysettings & (1 << 3)) ? '1' : '0', (keysettings & (1 << 3)) ? _GREEN_("YES") : "NO (frozen)"); PrintAndLogEx(SUCCESS, "[%c...] AMK Configuration changeable : %s", (keysettings & (1 << 3)) ? '1' : '0', (keysettings & (1 << 3)) ? _GREEN_("YES") : "NO (frozen)");
PrintAndLogEx(SUCCESS, "[.%c..] AMK required for create/delete : %s", (keysettings & (1 << 2)) ? '1' : '0', (keysettings & (1 << 2)) ? "NO" : "YES"); PrintAndLogEx(SUCCESS, "[.%c..] AMK required for create/delete : %s", (keysettings & (1 << 2)) ? '1' : '0', (keysettings & (1 << 2)) ? "NO" : "YES");
PrintAndLogEx(SUCCESS, "[..%c.] Directory list access with AMK : %s", (keysettings & (1 << 1)) ? '1' : '0', (keysettings & (1 << 1)) ? "NO" : "YES"); PrintAndLogEx(SUCCESS, "[..%c.] Directory list access with AMK : %s", (keysettings & (1 << 1)) ? '1' : '0', (keysettings & (1 << 1)) ? "NO" : "YES");

View file

@ -101,7 +101,7 @@ static void DesfireSecureChannelEncodeD40(DesfireContext *ctx, uint8_t cmd, uint
static void DesfireSecureChannelEncodeEV1(DesfireContext *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) { static void DesfireSecureChannelEncodeEV1(DesfireContext *ctx, uint8_t cmd, uint8_t *srcdata, size_t srcdatalen, uint8_t *dstdata, size_t *dstdatalen) {
uint8_t data[1024] = {0}; uint8_t data[1024] = {0};
size_t rlen = 0; size_t rlen = 0;
// we calc MAC anyway // we calc MAC anyway
// if encypted channel and no data - we only calc MAC // if encypted channel and no data - we only calc MAC
if (ctx->commMode == DCMPlain || ctx->commMode == DCMMACed || (ctx->commMode == DCMEncrypted && srcdatalen == 0)) { if (ctx->commMode == DCMPlain || ctx->commMode == DCMMACed || (ctx->commMode == DCMEncrypted && srcdatalen == 0)) {
@ -121,9 +121,9 @@ static void DesfireSecureChannelEncodeEV1(DesfireContext *ctx, uint8_t cmd, uint
data[0] = cmd; data[0] = cmd;
memcpy(&data[1], srcdata, srcdatalen); memcpy(&data[1], srcdata, srcdatalen);
desfire_crc32_append(data, srcdatalen + 1); desfire_crc32_append(data, srcdatalen + 1);
DesfireCryptoEncDec(ctx, true, &data[1], rlen, dstdata, true); DesfireCryptoEncDec(ctx, true, &data[1], rlen, dstdata, true);
*dstdatalen = rlen; *dstdatalen = rlen;
} else { } else {
memcpy(dstdata, srcdata, srcdatalen); memcpy(dstdata, srcdata, srcdatalen);
@ -256,38 +256,38 @@ bool PrintChannelModeWarning(uint8_t cmd, DesfireSecureChannel secureChannel, De
PrintAndLogEx(WARNING, "Communication mode can't be NONE. command: %02x", cmd); PrintAndLogEx(WARNING, "Communication mode can't be NONE. command: %02x", cmd);
return false; return false;
} }
// no security set // no security set
if (secureChannel == DACNone) if (secureChannel == DACNone)
return true; return true;
bool found = false; bool found = false;
for (int i = 0; i < ARRAY_LENGTH(AllowedChannelModes); i++) for (int i = 0; i < ARRAY_LENGTH(AllowedChannelModes); i++)
if (AllowedChannelModes[i].cmd == cmd) { if (AllowedChannelModes[i].cmd == cmd) {
// full compare // full compare
if (AllowedChannelModes[i].secureChannel == secureChannel && if (AllowedChannelModes[i].secureChannel == secureChannel &&
(AllowedChannelModes[i].cmdSet == cmdSet || (AllowedChannelModes[i].cmdSet == DCCNative && cmdSet == DCCNativeISO)) && (AllowedChannelModes[i].cmdSet == cmdSet || (AllowedChannelModes[i].cmdSet == DCCNative && cmdSet == DCCNativeISO)) &&
AllowedChannelModes[i].commMode == commMode){ AllowedChannelModes[i].commMode == commMode) {
found = true; found = true;
break; break;
} }
// ev1 plain and mac are the same // ev1 plain and mac are the same
if (AllowedChannelModes[i].secureChannel == secureChannel && if (AllowedChannelModes[i].secureChannel == secureChannel &&
AllowedChannelModes[i].secureChannel == DACEV1 && AllowedChannelModes[i].secureChannel == DACEV1 &&
(AllowedChannelModes[i].cmdSet == cmdSet || (AllowedChannelModes[i].cmdSet == DCCNative && cmdSet == DCCNativeISO)) && (AllowedChannelModes[i].cmdSet == cmdSet || (AllowedChannelModes[i].cmdSet == DCCNative && cmdSet == DCCNativeISO)) &&
(commMode == DCMPlain || commMode == DCMMACed)){ (commMode == DCMPlain || commMode == DCMMACed)) {
found = true; found = true;
break; break;
} }
} }
if (!found) if (!found)
PrintAndLogEx(WARNING, "Wrong communication mode. Check settings. command: %02x", cmd); PrintAndLogEx(WARNING, "Wrong communication mode. Check settings. command: %02x", cmd);
return found; return found;
} }