diff --git a/src/slic3r/GUI/ConnectPrinter.cpp b/src/slic3r/GUI/ConnectPrinter.cpp index 5d7bf67e03..c69e81f650 100644 --- a/src/slic3r/GUI/ConnectPrinter.cpp +++ b/src/slic3r/GUI/ConnectPrinter.cpp @@ -14,6 +14,7 @@ #include #include "slic3r/GUI/wxExtensions.hpp" #include "libslic3r/AppConfig.hpp" +#include "IPrinterAgent.hpp" #include "DeviceCore/DevManager.h" @@ -169,14 +170,16 @@ void ConnectPrinterDialog::on_input_enter(wxCommandEvent& evt) void ConnectPrinterDialog::on_button_confirm(wxCommandEvent &event) { wxString code = m_textCtrl_code->GetTextCtrl()->GetValue(); - if (code.empty()) - code = "88888888"; + // Validate only what the user typed; the no-key sentinel is applied afterwards (it contains + // non-alphanumeric characters, so it must not go through this check). for (char c : code) { if (!(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'))) { show_error(this, _L("Invalid input")); return; } } + if (code.empty()) + code = NO_API_KEY_SENTINEL; if (m_obj) { m_obj->set_access_code(code.ToStdString()); } diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 30e7282c0e..e6e483a3e6 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -2681,7 +2681,8 @@ int MachineObject::connect() { if (get_dev_ip().empty()) return -1; std::string username = m_agent ? m_agent->default_lan_username() : std::string(); - std::string password = get_access_code(); + // The stored access code may be the "no API key" sentinel; agents expect an empty credential. + std::string password = normalize_access_code(get_access_code()); std::string port; std::string input = get_dev_ip(); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 11cde7e5f2..45be004c00 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -4263,7 +4263,7 @@ void GUI_App::select_machine(const std::string& agent_id) auto access_code = preset.config.opt_string("printhost_apikey"); // Orca expect non empty access code if (access_code.empty()) { - access_code = "88888888"; + access_code = NO_API_KEY_SENTINEL; } existing = m_device_manager->insert_local_device( diff --git a/src/slic3r/GUI/ReleaseNote.cpp b/src/slic3r/GUI/ReleaseNote.cpp index b200473e08..869c05f47c 100644 --- a/src/slic3r/GUI/ReleaseNote.cpp +++ b/src/slic3r/GUI/ReleaseNote.cpp @@ -2,6 +2,7 @@ #include "I18N.hpp" #include "bambu_networking.hpp" +#include "IPrinterAgent.hpp" #include "libslic3r/Utils.hpp" #include "GUI.hpp" #include "GUI_App.hpp" @@ -1903,7 +1904,7 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt) std::string str_ip = m_input_ip->GetTextCtrl()->GetValue().ToStdString(); std::string str_access_code = m_input_access_code->GetTextCtrl()->GetValue().ToStdString(); if (str_access_code.empty()) - str_access_code = "88888888"; + str_access_code = NO_API_KEY_SENTINEL; std::string str_name = m_input_printer_name->GetTextCtrl()->GetValue().Strip(wxString::both).ToStdString(); // Serial number should not contain lower case letters, and bambu_network plugin crashes // if user entered the wrong serial number, so we call `Upper()` here. @@ -1950,7 +1951,7 @@ void InputIpAddressDialog::on_send_retry() wxString ip = m_input_ip->GetTextCtrl()->GetValue(); wxString str_access_code = m_input_access_code->GetTextCtrl()->GetValue(); if (str_access_code.IsEmpty()) - str_access_code = "88888888"; + str_access_code = NO_API_KEY_SENTINEL; // check support function if (!m_obj) return; diff --git a/src/slic3r/Utils/IPrinterAgent.hpp b/src/slic3r/Utils/IPrinterAgent.hpp index 07ce9af33d..98bd8986af 100644 --- a/src/slic3r/Utils/IPrinterAgent.hpp +++ b/src/slic3r/Utils/IPrinterAgent.hpp @@ -45,6 +45,17 @@ struct PrinterConnectionParams std::string ca_file; }; +// Sentinel stored as a LAN device's access code when the user has not supplied one, so the device +// stays registered (has_access_right() is !access_code.empty()). It is not a real credential: every +// printer agent must translate it back to an empty string before using/sending it on the wire. +inline constexpr const char* NO_API_KEY_SENTINEL = "*_{NO_API_KEY}_*"; + +// Returns an empty string when `code` is the "no API key" sentinel, otherwise `code` unchanged. +inline std::string normalize_access_code(const std::string& code) +{ + return code == NO_API_KEY_SENTINEL ? std::string() : code; +} + /** * FilamentSyncMode - Modes for filament data synchronization. * diff --git a/src/slic3r/Utils/MoonrakerPrinterAgent.cpp b/src/slic3r/Utils/MoonrakerPrinterAgent.cpp index 32fff18342..30c380589a 100644 --- a/src/slic3r/Utils/MoonrakerPrinterAgent.cpp +++ b/src/slic3r/Utils/MoonrakerPrinterAgent.cpp @@ -2338,7 +2338,7 @@ void MoonrakerPrinterAgent::announce_printhost_device() const std::string model_id = device_info.model_id; if (auto* app_config = GUI::wxGetApp().app_config) { - const std::string access_code = device_info.api_key.empty() ? "88888888" : device_info.api_key; + const std::string access_code = device_info.api_key.empty() ? NO_API_KEY_SENTINEL : device_info.api_key; app_config->set_str("access_code", device_info.dev_id, access_code); }