From 9243bda859cdb946f14a03e6fc07a0e942d7beee Mon Sep 17 00:00:00 2001 From: VirtualMachinist Date: Mon, 26 Oct 2026 16:08:54 -0400 Subject: [PATCH] fix(vault): x25519 recipients can open their vault; rotate fails closed An identity added with `vault add-recipient --gpub` could not open the vault: load_recipients_for only matched symmetric recipients, so the added key got an authentication failure on verify/list/cat/open/rotate. Rotating with the original key while dropping itself then left a vault that no key could read. - load_recipients_for unwraps the epoch key from the X25519 recipient whose public matches the identity (ISK-derived X25519 secret). - vault rotate reseals from the epoch key it actually unwrapped instead of re-deriving it from the operator ISK (which reset the manifest when an X25519 identity rotated). - vault rotate refuses, before any write, a kept symmetric recipient it cannot re-wrap, an unusable X25519 public, or a kept set nobody can open; verifies the new wraps, manifest and resealed objects before the header commit; and restores the old epoch on any failure. - geode open writes extracted plaintext owner-only (0600 for a 0644 entry), created with that mode. Regression tests: add-recipient key reads; drop old + reseal keeps the new key and locks out the old; lockout rotate refused with the vault unchanged; open output is 0600. --- CHANGELOG.md | 10 ++ crates/geode-cli/src/cmd/key.rs | 12 +- crates/geode-cli/src/cmd/mod.rs | 29 +++- crates/geode-cli/src/cmd/open.rs | 54 +++++- crates/geode-cli/src/cmd/vault.rs | 248 +++++++++++++++++++++++---- crates/geode-cli/tests/rotate_cli.rs | 148 ++++++++++++++++ 6 files changed, 457 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ffffd0..ad72d09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,16 @@ Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Versioning: se ## [Unreleased] +### Fixed + +- An identity added with `vault add-recipient --gpub` (or `vault rotate --add-recipient`) can now open its vault: `verify`, `list`, `cat`, `open` and `rotate` unwrap the epoch key from the identity's X25519 recipient entry. Before, only symmetric recipients were matched and the added key failed with an authentication error. +- `vault rotate` reseals from the epoch key it actually unwrapped, so a rotation run by an X25519 identity no longer resets the current manifest. +- `vault rotate` fails closed: it refuses a kept symmetric recipient it cannot re-wrap (that recipient would be locked out), an unusable X25519 public, or a kept set no one can open; it verifies the new wraps, the new manifest and every resealed object before the header commits, and restores the old epoch on any failure. + +### Security + +- `geode open` writes extracted files owner-only (0600 for a 0644 entry; owner bits kept, group and other cleared), created with that mode so plaintext is never briefly world-readable. + ## [3.0.0] — 2026-10-26 ### BREAKING diff --git a/crates/geode-cli/src/cmd/key.rs b/crates/geode-cli/src/cmd/key.rs index fb6082d..f3c8507 100644 --- a/crates/geode-cli/src/cmd/key.rs +++ b/crates/geode-cli/src/cmd/key.rs @@ -271,10 +271,14 @@ fn keychain_store(path: &Path, label: &str, key_id: &KeyId, pass: &str) -> Resul } /// Derive the identity's X25519 static secret from the ISK (BLAKE3-expand -/// stream, 02-cryptography 6.3) and return the public key bytes. -fn x25519_public(isk: &[u8; 32]) -> [u8; 32] { - let sk_bytes = blake3::derive_key(X25519_IDENTITY_DOMAIN, isk); - let sk = x25519_dalek::StaticSecret::from(sk_bytes); +/// stream, 02-cryptography 6.3). Secret material: never log or print. +pub(crate) fn x25519_secret(isk: &[u8; 32]) -> zeroize::Zeroizing<[u8; 32]> { + zeroize::Zeroizing::new(blake3::derive_key(X25519_IDENTITY_DOMAIN, isk)) +} + +/// The identity's X25519 public key (the `.gpub` `x25519_public`). +pub(crate) fn x25519_public(isk: &[u8; 32]) -> [u8; 32] { + let sk = x25519_dalek::StaticSecret::from(*x25519_secret(isk)); x25519_dalek::PublicKey::from(&sk).to_bytes() } diff --git a/crates/geode-cli/src/cmd/mod.rs b/crates/geode-cli/src/cmd/mod.rs index 3204bd3..ccafb4b 100644 --- a/crates/geode-cli/src/cmd/mod.rs +++ b/crates/geode-cli/src/cmd/mod.rs @@ -296,17 +296,40 @@ fn load_recipients_for( let rec_text = std::fs::read_to_string(root.join("recipients.json")).map_err(Error::Io)?; let recs: Recipients = serde_json::from_str(&rec_text) .map_err(|e| Error::Format(format!("recipients.json: {e}")))?; + let own_public = key::x25519_public(isk.as_bytes()); for r in &recs.recipients { - if let Recipient::Symmetric { key_id: kid, .. } = r { - if kid.0 == key_id { + match r { + Recipient::Symmetric { key_id: kid, .. } if kid.0 == key_id => { return recipients::unwrap_symmetric(r, isk, vault_id, epoch); } + // A recipient added with `vault add-recipient --gpub` (or + // `rotate --add-recipient`) holds an X25519 wrap of the EK; its + // identity unwraps it with the ISK-derived X25519 secret. + Recipient::X25519 { public, .. } if x25519_public_matches(public, &own_public) => { + let sk = key::x25519_secret(isk.as_bytes()); + return recipients::unwrap_x25519(r, &sk, vault_id, epoch); + } + _ => {} } } Err(Error::AuthFail) } -fn load_manifest(root: &Path, ek: &EpochKey, vault_id: VaultId, epoch: Epoch) -> Result { +/// True when a recipient's base64 X25519 public equals `own` (constant time). +pub(crate) fn x25519_public_matches(public_b64: &str, own: &[u8; 32]) -> bool { + use base64ct::{Base64, Encoding}; + match Base64::decode_vec(public_b64) { + Ok(bytes) if bytes.len() == 32 => geode_grotto::zero::ct_eq(&bytes, own), + _ => false, + } +} + +pub(crate) fn load_manifest( + root: &Path, + ek: &EpochKey, + vault_id: VaultId, + epoch: Epoch, +) -> Result { let mk = kdf::derive_manifest_key(ek, vault_id, epoch); let mjson = read_json(&manifest_path(root, epoch))?; verify_json_mac(&mk, &mjson, "manifest_mac")?; diff --git a/crates/geode-cli/src/cmd/open.rs b/crates/geode-cli/src/cmd/open.rs index b7f799b..429fb8a 100644 --- a/crates/geode-cli/src/cmd/open.rs +++ b/crates/geode-cli/src/cmd/open.rs @@ -66,6 +66,52 @@ fn read_entry_plaintext(ctx: &cmd::VaultCtx, vault: &Path, e: &Entry) -> Result< Ok(data) } +/// Owner-only mode for extracted plaintext: keep the owner bits of the +/// sealed mode (so an owner-executable stays executable), never group or +/// other, and always owner read+write. A 0644 entry lands as 0600. +#[cfg(unix)] +pub(crate) fn private_mode(sealed_mode: u32) -> u32 { + (sealed_mode & 0o700) | 0o600 +} + +/// Write extracted plaintext atomically. On unix the temp file is created +/// 0600 before any byte is written, so the plaintext is never visible to +/// group/other, even transiently. +fn write_plaintext(target: &Path, data: &[u8], sealed_mode: u32) -> Result<()> { + #[cfg(unix)] + { + use std::io::Write as _; + use std::os::unix::fs::{OpenOptionsExt, PermissionsExt}; + let parent = target + .parent() + .ok_or_else(|| Error::Format("open target has no parent".into()))?; + let mut nonce = [0u8; 8]; + getrandom::fill(&mut nonce).map_err(|e| Error::Format(format!("rng: {e}")))?; + let tmp = parent.join(format!(".gde-open-{}", cmd::hex(&nonce))); + let res = (|| -> std::io::Result<()> { + let mut f = std::fs::OpenOptions::new() + .write(true) + .create_new(true) + .mode(0o600) + .open(&tmp)?; + f.write_all(data)?; + f.sync_all()?; + f.set_permissions(std::fs::Permissions::from_mode(private_mode(sealed_mode)))?; + std::fs::rename(&tmp, target) + })(); + if let Err(e) = res { + let _ = std::fs::remove_file(&tmp); + return Err(Error::Io(e)); + } + Ok(()) + } + #[cfg(not(unix))] + { + let _ = sealed_mode; + corevault::write_atomic(target, data) + } +} + pub fn run(args: &OpenArgs, global: &GlobalArgs, out: OutMode) -> Result<()> { let key_path = cmd::require_key(global)?; let isk = cmd::load_isk(&key_path)?; @@ -125,13 +171,7 @@ pub fn run(args: &OpenArgs, global: &GlobalArgs, out: OutMode) -> Result<()> { } EntryKind::File => { let data = read_entry_plaintext(&ctx, &args.vault, e)?; - corevault::write_atomic(&target, &data)?; - #[cfg(unix)] - { - use std::os::unix::fs::PermissionsExt; - std::fs::set_permissions(&target, std::fs::Permissions::from_mode(e.mode)) - .map_err(Error::Io)?; - } + write_plaintext(&target, &data, e.mode)?; files += 1; plain_bytes += data.len() as u64; } diff --git a/crates/geode-cli/src/cmd/vault.rs b/crates/geode-cli/src/cmd/vault.rs index 6213523..6eb513c 100644 --- a/crates/geode-cli/src/cmd/vault.rs +++ b/crates/geode-cli/src/cmd/vault.rs @@ -336,7 +336,10 @@ fn rotate(args: &RotateArgs, global: &GlobalArgs, out: OutMode) -> Result<()> { let recs: Recipients = serde_json::from_str(&rec_text) .map_err(|e| Error::Format(format!("recipients.json: {e}")))?; let keep = select_keep(recs.recipients, &args.drop_recipient, &args.add_recipient)?; - snapshot_old_recipients(&args.dir, ctx.epoch, &rec_text)?; + let own_public = cmd::key::x25519_public(isk.as_bytes()); + // Refuse before anything touches disk: a kept recipient this operator + // cannot re-wrap correctly, or a kept set nobody could open. + check_keep_reachable(&keep, ctx.key_id)?; let generator = format!("geode {}", env!("CARGO_PKG_VERSION")); let generated_at = now_ms() / 1000; @@ -346,36 +349,54 @@ fn rotate(args: &RotateArgs, global: &GlobalArgs, out: OutMode) -> Result<()> { context_label: "", keep, }; - let outcome = rotate::rotate_epoch(&isk, &args.dir, &plan, &generator, generated_at)?; - let mut objects = 0u64; - if args.reseal { - objects = rotate::reseal( - &args.dir, - ctx.vault_id, - &rotate::EpochKeys { - old_epoch: ctx.epoch, - old_ek: &outcome.old_ek, - new_epoch: outcome.new_epoch, - new_ek: &outcome.new_ek, - }, - &rotate::RotationStamp { - generator: &generator, - generated_at, - }, - )?; - } - let policy_resealed = rotate::reseal_policy( - &args.dir, - ctx.vault_id, - &rotate::EpochKeys { - old_epoch: ctx.epoch, - old_ek: &outcome.old_ek, - new_epoch: outcome.new_epoch, - new_ek: &outcome.new_ek, - }, - )?; - bump_header_epoch(&args.dir, outcome.new_epoch, &outcome.new_ek, ctx.vault_id)?; + let outcome = rotate::plan_rotation(&isk, &plan)?; + // Every kept wrap must carry the new EK before anything is written. + verify_new_wraps(&outcome, &isk, ctx.vault_id, &own_public)?; + // The old EK is the one this operator actually unwrapped (`ctx.ek`). + // `outcome.old_ek` is re-derived from the operator's ISK, which only + // matches for the vault's original symmetric identity. + let keys = rotate::EpochKeys { + old_epoch: ctx.epoch, + old_ek: &ctx.ek, + new_epoch: outcome.new_epoch, + new_ek: &outcome.new_ek, + }; + let backup = RotateBackup::take(&args.dir, outcome.new_epoch, &rec_text)?; + let staged = (|| -> Result<(u64, bool)> { + snapshot_old_recipients(&args.dir, ctx.epoch, &rec_text)?; + rotate::commit_rotation(&args.dir, ctx.vault_id, &outcome, &generator, generated_at)?; + // Without reseal the new epoch starts from the current entries + // (old-epoch objects stay readable through the old EK snapshot). + let objects = if args.reseal { + rotate::reseal( + &args.dir, + ctx.vault_id, + &keys, + &rotate::RotationStamp { + generator: &generator, + generated_at, + }, + )? + } else { + 0 + }; + let policy_resealed = rotate::reseal_policy(&args.dir, ctx.vault_id, &keys)?; + verify_new_epoch(&args.dir, ctx.vault_id, outcome.new_epoch, &outcome.new_ek)?; + bump_header_epoch(&args.dir, outcome.new_epoch, &outcome.new_ek, ctx.vault_id)?; + // If this operator kept access, the committed vault must load. + if operator_kept(&outcome.new_recipients.recipients, ctx.key_id, &own_public) { + cmd::load_vault(&args.dir, &isk)?; + } + Ok((objects, policy_resealed)) + })(); drop(isk); + let (objects, policy_resealed) = match staged { + Ok(v) => v, + Err(e) => { + backup.restore(&args.dir); + return Err(e); + } + }; let dropped: Vec = args .drop_recipient @@ -420,6 +441,173 @@ fn rotate(args: &RotateArgs, global: &GlobalArgs, out: OutMode) -> Result<()> { Ok(()) } +/// True when `r` is this operator's own recipient entry. +fn is_own(r: &Recipient, own_key_id: kdf::KeyId, own_public: &[u8; 32]) -> bool { + match r { + Recipient::Symmetric { key_id, .. } => *key_id == own_key_id, + Recipient::X25519 { public, .. } => cmd::x25519_public_matches(public, own_public), + Recipient::Hybrid { .. } => false, + } +} + +fn operator_kept(keep: &[Recipient], own_key_id: kdf::KeyId, own_public: &[u8; 32]) -> bool { + keep.iter().any(|r| is_own(r, own_key_id, own_public)) +} + +/// A usable X25519 recipient public: 32 bytes, not a low-order point (a +/// low-order public makes the wrap's shared secret all-zero). +fn x25519_public_usable(public_b64: &str) -> bool { + let Ok(bytes) = Base64::decode_vec(public_b64) else { + return false; + }; + let Ok(pk) = <[u8; 32]>::try_from(bytes.as_slice()) else { + return false; + }; + let probe = x25519_dalek::StaticSecret::from([0x42u8; 32]); + probe + .diffie_hellman(&x25519_dalek::PublicKey::from(pk)) + .was_contributory() +} + +/// Lockout guard (fail closed, before any write). +/// +/// - A symmetric recipient is re-wrapped under the rotating key's ISK, so a +/// symmetric recipient that is NOT this operator would be silently +/// re-wrapped to a key it cannot derive; refuse and say how to proceed. +/// - Every kept X25519 public must be a usable curve point. +/// - At least one kept recipient must be able to open the new epoch. +fn check_keep_reachable(keep: &[Recipient], own_key_id: kdf::KeyId) -> Result<()> { + let mut reachable = 0usize; + for r in keep { + match r { + Recipient::Symmetric { key_id, .. } => { + if *key_id != own_key_id { + return Err(Error::Format(format!( + "symmetric recipient {} can only be re-wrapped by its own key; \ + rotate with that key or --drop-recipient it (refusing: it would be locked out)", + cmd::hex(&key_id.0) + ))); + } + reachable += 1; + } + Recipient::X25519 { key_id, public, .. } => { + if !x25519_public_usable(public) { + return Err(Error::Format(format!( + "x25519 recipient {} has an unusable public key (refusing rotate)", + cmd::hex(&key_id.0) + ))); + } + reachable += 1; + } + Recipient::Hybrid { .. } => {} + } + } + if reachable == 0 { + return Err(Error::Format( + "rotate would leave no recipient able to open the vault (refusing lockout)".into(), + )); + } + Ok(()) +} + +/// Check the planned wraps before commit: every recipient this operator can +/// open must unwrap to exactly the new EK; X25519 wraps for other +/// identities must at least parse for their stored public. +fn verify_new_wraps( + outcome: &rotate::RotateOutcome, + isk: &kdf::IdentitySecret, + vault_id: kdf::VaultId, + own_public: &[u8; 32], +) -> Result<()> { + let own_key_id = kdf::derive_key_id(isk)?; + let epoch = outcome.new_epoch; + for r in &outcome.new_recipients.recipients { + if !is_own(r, own_key_id, own_public) { + continue; + } + let ek = match r { + Recipient::Symmetric { .. } => recipients::unwrap_symmetric(r, isk, vault_id, epoch)?, + Recipient::X25519 { .. } => { + let sk = cmd::key::x25519_secret(isk.as_bytes()); + recipients::unwrap_x25519(r, &sk, vault_id, epoch)? + } + Recipient::Hybrid { .. } => return Err(Error::NotImplemented), + }; + if !geode_grotto::zero::ct_eq(ek.as_bytes(), outcome.new_ek.as_bytes()) { + return Err(Error::AuthFail); + } + } + Ok(()) +} + +/// Before the header bump commits the rotation: the new-epoch manifest must +/// authenticate under the new EK and every object it names must open. +fn verify_new_epoch( + root: &Path, + vault_id: kdf::VaultId, + epoch: Epoch, + ek: &EpochKey, +) -> Result<()> { + let manifest = cmd::load_manifest(root, ek, vault_id, epoch)?; + for e in &manifest.entries { + if e.kind == geode_grotto::manifest::EntryKind::Dir { + continue; + } + let raw = geode_grotto::vault::read_object(root, epoch, &e.object_id)?; + if raw.len() < geode_grotto::object::HEADER_SIZE { + return Err(Error::AuthFail); + } + let bind: &[u8] = if e.bind { e.path.as_bytes() } else { b"" }; + let (hs, body) = raw.split_at(geode_grotto::object::HEADER_SIZE); + geode_grotto::object::open_object(ek, hs, body, bind)?; + } + Ok(()) +} + +/// What rotate restores if any step fails: the vault stays on the old epoch. +struct RotateBackup { + recipients: String, + header: Vec, + policy: Option>, + new_epoch_dir: Option, +} + +impl RotateBackup { + fn take(root: &Path, new_epoch: Epoch, rec_text: &str) -> Result { + let header = std::fs::read(root.join("header.json")).map_err(Error::Io)?; + let pol = geode_grotto::policy::policy_path(root); + let policy = if pol.exists() { + Some(std::fs::read(&pol).map_err(Error::Io)?) + } else { + None + }; + let dir = rotate::epoch_recipients_path(root, new_epoch) + .parent() + .map(Path::to_path_buf); + let new_epoch_dir = dir.filter(|d| !d.exists()); + Ok(Self { + recipients: rec_text.to_string(), + header, + policy, + new_epoch_dir, + }) + } + + fn restore(&self, root: &Path) { + let _ = geode_grotto::vault::write_atomic( + &root.join("recipients.json"), + self.recipients.as_bytes(), + ); + let _ = geode_grotto::vault::write_atomic(&root.join("header.json"), &self.header); + if let Some(p) = &self.policy { + let _ = geode_grotto::vault::write_atomic(&geode_grotto::policy::policy_path(root), p); + } + if let Some(d) = &self.new_epoch_dir { + let _ = std::fs::remove_dir_all(d); + } + } +} + fn now_ms() -> i64 { SystemTime::now() .duration_since(UNIX_EPOCH) diff --git a/crates/geode-cli/tests/rotate_cli.rs b/crates/geode-cli/tests/rotate_cli.rs index 24b43a0..9a2d480 100644 --- a/crates/geode-cli/tests/rotate_cli.rs +++ b/crates/geode-cli/tests/rotate_cli.rs @@ -358,3 +358,151 @@ fn rotate_token_rejected() { assert_ok(&list, "list after rotate"); assert!(String::from_utf8_lossy(&list.stdout).contains("note.txt")); } + +// ---- Re-key lockout regressions ---- + +fn seal_note(dir: &Path) { + std::fs::write(dir.join("note.txt"), b"rekey-object\n").expect("write"); + assert_ok( + &geode(dir, &["--key", "k.gkey", "seal", "note.txt", "v.geode"]), + "seal", + ); +} + +fn assert_reads(dir: &Path, key: &str, what: &str) { + assert_ok(&geode(dir, &["--key", key, "verify", "v.geode"]), what); + assert_ok(&geode(dir, &["--key", key, "list", "v.geode"]), what); + let cat = geode(dir, &["--key", key, "cat", "v.geode", "note.txt"]); + assert_ok(&cat, what); + assert_eq!(cat.stdout, b"rekey-object\n", "{what}"); +} + +fn vault_snapshot(root: &Path) -> Vec<(String, Vec)> { + let mut out = Vec::new(); + let mut stack = vec![root.to_path_buf()]; + while let Some(d) = stack.pop() { + for ent in std::fs::read_dir(&d).expect("read_dir") { + let p = ent.expect("entry").path(); + if p.is_dir() { + stack.push(p); + } else { + let rel = p.strip_prefix(root).unwrap().display().to_string(); + out.push((rel, std::fs::read(&p).expect("read"))); + } + } + } + out.sort(); + out +} + +#[test] +fn add_recipient_new_key_reads() { + let tmp = tempfile::tempdir().expect("tempdir"); + let dir = tmp.path(); + setup_vault(dir); + seal_note(dir); + add_bob(dir); + assert_reads(dir, "bob.gkey", "added x25519 recipient reads"); + assert_reads(dir, "k.gkey", "original key still reads"); +} + +#[test] +fn rotate_drop_old_reseal_new_key_still_reads() { + let tmp = tempfile::tempdir().expect("tempdir"); + let dir = tmp.path(); + setup_vault(dir); + seal_note(dir); + add_bob(dir); + let old_id = gpub_key_id(dir, "k.gpub"); + let rot = geode( + dir, + &[ + "--key", + "k.gkey", + "vault", + "rotate", + "v.geode", + "--yes", + "--drop-recipient", + &old_id, + "--reseal", + ], + ); + assert_ok(&rot, "rotate drop old + reseal"); + assert_no_isk(&rot, dir, &["k.gkey", "bob.gkey"], "drop old"); + let (epoch, types) = recs_epoch_and_types(dir); + assert_eq!(epoch, 2); + assert_eq!(types, vec!["x25519".to_string()]); + assert_reads(dir, "bob.gkey", "new key after rotate"); + let old = geode(dir, &["--key", "k.gkey", "cat", "v.geode", "note.txt"]); + assert_eq!(old.status.code(), Some(2), "old key: {}", combined(&old)); + // The x25519 identity can now rotate the vault it holds alone. + assert_ok( + &geode( + dir, + &[ + "--key", "bob.gkey", "vault", "rotate", "v.geode", "--yes", "--reseal", + ], + ), + "new key rotates", + ); + assert_reads(dir, "bob.gkey", "new key after its own rotate"); +} + +#[test] +fn rotate_lockout_refused_vault_unchanged() { + let tmp = tempfile::tempdir().expect("tempdir"); + let dir = tmp.path(); + setup_vault(dir); + seal_note(dir); + let bob_id = add_bob(dir); + let before = vault_snapshot(&dir.join("v.geode")); + // The x25519 identity cannot re-wrap the original symmetric recipient: + // keeping it (with or without dropping itself) would lock it out. + for drops in [vec![], vec!["--drop-recipient", bob_id.as_str()]] { + let mut args = vec![ + "--key", "bob.gkey", "vault", "rotate", "v.geode", "--yes", "--reseal", + ]; + args.extend(drops); + let out = geode(dir, &args); + assert_eq!(out.status.code(), Some(1), "refused: {}", combined(&out)); + assert!(combined(&out).contains("locked out"), "{}", combined(&out)); + assert_eq!( + vault_snapshot(&dir.join("v.geode")), + before, + "vault unchanged after refused rotate" + ); + } + assert_reads(dir, "k.gkey", "original key after refusal"); + assert_reads(dir, "bob.gkey", "x25519 key after refusal"); +} + +#[cfg(unix)] +#[test] +fn open_writes_plaintext_0600() { + use std::os::unix::fs::PermissionsExt; + let tmp = tempfile::tempdir().expect("tempdir"); + let dir = tmp.path(); + setup_vault(dir); + std::fs::write(dir.join("note.txt"), b"rekey-object\n").expect("write"); + std::fs::set_permissions(dir.join("note.txt"), std::fs::Permissions::from_mode(0o644)) + .expect("chmod"); + assert_ok( + &geode(dir, &["--key", "k.gkey", "seal", "note.txt", "v.geode"]), + "seal", + ); + assert_ok( + &geode(dir, &["--key", "k.gkey", "open", "v.geode", "out"]), + "open", + ); + let mode = std::fs::metadata(dir.join("out/note.txt")) + .expect("stat") + .permissions() + .mode() + & 0o777; + assert_eq!(mode, 0o600, "open output mode {mode:o}"); + assert_eq!( + std::fs::read(dir.join("out/note.txt")).expect("read"), + b"rekey-object\n" + ); +}