LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.
C cdebiandesktop-environmentebpffirewalllandlocklinuxlinux-distributionopen-sourceprivacyquickjsraspberry-pi-5reactsecuritywaylandwayland-compositor
Firewall: enforce the non-network restrictions where the resource is handed out
Federico Pereira73f2f3472973
diff --git a/apps/monitor/Firewall.jsx b/apps/monitor/Firewall.jsxindex ef275ce..6932237 100644--- a/apps/monitor/Firewall.jsx+++ b/apps/monitor/Firewall.jsx@@ -3,14 +3,20 @@// - status of lord-netperm (the service that applies the rules in the kernel) and the mode;// - Trusted apps: allowed without logging (explicit denials still apply);// - Restricted apps: one checkbox per restriction (no internet = "LAN only", no LAN, no network,-// no incoming connections, and the non-network ones: camera, microphone…).+// no incoming connections, and the non-network ones: camera, microphone…). Every one is+// enforced (docs/FIREWALL.md, "Non-network restrictions"). The "LordOS" row is the desktop+// itself: it does not offer files, USB, clipboard or Bluetooth, which the shell always uses.// The rules are saved by lord-server (lord.fw); this screen writes no files. Drawn like the// Settings sections: 13/600 headers, inset GroupBoxes with hairlines, footers.import { View, Text, Button, Segmented, ScrollView, GroupBox, useTheme, useLocale, useStore, useLauncherApps, firewall, firewallState, spacing, typeScale, errorText } from '@lordos/sdk';import { useState } from 'react';// Firewall id of a launcher app: the built-in ones run inside LordOS.-const fwId = (a) => (a.kind === 'linux' ? a.id : a.kind === 'package' ? `lpk:${a.id}` : 'lordos');+// Isolated built-in apps (Passwords) have their own scope, like a package.+const fwId = (a) => (a.kind === 'linux' ? a.id : a.kind === 'package' || a.isolated ? `lpk:${a.id}` : 'lordos');+// The desktop shell and the built-in apps share "lordos": these would cut the desktop off itself.+const DESKTOP_ALWAYS = ['no-files', 'no-usb', 'no-clipboard', 'no-bluetooth'];+const offered = (id) => (id === 'lordos' ? firewall.RESTRICTIONS.filter((f) => !DESKTOP_ALWAYS.includes(f)) : firewall.RESTRICTIONS);function useAppIndex() {const list = useLauncherApps();@@ -91,7 +97,7 @@ export function FirewallPrivacy() {const statusText = !status.daemon ? tr('firewall.status.noDaemon') : !status.bpf ? tr('firewall.status.noBpf', { error: errorText(status.error || '') }) :tr('firewall.status.on', { dns: tr(`firewall.dns.${status.dns || 'none'}`) });const setFlag = (id, flag, on) => {- const cur = restricted[id] || [];+ const cur = (restricted[id] || []).filter((f) => offered(id).includes(f));const next = on ? [...cur, flag] : cur.filter((f) => f !== flag);firewall.setRestricted(id, next.length ? next : []);};@@ -140,10 +146,11 @@ export function FirewallPrivacy() {<Button small label={tr('firewall.remove')} onClick={() => firewall.setRestricted(id, [])} /></View><View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 6, paddingHorizontal: 32 }}>- {firewall.RESTRICTIONS.map((f) => (+ {offered(id).map((f) => (<Check key={f} on={restricted[id].includes(f)} label={tr(`firewall.r.${f}`)} onChange={(on) => setFlag(id, f, on)} />))}</View>+ {id === 'lordos' && <Text style={{ fontSize: typeScale.caption, color: t.textDim, lineHeight: 1.35, paddingHorizontal: 32, textAlign: 'start' }}>{tr('firewall.desktopAlways')}</Text>}</View>))}{!Object.keys(restricted).length && empty}diff --git a/apps/passwords/api.js b/apps/passwords/api.jsindex 32144cd..6d11320 100644--- a/apps/passwords/api.js+++ b/apps/passwords/api.js@@ -129,6 +129,6 @@ export function errorText(code) {const known = ['bad-key', 'locked', 'not-found', 'corrupt', 'truncated', 'not-a-vault', 'unsupported-version', 'no-device', 'keyfile-read','keyfile-short', 'keyfile-write', 'unknown-format', 'bad-password', 'encrypted-export', 'unsupported-cipher', 'unsupported-kdf','too-big', 'no-qr', 'not-an-image', 'last-slot', 'exists', 'busy', 'file', 'fido-timeout', 'fido-pin-required', 'fido-pin-invalid',- 'fido-pin-blocked', 'fido-no-credential', 'fido-no-hmac', 'fido-denied', 'unavailable', 'bad-keyfile'];+ 'fido-pin-blocked', 'fido-no-credential', 'fido-no-hmac', 'fido-denied', 'fido-restricted', 'unavailable', 'bad-keyfile'];return known.includes(code) ? t(`passwords.err.${code}`) : t('passwords.err.other', { code: String(code || '?') });}diff --git a/assets/locales/en/errors.json b/assets/locales/en/errors.jsonindex 912f11f..4d1de6d 100644--- a/assets/locales/en/errors.json+++ b/assets/locales/en/errors.json@@ -537,5 +537,13 @@"fan.saveFailed": "Could not save the fan settings","fan.unavailable": "The fan service is not running","hw.notRaspberryPi5": "This only works on a Raspberry Pi 5",- "hw.caseFailed": "Could not save the case settings"+ "hw.caseFailed": "Could not save the case settings",+ "fw.restricted.camera": "{app} is restricted from using the camera (Privacy → App network access)",+ "fw.restricted.microphone": "{app} is restricted from using the microphone (Privacy → App network access)",+ "fw.restricted.screen": "{app} is restricted from capturing the screen (Privacy → App network access)",+ "fw.restricted.usb": "{app} is restricted from using USB devices (Privacy → App network access)",+ "fw.restricted.files": "{app} is restricted from opening or saving your files (Privacy → App network access)",+ "fw.restricted.clipboard": "{app} is restricted from reading the clipboard (Privacy → App network access)",+ "fw.restricted.bluetooth": "{app} is restricted from using Bluetooth (Privacy → App network access)",+ "fw.restricted.notifications": "{app} is restricted from showing notifications (Privacy → App network access)"}diff --git a/assets/locales/en/firewall.json b/assets/locales/en/firewall.jsonindex 4c96e38..540bffa 100644--- a/assets/locales/en/firewall.json+++ b/assets/locales/en/firewall.json@@ -30,12 +30,14 @@"r.no-screen": "No screen capture","r.no-usb": "No USB","r.no-bluetooth": "No Bluetooth",- "r.no-files": "No files outside the file picker",+ "r.no-files": "No access to your files","r.no-notifications": "No notifications","off": "— (the firewall is not active)","rule.allow": "Allow","rule.deny": "Deny","rule.none": "No rule (per the mode)","counts": "Connections",- "countsValue": "{allowed} allowed · {denied} denied"+ "countsValue": "{allowed} allowed · {denied} denied",+ "r.no-clipboard": "No reading the clipboard",+ "desktopAlways": "The desktop itself always has access to files, removable drives, the clipboard and Bluetooth; restrict individual apps instead."}diff --git a/assets/locales/en/passwords.json b/assets/locales/en/passwords.jsonindex 5b9ee39..509b57f 100644--- a/assets/locales/en/passwords.json+++ b/assets/locales/en/passwords.json@@ -443,5 +443,6 @@"list.sortDate": "Recent","list.sortHint": "Sort by name or by the last change","list.emptyHint": "Add one with +.",- "picker.up": "Back"+ "picker.up": "Back",+ "err.fido-restricted": "USB security keys are blocked for Passwords by a restriction in Privacy → App network access."}diff --git a/assets/locales/es/errors.json b/assets/locales/es/errors.jsonindex 312d16d..731b7df 100644--- a/assets/locales/es/errors.json+++ b/assets/locales/es/errors.json@@ -537,5 +537,13 @@"fan.saveFailed": "No se pudo guardar la configuración de los ventiladores","fan.unavailable": "El servicio de ventiladores no está en marcha","hw.notRaspberryPi5": "Esto solo funciona en una Raspberry Pi 5",- "hw.caseFailed": "No se pudo guardar la configuración de la caja"+ "hw.caseFailed": "No se pudo guardar la configuración de la caja",+ "fw.restricted.camera": "{app} tiene restringido el uso de la cámara (Privacidad → Red de las apps)",+ "fw.restricted.microphone": "{app} tiene restringido el uso del micrófono (Privacidad → Red de las apps)",+ "fw.restricted.screen": "{app} tiene restringida la captura de pantalla (Privacidad → Red de las apps)",+ "fw.restricted.usb": "{app} tiene restringido el uso de dispositivos USB (Privacidad → Red de las apps)",+ "fw.restricted.files": "{app} tiene restringido abrir o guardar tus archivos (Privacidad → Red de las apps)",+ "fw.restricted.clipboard": "{app} tiene restringido leer el portapapeles (Privacidad → Red de las apps)",+ "fw.restricted.bluetooth": "{app} tiene restringido el uso de Bluetooth (Privacidad → Red de las apps)",+ "fw.restricted.notifications": "{app} tiene restringido mostrar notificaciones (Privacidad → Red de las apps)"}diff --git a/assets/locales/es/firewall.json b/assets/locales/es/firewall.jsonindex bfba5f2..813702c 100644--- a/assets/locales/es/firewall.json+++ b/assets/locales/es/firewall.json@@ -30,12 +30,14 @@"r.no-screen": "Sin captura de pantalla","r.no-usb": "Sin USB","r.no-bluetooth": "Sin Bluetooth",- "r.no-files": "Sin archivos fuera del selector",+ "r.no-files": "Sin acceso a tus archivos","r.no-notifications": "Sin notificaciones","off": "— (el firewall no está activo)","rule.allow": "Permitir","rule.deny": "Denegar","rule.none": "Sin regla (según el modo)","counts": "Conexiones",- "countsValue": "{allowed} permitidas · {denied} denegadas"+ "countsValue": "{allowed} permitidas · {denied} denegadas",+ "r.no-clipboard": "Sin leer el portapapeles",+ "desktopAlways": "El escritorio en sí siempre tiene acceso a los archivos, las unidades extraíbles, el portapapeles y Bluetooth; restringe apps individuales."}diff --git a/assets/locales/es/passwords.json b/assets/locales/es/passwords.jsonindex 195314d..75127aa 100644--- a/assets/locales/es/passwords.json+++ b/assets/locales/es/passwords.json@@ -443,5 +443,6 @@"list.sortDate": "Recientes","list.sortHint": "Ordenar por nombre o por el último cambio","list.emptyHint": "Agregá una con +.",- "picker.up": "Atrás"+ "picker.up": "Atrás",+ "err.fido-restricted": "Las llaves de seguridad USB están bloqueadas para Contraseñas por una restricción en Privacidad → Red de las apps."}diff --git a/assets/locales/pt/errors.json b/assets/locales/pt/errors.jsonindex 3090946..d457139 100644--- a/assets/locales/pt/errors.json+++ b/assets/locales/pt/errors.json@@ -537,5 +537,13 @@"fan.saveFailed": "Não foi possível salvar as configurações das ventoinhas","fan.unavailable": "O serviço de ventoinhas não está em execução","hw.notRaspberryPi5": "Isto só funciona em um Raspberry Pi 5",- "hw.caseFailed": "Não foi possível salvar as configurações do gabinete"+ "hw.caseFailed": "Não foi possível salvar as configurações do gabinete",+ "fw.restricted.camera": "{app} está impedido de usar a câmera (Privacidade → Rede dos apps)",+ "fw.restricted.microphone": "{app} está impedido de usar o microfone (Privacidade → Rede dos apps)",+ "fw.restricted.screen": "{app} está impedido de capturar a tela (Privacidade → Rede dos apps)",+ "fw.restricted.usb": "{app} está impedido de usar dispositivos USB (Privacidade → Rede dos apps)",+ "fw.restricted.files": "{app} está impedido de abrir ou salvar seus arquivos (Privacidade → Rede dos apps)",+ "fw.restricted.clipboard": "{app} está impedido de ler a área de transferência (Privacidade → Rede dos apps)",+ "fw.restricted.bluetooth": "{app} está impedido de usar Bluetooth (Privacidade → Rede dos apps)",+ "fw.restricted.notifications": "{app} está impedido de mostrar notificações (Privacidade → Rede dos apps)"}diff --git a/assets/locales/pt/firewall.json b/assets/locales/pt/firewall.jsonindex 70af955..200c3fb 100644--- a/assets/locales/pt/firewall.json+++ b/assets/locales/pt/firewall.json@@ -30,12 +30,14 @@"r.no-screen": "Sem captura de tela","r.no-usb": "Sem USB","r.no-bluetooth": "Sem Bluetooth",- "r.no-files": "Sem arquivos fora do seletor",+ "r.no-files": "Sem acesso aos seus arquivos","r.no-notifications": "Sem notificações","off": "— (o firewall não está ativo)","rule.allow": "Permitir","rule.deny": "Negar","rule.none": "Sem regra (conforme o modo)","counts": "Conexões",- "countsValue": "{allowed} permitidas · {denied} negadas"+ "countsValue": "{allowed} permitidas · {denied} negadas",+ "r.no-clipboard": "Sem ler a área de transferência",+ "desktopAlways": "A própria área de trabalho sempre tem acesso aos arquivos, unidades removíveis, área de transferência e Bluetooth; restrinja apps individuais."}diff --git a/assets/locales/pt/passwords.json b/assets/locales/pt/passwords.jsonindex e43df89..7628e3a 100644--- a/assets/locales/pt/passwords.json+++ b/assets/locales/pt/passwords.json@@ -443,5 +443,6 @@"list.sortDate": "Recentes","list.sortHint": "Ordenar por nome ou pela última alteração","list.emptyHint": "Adicione um com +.",- "picker.up": "Voltar"+ "picker.up": "Voltar",+ "err.fido-restricted": "As chaves de segurança USB estão bloqueadas para Senhas por uma restrição em Privacidade → Rede dos apps."}diff --git a/sdk/monitor.js b/sdk/monitor.jsindex 458d977..8cff561 100644--- a/sdk/monitor.js+++ b/sdk/monitor.js@@ -130,11 +130,12 @@ export const firewall = {setTrusted: (app, on) => fwBump(fwCall((f) => f.setTrusted(app, !!on), false)),setRestricted: (app, flags) => fwBump(fwCall((f) => f.setRestricted(app, flags), false)),setMode: (m) => fwBump(fwCall((f) => f.setMode(m), false)),+ blocks: (app, flag) => fwCall((f) => f.blocks(app, flag), false),rules: (app) => fwCall((f) => f.rules(app), []),addRule: (r) => fwBump(fwCall((f) => f.addRule(r), false)),removeRule: (id) => fwBump(fwCall((f) => f.removeRule(id), false)),refresh: () => fwPoll(true),- RESTRICTIONS: ['no-internet', 'no-lan', 'no-network', 'no-incoming', 'no-camera', 'no-mic', 'no-screen', 'no-usb', 'no-bluetooth', 'no-files', 'no-notifications'],+ RESTRICTIONS: ['no-internet', 'no-lan', 'no-network', 'no-incoming', 'no-camera', 'no-mic', 'no-screen', 'no-usb', 'no-bluetooth', 'no-files', 'no-clipboard', 'no-notifications'],};let infoCache = null;diff --git a/sdk/notify.js b/sdk/notify.jsindex 64f90bc..be07e94 100644--- a/sdk/notify.js+++ b/sdk/notify.js@@ -64,11 +64,24 @@ function remember(app) {settings.set((s) => ({ ...s, notifications: { ...notifyPrefs(s), seen: [app, ...notifyPrefs(s).seen].slice(0, 64) } }));}+// Firewall restriction "no notifications" (Settings → Privacy → Apps' network, docs/FIREWALL.md):+// checked in lord-server's rule store before anything is shown, above the per-app setting. A+// built-in app is "lordos", an isolated one (.lpk, Passwords) "lpk:<id>". Settings' own system+// warnings (battery) are exempt; Linux apps ('linux:…') are checked where their D-Bus call arrives.+function fwNotifyBlocked(app) {+ try {+ if (typeof lord === 'undefined' || !lord.fw || typeof lord.fw.blocks !== 'function') return false;+ if (!app || app === 'settings' || app.startsWith('linux:')) return false;+ const a = getApp(app);+ return !!lord.fw.blocks(a && (a.package || a.isolated) ? `lpk:${app}` : 'lordos', 'no-notifications');+ } catch (e) { return false; }+}+export function notify({ app = '', title = '', body = '', actions = [], sound: withSound = true, sticky = false, timeout = 6000, onClose, label = '', icon = null } = {}) {app = String(app);const ap = appNotifyPrefs(app);remember(app);- if (!ap.allow) return 0; // not delivered at all+ if (!ap.allow || fwNotifyBlocked(app)) return 0; // not delivered at allconst id = seq++;const n = { id, app, label: String(label), Icon: typeof icon === 'function' ? icon : null, title: String(title), body: String(body), actions: Array.isArray(actions) ? actions.slice(0, 3) : [],sticky: !!sticky || ap.style === 'alert', time: Date.now(), onClose };diff --git a/server/Makefile b/server/Makefileindex 90f8100..217f45a 100644--- a/server/Makefile+++ b/server/Makefile@@ -51,7 +51,7 @@ QJS_OBJ := $(patsubst %,build/qjs/%.o,quickjs libregexp libunicode cutils dtoa)MON_SRC := src/monitor/mon.c src/monitor/conn.c src/monitor/mmdb.c src/monitor/map.c src/ui/js_monitor.c# Media (src/media, docs/MEDIA.md): only the lord-server side. Only lord-media links FFmpeg.MEDIA_SRC := src/media/media.c src/media/mview.c src/media/capture.c src/media/annot.c src/media/maudio.c src/media/mpulse.c src/media/proto.c src/ui/js_media.c-SEC_SRC := src/sec/json.c src/sec/sign.c src/sec/pkgstate.c src/sec/perms.c src/sec/cgroup.c src/sec/sandbox.c src/sec/brokersrv.c src/sec/brokercam.c src/sec/brokerkr.c+SEC_SRC := src/sec/json.c src/sec/sign.c src/sec/pkgstate.c src/sec/perms.c src/sec/cgroup.c src/sec/sandbox.c src/sec/brokersrv.c src/sec/brokercam.c src/sec/brokerkr.c src/sec/restrict.c# App mode: lord-server --app <id> runs an .lpk app as an isolated Wayland client (src/app)APP_SRC := src/app/appclient.c src/app/appspawn.c src/ui/js_broker.c src/ui/js_brokercam.cSRC := src/main.c src/kms.c src/gpu/gpu.c src/input.c src/canvas.c src/admin.c src/install/install.c src/apps.c src/lpk.c src/fsops.c src/remote/mirror.c src/remote/remote_admin.c src/users/users_admin.c src/users/homedirs.c src/keyboard.c src/ime.c src/wl/wl.c \@@ -220,7 +220,15 @@ build/journal-test: tests/journal_test.c src/logs/journal.c src/logs/journal.h s$(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/journal_test.c src/logs/journal.c src/pkg/xz.c build/obj/ui/stb.o -lm./$@ || { rm -f $@; exit 1; }# per-app firewall: rules (precedence, networks, JSON) and DNS names (broken packets, LRU)-test: build/fw-rules-test build/dnsmap-test+test: build/fw-rules-test build/dnsmap-test build/broker-restrict-test+# the firewall's non-network restrictions in the real broker code (docs/FIREWALL.md); open() is+# wrapped so a fake /dev/video9 can be opened+BROKER_RESTRICT_SRC := src/sec/brokersrv.c src/sec/brokercam.c src/sec/restrict.c src/sec/perms.c src/sec/json.c \+ src/fw/rules.c src/fw/fwmap.c src/media/proto.c+build/broker-restrict-test: tests/broker_restrict_test.c $(BROKER_RESTRICT_SRC) $(wildcard src/sec/*.h src/fw/*.h src/media/*.h)+ @mkdir -p build+ $(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/broker_restrict_test.c $(BROKER_RESTRICT_SRC) -Wl,--wrap=open+ ./$@ || { rm -f $@; exit 1; }build/fw-rules-test: tests/fw_rules_test.c src/fw/rules.c src/fw/fwmap.c src/sec/json.c $(wildcard src/fw/*.h) src/sec/json.h@mkdir -p build$(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/fw_rules_test.c src/fw/rules.c src/fw/fwmap.c src/sec/json.cdiff --git a/server/src/fw/rules.c b/server/src/fw/rules.cindex 102cc8a..85dddb2 100644--- a/server/src/fw/rules.c+++ b/server/src/fw/rules.c@@ -264,7 +264,7 @@ int fw_format_dest(const FwRule *r, char *out, size_t n) {static const char *const FLAG_NAMES[] = {"no-internet", "no-lan", "no-network", "no-incoming", "no-camera", "no-mic", "no-screen",- "no-usb", "no-bluetooth", "no-files", "no-notifications",+ "no-usb", "no-bluetooth", "no-files", "no-notifications", "no-clipboard",};#define NFLAGS (int)(sizeof FLAG_NAMES / sizeof *FLAG_NAMES)diff --git a/server/src/fw/rules.h b/server/src/fw/rules.hindex 58a787f..ec8cce7 100644--- a/server/src/fw/rules.h+++ b/server/src/fw/rules.h@@ -42,8 +42,10 @@ typedef enum {FW_DST_INTERNET, /* everything that isn't LAN */} FwDstKind;-/* Restrictions of an app in the "Restricted apps" list. The network ones are applied by fw_decide;- * the others are checked with fw_blocks by whoever manages that resource (broker, camera, portal...). */+/* Restrictions of an app in the "Restricted apps" list. The network ones are applied by fw_decide+ * (and, in the kernel, by lord-netperm). The others are checked with fw_blocks, through+ * sec/restrict.h, where the resource is handed out (docs/FIREWALL.md, "Non-network+ * restrictions"): the broker for isolated apps, js_media.c and sdk/notify.js for built-in apps. */enum {FW_R_NO_INTERNET = 1u << 0,FW_R_NO_LAN = 1u << 1,@@ -54,9 +56,10 @@ enum {FW_R_NO_SCREEN = 1u << 6,FW_R_NO_USB = 1u << 7,FW_R_NO_BLUETOOTH = 1u << 8,- FW_R_NO_FILES = 1u << 9, /* nothing outside the file picker */+ FW_R_NO_FILES = 1u << 9, /* no user files (isolated apps: the file picker is refused) */FW_R_NO_NOTIFICATIONS = 1u << 10,- FW_R_ALL = (1u << 11) - 1,+ FW_R_NO_CLIPBOARD = 1u << 11, /* no reading the clipboard */+ FW_R_ALL = (1u << 12) - 1,};typedef struct {diff --git a/server/src/sec/broker_int.h b/server/src/sec/broker_int.hindex ceabd8f..fddf480 100644--- a/server/src/sec/broker_int.h+++ b/server/src/sec/broker_int.h@@ -31,6 +31,7 @@ void brokercam_handle(int conn, int fd, uint32_t reqid, const char *payload, uinint brokercam_pick_result(uint32_t reqid, const char *path); /* 1 if it was a camera save */void brokercam_conn_closed(int conn);void brokercam_revoke(const char *app);+void brokercam_revoke_mic(const char *app); /* stops recordings that use the microphone */void brokercam_tick(void);#endifdiff --git a/server/src/sec/brokercam.c b/server/src/sec/brokercam.cindex b5b1492..1607f34 100644--- a/server/src/sec/brokercam.c+++ b/server/src/sec/brokercam.c@@ -12,6 +12,9 @@* Revoking the permission kills the helper and closes the stream at once. */#include "broker_int.h"#include "perms.h"+#include "restrict.h"+#include "../fw/rules.h"+#include "../errcode.h"#include "json.h"#include "../media/media_int.h"@@ -189,7 +192,7 @@ void brokercam_handle(int conn, int fd, uint32_t reqid, const char *payload, uinconst char *app = brokersrv_conn_app(conn);char cmd[16] = "";sscanf(payload, "%15s", cmd);- int allowed = app && perm_get(app, PERM_CAMERA) == PERM_ALLOW;+ int allowed = app && restrict_perm_pkg(app, PERM_CAMERA) == PERM_ALLOW; /* a restriction beats the permission */if (!strcmp(cmd, "list")) {static char json[8192];if (!allowed) snprintf(json, sizeof json, "[]");@@ -201,6 +204,13 @@ void brokercam_handle(int conn, int fd, uint32_t reqid, const char *payload, uinchar dev[32] = "";int w = 1280, h = 720;sscanf(payload, "%*s %31s %d %d", dev, &w, &h);+ if (app && restrict_blocks_pkg(app, FW_R_NO_CAMERA)) {+ char line[160];+ lerr_set(line, sizeof line, restrict_code(FW_R_NO_CAMERA), "app", app, NULL);+ fprintf(stderr, "broker[%s]: camera refused by a restriction\n", app);+ brokersrv_reply(fd, reqid, BST_DENIED, line, (uint32_t)strlen(line), -1);+ return;+ }if (!allowed) { brokersrv_reply(fd, reqid, BST_DENIED, NULL, 0, -1); return; }if (!dev_ok(dev)) { brokersrv_reply(fd, reqid, BST_ERROR, NULL, 0, -1); return; }if (w < 160 || w > 3840) w = 1280;@@ -279,6 +289,13 @@ void brokercam_handle(int conn, int fd, uint32_t reqid, const char *payload, uinif (!strcmp(cmd, "photo")) sscanf(payload, "%*s %*d %d", &mirror);else sscanf(payload, "%*s %*d %d %d", &mirror, &mic);for (int k = 0; k < (cmd[0] == 'p' ? 3 : 4) && rest; k++) { rest = strchr(rest, ' '); if (rest) rest++; }+ if (app && restrict_blocks_pkg(app, FW_R_NO_FILES)) {+ /* photos and videos are user files, saved through the same system dialog as the picker */+ char line[160];+ lerr_set(line, sizeof line, restrict_code(FW_R_NO_FILES), "app", app, NULL);+ brokersrv_reply(fd, reqid, BST_DENIED, line, (uint32_t)strlen(line), -1);+ return;+ }if (!s || s->sock < 0 || !allowed || c->pick_req) { brokersrv_reply(fd, reqid, BST_ERROR, NULL, 0, -1); return; }clean_name(rest, cmd[0] == 'p' ? "foto.jpg" : "video.mp4", c->out_name, sizeof c->out_name);/* the save dialog is the system's; the chosen file is opened here and goes to lord-media */@@ -314,7 +331,8 @@ int brokercam_pick_result(uint32_t reqid, const char *path) {const char *app = brokersrv_conn_app(c->conn);int f = -1;struct stat st;- if (path && path[0] && s && s->sock >= 0 && app && perm_get(app, PERM_CAMERA) == PERM_ALLOW)+ if (path && path[0] && s && s->sock >= 0 && app && restrict_perm_pkg(app, PERM_CAMERA) == PERM_ALLOW &&+ !restrict_blocks_pkg(app, FW_R_NO_FILES))f = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, 0644);if (f >= 0 && (fstat(f, &st) || !S_ISREG(st.st_mode))) { close(f); f = -1; }const char *base = path ? strrchr(path, '/') : NULL;@@ -330,7 +348,7 @@ int brokercam_pick_result(uint32_t reqid, const char *path) {r = mp_send(s->sock, MM_PHOTO, 1, v, NULL, 0, &f, 1);} else {int ring = -1;- if (c->pick_mic && perm_get(app, PERM_MICROPHONE) == PERM_ALLOW) {+ if (c->pick_mic && restrict_perm_pkg(app, PERM_MICROPHONE) == PERM_ALLOW) {maudio_close(s->mic);s->mic = maudio_open(1, app, "Video", "", &ring);}@@ -360,6 +378,21 @@ void brokercam_revoke(const char *app) {}}+/* The microphone was revoked or restricted: a video recording that takes sound from it stops now+ * (the file is finished properly) and the stream is closed. */+void brokercam_revoke_mic(const char *app) {+ for (int i = 0; i < MAX_CAMS; i++) {+ Cam *c = &cams[i];+ const char *a = c->used ? brokersrv_conn_app(c->conn) : NULL;+ MediaSrc *s = a && !strcmp(a, app) ? media_src_get(c->sid) : NULL;+ if (!s || !s->mic) continue;+ if (s->sock >= 0) mp_send(s->sock, MM_RECORD, 2, NULL, NULL, 0, NULL, 0);+ maudio_close(s->mic);+ s->mic = NULL;+ fprintf(stderr, "broker[%s]: microphone revoked: camera recording stopped\n", app);+ }+}+void brokercam_tick(void) {for (int i = 0; i < MAX_CAMS; i++) {Cam *c = &cams[i];diff --git a/server/src/sec/brokersrv.c b/server/src/sec/brokersrv.cindex 563945a..4c8a404 100644--- a/server/src/sec/brokersrv.c+++ b/server/src/sec/brokersrv.c@@ -4,6 +4,9 @@* sistema (nunca lo dibuja la app). */#include "broker_int.h"#include "perms.h"+#include "restrict.h"+#include "../fw/rules.h"+#include "../errcode.h"#include "json.h"#include "../lpk.h"#include "../term/term.h"@@ -116,6 +119,7 @@ void brokersrv_pick_result(uint32_t ui, const char *path) {int f = -1;const char *name = path ? strrchr(path, '/') : NULL;name = name ? name + 1 : path;+ if (path && path[0] && restrict_blocks_pkg(picks[i].id, FW_R_NO_FILES)) path = NULL; /* restricted meanwhile */if (path && path[0]) {/* lord-server abre el archivo con los permisos del usuario; la app recibe solo el fd */f = open(path, picks[i].save ? (O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC) : (O_RDONLY | O_CLOEXEC), 0644);@@ -144,6 +148,7 @@ void brokersrv_revoke(const char *app, const char *perm) {for (int i = 0; i < MAX_APPS; i++) if (apps[i].used && !strcmp(apps[i].id, app)) send_event(&apps[i], "revoke", json, strlen(json));if (!strcmp(perm, "microphone")) for (int i = 0; i < MAX_APPS; i++)if (apps[i].used && !strcmp(apps[i].id, app) && apps[i].mic) { maudio_close(apps[i].mic); apps[i].mic = NULL; }+ if (!strcmp(perm, "microphone")) brokercam_revoke_mic(app);if (!strcmp(perm, "camera")) brokercam_revoke(app); /* kills its lord-media: the stream stops now */if (!strcmp(perm, "camera") || !strcmp(perm, "microphone"))queue_evt("device", "{\"app\":\"%s\",\"kind\":\"%s\",\"on\":false}", app, perm);@@ -271,6 +276,18 @@ static int data_path(const char *id, const char *rel, char *out, size_t n) {return 0;}+/* A firewall restriction (Settings → Privacy → "Apps' network") covers this request: it is+ * refused without a prompt, whatever the permission says, and the reply carries the code line+ * ("fw.restricted.camera app=<id>") so the app can say why. See restrict.h. */+static int deny_restricted(int fd, uint32_t reqid, const char *id, uint32_t flag) {+ if (!restrict_blocks_pkg(id, flag)) return 0;+ char line[160];+ lerr_set(line, sizeof line, restrict_code(flag), "app", id, NULL);+ fprintf(stderr, "broker[%s]: refused by a restriction (%s)\n", id, fw_flag_name(flag));+ send_reply(fd, reqid, BST_DENIED, line, (uint32_t)strlen(line));+ return 1;+}+static void handle(AppConn *a, BrokerHdr *h, char *payload) {int fd = a->fd;switch (h->op) {@@ -333,6 +350,7 @@ static void handle(AppConn *a, BrokerHdr *h, char *payload) {break;}case BOP_CLIP_GET: {+ if (deny_restricted(fd, h->reqid, a->id, FW_R_NO_CLIPBOARD)) break;if (perm_get(a->id, PERM_CLIPBOARD) != PERM_ALLOW) { send_reply(fd, h->reqid, BST_DENIED, NULL, 0); break; }const char *txt = term_clipboard();send_reply(fd, h->reqid, BST_OK, txt ? txt : "", txt ? (uint32_t)strlen(txt) : 0);@@ -345,6 +363,15 @@ static void handle(AppConn *a, BrokerHdr *h, char *payload) {case BOP_PERM: {int p = perm_from_name(payload);if (p < 0) { send_reply(fd, h->reqid, BST_DENIED, NULL, 0); break; }+ uint32_t rf = restrict_flag_of((Perm)p);+ if (rf && restrict_blocks_pkg(a->id, rf)) {+ /* restricted: "no", without a prompt; the code line follows the "0" */+ char line[160] = "0 ";+ lerr_set(line + 2, sizeof line - 2, restrict_code(rf), "app", a->id, NULL);+ fprintf(stderr, "broker[%s]: permission %s refused by a restriction\n", a->id, payload);+ send_reply(fd, h->reqid, BST_OK, line, (uint32_t)strlen(line));+ break;+ }PermState st = perm_get(a->id, (Perm)p);fprintf(stderr, "broker[%s]: permission %s = %s\n", a->id, payload, st == PERM_ALLOW ? "allow" : st == PERM_DENY ? "deny" : "ask (prompt)");if (st == PERM_ALLOW) { send_reply(fd, h->reqid, BST_OK, "1", 1); break; }@@ -364,13 +391,14 @@ static void handle(AppConn *a, BrokerHdr *h, char *payload) {char kind[16] = ""; int on = 0;sscanf(payload, "%15s %d", kind, &on);int p = perm_from_name(kind);- if (p >= 0 && perm_get(a->id, (Perm)p) == PERM_ALLOW)+ if (p >= 0 && restrict_perm_pkg(a->id, (Perm)p) == PERM_ALLOW)queue_evt("device", "{\"app\":\"%s\",\"kind\":\"%s\",\"on\":%s}", a->id, kind, on ? "true" : "false");send_reply(fd, h->reqid, BST_OK, NULL, 0);break;}case BOP_PICK: {- /* payload: "save\0nombreSugerido"; el diálogo lo dibuja lord-server, no la app */+ /* payload: "save\0suggestedName"; the dialog is drawn by lord-server, never by the app */+ if (deny_restricted(fd, h->reqid, a->id, FW_R_NO_FILES)) break;int save = payload[0] == '1';const char *suggest = memchr(payload, 0, h->len);suggest = suggest ? suggest + 1 : "";@@ -404,6 +432,7 @@ static void handle(AppConn *a, BrokerHdr *h, char *payload) {case BOP_MIC: {int want = payload[0] == '1';if (!want) { if (a->mic) { maudio_close(a->mic); a->mic = NULL; } send_reply(fd, h->reqid, BST_OK, NULL, 0); break; }+ if (deny_restricted(fd, h->reqid, a->id, FW_R_NO_MIC)) break;if (perm_get(a->id, PERM_MICROPHONE) != PERM_ALLOW) { send_reply(fd, h->reqid, BST_DENIED, NULL, 0); break; }if (!a->mic) {int rfd = -1;@@ -443,7 +472,9 @@ static void handle(AppConn *a, BrokerHdr *h, char *payload) {case BOP_VAULT_FIDO: {/* only the system Passwords app (spawned with a vault channel), only with `usb` allowed; the* hidraw fd goes from here straight to lord-vault */- if (!a->vault || perm_get(a->id, PERM_USB) != PERM_ALLOW) { send_reply(fd, h->reqid, BST_DENIED, NULL, 0); break; }+ if (!a->vault) { send_reply(fd, h->reqid, BST_DENIED, NULL, 0); break; }+ if (deny_restricted(fd, h->reqid, a->id, FW_R_NO_USB)) break;+ if (perm_get(a->id, PERM_USB) != PERM_ALLOW) { send_reply(fd, h->reqid, BST_DENIED, NULL, 0); break; }char name[128] = "";int r = vc_fido_attach(name, sizeof name);if (r) send_reply(fd, h->reqid, BST_ERROR, r == -1 ? "no-device" : "no-access", r == -1 ? 9 : 9);@@ -469,6 +500,7 @@ void brokersrv_resolve(uint32_t ui, int allow) {if (brokerkr_resolve(ui, allow)) return;for (int i = 0; i < MAX_PENDING; i++) if (pend[i].used && pend[i].ui == ui) {perm_set(pend[i].id, pend[i].perm, allow ? PERM_ALLOW : PERM_DENY);+ if (allow && restrict_perm_pkg(pend[i].id, pend[i].perm) != PERM_ALLOW) allow = 0; /* restricted meanwhile */send_reply(pend[i].fd, pend[i].reqid, BST_OK, allow ? "1" : "0", 1);pend[i].used = 0;return;diff --git a/server/src/sec/restrict.c b/server/src/sec/restrict.cnew file mode 100644index 0000000..83db5d2--- /dev/null+++ b/server/src/sec/restrict.c@@ -0,0 +1,68 @@+/* restrict.c — the firewall's non-network restrictions (see restrict.h). */+#include "restrict.h"+#include "broker.h"+#include "../fw/rules.h"++#include <stdio.h>+#include <string.h>++static const FwStore *store;+static RestrictLocalFn local_hook;++void restrict_set_store(const struct FwStore *s) { store = s; }+void restrict_set_local_hook(RestrictLocalFn fn) { local_hook = fn; }++int restrict_blocks(const char *fwid, uint32_t flag) {+ return store && fwid && flag && fw_blocks(store, fwid, flag);+}++int restrict_blocks_pkg(const char *id, uint32_t flag) {+ char fwid[FW_APP_MAX];+ if (!id || !id[0] || (size_t)snprintf(fwid, sizeof fwid, "lpk:%s", id) >= sizeof fwid) return 0;+ return restrict_blocks(fwid, flag);+}++uint32_t restrict_flag_of(Perm p) {+ switch (p) {+ case PERM_CAMERA: return FW_R_NO_CAMERA;+ case PERM_MICROPHONE: return FW_R_NO_MIC;+ case PERM_SCREEN: return FW_R_NO_SCREEN;+ case PERM_USB: return FW_R_NO_USB;+ case PERM_FILES: return FW_R_NO_FILES;+ case PERM_CLIPBOARD: return FW_R_NO_CLIPBOARD;+ case PERM_BLUETOOTH: return FW_R_NO_BLUETOOTH;+ case PERM_NOTIFICATIONS: return FW_R_NO_NOTIFICATIONS;+ default: return 0;+ }+}++const char *restrict_code(uint32_t flag) {+ switch (flag) {+ case FW_R_NO_CAMERA: return "fw.restricted.camera";+ case FW_R_NO_MIC: return "fw.restricted.microphone";+ case FW_R_NO_SCREEN: return "fw.restricted.screen";+ case FW_R_NO_USB: return "fw.restricted.usb";+ case FW_R_NO_FILES: return "fw.restricted.files";+ case FW_R_NO_CLIPBOARD: return "fw.restricted.clipboard";+ case FW_R_NO_BLUETOOTH: return "fw.restricted.bluetooth";+ case FW_R_NO_NOTIFICATIONS: return "fw.restricted.notifications";+ default: return NULL;+ }+}++PermState restrict_perm_pkg(const char *id, Perm p) {+ uint32_t f = restrict_flag_of(p);+ if (f && restrict_blocks_pkg(id, f)) return PERM_DENY;+ return perm_get(id, p);+}++void restrict_changed(const char *fwid, uint32_t before, uint32_t after) {+ uint32_t added = after & ~before;+ if (!fwid || !added) return;+ if (!strncmp(fwid, "lpk:", 4) && fwid[4]) {+ /* the same path as revoking the permission in Privacy: the app is told, the camera's+ * lord-media is killed and the microphone stream is closed */+ if (added & FW_R_NO_CAMERA) brokersrv_revoke(fwid + 4, "camera");+ if (added & FW_R_NO_MIC) brokersrv_revoke(fwid + 4, "microphone");+ } else if (!strcmp(fwid, "lordos") && local_hook) local_hook(added);+}diff --git a/server/src/sec/restrict.h b/server/src/sec/restrict.hnew file mode 100644index 0000000..ee61575--- /dev/null+++ b/server/src/sec/restrict.h@@ -0,0 +1,52 @@+/* restrict.h — the firewall's non-network restrictions, enforced where the resource is handed out+ * (docs/FIREWALL.md, "Non-network restrictions", and docs/PRIVACY.md).+ *+ * Settings → Privacy → "Apps' network" lets the owner restrict an app: "no camera", "no+ * microphone"… (FW_R_* in fw/rules.h, stored in firewall.json by lord.fw). A restriction is+ * stronger than any permission: a restricted app is denied without a prompt, even if the user+ * allowed the permission before. The network ones are applied in the kernel by lord-netperm; the+ * others are checked here, by the code that hands out the resource:+ *+ * isolated apps (.lpk and Passwords), firewall id "lpk:<id>": the broker (brokersrv.c,+ * brokercam.c) for camera, microphone, screen, USB (the FIDO2 key of Passwords), the file+ * picker (powerbox) and reading the clipboard;+ * built-in apps inside lord-server, firewall id "lordos": js_media.c (camera, microphone,+ * screen capture and recording).+ *+ * Linux apps (desktop:<id>) are not sandboxed: they reach devices directly, so only the network+ * restrictions apply to them. Bluetooth and notifications have no app API yet.+ *+ * The store is lord.fw's (ui/js_fw.c, the one Settings edits), so a change is seen at once. */+#ifndef LORD_SEC_RESTRICT_H+#define LORD_SEC_RESTRICT_H++#include <stdint.h>+#include "perms.h"++struct FwStore;++/* The rule store to consult (js_fw.c sets it after loading firewall.json). NULL = no restrictions. */+void restrict_set_store(const struct FwStore *s);++/* Is the app with firewall id `fwid` ("lpk:<id>", "lordos"…) restricted in `flag` (FW_R_*)? */+int restrict_blocks(const char *fwid, uint32_t flag);+/* The same for an isolated app by its broker id (the verified package id, "lpk:" is added). */+int restrict_blocks_pkg(const char *id, uint32_t flag);++/* The restriction that covers permission p (FW_R_NO_CAMERA for PERM_CAMERA…), or 0. */+uint32_t restrict_flag_of(Perm p);+/* Error code of a denial by restriction ("fw.restricted.camera"…), or NULL for an unknown flag. */+const char *restrict_code(uint32_t flag);++/* The permission an isolated app effectively has: PERM_DENY when a restriction covers it,+ * otherwise the saved decision (perm_get). Every broker check uses this, never perm_get. */+PermState restrict_perm_pkg(const char *id, Perm p);++/* The restrictions of `fwid` changed from `before` to `after`: what was just restricted is taken+ * away from a running app, like revoking the permission (the camera stream and the microphone stop+ * now). Isolated apps through brokersrv_revoke; built-in apps through the hook js_media.c sets. */+void restrict_changed(const char *fwid, uint32_t before, uint32_t after);+typedef void (*RestrictLocalFn)(uint32_t added);+void restrict_set_local_hook(RestrictLocalFn fn);++#endifdiff --git a/server/src/ui/js_broker.c b/server/src/ui/js_broker.cindex f2b1ac6..484ee0f 100644--- a/server/src/ui/js_broker.c+++ b/server/src/ui/js_broker.c@@ -228,7 +228,13 @@ static JSValue f_fs_list(JSContext *c, JSValueConst t, int argc, JSValueConst *astatic JSValue f_clip_get(JSContext *c, JSValueConst t, int argc, JSValueConst *argv) {(void)t; (void)argc; (void)argv;int st = BST_ERROR; char *out = NULL; uint32_t len = 0;- if (rpc(BOP_CLIP_GET, NULL, 0, &st, &out, &len) || st != BST_OK) { free(out); return js_throw_code(c, "app.clipboardDenied", NULL); }+ if (rpc(BOP_CLIP_GET, NULL, 0, &st, &out, &len) || st != BST_OK) {+ /* a firewall restriction comes back as its code line (fw.restricted.clipboard) */+ char line[160] = "";+ if (st == BST_DENIED && out && len && len < sizeof line) { memcpy(line, out, len); line[len] = 0; }+ free(out);+ return lerr_is(line) ? js_throw_line(c, line) : js_throw_code(c, "app.clipboardDenied", NULL);+ }JSValue v = JS_NewStringLen(c, out, len);free(out);return v;@@ -271,7 +277,8 @@ int js_broker_vault_fido(char *name, size_t n, char *err, size_t en) {int st = BST_ERROR; char *out = NULL; uint32_t len = 0;int r = rpc(BOP_VAULT_FIDO, NULL, 0, &st, &out, &len);if (!r && st == BST_OK) { snprintf(name, n, "%.*s", (int)len, out ? out : ""); free(out); return 0; }- snprintf(err, en, "%s", st == BST_DENIED ? "fido-denied" : out && len ? out : "no-device");+ /* denied by the permission, or by a firewall restriction (a code line, "fw.restricted.usb …") */+ snprintf(err, en, "%s", st == BST_DENIED ? (out && len && lerr_is(out) ? "fido-restricted" : "fido-denied") : out && len ? out : "no-device");free(out);return -1;}@@ -298,7 +305,12 @@ static int rpc_fd(int op, const void *payload, uint32_t len, char *name, size_tfor (struct cmsghdr *cm = CMSG_FIRSTHDR(&rm); cm; cm = CMSG_NXTHDR(&rm, cm))if (cm->cmsg_level == SOL_SOCKET && cm->cmsg_type == SCM_RIGHTS) memcpy(&fd, CMSG_DATA(cm), sizeof fd);uint32_t pl = (uint32_t)n - sizeof r;- if (r.status != BST_OK) { if (fd >= 0) close(fd); return -1; }+ if (r.status != BST_OK) {+ if (fd >= 0) close(fd);+ /* the reason, when it is a code line (a firewall restriction): the caller can throw it */+ if (name && nn) { size_t k = pl < nn - 1 ? pl : nn - 1; memcpy(name, buf, k); name[k] = 0; if (!lerr_is(name)) name[0] = 0; }+ return -1;+ }if (name && nn) { size_t k = pl < nn - 1 ? pl : nn - 1; memcpy(name, buf, k); name[k] = 0; }return fd;}@@ -320,13 +332,13 @@ static JSValue f_broker_pick(JSContext *c, JSValueConst t, int argc, JSValueCons(void)t; (void)argc;int save = JS_ToBool(c, argv[0]);const char *sg = JS_IsString(argv[1]) ? JS_ToCString(c, argv[1]) : "";- char pl[300], name[256];+ char pl[300], name[256] = "";int n = snprintf(pl, sizeof pl, "%d", save);pl[n++] = 0;n += snprintf(pl + n, sizeof pl - n, "%s", sg ? sg : "");int fd = rpc_fd(BOP_PICK, pl, (uint32_t)n, name, sizeof name);if (sg && sg[0]) JS_FreeCString(c, sg);- if (fd < 0) return JS_NULL;+ if (fd < 0) return name[0] ? js_throw_line(c, name) : JS_NULL; /* restricted: fw.restricted.files; cancelled: null */JSValue o = JS_NewObject(c);JS_SetPropertyStr(c, o, "fd", JS_NewInt32(c, fd));JS_SetPropertyStr(c, o, "name", JS_NewString(c, name));@@ -393,9 +405,9 @@ static int mic_fd = -1;static JSValue f_mic_start(JSContext *c, JSValueConst t, int argc, JSValueConst *argv) {(void)t; (void)argc; (void)argv;- char name[256];+ char name[256] = "";int ro = rpc_fd(BOP_MIC, "1", 1, name, sizeof name);- if (ro < 0) return JS_NewBool(c, 0);+ if (ro < 0) return name[0] ? js_throw_line(c, name) : JS_NewBool(c, 0); /* fw.restricted.microphone */unsigned size = 0, rate = 0, ch = 0;sscanf(name, "%u %u %u", &size, &rate, &ch);size_t maplen = AR_HDR + size;diff --git a/server/src/ui/js_brokercam.c b/server/src/ui/js_brokercam.cindex 8074f2c..3d84b39 100644--- a/server/src/ui/js_brokercam.c+++ b/server/src/ui/js_brokercam.c@@ -163,7 +163,10 @@ static JSValue f_camera(JSContext *c, JSValueConst t, int argc, JSValueConst *archar *out = NULL;uint32_t len = 0;if (js_broker_rpc(BOP_CAMERA, p, (uint32_t)n, &st, &out, &len) || st != BST_OK || !out) {+ char line[160] = "";+ if (st == BST_DENIED && out && len && len < sizeof line) { memcpy(line, out, len); line[len] = 0; }free(out);+ if (lerr_is(line)) return js_throw_line(c, line); /* fw.restricted.camera */return js_throw_code(c, st == BST_DENIED ? "perm.cameraDenied" : "camera.openFailed", NULL);}int sid = atoi(out);diff --git a/server/src/ui/js_fw.c b/server/src/ui/js_fw.cindex 3e93dfb..497ea96 100644--- a/server/src/ui/js_fw.c+++ b/server/src/ui/js_fw.c@@ -16,10 +16,17 @@* rules(app) [{ id, dir, dst, port, proto, action }]* addRule({ app, dir, dst, port, proto, action }) → id removeRule(id)* poll() { counts: { app: [allowed, denied] }, events: [...] }+ * blocks(app, restriction) true if the app is restricted in it (sdk/notify.js asks before showing+ * a built-in app's notification)+ *+ * The non-network restrictions are enforced in C where the resource is handed out (sec/restrict.h:+ * the broker and js_media.c read this same store); adding one to a running app takes the camera+ * or the microphone away at once (restrict_changed).** All of them validate: app ids with fw_app_canon, destinations with fw_parse_dest, ports 1–65535. */#include "js_fw.h"#include "../fw/rules.h"+#include "../sec/restrict.h"#include "js_err.h"#include "../netperm/npproto.h"@@ -276,8 +283,22 @@ static JSValue f_set_restricted(JSContext *c, JSValueConst t, int argc, JSValueCif (!f) return js_throw_code(c, "fw.invalidRestrictions", NULL);flags |= f;}+ uint32_t before = fw_restricted(store, app);if (fw_set_restricted(store, app, flags)) return JS_FALSE;- return JS_NewBool(c, save() == 0);+ int ok = save() == 0;+ restrict_changed(app, before, fw_restricted(store, app));+ return JS_NewBool(c, ok);+}++static JSValue f_blocks(JSContext *c, JSValueConst t, int argc, JSValueConst *argv) {+ (void)t;+ char app[FW_APP_MAX];+ if (argc < 2 || arg_app(c, argv[0], app)) return js_throw_code(c, "fw.invalidApp", NULL);+ const char *s = JS_IsString(argv[1]) ? JS_ToCString(c, argv[1]) : NULL;+ uint32_t f = s ? fw_flag_from_name(s) : 0;+ if (s) JS_FreeCString(c, s);+ if (!f) return js_throw_code(c, "fw.invalidRestrictions", NULL);+ return JS_NewBool(c, fw_blocks(store, app, f));}static JSValue f_set_mode(JSContext *c, JSValueConst t, int argc, JSValueConst *argv) {@@ -414,6 +435,7 @@ static const JSCFunctionListEntry fw_funcs[] = {JS_CFUNC_DEF("addRule", 1, f_add_rule),JS_CFUNC_DEF("removeRule", 1, f_remove_rule),JS_CFUNC_DEF("poll", 0, f_poll),+ JS_CFUNC_DEF("blocks", 2, f_blocks),};void js_fw_register(JSContext *c, JSValue lord) {@@ -426,6 +448,7 @@ void js_fw_register(JSContext *c, JSValue lord) {char err[200] = "";int r = store ? fw_load(store, path, err, sizeof err) : -1;if (r < 0) fprintf(stderr, "lord.fw: %s invalid (%s): starting without rules\n", path, err);+ restrict_set_store(store); /* the broker and js_media.c check it (sec/restrict.h) */ensure(); /* lord-netperm reads this session's rules */}if (!store) return;diff --git a/server/src/ui/js_media.c b/server/src/ui/js_media.cindex a8a8f76..c97a03d 100644--- a/server/src/ui/js_media.c+++ b/server/src/ui/js_media.c@@ -8,11 +8,16 @@* - camera, microphone and screen are checked against the system permissions (sec/perms.c,* per-app permission prompts) in C, not only in the SDK: the prompt is shown by the system (sdk/privacy.js) and here* the saved decision is required to be "allow";+ * - a firewall restriction of the built-in apps (firewall id "lordos", sec/restrict.h) beats the+ * permission: refused with fw.restricted.<perm>, and restricting while a camera, microphone+ * or screen recording runs stops it at once (media_restricted below);* - the decoder (lord-media) never receives a path: lord-server opens the file and passes the fd. */#include "js_media.h"#include "../media/media_int.h"#include "../media/proto.h"#include "../sec/perms.h"+#include "../sec/restrict.h"+#include "../fw/rules.h"#include "ui.h"#include "js_err.h"@@ -96,7 +101,15 @@ static int arg_id(JSContext *c, JSValueConst v) {return id;}+/* Built-in apps run inside lord-server: their firewall id is "lordos" (docs/FIREWALL.md). */+#define BUILTIN_FWID "lordos"+static int permitted(JSContext *c, const char *app, Perm p) {+ uint32_t rf = restrict_flag_of(p);+ if (rf && restrict_blocks(BUILTIN_FWID, rf)) { /* restricted: no prompt, no permission */+ js_throw_code(c, restrict_code(rf), "app", app, NULL);+ return 0;+ }if (perm_get(app, p) == PERM_ALLOW) return 1;char code[48];snprintf(code, sizeof code, "media.denied.%s", perm_name(p)); /* media.denied.camera, .microphone, .screen */@@ -629,7 +642,7 @@ static JSValue f_camera_record(JSContext *c, JSValueConst t, int argc, JSValueCoif (tmp[0]) return JS_FALSE;JSValueConst o = argc > 2 ? argv[2] : JS_UNDEFINED;int mic = opt_int(c, o, "mic", 1, 0, 1);- if (mic && perm_get(s->app, PERM_MICROPHONE) != PERM_ALLOW) mic = 0; /* no permission: video without sound */+ if (mic && (perm_get(s->app, PERM_MICROPHONE) != PERM_ALLOW || restrict_blocks(BUILTIN_FWID, FW_R_NO_MIC))) mic = 0; /* no permission: video without sound */const char *out = arg_path(c, argv[1]);if (!out) return JS_FALSE;int fd = media_open_output(out, tmp, 2048, dst, 2048);@@ -690,7 +703,37 @@ static const JSCFunctionListEntry media_funcs[] = {JS_CFUNC_DEF("hwaccel", 0, f_hwaccel),};+/* A restriction was just added to the built-in apps: what it covers stops now, like revoking the+ * permission of an isolated app. The camera's lord-media is killed (the window gets "closed" with+ * revoked); recordings that use the microphone or the screen are finished properly (the file is+ * kept up to the moment of the restriction). Sources of isolated apps (bk) are the broker's. */+static void media_restricted(uint32_t added) {+ for (int i = 0; i < MEDIA_MAX_SRC; i++) {+ MediaSrc *s = media_src_at(i);+ if (!s || s->bk) continue;+ if (s->kind == SK_CAMERA && (added & FW_R_NO_CAMERA)) {+ int id = s->id;+ fprintf(stderr, "media: camera of %s stopped by a restriction\n", s->app);+ media_src_close(s);+ media_event(id, "closed", "{\"crashed\":false,\"revoked\":true}");+ continue;+ }+ if (s->kind == SK_CAMERA && s->mic && (added & FW_R_NO_MIC) && s->sock >= 0) {+ mp_send(s->sock, MM_RECORD, 2, NULL, NULL, 0, NULL, 0); /* the video recording stops */+ maudio_close(s->mic);+ s->mic = NULL;+ }+ int stop = (s->kind == SK_AUDIOREC && (added & FW_R_NO_MIC)) ||+ (s->kind == SK_SCREENREC && ((added & FW_R_NO_SCREEN) || (s->mic && (added & FW_R_NO_MIC))));+ if (stop && s->sock >= 0) {+ fprintf(stderr, "media: recording of %s stopped by a restriction\n", s->app);+ mp_sendv(s->sock, MM_STOP, 0, 0, 0, 0, 0);+ }+ }+}+void js_media_register(JSContext *c, JSValue lord) {+ restrict_set_local_hook(media_restricted);JSValue m = JS_NewObject(c);JS_SetPropertyFunctionList(c, m, media_funcs, sizeof media_funcs / sizeof media_funcs[0]);JS_SetPropertyStr(c, lord, "media", m);diff --git a/server/tests/broker_restrict_test.c b/server/tests/broker_restrict_test.cnew file mode 100644index 0000000..0884582--- /dev/null+++ b/server/tests/broker_restrict_test.c@@ -0,0 +1,347 @@+/* broker_restrict_test.c — the firewall's non-network restrictions in the broker (src/sec/restrict.c,+ * brokersrv.c, brokercam.c; docs/FIREWALL.md, "Non-network restrictions").+ *+ * The real broker server code runs against a fake isolated app on a socketpair: it sends requests+ * like js_broker.c does and reads the replies. For every restriction the test checks that the+ * request goes through without it and is refused with it, without a prompt, with the code line+ * fw.restricted.<what>, even when the permission was granted before. It also checks live+ * revocation (restricting a running app stops its camera and its microphone), the "restricted+ * meanwhile" paths (prompt answered or file picked after the restriction) and the built-in apps'+ * hook (firewall id "lordos", used by js_media.c).+ *+ * Only the edges are stand-ins: the terminal's clipboard, PipeWire (maudio_*), lord-vault's FIDO+ * attach, the keyring, the keyboard and lord-media's spawn. open() is wrapped so /dev/video9 is+ * /dev/null. Temporary HOME. `make build/broker-restrict-test && build/broker-restrict-test`. */+#include "sec/broker_int.h"+#include "sec/perms.h"+#include "sec/restrict.h"+#include "fw/rules.h"+#include "media/media_int.h"+#include "errcode.h"++#include <fcntl.h>+#include <poll.h>+#include <stdarg.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>+#include <sys/mman.h>+#include <sys/socket.h>+#include <sys/stat.h>+#include <unistd.h>++static int fails, total;+static void check(int ok, const char *what) { total++; printf("%s: %s\n", ok ? "ok " : "FAIL", what); if (!ok) fails++; }++/* ---- stand-ins for the rest of lord-server ---- */+const char *term_clipboard(void) { return "clipboard text"; }+void term_set_clipboard(const char *s, size_t n) { (void)s; (void)n; }+void term_clipboard_mark(const char *app, int secret) { (void)app; (void)secret; }+const char *kb_layouts(void) { return "us"; }+const char *kb_variants(void) { return ""; }+int kb_group(void) { return 0; }+void sha256(const void *d, size_t n, uint8_t out[32]) { (void)d; (void)n; memset(out, 0, 32); }+int vc_fido_attach(char *name, size_t n) { snprintf(name, n, "test key"); return 0; }+void brokerkr_handle(int conn, int fd, uint32_t reqid, const char *app, char *payload, uint32_t len) { (void)conn; (void)fd; (void)reqid; (void)app; (void)payload; (void)len; }+int brokerkr_resolve(uint32_t prompt, int allow) { (void)prompt; (void)allow; return 0; }+void brokerkr_conn_closed(int conn) { (void)conn; }+void brokerkr_tick(void) {}+int brokerkr_pollfd(void) { return -1; }++struct MAudio { int open; };+static struct MAudio mics[8];+static int mics_open, mics_closed;+MAudio *maudio_open(int capture, const char *app, const char *title, const char *src, int *ringfd) {+ (void)capture; (void)app; (void)title; (void)src;+ for (int i = 0; i < 8; i++) if (!mics[i].open) {+ mics[i].open = 1;+ mics_open++;+ *ringfd = memfd_create("ring", MFD_CLOEXEC);+ if (*ringfd >= 0 && ftruncate(*ringfd, 4096)) { close(*ringfd); *ringfd = -1; }+ return &mics[i];+ }+ return NULL;+}+void maudio_close(MAudio *a) { if (a && a->open) { a->open = 0; mics_closed++; } }+int maudio_pollfd(const MAudio *a, short *events) { (void)a; *events = 0; return -1; }+void maudio_service(MAudio *a) { (void)a; }+void maudio_mic_drain(MAudio *a) { (void)a; }++static MediaSrc srcs[4];+static int srcs_closed;+MediaSrc *media_src_new(int kind, const char *app) {+ for (int i = 0; i < 4; i++) if (!srcs[i].used) {+ memset(&srcs[i], 0, sizeof srcs[i]);+ srcs[i].used = 1; srcs[i].id = i + 1; srcs[i].kind = kind; srcs[i].sock = -1; srcs[i].in_fd = -1;+ snprintf(srcs[i].app, sizeof srcs[i].app, "%s", app);+ return &srcs[i];+ }+ return NULL;+}+MediaSrc *media_src_get(int id) { return id >= 1 && id <= 4 && srcs[id - 1].used ? &srcs[id - 1] : NULL; }+void media_src_close(MediaSrc *s) { if (s && s->used) { if (s->sock >= 0) close(s->sock); s->used = 0; srcs_closed++; } }+int media_spawn(int kind, const char *params, const int *fds, int nfds, pid_t *pid) {+ (void)kind; (void)params; (void)fds; (void)nfds;+ int sv[2];+ if (socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sv)) return -1;+ *pid = 0; /* no real helper: nothing to kill */+ return sv[0]; /* sv[1] leaks on purpose: the "helper" side */+}+int media_render_fd(void) { return -1; }+const char *media_hwaccel(void) { return "none"; }+int media_cameras(char *json, size_t n) { snprintf(json, n, "[{\"dev\":\"/dev/video9\"}]"); return 1; }++/* /dev/video9 → /dev/null, so the broker's camera open succeeds without a camera */+int __real_open(const char *path, int flags, ...);+int __wrap_open(const char *path, int flags, ...) {+ va_list ap;+ va_start(ap, flags);+ int mode = (flags & O_CREAT) ? va_arg(ap, int) : 0;+ va_end(ap);+ if (!strcmp(path, "/dev/video9")) return __real_open("/dev/null", O_RDWR | O_CLOEXEC);+ return __real_open(path, flags, mode);+}++/* ---- the fake app ---- */+static int app_end, srv_end;+static uint32_t next_req = 1;+static char got[1 << 16];+static uint32_t got_len;+static int got_status, got_fd;+static char evs[64][300];+static int nevs;++static void collect_events(const char *kind, const char *json) { if (nevs < 64) snprintf(evs[nevs++], sizeof evs[0], "%s %s", kind, json); }+static int has_event(const char *needle) {+ for (int i = 0; i < nevs; i++) if (strstr(evs[i], needle)) return 1;+ return 0;+}++/* sends one request and runs the server's dispatch; 1 if a reply came back */+static int call(int op, const void *payload, uint32_t len) {+ BrokerHdr h = { .reqid = next_req++, .op = (uint16_t)op, .status = BROKER_REQ, .len = len };+ struct iovec iov[2] = { { &h, sizeof h }, { (void *)payload, len } };+ struct msghdr m = { .msg_iov = iov, .msg_iovlen = len ? 2 : 1 };+ if (sendmsg(app_end, &m, MSG_NOSIGNAL) < 0) return 0;+ struct pollfd pfd[8];+ int n = brokersrv_pollfds(pfd, 8);+ for (int i = 0; i < n; i++) pfd[i].revents = pfd[i].fd == srv_end ? POLLIN : 0;+ brokersrv_dispatch(pfd, n);+ nevs = 0;+ brokersrv_events(collect_events);+ got_fd = -1;+ for (;;) {+ BrokerHdr r;+ char cm[CMSG_SPACE(sizeof(int))];+ struct iovec riov[2] = { { &r, sizeof r }, { got, sizeof got - 1 } };+ struct msghdr rm = { .msg_iov = riov, .msg_iovlen = 2, .msg_control = cm, .msg_controllen = sizeof cm };+ ssize_t k = recvmsg(app_end, &rm, MSG_DONTWAIT);+ if (k < (ssize_t)sizeof r) return 0;+ got_len = (uint32_t)(k - (ssize_t)sizeof r);+ got[got_len] = 0;+ for (struct cmsghdr *c = CMSG_FIRSTHDR(&rm); c; c = CMSG_NXTHDR(&rm, c))+ if (c->cmsg_level == SOL_SOCKET && c->cmsg_type == SCM_RIGHTS) memcpy(&got_fd, CMSG_DATA(c), sizeof got_fd);+ if (r.op == BOP_EVENT) continue; /* unrequested events: skipped here */+ got_status = r.status;+ if (got_fd >= 0) close(got_fd);+ return r.reqid == h.reqid;+ }+}+#define CALLS(op, s) call(op, s, (uint32_t)strlen(s))++/* reads the unrequested events the server sent to the app ("revoke", "cam" …) */+static int app_event(const char *needle) {+ int found = 0;+ for (;;) {+ BrokerHdr r;+ char buf[2048];+ struct iovec riov[2] = { { &r, sizeof r }, { buf, sizeof buf - 1 } };+ struct msghdr rm = { .msg_iov = riov, .msg_iovlen = 2 };+ ssize_t k = recvmsg(app_end, &rm, MSG_DONTWAIT);+ if (k < (ssize_t)sizeof r) return found;+ size_t pl = (size_t)k - sizeof r;+ for (size_t i = 0; i < pl; i++) if (!buf[i]) buf[i] = ' ';+ buf[pl] = 0;+ if (r.op == BOP_EVENT && strstr(buf, needle)) found = 1;+ }+}++/* the next reply (not an event) that is already waiting: its status, payload in got */+static int read_reply(void) {+ for (;;) {+ BrokerHdr r;+ struct iovec iov[2] = { { &r, sizeof r }, { got, sizeof got - 1 } };+ struct msghdr m = { .msg_iov = iov, .msg_iovlen = 2 };+ ssize_t k = recvmsg(app_end, &m, MSG_DONTWAIT);+ if (k < (ssize_t)sizeof r) { got[0] = 0; return got_status = -1; }+ got[k - sizeof r] = 0;+ if (r.op != BOP_EVENT) return got_status = r.status;+ }+}++static int denied_with(const char *code) { return got_status == BST_DENIED && lerr_has(got, code); }++static FwStore *store;+static void restrict_app(const char *fwid, uint32_t flags) {+ uint32_t before = fw_restricted(store, fwid);+ fw_set_restricted(store, fwid, flags);+ restrict_changed(fwid, before, fw_restricted(store, fwid));+}++static uint32_t local_added;+static void local_hook(uint32_t added) { local_added |= added; }++int main(void) {+ char home[] = "/tmp/broker-restrict-XXXXXX";+ if (!mkdtemp(home)) { perror("mkdtemp"); return 1; }+ setenv("HOME", home, 1);+ perm_init(home);+ store = fw_store_new();+ restrict_set_store(store);+ restrict_set_local_hook(local_hook);++ int sv[2];+ if (socketpair(AF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0, sv)) { perror("socketpair"); return 1; }+ app_end = sv[0]; srv_end = sv[1];+ brokersrv_add(srv_end, "game", 4242);+ brokersrv_set_vault(srv_end); /* lets the test reach the FIDO op too */+ const char *perms_on[] = { "camera", "microphone", "clipboard", "usb", "files", "screen", "bluetooth", "notifications" };+ for (size_t i = 0; i < sizeof perms_on / sizeof *perms_on; i++) perm_set("game", (Perm)perm_from_name(perms_on[i]), PERM_ALLOW);++ /* ---- clipboard ---- */+ check(call(BOP_CLIP_GET, NULL, 0) && got_status == BST_OK && !strcmp(got, "clipboard text"), "clipboard: read with the permission");+ restrict_app("lpk:game", FW_R_NO_CLIPBOARD);+ check(call(BOP_CLIP_GET, NULL, 0) && denied_with("fw.restricted.clipboard"), "clipboard: no-clipboard refuses it with fw.restricted.clipboard");+ check(strstr(got, "app=game") != NULL, "clipboard: the code line names the app");+ restrict_app("lpk:game", 0);++ /* ---- permissions: refused without a prompt ---- */+ for (size_t i = 0; i < sizeof perms_on / sizeof *perms_on; i++) {+ Perm p = (Perm)perm_from_name(perms_on[i]);+ uint32_t f = restrict_flag_of(p);+ char what[128];+ CALLS(BOP_PERM, perms_on[i]);+ snprintf(what, sizeof what, "permission %s: granted without a restriction", perms_on[i]);+ check(got_status == BST_OK && got[0] == '1', what);+ restrict_app("lpk:game", f);+ CALLS(BOP_PERM, perms_on[i]);+ snprintf(what, sizeof what, "permission %s: restricted → \"0\" with %s, no prompt", perms_on[i], restrict_code(f));+ check(got_status == BST_OK && got[0] == '0' && lerr_has(got + 2, restrict_code(f)) && !has_event("prompt"), what);+ perm_set("game", p, PERM_ASK); /* never asked: still no prompt */+ CALLS(BOP_PERM, perms_on[i]);+ snprintf(what, sizeof what, "permission %s: restricted and never asked → no prompt either", perms_on[i]);+ check(got[0] == '0' && !has_event("prompt"), what);+ perm_set("game", p, PERM_ALLOW);+ restrict_app("lpk:game", 0);+ }++ /* a prompt answered "allow" after the app was restricted meanwhile still gets "0" */+ perm_set("game", PERM_CAMERA, PERM_ASK);+ CALLS(BOP_PERM, "camera");+ unsigned ui = 0;+ for (int i = 0; i < nevs; i++) { const char *q = strstr(evs[i], "\"reqid\":"); if (strstr(evs[i], "prompt") && q) ui = (unsigned)strtoul(q + 8, NULL, 10); }+ check(ui != 0, "camera: without a restriction an undecided permission prompts");+ restrict_app("lpk:game", FW_R_NO_CAMERA);+ brokersrv_resolve(ui, 1);+ read_reply();+ check(got[0] == '0', "camera: a prompt allowed after the restriction still answers \"0\"");+ restrict_app("lpk:game", 0);+ perm_set("game", PERM_CAMERA, PERM_ALLOW);++ /* ---- device indicator ---- */+ CALLS(BOP_DEVICE, "camera 1");+ check(has_event("\"kind\":\"camera\",\"on\":true"), "camera: the indicator lights with the permission");+ restrict_app("lpk:game", FW_R_NO_CAMERA);+ CALLS(BOP_DEVICE, "camera 1");+ check(!has_event("\"kind\":\"camera\",\"on\":true"), "camera: a restricted app cannot light the camera indicator");+ restrict_app("lpk:game", 0);++ /* ---- microphone, and live revocation ---- */+ check(call(BOP_MIC, "1", 1) && got_status == BST_OK, "microphone: the ring is handed over with the permission");+ int closed0 = mics_closed;+ app_event(""); /* drain */+ restrict_app("lpk:game", FW_R_NO_MIC);+ check(mics_closed == closed0 + 1, "microphone: restricting the running app closes its stream now");+ check(app_event("revoke {\"perm\":\"microphone\"}"), "microphone: the app is told (revoke event)");+ nevs = 0; brokersrv_events(collect_events);+ check(has_event("\"kind\":\"microphone\",\"on\":false"), "microphone: the indicator goes off");+ check(call(BOP_MIC, "1", 1) && denied_with("fw.restricted.microphone"), "microphone: no-mic refuses it with fw.restricted.microphone");+ restrict_app("lpk:game", 0);++ /* ---- camera, and live revocation ---- */+ check(CALLS(BOP_CAMERA, "list") && strstr(got, "video9"), "camera: listed with the permission");+ restrict_app("lpk:game", FW_R_NO_CAMERA);+ check(CALLS(BOP_CAMERA, "list") && !strcmp(got, "[]"), "camera: a restricted app sees no cameras");+ check(CALLS(BOP_CAMERA, "open /dev/video9 640 480") && denied_with("fw.restricted.camera"), "camera: no-camera refuses open with fw.restricted.camera");+ restrict_app("lpk:game", 0);+ check(CALLS(BOP_CAMERA, "open /dev/video9 640 480") && got_status == BST_OK, "camera: opens without the restriction");+ int sid = atoi(got);+ int sclosed0 = srcs_closed;+ app_event("");+ restrict_app("lpk:game", FW_R_NO_CAMERA);+ check(srcs_closed == sclosed0 + 1 && !media_src_get(sid), "camera: restricting the running app ends its stream now");+ char needle[64];+ snprintf(needle, sizeof needle, "closed %d revoked", sid);+ check(app_event(needle), "camera: the app gets \"closed … revoked\"");+ restrict_app("lpk:game", 0);++ /* ---- files: the picker and the camera's save dialog ---- */+ check(call(BOP_PICK, "0\0x.txt", 7) == 0 && has_event("pick"), "files: the picker opens without the restriction");+ unsigned pick = 0;+ for (int i = 0; i < nevs; i++) { const char *q = strstr(evs[i], "\"reqid\":"); if (strstr(evs[i], "pick") && q) pick = (unsigned)strtoul(q + 8, NULL, 10); }+ restrict_app("lpk:game", FW_R_NO_FILES);+ char picked[600];+ snprintf(picked, sizeof picked, "%s/picked.txt", home);+ { int f = open(picked, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (f >= 0) close(f); }+ brokersrv_pick_result(pick, picked);+ read_reply();+ check(got_status == BST_DENIED, "files: a file picked after the restriction is not handed over");+ check(call(BOP_PICK, "0\0x.txt", 7) && denied_with("fw.restricted.files"), "files: no-files refuses the picker with fw.restricted.files");+ check(!has_event("pick"), "files: and no dialog is shown");+ restrict_app("lpk:game", 0);+ CALLS(BOP_CAMERA, "open /dev/video9 640 480");+ sid = atoi(got);+ restrict_app("lpk:game", FW_R_NO_FILES);+ char ph[64];+ snprintf(ph, sizeof ph, "photo %d 0 shot.jpg", sid);+ check(CALLS(BOP_CAMERA, ph) && denied_with("fw.restricted.files"), "files: no-files refuses saving a camera photo");+ restrict_app("lpk:game", 0);+ snprintf(ph, sizeof ph, "close %d", sid);+ CALLS(BOP_CAMERA, ph);++ /* ---- USB (the FIDO2 key of Passwords) ---- */+ check(call(BOP_VAULT_FIDO, NULL, 0) && got_status == BST_OK && !strcmp(got, "test key"), "usb: the key is attached with the permission");+ restrict_app("lpk:game", FW_R_NO_USB);+ check(call(BOP_VAULT_FIDO, NULL, 0) && denied_with("fw.restricted.usb"), "usb: no-usb refuses it with fw.restricted.usb");+ restrict_app("lpk:game", 0);++ /* ---- other apps and ids ---- */+ restrict_app("lpk:other", FW_R_ALL);+ check(call(BOP_CLIP_GET, NULL, 0) && got_status == BST_OK, "another app's restriction does not touch this one");+ restrict_app("lpk:other", 0);+ check(restrict_perm_pkg("game", PERM_CAMERA) == PERM_ALLOW, "restrict_perm_pkg: the permission when not restricted");+ restrict_app("lpk:game", FW_R_NO_CAMERA);+ check(restrict_perm_pkg("game", PERM_CAMERA) == PERM_DENY, "restrict_perm_pkg: DENY when restricted, over an allow");+ restrict_app("lpk:game", 0);++ /* ---- built-in apps: firewall id "lordos" (js_media.c) ---- */+ check(!restrict_blocks("lordos", FW_R_NO_CAMERA), "lordos: not restricted by default");+ restrict_app("lordos", FW_R_NO_CAMERA | FW_R_NO_MIC);+ check(restrict_blocks("lordos", FW_R_NO_CAMERA) && restrict_blocks("lordos", FW_R_NO_MIC) && !restrict_blocks("lordos", FW_R_NO_SCREEN),+ "lordos: js_media.c sees exactly the restrictions set");+ check(local_added == (FW_R_NO_CAMERA | FW_R_NO_MIC), "lordos: the live hook gets what was just added (stops camera and recordings)");+ local_added = 0;+ restrict_app("lordos", FW_R_NO_CAMERA | FW_R_NO_MIC | FW_R_NO_SCREEN);+ check(local_added == FW_R_NO_SCREEN, "lordos: only the new restriction is passed on");+ restrict_app("lordos", 0);+ check(!restrict_blocks_pkg("lordos", FW_R_NO_CAMERA), "a package named \"lordos\" is lpk:lordos, not the built-in apps");+ restrict_set_store(NULL);+ check(!restrict_blocks("lpk:game", FW_R_NO_CAMERA), "no store: no restrictions (and no crash)");++ char cmd[600];+ snprintf(cmd, sizeof cmd, "rm -rf '%s'", home);+ if (system(cmd)) {}+ fw_store_free(store);+ printf("%d/%d %s\n", total - fails, total, fails ? "FAILED" : "passed");+ return fails ? 1 : 0;+}