clear security state when card returns error

This commit is contained in:
merlokk 2021-06-03 12:03:32 +03:00
commit a206dcc9b2

View file

@ -72,8 +72,15 @@ static int CIPURSEExchangeEx(bool ActivateField, bool LeaveFieldON, sAPDU apdu,
} }
size_t rlen = 0; size_t rlen = 0;
if (*ResultLen == 2) {
CipurseCClearContext(&cipurseContext);
isw = Result[0] * 0x0100 + Result[1];
} else {
CipurseCAPDURespDecode(&cipurseContext, Result, *ResultLen, securedata, &rlen, &isw); CipurseCAPDURespDecode(&cipurseContext, Result, *ResultLen, securedata, &rlen, &isw);
memcpy(Result, securedata, rlen); memcpy(Result, securedata, rlen);
}
if (ResultLen != NULL) if (ResultLen != NULL)
*ResultLen = rlen; *ResultLen = rlen;
@ -171,6 +178,7 @@ bool CIPURSEChannelAuthenticate(uint8_t keyIndex, uint8_t *key, bool verbose) {
if (verbose) if (verbose)
PrintAndLogEx(INFO, "Authentication " _GREEN_("OK")); PrintAndLogEx(INFO, "Authentication " _GREEN_("OK"));
//CipurseCChannelSetSecurityLevels(&cpc, CPSEncrypted, CPSEncrypted);
CipurseCChannelSetSecurityLevels(&cpc, CPSMACed, CPSMACed); CipurseCChannelSetSecurityLevels(&cpc, CPSMACed, CPSMACed);
//CipurseCChannelSetSecurityLevels(&cpc, CPSPlain, CPSPlain); //CipurseCChannelSetSecurityLevels(&cpc, CPSPlain, CPSPlain);
memcpy(&cipurseContext, &cpc, sizeof(CipurseContext)); memcpy(&cipurseContext, &cpc, sizeof(CipurseContext));