Skip to content

Commit f475296

Browse files
committed
codebase: unify all 'read' prompts to add -r, so that backslackes in answers are escaped prior of being put in variable (remove TODO)
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent c43af60 commit f475296

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed

initrd/bin/kexec-boot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ DO_WITH_DEBUG eval "$kexeccmd" 2>/dev/null \
158158

159159
if [ "$CONFIG_DEBUG_OUTPUT" = "y" ];then
160160
#Ask user if they want to continue booting without echoing back the input (-s)
161-
read -s -n 1 -p "[DEBUG] Continue booting? [Y/n]: " debug_boot_confirm
161+
read -r -s -n 1 -p "[DEBUG] Continue booting? [Y/n]: " debug_boot_confirm
162162
echo
163163
if [ "${debug_boot_confirm^^}" = N ]; then
164164
# abort

initrd/bin/kexec-seal-key

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ attempts=0
6969

7070
# Ask for the DRK passphrase first, before testing any devices
7171
while [ $attempts -lt 3 ] && [ $luks_drk_passphrase_valid -eq 0 ]; do
72-
read -s -p $'\nEnter LUKS Disk Recovery Key (DRK) passphrase that can unlock '"$key_devices"': ' disk_recovery_key_passphrase
72+
read -r -s -p $'\nEnter LUKS Disk Recovery Key (DRK) passphrase that can unlock '"$key_devices"': ' disk_recovery_key_passphrase
7373
echo -n "$disk_recovery_key_passphrase" >"$DISK_RECOVERY_KEY_FILE"
7474

7575
# Test the passphrase against ALL devices before deciding if it's valid
@@ -102,14 +102,14 @@ done
102102
MIN_PASSPHRASE_LENGTH=12
103103
attempts=0
104104
while [ $attempts -lt 3 ]; do
105-
read -s -p $'\nNew LUKS TPM Disk Unlock Key (DUK) passphrase for booting (minimum '"$MIN_PASSPHRASE_LENGTH"' characters): ' key_password
105+
read -r -s -p $'\nNew LUKS TPM Disk Unlock Key (DUK) passphrase for booting (minimum '"$MIN_PASSPHRASE_LENGTH"' characters): ' key_password
106106
if [ ${#key_password} -lt $MIN_PASSPHRASE_LENGTH ]; then
107107
attempts=$((attempts + 1))
108108
warn "Disk Unlock Key (DUK) passphrase is too short. Please try again."
109109
continue
110110
fi
111111

112-
read -s -p $'\nRepeat LUKS TPM Disk Unlock Key (DUK) passphrase for booting: ' key_password2
112+
read -r -s -p $'\nRepeat LUKS TPM Disk Unlock Key (DUK) passphrase for booting: ' key_password2
113113
if [ "$key_password" != "$key_password2" ]; then
114114
attempts=$((attempts + 1))
115115
warn "Disk Unlock Key (DUK) passphrases do not match. Please try again."

initrd/bin/kexec-unseal-key

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ DEBUG "Show PCRs"
2626
DEBUG "$(pcrs)"
2727

2828
for tries in 1 2 3; do
29-
read -s -p $'\nEnter LUKS TPM Disk Unlock Key passphrase (blank to abort): ' tpm_password
29+
read -r -s -p $'\nEnter LUKS TPM Disk Unlock Key passphrase (blank to abort): ' tpm_password
3030
echo
3131
if [ -z "$tpm_password" ]; then
3232
die "Aborting unseal disk encryption key"

initrd/bin/seal-hotpkey

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ fi
144144
if [ "$admin_pin_status" -ne 0 ]; then
145145

146146
# prompt user for PIN and retry
147-
read -s -p $'\nEnter your '"$HOTPKEY_BRANDING $prompt_message"' PIN: ' admin_pin
147+
read -r -s -p $'\nEnter your '"$HOTPKEY_BRANDING $prompt_message"' PIN: ' admin_pin
148148

149149
hotp_initialize "$admin_pin" $HOTP_SECRET $counter_value "$HOTPKEY_BRANDING"
150150
if [ $? -ne 0 ]; then
151-
read -s -p $'\nError setting HOTP secret, re-enter '"$prompt_message"' PIN and try again: ' admin_pin
151+
read -r -s -p $'\nError setting HOTP secret, re-enter '"$prompt_message"' PIN and try again: ' admin_pin
152152
if ! hotp_initialize "$admin_pin" $HOTP_SECRET $counter_value "$HOTPKEY_BRANDING"; then
153153
# don't leak key on failure
154154
shred -n 10 -z -u "$HOTP_SECRET" 2>/dev/null

initrd/etc/functions

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ confirm_gpg_card() {
170170
echo
171171
gpg_admin_pin=""
172172
while [ -z "$gpg_admin_pin" ]; do
173-
#TODO: change all passphrase prompts in codebase to include -r to prevent backslash escapes
174173
read -r -s -p $'\nPlease enter GPG Admin PIN needed to use the GPG backup thumb drive: ' gpg_admin_pin
175174
done
176175
#prompt user to select the proper encrypted partition, which should the first one on next prompt
@@ -789,7 +788,7 @@ prompt_tpm_owner_password() {
789788
return 0
790789
fi
791790

792-
read -s -p $'\nTPM Owner Password: ' tpm_owner_password
791+
read -r -s -p $'\nTPM Owner Password: ' tpm_owner_password
793792

794793
# Cache the password externally to be reused by who needs it
795794
DEBUG "Caching TPM Owner Password to /tmp/secret/tpm_owner_password"
@@ -807,9 +806,9 @@ prompt_new_owner_password() {
807806
tpm_owner_password=1
808807
tpm_owner_password2=2
809808
while [ "$tpm_owner_password" != "$tpm_owner_password2" ] || [ "${#tpm_owner_password}" -gt 32 ] || [ -z "$tpm_owner_password" ]; do
810-
read -s -p $'\nNew TPM Owner Password (2 words suggested, 1-32 characters max): ' tpm_owner_password
809+
read -r -s -p $'\nNew TPM Owner Password (2 words suggested, 1-32 characters max): ' tpm_owner_password
811810

812-
read -s -p $'\nRepeat chosen TPM Owner Password: ' tpm_owner_password2
811+
read -r -s -p $'\nRepeat chosen TPM Owner Password: ' tpm_owner_password2
813812
echo
814813

815814
if [ "$tpm_owner_password" != "$tpm_owner_password2" ]; then

0 commit comments

Comments
 (0)