get trophy key from toml file

This commit is contained in:
georgemoralis 2024-12-27 18:13:45 +02:00
parent abe85fd3e0
commit 8248db8e03
3 changed files with 33 additions and 0 deletions

View File

@ -68,6 +68,7 @@ static bool separateupdatefolder = false;
static bool compatibilityData = false; static bool compatibilityData = false;
static bool checkCompatibilityOnStartup = false; static bool checkCompatibilityOnStartup = false;
static std::string audioBackend = "cubeb"; static std::string audioBackend = "cubeb";
static std::string trophyKey = "";
// Gui // Gui
std::vector<std::filesystem::path> settings_install_dirs = {}; std::vector<std::filesystem::path> settings_install_dirs = {};
@ -92,6 +93,14 @@ std::string emulator_language = "en";
// Language // Language
u32 m_language = 1; // english u32 m_language = 1; // english
std::string getTrophyKey() {
return trophyKey;
}
void setTrophyKey(std::string key) {
trophyKey = key;
}
bool isNeoMode() { bool isNeoMode() {
return isNeo; return isNeo;
} }
@ -667,6 +676,11 @@ void load(const std::filesystem::path& path) {
m_language = toml::find_or<int>(settings, "consoleLanguage", 1); m_language = toml::find_or<int>(settings, "consoleLanguage", 1);
} }
if (data.contains("Keys")) {
const toml::value& keys = data.at("keys");
trophyKey = toml::find_or<std::string>(keys, "TrophyKey", "");
}
} }
void save(const std::filesystem::path& path) { void save(const std::filesystem::path& path) {
@ -727,6 +741,8 @@ void save(const std::filesystem::path& path) {
data["Audio"]["backend"] = audioBackend; data["Audio"]["backend"] = audioBackend;
data["Debug"]["DebugDump"] = isDebugDump; data["Debug"]["DebugDump"] = isDebugDump;
data["Debug"]["CollectShader"] = isShaderDebug; data["Debug"]["CollectShader"] = isShaderDebug;
data["Keys"]["TrophyKey"] = trophyKey;
std::vector<std::string> install_dirs; std::vector<std::string> install_dirs;
for (const auto& dirString : settings_install_dirs) { for (const auto& dirString : settings_install_dirs) {

View File

@ -15,6 +15,9 @@ void load(const std::filesystem::path& path);
void save(const std::filesystem::path& path); void save(const std::filesystem::path& path);
void saveMainWindow(const std::filesystem::path& path); void saveMainWindow(const std::filesystem::path& path);
std::string getTrophyKey();
void setTrophyKey(std::string key);
bool isNeoMode(); bool isNeoMode();
bool isFullscreenMode(); bool isFullscreenMode();
bool getPlayBGM(); bool getPlayBGM();

View File

@ -3,6 +3,7 @@
#include <array> #include <array>
#include "crypto.h" #include "crypto.h"
#include <common/config.h>
CryptoPP::RSA::PrivateKey Crypto::key_pkg_derived_key3_keyset_init() { CryptoPP::RSA::PrivateKey Crypto::key_pkg_derived_key3_keyset_init() {
CryptoPP::InvertibleRSAFunction params; CryptoPP::InvertibleRSAFunction params;
@ -137,6 +138,13 @@ void Crypto::aesCbcCfb128DecryptEntry(std::span<const CryptoPP::byte, 32> 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<CryptoPP::byte, 16> NPcommID, void Crypto::decryptEFSM(std::span<CryptoPP::byte, 16> NPcommID,
std::span<CryptoPP::byte, 16> efsmIv, std::span<CryptoPP::byte> ciphertext, std::span<CryptoPP::byte, 16> efsmIv, std::span<CryptoPP::byte> ciphertext,
std::span<CryptoPP::byte> decrypted) { std::span<CryptoPP::byte> decrypted) {
@ -145,9 +153,15 @@ void Crypto::decryptEFSM(std::span<CryptoPP::byte, 16> NPcommID,
// step 1: Encrypt NPcommID // step 1: Encrypt NPcommID
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption encrypt; CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption encrypt;
const char* TrophyKeyget = Config::getTrophyKey().c_str();
std::vector<CryptoPP::byte> TrophyKey;
hexToBytes(TrophyKeyget, TrophyKey.data());
std::vector<CryptoPP::byte> trpKey(16); std::vector<CryptoPP::byte> trpKey(16);
encrypt.ProcessData(trpKey.data(), NPcommID.data(), 16); encrypt.ProcessData(trpKey.data(), NPcommID.data(), 16);
encrypt.SetKeyWithIV(TrophyKey.data(), TrophyKey.size(), TrophyIV.data());
// step 2: decrypt efsm. // step 2: decrypt efsm.
CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption decrypt; CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption decrypt;
decrypt.SetKeyWithIV(trpKey.data(), trpKey.size(), efsmIv.data()); decrypt.SetKeyWithIV(trpKey.data(), trpKey.size(), efsmIv.data());