mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 12:21:08 +01:00
Plug-ins: a removal the key store can't make last fails
plugin.remove now fails and leaves the plug-in installed while the key store can't be reached, also when grants.json is missing or doesn't name the plug-in, since an earlier signed copy put back could otherwise grant it again. A grants file that is too large or doesn't hold a list no longer stops a removal once the generation is raised. Removing an id that isn't installed deletes the module stored for it that didn't load and reports it removed. The system key store is reached through keyring-core and the platform store crates keyring 4.2 uses; a failed connection is tried again on the next call. The key is read from the key store each time grants.json is checked or signed, so a key removed or replaced there is not used. The key and the generations are kept as hexadecimal text. On Windows the lock for making the first key is in %LOCALAPPDATA%. The wrong-key and copied-file cases of the edited-file test are at the generation kept for their folder, so only the MAC rejects them.
This commit is contained in:
1 parent
d60e2998d7
commit
685e7cc3ea
9 files changed
+327
-103
No files matched your search
Generated
+4
-13
@@ -3596,18 +3596,6 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "keyring"
|
||||
version = "4.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2270074a3d26bcac93c1dc5d2845eb4c089e8d761ccf6e0ea266a16004640627"
|
||||
dependencies = [
|
||||
"apple-native-keyring-store",
|
||||
"keyring-core",
|
||||
"windows-native-keyring-store",
|
||||
"zbus-secret-service-keyring-store",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "keyring-core"
|
||||
version = "1.1.0"
|
||||
@@ -7204,6 +7192,7 @@ dependencies = [
|
||||
name = "vectorcraft-engine"
|
||||
version = "0.24.1"
|
||||
dependencies = [
|
||||
"apple-native-keyring-store",
|
||||
"cfb",
|
||||
"chrono",
|
||||
"craft-cdr",
|
||||
@@ -7224,7 +7213,7 @@ dependencies = [
|
||||
"jxl-color",
|
||||
"jxl-grid",
|
||||
"jxl-oxide",
|
||||
"keyring",
|
||||
"keyring-core",
|
||||
"kurbo 0.13.1",
|
||||
"log",
|
||||
"proptest",
|
||||
@@ -7261,6 +7250,8 @@ dependencies = [
|
||||
"vectorcraft-tools",
|
||||
"vectorcraft-trace",
|
||||
"wat",
|
||||
"windows-native-keyring-store",
|
||||
"zbus-secret-service-keyring-store",
|
||||
"zune-core",
|
||||
"zune-jpegxl",
|
||||
]
|
||||
|
||||
@@ -79,6 +79,8 @@ rustix = { workspace = true, features = ["std", "process"] }
|
||||
# (walkdir), so this adds no new crate.
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
same-file = "1.0.6"
|
||||
# Credential Manager, the system key store of grant_keys.rs on Windows (see keyring-core below).
|
||||
windows-native-keyring-store = "1.1"
|
||||
|
||||
# The tiles of a HEIC photo decode in parallel on native; wasm stays single-threaded.
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
@@ -90,7 +92,15 @@ rayon = { version = "1.12", optional = true }
|
||||
hmac = "0.12.1"
|
||||
sha2 = { version = "0.10", default-features = false }
|
||||
getrandom = "0.4"
|
||||
keyring = "4.2"
|
||||
keyring-core = "1.1"
|
||||
|
||||
# The system key store of grant_keys.rs on each platform, connected through keyring-core: the same
|
||||
# store crates and features that keyring 4.2 uses. All MIT OR Apache-2.0.
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
apple-native-keyring-store = { version = "1.0.2", features = ["keychain"] }
|
||||
|
||||
[target.'cfg(all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "android"))))'.dependencies]
|
||||
zbus-secret-service-keyring-store = { version = "1.0.1", features = ["crypto-rust"] }
|
||||
|
||||
[dev-dependencies]
|
||||
# JPEG XL files for the `.jxl` open and place tests.
|
||||
|
||||
@@ -1219,9 +1219,10 @@ fn remove(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
// Settings and cache the store keeps for an id that isn't installed are deleted too.
|
||||
let stored = !installed && vectorcraft_plugins::manifest::valid_id(id) && s.has_plugin_storage(id);
|
||||
// Installed again, it asks again. A grant that can't be removed may still approve the module, and
|
||||
// so may a grants file that can't be opened or read. One that is too large or doesn't hold a
|
||||
// list approves nothing and doesn't stop the removal.
|
||||
let forget = || s.store_grant_in(&turn, id, None) || !s.holds_plugin_grant(id);
|
||||
// so may a grants file that can't be opened or read, or a signed copy of the file put back when
|
||||
// the generation couldn't be raised (the key store can't be reached). Without a plug-in folder
|
||||
// nothing keeps a grant.
|
||||
let forget = || s.store_grant_in(&turn, id, None) || s.plugin_dir.is_none();
|
||||
// Its settings and cache are moved aside and its grant removed before anything is deleted: when
|
||||
// either can't be done, the plug-in stays installed, as it was, and a second `plugin.remove`
|
||||
// tries again.
|
||||
@@ -1237,8 +1238,13 @@ fn remove(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
return Err(EngineError::Other(e));
|
||||
}
|
||||
registry::revoke(id);
|
||||
s.unstore_plugin(&turn, id);
|
||||
if !stored && (!installed || !registry::remove(id)) {
|
||||
// A module stored for an id that isn't installed (one no grant covers is skipped at startup)
|
||||
// counts as removed once its file is gone.
|
||||
let module = !installed && vectorcraft_plugins::manifest::valid_id(id) && s.holds_stored_plugin(id);
|
||||
if !s.unstore_plugin(&turn, id) && module {
|
||||
return Err(EngineError::Other(format!("plugin.remove: can't delete {}", s.stored_plugin_file(id).unwrap_or_default())));
|
||||
}
|
||||
if !stored && !module && (!installed || !registry::remove(id)) {
|
||||
return Err(err(vectorcraft_plugins::Error::NotFound(id.into())));
|
||||
}
|
||||
Ok(json!({"removed": id}))
|
||||
@@ -1315,7 +1321,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Remove Plug-in",
|
||||
[],
|
||||
None,
|
||||
"{id} uninstall a plug-in (its live effects then leave the geometry as it is) and delete the settings and cache it kept (when their folder can't be moved aside, or its grant can't be removed from the plug-in store, the command fails and the plug-in stays installed; when the settings can't be moved back either, the error names the folder they stay in, and the next load, install or removal of the plug-in moves them back); for an id that isn't installed, deletes the settings and cache the plug-in store still keeps for it; it waits while another window or process changes the plug-in store, and when the store's disabled.lock can't be locked, the command fails and nothing is removed → {removed}",
|
||||
"{id} uninstall a plug-in (its live effects then leave the geometry as it is) and delete the settings and cache it kept (when their folder can't be moved aside, or its grant can't be removed from the plug-in store, the command fails and the plug-in stays installed, as it does when the system key store can't be reached to make sure no earlier copy of grants.json grants it again; when the settings can't be moved back either, the error names the folder they stay in, and the next load, install or removal of the plug-in moves them back); for an id that isn't installed, deletes the settings and cache the plug-in store still keeps for it and the module stored for it that didn't load, and reports it removed; it waits while another window or process changes the plug-in store, and when the store's disabled.lock can't be locked, the command fails and nothing is removed → {removed}",
|
||||
always,
|
||||
remove
|
||||
),
|
||||
|
||||
+18
-11
@@ -748,9 +748,11 @@ impl Session {
|
||||
/// doesn't grant it again. The generation is never read from the file; when it can't be raised,
|
||||
/// nothing is recorded. When the key store can't be reached ([`Trust::Unknown`], or
|
||||
/// a key can't be made or kept), the file is left as it is and nothing is recorded, and an entry
|
||||
/// for `id` stays. A grants file that is too large, can't
|
||||
/// be read or doesn't hold a list is left as it is, with a log record, and nothing is recorded;
|
||||
/// so is one whose new content would be larger than `MAX_GRANTS_FILE`. The file is read and
|
||||
/// for `id` stays; a removal then reports a failure, also when the file doesn't name `id`. A
|
||||
/// grants file that is too large, can't be read or doesn't hold a list is left as it is, with a
|
||||
/// log record, and nothing is recorded; so is one whose new content would be larger than
|
||||
/// `MAX_GRANTS_FILE`. A removal still holds for a file that is too large or doesn't hold a list
|
||||
/// once the generation is raised ([`retire_signed_copies`]). The file is read and
|
||||
/// written in `turn`. → whether the store now holds what was asked (`false` without a folder,
|
||||
/// and when `turn` isn't held). When it does, the grant kept for `id` counts again, for every
|
||||
/// session in the process attached to the store ([`Session::ignore_stored_grant`]).
|
||||
@@ -809,11 +811,9 @@ impl Session {
|
||||
Err(e) => {
|
||||
log::warn!("not updating the stored plug-in grants {}: {}", dir.join(GRANTS_FILE).display(), e.why);
|
||||
// A file that is too large or doesn't hold a list grants nothing and is left as it
|
||||
// is, but a signed copy made before it must not grant `id` again once it is put back.
|
||||
if grant.is_none() && !e.unread {
|
||||
retire_signed_copies(dir);
|
||||
}
|
||||
return false;
|
||||
// is, but a signed copy made before it must not grant `id` again once it is put back:
|
||||
// the removal holds once no such copy can.
|
||||
return grant.is_none() && !e.unread && retire_signed_copies(dir);
|
||||
}
|
||||
};
|
||||
#[cfg(test)]
|
||||
@@ -822,9 +822,10 @@ impl Session {
|
||||
}
|
||||
match (file.trust, &grant) {
|
||||
// Nothing in the file can be checked, so nothing in it is rewritten: a grant holds for
|
||||
// the session only, and one the file may still hold for `id` can't be removed.
|
||||
(Trust::Unknown, Some(_)) => return false,
|
||||
(Trust::Unknown, None) => return !file.names(id),
|
||||
// the session only, and one the file may still hold for `id` can't be removed. A file
|
||||
// that doesn't name `id` may not be the one the kept generation was signed for, so the
|
||||
// removal isn't known to hold either.
|
||||
(Trust::Unknown, _) => return false,
|
||||
// The file grants nothing. A new grant replaces it with a signed file that holds that
|
||||
// grant alone; removing one takes its entry out and leaves the rest unsigned.
|
||||
(Trust::Unsigned, Some(_)) => {
|
||||
@@ -875,6 +876,12 @@ impl Session {
|
||||
})
|
||||
}
|
||||
|
||||
/// Does the attached plug-in store hold a module file for the plug-in `id`, loaded or not (one
|
||||
/// that no grant covers is skipped at startup and stays in the folder)?
|
||||
pub(crate) fn holds_stored_plugin(&self, id: &str) -> bool {
|
||||
self.plugin_dir.as_deref().is_some_and(|dir| std::fs::symlink_metadata(dir.join(format!("{}.{PLUGIN_EXT}", file_stem(id)))).is_ok())
|
||||
}
|
||||
|
||||
/// Remove the plug-in `id` from the store in `turn` → whether its file is gone (`false` without a
|
||||
/// folder, and when `turn` isn't held).
|
||||
pub(crate) fn unstore_plugin(&self, turn: &StoreTurn, id: &str) -> bool {
|
||||
|
||||
@@ -260,11 +260,26 @@ fn from_hex(tag: &str) -> Option<Vec<u8>> {
|
||||
pairs.iter().map(|&[high, low]| Some((digit(high)? << 4) | digit(low)?)).collect()
|
||||
}
|
||||
|
||||
/// The system's key store, through `keyring`. The key is read once and kept for the process.
|
||||
/// The system's key store, through `keyring-core` and the store crate of the platform. The key is
|
||||
/// read from the store each time it is needed. The key and the generations are kept as lower-case
|
||||
/// hexadecimal text, since some stores (KDE Wallet behind the Secret Service) keep only UTF-8.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
#[derive(Default)]
|
||||
struct OsGrantKeys {
|
||||
read: Mutex<Option<GrantKey>>,
|
||||
/// Held while a key is kept, so that the threads of the process that make the first key at the
|
||||
/// same time keep one.
|
||||
making: Mutex<()>,
|
||||
/// The connection to the system's key store, once one is made. A failed connection is not
|
||||
/// kept: the next call tries again, so a key store that starts after VectorCraft is used.
|
||||
store: Mutex<Option<Arc<keyring_core::CredentialStore>>>,
|
||||
/// How a connection is made ([`connect`]).
|
||||
connect: fn() -> Result<Arc<keyring_core::CredentialStore>, keyring_core::Error>,
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl Default for OsGrantKeys {
|
||||
fn default() -> Self {
|
||||
OsGrantKeys { making: Mutex::default(), store: Mutex::default(), connect }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
@@ -272,96 +287,141 @@ impl OsGrantKeys {
|
||||
const SERVICE: &str = "org.storytold.vectorcraft.plugin-grants";
|
||||
const ACCOUNT: &str = "hmac-sha256-v1";
|
||||
|
||||
fn entry() -> Result<keyring::Entry, KeyStoreError> {
|
||||
keyring::Entry::new(Self::SERVICE, Self::ACCOUNT).map_err(store_error)
|
||||
/// The system's key store: the connection made before, else a new one.
|
||||
fn store(&self) -> Result<Arc<keyring_core::CredentialStore>, KeyStoreError> {
|
||||
let mut store = self.store.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if let Some(store) = store.as_ref() {
|
||||
return Ok(store.clone());
|
||||
}
|
||||
Ok(store.insert((self.connect)().map_err(store_error)?).clone())
|
||||
}
|
||||
|
||||
fn entry(&self, account: &str) -> Result<keyring_core::Entry, KeyStoreError> {
|
||||
self.store()?.build(Self::SERVICE, account, None).map_err(store_error)
|
||||
}
|
||||
|
||||
fn key_entry(&self) -> Result<keyring_core::Entry, KeyStoreError> {
|
||||
self.entry(Self::ACCOUNT)
|
||||
}
|
||||
|
||||
/// The key the system's key store keeps, read from it.
|
||||
fn stored(entry: &keyring::Entry) -> Result<Option<GrantKey>, KeyStoreError> {
|
||||
fn stored(entry: &keyring_core::Entry) -> Result<Option<GrantKey>, KeyStoreError> {
|
||||
match entry.get_secret() {
|
||||
// A secret of another length is not a key this version made: there is none.
|
||||
Ok(secret) => Ok(<[u8; KEY_LEN]>::try_from(secret.as_slice()).ok().map(GrantKey)),
|
||||
Err(keyring::Error::NoEntry) => Ok(None),
|
||||
// A secret that is not 64 hexadecimal digits is not a key this version made: there is none.
|
||||
Ok(secret) => Ok(std::str::from_utf8(&secret)
|
||||
.ok()
|
||||
.and_then(from_hex)
|
||||
.and_then(|bytes| <[u8; KEY_LEN]>::try_from(bytes.as_slice()).ok())
|
||||
.map(GrantKey)),
|
||||
Err(keyring_core::Error::NoEntry) => Ok(None),
|
||||
Err(e) => Err(store_error(e)),
|
||||
}
|
||||
}
|
||||
|
||||
/// The entry of the generation of the plug-in store whose folder is `folder`: the account
|
||||
/// `generation-v1-` followed by the SHA-256 of the folder in hexadecimal digits.
|
||||
fn generation_entry(folder: &Path) -> Result<keyring::Entry, KeyStoreError> {
|
||||
fn generation_entry(&self, folder: &Path) -> Result<keyring_core::Entry, KeyStoreError> {
|
||||
use sha2::Digest;
|
||||
let digest = sha2::Sha256::digest(folder.as_os_str().as_encoded_bytes());
|
||||
let account: String = digest.iter().map(|b| format!("{b:02x}")).collect();
|
||||
keyring::Entry::new(Self::SERVICE, &format!("generation-v1-{account}")).map_err(store_error)
|
||||
self.entry(&format!("generation-v1-{}", to_hex(&digest)))
|
||||
}
|
||||
}
|
||||
|
||||
/// A connection to the system's key store: Keychain on macOS, Credential Manager on Windows, the
|
||||
/// Secret Service on Linux and the BSDs. The same stores, made the same way, that `keyring` 4.2
|
||||
/// uses, so entries it kept are read.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn connect() -> Result<Arc<keyring_core::CredentialStore>, keyring_core::Error> {
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let store: Arc<keyring_core::CredentialStore> = apple_native_keyring_store::keychain::Store::new()?;
|
||||
Ok(store)
|
||||
}
|
||||
#[cfg(windows)]
|
||||
{
|
||||
let store: Arc<keyring_core::CredentialStore> = windows_native_keyring_store::Store::new()?;
|
||||
Ok(store)
|
||||
}
|
||||
#[cfg(all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "android"))))]
|
||||
{
|
||||
let store: Arc<keyring_core::CredentialStore> = zbus_secret_service_keyring_store::Store::new()?;
|
||||
Ok(store)
|
||||
}
|
||||
#[cfg(not(any(target_os = "macos", windows, all(unix, not(any(target_os = "macos", target_os = "ios", target_os = "android"))))))]
|
||||
Err(keyring_core::Error::NoDefaultStore)
|
||||
}
|
||||
|
||||
/// `bytes` as lower-case hexadecimal digits.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn to_hex(bytes: &[u8]) -> String {
|
||||
bytes.iter().map(|b| format!("{b:02x}")).collect()
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
impl GrantKeyStore for OsGrantKeys {
|
||||
/// Read from the key store each time, so that a key removed or replaced there is not used.
|
||||
fn key(&self) -> Result<Option<GrantKey>, KeyStoreError> {
|
||||
let mut read = self.read.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if let Some(key) = read.as_ref() {
|
||||
return Ok(Some(key.clone()));
|
||||
}
|
||||
Ok(Self::stored(&Self::entry()?)?.map(|key| read.insert(key).clone()))
|
||||
Self::stored(&self.key_entry()?)
|
||||
}
|
||||
|
||||
fn set_key(&self, key: &GrantKey) -> Result<(), KeyStoreError> {
|
||||
let mut read = self.read.lock().unwrap_or_else(|e| e.into_inner());
|
||||
Self::entry()?.set_secret(&key.0).map_err(store_error)?;
|
||||
*read = Some(key.clone());
|
||||
Ok(())
|
||||
let _making = self.making.lock().unwrap_or_else(|e| e.into_inner());
|
||||
self.key_entry()?.set_secret(to_hex(&key.0).as_bytes()).map_err(store_error)
|
||||
}
|
||||
|
||||
/// Reads the key store again, not the key read before, and makes the key only while holding
|
||||
/// [`creation_lock`], so that processes of this user that make the first key at the same time
|
||||
/// all keep the first one made.
|
||||
/// Reads the key store again and makes the key only while holding [`creation_lock`], so that
|
||||
/// processes of this user that make the first key at the same time all keep the first one made.
|
||||
fn create_key(&self) -> Result<GrantKey, KeyStoreError> {
|
||||
let mut read = self.read.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let entry = Self::entry()?;
|
||||
let _making = self.making.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let entry = self.key_entry()?;
|
||||
if let Some(key) = Self::stored(&entry)? {
|
||||
return Ok(read.insert(key).clone());
|
||||
return Ok(key);
|
||||
}
|
||||
let _turn = creation_lock()?;
|
||||
let key = match Self::stored(&entry)? {
|
||||
Some(key) => key,
|
||||
match Self::stored(&entry)? {
|
||||
Some(key) => Ok(key),
|
||||
None => {
|
||||
entry.set_secret(&GrantKey::random()?.0).map_err(store_error)?;
|
||||
Self::stored(&entry)?.ok_or_else(|| KeyStoreError("the key store didn't keep the key".into()))?
|
||||
entry.set_secret(to_hex(&GrantKey::random()?.0).as_bytes()).map_err(store_error)?;
|
||||
Self::stored(&entry)?.ok_or_else(|| KeyStoreError("the key store didn't keep the key".into()))
|
||||
}
|
||||
};
|
||||
*read = Some(key.clone());
|
||||
Ok(key)
|
||||
}
|
||||
}
|
||||
|
||||
/// Read from the key store each time, since another process on the folder may have raised it.
|
||||
/// A kept value that is not 8 bytes is an error, so that nothing counts as signed with it.
|
||||
/// A kept value that is not 16 hexadecimal digits is an error, so that nothing counts as signed
|
||||
/// with it.
|
||||
fn generation(&self, folder: &Path) -> Result<Option<u64>, KeyStoreError> {
|
||||
match Self::generation_entry(folder)?.get_secret() {
|
||||
Ok(secret) => <[u8; 8]>::try_from(secret.as_slice())
|
||||
match self.generation_entry(folder)?.get_secret() {
|
||||
Ok(secret) => std::str::from_utf8(&secret)
|
||||
.ok()
|
||||
.and_then(from_hex)
|
||||
.and_then(|bytes| <[u8; 8]>::try_from(bytes.as_slice()).ok())
|
||||
.map(|bytes| Some(u64::from_be_bytes(bytes)))
|
||||
.map_err(|_| KeyStoreError("the key store holds a generation of another length".into())),
|
||||
Err(keyring::Error::NoEntry) => Ok(None),
|
||||
.ok_or_else(|| KeyStoreError("the key store holds a generation that is not 16 hexadecimal digits".into())),
|
||||
Err(keyring_core::Error::NoEntry) => Ok(None),
|
||||
Err(e) => Err(store_error(e)),
|
||||
}
|
||||
}
|
||||
|
||||
fn set_generation(&self, folder: &Path, generation: u64) -> Result<(), KeyStoreError> {
|
||||
Self::generation_entry(folder)?.set_secret(&generation.to_be_bytes()).map_err(store_error)
|
||||
self.generation_entry(folder)?.set_secret(to_hex(&generation.to_be_bytes()).as_bytes()).map_err(store_error)
|
||||
}
|
||||
}
|
||||
|
||||
/// `vectorcraft-plugin-grant-key.lock` in a folder of this user's own, locked until the file is
|
||||
/// dropped, waiting while another process holds it: the temporary folder on Windows and macOS,
|
||||
/// `$XDG_RUNTIME_DIR` elsewhere. An error when there is no such folder or the file can't be
|
||||
/// locked: no key is made then.
|
||||
/// dropped, waiting while another process holds it: `%LOCALAPPDATA%` on Windows, the temporary
|
||||
/// folder on macOS, `$XDG_RUNTIME_DIR` elsewhere. An error when there is no such folder or the file
|
||||
/// can't be locked: no key is made then.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn creation_lock() -> Result<std::fs::File, KeyStoreError> {
|
||||
#[cfg(any(windows, target_os = "macos"))]
|
||||
let dir = Some(std::env::temp_dir());
|
||||
#[cfg(windows)]
|
||||
let (dir, variable) = (std::env::var_os("LOCALAPPDATA"), "%LOCALAPPDATA%");
|
||||
#[cfg(target_os = "macos")]
|
||||
let (dir, variable) = (Some(std::env::temp_dir().into_os_string()), "$TMPDIR");
|
||||
#[cfg(not(any(windows, target_os = "macos")))]
|
||||
let dir = std::env::var_os("XDG_RUNTIME_DIR").map(std::path::PathBuf::from).filter(|dir| dir.is_absolute());
|
||||
let dir = dir.ok_or_else(|| KeyStoreError("there is no folder for the key's lock ($XDG_RUNTIME_DIR is not set)".into()))?;
|
||||
let (dir, variable) = (std::env::var_os("XDG_RUNTIME_DIR"), "$XDG_RUNTIME_DIR");
|
||||
let dir = dir.map(std::path::PathBuf::from).filter(|dir| dir.is_absolute());
|
||||
let dir = dir.ok_or_else(|| KeyStoreError(format!("there is no folder for the key's lock ({variable} is not set)")))?;
|
||||
let file = std::fs::File::options()
|
||||
.create(true)
|
||||
.truncate(false)
|
||||
@@ -375,11 +435,64 @@ fn creation_lock() -> Result<std::fs::File, KeyStoreError> {
|
||||
|
||||
/// What a key store error says, without the secret some of them hold.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn store_error(e: keyring::Error) -> KeyStoreError {
|
||||
fn store_error(e: keyring_core::Error) -> KeyStoreError {
|
||||
KeyStoreError(match e {
|
||||
keyring::Error::NoStorageAccess(e) => format!("the key store is locked or can't be reached ({e})"),
|
||||
keyring::Error::PlatformFailure(e) => format!("the key store failed ({e})"),
|
||||
keyring::Error::NoDefaultStore => "there is no key store".into(),
|
||||
keyring_core::Error::NoStorageAccess(e) => format!("the key store is locked or can't be reached ({e})"),
|
||||
keyring_core::Error::PlatformFailure(e) => format!("the key store failed ({e})"),
|
||||
keyring_core::Error::NoDefaultStore => "there is no key store".into(),
|
||||
_ => "the key store can't read or keep the key".into(),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use keyring_core::api::CredentialStoreApi;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
/// Connections asked for from [`flaky`].
|
||||
static TRIES: AtomicUsize = AtomicUsize::new(0);
|
||||
/// The store [`flaky`] connects to.
|
||||
static MOCK: LazyLock<Arc<keyring_core::mock::Store>> = LazyLock::new(|| keyring_core::mock::Store::new().unwrap());
|
||||
|
||||
/// A key store that can't be reached on the first try and is reached on every later one.
|
||||
fn flaky() -> Result<Arc<keyring_core::CredentialStore>, keyring_core::Error> {
|
||||
if TRIES.fetch_add(1, Ordering::SeqCst) == 0 {
|
||||
return Err(keyring_core::Error::NoDefaultStore);
|
||||
}
|
||||
let store: Arc<keyring_core::CredentialStore> = MOCK.clone();
|
||||
Ok(store)
|
||||
}
|
||||
|
||||
/// The secret `MOCK` keeps for `account`, as it is kept.
|
||||
fn kept(account: &str) -> Vec<u8> {
|
||||
MOCK.build(OsGrantKeys::SERVICE, account, None).unwrap().get_secret().unwrap()
|
||||
}
|
||||
|
||||
/// The system key store is connected again after a connection fails, the key and the
|
||||
/// generations are kept as hexadecimal text, and the key is read from the store each time; a
|
||||
/// value kept as raw bytes is not read as a key or a generation.
|
||||
#[test]
|
||||
fn the_system_key_store_reconnects_and_keeps_text() {
|
||||
let keys = OsGrantKeys { connect: flaky, ..OsGrantKeys::default() };
|
||||
assert!(keys.key().is_err(), "the first connection fails");
|
||||
let key = GrantKey::from_bytes([0xa7; KEY_LEN]);
|
||||
keys.set_key(&key).unwrap();
|
||||
assert_eq!(kept(OsGrantKeys::ACCOUNT), "a7".repeat(KEY_LEN).into_bytes(), "the key is kept as text");
|
||||
assert_eq!(OsGrantKeys { connect: flaky, ..OsGrantKeys::default() }.key().unwrap(), Some(key), "and read back");
|
||||
|
||||
let folder = Path::new("/plug-ins");
|
||||
keys.set_generation(folder, 0x1_0000_0005).unwrap();
|
||||
let account = format!("generation-v1-{}", to_hex(&<sha2::Sha256 as sha2::Digest>::digest(folder.as_os_str().as_encoded_bytes())));
|
||||
assert_eq!(kept(&account), b"0000000100000005", "the generation is kept as text");
|
||||
assert_eq!(keys.generation(folder).unwrap(), Some(0x1_0000_0005));
|
||||
|
||||
MOCK.build(OsGrantKeys::SERVICE, &account, None).unwrap().set_secret(&5u64.to_be_bytes()).unwrap();
|
||||
assert!(keys.generation(folder).is_err(), "a generation kept as raw bytes is an error");
|
||||
MOCK.build(OsGrantKeys::SERVICE, OsGrantKeys::ACCOUNT, None).unwrap().set_secret(&[0xa7; KEY_LEN]).unwrap();
|
||||
assert_eq!(keys.key().unwrap(), None, "a key kept as raw bytes is none, also after a key was read");
|
||||
MOCK.build(OsGrantKeys::SERVICE, OsGrantKeys::ACCOUNT, None).unwrap().set_secret("b8".repeat(KEY_LEN).as_bytes()).unwrap();
|
||||
assert_eq!(keys.key().unwrap(), Some(GrantKey::from_bytes([0xb8; KEY_LEN])), "a key replaced in the key store is the one used");
|
||||
}
|
||||
}
|
||||
@@ -4313,8 +4313,12 @@ fn a_grants_file_changed_outside_vectorcraft_grants_nothing() {
|
||||
change(&mut file);
|
||||
serde_json::to_vec(&file).unwrap()
|
||||
};
|
||||
// At the generation kept for the folder, so that only the MAC tells the file apart.
|
||||
let generation = file["generation"].as_u64().unwrap();
|
||||
let other_key = {
|
||||
let _other = ThreadKeys::using(MemoryGrantKeys::with_key(GrantKey::from_bytes([7; 32])));
|
||||
let keys = MemoryGrantKeys::with_key(GrantKey::from_bytes([7; 32]));
|
||||
crate::store::grant_keys::GrantKeyStore::set_generation(&keys, &crate::store::plugin_store_key(&folder.0), generation).unwrap();
|
||||
let _other = ThreadKeys::using(keys);
|
||||
crate::store::signed_grants_file(&folder.0, &file["grants"].to_string())
|
||||
};
|
||||
let tag = file["mac"].as_str().unwrap().to_string();
|
||||
@@ -4339,6 +4343,7 @@ fn a_grants_file_changed_outside_vectorcraft_grants_nothing() {
|
||||
std::fs::write(&grants, &written).unwrap();
|
||||
std::fs::write(copy.0.join("copied.wasm"), &wasm).unwrap();
|
||||
std::fs::write(copy.0.join("grants.json"), &written).unwrap();
|
||||
crate::store::grant_keys::set_current_generation(&crate::store::plugin_store_key(©.0), generation).unwrap();
|
||||
assert_eq!(starts_from(©.0, id, &data), (false, true), "copied into another folder");
|
||||
assert_eq!(starts_from(&folder.0, id, &data), (true, false), "the file left as written keeps its grant");
|
||||
std::fs::remove_file(&added_file).unwrap();
|
||||
@@ -4459,6 +4464,87 @@ fn an_unreachable_key_store_keeps_approvals_in_the_session() {
|
||||
assert!(!grants.exists());
|
||||
}
|
||||
|
||||
/// While the key store can't be reached, removing a plug-in fails and leaves it installed when no
|
||||
/// earlier signed copy of the grants file can be kept from granting it again: with the grants file
|
||||
/// gone, and with a grants file that doesn't name the plug-in. Once the key store can be reached, the
|
||||
/// removal raises the generation, and the copy put back grants nothing.
|
||||
#[test]
|
||||
fn a_removal_the_key_store_cannot_make_last_fails() {
|
||||
let folder = crate::tests_links::Folder::new("plugin-store-unreachable-remove");
|
||||
let id = "test.engine.permissions.unreachableremove";
|
||||
let wasm = asking(id, r#"["doc.read"]"#, &json!({"objects": []}));
|
||||
let data = vectorcraft_format::base64_encode(&wasm);
|
||||
let grants = folder.0.join("grants.json");
|
||||
let mut s = session();
|
||||
s.attach_plugin_store(folder.0.clone());
|
||||
run(&mut s, "plugin.install", json!({"dataBase64": data, "grant": ["doc.read"]}));
|
||||
let module = std::path::PathBuf::from(s.stored_plugin_file(id).unwrap());
|
||||
let written = std::fs::read(&grants).unwrap();
|
||||
std::fs::remove_file(&grants).unwrap();
|
||||
|
||||
let locked = ThreadKeys::using(UnreachableKeys);
|
||||
let refused = s.execute("plugin.remove", &json!({"id": id})).unwrap_err().to_string();
|
||||
assert!(refused.contains(crate::store::GRANT_NOT_REMOVED), "with the grants file gone: {refused}");
|
||||
assert!(vectorcraft_plugins::registry::get(id).is_some() && module.exists(), "the plug-in stays installed");
|
||||
drop(locked);
|
||||
run(&mut s, "plugin.remove", json!({"id": id}));
|
||||
std::fs::write(&grants, &written).unwrap();
|
||||
std::fs::write(&module, &wasm).unwrap();
|
||||
assert_eq!(starts_from(&folder.0, id, &data), (false, true), "the copy put back grants nothing");
|
||||
std::fs::remove_file(&grants).unwrap();
|
||||
std::fs::remove_file(&module).unwrap();
|
||||
|
||||
let other = "test.engine.permissions.unreachableremoveother";
|
||||
let plain = vectorcraft_format::base64_encode(&asking(id, "[]", &json!({"objects": []})));
|
||||
let other_data = vectorcraft_format::base64_encode(&asking(other, r#"["doc.read"]"#, &json!({"objects": []})));
|
||||
let mut s = session();
|
||||
s.attach_plugin_store(folder.0.clone());
|
||||
run(&mut s, "plugin.install", json!({"dataBase64": other_data, "grant": ["doc.read"]}));
|
||||
run(&mut s, "plugin.install", json!({"dataBase64": plain}));
|
||||
let names: Vec<Value> = crate::store::grant_entries(&std::fs::read(&grants).unwrap()).iter().map(|e| e["id"].clone()).collect();
|
||||
assert_eq!(names, vec![json!(other)], "the grants file doesn't name the plug-in");
|
||||
let locked = ThreadKeys::using(UnreachableKeys);
|
||||
let refused = s.execute("plugin.remove", &json!({"id": id})).unwrap_err().to_string();
|
||||
assert!(refused.contains(crate::store::GRANT_NOT_REMOVED), "with a grants file that can't be checked: {refused}");
|
||||
assert!(vectorcraft_plugins::registry::get(id).is_some() && module.exists(), "the plug-in stays installed");
|
||||
drop(locked);
|
||||
run(&mut s, "plugin.remove", json!({"id": id}));
|
||||
run(&mut s, "plugin.remove", json!({"id": other}));
|
||||
}
|
||||
|
||||
/// A stored plug-in that didn't load, because the grants file of an older version doesn't count, and
|
||||
/// that keeps no settings or cache, is removed with its module and its entry, and the removal
|
||||
/// reports it removed. A removal whose stored module can't be deleted fails.
|
||||
#[test]
|
||||
fn removing_a_stored_plugin_that_did_not_load_reports_it_removed() {
|
||||
use vectorcraft_plugins::permissions::sha256_hex;
|
||||
let folder = crate::tests_links::Folder::new("plugin-store-unloaded-remove");
|
||||
let id = "test.engine.permissions.unloadedremove";
|
||||
let wasm = asking(id, r#"["doc.read"]"#, &json!({"objects": []}));
|
||||
let data = vectorcraft_format::base64_encode(&wasm);
|
||||
let grants = folder.0.join("grants.json");
|
||||
let module = folder.0.join(format!("{}.wasm", crate::store::file_stem(id)));
|
||||
std::fs::write(&grants, serde_json::to_vec(&json!([{"id": id, "hash": sha256_hex(&wasm), "permissions": ["doc.read"]}])).unwrap()).unwrap();
|
||||
std::fs::write(&module, &wasm).unwrap();
|
||||
assert_eq!(starts_from(&folder.0, id, &data), (false, true), "the unsigned list grants nothing");
|
||||
|
||||
let mut s = session();
|
||||
s.attach_plugin_store(folder.0.clone());
|
||||
assert_eq!(s.execute("plugin.remove", &json!({"id": id})).ok(), Some(json!({"removed": id})));
|
||||
assert!(!module.exists(), "the module is removed");
|
||||
assert!(!grants.exists(), "and its entry");
|
||||
assert!(s.execute("plugin.remove", &json!({"id": id})).is_err(), "a second removal finds nothing");
|
||||
|
||||
// A stored module that can't be deleted (here a folder in its place), of a plug-in that keeps
|
||||
// settings, fails the removal.
|
||||
std::fs::create_dir_all(module.join("held")).unwrap();
|
||||
std::fs::create_dir_all(crate::store::plugin_data_dir(&folder.0, id)).unwrap();
|
||||
let refused = s.execute("plugin.remove", &json!({"id": id})).unwrap_err().to_string();
|
||||
assert!(refused.contains("can't delete"), "{refused}");
|
||||
assert!(module.exists());
|
||||
std::fs::remove_dir_all(&module).unwrap();
|
||||
}
|
||||
|
||||
/// A MAC is made over the generation, the grants and the folder, and only the whole MAC of the same
|
||||
/// key, generation, grants and folder verifies. A key's bytes are never printed.
|
||||
#[test]
|
||||
@@ -4610,14 +4696,15 @@ fn a_grant_revoked_without_a_signed_file_doesnt_come_back_with_one() {
|
||||
std::fs::write(&grants, &signed).unwrap();
|
||||
assert_eq!(starts_from(&folder.0, id, &data), (false, true), "the grant revoked over an unsigned file doesn't come back");
|
||||
|
||||
// A file that doesn't hold a list is in place: the revoke isn't recorded, and still raises the
|
||||
// generation.
|
||||
// A file that doesn't hold a list is in place: it is left as it is, and the revoke holds once it
|
||||
// raises the generation.
|
||||
let mut s = session();
|
||||
s.attach_plugin_store(folder.0.clone());
|
||||
run(&mut s, "plugin.install", json!({"dataBase64": data, "grant": ["doc.read"]}));
|
||||
let signed = std::fs::read(&grants).unwrap();
|
||||
std::fs::write(&grants, br#""not a list""#).unwrap();
|
||||
assert!(!s.store_grant(id, None));
|
||||
assert!(s.store_grant(id, None));
|
||||
assert_eq!(std::fs::read(&grants).unwrap(), br#""not a list""#, "the file is left as it is");
|
||||
std::fs::write(&grants, &signed).unwrap();
|
||||
assert_eq!(starts_from(&folder.0, id, &data), (false, true), "the grant revoked over a file without a list doesn't come back");
|
||||
}
|
||||
@@ -4926,7 +5013,7 @@ fn a_write_whose_generation_wasnt_kept_grants_nothing_after_a_revoke() {
|
||||
"not-a-list" => std::fs::write(&grants, br#""not a list""#).unwrap(),
|
||||
_ => std::fs::write(&grants, crate::store::signed_grants_file(&folder.0, &other_grant)).unwrap(),
|
||||
}
|
||||
assert_eq!(s.store_grant(other, None), path != "not-a-list", "{path}");
|
||||
assert!(s.store_grant(other, None), "{path}");
|
||||
std::fs::write(&grants, &unkept).unwrap();
|
||||
assert_eq!(starts_from(&folder.0, other, &other_data), (false, true), "{path}: the revoked grant doesn't come back");
|
||||
assert_eq!(starts_from(&folder.0, id, &data), (false, true), "{path}: the copy grants nothing");
|
||||
|
||||
+5
-3
@@ -13231,9 +13231,11 @@ approval lasts for that session only and the file is left as it is. `plugin.remo
|
||||
forgets the approval, and so does installing a module that lists no permissions under that id: the earlier bytes then
|
||||
need a new approval. A refused install keeps the grant. A failed write of the module to the plug-in store leaves the
|
||||
grant in the store. A stored module that is disabled, or not read in Safe Mode, keeps the grant for its id. When
|
||||
`plugin.remove` can't remove the grant from the plug-in store, it returns an error and the plug-in stays installed.
|
||||
When the plug-in's settings and cache can't be moved back from their `.removed` folder then either, the error names
|
||||
that folder, and the next load, install or `plugin.remove` of the plug-in moves them back. A
|
||||
`plugin.remove` can't remove the grant from the plug-in store, it returns an error and the plug-in stays installed;
|
||||
so does a `plugin.remove` while the system key store can't be reached, also when `grants.json` is missing or doesn't
|
||||
name the plug-in. For an id that isn't installed, `plugin.remove` also deletes the module stored for it that didn't
|
||||
load and returns `{removed}`. When the plug-in's settings and cache can't be moved back from their `.removed` folder
|
||||
then either, the error names that folder, and the next load, install or `plugin.remove` of the plug-in moves them back. A
|
||||
filter without `doc.write` or `state` that returns output needing them gets an error and the document is unchanged.
|
||||
A plug-in of API level 2 (`api: 2` in its entry) that lists `progress` may report its progress, see Cancel and write
|
||||
log lines: `notifications/cancelled` makes its `vc_cancelled` return 1, and its log lines go to the server's log
|
||||
|
||||
+20
-12
@@ -362,27 +362,33 @@ each time it is drawn, and a paint linked to a global swatch is drawn in that sw
|
||||
`mac` is an HMAC-SHA-256 ([RFC 2104](https://www.rfc-editor.org/rfc/rfc2104)), in lower-case hexadecimal, of the
|
||||
folder the file is in, the `generation` and the `grants` list written as compact JSON. The key is 32 random bytes that
|
||||
VectorCraft makes when it records the first grant. VectorCraft keeps the key in the system key store, as the secret of
|
||||
the account `hmac-sha256-v1` of the service `org.storytold.vectorcraft.plugin-grants`, and never in a file:
|
||||
the account `hmac-sha256-v1` of the service `org.storytold.vectorcraft.plugin-grants`, written as 64 lower-case
|
||||
hexadecimal digits, and never in a file:
|
||||
|
||||
- On macOS the key is in the user's Keychain.
|
||||
- On Windows the key is a generic credential in Credential Manager.
|
||||
- On Linux and the BSDs the key is in the Secret Service, for example GNOME Keyring. When its collection is locked,
|
||||
the desktop may ask to unlock it.
|
||||
|
||||
VectorCraft makes the key while it holds `vectorcraft-plugin-grant-key.lock` in the temporary folder on Windows and
|
||||
macOS, and in `$XDG_RUNTIME_DIR` elsewhere. When that file can't be locked, or `$XDG_RUNTIME_DIR` is not set, no key
|
||||
is made, and approvals last for the session only, as when the key store can't be reached.
|
||||
When VectorCraft can't connect to the key store, it tries again the next time it needs the key, so a key store that
|
||||
starts after VectorCraft is used without a restart. VectorCraft reads the key from the key store each time it checks or
|
||||
signs `grants.json`, so a key removed or replaced there is not used.
|
||||
|
||||
The key store also keeps a generation for each `Plug-ins` folder, as an 8-byte secret of the account `generation-v1-`
|
||||
followed by the SHA-256 of the folder's resolved path in hexadecimal, in the same service. A key store that holds no
|
||||
generation for a folder counts as generation 0. VectorCraft reads the generation from the key store only, never from
|
||||
`grants.json`. Each time VectorCraft writes a signed `grants.json`, in the folder's turn (`disabled.lock`), it first
|
||||
VectorCraft makes the key while it holds `vectorcraft-plugin-grant-key.lock` in `%LOCALAPPDATA%` on Windows, in the
|
||||
temporary folder on macOS, and in `$XDG_RUNTIME_DIR` elsewhere. When that file can't be locked, or `%LOCALAPPDATA%` or
|
||||
`$XDG_RUNTIME_DIR` is not set, no key is made, and approvals last for the session only, as when the key store can't be
|
||||
reached.
|
||||
|
||||
The key store also keeps a generation for each `Plug-ins` folder, as a secret of 16 lower-case hexadecimal digits (the
|
||||
generation as an 8-byte big-endian number) of the account `generation-v1-` followed by the SHA-256 of the folder's
|
||||
resolved path in hexadecimal, in the same service. A key store that holds no generation for a folder counts as
|
||||
generation 0. VectorCraft reads the generation from the key store only, never from `grants.json`. Each time VectorCraft writes a signed `grants.json`, in the folder's turn (`disabled.lock`), it first
|
||||
raises the kept generation by two, then writes the file at the generation after the raised one, and then keeps that
|
||||
generation. When it removes a signed `grants.json`, it raises the generation by two first. The kept generation never
|
||||
goes down: when the file can't be written or removed after the raise, the generation stays raised, the file left in
|
||||
place grants nothing, and each plug-in it names that lists permissions asks for approval again. VectorCraft checks
|
||||
before the raise whether the signed file would be larger than 1 MiB; when it would, VectorCraft logs a warning and
|
||||
leaves the file and the generation as they are. When the key store can't keep the generation of a write, the file
|
||||
leaves the file and the generation as they are, and the file keeps its grants. When the key store can't keep the generation of a write, the file
|
||||
just written grants nothing, and the write reports a failure. That file is one generation past the kept one, so the
|
||||
next raise by two moves past it. When the kept generation is within two of the largest 64-bit value, VectorCraft
|
||||
logs a warning and leaves the file and the generation as they are.
|
||||
@@ -393,7 +399,7 @@ names that lists permissions asks for approval again. This covers a file that an
|
||||
list), a grant that another program edited or added, a file whose `mac` was removed or changed, a file copied from
|
||||
another `Plug-ins` folder or another computer, an earlier copy of the file put back after a grant was revoked or the
|
||||
file was removed, a write whose generation the key store didn't keep, a file left in place by a write or removal that
|
||||
failed, and a file whose key is no longer in the key store. The next approval replaces such a file with a signed file that holds that grant alone, making a key first when
|
||||
failed after the generation was raised, and a file whose key is no longer in the key store. The next approval replaces such a file with a signed file that holds that grant alone, making a key first when
|
||||
the key store has none. When a grant is forgotten without an approval (`plugin.remove`, installing a module that lists
|
||||
no permissions under that id, or a folder load that forgets the grant), VectorCraft raises the generation by two, then
|
||||
takes that entry out of such a file and leaves the rest unsigned, so no earlier signed copy brings the entry back. It
|
||||
@@ -404,8 +410,10 @@ store can't raise the generation, VectorCraft logs a warning.
|
||||
|
||||
When the key store can't be reached (it is locked, or a headless Linux session has no Secret Service), no
|
||||
`grants.json` grants anything and VectorCraft writes none: an approval lasts for the session only, the module stored
|
||||
for the id is not replaced, and `plugin.remove` of a plug-in that the file names returns an error, as for a grant that
|
||||
can't be removed. With `VECTORCRAFT_NO_PREFS` set there is no plug-in store, and the web build keeps no grants file. The
|
||||
for the id is not replaced, and `plugin.remove` of a plug-in returns an error and leaves the plug-in installed, as for a
|
||||
grant that can't be removed. This also happens when there is no `grants.json` or the file doesn't name the plug-in.
|
||||
`plugin.remove` of an id that isn't installed deletes the module stored for it that didn't load, such as one an
|
||||
earlier version's `grants.json` approved, and returns `{removed}`. With `VECTORCRAFT_NO_PREFS` set there is no plug-in store, and the web build keeps no grants file. The
|
||||
MAC does not protect against another program running as the same user, which can read the key from the key store or
|
||||
change VectorCraft itself.
|
||||
|
||||
|
||||
@@ -2660,7 +2660,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **An install automation asked for needs the person to start it (G17):** an approval question that a control request, MCP, injected input or a file dialog one of them opened leads to keeps OK disabled and refuses every confirm, a person's click included; it says to choose Object › Plug-ins › Install Plug-in…, and `ui.installPlugin` answers `approval: "personMustStartInstall"`. The person's own Install Plug-in…, File › Open or drop inspects the module again and asks a new question. Automation's `replace: true` no longer skips the question about taking another module's place, and that question now opens in the approval dialog for everyone. VectorCraft's own rule. Regressions: `crates/ui-egui/src/tests/automation.rs`, `crates/ui-egui/src/tests/plugins.rs`. Scores and hours unchanged.
|
||||
- **A plug-in with no permissions ends its id's grant (G17):** installing a module that lists no permissions under a granted id forgets the grant, in the process and in `grants.json`, so the formerly approved bytes need a new approval. Attaching a `Plug-ins` folder whose module for that id lists no permissions forgets it too, and plug-in folders forget the process's grant. A refused install leaves the grant. Regressions: `crates/engine/src/tests/plugins.rs`, `crates/engine/tests/plugin_safe_mode.rs`. Scores and hours unchanged.
|
||||
- **A grant that can't be forgotten stops counting in the whole process (G17):** when such a grant can't be removed from `grants.json`, no session in the process that uses the same `Plug-ins` folder, by any path to it, counts it for `plugin.inspect`, `plugin.install` or loading plug-ins, until `grants.json` can be written for that plug-in; another process on the folder reads `grants.json` as it is. Regressions: `crates/engine/src/tests/plugins.rs`. Scores and hours unchanged.
|
||||
- **An edited grants file grants nothing (G17):** `grants.json` carries a generation and an HMAC-SHA-256 of its folder, generation and grants, made with a random key kept in the system key store (Keychain, Credential Manager, the Secret Service) and compared in constant time; the key store keeps each folder's generation, raised on every signed write and removal and never lowered. A file without that MAC or at another generation (an earlier version's plain list, an edited or added grant, a removed or changed MAC, a file copied from another folder, an earlier copy put back after a revoke, a write whose generation wasn't kept, a file left in place by a failed write or removal) grants nothing, and its plug-ins ask for approval again; the next approval replaces it with a signed file. When the key store can't be reached, an approval lasts for the session only and the file is left as it is. VectorCraft's own rule. Regressions: `crates/engine/src/tests/plugins.rs`. Scores and hours unchanged.
|
||||
- **An edited grants file grants nothing (G17):** `grants.json` carries a generation and an HMAC-SHA-256 of its folder, generation and grants, made with a random key kept in the system key store (Keychain, Credential Manager, the Secret Service) and compared in constant time; the key store keeps each folder's generation, raised on every signed write and removal and never lowered. A file without that MAC or at another generation (an earlier version's plain list, an edited or added grant, a removed or changed MAC, a file copied from another folder, an earlier copy put back after a revoke, a write whose generation wasn't kept, a file left in place by a write or removal that failed after the generation was raised) grants nothing, and its plug-ins ask for approval again; the next approval replaces it with a signed file, and `plugin.remove` of a stored plug-in that didn't load deletes its module and reports it removed. When the key store can't be reached, an approval lasts for the session only, the file is left as it is, and `plugin.remove` fails and leaves the plug-in installed. A key store that can't be reached is tried again the next time it is needed. VectorCraft's own rule. Regressions: `crates/engine/src/tests/plugins.rs`, `crates/engine/src/store/grant_keys.rs`. Scores and hours unchanged.
|
||||
- **Plug-in commands (G17):** a filter or live effect may declare up to 32 `commands` (`{id, label, params?}`); each is the command `plugin.<id>.<command>` while the plug-in is installed, in a submenu named after the plug-in under Object › Plug-ins (Effect › Plug-ins for a live effect) whatever menu the manifest names, with its label escaped. Commands are recorded in actions, listed in Keyboard Shortcuts for the user to give a shortcut, and run through `run` and MCP with their parameters checked first (a command with parameters opens a dialog from its menu item or shortcut). A run uses the plug-in's permissions (a live effect with commands may also hold `doc.write` and `state`, and gets them without a `permissions` list), is one undo step named after the command, and on failure (a trap or an exhausted instruction budget) leaves the document and the undo history as they were with an error naming the plug-in and the command. For a command and for `plugin.run`, an `ids` that is not a list of object ids is an error rather than the selection. A malformed entry is refused by name when the module is installed. Regressions: `crates/plugins/src/manifest.rs`, `crates/plugins/src/permissions.rs`, `crates/engine/src/tests/plugins.rs`, `crates/engine/tests/plugin_fuzz.rs`, `crates/ui-egui/src/tests/plugins.rs`. Scores and hours unchanged.
|
||||
- **Filter plug-ins call commands (G17, #2186):** a filter at plug-in API level 2 with the `commands` permission names the commands it may run in its manifest's `commandAllowlist` and runs them with `env.vc_call`, reading each result with `env.vc_call_result`. Each call sees what the calls before it changed; the calls and the filter's output are one undo step, and a run that fails, is canceled or makes a call that fails leaves every document, its selection and its history as they were. Commands that read or write files, use the clipboard, change preferences or the view, run scripts, actions or plug-ins, switch documents or undo are never called, and a manifest that lists one is refused when the module is installed. A command counts as taking a file or folder when its params description or schema names a file key as a param; a word in the description's prose or result does not count. Each exemption for a key that names part of the document names a param its command takes, which `every_command_is_sorted` checks, and Image Trace's path fidelity setting (`params.paths`, `savedPreset.paths`) is exempt only inside those settings. The install dialog lists the allowed commands. A run makes at most 1,000 calls, and each call costs 10,000 instructions of its budget. Regressions: `crates/plugins/tests/call.rs`, `crates/engine/tests/plugin_call.rs`, `crates/engine/src/cmd/plugin_call.rs`. Scores and hours unchanged.
|
||||
- **The command sweep sends file and folder params into its temp folder by the command catalog:** the sweeps in `crates/engine/tests/command_sweep.rs` take each command's file and folder keys from the catalog (`cmd::location_keys`, the same key list the plug-in call rules use, less the keys that name part of the document in a command), read every key a params description names (`{path | name …}`, `{folder? (…)}` included) and its schema's params, and send every string under such a key, in arrays and in objects inside them (`paths: [{ids, path}]`), as a location in the temp folder, so a command added later is swept and checked without editing the sweep. `diffPath` counts as a file key, and Slice Options' `url` and Export for Screens' `folders` do not. Regressions: `sweep_cases_name_files_only_inside_the_temp_folder` and `sweep_cases_send_the_file_keys_of_the_command_catalog` in `command_sweep`, `location_keys_come_from_the_command_catalog` in `cmd::plugin_call`. Scores and hours unchanged.
|
||||
|
||||
Reference in new issue
Block a user