Skip to content

Commit c43af60

Browse files
committed
codebase: unify all 'read' prompts to inject newline prior of asking for input
Signed-off-by: Thierry Laurion <insurgo@riseup.net>
1 parent b95ffcc commit c43af60

File tree

4 files changed

+10
-24
lines changed

4 files changed

+10
-24
lines changed

initrd/bin/kexec-seal-key

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +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-
echo ""
73-
read -s -p "Enter LUKS Disk Recovery Key (DRK) passphrase that can unlock $key_devices: " disk_recovery_key_passphrase
74-
echo ""
72+
read -s -p $'\nEnter LUKS Disk Recovery Key (DRK) passphrase that can unlock '"$key_devices"': ' disk_recovery_key_passphrase
7573
echo -n "$disk_recovery_key_passphrase" >"$DISK_RECOVERY_KEY_FILE"
7674

7775
# Test the passphrase against ALL devices before deciding if it's valid
@@ -104,19 +102,14 @@ done
104102
MIN_PASSPHRASE_LENGTH=12
105103
attempts=0
106104
while [ $attempts -lt 3 ]; do
107-
echo ""
108-
read -s -p "New LUKS TPM Disk Unlock Key (DUK) passphrase for booting (minimum $MIN_PASSPHRASE_LENGTH characters): " key_password
109-
echo ""
105+
read -s -p $'\nNew LUKS TPM Disk Unlock Key (DUK) passphrase for booting (minimum '"$MIN_PASSPHRASE_LENGTH"' characters): ' key_password
110106
if [ ${#key_password} -lt $MIN_PASSPHRASE_LENGTH ]; then
111107
attempts=$((attempts + 1))
112108
warn "Disk Unlock Key (DUK) passphrase is too short. Please try again."
113109
continue
114110
fi
115111

116-
echo ""
117-
read -s -p "Repeat LUKS TPM Disk Unlock Key (DUK) passphrase for booting: " key_password2
118-
echo ""
119-
echo ""
112+
read -s -p $'\nRepeat LUKS TPM Disk Unlock Key (DUK) passphrase for booting: ' key_password2
120113
if [ "$key_password" != "$key_password2" ]; then
121114
attempts=$((attempts + 1))
122115
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 "Enter LUKS TPM Disk Unlock Key passphrase (blank to abort): " tpm_password
29+
read -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 & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,11 @@ fi
144144
if [ "$admin_pin_status" -ne 0 ]; then
145145

146146
# prompt user for PIN and retry
147-
echo ""
148-
read -s -p "Enter your $HOTPKEY_BRANDING $prompt_message PIN: " admin_pin
149-
echo -e "\n"
147+
read -s -p $'\nEnter your '"$HOTPKEY_BRANDING $prompt_message"' PIN: ' admin_pin
150148

151149
hotp_initialize "$admin_pin" $HOTP_SECRET $counter_value "$HOTPKEY_BRANDING"
152150
if [ $? -ne 0 ]; then
153-
echo -e "\n"
154-
read -s -p "Error setting HOTP secret, re-enter $prompt_message PIN and try again: " admin_pin
155-
echo -e "\n"
151+
read -s -p $'\nError setting HOTP secret, re-enter '"$prompt_message"' PIN and try again: ' admin_pin
156152
if ! hotp_initialize "$admin_pin" $HOTP_SECRET $counter_value "$HOTPKEY_BRANDING"; then
157153
# don't leak key on failure
158154
shred -n 10 -z -u "$HOTP_SECRET" 2>/dev/null

initrd/etc/functions

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,7 @@ confirm_gpg_card() {
171171
gpg_admin_pin=""
172172
while [ -z "$gpg_admin_pin" ]; do
173173
#TODO: change all passphrase prompts in codebase to include -r to prevent backslash escapes
174-
read -r -s -p "Please enter GPG Admin PIN needed to use the GPG backup thumb drive: " gpg_admin_pin
175-
echo
174+
read -r -s -p $'\nPlease enter GPG Admin PIN needed to use the GPG backup thumb drive: ' gpg_admin_pin
176175
done
177176
#prompt user to select the proper encrypted partition, which should the first one on next prompt
178177
warn "Please select encrypted LUKS on GPG key material backup thumb drive (not public labeled one)"
@@ -790,8 +789,7 @@ prompt_tpm_owner_password() {
790789
return 0
791790
fi
792791

793-
read -s -p "TPM Owner Password: " tpm_owner_password
794-
echo # new line after password prompt
792+
read -s -p $'\nTPM Owner Password: ' tpm_owner_password
795793

796794
# Cache the password externally to be reused by who needs it
797795
DEBUG "Caching TPM Owner Password to /tmp/secret/tpm_owner_password"
@@ -809,10 +807,9 @@ prompt_new_owner_password() {
809807
tpm_owner_password=1
810808
tpm_owner_password2=2
811809
while [ "$tpm_owner_password" != "$tpm_owner_password2" ] || [ "${#tpm_owner_password}" -gt 32 ] || [ -z "$tpm_owner_password" ]; do
812-
read -s -p "New TPM Owner Password (2 words suggested, 1-32 characters max): " tpm_owner_password
813-
echo
810+
read -s -p $'\nNew TPM Owner Password (2 words suggested, 1-32 characters max): ' tpm_owner_password
814811

815-
read -s -p "Repeat chosen TPM Owner Password: " tpm_owner_password2
812+
read -s -p $'\nRepeat chosen TPM Owner Password: ' tpm_owner_password2
816813
echo
817814

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

0 commit comments

Comments
 (0)