| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Test encrypting a directory using a raw_key protector. |
| 4 |
|
| 5 |
cd "$(dirname "$0")" |
| 6 |
. common.sh |
| 7 |
|
| 8 |
dir="$MNT/dir" |
| 9 |
raw_key_file="$TMPDIR/raw_key" |
| 10 |
|
| 11 |
begin() |
| 12 |
{ |
| 13 |
_reset_filesystems |
| 14 |
mkdir "$dir" |
| 15 |
_print_header "$1" |
| 16 |
} |
| 17 |
|
| 18 |
show_status() |
| 19 |
{ |
| 20 |
local encrypted=$1 |
| 21 |
|
| 22 |
fscrypt status "$MNT" |
| 23 |
if $encrypted; then |
| 24 |
fscrypt status "$dir" |
| 25 |
else |
| 26 |
_expect_failure "fscrypt status '$dir'" |
| 27 |
fi |
| 28 |
} |
| 29 |
|
| 30 |
begin "Encrypt with raw_key protector from file" |
| 31 |
head -c 32 /dev/urandom > "$raw_key_file" |
| 32 |
fscrypt encrypt --quiet --name=prot --source=raw_key --key="$raw_key_file" "$dir" |
| 33 |
show_status true |
| 34 |
|
| 35 |
begin "Encrypt with raw_key protector from stdin" |
| 36 |
head -c 32 /dev/urandom | fscrypt encrypt --quiet --name=prot --source=raw_key "$dir" |
| 37 |
show_status true |
| 38 |
|
| 39 |
begin "Try to encrypt with raw_key protector from file, using wrong key length" |
| 40 |
head -c 16 /dev/urandom > "$raw_key_file" |
| 41 |
_expect_failure "fscrypt encrypt --quiet --name=prot --source=raw_key --key='$raw_key_file' '$dir'" |
| 42 |
show_status false |
| 43 |
|
| 44 |
begin "Try to encrypt with raw_key protector from stdin, using wrong key length" |
| 45 |
_expect_failure "head -c 16 /dev/urandom | fscrypt encrypt --quiet --name=prot --source=raw_key '$dir'" |
| 46 |
show_status false |
| 47 |
|
| 48 |
begin "Encrypt with raw_key protector from file, unlock from stdin" |
| 49 |
head -c 32 /dev/urandom > "$raw_key_file" |
| 50 |
fscrypt encrypt --quiet --name=prot --source=raw_key --key="$raw_key_file" "$dir" |
| 51 |
fscrypt lock "$dir" |
| 52 |
fscrypt unlock --quiet "$dir" < "$raw_key_file" |
| 53 |
show_status true |
| 54 |
|
| 55 |
begin "Try to unlock with wrong key, both with and without --quiet" |
| 56 |
head -c 32 /dev/urandom > "$raw_key_file" |
| 57 |
fscrypt encrypt --quiet --name=prot --source=raw_key --key="$raw_key_file" "$dir" |
| 58 |
fscrypt lock "$dir" |
| 59 |
head -c 32 /dev/urandom > "$raw_key_file" |
| 60 |
_expect_failure "fscrypt unlock --quiet --key='$raw_key_file' '$dir'" |
| 61 |
_expect_failure "fscrypt unlock --key='$raw_key_file' '$dir'" |
| 62 |
show_status true |