Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cli-tests/t_encrypt_raw_key.out
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,25 @@ Unlocked: Yes
Protected with 1 protector:
PROTECTOR LINKED DESCRIPTION
desc11 No raw key protector "prot"

# Try to unlock with wrong key, both with and without --quiet
"MNT/dir" is now locked.
[ERROR] fscrypt unlock: incorrect key provided
[ERROR] fscrypt unlock: incorrect key provided
ext4 filesystem "MNT" has 1 protector and 1 policy.
All users can create fscrypt metadata on this filesystem.

PROTECTOR LINKED DESCRIPTION
desc16 No raw key protector "prot"

POLICY UNLOCKED PROTECTORS
desc17 No desc16
"MNT/dir" is encrypted with fscrypt.

Policy: desc17
Options: padding:32 contents:AES_256_XTS filenames:AES_256_CTS policy_version:2
Unlocked: No

Protected with 1 protector:
PROTECTOR LINKED DESCRIPTION
desc16 No raw key protector "prot"
9 changes: 9 additions & 0 deletions cli-tests/t_encrypt_raw_key.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ fscrypt encrypt --quiet --name=prot --source=raw_key --key="$raw_key_file" "$dir
fscrypt lock "$dir"
fscrypt unlock --quiet "$dir" < "$raw_key_file"
show_status true

begin "Try to unlock with wrong key, both with and without --quiet"
head -c 32 /dev/urandom > "$raw_key_file"
fscrypt encrypt --quiet --name=prot --source=raw_key --key="$raw_key_file" "$dir"
fscrypt lock "$dir"
head -c 32 /dev/urandom > "$raw_key_file"
_expect_failure "fscrypt unlock --quiet --key='$raw_key_file' '$dir'"
_expect_failure "fscrypt unlock --key='$raw_key_file' '$dir'"
show_status true
12 changes: 9 additions & 3 deletions cmd/fscrypt/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,17 @@ func makeKeyFunc(supportRetry, shouldConfirm bool, prefix string) actions.KeyFun
if !supportRetry {
panic("this KeyFunc does not support retrying")
}
// Don't retry for non-interactive sessions
if quietFlag.Value || !term.IsTerminal(stdinFd) {
// Don't retry in --quiet mode, for non-interactive
// sessions, or when a key file was specified.
if quietFlag.Value || !term.IsTerminal(stdinFd) ||
(info.Source() == metadata.SourceType_raw_key && keyFileFlag.Value != "") {
return nil, ErrWrongKey
}
fmt.Println("Incorrect Passphrase")
if info.Source() == metadata.SourceType_raw_key {
fmt.Println("Incorrect Key")
} else {
fmt.Println("Incorrect Passphrase")
}
}

switch info.Source() {
Expand Down
Loading