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

key_manager: Add support for console-specific keyfile

This commit is contained in:
Zach Hilman 2018-09-23 20:37:27 -04:00
parent 721632fe66
commit ce05df0a6d
2 changed files with 13 additions and 3 deletions

View File

@ -138,6 +138,8 @@ KeyManager::KeyManager() {
AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "title.keys", true); AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "title.keys", true);
AttemptLoadKeyFile(yuzu_keys_dir, yuzu_keys_dir, "title.keys_autogenerated", true); AttemptLoadKeyFile(yuzu_keys_dir, yuzu_keys_dir, "title.keys_autogenerated", true);
AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "console.keys", false);
AttemptLoadKeyFile(yuzu_keys_dir, yuzu_keys_dir, "console.keys_autogenerated", false);
} }
void KeyManager::LoadFromFile(const std::string& filename, bool is_title_keys) { void KeyManager::LoadFromFile(const std::string& filename, bool is_title_keys) {
@ -213,8 +215,10 @@ void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname,
const std::array<u8, Size>& key) { const std::array<u8, Size>& key) {
const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir); const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir);
std::string filename = "title.keys_autogenerated"; std::string filename = "title.keys_autogenerated";
if (!title_key) if (category == KeyCategory::Standard)
filename = dev_mode ? "dev.keys_autogenerated" : "prod.keys_autogenerated"; filename = dev_mode ? "dev.keys_autogenerated" : "prod.keys_autogenerated";
else if (category == KeyCategory::Console)
filename = "console.keys_autogenerated";
const auto add_info_text = !FileUtil::Exists(yuzu_keys_dir + DIR_SEP + filename); const auto add_info_text = !FileUtil::Exists(yuzu_keys_dir + DIR_SEP + filename);
FileUtil::CreateFullPath(yuzu_keys_dir + DIR_SEP + filename); FileUtil::CreateFullPath(yuzu_keys_dir + DIR_SEP + filename);
std::ofstream file(yuzu_keys_dir + DIR_SEP + filename, std::ios::app); std::ofstream file(yuzu_keys_dir + DIR_SEP + filename, std::ios::app);
@ -228,7 +232,7 @@ void KeyManager::WriteKeyToFile(bool title_key, std::string_view keyname,
} }
file << fmt::format("\n{} = {}", keyname, Common::HexArrayToString(key)); file << fmt::format("\n{} = {}", keyname, Common::HexArrayToString(key));
AttemptLoadKeyFile(yuzu_keys_dir, yuzu_keys_dir, filename, title_key); AttemptLoadKeyFile(yuzu_keys_dir, yuzu_keys_dir, filename, category == KeyCategory::Title);
} }
void KeyManager::SetKey(S128KeyType id, Key128 key, u64 field1, u64 field2) { void KeyManager::SetKey(S128KeyType id, Key128 key, u64 field1, u64 field2) {
@ -261,7 +265,7 @@ void KeyManager::SetKey(S256KeyType id, Key256 key, u64 field1, u64 field2) {
std::tie(id, field1, field2); std::tie(id, field1, field2);
}); });
if (iter != s256_file_id.end()) if (iter != s256_file_id.end())
WriteKeyToFile(false, iter->first, key); WriteKeyToFile(KeyCategory::Standard, iter->first, key);
s256_keys[{id, field1, field2}] = key; s256_keys[{id, field1, field2}] = key;
} }

View File

@ -26,6 +26,12 @@ using SHA256Hash = std::array<u8, 0x20>;
static_assert(sizeof(Key128) == 16, "Key128 must be 128 bytes big."); static_assert(sizeof(Key128) == 16, "Key128 must be 128 bytes big.");
static_assert(sizeof(Key256) == 32, "Key128 must be 128 bytes big."); static_assert(sizeof(Key256) == 32, "Key128 must be 128 bytes big.");
enum class KeyCategory : u8 {
Standard,
Title,
Console,
};
enum class S256KeyType : u64 { enum class S256KeyType : u64 {
Header, // Header, //
SDKeySource, // f1=SDKeyType SDKeySource, // f1=SDKeyType