Debian Codegraph @

tests/ts/mount/dm-verity

raw
1 #!/bin/bash
2
3 #
4 # Copyright (C) 2021 Vojtech Eichler <[email protected]>
5 #
6 # This file is part of util-linux.
7 #
8 # This file is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This file is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 TS_TOPDIR="${0%/*}/../.."
19 TS_DESC="dm-verity support"
20
21 . "$TS_TOPDIR"/functions.sh
22 ts_init "$*"
23
24 VERITY_OUTPUT="$TS_OUTPUT.log"
25 HASH_DEVICE="$TS_OUTDIR/dm-verity.hash"
26 SQUASHFS="$TS_OUTDIR/dm-verity.img"
27 VERITY_DEVICE="test_dm_verity"
28 VERITY_DEVICE_ABS="/dev/mapper/$VERITY_DEVICE"
29 ROOT_HASH_FILE="$TS_OUTDIR/root_hash_file.hash"
30
31 ts_check_test_command "$TS_CMD_MOUNT"
32 ts_check_test_command "$TS_CMD_UMOUNT"
33
34 ts_skip_nonroot
35 ts_check_prog "mksquashfs"
36 ts_check_prog "veritysetup"
37
38 grep -q '#define HAVE_CRYPTSETUP' ${top_builddir}/config.h || ts_skip "no dm-verity support"
39
40 # Make a squashfs and prepare verity device out of it
41 mksquashfs $TS_SELF $SQUASHFS &>/dev/null || ts_skip "error: mksquashfs on $TS_SELF"
42 veritysetup format $SQUASHFS $HASH_DEVICE > $VERITY_OUTPUT || ts_skip "cannot format $SQUASHFS"
43
44 # Extract root hash out of veritysetup output
45 HASH=$(cat $VERITY_OUTPUT | awk '/Root hash:/ { print $3 }') || ts_die "error: extract hash"
46 echo $HASH > $ROOT_HASH_FILE
47 # Activate verity data device
48 veritysetup create $VERITY_DEVICE $SQUASHFS $HASH_DEVICE $HASH || ts_skip "cannot activate verity device"
49
50
51 ts_init_subtest "roothash"
52 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
53 $TS_CMD_MOUNT --options verity.hashdevice=$HASH_DEVICE,verity.roothash=$HASH,verity.hashoffset=0 \
54 $VERITY_DEVICE_ABS \
55 $TS_MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
56 $TS_CMD_UMOUNT --lazy $TS_MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
57 ts_finalize_subtest
58
59
60 ts_init_subtest "roothashfile"
61 [ -d "$TS_MOUNTPOINT" ] || mkdir -p $TS_MOUNTPOINT
62 $TS_CMD_MOUNT --options verity.hashdevice=$HASH_DEVICE,verity.roothashfile=$ROOT_HASH_FILE \
63 $VERITY_DEVICE_ABS \
64 $TS_MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
65 $TS_CMD_UMOUNT --lazy $TS_MOUNTPOINT >> $TS_OUTPUT 2>> $TS_ERRLOG
66 ts_finalize_subtest
67
68
69 # Cleanup
70 dmsetup remove -f $VERITY_DEVICE
71
72 ts_finalize