Debian Codegraph @

cli-tests/t_unlock.sh

raw
1 #!/bin/bash
2
3 # Test unlocking a directory.
4
5 cd "$(dirname "$0")"
6 . common.sh
7
8 dir="$MNT/dir"
9 mkdir "$dir"
10
11 _print_header "Encrypt directory with --skip-unlock"
12 echo hunter2 | fscrypt encrypt --quiet --name=prot --skip-unlock "$dir"
13 _print_header "=> Check dir status"
14 fscrypt status "$dir"
15 _expect_failure "touch '$dir/file'"
16 policy=$(fscrypt status "$dir" | awk '/Policy:/{print $2}')
17 _print_header "=> Get policy status via mount:"
18 fscrypt status "$MNT" | grep "^$policy"
19
20 _print_header "Unlock directory"
21 echo hunter2 | fscrypt unlock "$dir"
22 _print_header "=> Check dir status"
23 fscrypt status "$dir"
24 echo contents > "$dir/file"
25 _print_header "=> Get policy status via mount:"
26 fscrypt status "$MNT" | grep "^$policy"
27
28 _print_header "Lock by cycling mount"
29 umount "$MNT"
30 mount "$DEV" "$MNT"
31 _print_header "=> Check dir status"
32 fscrypt status "$dir"
33 _expect_failure "mkdir '$dir/subdir'"
34 _print_header "=> Get policy status via mount:"
35 fscrypt status "$MNT" | grep "^$policy"
36
37 _print_header "Try to unlock with wrong passphrase"
38 _expect_failure "echo bad | fscrypt unlock --quiet '$dir'"
39 fscrypt status "$dir"
40
41 _print_header "Try to unlock with no stdin"
42 _expect_failure "fscrypt unlock --quiet '$dir' </dev/null"
43 fscrypt status "$dir"
44
45 _print_header "Try to unlock with only a newline"
46 _expect_failure "echo | fscrypt unlock --quiet '$dir'"
47 fscrypt status "$dir"
48
49 _print_header "Unlock directory"
50 echo hunter2 | fscrypt unlock "$dir"
51 _print_header "=> Check dir status"
52 fscrypt status "$dir"
53 cat "$dir/file"
54 _print_header "=> Get policy status via mount:"
55 fscrypt status "$MNT" | grep "^$policy"
56
57 _print_header "Try to unlock with corrupt policy metadata"
58 umount "$MNT"
59 mount "$DEV" "$MNT"
60 echo bad > "$MNT/.fscrypt/policies/$policy"
61 _expect_failure "echo hunter2 | fscrypt unlock '$dir'"
62
63 _reset_filesystems
64
65 _print_header "Try to unlock with missing policy metadata"
66 mkdir "$dir"
67 echo hunter2 | fscrypt encrypt --quiet --name=prot --skip-unlock "$dir"
68 rm "$MNT"/.fscrypt/policies/*
69 _expect_failure "echo hunter2 | fscrypt unlock '$dir'"
70
71 _reset_filesystems
72
73 _print_header "Try to unlock with missing protector metadata"
74 mkdir "$dir"
75 echo hunter2 | fscrypt encrypt --quiet --name=prot --skip-unlock "$dir"
76 rm "$MNT"/.fscrypt/protectors/*
77 _expect_failure "echo hunter2 | fscrypt unlock '$dir'"
78
79 _print_header "Try to unlock with wrong policy metadata"
80 _reset_filesystems
81 mkdir "$MNT/dir1"
82 mkdir "$MNT/dir2"
83 echo hunter2 | fscrypt encrypt --quiet --name=dir1 --skip-unlock "$MNT/dir1"
84 echo hunter2 | fscrypt encrypt --quiet --name=dir2 --skip-unlock "$MNT/dir2"
85 policy1=$(find "$MNT/.fscrypt/policies/" -type f | head -1)
86 policy2=$(find "$MNT/.fscrypt/policies/" -type f | tail -1)
87 mv "$policy1" "$TMPDIR/policy"
88 mv "$policy2" "$policy1"
89 mv "$TMPDIR/policy" "$policy2"
90 _expect_failure "echo hunter2 | fscrypt unlock '$MNT/dir1'"