diff options
| author | 2024-01-24 12:33:34 -0500 | |
|---|---|---|
| committer | 2024-01-25 12:53:48 -0500 | |
| commit | 1a3fc3724aa2d38e717a8dcbfcc6c8a808a693b6 (patch) | |
| tree | bea2cc265f8c2ca59a2f642128e6ee6d1c1196a6 | |
| parent | Merge pull request #12739 from t895/debug-keystore (diff) | |
| download | yuzu-1a3fc3724aa2d38e717a8dcbfcc6c8a808a693b6.tar.gz yuzu-1a3fc3724aa2d38e717a8dcbfcc6c8a808a693b6.tar.xz yuzu-1a3fc3724aa2d38e717a8dcbfcc6c8a808a693b6.zip | |
frontend_common: Remove key rederivation and keep key check
| -rw-r--r-- | src/frontend_common/content_manager.h | 7 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 114 | ||||
| -rw-r--r-- | src/yuzu/main.h | 8 | ||||
| -rw-r--r-- | src/yuzu/main.ui | 5 |
4 files changed, 13 insertions, 121 deletions
diff --git a/src/frontend_common/content_manager.h b/src/frontend_common/content_manager.h index 0b0fee73e..fb92a1695 100644 --- a/src/frontend_common/content_manager.h +++ b/src/frontend_common/content_manager.h | |||
| @@ -368,4 +368,11 @@ inline GameVerificationResult VerifyGameContents( | |||
| 368 | return GameVerificationResult::Success; | 368 | return GameVerificationResult::Success; |
| 369 | } | 369 | } |
| 370 | 370 | ||
| 371 | /** | ||
| 372 | * Checks if the keys required for decrypting firmware and games are available | ||
| 373 | */ | ||
| 374 | inline bool AreKeysPresent() { | ||
| 375 | return !Core::Crypto::KeyManager::Instance().BaseDeriveNecessary(); | ||
| 376 | } | ||
| 377 | |||
| 371 | } // namespace ContentManager | 378 | } // namespace ContentManager |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index d8b0beadf..bb0fbef7c 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -423,7 +423,7 @@ GMainWindow::GMainWindow(std::unique_ptr<QtConfig> config_, bool has_broken_vulk | |||
| 423 | RemoveCachedContents(); | 423 | RemoveCachedContents(); |
| 424 | 424 | ||
| 425 | // Gen keys if necessary | 425 | // Gen keys if necessary |
| 426 | OnReinitializeKeys(ReinitializeKeyBehavior::NoWarning); | 426 | OnCheckFirmwareDecryption(); |
| 427 | 427 | ||
| 428 | game_list->LoadCompatibilityList(); | 428 | game_list->LoadCompatibilityList(); |
| 429 | game_list->PopulateAsync(UISettings::values.game_dirs); | 429 | game_list->PopulateAsync(UISettings::values.game_dirs); |
| @@ -1574,8 +1574,6 @@ void GMainWindow::ConnectMenuEvents() { | |||
| 1574 | connect(multiplayer_state, &MultiplayerState::SaveConfig, this, &GMainWindow::OnSaveConfig); | 1574 | connect(multiplayer_state, &MultiplayerState::SaveConfig, this, &GMainWindow::OnSaveConfig); |
| 1575 | 1575 | ||
| 1576 | // Tools | 1576 | // Tools |
| 1577 | connect_menu(ui->action_Rederive, std::bind(&GMainWindow::OnReinitializeKeys, this, | ||
| 1578 | ReinitializeKeyBehavior::Warning)); | ||
| 1579 | connect_menu(ui->action_Load_Album, &GMainWindow::OnAlbum); | 1577 | connect_menu(ui->action_Load_Album, &GMainWindow::OnAlbum); |
| 1580 | connect_menu(ui->action_Load_Cabinet_Nickname_Owner, | 1578 | connect_menu(ui->action_Load_Cabinet_Nickname_Owner, |
| 1581 | [this]() { OnCabinet(Service::NFP::CabinetMode::StartNicknameAndOwnerSettings); }); | 1579 | [this]() { OnCabinet(Service::NFP::CabinetMode::StartNicknameAndOwnerSettings); }); |
| @@ -4551,122 +4549,20 @@ void GMainWindow::OnMouseActivity() { | |||
| 4551 | } | 4549 | } |
| 4552 | } | 4550 | } |
| 4553 | 4551 | ||
| 4554 | void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) { | 4552 | void GMainWindow::OnCheckFirmwareDecryption() { |
| 4555 | if (behavior == ReinitializeKeyBehavior::Warning) { | ||
| 4556 | const auto res = QMessageBox::information( | ||
| 4557 | this, tr("Confirm Key Rederivation"), | ||
| 4558 | tr("You are about to force rederive all of your keys. \nIf you do not know what " | ||
| 4559 | "this " | ||
| 4560 | "means or what you are doing, \nthis is a potentially destructive action. " | ||
| 4561 | "\nPlease " | ||
| 4562 | "make sure this is what you want \nand optionally make backups.\n\nThis will " | ||
| 4563 | "delete " | ||
| 4564 | "your autogenerated key files and re-run the key derivation module."), | ||
| 4565 | QMessageBox::StandardButtons{QMessageBox::Ok, QMessageBox::Cancel}); | ||
| 4566 | |||
| 4567 | if (res == QMessageBox::Cancel) | ||
| 4568 | return; | ||
| 4569 | |||
| 4570 | const auto keys_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::KeysDir); | ||
| 4571 | |||
| 4572 | Common::FS::RemoveFile(keys_dir / "prod.keys_autogenerated"); | ||
| 4573 | Common::FS::RemoveFile(keys_dir / "console.keys_autogenerated"); | ||
| 4574 | Common::FS::RemoveFile(keys_dir / "title.keys_autogenerated"); | ||
| 4575 | } | ||
| 4576 | |||
| 4577 | Core::Crypto::KeyManager& keys = Core::Crypto::KeyManager::Instance(); | ||
| 4578 | bool all_keys_present{true}; | ||
| 4579 | |||
| 4580 | if (keys.BaseDeriveNecessary()) { | ||
| 4581 | Core::Crypto::PartitionDataManager pdm{vfs->OpenDirectory("", FileSys::Mode::Read)}; | ||
| 4582 | |||
| 4583 | const auto function = [this, &keys, &pdm] { | ||
| 4584 | keys.PopulateFromPartitionData(pdm); | ||
| 4585 | |||
| 4586 | system->GetFileSystemController().CreateFactories(*vfs); | ||
| 4587 | keys.DeriveETicket(pdm, system->GetContentProvider()); | ||
| 4588 | }; | ||
| 4589 | |||
| 4590 | QString errors; | ||
| 4591 | if (!pdm.HasFuses()) { | ||
| 4592 | errors += tr("Missing fuses"); | ||
| 4593 | } | ||
| 4594 | if (!pdm.HasBoot0()) { | ||
| 4595 | errors += tr(" - Missing BOOT0"); | ||
| 4596 | } | ||
| 4597 | if (!pdm.HasPackage2()) { | ||
| 4598 | errors += tr(" - Missing BCPKG2-1-Normal-Main"); | ||
| 4599 | } | ||
| 4600 | if (!pdm.HasProdInfo()) { | ||
| 4601 | errors += tr(" - Missing PRODINFO"); | ||
| 4602 | } | ||
| 4603 | if (!errors.isEmpty()) { | ||
| 4604 | all_keys_present = false; | ||
| 4605 | QMessageBox::warning( | ||
| 4606 | this, tr("Derivation Components Missing"), | ||
| 4607 | tr("Encryption keys are missing. " | ||
| 4608 | "<br>Please follow <a href='https://yuzu-emu.org/help/quickstart/'>the yuzu " | ||
| 4609 | "quickstart guide</a> to get all your keys, firmware and " | ||
| 4610 | "games.<br><br><small>(%1)</small>") | ||
| 4611 | .arg(errors)); | ||
| 4612 | } | ||
| 4613 | |||
| 4614 | QProgressDialog prog(this); | ||
| 4615 | prog.setRange(0, 0); | ||
| 4616 | prog.setLabelText(tr("Deriving keys...\nThis may take up to a minute depending \non your " | ||
| 4617 | "system's performance.")); | ||
| 4618 | prog.setWindowTitle(tr("Deriving Keys")); | ||
| 4619 | |||
| 4620 | prog.show(); | ||
| 4621 | |||
| 4622 | auto future = QtConcurrent::run(function); | ||
| 4623 | while (!future.isFinished()) { | ||
| 4624 | QCoreApplication::processEvents(); | ||
| 4625 | } | ||
| 4626 | |||
| 4627 | prog.close(); | ||
| 4628 | } | ||
| 4629 | |||
| 4630 | system->GetFileSystemController().CreateFactories(*vfs); | 4553 | system->GetFileSystemController().CreateFactories(*vfs); |
| 4631 | 4554 | if (!ContentManager::AreKeysPresent()) { | |
| 4632 | if (all_keys_present && !this->CheckSystemArchiveDecryption()) { | ||
| 4633 | LOG_WARNING(Frontend, "Mii model decryption failed"); | ||
| 4634 | QMessageBox::warning( | 4555 | QMessageBox::warning( |
| 4635 | this, tr("System Archive Decryption Failed"), | 4556 | this, tr("Derivation Components Missing"), |
| 4636 | tr("Encryption keys failed to decrypt firmware. " | 4557 | tr("Encryption keys are missing. " |
| 4637 | "<br>Please follow <a href='https://yuzu-emu.org/help/quickstart/'>the yuzu " | 4558 | "<br>Please follow <a href='https://yuzu-emu.org/help/quickstart/'>the yuzu " |
| 4638 | "quickstart guide</a> to get all your keys, firmware and " | 4559 | "quickstart guide</a> to get all your keys, firmware and " |
| 4639 | "games.")); | 4560 | "games.")); |
| 4640 | } | 4561 | } |
| 4641 | |||
| 4642 | SetFirmwareVersion(); | 4562 | SetFirmwareVersion(); |
| 4643 | |||
| 4644 | if (behavior == ReinitializeKeyBehavior::Warning) { | ||
| 4645 | game_list->PopulateAsync(UISettings::values.game_dirs); | ||
| 4646 | } | ||
| 4647 | |||
| 4648 | UpdateMenuState(); | 4563 | UpdateMenuState(); |
| 4649 | } | 4564 | } |
| 4650 | 4565 | ||
| 4651 | bool GMainWindow::CheckSystemArchiveDecryption() { | ||
| 4652 | constexpr u64 MiiModelId = 0x0100000000000802; | ||
| 4653 | |||
| 4654 | auto bis_system = system->GetFileSystemController().GetSystemNANDContents(); | ||
| 4655 | if (!bis_system) { | ||
| 4656 | // Not having system BIS files is not an error. | ||
| 4657 | return true; | ||
| 4658 | } | ||
| 4659 | |||
| 4660 | auto mii_nca = bis_system->GetEntry(MiiModelId, FileSys::ContentRecordType::Data); | ||
| 4661 | if (!mii_nca) { | ||
| 4662 | // Not having the Mii model is not an error. | ||
| 4663 | return true; | ||
| 4664 | } | ||
| 4665 | |||
| 4666 | // Return whether we are able to decrypt the RomFS of the Mii model. | ||
| 4667 | return mii_nca->GetRomFS().get() != nullptr; | ||
| 4668 | } | ||
| 4669 | |||
| 4670 | bool GMainWindow::CheckFirmwarePresence() { | 4566 | bool GMainWindow::CheckFirmwarePresence() { |
| 4671 | constexpr u64 MiiEditId = static_cast<u64>(Service::AM::Applets::AppletProgramId::MiiEdit); | 4567 | constexpr u64 MiiEditId = static_cast<u64>(Service::AM::Applets::AppletProgramId::MiiEdit); |
| 4672 | 4568 | ||
diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 280fae5c3..6b72094ff 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h | |||
| @@ -125,11 +125,6 @@ enum class EmulatedDirectoryTarget { | |||
| 125 | SDMC, | 125 | SDMC, |
| 126 | }; | 126 | }; |
| 127 | 127 | ||
| 128 | enum class ReinitializeKeyBehavior { | ||
| 129 | NoWarning, | ||
| 130 | Warning, | ||
| 131 | }; | ||
| 132 | |||
| 133 | namespace VkDeviceInfo { | 128 | namespace VkDeviceInfo { |
| 134 | class Record; | 129 | class Record; |
| 135 | } | 130 | } |
| @@ -400,7 +395,7 @@ private slots: | |||
| 400 | void OnMiiEdit(); | 395 | void OnMiiEdit(); |
| 401 | void OnOpenControllerMenu(); | 396 | void OnOpenControllerMenu(); |
| 402 | void OnCaptureScreenshot(); | 397 | void OnCaptureScreenshot(); |
| 403 | void OnReinitializeKeys(ReinitializeKeyBehavior behavior); | 398 | void OnCheckFirmwareDecryption(); |
| 404 | void OnLanguageChanged(const QString& locale); | 399 | void OnLanguageChanged(const QString& locale); |
| 405 | void OnMouseActivity(); | 400 | void OnMouseActivity(); |
| 406 | bool OnShutdownBegin(); | 401 | bool OnShutdownBegin(); |
| @@ -441,7 +436,6 @@ private: | |||
| 441 | void LoadTranslation(); | 436 | void LoadTranslation(); |
| 442 | void OpenPerGameConfiguration(u64 title_id, const std::string& file_name); | 437 | void OpenPerGameConfiguration(u64 title_id, const std::string& file_name); |
| 443 | bool CheckDarkMode(); | 438 | bool CheckDarkMode(); |
| 444 | bool CheckSystemArchiveDecryption(); | ||
| 445 | bool CheckFirmwarePresence(); | 439 | bool CheckFirmwarePresence(); |
| 446 | void SetFirmwareVersion(); | 440 | void SetFirmwareVersion(); |
| 447 | void ConfigureFilesystemProvider(const std::string& filepath); | 441 | void ConfigureFilesystemProvider(const std::string& filepath); |
diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui index e53f9951e..6a6b0821f 100644 --- a/src/yuzu/main.ui +++ b/src/yuzu/main.ui | |||
| @@ -224,11 +224,6 @@ | |||
| 224 | <string>&Stop</string> | 224 | <string>&Stop</string> |
| 225 | </property> | 225 | </property> |
| 226 | </action> | 226 | </action> |
| 227 | <action name="action_Rederive"> | ||
| 228 | <property name="text"> | ||
| 229 | <string>&Reinitialize keys...</string> | ||
| 230 | </property> | ||
| 231 | </action> | ||
| 232 | <action name="action_Verify_installed_contents"> | 227 | <action name="action_Verify_installed_contents"> |
| 233 | <property name="text"> | 228 | <property name="text"> |
| 234 | <string>&Verify Installed Contents</string> | 229 | <string>&Verify Installed Contents</string> |