diff --git a/crates/bitwarden-vault/src/cipher/attachment.rs b/crates/bitwarden-vault/src/cipher/attachment.rs index 27ed7fdc1..e12c18b62 100644 --- a/crates/bitwarden-vault/src/cipher/attachment.rs +++ b/crates/bitwarden-vault/src/cipher/attachment.rs @@ -59,6 +59,9 @@ pub struct AttachmentView { /// Do not rely on this field for long-term use. #[cfg(feature = "wasm")] pub decrypted_key: Option, + /// Indicates whether this attachment failed to decrypt. + #[serde(default)] + pub decryption_failure: bool, } impl AttachmentView { @@ -211,6 +214,12 @@ impl Decryptable for Attachment { ctx: &mut KeyStoreContext, key: SymmetricKeyId, ) -> Result { + // Try to decrypt the file name + let (file_name, decryption_failure) = match self.file_name.decrypt(ctx, key) { + Ok(name) => (name, false), + Err(..) => (None, true), + }; + #[cfg(feature = "wasm")] let decrypted_key = if let Some(attachment_key) = &self.key { let content_key_id = ctx.unwrap_symmetric_key(key, attachment_key)?; @@ -228,7 +237,8 @@ impl Decryptable for Attachment { url: self.url.clone(), size: self.size.clone(), size_name: self.size_name.clone(), - file_name: self.file_name.decrypt(ctx, key)?, + file_name, + decryption_failure, key: self.key.clone(), #[cfg(feature = "wasm")] decrypted_key: decrypted_key.map(|k| k.to_string()), @@ -290,6 +300,7 @@ mod tests { key: None, #[cfg(feature = "wasm")] decrypted_key: None, + decryption_failure: false, }; let contents = b"This is a test file that we will encrypt. It's 100 bytes long, the encrypted version will be longer!"; @@ -350,6 +361,7 @@ mod tests { key: Some("2.r288/AOSPiaLFkW07EBGBw==|SAmnnCbOLFjX5lnURvoualOetQwuyPc54PAmHDTRrhT0gwO9ailna9U09q9bmBfI5XrjNNEsuXssgzNygRkezoVQvZQggZddOwHB6KQW5EQ=|erIMUJp8j+aTcmhdE50zEX+ipv/eR1sZ7EwULJm/6DY=".parse().unwrap()), #[cfg(feature = "wasm")] decrypted_key: None, + decryption_failure: false, }; let cipher = Cipher { @@ -411,6 +423,7 @@ mod tests { key: None, #[cfg(feature = "wasm")] decrypted_key: None, + decryption_failure: false, }; let cipher = Cipher { diff --git a/crates/bitwarden-vault/src/cipher/cipher.rs b/crates/bitwarden-vault/src/cipher/cipher.rs index 39c6c666b..75918e0e1 100644 --- a/crates/bitwarden-vault/src/cipher/cipher.rs +++ b/crates/bitwarden-vault/src/cipher/cipher.rs @@ -1454,6 +1454,7 @@ mod tests { key: None, #[cfg(feature = "wasm")] decrypted_key: None, + decryption_failure: false, }; cipher.attachments = Some(vec![attachment]); @@ -1567,6 +1568,7 @@ mod tests { key: None, #[cfg(feature = "wasm")] decrypted_key: None, + decryption_failure: false, }; cipher.attachments = Some(vec![attachment]); @@ -1612,6 +1614,7 @@ mod tests { key: Some(attachment_key_enc), #[cfg(feature = "wasm")] decrypted_key: None, + decryption_failure: false, }; cipher.attachments = Some(vec![attachment]); let cred = generate_fido2(&mut key_store.context(), SymmetricKeyId::User); @@ -1681,6 +1684,7 @@ mod tests { key: Some(attachment_key_enc.clone()), #[cfg(feature = "wasm")] decrypted_key: None, + decryption_failure: false, }; cipher.attachments = Some(vec![attachment]); diff --git a/crates/bitwarden-vault/src/cipher/cipher_client/share_cipher.rs b/crates/bitwarden-vault/src/cipher/cipher_client/share_cipher.rs index f5002ee00..c67a38c13 100644 --- a/crates/bitwarden-vault/src/cipher/cipher_client/share_cipher.rs +++ b/crates/bitwarden-vault/src/cipher/cipher_client/share_cipher.rs @@ -441,6 +441,7 @@ mod tests { key: None, // No key! #[cfg(feature = "wasm")] decrypted_key: None, + decryption_failure: false, }]); let organization_id: OrganizationId = TEST_ORG_ID.parse().unwrap();