Skip to content

Commit bcd2693

Browse files
authored
Merge pull request #1514 from tlaurion/confirm_rom_hash_before_flashing
bin/flash-gui.sh & initrd/bin/flash.sh: Show SHA256SUM for manual verification prior of flashing
2 parents f540f2a + c0cf446 commit bcd2693

File tree

1 file changed

+51
-53
lines changed

1 file changed

+51
-53
lines changed

initrd/bin/flash-gui.sh

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -25,67 +25,65 @@ while true; do
2525
menu_choice=$(cat /tmp/whiptail)
2626

2727
case "$menu_choice" in
28-
"x" )
29-
exit 0
28+
"x")
29+
exit 0
3030
;;
31-
f|c )
32-
if (whiptail $BG_COLOR_WARNING --title 'Flash the BIOS with a new ROM' \
33-
--yesno "You will need to insert a USB drive containing your BIOS image (*.rom or *.tgz).\n\nAfter you select this file, this program will reflash your BIOS.\n\nDo you want to proceed?" 0 80) then
34-
mount_usb
35-
if grep -q /media /proc/mounts ; then
36-
find /media ! -path '*/\.*' -type f \( -name '*.rom' -o -name '*.tgz' -o -type f -name '*.npf' \) | sort > /tmp/filelist.txt
37-
file_selector "/tmp/filelist.txt" "Choose the ROM to flash"
38-
if [ "$FILE" == "" ]; then
39-
exit 1
40-
else
41-
ROM=$FILE
42-
fi
31+
f | c)
32+
if (whiptail $BG_COLOR_WARNING --title 'Flash the BIOS with a new ROM' \
33+
--yesno "You will need to insert a USB drive containing your BIOS image (*.rom, *.npf or *.tgz).\n\nAfter you select this file, this program will reflash your BIOS.\n\nDo you want to proceed?" 0 80); then
34+
mount_usb
35+
if grep -q /media /proc/mounts; then
36+
find /media ! -path '*/\.*' -type f \( -name '*.rom' -o -name '*.tgz' -o -type f -name '*.npf' \) | sort >/tmp/filelist.txt
37+
file_selector "/tmp/filelist.txt" "Choose the ROM to flash"
38+
if [ "$FILE" == "" ]; then
39+
exit 1
40+
else
41+
ROM=$FILE
42+
fi
4343

44-
# is a .npf provided?
45-
if [ -z "${ROM##*.npf}" ]; then
46-
# unzip to /tmp/verified_rom
47-
mkdir /tmp/verified_rom
48-
unzip $ROM -d /tmp/verified_rom
49-
# check file integrity
50-
if (cd /tmp/verified_rom/ && sha256sum -cs /tmp/verified_rom/sha256sum.txt) ; then
51-
ROM="$(head -n1 /tmp/verified_rom/sha256sum.txt | cut -d ' ' -f 3)"
52-
else
53-
whiptail --title 'ROM Integrity Check Failed! ' \
54-
--msgbox "$ROM integrity check failed. Did not flash.\n\nPlease check your file (e.g. re-download).\n" 16 60
55-
exit
56-
fi
44+
# is a .npf provided?
45+
if [ -z "${ROM##*.npf}" ]; then
46+
#preventive cleanup
47+
rm -rf /tmp/verified_rom >/dev/null 2>&1 || true
48+
# unzip to /tmp/verified_rom
49+
mkdir -p /tmp/verified_rom >/dev/null 2>&1 || true
50+
unzip $ROM -d /tmp/verified_rom || die "Failed to unzip ROM file"
51+
# check file integrity
52+
if (cd /tmp/verified_rom/ && sha256sum -cs /tmp/verified_rom/sha256sum.txt); then
53+
ROM="$(head -n1 /tmp/verified_rom/sha256sum.txt | cut -d ' ' -f 3)"
5754
else
58-
# exit if we shall not proceed
59-
if ! (whiptail $CONFIG_ERROR_BG_COLOR --title 'Flash ROM without integrity check?' \
60-
--yesno "You have provided a *.rom file. The integrity of the file can not be\nchecked for this file.\nIf you do not know how to check the file integrity yourself,\nyou should use a *.npf file instead.\n\nIf the file is damaged, you will not be able to boot anymore.\nDo you want to proceed flashing without file integrity check?" 16 60) then
61-
exit
62-
fi
55+
whiptail --title 'ROM Integrity Check Failed! ' \
56+
--msgbox "$ROM integrity check failed. Did not flash.\n\nPlease check your file (e.g. re-download).\n" 16 60
57+
exit
6358
fi
64-
65-
if (whiptail $BG_COLOR_WARNING --title 'Flash ROM?' \
66-
--yesno "This will replace your current ROM with:\n\n${ROM#"/media/"}\n\nDo you want to proceed?" 0 80) then
67-
if [ "$menu_choice" == "c" ]; then
68-
/bin/flash.sh -c "$ROM"
69-
# after flash, /boot signatures are now invalid so go ahead and clear them
70-
if ls /boot/kexec* >/dev/null 2>&1 ; then
71-
(
72-
mount -o remount,rw /boot 2>/dev/null
73-
rm /boot/kexec* 2>/dev/null
74-
mount -o remount,ro /boot 2>/dev/null
75-
)
76-
fi
77-
else
78-
/bin/flash.sh "$ROM"
79-
fi
80-
whiptail --title 'ROM Flashed Successfully' \
81-
--msgbox "${ROM#"/media/"}\n\nhas been flashed successfully.\n\nPress Enter to reboot\n" 0 80
82-
umount /media
83-
/bin/reboot
84-
else
59+
else
60+
# a rom file was provided. exit if we shall not proceed
61+
ROM_HASH=$(sha256sum "$ROM" | awk '{print $1}') || die "Failed to hash ROM file"
62+
if ! (whiptail $CONFIG_ERROR_BG_COLOR --title 'Flash ROM without integrity check?' \
63+
--yesno "You have provided a *.rom file. The integrity of the file can not be\nchecked automatically for this file type.\n\nROM: $ROM\nSHA256SUM: $ROM_HASH\n\nIf you do not know how to check the file integrity yourself,\nyou should use a *.npf file instead.\n\nIf the file is damaged, you will not be able to boot anymore.\nDo you want to proceed flashing without file integrity check?" 0 80); then
8564
exit
8665
fi
8766
fi
67+
68+
if [ "$menu_choice" == "c" ]; then
69+
/bin/flash.sh -c "$ROM"
70+
# after flash, /boot signatures are now invalid so go ahead and clear them
71+
if ls /boot/kexec* >/dev/null 2>&1; then
72+
(
73+
mount -o remount,rw /boot 2>/dev/null
74+
rm /boot/kexec* 2>/dev/null
75+
mount -o remount,ro /boot 2>/dev/null
76+
)
77+
fi
78+
else
79+
/bin/flash.sh "$ROM"
80+
fi
81+
whiptail --title 'ROM Flashed Successfully' \
82+
--msgbox "${ROM#"/media/"}\n\nhas been flashed successfully.\n\nPress Enter to reboot\n" 0 80
83+
umount /media
84+
/bin/reboot
8885
fi
86+
fi
8987
;;
9088
esac
9189

0 commit comments

Comments
 (0)