Skip to content

Commit a5f98db

Browse files
authored
[PM-14808] Add uris to ListView (#29)
Adds the login URIs to `CipherListView` to make it useable for autofill.
1 parent 2d677e8 commit a5f98db

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

crates/bitwarden-vault/src/cipher/cipher.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use uuid::Uuid;
1414
use super::{
1515
attachment, card, field, identity,
1616
local_data::{LocalData, LocalDataView},
17+
login::LoginListView,
1718
secure_note, ssh_key,
1819
};
1920
use crate::{
@@ -133,10 +134,7 @@ pub struct CipherView {
133134
#[serde(rename_all = "camelCase", deny_unknown_fields)]
134135
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
135136
pub enum CipherListViewType {
136-
Login {
137-
has_fido2: bool,
138-
totp: Option<EncString>,
139-
},
137+
Login(LoginListView),
140138
SecureNote,
141139
Card,
142140
Identity,
@@ -182,10 +180,11 @@ impl CipherListView {
182180
let cipher_key = Cipher::get_cipher_key(key, &self.key)?;
183181
let key = cipher_key.as_ref().unwrap_or(key);
184182

185-
let totp = if let CipherListViewType::Login { totp, .. } = self.r#type {
186-
totp.decrypt_with_key(key)?
187-
} else {
188-
None
183+
let totp = match self.r#type {
184+
CipherListViewType::Login(LoginListView { totp, .. }) => {
185+
totp.map(|t| t.decrypt_with_key(key)).transpose()?
186+
}
187+
_ => None,
189188
};
190189

191190
Ok(totp)
@@ -562,10 +561,7 @@ impl KeyDecryptable<SymmetricCryptoKey, CipherListView> for Cipher {
562561
.login
563562
.as_ref()
564563
.ok_or(CryptoError::MissingField("login"))?;
565-
CipherListViewType::Login {
566-
has_fido2: login.fido2_credentials.is_some(),
567-
totp: login.totp.clone(),
568-
}
564+
CipherListViewType::Login(login.decrypt_with_key(key)?)
569565
}
570566
CipherType::SecureNote => CipherListViewType::SecureNote,
571567
CipherType::Card => CipherListViewType::Card,
@@ -803,10 +799,11 @@ mod tests {
803799
key: cipher.key,
804800
name: "My test login".to_string(),
805801
subtitle: "test_username".to_string(),
806-
r#type: CipherListViewType::Login {
802+
r#type: CipherListViewType::Login(LoginListView {
807803
has_fido2: true,
808-
totp: cipher.login.as_ref().unwrap().totp.clone()
809-
},
804+
totp: cipher.login.as_ref().unwrap().totp.clone(),
805+
uris: None,
806+
}),
810807
favorite: cipher.favorite,
811808
reprompt: cipher.reprompt,
812809
edit: cipher.edit,

crates/bitwarden-vault/src/cipher/login.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use serde_repr::{Deserialize_repr, Serialize_repr};
1111

1212
use crate::VaultParseError;
1313

14-
#[derive(Clone, Copy, Serialize_repr, Deserialize_repr, Debug, JsonSchema)]
14+
#[derive(Clone, Copy, Serialize_repr, Deserialize_repr, Debug, JsonSchema, PartialEq)]
1515
#[repr(u8)]
1616
#[serde(rename_all = "camelCase", deny_unknown_fields)]
1717
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))]
@@ -33,7 +33,7 @@ pub struct LoginUri {
3333
pub uri_checksum: Option<EncString>,
3434
}
3535

36-
#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone)]
36+
#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone, PartialEq)]
3737
#[serde(rename_all = "camelCase", deny_unknown_fields)]
3838
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
3939
pub struct LoginUriView {
@@ -268,6 +268,16 @@ pub struct LoginView {
268268
pub fido2_credentials: Option<Vec<Fido2Credential>>,
269269
}
270270

271+
#[derive(Serialize, Deserialize, Debug, JsonSchema, Clone, PartialEq)]
272+
#[serde(rename_all = "camelCase", deny_unknown_fields)]
273+
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
274+
pub struct LoginListView {
275+
pub has_fido2: bool,
276+
/// The TOTP key is not decrypted. Useable as is with [`crate::generate_totp_cipher_view`].
277+
pub totp: Option<EncString>,
278+
pub uris: Option<Vec<LoginUriView>>,
279+
}
280+
271281
impl KeyEncryptable<SymmetricCryptoKey, LoginUri> for LoginUriView {
272282
fn encrypt_with_key(self, key: &SymmetricCryptoKey) -> Result<LoginUri, CryptoError> {
273283
Ok(LoginUri {
@@ -316,6 +326,16 @@ impl KeyDecryptable<SymmetricCryptoKey, LoginView> for Login {
316326
}
317327
}
318328

329+
impl KeyDecryptable<SymmetricCryptoKey, LoginListView> for Login {
330+
fn decrypt_with_key(&self, key: &SymmetricCryptoKey) -> Result<LoginListView, CryptoError> {
331+
Ok(LoginListView {
332+
has_fido2: self.fido2_credentials.is_some(),
333+
totp: self.totp.clone(),
334+
uris: self.uris.decrypt_with_key(key).ok().flatten(),
335+
})
336+
}
337+
}
338+
319339
impl KeyEncryptable<SymmetricCryptoKey, Fido2Credential> for Fido2CredentialView {
320340
fn encrypt_with_key(self, key: &SymmetricCryptoKey) -> Result<Fido2Credential, CryptoError> {
321341
Ok(Fido2Credential {

crates/bitwarden-vault/src/totp.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ mod tests {
266266
use uuid::Uuid;
267267

268268
use super::*;
269-
use crate::{cipher::cipher::CipherListViewType, CipherRepromptType};
269+
use crate::{cipher::cipher::CipherListViewType, login::LoginListView, CipherRepromptType};
270270

271271
#[test]
272272
fn test_decode_b32() {
@@ -377,10 +377,11 @@ mod tests {
377377
key: None,
378378
name: "My test login".to_string(),
379379
subtitle: "test_username".to_string(),
380-
r#type: CipherListViewType::Login {
380+
r#type: CipherListViewType::Login(LoginListView{
381381
has_fido2: true,
382382
totp: Some("2.hqdioUAc81FsKQmO1XuLQg==|oDRdsJrQjoFu9NrFVy8tcJBAFKBx95gHaXZnWdXbKpsxWnOr2sKipIG43pKKUFuq|3gKZMiboceIB5SLVOULKg2iuyu6xzos22dfJbvx0EHk=".parse().unwrap()),
383-
},
383+
uris: None,
384+
}),
384385
favorite: false,
385386
reprompt: CipherRepromptType::None,
386387
edit: true,

0 commit comments

Comments
 (0)