Debian Codegraph @

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

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 # shellcheck disable=SC1091
4 type getarg >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || . /lib/dracut-lib.shscip-shell source . . `/lib/dracut-lib.sh`.
5 type set_root_map >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || . /lib/kiwi-lib.shscip-shell source . . `/lib/kiwi-lib.sh`.
6 type wait_for_storage_device >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || . /lib/kiwi-partitions-lib.shscip-shell source . . `/lib/kiwi-partitions-lib.sh`.
7 type ask_for_password >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || . /lib/dracut-crypt-lib.shscip-shell source . . `/lib/dracut-crypt-lib.sh`.
8 type run_progress_dialog >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || . /lib/kiwi-dialog-lib.shscip-shell source . . `/lib/kiwi-dialog-lib.sh`.
9
10 function luks_systemscip-shell shell shell-project 0.0.0 luks_system(). {
11 declare kiwi_RootPart=${kiwi_RootPart}
12 local disk=$1
13 local device
14 device=$(get_partition_node_name "${disk}" "${kiwi_RootPart}")
15 if cryptsetup isLuks "${device}" &>/dev/nullscip-shell filesystem . . `/dev/null`.;then
16 return 0
17 fi
18 return 1
19 }
20
21 function deactivate_luksscip-shell shell shell-project 0.0.0 deactivate_luks(). {
22 /usr/lib/systemd/systemd-cryptsetupscip-shell filesystem . . `/usr/lib/systemd/systemd-cryptsetup`. detach luks
23 }
24
25 function reencrypt_luksscip-shell shell shell-project 0.0.0 reencrypt_luks(). {
26 declare kiwi_RootPart=${kiwi_RootPart}
27 local disk=$1
28 local keyslot=/root/.luks.slotscip-shell filesystem . . `/root/.luks.slot`.
29 local header_checksum_origin=/root/.luks.headerscip-shell filesystem . . `/root/.luks.header`.
30 local header_checksum_cur=/root/.luks.header.curscip-shell filesystem . . `/root/.luks.header.cur`.
31 local keyfile=/root/.root.keyfilescip-shell filesystem . . `/root/.root.keyfile`.
32 local new_keyfile=/run/.kiwi_reencrypt.keyfilescip-shell filesystem . . `/run/.kiwi_reencrypt.keyfile`.
33 local passphrase_file=/root/.slotpassscip-shell filesystem . . `/root/.slotpass`.
34 local progress=/dev/install_progressscip-shell filesystem . . `/dev/install_progress`.
35 local load_text="Reencrypting..."
36 local title_text="LUKS"
37 local shasum
38 local device
39 device=$(get_partition_node_name "${disk}" "${kiwi_RootPart}")
40 read -r header_checksum_origin < "${header_checksum_origin}"
41 read -r keyslot < "${keyslot}"
42
43 # Checksum test if luks header is still the image origin header
44 shasum=$(shasum_tool)
45 cryptsetup luksHeaderBackup \
46 "${device}" --header-backup-file "${header_checksum_cur}"
47 header_checksum_cur=$(
48 "${shasum}" "${header_checksum_cur}" |\
49 cut -f1 -d" "; rm -f "${header_checksum_cur}"
50 )
51 if [scip-shell system . . `[`. "${header_checksum_origin}" == "${header_checksum_cur}" ];then
52 if getargbool 0 rd.kiwi.oem.luks.reencrypt_randompass; then
53 # reset insecure built time passphrase with a random
54 # onetime passphrase that will be stored in memory at $new_keyfile
55 # This action require that the boot process uses $new_keyfile
56 # and sets a retrievable keyfile information for subsequent
57 # boot processes of this system
58 (umask 077; touchscip-shell system . . touch. "${new_keyfile}")
59 trscip-shell system . . tr. -dc '[:graph:]' 2>/dev/nullscip-shell filesystem . . `/dev/null`. < /dev/urandomscip-shell filesystem . . `/dev/urandom`. |\
60 head -c 32 > "${new_keyfile}"
61 chmodscip-shell system . . chmod. 0400 "${new_keyfile}"
62 cryptsetup \
63 --key-file "${passphrase_file}" \
64 --key-slot "${keyslot}" \
65 luksChangeKey "${device}" "${new_keyfile}"
66 cpscip-shell system . . cp. "${new_keyfile}" "${passphrase_file}"
67 if [scip-shell system . . `[`. -e "${keyfile}" ]; then
68 # if there is a keyfile it's referenced in the crypttab
69 # of this initrd instance in memory. Make sure all subsequent
70 # tasks e.g. luks resize have permissions to complete while
71 # inside of this initrd instance
72 cpscip-shell system . . cp. "${new_keyfile}" "${keyfile}"
73 fi
74 fi
75 # reencrypt
76 setup_progress_fifo ${progress}
77 (
78 # reencrypt, this will overwrite all key slots
79 set_device_lock "${device}" cryptsetup reencrypt \
80 --progress-frequency 1 \
81 --key-file "${passphrase_file}" \
82 --key-slot "${keyslot}" \
83 "${device}" 2>&1 | sedscip-shell system . . sed. -u 's/.* \([0-9]*\)[0-9.]*%.*/\1/'
84 ) >"${progress}" &
85 run_progress_dialog "${load_text}" "${title_text}"
86 if [scip-shell system . . `[`. -e "${keyfile}" ] && [scip-shell system . . `[`. ! -e "${new_keyfile}" ];then
87 # re-add keyfile if present and no other keyfile was created
88 cryptsetup --key-file "${passphrase_file}" luksAddKey \
89 "${device}" "${keyfile}"
90 fi
91 fi
92 }
93
94 function resize_luksscip-shell shell shell-project 0.0.0 resize_luks(). {
95 cryptsetup resize luks
96 }
97
98 function activate_luksscip-shell shell shell-project 0.0.0 activate_luks(). {
99 declare kiwi_luks_empty_passphrase=${kiwi_luks_empty_passphrase}
100 local device=$1
101 if [scip-shell system . . `[`. "${kiwi_luks_empty_passphrase}" = "true" ];then
102 # There is no keyfile and kiwi has created the luks pool with
103 # an empty key. Therefore it can be opened without interaction
104 # but this requires to manually call luksOpen since
105 # with systemd-cryptsetup we saw it still asking for
106 # a passphrase
107 set_device_lock "${device}" cryptsetup \
108 --key-file /dev/zeroscip-shell filesystem . . `/dev/zero`. \
109 --keyfile-size 32 \
110 luksOpen "${device}" luks
111 else
112 # There is a keyfile and we need to get prompted to enter the passphrase
113 systemctl start systemd-cryptsetup@luks
114 fi
115 wait_for_storage_device "/dev/mapper/luksscip-shell filesystem . . `/dev/mapper/luks`."
116 set_root_map "/dev/mapper/luksscip-shell filesystem . . `/dev/mapper/luks`."
117 }