diff --git a/src/common/config.cpp b/src/common/config.cpp index deef0fa88..4fce7d97f 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -67,6 +67,7 @@ static int cursorHideTimeout = 5; // 5 seconds (default) static bool separateupdatefolder = false; static bool compatibilityData = false; static bool checkCompatibilityOnStartup = false; +static std::string trophyKey = ""; // Gui std::vector settings_install_dirs = {}; @@ -91,6 +92,14 @@ std::string emulator_language = "en"; // Language u32 m_language = 1; // english +std::string getTrophyKey() { + return trophyKey; +} + +void setTrophyKey(std::string key) { + trophyKey = key; +} + bool isNeoMode() { return isNeo; } @@ -652,6 +661,11 @@ void load(const std::filesystem::path& path) { m_language = toml::find_or(settings, "consoleLanguage", 1); } + + if (data.contains("Keys")) { + const toml::value& keys = data.at("Keys"); + trophyKey = toml::find_or(keys, "TrophyKey", ""); + } } void save(const std::filesystem::path& path) { @@ -712,6 +726,8 @@ void save(const std::filesystem::path& path) { data["Debug"]["DebugDump"] = isDebugDump; data["Debug"]["CollectShader"] = isShaderDebug; + data["Keys"]["TrophyKey"] = trophyKey; + std::vector install_dirs; for (const auto& dirString : settings_install_dirs) { install_dirs.emplace_back(std::string{fmt::UTF(dirString.u8string()).data}); diff --git a/src/common/config.h b/src/common/config.h index 701aadb12..9d943008b 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -15,6 +15,9 @@ void load(const std::filesystem::path& path); void save(const std::filesystem::path& path); void saveMainWindow(const std::filesystem::path& path); +std::string getTrophyKey(); +void setTrophyKey(std::string key); + bool isNeoMode(); bool isFullscreenMode(); bool getPlayBGM(); diff --git a/src/core/crypto/crypto.cpp b/src/core/crypto/crypto.cpp index 00f1dea46..472d284fc 100644 --- a/src/core/crypto/crypto.cpp +++ b/src/core/crypto/crypto.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include "crypto.h" CryptoPP::RSA::PrivateKey Crypto::key_pkg_derived_key3_keyset_init() { @@ -137,6 +138,13 @@ void Crypto::aesCbcCfb128DecryptEntry(std::span ivkey, } } +static void hexToBytes(const char* hex, unsigned char* dst) { + for (size_t i = 0; hex[i] != 0; i++) { + const unsigned char value = (hex[i] < 0x3A) ? (hex[i] - 0x30) : (hex[i] - 0x37); + dst[i / 2] |= ((i % 2) == 0) ? (value << 4) : (value); + } +} + void Crypto::decryptEFSM(std::span NPcommID, std::span efsmIv, std::span ciphertext, std::span decrypted) { @@ -145,9 +153,15 @@ void Crypto::decryptEFSM(std::span NPcommID, // step 1: Encrypt NPcommID CryptoPP::CBC_Mode::Encryption encrypt; + const char* TrophyKeyget = Config::getTrophyKey().c_str(); + std::vector TrophyKey; + hexToBytes(TrophyKeyget, TrophyKey.data()); + std::vector trpKey(16); encrypt.ProcessData(trpKey.data(), NPcommID.data(), 16); + encrypt.SetKeyWithIV(TrophyKey.data(), TrophyKey.size(), TrophyIV.data()); + // step 2: decrypt efsm. CryptoPP::CBC_Mode::Decryption decrypt; decrypt.SetKeyWithIV(trpKey.data(), trpKey.size(), efsmIv.data());