Debian Codegraph @

tests/tcrypt-compat-test

raw symbols SCIP
1 #!/bin/bashscip-shell filesystem . . `/bin/bash`.
2
3 # check tcrypt images parsing
4
5 [scip-shell system . . `[`. -z "$CRYPTSETUP_PATH" ] && CRYPTSETUP_PATH=".."
6 CRYPTSETUP=$CRYPTSETUP_PATH/cryptsetup
7 TST_DIR=tcrypt-images
8 MAP=tctst
9 PASSWORD="aaaaaaaaaaaa"
10 PASSWORD_HIDDEN="bbbbbbbbbbbb"
11 PASSWORD_72C="aaaaaaaaaaaabbbbbbbbbbbbccccccccccccddddddddddddeeeeeeeeeeeeffffffffffff"
12 PIM=1234
13 LOOP_SYS=""
14 PART_IMG=tctst-part-img
15
16 CRYPTOCHECK=./crypto-check
17
18 if [scip-shell system . . `[`. -n "$CRYPTSETUP_TESTS_RUN_IN_MESON" ]; then
19 CRYPTSETUP_VALGRIND=$CRYPTSETUP
20 else
21 CRYPTSETUP_VALGRIND=../.libs/cryptsetup
22 CRYPTSETUP_LIB_VALGRIND=../.libs
23 fi
24
25 [scip-shell system . . `[`. -z "$srcdir" ] && srcdir="."
26
27 remove_mappingscip-shell shell shell-project 0.0.0 remove_mapping().()
28 {
29 [scip-shell system . . `[`. -b /dev/mapper/$MAP ] && dmsetup remove --retry $MAP
30 [scip-shell system . . `[`. -b /dev/mapper/"$MAP"_1 ] && dmsetup remove --retry "$MAP"_1
31 [scip-shell system . . `[`. -b /dev/mapper/"$MAP"_2 ] && dmsetup remove --retry "$MAP"_2
32 [scip-shell system . . `[`. -n "$LOOP_SYS" ] && losetupscip-shell system . . losetup. -d $LOOP_SYS
33 rmscip-shell system . . rm. -rf $TST_DIR $PART_IMG
34 }
35
36 failscip-shell shell shell-project 0.0.0 fail().()
37 {
38 [scip-shell system . . `[`. -n "$1" ] && echoscip-shell system . . echo. "$1"
39 echoscip-shell system . . echo. " [FAILED]"
40 echoscip-shell system . . echo. "FAILED backtrace:"
41 while caller $frame; do ((frame++)); done
42 remove_mappingscip-shell shell shell-project 0.0.0 remove_mapping().
43 exit 2
44 }
45
46 _sigchldscip-shell shell shell-project 0.0.0 _sigchld().() { local c=$?; [scip-shell system . . `[`. $c -eq 139 ] && failscip-shell shell shell-project 0.0.0 fail(). "Segfault"; [scip-shell system . . `[`. $c -eq 134 ] && failscip-shell shell shell-project 0.0.0 fail(). "Aborted"; }
47 trap _sigchld CHLD
48
49 skipscip-shell shell shell-project 0.0.0 skip().()
50 {
51 [scip-shell system . . `[`. -n "$1" ] && echoscip-shell system . . echo. "$1"
52 remove_mappingscip-shell shell shell-project 0.0.0 remove_mapping().
53 exit 77
54 }
55
56 test_onescip-shell shell shell-project 0.0.0 test_one().() # cipher mode keysize rm_pattern
57 {
58 $CRYPTOCHECK cipher $1 $2 $3
59 if [scip-shell system . . `[`. $? -ne 0 ] ; then
60 echoscip-shell system . . echo. "$1-$2 [N/A]"
61 IMGS=$(lsscip-shell system . . ls. $TST_DIR/[tv]c* | grepscip-shell system . . grep. "$4")
62 [scip-shell system . . `[`. -n "$IMGS" ] && rmscip-shell system . . rm. $IMGS
63 else
64 echoscip-shell system . . echo. "$1-$2 [OK]"
65 fi
66 }
67
68 test_kdfscip-shell shell shell-project 0.0.0 test_kdf().() # hash img_hash
69 {
70 $CRYPTOCHECK hash $1
71 if [scip-shell system . . `[`. $? -ne 0 ] ; then
72 echoscip-shell system . . echo. "pbkdf2-$1 [N/A]"
73 IMGS=$(lsscip-shell system . . ls. $TST_DIR/[tv]c* | grepscip-shell system . . grep. "$2")
74 [scip-shell system . . `[`. -n "$IMGS" ] && rmscip-shell system . . rm. $IMGS
75 else
76 echoscip-shell system . . echo. "pbkdf2-$1 [OK]"
77 fi
78 }
79
80 get_HASH_CIPHERscip-shell shell shell-project 0.0.0 get_HASH_CIPHER().() # filename
81 {
82 # speed up the test by limiting options for hash and (first) cipher
83 HASH=$(echoscip-shell system . . echo. $file | cutscip-shell system . . cut. -d'-' -f3)
84 CIPHER=$(echoscip-shell system . . echo. $file | cutscip-shell system . . cut. -d'-' -f5)
85 }
86
87 test_requiredscip-shell shell shell-project 0.0.0 test_required().()
88 {
89 command -v blkid >/dev/nullscip-shell filesystem . . `/dev/null`. || skipscip-shell shell shell-project 0.0.0 skip(). "blkid tool required, test skipped."
90 [scip-shell system . . `[`. ! -x "$CRYPTOCHECK" ] && skipscip-shell shell shell-project 0.0.0 skip(). "Cannot find $CRYPTOCHECK, test skipped."
91
92 echoscip-shell system . . echo. "REQUIRED KDF TEST"
93 test_kdfscip-shell shell shell-project 0.0.0 test_kdf(). sha256 sha256
94 test_kdfscip-shell shell shell-project 0.0.0 test_kdf(). sha512 sha512
95 test_kdfscip-shell shell shell-project 0.0.0 test_kdf(). blake2s-256 blake2
96 test_kdfscip-shell shell shell-project 0.0.0 test_kdf(). ripemd160 ripemd160
97 test_kdfscip-shell shell shell-project 0.0.0 test_kdf(). whirlpool whirlpool
98 test_kdfscip-shell shell shell-project 0.0.0 test_kdf(). stribog512 stribog
99
100 echoscip-shell system . . echo. "REQUIRED CIPHERS TEST"
101 test_onescip-shell shell shell-project 0.0.0 test_one(). aes cbc 256 cbc-aes
102 test_onescip-shell shell shell-project 0.0.0 test_one(). aes lrw 384 lrw-aes
103 test_onescip-shell shell shell-project 0.0.0 test_one(). aes xts 512 xts-aes
104
105 test_onescip-shell shell shell-project 0.0.0 test_one(). twofish ecb 256 twofish
106 test_onescip-shell shell shell-project 0.0.0 test_one(). twofish cbc 256 cbc-twofish
107 test_onescip-shell shell shell-project 0.0.0 test_one(). twofish lrw 384 lrw-twofish
108 test_onescip-shell shell shell-project 0.0.0 test_one(). twofish xts 512 xts-twofish
109
110 test_onescip-shell shell shell-project 0.0.0 test_one(). serpent ecb 256 serpent
111 test_onescip-shell shell shell-project 0.0.0 test_one(). serpent cbc 256 cbc-serpent
112 test_onescip-shell shell shell-project 0.0.0 test_one(). serpent lrw 384 lrw-serpent
113 test_onescip-shell shell shell-project 0.0.0 test_one(). serpent xts 512 xts-serpent
114
115 test_onescip-shell shell shell-project 0.0.0 test_one(). blowfish cbc 256 blowfish
116
117 test_onescip-shell shell shell-project 0.0.0 test_one(). des3_ede cbc 192 des3_ede
118 test_onescip-shell shell shell-project 0.0.0 test_one(). cast5 cbc 128 cast5
119
120 test_onescip-shell shell shell-project 0.0.0 test_one(). camellia xts 512 camellia
121 test_onescip-shell shell shell-project 0.0.0 test_one(). kuznyechik xts 512 kuznyechik
122
123 lsscip-shell system . . ls. $TST_DIR/[tv]c* >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 || skipscip-shell shell shell-project 0.0.0 skip(). "No remaining images, test skipped."
124 }
125
126 check_uuidscip-shell shell shell-project 0.0.0 check_uuid().()
127 {
128 UUID=$(blkidscip-shell system . . blkid. -p -o value -s UUID /dev/mapper/$MAP)
129 [scip-shell system . . `[`. "$UUID" != "$1" ] && failscip-shell shell shell-project 0.0.0 fail(). "UUID check failed."
130 }
131
132 valgrind_setupscip-shell shell shell-project 0.0.0 valgrind_setup().()
133 {
134 command -v valgrind >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail(). "Cannot find valgrind."
135 [scip-shell system . . `[`. ! -f $CRYPTSETUP_VALGRIND ] && failscip-shell shell shell-project 0.0.0 fail(). "Unable to get location of cryptsetup executable."
136 [scip-shell system . . `[`. ! -f valg.sh ] && failscip-shell shell shell-project 0.0.0 fail(). "Unable to get location of valg runner script."
137 if [scip-shell system . . `[`. -z "$CRYPTSETUP_TESTS_RUN_IN_MESON" ]; then
138 export LD_LIBRARY_PATH="$CRYPTSETUP_LIB_VALGRIND:$LD_LIBRARY_PATH"
139 fi
140 }
141
142 valgrind_runscip-shell shell shell-project 0.0.0 valgrind_run().()
143 {
144 INFOSTRING="$(basenamescip-shell system . . basename. ${BASH_SOURCE[1]})-line-${BASH_LINENO[0]}" ./valg.sh ${CRYPTSETUP_VALGRIND} "$@"
145 }
146
147 export LANG=C
148 [scip-shell system . . `[`. ! -x "$CRYPTSETUP" ] && skipscip-shell shell shell-project 0.0.0 skip(). "Cannot find $CRYPTSETUP, test skipped."
149 [scip-shell system . . `[`. ! -d $TST_DIR ] && tarscip-shell system . . tar. xJf $srcdir/tcrypt-images.tar.xz --no-same-owner
150
151 [scip-shell system . . `[`. -n "$VALG" ] && valgrind_setupscip-shell shell shell-project 0.0.0 valgrind_setup(). && CRYPTSETUP=valgrind_run
152
153 test_requiredscip-shell shell shell-project 0.0.0 test_required().
154
155 echoscip-shell system . . echo. "HEADER CHECK"
156 for file in $(lsscip-shell system . . ls. $TST_DIR/[tv]c_* $TST_DIR/vcpim_* $TST_DIR/sys_[tv]c_*) ; do
157 echoscip-shell system . . echo. -n " $file"
158 PIM_OPT=""
159 [[ $file =~ vcpim.* ]] && PIM_OPT="--veracrypt-pim $PIM"
160 SYS_OPT=""
161 [[ $file =~ sys_.* ]] && SYS_OPT="--tcrypt-system"
162 get_HASH_CIPHERscip-shell shell shell-project 0.0.0 get_HASH_CIPHER(). $file
163 echoscip-shell system . . echo. $PASSWORD | $CRYPTSETUP tcryptDump $SYS_OPT $PIM_OPT -h $HASH -c $CIPHER $file >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
164 if [[ $file =~ .*-sha512-xts-aes$ ]] ; then
165 echoscip-shell system . . echo. $PASSWORD | $CRYPTSETUP tcryptDump $SYS_OPT $PIM_OPT -h sha512 -c aes $file >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
166 echoscip-shell system . . echo. $PASSWORD | $CRYPTSETUP tcryptDump $SYS_OPT $PIM_OPT -h xxxx $file 2>/dev/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail().
167 echoscip-shell system . . echo. $PASSWORD | $CRYPTSETUP tcryptDump $SYS_OPT $PIM_OPT -h sha512 -c xxx $file 2>/dev/nullscip-shell filesystem . . `/dev/null`. && failscip-shell shell shell-project 0.0.0 fail().
168 fi
169 echoscip-shell system . . echo. " [OK]"
170 done
171
172 echoscip-shell system . . echo. "HEADER CHECK (TCRYPT only)"
173 for file in $(lsscip-shell system . . ls. $TST_DIR/vc_* $TST_DIR/vcpim_*) ; do
174 echoscip-shell system . . echo. -n " $file"
175 PIM_OPT=""
176 [[ $file =~ vcpim.* ]] && PIM_OPT="--veracrypt-pim $PIM"
177 get_HASH_CIPHERscip-shell shell shell-project 0.0.0 get_HASH_CIPHER(). $file
178 echoscip-shell system . . echo. $PASSWORD | $CRYPTSETUP tcryptDump --disable-veracrypt $PIM_OPT -h $HASH -c $CIPHER $file >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 && failscip-shell shell shell-project 0.0.0 fail().
179 echoscip-shell system . . echo. " [OK]"
180 done
181
182 echoscip-shell system . . echo. "HEADER CHECK (HIDDEN)"
183 for file in $(lsscip-shell system . . ls. $TST_DIR/[tv]c_*-hidden) ; do
184 echoscip-shell system . . echo. -n " $file (hidden)"
185 get_HASH_CIPHERscip-shell shell shell-project 0.0.0 get_HASH_CIPHER(). $file
186 echoscip-shell system . . echo. $PASSWORD_HIDDEN | $CRYPTSETUP tcryptDump --tcrypt-hidden -h $HASH -c $CIPHER $file >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
187 echoscip-shell system . . echo. " [OK]"
188 done
189
190 echoscip-shell system . . echo. "HEADER KEYFILES CHECK"
191 for file in $(lsscip-shell system . . ls. $TST_DIR/[tv]ck_*) ; do
192 echoscip-shell system . . echo. -n " $file"
193 PWD=$PASSWORD
194 [[ $file =~ vck_1_nopw.* ]] && PWD=""
195 [[ $file =~ vck_1_pw72.* ]] && PWD=$PASSWORD_72C
196 get_HASH_CIPHERscip-shell shell shell-project 0.0.0 get_HASH_CIPHER(). $file
197 echoscip-shell system . . echo. $PWD | $CRYPTSETUP tcryptDump -d $TST_DIR/keyfile1 -d $TST_DIR/keyfile2 -h $HASH -c $CIPHER $file >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
198 echoscip-shell system . . echo. " [OK]"
199 done
200
201 if [scip-shell system . . `[`. $(idscip-shell system . . id. -u) != 0 ]; then
202 echoscip-shell system . . echo. "WARNING: You must be root to run activation part of test, test skipped."
203 remove_mappingscip-shell shell shell-project 0.0.0 remove_mapping().
204 exit 0
205 fi
206
207 echoscip-shell system . . echo. "ACTIVATION FS UUID CHECK"
208 for file in $(lsscip-shell system . . ls. $TST_DIR/[tv]c_* $TST_DIR/vcpim_*) ; do
209 echoscip-shell system . . echo. -n " $file"
210 PIM_OPT=""
211 [[ $file =~ vcpim.* ]] && PIM_OPT="--veracrypt-pim $PIM"
212 get_HASH_CIPHERscip-shell shell shell-project 0.0.0 get_HASH_CIPHER(). $file
213 out=$(echoscip-shell system . . echo. $PASSWORD | $CRYPTSETUP tcryptOpen $PIM_OPT -r -h $HASH -c $CIPHER $file $MAP 2>&1)
214 ret=$?
215 [scip-shell system . . `[`. $ret -eq 1 ] && ( echoscip-shell system . . echo. "$out" | grepscip-shell system . . grep. -q -e "TCRYPT legacy mode" ) && echoscip-shell system . . echo. " [N/A]" && continue
216 [scip-shell system . . `[`. $ret -eq 1 ] && ( echoscip-shell system . . echo. "$out" | grepscip-shell system . . grep. -q -e "TCRYPT compatible mapping" ) && echoscip-shell system . . echo. " [N/A]" && continue
217 [scip-shell system . . `[`. $ret -ne 0 ] && failscip-shell shell shell-project 0.0.0 fail().
218 $CRYPTSETUP status $MAP >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
219 $CRYPTSETUP status /dev/mapper/$MAP >/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
220 check_uuidscip-shell shell shell-project 0.0.0 check_uuid(). DEAD-BABE
221 $CRYPTSETUP close $MAP || failscip-shell shell shell-project 0.0.0 fail().
222 echoscip-shell system . . echo. " [OK]"
223 done
224
225 echoscip-shell system . . echo. "ACTIVATION SYSTEM FS UUID CHECK"
226 for file in $(lsscip-shell system . . ls. $TST_DIR/sys_[tv]c_*) ; do
227 echoscip-shell system . . echo. -n " $file"
228 LOOP_SYS=$(losetupscip-shell system . . losetup. -r -f --show -P $file)
229 if [scip-shell system . . `[`. -z "$LOOP_SYS" ]; then
230 echoscip-shell system . . echo. " [N/A]"
231 continue
232 fi
233 if [[ $file =~ _gpt_ ]]; then
234 LOOP_PART="$LOOP_SYS"p3
235 else
236 LOOP_PART="$LOOP_SYS"p1
237 fi
238 if [scip-shell system . . `[`. ! -b "$LOOP_PART" ]; then
239 echoscip-shell system . . echo. " [N/A]"
240 losetupscip-shell system . . losetup. -d $LOOP_SYS
241 LOOP_SYS=""
242 continue
243 fi
244 get_HASH_CIPHERscip-shell shell shell-project 0.0.0 get_HASH_CIPHER(). $file
245 # map through partition name
246 echoscip-shell system . . echo. -n " [PART]"
247 echoscip-shell system . . echo. $PASSWORD | $CRYPTSETUP tcryptOpen --tcrypt-system -r -h $HASH -c $CIPHER $LOOP_PART $MAP || failscip-shell shell shell-project 0.0.0 fail().
248 check_uuidscip-shell shell shell-project 0.0.0 check_uuid(). DEAD-BABE
249 $CRYPTSETUP close $MAP || failscip-shell shell shell-project 0.0.0 fail().
250 if [[ $file =~ _part ]]; then
251 # map through image only (TCRYPT hdr contains partition offset and size)
252 echoscip-shell system . . echo. -n "[IMG]"
253 echoscip-shell system . . echo. $PASSWORD | $CRYPTSETUP tcryptOpen --tcrypt-system -r -h $HASH -c $CIPHER $file $MAP 2>/dev/nullscip-shell filesystem . . `/dev/null`. || failscip-shell shell shell-project 0.0.0 fail().
254 check_uuidscip-shell shell shell-project 0.0.0 check_uuid(). DEAD-BABE
255 $CRYPTSETUP close $MAP || failscip-shell shell shell-project 0.0.0 fail().
256 # map through full device (TCRYPT hdr contains partition offset and size)
257 echoscip-shell system . . echo. -n "[DRIVE]"
258 echoscip-shell system . . echo. $PASSWORD | $CRYPTSETUP tcryptOpen --tcrypt-system -r -h $HASH -c $CIPHER $LOOP_SYS $MAP || failscip-shell shell shell-project 0.0.0 fail().
259 check_uuidscip-shell shell shell-project 0.0.0 check_uuid(). DEAD-BABE
260 $CRYPTSETUP close $MAP || failscip-shell shell shell-project 0.0.0 fail().
261 elif [[ $file =~ _full ]]; then
262 # map through image + header in real partition (whole system)
263 ddscip-shell system . . dd. if=$LOOP_PART of=$PART_IMG bs=1M >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
264 echoscip-shell system . . echo. -n "[PART+IMG]"
265 echoscip-shell system . . echo. $PASSWORD | $CRYPTSETUP tcryptOpen --tcrypt-system -r -h $HASH -c $CIPHER --header $LOOP_PART $PART_IMG $MAP || failscip-shell shell shell-project 0.0.0 fail().
266 check_uuidscip-shell shell shell-project 0.0.0 check_uuid(). DEAD-BABE
267 $CRYPTSETUP close $MAP || failscip-shell shell shell-project 0.0.0 fail().
268 rmscip-shell system . . rm. $PART_IMG
269 fi
270 losetupscip-shell system . . losetup. -d $LOOP_SYS
271 LOOP_SYS=""
272 echoscip-shell system . . echo. " [OK]"
273 done
274
275 echoscip-shell system . . echo. "ACTIVATION FS UUID (HIDDEN) CHECK"
276 for file in $(lsscip-shell system . . ls. $TST_DIR/[tv]c_*-hidden) ; do
277 echoscip-shell system . . echo. -n " $file"
278 get_HASH_CIPHERscip-shell shell shell-project 0.0.0 get_HASH_CIPHER(). $file
279 out=$(echoscip-shell system . . echo. $PASSWORD_HIDDEN | $CRYPTSETUP tcryptOpen -r -h $HASH -c $CIPHER $file $MAP --tcrypt-hidden 2>&1)
280 ret=$?
281 [scip-shell system . . `[`. $ret -eq 1 ] && ( echoscip-shell system . . echo. "$out" | grepscip-shell system . . grep. -q -e "TCRYPT legacy mode" ) && echoscip-shell system . . echo. " [N/A]" && continue
282 [scip-shell system . . `[`. $ret -eq 1 ] && ( echoscip-shell system . . echo. "$out" | grepscip-shell system . . grep. -q -e "TCRYPT compatible mapping" ) && echoscip-shell system . . echo. " [N/A]" && continue
283 [scip-shell system . . `[`. $ret -ne 0 ] && failscip-shell shell shell-project 0.0.0 fail().
284 check_uuidscip-shell shell shell-project 0.0.0 check_uuid(). CAFE-BABE
285 $CRYPTSETUP close $MAP || failscip-shell shell shell-project 0.0.0 fail().
286 echoscip-shell system . . echo. " [OK]"
287 done
288
289 remove_mappingscip-shell shell shell-project 0.0.0 remove_mapping().
290 exit 0