diff --git a/crates/bitwarden-crypto/src/keys/shareable_key.rs b/crates/bitwarden-crypto/src/keys/shareable_key.rs index 0d3b33ec5..e84e05ca3 100644 --- a/crates/bitwarden-crypto/src/keys/shareable_key.rs +++ b/crates/bitwarden-crypto/src/keys/shareable_key.rs @@ -2,9 +2,12 @@ use std::pin::Pin; use aes::cipher::typenum::U64; use generic_array::GenericArray; -use hmac::{Hmac, Mac}; +use hmac::Mac; -use crate::{keys::SymmetricCryptoKey, util::hkdf_expand}; +use crate::{ + keys::SymmetricCryptoKey, + util::{hkdf_expand, PbkdfSha256Hmac}, +}; /// Derive a shareable key using hkdf from secret and name. /// @@ -19,7 +22,7 @@ pub fn derive_shareable_key( // TODO: Are these the final `key` and `info` parameters or should we change them? I followed // the pattern used for sends - let res = Hmac::::new_from_slice(format!("bitwarden-{}", name).as_bytes()) + let res = PbkdfSha256Hmac::new_from_slice(format!("bitwarden-{}", name).as_bytes()) .expect("hmac new_from_slice should not fail") .chain_update(secret) .finalize() diff --git a/crates/bws/src/config.rs b/crates/bws/src/config.rs index d1724a8fe..6cc471f97 100644 --- a/crates/bws/src/config.rs +++ b/crates/bws/src/config.rs @@ -46,23 +46,28 @@ impl ProfileKey { pub(crate) const FILENAME: &str = "config"; pub(crate) const DIRECTORY: &str = ".bws"; -pub(crate) fn get_config_path(config_file: Option<&Path>, ensure_folder_exists: bool) -> PathBuf { - let config_file = config_file.map(ToOwned::to_owned).unwrap_or_else(|| { - let base_dirs = BaseDirs::new().expect("A valid home directory should exist"); - base_dirs.home_dir().join(DIRECTORY).join(FILENAME) - }); +fn get_config_path(config_file: Option<&Path>, ensure_folder_exists: bool) -> Result { + let config_file = match config_file { + Some(path) => path.to_owned(), + None => { + let Some(base_dirs) = BaseDirs::new() else { + bail!("A valid home directory doesn't exist"); + }; + base_dirs.home_dir().join(DIRECTORY).join(FILENAME) + } + }; if ensure_folder_exists { if let Some(parent_folder) = config_file.parent() { - std::fs::create_dir_all(parent_folder).expect("Parent directory should be writable"); + std::fs::create_dir_all(parent_folder)?; } } - config_file + Ok(config_file) } pub(crate) fn load_config(config_file: Option<&Path>, must_exist: bool) -> Result { - let file = get_config_path(config_file, false); + let file = get_config_path(config_file, false)?; let content = match file.exists() { true => read_to_string(file), @@ -75,7 +80,7 @@ pub(crate) fn load_config(config_file: Option<&Path>, must_exist: bool) -> Resul } fn write_config(config: Config, config_file: Option<&Path>) -> Result<()> { - let file = get_config_path(config_file, true); + let file = get_config_path(config_file, true)?; let content = toml::to_string_pretty(&config)?;