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(-)
diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp
index bb685f60e..6351e676f 100644
--- a/src/slic3r/GUI/PhysicalPrinterDialog.cpp
+++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp
@@ -282,7 +282,7 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxWindow* parent, wxString printer_
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)) {
--
2.48.1
From 27cd64991133e9129cf51130a7992f95c8341d49 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Tue, 11 Mar 2025 20:00:54 +0100
Subject: [PATCH 2/5] GUI:PhysicalPrinterDialog: Also store the apikey in
secret storage
---
src/slic3r/GUI/PhysicalPrinterDialog.cpp | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp
index 6351e676f..775fa99ce 100644
--- a/src/slic3r/GUI/PhysicalPrinterDialog.cpp
+++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp
@@ -295,6 +295,17 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxWindow* parent, wxString printer_
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& event)
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);
--
2.48.1
From 1c34425b34ae54d73d359833a2277c0e7c8af5bc Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Tue, 11 Mar 2025 21:14:04 +0100
Subject: [PATCH 3/5] GUI:Plater: Fix secret storage username/password check
---
src/slic3r/GUI/Plater.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp
index f40b858e8..1072d07c2 100644
--- a/src/slic3r/GUI/Plater.cpp
+++ b/src/slic3r/GUI/Plater.cpp
@@ -6666,7 +6666,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)) {
--
2.48.1
From 52225df036bf76c48560d7bdfbe0b03684115bd5 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Tue, 11 Mar 2025 20:13:45 +0100
Subject: [PATCH 4/5] Plater: Support reading apikey from secret storage
---
src/slic3r/GUI/Plater.cpp | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp
index 1072d07c2..4fdbe064c 100644
--- a/src/slic3r/GUI/Plater.cpp
+++ b/src/slic3r/GUI/Plater.cpp
@@ -6680,16 +6680,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);
}
--
2.48.1
From ae3920fc05f56abe180e338ce082132d0598a8a5 Mon Sep 17 00:00:00 2001
From: Andreas Schneider <asn@cryptomilk.org>
Date: Tue, 11 Mar 2025 21:14:32 +0100
Subject: [PATCH 5/5] GUI:MainFrame: Add support for secret storage for
physical printer
---
src/slic3r/GUI/MainFrame.cpp | 57 ++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp
index aa1998427..94977aef3 100644
--- a/src/slic3r/GUI/MainFrame.cpp
+++ b/src/slic3r/GUI/MainFrame.cpp
@@ -922,6 +922,37 @@ void MainFrame::remove_printables_webview_tab()
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(DynamicPrintConfig* dpc)
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));
--
2.48.1