diff --git a/docs/proxy.md b/docs/proxy.md index 1aae0eb..520583f 100644 --- a/docs/proxy.md +++ b/docs/proxy.md @@ -1,6 +1,12 @@ ## Configuring your browser's proxy settings -We recommend installing **FoxyProxy** to manage your browser's proxies. +**If you use Nix**, you can launch a pre-configured browser (LibreWolf) with the proxy and certificate already set up: + +```sh +nix run github:anotherhadi/spilltea#browser{{if or (ne .Cfg.App.Host "127.0.0.1") (ne .Cfg.App.Port 8080) (ne .Cfg.App.CertDir "~/.local/share/spilltea")}} --{{end}}{{if ne .Cfg.App.Host "127.0.0.1"}} --host {{.Cfg.App.Host}}{{end}}{{if ne .Cfg.App.Port 8080}} --port {{.Cfg.App.Port}}{{end}}{{if ne .Cfg.App.CertDir "~/.local/share/spilltea"}} --cert-dir {{.Cfg.App.CertDir}}{{end}} +``` + +Otherwise, we recommend installing **FoxyProxy** to manage your browser's proxies. You can install it from the [Google Chrome extension store](https://chromewebstore.google.com/) or from the [Firefox extension store](https://addons.mozilla.org/en-US/firefox/extensions) 1. Open FoxyProxy's options, then click on `Add New Proxy` button. diff --git a/nix/browser.nix b/nix/browser.nix new file mode 100644 index 0000000..06474a7 --- /dev/null +++ b/nix/browser.nix @@ -0,0 +1,61 @@ +{pkgs}: let + defaultCertDir = "$HOME/.local/share/spilltea"; + defaultHost = "127.0.0.1"; + defaultPort = "8080"; +in + pkgs.writeShellApplication { + name = "spilltea-browser"; + runtimeInputs = with pkgs; [nss.tools librewolf netcat-gnu procps]; + text = '' + CERT_DIR="${defaultCertDir}" + HOST="${defaultHost}" + PORT="${defaultPort}" + + while [[ $# -gt 0 ]]; do + case "$1" in + --cert-dir) CERT_DIR="$2"; shift 2 ;; + --host) HOST="$2"; shift 2 ;; + --port) PORT="$2"; shift 2 ;; + *) echo "Unknown argument: $1"; exit 1 ;; + esac + done + + CERT_FILE="$CERT_DIR/mitmproxy-ca-cert.pem" + + if [[ ! -f "$CERT_FILE" ]]; then + echo "Certificate not found at $CERT_FILE" + echo "Launch spilltea first, or use --cert-dir if you changed cert_dir in your config." + exit 1 + fi + + if ! pgrep -x spilltea > /dev/null 2>&1; then + echo "spilltea is not running. Launch spilltea first." + exit 1 + fi + + if ! nc -z "$HOST" "$PORT" > /dev/null 2>&1; then + echo "Nothing is listening on $HOST:$PORT." + echo "Is spilltea configured on that port? Use --host and --port if you changed them in your config." + exit 1 + fi + + PROFILE=$(mktemp -d) + trap 'rm -rf "$PROFILE"' EXIT + + certutil -N -d sql:"$PROFILE" --empty-password + certutil -d sql:"$PROFILE" -A -n "spilltea" -t "CT,," -i "$CERT_FILE" + + cat > "$PROFILE/user.js" <