-
Notifications
You must be signed in to change notification settings - Fork 49
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
[PM-5728] Enable Zeroize support for keys and EncStrings #515
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #515 +/- ##
==========================================
+ Coverage 51.51% 51.69% +0.17%
==========================================
Files 163 163
Lines 8168 8202 +34
==========================================
+ Hits 4208 4240 +32
- Misses 3960 3962 +2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suspect we need to spend some more time thinking about vectors potentially copying on resize, this might also apply to strings?
Generally good improvements, I do wonder how we'll test this efficiently though, would be nice if we could produce memory dumps of tests somehow and assert.
# Conflicts: # crates/bitwarden-crypto/src/enc_string/asymmetric.rs
Fixed Issues
|
Welp scratch that, those tests worked for me locally but they segfault on CI |
let mut dec: Vec<u8> = protected_user_key.decrypt_with_key(&device_private_key)?; | ||
let user_key: SymmetricCryptoKey = dec.as_mut_slice().try_into()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this consumes the key. Do we need to zero dec
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We zeroize the key inside the TryFrom<&mut [u8]>
impl:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That feels potentially confusing? Do you expect a TryFrom
of a slice to manipulate the input? I do see the benefit of ensuring it gets consumed though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also just pass an owned Vec<> and consume it in the function, but that will limit the use of the API for someone trying to pass a GenericArray or a [u8; 64] for example.
I think the fact that the function receives a &mut [u8]
should make it clear enough that something is being modified, but we could add a comment mentioning explicitly that it's being zeroed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a comment to make it explicit. We can revaluate if this turns out to be confusing, potentially not using try from and instead having an explicit function could make it less confusing.
# Conflicts: # crates/bitwarden-crypto/src/keys/asymmetric_crypto_key.rs
Type of change
Objective