From 867d2d65203dad7f950a9be82a3c59cec9d26047 Mon Sep 17 00:00:00 2001 From: shchmue Date: Tue, 5 Mar 2019 13:09:37 -0500 Subject: [PATCH] Do not overwrite newer keyfile from Lockpick_RCM --- Makefile | 2 +- changelog.md | 5 +++++ source/Common.cpp | 4 ++-- source/KeyCollection.cpp | 32 ++++++++++++++++++++++++++++---- 4 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index b47319c..fae9b9a 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ include $(DEVKITPRO)/libnx/switch_rules #--------------------------------------------------------------------------------- APP_TITLE := Lockpick APP_AUTHOR := shchmue -APP_VERSION := 1.2.1 +APP_VERSION := 1.2.2 TARGET := $(subst $e ,_,$(notdir $(APP_TITLE))) BUILD := build diff --git a/changelog.md b/changelog.md index 6a1aeab..0f6edd0 100644 --- a/changelog.md +++ b/changelog.md @@ -1,4 +1,9 @@ # Changelog +## Version 1.2.2 +* Do not overwrite existing keyfile that contains master_key_07 +* Read eticket_rsa_kek from existing keyfile in case user is only running this for titlekeys +* Create /switch folder if needed + ## Version 1.2.1 * Generate bis keys without master keys * Update file size check to support Hekate v4.8 TSEC dump diff --git a/source/Common.cpp b/source/Common.cpp index a77c0fe..f434e65 100644 --- a/source/Common.cpp +++ b/source/Common.cpp @@ -142,8 +142,8 @@ namespace Common { memset(framebuf, 0, gfxGetFramebufferSize()); #endif draw_text(0x010, 0x020, YELLOW, "Lockpick! by shchmue"); - draw_text(0x190, 0x020, YELLOW, "Note: Only dumps keys 00-06 on 6.2.0"); - draw_text(0x190, 0x040, YELLOW, " and keys 00-05 on all other firmwares including 7.0.0+"); + draw_text(0x190, 0x020, YELLOW, "Note: This can only dump keys 00-05 (or 00-06 on 6.2.0)"); + draw_text(0x190, 0x040, YELLOW, "Use Lockpick_RCM for newer keys on firmware 7.0.0+!"); draw_set_rect(814, 452 + 42 * 0, 450, 42, FLAG_RED); draw_set_rect(814, 452 + 42 * 1, 450, 42, FLAG_ORANGE); diff --git a/source/KeyCollection.cpp b/source/KeyCollection.cpp index 6ffe971..12fa79d 100644 --- a/source/KeyCollection.cpp +++ b/source/KeyCollection.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -228,8 +229,8 @@ void KeyCollection::get_keys() { } else { Common::draw_text(0x010, 0x60, RED, "Get Tegra keys..."); Common::draw_text(0x190, 0x60, RED, "Failed"); - Common::draw_text(0x190, 0x20, RED, "Warning: Saving limited keyset."); - Common::draw_text(0x190, 0x40, RED, "Dump Tegra keys with payload and run again to get all keys."); + Common::draw_text(0x2a0, 0x60, RED, "Warning: Saving limited keyset."); + Common::draw_text(0x2a0, 0x80, RED, "Dump TSEC and Fuses with Hekate."); } profiler_time = profile(&KeyCollection::get_memory_keys, *this); @@ -241,8 +242,31 @@ void KeyCollection::get_keys() { profiler_time = profile(&KeyCollection::derive_keys, *this); Common::draw_text_with_time(0x10, 0x0c0, GREEN, "Derive remaining keys...", profiler_time); - profiler_time = profile(&KeyCollection::save_keys, *this); - Common::draw_text_with_time(0x10, 0x0e0, GREEN, "Saving keys to keyfile...", profiler_time); + // avoid crash on CFWs that don't use /switch folder + if (!std::filesystem::exists("/switch")) + std::filesystem::create_directory("/switch"); + // since Lockpick_RCM can dump newer keys, check for existing keyfile + bool Lockpick_RCM_file_found = false; + if (std::filesystem::exists("/switch/prod.keys")) { + FILE *key_file = fopen("/switch/prod.keys", "r"); + char line[0x200]; + while (fgets(line, sizeof(line), key_file)) { + if (strncmp("master_key_07", line, 13) == 0) { + Lockpick_RCM_file_found = true; + } else if (!eticket_rsa_kek.found() && (strncmp("eticket_rsa_kek", line, 15)) == 0) { + // grab eticket_rsa_kek from existing file to make sure we can dump titlekeys + eticket_rsa_kek = Key("eticket_rsa_kek", 0x10, Common::key_string_to_byte_vector(line)); + } + } + fclose(key_file); + } + if (!Lockpick_RCM_file_found) { + profiler_time = profile(&KeyCollection::save_keys, *this); + Common::draw_text_with_time(0x10, 0x0e0, GREEN, "Saving keys to keyfile...", profiler_time); + } else { + Common::draw_text(0x10, 0x0e0, YELLOW, "Saving keys to keyfile..."); + Common::draw_text(0x190, 0x0e0, YELLOW, "Newer keyfile found. Skipped overwriting keys"); + } total_time.stop(); Common::draw_line(0x8, 0xf0, 0x280, GREEN);