Skip to content

feat(airc-protocol): real Ed25519 signing + verify (closes PR-1 stub) - #669

Merged
joelteply merged 1 commit into
rust-rewritefrom
feat/airc-protocol-ed25519
May 19, 2026
Merged

joelteply merged 1 commit into
rust-rewritefrom
feat/airc-protocol-ed25519

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

PR-1 (#667) shipped Signature::Ed25519 + the policy dispatcher but left verify() as a stub. This PR wires real ed25519-dalek byte-level verify + adds the send side (PeerKeypair). Per Codex's PR-3 steer + Joel's "always go most-capable" principle:

  • No plaintext production paths
  • No silent-pass shortcuts — Strict policy fails closed on every failure mode
  • Crypto choice = Ed25519 (sub-50µs verify, deterministic sign, standard ecosystem, fits the per-frame budget)

New: keypair.rs

pub struct PeerKeypair { ... }
impl PeerKeypair {
    pub fn generate() -> Self;
    pub fn from_secret_bytes(secret: &[u8; 32]) -> Self;
    pub fn secret_bytes(&self) -> [u8; 32];
    pub fn public_bytes(&self) -> [u8; 32];
    pub fn verifying_key(&self) -> VerifyingKey;
    pub fn sign_envelope(&self, &Envelope, PeerId, u32) -> Result<Signature, CanonicalError>;
}

Debug redacts the secret (pinned by debug_redacts_secret test). Storage is in-memory only; persistence (SQLCipher, keychain, hardware enclave) is the integrator's responsibility.

Changed: signature.rs

  • PeerKeyRegistry storage: raw [u8; 32] → parsed VerifyingKey. Pre-validate at enrol time so the verify hot path doesn't re-parse on every frame.
  • enrol() now returns Result<(), KeyError>. Refuses invalid Ed25519 points at enrolment.
  • verify() dispatches Signature::Ed25519 to verify_ed25519: registry lookup → canonical CBOR encode → ed25519_dalek::Verifier::verify. Lookup miss = UnknownSigner; crypto mismatch = BadSignature.

Tests (10 new in keypair.rs)

  • sign_then_verify_with_enrolled_key_passes_under_strict — base round-trip
  • tampered_envelope_after_signing_fails_bad_signature — body tamper
  • tampered_lamport_fails_bad_signature — ordering field
  • tampered_headers_fail_bad_signature — header injection
  • tampered_reply_to_fails_bad_signature — threading field
  • wrong_pubkey_in_registry_fails_bad_signature — evil-twin pubkey
  • unenrolled_signer_fails_unknown_signer — fail-closed on empty registry
  • key_rotation_via_key_id_works — same peer, two keys, both verify
  • keypair_secret_roundtrips_through_bytes — persistence contract
  • debug_redacts_secret — no secret in `Debug` output

PR-1's stub test (`ed25519_with_registered_signer_passes_pr1_stub`) is rewritten as ed25519_with_garbage_signature_fails_bad_signature — asserts an all-zero sig against a real pubkey fails BadSignature (the correct stronger contract).

Test plan

  • `cargo fmt -p airc-protocol` — clean
  • `cargo clippy -p airc-protocol --all-targets -- -D warnings` — clean
  • `cargo test -p airc-protocol` — 44 pass / 0 fail (was 34 in PR-1)

Stack

Stacked on `feat/airc-protocol-envelope` (#667). Next: PR-3b (`feat/airc-transport-lan-tcp`) — secure LAN transport (TLS via rustls peer-pinning to these Ed25519 keys). Fails closed when keys/certs are missing.

Dependencies

Adds: `ed25519-dalek = "2"`, `rand = "0.8"`.

🤖 Generated with Claude Code

PR-1 shipped Signature::Ed25519 + the policy dispatcher but left
verify() as a stub that returned Ok(()) once the registry had a key.
This PR wires the actual ed25519-dalek byte-level verify + adds the
send side (PeerKeypair).

Per Codex's PR-3 steer (and Joel's "always go most-capable"):
  * no plaintext production paths
  * no silent-pass shortcuts
  * Strict policy fails closed on every failure mode
  * crypto choice = Ed25519 (sub-50µs verify, deterministic sign,
    standard ecosystem, fits the per-frame budget)

New module: crates/airc-protocol/src/keypair.rs

  * PeerKeypair::generate() — fresh random from OsRng
  * PeerKeypair::from_secret_bytes(&[u8;32]) — persistence restore
  * PeerKeypair::secret_bytes() / public_bytes() / verifying_key()
  * PeerKeypair::sign_envelope(envelope, signer, key_id) — produces
    Signature::Ed25519 over canonical_signed_bytes(envelope)
  * Debug impl redacts the secret (pinned by test)
  * Storage is in-memory only; persistence (SQLCipher, keychain,
    hardware enclave) is the integrator's responsibility — substrate
    just signs and verifies.

Wired in signature.rs:

  * PeerKeyRegistry storage changed from raw [u8;32] to parsed
    VerifyingKey — pre-validate once at enrol time so verify() in
    the hot path doesn't re-parse on every frame.
  * enrol() now returns Result<(), KeyError>; refuses invalid
    Ed25519 points (garbage / wrong-curve) at enrolment rather
    than at verify time.
  * verify() dispatches Signature::Ed25519 to a verify_ed25519
    helper: registry lookup -> canonical-encode -> ed25519_dalek
    Verifier::verify. Lookup miss = UnknownSigner; crypto mismatch
    = BadSignature.

Tests added (keypair.rs):

  * sign_then_verify_with_enrolled_key_passes_under_strict — base
  * tampered_envelope_after_signing_fails_bad_signature — body
  * tampered_lamport_fails_bad_signature — ordering field
  * tampered_headers_fail_bad_signature — header injection
  * tampered_reply_to_fails_bad_signature — threading field
  * wrong_pubkey_in_registry_fails_bad_signature — evil twin pubkey
  * unenrolled_signer_fails_unknown_signer — fail-closed empty registry
  * key_rotation_via_key_id_works — two keys per peer, both verify
  * keypair_secret_roundtrips_through_bytes — persistence contract
  * debug_redacts_secret — no secret in Debug output

The PR-1 stub test ("ed25519_with_registered_signer_passes_pr1_stub")
is rewritten as ed25519_with_garbage_signature_fails_bad_signature —
asserts that an all-zero signature against a real pubkey fails
BadSignature (the correct stronger contract now that crypto is wired).

Tests: 44 pass (was 34 in PR-1), clippy clean (-D warnings), fmt clean.

Deps added: ed25519-dalek = "2", rand = "0.8" (for OsRng::fill_bytes).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Base automatically changed from feat/airc-protocol-envelope to rust-rewrite May 19, 2026 02:09
@joelteply
joelteply merged commit 3cf3874 into rust-rewrite May 19, 2026
1 check passed
@joelteply
joelteply deleted the feat/airc-protocol-ed25519 branch May 19, 2026 02:09
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