How to dump the latest master key (master_key_06) + others

Here's a quick guide/code snippet for dumping the latest master key, as well as the tsec_root_key.

Add this to line 144 of key_derivation.c in atmosphere/fusee_secondary, then compile atmosphere as usual:

Code:
    if (target_firmware >= EXOSPHERE_TARGET_FIRMWARE_620) {
        if (memcmp(tsec_root_key, zeroes, 0x10) != 0) {
            /* Determine filename based on whether the device is a retail or dev unit. */
            char *filename = fuse_get_retail_type() ? "prod.keys" : "dev.keys";
            /* Open the key file for writing. */
            FILE *keyf = fopen(filename, "wb");
            /* Log to screen. */
            printf("[NXBOOT]: Dumping keys to %s...\n", filename);
            /* Print the name of the key. */
            fprintf(keyf, "tsec_root_key = ");
            /* Print the tsec_root_key as an uppercase hex string to the key file. */
            for (int i = 0; i < 16; i++) {
                fprintf(keyf, "%02X", ((uint8_t*)tsec_root_key)[i]);
            }
            /* Print the name of the key. */
            fprintf(keyf, "\nmaster_kek_source_06 = ");
            /* Print master_key_source_06 as an uppercase hex string to the key file. */
            for (int i = 0; i < 16; i++) {
                fprintf(keyf, "%02X", new_master_kek_seeds[0][i]);
            }
            /* Print the name of the key. */
            fprintf(keyf, "\nmaster_key_06 = ");
            /* Set keyslot 0xC with the tsec_root_key. */
            set_aes_keyslot(0xC, tsec_root_key, 0x10);
            for (unsigned int rev = MASTERKEY_REVISION_620_CURRENT; rev < MASTERKEY_REVISION_MAX; rev++) {
                /* Decrypt the new master kek seed with the contents of keyslot 0xC (tsec_root_key) and write the result to work_buffer. */
                se_aes_ecb_decrypt_block(0xC, work_buffer, 0x10, new_master_kek_seeds[rev - MASTERKEY_REVISION_620_CURRENT], 0x10);
                /* Set keyslot 0xC to the derived value stored in work_buffer */
                set_aes_keyslot(0xC, work_buffer, 0x10);
                /* Lastly, decrypt the masterkey_seed with the contents of keyslot 0xC (the master_kek) and write the result to work_buffer. */
                se_aes_ecb_decrypt_block(0xC, work_buffer, 0x10, masterkey_seed, 0x10);
                /* Print work_buffer as an uppercase hex string to the key file. (this is master_key_06!) */
                for (int i = 0; i < 16; i++) {
                    fprintf(keyf, "%02X", work_buffer[i]);
                }
                /* Set keyslot 0xC back to its intended value. */
                set_aes_keyslot(0xC, tsec_root_key, 0x10);
                se_aes_ecb_decrypt_block(0xC, work_buffer, 0x10, new_master_kek_seeds[rev - MASTERKEY_REVISION_620_CURRENT], 0x10);
                memcpy(g_dec_keyblobs[rev].master_kek, work_buffer, 0x10);
            }
            fclose(keyf);
        } else {

Alternatively, attached is a pre-compiled fusee_secondary.bin (for version 0.8.1) to save you the trouble of compiling atmosphere.

Place the fusee_secondary.bin file on the root of your SD card, boot atmosphere as normal, and the keys will be dumped to prod.keys (or dev.keys if using a dev unit).
 

Attachments

  • fusee-secondary.zip
    905.7 KB · Views: 935

Selver

13,5,1,14,9,14,7,12,5,19,19
Member
Joined
Dec 22, 2015
Messages
219
Trophies
0
XP
426
Country
Add this to line 144 of key_derivation.c in atmosphere/fusee_secondary, then compile atmosphere as usual:

Can you give a GIT repo link and corresponding GIT commit hash for the source you apply this to?

As you know, giving a line number makes the instructions heavily dependent on a specific revision. Giving the git commit hash the instructions are based on removes (future) ambiguity.

Thanks!
 

Selver

13,5,1,14,9,14,7,12,5,19,19
Member
Joined
Dec 22, 2015
Messages
219
Trophies
0
XP
426
Country
Fusee-secondary does not dump the keys, it only initializes them for internal use.
It's OK, I was able to modify the file enough for my use.
 

SimonMKWii

Professional Idiot
OP
Member
Joined
Nov 18, 2017
Messages
666
Trophies
0
Location
Melbourne, Victoria
XP
2,760
Country
Australia
Sorry, I should have clarified, replace lines 144-152 with the code snippet.
Although you may want to alter it a little bit and add another buffer for the derived master_kek to prevent performing the same crypto operation twice.
 

midstor

Well-Known Member
Member
Joined
Aug 1, 2018
Messages
299
Trophies
0
Age
25
XP
797
Country
United States
Here's a quick guide/code snippet for dumping the latest master key, as well as the tsec_root_key.

Add this to line 144 of key_derivation.c in atmosphere/fusee_secondary, then compile atmosphere as usual:

Code:
    if (target_firmware >= EXOSPHERE_TARGET_FIRMWARE_620) {
        if (memcmp(tsec_root_key, zeroes, 0x10) != 0) {
            /* Determine filename based on whether the device is a retail or dev unit. */
            char *filename = fuse_get_retail_type() ? "prod.keys" : "dev.keys";
            /* Open the key file for writing. */
            FILE *keyf = fopen(filename, "wb");
            /* Log to screen. */
            printf("[NXBOOT]: Dumping keys to %s...\n", filename);
            /* Print the name of the key. */
            fprintf(keyf, "tsec_root_key = ");
            /* Print the tsec_root_key as an uppercase hex string to the key file. */
            for (int i = 0; i < 16; i++) {
                fprintf(keyf, "%02X", ((uint8_t*)tsec_root_key)[i]);
            }
            /* Print the name of the key. */
            fprintf(keyf, "\nmaster_kek_source_06 = ");
            /* Print master_key_source_06 as an uppercase hex string to the key file. */
            for (int i = 0; i < 16; i++) {
                fprintf(keyf, "%02X", new_master_kek_seeds[0][i]);
            }
            /* Print the name of the key. */
            fprintf(keyf, "\nmaster_key_06 = ");
            /* Set keyslot 0xC with the tsec_root_key. */
            set_aes_keyslot(0xC, tsec_root_key, 0x10);
            for (unsigned int rev = MASTERKEY_REVISION_620_CURRENT; rev < MASTERKEY_REVISION_MAX; rev++) {
                /* Decrypt the new master kek seed with the contents of keyslot 0xC (tsec_root_key) and write the result to work_buffer. */
                se_aes_ecb_decrypt_block(0xC, work_buffer, 0x10, new_master_kek_seeds[rev - MASTERKEY_REVISION_620_CURRENT], 0x10);
                /* Set keyslot 0xC to the derived value stored in work_buffer */
                set_aes_keyslot(0xC, work_buffer, 0x10);
                /* Lastly, decrypt the masterkey_seed with the contents of keyslot 0xC (the master_kek) and write the result to work_buffer. */
                se_aes_ecb_decrypt_block(0xC, work_buffer, 0x10, masterkey_seed, 0x10);
                /* Print work_buffer as an uppercase hex string to the key file. (this is master_key_06!) */
                for (int i = 0; i < 16; i++) {
                    fprintf(keyf, "%02X", work_buffer[i]);
                }
                /* Set keyslot 0xC back to its intended value. */
                set_aes_keyslot(0xC, tsec_root_key, 0x10);
                se_aes_ecb_decrypt_block(0xC, work_buffer, 0x10, new_master_kek_seeds[rev - MASTERKEY_REVISION_620_CURRENT], 0x10);
                memcpy(g_dec_keyblobs[rev].master_kek, work_buffer, 0x10);
            }
            fclose(keyf);
        } else {

Alternatively, attached is a pre-compiled fusee_secondary.bin (for version 0.8.1) to save you the trouble of compiling atmosphere.

Place the fusee_secondary.bin file on the root of your SD card, boot atmosphere as normal, and the keys will be dumped to prod.keys (or dev.keys if using a dev unit).
Thanks <3 very g00d work
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • SylverReZ @ SylverReZ:
    When you play SM64 but you try recreating the slider song from memory during an episode.
  • BakerMan @ BakerMan:
    i kinda left without giving the quote, but here it is
    iu
    +1
  • BigOnYa @ BigOnYa:
    Not as scary as walking in the woods alone, and running into Wario.
    +1
  • BigOnYa @ BigOnYa:
    Our weather is crazy here in Ohio, was 90 last week, now its in the 60's, 45 at night.
    +1
  • AncientBoi @ AncientBoi:
    mmmAbout the same here. Under cloud cover at the moment
  • BigOnYa @ BigOnYa:
    You guys probably wearing winter jackets when in 60's in Cali.
  • BigOnYa @ BigOnYa:
    I heard a new term today related to Cali, thought was funny, "California Sober" lol
  • AncientBoi @ AncientBoi:
    ROFL LMAO
  • K3Nv2 @ K3Nv2:
    I hurt ancientbois feelings
  • BigOnYa @ BigOnYa:
    You wouldn't remove your teeth?
    +1
  • K3Nv2 @ K3Nv2:
    But his mouth is stuck on your meat
    +2
  • AncientBoi @ AncientBoi:
    AN SOFA
    +1
  • K3Nv2 @ K3Nv2:
    I had a power nap woke up with so much gas it's awesome
  • BakerMan @ BakerMan:
    holy shit why do i have 19 notifications?!
  • BakerMan @ BakerMan:
    AND WHY ARE SOME OF THEM BUNDLED UP REACTIONS TO POSTS?
  • BigOnYa @ BigOnYa:
    Cause I maybe, maybe clicked like a few times.
  • K3Nv2 @ K3Nv2:
    You're as loved as much as Juan now enjoy it
    +1
  • K3Nv2 @ K3Nv2:
    I'm sorry for the insult
  • BakerMan @ BakerMan:
    the difference is i like wario and samus and he likes muscle mommies and feet
    +1
  • BakerMan @ BakerMan:
    wait, i forgot wizards too
  • BigOnYa @ BigOnYa:
    I have a buddy that has a moonshine still and he makes his own shine. He brought me a jar of some peach shine/brandy, shit is damn good. Gonna have to see if can get more.
    +1
  • BakerMan @ BakerMan:
    careful that shit don't make you go blind
  • BigOnYa @ BigOnYa:
    Nuh that's only if you drink what first comes out when distilling, you must throw out the first part of it when it starts running.
  • K3Nv2 @ K3Nv2:
    If alcohol would've made @BigOnYa blind by now it would have
    +1
  • BigOnYa @ BigOnYa:
    So True.
    BigOnYa @ BigOnYa: So True.