Merge branch 'RfidResearchGroup:master' into feature/hrt_parser
This commit is contained in:
11 files changed
+430
-40
No files matched your search
@@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.
|
||||
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...
|
||||
|
||||
## [unreleased][unreleased]
|
||||
- Add support for Innovatron protocol detection to `hf 14b info` (@kormax)
|
||||
- Improved `lf cotag reader` and `lf cotag demod`: Reimplementation and enhancement of proxmark3 COTAG support
|
||||
- Added `hf felica sim` command (@kormax)
|
||||
- Added `mad read`, `mad write`, `mad verify`, `mad decode`, `mad encode` commands with typed struct MAD API (@AlxCzl)
|
||||
|
||||
+98
-1
@@ -1440,7 +1440,13 @@ static int Get14443bAnswerFromTag(uint8_t *response, uint16_t max_len, uint32_t
|
||||
|
||||
if (Handle14443bSamplesFromTag(ci, cq)) {
|
||||
|
||||
*eof_time = GetCountSspClkDelta(dma_start_time) - DELAY_TAG_TO_ARM; // end of EOF
|
||||
// Response timing is measured from DMA start, but trace rows use
|
||||
// absolute SSP time like reader frames.
|
||||
uint32_t eof_delta = GetCountSspClkDelta(dma_start_time);
|
||||
if (eof_delta > DELAY_TAG_TO_ARM) {
|
||||
eof_delta -= DELAY_TAG_TO_ARM;
|
||||
}
|
||||
*eof_time = dma_start_time + eof_delta; // end of EOF
|
||||
|
||||
if (Demod.len > Demod.max_len) {
|
||||
ret = PM3_EOVFLOW;
|
||||
@@ -1919,6 +1925,88 @@ int iso14443b_select_srx_card(iso14b_card_select_t *card) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Type B' / Innovatron APGEN.
|
||||
*/
|
||||
static int iso14443b_select_prime_card(iso14b_prime_card_select_t *card) {
|
||||
uint8_t apgen[] = {
|
||||
ISO14443B_PRIME_VT_ADDR_DEFAULT,
|
||||
ISO14443B_PRIME_CMD_APGEN,
|
||||
// Seems to affect time slots / response chance:
|
||||
// 0x3f card responds every time
|
||||
// 0x3e-0x00 reduced success rate
|
||||
// 0x40-0xff card does not respond
|
||||
0x3f,
|
||||
ISO14443B_PRIME_REQUEST_EXTENDED_REPGEN,
|
||||
0x00,
|
||||
0x00
|
||||
};
|
||||
uint8_t r_repgen[PM3_CMD_DATA_SIZE] = { 0x00 };
|
||||
|
||||
AddCrc14B(apgen, sizeof(apgen) - 2);
|
||||
|
||||
uint32_t start_time = 0;
|
||||
uint32_t eof_time = 0;
|
||||
CodeAndTransmit14443bAsReader(apgen, sizeof(apgen), &start_time, &eof_time, true);
|
||||
|
||||
eof_time += DELAY_ISO14443B_PCD_TO_PICC_READER;
|
||||
uint16_t retlen = 0;
|
||||
if (Get14443bAnswerFromTag(r_repgen, sizeof(r_repgen), s_iso14b_timeout, &eof_time, &retlen) != PM3_SUCCESS) {
|
||||
return PM3_ECARDEXCHANGE;
|
||||
}
|
||||
|
||||
// REPGEN carries V&T address, REPGEN command, DIV, VerLog, then CRC.
|
||||
if (retlen < 9) {
|
||||
return PM3_ELENGTH;
|
||||
}
|
||||
|
||||
if (check_crc(CRC_14443_B, r_repgen, retlen) == false) {
|
||||
return PM3_ECRC;
|
||||
}
|
||||
|
||||
const uint16_t repgen_len = retlen - 2;
|
||||
if (r_repgen[0] != apgen[0] || r_repgen[1] != ISO14443B_PRIME_CMD_REPGEN) {
|
||||
return PM3_EWRONGANSWER;
|
||||
}
|
||||
|
||||
if (card) {
|
||||
card->vt_addr = r_repgen[0];
|
||||
card->repgen_cmd = r_repgen[1];
|
||||
memcpy(card->div, r_repgen + 2, sizeof(card->div));
|
||||
card->verlog = r_repgen[6];
|
||||
|
||||
uint16_t offset = 7;
|
||||
if ((card->verlog & 0x80) && repgen_len > offset) {
|
||||
card->config = r_repgen[offset++];
|
||||
if ((card->config & 0x40) && repgen_len > offset) {
|
||||
uint16_t atr_len = repgen_len - offset;
|
||||
if (atr_len >= 2 && r_repgen[repgen_len - 2] == 0x90 && r_repgen[repgen_len - 1] == 0x00) {
|
||||
atr_len -= 2;
|
||||
}
|
||||
card->atr_len = (uint8_t)MIN(atr_len, ISO14B_PRIME_ATR_MAX_LEN);
|
||||
memcpy(card->atr, r_repgen + offset, card->atr_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t attrib[] = {
|
||||
r_repgen[0],
|
||||
ISO14443B_PRIME_CMD_ATTRIB,
|
||||
r_repgen[2],
|
||||
r_repgen[3],
|
||||
r_repgen[4],
|
||||
r_repgen[5],
|
||||
0x00,
|
||||
0x00,
|
||||
};
|
||||
AddCrc14B(attrib, sizeof(attrib) - 2);
|
||||
start_time = eof_time + ISO14B_TR2;
|
||||
CodeAndTransmit14443bAsReader(attrib, sizeof(attrib), &start_time, &eof_time, true);
|
||||
|
||||
s_iso14b_pcb_blocknum = 0;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// Xerox tag connect function: wup, anticoll, attrib, password
|
||||
// the original chips require all commands in this sequence
|
||||
|
||||
@@ -3148,6 +3236,15 @@ void SendRawCommand14443B(iso14b_raw_cmd_t *p) {
|
||||
if (status != PM3_SUCCESS) goto out;
|
||||
}
|
||||
|
||||
if ((p->flags & ISO14B_SELECT_PRIME) == ISO14B_SELECT_PRIME) {
|
||||
iso14b_prime_card_select_t *prime = (iso14b_prime_card_select_t *)buf;
|
||||
memset(prime, 0, sizeof(iso14b_prime_card_select_t));
|
||||
sendlen = sizeof(iso14b_prime_card_select_t);
|
||||
status = iso14443b_select_prime_card(prime);
|
||||
reply_ng(CMD_HF_ISO14443B_COMMAND, status, (uint8_t *)prime, sendlen);
|
||||
if (status != PM3_SUCCESS) goto out;
|
||||
}
|
||||
|
||||
// if field is off...
|
||||
if (
|
||||
((p->flags & ISO14B_APDU) == ISO14B_APDU) ||
|
||||
|
||||
@@ -61,6 +61,8 @@
|
||||
|
||||
// iso14b apdu input frame length
|
||||
static uint16_t apdu_frame_length = 0;
|
||||
static uint8_t prime_vt_addr = ISO14443B_PRIME_VT_ADDR_DEFAULT;
|
||||
static uint8_t prime_com_ra_cmd = ISO14443B_PRIME_COM_RA_START;
|
||||
//static uint16_t ats_fsc[] = {16, 24, 32, 40, 48, 64, 96, 128, 256};
|
||||
static bool apdu_in_framing_enable = true;
|
||||
|
||||
@@ -767,6 +769,22 @@ static void print_ct_general_info(void *vcard) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
}
|
||||
|
||||
static void print_prime_general_info(const iso14b_prime_card_select_t *card) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("Type B' / Innovatron") " ---------------------");
|
||||
PrintAndLogEx(SUCCESS, " V&T Ad : %02X", card->vt_addr);
|
||||
PrintAndLogEx(SUCCESS, " Cmd : %02X (REPGEN)", card->repgen_cmd);
|
||||
PrintAndLogEx(SUCCESS, " DIV : " _GREEN_("%s"), sprint_hex(card->div, sizeof(card->div)));
|
||||
PrintAndLogEx(SUCCESS, " VerLog : %02X", card->verlog);
|
||||
if (card->verlog & 0x80) {
|
||||
PrintAndLogEx(SUCCESS, " Config : %02X", card->config);
|
||||
}
|
||||
if (card->atr_len) {
|
||||
PrintAndLogEx(SUCCESS, " ATR : %s", sprint_hex(card->atr, card->atr_len));
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
}
|
||||
|
||||
static void print_hdr(void) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, " block# | data |lck| ascii");
|
||||
@@ -1323,6 +1341,71 @@ static bool HF14B_ST_Info(bool verbose, bool do_aid_search) {
|
||||
return true;
|
||||
}
|
||||
|
||||
int select_card_14443b_prime(bool disconnect, iso14b_prime_card_select_t *card, bool verbose) {
|
||||
|
||||
iso14b_raw_cmd_t packet = {
|
||||
.flags = (ISO14B_CONNECT | ISO14B_SELECT_PRIME | ISO14B_CLEARTRACE),
|
||||
.timeout = 0,
|
||||
.rawlen = 0,
|
||||
};
|
||||
|
||||
if (disconnect) {
|
||||
packet.flags |= ISO14B_DISCONNECT;
|
||||
}
|
||||
|
||||
clearCommandBuffer();
|
||||
PacketResponseNG resp;
|
||||
SendCommandNG(CMD_HF_ISO14443B_COMMAND, (uint8_t *)&packet, sizeof(iso14b_raw_cmd_t));
|
||||
if (WaitForResponseTimeout(CMD_HF_ISO14443B_COMMAND, &resp, TIMEOUT) == false) {
|
||||
if (verbose) {
|
||||
PrintAndLogEx(WARNING, "timeout while waiting for reply");
|
||||
}
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
switch (resp.status) {
|
||||
case PM3_SUCCESS: {
|
||||
if (resp.length < sizeof(iso14b_prime_card_select_t)) {
|
||||
if (verbose) {
|
||||
PrintAndLogEx(FAILED, "ISO 14443-B' card select response too short (%u bytes)", resp.length);
|
||||
}
|
||||
return PM3_ELENGTH;
|
||||
}
|
||||
|
||||
iso14b_prime_card_select_t selected = {0};
|
||||
memcpy(&selected, resp.data.asBytes, sizeof(selected));
|
||||
if (selected.repgen_cmd != ISO14443B_PRIME_CMD_REPGEN || selected.atr_len > sizeof(selected.atr)) {
|
||||
if (verbose) {
|
||||
PrintAndLogEx(FAILED, "ISO 14443-B' invalid card select response");
|
||||
}
|
||||
return PM3_EWRONGANSWER;
|
||||
}
|
||||
|
||||
prime_vt_addr = selected.vt_addr;
|
||||
prime_com_ra_cmd = ISO14443B_PRIME_COM_RA_START;
|
||||
SetISODEPState(disconnect ? ISODEP_INACTIVE : ISODEP_NFCB_PRIME);
|
||||
if (card) {
|
||||
*card = selected;
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
case PM3_ELENGTH:
|
||||
if (verbose) PrintAndLogEx(FAILED, "ISO 14443-B' REPGEN wrong length");
|
||||
break;
|
||||
case PM3_ECRC:
|
||||
if (verbose) PrintAndLogEx(FAILED, "ISO 14443-B' REPGEN CRC fail");
|
||||
break;
|
||||
case PM3_EWRONGANSWER:
|
||||
if (verbose) PrintAndLogEx(FAILED, "ISO 14443-B' REPGEN wrong answer");
|
||||
break;
|
||||
default:
|
||||
if (verbose) PrintAndLogEx(FAILED, "ISO 14443-B' APGEN failed");
|
||||
break;
|
||||
}
|
||||
|
||||
return resp.status;
|
||||
}
|
||||
|
||||
// menu command to get and print all info known about any known 14b tag
|
||||
static int CmdHF14Binfo(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
@@ -1580,6 +1663,16 @@ static bool HF14B_picopass_reader(bool verbose) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool HF14B_prime_reader(bool verbose) {
|
||||
|
||||
iso14b_prime_card_select_t card = {0};
|
||||
if (select_card_14443b_prime(true, &card, verbose) != PM3_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
print_prime_general_info(&card);
|
||||
return true;
|
||||
}
|
||||
|
||||
// test for other 14b type tags (mimic another reader - don't have tags to identify)
|
||||
static bool HF14B_other_reader(bool verbose) {
|
||||
|
||||
@@ -2514,6 +2607,118 @@ int exchange_14b_apdu(uint8_t *datain, int datainlen, bool activate_field,
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static uint8_t next_prime_com_ra_cmd(uint8_t cmd) {
|
||||
return (cmd + 0x02) & 0x0F;
|
||||
}
|
||||
|
||||
int exchange_14b_prime_apdu(uint8_t *datain, int datainlen, bool activate_field,
|
||||
bool leave_signal_on, uint8_t *dataout, int maxdataoutlen,
|
||||
int *dataoutlen, int user_timeout) {
|
||||
|
||||
if (dataoutlen == NULL || dataout == NULL || datainlen < 0 || datainlen > 0xFE || (datain == NULL && datainlen > 0)) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
*dataoutlen = 0;
|
||||
|
||||
if (activate_field) {
|
||||
int selres = select_card_14443b_prime(false, NULL, false);
|
||||
if (selres != PM3_SUCCESS) {
|
||||
return selres;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t frame[PM3_CMD_DATA_SIZE] = {0};
|
||||
const uint16_t frame_len = (uint16_t)datainlen + 3;
|
||||
if (frame_len > sizeof(frame)) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
frame[0] = prime_vt_addr;
|
||||
frame[1] = prime_com_ra_cmd;
|
||||
frame[2] = (uint8_t)datainlen + 1;
|
||||
if (datainlen > 0) {
|
||||
memcpy(frame + 3, datain, datainlen);
|
||||
}
|
||||
|
||||
uint32_t flags = ISO14B_RAW | ISO14B_APPEND_CRC;
|
||||
uint32_t timeout = 0;
|
||||
if (user_timeout > 0) {
|
||||
flags |= ISO14B_SET_TIMEOUT;
|
||||
if (user_timeout > MAX_14B_TIMEOUT_MS) {
|
||||
user_timeout = MAX_14B_TIMEOUT_MS;
|
||||
PrintAndLogEx(INFO, "set timeout to 4.9 seconds. The max we can wait for response");
|
||||
}
|
||||
timeout = (uint32_t)((13560 / 128) * user_timeout);
|
||||
}
|
||||
|
||||
iso14b_raw_cmd_t *packet = (iso14b_raw_cmd_t *)calloc(1, sizeof(iso14b_raw_cmd_t) + frame_len);
|
||||
if (packet == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
packet->flags = flags;
|
||||
packet->timeout = timeout;
|
||||
packet->rawlen = frame_len;
|
||||
memcpy(packet->raw, frame, frame_len);
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_ISO14443B_COMMAND, (uint8_t *)packet, sizeof(iso14b_raw_cmd_t) + packet->rawlen);
|
||||
free(packet);
|
||||
|
||||
PacketResponseNG resp;
|
||||
if (WaitForResponseTimeout(CMD_HF_ISO14443B_COMMAND, &resp, MAX(APDU_TIMEOUT, user_timeout)) == false) {
|
||||
if (leave_signal_on == false) {
|
||||
switch_off_field_14b();
|
||||
}
|
||||
PrintAndLogEx(ERR, "APDU: reply timeout");
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
if (resp.status != PM3_SUCCESS) {
|
||||
if (leave_signal_on == false) {
|
||||
switch_off_field_14b();
|
||||
}
|
||||
PrintAndLogEx(ERR, "APDU: no Type B' APDU response");
|
||||
return resp.status;
|
||||
}
|
||||
|
||||
const uint8_t *rx = resp.data.asBytes;
|
||||
if (resp.length < 5 || check_crc(CRC_14443_B, rx, resp.length) == false) {
|
||||
if (leave_signal_on == false) {
|
||||
switch_off_field_14b();
|
||||
}
|
||||
return PM3_ECRC;
|
||||
}
|
||||
|
||||
const uint8_t rx_len = rx[2];
|
||||
if (rx[0] != prime_vt_addr || (rx[1] & 0x01) || rx_len == 0 || resp.length < (uint16_t)rx_len + 4) {
|
||||
if (leave_signal_on == false) {
|
||||
switch_off_field_14b();
|
||||
}
|
||||
return PM3_EWRONGANSWER;
|
||||
}
|
||||
|
||||
const int apdu_len = rx_len - 1;
|
||||
if (maxdataoutlen && apdu_len > maxdataoutlen) {
|
||||
if (leave_signal_on == false) {
|
||||
switch_off_field_14b();
|
||||
}
|
||||
PrintAndLogEx(ERR, "APDU: buffer too small ( " _RED_("%d") " ), needs " _YELLOW_("%d") " bytes", maxdataoutlen, apdu_len);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
memcpy(dataout, rx + 3, apdu_len);
|
||||
*dataoutlen = apdu_len;
|
||||
prime_com_ra_cmd = next_prime_com_ra_cmd(prime_com_ra_cmd);
|
||||
|
||||
if (leave_signal_on == false) {
|
||||
switch_off_field_14b();
|
||||
}
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// ISO14443-4. 7. Half-duplex block transmission protocol
|
||||
static int CmdHF14BAPDU(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
@@ -3169,6 +3374,10 @@ int infoHF14B(bool verbose, bool do_aid_search) {
|
||||
if (HF14B_ST_Info(verbose, do_aid_search))
|
||||
return PM3_SUCCESS;
|
||||
|
||||
// try Type B' / Innovatron APGEN
|
||||
if (HF14B_prime_reader(verbose))
|
||||
return PM3_SUCCESS;
|
||||
|
||||
// try unknown 14b read commands (to be identified later)
|
||||
// could be read of calypso, CEPAS, moneo, or pico pass.
|
||||
if (verbose) {
|
||||
@@ -3204,6 +3413,11 @@ int readHF14B(bool loop, bool verbose, bool read_plot) {
|
||||
if (found)
|
||||
goto plot;
|
||||
|
||||
// try Type B' / Innovatron APGEN
|
||||
found |= HF14B_prime_reader(verbose);
|
||||
if (found)
|
||||
goto plot;
|
||||
|
||||
// try unknown 14b read commands (to be identified later)
|
||||
// could be read of calypso, CEPAS, moneo, or pico pass.
|
||||
found |= HF14B_other_reader(verbose);
|
||||
|
||||
@@ -27,7 +27,9 @@ int CmdHF14BNdefRead(const char *Cmd);
|
||||
|
||||
uint8_t *get_uid_from_filename(const char *filename);
|
||||
int exchange_14b_apdu(uint8_t *datain, int datainlen, bool activate_field, bool leave_signal_on, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, int user_timeout);
|
||||
int exchange_14b_prime_apdu(uint8_t *datain, int datainlen, bool activate_field, bool leave_signal_on, uint8_t *dataout, int maxdataoutlen, int *dataoutlen, int user_timeout);
|
||||
int select_card_14443b_4(bool disconnect, iso14b_card_select_t *card);
|
||||
int select_card_14443b_prime(bool disconnect, iso14b_prime_card_select_t *card, bool verbose);
|
||||
|
||||
int infoHF14B(bool verbose, bool do_aid_search);
|
||||
int readHF14B(bool loop, bool verbose, bool read_plot);
|
||||
|
||||
@@ -131,6 +131,8 @@ typedef struct {
|
||||
iso14a_card_select_t card_a;
|
||||
bool has_14b;
|
||||
iso14b_card_select_t card_b;
|
||||
bool has_prime;
|
||||
iso14b_prime_card_select_t card_prime;
|
||||
} calypso_rf_info_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -395,6 +397,9 @@ static const char *calypso_rf_protocol_desc(isodep_state_t protocol) {
|
||||
if (protocol == ISODEP_NFCA) {
|
||||
return "ISO14443-A";
|
||||
}
|
||||
if (protocol == ISODEP_NFCB_PRIME) {
|
||||
return "ISO14443-B' / Innovatron";
|
||||
}
|
||||
if (protocol == ISODEP_NFCB) {
|
||||
return "ISO14443-B";
|
||||
}
|
||||
@@ -430,6 +435,18 @@ static int calypso_connect_contactless(bool verbose, calypso_rf_info_t *rf) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
iso14b_prime_card_select_t card_prime = {0};
|
||||
res = select_card_14443b_prime(false, &card_prime, verbose);
|
||||
if (res == PM3_SUCCESS) {
|
||||
if (rf != NULL) {
|
||||
rf->present = true;
|
||||
rf->protocol = ISODEP_NFCB_PRIME;
|
||||
rf->has_prime = true;
|
||||
rf->card_prime = card_prime;
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -2169,6 +2186,10 @@ static void calypso_print_rf_info(const calypso_rf_info_t *rf) {
|
||||
} else if (rf->has_14b) {
|
||||
calypso_print_rf_hex_line(" PUPI : ", rf->card_b.uid, rf->card_b.uidlen);
|
||||
calypso_print_rf_hex_line(" ATQB : ", rf->card_b.atqb, sizeof(rf->card_b.atqb));
|
||||
} else if (rf->has_prime) {
|
||||
PrintAndLogEx(SUCCESS, " V&T Ad : " _GREEN_("%02X"), rf->card_prime.vt_addr);
|
||||
calypso_print_rf_hex_line(" DIV : ", rf->card_prime.div, sizeof(rf->card_prime.div));
|
||||
calypso_print_rf_hex_line(" ATR : ", rf->card_prime.atr, rf->card_prime.atr_len);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4494,7 +4515,8 @@ static int calypso_probe_setup(const calypso_select_result_t *selected, bool ver
|
||||
uint8_t select_response[APDU_RES_LEN] = {0};
|
||||
size_t select_response_len = 0;
|
||||
uint16_t select_sw = 0;
|
||||
int res = Iso7816Select(CC_CONTACTLESS, false, true, aid, aid_len, select_response, sizeof(select_response), &select_response_len, &select_sw);
|
||||
sAPDU_t apdu = {0x00, ISO7816_SELECT_FILE, 0x04, 0x00, (uint8_t)aid_len, aid};
|
||||
int res = Iso7816ExchangeEx(CC_CONTACTLESS, false, true, apdu, true, 0, select_response, sizeof(select_response), &select_response_len, &select_sw);
|
||||
if (res != PM3_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
+34
-36
@@ -4682,8 +4682,6 @@ static int CmdHFFelicaAuthentication1(const char *Cmd) {
|
||||
|
||||
uint8_t data[PM3_CMD_DATA_SIZE];
|
||||
memset(data, 0, sizeof(data));
|
||||
data[0] = 0x0C; // Static length
|
||||
data[1] = 0x3E; // Command ID
|
||||
|
||||
// Length (1),
|
||||
// Command ID (1),
|
||||
@@ -4759,7 +4757,7 @@ static int CmdHFFelicaAuthentication1(const char *Cmd) {
|
||||
uint8_t flags = (FELICA_APPEND_CRC | FELICA_RAW);
|
||||
|
||||
PrintAndLogEx(INFO, "Client send AUTH1 frame: %s", sprint_hex(data, datalen));
|
||||
clear_and_send_command(flags, datalen, data, 0);
|
||||
clear_and_send_command(flags, datalen, data, false);
|
||||
|
||||
PacketResponseNG resp;
|
||||
if (waitCmdFelica(false, &resp, true) == false) {
|
||||
@@ -4770,40 +4768,40 @@ static int CmdHFFelicaAuthentication1(const char *Cmd) {
|
||||
felica_auth1_response_t auth1_response;
|
||||
memcpy(&auth1_response, (felica_auth1_response_t *)resp.data.asBytes, sizeof(felica_auth1_response_t));
|
||||
|
||||
if (auth1_response.frame_response.IDm[0]) {
|
||||
PrintAndLogEx(SUCCESS, "Auth1 response:");
|
||||
PrintAndLogEx(SUCCESS, "IDm... %s", sprint_hex(auth1_response.frame_response.IDm, sizeof(auth1_response.frame_response.IDm)));
|
||||
PrintAndLogEx(SUCCESS, "M2C... %s", sprint_hex(auth1_response.m2c, sizeof(auth1_response.m2c)));
|
||||
PrintAndLogEx(SUCCESS, "M3C... %s", sprint_hex(auth1_response.m3c, sizeof(auth1_response.m3c)));
|
||||
|
||||
// Assumption: Key swap method used
|
||||
uint8_t rev_master_key[PM3_CMD_DATA_SIZE];
|
||||
reverse_3des_key(master_key, 16, rev_master_key);
|
||||
mbedtls_des3_set2key_dec(&des3_ctx, rev_master_key);
|
||||
|
||||
bool is_key_correct = false;
|
||||
unsigned char p2c[8];
|
||||
mbedtls_des3_crypt_ecb(&des3_ctx, auth1_response.m2c, p2c);
|
||||
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
if (p2c[i] != nonce[i]) {
|
||||
is_key_correct = false;
|
||||
break;
|
||||
} else {
|
||||
is_key_correct = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_key_correct) {
|
||||
PrintAndLogEx(SUCCESS, "Auth1 done with correct key material!");
|
||||
PrintAndLogEx(SUCCESS, "Use Auth2 now with M3C and same key");
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "3DES secret (swapped decryption): %s", sprint_hex(rev_master_key, 16));
|
||||
PrintAndLogEx(INFO, "P2c: %s", sprint_hex(p2c, 8));
|
||||
PrintAndLogEx(ERR, "Can't decrypt M2C with master secret (P1c != P2c)!");
|
||||
PrintAndLogEx(ERR, "Probably wrong keys or wrong decryption method");
|
||||
}
|
||||
if (auth1_response.frame_response.cmd_code[0] != 0x11) {
|
||||
PrintAndLogEx(ERR, "response code does not match");
|
||||
return PM3_ERFTRANS;
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Auth1 response:");
|
||||
PrintAndLogEx(SUCCESS, "IDm... %s", sprint_hex(auth1_response.frame_response.IDm, sizeof(auth1_response.frame_response.IDm)));
|
||||
PrintAndLogEx(SUCCESS, "M2C... %s", sprint_hex(auth1_response.m2c, sizeof(auth1_response.m2c)));
|
||||
PrintAndLogEx(SUCCESS, "M3C... %s", sprint_hex(auth1_response.m3c, sizeof(auth1_response.m3c)));
|
||||
|
||||
|
||||
mbedtls_des3_init(&des3_ctx);
|
||||
|
||||
// Assumption: Key swap method used
|
||||
uint8_t rev_master_key[16];
|
||||
reverse_3des_key(master_key, 16, rev_master_key);
|
||||
mbedtls_des3_set2key_dec(&des3_ctx, rev_master_key);
|
||||
|
||||
uint8_t p2c[8];
|
||||
mbedtls_des3_crypt_ecb(&des3_ctx, auth1_response.m2c, p2c);
|
||||
mbedtls_des3_free(&des3_ctx);
|
||||
|
||||
bool is_key_correct = memcmp(p2c, nonce, sizeof(nonce)) == 0;
|
||||
|
||||
if (is_key_correct) {
|
||||
PrintAndLogEx(SUCCESS, "Auth1 done with correct key material!");
|
||||
PrintAndLogEx(SUCCESS, "Use Auth2 now with M3C and same key");
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "3DES secret (swapped decryption): %s", sprint_hex(rev_master_key, 16));
|
||||
PrintAndLogEx(INFO, "P2c: %s", sprint_hex(p2c, 8));
|
||||
PrintAndLogEx(ERR, "Can't decrypt M2C with master secret (P1c != P2c)!");
|
||||
PrintAndLogEx(ERR, "Probably wrong keys or wrong decryption method");
|
||||
}
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,10 +44,11 @@ static isodep_state_t isodep_state = ISODEP_INACTIVE;
|
||||
void SetISODEPState(isodep_state_t state) {
|
||||
isodep_state = state;
|
||||
if (APDULogging) {
|
||||
PrintAndLogEx(SUCCESS, "Setting ISODEP -> %s%s%s%s"
|
||||
PrintAndLogEx(SUCCESS, "Setting ISODEP -> %s%s%s%s%s"
|
||||
, isodep_state == ISODEP_INACTIVE ? "inactive" : ""
|
||||
, isodep_state == ISODEP_NFCA ? _GREEN_("NFC-A") : ""
|
||||
, isodep_state == ISODEP_NFCB ? _GREEN_("NFC-B") : ""
|
||||
, isodep_state == ISODEP_NFCB_PRIME ? _GREEN_("NFC-B'") : ""
|
||||
, isodep_state == ISODEP_NFCV ? _GREEN_("NFC-V") : ""
|
||||
);
|
||||
}
|
||||
@@ -125,6 +126,9 @@ int Iso7816ExchangeEx(Iso7816CommandChannel channel, bool activate_field, bool l
|
||||
case ISODEP_NFCB:
|
||||
res = exchange_14b_apdu(data, datalen, activate_field, leave_field_on, result, (int)max_result_len, (int *)result_len, 4000);
|
||||
break;
|
||||
case ISODEP_NFCB_PRIME:
|
||||
res = exchange_14b_prime_apdu(data, datalen, activate_field, leave_field_on, result, (int)max_result_len, (int *)result_len, 4000);
|
||||
break;
|
||||
case ISODEP_NFCV:
|
||||
PrintAndLogEx(INFO, " To be implemented, feel free to contribute!");
|
||||
break;
|
||||
|
||||
@@ -31,6 +31,7 @@ typedef enum {
|
||||
ISODEP_NFCA,
|
||||
ISODEP_NFCB,
|
||||
ISODEP_NFCV,
|
||||
ISODEP_NFCB_PRIME,
|
||||
} isodep_state_t;
|
||||
|
||||
typedef enum {
|
||||
|
||||
@@ -1286,6 +1286,9 @@ static int l_set_iso_dep_state(lua_State *L) {
|
||||
case 3:
|
||||
SetISODEPState(ISODEP_NFCV);
|
||||
break;
|
||||
case 4:
|
||||
SetISODEPState(ISODEP_NFCB_PRIME);
|
||||
break;
|
||||
default:
|
||||
return returnToLuaWithError(L, "Wrong ISODEP STATE value");
|
||||
}
|
||||
|
||||
+13
-1
@@ -34,6 +34,18 @@ typedef struct {
|
||||
uint8_t fc;
|
||||
} PACKED iso14b_cts_card_select_t;
|
||||
|
||||
#define ISO14B_PRIME_DIV_LEN 4
|
||||
#define ISO14B_PRIME_ATR_MAX_LEN 33
|
||||
typedef struct {
|
||||
uint8_t vt_addr;
|
||||
uint8_t repgen_cmd;
|
||||
uint8_t div[ISO14B_PRIME_DIV_LEN];
|
||||
uint8_t verlog;
|
||||
uint8_t config;
|
||||
uint8_t atr_len;
|
||||
uint8_t atr[ISO14B_PRIME_ATR_MAX_LEN];
|
||||
} PACKED iso14b_prime_card_select_t;
|
||||
|
||||
typedef enum ISO14B_COMMAND {
|
||||
ISO14B_CONNECT = (1 << 0),
|
||||
ISO14B_DISCONNECT = (1 << 1),
|
||||
@@ -49,6 +61,7 @@ typedef enum ISO14B_COMMAND {
|
||||
ISO14B_CLEARTRACE = (1 << 11),
|
||||
ISO14B_SELECT_XRX = (1 << 12),
|
||||
ISO14B_SELECT_PICOPASS = (1 << 13),
|
||||
ISO14B_SELECT_PRIME = (1 << 14),
|
||||
} iso14b_command_t;
|
||||
|
||||
typedef enum ISO14B_TYPE {
|
||||
@@ -85,4 +98,3 @@ typedef struct {
|
||||
#define US_TO_ETU(x) ( (float)((x) / 9.4396) )
|
||||
|
||||
#endif // _ISO14B_H_
|
||||
|
||||
@@ -328,6 +328,42 @@ ISO 7816-4 Basic interindustry commands. For command APDU's.
|
||||
#define ISO14443B_PING 0xBA
|
||||
#define ISO14443B_PONG 0xAB
|
||||
|
||||
/*
|
||||
* Type B' / Innovatron frame format.
|
||||
*
|
||||
* Byte 0: V&T address. Public docs and traces label this "V&T Ad".
|
||||
* 0x01 is the default address observed in APGEN, REPGEN,
|
||||
* ATTRIB, COM_RA, and DISC frames.
|
||||
* Observed cards respond to any value from 0x00 to 0xFF, and
|
||||
* echo that same address in the response.
|
||||
*
|
||||
* Byte 1: payload type / command.
|
||||
*
|
||||
* Primary commands:
|
||||
* 0x0B APGEN "Appel General"; acts as the wake-up command.
|
||||
* 0x07 REPGEN response to APGEN.
|
||||
* 0x0F ATTRIB attribute / activation command.
|
||||
* 0x03 DISC disconnect.
|
||||
*
|
||||
* COM_RA frames:
|
||||
* COM_RA uses the even-valued payload type bytes. Bit 0 is clear; bits 1..3
|
||||
* are the rolling frame counter. The resulting byte advances by 0x02 for
|
||||
* each exchange and wraps in the low nibble:
|
||||
*
|
||||
* 04 -> 06 -> 08 -> 0A -> 0C -> 0E -> 00 -> 02 -> 04 ...
|
||||
*
|
||||
* Byte 2 is the COM_RA length byte. The length includes byte 2 itself, so
|
||||
* the number of bytes after byte 2 is length - 1.
|
||||
*/
|
||||
#define ISO14443B_PRIME_VT_ADDR_DEFAULT 0x01
|
||||
#define ISO14443B_PRIME_CMD_DISC 0x03
|
||||
#define ISO14443B_PRIME_CMD_REPGEN 0x07
|
||||
#define ISO14443B_PRIME_CMD_APGEN 0x0B
|
||||
#define ISO14443B_PRIME_CMD_ATTRIB 0x0F
|
||||
// APGEN parameter requesting the extended REPGEN response; also called 'APGEN!'
|
||||
#define ISO14443B_PRIME_REQUEST_EXTENDED_REPGEN 0x80
|
||||
#define ISO14443B_PRIME_COM_RA_START 0x02
|
||||
|
||||
// XEROX Commands
|
||||
#define ISO14443B_XEROX_PWD 0x38
|
||||
#define ISO14443B_XEROX_WUP1 0x0D
|
||||
|
||||
Reference in new issue
Block a user