-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.sh
110 lines (82 loc) · 2.71 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/sh
set -e -u
msg() {
printf '\x1b[1m%s\x1b[0m\n' "$1"
}
perform() {
msg "Attempting read, expecting failure"
if pv "/dev/mapper/$dm" >/dev/null; then
exit 1
fi
echo
msg "Scrub dry run, expecting lots of corrupt sectors"
"target/$profile/integrity-scrub" -n "/dev/mapper/$dm"
echo
msg "Attempting read, expecting failure"
if pv "/dev/mapper/$dm" >/dev/null; then
exit 1
fi
echo
msg "Scrub, expecting lots of corrupt sectors"
"target/$profile/integrity-scrub" "/dev/mapper/$dm"
echo
msg "Attempting read, expecting success"
pv "/dev/mapper/$dm" >/dev/null
echo
msg "Scrub again, expecting no corrupt sectors"
"target/$profile/integrity-scrub" "/dev/mapper/$dm"
echo
msg "Trying to corrupt data"
blockdev --flushbufs "/dev/mapper/$dm"
blockdev --flushbufs "$loop"
dd if=/dev/urandom of="$loop" bs=1MiB count="$((device_size - 16))" seek=16 conv=fdatasync
echo
msg "Attemping to read, expecting failure"
if pv "/dev/mapper/$dm" >/dev/null; then
exit 1
fi
echo
msg "Scrub, expecting single corrupt sector"
"target/$profile/integrity-scrub" "/dev/mapper/$dm"
echo
msg "Attemping to read, expecting success"
pv "/dev/mapper/$dm" >/dev/null
echo
}
profile="${profile:-debug}"
for sector_size in 512 1024 2048 4096; do
device_size="$((sector_size))"
msg "Profile $profile, sector size $sector_size, device size $device_size MiB"
tmp="$(mktemp)"
trap 'rm -f -- "$tmp"' EXIT HUP INT QUIT TERM
truncate --size "${device_size}MiB" "$tmp"
loop="$(losetup --show -f "$tmp")"
trap 'losetup -d "$loop"; rm -f -- "$tmp"' EXIT HUP INT QUIT TERM
msg "Trying integritysetup with CRC32c"
integritysetup format --batch-mode --no-wipe --journal-size 0 --sector-size "$sector_size" \
--integrity crc32c "$loop"
dm="$(mktemp -u tmp-XXXXXXXXXX)"
integritysetup open --batch-mode "$tmp" "$dm"
trap 'integritysetup close "$dm"; losetup -d "$loop"; rm -f -- "$tmp"' EXIT HUP INT QUIT TERM
echo
perform
integritysetup close "$dm"
msg "Trying cryptsetup with AEGIS-128"
key="$(mktemp)"
mktemp -u XXXXXXXXXXXX >"$key"
trap 'rm -f -- "$key"; losetup -d "$loop"; rm -f -- "$tmp"' EXIT HUP INT QUIT TERM
wipefs -a "$loop"
cryptsetup luksFormat --batch-mode --type luks2 --cipher aegis128-random --key-size 128 --key-file "$key" \
--force-password --integrity aead --integrity-no-journal --integrity-no-wipe --sector-size "$sector_size" "$loop"
cryptsetup open --batch-mode --integrity-no-journal --key-file "$key" "$loop" "$dm"
trap 'cryptsetup close "$dm"; rm -f -- "$key"; losetup -d "$loop"; rm -f -- "$tmp"' EXIT HUP INT QUIT TERM
echo
perform
cryptsetup close "$dm"
rm -f -- "$key"
losetup -d "$loop"
rm -f -- "$tmp"
trap - EXIT HUP INT QUIT TERM
echo
done
msg "All tests passed successfully"