Skip to content

Commit 15a187a

Browse files
authored
Merge pull request #2745 from OSInside/reencrypt_wipe_insecure_passphrase
Add rd.kiwi.oem.luks.reencrypt_randompass
2 parents 8491f40 + 88930d3 commit 15a187a

File tree

3 files changed

+39
-13
lines changed

3 files changed

+39
-13
lines changed

build-tests/x86/tumbleweed/test-image-luks/appliance.kiwi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
</type>
4949
</preferences>
5050
<preferences profiles="ReEncryptExtraBootWithPass">
51-
<type image="oem" filesystem="ext4" kernelcmdline="console=ttyS0 rd.kiwi.oem.luks.reencrypt" firmware="uefi" luks="linux" luks_version="luks2" luks_pbkdf="pbkdf2" bootpartition="true">
51+
<type image="oem" filesystem="ext4" kernelcmdline="console=ttyS0 rd.kiwi.oem.luks.reencrypt rd.kiwi.oem.luks.reencrypt_randompass quiet" firmware="uefi" luks="linux" luks_version="luks2" luks_pbkdf="pbkdf2" bootpartition="true">
5252
<luksformat>
5353
<option name="--cipher" value="aes-xts-plain64"/>
5454
<option name="--key-size" value="256"/>

doc/source/concept_and_workflow/customize_the_boot_process.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,21 @@ the available kernel boot parameters for these modules:
227227
for the passphrase if the image has been built with an initial
228228
luks passphrase.
229229

230+
``rd.kiwi.oem.luks.reencrypt_randompass``
231+
For OEM LUKS2 encrypted disk images in combination
232+
with `rd.kiwi.oem.luks.reencrypt`. Reset insecure built time
233+
passphrase, set via the `luks=` attribute, with a random
234+
onetime passphrase that will be stored in memory at
235+
`/run/.kiwi_reencrypt.keyfile`.
236+
237+
.. warning::
238+
239+
The passphrase will only persist as long as the system
240+
does not reboot. Using this option usually requires that
241+
the boot process implements code to set a retrievable keyfile
242+
information for subsequent boot processes of this system, e.g
243+
TPM setup or similar.
244+
230245
``rd.kiwi.oem.disk.consistency``
231246
For OEM disk images providing an installation image. If set,
232247
the installation image will check against all disks that are

dracut/modules.d/99kiwi-lib/kiwi-luks-lib.sh

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)