Skip to content
Open
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
41 changes: 17 additions & 24 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crates/bitwarden-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ bitwarden-uniffi-error = { workspace = true, optional = true }
cbc = { version = ">=0.1.2, <0.2", features = ["alloc", "zeroize"] }
chacha20poly1305 = { version = "0.10.1" }
ciborium = { version = ">=0.2.2, <0.3" }
coset = { version = ">=0.3.8, <0.4" }
coset = { version = ">=0.3.8, <0.5" }
ed25519-dalek = { workspace = true, features = ["rand_core"] }
generic-array = { version = ">=0.14.7, <1.0", features = ["zeroize"] }
hkdf = ">=0.12.3, <0.13"
Expand Down
26 changes: 15 additions & 11 deletions crates/bitwarden-crypto/src/cose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,21 @@ pub(crate) fn decrypt_xchacha20_poly1305(
return Err(CryptoError::WrongCoseKeyId);
}

let decrypted_message = msg.decrypt(&[], |data, aad| {
let nonce = msg.unprotected.iv.as_slice();
crate::xchacha20::decrypt_xchacha20_poly1305(
nonce
.try_into()
.map_err(|_| CryptoError::InvalidNonceLength)?,
&(*key.enc_key).into(),
data,
aad,
)
})?;
let decrypted_message = msg.decrypt_ciphertext(
&[],
|| CryptoError::MissingField("ciphertext"),
|data, aad| {
let nonce = msg.unprotected.iv.as_slice();
crate::xchacha20::decrypt_xchacha20_poly1305(
nonce
.try_into()
.map_err(|_| CryptoError::InvalidNonceLength)?,
&(*key.enc_key).into(),
data,
aad,
)
},
)?;

if should_pad_content(&content_format) {
// Unpad the data to get the original plaintext
Expand Down
26 changes: 15 additions & 11 deletions crates/bitwarden-crypto/src/safe/data_envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,21 @@ impl DataEnvelope {

// Decrypt the message
let decrypted_message = msg
.decrypt(&[], |data, aad| {
let nonce = msg.unprotected.iv.as_slice();
crate::xchacha20::decrypt_xchacha20_poly1305(
nonce
.try_into()
.map_err(|_| CryptoError::InvalidNonceLength)?,
&(*cek.enc_key).into(),
data,
aad,
)
})
.decrypt_ciphertext(
&[],
|| CryptoError::MissingField("ciphertext"),
|data, aad| {
let nonce = msg.unprotected.iv.as_slice();
crate::xchacha20::decrypt_xchacha20_poly1305(
nonce
.try_into()
.map_err(|_| CryptoError::InvalidNonceLength)?,
&(*cek.enc_key).into(),
data,
aad,
)
},
)
.map_err(|_| DataEnvelopeError::DecryptionError)?;

let unpadded_message =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use thiserror::Error;
use wasm_bindgen::convert::FromWasmAbi;

use crate::{
BitwardenLegacyKeyBytes, ContentFormat, CoseKeyBytes, EncodedSymmetricKey, KeyIds,
BitwardenLegacyKeyBytes, ContentFormat, CoseKeyBytes, CryptoError, EncodedSymmetricKey, KeyIds,
KeyStoreContext, SymmetricCryptoKey,
cose::{
ALG_ARGON2ID13, ARGON2_ITERATIONS, ARGON2_MEMORY, ARGON2_PARALLELISM, ARGON2_SALT,
Expand Down Expand Up @@ -185,9 +185,11 @@ impl PasswordProtectedKeyEnvelope {

let key_bytes = self
.cose_encrypt
.decrypt(&[], |data, aad| {
xchacha20::decrypt_xchacha20_poly1305(&nonce, &envelope_key, data, aad)
})
.decrypt_ciphertext(
&[],
|| CryptoError::MissingField("ciphertext"),
|data, aad| xchacha20::decrypt_xchacha20_poly1305(&nonce, &envelope_key, data, aad),
)
// If decryption fails, the envelope-key is incorrect and thus the password is incorrect
// since the KDF parameters & salt are guaranteed to be correct
.map_err(|_| PasswordProtectedKeyEnvelopeError::WrongPassword)?;
Expand Down
6 changes: 3 additions & 3 deletions crates/bitwarden-fido/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ bitwarden-crypto = { workspace = true }
bitwarden-encoding = { workspace = true }
bitwarden-vault = { workspace = true }
chrono = { workspace = true }
coset = ">=0.3.7, <0.4"
coset = ">=0.3.7, <0.5"
itertools = ">=0.13.0, <0.15"
p256 = ">=0.13.2, <0.14"
passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "357cc9672340f6ff1f22a0b210a74de64799fa73" }
passkey-client = { git = "https://github.com/bitwarden/passkey-rs", rev = "357cc9672340f6ff1f22a0b210a74de64799fa73", features = [
passkey = { git = "https://github.com/bitwarden/passkey-rs", rev = "043279e92e2eb5f509bf87eb7fa50987fd377e32" }
passkey-client = { git = "https://github.com/bitwarden/passkey-rs", rev = "043279e92e2eb5f509bf87eb7fa50987fd377e32", features = [
"android-asset-validation",
] }
reqwest = { workspace = true }
Expand Down
Loading