yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

Allow key loading from %YUZU_DIR%/keys in addition to ~/.switch

This commit is contained in:
Zach Hilman 2018-07-29 18:42:04 -04:00
parent cc8234fa89
commit 150527ec19
5 changed files with 23 additions and 7 deletions

View File

@ -32,6 +32,7 @@
#define SDMC_DIR "sdmc" #define SDMC_DIR "sdmc"
#define NAND_DIR "nand" #define NAND_DIR "nand"
#define SYSDATA_DIR "sysdata" #define SYSDATA_DIR "sysdata"
#define KEYS_DIR "keys"
#define LOG_DIR "log" #define LOG_DIR "log"
// Filenames // Filenames

View File

@ -706,6 +706,7 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) {
paths.emplace(UserPath::SDMCDir, user_path + SDMC_DIR DIR_SEP); paths.emplace(UserPath::SDMCDir, user_path + SDMC_DIR DIR_SEP);
paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP); paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP);
paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP); paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP);
paths.emplace(UserPath::KeysDir, user_path + KEYS_DIR DIR_SEP);
// TODO: Put the logs in a better location for each OS // TODO: Put the logs in a better location for each OS
paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP); paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP);
} }

View File

@ -23,6 +23,7 @@ namespace FileUtil {
enum class UserPath { enum class UserPath {
CacheDir, CacheDir,
ConfigDir, ConfigDir,
KeysDir,
LogDir, LogDir,
NANDDir, NANDDir,
RootDir, RootDir,

View File

@ -12,6 +12,7 @@
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/crypto/key_manager.h" #include "core/crypto/key_manager.h"
#include "core/settings.h" #include "core/settings.h"
#include "key_manager.h"
namespace Core::Crypto { namespace Core::Crypto {
@ -50,18 +51,17 @@ std::array<u8, 32> operator""_array32(const char* str, size_t len) {
KeyManager::KeyManager() { KeyManager::KeyManager() {
// Initialize keys // Initialize keys
std::string keys_dir = FileUtil::GetHactoolConfigurationPath(); std::string hactool_keys_dir = FileUtil::GetHactoolConfigurationPath();
std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir);
if (Settings::values.use_dev_keys) { if (Settings::values.use_dev_keys) {
dev_mode = true; dev_mode = true;
if (FileUtil::Exists(keys_dir + DIR_SEP + "dev.keys")) AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "dev.keys", false);
LoadFromFile(keys_dir + DIR_SEP + "dev.keys", false);
} else { } else {
dev_mode = false; dev_mode = false;
if (FileUtil::Exists(keys_dir + DIR_SEP + "prod.keys")) AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "prod.keys", false);
LoadFromFile(keys_dir + DIR_SEP + "prod.keys", false);
} }
if (FileUtil::Exists(keys_dir + DIR_SEP + "title.keys"))
LoadFromFile(keys_dir + DIR_SEP + "title.keys", true); AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "title.keys", true);
} }
void KeyManager::LoadFromFile(std::string_view filename_, bool is_title_keys) { void KeyManager::LoadFromFile(std::string_view filename_, bool is_title_keys) {
@ -104,6 +104,17 @@ void KeyManager::LoadFromFile(std::string_view filename_, bool is_title_keys) {
} }
} }
void KeyManager::AttemptLoadKeyFile(std::string_view dir1_, std::string_view dir2_,
std::string_view filename_, bool title) {
std::string dir1(dir1_);
std::string dir2(dir2_);
std::string filename(filename_);
if (FileUtil::Exists(dir1 + DIR_SEP + filename))
LoadFromFile(dir1 + DIR_SEP + filename, title);
else if (FileUtil::Exists(dir2 + DIR_SEP + filename))
LoadFromFile(dir2 + DIR_SEP + filename, title);
}
bool KeyManager::HasKey(S128KeyType id, u64 field1, u64 field2) const { bool KeyManager::HasKey(S128KeyType id, u64 field1, u64 field2) const {
return s128_keys.find({id, field1, field2}) != s128_keys.end(); return s128_keys.find({id, field1, field2}) != s128_keys.end();
} }

View File

@ -107,6 +107,8 @@ private:
bool dev_mode; bool dev_mode;
void LoadFromFile(std::string_view filename, bool is_title_keys); void LoadFromFile(std::string_view filename, bool is_title_keys);
void AttemptLoadKeyFile(std::string_view dir1, std::string_view dir2, std::string_view filename,
bool title);
static std::unordered_map<std::string, KeyIndex<S128KeyType>> s128_file_id; static std::unordered_map<std::string, KeyIndex<S128KeyType>> s128_file_id;
static std::unordered_map<std::string, KeyIndex<S256KeyType>> s256_file_id; static std::unordered_map<std::string, KeyIndex<S256KeyType>> s256_file_id;