Skip to content

Commit

Permalink
Allow dumping TSEC keys to sd card (#44)
Browse files Browse the repository at this point in the history
* Allow dumping tsec keys to sd card
  • Loading branch information
tesnos6921 authored and CTCaer committed Jul 10, 2018
1 parent 1988e3f commit 9401897
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions ipl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,36 +660,59 @@ void print_tsec_key()
u8 *pkg1 = (u8 *)malloc(0x40000);
sdmmc_storage_set_mmc_partition(&storage, 1);
sdmmc_storage_read(&storage, 0x100000 / NX_EMMC_BLOCKSIZE, 0x40000 / NX_EMMC_BLOCKSIZE, pkg1);
sdmmc_storage_end(&storage);
const pkg1_id_t *pkg1_id = pkg1_identify(pkg1);
if (!pkg1_id)
{
EPRINTFARGS("Could not identify package1 version\nto read TSEC firmware (= '%s').",
(char *)pkg1 + 0x10);
goto out;
goto out_wait;
}


u8 keys[0x10 * 3];
for(u32 i = 1; i <= 3; i++)
{
u8 key[0x10];
int res = tsec_query(key, i, pkg1 + pkg1_id->tsec_off);
int res = tsec_query(keys + ((i - 1) * 0x10), i, pkg1 + pkg1_id->tsec_off);

gfx_printf(&gfx_con, "%kTSEC key %d: %k", 0xFF00DDFF, i, 0xFFCCCCCC);
if (res >= 0)
{
for (u32 i = 0; i < 0x10; i++)
gfx_printf(&gfx_con, "%02X", key[i]);
for (u32 j = 0; j < 0x10; j++)
gfx_printf(&gfx_con, "%02X", keys[((i - 1) * 0x10) + j]);
}
else
EPRINTFARGS("ERROR %X", res);
gfx_putc(&gfx_con, '\n');
}

out:;
free(pkg1);
sdmmc_storage_end(&storage);
gfx_puts(&gfx_con, "\nPress POWER to dump them to SD Card.\nPress VOL to go to the menu.\n");

u32 btn = btn_wait();
if (btn & BTN_POWER)
{
if (sd_mount())
{
char tsec_keyFilename[26];
f_mkdir("Backup");
f_mkdir("Backup/Dumps");
memcpy(tsec_keyFilename, "Backup/Dumps/tsec_key.bin", 26);

gfx_puts(&gfx_con, "\nPress any key...\n");
if (!sd_save_to_file(keys, 0x10 * 3, tsec_keyFilename))
gfx_puts(&gfx_con, "\nDone!\n");
sd_unmount();
}
}
else
{
goto out;
}

out_wait:;
btn_wait();

out:;
free(pkg1);
}

void reboot_normal()
Expand Down

0 comments on commit 9401897

Please sign in to comment.