Force Proxy to any Windows/MacOS/Linux Application TCP and UDP traffic
C ccybersecurityhttp3httpproxylinuxlinux-proxymacosmacos-appmacos-proxyproxifierproxifier-alternativeproxyclienttcpthick-clientudpwindivertwindows
feat(linux/gui): profiles stored as .pbprofile files, import and export
anof-cyberbf23bc25125b
diff --git a/.github/workflows/build-linux.yml b/.github/workflows/build-linux.ymlindex c298cf1..896205a 100644--- a/.github/workflows/build-linux.yml+++ b/.github/workflows/build-linux.yml@@ -77,6 +77,7 @@ jobs:- name: Unit tests (rule engine, DNS parser, relay)timeout-minutes: 15run: |+ Linux/profile/tests/run_tests.shcd Linux/srcmake test-rules BUILD_DIR="$RUNNER_TEMP/pb-tests"cd tests@@ -185,7 +186,7 @@ jobs:uname -rls /sys/kernel/btf/vmlinux && mount | grep -q "type cgroup2" || { echo "kernel lacks BTF or cgroup2: skipping"; exit 0; }fail=0- for t in e2e e2e_rules e2e_domains e2e_security api_live; do+ for t in e2e e2e_rules e2e_domains e2e_security e2e_profile api_live; doecho "::group::$t"sudo env PB_DIR="$PWD/Linux/output" BPFTOOL="$BPFTOOL" bash "Linux/tests/$t.sh" || fail=1echo "::endgroup::"diff --git a/Linux/README.md b/Linux/README.mdindex 79a1cff..8933d44 100644--- a/Linux/README.md+++ b/Linux/README.md@@ -13,6 +13,7 @@ Universal proxy client for Linux applications - Route any application through SO- [Basic Usage](#basic-usage)- [Command Line Options](#command-line-options)- [Rule Format](#rule-format)+ - [Profiles](#profiles)- [Use Cases](#use-cases)- [Current Limitations](#current-limitations)- [Things to Note](#things-to-note)@@ -89,6 +90,7 @@ The GTK3-based GUI provides:- Proxy configuration (SOCKS5/HTTP with authentication)- Visual rule management with process selection- Real-time connection monitoring+- Profiles: create, switch, duplicate, rename, delete, **import and export** `.pbprofile` files (the Windows/macOS format, see [Profiles](#profiles))- Import/Export rules (JSON format compatible with Windows/macOS)- DNS via Proxy toggle@@ -193,6 +195,11 @@ OPTIONS:curl;wget:10.0.0.0/8:*:TCP:DIRECT*:*:53:UDP:PROXY=tor+ --profile <name|file> Load proxies and rules from a .pbprofile (a file path, or the name of a profile saved+ by the GUI). Same format as the Windows and macOS apps; repeatable, and can be+ combined with --proxy and --rule. Disabled rules are skipped.+ --list-profiles List the profiles saved by the GUI and exit+--dns-via-proxy <bool> Route DNS queries through the proxy (true/false/1/0, default true)--verbose <level> 0 none (default), 1 logs, 2 connections, 3 both@@ -202,6 +209,9 @@ OPTIONS:--help, -h Show this help messageEXAMPLES:+ sudo cli/ProxyBridge --profile work+ sudo cli/ProxyBridge --profile ./myconfig.pbprofile --verbose 2+sudo cli/ProxyBridge --rule curl:*:*:TCP:PROXYsudo cli/ProxyBridge --proxy socks5://192.168.1.10:1080 --proxy work=http://proxy.corp:8080 \@@ -261,6 +271,42 @@ Rules are evaluated **in order and the first match wins** (put specific rules be- A local proxy is never proxied through itself: processes that listen on a configured proxy address (for example Burp, mitmproxy, Tor or `ssh -D` on 127.0.0.1) are exempted automatically, so a rule with process `*` cannot create a loop. The exemption is per process, not per program, and is refreshed every two seconds- Press `Ctrl+C` to stop ProxyBridge; the kernel hooks are removed automatically, even if ProxyBridge crashes+### Profiles++A profile is a named set of proxies and rules. The GUI keeps any number of them (Proxy menu, **Profiles**: Switch, New, Duplicate, Rename, Delete, **Import**, **Export**), and the CLI runs one with `--profile`.+Profiles are stored in the **same `.pbprofile` JSON format as the Windows and macOS apps**, so a file exported on one platform imports on the others:++```bash+sudo ProxyBridge --profile work # a profile saved by the GUI (see --list-profiles)+sudo ProxyBridge --profile ~/exported.pbprofile # any .pbprofile file, e.g. exported from the Windows GUI+sudo ProxyBridge --profile work --rule "curl:*:*:TCP:DIRECT" # profile first, then extra proxies and rules+```++```json+{+ "Version": "1.0",+ "Name": "work",+ "IsTrafficLoggingEnabled": true,+ "DnsViaProxy": true,+ "DefaultProxyId": 1,+ "ProxyConfigs": [+ { "Id": 1, "Name": "corp", "Type": "SOCKS5", "Host": "proxy.corp", "Port": "1080", "Username": "", "Password": "", "SendDomainToProxy": false },+ { "Id": 2, "Name": "web", "Type": "HTTP", "Host": "10.0.0.2", "Port": "8080", "Username": "bob", "Password": "secret" }+ ],+ "ProxyRules": [+ { "ProcessName": "firefox;chrome", "TargetHosts": "*", "TargetPorts": "80;443", "TargetDomains": "*.github.com",+ "Protocol": "TCP", "Action": "PROXY", "IsEnabled": true, "ProxyConfigId": 2 }+ ]+}+```++- Rules point at proxies by `ProxyConfigId`; `0` means the default proxy (`DefaultProxyId`, otherwise the first proxy). A rule that names a proxy that is not in the file makes the profile invalid, rather than silently routing somewhere else.+- Linux keeps domain names in the host list. On export they are written to `TargetDomains` (as the Windows app does) and merged back on import.+- Fields this version has no use for (`LocalhostViaProxy`, `LogFilters`, `SendDomainToProxy`, ...) are ignored on import. `DnsViaProxy` and `DefaultProxyId` are Linux additions that other apps ignore. The CLI takes DNS-via-proxy from the profile unless `--dns-via-proxy` is given, and uses `--verbose` instead of the logging flag.+- Disabled rules (`"IsEnabled": false`) are kept in the GUI and skipped by the CLI.+- **GUI storage:** `/etc/proxybridge/profiles/<name>.pbprofile` (one file per profile) and `/etc/proxybridge/settings.json` (active profile, logging and DNS switches). The directory is `0700` and the files `0600`, because they hold proxy passwords; exported files are `0600` as well, and the CLI warns when a profile with credentials is readable by others. The `config.ini` of earlier versions is converted on the first start and kept as `config.ini.bak`.+- Files are limited to 4 MiB, 256 proxies and 4096 rules; malformed files are rejected with the reason, never partly applied.+## Domain rulesApplications resolve a name themselves and then connect to an IP address, so the kernel only ever sees the address. To apply domain rules ProxyBridge builds, like the macOS version, an **IP → domain-name map from the DNS answers the application received**:@@ -288,7 +334,7 @@ Add as many `--proxy` entries (CLI) or proxies (GUI) as you need; each rule choo- **Redirected UDP flows** are addressed by a loopback flow address that the relay maps back to the original destination. These addresses are not secret (they are visible in `/proc/net/udp`), so on a **multi-user host** another local user can send datagrams to the relay's UDP port and have them forwarded to a destination that some other process is already talking to, through the same proxy. Run ProxyBridge on machines you trust locally.- A rule that needs a proxy that does not exist **blocks** instead of letting traffic through.- The relay listens on loopback only (UDP is additionally bound to the `lo` device). Other network namespaces (containers) are never redirected.-- Proxy passwords are kept in `/etc/proxybridge/config.ini` (mode 0600, root). On the command line, `--proxy user:pass@host` is wiped from the process list after parsing, but a shell history can still keep it; prefer the GUI or a config file for secrets.+- Proxy passwords are kept in the profile files under `/etc/proxybridge/profiles/` (mode 0600, directory 0700, root). On the command line, `--proxy user:pass@host` is wiped from the process list after parsing, but a shell history can still keep it; prefer the GUI or a profile file for secrets.## Use Cases@@ -519,10 +565,12 @@ MIT License - See LICENSE file for details```bashcd Linux && ./build.sh # builds in a temp dir, final files land in Linux/output/cd src && make test-rules BUILD_DIR=/tmp/pbt # rule engine + DNS parser tests (no root needed)+profile/tests/run_tests.sh # .pbprofile reader/writer incl. fuzzing, under ASan/UBSan (no root needed)cd tests && ./run_relay_test.sh both # relay tests, plain and ASan/UBSan (no root needed)cd ../../tests && sudo ./e2e.sh # end-to-end with real kernel hooks (root); uses Linux/output, override with PB_DIR=sudo ./e2e_domains.sh # domain rules with a real resolver client (root, needs dig)sudo ./e2e_rules.sh # every rule form + every proxy type, incl. HTTP auth and UDP rules (root)+sudo ./e2e_profile.sh # `ProxyBridge --profile`: Windows-format profiles on the live datapath (root)sudo ./api_live.sh # library API: edit/move/disable/delete rules and proxies on the live datapath (root)sudo BPFTOOL=$(command -v bpftool) ./e2e_security.sh # relay hand-off cannot be hijacked from another loopback address (root)sudo ./churn.sh 3000 # rule/proxy churn with live traffic: memory, fds and threads must stay flat (root)@@ -530,5 +578,5 @@ sudo ./e2e_openssh.sh # interoperability with a realsudo NODE=$(command -v node) NEXUS_JS=/path/to/nexus-proxy/script.js ./e2e_nexus.sh # against Nexus Proxy, a real forwarding SOCKS5 server with UDP (root)sudo ./scale.sh 10000 # 10,000 concurrent proxied connections (root)sudo ./gui_headless.sh <ProxyBridgeGUI> <libdir> # the real GTK GUI under the Broadway backend (root, needs broadwayd)-cd ../gui/tests && gcc -I../../src -I.. -D_GNU_SOURCE $(pkg-config --cflags gtk+-3.0) config_test.c ../gui_config.c -o /tmp/config_test $(pkg-config --libs gtk+-3.0) && /tmp/config_test # GUI config/profile tests+gui/tests/run_tests.sh # GUI config/profile storage, JSON and event-queue tests (ASan, UBSan, TSan; no root needed)```diff --git a/Linux/gui/Makefile b/Linux/gui/Makefileindex b7ca1a3..0d49055 100644--- a/Linux/gui/Makefile+++ b/Linux/gui/Makefile@@ -8,12 +8,12 @@ GTK_CFLAGS = $(shell pkg-config --cflags gtk+-3.0) -DGDK_VERSION_MIN_REQUIRED=GD-DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_72 -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_72GTK_LIBS = $(shell pkg-config --libs gtk+-3.0)-CFLAGS = $(CFLAGS_COMMON) -Wno-unused-parameter -fPIE -D_GNU_SOURCE -I../src $(GTK_CFLAGS)+CFLAGS = $(CFLAGS_COMMON) -Wno-unused-parameter -fPIE -D_GNU_SOURCE -I../src -I../profile $(GTK_CFLAGS)LDFLAGS = -pie $(HARDEN_LDFLAGS) -L$(LIBDIR) -Wl,-rpath,'$$ORIGIN' -export-dynamic $(STRIP_FLAG)LIBS = -lproxybridge -lpthread $(GTK_LIBS)SOURCES = $(filter-out tests/%,$(wildcard *.c))-OBJECTS = $(addprefix $(BUILD_DIR)/,$(SOURCES:.c=.o))+OBJECTS = $(addprefix $(BUILD_DIR)/,$(SOURCES:.c=.o)) $(BUILD_DIR)/pb_profile.oTARGET = $(BUILD_DIR)/ProxyBridgeGUIall: $(TARGET)@@ -27,6 +27,9 @@ $(TARGET): $(OBJECTS)$(BUILD_DIR)/%.o: %.c gui.h | $(BUILD_DIR)$(CC) $(CFLAGS) -c $< -o $@+$(BUILD_DIR)/pb_profile.o: ../profile/pb_profile.c ../profile/pb_profile.h | $(BUILD_DIR)+ $(CC) $(CFLAGS) -c $< -o $@+clean:rm -f $(OBJECTS) $(TARGET)diff --git a/Linux/gui/gui.h b/Linux/gui/gui.hindex edb7cd9..dfaecae 100644--- a/Linux/gui/gui.h+++ b/Linux/gui/gui.h@@ -39,6 +39,7 @@ typedef struct {GList *proxies;char *default_proxy;GList *rules;+ char *saved; // what is on disk, to skip rewriting unchanged profiles} Profile;typedef void (*RuleImportCb)(const RuleData *rule, int index, void *ud);@@ -80,6 +81,8 @@ Profile *profile_create(const char *name, bool copy_active);bool profile_rename(Profile *p, const char *new_name);bool profile_activate(const char *name);bool profile_delete(Profile *p);+bool profile_export(const Profile *prof, const char *path, char *err, size_t errlen);+Profile *profile_import(const char *path, char *err, size_t errlen); // not activatedvoid on_proxy_configure(GtkWidget *widget, gpointer data);void on_profiles_clicked(GtkWidget *widget, gpointer data);diff --git a/Linux/gui/gui_config.c b/Linux/gui/gui_config.cindex e70d63e..fa27b43 100644--- a/Linux/gui/gui_config.c+++ b/Linux/gui/gui_config.c@@ -1,19 +1,30 @@#include "gui.h"#include <fcntl.h>--#define CONFIG_DIR_DEFAULT "/etc/proxybridge"+#include <dirent.h>+#include "pb_profile.h"GList *g_profiles = NULL;char *g_active_profile = NULL;-// PROXYBRIDGE_CONFIG_DIR overrides the default dir (used for testing)static char *config_dir() {- const char *env = getenv("PROXYBRIDGE_CONFIG_DIR");- return g_strdup((env && *env) ? env : CONFIG_DIR_DEFAULT);+ return g_strdup(pbp_config_dir());+}++static char *profile_path(const char *name) {+ char *file = pbp_filename_for(name);+ if (!file) return NULL;+ char *dir = config_dir();+ char *path = g_strdup_printf("%s/profiles/%s", dir, file);+ free(file);+ g_free(dir);+ return path;}-static char *esc(const char *s) {- return g_uri_escape_string(s ? s : "", NULL, FALSE);+// the file of a deleted or renamed profile must go, or it would come back at the next start+static void remove_profile_file(const char *name) {+ char *path = profile_path(name);+ if (path) unlink(path);+ g_free(path);}static char *unesc(const char *s) {@@ -21,13 +32,6 @@ static char *unesc(const char *s) {return out ? out : g_strdup("");}-static void put_esc(FILE *f, const char *s, char sep) {- char *e = esc(s);- fputs(e, f);- fputc(sep, f);- g_free(e);-}-static void free_profile(Profile *p) {for (GList *l = p->proxies; l != NULL; l = l->next) free_proxy_data((ProxyData *)l->data);for (GList *l = p->rules; l != NULL; l = l->next) free_rule_data((RuleData *)l->data);@@ -35,6 +39,7 @@ static void free_profile(Profile *p) {g_list_free(p->rules);g_free(p->default_proxy);g_free(p->name);+ free(p->saved);g_free(p);}@@ -118,6 +123,7 @@ bool profile_rename(Profile *p, const char *new_name) {if (strcmp(p->name, new_name) == 0) return true;if (profile_find(new_name)) return false;bool active = g_active_profile && strcmp(g_active_profile, p->name) == 0;+ remove_profile_file(p->name);g_free(p->name);p->name = g_strdup(new_name);if (active) {@@ -149,89 +155,190 @@ bool profile_delete(Profile *p) {if (!profile_activate(other->name)) return false;}g_profiles = g_list_remove(g_profiles, p);+ remove_profile_file(p->name);free_profile(p);return true;}-static void write_profile(FILE *f, Profile *prof) {- fputs("[PROFILE:", f);- char *pn = esc(prof->name);- fprintf(f, "%s]\ndefaultProxy=", pn);- g_free(pn);- put_esc(f, prof->default_proxy, '\n');+static ProxyData *find_in_list(GList *list, const char *name) {+ for (GList *l = list; l != NULL; l = l->next)+ if (strcmp(((ProxyData *)l->data)->name, name) == 0) return (ProxyData *)l->data;+ return NULL;+}- // fields are percent-encoded so '|' and newlines are safe: name|type|host|port|user|pass- fputs("[PROXIES]\n", f);+// Borrows the strings of the profile; release with free_pbp_view, not pbp_free.+static void profile_to_pbp(const Profile *prof, struct pbp_profile *out) {+ memset(out, 0, sizeof *out);+ out->name = prof->name;+ out->logging = g_chk_logging;+ out->dns_via_proxy = g_chk_dns;+ out->nproxies = g_list_length(prof->proxies);+ out->nrules = g_list_length(prof->rules);+ out->proxies = g_new0(struct pbp_proxy, out->nproxies + 1);+ out->rules = g_new0(struct pbp_rule, out->nrules + 1);++ uint32_t id = 0;for (GList *l = prof->proxies; l != NULL; l = l->next) {ProxyData *p = (ProxyData *)l->data;- put_esc(f, p->name, '|');- fprintf(f, "%d|", p->type);- put_esc(f, p->host, '|');- fprintf(f, "%u|", p->port);- put_esc(f, p->username, '|');- put_esc(f, p->password, '\n');+ struct pbp_proxy *x = &out->proxies[id++];+ x->id = id;+ x->name = p->name;+ x->type = p->type == PROXY_TYPE_HTTP ? 0 : 1;+ x->host = p->host;+ x->port = p->port;+ x->user = p->username ? p->username : (char *)"";+ x->pass = p->password ? p->password : (char *)"";+ if (prof->default_proxy && strcmp(prof->default_proxy, p->name) == 0) out->default_proxy_id = x->id;}-- // id|protocol|action|enabled|procname|hosts|ports|proxyname- fputs("[RULES]\n", f);+ size_t i = 0;for (GList *l = prof->rules; l != NULL; l = l->next) {RuleData *r = (RuleData *)l->data;- fprintf(f, "%u|%d|%d|%d|%s|%s|%s|", r->id, r->protocol, r->action, r->enabled,- r->process_name ? r->process_name : "", r->target_hosts ? r->target_hosts : "",- r->target_ports ? r->target_ports : "");- put_esc(f, r->proxy_name, '\n');+ struct pbp_rule *x = &out->rules[i++];+ x->process = r->process_name ? r->process_name : (char *)"*";+ x->hosts = r->target_hosts ? r->target_hosts : (char *)"*";+ x->ports = r->target_ports ? r->target_ports : (char *)"*";+ x->protocol = r->protocol;+ x->action = r->action;+ x->enabled = r->enabled;+ if (r->action == RULE_ACTION_PROXY && r->proxy_name && r->proxy_name[0])+ for (size_t k = 0; k < out->nproxies; k++)+ if (strcmp(out->proxies[k].name, r->proxy_name) == 0) { x->proxy_id = out->proxies[k].id; break; }}}-void save_config() {+static void free_pbp_view(struct pbp_profile *v) {+ g_free(v->proxies);+ g_free(v->rules);+}++static void fill_profile_from_pbp(Profile *p, const struct pbp_profile *src) {+ for (size_t i = 0; i < src->nproxies; i++) {+ const struct pbp_proxy *x = &src->proxies[i];+ ProxyData *px = g_malloc0(sizeof(ProxyData));+ px->name = g_strdup(x->name);+ px->type = x->type ? PROXY_TYPE_SOCKS5 : PROXY_TYPE_HTTP;+ px->host = g_strdup(x->host);+ px->port = x->port;+ px->username = g_strdup(x->user);+ px->password = g_strdup(x->pass);+ p->proxies = g_list_append(p->proxies, px);+ }+ for (size_t i = 0; i < src->nrules; i++) {+ const struct pbp_rule *x = &src->rules[i];+ RuleData *r = g_malloc0(sizeof(RuleData));+ r->process_name = g_strdup(x->process);+ r->target_hosts = g_strdup(x->hosts);+ r->target_ports = g_strdup(x->ports);+ r->protocol = x->protocol;+ r->action = x->action;+ r->enabled = x->enabled;+ const struct pbp_proxy *px = x->proxy_id ? pbp_find_proxy(src, x->proxy_id) : NULL;+ if (px) r->proxy_name = g_strdup(px->name);+ p->rules = g_list_append(p->rules, r);+ }+ const struct pbp_proxy *d = src->default_proxy_id ? pbp_find_proxy(src, src->default_proxy_id) : NULL;+ g_free(p->default_proxy);+ p->default_proxy = d ? g_strdup(d->name) : NULL;+}++bool profile_export(const Profile *prof, const char *path, char *err, size_t errlen) {profile_sync_active();+ struct pbp_profile view;+ profile_to_pbp(prof, &view);+ bool ok = pbp_save_file(path, &view, err, errlen) == 0;+ free_pbp_view(&view);+ return ok;+}- char *dir = config_dir();- char *path = g_strdup_printf("%s/config.ini", dir);+static bool name_storable(const char *name) {+ char *file = pbp_filename_for(name);+ free(file);+ return file != NULL;+}++// the profile is named after the file (or the "Name" it carries), made unique if needed+Profile *profile_import(const char *path, char *err, size_t errlen) {+ struct pbp_profile src;+ if (pbp_load_file(path, &src, err, errlen) != 0) return NULL;++ char *base = NULL;+ if (src.name && src.name[0]) {+ base = g_strdup(src.name);+ } else {+ char *file = g_path_get_basename(path);+ size_t n = strlen(file), e = strlen(PBP_EXT);+ if (n > e && strcmp(file + n - e, PBP_EXT) == 0) file[n - e] = 0;+ base = file;+ }+ char *name = g_strdup(base);+ for (int i = 2; profile_find(name) || !name_storable(name); i++) {+ g_free(name);+ name = g_strdup_printf("%s (%d)", base[0] ? base : "Imported", i);+ if (i > 1000) { g_free(name); g_free(base); pbp_free(&src); snprintf(err, errlen, "no free profile name"); return NULL; }+ }+ profile_sync_active();+ Profile *p = profile_new_empty(name);+ fill_profile_from_pbp(p, &src);+ g_free(name);+ g_free(base);+ pbp_free(&src);+ return p;+}++static bool ensure_private_dir(const char *dir) {struct stat st;if (stat(dir, &st) == -1) {- if (g_mkdir_with_parents(dir, 0700) != 0) {- perror("failed to create config dir");- goto out;- }+ if (g_mkdir_with_parents(dir, 0700) != 0) { perror("failed to create config dir"); return false; }} else if (chmod(dir, 0700) != 0) {perror("chmod config dir failed");}+ return true;+}- int cfg_fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0600);- if (cfg_fd < 0) {- fprintf(stderr, "failed to save config to %s\n", path);- goto out;- }- // mode on open only hits create; tighten existing 0644 installs too- if (fchmod(cfg_fd, 0600) != 0) perror("chmod config file failed");- FILE *f = fdopen(cfg_fd, "w");- if (!f) {- close(cfg_fd);- fprintf(stderr, "failed to save config to %s\n", path);- goto out;- }+void save_config() {+ profile_sync_active();- fputs("[SETTINGS]\nactiveProfile=", f);- put_esc(f, g_active_profile, '\n');- fprintf(f, "logging=%d\ndns=%d\n", g_chk_logging, g_chk_dns);- for (GList *l = g_profiles; l != NULL; l = l->next) write_profile(f, (Profile *)l->data);- fclose(f);+ char *dir = config_dir();+ char *pdir = g_strdup_printf("%s/profiles", dir);+ if (!ensure_private_dir(dir) || !ensure_private_dir(pdir)) goto out;++ char err[256];+ for (GList *l = g_profiles; l != NULL; l = l->next) {+ Profile *prof = (Profile *)l->data;+ char *path = profile_path(prof->name);+ if (!path) {+ fprintf(stderr, "profile '%s': the name is too long to be stored\n", prof->name);+ continue;+ }+ struct pbp_profile view;+ profile_to_pbp(prof, &view);+ char *json = pbp_serialize(&view);+ free_pbp_view(&view);+ if (json && !(prof->saved && strcmp(prof->saved, json) == 0 && access(path, F_OK) == 0)) {+ if (pbp_write_file(path, json, err, sizeof err) == 0) {+ free(prof->saved);+ prof->saved = json;+ json = NULL;+ } else {+ fprintf(stderr, "failed to save profile '%s': %s\n", prof->name, err);+ }+ }+ free(json);+ g_free(path);+ }+ char *settings = g_strdup_printf("%s/settings.json", dir);+ if (pbp_settings_save(settings, g_active_profile, g_chk_logging, g_chk_dns, err, sizeof err) != 0)+ fprintf(stderr, "failed to save settings: %s\n", err);+ g_free(settings);out:+ g_free(pdir);g_free(dir);- g_free(path);}static ProxyType proxy_type_from_int(int v) {return v == PROXY_TYPE_HTTP ? PROXY_TYPE_HTTP : PROXY_TYPE_SOCKS5;}-static ProxyData *find_in_list(GList *list, const char *name) {- for (GList *l = list; l != NULL; l = l->next)- if (strcmp(((ProxyData *)l->data)->name, name) == 0) return (ProxyData *)l->data;- return NULL;-}-static ProxyData *parse_proxy_line(char *line) {char *fields[6] = {NULL};int n = 0;@@ -276,14 +383,14 @@ static RuleData *parse_rule_line(char *line) {return rule;}-// files without profile blocks (old format) end up in a profile called "Default"-void load_config() {- char *dir = config_dir();+// config.ini of the previous versions; files without profile blocks end up in a profile called "Default".+// Returns false when there is no such file.+static bool load_legacy_ini(const char *dir, char **saved_active_out) {char *path = g_strdup_printf("%s/config.ini", dir);chmod(path, 0600);FILE *f = fopen(path, "r");- g_free(dir);g_free(path);+ if (!f) return false;char line[8192];int section = 0; // 1=settings, 2=rules, 3=proxies, 4=profile header@@ -294,7 +401,7 @@ void load_config() {char old_ip[256] = "", old_user[256] = "", old_pass[256] = "";int old_port = 0, old_type = PROXY_TYPE_SOCKS5;- while (f && fgets(line, sizeof(line), f)) {+ while (fgets(line, sizeof(line), f)) {line[strcspn(line, "\r\n")] = 0;if (!line[0] || line[0] == '#') continue;@@ -346,7 +453,7 @@ void load_config() {if (rule) cur->rules = g_list_append(cur->rules, rule);}}- if (f) fclose(f);+ fclose(f);if (old_ip[0] && old_port >= 1 && old_port <= 65535) {Profile *d = profile_find("Default");@@ -365,6 +472,11 @@ void load_config() {}}+ *saved_active_out = saved_active;+ return true;+}++static void finish_load(char *saved_active) {if (!g_profiles) profile_new_empty("Default");for (GList *l = g_profiles; l != NULL; l = l->next) {@@ -382,3 +494,67 @@ void load_config() {g_active_profile = g_strdup(act->name);load_globals_from(act);}++static gint compare_names(gconstpointer a, gconstpointer b) {+ return strcmp(*(char *const *)a, *(char *const *)b);+}++// sorted by file name, so the order is the same on every start+static void load_profile_files(const char *dir) {+ char *pdir = g_strdup_printf("%s/profiles", dir);+ GPtrArray *files = g_ptr_array_new_with_free_func(g_free);+ DIR *d = opendir(pdir);+ struct dirent *de;+ while (d && (de = readdir(d)) != NULL)+ if (strlen(de->d_name) > strlen(PBP_EXT)) g_ptr_array_add(files, g_strdup(de->d_name));+ if (d) closedir(d);+ g_ptr_array_sort(files, compare_names);++ for (guint i = 0; i < files->len; i++) {+ const char *file = g_ptr_array_index(files, i);+ char *name = pbp_name_from_filename(file);+ if (!name) continue;+ char *path = g_strdup_printf("%s/%s", pdir, file);+ struct pbp_profile src;+ char err[256];+ chmod(path, 0600);+ if (profile_find(name)) {+ /* duplicate name after decoding: keep the first */+ } else if (pbp_load_file(path, &src, err, sizeof err) == 0) {+ fill_profile_from_pbp(profile_new_empty(name), &src);+ pbp_free(&src);+ } else {+ fprintf(stderr, "ignoring profile '%s': %s\n", name, err);+ }+ g_free(path);+ free(name);+ }+ g_ptr_array_free(files, TRUE);+ g_free(pdir);+}++// profiles/<name>.pbprofile + settings.json; a config.ini from an older version is converted on first start+void load_config() {+ char *dir = config_dir();+ char *settings_active = NULL, *legacy_active = NULL;+ bool migrate = false;++ load_profile_files(dir);+ char *settings = g_strdup_printf("%s/settings.json", dir);+ pbp_settings_load(settings, &settings_active, &g_chk_logging, &g_chk_dns);+ g_free(settings);+ if (!g_profiles) migrate = load_legacy_ini(dir, &legacy_active);+ char *active = g_strdup(migrate && legacy_active ? legacy_active : settings_active);+ free(settings_active);+ g_free(legacy_active);+ finish_load(active);++ if (migrate) {+ save_config();+ char *from = g_strdup_printf("%s/config.ini", dir), *to = g_strdup_printf("%s/config.ini.bak", dir);+ if (rename(from, to) != 0) perror("could not set the old config.ini aside");+ g_free(from);+ g_free(to);+ }+ g_free(dir);+}diff --git a/Linux/gui/gui_settings.c b/Linux/gui/gui_settings.cindex a97d4f4..7d7f14f 100644--- a/Linux/gui/gui_settings.c+++ b/Linux/gui/gui_settings.c@@ -577,6 +577,58 @@ static void on_profile_delete(GtkWidget *widget, gpointer data) {g_free(name);}+static void on_profile_import(GtkWidget *widget, gpointer data) {+ ProfilesInfo *pi = (ProfilesInfo *)data;+ GtkWidget *dialog = gtk_file_chooser_dialog_new("Import Profile", GTK_WINDOW(pi->dialog), GTK_FILE_CHOOSER_ACTION_OPEN,+ "Cancel", GTK_RESPONSE_CANCEL, "Import", GTK_RESPONSE_ACCEPT, NULL);+ GtkFileFilter *filter = gtk_file_filter_new();+ gtk_file_filter_set_name(filter, "ProxyBridge profiles (*.pbprofile)");+ gtk_file_filter_add_pattern(filter, "*.pbprofile");+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);+ GtkFileFilter *all = gtk_file_filter_new();+ gtk_file_filter_set_name(all, "All files");+ gtk_file_filter_add_pattern(all, "*");+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), all);+ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {+ char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));+ char err[256];+ Profile *p = filename ? profile_import(filename, err, sizeof err) : NULL;+ if (p) {+ save_config();+ refresh_profile_store(pi);+ show_message(GTK_WINDOW(pi->dialog), GTK_MESSAGE_INFO, "Imported as profile '%s'. Use Switch to activate it.", p->name);+ } else {+ show_message(GTK_WINDOW(pi->dialog), GTK_MESSAGE_ERROR, "Import failed: %s", filename ? err : "no file selected");+ }+ g_free(filename);+ }+ gtk_widget_destroy(dialog);+}++static void on_profile_export(GtkWidget *widget, gpointer data) {+ ProfilesInfo *pi = (ProfilesInfo *)data;+ char *name = selected_profile_name(pi);+ if (!name) return;+ GtkWidget *dialog = gtk_file_chooser_dialog_new("Export Profile", GTK_WINDOW(pi->dialog), GTK_FILE_CHOOSER_ACTION_SAVE,+ "Cancel", GTK_RESPONSE_CANCEL, "Export", GTK_RESPONSE_ACCEPT, NULL);+ gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);+ char *suggested = g_strdup_printf("%s.pbprofile", name);+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), suggested);+ g_free(suggested);+ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {+ char *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));+ char err[256];+ if (filename && profile_export(profile_find(name), filename, err, sizeof err))+ show_message(GTK_WINDOW(pi->dialog), GTK_MESSAGE_INFO,+ "Profile '%s' exported to %s.\nThe file contains your proxy credentials, so it is readable by you only.", name, filename);+ else+ show_message(GTK_WINDOW(pi->dialog), GTK_MESSAGE_ERROR, "Export failed: %s", filename ? err : "no file selected");+ g_free(filename);+ }+ gtk_widget_destroy(dialog);+ g_free(name);+}+static void on_profile_row_activated(GtkTreeView *tree, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data) {on_profile_switch(NULL, data);}@@ -585,7 +637,7 @@ void on_profiles_clicked(GtkWidget *widget, gpointer data) {ProfilesInfo pi = {0};pi.dialog = gtk_dialog_new_with_buttons("Profiles", GTK_WINDOW(window), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,"Close", GTK_RESPONSE_CLOSE, NULL);- gtk_window_set_default_size(GTK_WINDOW(pi.dialog), 420, 360);+ gtk_window_set_default_size(GTK_WINDOW(pi.dialog), 560, 360);GtkWidget *box = gtk_dialog_get_content_area(GTK_DIALOG(pi.dialog));gtk_container_set_border_width(GTK_CONTAINER(box), 10);@@ -604,9 +656,10 @@ void on_profiles_clicked(GtkWidget *widget, gpointer data) {gtk_box_pack_start(GTK_BOX(box), scroll, TRUE, TRUE, 0);GtkWidget *btns = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);- const char *labels[] = {"Switch", "New", "Duplicate", "Rename", "Delete"};- void (*cbs[])(GtkWidget *, gpointer) = {on_profile_switch, on_profile_new, on_profile_duplicate, on_profile_rename, on_profile_delete};- for (int i = 0; i < 5; i++) {+ const char *labels[] = {"Switch", "New", "Duplicate", "Rename", "Delete", "Import...", "Export..."};+ void (*cbs[])(GtkWidget *, gpointer) = {on_profile_switch, on_profile_new, on_profile_duplicate, on_profile_rename, on_profile_delete,+ on_profile_import, on_profile_export};+ for (int i = 0; i < 7; i++) {GtkWidget *b = gtk_button_new_with_label(labels[i]);g_signal_connect(b, "clicked", G_CALLBACK(cbs[i]), &pi);gtk_box_pack_start(GTK_BOX(btns), b, FALSE, FALSE, 0);diff --git a/Linux/gui/tests/config_test.c b/Linux/gui/tests/config_test.cindex ffd6659..a4b416b 100644--- a/Linux/gui/tests/config_test.c+++ b/Linux/gui/tests/config_test.c@@ -1,7 +1,9 @@// root-free test of gui_config.c: profiles, migration, round trip, leak/heap stress// build: see run_tests.sh#include "gui.h"+#include "pb_profile.h"#include <malloc.h>+#include <glib/gstdio.h>GList *g_proxies_list = NULL;char *g_default_proxy = NULL;@@ -36,6 +38,7 @@ static void add_content(const char *proxy_name) {px->name = g_strdup(proxy_name); px->host = g_strdup("github.com"); px->port = 8080;px->username = g_strdup(""); px->password = g_strdup("s3cr|et");g_proxies_list = g_list_append(g_proxies_list, px);+ g_free(g_default_proxy);g_default_proxy = g_strdup(proxy_name);RuleData *r = g_malloc0(sizeof(RuleData));r->process_name = g_strdup("curl"); r->target_hosts = g_strdup("*.github.com"); r->target_ports = g_strdup("*");@@ -43,6 +46,113 @@ static void add_content(const char *proxy_name) {g_rules_list = g_list_append(g_rules_list, r);}+static void check_storage(const char *dir) {+ struct stat st;+ char *p = g_strdup_printf("%s/profiles/Work.pbprofile", dir);+ CHECK(stat(p, &st) == 0 && (st.st_mode & 0777) == 0600); // profiles hold proxy credentials+ g_free(p);+ p = g_strdup_printf("%s/profiles", dir);+ CHECK(stat(p, &st) == 0 && (st.st_mode & 0777) == 0700);+ g_free(p);+ p = g_strdup_printf("%s/settings.json", dir);+ CHECK(stat(p, &st) == 0);+ g_free(p);+ // the migration set the old file aside+ p = g_strdup_printf("%s/config.ini", dir);+ CHECK(stat(p, &st) != 0);+ g_free(p);+ p = g_strdup_printf("%s/config.ini.bak", dir);+ CHECK(stat(p, &st) == 0 && (st.st_mode & 0777) == 0600);+ g_free(p);+}++static bool profile_file_exists(const char *dir, const char *file) {+ char *p = g_strdup_printf("%s/profiles/%s", dir, file);+ bool ok = g_file_test(p, G_FILE_TEST_EXISTS);+ g_free(p);+ return ok;+}++// import/export in the Windows .pbprofile format, odd names, corrupt files, file bookkeeping+static void test_pbprofile(const char *dir) {+ char err[256];+ CHECK(profile_activate("Default"));+ add_content("exp");+ char *out = g_strdup_printf("%s/out.pbprofile", dir);+ CHECK(profile_export(profile_find("Default"), out, err, sizeof err));+ char *json = NULL;+ CHECK(g_file_get_contents(out, &json, NULL, NULL));+ CHECK(json && strstr(json, "\"TargetDomains\": \"*.github.com\"") && strstr(json, "\"TargetHosts\": \"*\""));+ CHECK(json && strstr(json, "\"Type\": \"HTTP\"") != NULL);+ g_free(json);++ Profile *imp = profile_import(out, err, sizeof err);+ CHECK(imp && strcmp(imp->name, "Default") != 0); // the "Name" in the file is taken, then made unique+ CHECK(imp && g_list_length(imp->proxies) == g_list_length(profile_find("Default")->proxies));+ CHECK(imp && g_list_length(imp->rules) == g_list_length(profile_find("Default")->rules));+ CHECK(imp && strcmp(((RuleData *)g_list_last(imp->rules)->data)->target_hosts, "*.github.com") == 0);+ Profile *imp2 = profile_import(out, err, sizeof err);+ CHECK(imp2 && imp && strcmp(imp2->name, imp->name) != 0);++ // a hostile or damaged file is refused and changes nothing+ guint before = g_list_length(g_profiles);+ char *bad = g_strdup_printf("%s/bad.pbprofile", dir);+ g_file_set_contents(bad, "{\"ProxyRules\":[{\"ProxyConfigId\":42}]}", -1, NULL);+ CHECK(profile_import(bad, err, sizeof err) == NULL && strstr(err, "does not match"));+ g_file_set_contents(bad, "garbage", -1, NULL);+ CHECK(profile_import(bad, err, sizeof err) == NULL);+ CHECK(profile_import("/nonexistent.pbprofile", err, sizeof err) == NULL);+ CHECK(g_list_length(g_profiles) == before);+ g_free(bad);++ // names with path characters are stored safely and survive a restart+ CHECK(profile_create("../../etc/x", false) != NULL);+ CHECK(profile_create("a/b:c*", false) != NULL);+ save_config();+ char *esc_check = g_strdup_printf("%s/../../etc/x", dir);+ CHECK(!g_file_test(esc_check, G_FILE_TEST_EXISTS)); // nothing was written outside the profiles directory+ g_free(esc_check);+ config_free_all();+ load_config();+ CHECK(profile_find("../../etc/x") && profile_find("a/b:c*"));++ // rename and delete take their files with them+ CHECK(profile_rename(profile_find("a/b:c*"), "plain"));+ save_config();+ CHECK(profile_file_exists(dir, "plain.pbprofile"));+ CHECK(profile_delete(profile_find("plain")));+ CHECK(!profile_file_exists(dir, "plain.pbprofile"));+ config_free_all();+ load_config();+ CHECK(!profile_find("plain") && !profile_find("a/b:c*"));++ // a damaged file in the profiles directory is skipped, kept on disk, and the rest still loads+ char *broken = g_strdup_printf("%s/profiles/Broken.pbprofile", dir);+ g_file_set_contents(broken, "{ not json", -1, NULL);+ config_free_all();+ load_config();+ CHECK(!profile_find("Broken") && profile_find("Default"));+ save_config();+ CHECK(profile_file_exists(dir, "Broken.pbprofile"));+ g_remove(broken);+ g_free(broken);+ g_free(out);++ for (GList *l = g_profiles; l;) { // back to a single profile for the stress run+ Profile *p = (Profile *)l->data;+ l = l->next;+ if (strcmp(p->name, "Default") != 0) CHECK(profile_delete(p));+ }+ CHECK(g_list_length(g_profiles) == 1 && strcmp(g_active_profile, "Default") == 0);+ g_free(g_default_proxy);+ for (GList *l = g_proxies_list; l; l = l->next) free_proxy_data(l->data);+ for (GList *l = g_rules_list; l; l = l->next) free_rule_data(l->data);+ g_list_free(g_proxies_list); g_list_free(g_rules_list);+ g_proxies_list = g_rules_list = NULL;+ g_default_proxy = NULL;+ save_config();+}+int main() {char *dir = g_dir_make_tmp("pbcfg-XXXXXX", NULL);CHECK(dir != NULL);@@ -75,10 +185,7 @@ int main() {g_chk_dns = false;save_config();- char *path = g_strdup_printf("%s/config.ini", dir);- struct stat st;- CHECK(stat(path, &st) == 0 && (st.st_mode & 0777) == 0600);- g_free(path);+ check_storage(dir);config_free_all();load_config();@@ -95,6 +202,7 @@ int main() {CHECK(!profile_delete(profile_find("Default")));CHECK(g_list_length(g_profiles) == 1);save_config();+ test_pbprofile(dir);config_free_all();// stress: heap must return to baseline@@ -104,7 +212,7 @@ int main() {if (p) profile_delete(p);}size_t base = heap_used();- for (int i = 0; i < 20000; i++) {+ for (int i = 0; i < 1500; i++) { // every pass writes profile files to diskchar *a = g_strdup_printf("p%d", i), *b = g_strdup_printf("q%d", i), *c = g_strdup_printf("c%d", i);CHECK(profile_create(a, false) != NULL);CHECK(profile_activate(a));diff --git a/Linux/gui/tests/run_tests.sh b/Linux/gui/tests/run_tests.shindex c09b9cf..cd23bb2 100755--- a/Linux/gui/tests/run_tests.sh+++ b/Linux/gui/tests/run_tests.sh@@ -3,11 +3,11 @@set -ecd "$(dirname "$0")/.."OUT="${1:-$(mktemp -d)}"-CF="-Wall -Wextra -Wno-unused-parameter -g -fsanitize=address,undefined -I../src -I. -D_GNU_SOURCE $(pkg-config --cflags gtk+-3.0)"+CF="-Wall -Wextra -Wno-unused-parameter -g -fsanitize=address,undefined -I../src -I../profile -I. -D_GNU_SOURCE $(pkg-config --cflags gtk+-3.0)"LF="$(pkg-config --libs gtk+-3.0)"-gcc $CF tests/config_test.c gui_config.c -o "$OUT/config_test" $LF+gcc $CF tests/config_test.c gui_config.c ../profile/pb_profile.c -o "$OUT/config_test" $LFgcc $CF tests/json_test.c gui_json.c -o "$OUT/json_test" $LF-gcc -O1 -I../src -I. -D_GNU_SOURCE $(pkg-config --cflags gtk+-3.0) tests/config_test.c gui_config.c -o "$OUT/config_plain" $LF+gcc -O1 -I../src -I../profile -I. -D_GNU_SOURCE $(pkg-config --cflags gtk+-3.0) tests/config_test.c gui_config.c ../profile/pb_profile.c -o "$OUT/config_plain" $LF"$OUT/config_plain"ASAN_OPTIONS=detect_leaks=1 "$OUT/config_test"ASAN_OPTIONS=detect_leaks=1 "$OUT/json_test"diff --git a/Linux/tests/gui_headless.sh b/Linux/tests/gui_headless.shindex d3e9d48..68da172 100755--- a/Linux/tests/gui_headless.sh+++ b/Linux/tests/gui_headless.sh@@ -20,6 +20,7 @@ python3 "$HERE/fake_dns.py" $DNSIP "$DLOG" >/dev/null 2>&1 & DNSP=$!broadwayd :9 >/dev/null 2>&1 & BW=$!sleep 1.5+# Seeded in the format of the previous GUI versions, so the first start also exercises the migration to .pbprofile files.# profile "Default": proxy a (default) + b; "Alt": curl goes through b insteadwrite_cfg() { # active-profilemkdir -p "$WORK/cfg"@@ -50,7 +51,8 @@ chmod 600 "$WORK/cfg/config.ini"}run_gui() { # active profile- write_cfg "$1"+ if [ ! -d "$WORK/cfg/profiles" ]; then write_cfg "$1"+ else printf '{ "ActiveProfileName": "%s", "IsTrafficLoggingEnabled": true, "DnsViaProxy": true }\n' "$1" > "$WORK/cfg/settings.json"; fiGDK_BACKEND=broadway BROADWAY_DISPLAY=:9 PROXYBRIDGE_CONFIG_DIR="$WORK/cfg" LD_LIBRARY_PATH="$LIBDIR" "$GUI" > "$WORK/gui.out" 2>&1 & GUI_PID=$!for _ in $(seq 60); do "${BPFTOOL:-bpftool}" prog show 2>/dev/null | grep -q pb_connect4 && break; kill -0 $GUI_PID 2>/dev/null || break; sleep 0.25; donesleep 1@@ -79,8 +81,26 @@ run_gui Altout=$(curl -s -m 5 http://192.0.2.7/); has "Alt profile: same rule now goes through proxy b" "$out" "hello-from-B dst=192.0.2.7:80"out=$(curl -s -m 2 http://198.51.100.7/ 2>&1; echo "rc=$?"); [[ "$out" != *hello-from* ]] && ok "Alt profile does not apply rules of the Default profile" || bad "Default rules leaked into Alt"stop_gui-grep -q "^\[PROFILE:Default\]" "$WORK/cfg/config.ini" && grep -q "^\[PROFILE:Alt\]" "$WORK/cfg/config.ini" && ok "both profiles preserved in the config after the GUI saved it" || bad "profiles lost from the config"-[ "$(stat -c %a "$WORK/cfg/config.ini")" = 600 ] && ok "config file mode is 0600" || bad "config file mode"+P="$WORK/cfg/profiles"+[ -f "$P/Default.pbprofile" ] && [ -f "$P/Alt.pbprofile" ] && ok "the old config.ini was converted to one .pbprofile per profile" || bad "profiles not written: $(ls "$WORK/cfg" "$P")"+[ -f "$WORK/cfg/config.ini.bak" ] && [ ! -f "$WORK/cfg/config.ini" ] && ok "config.ini was set aside as config.ini.bak" || bad "config.ini handling"+grep -q '"ActiveProfileName": "Alt"' "$WORK/cfg/settings.json" && ok "settings.json remembers the active profile" || bad "settings.json: $(cat "$WORK/cfg/settings.json")"+grep -q '"ProxyConfigs"' "$P/Default.pbprofile" && grep -q '"TargetDomains": "\*.example.test"' "$P/Default.pbprofile" && grep -q '"Version": "1.0"' "$P/Default.pbprofile" \+ && ok "the saved profile uses the Windows/macOS format (domain rule in TargetDomains)" || bad "profile format: $(head -40 "$P/Default.pbprofile")"+[ "$(stat -c %a "$P/Default.pbprofile")" = 600 ] && [ "$(stat -c %a "$P")" = 700 ] && ok "profile files are 0600 in a 0700 directory" || bad "profile permissions"++echo "== a profile exported by the Windows app, dropped into the profiles directory"+cat > "$P/From Windows.pbprofile" <<'JSON'+{ "Version": "1.0", "LocalhostViaProxy": false, "IsTrafficLoggingEnabled": true,+ "ProxyConfigs": [ { "Id": 5, "Type": "socks5", "Host": "127.0.0.1", "Port": "19080", "Username": "", "Password": "", "SendDomainToProxy": true } ],+ "ProxyRules": [ { "ProcessName": "curl", "TargetHosts": "192.0.2.0/24", "TargetPorts": "*", "TargetDomains": "", "Protocol": "TCP", "Action": "PROXY", "IsEnabled": true, "ProxyConfigId": 5 } ] }+JSON+run_gui "From Windows"+out=$(curl -s -m 5 http://192.0.2.9/); has "rule and proxy imported from the Windows file are applied" "$out" "hello-from-A dst=192.0.2.9:80"+stop_gui+out=$(PROXYBRIDGE_CONFIG_DIR="$WORK/cfg" LD_LIBRARY_PATH="$LIBDIR" "$LIBDIR/ProxyBridge" --list-profiles 2>&1)+has "the CLI lists the GUI's profiles" "$out" "From Windows"+[ "$(stat -c %a "$P/From Windows.pbprofile")" = 600 ] && ok "the dropped-in file was tightened to 0600" || bad "dropped-in file mode"echo; echo "passed=$PASS failed=$FAIL"-[ "$FAIL" = 0 ] || { echo "---- gui output"; cat "$WORK/gui.out"; echo "---- config"; cat "$WORK/cfg/config.ini"; exit 1; }+[ "$FAIL" = 0 ] || { echo "---- gui output"; cat "$WORK/gui.out"; echo "---- config"; ls -lR "$WORK/cfg"; exit 1; }