@@ -28,36 +28,47 @@ function reencrypt_luks {
2828 local header_checksum_origin=/root/.luks.header
2929 local header_checksum_cur=/root/.luks.header.cur
3030 local keyfile=/root/.root.keyfile
31+ local new_keyfile=/run/.kiwi_reencrypt.keyfile
3132 local passphrase_file=/root/.slot0
3233 local progress=/dev/install_progress
3334 local load_text=" Reencrypting..."
3435 local title_text=" LUKS"
3536 local device
3637 device=$( get_partition_node_name " ${disk} " " ${kiwi_RootPart} " )
3738 read -r header_checksum_origin < " ${header_checksum_origin} "
38- if [ " ${kiwi_luks_empty_passphrase} " = " true" ]; then
39- cryptsetup \
40- --key-file /dev/zero \
41- --keyfile-size 32 \
42- luksHeaderBackup " ${device} " \
43- --header-backup-file " ${header_checksum_cur} "
44- else
45- cryptsetup \
46- --key-file " ${keyfile} " \
47- luksHeaderBackup " ${device} " \
48- --header-backup-file " ${header_checksum_cur} "
49- fi
39+
40+ # Checksum test if luks header is still the image origin header
41+ cryptsetup luksHeaderBackup \
42+ " ${device} " --header-backup-file " ${header_checksum_cur} "
5043 header_checksum_cur=$(
5144 sha256sum " ${header_checksum_cur} " | \
5245 cut -f1 -d" " ; rm -f " ${header_checksum_cur} "
5346 )
5447 if [ " ${header_checksum_origin} " == " ${header_checksum_cur} " ]; then
48+ # setup credentials
5549 if [ " ${kiwi_luks_empty_passphrase} " = " true" ]; then
5650 echo -n > " ${passphrase_file} "
51+ elif [ -e " ${keyfile} " ]; then
52+ cp " ${keyfile} " " ${passphrase_file} "
5753 else
5854 ask_for_credentials " Enter Credentials for Key Slot(0)"
5955 get_dialog_result > " ${passphrase_file} "
6056 fi
57+ if getargbool 0 rd.kiwi.oem.luks.reencrypt_randompass; then
58+ # reset insecure built time passphrase with a random
59+ # onetime passphrase that will be stored in memory at $new_keyfile
60+ # This action require that the boot process uses $new_keyfile
61+ # and sets a retrievable keyfile information for subsequent
62+ # boot processes of this system
63+ tr -dc ' [:graph:]' 2> /dev/null < /dev/urandom | \
64+ head -c 32 > " ${new_keyfile} "
65+ cryptsetup \
66+ --key-file " ${passphrase_file} " \
67+ --key-slot 0 \
68+ luksChangeKey " ${device} " " ${new_keyfile} "
69+ cp " ${new_keyfile} " " ${passphrase_file} "
70+ fi
71+ # reencrypt
6172 setup_progress_fifo ${progress}
6273 (
6374 # reencrypt slot0, this will wipe all key slots
0 commit comments