Skip to content
API Documentation
BastionGuard™
SecureBrowser.cpp File Reference

Go to the source code of this file.

Classes

class  InstanceLock
class  SimpleHandler
class  SecurePopupWindowDelegate
class  SecureBrowserViewDelegate
class  ClamApp

Macros

#define BASTIONGUARD_LOCAL_WARNING_IP   "127.0.0.2"
#define BASTIONGUARD_WARNING_DEFAULT_HTTP   81

Functions

static bool is_payment_domain (const std::string &host)
static void clear_proxy_env ()
void start_local_warning_server ()
static std::string to_lower (std::string s)
static std::string clean_domain (std::string d)
static std::string host_from_url (const std::string &url)
static void load_list_file (const std::string &path, std::vector< std::string > &out)
static bool is_trusted_domain (const std::string &host)

Variables

static std::unique_ptr< LocalWarningServer > g_warning_server
static std::atomic< bool > g_cef_started {false}

Macro Definition Documentation

◆ BASTIONGUARD_LOCAL_WARNING_IP

#define BASTIONGUARD_LOCAL_WARNING_IP   "127.0.0.2"

Definition at line 61 of file SecureBrowser.cpp.

Referenced by start_local_warning_server().

◆ BASTIONGUARD_WARNING_DEFAULT_HTTP

#define BASTIONGUARD_WARNING_DEFAULT_HTTP   81

Definition at line 62 of file SecureBrowser.cpp.

Referenced by start_local_warning_server().

Function Documentation

◆ clean_domain()

std::string clean_domain ( std::string d)
static

Definition at line 135 of file SecureBrowser.cpp.

135 {
136 d = to_lower(d);
137 if (!d.empty() && d[0] == '.') d.erase(0, 1);
138 if (d.rfind("www.", 0) == 0) d.erase(0, 4);
139 auto p = d.find(':');
140 if (p != std::string::npos) d.erase(p);
141 return d;
142}
static std::string to_lower(std::string s)

References clean_domain(), and to_lower().

◆ clear_proxy_env()

void clear_proxy_env ( )
static

Definition at line 71 of file SecureBrowser.cpp.

71 {
72 unsetenv("http_proxy");
73 unsetenv("https_proxy");
74 unsetenv("ftp_proxy");
75 unsetenv("all_proxy");
76 unsetenv("HTTP_PROXY");
77 unsetenv("HTTPS_PROXY");
78 unsetenv("FTP_PROXY");
79 unsetenv("ALL_PROXY");
80 unsetenv("no_proxy");
81 unsetenv("NO_PROXY");
82}

References clear_proxy_env().

Referenced by clear_proxy_env(), SecureBrowser::open(), and SecureBrowser::open_notify().

◆ host_from_url()

std::string host_from_url ( const std::string & url)
static

Definition at line 144 of file SecureBrowser.cpp.

144 {
145 std::string s = url;
146 auto pos = s.find("://");
147 if (pos != std::string::npos) s.erase(0, pos + 3);
148 pos = s.find('/');
149 if (pos != std::string::npos) s.erase(pos);
150 pos = s.find('@');
151 if (pos != std::string::npos) s = s.substr(pos + 1);
152 return clean_domain(s);
153}
static std::string clean_domain(std::string d)

References clean_domain(), and host_from_url().

Referenced by host_from_url(), SimpleHandler::OnBeforeBrowse(), and SimpleHandler::OnCertificateError().

◆ is_payment_domain()

bool is_payment_domain ( const std::string & host)
static

Definition at line 823 of file SecureBrowser.cpp.

823 {
825 return false;
826
827 // Provider di pagamento "navigabili" riconosciuti SEMPRE: senza questo,
828 // il filtro di navigazione del SecureBrowser bloccherebbe Stripe/PayPal/
829 // ecc. quando non sono in payments.json, lasciando una pagina vuota nella
830 // sandbox. NON includere endpoint tecnici (js./api./hooks./cdn.): quelli
831 // sono comunque consentiti come subframe in sessione trusted.
832 {
833 static const std::unordered_set<std::string> builtin = {
834 "stripe.com", "paypal.com", "paypalobjects.com", "adyen.com",
835 "checkout.com", "klarna.com", "worldpay.com", "braintreegateway.com",
836 "nexi.it", "nexigroup.com", "sisalpay.it", "satispay.com",
837 "sumup.com", "square.com", "squareup.com", "mollie.com",
838 "gocardless.com", "wise.com", "revolut.com", "skrill.com",
839 "neteller.com", "paysafecard.com", "amazonpay.com",
840 "wallet.google.com", "pay.google.com",
841 };
842 const std::string hb = clean_domain(host);
843 if (builtin.count(hb)) return true;
844 auto d = hb.find('.');
845 while (d != std::string::npos) {
846 if (builtin.count(hb.substr(d + 1))) return true;
847 d = hb.find('.', d + 1);
848 }
849 }
850
851 static std::unordered_set<std::string> payment_domains;
852 static bool initialized = false;
853
854 if (!initialized) {
855 std::vector<std::string> tmp;
856 std::cerr << _("[SecureBrowser] 🔍 Caricamento domini pagamenti...\n");
857
858 load_list_file("/usr/share/BastionGuard/data/payments/payments.json", tmp);
859
860 const char* home = std::getenv("HOME");
861 if (home) {
862 load_list_file(std::string(home) + "/.local/share/BastionGuard/payments/payments.json", tmp);
863 load_list_file(std::string(home) + "/.config/BastionGuard/payments.json", tmp);
864 }
865
866 for (auto& d : tmp) {
867 payment_domains.insert(clean_domain(d));
868 }
869
870 std::cerr << _("[SecureBrowser] ✅ Cache pagamenti inizializzata: ")
871 << payment_domains.size() << _(" domini.\n");
872
873 initialized = true;
874 }
875
876 const std::string h = clean_domain(host);
877
878 if (payment_domains.count(h)) {
879 std::cerr << _("[SecureBrowser] 🟢 Payment trusted (match diretto): ") << h << "\n";
880 return true;
881 }
882
883 auto dot = h.find('.');
884 while (dot != std::string::npos) {
885 std::string parent = h.substr(dot + 1);
886 if (payment_domains.count(parent)) {
887 std::cerr << _("[SecureBrowser] 🟢 Payment trusted (match parent '")
888 << parent << "'): " << h << "\n";
889 return true;
890 }
891 dot = h.find('.', dot + 1);
892 }
893
894 return false;
895}
static void load_list_file(const std::string &path, std::vector< std::string > &out)
#define _(s)
static bool get_secure_payments_enabled()

References _, clean_domain(), SettingsStore::get_secure_payments_enabled(), is_payment_domain(), and load_list_file().

Referenced by is_payment_domain(), and SimpleHandler::OnBeforeBrowse().

◆ is_trusted_domain()

bool is_trusted_domain ( const std::string & host)
static

Definition at line 209 of file SecureBrowser.cpp.

209 {
210 static std::unordered_set<std::string> trusted_domains;
211 static bool initialized = false;
212
213 if (!initialized) {
214 std::vector<std::string> tmp;
215 std::cerr << _("[SecureBrowser] 🔍 Caricamento domini trusted...\n");
216 load_list_file("/usr/share/BastionGuard/data/bank/banks.json", tmp);
217
218 const char* home = std::getenv("HOME");
219 if (home) {
220 load_list_file(std::string(home) + "/.local/share/BastionGuard/banks.json", tmp);
221 load_list_file(std::string(home) + "/.config/BastionGuard/whitelist.json", tmp);
222 }
223
224 for (auto& d : tmp) {
225 trusted_domains.insert(clean_domain(d));
226 }
227
228 std::cerr << _("[SecureBrowser] ✅ Cache inizializzata: ")
229 << trusted_domains.size() << _(" domini trusted.\n");
230
231 if (trusted_domains.count("intesasanpaolo.com"))
232 std::cerr << _("[SecureBrowser] 🔎 Verifica: 'intesasanpaolo.com' presente in cache.\n");
233 else
234 std::cerr << _("[SecureBrowser] 🔎 Verifica: 'intesasanpaolo.com' NON presente in cache.\n");
235
236 initialized = true;
237 }
238
239 const std::string h = clean_domain(host);
240
241 if (trusted_domains.count(h)) {
242 std::cerr << _("[SecureBrowser] 🟢 Trusted (match diretto): ") << h << "\n";
243 return true;
244 }
245
246 auto dot = h.find('.');
247 while (dot != std::string::npos) {
248 std::string parent = h.substr(dot + 1);
249 if (trusted_domains.count(parent)) {
250 std::cerr << Glib::ustring::compose(
251 _("[SecureBrowser] 🟢 Trusted (match parent '%1'): %2"),
252 parent,
253 h
254 ) << "\n";
255 return true;
256 }
257 dot = h.find('.', dot + 1);
258 }
259
260 std::cerr << _("[SecureBrowser] 🔴 NON trusted: ") << h << "\n";
261 return false;
262}

References _, clean_domain(), is_trusted_domain(), and load_list_file().

Referenced by SimpleHandler::OnBeforeBrowse().

◆ load_list_file()

void load_list_file ( const std::string & path,
std::vector< std::string > & out )
static

Definition at line 155 of file SecureBrowser.cpp.

155 {
156 if (!fs::exists(path)) {
157 std::cerr << _("[SecureBrowser] ⚠ File non trovato: ") << path << "\n";
158 return;
159 }
160
161 try {
162 std::ifstream f(path, std::ios::binary);
163 if (!f.good()) {
164 std::cerr << _("[SecureBrowser] ⚠ Impossibile aprire: ") << path << "\n";
165 return;
166 }
167
168 std::string data((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
169 data.erase(std::remove(data.begin(), data.end(), '\0'), data.end());
170
171 nlohmann::json j = nlohmann::json::parse(data, nullptr, true, true);
172
173 auto push_domain = [&](const std::string& d_raw) {
174 std::string d = clean_domain(d_raw);
175 if (!d.empty()) out.push_back(d);
176 };
177
178 if (j.is_object()) {
179 if (j.contains("list") && j["list"].is_array()) {
180 for (const auto& v : j["list"]) {
181 if (v.is_string()) push_domain(v.get<std::string>());
182 }
183 } else if (j.contains("domains") && j["domains"].is_array()) {
184 for (const auto& v : j["domains"]) {
185 if (v.is_string()) push_domain(v.get<std::string>());
186 }
187 } else if (j.contains("whitelist") && j["whitelist"].is_array()) {
188 for (const auto& v : j["whitelist"]) {
189 if (v.is_string()) push_domain(v.get<std::string>());
190 }
191 }
192 } else if (j.is_array()) {
193 for (const auto& v : j) {
194 if (v.is_string()) push_domain(v.get<std::string>());
195 }
196 }
197
198 std::cerr << _("[SecureBrowser] ✅ Caricati ") << out.size()
199 << _(" domini trusted da ") << path << "\n";
200 } catch (const std::exception& e) {
201 std::cerr << Glib::ustring::compose(
202 _("[SecureBrowser] ❌ Errore parsing JSON (%1): %2"),
203 path,
204 e.what()
205 ) << "\n";
206 }
207}

References _, clean_domain(), and load_list_file().

◆ start_local_warning_server()

void start_local_warning_server ( )

Definition at line 84 of file SecureBrowser.cpp.

84 {
85 if (!g_warning_server) {
86 g_warning_server = std::make_unique<LocalWarningServer>(
88 444,
90 "",
91 "",
92 ""
93 );
94 g_warning_server->start();
95 }
96}
static std::unique_ptr< LocalWarningServer > g_warning_server
#define BASTIONGUARD_WARNING_DEFAULT_HTTP
#define BASTIONGUARD_LOCAL_WARNING_IP

References BASTIONGUARD_LOCAL_WARNING_IP, BASTIONGUARD_WARNING_DEFAULT_HTTP, g_warning_server, and start_local_warning_server().

Referenced by SecureBrowser::open(), and start_local_warning_server().

◆ to_lower()

std::string to_lower ( std::string s)
static

Definition at line 129 of file SecureBrowser.cpp.

129 {
130 std::transform(s.begin(), s.end(), s.begin(),
131 [](unsigned char c){ return static_cast<char>(std::tolower(c)); });
132 return s;
133}

References to_lower().

Variable Documentation

◆ g_cef_started

std::atomic<bool> g_cef_started {false}
static

Definition at line 67 of file SecureBrowser.cpp.

Referenced by SecureBrowser::open().

◆ g_warning_server

std::unique_ptr<LocalWarningServer> g_warning_server
static

Definition at line 66 of file SecureBrowser.cpp.

Referenced by start_local_warning_server().