-
Notifications
You must be signed in to change notification settings - Fork 170
[cryptography] Add Secret<T> wrapper for protected key material #2640
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
commonware-mcp | 99b8b43 | Jan 07 2026, 10:28 AM |
Deploying monorepo with
|
| Latest commit: |
99b8b43
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://4a07c0ed.monorepo-eu0.pages.dev |
| Branch Preview URL: | https://andre-secrets-wrapper.monorepo-eu0.pages.dev |
|
This is a really good idea! I think we should lean on some of the existing ecosystem crates like "subtle", because the compiler is really good at detecting your constant time comparison and messing it up, so it's better to use a nice dependency which can use the most current tricks to fool it. |
this is easier to safeguard than the guard based approach
4eee3a3 to
3263f2d
Compare
this allows avoiding the call to as_slice() which could leak on the stack
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #2640 +/- ##
==========================================
+ Coverage 92.91% 93.02% +0.10%
==========================================
Files 363 364 +1
Lines 108104 108214 +110
==========================================
+ Hits 100450 100666 +216
+ Misses 7654 7548 -106
... and 1 file with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
This PR introduces a
Secret<T>wrapper type that provides secure handling of sensitive cryptographic material.The wrapper prevents accidental leakage of secrets,
DebugandDisplayimplementations always print [REDACTED] rather than the actual value. When the secret is dropped, the memory is explicitly zeroized to prevent data from lingering in freed memory.All comparisons use constant-time algorithms from the
subtlecrate to prevent timing side-channel attacks, examining every byte rather than short-circuiting on the first difference.To read a secret, callers must use the
expose()method with a closure. Currently the wrapper will just call the closure with the inner secret value and not do any special handling, but this API allows easily auditing all places where secrets are used (i.e. just grep forexpose), and in the future this API can be augmented with OS-specific memory hardening.All private key types in the cryptography crate now store their sensitive material in
Secret<T>wrappers.Replaces #2423.