Skip to content

Commit c66b5b6

Browse files
committed
Merge remote-tracking branch 'JonathonHall-Purism/introduce_quiet_mode-diceware_STAGING' into JonathonHall-Purism_introduce_quiet_mode-diceware_STAGING
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
2 parents 9b8b815 + 96c7a7c commit c66b5b6

5 files changed

Lines changed: 57 additions & 85 deletions

File tree

initrd/bin/config-gui.sh

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,7 @@ while true; do
8080

8181
# Debugging option always available
8282
dynamic_config_options+=(
83-
'Z' " $(get_config_display_action "$CONFIG_DEBUG_OUTPUT") $CONFIG_BRAND_NAME debug and function tracing output"
84-
)
85-
86-
# Quiet option always available
87-
dynamic_config_options+=(
88-
'Q' " $(get_config_display_action "$CONFIG_QUIET_MODE") $CONFIG_BRAND_NAME quiet mode"
83+
'Z' " Configure $CONFIG_BRAND_NAME informational / debug output"
8984
)
9085

9186
[ "$CONFIG_FINALIZE_PLATFORM_LOCKING" = "y" ] && dynamic_config_options+=(
@@ -553,52 +548,34 @@ while true; do
553548
fi
554549
;;
555550
"Z")
556-
if [ "$CONFIG_DEBUG_OUTPUT" != "y" ]; then
557-
if (whiptail --title 'Enable Debugging and Tracing output?' \
558-
--yesno "This will enable DEBUG and TRACE output from scripts.\n\nDo you want to proceed?" 0 80); then
559-
560-
set_user_config "CONFIG_DEBUG_OUTPUT" "y"
561-
set_user_config "CONFIG_ENABLE_FUNCTION_TRACING_OUTPUT" "y"
562-
#DEBUG+TRACE is incompatible with QUIET mode, turn it off
563-
set_user_config "CONFIG_QUIET_MODE" "n"
564-
565-
whiptail --title 'Config change successful' \
566-
--msgbox "Debugging and Tracing output enabled;\nsave the config change and reboot for it to go into effect." 0 80
567-
fi
568-
else
569-
if (whiptail --title 'Disable Enable Debugging and Tracing output?' \
570-
--yesno "This will disable DEBUG and TRACE output from scripts.\n\nDo you want to proceed?" 0 80); then
551+
unset output_choice
552+
whiptail_type $BG_COLOR_MAIN_MENU --title "Informational / Debug Output" \
553+
--menu "$CONFIG_BRAND_NAME can display informational or debug output.\n\nChoose the output level:" 0 80 10 \
554+
0 'None - Show no extra output' \
555+
1 "Info - Show information about operations in $CONFIG_BRAND_NAME" \
556+
2 "Debug - Show detailed information suitable for debugging $CONFIG_BRAND_NAME" \
557+
2>/tmp/whiptail || recovery "GUI menu failed"
571558

559+
output_choice=$(cat /tmp/whiptail)
560+
case "$output_choice" in
561+
0)
572562
set_user_config "CONFIG_DEBUG_OUTPUT" "n"
573563
set_user_config "CONFIG_ENABLE_FUNCTION_TRACING_OUTPUT" "n"
574-
575-
whiptail --title 'Config change successful' \
576-
--msgbox "Debugging and Tracing output disabled;\nsave the config change and reboot for it to go into effect." 0 80
577-
fi
578-
fi
579-
;;
580-
"Q")
581-
#Quiet mode: turn off/on console technical output
582-
if [ "$CONFIG_QUIET_MODE" != "y" ]; then
583-
if (whiptail --title 'Enable Quiet mode?' \
584-
--yesno "This will enable QUIET mode, which will turn off console technical output.\n\nDo you want to proceed?" 0 80); then
585-
586564
set_user_config "CONFIG_QUIET_MODE" "y"
587-
#DEBUG+TRACE is incompatible with QUIET mode, turn it off
565+
;;
566+
1)
588567
set_user_config "CONFIG_DEBUG_OUTPUT" "n"
589568
set_user_config "CONFIG_ENABLE_FUNCTION_TRACING_OUTPUT" "n"
590-
whiptail --title 'Config change successful' \
591-
--msgbox "Quiet mode enabled;\nsave the config change and reboot for it to go into effect." 0 80
592-
fi
593-
else
594-
if (whiptail --title 'Disable Quiet mode?' \
595-
--yesno "This will disable QUIET mode, which will turn on console technical output.\n\nDo you want to proceed?" 0 80); then
596-
597569
set_user_config "CONFIG_QUIET_MODE" "n"
598-
whiptail --title 'Config change successful' \
599-
--msgbox "Quiet mode disabled;\nsave the config change and reboot for it to go into effect." 0 80
600-
fi
601-
fi
570+
;;
571+
2)
572+
set_user_config "CONFIG_DEBUG_OUTPUT" "y"
573+
set_user_config "CONFIG_ENABLE_FUNCTION_TRACING_OUTPUT" "y"
574+
set_user_config "CONFIG_QUIET_MODE" "n"
575+
;;
576+
esac
577+
whiptail --title 'Config change successful' \
578+
--msgbox "Output level changed.\nSave the config change and reboot for it to go into effect." 0 80
602579
;;
603580
esac
604581
done

initrd/bin/seal-totp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ tpmr seal "$TOTP_SECRET" "$TPM_NVRAM_SPACE" 0,1,2,3,4,7 "$pcrf" 312 "" "$TPM_PAS
5555
shred -n 10 -z -u "$TOTP_SEALED" 2>/dev/null
5656

5757
url="otpauth://totp/$HOST?secret=$secret"
58-
secret=""
5958

6059
DEBUG "TOTP secret output on screen (both URL and QR code)"
6160
qrenc "$url"
6261

63-
echo "TOTP secret for manual input (if no mobile phone) is after the 'secret=' part of the URL:"
64-
echo "$url"
62+
echo "TOTP secret for manual input (device without camera): $secret"
63+
secret=""

initrd/bin/tpmr

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -611,16 +611,9 @@ tpm2_unseal() {
611611
fi
612612

613613
# tpm2 unseal will write the unsealed data to stdout and any errors to
614-
# stderr. We capture the unsealed data to $file, but still log the errors for quiet mode.
615-
# In case of unseal error, caller will also report on TOTP not being able to be unsealed.
616-
TMP_ERR_FILE=$(mktemp)
614+
# stderr; capture stderr to log.
617615
if ! tpm2 unseal -Q -c "$handle" -p "session:$POLICY_SESSION$UNSEAL_PASS_SUFFIX" \
618-
-S "$ENC_SESSION_FILE" >"$file" 2>"$TMP_ERR_FILE"; then
619-
# Log the contents of the temporary error file
620-
while IFS= read -r line; do
621-
LOG "tpm2 stderr: $line"
622-
done <"$TMP_ERR_FILE"
623-
rm -f "$TMP_ERR_FILE"
616+
-S "$ENC_SESSION_FILE" >"$file" 2> >(SINK_LOG "tpm2 stderr"); then
624617
LOG "Unable to unseal secret from TPM NVRAM"
625618

626619
# should succeed, exit if it doesn't
@@ -672,15 +665,15 @@ tpm2_reset() {
672665
# output TPM Owner Password to a file to be reused in this boot session until recovery shell/reboot
673666
DEBUG "Caching TPM Owner Password to $SECRET_DIR/tpm_owner_password"
674667
echo -n "$tpm_owner_password" >"$SECRET_DIR/tpm_owner_password"
675-
tpm2 clear -c platform >/dev/null 2>&1 || LOG "Unable to clear TPM on platform hierarchy"
676-
tpm2 changeauth -c owner "$(tpm2_password_hex "$tpm_owner_password")" >/dev/null 2>&1 || LOG "Unable to change owner password"
677-
tpm2 changeauth -c endorsement "$(tpm2_password_hex "$tpm_owner_password")" >/dev/null 2>&1 || LOG "Unable to change endorsement password"
678-
tpm2 createprimary -C owner -g sha256 -G "${CONFIG_PRIMARY_KEY_TYPE:-rsa}" \
679-
-c "$SECRET_DIR/primary.ctx" -P "$(tpm2_password_hex "$tpm_owner_password")" >/dev/null 2>&1 || LOG "Unable to create primary key"
680-
tpm2 evictcontrol -C owner -c "$SECRET_DIR/primary.ctx" "$PRIMARY_HANDLE" \
681-
-P "$(tpm2_password_hex "$tpm_owner_password")" >/dev/null 2>&1 || LOG "Unable to evict primary key"
682-
shred -u "$SECRET_DIR/primary.ctx" >/dev/null 2>&1
683-
tpm2_startsession >/dev/null 2>&1 || LOG "Unable to start session"
668+
DO_WITH_DEBUG tpm2 clear -c platform &>/dev/null
669+
DO_WITH_DEBUG tpm2 changeauth -c owner "$(tpm2_password_hex "$tpm_owner_password")" &>/dev/null
670+
DO_WITH_DEBUG tpm2 changeauth -c endorsement "$(tpm2_password_hex "$tpm_owner_password")" &>/dev/null
671+
DO_WITH_DEBUG tpm2 createprimary -C owner -g sha256 -G "${CONFIG_PRIMARY_KEY_TYPE:-rsa}" \
672+
-c "$SECRET_DIR/primary.ctx" -P "$(tpm2_password_hex "$tpm_owner_password")" &>/dev/null
673+
DO_WITH_DEBUG tpm2 evictcontrol -C owner -c "$SECRET_DIR/primary.ctx" "$PRIMARY_HANDLE" \
674+
-P "$(tpm2_password_hex "$tpm_owner_password")" &>/dev/null
675+
shred -u "$SECRET_DIR/primary.ctx" &>/dev/null
676+
DO_WITH_DEBUG tpm2_startsession &>/dev/null
684677

685678
# Set the dictionary attack parameters. TPM2 defaults vary widely, we
686679
# want consistent behavior on any TPM.
@@ -722,17 +715,17 @@ tpm1_reset() {
722715
DEBUG "Caching TPM Owner Password to $SECRET_DIR/tpm_owner_password"
723716
echo -n "$tpm_owner_password" >"$SECRET_DIR/tpm_owner_password"
724717
# Make sure the TPM is ready to be reset
725-
tpm physicalpresence -s >/dev/null 2>&1 || LOG "Unable to assert physical presence"
726-
tpm physicalenable >/dev/null 2>&1 || LOG "Unable to enable TPM"
727-
tpm physicalsetdeactivated -c >/dev/null 2>&1 || LOG "Unable to deactivate TPM"
728-
tpm forceclear >/dev/null 2>&1 || LOG "Unable to clear TPM"
729-
tpm physicalenable >/dev/null 2>&1 || LOG "Unable to enable TPM"
730-
tpm takeown -pwdo "$tpm_owner_password" >/dev/null 2>&1 || LOG "Unable to take ownership of TPM"
718+
DO_WITH_DEBUG tpm physicalpresence -s &>/dev/null
719+
DO_WITH_DEBUG tpm physicalenable &>/dev/null
720+
DO_WITH_DEBUG tpm physicalsetdeactivated -c &>/dev/null
721+
DO_WITH_DEBUG tpm forceclear &>/dev/null
722+
DO_WITH_DEBUG tpm physicalenable &>/dev/null
723+
DO_WITH_DEBUG tpm takeown -pwdo "$tpm_owner_password" &>/dev/null
731724

732725
# And now turn it all back on
733-
tpm physicalpresence -s >/dev/null 2>&1 || LOG "Unable to assert physical presence"
734-
tpm physicalenable >/dev/null 2>&1 || LOG "Unable to enable TPM"
735-
tpm physicalsetdeactivated -c >/dev/null 2>&1 || LOG "Unable to deactivate TPM physical presence requirement"
726+
DO_WITH_DEBUG tpm physicalpresence -s &>/dev/null
727+
DO_WITH_DEBUG tpm physicalenable &>/dev/null
728+
DO_WITH_DEBUG tpm physicalsetdeactivated -c &>/dev/null
736729
}
737730

738731
# Perform final cleanup before boot and lock the platform heirarchy.
@@ -810,13 +803,9 @@ if [ "$CONFIG_TPM2_TOOLS" != "y" ]; then
810803
TRACE_FUNC
811804
LOG "TPM: Extending PCR[$3] with hash $hash"
812805

813-
# Redirect the output of DO_WITH_DEBUG to a temporary file so we can LOG it in quiet mode
814-
TMP_DEBUG_FILE=$(mktemp)
815-
DO_WITH_DEBUG exec tpm "$@" >"$TMP_DEBUG_FILE" 2>&1
816-
while IFS= read -r line; do
817-
LOG "$line"
818-
done <"$TMP_DEBUG_FILE"
819-
rm -f "$TMP_DEBUG_FILE"
806+
# Silence stdout/stderr, they're only useful for debugging
807+
# and DO_WITH_DEBUG captures them
808+
DO_WITH_DEBUG exec tpm "$@" &>/dev/null
820809
;;
821810
seal)
822811
shift

initrd/etc/functions

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,15 @@ mask_param() {
402402
#
403403
# For example:
404404
# ls /boot/vmlinux* | SINK_LOG "/boot kernels"
405+
#
406+
# To capture stderr:
407+
# cryptsetup open /dev/sda1 media-crypt 2> >(SINK_LOG "LUKS unlock sda1 errors")
408+
# (Note: the space between '>' is necessary in '2> >(SINK_LOG ...)')
409+
#
410+
# To capture both:
411+
# tpm reset > >(SINK_LOG "tpm reset") 2>&1
412+
# (Note: 2>&1 must follow the stdout redirection, and space between '>' is
413+
# necessary)
405414
SINK_LOG() {
406415
local name="$1"
407416
local line haveblank
@@ -413,7 +422,7 @@ SINK_LOG() {
413422
cat
414423
echo
415424
) | while IFS= read -r line; do
416-
[[ -n "$haveblank" ]] && DEBUG "$name: " # Emit buffered blank line
425+
[[ -n "$haveblank" ]] && LOG "$name: " # Emit buffered blank line
417426
if [[ -z "$line" ]]; then
418427
haveblank=y
419428
else

initrd/init

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#! /bin/bash
2-
# Note this is used on legacy-flash boards that lack bash, it runs with busybox
3-
# ash. Calls to bash scripts must be guarded by checking config.
42

53
mknod /dev/ttyprintk c 5 3
64
echo "hello world" >/dev/ttyprintk

0 commit comments

Comments
 (0)