summaryrefslogtreecommitdiff
path: root/src/core/crypto/key_manager.cpp
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/core/crypto/key_manager.cpp
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/core/crypto/key_manager.cpp')
-rw-r--r--src/core/crypto/key_manager.cpp25
1 files changed, 18 insertions, 7 deletions
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}