Skip to content
Merged
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
12 changes: 6 additions & 6 deletions bitwarden_license/bitwarden-sm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ use validator::ValidationErrors;
#[derive(Debug, thiserror::Error)]
pub enum SecretsManagerError {
#[error(transparent)]
ValidationError(ValidationError),
Validation(ValidationError),
#[error(transparent)]
CryptoError(#[from] bitwarden_crypto::CryptoError),
Crypto(#[from] bitwarden_crypto::CryptoError),
#[error(transparent)]
Chrono(#[from] chrono::ParseError),

#[error(transparent)]
ApiError(#[from] bitwarden_core::ApiError),
Api(#[from] bitwarden_core::ApiError),
#[error(transparent)]
MissingFieldError(#[from] bitwarden_core::MissingFieldError),
MissingField(#[from] bitwarden_core::MissingFieldError),
}

// Validation
Expand Down Expand Up @@ -78,12 +78,12 @@ impl From<ValidationErrors> for ValidationError {

impl From<ValidationErrors> for SecretsManagerError {
fn from(e: ValidationErrors) -> Self {
SecretsManagerError::ValidationError(e.into())
SecretsManagerError::Validation(e.into())
}
}

impl<T> From<ApiApisError<T>> for SecretsManagerError {
fn from(e: bitwarden_api_api::apis::Error<T>) -> Self {
SecretsManagerError::ApiError(e.into())
SecretsManagerError::Api(e.into())
}
}
2 changes: 1 addition & 1 deletion crates/bitwarden-collections/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ pub enum CollectionsParseError {
#[error(transparent)]
Crypto(#[from] bitwarden_crypto::CryptoError),
#[error(transparent)]
MissingFieldError(#[from] bitwarden_core::MissingFieldError),
MissingField(#[from] bitwarden_core::MissingFieldError),
}
2 changes: 1 addition & 1 deletion crates/bitwarden-core/src/client/encryption_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub enum EncryptionSettingsError {
MissingPrivateKey(#[from] MissingPrivateKeyError),

#[error(transparent)]
UserIdAlreadySetError(#[from] UserIdAlreadySetError),
UserIdAlreadySet(#[from] UserIdAlreadySetError),

#[error("Wrong Pin")]
WrongPin,
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub enum StatefulCryptoError {
got: u32,
},
#[error("Crypto error, {0}")]
CryptoError(#[from] bitwarden_crypto::CryptoError),
Crypto(#[from] bitwarden_crypto::CryptoError),
}

/// This macro is used to require that a value is present or return an error otherwise.
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-core/src/key_management/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ pub(crate) fn make_v2_keys_for_v1_user(
// V1 user must have a private key to upgrade. This should be ensured by the client before
// calling the upgrade function.
if !ctx.has_asymmetric_key(AsymmetricKeyId::UserPrivateKey) {
return Err(StatefulCryptoError::CryptoError(CryptoError::MissingKeyId(
return Err(StatefulCryptoError::Crypto(CryptoError::MissingKeyId(
"UserPrivateKey".to_string(),
)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct FingerprintResponse {
#[derive(Debug, Error)]
pub enum FingerprintError {
#[error(transparent)]
CryptoError(#[from] bitwarden_crypto::CryptoError),
Crypto(#[from] bitwarden_crypto::CryptoError),
}

pub(crate) fn generate_fingerprint(input: &FingerprintRequest) -> Result<String, FingerprintError> {
Expand Down
8 changes: 4 additions & 4 deletions crates/bitwarden-crypto/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ pub enum CryptoError {
EncString(#[from] EncStringParseError),

#[error("Rsa error, {0}")]
RsaError(#[from] RsaError),
Rsa(#[from] RsaError),

#[error("Fingerprint error, {0}")]
FingerprintError(#[from] FingerprintError),
Fingerprint(#[from] FingerprintError),

#[error("Argon2 error, {0}")]
ArgonError(#[from] argon2::Error),
Expand All @@ -66,10 +66,10 @@ pub enum CryptoError {
InvalidPadding,

#[error("Signature error, {0}")]
SignatureError(#[from] SignatureError),
Signature(#[from] SignatureError),

#[error("Encoding error, {0}")]
EncodingError(#[from] EncodingError),
Encoding(#[from] EncodingError),
}

#[derive(Debug, Error)]
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-crypto/src/rsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ pub(super) fn encrypt_rsa2048_oaep_sha1(public_key: &RsaPublicKey, data: &[u8])
let padding = Oaep::new::<Sha1>();
public_key
.encrypt(&mut rng, padding, data)
.map_err(|e| CryptoError::RsaError(e.into()))
.map_err(|e| CryptoError::Rsa(e.into()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
#[allow(deprecated)]
let key_ref = ctx
.dangerous_get_symmetric_key(key_to_seal)
.map_err(|_| PasswordProtectedKeyEnvelopeError::KeyMissingError)?;
.map_err(|_| PasswordProtectedKeyEnvelopeError::KeyMissing)?;
Self::seal_ref(key_ref, password)
}

Expand Down Expand Up @@ -97,7 +97,7 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
// The envelope key is directly derived from the KDF and used as the key to encrypt the key
// that should be sealed.
let envelope_key = derive_key(kdf_settings, password)
.map_err(|_| PasswordProtectedKeyEnvelopeError::KdfError)?;
.map_err(|_| PasswordProtectedKeyEnvelopeError::Kdf)?;

let (content_format, key_to_seal_bytes) = match key_to_seal.to_encoded_raw() {
EncodedSymmetricKey::BitwardenLegacyKey(key_bytes) => {
Expand Down Expand Up @@ -145,7 +145,7 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
let key = self.unseal_ref(password)?;
#[allow(deprecated)]
ctx.set_symmetric_key(target_keyslot, key)
.map_err(|_| PasswordProtectedKeyEnvelopeError::KeyStoreError)?;
.map_err(|_| PasswordProtectedKeyEnvelopeError::KeyStore)?;
Ok(target_keyslot)
}

Expand All @@ -161,34 +161,32 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
.first()
.filter(|_| self.cose_encrypt.recipients.len() == 1)
.ok_or_else(|| {
PasswordProtectedKeyEnvelopeError::ParsingError(
PasswordProtectedKeyEnvelopeError::Parsing(
"Invalid number of recipients".to_string(),
)
})?;

if recipient.protected.header.alg != Some(coset::Algorithm::PrivateUse(ALG_ARGON2ID13)) {
return Err(PasswordProtectedKeyEnvelopeError::ParsingError(
return Err(PasswordProtectedKeyEnvelopeError::Parsing(
"Unknown or unsupported KDF algorithm".to_string(),
));
}

let kdf_settings: Argon2RawSettings =
(&recipient.unprotected).try_into().map_err(|_| {
PasswordProtectedKeyEnvelopeError::ParsingError(
PasswordProtectedKeyEnvelopeError::Parsing(
"Invalid or missing KDF parameters".to_string(),
)
})?;
let envelope_key = derive_key(&kdf_settings, password)
.map_err(|_| PasswordProtectedKeyEnvelopeError::KdfError)?;
.map_err(|_| PasswordProtectedKeyEnvelopeError::Kdf)?;
let nonce: [u8; crate::xchacha20::NONCE_SIZE] = self
.cose_encrypt
.unprotected
.iv
.clone()
.try_into()
.map_err(|_| {
PasswordProtectedKeyEnvelopeError::ParsingError("Invalid IV".to_string())
})?;
.map_err(|_| PasswordProtectedKeyEnvelopeError::Parsing("Invalid IV".to_string()))?;

let key_bytes = self
.cose_encrypt
Expand All @@ -201,9 +199,7 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {

SymmetricCryptoKey::try_from(
match ContentFormat::try_from(&self.cose_encrypt.protected.header).map_err(|_| {
PasswordProtectedKeyEnvelopeError::ParsingError(
"Invalid content format".to_string(),
)
PasswordProtectedKeyEnvelopeError::Parsing("Invalid content format".to_string())
})? {
ContentFormat::BitwardenLegacyKey => EncodedSymmetricKey::BitwardenLegacyKey(
BitwardenLegacyKeyBytes::from(key_bytes),
Expand All @@ -212,15 +208,13 @@ impl<Ids: KeyIds> PasswordProtectedKeyEnvelope<Ids> {
EncodedSymmetricKey::CoseKey(CoseKeyBytes::from(key_bytes))
}
_ => {
return Err(PasswordProtectedKeyEnvelopeError::ParsingError(
return Err(PasswordProtectedKeyEnvelopeError::Parsing(
"Unknown or unsupported content format".to_string(),
));
}
},
)
.map_err(|_| {
PasswordProtectedKeyEnvelopeError::ParsingError("Failed to decode key".to_string())
})
.map_err(|_| PasswordProtectedKeyEnvelopeError::Parsing("Failed to decode key".to_string()))
}

/// Re-seals the key with new KDF parameters (updated settings, salt), and a new password
Expand Down Expand Up @@ -268,12 +262,12 @@ impl<Ids: KeyIds> FromStr for PasswordProtectedKeyEnvelope<Ids> {

fn from_str(s: &str) -> Result<Self, Self::Err> {
let data = B64::try_from(s).map_err(|_| {
PasswordProtectedKeyEnvelopeError::ParsingError(
PasswordProtectedKeyEnvelopeError::Parsing(
"Invalid PasswordProtectedKeyEnvelope Base64 encoding".to_string(),
)
})?;
Self::try_from(&data.into_bytes()).map_err(|_| {
PasswordProtectedKeyEnvelopeError::ParsingError(
PasswordProtectedKeyEnvelopeError::Parsing(
"Failed to parse PasswordProtectedKeyEnvelope".to_string(),
)
})
Expand Down Expand Up @@ -373,7 +367,7 @@ impl TryInto<Params> for &Argon2RawSettings {
self.parallelism,
Some(ENVELOPE_ARGON2_OUTPUT_KEY_SIZE),
)
.map_err(|_| PasswordProtectedKeyEnvelopeError::KdfError)
.map_err(|_| PasswordProtectedKeyEnvelopeError::Kdf)
}
}

Expand All @@ -388,9 +382,7 @@ impl TryInto<Argon2RawSettings> for &Header {
salt: extract_bytes(self, ARGON2_SALT, "salt")?
.try_into()
.map_err(|_| {
PasswordProtectedKeyEnvelopeError::ParsingError(
"Invalid Argon2 salt".to_string(),
)
PasswordProtectedKeyEnvelopeError::Parsing("Invalid Argon2 salt".to_string())
})?,
})
}
Expand All @@ -415,7 +407,7 @@ fn derive_key(
argon2_settings.try_into()?,
)
.hash_password_into(password.as_bytes(), &argon2_settings.salt, &mut hash)
.map_err(|_| PasswordProtectedKeyEnvelopeError::KdfError)?;
.map_err(|_| PasswordProtectedKeyEnvelopeError::Kdf)?;

Ok(hash)
}
Expand All @@ -428,29 +420,29 @@ pub enum PasswordProtectedKeyEnvelopeError {
WrongPassword,
/// The envelope could not be parsed correctly, or the KDF parameters are invalid
#[error("Parsing error {0}")]
ParsingError(String),
Parsing(String),
/// The KDF failed to derive a key, possibly due to invalid parameters or memory allocation
/// issues
#[error("Kdf error")]
KdfError,
Kdf,
/// There is no key for the provided key id in the key store
#[error("Key missing error")]
KeyMissingError,
KeyMissing,
/// The key store could not be written to, for example due to being read-only
#[error("Could not write to key store")]
KeyStoreError,
KeyStore,
}

impl From<CoseExtractError> for PasswordProtectedKeyEnvelopeError {
fn from(err: CoseExtractError) -> Self {
let CoseExtractError::MissingValue(label) = err;
PasswordProtectedKeyEnvelopeError::ParsingError(format!("Missing value for {}", label))
PasswordProtectedKeyEnvelopeError::Parsing(format!("Missing value for {}", label))
}
}

impl From<TryFromIntError> for PasswordProtectedKeyEnvelopeError {
fn from(err: TryFromIntError) -> Self {
PasswordProtectedKeyEnvelopeError::ParsingError(format!("Invalid integer: {}", err))
PasswordProtectedKeyEnvelopeError::Parsing(format!("Invalid integer: {}", err))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden-exporters/src/cxf/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ fn extract_key_type(public_key: &str) -> Result<String, SshKeyExportError> {
let key_type = public_key
.split_whitespace()
.next()
.ok_or(SshKeyExportError::KeyConversionError)?;
.ok_or(SshKeyExportError::KeyConversion)?;

Ok(key_type.to_string())
}
Expand Down
8 changes: 4 additions & 4 deletions crates/bitwarden-exporters/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ pub enum ExportError {
#[error("CSV error: {0}")]
Csv(#[from] crate::csv::CsvError),
#[error("Credential Exchange error: {0}")]
CxfError(#[from] crate::cxf::CxfError),
Cxf(#[from] crate::cxf::CxfError),
#[error("JSON error: {0}")]
Json(#[from] crate::json::JsonError),
#[error("Encrypted JSON error: {0}")]
EncryptedJsonError(#[from] crate::encrypted_json::EncryptedJsonError),
EncryptedJson(#[from] crate::encrypted_json::EncryptedJsonError),

#[error(transparent)]
BitwardenCryptoError(#[from] bitwarden_crypto::CryptoError),
BitwardenCrypto(#[from] bitwarden_crypto::CryptoError),
#[error(transparent)]
CipherError(#[from] bitwarden_vault::CipherError),
Cipher(#[from] bitwarden_vault::CipherError),
}
Loading