diff options
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/core.cpp | 12 | ||||
-rw-r--r-- | src/core/core.h | 14 | ||||
-rw-r--r-- | src/core/crypto/key_manager.cpp | 27 | ||||
-rw-r--r-- | src/core/crypto/key_manager.h | 2 | ||||
-rw-r--r-- | src/core/file_sys/content_archive.cpp | 10 | ||||
-rw-r--r-- | src/core/loader/loader.h | 3 | ||||
-rw-r--r-- | src/core/loader/xci.cpp | 2 |
7 files changed, 51 insertions, 19 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index b7f4b4532..0ef6af3fe 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -101,8 +101,10 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file static_cast<int>(system_mode.second)); switch (system_mode.second) { - case Loader::ResultStatus::ErrorEncrypted: - return ResultStatus::ErrorLoader_ErrorEncrypted; + case Loader::ResultStatus::ErrorMissingKeys: + return ResultStatus::ErrorLoader_ErrorMissingKeys; + case Loader::ResultStatus::ErrorDecrypting: + return ResultStatus::ErrorLoader_ErrorDecrypting; case Loader::ResultStatus::ErrorInvalidFormat: return ResultStatus::ErrorLoader_ErrorInvalidFormat; case Loader::ResultStatus::ErrorUnsupportedArch: @@ -126,8 +128,10 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file System::Shutdown(); switch (load_result) { - case Loader::ResultStatus::ErrorEncrypted: - return ResultStatus::ErrorLoader_ErrorEncrypted; + case Loader::ResultStatus::ErrorMissingKeys: + return ResultStatus::ErrorLoader_ErrorMissingKeys; + case Loader::ResultStatus::ErrorDecrypting: + return ResultStatus::ErrorLoader_ErrorDecrypting; case Loader::ResultStatus::ErrorInvalidFormat: return ResultStatus::ErrorLoader_ErrorInvalidFormat; case Loader::ResultStatus::ErrorUnsupportedArch: diff --git a/src/core/core.h b/src/core/core.h index c123fe401..a90bff3df 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -43,12 +43,14 @@ public: /// Enumeration representing the return values of the System Initialize and Load process. enum class ResultStatus : u32 { - Success, ///< Succeeded - ErrorNotInitialized, ///< Error trying to use core prior to initialization - ErrorGetLoader, ///< Error finding the correct application loader - ErrorSystemMode, ///< Error determining the system mode - ErrorLoader, ///< Error loading the specified application - ErrorLoader_ErrorEncrypted, ///< Error loading the specified application due to encryption + Success, ///< Succeeded + ErrorNotInitialized, ///< Error trying to use core prior to initialization + ErrorGetLoader, ///< Error finding the correct application loader + ErrorSystemMode, ///< Error determining the system mode + ErrorLoader, ///< Error loading the specified application + ErrorLoader_ErrorMissingKeys, ///< Error because the key/keys needed to run could not be + ///< found. + ErrorLoader_ErrorDecrypting, ///< Error loading the specified application due to encryption ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an /// invalid format ErrorSystemFiles, ///< Error in finding system files diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index 33633de7e..678ac5752 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp @@ -53,8 +53,8 @@ std::array<u8, 32> operator""_array32(const char* str, size_t len) { KeyManager::KeyManager() { // Initialize keys - std::string hactool_keys_dir = FileUtil::GetHactoolConfigurationPath(); - std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir); + const std::string hactool_keys_dir = FileUtil::GetHactoolConfigurationPath(); + const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir); if (Settings::values.use_dev_keys) { dev_mode = true; AttemptLoadKeyFile(yuzu_keys_dir, hactool_keys_dir, "dev.keys", false); @@ -109,9 +109,9 @@ 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_); + const std::string dir1(dir1_); + const std::string dir2(dir2_); + const 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)) @@ -146,6 +146,23 @@ void KeyManager::SetKey(S256KeyType id, Key256 key, u64 field1, u64 field2) { s256_keys[{id, field1, field2}] = key; } +bool KeyManager::KeyFileExists(bool title) { + const std::string hactool_keys_dir = FileUtil::GetHactoolConfigurationPath(); + const std::string yuzu_keys_dir = FileUtil::GetUserPath(FileUtil::UserPath::KeysDir); + if (title) { + return FileUtil::Exists(hactool_keys_dir + DIR_SEP + "title.keys") || + FileUtil::Exists(yuzu_keys_dir + DIR_SEP + "title.keys"); + } + + if (Settings::values.use_dev_keys) { + return FileUtil::Exists(hactool_keys_dir + DIR_SEP + "dev.keys") || + FileUtil::Exists(yuzu_keys_dir + DIR_SEP + "dev.keys"); + } + + return FileUtil::Exists(hactool_keys_dir + DIR_SEP + "prod.keys") || + FileUtil::Exists(yuzu_keys_dir + DIR_SEP + "prod.keys"); +} + const std::unordered_map<std::string, KeyIndex<S128KeyType>> KeyManager::s128_file_id = { {"master_key_00", {S128KeyType::Master, 0, 0}}, {"master_key_01", {S128KeyType::Master, 1, 0}}, diff --git a/src/core/crypto/key_manager.h b/src/core/crypto/key_manager.h index c09a6197e..03152a12c 100644 --- a/src/core/crypto/key_manager.h +++ b/src/core/crypto/key_manager.h @@ -102,6 +102,8 @@ public: void SetKey(S128KeyType id, Key128 key, u64 field1 = 0, u64 field2 = 0); void SetKey(S256KeyType id, Key256 key, u64 field1 = 0, u64 field2 = 0); + static bool KeyFileExists(bool title); + private: std::unordered_map<KeyIndex<S128KeyType>, Key128> s128_keys; std::unordered_map<KeyIndex<S256KeyType>, Key256> s256_keys; diff --git a/src/core/file_sys/content_archive.cpp b/src/core/file_sys/content_archive.cpp index cb59c0a2b..2deb727cc 100644 --- a/src/core/file_sys/content_archive.cpp +++ b/src/core/file_sys/content_archive.cpp @@ -156,9 +156,9 @@ NCA::NCA(VirtualFile file_) : file(std::move(file_)) { encrypted = true; } else { if (!keys.HasKey(Core::Crypto::S256KeyType::Header)) - status = Loader::ResultStatus::ErrorEncrypted; + status = Loader::ResultStatus::ErrorMissingKeys; else - status = Loader::ResultStatus::ErrorInvalidFormat; + status = Loader::ResultStatus::ErrorDecrypting; return; } } @@ -194,6 +194,9 @@ NCA::NCA(VirtualFile file_) : file(std::move(file_)) { if (dec != nullptr) { files.emplace_back(); romfs = files.back(); + } else { + status = Loader::ResultStatus::ErrorMissingKeys; + return; } } else if (section.raw.header.filesystem_type == NCASectionFilesystemType::PFS0) { u64 offset = (static_cast<u64>(header.section_tables[i].media_offset) * @@ -211,6 +214,9 @@ NCA::NCA(VirtualFile file_) : file(std::move(file_)) { if (IsDirectoryExeFS(dirs.back())) exefs = dirs.back(); } + } else { + status = Loader::ResultStatus::ErrorMissingKeys; + return; } } } diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index dc8d28311..cd8b41bb6 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h @@ -73,7 +73,8 @@ enum class ResultStatus { ErrorNotUsed, ErrorAlreadyLoaded, ErrorMemoryAllocationFailed, - ErrorEncrypted, + ErrorMissingKeys, + ErrorDecrypting, ErrorUnsupportedArch, }; diff --git a/src/core/loader/xci.cpp b/src/core/loader/xci.cpp index 74940fb83..d757862f0 100644 --- a/src/core/loader/xci.cpp +++ b/src/core/loader/xci.cpp @@ -49,7 +49,7 @@ ResultStatus AppLoader_XCI::Load(Kernel::SharedPtr<Kernel::Process>& process) { } if (xci->GetNCAFileByType(FileSys::NCAContentType::Program) == nullptr) { - return ResultStatus::ErrorEncrypted; + return ResultStatus::ErrorDecrypting; } auto result = nca_loader->Load(process); |