Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/scripts/qemu_ck_recovery_test.sh # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / scripts / qemu_ck_recovery_test.sh` 125 lines ยท 6733 bytes Raw Blame History 1 #!/usr/bin/env bash 2 # SPDX-License-Identifier: Apache-2.0 3 # Copyright 2026 Drake Stapleton (AIEN / aien-dev) 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # CK gate M4_RECOVERY: C kernel Recovery Core (inspect / repair-degraded-peer / 18 # provision-identity, operator-authorised) under QEMU, one cold boot each. 19 # Oracle: scripts/qemu_recovery_test.sh (Rust). Contract section 6.2. 20 # Mode selection: contract K-7. The operator key is TEST-ONLY (0x0f x32). 21 # QEMU is not hardware. Run only through the heavy forge. Usage: [--mutant NAME] 22 set -uo pipefail 23 cd "$(dirname "${BASH_SOURCE[0]}")/.." 24 repo_root="$(pwd)" 25 gate_name=M4_RECOVERY 26 script_tag=qemu_ck_recovery 27 # shellcheck source=scripts/lib_ck_cont_qemu.sh 28 source scripts/lib_ck_cont_qemu.sh 29 cq_init "$@" 30 cq_build 31 [[ "${cq_mode}" == mutant ]] || cq_default_image_checks 32 cq_quiet_and_trap 33 [[ "${cq_mode}" == mutant || "${hw_ok}" == 1 ]] || fail=1 34 new_disk 35 36 test_key=$(printf '0f%.0s' $(seq 32)) 37 wrong_key=$(printf '0e%.0s' $(seq 32)) 38 zero=$(printf '00%.0s' $(seq 32)) 39 respond() { "${cont_tool}" respond "$1" "$2"; } 40 challenge_for() { sed -nE "s/^RECOVERY_CHALLENGE: action=$1 challenge=([0-9a-f]{64})\$/\1/p" "${work}/serial.txt" | tail -1; } 41 refused_unauth() { [[ -n "$(out '^RECOVERY_REFUSED \(Unauthorised\)$')" ]] && unchanged; } 42 b() { plan "$@"; boot; } # plan + boot 43 44 # Setup: provisioned store with memory, then a malformed inactive peer. 45 fresh_image; b 5 46 l=$(out '^CONTINUITY: PROVISIONED '); agent=$(agent_of "${l}") 47 [[ -n "${agent}" ]] || bad "setup: provision failed" 48 b 7 49 lm=$(out '^CONTINUITY: REMEMBERED '); memory=$(field memory "${lm}") 50 [[ -n "${memory}" ]] || bad "setup: remember failed" 51 good_image="${top}/good.img"; cp "${image}" "${good_image}" 52 "${cont_tool}" inject-peer "${image}" 4096 >/dev/null || bad "setup: inject-peer failed" 53 54 echo "=== 1. Degraded store ===" 55 b 9 56 if [[ -n "$(out '^RECOVERY_OPERATOR_KEY: TEST-ONLY$')" && \ 57 -n "$(out '^RECOVERY_CORE: ENTERED reason=Degraded\(Malformed\)$')" && \ 58 "$(agent_of "$(out '^RECOVERY_RECORD:')")" == "${agent}" ]] && unchanged; then 59 pass "88 inspection enters the Recovery Core (Degraded(Malformed)), same agent, writes nothing" 60 else bad "88 inspection: $(grep -E '^RECOVERY_' "${work}/serial.txt" | tr '\n' '|')"; fi 61 c_repair=$(challenge_for repair-degraded-peer) 62 [[ ${#c_repair} == 64 ]] || bad "88 no repair challenge offered" 63 good=$(respond "${test_key}" "${c_repair}") 64 flip="${good:0:63}$([[ "${good:63:1}" == 0 ]] && echo 1 || echo 0)" 65 i=0 66 for c in zero wrong_key wrong_challenge flipped_last_byte; do 67 case "${c}" in 68 zero) r="${zero}" ;; 69 wrong_key) r=$(respond "${wrong_key}" "${c_repair}") ;; 70 wrong_challenge) r=$(respond "${test_key}" "$(printf 'ff%.0s' $(seq 32))") ;; 71 flipped_last_byte) r="${flip}" ;; 72 esac 73 plan 10 "response=${r}"; boot 74 i=$(( i + 1 )) 75 if refused_unauth; then pass "88.${i} repair with ${c} response refused (Unauthorised), image unchanged" 76 else bad "88.${i} repair with ${c}: $(out '^RECOVERY_(ACTION|REFUSED)')"; fi 77 done 78 plan 10 "response=${good}"; boot 79 if [[ -n "$(out '^RECOVERY_ACTION: repair-degraded-peer DONE$')" ]] && ! unchanged; then pass "89 authorised repair done, image changed" 80 else bad "89 authorised repair: $(out '^RECOVERY_(ACTION|REFUSED)')"; fi 81 b 6; r=$(out '^CONTINUITY: RESUMED ') 82 if [[ "$(agent_of "${r}")" == "${agent}" && "$(field memory "${r}")" == "${memory}" ]]; then pass "89a after repair a cold boot resumes writable, same agent and memory" 83 else bad "89a resume after repair: '${r:-$(out '^CONTINUITY:')}'"; fi 84 plan 10 "response=${good}"; boot 85 if [[ -n "$(out '^RECOVERY_REFUSED \(NotApplicable\)$')" ]] && unchanged; then pass "89b replaying the repair authorisation on the healthy store: NotApplicable, image unchanged" 86 else bad "89b replay: $(out '^RECOVERY_(ACTION|REFUSED)')"; fi 87 88 echo "=== 2. Unprovisioned store ===" 89 fresh_image; b 1; b 9 90 if [[ -n "$(out '^RECOVERY_CORE: ENTERED reason=Unprovisioned$')" ]] && unchanged; then pass "90 unprovisioned store enters the Recovery Core" 91 else bad "90 inspection: $(grep -E '^RECOVERY_' "${work}/serial.txt" | tr '\n' '|')"; fi 92 c_prov=$(challenge_for provision-identity) 93 [[ ${#c_prov} == 64 ]] || bad "90 no provision challenge offered" 94 plan 11 "response=$(respond "${wrong_key}" "${c_prov}")"; boot 95 if refused_unauth; then pass "90a provisioning with the wrong key refused, image unchanged" 96 else bad "90a wrong key: $(out '^RECOVERY_(ACTION|REFUSED)')"; fi 97 plan 11 "response=$(respond "${test_key}" "${c_prov}")"; boot 98 da=$(out '^RECOVERY_ACTION: provision-identity DONE agent=[0-9a-f]{64}$'); pa=$(agent_of "${da}") 99 b 6; r=$(out '^CONTINUITY: RESUMED ') 100 if [[ -n "${pa}" && "$(agent_of "${r}")" == "${pa}" ]]; then pass "90b authorised provisioning done; a cold resume returns that agent" 101 else bad "90b provisioning: '${da}' resume '${r}'"; fi 102 103 echo "=== 3. Corrupted agent root (identity lost) ===" 104 cp "${good_image}" "${image}" 105 "${cont_tool}" corrupt-root "${image}" 4096 >/dev/null || bad "91 corrupt-root failed" 106 b 9 107 if [[ -n "$(out '^RECOVERY_CORE: ENTERED ')" && -z "$(out '^RECOVERY_CHALLENGE')" ]] && unchanged; then pass "91 corrupted root: Recovery Core entered, no challenge, image unchanged" 108 else bad "91 corrupt root: $(grep -E '^RECOVERY_' "${work}/serial.txt" | tr '\n' '|')"; fi 109 for m in 10 11; do 110 plan "${m}" "response=${zero}"; boot 111 if [[ -n "$(out '^RECOVERY_REFUSED ')" && -z "$(out '^RECOVERY_ACTION')" ]] && unchanged; then pass "91.m${m} mode ${m} with a forged response refused, nothing done, image unchanged" 112 else bad "91.m${m} forged response: $(out '^RECOVERY_(ACTION|REFUSED)')"; fi 113 done 114 b 6 115 if [[ -z "$(out '^CONTINUITY: (RESUMED|PROVISIONED)')" && -n "$(out '^CONTINUITY: ')" ]] && unchanged; then pass "91c normal boot after identity loss: no RESUMED/PROVISIONED ($(out '^CONTINUITY: ')), image unchanged" 116 else bad "91c identity loss resume: '$(out '^CONTINUITY: ')'"; fi 117 118 echo "rows ${rows_ok}/${rows}; M1 failures: ${m1_fail}" 119 if [[ "${cq_mode}" == mutant ]]; then 120 release_flag 121 if [[ "${fail}" == 0 ]]; then verdict SURVIVED; else verdict "KILLED (gate failed)"; fi 122 exit 0 123 fi 124 [[ "${hw_ok:-1}" == 1 && "${fail}" == 0 ]] && verdict PASS || verdict FAIL 125 [[ "${fail}" == 0 ]]