iso auth works for app and picc level

This commit is contained in:
merlokk 2021-07-31 12:36:49 +03:00
parent 91f000ad33
commit 84d89b2480
3 changed files with 8 additions and 2 deletions

View file

@ -774,6 +774,7 @@ int DesfireSelectAID(DesfireContext *ctx, uint8_t *aid1, uint8_t *aid2) {
return PM3_EAPDU_FAIL;
DesfireClearSession(ctx);
ctx->appSelected = (aid1[0] != 0x00 || aid1[1] != 0x00 || aid1[2] != 0x00);
return PM3_SUCCESS;
}
@ -1297,14 +1298,14 @@ static int DesfireAuthenticateISO(DesfireContext *dctx, DesfireSecureChannel sec
DesfireCryptoEncDec(dctx, false, both, rndlen * 2, both, true); // error 303
// external authenticate
res = DesfireISOExternalAuth(dctx, true, dctx->keyNum, dctx->keyType, both);
res = DesfireISOExternalAuth(dctx, dctx->appSelected, dctx->keyNum, dctx->keyType, both);
if (res != PM3_SUCCESS)
return 304;
// internal authenticate
uint8_t rnddata[64] = {0};
xlen = 0;
res = DesfireISOInternalAuth(dctx, true, dctx->keyNum, dctx->keyType, hostrnd2, rnddata, &xlen);
res = DesfireISOInternalAuth(dctx, dctx->appSelected, dctx->keyNum, dctx->keyType, hostrnd2, rnddata, &xlen);
if (res != PM3_SUCCESS)
return 305;
@ -2233,6 +2234,7 @@ int DesfireISOSelect(DesfireContext *dctx, DesfireISOSelectControl cntr, uint8_t
}
DesfireClearSession(dctx);
dctx->appSelected = !( (cntr == ISSMFDFEF && datalen == 0) || (cntr == ISSEFByFileID && datalen == 2 && data[0] == 0 && data[1] == 0) );
return res;
}

View file

@ -41,6 +41,8 @@ void DesfireClearContext(DesfireContext *ctx) {
ctx->secureChannel = DACNone;
ctx->cmdSet = DCCNative;
ctx->commMode = DCMNone;
ctx->appSelected = false;
ctx->kdfAlgo = 0;
ctx->kdfInputLen = 0;

View file

@ -75,6 +75,8 @@ typedef struct DesfireContextS {
DesfireSecureChannel secureChannel; // none/d40/ev1/ev2
DesfireCommandSet cmdSet; // native/nativeiso/iso
DesfireCommunicationMode commMode; // plain/mac/enc
bool appSelected; // for iso auth
uint8_t IV[DESFIRE_MAX_KEY_SIZE];
uint8_t sessionKeyMAC[DESFIRE_MAX_KEY_SIZE];