mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 13:53:55 -07:00
hf iclass chk - now uses NG
This commit is contained in:
parent
305903c513
commit
cd9090b6c8
8 changed files with 96 additions and 68 deletions
|
@ -1695,14 +1695,14 @@ static void PacketReceived(PacketCommandNG *packet) {
|
|||
break;
|
||||
}
|
||||
case CMD_HF_ICLASS_CHKKEYS: {
|
||||
iClass_Authentication_fast(packet->oldarg[0], packet->oldarg[1], packet->data.asBytes);
|
||||
iClass_Authentication_fast((iclass_chk_t*)packet->data.asBytes);
|
||||
break;
|
||||
}
|
||||
case CMD_HF_ICLASS_DUMP: {
|
||||
iClass_Dump(packet->data.asBytes);
|
||||
break;
|
||||
}
|
||||
case CMD_HF_ICLASS_RESTORE: {
|
||||
case CMD_HF_ICLASS_RESTORE: {
|
||||
iClass_Restore((iclass_restore_req_t *)packet->data.asBytes);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1512,9 +1512,6 @@ bool authenticate_iclass_tag(iclass_auth_req_t *payload, picopass_hdr_t *hdr, ui
|
|||
return iclass_send_cmd_with_retries(cmd_check, sizeof(cmd_check), resp_auth, sizeof(resp_auth), 4, 2, start_time, ICLASS_READER_TIMEOUT_OTHERS, eof_time);
|
||||
}
|
||||
|
||||
typedef struct iclass_premac {
|
||||
uint8_t mac[4];
|
||||
} iclass_premac_t;
|
||||
|
||||
/* this function works on the following assumptions.
|
||||
* - one select first, to get CSN / CC (e-purse)
|
||||
|
@ -1523,36 +1520,35 @@ typedef struct iclass_premac {
|
|||
* - key loop only test one type of authtication key. Ie two calls needed
|
||||
* to cover debit and credit key. (AA1/AA2)
|
||||
*/
|
||||
void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) {
|
||||
|
||||
// uint8_t lastChunk = ((arg0 >> 8) & 0xFF);
|
||||
bool use_credit_key = ((arg0 >> 16) & 0xFF);
|
||||
uint8_t keyCount = arg1 & 0xFF;
|
||||
void iClass_Authentication_fast(iclass_chk_t *p) {
|
||||
// sanitation
|
||||
if (p == NULL) {
|
||||
reply_ng(CMD_HF_ICLASS_CHKKEYS, PM3_ESOFT, NULL, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t check[9] = { ICLASS_CMD_CHECK };
|
||||
uint8_t resp[ICLASS_BUFFER_SIZE] = {0};
|
||||
uint8_t readcheck_cc[] = { 0x80 | ICLASS_CMD_READCHECK, 0x02 };
|
||||
|
||||
if (use_credit_key)
|
||||
if (p->use_credit_key)
|
||||
readcheck_cc[0] = 0x10 | ICLASS_CMD_READCHECK;
|
||||
|
||||
// select card / e-purse
|
||||
picopass_hdr_t hdr = {0};
|
||||
|
||||
iclass_premac_t *keys = (iclass_premac_t *)datain;
|
||||
iclass_premac_t *keys = p->items;
|
||||
|
||||
LED_A_ON();
|
||||
|
||||
// fresh start
|
||||
switch_off();
|
||||
SpinDelay(20);
|
||||
|
||||
Iso15693InitReader();
|
||||
|
||||
bool isOK = false;
|
||||
|
||||
uint32_t start_time = 0, eof_time = 0;
|
||||
if (select_iclass_tag(&hdr, use_credit_key, &eof_time) == false)
|
||||
if (select_iclass_tag(&hdr, p->use_credit_key, &eof_time) == false)
|
||||
goto out;
|
||||
|
||||
start_time = eof_time + DELAY_ICLASS_VICC_TO_VCD_READER;
|
||||
|
@ -1562,7 +1558,7 @@ void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain) {
|
|||
|
||||
// Keychunk loop
|
||||
uint8_t i = 0;
|
||||
for (i = 0; i < keyCount; i++) {
|
||||
for (i = 0; i < p->count; i++) {
|
||||
|
||||
// Allow button press / usb cmd to interrupt device
|
||||
if (checked == 1000) {
|
||||
|
|
|
@ -28,7 +28,7 @@ int do_iclass_simulation(int simulationMode, uint8_t *reader_mac_buf);
|
|||
void SimulateIClass(uint32_t arg0, uint32_t arg1, uint32_t arg2, uint8_t *datain);
|
||||
void iclass_simulate(uint8_t sim_type, uint8_t num_csns, bool send_reply, uint8_t *datain, uint8_t *dataout, uint16_t *dataoutlen);
|
||||
|
||||
void iClass_Authentication_fast(uint64_t arg0, uint64_t arg1, uint8_t *datain);
|
||||
void iClass_Authentication_fast(iclass_chk_t *p);
|
||||
bool iclass_auth(iclass_auth_req_t *payload, uint8_t *out);
|
||||
|
||||
void iClass_ReadBlock(uint8_t *msg);
|
||||
|
|
|
@ -449,19 +449,10 @@ static bool MifareSimInit(uint16_t flags, uint8_t *datain, uint16_t atqa, uint8_
|
|||
void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint16_t atqa, uint8_t sak) {
|
||||
tag_response_info_t *responses;
|
||||
uint8_t cardSTATE = MFEMUL_NOFIELD;
|
||||
uint8_t uid_len = 0; // 4,7, 10
|
||||
uint32_t cuid = 0;
|
||||
|
||||
// int vHf = 0; // in mV
|
||||
|
||||
uint32_t selTimer = 0;
|
||||
uint32_t authTimer = 0;
|
||||
|
||||
uint8_t uid_len = 0; // 4, 7, 10
|
||||
uint32_t cuid = 0, selTimer = 0, authTimer = 0;
|
||||
uint32_t nr, ar;
|
||||
uint8_t blockNo;
|
||||
|
||||
uint32_t nr;
|
||||
uint32_t ar;
|
||||
|
||||
bool encrypted_data;
|
||||
|
||||
uint8_t cardWRBL = 0;
|
||||
|
@ -469,9 +460,9 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
|||
uint8_t cardAUTHKEY = AUTHKEYNONE; // no authentication
|
||||
uint32_t cardRr = 0;
|
||||
uint32_t ans = 0;
|
||||
|
||||
uint32_t cardINTREG = 0;
|
||||
uint8_t cardINTBLOCK = 0;
|
||||
|
||||
struct Crypto1State mpcs = {0, 0};
|
||||
struct Crypto1State *pcs;
|
||||
pcs = &mpcs;
|
||||
|
@ -849,7 +840,8 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
|||
EmSend4bit(mf_crypto1_encrypt4bit(pcs, CARD_NACK_NA));
|
||||
FpgaDisableTracing();
|
||||
|
||||
if (DBGLEVEL >= DBG_ERROR) Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on block (0x%02x) not authenticated for (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], cardAUTHSC);
|
||||
if (DBGLEVEL >= DBG_ERROR)
|
||||
Dbprintf("[MFEMUL_WORK] Reader tried to operate (0x%02x) on block (0x%02x) not authenticated for (0x%02x), nacking", receivedCmd_dec[0], receivedCmd_dec[1], cardAUTHSC);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -883,20 +875,20 @@ void Mifare1ksim(uint16_t flags, uint8_t exitAfterNReads, uint8_t *datain, uint1
|
|||
// Check if selected Block is a Sector Trailer
|
||||
if (IsSectorTrailer(blockNo)) {
|
||||
|
||||
if (!IsAccessAllowed(blockNo, cardAUTHKEY, AC_KEYA_READ)) {
|
||||
if (IsAccessAllowed(blockNo, cardAUTHKEY, AC_KEYA_READ) == false) {
|
||||
memset(response, 0x00, 6); // keyA can never be read
|
||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsSectorTrailer] keyA can never be read - block %d (0x%02x)", blockNo, blockNo);
|
||||
}
|
||||
if (!IsAccessAllowed(blockNo, cardAUTHKEY, AC_KEYB_READ)) {
|
||||
if (IsAccessAllowed(blockNo, cardAUTHKEY, AC_KEYB_READ) == false) {
|
||||
memset(response + 10, 0x00, 6); // keyB cannot be read
|
||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsSectorTrailer] keyB cannot be read - block %d (0x%02x)", blockNo, blockNo);
|
||||
}
|
||||
if (!IsAccessAllowed(blockNo, cardAUTHKEY, AC_AC_READ)) {
|
||||
if (IsAccessAllowed(blockNo, cardAUTHKEY, AC_AC_READ) == false) {
|
||||
memset(response + 6, 0x00, 4); // AC bits cannot be read
|
||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsAccessAllowed] AC bits cannot be read - block %d (0x%02x)", blockNo, blockNo);
|
||||
}
|
||||
} else {
|
||||
if (!IsAccessAllowed(blockNo, cardAUTHKEY, AC_DATA_READ)) {
|
||||
if (IsAccessAllowed(blockNo, cardAUTHKEY, AC_DATA_READ) == false) {
|
||||
memset(response, 0x00, 16); // datablock cannot be read
|
||||
if (DBGLEVEL >= DBG_EXTENDED) Dbprintf("[MFEMUL_WORK - IsAccessAllowed] Data block %d (0x%02x) cannot be read", blockNo, blockNo);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue