Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.
Rust agentai-agentapplecomputer-usecomputer-use-agentcontainerizationcuadesktop-automationhacktoberfestlumemacosmanusoperatorswiftvirtualizationvirtualization-frameworkwindowswindows-sandbox
fix(cua-driver): share the keyring history key provider in cua-driver-core (#5895)
injaneitye9c847820bca
diff --git a/libs/cua-driver/rust/Cargo.lock b/libs/cua-driver/rust/Cargo.lockindex b060ec909b..a7d8cfcdbd 100644--- a/libs/cua-driver/rust/Cargo.lock+++ b/libs/cua-driver/rust/Cargo.lock@@ -1290,6 +1290,7 @@ dependencies = ["hmac","image","jsonschema",+ "keyring","libc","regex","regorus",@@ -3541,9 +3542,7 @@ dependencies = ["enumflags2","evdev","futures-util",- "getrandom 0.4.2","image",- "keyring","libc","libspa","memmap2",@@ -3562,7 +3561,6 @@ dependencies = ["tracing","tracing-subscriber","url",- "uuid","wayland-backend","wayland-client","wayland-protocols",@@ -3572,7 +3570,6 @@ dependencies = ["x11rb","xkbcommon","zbus",- "zeroize",][[package]]@@ -3628,7 +3625,6 @@ dependencies = ["cursor-overlay","getrandom 0.4.2","image",- "keyring","pip-preview","serde","serde_json",diff --git a/libs/cua-driver/rust/crates/cua-driver-core/Cargo.toml b/libs/cua-driver/rust/crates/cua-driver-core/Cargo.tomlindex de9e618d6b..5000ae69e4 100644--- a/libs/cua-driver/rust/crates/cua-driver-core/Cargo.toml+++ b/libs/cua-driver/rust/crates/cua-driver-core/Cargo.toml@@ -14,6 +14,8 @@ rego = ["dep:regorus"]# offered unless the operator turns it off at runtime. Without this feature# the tool is not offered at all.script = ["dep:rquickjs"]+# OS credential-store history key provider (Linux Secret Service, Windows Credential Manager).+keyring = ["dep:keyring"][dependencies]cua-driver-contract = { path = "../cua-driver-contract" }@@ -52,6 +54,7 @@ coset = { workspace = true }ciborium = { workspace = true }time = { workspace = true }getrandom = { workspace = true }+keyring = { version = "4.1.6", default-features = false, features = ["v1"], optional = true }fs2 = { workspace = true }hmac = { workspace = true }# Validate the raw wire payload; serde permits some shapes the schema rejects.diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/history_keyring.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/history_keyring.rsnew file mode 100644index 0000000000..a81448ecc4--- /dev/null+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/history_keyring.rs@@ -0,0 +1,233 @@+//! OS credential-store history key provider, shared by Linux (Secret Service)+//! and Windows (Credential Manager).++use crate::history::{HistoryError, HistoryHealthCategory, HistoryKey, KeyProvider};+use keyring::{Entry, Error as KeyringError};+use std::sync::Arc;+use zeroize::Zeroizing;++const KEY_ACCOUNT: &str = "namespace-root-key-v1";++#[derive(Default)]+pub struct KeyringKeyProvider;++impl KeyringKeyProvider {+ pub fn shared() -> Arc<Self> {+ Arc::new(Self)+ }++ fn service(namespace: &str) -> Result<String, HistoryError> {+ validate_namespace(namespace)?;+ Ok(format!("com.trycua.{namespace}.computer-history.v1"))+ }++ fn entry(service: &str) -> Result<Entry, HistoryError> {+ Entry::new(service, KEY_ACCOUNT).map_err(map_keyring_error)+ }+}++impl KeyProvider for KeyringKeyProvider {+ fn load_or_create(&self, namespace: &str) -> Result<HistoryKey, HistoryError> {+ let service = Self::service(namespace)?;+ let entry = Self::entry(&service)?;+ match entry.get_secret() {+ Ok(bytes) => key(service, bytes),+ Err(KeyringError::NoEntry) => {+ let mut bytes = Zeroizing::new(vec![0_u8; 32]);+ getrandom::fill(&mut bytes)+ .map_err(|_| HistoryError::new(HistoryHealthCategory::KeyUnavailable))?;+ entry.set_secret(&bytes).map_err(map_keyring_error)?;+ let verified = Zeroizing::new(entry.get_secret().map_err(map_keyring_error)?);+ if verified.as_slice() != bytes.as_slice() {+ return Err(HistoryError::new(HistoryHealthCategory::KeyCorrupt));+ }+ zeroizing_key(service, verified)+ }+ Err(error) => Err(map_keyring_error(error)),+ }+ }++ fn load(&self, namespace: &str, reference: &str) -> Result<HistoryKey, HistoryError> {+ let service = Self::service(namespace)?;+ if reference != service {+ return Err(HistoryError::new(HistoryHealthCategory::KeyUnavailable));+ }+ key(+ service.clone(),+ Self::entry(&service)?+ .get_secret()+ .map_err(map_keyring_error)?,+ )+ }++ fn references(&self, namespace: &str) -> Result<Vec<String>, HistoryError> {+ let service = Self::service(namespace)?;+ match Self::entry(&service)?.get_secret() {+ Ok(bytes) => {+ let _bytes = Zeroizing::new(bytes);+ Ok(vec![service])+ }+ Err(KeyringError::NoEntry) => Ok(Vec::new()),+ Err(error) => Err(map_keyring_error(error)),+ }+ }++ fn destroy(&self, namespace: &str, reference: &str) -> Result<(), HistoryError> {+ let service = Self::service(namespace)?;+ if reference != service {+ return Err(HistoryError::new(HistoryHealthCategory::KeyUnavailable));+ }+ let entry = Self::entry(&service)?;+ match entry.delete_credential() {+ Ok(()) | Err(KeyringError::NoEntry) => {}+ Err(error) => return Err(map_keyring_error(error)),+ }+ match entry.get_secret() {+ Err(KeyringError::NoEntry) => Ok(()),+ Ok(bytes) => {+ let _bytes = Zeroizing::new(bytes);+ Err(HistoryError::new(HistoryHealthCategory::KeyDestroyFailed))+ }+ Err(error) => Err(map_keyring_error(error)),+ }+ }+}++fn validate_namespace(namespace: &str) -> Result<(), HistoryError> {+ let valid = !namespace.is_empty()+ && namespace.len() <= 64+ && namespace+ .bytes()+ .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_'));+ valid+ .then_some(())+ .ok_or_else(|| HistoryError::new(HistoryHealthCategory::KeyUnavailable))+}++fn key(reference: String, bytes: Vec<u8>) -> Result<HistoryKey, HistoryError> {+ zeroizing_key(reference, Zeroizing::new(bytes))+}++fn zeroizing_key(reference: String, bytes: Zeroizing<Vec<u8>>) -> Result<HistoryKey, HistoryError> {+ if bytes.len() != 32 {+ return Err(HistoryError::new(HistoryHealthCategory::KeyCorrupt));+ }+ Ok(HistoryKey {+ reference,+ epoch: 1,+ bytes,+ })+}++fn map_keyring_error(error: KeyringError) -> HistoryError {+ let category = match error {+ KeyringError::NoStorageAccess(_) => HistoryHealthCategory::KeyLocked,+ KeyringError::BadDataFormat(_, _)+ | KeyringError::BadStoreFormat(_)+ | KeyringError::BadEncoding(_)+ | KeyringError::Ambiguous(_) => HistoryHealthCategory::KeyCorrupt,+ _ => HistoryHealthCategory::KeyUnavailable,+ };+ HistoryError::new(category)+}++#[cfg(test)]+mod tests {+ use super::*;++ struct CredentialCleanup(Entry);++ impl Drop for CredentialCleanup {+ fn drop(&mut self) {+ let _ = self.0.delete_credential();+ }+ }++ #[test]+ fn service_and_account_strings_are_stable() {+ assert_eq!(+ KeyringKeyProvider::service("cua-driver-local").unwrap(),+ "com.trycua.cua-driver-local.computer-history.v1"+ );+ assert_eq!(KEY_ACCOUNT, "namespace-root-key-v1");+ }++ #[test]+ fn credential_namespace_is_strict_and_separated() {+ assert_ne!(+ KeyringKeyProvider::service("cua-driver").unwrap(),+ KeyringKeyProvider::service("cua-driver-local").unwrap()+ );+ assert_eq!(+ KeyringKeyProvider::service("../escape")+ .unwrap_err()+ .category,+ HistoryHealthCategory::KeyUnavailable+ );+ assert_eq!(+ KeyringKeyProvider::service("").unwrap_err().category,+ HistoryHealthCategory::KeyUnavailable+ );+ assert_eq!(+ KeyringKeyProvider::service(&"a".repeat(65))+ .unwrap_err()+ .category,+ HistoryHealthCategory::KeyUnavailable+ );+ assert_eq!(+ KeyringKeyProvider::service("caf\u{e9}")+ .unwrap_err()+ .category,+ HistoryHealthCategory::KeyUnavailable+ );+ assert!(KeyringKeyProvider::service(&"a".repeat(64)).is_ok());+ assert!(KeyringKeyProvider::service("a-b_c").is_ok());+ }++ #[test]+ fn inaccessible_store_maps_to_locked_without_fallback() {+ let error = KeyringError::NoStorageAccess(Box::new(std::io::Error::new(+ std::io::ErrorKind::PermissionDenied,+ "synthetic locked vault",+ )));+ assert_eq!(+ map_keyring_error(error).category,+ HistoryHealthCategory::KeyLocked+ );+ }++ #[test]+ #[ignore = "mutates uniquely named OS credential-store items; run in native release qualification"]+ fn key_lifecycle_is_isolated_corruptible_and_destroyable() {+ let namespace = format!("cua-driver-local-test-{}", uuid::Uuid::new_v4().simple());+ let other_namespace = format!("{namespace}-other");+ let provider = KeyringKeyProvider;+ assert!(provider.references(&namespace).unwrap().is_empty());+ assert!(provider.references(&other_namespace).unwrap().is_empty());++ let created = provider.load_or_create(&namespace).unwrap();+ let entry = KeyringKeyProvider::entry(&created.reference).unwrap();+ let _cleanup = CredentialCleanup(entry);+ assert_eq!(created.bytes.len(), 32);+ assert_eq!(+ provider+ .load(&namespace, &created.reference)+ .unwrap()+ .bytes+ .as_slice(),+ created.bytes.as_slice()+ );+ assert!(provider.references(&other_namespace).unwrap().is_empty());++ KeyringKeyProvider::entry(&created.reference)+ .unwrap()+ .set_secret(b"corrupt")+ .unwrap();+ match provider.load(&namespace, &created.reference) {+ Err(error) => assert_eq!(error.category, HistoryHealthCategory::KeyCorrupt),+ Ok(_) => panic!("corrupt credential unexpectedly loaded"),+ }+ provider.destroy(&namespace, &created.reference).unwrap();+ assert!(provider.references(&namespace).unwrap().is_empty());+ }+}diff --git a/libs/cua-driver/rust/crates/cua-driver-core/src/lib.rs b/libs/cua-driver/rust/crates/cua-driver-core/src/lib.rsindex 730e294b4a..8580833866 100644--- a/libs/cua-driver/rust/crates/cua-driver-core/src/lib.rs+++ b/libs/cua-driver/rust/crates/cua-driver-core/src/lib.rs@@ -79,6 +79,8 @@ pub mod expectation;pub mod ffmpeg_install;pub mod health_report;pub mod history;+#[cfg(feature = "keyring")]+pub mod history_keyring;pub mod image_utils;pub mod interactive_input;pub mod key_pacing;diff --git a/libs/cua-driver/rust/crates/platform-linux/Cargo.toml b/libs/cua-driver/rust/crates/platform-linux/Cargo.tomlindex dfb5ec0fdc..24dea65e43 100644--- a/libs/cua-driver/rust/crates/platform-linux/Cargo.toml+++ b/libs/cua-driver/rust/crates/platform-linux/Cargo.toml@@ -17,15 +17,13 @@ cua-driver-core = { path = "../cua-driver-core" }cua-driver-contract = { path = "../cua-driver-contract" }cursor-overlay = { path = "../cursor-overlay" }pip-preview = { path = "../pip-preview" }-zeroize = { workspace = true }-getrandom = { workspace = true }sha2 = { workspace = true }# tiny-skia for cursor rendering (shared cross-platform)tiny-skia = { version = "0.11", default-features = false, features = ["std"] }[target.'cfg(target_os = "linux")'.dependencies]clipboard-rs = { version = "0.3.5", features = ["wayland"] }-keyring = { version = "4.1.6", default-features = false, features = ["v1"] }+cua-driver-core = { path = "../cua-driver-core", features = ["keyring"] }# X11 background input + window enumeration + MIT-SHM capturex11rb = { version = "0.13", features = ["xinput", "randr", "xfixes", "composite", "shape", "xtest", "shm", "res"] }x11 = { version = "2.21", features = ["xlib", "xinput", "xtest"] }@@ -156,7 +154,6 @@ portal-libei = ["portal-input", "portal-capture"][dev-dependencies]tokio = { workspace = true, features = ["test-util"] }-uuid = { workspace = true }tempfile = "3"# Used by the `screenshot_cascade` example to surface the# `tracing::debug!` lines emitted by each tier of the dispatch as itdiff --git a/libs/cua-driver/rust/crates/platform-linux/src/history.rs b/libs/cua-driver/rust/crates/platform-linux/src/history.rsindex 5f3768b7da..c929d3a032 100644--- a/libs/cua-driver/rust/crates/platform-linux/src/history.rs+++ b/libs/cua-driver/rust/crates/platform-linux/src/history.rs@@ -1,137 +1,8 @@//! Linux adapters for encrypted Computer History.-use cua_driver_core::history::{- ApplicationIdentity, ApplicationIdentityProvider, HistoryError, HistoryHealthCategory,- HistoryKey, KeyProvider,-};-use keyring::{Entry, Error as KeyringError};+use cua_driver_core::history::{ApplicationIdentity, ApplicationIdentityProvider};+pub use cua_driver_core::history_keyring::KeyringKeyProvider as LinuxSecretServiceKeyProvider;use std::sync::Arc;-use zeroize::Zeroizing;--const KEY_ACCOUNT: &str = "namespace-root-key-v1";--#[derive(Default)]-pub struct LinuxSecretServiceKeyProvider;--impl LinuxSecretServiceKeyProvider {- pub fn shared() -> Arc<Self> {- Arc::new(Self)- }-- fn service(namespace: &str) -> Result<String, HistoryError> {- validate_namespace(namespace)?;- Ok(format!("com.trycua.{namespace}.computer-history.v1"))- }-- fn entry(service: &str) -> Result<Entry, HistoryError> {- Entry::new(service, KEY_ACCOUNT).map_err(map_keyring_error)- }-}--impl KeyProvider for LinuxSecretServiceKeyProvider {- fn load_or_create(&self, namespace: &str) -> Result<HistoryKey, HistoryError> {- let service = Self::service(namespace)?;- let entry = Self::entry(&service)?;- match entry.get_secret() {- Ok(bytes) => key(service, bytes),- Err(KeyringError::NoEntry) => {- let mut bytes = Zeroizing::new(vec![0_u8; 32]);- getrandom::fill(&mut bytes)- .map_err(|_| HistoryError::new(HistoryHealthCategory::KeyUnavailable))?;- entry.set_secret(&bytes).map_err(map_keyring_error)?;- let verified = Zeroizing::new(entry.get_secret().map_err(map_keyring_error)?);- if verified.as_slice() != bytes.as_slice() {- return Err(HistoryError::new(HistoryHealthCategory::KeyCorrupt));- }- zeroizing_key(service, verified)- }- Err(error) => Err(map_keyring_error(error)),- }- }-- fn load(&self, namespace: &str, reference: &str) -> Result<HistoryKey, HistoryError> {- let service = Self::service(namespace)?;- if reference != service {- return Err(HistoryError::new(HistoryHealthCategory::KeyUnavailable));- }- key(- service.clone(),- Self::entry(&service)?- .get_secret()- .map_err(map_keyring_error)?,- )- }-- fn references(&self, namespace: &str) -> Result<Vec<String>, HistoryError> {- let service = Self::service(namespace)?;- match Self::entry(&service)?.get_secret() {- Ok(bytes) => {- let _bytes = Zeroizing::new(bytes);- Ok(vec![service])- }- Err(KeyringError::NoEntry) => Ok(Vec::new()),- Err(error) => Err(map_keyring_error(error)),- }- }-- fn destroy(&self, namespace: &str, reference: &str) -> Result<(), HistoryError> {- let service = Self::service(namespace)?;- if reference != service {- return Err(HistoryError::new(HistoryHealthCategory::KeyUnavailable));- }- let entry = Self::entry(&service)?;- match entry.delete_credential() {- Ok(()) | Err(KeyringError::NoEntry) => {}- Err(error) => return Err(map_keyring_error(error)),- }- match entry.get_secret() {- Err(KeyringError::NoEntry) => Ok(()),- Ok(bytes) => {- let _bytes = Zeroizing::new(bytes);- Err(HistoryError::new(HistoryHealthCategory::KeyDestroyFailed))- }- Err(error) => Err(map_keyring_error(error)),- }- }-}--fn validate_namespace(namespace: &str) -> Result<(), HistoryError> {- let valid = !namespace.is_empty()- && namespace.len() <= 64- && namespace- .bytes()- .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_'));- valid- .then_some(())- .ok_or_else(|| HistoryError::new(HistoryHealthCategory::KeyUnavailable))-}--fn key(reference: String, bytes: Vec<u8>) -> Result<HistoryKey, HistoryError> {- zeroizing_key(reference, Zeroizing::new(bytes))-}--fn zeroizing_key(reference: String, bytes: Zeroizing<Vec<u8>>) -> Result<HistoryKey, HistoryError> {- if bytes.len() != 32 {- return Err(HistoryError::new(HistoryHealthCategory::KeyCorrupt));- }- Ok(HistoryKey {- reference,- epoch: 1,- bytes,- })-}--fn map_keyring_error(error: KeyringError) -> HistoryError {- let category = match error {- KeyringError::NoStorageAccess(_) => HistoryHealthCategory::KeyLocked,- KeyringError::BadDataFormat(_, _)- | KeyringError::BadStoreFormat(_)- | KeyringError::BadEncoding(_)- | KeyringError::Ambiguous(_) => HistoryHealthCategory::KeyCorrupt,- _ => HistoryHealthCategory::KeyUnavailable,- };- HistoryError::new(category)-}#[derive(Default)]pub struct LinuxApplicationIdentityProvider;@@ -197,23 +68,6 @@ pub fn application_identity_provider() -> Arc<dyn ApplicationIdentityProvider> {mod tests {use super::*;- struct CredentialCleanup(Entry);-- impl Drop for CredentialCleanup {- fn drop(&mut self) {- let _ = self.0.delete_credential();- }- }-- #[test]- fn secret_service_namespace_is_strict_and_separated() {- assert_ne!(- LinuxSecretServiceKeyProvider::service("cua-driver").unwrap(),- LinuxSecretServiceKeyProvider::service("cua-driver-local").unwrap()- );- assert!(LinuxSecretServiceKeyProvider::service("../escape").is_err());- }-#[test]fn current_process_identity_is_resolvable_without_titles_or_paths() {let identity = LinuxApplicationIdentityProvider@@ -235,51 +89,4 @@ mod tests {assert_ne!(identity.bundle_id.as_deref(), Some(title.as_str()));assert_ne!(identity.display_name.as_deref(), Some(title.as_str()));}-- #[test]- fn inaccessible_store_maps_to_locked_without_fallback() {- let error = KeyringError::NoStorageAccess(Box::new(std::io::Error::new(- std::io::ErrorKind::PermissionDenied,- "synthetic locked vault",- )));- assert_eq!(- map_keyring_error(error).category,- HistoryHealthCategory::KeyLocked- );- }-- #[test]- #[ignore = "mutates uniquely named Secret Service items; run in native release qualification"]- fn secret_service_key_lifecycle_is_isolated_corruptible_and_destroyable() {- let namespace = format!("cua-driver-local-test-{}", uuid::Uuid::new_v4().simple());- let other_namespace = format!("{namespace}-other");- let provider = LinuxSecretServiceKeyProvider;- assert!(provider.references(&namespace).unwrap().is_empty());- assert!(provider.references(&other_namespace).unwrap().is_empty());-- let created = provider.load_or_create(&namespace).unwrap();- let entry = LinuxSecretServiceKeyProvider::entry(&created.reference).unwrap();- let _cleanup = CredentialCleanup(entry);- assert_eq!(created.bytes.len(), 32);- assert_eq!(- provider- .load(&namespace, &created.reference)- .unwrap()- .bytes- .as_slice(),- created.bytes.as_slice()- );- assert!(provider.references(&other_namespace).unwrap().is_empty());-- LinuxSecretServiceKeyProvider::entry(&created.reference)- .unwrap()- .set_secret(b"corrupt")- .unwrap();- match provider.load(&namespace, &created.reference) {- Err(error) => assert_eq!(error.category, HistoryHealthCategory::KeyCorrupt),- Ok(_) => panic!("corrupt credential unexpectedly loaded"),- }- provider.destroy(&namespace, &created.reference).unwrap();- assert!(provider.references(&namespace).unwrap().is_empty());- }}diff --git a/libs/cua-driver/rust/crates/platform-windows/Cargo.toml b/libs/cua-driver/rust/crates/platform-windows/Cargo.tomlindex 7868ee8a4b..a1dbf7ca91 100644--- a/libs/cua-driver/rust/crates/platform-windows/Cargo.toml+++ b/libs/cua-driver/rust/crates/platform-windows/Cargo.toml@@ -26,7 +26,7 @@ tiny-skia = { version = "0.11", default-features = false, features = ["std"] }[target.'cfg(target_os = "windows")'.dependencies]clipboard-rs = "0.3.5"-keyring = { version = "4.1.6", default-features = false, features = ["v1"] }+cua-driver-core = { path = "../cua-driver-core", features = ["keyring"] }image = { workspace = true }windows = { version = "0.58", features = ["Win32_Foundation",diff --git a/libs/cua-driver/rust/crates/platform-windows/src/history.rs b/libs/cua-driver/rust/crates/platform-windows/src/history.rsindex 3dee295fd0..9b28ea0734 100644--- a/libs/cua-driver/rust/crates/platform-windows/src/history.rs+++ b/libs/cua-driver/rust/crates/platform-windows/src/history.rs@@ -1,137 +1,8 @@//! Windows adapters for encrypted Computer History.-use cua_driver_core::history::{- ApplicationIdentity, ApplicationIdentityProvider, HistoryError, HistoryHealthCategory,- HistoryKey, KeyProvider,-};-use keyring::{Entry, Error as KeyringError};+use cua_driver_core::history::{ApplicationIdentity, ApplicationIdentityProvider};+pub use cua_driver_core::history_keyring::KeyringKeyProvider as WindowsCredentialKeyProvider;use std::{path::PathBuf, sync::Arc};-use zeroize::Zeroizing;--const KEY_ACCOUNT: &str = "namespace-root-key-v1";--#[derive(Default)]-pub struct WindowsCredentialKeyProvider;--impl WindowsCredentialKeyProvider {- pub fn shared() -> Arc<Self> {- Arc::new(Self)- }-- fn service(namespace: &str) -> Result<String, HistoryError> {- validate_namespace(namespace)?;- Ok(format!("com.trycua.{namespace}.computer-history.v1"))- }-- fn entry(service: &str) -> Result<Entry, HistoryError> {- Entry::new(service, KEY_ACCOUNT).map_err(map_keyring_error)- }-}--impl KeyProvider for WindowsCredentialKeyProvider {- fn load_or_create(&self, namespace: &str) -> Result<HistoryKey, HistoryError> {- let service = Self::service(namespace)?;- let entry = Self::entry(&service)?;- match entry.get_secret() {- Ok(bytes) => key(service, bytes),- Err(KeyringError::NoEntry) => {- let mut bytes = Zeroizing::new(vec![0_u8; 32]);- getrandom::fill(&mut bytes)- .map_err(|_| HistoryError::new(HistoryHealthCategory::KeyUnavailable))?;- entry.set_secret(&bytes).map_err(map_keyring_error)?;- let verified = Zeroizing::new(entry.get_secret().map_err(map_keyring_error)?);- if verified.as_slice() != bytes.as_slice() {- return Err(HistoryError::new(HistoryHealthCategory::KeyCorrupt));- }- zeroizing_key(service, verified)- }- Err(error) => Err(map_keyring_error(error)),- }- }-- fn load(&self, namespace: &str, reference: &str) -> Result<HistoryKey, HistoryError> {- let service = Self::service(namespace)?;- if reference != service {- return Err(HistoryError::new(HistoryHealthCategory::KeyUnavailable));- }- key(- service.clone(),- Self::entry(&service)?- .get_secret()- .map_err(map_keyring_error)?,- )- }-- fn references(&self, namespace: &str) -> Result<Vec<String>, HistoryError> {- let service = Self::service(namespace)?;- match Self::entry(&service)?.get_secret() {- Ok(bytes) => {- let _bytes = Zeroizing::new(bytes);- Ok(vec![service])- }- Err(KeyringError::NoEntry) => Ok(Vec::new()),- Err(error) => Err(map_keyring_error(error)),- }- }-- fn destroy(&self, namespace: &str, reference: &str) -> Result<(), HistoryError> {- let service = Self::service(namespace)?;- if reference != service {- return Err(HistoryError::new(HistoryHealthCategory::KeyUnavailable));- }- let entry = Self::entry(&service)?;- match entry.delete_credential() {- Ok(()) | Err(KeyringError::NoEntry) => {}- Err(error) => return Err(map_keyring_error(error)),- }- match entry.get_secret() {- Err(KeyringError::NoEntry) => Ok(()),- Ok(bytes) => {- let _bytes = Zeroizing::new(bytes);- Err(HistoryError::new(HistoryHealthCategory::KeyDestroyFailed))- }- Err(error) => Err(map_keyring_error(error)),- }- }-}--fn validate_namespace(namespace: &str) -> Result<(), HistoryError> {- let valid = !namespace.is_empty()- && namespace.len() <= 64- && namespace- .bytes()- .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_'));- valid- .then_some(())- .ok_or_else(|| HistoryError::new(HistoryHealthCategory::KeyUnavailable))-}--fn key(reference: String, bytes: Vec<u8>) -> Result<HistoryKey, HistoryError> {- zeroizing_key(reference, Zeroizing::new(bytes))-}--fn zeroizing_key(reference: String, bytes: Zeroizing<Vec<u8>>) -> Result<HistoryKey, HistoryError> {- if bytes.len() != 32 {- return Err(HistoryError::new(HistoryHealthCategory::KeyCorrupt));- }- Ok(HistoryKey {- reference,- epoch: 1,- bytes,- })-}--fn map_keyring_error(error: KeyringError) -> HistoryError {- let category = match error {- KeyringError::NoStorageAccess(_) => HistoryHealthCategory::KeyLocked,- KeyringError::BadDataFormat(_, _)- | KeyringError::BadStoreFormat(_)- | KeyringError::BadEncoding(_)- | KeyringError::Ambiguous(_) => HistoryHealthCategory::KeyCorrupt,- _ => HistoryHealthCategory::KeyUnavailable,- };- HistoryError::new(category)-}#[derive(Default)]pub struct WindowsApplicationIdentityProvider;@@ -192,73 +63,9 @@ pub fn process_executable_path(pid: u32) -> Option<PathBuf> {mod tests {use super::*;- struct CredentialCleanup(Entry);-- impl Drop for CredentialCleanup {- fn drop(&mut self) {- let _ = self.0.delete_credential();- }- }-- #[test]- fn credential_namespace_is_strict_and_separated() {- assert_ne!(- WindowsCredentialKeyProvider::service("cua-driver").unwrap(),- WindowsCredentialKeyProvider::service("cua-driver-local").unwrap()- );- assert!(WindowsCredentialKeyProvider::service("../escape").is_err());- }-#[test]fn current_process_identity_is_resolvable() {let path = process_executable_path(std::process::id()).expect("current process path");assert!(path.is_absolute());}-- #[test]- fn inaccessible_store_maps_to_locked_without_fallback() {- let error = KeyringError::NoStorageAccess(Box::new(std::io::Error::new(- std::io::ErrorKind::PermissionDenied,- "synthetic locked vault",- )));- assert_eq!(- map_keyring_error(error).category,- HistoryHealthCategory::KeyLocked- );- }-- #[test]- #[ignore = "mutates uniquely named Windows Credential Manager items; run in native release qualification"]- fn credential_manager_key_lifecycle_is_isolated_corruptible_and_destroyable() {- let namespace = format!("cua-driver-local-test-{}", uuid::Uuid::new_v4().simple());- let other_namespace = format!("{namespace}-other");- let provider = WindowsCredentialKeyProvider;- assert!(provider.references(&namespace).unwrap().is_empty());- assert!(provider.references(&other_namespace).unwrap().is_empty());-- let created = provider.load_or_create(&namespace).unwrap();- let entry = WindowsCredentialKeyProvider::entry(&created.reference).unwrap();- let _cleanup = CredentialCleanup(entry);- assert_eq!(created.bytes.len(), 32);- assert_eq!(- provider- .load(&namespace, &created.reference)- .unwrap()- .bytes- .as_slice(),- created.bytes.as_slice()- );- assert!(provider.references(&other_namespace).unwrap().is_empty());-- WindowsCredentialKeyProvider::entry(&created.reference)- .unwrap()- .set_secret(b"corrupt")- .unwrap();- match provider.load(&namespace, &created.reference) {- Err(error) => assert_eq!(error.category, HistoryHealthCategory::KeyCorrupt),- Ok(_) => panic!("corrupt credential unexpectedly loaded"),- }- provider.destroy(&namespace, &created.reference).unwrap();- assert!(provider.references(&namespace).unwrap().is_empty());- }}diff --git a/libs/cua-spacesd/Cargo.lock b/libs/cua-spacesd/Cargo.lockindex 3b0befa33a..0d682229b6 100644--- a/libs/cua-spacesd/Cargo.lock+++ b/libs/cua-spacesd/Cargo.lock@@ -1894,6 +1894,7 @@ dependencies = ["hmac 0.12.1","image","jsonschema",+ "keyring 4.2.0","libc","regex","regorus",@@ -5309,9 +5310,7 @@ dependencies = ["dirs","evdev","futures-util",- "getrandom 0.4.3","image",- "keyring 4.2.0","libc","memmap2","meval",@@ -5333,7 +5332,6 @@ dependencies = ["x11","x11rb","zbus",- "zeroize",][[package]]@@ -5387,7 +5385,6 @@ dependencies = ["cursor-overlay","getrandom 0.4.3","image",- "keyring 4.2.0","pip-preview","serde","serde_json",diff --git a/libs/cua-spacesd/tests/spaces-e2e/Cargo.lock b/libs/cua-spacesd/tests/spaces-e2e/Cargo.lockindex e49a1c3d39..e33a01ef9c 100644--- a/libs/cua-spacesd/tests/spaces-e2e/Cargo.lock+++ b/libs/cua-spacesd/tests/spaces-e2e/Cargo.lock@@ -2318,6 +2318,7 @@ dependencies = ["hmac 0.12.1","image","jsonschema",+ "keyring 4.2.0","libc","regex","regorus",@@ -6225,9 +6226,7 @@ dependencies = ["dirs","evdev","futures-util",- "getrandom 0.4.3","image",- "keyring 4.2.0","libc","memmap2","meval",@@ -6249,7 +6248,6 @@ dependencies = ["x11","x11rb","zbus",- "zeroize",][[package]]@@ -6303,7 +6301,6 @@ dependencies = ["cursor-overlay","getrandom 0.4.3","image",- "keyring 4.2.0","pip-preview","serde","serde_json",diff --git a/libs/cua-spacesd/tests/teleport-e2e/Cargo.lock b/libs/cua-spacesd/tests/teleport-e2e/Cargo.lockindex f8f0413a74..820abd3ed0 100644--- a/libs/cua-spacesd/tests/teleport-e2e/Cargo.lock+++ b/libs/cua-spacesd/tests/teleport-e2e/Cargo.lock@@ -1428,6 +1428,7 @@ dependencies = ["hmac 0.12.1","image","jsonschema",+ "keyring","libc","regex","regorus",@@ -4389,9 +4390,7 @@ dependencies = ["dirs","evdev","futures-util",- "getrandom 0.4.3","image",- "keyring","libc","memmap2","meval",@@ -4413,7 +4412,6 @@ dependencies = ["x11","x11rb","zbus",- "zeroize",][[package]]@@ -4467,7 +4465,6 @@ dependencies = ["cursor-overlay","getrandom 0.4.3","image",- "keyring","pip-preview","serde","serde_json",