File PrusaSlicer-2.9.1-pr14263-secretstorage.patch of Package PrusaSlicer
From a04537928d480ec9597b663d1eaa8db550cc6b4e Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Tue, 11 Mar 2025 21:16:20 +0100
Subject: [PATCH 1/5] GUI:PhysicalPrinterDialog: Fix secret storage
user/password check
---
src/slic3r/GUI/PhysicalPrinterDialog.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Index: PrusaSlicer-version_2.9.3/src/slic3r/GUI/PhysicalPrinterDialog.cpp
===================================================================
--- PrusaSlicer-version_2.9.3.orig/src/slic3r/GUI/PhysicalPrinterDialog.cpp
+++ PrusaSlicer-version_2.9.3/src/slic3r/GUI/PhysicalPrinterDialog.cpp
@@ -282,7 +282,7 @@ PhysicalPrinterDialog::PhysicalPrinterDi
for (const std::string& preset_name : preset_names)
m_presets.emplace_back(new PresetForPrinter(this, preset_name));
// "stored" indicates data are stored secretly, load them from store.
- if (m_printer.config.opt_string("printhost_password") == "stored" && m_printer.config.opt_string("printhost_password") == "stored") {
+ if (m_printer.config.opt_string("printhost_user") == "stored" && m_printer.config.opt_string("printhost_password") == "stored") {
std::string username;
std::string password;
if (load_secret(m_printer.name, "printhost_password", username, password)) {
@@ -295,6 +295,17 @@ PhysicalPrinterDialog::PhysicalPrinterDi
m_printer.config.opt_string("printhost_password") = std::string();
}
}
+
+ if (m_printer.config.opt_string("printhost_apikey") == "stored") {
+ std::string dummy;
+ std::string apikey;
+ if (load_secret(m_printer.name, "printhost_apikey", dummy, apikey)) {
+ if (!apikey.empty())
+ m_printer.config.opt_string("printhost_apikey") = apikey;
+ } else {
+ m_printer.config.opt_string("printhost_apikey") = std::string();
+ }
+ }
}
if (m_presets.size() == 1)
@@ -972,6 +983,13 @@ void PhysicalPrinterDialog::OnOK(wxEvent
m_printer.config.opt_string("printhost_password", false) = "stored";
}
}
+ if (!m_printer.config.opt_string("printhost_apikey").empty()) {
+ if (save_secret(m_printer.name, "printhost_apikey",
+ "apikey", /* username will be ignored */
+ m_printer.config.opt_string("printhost_apikey"))) {
+ m_printer.config.opt_string("printhost_apikey", false) = "stored";
+ }
+ }
// save new physical printer
printers.save_printer(m_printer, renamed_from);
Index: PrusaSlicer-version_2.9.3/src/slic3r/GUI/Plater.cpp
===================================================================
--- PrusaSlicer-version_2.9.3.orig/src/slic3r/GUI/Plater.cpp
+++ PrusaSlicer-version_2.9.3/src/slic3r/GUI/Plater.cpp
@@ -6698,7 +6698,7 @@ void Plater::send_gcode()
// Passwords and API keys
// "stored" indicates data are stored secretly, load them from store.
std::string printer_name = wxGetApp().preset_bundle->physical_printers.get_selected_printer().name;
- if (physical_printer_config->opt_string("printhost_password") == "stored" && physical_printer_config->opt_string("printhost_password") == "stored") {
+ if (physical_printer_config->opt_string("printhost_user") == "stored" && physical_printer_config->opt_string("printhost_password") == "stored") {
std::string username;
std::string password;
if (load_secret(printer_name, "printhost_password", username, password)) {
@@ -6712,16 +6712,14 @@ void Plater::send_gcode()
physical_printer_config->opt_string("printhost_password") = std::string();
}
}
- /*
if (physical_printer_config->opt_string("printhost_apikey") == "stored") {
- std::string username;
- std::string password;
- if (load_secret(printer_name, "printhost_apikey", username, password) && !password.empty())
- physical_printer_config->opt_string("printhost_apikey") = password;
+ std::string dummy;
+ std::string apikey;
+ if (load_secret(printer_name, "printhost_apikey", dummy, apikey) && !apikey.empty())
+ physical_printer_config->opt_string("printhost_apikey") = apikey;
else
physical_printer_config->opt_string("printhost_apikey") = std::string();
}
- */
send_gcode_inner(physical_printer_config);
}
Index: PrusaSlicer-version_2.9.3/src/slic3r/GUI/MainFrame.cpp
===================================================================
--- PrusaSlicer-version_2.9.3.orig/src/slic3r/GUI/MainFrame.cpp
+++ PrusaSlicer-version_2.9.3/src/slic3r/GUI/MainFrame.cpp
@@ -922,6 +922,37 @@ void MainFrame::remove_printables_webvie
m_printables_webview->destroy_browser();
}
+namespace {
+bool load_secret(const std::string& id, const std::string& opt, std::string& usr, std::string& psswd)
+{
+#if wxUSE_SECRETSTORE
+ wxSecretStore store = wxSecretStore::GetDefault();
+ wxString errmsg;
+ if (!store.IsOk(&errmsg)) {
+ std::string msg = GUI::format("%1% (%2%).", _u8L("This system doesn't support storing passwords securely"), errmsg);
+ BOOST_LOG_TRIVIAL(error) << msg;
+ show_error(nullptr, msg);
+ return false;
+ }
+ const wxString service = GUI::format_wxstr(L"%1%/PhysicalPrinter/%2%/%3%", SLIC3R_APP_NAME, id, opt);
+ wxString username;
+ wxSecretValue password;
+ if (!store.Load(service, username, password)) {
+ std::string msg(_u8L("Failed to load credentials from the system password store."));
+ BOOST_LOG_TRIVIAL(error) << msg;
+ show_error(nullptr, msg);
+ return false;
+ }
+ usr = into_u8(username);
+ psswd = into_u8(password.GetAsString());
+ return true;
+#else
+ BOOST_LOG_TRIVIAL(error) << "wxUSE_SECRETSTORE not supported. Cannot load password from the system store.";
+ return false;
+#endif // wxUSE_SECRETSTORE
+}
+}
+
void MainFrame::show_printer_webview_tab(DynamicPrintConfig* dpc)
{
@@ -932,11 +963,37 @@ void MainFrame::show_printer_webview_tab
if (url.find("http://") != 0 && url.find("https://") != 0) {
url = "http://" + url;
}
+
// set password / api key
+ std::string printer_name = wxGetApp().preset_bundle->physical_printers.get_selected_printer().name;
if (dynamic_cast<const ConfigOptionEnum<AuthorizationType>*>(dpc->option("printhost_authorization_type"))->value == AuthorizationType::atKeyPassword) {
+
+ if (dpc->opt_string("printhost_apikey") == "stored") {
+ std::string dummy;
+ std::string apikey;
+ if (load_secret(printer_name, "printhost_apikey", dummy, apikey) && !apikey.empty())
+ dpc->opt_string("printhost_apikey") = apikey;
+ else
+ dpc->opt_string("printhost_apikey") = std::string();
+ }
+
set_printer_webview_api_key(dpc->opt_string("printhost_apikey"));
}
else {
+ if (dpc->opt_string("printhost_user") == "stored" &&
+ dpc->opt_string("printhost_password") == "stored") {
+ std::string user;
+ std::string password;
+ if (load_secret(printer_name, "printhost_password", user, password) &&
+ !user.empty() && !password.empty()) {
+ dpc->opt_string("printhost_user") = user;
+ dpc->opt_string("printhost_password") = password;
+ }
+ } else {
+ dpc->opt_string("printhost_user") = std::string();
+ dpc->opt_string("printhost_password") = std::string();
+ }
+
set_printer_webview_credentials(dpc->opt_string("printhost_user"), dpc->opt_string("printhost_password"));
}
add_printer_webview_tab(from_u8(url));