Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(key): report a key file too short to decrypt as damaged - #668

Open
Akayashuu wants to merge 1 commit into
rustic-rs:mainfrom
Akayashuu:fix/short-key-file
Open

Akayashuu wants to merge 1 commit into
rustic-rs:mainfrom
Akayashuu:fix/short-key-file

Conversation

@Akayashuu

Copy link
Copy Markdown
Contributor

Closes #663

A key file whose data holds fewer than 32 bytes (nonce plus MAC) failed the MAC check with C001, so find_key_in_backend skipped it like a key for another password and opening ended in C002, telling the user to retry a password that can never work.

Changes

  • KeyFile::key_from_data and KeyFile::key_from_password return an ErrorKind::Key error with code C004 when data is shorter than 32 bytes. key_from_password checks this before running scrypt.
  • find_key_in_backend no longer stops at such a file and keeps trying the other keys:
    • when a key opens, the damaged file is ignored as before;
    • when no key opens and no key rejected the password (C001), it returns the C004 error with the key_id of the damaged file, so a repository whose only key is truncated says so;
    • when some key rejected the password, it still returns C002, so is_incorrect_password() keeps working for a mistyped password, with the damaged ids in a damaged_key_files context.

Tests

In tests/keys.rs, with data cut to 20 zero bytes as in the issue:

  • the only key file truncated, opened with the right and with a wrong password: C004 and not is_incorrect_password() (both fail on main);
  • a truncated file beside key1: the right password opens, a wrong one gives C002 with the damaged id in damaged_key_files (the second fails on main).

cargo +stable fmt --all -- --check, cargo +stable clippy -p rustic_core --all-targets --all-features -- -D warnings and cargo test -p rustic_core --test keys pass locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A key file too short to decrypt is skipped as a wrong password

1 participant