summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Zach Hilman2018-07-29 18:42:04 -0400
committerGravatar Zach Hilman2018-08-01 00:16:54 -0400
commit150527ec194107f0ba5ea9bdef487782e64090ef (patch)
treebf6a2589e1a05eb4546ef74715050d8f986c8e78 /src
parentUse SHGetKnownFolderPath instead of SHGetFolderPathA (diff)
downloadyuzu-150527ec194107f0ba5ea9bdef487782e64090ef.tar.gz
yuzu-150527ec194107f0ba5ea9bdef487782e64090ef.tar.xz
yuzu-150527ec194107f0ba5ea9bdef487782e64090ef.zip
Allow key loading from %YUZU_DIR%/keys in addition to ~/.switch
Diffstat (limited to 'src')
-rw-r--r--src/common/common_paths.h1
-rw-r--r--src/common/file_util.cpp1
-rw-r--r--src/common/file_util.h1
-rw-r--r--src/core/crypto/key_manager.cpp25
-rw-r--r--src/core/crypto/key_manager.h2
5 files changed, 23 insertions, 7 deletions
diff --git a/src/common/common_paths.h b/src/common/common_paths.h
index 6799a357a..df2ce80b1 100644
--- a/src/common/common_paths.h
+++ b/src/common/common_paths.h
@@ -32,6 +32,7 @@
32#define SDMC_DIR "sdmc" 32#define SDMC_DIR "sdmc"
33#define NAND_DIR "nand" 33#define NAND_DIR "nand"
34#define SYSDATA_DIR "sysdata" 34#define SYSDATA_DIR "sysdata"
35#define KEYS_DIR "keys"
35#define LOG_DIR "log" 36#define LOG_DIR "log"
36 37
37// Filenames 38// Filenames
diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp
index ed38c3ced..7aeda737f 100644
--- a/src/common/file_util.cpp
+++ b/src/common/file_util.cpp
@@ -706,6 +706,7 @@ const std::string& GetUserPath(UserPath path, const std::string& new_path) {
706 paths.emplace(UserPath::SDMCDir, user_path + SDMC_DIR DIR_SEP); 706 paths.emplace(UserPath::SDMCDir, user_path + SDMC_DIR DIR_SEP);
707 paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP); 707 paths.emplace(UserPath::NANDDir, user_path + NAND_DIR DIR_SEP);
708 paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP); 708 paths.emplace(UserPath::SysDataDir, user_path + SYSDATA_DIR DIR_SEP);
709 paths.emplace(UserPath::KeysDir, user_path + KEYS_DIR DIR_SEP);
709 // TODO: Put the logs in a better location for each OS 710 // TODO: Put the logs in a better location for each OS
710 paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP); 711 paths.emplace(UserPath::LogDir, user_path + LOG_DIR DIR_SEP);
711 } 712 }
diff --git a/src/common/file_util.h b/src/common/file_util.h
index d530d86c9..28697d527 100644
--- a/src/common/file_util.h
+++ b/src/common/file_util.h
@@ -23,6 +23,7 @@ namespace FileUtil {
23enum class UserPath { 23enum class UserPath {
24 CacheDir, 24 CacheDir,
25 ConfigDir, 25 ConfigDir,
26 KeysDir,
26 LogDir, 27 LogDir,
27 NANDDir, 28 NANDDir,
28 RootDir, 29 RootDir,
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp
index ea20bc31b..dea092b5e 100644
--- a/src/core/crypto/key_manager.cpp
+++ b/src/core/crypto/key_manager.cpp
@@ -12,6 +12,7 @@
12#include "common/logging/log.h" 12#include "common/logging/log.h"
13#include "core/crypto/key_manager.h" 13#include "core/crypto/key_manager.h"
14#include "core/settings.h" 14#include "core/settings.h"
15#include "key_manager.h"
15 16
16namespace Core::Crypto { 17namespace Core::Crypto {
17 18
@@ -50,18 +51,17 @@ std::array<u8, 32> operator""_array32(const char* str, size_t len) {
50 51
51KeyManager::KeyManager() { 52KeyManager::KeyManager() {
52 // Initialize keys 53 // Initialize keys
53 std::string keys_dir = FileUtil::GetHactoolConfigurationPath(); 54 std::string hactool_keys_dir = FileUtil::GetHactoolConfigurationPath();
55 std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir);
54 if (Settings::values.use_dev_keys) { 56 if (Settings::values.use_dev_keys) {
55 dev_mode = true; 57 dev_mode = true;
56 if (FileUtil::Exists(keys_dir + DIR_SEP + "dev.keys")) 58 AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "dev.keys", false);
57 LoadFromFile(keys_dir + DIR_SEP + "dev.keys", false);
58 } else { 59 } else {
59 dev_mode = false; 60 dev_mode = false;
60 if (FileUtil::Exists(keys_dir + DIR_SEP + "prod.keys")) 61 AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "prod.keys", false);
61 LoadFromFile(keys_dir + DIR_SEP + "prod.keys", false);
62 } 62 }
63 if (FileUtil::Exists(keys_dir + DIR_SEP + "title.keys")) 63
64 LoadFromFile(keys_dir + DIR_SEP + "title.keys", true); 64 AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "title.keys", true);
65} 65}
66 66
67void KeyManager::LoadFromFile(std::string_view filename_, bool is_title_keys) { 67void 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) {
104 } 104 }
105} 105}
106 106
107void KeyManager::AttemptLoadKeyFile(std::string_view dir1_, std::string_view dir2_,
108 std::string_view filename_, bool title) {
109 std::string dir1(dir1_);
110 std::string dir2(dir2_);
111 std::string filename(filename_);
112 if (FileUtil::Exists(dir1 + DIR_SEP + filename))
113 LoadFromFile(dir1 + DIR_SEP + filename, title);
114 else if (FileUtil::Exists(dir2 + DIR_SEP + filename))
115 LoadFromFile(dir2 + DIR_SEP + filename, title);
116}
117
107bool KeyManager::HasKey(S128KeyType id, u64 field1, u64 field2) const { 118bool KeyManager::HasKey(S128KeyType id, u64 field1, u64 field2) const {
108 return s128_keys.find({id, field1, field2}) != s128_keys.end(); 119 return s128_keys.find({id, field1, field2}) != s128_keys.end();
109} 120}
diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h
index e04f1d49f..a52ea4cb9 100644
--- a/src/core/crypto/key_manager.h
+++ b/src/core/crypto/key_manager.h
@@ -107,6 +107,8 @@ private:
107 107
108 bool dev_mode; 108 bool dev_mode;
109 void LoadFromFile(std::string_view filename, bool is_title_keys); 109 void LoadFromFile(std::string_view filename, bool is_title_keys);
110 void AttemptLoadKeyFile(std::string_view dir1, std::string_view dir2, std::string_view filename,
111 bool title);
110 112
111 static std::unordered_map<std::string, KeyIndex<S128KeyType>> s128_file_id; 113 static std::unordered_map<std::string, KeyIndex<S128KeyType>> s128_file_id;
112 static std::unordered_map<std::string, KeyIndex<S256KeyType>> s256_file_id; 114 static std::unordered_map<std::string, KeyIndex<S256KeyType>> s256_file_id;