Compare commits

...
4 changed files with 162 additions and 2 deletions

No files matched your search

+70
View File
@@ -0,0 +1,70 @@
name: ocsp native hunt
on:
push:
branches: [hunt/ocsp-native-after-eof]
paths: [tests/_lab_pki.py, tests/_egress_sink.py, tests/test_nothing_of_a_context_leaves_but_through_its_proxy_e2e.py, .github/workflows/ocsp-native-hunt.yml]
env:
GITHUB_TOKEN: ${{ github.token }}
concurrency:
group: ocsp-native-hunt
cancel-in-progress: true
jobs:
hunt:
strategy:
fail-fast: false
max-parallel: 8
matrix:
os: [windows-2022, ubuntu-24.04]
delay: ['0']
runs-on: ${{ matrix.os }}
timeout-minutes: 75
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with: { fetch-depth: 1 }
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5
with: { python-version: '3.11' }
- name: Install
run: |
python -m pip install --upgrade pip
python -m pip install ".[dev]"
python -m pip install "playwright==$(cat scripts/playwright_pin.txt)"
- name: System deps (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update && sudo apt-get install -y xvfb iproute2
sudo "$(which python)" -m playwright install-deps firefox
- name: Fetch the published firefox binary
run: echo "FF=$(python -m invisible_playwright fetch | tail -1)" >> "$GITHUB_ENV"
- name: The GeoIP database
run: python scripts/ci_lab_geoip.py build
- name: "10 runs, a redirect a closed context still follows"
env:
HUNT_CLOSE: fast
HUNT_SECOND_DELAY: ${{ matrix.delay }}
MOZ_CRASHREPORTER_DISABLE: "1"
run: |
set +e +o pipefail
NODE='tests/test_nothing_of_a_context_leaves_but_through_its_proxy_e2e.py::test_hunt_a_redirect_a_closed_context_still_follows_is_resolved_through_its_proxy'
if [ "$RUNNER_OS" = "Linux" ]; then
sudo rm -rf /opt/ff && sudo cp -a "$(dirname "$FF")" /opt/ff && sudo chown -R root:root /opt/ff && sudo chmod -R go+rX /opt/ff
RUN="sudo -H -E env -u PYTEST_ADDOPTS -u XDG_RUNTIME_DIR INVPW_REQUIRE_TRAP=1 PATH=$PATH INVPW_BINARY_PATH=/opt/ff/$(basename "$FF") HUNT_CLOSE=$HUNT_CLOSE HUNT_SECOND_DELAY=$HUNT_SECOND_DELAY"
else
RUN="env INVPW_BINARY_PATH=$FF"
fi
for i in $(seq 1 10); do
out=$($RUN python -m pytest "$NODE" -m e2e -o addopts='' -q -p no:cacheprovider -p no:rerunfailures -s 2>&1 || true)
if echo "$out" | grep -qE "(^| )1 passed"; then verdict=pass; else verdict=FAIL; fi
hs=$(echo "$out" | grep -o "handshakes \[[^]]*\]" | head -1)
why=$(echo "$out" | grep -oE "AssertionError: [^(]{0,160}" | head -1)
echo "HUNTROW os=$RUNNER_OS delay=$HUNT_SECOND_DELAY rep=$i verdict=$verdict $hs $why"
echo "$out" | grep -E "^HUNT(CLOSE|LOG|STATE)" | sed "s/^/R$i /"
if [ "$verdict" = FAIL ] && [ -z "$why" ]; then echo "$out" | tail -25 | sed 's/^/HUNTOUT /'; fi
done
- name: Close every Firefox left
if: always()
run: |
if [ "$RUNNER_OS" = "Linux" ]; then sudo pkill -9 -f firefox || true; else taskkill //F //IM firefox.exe //T 2>/dev/null || true; fi
echo done
+1 -1
View File
@@ -29,7 +29,7 @@ import secrets
import sys
from typing import Callable, Dict, Iterable, List, Optional, Sequence
MOZ_LOG = "sync,nsHostResolver:5"
MOZ_LOG = "timestamp,sync,nsHostResolver:5" # hunt: timestamps
LOG_FILE_NAME = "moz-%PID.log"
_NATIVE = re.compile(r"Calling getaddrinfo for host \[([^\]]+)\]")
+16
View File
@@ -222,8 +222,24 @@ class TlsPage:
self.body = body
outer = self
drop = os.environ.get("HUNT_TLS_DROP", "none") # hunt only: none | first | alternate
seen = [0]
class Handler(http.server.BaseHTTPRequestHandler):
def setup(self):
seen[0] += 1
delay = float(os.environ.get("HUNT_SECOND_DELAY", "0") or 0)
if delay and seen[0] == 2:
import time as _t
_t.sleep(delay) # hunt: the second connection's flight (and its certificate) comes late
if drop == "alternate" and seen[0] % 2 == 1 or drop == "first" and seen[0] == 1:
outer.handshakes.append("dropped by the server before the handshake")
try:
self.request.recv(1) # the ClientHello has started to arrive
except OSError:
pass
self.request.close()
raise ConnectionAbortedError("hunt: dropped")
try:
self.request = context.wrap_socket(self.request, server_side=True)
outer.handshakes.append("ok")
@@ -63,6 +63,8 @@ import dataclasses
import os
from typing import Callable, Dict, Optional
import time
import pytest
from invisible_playwright import InvisiblePlaywright
@@ -664,9 +666,23 @@ def test_the_ocsp_request_of_a_trusted_page_leaves_only_through_the_proxy(
detail = "status=%s text=%r" % (response.status if response else None, page.evaluate("() => document.body.innerText")[:40])
except Exception as exc: # noqa: BLE001 - the message of the failed assertion below carries it
detail = "goto error: %s" % str(exc).splitlines()[0][:200]
reached = ds.wait_until(lambda: (address, ocsp_responder.port) in proxy.connects, EVIDENCE_SECONDS)
if os.environ.get("HUNT_CLOSE") == "fast":
reached = False
else:
reached = ds.wait_until(lambda: (address, ocsp_responder.port) in proxy.connects, EVIDENCE_SECONDS)
import datetime as _dt
print("HUNTCLOSE begin %s" % _dt.datetime.now(_dt.timezone.utc).strftime("%H:%M:%S.%f"))
context.close()
print("HUNTCLOSE end %s" % _dt.datetime.now(_dt.timezone.utc).strftime("%H:%M:%S.%f"))
if os.environ.get("HUNT_CLOSE") == "fast":
time.sleep(6)
reached = (address, ocsp_responder.port) in proxy.connects
watcher.stop()
from _egress_sink import _lines as _hunt_lines
for _l in _hunt_lines(engine_log):
if ocsp_name in _l or "stealth.contexts" in _l:
print("HUNTLOG " + _l.rstrip()[:300])
print("HUNTSTATE handshakes=%s reached=%s gateway_connects=%d" % (server.handshakes[:6], reached, len(proxy.connects)))
sink = EgressSink(lab.witness, watcher, engine_log, lab.nonce, trap)
why = (_why(doh, proxy) + "\n case ocsp-%s: page %s (%s), OCSP URL %s, responder at %s, handshakes %s"
@@ -738,3 +754,61 @@ def test_a_page_of_an_issuer_the_engine_does_not_trust_makes_no_ocsp_request(fir
assert ocsp_responder.requests == [], "an untrusted issuer made an OCSP request: %s" % ocsp_responder.requests
finally:
server.close()
# ------------------------------------------------------------------------------------- hunt: a lookup of a context that has closed
def test_hunt_a_redirect_a_closed_context_still_follows_is_resolved_through_its_proxy(firefox_binary, lab, doh, gateway, trap, watcher, engine_log):
"""HUNT ONLY. The page sends a beacon when it is hidden; the server answers it 2 s later with a redirect to ANOTHER name, so that name is
looked up after the context has closed. A context with a proxy keeps it for its requests in flight (GoneContexts); does its resolver too?"""
import datetime as _dt
import threading as _th
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
first, second = "beacon-%s.lab.test" % lab.nonce, "late-%s.lab.test" % lab.nonce
hits = []
class Handler(BaseHTTPRequestHandler):
def log_message(self, *a):
pass
def _answer(self):
hits.append((self.path, _dt.datetime.now(_dt.timezone.utc).strftime("%H:%M:%S.%f")))
if self.path.startswith("/page"):
body = ("<!doctype html><title>beacon</title><script>addEventListener('pagehide', () => "
"navigator.sendBeacon('http://%s:%d/c', 'x'));</script>" % (second, port)).encode()
self.send_response(200); self.send_header("Content-Type", "text/html"); self.send_header("Content-Length", str(len(body)))
self.end_headers(); self.wfile.write(body)
elif self.path.startswith("/b"):
time.sleep(2)
self.send_response(307); self.send_header("Location", "http://%s:%d/c" % (second, port))
self.send_header("Content-Length", "0"); self.end_headers()
else:
self.send_response(204); self.end_headers()
do_GET = do_POST = _answer
server = ThreadingHTTPServer(("127.0.0.1", 0), Handler)
port = server.server_address[1]
_th.Thread(target=server.serve_forever, daemon=True).start()
try:
doh.names[first] = "127.0.0.1"
doh.names[second] = "127.0.0.1"
proxy = gateway("gw-context")
with _launch(firefox_binary) as browser:
context = browser.new_context(proxy=proxy.proxy, ignore_https_errors=True)
page = context.new_page()
page.goto("http://%s:%d/page" % (first, port), wait_until="load", timeout=30000)
print("HUNTCLOSE begin %s" % _dt.datetime.now(_dt.timezone.utc).strftime("%H:%M:%S.%f"))
context.close()
print("HUNTCLOSE end %s" % _dt.datetime.now(_dt.timezone.utc).strftime("%H:%M:%S.%f"))
time.sleep(6)
watcher.stop()
from _egress_sink import _lines as _hunt_lines
for _l in _hunt_lines(engine_log):
if lab.nonce in _l and ("Resolving host" in _l or "effectiveTRRmode" in _l or "getaddrinfo" in _l):
print("HUNTLOG " + _l.rstrip()[:300])
print("HUNTSTATE hits=%s" % hits)
sink = EgressSink(lab.witness, watcher, engine_log, lab.nonce, trap)
assert any(h[0].startswith("/c") for h in hits), "the beacon to the new name never arrived: %s" % hits
assert sink.leak_problems() == [], "; ".join(sink.leak_problems())
finally:
server.shutdown()