mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-22 14:23:50 -07:00
iso select refactoring
This commit is contained in:
parent
5484cdb517
commit
72585aae8a
3 changed files with 32 additions and 5 deletions
|
@ -3080,7 +3080,10 @@ static int CmdHF14ADesSelectApp(const char *Cmd) {
|
|||
if (dctx.cmdSet == DCCISO || dfnamelen > 0) {
|
||||
uint8_t resp[250] = {0};
|
||||
size_t resplen = 0;
|
||||
res = DesfireISOSelect(&dctx, (char *)dfname, resp, &resplen);
|
||||
if (dfnamelen > 0)
|
||||
res = DesfireISOSelectDF(&dctx, (char *)dfname, resp, &resplen);
|
||||
else
|
||||
res = DesfireISOSelect(&dctx, ISSMFDFEF, NULL, 0, resp, &resplen);
|
||||
if (res != PM3_SUCCESS) {
|
||||
DropField();
|
||||
PrintAndLogEx(FAILED, "ISO Select application `%s` " _RED_("failed"), (char *)dfname);
|
||||
|
@ -3090,7 +3093,10 @@ static int CmdHF14ADesSelectApp(const char *Cmd) {
|
|||
if (resplen > 0)
|
||||
PrintAndLogEx(FAILED, "Application " _CYAN_("FCI template") " [%zu]%s", resplen, sprint_hex(resp, resplen));
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Application `%s` selected " _GREEN_("succesfully") " ", (char *)dfname);
|
||||
if (dfnamelen > 0)
|
||||
PrintAndLogEx(SUCCESS, "Application `%s` selected " _GREEN_("succesfully"), (char *)dfname);
|
||||
else
|
||||
PrintAndLogEx(SUCCESS, "PICC MF selected " _GREEN_("succesfully"));
|
||||
} else {
|
||||
res = DesfireSelectAndAuthenticateEx(&dctx, securechann, appid, true, verbose);
|
||||
if (res != PM3_SUCCESS) {
|
||||
|
|
|
@ -2218,15 +2218,26 @@ int DesfireSetConfiguration(DesfireContext *dctx, uint8_t paramid, uint8_t *para
|
|||
return res;
|
||||
}
|
||||
|
||||
int DesfireISOSelect(DesfireContext *dctx, char *dfname, uint8_t *resp, size_t *resplen) {
|
||||
int DesfireISOSelect(DesfireContext *dctx, DesfireISOSelectControl cntr, uint8_t *data, uint8_t datalen, uint8_t *resp, size_t *resplen) {
|
||||
uint8_t xresp[250] = {0};
|
||||
size_t xresplen = 0;
|
||||
uint16_t sw = 0;
|
||||
int res = DesfireExchangeISO(true, dctx, (sAPDU) {0x00, ISO7816_SELECT_FILE, 0x04, 0x00, strnlen(dfname, 16), (uint8_t *)dfname}, APDU_INCLUDE_LE_00, resp, resplen, &sw);
|
||||
int res = DesfireExchangeISO(true, dctx, (sAPDU) {0x00, ISO7816_SELECT_FILE, cntr, ((resp == NULL) ? 0x0C : 0x00), datalen, data}, APDU_INCLUDE_LE_00, xresp, &xresplen, &sw);
|
||||
if (res == PM3_SUCCESS && sw != 0x9000)
|
||||
return PM3_ESOFT;
|
||||
|
||||
if (resp != NULL && resplen != NULL) {
|
||||
*resplen = xresplen;
|
||||
memcpy(resp, xresp, xresplen);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int DesfireISOSelectDF(DesfireContext *dctx, char *dfname, uint8_t *resp, size_t *resplen) {
|
||||
return DesfireISOSelect(dctx, ISSDFName, (uint8_t *)dfname, strnlen(dfname, 16), resp, resplen);
|
||||
}
|
||||
|
||||
int DesfireISOGetChallenge(DesfireContext *dctx, DesfireCryptoAlgorythm keytype, uint8_t *resp, size_t *resplen) {
|
||||
uint16_t sw = 0;
|
||||
int res = DesfireExchangeISO(false, dctx, (sAPDU) {0x00, ISO7816_GET_CHALLENGE, 0x00, 0x00, 0x00, NULL}, DesfireGetRndLenForKey(keytype), resp, resplen, &sw);
|
||||
|
|
|
@ -21,6 +21,15 @@
|
|||
|
||||
#define DESFIRE_TX_FRAME_MAX_LEN 54
|
||||
|
||||
enum DesfireISOSelectControlEnum {
|
||||
ISSMFDFEF = 0x00,
|
||||
ISSChildDF = 0x01,
|
||||
ISSEFByFileID = 0x02,
|
||||
ISSParentDF = 0x03,
|
||||
ISSDFName = 0x04
|
||||
};
|
||||
typedef enum DesfireISOSelectControlEnum DesfireISOSelectControl;
|
||||
|
||||
typedef struct {
|
||||
const uint8_t id;
|
||||
const char *text;
|
||||
|
@ -167,7 +176,8 @@ int DesfireReadRecords(DesfireContext *dctx, uint8_t fnum, uint32_t recnum, uint
|
|||
int DesfireWriteRecord(DesfireContext *dctx, uint8_t fnum, uint32_t offset, uint32_t len, uint8_t *data);
|
||||
int DesfireUpdateRecord(DesfireContext *dctx, uint8_t fnum, uint32_t recnum, uint32_t offset, uint32_t len, uint8_t *data);
|
||||
|
||||
int DesfireISOSelect(DesfireContext *dctx, char *dfname, uint8_t *resp, size_t *resplen);
|
||||
int DesfireISOSelectDF(DesfireContext *dctx, char *dfname, uint8_t *resp, size_t *resplen);
|
||||
int DesfireISOSelect(DesfireContext *dctx, DesfireISOSelectControl cntr, uint8_t *data, uint8_t datalen, uint8_t *resp, size_t *resplen);
|
||||
int DesfireISOGetChallenge(DesfireContext *dctx, DesfireCryptoAlgorythm keytype, uint8_t *resp, size_t *resplen);
|
||||
int DesfireISOExternalAuth(DesfireContext *dctx, bool app_level, uint8_t keynum, DesfireCryptoAlgorythm keytype, uint8_t *data);
|
||||
int DesfireISOInternalAuth(DesfireContext *dctx, bool app_level, uint8_t keynum, DesfireCryptoAlgorythm keytype, uint8_t *data, uint8_t *resp, size_t *resplen);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue