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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ targets
.direnv
**/.direnv
**/dist
# pkgs/id/web/dist must exist (possibly empty) in source copies: id-web
# embeds it with rust-embed, which generates no Assets::get when the
# folder is absent - that broke source-only builds (the Nix id-lib
# package) once the web layer became its own crate in split step 6c.
!/pkgs/id/web/dist
/pkgs/id/web/dist/*
!/pkgs/id/web/dist/.gitkeep
**/.tmp
*.kate-swp
**/*.kate-swp
Expand Down
5 changes: 5 additions & 0 deletions pkgs/id/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkgs/id/crates/id-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ test-provider = []

[dependencies]
anyhow = "1"
argon2 = "0.6"
chacha20poly1305 = "0.10"
rand = "0.10"
sha2 = "0.11"
zeroize = "1"
# Content address of a boundary declaration (boundary.rs, #7782).
blake3 = "1"
cbor-core = { version = "=0.10.1", features = ["serde"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const MIN_LANES: u32 = 1;
const MAX_LANES: u32 = 4;

/// Encrypt a raw 32-byte identity key into the version 1 envelope.
pub(crate) fn encrypt(passphrase: &[u8], key: &[u8; KEY_LEN]) -> Result<Vec<u8>> {
pub fn encrypt(passphrase: &[u8], key: &[u8; KEY_LEN]) -> Result<Vec<u8>> {
let mut salt = [0; SALT_LEN];
let mut nonce = [0; NONCE_LEN];
rand::rng().fill(&mut salt);
Expand Down Expand Up @@ -81,7 +81,7 @@ pub(crate) fn encrypt(passphrase: &[u8], key: &[u8; KEY_LEN]) -> Result<Vec<u8>>
}

/// Authenticate and decrypt a version 1 identity key envelope.
pub(crate) fn decrypt(passphrase: &[u8], envelope: &[u8]) -> Result<[u8; KEY_LEN]> {
pub fn decrypt(passphrase: &[u8], envelope: &[u8]) -> Result<[u8; KEY_LEN]> {
if envelope.len() != ENVELOPE_LEN {
bail!("invalid key envelope length");
}
Expand Down
19 changes: 19 additions & 0 deletions pkgs/id/crates/id-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ pub mod connectivity;
pub mod discovery;
pub mod frames;
pub mod hex;
pub mod key_envelope;
pub mod seed_phrase;
pub mod ip_evidence;
pub mod json_unique;
pub mod membership;
Expand Down Expand Up @@ -74,3 +76,20 @@ pub enum Refusal {
#[error("{0}")]
RateLimited(String),
}

/// Filename for the server's Ed25519 keypair.
///
/// The node's long-term identity key, stored in the node's data directory.
pub const KEY_FILE: &str = ".iroh-key";

/// Filename for the client's Ed25519 keypair.
///
/// Used when connecting to remote peers. Separate from the server key to allow
/// different identities for serving vs. connecting.
pub const CLIENT_KEY_FILE: &str = ".iroh-key-client";

/// Filename for the serve lock file.
///
/// Created when `id serve` is running. Contains the node ID and addresses
/// for local clients to connect. Automatically removed on clean shutdown.
pub const SERVE_LOCK: &str = ".iroh-serve.lock";
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn wordlist() -> Vec<&'static str> {
/// Encode entropy as a seed phrase: the entropy bits followed by the
/// first `entropy_bits / 32` bits of its SHA-256, split into 11-bit
/// word indices.
pub(crate) fn encode(entropy: &[u8]) -> Result<String> {
pub fn encode(entropy: &[u8]) -> Result<String> {
if !ENTROPY_LENGTHS.contains(&entropy.len()) {
bail!(
"seed phrase entropy must be one of {ENTROPY_LENGTHS:?} bytes, got {}",
Expand Down Expand Up @@ -61,7 +61,7 @@ pub(crate) fn encode(entropy: &[u8]) -> Result<String> {
/// against the wordlist and the trailing checksum against SHA-256.
/// Input is normalized the way a person pastes: any whitespace runs
/// separate words, and case is folded (the wordlist is lowercase).
pub(crate) fn decode(phrase: &str) -> Result<Zeroizing<Vec<u8>>> {
pub fn decode(phrase: &str) -> Result<Zeroizing<Vec<u8>>> {
let words = wordlist();
let tokens: Vec<&str> = phrase.split_whitespace().collect();
let total_bits = tokens.len() * 11;
Expand Down Expand Up @@ -100,12 +100,12 @@ pub(crate) fn decode(phrase: &str) -> Result<Zeroizing<Vec<u8>>> {
}

/// Encode the identity key (32 bytes) as its 24-word seed phrase.
pub(crate) fn encode_key(key: &[u8; 32]) -> Result<String> {
pub fn encode_key(key: &[u8; 32]) -> Result<String> {
encode(key)
}

/// Decode a seed phrase that must carry a full 32-byte identity key.
pub(crate) fn decode_key(phrase: &str) -> Result<Zeroizing<[u8; 32]>> {
pub fn decode_key(phrase: &str) -> Result<Zeroizing<[u8; 32]>> {
let entropy = decode(phrase)?;
if entropy.len() != 32 {
bail!(
Expand Down
4 changes: 2 additions & 2 deletions pkgs/id/src/backup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! for issue #7360.
//!
//! Format (v1, #5033 items 1–4):
//! - The backup blob is the [`crate::key_envelope`] v1 envelope
//! - The backup blob is the [`id_core::key_envelope`] v1 envelope
//! byte-for-byte: `IDKEY` magic, version byte 1, a 60-byte header,
//! the 32-byte identity key wrapped with Argon2id + XChaCha20-Poly1305,
//! 108 bytes total. The server never sees a passphrase and cannot
Expand Down Expand Up @@ -52,7 +52,7 @@ use std::fmt;
use ed25519_dalek::{Signature, Signer as _, SigningKey, VerifyingKey};
use sha2::{Digest as _, Sha256};

use crate::key_envelope;
use id_core::key_envelope;

/// Total v1 envelope length: 60-byte header + 32-byte wrapped key +
/// 16-byte AEAD tag, matching `key_envelope`'s layout.
Expand Down
4 changes: 2 additions & 2 deletions pkgs/id/src/commands/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use anyhow::{Context, Result, bail};
use zeroize::Zeroizing;

use crate::cli::KeyCommand;
use crate::key_envelope;
use crate::seed_phrase;
use id_core::key_envelope;
use id_core::seed_phrase;
use crate::store::load_or_create_keypair;
use crate::{CLIENT_KEY_FILE, KEY_FILE};

Expand Down
19 changes: 2 additions & 17 deletions pkgs/id/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ pub mod input_framing;
pub use id_directory::invite;
pub use id_directory::invites;
pub use id_store::issuer_rotation;
pub(crate) mod key_envelope;
pub(crate) mod seed_phrase;
pub mod local;
pub use id_events::local_claims;
pub use id_events::local_events;
Expand Down Expand Up @@ -382,25 +380,12 @@ use std::path::PathBuf;
// Constants
// ============================================================================

/// Filename for the server's Ed25519 keypair.
///
/// This file is created in the working directory and contains the private key
/// used to identify this node. The public key derived from this is the node ID.
pub const KEY_FILE: &str = ".iroh-key";

/// Filename for the client's Ed25519 keypair.
///
/// Used when connecting to remote peers. Separate from the server key to allow
/// different identities for serving vs. connecting.
pub const CLIENT_KEY_FILE: &str = ".iroh-key-client";

pub use id_core::{CLIENT_KEY_FILE, KEY_FILE, SERVE_LOCK};

pub use id_store::STORE_PATH;

/// Filename for the serve lock file.
///
/// Created when `id serve` is running. Contains the node ID and addresses
/// for local clients to connect. Automatically removed on clean shutdown.
pub const SERVE_LOCK: &str = ".iroh-serve.lock";

pub use id_sync::protocol::META_ALPN;

Expand Down
4 changes: 4 additions & 0 deletions pkgs/id/web/dist/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Placeholder so the web/dist directory exists in source copies.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude the placeholder from release asset validation

On a clean checkout, this placeholder is the only entry in web/dist, but pkgs/id/build.rs:7–10 considers any directory entry proof that frontend assets exist. Consequently, a release build with the web feature now passes the guard without running Bun and can ship a binary whose static assets all return 404. Update the guard alongside this placeholder to ignore .gitkeep or require an actual build artifact, preserving the documented requirement that web assets be built first.

AGENTS.md reference: pkgs/id/AGENTS.md:L88-L91

Useful? React with 👍 / 👎.

The real assets are built by bun (locally and in the Nix
id-web package); id-web's rust-embed needs the folder to
exist at compile time even when it is empty.
Loading