-
Notifications
You must be signed in to change notification settings - Fork 50
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-5791] Change decrypt to return Sensitive #536
Conversation
No New Or Fixed Issues Found |
KeyEncryptable<Key, Output> for Decrypted<T> | ||
{ | ||
fn encrypt_with_key(self, key: &Key) -> Result<Output, CryptoError> { | ||
self.value.clone().encrypt_with_key(key) |
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.
Todo: need to validate what happens with the string after encrypting it. If we consume it we should zero it.
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.
Yeah, we should probably add the zeroize in the KeyEncryptable implementation of the EncStrings, which is where the String is consumed finally.
Also, we could avoid the extra clone here by doing
std::mem::take(&mut self.value).encrypt_with_key(key)
It would mean adding a Default
bound to the impl, though
…pted # Conflicts: # Cargo.lock # crates/bitwarden-crypto/Cargo.toml # crates/bitwarden-crypto/src/enc_string/symmetric.rs # crates/bitwarden-crypto/src/keys/device_key.rs # crates/bitwarden-crypto/src/keys/master_key.rs # crates/bitwarden/src/auth/login/access_token.rs # crates/bitwarden/src/client/encryption_settings.rs # crates/bitwarden/src/vault/cipher/attachment.rs # crates/bitwarden/src/vault/cipher/cipher.rs
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #536 +/- ##
==========================================
+ Coverage 60.90% 61.72% +0.82%
==========================================
Files 173 173
Lines 10694 10905 +211
==========================================
+ Hits 6513 6731 +218
+ Misses 4181 4174 -7 ☔ 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.
Looks pretty good to me, just some small comments
KeyEncryptable<Key, Output> for Decrypted<T> | ||
{ | ||
fn encrypt_with_key(self, key: &Key) -> Result<Output, CryptoError> { | ||
self.value.clone().encrypt_with_key(key) |
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.
Yeah, we should probably add the zeroize in the KeyEncryptable implementation of the EncStrings, which is where the String is consumed finally.
Also, we could avoid the extra clone here by doing
std::mem::take(&mut self.value).encrypt_with_key(key)
It would mean adding a Default
bound to the impl, though
# Conflicts: # crates/bitwarden-crypto/src/enc_string/symmetric.rs # crates/bitwarden-crypto/src/keys/device_key.rs # crates/bitwarden-crypto/src/keys/master_key.rs # crates/bitwarden/src/auth/auth_request.rs # crates/bitwarden/src/vault/cipher/field.rs # crates/bitwarden/src/vault/folder.rs
## Type of change ``` - [ ] Bug fix - [ ] New feature development - [x] Tech debt (refactoring, code cleanup, dependency upgrades, etc) - [ ] Build/deploy pipeline (DevOps) - [ ] Other ``` ## Objective This is a small subset of #536, which only contains the minimum code to protect the import/export functions on SymmetricCryptoKey. It also enables the from_base64 test on SymmetricCryptoKey as that passes now. After this PR is merged I'll be expanding the use of Sensitive to other parts of the codebase while adding some extra memory testing checks to validate that it works for them.
…pted # Conflicts: # crates/bitwarden-crypto/src/enc_string/symmetric.rs # crates/bitwarden-crypto/src/keys/device_key.rs # crates/bitwarden-crypto/src/keys/master_key.rs # crates/bitwarden-crypto/src/sensitive/sensitive.rs # crates/bitwarden/src/auth/login/access_token.rs # crates/bitwarden/src/mobile/crypto.rs # crates/bitwarden/src/secrets_manager/projects/project_response.rs # crates/bitwarden/src/secrets_manager/secrets/list.rs # crates/bitwarden/src/secrets_manager/secrets/secret_response.rs # crates/bitwarden/src/secrets_manager/state.rs # crates/bitwarden/src/uniffi_support.rs # crates/bitwarden/src/vault/cipher/attachment.rs # crates/bitwarden/src/vault/cipher/cipher.rs # crates/bitwarden/src/vault/send.rs
…pted # Conflicts: # crates/bitwarden/src/vault/send.rs
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.
Reminders for myself.
…pted # Conflicts: # crates/bitwarden-crypto/src/keys/master_key.rs # crates/bitwarden/src/mobile/crypto.rs # crates/bitwarden/src/vault/send.rs
I think the remaining tasks are large enough to be separate tasks. @dani-garcia let me know if you disagree. I'll write up tickets for them. |
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.
Mostly LGTM, just a couple of comments.
Let's go ahead and open tickets for the other unresolved tasks, plus the SensitiveString improvements we've mentioned.
Type of change
Objective
Updates the decrypt methods to return a
Sensitive
value which implementszeroize
andzeroize on drop
to ensure the values are zeroed on drop within the rust ecosystem.Before you submit