Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions crates/geode-cli/src/cmd/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
29 changes: 26 additions & 3 deletions crates/geode-cli/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Manifest> {
/// 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<Manifest> {
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")?;
Expand Down
54 changes: 47 additions & 7 deletions crates/geode-cli/src/cmd/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down Expand Up @@ -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;
}
Expand Down
Loading
Loading