Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Buildroot/board/FOG/FOS/rootfs_overlay/bin/fog.enrollsb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ sbEnroll handleError
# outcome is sbEnroll's own -- "mok" for a staged request is what stops the
# server recording a machine as enrolled when a human has yet to confirm it.
sbReport "$sbOutcome" "$sbFingerprint"
. /bin/fog.nonimgcomplete
# Started from the PXE menu, not scheduled: there is no task to complete.
if [[ $sbNoTask -eq 1 ]]; then
echo " * Task Complete"
else
. /bin/fog.nonimgcomplete
fi
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,20 @@ sbCertFingerprint() {
# handleError and never fails the task; it says what it did and moves on. The
# record is a convenience for the administrator, not a step in the enrollment.
#
# The PXE menu item "Enroll Secure Boot Key (Unattended)" boots this same task
# with no task scheduled. The server then answers notasking (or unknownhost for
# a machine never registered). That answer sets $sbNoTask=1, so the caller
# skips fog.nonimgcomplete: with no task there is nothing to complete, and
# Post_Wipe.php would answer "No Active Task found" eleven times and then fail
# a task that enrolled correctly (forum topic 18307).
#
# $1 the result: db, trusted or mok
# $2 the certificate's SHA-256 fingerprint
sbReport() {
local result="$1"
local cert="$2"
local mactosend="${mac}"
sbNoTask=0
[[ -z $result || -z $cert ]] && return 0
[[ -z $web ]] && return 0
[[ -z $mactosend ]] && return 0
Expand All @@ -193,6 +201,13 @@ sbReport() {
callServer "${web}service/secureboot.report.php" \
"mac=${mactosend}&result=${result}&cert=${cert}&sbstate=$(sbState)"
[[ $serverBody == "##ok" ]] && return 0
# Started from the PXE menu: no task exists, so the server keeps no record.
if [[ $serverBody == "##notasking" || $serverBody == "##unknownhost" ]]; then
sbNoTask=1
echo " * Note: no Enroll Secure Boot task is scheduled for this machine,"
echo " so the FOG server keeps no record of this enrollment."
return 0
fi
# Said out loud rather than swallowed. It is not a failure of the
# enrollment, and the wording has to make that clear, or the next person
# reads it as one and goes looking at firmware that is perfectly fine.
Expand Down
50 changes: 48 additions & 2 deletions tests/checks/secureboot-enrollment-report.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ drive() {
web="http://fog.example/fog/"
mac="00:11:22:33:44:55"
sbReport "$@"
printf '\nRC=%s\n' "$?"
printf '\nRC=%s\nNOTASK=%s\n' "$?" "$sbNoTask"
)
}

Expand Down Expand Up @@ -150,7 +150,7 @@ done
# perfectly fine, so the message has to name the RECORDING as the thing that
# did not happen.
for arm in "unreachable:FAKE_CURL_RC=7" "http404:FAKE_CODE=404" \
"emptybody:FAKE_CODE=200 FAKE_BODY=" "wrongbody:FAKE_CODE=200 FAKE_BODY=##notasking"; do
"emptybody:FAKE_CODE=200 FAKE_BODY=" "wrongbody:FAKE_CODE=200 FAKE_BODY=##badresult"; do
name=${arm%%:*}
env=${arm#*:}
rm -f "$SANDBOX/curl.argv"
Expand Down Expand Up @@ -223,6 +223,52 @@ done < <(grep -n '^[[:space:]]*\(sbReport \|\. /bin/fog\.nonimgcomplete\)' \
"$REPO_BIN/fog.enrollsb" | sed 's/:[[:space:]]*/ /')
note "12. each exit reports before completing the task" "$err"

# --- 13. no task on the server sets sbNoTask, and only that does -----------
# The PXE menu item boots this task with nothing scheduled. The endpoint then
# answers notasking (unknownhost for a machine never registered). That answer,
# and no other, tells fog.enrollsb to skip fog.nonimgcomplete (forum 18307).
for arm in "notasking:##notasking:1" "unknownhost:##unknownhost:1" \
"ok:##ok:0" "badresult:##badresult:0"; do
IFS=: read -r name body want <<<"$arm"
out=$(FAKE_CODE=200 FAKE_BODY="$body" drive 'db' 'AA:BB')
err=""
[[ $out == *"RC=0"* ]] || err="rc not 0"
[[ $out == *"NOTASK=$want"* ]] || err="$err; sbNoTask is not $want"
if [[ $want == 1 ]]; then
grep -qi 'could not be recorded' <<<"$out" && err="$err; reads as a recording failure"
grep -qi 'no Enroll Secure Boot task' <<<"$out" || err="$err; does not say no task exists"
fi
note "13. $name: sbNoTask=$want" "$err"
done

# --- 14. fog.enrollsb completes the task only when one exists --------------
# Runs the real task script against stubs: sbReport sets sbNoTask from the
# environment, and fog.nonimgcomplete only leaves a marker.
cat > "$SANDBOX/stub-lib.sh" <<'EOF'
clearScreen() { :; }
displayBanner() { :; }
handleError() { echo "HANDLEERROR $*"; exit 1; }
sbEnroll() { sbOutcome=db; sbFingerprint=AA:BB; }
sbReport() { sbNoTask=$FAKE_NOTASK; }
EOF
echo 'echo COMPLETED' > "$SANDBOX/nonimgcomplete"
sed -e "s#^\. /usr/share/fog/lib/funcs\.sh#. $SANDBOX/stub-lib.sh#" \
-e "s#^\. /usr/share/fog/lib/secureboot-funcs\.sh#:#" \
-e "s#\. /bin/fog\.nonimgcomplete#. $SANDBOX/nonimgcomplete#" \
"$REPO_BIN/fog.enrollsb" > "$SANDBOX/fog.enrollsb"
for arm in "0:completes" "1:skips"; do
want=${arm%%:*}
out=$(FAKE_NOTASK=$want bash "$SANDBOX/fog.enrollsb" 2>&1)
err=""
if [[ $want == 1 ]]; then
grep -q COMPLETED <<<"$out" && err="ran fog.nonimgcomplete with no task"
grep -q 'Task Complete' <<<"$out" || err="$err; says nothing at the end"
else
grep -q COMPLETED <<<"$out" || err="did not complete the scheduled task"
fi
note "14. sbNoTask=$want: the task script ${arm#*:} fog.nonimgcomplete" "$err"
done

echo "----"
echo "$PASS passed, $FAIL failed"
[[ $FAIL -eq 0 ]] || exit 1
Loading