2020-03-04 09:35:06 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-10-17 16:13:06 +00:00
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
2017-08-07 19:09:21 +00:00
|
|
|
set -e
|
2021-04-19 11:01:59 +00:00
|
|
|
|
2012-09-13 21:19:05 +00:00
|
|
|
TEST_DESCRIPTION="cryptsetup systemd setup"
|
2019-12-12 08:37:19 +00:00
|
|
|
IMAGE_NAME="cryptsetup"
|
2017-08-04 12:34:14 +00:00
|
|
|
TEST_NO_NSPAWN=1
|
2021-01-06 21:42:28 +00:00
|
|
|
TEST_FORCE_NEWIMAGE=1
|
2012-09-13 21:19:05 +00:00
|
|
|
|
2021-04-19 11:01:59 +00:00
|
|
|
# shellcheck source=test/test-functions
|
|
|
|
. "${TEST_BASE_DIR:?}/test-functions"
|
2012-09-13 21:19:05 +00:00
|
|
|
|
2022-05-25 15:39:14 +00:00
|
|
|
PART_UUID="deadbeef-dead-dead-beef-000000000000"
|
|
|
|
DM_NAME="test24_varcrypt"
|
|
|
|
# Mount the keyfile only in initrd (hence rd.luks.key), since it resides on
|
|
|
|
# the rootfs and we would get a (harmless) error when trying to mount it after
|
|
|
|
# switching root (since rootfs is already mounted)
|
|
|
|
KERNEL_APPEND+=" rd.luks=1 luks.name=$PART_UUID=$DM_NAME rd.luks.key=$PART_UUID=/etc/varkey:LABEL=systemd_boot"
|
|
|
|
|
2013-11-05 22:32:56 +00:00
|
|
|
check_result_qemu() {
|
2021-04-19 11:01:59 +00:00
|
|
|
local ret=1
|
|
|
|
|
2020-03-20 19:17:11 +00:00
|
|
|
mount_initdir
|
2021-04-19 11:01:59 +00:00
|
|
|
[[ -e "${initdir:?}/testok" ]] && ret=0
|
|
|
|
[[ -f "$initdir/failed" ]] && cp -a "$initdir/failed" "${TESTDIR:?}"
|
|
|
|
|
2022-05-25 15:39:14 +00:00
|
|
|
cryptsetup luksOpen "${LOOPDEV:?}p2" "${DM_NAME:?}" <"$TESTDIR/keyfile"
|
|
|
|
mount "/dev/mapper/$DM_NAME" "$initdir/var"
|
2021-04-19 11:01:59 +00:00
|
|
|
save_journal "$initdir/var/log/journal"
|
2021-10-21 16:12:06 +00:00
|
|
|
check_coverage_reports "${initdir:?}" || ret=5
|
2021-04-19 11:01:59 +00:00
|
|
|
_umount_dir "$initdir/var"
|
|
|
|
_umount_dir "$initdir"
|
2022-05-25 15:39:14 +00:00
|
|
|
cryptsetup luksClose "/dev/mapper/$DM_NAME"
|
2021-04-19 11:01:59 +00:00
|
|
|
|
|
|
|
[[ -f "$TESTDIR/failed" ]] && cat "$TESTDIR/failed"
|
|
|
|
echo "${JOURNAL_LIST:-No journals were saved}"
|
|
|
|
|
2021-04-23 08:55:49 +00:00
|
|
|
test -s "$TESTDIR/failed" && ret=1
|
2012-09-13 21:19:05 +00:00
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
2019-12-12 08:37:19 +00:00
|
|
|
test_create_image() {
|
2019-07-12 15:47:26 +00:00
|
|
|
create_empty_image_rootdir
|
2021-04-19 11:01:59 +00:00
|
|
|
|
|
|
|
echo -n test >"${TESTDIR:?}/keyfile"
|
2022-05-25 15:39:14 +00:00
|
|
|
cryptsetup -q luksFormat --uuid="$PART_UUID" --pbkdf pbkdf2 --pbkdf-force-iterations 1000 "${LOOPDEV:?}p2" "$TESTDIR/keyfile"
|
|
|
|
cryptsetup luksOpen "${LOOPDEV}p2" "${DM_NAME:?}" <"$TESTDIR/keyfile"
|
|
|
|
mkfs.ext4 -L var "/dev/mapper/$DM_NAME"
|
2021-04-19 11:01:59 +00:00
|
|
|
mkdir -p "${initdir:?}/var"
|
2022-05-25 15:39:14 +00:00
|
|
|
mount "/dev/mapper/$DM_NAME" "$initdir/var"
|
|
|
|
|
|
|
|
LOG_LEVEL=5
|
|
|
|
|
|
|
|
setup_basic_environment
|
|
|
|
mask_supporting_services
|
|
|
|
|
|
|
|
install_dmevent
|
|
|
|
generate_module_dependencies
|
|
|
|
|
|
|
|
echo -n test >"$initdir/etc/varkey"
|
2012-09-13 21:19:05 +00:00
|
|
|
|
2022-05-25 15:39:14 +00:00
|
|
|
cat >>"$initdir/etc/fstab" <<EOF
|
|
|
|
/dev/mapper/$DM_NAME /var ext4 defaults 0 1
|
2013-11-05 22:32:56 +00:00
|
|
|
EOF
|
2020-06-09 14:51:55 +00:00
|
|
|
|
2022-05-25 15:39:14 +00:00
|
|
|
# Forward journal messages to the console, so we have something
|
|
|
|
# to investigate even if we fail to mount the encrypted /var
|
|
|
|
echo ForwardToConsole=yes >> "$initdir/etc/systemd/journald.conf"
|
2019-07-12 15:47:26 +00:00
|
|
|
}
|
2012-09-13 21:19:05 +00:00
|
|
|
|
2019-07-12 15:47:26 +00:00
|
|
|
cleanup_root_var() {
|
2021-04-19 11:01:59 +00:00
|
|
|
ddebug "umount ${initdir:?}/var"
|
|
|
|
mountpoint "$initdir/var" && umount "$initdir/var"
|
2022-05-25 15:39:14 +00:00
|
|
|
[[ -b "/dev/mapper/${DM_NAME:?}" ]] && cryptsetup luksClose "/dev/mapper/$DM_NAME"
|
2012-09-13 21:19:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_cleanup() {
|
2019-07-12 18:09:48 +00:00
|
|
|
# ignore errors, so cleanup can continue
|
2019-07-19 00:34:57 +00:00
|
|
|
cleanup_root_var || :
|
2019-07-12 15:47:26 +00:00
|
|
|
_test_cleanup
|
|
|
|
}
|
|
|
|
|
|
|
|
test_setup_cleanup() {
|
2019-12-13 13:21:31 +00:00
|
|
|
cleanup_root_var || :
|
|
|
|
cleanup_initdir
|
2012-09-13 21:19:05 +00:00
|
|
|
}
|
|
|
|
|
2021-04-26 17:20:18 +00:00
|
|
|
do_test "$@"
|