diff --git a/.gitignore b/.gitignore index 9d44ff640a..de95d9048a 100755 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/pkgs/id/Cargo.lock b/pkgs/id/Cargo.lock index 8f47cd7e26..749fa1330d 100644 --- a/pkgs/id/Cargo.lock +++ b/pkgs/id/Cargo.lock @@ -3964,8 +3964,10 @@ name = "id-core" version = "0.1.0" dependencies = [ "anyhow", + "argon2", "blake3", "cbor-core", + "chacha20poly1305", "ed25519-dalek 3.0.0", "futures-lite", "iroh", @@ -3976,9 +3978,11 @@ dependencies = [ "postcard", "proptest", "qrcode", + "rand 0.10.3", "rqrr", "serde", "serde_json", + "sha2 0.11.0", "tempfile", "thiserror 2.0.21", "tokio", @@ -3987,6 +3991,7 @@ dependencies = [ "unicode-segmentation", "unicode-width", "vt100", + "zeroize", ] [[package]] diff --git a/pkgs/id/crates/id-core/Cargo.toml b/pkgs/id/crates/id-core/Cargo.toml index 1e918014c3..7360a601f9 100644 --- a/pkgs/id/crates/id-core/Cargo.toml +++ b/pkgs/id/crates/id-core/Cargo.toml @@ -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"] } diff --git a/pkgs/id/src/key_envelope.rs b/pkgs/id/crates/id-core/src/key_envelope.rs similarity index 97% rename from pkgs/id/src/key_envelope.rs rename to pkgs/id/crates/id-core/src/key_envelope.rs index a1e90973a1..ce64663d50 100644 --- a/pkgs/id/src/key_envelope.rs +++ b/pkgs/id/crates/id-core/src/key_envelope.rs @@ -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> { +pub fn encrypt(passphrase: &[u8], key: &[u8; KEY_LEN]) -> Result> { let mut salt = [0; SALT_LEN]; let mut nonce = [0; NONCE_LEN]; rand::rng().fill(&mut salt); @@ -81,7 +81,7 @@ pub(crate) fn encrypt(passphrase: &[u8], key: &[u8; KEY_LEN]) -> Result> } /// 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"); } diff --git a/pkgs/id/crates/id-core/src/lib.rs b/pkgs/id/crates/id-core/src/lib.rs index 028657286c..0d220c29a7 100644 --- a/pkgs/id/crates/id-core/src/lib.rs +++ b/pkgs/id/crates/id-core/src/lib.rs @@ -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; @@ -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"; diff --git a/pkgs/id/src/seed_phrase.rs b/pkgs/id/crates/id-core/src/seed_phrase.rs similarity index 98% rename from pkgs/id/src/seed_phrase.rs rename to pkgs/id/crates/id-core/src/seed_phrase.rs index 316072e181..44c9e30bb8 100644 --- a/pkgs/id/src/seed_phrase.rs +++ b/pkgs/id/crates/id-core/src/seed_phrase.rs @@ -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 { +pub fn encode(entropy: &[u8]) -> Result { if !ENTROPY_LENGTHS.contains(&entropy.len()) { bail!( "seed phrase entropy must be one of {ENTROPY_LENGTHS:?} bytes, got {}", @@ -61,7 +61,7 @@ pub(crate) fn encode(entropy: &[u8]) -> Result { /// 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>> { +pub fn decode(phrase: &str) -> Result>> { let words = wordlist(); let tokens: Vec<&str> = phrase.split_whitespace().collect(); let total_bits = tokens.len() * 11; @@ -100,12 +100,12 @@ pub(crate) fn decode(phrase: &str) -> Result>> { } /// Encode the identity key (32 bytes) as its 24-word seed phrase. -pub(crate) fn encode_key(key: &[u8; 32]) -> Result { +pub fn encode_key(key: &[u8; 32]) -> Result { encode(key) } /// Decode a seed phrase that must carry a full 32-byte identity key. -pub(crate) fn decode_key(phrase: &str) -> Result> { +pub fn decode_key(phrase: &str) -> Result> { let entropy = decode(phrase)?; if entropy.len() != 32 { bail!( diff --git a/pkgs/id/src/seed_wordlist.txt b/pkgs/id/crates/id-core/src/seed_wordlist.txt similarity index 100% rename from pkgs/id/src/seed_wordlist.txt rename to pkgs/id/crates/id-core/src/seed_wordlist.txt diff --git a/pkgs/id/src/backup.rs b/pkgs/id/src/backup.rs index 85f4648eac..99faa1b501 100644 --- a/pkgs/id/src/backup.rs +++ b/pkgs/id/src/backup.rs @@ -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 @@ -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. diff --git a/pkgs/id/src/commands/key.rs b/pkgs/id/src/commands/key.rs index 655caea1ca..6ab012c51c 100644 --- a/pkgs/id/src/commands/key.rs +++ b/pkgs/id/src/commands/key.rs @@ -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}; diff --git a/pkgs/id/src/lib.rs b/pkgs/id/src/lib.rs index 0fe44e4b42..e1996a25a6 100644 --- a/pkgs/id/src/lib.rs +++ b/pkgs/id/src/lib.rs @@ -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; @@ -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; diff --git a/pkgs/id/web/dist/.gitkeep b/pkgs/id/web/dist/.gitkeep new file mode 100644 index 0000000000..4f838297b1 --- /dev/null +++ b/pkgs/id/web/dist/.gitkeep @@ -0,0 +1,4 @@ +Placeholder so the web/dist directory exists in source copies. +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.