| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Test using v1 encryption policies (deprecated). |
| 4 |
|
| 5 |
cd "$(dirname "$0")" |
| 6 |
. common.sh |
| 7 |
|
| 8 |
_setup_session_keyring |
| 9 |
trap _cleanup_user_keyrings EXIT |
| 10 |
|
| 11 |
dir="$MNT/dir" |
| 12 |
mkdir "$dir" |
| 13 |
chown "$TEST_USER" "$dir" |
| 14 |
|
| 15 |
_print_header "Set policy_version 1" |
| 16 |
sed -E -i 's/"policy_version": +"2"/"policy_version": "1"/' "$FSCRYPT_CONF" |
| 17 |
|
| 18 |
_print_header "Try to encrypt as root" |
| 19 |
_expect_failure "echo hunter2 | fscrypt encrypt --quiet --name=prot '$dir'" |
| 20 |
|
| 21 |
_print_header "Try to use --user=root as user" |
| 22 |
_user_do_and_expect_failure "echo hunter2 | fscrypt encrypt --quiet --name=prot --user=root '$dir'" |
| 23 |
|
| 24 |
_print_header "Try to encrypt without user keyring in session keyring" |
| 25 |
_user_do "keyctl unlink @u @s" |
| 26 |
_user_do_and_expect_failure "echo hunter2 | fscrypt encrypt --quiet --name=prot '$dir'" |
| 27 |
_user_do "keyctl link @u @s" |
| 28 |
|
| 29 |
_print_header "Encrypt a directory" |
| 30 |
_user_do "echo hunter2 | fscrypt encrypt --quiet --name=prot '$dir'" |
| 31 |
|
| 32 |
_print_header "Get dir status as user" |
| 33 |
_user_do "fscrypt status '$dir'" |
| 34 |
|
| 35 |
_print_header "Get dir status as root" |
| 36 |
fscrypt status "$dir" |
| 37 |
|
| 38 |
_print_header "Create files in v1-encrypted directory" |
| 39 |
echo contents > "$dir/file" |
| 40 |
mkdir "$dir/subdir" |
| 41 |
ln -s target "$dir/symlink" |
| 42 |
|
| 43 |
# Due to the limitations of the v1 key management mechanism, 'fscrypt lock' only |
| 44 |
# works when run as root and with the --user argument. |
| 45 |
|
| 46 |
_print_header "Try to lock v1-encrypted directory as user" |
| 47 |
_user_do_and_expect_failure "fscrypt lock '$dir'" |
| 48 |
_user_do "fscrypt status '$dir'" |
| 49 |
|
| 50 |
_print_header "Try to lock v1-encrypted directory as root without --user" |
| 51 |
_expect_failure "fscrypt lock '$dir'" |
| 52 |
_user_do "fscrypt status '$dir'" |
| 53 |
|
| 54 |
_print_header "Lock v1-encrypted directory" |
| 55 |
fscrypt lock "$dir" --user="$TEST_USER" |
| 56 |
_user_do "fscrypt status '$dir'" |
| 57 |
_expect_failure "cat '$dir/file'" |
| 58 |
|
| 59 |
# 'fscrypt lock' and 'fscrypt status' implement a heuristic that should detect |
| 60 |
# the "files busy" case with v1. |
| 61 |
_print_header "Testing incompletely locking v1-encrypted directory" |
| 62 |
_user_do "echo hunter2 | fscrypt unlock '$dir'" |
| 63 |
exec 3<"$dir/file" |
| 64 |
_expect_failure "fscrypt lock '$dir' --user='$TEST_USER'" |
| 65 |
_user_do "fscrypt status '$dir'" |
| 66 |
# ... except in this case, because we can't detect it without a directory path. |
| 67 |
_user_do "fscrypt status '$MNT'" |
| 68 |
exec 3<&- |
| 69 |
_print_header "Finishing locking v1-encrypted directory" |
| 70 |
fscrypt lock "$dir" --user="$TEST_USER" |
| 71 |
_user_do "fscrypt status '$dir'" |
| 72 |
_expect_failure "cat '$dir/file'" |