fix: return encrypted DKG backups accepted by production restore

DKG finalize used to return only plaintext key bytes, but production key restore needs an encrypted v2 envelope bound to the network and vault. Finalize now also returns two new fields, key_blob_b64 and recovery_vault_pub_key, using the canonical group identity. It builds the backup before any durable finalize change or staging cleanup, and it builds a valid backup again when a finalized session is replayed. If no at-rest key is configured outside explicit mocknet, finalize fails before touching anything, so the staged share is still there to retry. key_blob_b64 is left out only in keyless, explicit mocknet development.

These backups leave the host, so they are not keyed by the fast, unsalted at-rest key. They use a new sealed recovery envelope (TKR\x03). Each envelope runs Argon2id v19 (64 MiB, t=3, p=1) over the signer secret with its own random 16-byte salt. It then encrypts with XChaCha20-Poly1305, using the full header (version, KDF params, salt, nonce) as AAD. KDF params are fixed for each KDF id, and any other values are rejected before key derivation. The at-rest key is unchanged for local sled storage.

When a seed is configured, restore accepts only sealed envelopes, and their payload must carry the bound context, even on mocknet. Plaintext is still accepted only in keyless dev mode. Restore rejects backups keyed directly by the at-rest key (TKE\x01) on every network. A new POST /v1/monero/keys/recovery/migrate endpoint re-seals these legacy backups. It requires full authentication and checks the network, the vault and the keyshare. It persists nothing, and it rejects input that is already sealed. Unbound legacy payloads can be migrated only on explicit mocknet.

KDF work runs off the async runtime, with at most 2 evaluations at once. A slot stays held until its blocking task finishes. Restore derives the key before taking key_restore_lock. Config::is_explicit_mocknet replaces the inline explicit-mocknet checks.

Finalize also seals outside key_restore_lock. A burst of restore or migrate requests waiting for KDF slots no longer stalls finalize, restore commits or the receipt sweep. Finalize loads and checks its material under the lock, releases the lock while sealing, then takes it again and re-reads the material before committing. If the plaintext share and group key still match, the commit goes ahead. So an identical finalize that overlaps one that has already moved staging to the receipt still succeeds, as Bifrost's quorum-adoption path needs, because every commit is insert-if-absent. Any other change made while the lock was released fails closed with Conflict, and the caller retries. Examples are an expired or swept receipt, or a rewritten staging share.

Addresses the signer-side producer gap in #655. Keep the issue open until the recovery consumer adopts the new fields.

key_bytes_hex stays for compatibility with current keygen. Recovery consumers must adopt the two new fields and keep the same signer seed. Bifrost recovery clients that still use plaintext need a matching consumer change. Any existing at-rest-keyed backups must be migrated once before they can be restored. The README documents the wire contract, the envelope format, the restore request and the migration flow.

Dependencies: adds argon2 0.5 to the signer. argon2 and blake2 are built at opt-level = 3 in the dev profile, because tests use the production KDF params. To keep the cargo-deny gate passing, this bumps:

  • rustls to 0.23.46 (RUSTSEC-2026-0347/0348/0349)
  • rustls-webpki to 0.103.16 (RUSTSEC-2026-0382)
  • tokio to 1.53.3 (RUSTSEC-2026-0386)

Two advisories have no compatible fix, so deny.toml ignores them and gives the reason for each:

  • crypto-bigint 0.5 timing issue (RUSTSEC-2026-0387): fixed only in 0.7.6. In the signer it only handles public points through hash_to_point. Secret scalars use curve25519-dalek, and k256/elliptic-curve are dev-only.
  • pin-utils is unmaintained (RUSTSEC-2026-0441): no fixed release exists.

Validation: signer unit tests cover:

  • production finalize → restore into a fresh database
  • finalized-session replay
  • rejection of a wrong seed, network or vault
  • staging is kept when production has no key
  • encoder and decoder size limits
  • the Argon2id envelope kept separate from the at-rest key
  • header authentication and fixed params
  • legacy-backup rejection
  • the migrate → restore round trip, and refusal to re-migrate a sealed envelope

Another test checks that the restore lock stays free while finalize waits for a KDF slot. It also checks that an identical finalize overlapping a concurrent commit succeeds without refreshing the receipt's replay window.

🤖 Generated with Claude Code

Edited by Huginn Ai

Merge request reports

Loading
Loading