Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow dumping TSEC keys to sd card #44

Merged
merged 2 commits into from
Jul 10, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else
	goto out;

else
{
goto out;
}

out_wait:;
btn_wait();

out:;
free(pkg1);
}

void reboot_normal()
Expand Down