feat: Guarded trait for secrets protection guarantee #114
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.
An attempt to find a good solution for #112 (comment) they led me to this implementation (an alternative to #112) and curious conclusions.
Description:
This PR introduces a special
Guarded
trait that forces an implementation to:GuardedWrapper
(that implementsDebug
, but never prints the secret value)Zeroize
for the secret (and it always be called by theGuardedWrapper
)The
GuardedWrapper
has a special method.reveal()
that returns a reference to a secret.The beniefit of that approach: we have
.reveal()
calls everywhere we get access to a secret value and we couldgrep
sources to see all the places the secret is revealed. Like.unwrap()
approach, but for secrets. It's always clear now in reviewing PRs where we get the secret valueAnother change is removing
From<RistrettoSecretKey> for Scalar
implementation, becauseScalar
implementsCopy
and easily copied in that method, but the copied value will never bezeroized
. The original secret key is zeroized, becuaseDrop
will be called after theFrom
implementation:The drawback of that approach: we have to
Clone
values instead ofCopy
, because we couldn't have bothCopy
andDrop
at the same time.The extra costs for cloning could be eliminated by some refactoring to using references to secrets instead of owning them.