Skip to content

fix(crypto): harden secret key material against Debug leakage and zeroize gaps#507

Open
varex83agent wants to merge 1 commit into
mainfrom
bohdan/secret-key-zeroization
Open

fix(crypto): harden secret key material against Debug leakage and zeroize gaps#507
varex83agent wants to merge 1 commit into
mainfrom
bohdan/secret-key-zeroization

Conversation

@varex83agent

Copy link
Copy Markdown
Collaborator

Summary

Addresses five P0 secret-key-material findings across frost, crypto, and k1util — closing log-leakage holes, wiping in-memory secrets, and fixing one Charon parity divergence in on-disk key permissions.

High-value validator secret key material was held as plain byte arrays / bare stack scalars, printed via derived Debug, and (in one case) written to disk with world-readable permissions.

Changes

Task Finding Fix
T01 Derived Debug leaks FROST SigningShare/KeyPackage secret share Dropped Debug from derives; added redacting manual impl fmt::Debug (<redacted> placeholder, public fields preserved on KeyPackage)
T02 Derived Debug leaks ShamirShare value Manual Debug printing id, redacting value
T03 k1util::save() writes key world-readable Unix path creates the file with 0o600 (and tightens an existing looser file), matching Charon app/k1util/k1util.go Save (v1.7.1, 0o600)
T04 Scalar not zeroized on drop; Copy conflict Decision: keep Copy — removing it ripples across the crate for no real guarantee (the inner blst_fr is a Copy C struct, so moves bit-copy it regardless). Rationale documented on the type
T05 Ephemeral nonce & reconstructed key scalars never wiped Explicit .zeroize() on k/wi/share_scalar in round1 and own_share_scalar/share_sum/share_scalar/total_scalar in round2
T06 Crypto crate holds BLS secrets un-zeroized Added zeroize dep; wrapped raw ikm/candidate byte buffers in Zeroizing. Confirmed blst SecretKey is #[zeroize(drop)] (0.3.16), so BlstSecretKey intermediates already auto-wipe

Parity / safety

No wire-format, signature, or DKG-output changes — only Debug output, drop behaviour, and on-disk file mode. The only intentional parity change is T03 aligning the secp256k1 key file mode to Charon's 0o600. Zeroization is framed as best-effort defense-in-depth.

Tests

  • 5 new unit tests: Debug redaction for SigningShare, KeyPackage, ShamirShare; 0o600 permission on save (incl. tightening an existing looser file).
  • cargo +nightly fmt --all --check
  • cargo clippy on frost/crypto/k1util + dependent dkg crate, -D warnings
  • cargo test passes — including the 107 dkg tests, confirming the Debug-derive removals don't break dependents.

🤖 Generated with Claude Code

…oize gaps

Addresses five P0 secret-key-material findings across frost, crypto, and
k1util — closing log-leakage holes, wiping in-memory secrets, and fixing one
Charon parity divergence in on-disk key permissions.

- frost: replace derived `Debug` on `SigningShare`, `KeyPackage` and
  `ShamirShare` with redacting manual impls so secret scalars/shares can no
  longer reach logs/panics (mirrors the existing `BlsSignature` style).
- frost: explicitly zeroize the ephemeral Schnorr nonce and the reconstructed
  signing-key scalars in kryptology `round1`/`round2`. `Scalar` deliberately
  keeps `Copy` (removing it ripples across the crate for no guarantee — the
  inner `blst_fr` is a `Copy` C struct); rationale documented on the type.
- crypto: declare the `zeroize` dep and wrap the raw `ikm`/candidate byte
  buffers in `Zeroizing`. blst's `SecretKey` is `#[zeroize(drop)]`, so the
  `BlstSecretKey` intermediates already wipe on drop.
- k1util: write the secp256k1 private key with mode `0o600`, matching Charon
  `app/k1util/k1util.go` Save (v1.7.1); previously used the default umask mode.

No wire-format, signature, or DKG-output changes; only Debug output, drop
behaviour, and on-disk file mode. Adds unit tests for each redaction and the
0o600 permission (incl. tightening an existing looser file).

Co-Authored-By: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>
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