misc: move exit status into trap handler
[xfstests-dev.git] / tests / generic / 625
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-only
3 # Copyright 2021 Google LLC
4 #
5 # FS QA Test No. 625
6 #
7 # Test retrieving the built-in signature of a verity file using
8 # FS_IOC_READ_VERITY_METADATA.
9 #
10 # This is separate from the other tests for FS_IOC_READ_VERITY_METADATA because
11 # the fs-verity built-in signature support is optional.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16
17 here=`pwd`
18 tmp=/tmp/$$
19 status=1        # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
21
22 _cleanup()
23 {
24         cd /
25         rm -f $tmp.*
26 }
27
28 . ./common/rc
29 . ./common/filter
30 . ./common/verity
31
32 rm -f $seqres.full
33
34 _supported_fs generic
35 _require_scratch_verity
36 _require_fsverity_builtin_signatures
37
38 _scratch_mkfs_verity &>> $seqres.full
39 _scratch_mount
40
41 echo -e "\n# Setting up signed verity file"
42 _fsv_generate_cert $tmp.key $tmp.cert $tmp.cert.der
43 _fsv_clear_keyring
44 _fsv_load_cert $tmp.cert.der
45 fsv_file=$SCRATCH_MNT/file
46 echo foo > $fsv_file
47 _fsv_sign $fsv_file $tmp.sig --key=$tmp.key --cert=$tmp.cert >> $seqres.full
48 _fsv_enable $fsv_file --signature=$tmp.sig
49 _require_fsverity_dump_metadata $fsv_file
50
51 echo -e "\n# Dumping and comparing signature"
52 _fsv_dump_signature $fsv_file > $tmp.sig2
53 # The signature returned by FS_IOC_READ_VERITY_METADATA should exactly match the
54 # one we passed to FS_IOC_ENABLE_VERITY earlier.
55 cmp $tmp.sig $tmp.sig2
56
57 echo -e "\n# Dumping and comparing signature (in chunks)"
58 sig_size=$(stat -c %s $tmp.sig)
59 for (( i = 0; i < sig_size; i += 13 )); do
60         _fsv_dump_signature $fsv_file --offset=$i --length=13
61 done > $tmp.sig2
62 cmp $tmp.sig $tmp.sig2
63
64 # success, all done
65 status=0
66 exit