diff --git a/.github/workflows/tron-headless.yml b/.github/workflows/tron-headless.yml new file mode 100644 index 0000000..365120e --- /dev/null +++ b/.github/workflows/tron-headless.yml @@ -0,0 +1,147 @@ +# Build, smoke-test and publish ghcr.io/profullstack/tron-headless: the +# TronBrowser engine headless with CDP on :9222, for c0mpute browser nodes. +# Contract: docker/tron-headless/README.md. +# +# Pull requests that touch the image: build + smoke test, push nothing. +# v* tags (every TronBrowser release) and workflow_dispatch: smoke test, then +# push :vX.Y.Z and :latest (linux/amd64). Nothing is uploaded as a workflow +# artifact; the registry is the only output. +# +# Visibility: GHCR creates org packages PRIVATE and has no API to change it, so +# it is one click by an org admin: github.com/orgs/profullstack/packages -> +# tron-headless -> Package settings -> Change visibility -> Public. The last +# step warns until an anonymous pull works. +name: tron-headless image + +on: + push: + tags: ['v*'] + pull_request: + paths: + - 'docker/tron-headless/**' + - '.github/workflows/tron-headless.yml' + workflow_dispatch: + inputs: + version: + description: 'Tag to publish, e.g. 3.21.0 (pushed as v3.21.0 and latest)' + required: true + +permissions: + contents: read + +env: + IMAGE: ghcr.io/profullstack/tron-headless + +concurrency: + group: tron-headless-${{ github.event_name }}-${{ github.ref }} + cancel-in-progress: false + +jobs: + smoke: + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v5 + - uses: actions/setup-node@v5 + with: + node-version: 22 + # The smoke script has no dependencies; without this, setup-node v5 + # sees package.json's packageManager and looks for pnpm. + package-manager-cache: false + + - name: Build + run: docker build -t tron-headless:ci docker/tron-headless + + - name: Run with the c0mpute node's flags + run: | + docker run -d --name th \ + --cap-drop ALL --security-opt no-new-privileges \ + --shm-size 1g --memory 2g \ + -p 127.0.0.1:9222:9222 tron-headless:ci + test "$(docker exec th id -u):$(docker exec th id -g)" = "1000:1000" + + - name: CDP smoke test (version, attach, navigate, screencast, screenshot) + run: node docker/tron-headless/smoke.mjs http://127.0.0.1:9222 + + - name: The container exits when its command exits + run: | + set -eu + docker run -d --name th-exit --cap-drop ALL --security-opt no-new-privileges \ + --shm-size 1g tron-headless:ci bash -c 'sleep 3; exit 7' + code=$(timeout 60 docker wait th-exit) + test "$code" = "7" + + - name: Container logs + if: always() + run: docker logs th 2>&1 | grep -v -E 'dbus|GLib-GIO' | tail -40 || true + + publish: + needs: smoke + if: github.event_name != 'pull_request' + runs-on: ubuntu-latest + timeout-minutes: 30 + permissions: + contents: read + packages: write + steps: + - id: v + env: + EVENT: ${{ github.event_name }} + INPUT_VERSION: ${{ inputs.version }} + REF_NAME: ${{ github.ref_name }} + run: | + set -eu + if [ "$EVENT" = "workflow_dispatch" ]; then v="${INPUT_VERSION#v}"; else v="${REF_NAME#v}"; fi + echo "$v" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$' || { echo "not a release version: $v" >&2; exit 1; } + echo "tag=v$v" >> "$GITHUB_OUTPUT" + echo "version=$v" >> "$GITHUB_OUTPUT" + + - uses: actions/checkout@v5 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + id: build + uses: docker/build-push-action@v6 + with: + context: docker/tron-headless + platforms: linux/amd64 + push: true + tags: | + ${{ env.IMAGE }}:${{ steps.v.outputs.tag }} + ${{ env.IMAGE }}:latest + labels: | + org.opencontainers.image.source=https://github.com/${{ github.repository }} + org.opencontainers.image.url=https://tronbrowser.dev + org.opencontainers.image.title=tron-headless + org.opencontainers.image.description=TronBrowser engine (ungoogled-chromium) headless, CDP on :9222, for c0mpute browser nodes + org.opencontainers.image.licenses=MIT + org.opencontainers.image.version=${{ steps.v.outputs.version }} + org.opencontainers.image.revision=${{ github.sha }} + + - name: Inspect + env: + TAG: ${{ steps.v.outputs.tag }} + DIGEST: ${{ steps.build.outputs.digest }} + run: | + docker buildx imagetools inspect "${IMAGE}:${TAG}" + echo "${IMAGE}:${TAG} @ ${DIGEST}" >> "$GITHUB_STEP_SUMMARY" + + - name: Check anonymous pull (package visibility) + env: + TAG: ${{ steps.v.outputs.tag }} + run: | + token=$(curl -fsS "https://ghcr.io/token?scope=repository:profullstack/tron-headless:pull" | jq -r .token) + code=$(curl -s -o /dev/null -w '%{http_code}' -H "Authorization: Bearer $token" \ + -H 'Accept: application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.list.v2+json' \ + "https://ghcr.io/v2/profullstack/tron-headless/manifests/${TAG}") + if [ "$code" = "200" ]; then + echo "anonymous pull works" >> "$GITHUB_STEP_SUMMARY" + else + echo "::warning::ghcr.io/profullstack/tron-headless is not public (HTTP $code): an org admin must set Package settings -> Change visibility -> Public" + echo "ghcr.io/profullstack/tron-headless is PRIVATE (HTTP $code): make it public in package settings" >> "$GITHUB_STEP_SUMMARY" + fi diff --git a/.github/workflows/windows-pit.yml b/.github/workflows/windows-pit.yml index d58eb64..4e69f8d 100644 --- a/.github/workflows/windows-pit.yml +++ b/.github/workflows/windows-pit.yml @@ -5,7 +5,7 @@ on: branches: [main] paths: - 'apps/desktop/launcher/**' - - 'apps/desktop/test/test_windows_pit.py' + - 'apps/desktop/test/test_*.py' - 'apps/desktop/test/windows_pit_acceptance.py' - 'apps/desktop/test/windows-pit-browser.mjs' - 'apps/desktop/test/browser-driver/**' @@ -17,7 +17,7 @@ on: pull_request: paths: - 'apps/desktop/launcher/**' - - 'apps/desktop/test/test_windows_pit.py' + - 'apps/desktop/test/test_*.py' - 'apps/desktop/test/windows_pit_acceptance.py' - 'apps/desktop/test/windows-pit-browser.mjs' - 'apps/desktop/test/browser-driver/**' @@ -45,7 +45,7 @@ jobs: with: python-version: '3.12' - name: Test helper and Windows launcher (no certificate imports) - run: python -B -m unittest discover -s apps/desktop/test -p test_windows_pit.py -v + run: python -B -m unittest discover -s apps/desktop/test -p 'test_*.py' -v windows-browser: if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository diff --git a/README.md b/README.md index d621a43..06db03d 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,16 @@ tron version > clearnet names untouched. For every app on the box run `moshcode dns enable` > instead. Details: [`docs/moshpit-pit-toggle.md`](docs/moshpit-pit-toggle.md). +> **🌱 Scallion** (Settings, and a sidebar button) is c0mpute's onion-style relay +> network. It is **off by default, experimental and unreviewed**, and today it +> cannot carry TronBrowser's traffic: the setting shows the c0mpute CLI's own +> readiness check and its blockers, and only routes once that check passes and a +> local Scallion SOCKS client is running. Details: [`docs/scallion.md`](docs/scallion.md). +> +> **`ghcr.io/profullstack/tron-headless`** is a headless Tron engine image with +> CDP on port 9222, used by c0mpute browser nodes. Details: +> [`docker/tron-headless/README.md`](docker/tron-headless/README.md). + Also packaged for **macOS · Windows · Debian/Ubuntu (.deb) · Fedora/RHEL (.rpm) · Arch (AUR) · Gentoo · NixOS · Snap · Flatpak · AppImage · FreeBSD** — and arm64 Linux phones (Librem 5 / PinePhone / Ubuntu Touch). See diff --git a/apps/desktop/extensions/ai-sidebar/background-helper.test.js b/apps/desktop/extensions/ai-sidebar/background-helper.test.js index 7055c8e..54c9a2f 100644 --- a/apps/desktop/extensions/ai-sidebar/background-helper.test.js +++ b/apps/desktop/extensions/ai-sidebar/background-helper.test.js @@ -71,6 +71,55 @@ describe('extension network helper requests', () => { expectSimpleRequests(); }); + it('refuses Scallion while the doctor is not ready and never touches the proxy', async () => { + fetchMock.mockImplementation(async (url) => ({ + ok: true, + json: async () => url.endsWith('/scallion/start') + ? { started: false, routing: false, ready: false, error: 'not-ready', blockers: ['independent security review is outstanding'] } + : {}, + })); + const res = await send({ type: 'scallion-set', on: true }); + expect(res).toMatchObject({ enabled: false, error: 'not-ready' }); + expect(res.status.blockers).toEqual(['independent security review is outstanding']); + expect(chrome.proxy.settings.set).not.toHaveBeenCalled(); + expect(helperCalls().map(([url, options]) => [new URL(url).pathname, options.method])) + .toEqual([['/scallion/start', 'POST']]); + expectSimpleRequests(); + }); + + it('routes through a ready Scallion SOCKS client and reverts when traffic does not flow', async () => { + let verify = false; + fetchMock.mockImplementation(async (url) => { + if (url.startsWith('https://my.ip.pit.world/')) { + if (!verify) throw new Error('socks dead'); + return { ok: true, json: async () => ({ ip: '203.0.113.7' }) }; + } + return { + ok: true, + json: async () => url.endsWith('/scallion/start') + ? { started: true, routing: true, ready: true, socks: '127.0.0.1:9095', host: '127.0.0.1', port: 9095 } + : { stopped: true }, + }; + }); + const failed = await send({ type: 'scallion-set', on: true }); + expect(failed).toMatchObject({ enabled: false, error: 'verify-failed' }); + const sets = chrome.proxy.settings.set.mock.calls.map(([arg]) => arg.value); + expect(sets[0].rules.singleProxy).toEqual({ scheme: 'socks5', host: '127.0.0.1', port: 9095 }); + expect(sets.at(-1)).toEqual({ mode: 'system' }); + expect(helperCalls().map(([url]) => new URL(url).pathname)).toEqual(['/scallion/start', '/scallion/stop']); + + verify = true; + expect(await send({ type: 'scallion-set', on: true })).toMatchObject({ enabled: true, check: { ok: true, ip: '203.0.113.7' } }); + expect(chrome.privacy.network.webRTCIPHandlingPolicy.set).toHaveBeenCalledWith({ value: 'disable_non_proxied_udp' }); + }); + + it('keeps Scallion and Tor exclusive', async () => { + chrome.storage.local.get.mockResolvedValue({ torEnabled: true }); + expect(await send({ type: 'scallion-set', on: true })).toMatchObject({ enabled: false, error: 'tor-on' }); + chrome.storage.local.get.mockResolvedValue({ scallionEnabled: true }); + expect(await send({ type: 'pit-set', on: true })).toMatchObject({ enabled: false, error: 'scallion-on' }); + }); + it('uses POST for Tor mutations and GET only for status', async () => { expect(await send({ type: 'tor-set', on: true })).toMatchObject({ enabled: true }); expect(await send({ type: 'tor-set', on: false })).toEqual({ enabled: false }); diff --git a/apps/desktop/extensions/ai-sidebar/background.js b/apps/desktop/extensions/ai-sidebar/background.js index 812596b..e3d05c0 100644 --- a/apps/desktop/extensions/ai-sidebar/background.js +++ b/apps/desktop/extensions/ai-sidebar/background.js @@ -1,5 +1,6 @@ import { decideInstallTarget, lookupInstalled } from './install-state.js'; import { PIT_SOCKS_PORT, pitProxyConfig } from './pit-proxy.js'; +import { SCALLION_CHECK_URL, parseLoopbackSocks, scallionProxyConfig } from './scallion.js'; import { installPush } from './push-client.js'; import { PIT_DIRECT_RULES, w3bsFromSearch } from './w3bs.js'; @@ -168,9 +169,9 @@ const TOR_CHECK_URL = 'https://check.torproject.org/api/ip'; // to Tor until the user flips it on. const TOR_HELPER = 'http://127.0.0.1:9061'; -async function helperJson(path, method) { +async function helperJson(path, method, timeoutMs = 8000) { const ctrl = new AbortController(); - const t = setTimeout(() => ctrl.abort(), 8000); + const t = setTimeout(() => ctrl.abort(), timeoutMs); try { const res = await fetch(`${TOR_HELPER}${path}`, { method, signal: ctrl.signal }); return await res.json().catch(() => ({})); @@ -287,11 +288,16 @@ chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => { if (msg.on) { // Tor and the pit are exclusive: the pit's PAC asks the system resolver // about every host, which under Tor would leak lookups outside it. - const { pitEnabled } = await chrome.storage.local.get('pitEnabled'); + const { pitEnabled, scallionEnabled } = await chrome.storage.local.get(['pitEnabled', 'scallionEnabled']); if (pitEnabled) { await disablePit(); await stopPitViaHelper(); } + // Tor and Scallion both own the whole proxy; only one at a time. + if (scallionEnabled) { + await disableScallion(); + await stopScallionViaHelper(); + } const started = await startTorViaHelper(); if (started.error === 'unreachable') { sendResponse({ enabled: false, started: { error: 'unreachable' } }); @@ -483,9 +489,9 @@ async function enablePit() { } async function disablePit() { - // Only hand the proxy back to the OS when Tor is not holding it. - const { torEnabled } = await chrome.storage.local.get('torEnabled'); - if (!torEnabled) { + // Only hand the proxy back to the OS when Tor or Scallion is not holding it. + const { torEnabled, scallionEnabled } = await chrome.storage.local.get(['torEnabled', 'scallionEnabled']); + if (!torEnabled && !scallionEnabled) { try { await chrome.proxy.settings.set({ value: { mode: 'system' }, scope: 'regular' }); } catch (_) { /* fall through to clear */ } @@ -537,11 +543,15 @@ chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => { if (msg?.type === 'pit-set') { (async () => { if (msg.on) { - const { torEnabled } = await chrome.storage.local.get('torEnabled'); + const { torEnabled, scallionEnabled } = await chrome.storage.local.get(['torEnabled', 'scallionEnabled']); if (torEnabled) { sendResponse({ enabled: false, error: 'tor-on' }); return; } + if (scallionEnabled) { + sendResponse({ enabled: false, error: 'scallion-on' }); + return; + } const started = await startPitViaHelper(); if (!started.started) { sendResponse({ enabled: false, error: started.error || 'pit-failed' }); @@ -566,25 +576,170 @@ chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => { } }); +// --- Scallion (c0mpute network) ----------------------------------------- +// Off by default and fail closed. The helper decides whether routing is even +// allowed (doctor ready:true AND a loopback `socks` it can connect to); today it +// never is, so 'scallion-set' on returns the doctor's blockers. When it is, the +// proxy goes on exactly like Tor's (SOCKS5 + WebRTC guard), traffic is verified, +// and any failure reverts to normal browsing. Exclusive with Tor and the pit. +// Experimental and unreviewed; not anonymity. See docs/scallion.md. +async function scallionStatusViaHelper() { + try { + const st = await helperJson('/scallion/status', 'GET', 30000); + if (st && st.error === 'not-found') return { error: 'helper-stale' }; + return st; + } catch (_) { + return { error: 'unreachable' }; + } +} + +async function stopScallionViaHelper() { + try { + await helperJson('/scallion/stop', 'POST', 5000); + } catch (_) { /* helper not running: nothing to stop */ } +} + +async function setScallionBadge(on) { + try { + await chrome.action.setBadgeText({ text: on ? 'SCL' : '' }); + await chrome.action.setBadgeBackgroundColor({ color: '#c47f00' }); + await chrome.action.setTitle({ title: on ? 'TronBrowser: Scallion ON (experimental)' : 'TronBrowser' }); + } catch (_) { /* action API may be unavailable */ } +} + +async function enableScallion(socks) { + await chrome.proxy.settings.set({ value: scallionProxyConfig(socks), scope: 'regular' }); + try { + await chrome.privacy.network.webRTCIPHandlingPolicy.set({ value: 'disable_non_proxied_udp' }); + } catch (_) { /* privacy controlled elsewhere */ } + await chrome.storage.local.set({ scallionEnabled: true }); + try { await chrome.storage.session.set({ scallionSession: true }); } catch (_) { /* no-op */ } + await setScallionBadge(true); +} + +async function disableScallion() { + // Same order as Tor: force 'system' first so a stopped client never leaves a + // dead fixed_servers proxy behind. + try { + await chrome.proxy.settings.set({ value: { mode: 'system' }, scope: 'regular' }); + } catch (_) { /* fall through to clear */ } + try { await chrome.proxy.settings.clear({ scope: 'regular' }); } catch (_) { /* already clear */ } + try { await chrome.privacy.network.webRTCIPHandlingPolicy.clear({}); } catch (_) { /* already clear */ } + await chrome.storage.local.set({ scallionEnabled: false }); + try { await chrome.storage.session.remove('scallionSession'); } catch (_) { /* no-op */ } + await setScallionBadge(false); +} + +async function checkScallion() { + try { + const ctrl = new AbortController(); + const t = setTimeout(() => ctrl.abort(), 20000); + const res = await fetch(SCALLION_CHECK_URL, { cache: 'no-store', signal: ctrl.signal }); + clearTimeout(t); + if (!res.ok) return { ok: false, error: `HTTP ${res.status}` }; + const data = await res.json(); + return { ok: true, ip: data.ip || data.ipv4 || data.ipv6 || null }; + } catch (e) { + return { ok: false, error: String((e && e.message) || e) }; + } +} + +chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => { + if (msg?.type === 'scallion-status') { + (async () => { + const { scallionEnabled } = await chrome.storage.local.get('scallionEnabled'); + sendResponse({ enabled: !!scallionEnabled, status: await scallionStatusViaHelper() }); + })(); + return true; + } + if (msg?.type === 'scallion-install') { + (async () => { + let st; + try { + st = await helperJson('/scallion/install', 'POST', 300000); + if (st && st.error === 'not-found') st = { error: 'helper-stale' }; + } catch (_) { + st = { error: 'unreachable' }; + } + sendResponse({ enabled: false, status: st }); + })(); + return true; + } + if (msg?.type === 'scallion-set') { + (async () => { + if (!msg.on) { + await disableScallion(); + await stopScallionViaHelper(); + sendResponse({ enabled: false, status: await scallionStatusViaHelper() }); + return; + } + const { torEnabled, pitEnabled } = await chrome.storage.local.get(['torEnabled', 'pitEnabled']); + if (torEnabled) { + sendResponse({ enabled: false, error: 'tor-on' }); + return; + } + let started; + try { + started = await helperJson('/scallion/start', 'POST', 45000); + } catch (_) { + started = { error: 'unreachable' }; + } + if (started && started.error === 'not-found') started = { error: 'helper-stale' }; + const socks = started && started.started && started.routing && started.ready + ? parseLoopbackSocks(started.socks) + : null; + if (!socks) { + sendResponse({ enabled: false, error: (started && started.error) || 'scallion-failed', status: started }); + return; + } + if (pitEnabled) { + await disablePit(); + await stopPitViaHelper(); + } + await enableScallion(socks); + const check = await checkScallion(); + if (!check.ok) { + // Never leave a dead proxy: back to normal browsing. + await disableScallion(); + await stopScallionViaHelper(); + sendResponse({ enabled: false, error: 'verify-failed', check, status: started }); + return; + } + sendResponse({ enabled: true, check, status: started }); + })(); + return true; + } +}); + // Tor and the pit default OFF on every fresh browser start — nobody is routed // anywhere unless they flip a toggle. chrome.storage.session is wiped on // browser restart, so it tells a fresh launch from a service-worker restart // mid-session. (async () => { try { - const { torSession, pitSession } = await chrome.storage.session.get(['torSession', 'pitSession']); + const { torSession, pitSession, scallionSession } = + await chrome.storage.session.get(['torSession', 'pitSession', 'scallionSession']); if (torSession) { // Same session, SW just restarted → keep Tor on (re-apply the proxy). await enableTor(); } else if (pitSession) { await enablePit(); + } else if (scallionSession) { + // Re-apply only while the helper still has routing cleared; otherwise + // fail closed back to normal browsing. + const st = await scallionStatusViaHelper(); + const socks = st && st.routing && st.ready ? parseLoopbackSocks(st.socks) : null; + if (socks) await enableScallion(socks); + else await disableScallion(); } else { // Fresh browser start. If local still says a toggle was on (carried over // from the last run), clear it + any persisted proxy. Otherwise leave the // proxy untouched. - const { torEnabled, pitEnabled } = await chrome.storage.local.get(['torEnabled', 'pitEnabled']); + const { torEnabled, pitEnabled, scallionEnabled } = + await chrome.storage.local.get(['torEnabled', 'pitEnabled', 'scallionEnabled']); if (torEnabled) await disableTor(); else if (pitEnabled) { await disablePit(); await stopPitViaHelper(); } + else if (scallionEnabled) { await disableScallion(); await stopScallionViaHelper(); } } } catch (_) { /* best effort */ } })(); diff --git a/apps/desktop/extensions/ai-sidebar/options.html b/apps/desktop/extensions/ai-sidebar/options.html index 8b936da..a43cba8 100644 --- a/apps/desktop/extensions/ai-sidebar/options.html +++ b/apps/desktop/extensions/ai-sidebar/options.html @@ -46,6 +46,15 @@ .pw-dialog button { border-radius:8px; padding:8px 14px; font:inherit; cursor:pointer; background:transparent; color:var(--fg); border:1px solid var(--line); } .pw-dialog button.primary { background:var(--cyan); color:#04060c; border:0; font-weight:700; } + .scl-box { border:1px solid var(--line); border-radius:10px; padding:12px 14px; margin-top:12px; } + .scl-title { font-weight:700; } + .scl-title.warn { color:#ffcf6b; } .scl-title.on { color:#a6ff1a; } + .scl-blockers { margin:8px 0 0; padding-left:18px; color:var(--muted); font-size:12px; } + .scl-toggle { display:flex; gap:8px; align-items:center; color:var(--fg); } + .scl-toggle input { width:auto; } + .scl-toggle:has(input:disabled) { opacity:.55; } + .scl-tail { background:#04060c; border:1px solid var(--line); border-radius:8px; padding:8px; + font-size:11px; max-height:220px; overflow:auto; white-space:pre-wrap; }
@@ -89,6 +98,33 @@moshcode dns enable installs.
+
+ Scallion is the onion-style relay network being built on
+ c0mpute. It is
+ experimental and unreviewed: no independent security review, no
+ multi-host or leak testing yet. It is off by default, and it is
+ not anonymity. TronBrowser only routes through it when the c0mpute CLI's own
+ check (c0mpute scallion doctor) says the Scallion client is ready and
+ a local Scallion SOCKS client is running; otherwise nothing changes. Like
+ 🧅 Tor and 🤘 Pit, only one of the three can be on at a time.
+
Runs
+ through TronBrowser's helper: the c0mpute CLI only, no worker service, nothing
+ started in the background.
Details: docs/scallion.md
+Sites send browser notifications through a push service the browser chooses. @@ -193,5 +229,6 @@