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

qt: Add rederive keyset menu option

This commit is contained in:
Zach Hilman 2018-09-23 21:35:32 -04:00
parent 3edafc6802
commit 8f958b89e7
3 changed files with 89 additions and 49 deletions

View File

@ -173,55 +173,7 @@ GMainWindow::GMainWindow()
show();
// Gen keys if necessary
Core::Crypto::KeyManager keys{};
if (keys.BaseDeriveNecessary()) {
Core::Crypto::PartitionDataManager pdm{vfs->OpenDirectory(
FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir), FileSys::Mode::Read)};
const auto function = [this, &keys, &pdm]() {
keys.PopulateFromPartitionData(pdm);
Service::FileSystem::CreateFactories(vfs);
keys.DeriveETicket(pdm);
};
std::vector<std::string> errors;
if (!pdm.HasFuses())
errors.push_back("Missing fuses - Cannot derive SBK");
if (!pdm.HasBoot0())
errors.push_back("Missing BOOT0 - Cannot derive master keys");
if (!pdm.HasPackage2())
errors.push_back("Missing BCPKG2-1-Normal-Main - Cannot derive general keys");
if (!pdm.HasProdInfo())
errors.push_back("Missing PRODINFO - Cannot derive title keys");
if (!errors.empty()) {
std::string error_str;
for (const auto& error : errors)
error_str += " - " + error + "\n";
QMessageBox::warning(
this, tr("Warning Missing Derivation Components"),
tr("The following are missing from your configuration that may hinder key "
"derivation. It will be attempted but may not complete.\n\n") +
QString::fromStdString(error_str));
}
QProgressDialog prog;
prog.setRange(0, 0);
prog.setLabelText(tr("Deriving keys...\nThis may take up to a minute depending \non your "
"system's performance."));
prog.setWindowTitle(tr("Deriving Keys"));
prog.show();
auto future = QtConcurrent::run(function);
while (!future.isFinished()) {
QCoreApplication::processEvents();
}
prog.close();
}
OnReinitializeKeys(false);
// Necessary to load titles from nand in gamelist.
Service::FileSystem::CreateFactories(vfs);
@ -495,6 +447,8 @@ void GMainWindow::ConnectMenuEvents() {
connect(ui.action_Fullscreen, &QAction::triggered, this, &GMainWindow::ToggleFullscreen);
// Help
connect(ui.action_Rederive, &QAction::triggered, this,
std::bind(&GMainWindow::OnReinitializeKeys, this, true));
connect(ui.action_About, &QAction::triggered, this, &GMainWindow::OnAbout);
}
@ -1427,6 +1381,85 @@ void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string det
}
}
void GMainWindow::OnReinitializeKeys(bool callouts) {
if (callouts) {
const auto res = QMessageBox::information(
this, tr("Confirm Key Rederivation"),
tr("You are about to force rederive all of your keys. \nIf you do not know what this "
"means or what you are doing, \nthis is a potentially destructive action. \nPlease "
"make "
"sure this is what you want \nand optionally make backups.\n\nThis will delete your "
"autogenerated key files and re-run the key derivation module."),
QMessageBox::StandardButtons{QMessageBox::Ok, QMessageBox::Cancel});
if (res == QMessageBox::Cancel)
return;
FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::KeysDir) +
"prod.keys_autogenerated");
FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::KeysDir) +
"console.keys_autogenerated");
FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::KeysDir) +
"title.keys_autogenerated");
}
Core::Crypto::KeyManager keys{};
if (keys.BaseDeriveNecessary()) {
Core::Crypto::PartitionDataManager pdm{vfs->OpenDirectory(
FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir), FileSys::Mode::Read)};
const auto function = [this, &keys, &pdm]() {
keys.PopulateFromPartitionData(pdm);
Service::FileSystem::CreateFactories(vfs);
keys.DeriveETicket(pdm);
};
std::vector<std::string> errors;
if (!pdm.HasFuses())
errors.push_back("Missing fuses - Cannot derive SBK");
if (!pdm.HasBoot0())
errors.push_back("Missing BOOT0 - Cannot derive master keys");
if (!pdm.HasPackage2())
errors.push_back("Missing BCPKG2-1-Normal-Main - Cannot derive general keys");
if (!pdm.HasProdInfo())
errors.push_back("Missing PRODINFO - Cannot derive title keys");
if (!errors.empty()) {
std::string error_str;
for (const auto& error : errors)
error_str += " - " + error + "\n";
QMessageBox::warning(
this, tr("Warning Missing Derivation Components"),
tr("The following are missing from your configuration that may hinder key "
"derivation. It will be attempted but may not complete.\n\n") +
QString::fromStdString(error_str));
}
QProgressDialog prog;
prog.setRange(0, 0);
prog.setLabelText(tr("Deriving keys...\nThis may take up to a minute depending \non your "
"system's performance."));
prog.setWindowTitle(tr("Deriving Keys"));
prog.show();
auto future = QtConcurrent::run(function);
while (!future.isFinished()) {
QCoreApplication::processEvents();
}
prog.close();
}
Service::FileSystem::CreateFactories(vfs);
if (callouts) {
game_list->PopulateAsync(UISettings::values.gamedir, UISettings::values.gamedir_deepscan);
}
}
bool GMainWindow::ConfirmClose() {
if (emu_thread == nullptr || !UISettings::values.confirm_before_closing)
return true;

View File

@ -167,6 +167,7 @@ private slots:
void HideFullscreen();
void ToggleWindowMode();
void OnCoreError(Core::System::ResultStatus, std::string);
void OnReinitializeKeys(bool callouts);
private:
void UpdateStatusBar();

View File

@ -103,6 +103,7 @@
</property>
<addaction name="action_Report_Compatibility"/>
<addaction name="separator"/>
<addaction name="action_Rederive"/>
<addaction name="action_About"/>
</widget>
<addaction name="menu_File"/>
@ -159,6 +160,11 @@
<string>&amp;Stop</string>
</property>
</action>
<action name="action_Rederive">
<property name="text">
<string>Reinitialize keys...</string>
</property>
</action>
<action name="action_About">
<property name="text">
<string>About yuzu</string>