Minor fixes, styles adaption

This commit is contained in:
Bjoern Kerler 2020-04-05 00:07:05 +02:00
commit 99838b958e

View file

@ -38,23 +38,25 @@ typedef enum {
static int CmdHelp(const char *Cmd); static int CmdHelp(const char *Cmd);
static int SendDesfireCmd(uint8_t* c, int len, int flags, PacketResponseNG* response, int timeout)
{ static int SendDesfireCmd(uint8_t *c, size_t len, int p0, int p1, int p2, PacketResponseNG *response, int timeout) {
PacketResponseNG resp; PacketResponseNG resp;
if (response == NULL) if (response == NULL)
response = &resp; response = &resp;
SendCommandMIX(CMD_HF_DESFIRE_COMMAND, flags , len, 0, c, len); clearCommandBuffer();
SendCommandMIX(CMD_HF_DESFIRE_COMMAND, p0, p1, p2, c, len);
if (!WaitForResponseTimeout(CMD_ACK, response, timeout)) { if (!WaitForResponseTimeout(CMD_ACK, response, timeout)) {
PrintAndLogEx(WARNING, "[SendDesfireCmd] Timed-out: " _RED_("%s"), sprint_hex(c,sizeof(c))); PrintAndLogEx(WARNING, "[SendDesfireCmd] Timed-out: " _RED_("%s"), sprint_hex(c, len));
DropField(); DropField();
return PM3_ETIMEOUT; return PM3_ETIMEOUT;
} }
uint8_t isOK = response->oldarg[0] & 0xff; uint8_t isOK = response->data.asBytes[0] & 0xff;
if (!isOK) { if (!isOK) {
PrintAndLogEx(WARNING, "[SendDesfireCmd] Unsuccessful: " _RED_("%s"), sprint_hex(c,sizeof(c))); PrintAndLogEx(WARNING, "[SendDesfireCmd] Unsuccessful: " _RED_("%s"), sprint_hex(c, len));
return PM3_ESOFT; return PM3_ESOFT;
} }
return PM3_SUCCESS; return PM3_SUCCESS;
@ -168,7 +170,7 @@ static int desfire_print_signature(uint8_t *uid, uint8_t *signature, size_t sign
int res; int res;
bool is_valid = false; bool is_valid = false;
for (i = 0; i< ARRAYLEN(nxp_desfire_public_keys); i++) { for (i = 0; i < ARRAYLEN(nxp_desfire_public_keys); i++) {
int dl = 0; int dl = 0;
uint8_t key[PUBLIC_DESFIRE_ECDA_KEYLEN]; uint8_t key[PUBLIC_DESFIRE_ECDA_KEYLEN];
@ -184,7 +186,7 @@ static int desfire_print_signature(uint8_t *uid, uint8_t *signature, size_t sign
return PM3_ESOFT; return PM3_ESOFT;
} }
PrintAndLogEx(NORMAL,""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "--- " _CYAN_("Tag Signature")); PrintAndLogEx(INFO, "--- " _CYAN_("Tag Signature"));
PrintAndLogEx(INFO, " IC signature public key name: %s", nxp_desfire_public_keys[i].desc); PrintAndLogEx(INFO, " IC signature public key name: %s", nxp_desfire_public_keys[i].desc);
PrintAndLogEx(INFO, "IC signature public key value: %.32s", nxp_desfire_public_keys[i].value); PrintAndLogEx(INFO, "IC signature public key value: %.32s", nxp_desfire_public_keys[i].value);
@ -255,8 +257,8 @@ static int desfire_print_keysetting(uint8_t key_settings, uint8_t num_keys) {
static int get_desfire_keysettings(uint8_t *key_settings, uint8_t *num_keys) { static int get_desfire_keysettings(uint8_t *key_settings, uint8_t *num_keys) {
PacketResponseNG resp; PacketResponseNG resp;
uint8_t c[] = {MFDES_GET_KEY_SETTINGS, 0x00, 0x00, 0x00}; // 0x45 uint8_t c[] = {MFDES_GET_KEY_SETTINGS, 0x00, 0x00, 0x00}; // 0x45
int ret=SendDesfireCmd(c, sizeof(c), NONE, &resp, 1500); int ret = SendDesfireCmd(c, sizeof(c), NONE, sizeof(c), 0, &resp, 1500);
if (ret!=PM3_SUCCESS) return ret; if (ret != PM3_SUCCESS) return ret;
if (resp.data.asBytes[1] == 0x91 && resp.data.asBytes[2] == 0xae) { if (resp.data.asBytes[1] == 0x91 && resp.data.asBytes[2] == 0xae) {
PrintAndLogEx(WARNING, _RED_("[get_desfire_keysettings] Authentication error")); PrintAndLogEx(WARNING, _RED_("[get_desfire_keysettings] Authentication error"));
@ -278,10 +280,10 @@ static int desfire_print_keyversion(uint8_t key_idx, uint8_t key_version) {
static int get_desfire_keyversion(uint8_t curr_key, uint8_t *num_versions) { static int get_desfire_keyversion(uint8_t curr_key, uint8_t *num_versions) {
PacketResponseNG resp; PacketResponseNG resp;
uint8_t c[] = {MFDES_GET_KEY_VERSION, 0x00, 0x00, 0x01, curr_key, 0x00}; // 0x64 uint8_t c[] = {MFDES_GET_KEY_VERSION, 0x00, 0x00, 0x01, curr_key, 0x00}; // 0x64
int ret=SendDesfireCmd(c, sizeof(c), NONE, &resp, 1500); int ret = SendDesfireCmd(c, sizeof(c), NONE, sizeof(c), 0, &resp, 1500);
if (ret!=PM3_SUCCESS) return ret; if (ret != PM3_SUCCESS) return ret;
if ( resp.data.asBytes[1] == 0x91 && resp.data.asBytes[2] == 0x40) { if (resp.data.asBytes[1] == 0x91 && resp.data.asBytes[2] == 0x40) {
return PM3_ESOFT; return PM3_ESOFT;
} }
@ -296,11 +298,9 @@ static int get_desfire_select_application(uint8_t *aid) {
uint8_t c[] = {SELECT_APPLICATION, 0x00, 0x00, 0x03, aid[0], aid[1], aid[2], 0x00}; // 0x5a uint8_t c[] = {SELECT_APPLICATION, 0x00, 0x00, 0x03, aid[0], aid[1], aid[2], 0x00}; // 0x5a
PacketResponseNG resp; PacketResponseNG resp;
int ret=SendDesfireCmd(c, sizeof(c), INIT, &resp, 3000); int ret = SendDesfireCmd(c, sizeof(c), INIT, sizeof(c), 0, &resp, 3000);
if (ret!=PM3_SUCCESS) if (ret != PM3_SUCCESS) {
{ if (ret == PM3_ESOFT) {
if (ret==PM3_ESOFT)
{
PrintAndLogEx(WARNING, "[get_desfire_select_application] Can't select AID: " _RED_("%s"), sprint_hex(aid, 3)); PrintAndLogEx(WARNING, "[get_desfire_select_application] Can't select AID: " _RED_("%s"), sprint_hex(aid, 3));
} }
return ret; return ret;
@ -319,8 +319,8 @@ static int get_desfire_appids(uint8_t *dest, uint8_t *app_ids_len) {
uint8_t c[] = {GET_APPLICATION_IDS, 0x00, 0x00, 0x00}; //0x6a uint8_t c[] = {GET_APPLICATION_IDS, 0x00, 0x00, 0x00}; //0x6a
PacketResponseNG resp; PacketResponseNG resp;
int ret=SendDesfireCmd(c, sizeof(c), INIT | CLEARTRACE | DISCONNECT, &resp, 1500); int ret = SendDesfireCmd(c, sizeof(c), INIT | CLEARTRACE | DISCONNECT, sizeof(c), 0, &resp, 1500);
if (ret!=PM3_SUCCESS) return ret; if (ret != PM3_SUCCESS) return ret;
*app_ids_len = resp.length - 5; *app_ids_len = resp.length - 5;
@ -330,8 +330,8 @@ static int get_desfire_appids(uint8_t *dest, uint8_t *app_ids_len) {
if (resp.data.asBytes[resp.length - 3] == MFDES_ADDITIONAL_FRAME) { if (resp.data.asBytes[resp.length - 3] == MFDES_ADDITIONAL_FRAME) {
c[0] = MFDES_ADDITIONAL_FRAME; //0xAF c[0] = MFDES_ADDITIONAL_FRAME; //0xAF
ret=SendDesfireCmd(c, sizeof(c), NONE, &resp, 1500); ret = SendDesfireCmd(c, sizeof(c), NONE, sizeof(c), 0, &resp, 1500);
if (ret!=PM3_SUCCESS) return ret; if (ret != PM3_SUCCESS) return ret;
memcpy(dest + *app_ids_len, resp.data.asBytes + 1, resp.length - 5); memcpy(dest + *app_ids_len, resp.data.asBytes + 1, resp.length - 5);
@ -345,8 +345,8 @@ static int get_desfire_appids(uint8_t *dest, uint8_t *app_ids_len) {
static int get_desfire_fileids(uint8_t *dest, uint8_t *file_ids_len) { static int get_desfire_fileids(uint8_t *dest, uint8_t *file_ids_len) {
uint8_t c[] = {MFDES_GET_FILE_IDS, 0x00, 0x00, 0x00}; // 0x6f uint8_t c[] = {MFDES_GET_FILE_IDS, 0x00, 0x00, 0x00}; // 0x6f
PacketResponseNG resp; PacketResponseNG resp;
int ret=SendDesfireCmd(c, sizeof(c), NONE, &resp, 1500); int ret = SendDesfireCmd(c, sizeof(c), NONE, sizeof(c), 0, &resp, 1500);
if (ret!=PM3_SUCCESS) return ret; if (ret != PM3_SUCCESS) return ret;
if (resp.data.asBytes[resp.length - 4] == 0x91 && resp.data.asBytes[resp.length - 3] == 0x00) { if (resp.data.asBytes[resp.length - 4] == 0x91 && resp.data.asBytes[resp.length - 3] == 0x00) {
*file_ids_len = resp.length - 5; *file_ids_len = resp.length - 5;
@ -552,7 +552,7 @@ void getKeySettings(uint8_t *aid) {
uint8_t key_setting = 0; uint8_t key_setting = 0;
if (get_desfire_keysettings(&key_setting, &num_keys) == PM3_SUCCESS) { if (get_desfire_keysettings(&key_setting, &num_keys) == PM3_SUCCESS) {
// number of Master keys (0x01) // number of Master keys (0x01)
PrintAndLogEx(SUCCESS, " Number of Masterkeys : " _YELLOW_("%u"), (num_keys & 0x3F) ); PrintAndLogEx(SUCCESS, " Number of Masterkeys : " _YELLOW_("%u"), (num_keys & 0x3F));
PrintAndLogEx(SUCCESS, " [0x08] Configuration changeable : %s", (key_setting & (1 << 3)) ? _GREEN_("YES") : "NO"); PrintAndLogEx(SUCCESS, " [0x08] Configuration changeable : %s", (key_setting & (1 << 3)) ? _GREEN_("YES") : "NO");
PrintAndLogEx(SUCCESS, " [0x04] CMK required for create/delete : %s", (key_setting & (1 << 2)) ? _GREEN_("YES") : "NO"); PrintAndLogEx(SUCCESS, " [0x04] CMK required for create/delete : %s", (key_setting & (1 << 2)) ? _GREEN_("YES") : "NO");
@ -674,7 +674,7 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
aid[1] = app_ids[i + 1]; aid[1] = app_ids[i + 1];
aid[2] = app_ids[i + 2]; aid[2] = app_ids[i + 2];
PrintAndLogEx(SUCCESS, " AID %d : " _GREEN_("%02X %02X %02X"), i, app_ids[i], app_ids[i+1], app_ids[i+2]); PrintAndLogEx(SUCCESS, " AID %d : " _GREEN_("%02X %02X %02X"), i, app_ids[i], app_ids[i + 1], app_ids[i + 2]);
getKeySettings(aid); getKeySettings(aid);
@ -686,7 +686,7 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
} }
} }
/* /*
// Get ISO File IDs // Get ISO File IDs
{ {
uint8_t data[] = {GET_ISOFILE_IDS, 0x00, 0x00, 0x00}; // 0x61 uint8_t data[] = {GET_ISOFILE_IDS, 0x00, 0x00, 0x00}; // 0x61