Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

chore(deps): bump sha2 from 0.10.9 to 0.11.1 in /desktop (#2849)

dependabot[bot]f85172d5d3a6
diff --git a/desktop/Cargo.lock b/desktop/Cargo.lock
index 6f68321cd..f70d65cdf 100644
--- a/desktop/Cargo.lock
+++ b/desktop/Cargo.lock
@@ -242,7 +242,7 @@ dependencies = [
"reqwest 0.12.28",
"serde",
"serde_json",
- "sha2",
+ "sha2 0.11.1",
"sys-locale",
"tar",
"tauri",
@@ -273,7 +273,7 @@ dependencies = [
"semver",
"serde",
"serde_json",
- "sha2",
+ "sha2 0.11.1",
"thiserror 2.0.21",
"tokio",
"url",
@@ -337,6 +337,15 @@ dependencies = [
"generic-array",
]
+[[package]]
+name = "block-buffer"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa"
+dependencies = [
+ "hybrid-array",
+]
+
[[package]]
name = "block2"
version = "0.6.2"
@@ -564,6 +573,12 @@ dependencies = [
"crossbeam-utils",
]
+[[package]]
+name = "const-oid"
+version = "0.10.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a6ef517f0926dd24a1582492c791b6a4818a4d94e789a334894aa15b0d12f55c"
+
[[package]]
name = "const-random"
version = "0.1.18"
@@ -643,6 +658,15 @@ dependencies = [
"libc",
]
+[[package]]
+name = "cpufeatures"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566"
+dependencies = [
+ "libc",
+]
+
[[package]]
name = "crc32fast"
version = "1.5.0"
@@ -683,6 +707,15 @@ dependencies = [
"typenum",
]
+[[package]]
+name = "crypto-common"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453"
+dependencies = [
+ "hybrid-array",
+]
+
[[package]]
name = "cssparser"
version = "0.37.0"
@@ -793,8 +826,19 @@ version = "0.10.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
- "block-buffer",
- "crypto-common",
+ "block-buffer 0.10.4",
+ "crypto-common 0.1.7",
+]
+
+[[package]]
+name = "digest"
+version = "0.11.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2"
+dependencies = [
+ "block-buffer 0.12.1",
+ "const-oid",
+ "crypto-common 0.2.2",
]
[[package]]
@@ -1626,6 +1670,15 @@ version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
+[[package]]
+name = "hybrid-array"
+version = "0.4.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17"
+dependencies = [
+ "typenum",
+]
+
[[package]]
name = "hyper"
version = "1.11.0"
@@ -3522,8 +3575,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283"
dependencies = [
"cfg-if",
- "cpufeatures",
- "digest",
+ "cpufeatures 0.2.17",
+ "digest 0.10.7",
+]
+
+[[package]]
+name = "sha2"
+version = "0.11.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19"
+dependencies = [
+ "cfg-if",
+ "cpufeatures 0.3.1",
+ "digest 0.11.3",
]
[[package]]
@@ -3928,7 +3992,7 @@ dependencies = [
"semver",
"serde",
"serde_json",
- "sha2",
+ "sha2 0.10.9",
"syn 2.0.119",
"tauri-utils",
"thiserror 2.0.21",
@@ -5530,7 +5594,7 @@ dependencies = [
"once_cell",
"percent-encoding",
"raw-window-handle",
- "sha2",
+ "sha2 0.10.9",
"soup3",
"tao-macros",
"thiserror 2.0.21",
diff --git a/desktop/Cargo.toml b/desktop/Cargo.toml
index 891273abc..ef08142ff 100644
--- a/desktop/Cargo.toml
+++ b/desktop/Cargo.toml
@@ -13,7 +13,7 @@ async-trait = "0.1"
reqwest = { version = "0.12", default-features = false }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
-sha2 = "0.10"
+sha2 = "0.11"
sys-locale = "0.3.2"
thiserror = "2"
tokio = { version = "1", default-features = false, features = ["rt", "time"] }
diff --git a/desktop/runtime-host/src/computer_use.rs b/desktop/runtime-host/src/computer_use.rs
index 574a61843..c7d4eac61 100644
--- a/desktop/runtime-host/src/computer_use.rs
+++ b/desktop/runtime-host/src/computer_use.rs
@@ -689,17 +689,18 @@ mod tests {
#[test]
fn tool_snapshot_digest_matches_the_runtime_pin() {
+ use crate::hashing::lower_hex;
use sha2::{Digest, Sha256};
const SNAPSHOT: &[u8] =
include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../cua-driver/tools-v0.31.0.json"));
- let actual = format!("{:x}", Sha256::digest(SNAPSHOT));
+ let actual = lower_hex(&Sha256::digest(SNAPSHOT));
assert_eq!(actual, COMPUTER_USE_TOOL_SNAPSHOT_SHA256);
let mut mutated = SNAPSHOT.to_vec();
mutated[0] ^= 1;
assert_ne!(
- format!("{:x}", Sha256::digest(mutated)),
+ lower_hex(&Sha256::digest(mutated)),
COMPUTER_USE_TOOL_SNAPSHOT_SHA256,
"a changed snapshot must fail the runtime pin"
);
diff --git a/desktop/runtime-host/src/hashing.rs b/desktop/runtime-host/src/hashing.rs
new file mode 100644
index 000000000..7de865070
--- /dev/null
+++ b/desktop/runtime-host/src/hashing.rs
@@ -0,0 +1,148 @@
+//! Byte-preserving SHA-256 I/O and formatting shared by desktop consumers.
+//!
+//! sha2 0.11 no longer implements `io::Write` for hashers or `LowerHex` for
+//! digest output. Keep the file stream and persisted lowercase hex unchanged.
+use sha2::{Digest, Sha256};
+use std::io::{self, Read};
+
+/// Append a stream to an existing hash without buffering the whole file.
+/// Retry interrupted reads, like `io::copy`, but propagate all other I/O errors.
+pub fn update_from_reader(hasher: &mut Sha256, mut reader: impl Read) -> io::Result<()> {
+ let mut buffer = [0_u8; 64 * 1024];
+ loop {
+ match reader.read(&mut buffer) {
+ Ok(0) => return Ok(()),
+ Ok(read) => hasher.update(&buffer[..read]),
+ Err(error) if error.kind() == io::ErrorKind::Interrupted => continue,
+ Err(error) => return Err(error),
+ }
+ }
+}
+
+/// Two lowercase hex characters per byte, including leading zeroes.
+pub fn lower_hex(bytes: &[u8]) -> String {
+ const HEX: &[u8; 16] = b"0123456789abcdef";
+ let mut result = String::with_capacity(bytes.len() * 2);
+ for &byte in bytes {
+ result.push(HEX[usize::from(byte >> 4)] as char);
+ result.push(HEX[usize::from(byte & 15)] as char);
+ }
+ result
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn standard_sha256_vectors_keep_their_canonical_hex() {
+ for (input, expected) in [
+ (
+ b"".as_slice(),
+ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
+ ),
+ (
+ b"abc".as_slice(),
+ "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad",
+ ),
+ (
+ b"c4".as_slice(),
+ "0012a3fa000c5dc26ee658c3c58e12cecd58d6455cec3d5621f0c787675b38aa",
+ ),
+ ] {
+ let mut hasher = Sha256::new();
+ update_from_reader(&mut hasher, input).unwrap();
+ assert_eq!(lower_hex(&hasher.finalize()), expected);
+ assert_eq!(lower_hex(&Sha256::digest(input)), expected);
+ }
+ assert_eq!(lower_hex(&[0, 1, 15, 16, 128, 255]), "00010f1080ff");
+ }
+
+ #[test]
+ fn streaming_hash_preserves_chunk_boundaries_and_bounded_reads() {
+ // Fixed values from Python hashlib/OpenSSL, not the helper under test.
+ for (size, expected) in [
+ (
+ 65535,
+ "6e1bebca6a8229364a162a72ef064826c4cd7457bf54f190ef782bd9deff3e42",
+ ),
+ (
+ 65536,
+ "bf718b6f653bebc184e1479f1935b8da974d701b893afcf49e701f3e2f9f9c5a",
+ ),
+ (
+ 65537,
+ "008ffc88d3c96a9f307524eb361e47c5222a887fc45fa0c1fb8d429c5c23b430",
+ ),
+ (
+ 131073,
+ "7e009ea4ef882e385b3c0bcbbfa8d009bb0a633bdd764415c09182ee0e75da73",
+ ),
+ ] {
+ struct BoundedReader(usize);
+ impl Read for BoundedReader {
+ fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
+ assert!(buf.len() <= 64 * 1024);
+ let count = self.0.min(buf.len());
+ buf[..count].fill(b'a');
+ self.0 -= count;
+ Ok(count)
+ }
+ }
+ let mut hasher = Sha256::new();
+ update_from_reader(&mut hasher, BoundedReader(size)).unwrap();
+ assert_eq!(lower_hex(&hasher.finalize()), expected);
+ }
+ }
+
+ #[test]
+ fn short_and_interrupted_reads_append_without_resetting_the_hash() {
+ struct ShortReader(usize);
+ impl Read for ShortReader {
+ fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
+ self.0 += 1;
+ match self.0 {
+ 1 | 3 => Err(io::ErrorKind::Interrupted.into()),
+ 2 => {
+ buf[0] = b'a';
+ Ok(1)
+ }
+ 4 => {
+ buf[0] = b'b';
+ Ok(1)
+ }
+ 5 => {
+ buf[0] = b'c';
+ Ok(1)
+ }
+ _ => Ok(0),
+ }
+ }
+ }
+ let mut hasher = Sha256::new();
+ hasher.update(b"prefix");
+ update_from_reader(&mut hasher, ShortReader(0)).unwrap();
+ assert_eq!(
+ lower_hex(&hasher.finalize()),
+ "bb55a5ab9f6a401bfca2ff147197209c59a002a3994731d8f2d2f45692f41846"
+ );
+ }
+
+ #[test]
+ fn a_read_failure_after_partial_data_is_not_reported_as_success() {
+ struct FailingReader(bool);
+ impl Read for FailingReader {
+ fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
+ if self.0 {
+ return Err(io::Error::new(io::ErrorKind::PermissionDenied, "fixture read failure"));
+ }
+ self.0 = true;
+ buf[0] = b'a';
+ Ok(1)
+ }
+ }
+ let error = update_from_reader(&mut Sha256::new(), FailingReader(false)).unwrap_err();
+ assert_eq!(error.kind(), io::ErrorKind::PermissionDenied);
+ assert_eq!(error.to_string(), "fixture read failure");
+ }
+}
diff --git a/desktop/runtime-host/src/lib.rs b/desktop/runtime-host/src/lib.rs
index 9e4e34a27..44ca5ea4b 100644
--- a/desktop/runtime-host/src/lib.rs
+++ b/desktop/runtime-host/src/lib.rs
@@ -25,6 +25,7 @@ pub mod bootstrap_log;
pub mod computer_use;
pub mod deep_link;
pub mod download;
+pub mod hashing;
pub mod health;
pub mod launcher;
pub mod login_path;
diff --git a/desktop/runtime-host/src/private_runtime.rs b/desktop/runtime-host/src/private_runtime.rs
index a4d903550..9072c485d 100644
--- a/desktop/runtime-host/src/private_runtime.rs
+++ b/desktop/runtime-host/src/private_runtime.rs
@@ -12,6 +12,7 @@ use std::io::{self, Read, Write};
use std::path::{Component, Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};
+use crate::hashing::{lower_hex, update_from_reader};
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use zip::ZipArchive;
@@ -514,8 +515,8 @@ fn verify_archive(path: &Path, manifest: &RuntimeBundleManifest) -> Result<(), P
let mut file = File::open(path).map_err(PrivateRuntimeError::ArchiveUnavailable)?;
let mut hasher = Sha256::new();
- io::copy(&mut file, &mut hasher).map_err(PrivateRuntimeError::ArchiveUnavailable)?;
- let actual = format!("{:x}", hasher.finalize());
+ update_from_reader(&mut hasher, &mut file).map_err(PrivateRuntimeError::ArchiveUnavailable)?;
+ let actual = lower_hex(&hasher.finalize());
if actual != manifest.archive_sha256 {
return Err(PrivateRuntimeError::ArchiveVerification);
}
@@ -636,9 +637,9 @@ fn verify_installed_tree(root: &Path, manifest: &RuntimeBundleManifest) -> Resul
for (relative, path, size) in &files {
update_tree_header(&mut hasher, relative, *size);
let mut file = File::open(path).map_err(PrivateRuntimeError::Install)?;
- io::copy(&mut file, &mut hasher).map_err(PrivateRuntimeError::Install)?;
+ update_from_reader(&mut hasher, &mut file).map_err(PrivateRuntimeError::Install)?;
}
- let actual = format!("{:x}", hasher.finalize());
+ let actual = lower_hex(&hasher.finalize());
if actual != manifest.tree_sha256 {
return Err(PrivateRuntimeError::ArchiveVerification);
}
@@ -860,11 +861,11 @@ mod tests {
os: current_os().to_owned(),
arch: current_arch().to_owned(),
archive: "runtime.zip".to_owned(),
- archive_sha256: format!("{:x}", Sha256::digest(&bytes)),
+ archive_sha256: lower_hex(&Sha256::digest(&bytes)),
archive_size: bytes.len() as u64,
unpacked_size,
entry_count,
- tree_sha256: format!("{:x}", tree_hasher.finalize()),
+ tree_sha256: lower_hex(&tree_hasher.finalize()),
python_entrypoint: python.to_owned(),
node_entrypoint: node.to_owned(),
npm_entrypoint: npm_cli.to_owned(),
@@ -890,6 +891,31 @@ mod tests {
manifest
}
+ #[test]
+ fn tree_verification_keeps_the_frozen_v1_digest_and_rejects_equal_size_tampering() {
+ let root = scratch("frozen-tree-digest");
+ let mut manifest = write_bundle(&root, None);
+ let tree = root.join("tree");
+ fs::create_dir_all(tree.join("dir")).unwrap();
+ // Deliberately create files out of sorted order, including an empty file
+ // and a UTF-8 path. The v1 hash uses byte lengths, not character counts.
+ fs::write(tree.join("z"), b"c4").unwrap();
+ fs::write(tree.join("dir/测试"), b"abc").unwrap();
+ fs::write(tree.join("a"), b"").unwrap();
+ manifest.entry_count = 3;
+ manifest.unpacked_size = 5;
+ // Independent SHA-256 vector for domain + sorted length/path/size/data
+ // records, confirmed against the pre-upgrade sha2 0.10 implementation.
+ manifest.tree_sha256 = "b15f116b100c3be48b84107d8097a4874f97a7bdc0c127035bdaa702767ac411".into();
+ verify_installed_tree(&tree, &manifest).unwrap();
+ fs::write(tree.join("dir/测试"), b"abd").unwrap();
+ assert!(matches!(
+ verify_installed_tree(&tree, &manifest),
+ Err(PrivateRuntimeError::ArchiveVerification)
+ ));
+ fs::remove_dir_all(root).unwrap();
+ }
+
#[test]
fn installs_once_into_a_versioned_content_addressed_directory() {
let root = scratch("install");
@@ -1506,7 +1532,7 @@ mod tests {
// payload hashes, staging cleanup and publication are part of this boundary.
fn refresh_archive_identity(root: &Path, manifest: &mut RuntimeBundleManifest) {
let bytes = fs::read(root.join("bundle/runtime.zip")).expect("archive bytes");
- manifest.archive_sha256 = format!("{:x}", Sha256::digest(&bytes));
+ manifest.archive_sha256 = lower_hex(&Sha256::digest(&bytes));
manifest.archive_size = bytes.len() as u64;
fs::write(
root.join("bundle").join(MANIFEST_NAME),
diff --git a/desktop/runtime-host/src/update.rs b/desktop/runtime-host/src/update.rs
index 0ee14052f..b070198ae 100644
--- a/desktop/runtime-host/src/update.rs
+++ b/desktop/runtime-host/src/update.rs
@@ -1,4 +1,5 @@
//! Signed desktop release contract, shared by the shell and release verifier.
+use crate::hashing::lower_hex;
use base64::{engine::general_purpose::STANDARD, Engine};
use minisign_verify::{PublicKey, Signature};
use semver::Version;
@@ -216,7 +217,7 @@ impl Manifest {
}
impl Artifact {
pub fn verify(&self, bytes: &[u8], public_key: &str) -> Result<(), String> {
- if bytes.len() as u64 != self.size || format!("{:x}", Sha256::digest(bytes)) != self.sha256 {
+ if bytes.len() as u64 != self.size || lower_hex(&Sha256::digest(bytes)) != self.sha256 {
return Err("update artifact integrity mismatch".into());
}
verify_signature(bytes, &self.signature, public_key)
diff --git a/desktop/src-tauri/src/computer_use.rs b/desktop/src-tauri/src/computer_use.rs
index 633e31917..e9cf6741e 100644
--- a/desktop/src-tauri/src/computer_use.rs
+++ b/desktop/src-tauri/src/computer_use.rs
@@ -18,6 +18,7 @@ use avibe_runtime_host::computer_use::{
StoredComputerUseState, ToolSnapshot, COMPUTER_USE_DRIVER_VERSION, COMPUTER_USE_LOCK_FILE,
COMPUTER_USE_SCHEMA_VERSION, COMPUTER_USE_SOCKET_FILE, COMPUTER_USE_STATE_FILE, COMPUTER_USE_TOOL_SNAPSHOT_SHA256,
};
+use avibe_runtime_host::hashing::{lower_hex, update_from_reader};
use avibe_runtime_host::{BootstrapLog, LoopbackOrigin, BOOTSTRAP_LOG_NAME};
use block2::RcBlock;
use objc2::rc::{Allocated, Retained};
@@ -242,7 +243,7 @@ impl Paths {
fn short_socket_path(state_dir: &Path, owner_uid: u32) -> PathBuf {
let mut digest = Sha256::new();
digest.update(state_dir.as_os_str().as_bytes());
- let flavor = format!("{:x}", digest.finalize());
+ let flavor = lower_hex(&digest.finalize());
let flavor = &flavor[..SOCKET_FLAVOR_HEX_BYTES];
PathBuf::from("/tmp")
.join(format!("avibe-cua-{owner_uid}-{flavor}"))
@@ -2040,15 +2041,8 @@ fn open_missing_permission_settings(app: &AppHandle, grants: Grants) {
fn sha256_file(path: &Path) -> Option<String> {
let mut file = File::open(path).ok()?;
let mut hasher = Sha256::new();
- let mut buffer = [0_u8; 64 * 1024];
- loop {
- let read = file.read(&mut buffer).ok()?;
- if read == 0 {
- break;
- }
- hasher.update(&buffer[..read]);
- }
- Some(format!("{:x}", hasher.finalize()))
+ update_from_reader(&mut hasher, &mut file).ok()?;
+ Some(lower_hex(&hasher.finalize()))
}
fn random_instance_id() -> io::Result<String> {