# The runtime of an installed toolchain, held to its installer's record. # # A link that injects hwjs_user_rt.bc re-keys the runtime's RT-PROVENANCE # sidecar against the kernel checkout it came from (BRINTIUM_KERNEL_SRC). An # installed tree, the wasm32 guest's, has no kernel checkout. Its installer # read the runtime where the kernel build left it and recorded it in # libexec/hwjs-installed.stamp, after the commit line: # # commit=<40 hex> # rt_sha256=<64 hex> the sha256 of the build/hwjs_user_rt.bc it installed # rt_provenance= the RT-PROVENANCE line of that runtime's .stamp # # With no BRINTIUM_KERNEL_SRC, a link holds the runtime to that record: the # same bytes and the same sidecar, or a refusal. A stamp without the two lines # is no record, and the link refuses as it does with no kernel checkout. # hwjs_rt_installed_record_v : 0 when carries both runtime # lines, with HWJS_RT_SHA256 and HWJS_RT_PROVENANCE set to their values; else 1. hwjs_rt_installed_record_v() { local _rir_k _rir_v HWJS_RT_SHA256="" HWJS_RT_PROVENANCE="" [[ -r "$1" ]] || return 1 while IFS='=' read -r _rir_k _rir_v || [[ -n "$_rir_k" ]]; do case "$_rir_k" in rt_sha256) HWJS_RT_SHA256="$_rir_v" ;; rt_provenance) HWJS_RT_PROVENANCE="$_rir_v" ;; esac done < "$1" [[ -n "$HWJS_RT_SHA256" && -n "$HWJS_RT_PROVENANCE" ]] } # hwjs_rt_installed_verify : return when # and its .stamp are what records (hwjs_rt_installed_record_v read # it); otherwise a FATAL on stderr, prefixed with , and exit 1. hwjs_rt_installed_verify() { local who="$1" rt="$2" rec="$3" have="" line="" [[ "$HWJS_RT_SHA256" =~ ^[0-9a-f]{64}$ && "$HWJS_RT_PROVENANCE" =~ ^RT-PROVENANCE\ commit=[0-9a-f]{40}\ dirty=0\ src=[0-9a-f]{64}\ srckey=[0-9a-f]{64}$ ]] || { echo "$who: FATAL (RT-PROVENANCE): $rec records the runtime as [rt_sha256=$HWJS_RT_SHA256] [rt_provenance=$HWJS_RT_PROVENANCE], which is not a sha256 and an RT-PROVENANCE line of a clean kernel build. Reinstall the toolchain." >&2 exit 1 } have="$(sha256sum 2>/dev/null < "$rt" | cut -c1-64)" || have="" [[ "$have" =~ ^[0-9a-f]{64}$ ]] || { echo "$who: FATAL (RT-PROVENANCE): cannot read the runtime $rt to hold it to $rec. Reinstall the toolchain." >&2 exit 1 } [[ "$have" == "$HWJS_RT_SHA256" ]] || { echo "$who: FATAL (RT-PROVENANCE): the runtime $rt is not the one this toolchain was installed with: its sha256 is $have, and $rec records rt_sha256=$HWJS_RT_SHA256. Reinstall the toolchain, or set WACKY_HWJS_RT to take a runtime verbatim, which is honoured and says on every link that its provenance is unverified." >&2 exit 1 } if [[ -r "$rt.stamp" ]]; then IFS= read -r line < "$rt.stamp" || true; fi [[ "$line" == "$HWJS_RT_PROVENANCE" ]] || { echo "$who: FATAL (RT-PROVENANCE): the sidecar $rt.stamp holds [$line], and $rec records the runtime's as [$HWJS_RT_PROVENANCE]. Reinstall the toolchain." >&2 exit 1 } }