From fdaface79f5ef07265a6e6ed54cca111900e0638 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 23 Nov 2023 07:50:41 +0100 Subject: [PATCH] probe: use fallback password hash also for qeneth (regression tests) Break fallback hash to a separate function and allow gen_qemu_system_file() to return the status. We'd like to update the qeneth templates to include the same VPD data as is used with qemu.sh, but for now this is sufficient. The Qemu detection has been changed to the, slightly more, secure detection of qemu_fw_cfg filesystem. Signed-off-by: Joachim Wiberg --- board/common/rootfs/lib/infix/probe | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/board/common/rootfs/lib/infix/probe b/board/common/rootfs/lib/infix/probe index a324c729..726af7e7 100755 --- a/board/common/rootfs/lib/infix/probe +++ b/board/common/rootfs/lib/infix/probe @@ -2,13 +2,21 @@ # Probe for various types of harware features #TODO Rewrite this script in python before extending it further -#TODO Remove fallback temporary development hash +#TODO Remove fallback temporary development hash for real hw -gen_qemu_system_file() { +# Fallback for Qemu system, clear text pass: admin +gen_fallback_hash() +{ + # shellcheck disable=SC2016 + echo '{"pwhash": "$5$n2xoZAmITmPYjOTO$pbWHoa1Mu25a0e.akViAf9uWRvUgbq9BbcmzWWaNP0A"}' > /run/system.json +} + +gen_qemu_system_file() +{ vbd_json="$(onieprom /sys/firmware/qemu_fw_cfg/by_name/opt/vbd/raw)" if [ $? -ne 0 ]; then logger -p user.crit -t "probe" "Error, running onieprom tool" - exit 1 + return 1 fi pwhash="$(echo "$vbd_json" | jq -r '.["vendor-extension"][0][1]' | jq -r '.pwhash')" @@ -20,16 +28,19 @@ gen_qemu_system_file() { system_json="$(echo "$vbd_json" | jq -r 'del(."vendor-extension")')" system_json="$(echo "$system_json" | jq --arg val "$pwhash" '. += {"pwhash": $val}')" echo "$system_json" > /run/system.json + + return 0 } -if dmesg | grep -q QEMU || test -d /sys/module/qemu_fw_cfg; then +if [ -f /sys/firmware/qemu_fw_cfg/rev ]; then initctl cond set qemu - gen_qemu_system_file + # NOTE: eventually we want to remove this fallback too, but it needs a bit + # more work, e.g. new qeneth template, to roll out. + gen_qemu_system_file || gen_fallback_hash else # NOTE: All this code will soon go away. echo -e "\n\n\e[31mWARNING! Probe failed to get password hash from hardware\n" \ "Falling back to temporary hash\e[0m\n" > /dev/console - # Clear Test = admin - echo '{"pwhash": "$5$n2xoZAmITmPYjOTO$pbWHoa1Mu25a0e.akViAf9uWRvUgbq9BbcmzWWaNP0A"}' > /run/system.json -fi + gen_fallback_hash +fi