Skip to content

Commit 43ea22c

Browse files
committed
Fix reencryption master key passphrase
Make sure to use the correct passphrase for the master key such that it can be decrypted with the same credentials as before. The credentials reset is a subsequent task after reencryption.
1 parent a3d10cd commit 43ea22c

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@ function reencrypt_luks {
4747
cut -f1 -d" "; rm -f "${header_checksum_cur}"
4848
)
4949
if [ "${header_checksum_origin}" == "${header_checksum_cur}" ];then
50-
# setup credentials
51-
if [ "${kiwi_luks_empty_passphrase}" = "true" ];then
52-
echo -n > "${passphrase_file}"
53-
elif [ -e "${keyfile}" ];then
54-
cp "${keyfile}" "${passphrase_file}"
55-
else
56-
ask_for_credentials "Enter Credentials for Key Slot(0)"
57-
get_dialog_result > "${passphrase_file}"
58-
fi
5950
if getargbool 0 rd.kiwi.oem.luks.reencrypt_randompass; then
6051
# reset insecure built time passphrase with a random
6152
# onetime passphrase that will be stored in memory at $new_keyfile

kiwi/builder/disk.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def __init__(
118118
self.root_dir = root_dir
119119
self.target_dir = target_dir
120120
self.xml_state = xml_state
121+
self.cmdline = xml_state.build_type.get_kernelcmdline() or ''
121122
self.spare_part_mbsize = xml_state.get_build_type_spare_part_size()
122123
self.spare_part_fs = xml_state.build_type.get_spare_part_fs()
123124
self.spare_part_is_last = xml_state.build_type.get_spare_part_is_last()
@@ -784,7 +785,8 @@ def _build_main_system(
784785

785786
self._write_crypttab_to_system_image(luks_root)
786787

787-
self._write_luks_header_checksum_to_boot_image(luks_root)
788+
if 'rd.kiwi.oem.luks.reencrypt' in self.cmdline:
789+
self._write_luks_header_checksum_to_boot_image(luks_root)
788790

789791
self._write_integritytab_to_system_image(integrity_root)
790792

@@ -1289,7 +1291,8 @@ def _write_luks_header_checksum_to_boot_image(
12891291
)
12901292
filenames = [
12911293
''.join([self.root_dir, '/root/.luks.header']),
1292-
''.join([self.root_dir, '/root/.luks.slot'])
1294+
''.join([self.root_dir, '/root/.luks.slot']),
1295+
''.join([self.root_dir, '/root/.slotpass'])
12931296
]
12941297
for filename in filenames:
12951298
self.boot_image.include_file(

kiwi/storage/luks_device.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ def create_crypto_luks(
179179
'luksAddKey', storage_device, keyfile_path
180180
]
181181
)
182-
keyslot = '1'
183182

184183
# Create backup header checksum as reencryption reference
185184
master_checksum = f'{root_dir}/root/.luks.header'
@@ -201,6 +200,11 @@ def create_crypto_luks(
201200
with open(master_slot, 'w') as slot:
202201
slot.write(keyslot)
203202

203+
# Create slot passphrase as reencryption reference
204+
master_slotpass = f'{root_dir}/root/.slotpass'
205+
with open(master_slotpass, 'w') as slotpass:
206+
slotpass.write(self.passphrase)
207+
204208
# open the pool
205209
Command.run(
206210
[

test/unit/builder/disk_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,7 @@ def test_create_disk_luks_root(
11821182
self.disk_builder.boot_is_crypto = True
11831183
disk.public_partition_id_map = self.id_map
11841184
disk.public_partition_id_map['kiwi_ROPart'] = 1
1185+
self.disk_builder.cmdline = 'rd.kiwi.oem.luks.reencrypt'
11851186

11861187
with patch('builtins.open'):
11871188
self.disk_builder.create_disk()
@@ -1200,7 +1201,8 @@ def test_create_disk_luks_root(
12001201
call('/config.partids'),
12011202
call('/etc/crypttab'),
12021203
call(filename='/root/.luks.header', delete_after_include=True),
1203-
call(filename='/root/.luks.slot', delete_after_include=True)
1204+
call(filename='/root/.luks.slot', delete_after_include=True),
1205+
call(filename='/root/.slotpass', delete_after_include=True)
12041206
]
12051207
self.boot_image_task.write_system_config_file.assert_called_once_with(
12061208
config={'install_items': ['/root/.root.keyfile']},
@@ -1238,6 +1240,7 @@ def test_create_disk_luks_root_with_disk_password(
12381240
disk.public_partition_id_map = self.id_map
12391241
disk.public_partition_id_map['kiwi_ROPart'] = 1
12401242
bootloader = mock_BootLoaderInstall.return_value
1243+
self.disk_builder.cmdline = 'rd.kiwi.oem.luks.reencrypt'
12411244

12421245
with patch('builtins.open'):
12431246
self.disk_builder.create_disk()
@@ -1256,7 +1259,8 @@ def test_create_disk_luks_root_with_disk_password(
12561259
call('/config.partids'),
12571260
call('/etc/crypttab'),
12581261
call(filename='/root/.luks.header', delete_after_include=True),
1259-
call(filename='/root/.luks.slot', delete_after_include=True)
1262+
call(filename='/root/.luks.slot', delete_after_include=True),
1263+
call(filename='/root/.slotpass', delete_after_include=True)
12601264
]
12611265
self.boot_image_task.write_system_config_file.assert_called_once_with(
12621266
config={'install_items': ['/root/.root.keyfile']},

0 commit comments

Comments
 (0)