From 55ae2a63d9f22e7f710fb2c86c7b09fcb4634e40 Mon Sep 17 00:00:00 2001 From: ITotalJustice <47043333+ITotalJustice@users.noreply.github.com> Date: Thu, 15 May 2025 15:14:02 +0100 Subject: [PATCH] fix installing failing during setup if prod.keys isn't found. --- sphaira/source/app.cpp | 1 + sphaira/source/yati/nx/keys.cpp | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/sphaira/source/app.cpp b/sphaira/source/app.cpp index 2e087d2..6fdbde3 100644 --- a/sphaira/source/app.cpp +++ b/sphaira/source/app.cpp @@ -1260,6 +1260,7 @@ App::App(const char* argv0) { if (App::GetLogEnable()) { log_file_init(); log_write("hello world\n"); + App::Notify("Warning! Logs are enabled, Sphaira will run slowly!"_i18n); } if (App::GetMtpEnable()) { diff --git a/sphaira/source/yati/nx/keys.cpp b/sphaira/source/yati/nx/keys.cpp index cc53200..248a2f4 100644 --- a/sphaira/source/yati/nx/keys.cpp +++ b/sphaira/source/yati/nx/keys.cpp @@ -101,25 +101,26 @@ Result parse_keys(Keys& out, bool read_from_file) { ON_SCOPE_EXIT(setcalExit()); R_TRY(setcalGetEticketDeviceKey(std::addressof(out.eticket_device_key))); - R_UNLESS(ini_browse(cb, std::addressof(out), "/switch/prod.keys"), 0x1); + // it doesn't matter if this fails, its just that title decryption will also fail. + if (ini_browse(cb, std::addressof(out), "/switch/prod.keys")) { + // decrypt eticket device key. + if (out.eticket_rsa_kek.IsValid()) { + auto rsa_key = (es::EticketRsaDeviceKey*)out.eticket_device_key.key; - // decrypt eticket device key. - if (out.eticket_rsa_kek.IsValid()) { - auto rsa_key = (es::EticketRsaDeviceKey*)out.eticket_device_key.key; + Aes128CtrContext eticket_aes_ctx{}; + aes128CtrContextCreate(&eticket_aes_ctx, &out.eticket_rsa_kek, rsa_key->ctr); + aes128CtrCrypt(&eticket_aes_ctx, &(rsa_key->private_exponent), &(rsa_key->private_exponent), sizeof(es::EticketRsaDeviceKey) - sizeof(rsa_key->ctr)); - Aes128CtrContext eticket_aes_ctx{}; - aes128CtrContextCreate(&eticket_aes_ctx, &out.eticket_rsa_kek, rsa_key->ctr); - aes128CtrCrypt(&eticket_aes_ctx, &(rsa_key->private_exponent), &(rsa_key->private_exponent), sizeof(es::EticketRsaDeviceKey) - sizeof(rsa_key->ctr)); - - const auto public_exponent = std::byteswap(rsa_key->public_exponent); - if (public_exponent != 0x10001) { - log_write("etick decryption fail: 0x%X\n", public_exponent); - if (public_exponent == 0) { - log_write("eticket device id is NULL\n"); + const auto public_exponent = std::byteswap(rsa_key->public_exponent); + if (public_exponent != 0x10001) { + log_write("etick decryption fail: 0x%X\n", public_exponent); + if (public_exponent == 0) { + log_write("eticket device id is NULL\n"); + } + R_THROW(0x1); + } else { + log_write("eticket match\n"); } - R_THROW(0x1); - } else { - log_write("eticket match\n"); } } }