Skip to content

[PM-8618] Credential Exchange #32

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

Merged
merged 30 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e956c2c
Add credential exchange dependency
Hinton Nov 12, 2024
31323f5
Initial implementation for converting passwords to BasicAuth
Hinton Nov 12, 2024
666ac41
Wip json export for Apple
Hinton Nov 12, 2024
cc9a081
Merge branch 'main' of github.com:bitwarden/sdk-internal into credentโ€ฆ
Hinton Nov 12, 2024
27d8d4b
Add Account struct
Hinton Nov 14, 2024
8afb57d
Update credential exchange
Hinton Nov 14, 2024
c6d6f10
Return account directly
Hinton Nov 14, 2024
f3f3e6d
Implement passkey export
Hinton Nov 15, 2024
332db74
Fmt
Hinton Nov 15, 2024
ffc7ae3
Implement import for basic auth
Hinton Nov 21, 2024
204e329
Fix clippy
Hinton Nov 21, 2024
c935e6f
Really awful import logic
Hinton Nov 22, 2024
7f86d84
Add support for TOTP in exports
Hinton Nov 25, 2024
e78bb42
Add note export
Hinton Nov 26, 2024
582100c
Update tests to cover full export
Hinton Nov 26, 2024
0b64c4e
Update comments to better reflect the actual types
Hinton Nov 26, 2024
bd0d2a6
Add warnings
Hinton Nov 26, 2024
b6687f7
Improve documentation add todo
Hinton Nov 28, 2024
67ce782
Invert documentation
Hinton Nov 28, 2024
9fc823c
Merge branch 'main' of github.com:bitwarden/sdk-internal into credentโ€ฆ
Hinton Nov 28, 2024
95c6f87
Fix lockfile
Hinton Nov 28, 2024
cc68ca9
Cleanup exporter
Hinton Nov 28, 2024
dce7056
Update credential exchange crate
Hinton Dec 9, 2024
c79cdec
Extract convert totp
Hinton Dec 9, 2024
e199cdb
Add more export tests
Hinton Dec 10, 2024
7a6827d
Add more tests, use set_new_fido2_credentials
Hinton Dec 12, 2024
e402dc0
Merge branch 'main' of github.com:bitwarden/sdk-internal into credentโ€ฆ
Hinton Dec 12, 2024
ee0e0a6
Use less than equal for scenarios where the test is run to quickly.
Hinton Dec 12, 2024
b4bc137
Resolve some review feedback
Hinton Dec 12, 2024
061ec35
Fix tests for importing passkeys
Hinton Dec 12, 2024
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
50 changes: 50 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion crates/bitwarden-exporters/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ license-file.workspace = true
keywords.workspace = true

[features]
uniffi = ["dep:uniffi"] # Uniffi bindings
uniffi = ["dep:uniffi", "bitwarden-core/uniffi"] # Uniffi bindings

[dependencies]
base64 = ">=0.22.1, <0.23"
bitwarden-core = { workspace = true }
bitwarden-crypto = { workspace = true }
bitwarden-fido = { workspace = true }
bitwarden-vault = { workspace = true }
chrono = { workspace = true, features = ["std"] }
credential-exchange-types = { git = "https://github.com/bitwarden/credential-exchange.git", rev = "60bf99f097af72144b0eaa757ccb50fd46049f24" }
csv = "1.3.0"
schemars = { workspace = true }
serde = { workspace = true }
Expand All @@ -31,5 +33,8 @@ thiserror = { workspace = true }
uniffi = { workspace = true, optional = true }
uuid = { workspace = true }

[dev-dependencies]
rand = ">=0.8.5, <0.9"

[lints]
workspace = true
28 changes: 26 additions & 2 deletions crates/bitwarden-exporters/src/client_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
use bitwarden_vault::{Cipher, Collection, Folder};

use crate::{
export::{export_organization_vault, export_vault},
ExportError, ExportFormat,
export::{export_cxf, export_organization_vault, export_vault, import_cxf},
Account, ExportError, ExportFormat,
};

pub struct ClientExporters<'a> {
Expand Down Expand Up @@ -32,6 +32,30 @@
) -> Result<String, ExportError> {
export_organization_vault(collections, ciphers, format)
}

/// Credential Exchange Format (CXF)
///
/// *Warning:* Expect this API to be unstable, and it will change in the future.
///
/// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
/// Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
pub fn export_cxf(
&self,
account: Account,
ciphers: Vec<Cipher>,
) -> Result<String, ExportError> {
export_cxf(self.client, account, ciphers)
}

Check warning on line 48 in crates/bitwarden-exporters/src/client_exporter.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-exporters/src/client_exporter.rs#L42-L48

Added lines #L42 - L48 were not covered by tests

/// Credential Exchange Format (CXF)
///
/// *Warning:* Expect this API to be unstable, and it will change in the future.
///
/// For use with Apple using [ASCredentialExportManager](https://developer.apple.com/documentation/authenticationservices/ascredentialexportmanager).
/// Ideally the input should be immediately serialized from [ASImportableAccount](https://developer.apple.com/documentation/authenticationservices/asimportableaccount).
pub fn import_cxf(&self, payload: String) -> Result<Vec<Cipher>, ExportError> {
import_cxf(self.client, payload)
}

Check warning on line 58 in crates/bitwarden-exporters/src/client_exporter.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-exporters/src/client_exporter.rs#L56-L58

Added lines #L56 - L58 were not covered by tests
}

pub trait ClientExportersExt<'a> {
Expand Down
2 changes: 2 additions & 0 deletions crates/bitwarden-exporters/src/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ mod tests {
r#match: None,
}],
totp: None,
fido2_credentials: None,
})),
favorite: false,
reprompt: 0,
Expand All @@ -160,6 +161,7 @@ mod tests {
r#match: None,
}],
totp: Some("steam://ABCD123".to_string()),
fido2_credentials: None,
})),
favorite: true,
reprompt: 0,
Expand Down
12 changes: 12 additions & 0 deletions crates/bitwarden-exporters/src/cxp/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use std::borrow::Cow;

use thiserror::Error;

#[derive(Error, Debug)]
pub enum CxpError {
#[error("JSON error: {0}")]
Serde(#[from] serde_json::Error),

#[error("Internal error: {0}")]
Internal(Cow<'static, str>),
}
Loading
Loading