Package a per-user Windows installer and signed full update packages (#57)
Work in progress carried over from the main checkout: scripts/package builds one version from one commit, packs it with vpk 1.2.161 (full packages only), signs a manifest with Ed25519 and checks the result with the built executable. The core verifies the signed manifest and package digest before any unpacking. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6d07a9641f
commit
f90ae109b9
12 files changed
+395
No files matched your search
@@ -0,0 +1,53 @@
|
||||
use std::io::{self, Read};
|
||||
|
||||
use base64::prelude::{BASE64_STANDARD, Engine};
|
||||
use ring::{digest, signature};
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Manifest {
|
||||
app: String,
|
||||
target: String,
|
||||
channel: String,
|
||||
version: String,
|
||||
commit: String,
|
||||
package: String,
|
||||
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(
|
||||
public_key: &[u8],
|
||||
channel: &str,
|
||||
version: &str,
|
||||
manifest: &[u8],
|
||||
signature: &[u8],
|
||||
mut package: impl Read,
|
||||
) -> io::Result<String> {
|
||||
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)?;
|
||||
if release.app != "ArenaTracker"
|
||||
|| release.target != "win-x64"
|
||||
|| release.channel != channel
|
||||
|| release.version != version
|
||||
|| release.package != format!("ArenaTracker-{version}-{channel}-full.nupkg")
|
||||
{
|
||||
return Err(io::Error::other("Unexpected update identity"));
|
||||
}
|
||||
let mut hash = digest::Context::new(&digest::SHA256);
|
||||
let mut buffer = [0; 64 * 1024];
|
||||
loop {
|
||||
let n = package.read(&mut buffer)?;
|
||||
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"));
|
||||
}
|
||||
Ok(release.commit)
|
||||
}
|
||||
Reference in new issue
Block a user