Skip to content

feat!: remove DEFAULT_CIPHER/DEFAULT_NONCE public constants#75

Merged
iduartgomez merged 1 commit into
mainfrom
feat/remove-default-cipher-nonce-consts
May 16, 2026
Merged

feat!: remove DEFAULT_CIPHER/DEFAULT_NONCE public constants#75
iduartgomez merged 1 commit into
mainfrom
feat/remove-default-cipher-nonce-consts

Conversation

@iduartgomez
Copy link
Copy Markdown
Contributor

Problem

DelegateRequest::DEFAULT_CIPHER ([u8; 32]) and DelegateRequest::DEFAULT_NONCE ([u8; 24]) seeded a world-known XChaCha20-Poly1305 key and a fixed 24-byte nonce. Any freenet node that started without explicit --cipher / --nonce configuration encrypted all delegate secrets under this pair. Combined with the per-delegate nonce reuse fixed in freenet-core PR #4143, the result was that default-configured nodes' delegate secrets were trivially recoverable by anyone who could read the secrets directory.

PR #4143 closed the catastrophic-reuse half (per-write random nonce + on-disk versioned format with legacy fallback). This stdlib PR closes the world-known-key half so the next freenet-core PR can replace the DEFAULT_CIPHER fallback with auto-generated, per-node persisted ciphers.

Solution

Delete the two pub const declarations from DelegateRequest. The wire format RegisterDelegate { cipher: [u8; 32], nonce: [u8; 24] } is unchanged — only the named public constants are removed. Servers running freenet-core >= 0.2.59 generate per-write random nonces and treat the registration nonce as a read-side legacy fallback only.

Callers that previously named the consts must now:

  • Generate a fresh 32-byte cipher per delegate (e.g. XChaCha20Poly1305::generate_key(&mut OsRng)).
  • Pass any 24-byte nonce value for the wire field (commonly [0u8; 24]); it is no longer used by the server for new writes.

Version bump

0.7.00.8.0. Pre-1.0 semver: removing public consts is a breaking change for any consumer that named them, so the minor version bumps.

Wire-format pin tests

Untouched. The enum variant discriminants for DelegateRequest are not reordered, and the field shape of RegisterDelegate is unchanged. *_wire_format_is_stable tests continue to pass without modification.

Testing

cargo test --all — 19 passed, 0 failed; doc-tests pass.
cargo fmt --all --check clean.
cargo clippy --all -- -D warnings clean.

Next

After merge + cargo publish 0.8.0 to crates.io, freenet-core PR B2 will:

  • Bump freenet-stdlib = "0.8.0".
  • Replace the DEFAULT_CIPHER fallback in crates/core/src/config/secret.rs::SecretArgs::build with an auto-generated cipher persisted to secrets_dir/delegate_cipher (mirroring the existing transport_keypair auto-persist).
  • Drop the --nonce CLI flag (nonces are now per-write).
  • Update test/fdev call sites that named the removed consts.

Refs: freenet/freenet-core#4137 (tracker), freenet/freenet-core#4139 (sub-issue).

These constants seeded a world-known XChaCha20-Poly1305 key and a
fixed 24-byte nonce. Any node that started without explicit
`--cipher` / `--nonce` configuration encrypted all delegate secrets
under this pair. Combined with the per-delegate nonce reuse fixed in
freenet-core PR #4143, the result was that default-configured nodes'
delegate secrets were trivially recoverable by anyone who could read
the secrets directory.

The wire format `RegisterDelegate { cipher: [u8; 32], nonce: [u8; 24] }`
is unchanged — only the named public constants are removed. Servers
running freenet-core >= 0.2.59 generate per-write random nonces and
ignore the registration nonce except as a legacy-decrypt fallback for
pre-0.2.59 on-disk files. Callers that previously named the consts
must generate a fresh 32-byte cipher per delegate (e.g. via
`XChaCha20Poly1305::generate_key(&mut OsRng)`) and may pass any 24-byte
nonce value (it is no longer used for new writes).

Bumps stdlib to 0.8.0 since dropping public consts is a breaking
change for any consumer that named them. Wire-format pin tests
(`*_wire_format_is_stable`) are unaffected because the enum variant
discriminants are untouched.

Refs: freenet/freenet-core#4137, freenet/freenet-core#4139
@iduartgomez iduartgomez merged commit 83d344c into main May 16, 2026
9 checks passed
@iduartgomez iduartgomez deleted the feat/remove-default-cipher-nonce-consts branch May 16, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant