v0.25.5
This commit is contained in:
1 parent
1dea7f55c8
commit
c819f0a335
151 files changed
+7610
-4264
No files matched your search
+35
-9
@@ -144,7 +144,10 @@ fn harden_tree(root: &Path, path: &Path) -> Result<()> {
|
||||
if metadata.file_type().is_symlink() {
|
||||
let resolved = fs::canonicalize(path).context("restored symlink target is missing")?;
|
||||
let canonical_root = fs::canonicalize(root)?;
|
||||
ensure!(resolved.starts_with(&canonical_root), "restored symlink escapes the data directory");
|
||||
ensure!(
|
||||
resolved.starts_with(&canonical_root),
|
||||
"restored symlink escapes the data directory"
|
||||
);
|
||||
return Ok(());
|
||||
}
|
||||
#[cfg(unix)]
|
||||
@@ -164,7 +167,10 @@ fn harden_tree(root: &Path, path: &Path) -> Result<()> {
|
||||
fn private_dir(path: &Path) -> Result<()> {
|
||||
fs::create_dir_all(path)?;
|
||||
let meta = fs::symlink_metadata(path)?;
|
||||
ensure!(meta.is_dir() && !meta.file_type().is_symlink(), "backup directory must not be a symlink");
|
||||
ensure!(
|
||||
meta.is_dir() && !meta.file_type().is_symlink(),
|
||||
"backup directory must not be a symlink"
|
||||
);
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
@@ -337,13 +343,19 @@ fn encrypt_archive(input: &Path, output: &Path, crypto: &CryptoContext) -> Resul
|
||||
|
||||
fn decrypt_archive(input: &Path, output: &Path, password: &str) -> Result<Zeroizing<[u8; 32]>> {
|
||||
let metadata = fs::symlink_metadata(input)?;
|
||||
ensure!(metadata.is_file() && !metadata.file_type().is_symlink(), "backup must be a regular file");
|
||||
ensure!(
|
||||
metadata.is_file() && !metadata.file_type().is_symlink(),
|
||||
"backup must be a regular file"
|
||||
);
|
||||
let mut source = File::open(input)?;
|
||||
let mut magic = [0u8; 8];
|
||||
source.read_exact(&mut magic)?;
|
||||
ensure!(&magic == BACKUP_MAGIC, "not a RustProxy backup");
|
||||
let header_len = read_u32(&mut source)? as usize;
|
||||
ensure!(header_len > 0 && header_len <= MAX_HEADER_BYTES, "invalid backup header length");
|
||||
ensure!(
|
||||
header_len > 0 && header_len <= MAX_HEADER_BYTES,
|
||||
"invalid backup header length"
|
||||
);
|
||||
let mut header_bytes = vec![0u8; header_len];
|
||||
source.read_exact(&mut header_bytes)?;
|
||||
let crypto = parse_crypto_header(header_bytes, password)?;
|
||||
@@ -372,7 +384,10 @@ fn decrypt_archive(input: &Path, output: &Path, password: &str) -> Result<Zeroiz
|
||||
counter = counter.checked_add(1).context("backup is too large")?;
|
||||
}
|
||||
let mut extra = [0u8; 1];
|
||||
ensure!(source.read(&mut extra)? == 0, "trailing data after encrypted backup");
|
||||
ensure!(
|
||||
source.read(&mut extra)? == 0,
|
||||
"trailing data after encrypted backup"
|
||||
);
|
||||
target.sync_all()?;
|
||||
Ok(crypto.key)
|
||||
}
|
||||
@@ -398,7 +413,10 @@ fn seal_master_key(master: &[u8], backup_key: &[u8]) -> Result<Vec<u8>> {
|
||||
}
|
||||
|
||||
fn open_master_key(blob: &[u8], backup_key: &[u8]) -> Result<Zeroizing<Vec<u8>>> {
|
||||
ensure!(blob.len() == 4 + 12 + 32 + AES_256_GCM.tag_len(), "invalid wrapped secret store key");
|
||||
ensure!(
|
||||
blob.len() == 4 + 12 + 32 + AES_256_GCM.tag_len(),
|
||||
"invalid wrapped secret store key"
|
||||
);
|
||||
ensure!(&blob[..4] == KEY_MAGIC, "invalid wrapped secret store key");
|
||||
let mut nonce_bytes = [0u8; 12];
|
||||
nonce_bytes.copy_from_slice(&blob[4..16]);
|
||||
@@ -416,7 +434,10 @@ fn open_master_key(blob: &[u8], backup_key: &[u8]) -> Result<Zeroizing<Vec<u8>>>
|
||||
|
||||
fn hash_file(path: &Path) -> Result<(u64, String)> {
|
||||
let metadata = fs::symlink_metadata(path)?;
|
||||
ensure!(metadata.is_file() && !metadata.file_type().is_symlink(), "backup input must be a regular file");
|
||||
ensure!(
|
||||
metadata.is_file() && !metadata.file_type().is_symlink(),
|
||||
"backup input must be a regular file"
|
||||
);
|
||||
let mut file = File::open(path)?;
|
||||
let mut hasher = Sha256::new();
|
||||
let mut size = 0u64;
|
||||
@@ -426,7 +447,9 @@ fn hash_file(path: &Path) -> Result<(u64, String)> {
|
||||
if read == 0 {
|
||||
break;
|
||||
}
|
||||
size = size.checked_add(read as u64).context("backup input too large")?;
|
||||
size = size
|
||||
.checked_add(read as u64)
|
||||
.context("backup input too large")?;
|
||||
hasher.update(&buffer[..read]);
|
||||
}
|
||||
Ok((size, format!("{:x}", hasher.finalize())))
|
||||
@@ -437,5 +460,8 @@ fn hash_bytes(bytes: &[u8]) -> String {
|
||||
}
|
||||
|
||||
fn excluded_directory(name: &str) -> bool {
|
||||
matches!(name, "cache" | "logs" | "tmp" | "temp" | "work" | "acme-http01")
|
||||
matches!(
|
||||
name,
|
||||
"cache" | "logs" | "tmp" | "temp" | "work" | "acme-http01"
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user