From 09aab150311754675132ca17f5695d8a064e1633 Mon Sep 17 00:00:00 2001 From: saying Date: Sun, 27 Oct 2024 18:36:19 +0800 Subject: [PATCH] fix(macos): macos dependencies and item --- crates/decrypt-cookies/Cargo.toml | 3 +++ .../src/chromium/crypto/macos.rs | 24 ++++++++++++------- crates/decrypt-cookies/src/prelude.rs | 3 ++- crates/decrypt-cookies/src/safari/mod.rs | 4 +++- .../src/utils/binary_cookies.rs | 1 + 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/crates/decrypt-cookies/Cargo.toml b/crates/decrypt-cookies/Cargo.toml index 4184464..b69fc1b 100644 --- a/crates/decrypt-cookies/Cargo.toml +++ b/crates/decrypt-cookies/Cargo.toml @@ -61,6 +61,9 @@ tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } anyhow = { workspace = true } reqwest = { workspace = true, features = ["cookies"] } +[target.'cfg(target_os = "macos")'.features] +binary_cookies = [] + [features] default = ["reqwest"] reqwest = ["dep:reqwest"] diff --git a/crates/decrypt-cookies/src/chromium/crypto/macos.rs b/crates/decrypt-cookies/src/chromium/crypto/macos.rs index a58b3c6..cd08898 100644 --- a/crates/decrypt-cookies/src/chromium/crypto/macos.rs +++ b/crates/decrypt-cookies/src/chromium/crypto/macos.rs @@ -1,7 +1,16 @@ use aes::cipher::{block_padding, BlockDecryptMut, KeyIvInit}; -use miette::{bail, Result}; use pbkdf2::pbkdf2_hmac; +#[derive(Debug)] +#[derive(thiserror::Error)] +pub enum CryptoError { + #[error("Get keyring failed")] + Keyring(#[from] keyring::Error), + #[error("Unpad error: {0}")] + Unpadding(block_padding::UnpadError), +} +type Result = std::result::Result; + // https://source.chromium.org/chromium/chromium/src/+/main:components/os_crypt/sync/os_crypt_mac.mm;l=35 /// Key size required for 128 bit AES. // const K_DERIVED_KEY_SIZE_IN_BITS: u32 = 128; @@ -39,14 +48,14 @@ impl Decrypter { fn get_pass(safe_storage: &str, safe_name: &str) -> Result> { let entry = match keyring::Entry::new(safe_storage, safe_name) { Ok(res) => res, - Err(e) => bail!("Error: {e}.new keyring Entry failed"), + Err(e) => return Err(e.into()), }; match entry .get_password() .map(String::into_bytes) { Ok(res) => Ok(res), - Err(e) => bail!("Error: {e}.new keyring Entry failed"), + Err(e) => Err(e.into()), } } @@ -68,12 +77,9 @@ impl Decrypter { let decrypter = Aes128CbcDec::new(&key.into(), &iv.into()); - if let Ok(res) = - decrypter.decrypt_padded_mut::(&mut be_decrypte[prefix_len..]) - { - return Ok(String::from_utf8_lossy(res).to_string()); + match decrypter.decrypt_padded_mut::(&mut be_decrypte[prefix_len..]) { + Ok(res) => Ok(String::from_utf8_lossy(res).to_string()), + Err(e) => Err(CryptoError::Unpadding(e)), } - - miette::bail!("decrypt error") } } diff --git a/crates/decrypt-cookies/src/prelude.rs b/crates/decrypt-cookies/src/prelude.rs index d551963..e53c453 100644 --- a/crates/decrypt-cookies/src/prelude.rs +++ b/crates/decrypt-cookies/src/prelude.rs @@ -3,7 +3,7 @@ pub use sea_orm::prelude::ColumnTrait; #[cfg(not(target_os = "linux"))] pub use crate::browser::{Arc, CocCoc, OperaGX}; #[cfg(target_os = "macos")] -pub use crate::safari::{SafariBuilder, SafariCookie, SafariGetter}; +pub use crate::safari::{SafariBuilder, SafariGetter}; pub use crate::{ browser::{ cookies::LeetCodeCookies, @@ -15,4 +15,5 @@ pub use crate::{ ChromiumLoginCol, ChromiumLoginColIter, }, firefox::{FirefoxBuilder, FirefoxGetter, MozCookiesCol, MozCookiesColIter}, + utils::binary_cookies::SafariCookie, }; diff --git a/crates/decrypt-cookies/src/safari/mod.rs b/crates/decrypt-cookies/src/safari/mod.rs index 2effd59..f35c8bd 100644 --- a/crates/decrypt-cookies/src/safari/mod.rs +++ b/crates/decrypt-cookies/src/safari/mod.rs @@ -3,7 +3,9 @@ pub mod items; use std::path::PathBuf; pub use self::items::cookie::CookiesGetter; -use crate::browser::cookies::LeetCodeCookies; +use crate::{ + binary_cookies::BinaryCookies, browser::cookies::LeetCodeCookies, prelude::SafariCookie, +}; type Result = std::result::Result; diff --git a/crates/decrypt-cookies/src/utils/binary_cookies.rs b/crates/decrypt-cookies/src/utils/binary_cookies.rs index 1b17cb6..8e79c53 100644 --- a/crates/decrypt-cookies/src/utils/binary_cookies.rs +++ b/crates/decrypt-cookies/src/utils/binary_cookies.rs @@ -1,4 +1,5 @@ //! reference +//! //! //! //!