Skip to content

Commit d29d912

Browse files
authored
Merge pull request #3025 from aaronjamt/patch-3
[hf seos] Support variable length SIO
2 parents d436e8e + 25140d9 commit d29d912

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

client/src/cmdhfseos.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,17 @@ static int seos_get_data(uint8_t *rndICC, uint8_t *rndIFD, uint8_t *diversified_
325325
// 8E is our MAC response (8 bytes)
326326
// PrintAndLogEx(SUCCESS, "Raw Response..................... " _YELLOW_("%s"), sprint_hex_inrow(response, (resplen - 2)));
327327

328-
uint8_t cryptogram[64];
329328
uint8_t responseCode[2];
330329
uint8_t tag[2] = {0x00, 0x00};
331330
int getDataSize = 0;
332331

333332
// ------------------- Cryptogram Response -------------------
334-
if (resplen >= 2 && response[0] == 0x85 && response[1] == 0x40) {
335-
uint8_t decrypted[64];
336-
memcpy(cryptogram, response + 2, 64);
337-
memcpy(responseCode, response + 68, 2);
333+
if (resplen >= 2 && response[0] == 0x85 && response[1] >= 0x40) {
334+
uint8_t cryptogram_length = response[1];
335+
uint8_t cryptogram[cryptogram_length];
336+
uint8_t decrypted[cryptogram_length];
337+
memcpy(cryptogram, response + 2, cryptogram_length);
338+
memcpy(responseCode, response + cryptogram_length + 4, 2);
338339

339340
// Decrypt the response
340341
decrypt_cryptogram(diversified_enc_key, cryptogram, decrypted, sizeof(cryptogram), encryption_algorithm);
@@ -353,7 +354,7 @@ static int seos_get_data(uint8_t *rndICC, uint8_t *rndIFD, uint8_t *diversified_
353354
memmove(decrypted, decrypted + 1, sizeof(decrypted) - 1);
354355
memmove(sioOutput, decrypted + 2, getDataSize);
355356
*sio_size = getDataSize;
356-
memcpy(responseCode, response + 68, 2);
357+
memcpy(responseCode, response + cryptogram_length + 4, 2);
357358

358359
PrintAndLogEx(SUCCESS, "Response Code.................... " _YELLOW_("%s"), sprint_hex_inrow(responseCode, (ARRAYLEN(responseCode))));
359360
PrintAndLogEx(SUCCESS, "Output........................... " _YELLOW_("%s"), sprint_hex_inrow(sioOutput, getDataSize));

0 commit comments

Comments
 (0)