Repository navigation
feat(airc-protocol): real Ed25519 signing + verify (closes PR-1 stub) - #669
Merged
Merged
Conversation
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]>
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR-1 (#667) shipped
Signature::Ed25519+ the policy dispatcher but leftverify()as a stub. This PR wires realed25519-dalekbyte-level verify + adds the send side (PeerKeypair). Per Codex's PR-3 steer + Joel's "always go most-capable" principle:New:
keypair.rsDebugredacts the secret (pinned bydebug_redacts_secrettest). Storage is in-memory only; persistence (SQLCipher, keychain, hardware enclave) is the integrator's responsibility.Changed:
signature.rsPeerKeyRegistrystorage: raw[u8; 32]→ parsedVerifyingKey. Pre-validate at enrol time so the verify hot path doesn't re-parse on every frame.enrol()now returnsResult<(), KeyError>. Refuses invalid Ed25519 points at enrolment.verify()dispatchesSignature::Ed25519toverify_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-triptampered_envelope_after_signing_fails_bad_signature— body tampertampered_lamport_fails_bad_signature— ordering fieldtampered_headers_fail_bad_signature— header injectiontampered_reply_to_fails_bad_signature— threading fieldwrong_pubkey_in_registry_fails_bad_signature— evil-twin pubkeyunenrolled_signer_fails_unknown_signer— fail-closed on empty registrykey_rotation_via_key_id_works— same peer, two keys, both verifykeypair_secret_roundtrips_through_bytes— persistence contractdebug_redacts_secret— no secret in `Debug` outputPR-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
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