Debian Codegraph @

cli-tests/t_metadata.sh

raw
1 #!/bin/bash
2
3 # Test 'fscrypt metadata'.
4
5 cd "$(dirname "$0")"
6 . common.sh
7
8 # Create three protectors, and a policy protected by them.
9 echo foo | fscrypt metadata create protector "$MNT" \
10 --quiet --name=foo --source=custom_passphrase
11 echo bar | fscrypt metadata create protector "$MNT" \
12 --quiet --name=bar --source=custom_passphrase
13 echo baz | fscrypt metadata create protector "$MNT" \
14 --quiet --name=baz --source=custom_passphrase
15 prot_foo=$MNT:$(_get_protector_descriptor "$MNT" custom foo)
16 prot_bar=$MNT:$(_get_protector_descriptor "$MNT" custom bar)
17 desc_baz=$(_get_protector_descriptor "$MNT" custom baz)
18 prot_baz=$MNT:$desc_baz
19 echo foo | fscrypt metadata create policy "$MNT" --quiet \
20 --protector="$prot_foo"
21 policy=$MNT:$(fscrypt status "$MNT" | grep -A10 "^POLICY" | \
22 tail -1 | awk '{print $1}')
23 echo -e "bar\nfoo" | fscrypt metadata add-protector-to-policy --quiet \
24 --policy="$policy" --protector="$prot_bar"
25 echo -e "baz\nfoo" | fscrypt metadata add-protector-to-policy --quiet \
26 --policy="$policy" --protector="$prot_baz" --unlock-with="$prot_foo"
27 fscrypt status "$MNT"
28
29 # Remove two of the protectors from the policy.
30 # Make sure that this works even if the protector was already deleted.
31 fscrypt metadata remove-protector-from-policy --quiet --force \
32 --policy="$policy" --protector="$prot_bar"
33 rm "$MNT/.fscrypt/protectors/$desc_baz"
34 fscrypt metadata remove-protector-from-policy --quiet --force \
35 --policy="$policy" --protector="$prot_baz"
36 fscrypt status "$MNT"