81ac1475ad
Introduce a central policy module for format and resource validation, then route header parsing, KDF acceptance, range arithmetic, and pipeline sizing through that policy. New encryptions now write v3 headers that include an authenticated key commitment, which lets decrypt reject wrong keys or passphrases before chunk processing while preserving valid v1/v2 decrypt compatibility inside the configured caps. Replace process-list-visible raw key input with --key-file, add passphrase NFC normalization, enforce stronger new-encryption passphrase/KDF floors unless --allow-weak-kdf is supplied, and add a configurable decrypt Argon2 memory ceiling. Chunk buffers in the serial, parallel, and lookahead paths now use zeroizing storage. Rework output handling around randomized create-new temporary files with Unix 0600 mode, file fsync before persist, best-effort parent directory fsync, default no-overwrite behavior, safe in-place replacement, --force, --temp-dir, and --buffer-verify for decrypt-to-stdout. Known caveat: --key-file currently reads with a single read call. That is fine for regular files but can reject short reads from pipes or process substitution. A follow-up fix will make key-file reads loop before EOF. Test Plan: - cargo fmt --check - cargo clippy --all-targets -- -D warnings - cargo test - git diff --check - cargo run -- --help Refs: fcry security hardening plan
41 lines
762 B
Rust
41 lines
762 B
Rust
// SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
use chacha20poly1305::aead;
|
|
use std::io;
|
|
|
|
#[allow(dead_code)]
|
|
#[derive(Debug)]
|
|
pub enum FcryError {
|
|
Io(io::Error),
|
|
Crypto(aead::Error),
|
|
Rng(getrandom::Error),
|
|
Format(String),
|
|
Kdf(String),
|
|
Passphrase(String),
|
|
WrongKey,
|
|
}
|
|
|
|
impl From<io::Error> for FcryError {
|
|
fn from(e: io::Error) -> Self {
|
|
FcryError::Io(e)
|
|
}
|
|
}
|
|
|
|
impl From<aead::Error> for FcryError {
|
|
fn from(e: aead::Error) -> Self {
|
|
FcryError::Crypto(e)
|
|
}
|
|
}
|
|
|
|
impl From<getrandom::Error> for FcryError {
|
|
fn from(e: getrandom::Error) -> Self {
|
|
FcryError::Rng(e)
|
|
}
|
|
}
|
|
|
|
impl From<argon2::Error> for FcryError {
|
|
fn from(e: argon2::Error) -> Self {
|
|
FcryError::Kdf(e.to_string())
|
|
}
|
|
}
|