Skip to content
API Documentation
BastionGuard™
first-run-services-window.cpp File Reference

Go to the source code of this file.

Namespaces

namespace  anonymous_namespace{first-run-services-window.cpp}

Functions

static bool anonymous_namespace{first-run-services-window.cpp}::is_system_unit (const std::string &unit_name)
static bool anonymous_namespace{first-run-services-window.cpp}::run_cmd (const std::vector< std::string > &argv, bool silence_stderr=true, bool capture_stdout=false, std::string *out_stdout=nullptr)
static bool anonymous_namespace{first-run-services-window.cpp}::pkexec_servicectl (const std::vector< std::string > &args, bool silence_stderr=false)
static std::string anonymous_namespace{first-run-services-window.cpp}::get_user_intercept_ca_path ()
static std::string anonymous_namespace{first-run-services-window.cpp}::get_system_fallback_ca_path ()
static std::string anonymous_namespace{first-run-services-window.cpp}::resolve_ca_path ()
static void ensure_config_dir ()
static void ensure_flag_dir ()
static void touch_flag_file ()
static void save_config (const std::vector< std::string > &service_names, const std::vector< Gtk::CheckButton * > &check_buttons)
static void install_ca_system ()
static void install_ca_nss_user ()

Variables

const std::string anonymous_namespace{first-run-services-window.cpp}::FLAG_DIR = Glib::get_user_config_dir() + "/BastionGuard"
const std::string anonymous_namespace{first-run-services-window.cpp}::FLAG_FILE = FLAG_DIR + "/first-run-services-done"
const std::string anonymous_namespace{first-run-services-window.cpp}::CONFIG_DIR = Glib::get_user_config_dir() + "/BastionGuard"
const std::string anonymous_namespace{first-run-services-window.cpp}::CONFIG_FILE = CONFIG_DIR + "/config.json"
const std::set< std::string > anonymous_namespace{first-run-services-window.cpp}::SYSTEM_UNITS
static constexpr const char * anonymous_namespace{first-run-services-window.cpp}::CA_HELPER

Function Documentation

◆ ensure_config_dir()

void ensure_config_dir ( )
static

Definition at line 143 of file first-run-services-window.cpp.

144{
145 Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path(CONFIG_DIR);
146
147 if (!dir->query_exists())
148 {
149 try
150 {
151 dir->make_directory_with_parents();
152 }
153 catch (const Glib::Error& ex)
154 {
155 std::cerr << _("Impossibile creare directory config: ") << ex.what() << std::endl;
156 }
157 }
158}
#define _(s)

References _, anonymous_namespace{first-run-services-window.cpp}::CONFIG_DIR, and ensure_config_dir().

Referenced by ensure_config_dir(), and save_config().

◆ ensure_flag_dir()

void ensure_flag_dir ( )
static

Definition at line 160 of file first-run-services-window.cpp.

161{
162 Glib::RefPtr<Gio::File> dir = Gio::File::create_for_path(FLAG_DIR);
163
164 if (!dir->query_exists())
165 {
166 try
167 {
168 dir->make_directory_with_parents();
169 }
170 catch (const Glib::Error& ex)
171 {
172 std::cerr << _("Impossibile creare directory flag: ") << ex.what() << std::endl;
173 }
174 }
175}

References _, ensure_flag_dir(), and anonymous_namespace{first-run-services-window.cpp}::FLAG_DIR.

Referenced by ensure_flag_dir(), and touch_flag_file().

◆ install_ca_nss_user()

void install_ca_nss_user ( )
static

Definition at line 500 of file first-run-services-window.cpp.

501{
503 return;
504 }
505 const std::string ca_src = resolve_ca_path();
506 if (ca_src.empty()) {
507 std::cerr << _("[FirstRun] CA NSS utente non trovata\n");
508 return;
509 }
510
511 auto nss_add = [&](const std::string& db) {
512 if (!std::filesystem::exists(db))
513 return;
514
515 const std::string prefix =
516 std::filesystem::exists(db + "/cert9.db") ? "sql:" : "dbm:";
517
518 run_cmd({"certutil", "-D", "-d", prefix + db, "-n", "BastionGuard-CA"}, true);
519
520 bool ok = run_cmd({"certutil", "-A",
521 "-d", prefix + db,
522 "-n", "BastionGuard-CA",
523 "-t", "CT,,",
524 "-i", ca_src}, false);
525
526 if (ok)
527 std::cerr << _("[FirstRun] ✅ NSS: ") << db << "\n";
528 };
529
530 const std::string home = Glib::get_home_dir();
531
532
533 for (const auto& db : std::vector<std::string>{
534 home + "/.pki/nssdb",
535 home + "/snap/chromium/current/.pki/nssdb",
536 home + "/.var/app/org.chromium.Chromium/.pki/nssdb",
537 home + "/.var/app/com.google.Chrome/.pki/nssdb",
538 home + "/.var/app/com.brave.Browser/.pki/nssdb",
539 home + "/.var/app/com.microsoft.Edge/.pki/nssdb",
540 home + "/.var/app/com.opera.Opera/.pki/nssdb",
541 home + "/.var/app/com.vivaldi.Vivaldi/.pki/nssdb",
542 home + "/.config/BraveSoftware/Brave-Browser/Default",
543 home + "/.config/microsoft-edge/Default",
544 home + "/.config/opera",
545 home + "/.config/vivaldi/Default",
546 home + "/.config/chromium/Default",
547 home + "/.config/yandex-browser/Default",
548 }) {
549 nss_add(db);
550 }
551
552 auto is_profile = [](const std::string& n) {
553 for (const auto& s : {
554 ".default",
555 ".default-release",
556 ".default-esr",
557 ".dev-edition-default",
558 "-release",
559 "-esr"
560 }) {
561 if (n.size() >= std::string(s).size() &&
562 n.compare(n.size() - std::string(s).size(), std::string(s).size(), s) == 0)
563 return true;
564 }
565 return n.size() > 9 && n[8] == '.';
566 };
567
568 for (const auto& base : std::vector<std::string>{
569 home + "/.mozilla/firefox",
570 home + "/.var/app/org.mozilla.firefox/.mozilla/firefox",
571 home + "/.var/app/org.mozilla.firefoxesr/.mozilla/firefox",
572 home + "/snap/firefox/current/.mozilla/firefox",
573 home + "/.librewolf",
574 home + "/.var/app/io.gitlab.librewolf-community/.librewolf",
575 home + "/.waterfox",
576 home + "/.floorp",
577 home + "/.var/app/one.ablaze.floorp/.floorp",
578 home + "/.zen",
579 home + "/.var/app/io.github.zen_browser.zen/.zen",
580 home + "/.icecat",
581 home + "/.thunderbird",
582 home + "/.var/app/org.mozilla.Thunderbird/.thunderbird",
583 home + "/snap/thunderbird/current/.thunderbird",
584 }) {
585 if (!std::filesystem::exists(base))
586 continue;
587
588 try {
589 for (const auto& e : std::filesystem::directory_iterator(base)) {
590 if (e.is_directory() && is_profile(e.path().filename().string()))
591 nss_add(e.path().string());
592 }
593 } catch (...) {}
594 }
595
596 std::cerr << _("[FirstRun] ✅ NSS profili utente aggiornati\n");
597}
static bool run_cmd(const std::vector< std::string > &argv, bool silence_stderr=true, bool capture_stdout=false, std::string *out_stdout=nullptr)

References _, BastionGuard::Platform::cef_available(), install_ca_nss_user(), anonymous_namespace{first-run-services-window.cpp}::resolve_ca_path(), and anonymous_namespace{first-run-services-window.cpp}::run_cmd().

Referenced by FirstRunServicesWindow::apply_and_close(), and install_ca_nss_user().

◆ install_ca_system()

void install_ca_system ( )
static

Definition at line 462 of file first-run-services-window.cpp.

463{
465 std::cerr << _("[FirstRun] CA di sistema disabilitata: CEF non disponibile in questa build/distribuzione.\n");
466 return;
467 }
468 const std::string ca_src = resolve_ca_path();
469
470 if (ca_src.empty()) {
471 std::cerr << _("[FirstRun] CA non trovata né nella home utente né in /etc, verrà installata al primo avvio CEF\n");
472 return;
473 }
474
475 if (!std::filesystem::exists(CA_HELPER)) {
476 std::cerr << _("[FirstRun] helper non trovato: ") << CA_HELPER << "\n";
477 return;
478 }
479
480 std::cerr << _("[FirstRun] Installazione CA BastionGuard nel trust store...\n");
481 std::cerr << _("[FirstRun] Uso certificato: ") << ca_src << "\n";
482
483 bool ok = run_cmd({"pkexec", CA_HELPER, ca_src}, false);
484 if (!ok) {
485 std::cerr << _("[FirstRun] ⚠️ pkexec fallito, tentativo sudo...\n");
486 ok = run_cmd({"sudo", "--non-interactive", CA_HELPER, ca_src}, false);
487 }
488
489 if (ok) {
490 std::cerr << _("[FirstRun] ✅ CA installata nel sistema\n");
491 } else {
492 std::cerr << _("[FirstRun] ❌ Installazione CA fallita — verrà ritentata al primo avvio CEF\n");
493 try {
494 std::filesystem::remove(
495 Glib::get_user_data_dir() + "/BastionGuard/ca-installed.stamp");
496 } catch (...) {}
497 }
498}

References _, anonymous_namespace{first-run-services-window.cpp}::CA_HELPER, BastionGuard::Platform::cef_available(), install_ca_system(), anonymous_namespace{first-run-services-window.cpp}::resolve_ca_path(), and anonymous_namespace{first-run-services-window.cpp}::run_cmd().

Referenced by FirstRunServicesWindow::apply_and_close(), and install_ca_system().

◆ save_config()

void save_config ( const std::vector< std::string > & service_names,
const std::vector< Gtk::CheckButton * > & check_buttons )
static

Definition at line 192 of file first-run-services-window.cpp.

194{
196
197 json config;
198 config["wizard_completed"] = true;
199
200 Glib::DateTime now = Glib::DateTime::create_now_utc();
201 config["installed_at"] = now.format("%FT%TZ");
202
203 json services = json::object();
204 for (size_t i = 0; i < service_names.size(); ++i)
205 {
206 services[service_names[i]] = check_buttons[i]->get_active();
207 }
208 config["services"] = services;
209
210 try
211 {
212 std::ofstream file(CONFIG_FILE, std::ios::out | std::ios::trunc);
213 if (file.is_open())
214 {
215 file << config.dump(2);
216 file.close();
217 }
218 else
219 {
220 std::cerr << _("Errore: impossibile aprire config.json per scrittura") << std::endl;
221 }
222 }
223 catch (const std::exception& ex)
224 {
225 std::cerr << _("Errore durante il salvataggio config: ") << ex.what() << std::endl;
226 }
227}
nlohmann::json json
Definition Backend.cpp:2908
static void ensure_config_dir()

References _, anonymous_namespace{first-run-services-window.cpp}::CONFIG_FILE, ensure_config_dir(), and save_config().

Referenced by FirstRunServicesWindow::apply_and_close(), and save_config().

◆ touch_flag_file()

void touch_flag_file ( )
static

Definition at line 177 of file first-run-services-window.cpp.

178{
180
181 try
182 {
183 std::ofstream touch(FLAG_FILE, std::ios::out | std::ios::trunc);
184 touch.close();
185 }
186 catch (const std::exception& ex)
187 {
188 std::cerr << _("Errore durante scrittura flag file: ") << ex.what() << std::endl;
189 }
190}
static void ensure_flag_dir()

References _, ensure_flag_dir(), anonymous_namespace{first-run-services-window.cpp}::FLAG_FILE, and touch_flag_file().

Referenced by FirstRunServicesWindow::maybe_show(), and touch_flag_file().