-
Notifications
You must be signed in to change notification settings - Fork 20
[PM-25818] Migrate Basic Cipher Create, Edit, and Get Operations to SDK #455
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
base: main
Are you sure you want to change the base?
Changes from all commits
d5fb7b2
8144b98
0734d40
0987ba7
0535582
d008260
47ea335
d204e42
9a8d482
778c3ac
09af3cb
298b336
841f40a
17cecd8
9d27d7f
d219627
c1fcadc
2b8491a
a0bca6b
0c568a0
0f35f92
5bffe2a
04269c6
4593cd3
3f07956
223cfe1
bde6dde
f8dfeea
bd539ac
b3bbda7
8c331aa
1ea2211
cc78556
532a6ba
7f4033c
69bbc99
d06a363
a331fc6
f931e47
4a0c45c
1cf6514
86b0b56
69978d0
ef2f7ca
2b57bcf
cc2af00
5e13d4c
365534e
a1f39f2
1b897a2
7c423e9
c22d519
7332bba
c8f96d1
8600bd4
b665cab
9713beb
1e0ed6c
0ccac3d
bed6f11
08dbf06
ea7d98a
ed2f8e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
use bitwarden_api_api::models::CipherDetailsResponseModel; | ||
use bitwarden_api_api::models::{CipherDetailsResponseModel, CipherResponseModel}; | ||
use bitwarden_collections::collection::CollectionId; | ||
use bitwarden_core::{ | ||
MissingFieldError, OrganizationId, UserId, | ||
|
@@ -79,11 +79,12 @@ pub enum CipherType { | |
} | ||
|
||
#[allow(missing_docs)] | ||
#[derive(Clone, Copy, Serialize_repr, Deserialize_repr, Debug, PartialEq)] | ||
#[derive(Clone, Copy, Default, Serialize_repr, Deserialize_repr, Debug, PartialEq)] | ||
#[repr(u8)] | ||
#[cfg_attr(feature = "uniffi", derive(uniffi::Enum))] | ||
#[cfg_attr(feature = "wasm", wasm_bindgen)] | ||
pub enum CipherRepromptType { | ||
#[default] | ||
None = 0, | ||
Password = 1, | ||
} | ||
|
@@ -472,10 +473,8 @@ impl CipherView { | |
|
||
#[allow(missing_docs)] | ||
pub fn generate_checksums(&mut self) { | ||
if let Some(uris) = self.login.as_mut().and_then(|l| l.uris.as_mut()) { | ||
for uri in uris { | ||
uri.generate_checksum(); | ||
} | ||
if let Some(l) = self.login.as_mut() { | ||
l.generate_checksums(); | ||
} | ||
} | ||
|
||
|
@@ -528,11 +527,7 @@ impl CipherView { | |
new_key: SymmetricKeyId, | ||
) -> Result<(), CryptoError> { | ||
if let Some(login) = self.login.as_mut() { | ||
if let Some(fido2_credentials) = &mut login.fido2_credentials { | ||
let dec_fido2_credentials: Vec<Fido2CredentialFullView> = | ||
fido2_credentials.decrypt(ctx, old_key)?; | ||
*fido2_credentials = dec_fido2_credentials.encrypt_composite(ctx, new_key)?; | ||
} | ||
login.reencrypt_fido2_credentials(ctx, old_key, new_key)?; | ||
} | ||
Ok(()) | ||
} | ||
|
@@ -695,6 +690,15 @@ impl Decryptable<KeyIds, SymmetricKeyId, CipherListView> for Cipher { | |
} | ||
} | ||
|
||
#[cfg(feature = "wasm")] | ||
impl wasm_bindgen::__rt::VectorIntoJsValue for CipherView { | ||
fn vector_into_jsvalue( | ||
vector: wasm_bindgen::__rt::std::boxed::Box<[Self]>, | ||
) -> wasm_bindgen::JsValue { | ||
wasm_bindgen::__rt::js_value_vector_into_jsvalue(vector) | ||
} | ||
} | ||
|
||
Comment on lines
+693
to
+701
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: interesting, haven't seen this before. Did you have issues returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is because tsify isn't adding this derive, which wasm-bindgen expects for types returning lists. Oscar and I had the same problem with folders: Reported upstream: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, nice, thanks! |
||
impl IdentifyKey<SymmetricKeyId> for Cipher { | ||
fn key_identifier(&self) -> SymmetricKeyId { | ||
match self.organization_id { | ||
|
@@ -796,6 +800,75 @@ impl From<bitwarden_api_api::models::CipherRepromptType> for CipherRepromptType | |
} | ||
} | ||
|
||
impl From<CipherType> for bitwarden_api_api::models::CipherType { | ||
fn from(t: CipherType) -> Self { | ||
match t { | ||
CipherType::Login => bitwarden_api_api::models::CipherType::Login, | ||
CipherType::SecureNote => bitwarden_api_api::models::CipherType::SecureNote, | ||
CipherType::Card => bitwarden_api_api::models::CipherType::Card, | ||
CipherType::Identity => bitwarden_api_api::models::CipherType::Identity, | ||
CipherType::SshKey => bitwarden_api_api::models::CipherType::SSHKey, | ||
} | ||
} | ||
} | ||
|
||
impl From<CipherRepromptType> for bitwarden_api_api::models::CipherRepromptType { | ||
fn from(t: CipherRepromptType) -> Self { | ||
match t { | ||
CipherRepromptType::None => bitwarden_api_api::models::CipherRepromptType::None, | ||
CipherRepromptType::Password => bitwarden_api_api::models::CipherRepromptType::Password, | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<CipherResponseModel> for Cipher { | ||
type Error = VaultParseError; | ||
|
||
fn try_from(cipher: CipherResponseModel) -> Result<Self, Self::Error> { | ||
Ok(Self { | ||
id: cipher.id.map(CipherId::new), | ||
organization_id: cipher.organization_id.map(OrganizationId::new), | ||
folder_id: cipher.folder_id.map(FolderId::new), | ||
collection_ids: vec![], // CipherResponseModel doesn't include collection_ids | ||
name: require!(cipher.name).parse()?, | ||
notes: EncString::try_from_optional(cipher.notes)?, | ||
r#type: require!(cipher.r#type).into(), | ||
login: cipher.login.map(|l| (*l).try_into()).transpose()?, | ||
identity: cipher.identity.map(|i| (*i).try_into()).transpose()?, | ||
card: cipher.card.map(|c| (*c).try_into()).transpose()?, | ||
secure_note: cipher.secure_note.map(|s| (*s).try_into()).transpose()?, | ||
ssh_key: cipher.ssh_key.map(|s| (*s).try_into()).transpose()?, | ||
favorite: cipher.favorite.unwrap_or(false), | ||
reprompt: cipher | ||
.reprompt | ||
.map(|r| r.into()) | ||
.unwrap_or(CipherRepromptType::None), | ||
organization_use_totp: cipher.organization_use_totp.unwrap_or(false), | ||
edit: cipher.edit.unwrap_or(false), | ||
permissions: cipher.permissions.map(|p| (*p).try_into()).transpose()?, | ||
view_password: cipher.view_password.unwrap_or(true), | ||
local_data: None, // Not sent from server | ||
attachments: cipher | ||
.attachments | ||
.map(|a| a.into_iter().map(|a| a.try_into()).collect()) | ||
.transpose()?, | ||
fields: cipher | ||
.fields | ||
.map(|f| f.into_iter().map(|f| f.try_into()).collect()) | ||
.transpose()?, | ||
password_history: cipher | ||
.password_history | ||
.map(|p| p.into_iter().map(|p| p.try_into()).collect()) | ||
.transpose()?, | ||
creation_date: require!(cipher.creation_date).parse()?, | ||
deleted_date: cipher.deleted_date.map(|d| d.parse()).transpose()?, | ||
revision_date: require!(cipher.revision_date).parse()?, | ||
key: EncString::try_from_optional(cipher.key)?, | ||
archived_date: cipher.archived_date.map(|d| d.parse()).transpose()?, | ||
}) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
|
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.
๐ Thanks for moving the uri checksum generation and fido2 re-encryption logic to
Login
!