diff --git a/installer/.crumb b/installer/.crumb index 520a2dc..804c4f0 100644 --- a/installer/.crumb +++ b/installer/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-11-06T22:14:11Z", + "compiled_at": "2026-11-06T22:39:36Z", "compiler": "crumb-compile/1", - "digest": "sha256:a651b7fc6fea79a67bd555fa723b964d5416161815a497056a7912f072cd29db", + "digest": "sha256:9b4fbfc49e16f2f1289d90ea3ec9670941a54d63bc12aca0277babfb7bd696de", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 127, - "generated_at_commit": "c7bdc6243dad584b80615df5410d4bd86ad4e625", - "source_tree": "sha256:25d6b97552179024ffb779f99d4ed9cb63061dd20ed959b89ff8f81431c1823f" + "generated_at_commit": "e398a893ce7b6ca34cd2f11abd967652b42ce65b", + "source_tree": "sha256:ea9f5c1c8fcb3a02b4662b36affd0c4e28da337ac64a1d408897cc687a3d8eda" } }, "invariants": [ diff --git a/installer/HOST-DEPENDENCIES.md b/installer/HOST-DEPENDENCIES.md index 079e182..91b5913 100644 --- a/installer/HOST-DEPENDENCIES.md +++ b/installer/HOST-DEPENDENCIES.md @@ -129,3 +129,10 @@ The programs it sequences, seen on 2026-11-06 (Ubuntu 24.04.5 arm64): - `AIENOS_BASE_URL`: where `install.sh` downloads from. The signature is still checked against the key inside `install.sh`, so another source cannot change what gets installed. - `AIENOS_NO_WIZARD=1`: `install.sh` does not offer to open the wizard. + +These addresses, and the `url` of a model manifest, must be `https://`, or plain `http://` to +this machine only: the host exactly `127.0.0.1`, `localhost` or `[::1]`, with an optional +`:PORT` (the test servers and `rig/fileserv.om`). Anything else (another host, a user part, +`127.1`, another scheme) is refused before any request: `install.sh` exits 2, the wizard's +download step shows why and keeps nothing, and the token check sends nothing. Every `curl` +download follows redirects to `https` only (`--proto-redir =https`). diff --git a/installer/install.sh b/installer/install.sh index eb95005..192cd4c 100755 --- a/installer/install.sh +++ b/installer/install.sh @@ -15,7 +15,8 @@ # # Exit status: 0 installed, or a friendly "not supported here" (nothing touched); # 1 a signature or checksum did not match (nothing installed); -# 2 a needed tool or the download is missing. +# 2 a needed tool or the download is missing, or AIENOS_BASE_URL is plain http to +# another machine (nothing downloaded). set -eu TAG=alpha-20261029.1 @@ -58,6 +59,33 @@ not_here() { exit 0 } +# 0. The download address, before anything else: https to any host, or plain http only to this +# machine (127.0.0.1, localhost or [::1], with an optional :PORT), as the test rig serves. The +# bundle is signature-checked either way; this keeps unencrypted downloads off the network. +url_ok() { + case $1 in + https://*) return 0 ;; + http://*) ;; + *) return 1 ;; + esac + auth=${1#http://} + auth=${auth%%/*} + for h in 127.0.0.1 localhost '[::1]'; do + [ "$auth" != "$h" ] || return 0 + port=${auth#"$h":} + [ "$port" != "$auth" ] || continue + case $port in ''|*[!0-9]*) return 1 ;; esac + [ ${#port} -le 5 ] + return + done + return 1 +} +url_ok "$BASE_URL" || { + say "AIENOS_BASE_URL must be https, or plain http to this machine (127.0.0.1, localhost or [::1]): $BASE_URL" + say "Nothing was downloaded." + exit 2 +} + # 1. The platform, before anything is downloaded. os=$(uname -s 2>/dev/null || echo unknown) arch=$(uname -m 2>/dev/null || echo unknown) @@ -100,8 +128,9 @@ stage= # A staging folder left by an error or Ctrl+C goes too (a power cut leaves it; the next run removes it). trap 'rm -rf "$tmp" ${stage:+"$stage"}' EXIT HUP INT TERM +# A redirect may only go to https (GitHub sends release assets on to its https download host). fetch() { - curl -fsSL --retry 3 --proto '=https,http' -o "$tmp/$1" "$BASE_URL/$1" \ + curl -fsSL --retry 3 --proto '=https,http' --proto-redir '=https' -o "$tmp/$1" "$BASE_URL/$1" \ || { say "Could not download $BASE_URL/$1"; exit 2; } } diff --git a/installer/rig/README.md b/installer/rig/README.md index 0bf3641..c801c66 100644 --- a/installer/rig/README.md +++ b/installer/rig/README.md @@ -49,8 +49,8 @@ on a GitHub-hosted runner. `sh installer/rig/e2e.sh --tag TAG --out OUT.jsonl` runs four steps on this machine: install (`git clone --branch TAG`, `install.sh`, then the plain wizard answered by `answer.sh`), -`aienos verify`, `aienos chat` (a non-empty `model>` line is also required, because chat exits 0 -after an engine error), and +`aienos verify`, `aienos chat` (it must exit 0, print no `request failed: N` line and print a +non-empty `model>` line; alpha-20261029.1 and earlier exit 0 even when a request failed), and `aienos uninstall --yes`. Every step runs even after a failure, so uninstall always runs. Each step writes one JSON line (schema `si-rig-e2e/2`): `step`, `mode` (`REAL`, `FAKE` or `FAKE-MODEL`), `evidence`, `release_tag`, `source_commit` (the commit installed), `account`, @@ -84,6 +84,10 @@ home; e2e.sh exits 1 when the user, its group or its home is still present (`OUT It needs passwordless sudo and keeps the run out of the caller's `$HOME`. Records say `account: disposable`, or `caller` without the option. +The JSON lines are unsigned: they are evidence that a run happened with the recorded inputs and +exit codes, not a tamper-proof record. Anyone who can write `OUT.jsonl` can change it, and +`evcheck` checks the records' fields and labels, not who wrote them. Signed receipts need DRA-156. + `sh installer/rig/answer.sh LOG CMD...` answers the plain wizard by its own prompts instead of a fixed count of newlines: the wizard asks one more question when it finds a model server already running in `/proc`, so a fixed string can put the wrong answer on the consent. In plain mode diff --git a/installer/rig/e2e.sh b/installer/rig/e2e.sh index 054b47b..fafd422 100755 --- a/installer/rig/e2e.sh +++ b/installer/rig/e2e.sh @@ -2,6 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # End-to-end harness for the SI Alpha test Spark (DRA-55): install -> verify -> chat -> uninstall, # one evidence record per step in OUT (JSONL, schema si-rig-e2e/2, checked by evcheck.om). +# The records are unsigned: evidence of a run, not a tamper-proof record (signing needs DRA-156). # sh installer/rig/e2e.sh --tag TAG --out OUT REAL release run of published TAG # sh installer/rig/e2e.sh --ref SHA --out OUT REAL prerelease run of commit SHA # sh installer/rig/e2e.sh --ref SHA --fake-model --out OUT FAKE-MODEL prerelease run of SHA @@ -275,14 +276,17 @@ else } fi s_verify() { "$as" "$aienos" verify; } - # chat exits 0 even after an engine error, so the step also needs a non-empty model> reply. With - # piped input chat's "you> " prompt has no newline after it, so the reply line starts with it. + # chat exits 1 when a request failed (an error status, a timeout, or a stream that ended without + # [DONE]); releases before that change exit 0 and print "request failed: N" after any partial + # reply, so the step checks the status, that line, and a non-empty model> reply. With piped + # input chat's "you> " prompt has no newline after it, so the reply line starts with it. s_chat() { rc=0 printf 'Reply with one short sentence.\n/bye\n' | "$as" timeout 900 "$aienos" chat > "$work/chat" 2>&1 || rc=$? cat "$work/chat" "$as" "$aienos" stop || true [ "$rc" = 0 ] || return "$rc" + ! grep -q 'request failed: ' "$work/chat" || { echo "e2e: chat request failed"; return 1; } grep -Eq '^(you> )*model> .*[^[:space:]]' "$work/chat" || { echo "e2e: no model> reply"; return 1; } } s_uninstall() { diff --git a/installer/tests/fake-engine.om b/installer/tests/fake-engine.om index cf485ce..6531084 100644 --- a/installer/tests/fake-engine.om +++ b/installer/tests/fake-engine.om @@ -5,6 +5,9 @@ note event stream (two content deltas, one with a JSON \u escape, then [DONE]). note device. It serves at most 64 connections, then exits. Like Core main's engine it refuses to note start without AIEN_SERVE_HTTP_BEARER_TOKEN and answers a POST without the exact header note "Authorization: Bearer " with 401. It logs one line per POST (never the token). +note Two failure modes for the chat negative controls: a POST whose text contains "cut-stream" +note gets the first content delta and then the closed connection (no [DONE]); one containing +note "fail-500" gets HTTP 500 with a JSON error. om2 global buf uchar 65536 @@ -20,6 +23,10 @@ text ev1 "data: {\"choices\":[{\"delta\":{\"role\":\"assistant\",\"content\":\"H text ev2 "data: {\"choices\":[{\"delta\":{\"content\":\", caf\\u00e9 \\\"ok\\\"\"}}]}" text ev3 "data: [DONE]" text okb "ok" +text r_500 "HTTP/1.0 500 Internal Server Error" +text r_e500 "{\"error\":{\"message\":\"test failure\",\"type\":\"server_error\"}}" +text k_cut "cut-stream" +text k_500 "fail-500" text k_env "AIEN_SERVE_HTTP_BEARER_TOKEN=" text h_auth "Authorization: Bearer " text m_noenv "fake-engine: AIEN_SERVE_HTTP_BEARER_TOKEN must be set to a nonempty private credential" @@ -105,6 +112,15 @@ end ret true end +note Does the request in buf[0..n) contain the text t? +fn hasmk t view uchar * n ulong to bool +nd = new uchar 320 0 +for i ulong len t +put nd i get t i +end +ret found nd len t n +end + fn sendt fd int t view uchar * to void r = send fd t 0 len t 0 end @@ -145,10 +161,20 @@ sendt fd r_err ret end say 1 m_ok +if hasmk k_500 ulong n +line fd r_500 +line fd r_json +crlf fd +sendt fd r_e500 +ret +end line fd r_ok crlf fd line fd ev1 crlf fd +if hasmk k_cut ulong n +ret +end s = sleepns 50000000 line fd ev2 crlf fd diff --git a/installer/tests/run.sh b/installer/tests/run.sh index a7af328..d7e6282 100755 --- a/installer/tests/run.sh +++ b/installer/tests/run.sh @@ -141,6 +141,47 @@ h=$(newhome a5) out=$(boot "$h" "$S/root-gb10" "http://127.0.0.1:$PORT/nosig" 2>&1); rc=$? [ $rc -eq 2 ] && [ ! -e "$h/.local/share/aienos/current" ]; verdict missing-signature-refused $? +# The download address. Plain http to another machine, and any other scheme, exits 2 before the +# platform check and before any download; https and plain http to 127.0.0.1, localhost or [::1] +# pass. A stand-in curl (with a Linux aarch64 uname) records each URL and fails with exit 7, so +# nothing goes on the network. 127.1 is this machine too, but not on the exact allow-list: with +# the real curl it is the control that would reach this suite's server if the check were missing. +mkdir -p "$S/bin-urls" +cat > "$S/bin-urls/curl" <> "$S/curl-urls" +exit 7 +EOF +printf '#!/bin/sh\ncase "$1" in -s) echo Linux ;; -m) echo aarch64 ;; esac\n' > "$S/bin-urls/uname" +chmod +x "$S/bin-urls/curl" "$S/bin-urls/uname" +n=0 +for u in http://203.0.113.7/real http://203.0.113.7:18733/real http://127.0.0.1@203.0.113.7/real \ + http://127.0.0.1.example.invalid/real http://localhost.example.invalid:80/real \ + 'http://[::1].example.invalid/real' http://127.0.0.1:/real http://127.0.0.1:123456/real \ + http://127.0.0.1:80x/real HTTP://203.0.113.7/real ftp://127.0.0.1/real file:///etc; do + n=$((n + 1)); h=$(newhome "a7-$n"); rm -f "$S/curl-urls"; before=$(requests) + out=$(boot "$h" "$S/root-gb10" "$u" "$S/bin-urls" 2>&1); rc=$? + printf '%s\n%s\n' "$u" "$out" > "$S/a7-$n.out" + [ $rc -eq 2 ] && printf '%s' "$out" | grep -q "must be https, or plain http to this machine" \ + && [ ! -e "$S/curl-urls" ] && [ -z "$(files "$h")" ] && [ "$(requests)" = "$before" ] + verdict "plain-http-refused-$n" $? +done +h=$(newhome a7-127-1); before=$(requests) +out=$(boot "$h" "$S/root-gb10" "http://127.1:$PORT/real" 2>&1); rc=$? +printf '%s\n' "$out" > "$S/a7-127-1.out" +[ $rc -eq 2 ] && printf '%s' "$out" | grep -q "must be https, or plain http to this machine" \ + && [ -z "$(files "$h")" ] && [ "$(requests)" = "$before" ]; verdict plain-http-127-1-sends-nothing $? +n=0 +for u in https://203.0.113.7/real http://127.0.0.1/real "http://127.0.0.1:$PORT/real" \ + "http://localhost:$PORT/real" "http://[::1]:$PORT/real"; do + n=$((n + 1)); h=$(newhome "a8-$n"); rm -f "$S/curl-urls" + out=$(boot "$h" "$S/root-gb10" "$u" "$S/bin-urls" 2>&1); rc=$? + printf '%s\n%s\n' "$u" "$out" > "$S/a8-$n.out" + [ $rc -eq 2 ] && printf '%s' "$out" | grep -qF "Could not download $u/SHA256SUMS" \ + && [ "$(cat "$S/curl-urls" 2>/dev/null)" = "$u/SHA256SUMS" ]; verdict "url-allowed-$n" $? +done + # install.sh logs its progress lines to install.log, and doctor --report carries them in logs.txt. h=$S/home-a2 grep -q "^Signature and SHA-256 match" "$h/.local/share/aienos/install.log" \ @@ -162,23 +203,33 @@ printf '%s\n' "$out" > "$S/a6.out" chmod +x "$S/fake-engine" head -c 5000000 /dev/urandom > "$S/www/model/weights.bin" printf '{"model_type":"test"}\n' > "$S/www/model/config.json" -tb=$S/tstage -rm -rf "$tb"; cp -a "$STAGE" "$tb" -install -m 755 "$S/fake-engine" "$tb/bin/aien-serve-http" -{ - printf 'name test-model\nurl http://127.0.0.1:%s/model/\n' "$PORT" - printf 'bytes %s\nfiles 2\n' "$(cat "$S/www/model/weights.bin" "$S/www/model/config.json" | wc -c | tr -d ' ')" - for f in config.json weights.bin; do - printf '%s %s %s\n' "$(sha256sum "$S/www/model/$f" | cut -d' ' -f1)" "$(wc -c < "$S/www/model/$f" | tr -d ' ')" "$f" - done -} > "$tb/share/aienos/model.manifest" -(cd "$tb" && find . -type f ! -name SHA256SUMS | sed 's|^\./||' | LC_ALL=C sort | xargs sha256sum > SHA256SUMS) -(cd "$tb" && tar -czf "$S/www/test/$BUNDLE" .) -testkey "$DIST/install.sh" > "$S/www/test/install.sh" -(cd "$S/www/test" && sha256sum "$BUNDLE" install.sh > SHA256SUMS \ - && openssl pkeyutl -sign -inkey "$S/test.key" -rawin -in SHA256SUMS -out SHA256SUMS.sig) -tboot() { env HOME="$1" AIENOS_PROBE_ROOT="$2" AIENOS_BASE_URL="http://127.0.0.1:$PORT/test" \ - AIENOS_NO_WIZARD=1 sh "$S/www/test/install.sh"; } +mktb() { # name model-url: stage tstage-NAME and publish it as www/NAME, its manifest naming model-url + tb=$S/tstage-$1 + rm -rf "$tb"; cp -a "$STAGE" "$tb" + install -m 755 "$S/fake-engine" "$tb/bin/aien-serve-http" + { + printf 'name test-model\nurl %s\n' "$2" + printf 'bytes %s\nfiles 2\n' "$(cat "$S/www/model/weights.bin" "$S/www/model/config.json" | wc -c | tr -d ' ')" + for f in config.json weights.bin; do + printf '%s %s %s\n' "$(sha256sum "$S/www/model/$f" | cut -d' ' -f1)" "$(wc -c < "$S/www/model/$f" | tr -d ' ')" "$f" + done + } > "$tb/share/aienos/model.manifest" + (cd "$tb" && find . -type f ! -name SHA256SUMS | sed 's|^\./||' | LC_ALL=C sort | xargs sha256sum > SHA256SUMS) + mkdir -p "$S/www/$1" + (cd "$tb" && tar -czf "$S/www/$1/$BUNDLE" .) + testkey "$DIST/install.sh" > "$S/www/$1/install.sh" + (cd "$S/www/$1" && sha256sum "$BUNDLE" install.sh > SHA256SUMS \ + && openssl pkeyutl -sign -inkey "$S/test.key" -rawin -in SHA256SUMS -out SHA256SUMS.sig) +} +# Model addresses for the wizard's download check: 127.1 (plain http, not on the allow-list), +# localhost (allowed) and [::1] (allowed; nothing listens there, so curl runs and fails). +mktb badurl "http://127.1:$PORT/model/" +mktb lhurl "http://localhost:$PORT/model/" +mktb v6url "http://[::1]:$PORT/model/" +mktb test "http://127.0.0.1:$PORT/model/" +tb=$S/tstage-test +tboot() { env HOME="$1" AIENOS_PROBE_ROOT="$2" AIENOS_BASE_URL="http://127.0.0.1:$PORT/${3:-test}" \ + AIENOS_NO_WIZARD=1 sh "$S/www/${3:-test}/install.sh"; } wiz() { # home probe-root input printf '%b' "$3" | env HOME="$1" AIENOS_PROBE_ROOT="$2" \ timeout 300 "$1/.local/share/aienos/current/bin/aienos" wizard --plain @@ -202,6 +253,16 @@ out=$(env HOME="$h" "$h/.local/share/aienos/current/bin/aienos" stop 2>&1); rc=$ out=$(printf 'second question\n/bye\n' | env HOME="$h" AIENOS_PROBE_ROOT="$S/root-gb10" \ "$h/.local/share/aienos/current/bin/aienos" chat 2>&1); rc=$? [ $rc -eq 0 ] && printf '%s' "$out" | grep -q "model> Hello from the fake engine"; verdict chat-command $? +# A request that fails exits 1 and says so: a stream cut before [DONE] (after one content delta, +# so a partial "model> Hello from the fake engine" line is printed, which a reply-only check would +# pass), and an HTTP 500. The good chat above is the positive control. +for k in cut-stream:-71 fail-500:500; do + out=$(printf 'please %s now\n/bye\n' "${k%%:*}" | env HOME="$h" AIENOS_PROBE_ROOT="$S/root-gb10" \ + "$h/.local/share/aienos/current/bin/aienos" chat 2>&1); rc=$? + printf '%s\n' "$out" > "$S/chat-${k%%:*}.out" + [ $rc -eq 1 ] && printf '%s' "$out" | grep -q "request failed: ${k#*:}\$"; verdict "chat-${k%%:*}-exits-1" $? +done +grep -q "model> Hello from the fake engine" "$S/chat-cut-stream.out"; verdict chat-cut-stream-shows-partial $? env HOME="$h" "$h/.local/share/aienos/current/bin/aienos" stop > /dev/null 2>&1 printf 'x' >> "$h/.local/share/aienos/current/share/aienos/wizard/hole.om" out=$(env HOME="$h" "$h/.local/share/aienos/current/bin/aienos" verify 2>&1); rc=$? @@ -241,6 +302,35 @@ printf '%s\n' "$out" > "$S/b4.out" [ $rc -eq 0 ] && grep -q "I am not starting the engine now" "$S/b4.out" \ && [ ! -e "$h/.local/share/aienos/engine.pid" ]; verdict busy-gpu-starts-no-engine $? +# The model address. Plain http to 127.1 (not on the allow-list): refused before curl runs, no +# request reaches the server, no download log, no model file. localhost is allowed and downloads. +# [::1] is allowed: curl runs (download log written) and fails, since the server is IPv4 only. +h=$(newhome b5) +tboot "$h" "$S/root-gb10" badurl > /dev/null 2>&1 +before=$(requests) +out=$(wiz "$h" "$S/root-gb10" "$ALL" 2>&1); rc=$? +printf '%s\n' "$out" > "$S/b5.out" +env HOME="$h" "$h/.local/share/aienos/current/bin/aienos" stop > /dev/null 2>&1 +m=$h/.local/share/aienos/models/test-model +[ $rc -eq 1 ] && grep -q "The model address is plain http to another machine" "$S/b5.out" \ + && [ "$(requests)" = "$before" ] && [ ! -e "$h/.local/share/aienos/download.log" ] \ + && [ -z "$(find "$m" -type f 2>/dev/null)" ]; verdict wizard-plain-http-refused $? +h=$(newhome b6) +tboot "$h" "$S/root-gb10" lhurl > /dev/null 2>&1 +out=$(wiz "$h" "$S/root-gb10" "$ALL" 2>&1); rc=$? +printf '%s\n' "$out" > "$S/b6.out" +env HOME="$h" "$h/.local/share/aienos/current/bin/aienos" stop > /dev/null 2>&1 +m=$h/.local/share/aienos/models/test-model +[ $rc -eq 0 ] && grep -q "Every model file is downloaded and matches its SHA-256" "$S/b6.out" \ + && cmp -s "$m/weights.bin" "$S/www/model/weights.bin"; verdict wizard-localhost-http-downloads $? +h=$(newhome b7) +tboot "$h" "$S/root-gb10" v6url > /dev/null 2>&1 +out=$(wiz "$h" "$S/root-gb10" "$ALL" 2>&1); rc=$? +printf '%s\n' "$out" > "$S/b7.out" +[ $rc -eq 1 ] && grep -q "The download or a hash check failed" "$S/b7.out" \ + && ! grep -q "plain http to another machine" "$S/b7.out" \ + && [ -e "$h/.local/share/aienos/download.log" ]; verdict wizard-ipv6-loopback-allowed $? + # Rollback to an older release folder, then uninstall keeping the model, then everything. h=$S/home-b1 cp -a "$h/.local/share/aienos/releases/$TAG" "$h/.local/share/aienos/releases/alpha-20261025.9" diff --git a/installer/wizard/main.om b/installer/wizard/main.om index 4bf39ef..0a2e7f3 100644 --- a/installer/wizard/main.om +++ b/installer/wizard/main.om @@ -702,6 +702,8 @@ end ret 1 end +note Exit 0 when every request answered with a complete reply (the stream's [DONE] after content), +note 1 when any request failed: an HTTP error, a cut stream, a timeout or no connection. fn cchat to int r = cstart if ne r 0 @@ -710,11 +712,15 @@ end emit n_chat1 putb 10 put hsn 0 0 +bad = false while true bound 100000 emit n_you w = flush n = rline if or lt n 0 ibis n_bye +if bad +ret 1 +end ret 0 end if gt get hsn 0 0 @@ -729,6 +735,7 @@ q = chatreq PORT putb 10 w = flush if ne q 0 +bad = true emit n_err snum q putb 10 @@ -742,6 +749,9 @@ end hstr j_end end end +if bad +ret 1 +end ret 0 end diff --git a/installer/wizard/models.om b/installer/wizard/models.om index 4b6d324..671fa47 100644 --- a/installer/wizard/models.om +++ b/installer/wizard/models.om @@ -811,7 +811,8 @@ pstr h_hdr pkpath end -note Ask huggingface.co who the header in hf.header.new belongs to. Returns the HTTP status or < 0. +note Ask huggingface.co who the header in hf.header.new belongs to. Returns the HTTP status or < 0 +note (-3, nothing sent, when AIENOS_HF_API is plain http to another machine: see pbsafe). fn tkchk to long pkclr if not findbin h_curl @@ -837,6 +838,9 @@ pclr pstr h_dapi end pstr h_who +if not pbsafe +ret -3 +end pkpath r = runcap if ne r 0 diff --git a/installer/wizard/steps.om b/installer/wizard/steps.om index d833430..26541bd 100644 --- a/installer/wizard/steps.om +++ b/installer/wizard/steps.om @@ -66,6 +66,15 @@ text c_5 "5" text c_c "-C" text c_dash "-" text c_o "-o" +text c_pr "--proto" +text c_prv "=https,http" +text c_prr "--proto-redir" +text c_prrv "=https" +text t_https "https://" +text t_http "http://" +text t_lo4 "127.0.0.1" +text t_lohn "localhost" +text t_lo6 "[::1]" text c_ua "--user-agent" text c_uav "aienos-wizard/alpha" text t_part ".part" @@ -79,6 +88,8 @@ text m_l5 "Every file is checked against its SHA-256 before it is used." text m_l6 "A cut connection resumes where it stopped. q is not read here; Ctrl+C stops." text m_fail "The download or a hash check failed. No unverified file will be used." text m_fail2 "Partial downloads were kept. Run aienos again to resume. The log is ~/.local/share/aienos/download.log." +text m_badu1 "The model address is plain http to another machine, so nothing was downloaded." +text m_badu2 "Only https is used, or plain http to this machine (127.0.0.1, ::1 or localhost)." text m_done "Every model file is downloaded and matches its SHA-256." text m_vbad1 "model file " text m_vbad2 " does not match its SHA-256; the next aienos run downloads it again" @@ -839,12 +850,19 @@ end note Run curl for URL base + PATH into pb + ".part", animating while it runs. Returns curl's status. fn fetch e ulong sz ulong to long pkclr +if not urlok +ret -3 +end if not findbin h_curl ret -2 end pkpath pkstr c_f pkstr c_s +pkstr c_pr +pkstr c_prv +pkstr c_prr +pkstr c_prrv pkstr c_r pkstr c_5 pkstr c_ua @@ -863,6 +881,84 @@ pstr t_curlog ret runbg sz end +note May the manifest's url be fetched? It is copied to pb (overwriting it) and checked by pbsafe. +fn urlok to bool +u = mkey m_url +ue = mfnl u +pclr +for i ulong sub ue u +pbyte get mf add u i +end +ret pbsafe +end + +note May the URL in pb be fetched, possibly with a token header? https to any host, or plain http +note only to this machine: the authority must be exactly 127.0.0.1, localhost or [::1], with an +note optional :PORT of 1..5 digits (no user part, no other name). Redirects are limited to https +note (--proto-redir), so a loopback server cannot send curl on to plain http elsewhere. +fn pbsafe to bool +n = get pbn 0 +if pbat 0 n t_https +ret true +end +if not pbat 0 n t_http +ret false +end +a = len t_http +ae = a +while lt ae n bound 4097 +if eq get pb ae 47 +break +end +ae = add ae 1 +end +if lbis a ae t_lo4 +ret true +end +if lbis a ae t_lohn +ret true +end +ret lbis a ae t_lo6 +end + +note Does pb[o..e) start with t? +fn pbat o ulong e ulong t view uchar * to bool +if gt add o len t e +ret false +end +for i ulong len t +if ne get pb add o i get t i +ret false +end +end +ret true +end + +note Is pb[a..ae) exactly host t, or t then ":" and 1..5 digits? +fn lbis a ulong ae ulong t view uchar * to bool +if not pbat a ae t +ret false +end +r = add a len t +if eq r ae +ret true +end +if ne get pb r 58 +ret false +end +n = sub ae add r 1 +if or eq n 0 gt n 5 +ret false +end +for i ulong n +c = get pb add add r 1 i +if or lt c 48 gt c 57 +ret false +end +end +ret true +end + note The URL: the manifest's url value, then PATH. fn pkurl e ulong to void u = mkey m_url @@ -984,6 +1080,16 @@ put ui 6 0 if not r pclear pc 4 +if not urlok +pl m_badu1 +pc 2 +pln +pl m_badu2 +prompt t_close +show +x = ask +ret false +end pl m_fail pc 2 pln