diff --git a/Cargo.lock b/Cargo.lock index c23c050..4c4690b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "addr2line" @@ -621,9 +621,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -631,9 +631,9 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-executor" @@ -648,15 +648,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-macro" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" dependencies = [ "proc-macro2", "quote", @@ -665,21 +665,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-util" -version = "0.3.30" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ "futures-channel", "futures-core", diff --git a/src/api.rs b/src/api.rs index 3007fd1..5ba3d3c 100644 --- a/src/api.rs +++ b/src/api.rs @@ -100,7 +100,7 @@ impl<'de> serde::Deserialize<'de> for TwoFactorProviderType { D: serde::Deserializer<'de>, { struct TwoFactorProviderTypeVisitor; - impl<'de> serde::de::Visitor<'de> for TwoFactorProviderTypeVisitor { + impl serde::de::Visitor<'_> for TwoFactorProviderTypeVisitor { type Value = TwoFactorProviderType; fn expecting( @@ -186,7 +186,7 @@ impl<'de> serde::Deserialize<'de> for KdfType { D: serde::Deserializer<'de>, { struct KdfTypeVisitor; - impl<'de> serde::de::Visitor<'de> for KdfTypeVisitor { + impl serde::de::Visitor<'_> for KdfTypeVisitor { type Value = KdfType; fn expecting( @@ -767,6 +767,13 @@ struct FoldersPostReq { name: String, } +// Used for the Bitwarden-Client-Name header. Accepted values: +// https://github.com/bitwarden/server/blob/main/src/Core/Enums/BitwardenClient.cs +const BITWARDEN_CLIENT: &str = "cli"; + +// DeviceType.LinuxDesktop, as per Bitwarden API device types. +const DEVICE_TYPE: u8 = 8; + #[derive(Debug)] pub struct Client { base_url: String, @@ -796,12 +803,24 @@ impl Client { let mut default_headers = axum::http::HeaderMap::new(); default_headers.insert( "Bitwarden-Client-Name", - axum::http::HeaderValue::from_static(env!("CARGO_PKG_NAME")), + axum::http::HeaderValue::from_static(BITWARDEN_CLIENT), ); default_headers.insert( "Bitwarden-Client-Version", axum::http::HeaderValue::from_static(env!("CARGO_PKG_VERSION")), ); + default_headers.append( + "Device-Type", + // unwrap is safe here because DEVICE_TYPE is a number and digits + // are valid ASCII + axum::http::HeaderValue::from_str(&DEVICE_TYPE.to_string()) + .unwrap(), + ); + let user_agent = format!( + "{}/{}", + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_VERSION") + ); if let Some(client_cert_path) = self.client_cert_path.as_ref() { let mut buf = Vec::new(); let mut f = tokio::fs::File::open(client_cert_path) @@ -819,22 +838,14 @@ impl Client { let pem = reqwest::Identity::from_pem(&buf) .map_err(|e| Error::CreateReqwestClient { source: e })?; Ok(reqwest::Client::builder() - .user_agent(format!( - "{}/{}", - env!("CARGO_PKG_NAME"), - env!("CARGO_PKG_VERSION") - )) + .user_agent(user_agent) .identity(pem) .default_headers(default_headers) .build() .map_err(|e| Error::CreateReqwestClient { source: e })?) } else { Ok(reqwest::Client::builder() - .user_agent(format!( - "{}/{}", - env!("CARGO_PKG_NAME"), - env!("CARGO_PKG_VERSION") - )) + .user_agent(user_agent) .default_headers(default_headers) .build() .map_err(|e| Error::CreateReqwestClient { source: e })?) @@ -885,7 +896,7 @@ impl Client { // XXX unwraps here are not necessarily safe client_id: String::from_utf8(apikey.client_id().to_vec()) .unwrap(), - device_type: 8, + device_type: u32::from(DEVICE_TYPE), device_identifier: device_id.to_string(), device_name: "rbw".to_string(), device_push_token: String::new(), @@ -942,7 +953,7 @@ impl Client { grant_type: "authorization_code".to_string(), scope: "api offline_access".to_string(), client_id: "cli".to_string(), - device_type: 8, + device_type: u32::from(DEVICE_TYPE), device_identifier: device_id.to_string(), device_name: "rbw".to_string(), device_push_token: String::new(), diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index 486b5d1..4af92cb 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -1643,9 +1643,8 @@ fn check_config() -> anyhow::Result<()> { } fn version_or_quit() -> anyhow::Result { - crate::actions::version().map_err(|e| { + crate::actions::version().inspect_err(|_e| { let _ = crate::actions::quit(); - e }) }