summaryrefslogtreecommitdiffstats
path: root/src/core/crypto
diff options
context:
space:
mode:
authorZach Hilman <zachhilman@gmail.com>2018-07-30 00:42:04 +0200
committerZach Hilman <zachhilman@gmail.com>2018-08-01 06:16:54 +0200
commit150527ec194107f0ba5ea9bdef487782e64090ef (patch)
treebf6a2589e1a05eb4546ef74715050d8f986c8e78 /src/core/crypto
parentUse SHGetKnownFolderPath instead of SHGetFolderPathA (diff)
downloadyuzu-150527ec194107f0ba5ea9bdef487782e64090ef.tar
yuzu-150527ec194107f0ba5ea9bdef487782e64090ef.tar.gz
yuzu-150527ec194107f0ba5ea9bdef487782e64090ef.tar.bz2
yuzu-150527ec194107f0ba5ea9bdef487782e64090ef.tar.lz
yuzu-150527ec194107f0ba5ea9bdef487782e64090ef.tar.xz
yuzu-150527ec194107f0ba5ea9bdef487782e64090ef.tar.zst
yuzu-150527ec194107f0ba5ea9bdef487782e64090ef.zip
Diffstat (limited to 'src/core/crypto')
-rw-r--r--src/core/crypto/key_manager.cpp25
-rw-r--r--src/core/crypto/key_manager.h2
2 files changed, 20 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 @@
#include "common/logging/log.h"
#include "core/crypto/key_manager.h"
#include "core/settings.h"
+#include "key_manager.h"
namespace Core::Crypto {
@@ -50,18 +51,17 @@ std::array<u8, 32> operator""_array32(const char* str, size_t len) {
KeyManager::KeyManager() {
// 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) {
dev_mode = true;
- if (FileUtil::Exists(keys_dir + DIR_SEP + "dev.keys"))
- LoadFromFile(keys_dir + DIR_SEP + "dev.keys", false);
+ AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "dev.keys", false);
} else {
dev_mode = false;
- if (FileUtil::Exists(keys_dir + DIR_SEP + "prod.keys"))
- LoadFromFile(keys_dir + DIR_SEP + "prod.keys", false);
+ AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "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) {
@@ -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 {
return s128_keys.find({id, field1, field2}) != s128_keys.end();
}
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:
bool dev_mode;
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<S256KeyType>> s256_file_id;