Skip to content
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

Update mac handling in decrypting vault items to discard invalid items #516

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions crates/bitwarden/src/vault/cipher/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
impl KeyDecryptable<SymmetricCryptoKey, CardView> for Card {
fn decrypt_with_key(&self, key: &SymmetricCryptoKey) -> Result<CardView, CryptoError> {
Ok(CardView {
cardholder_name: self.cardholder_name.decrypt_with_key(key)?,
exp_month: self.exp_month.decrypt_with_key(key)?,
exp_year: self.exp_year.decrypt_with_key(key)?,
code: self.code.decrypt_with_key(key)?,
brand: self.brand.decrypt_with_key(key)?,
number: self.number.decrypt_with_key(key)?,
cardholder_name: self.cardholder_name.decrypt_with_key(key).ok().flatten(),
exp_month: self.exp_month.decrypt_with_key(key).ok().flatten(),
exp_year: self.exp_year.decrypt_with_key(key).ok().flatten(),
code: self.code.decrypt_with_key(key).ok().flatten(),
brand: self.brand.decrypt_with_key(key).ok().flatten(),
number: self.number.decrypt_with_key(key).ok().flatten(),

Check warning on line 55 in crates/bitwarden/src/vault/cipher/card.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/card.rs#L50-L55

Added lines #L50 - L55 were not covered by tests
})
}
}
Expand Down
24 changes: 12 additions & 12 deletions crates/bitwarden/src/vault/cipher/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,22 +182,22 @@
folder_id: self.folder_id,
collection_ids: self.collection_ids.clone(),
key: self.key.clone(),
name: self.name.decrypt_with_key(key)?,
notes: self.notes.decrypt_with_key(key)?,
name: self.name.decrypt_with_key(key).ok().unwrap_or_default(),
notes: self.notes.decrypt_with_key(key).ok().flatten(),

Check warning on line 186 in crates/bitwarden/src/vault/cipher/cipher.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/cipher.rs#L185-L186

Added lines #L185 - L186 were not covered by tests
r#type: self.r#type,
login: self.login.decrypt_with_key(key)?,
identity: self.identity.decrypt_with_key(key)?,
card: self.card.decrypt_with_key(key)?,
secure_note: self.secure_note.decrypt_with_key(key)?,
login: self.login.decrypt_with_key(key).ok().flatten(),
identity: self.identity.decrypt_with_key(key).ok().flatten(),
card: self.card.decrypt_with_key(key).ok().flatten(),
secure_note: self.secure_note.decrypt_with_key(key).ok().flatten(),

Check warning on line 191 in crates/bitwarden/src/vault/cipher/cipher.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/cipher.rs#L188-L191

Added lines #L188 - L191 were not covered by tests
favorite: self.favorite,
reprompt: self.reprompt,
organization_use_totp: self.organization_use_totp,
edit: self.edit,
view_password: self.view_password,
local_data: self.local_data.decrypt_with_key(key)?,
attachments: self.attachments.decrypt_with_key(key)?,
fields: self.fields.decrypt_with_key(key)?,
password_history: self.password_history.decrypt_with_key(key)?,
local_data: self.local_data.decrypt_with_key(key).ok().flatten(),
attachments: self.attachments.decrypt_with_key(key).ok().flatten(),
fields: self.fields.decrypt_with_key(key).ok().flatten(),
password_history: self.password_history.decrypt_with_key(key).ok().flatten(),

Check warning on line 200 in crates/bitwarden/src/vault/cipher/cipher.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/cipher.rs#L197-L200

Added lines #L197 - L200 were not covered by tests
creation_date: self.creation_date,
deleted_date: self.deleted_date,
revision_date: self.revision_date,
Expand Down Expand Up @@ -298,8 +298,8 @@
organization_id: self.organization_id,
folder_id: self.folder_id,
collection_ids: self.collection_ids.clone(),
name: self.name.decrypt_with_key(key)?,
sub_title: self.get_decrypted_subtitle(key)?,
name: self.name.decrypt_with_key(key).ok().unwrap_or_default(),
sub_title: self.get_decrypted_subtitle(key).ok().unwrap_or_default(),

Check warning on line 302 in crates/bitwarden/src/vault/cipher/cipher.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/cipher.rs#L301-L302

Added lines #L301 - L302 were not covered by tests
r#type: self.r#type,
favorite: self.favorite,
reprompt: self.reprompt,
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden/src/vault/cipher/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
impl KeyDecryptable<SymmetricCryptoKey, FieldView> for Field {
fn decrypt_with_key(&self, key: &SymmetricCryptoKey) -> Result<FieldView, CryptoError> {
Ok(FieldView {
name: self.name.decrypt_with_key(key)?,
value: self.value.decrypt_with_key(key)?,
name: self.name.decrypt_with_key(key).ok().flatten(),
value: self.value.decrypt_with_key(key).ok().flatten(),

Check warning on line 59 in crates/bitwarden/src/vault/cipher/field.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/field.rs#L58-L59

Added lines #L58 - L59 were not covered by tests
r#type: self.r#type,
linked_id: self.linked_id,
})
Expand Down
36 changes: 18 additions & 18 deletions crates/bitwarden/src/vault/cipher/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,24 @@
impl KeyDecryptable<SymmetricCryptoKey, IdentityView> for Identity {
fn decrypt_with_key(&self, key: &SymmetricCryptoKey) -> Result<IdentityView, CryptoError> {
Ok(IdentityView {
title: self.title.decrypt_with_key(key)?,
first_name: self.first_name.decrypt_with_key(key)?,
middle_name: self.middle_name.decrypt_with_key(key)?,
last_name: self.last_name.decrypt_with_key(key)?,
address1: self.address1.decrypt_with_key(key)?,
address2: self.address2.decrypt_with_key(key)?,
address3: self.address3.decrypt_with_key(key)?,
city: self.city.decrypt_with_key(key)?,
state: self.state.decrypt_with_key(key)?,
postal_code: self.postal_code.decrypt_with_key(key)?,
country: self.country.decrypt_with_key(key)?,
company: self.company.decrypt_with_key(key)?,
email: self.email.decrypt_with_key(key)?,
phone: self.phone.decrypt_with_key(key)?,
ssn: self.ssn.decrypt_with_key(key)?,
username: self.username.decrypt_with_key(key)?,
passport_number: self.passport_number.decrypt_with_key(key)?,
license_number: self.license_number.decrypt_with_key(key)?,
title: self.title.decrypt_with_key(key).ok().flatten(),
first_name: self.first_name.decrypt_with_key(key).ok().flatten(),
middle_name: self.middle_name.decrypt_with_key(key).ok().flatten(),
last_name: self.last_name.decrypt_with_key(key).ok().flatten(),
address1: self.address1.decrypt_with_key(key).ok().flatten(),
address2: self.address2.decrypt_with_key(key).ok().flatten(),
address3: self.address3.decrypt_with_key(key).ok().flatten(),
city: self.city.decrypt_with_key(key).ok().flatten(),
state: self.state.decrypt_with_key(key).ok().flatten(),
postal_code: self.postal_code.decrypt_with_key(key).ok().flatten(),
country: self.country.decrypt_with_key(key).ok().flatten(),
company: self.company.decrypt_with_key(key).ok().flatten(),
email: self.email.decrypt_with_key(key).ok().flatten(),
phone: self.phone.decrypt_with_key(key).ok().flatten(),
ssn: self.ssn.decrypt_with_key(key).ok().flatten(),
username: self.username.decrypt_with_key(key).ok().flatten(),
passport_number: self.passport_number.decrypt_with_key(key).ok().flatten(),
license_number: self.license_number.decrypt_with_key(key).ok().flatten(),

Check warning on line 103 in crates/bitwarden/src/vault/cipher/identity.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/identity.rs#L86-L103

Added lines #L86 - L103 were not covered by tests
})
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/bitwarden/src/vault/cipher/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@
impl KeyDecryptable<SymmetricCryptoKey, LoginView> for Login {
fn decrypt_with_key(&self, key: &SymmetricCryptoKey) -> Result<LoginView, CryptoError> {
Ok(LoginView {
username: self.username.decrypt_with_key(key)?,
password: self.password.decrypt_with_key(key)?,
username: self.username.decrypt_with_key(key).ok().flatten(),
password: self.password.decrypt_with_key(key).ok().flatten(),

Check warning on line 102 in crates/bitwarden/src/vault/cipher/login.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/login.rs#L101-L102

Added lines #L101 - L102 were not covered by tests
password_revision_date: self.password_revision_date,
uris: self.uris.decrypt_with_key(key)?,
totp: self.totp.decrypt_with_key(key)?,
uris: self.uris.decrypt_with_key(key).ok().flatten(),
totp: self.totp.decrypt_with_key(key).ok().flatten(),

Check warning on line 105 in crates/bitwarden/src/vault/cipher/login.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/login.rs#L104-L105

Added lines #L104 - L105 were not covered by tests
autofill_on_page_load: self.autofill_on_page_load,
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden/src/vault/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
id: self.id,
organization_id: self.organization_id,

name: self.name.decrypt_with_key(key)?,
name: self.name.decrypt_with_key(key).ok().unwrap_or_default(),

Check warning on line 54 in crates/bitwarden/src/vault/collection.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/collection.rs#L54

Added line #L54 was not covered by tests

external_id: self.external_id.clone(),
hide_passwords: self.hide_passwords,
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden/src/vault/folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
fn decrypt_with_key(&self, key: &SymmetricCryptoKey) -> Result<FolderView, CryptoError> {
Ok(FolderView {
id: self.id,
name: self.name.decrypt_with_key(key)?,
name: self.name.decrypt_with_key(key).ok().unwrap_or_default(),

Check warning on line 46 in crates/bitwarden/src/vault/folder.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/folder.rs#L46

Added line #L46 was not covered by tests
revision_date: self.revision_date,
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden/src/vault/password_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
key: &SymmetricCryptoKey,
) -> Result<PasswordHistoryView, CryptoError> {
Ok(PasswordHistoryView {
password: self.password.decrypt_with_key(key)?,
password: self.password.decrypt_with_key(key).ok().unwrap_or_default(),

Check warning on line 44 in crates/bitwarden/src/vault/password_history.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/password_history.rs#L44

Added line #L44 was not covered by tests
last_used_date: self.last_used_date,
})
}
Expand Down
8 changes: 4 additions & 4 deletions crates/bitwarden/src/vault/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ impl KeyDecryptable<SymmetricCryptoKey, SendView> for Send {
id: self.id,
access_id: self.access_id.clone(),

name: self.name.decrypt_with_key(&key)?,
notes: self.notes.decrypt_with_key(&key)?,
name: self.name.decrypt_with_key(&key).ok().unwrap_or_default(),
notes: self.notes.decrypt_with_key(&key).ok().flatten(),
key: Some(URL_SAFE_NO_PAD.encode(k)),
new_password: None,
has_password: self.password.is_some(),

r#type: self.r#type,
file: self.file.decrypt_with_key(&key)?,
text: self.text.decrypt_with_key(&key)?,
file: self.file.decrypt_with_key(&key).ok().flatten(),
text: self.text.decrypt_with_key(&key).ok().flatten(),

max_access_count: self.max_access_count,
access_count: self.access_count,
Expand Down