Verify the whole release folder in core and rebuild packaged sources (#57)

Address the code review of the carried-over work:
- scripts/package extracts the snapshot with fresh mtimes, so the shared
  target never reuses a workspace crate built from other sources.
- core::verify_release owns the release-folder contract (file names, size
  limits, signature, identity, digest) and returns Error::InvalidUpdate; it is
  tested natively with real folders, oversized manifests and missing files.
- The app's --verify-release only adds the build identity and commit check.
- French script messages, clearer path helpers, accurate Velopack stub facts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-11-20 10:43:02 +01:00
1 parent f90ae109b9
commit 18e9db54fc
7 files changed
+134 -85

No files matched your search

+40 -15
View File
@@ -1,9 +1,13 @@
use std::io::{self, Read};
use std::fs::File;
use std::io::Read;
use std::path::Path;
use base64::prelude::{BASE64_STANDARD, Engine};
use ring::{digest, signature};
use serde::Deserialize;
use crate::Error;
#[derive(Deserialize)]
struct Manifest {
app: String,
@@ -15,39 +19,60 @@ struct Manifest {
sha256: String,
}
/// Verifies the signed manifest and hashes the unopened archive format as a byte stream.
/// Returns the authenticated source commit. Callers must keep these bytes isolated until success.
pub fn verify_update_package(
/// Verifies a release folder: the signed manifest, then the digest of the package read as a plain
/// byte stream, never as an archive. Returns the authenticated source commit.
/// Callers must keep these bytes isolated until success, then apply exactly these bytes.
pub fn verify_release(
dir: &Path,
public_key: &[u8],
channel: &str,
version: &str,
manifest: &[u8],
signature: &[u8],
mut package: impl Read,
) -> io::Result<String> {
) -> Result<String, Error> {
let rejected = |why: String| Error::InvalidUpdate(why);
let open = |name: &str| {
File::open(dir.join(name)).map_err(|e| rejected(format!("{name} illisible ({e})")))
};
let read = |name: &str, limit: u64| {
let mut bytes = Vec::new();
open(name)?
.take(limit + 1)
.read_to_end(&mut bytes)
.map_err(|e| rejected(format!("{name} illisible ({e})")))?;
if bytes.len() as u64 > limit {
return Err(rejected(format!("{name} trop volumineux")));
}
Ok(bytes)
};
let manifest = read(&format!("release-{channel}.json"), 4096)?;
let signed = read(&format!("release-{channel}.sig"), 64)?;
signature::UnparsedPublicKey::new(&signature::ED25519, public_key)
.verify(manifest, signature)
.map_err(|_| io::Error::other("Invalid update signature"))?;
let release: Manifest = serde_json::from_slice(manifest)?;
.verify(&manifest, &signed)
.map_err(|_| rejected("signature invalide".into()))?;
let release: Manifest = serde_json::from_slice(&manifest)
.map_err(|e| rejected(format!("manifeste illisible ({e})")))?;
let package = format!("ArenaTracker-{version}-{channel}-full.nupkg");
if release.app != "ArenaTracker"
|| release.target != "win-x64"
|| release.channel != channel
|| release.version != version
|| release.package != format!("ArenaTracker-{version}-{channel}-full.nupkg")
|| release.package != package
{
return Err(io::Error::other("Unexpected update identity"));
return Err(rejected("identité inattendue".into()));
}
let mut file = open(&package)?;
let mut hash = digest::Context::new(&digest::SHA256);
let mut buffer = [0; 64 * 1024];
loop {
let n = package.read(&mut buffer)?;
let n = file
.read(&mut buffer)
.map_err(|e| rejected(format!("{package} illisible ({e})")))?;
if n == 0 {
break;
}
hash.update(&buffer[..n]);
}
if release.sha256 != BASE64_STANDARD.encode(hash.finish().as_ref()) {
return Err(io::Error::other("Update digest mismatch"));
return Err(rejected("condensat du paquet différent".into()));
}
Ok(release.commit)
}