generic/554: hide permision warning on exfat
[xfstests-dev.git] / tests / generic / 577
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright 2019 Google LLC
4 #
5 # FS QA Test generic/577
6 #
7 # Test the fs-verity built-in signature verification support.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1        # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         _restore_fsverity_signatures
22         rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/verity
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 # real QA test starts here
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 fsv_file=$SCRATCH_MNT/file.fsv
42 fsv_orig_file=$SCRATCH_MNT/file
43 keyfile=$tmp.key.pem
44 certfile=$tmp.cert.pem
45 certfileder=$tmp.cert.der
46 sigfile=$tmp.sig
47 otherfile=$SCRATCH_MNT/otherfile
48 othersigfile=$tmp.othersig
49
50 # Setup
51
52 echo -e "\n# Generating certificates and private keys"
53 for suffix in '' '.2'; do
54         _fsv_generate_cert $keyfile$suffix $certfile$suffix $certfileder$suffix
55 done
56
57 echo -e "\n# Clearing fs-verity keyring"
58 _fsv_clear_keyring
59
60 echo -e "\n# Loading first certificate into fs-verity keyring"
61 _fsv_load_cert $certfileder
62
63 echo -e "\n# Enabling fs.verity.require_signatures"
64 _enable_fsverity_signatures
65
66 echo -e "\n# Generating file and signing it for fs-verity"
67 head -c 100000 /dev/zero > $fsv_orig_file
68 for suffix in '' '.2'; do
69         _fsv_sign $fsv_orig_file $sigfile$suffix --key=$keyfile$suffix \
70                 --cert=$certfile$suffix | _filter_scratch
71 done
72
73 echo -e "\n# Signing a different file for fs-verity"
74 head -c 100000 /dev/zero | tr '\0' 'X' > $otherfile
75 _fsv_sign $otherfile $othersigfile --key=$keyfile --cert=$certfile \
76         | _filter_scratch
77
78 # Actual tests
79
80 reset_fsv_file()
81 {
82         rm -f $fsv_file
83         cp $fsv_orig_file $fsv_file
84 }
85
86 echo -e "\n# Enabling verity with valid signature (should succeed)"
87 reset_fsv_file
88 _fsv_enable $fsv_file --signature=$sigfile
89 cmp $fsv_file $fsv_orig_file
90
91 echo -e "\n# Enabling verity without signature (should fail)"
92 reset_fsv_file
93 _fsv_enable $fsv_file |& _filter_scratch
94
95 echo -e "\n# Opening verity file without signature (should fail)"
96 reset_fsv_file
97 _disable_fsverity_signatures
98 _fsv_enable $fsv_file
99 _enable_fsverity_signatures
100 _scratch_cycle_mount
101 md5sum $fsv_file |& _filter_scratch
102
103 echo -e "\n# Enabling verity with untrusted signature (should fail)"
104 reset_fsv_file
105 _fsv_enable $fsv_file --signature=$sigfile.2 |& _filter_scratch
106
107 echo -e "\n# Enabling verity with wrong file's signature (should fail)"
108 reset_fsv_file
109 _fsv_enable $fsv_file --signature=$othersigfile |& _filter_scratch
110
111 echo -e "\n# Enabling verity with malformed signature (should fail)"
112 echo foobarbaz > $tmp.malformed_sig
113 reset_fsv_file
114 _fsv_enable $fsv_file --signature=$tmp.malformed_sig |& _filter_scratch
115
116 echo -e "\n# Testing salt"
117 reset_fsv_file
118 _fsv_sign $fsv_orig_file $sigfile.salted --key=$keyfile --cert=$certfile \
119         --salt=abcd | _filter_scratch
120 _fsv_enable $fsv_file --signature=$sigfile.salted --salt=abcd
121 cmp $fsv_file $fsv_orig_file
122
123 echo -e "\n# Testing non-default hash algorithm"
124 if _fsv_have_hash_algorithm sha512 $fsv_file; then
125         reset_fsv_file
126         _fsv_sign $fsv_orig_file $sigfile.sha512 --key=$keyfile \
127                 --cert=$certfile --hash-alg=sha512 > /dev/null
128         _fsv_enable $fsv_file --signature=$sigfile.sha512 --hash-alg=sha512
129         cmp $fsv_file $fsv_orig_file
130 fi
131
132 echo -e "\n# Testing empty file"
133 echo -n > $fsv_file
134 _fsv_sign $fsv_file $sigfile.emptyfile --key=$keyfile --cert=$certfile | \
135                 _filter_scratch
136 _fsv_enable $fsv_file --signature=$sigfile.emptyfile
137
138 # success, all done
139 status=0
140 exit