| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# Test changing the passphrase of a custom_passphrase protector. |
| 4 |
|
| 5 |
cd "$(dirname "$0")" |
| 6 |
. common.sh |
| 7 |
|
| 8 |
dir="$MNT/dir" |
| 9 |
|
| 10 |
_print_header "Create encrypted directory" |
| 11 |
mkdir "$dir" |
| 12 |
echo pass1 | fscrypt encrypt --quiet --name=prot --skip-unlock "$dir" |
| 13 |
|
| 14 |
_print_header "Try to unlock with wrong passphrase" |
| 15 |
_expect_failure "echo pass2 | fscrypt unlock --quiet '$dir'" |
| 16 |
_expect_failure "mkdir '$dir/subdir'" |
| 17 |
protector=$(_get_protector_descriptor "$dir" custom prot) |
| 18 |
|
| 19 |
_print_header "Change passphrase" |
| 20 |
echo $'pass1\npass2' | \ |
| 21 |
fscrypt metadata change-passphrase --protector="$MNT:$protector" --quiet |
| 22 |
|
| 23 |
_print_header "Try to unlock with old passphrase" |
| 24 |
_expect_failure "echo pass1 | fscrypt unlock --quiet '$dir'" |
| 25 |
_expect_failure "mkdir '$dir/subdir'" |
| 26 |
|
| 27 |
_print_header "Unlock with new passphrase" |
| 28 |
echo pass2 | fscrypt unlock --quiet "$dir" |
| 29 |
mkdir "$dir/subdir" |
| 30 |
rmdir "$dir/subdir" |
| 31 |
|
| 32 |
_print_header "Try to change passphrase (interactively, mismatch)" |
| 33 |
expect << EOF |
| 34 |
spawn fscrypt metadata change-passphrase --protector=$MNT:$protector |
| 35 |
expect "Enter old custom passphrase" |
| 36 |
send "pass2\r" |
| 37 |
expect "Enter new custom passphrase" |
| 38 |
send "pass3\r" |
| 39 |
expect "Confirm passphrase" |
| 40 |
send "bad\r" |
| 41 |
expect eof |
| 42 |
EOF |
| 43 |
|
| 44 |
_print_header "Change passphrase (interactively)" |
| 45 |
expect << EOF |
| 46 |
spawn fscrypt metadata change-passphrase --protector=$MNT:$protector |
| 47 |
expect "Enter old custom passphrase" |
| 48 |
send "pass2\r" |
| 49 |
expect "Enter new custom passphrase" |
| 50 |
send "pass3\r" |
| 51 |
expect "Confirm passphrase" |
| 52 |
send "pass3\r" |
| 53 |
expect eof |
| 54 |
EOF |
| 55 |
|
| 56 |
_print_header "Lock, then unlock with new passphrase" |
| 57 |
fscrypt lock "$dir" |
| 58 |
_expect_failure "mkdir '$dir/subdir'" |
| 59 |
echo pass3 | fscrypt unlock --quiet "$dir" |
| 60 |
mkdir "$dir/subdir" |