Skip to content

Commit

Permalink
fix(macos): macos dependencies and item
Browse files Browse the repository at this point in the history
  • Loading branch information
saying121 committed Oct 27, 2024
1 parent 139af30 commit 09aab15
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
3 changes: 3 additions & 0 deletions crates/decrypt-cookies/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
24 changes: 15 additions & 9 deletions crates/decrypt-cookies/src/chromium/crypto/macos.rs
Original file line number Diff line number Diff line change
@@ -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<T> = std::result::Result<T, CryptoError>;

// 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;
Expand Down Expand Up @@ -39,14 +48,14 @@ impl Decrypter {
fn get_pass(safe_storage: &str, safe_name: &str) -> Result<Vec<u8>> {
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()),
}
}

Expand All @@ -68,12 +77,9 @@ impl Decrypter {

let decrypter = Aes128CbcDec::new(&key.into(), &iv.into());

if let Ok(res) =
decrypter.decrypt_padded_mut::<block_padding::Pkcs7>(&mut be_decrypte[prefix_len..])
{
return Ok(String::from_utf8_lossy(res).to_string());
match decrypter.decrypt_padded_mut::<block_padding::Pkcs7>(&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")
}
}
3 changes: 2 additions & 1 deletion crates/decrypt-cookies/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -15,4 +15,5 @@ pub use crate::{
ChromiumLoginCol, ChromiumLoginColIter,
},
firefox::{FirefoxBuilder, FirefoxGetter, MozCookiesCol, MozCookiesColIter},
utils::binary_cookies::SafariCookie,
};
4 changes: 3 additions & 1 deletion crates/decrypt-cookies/src/safari/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = std::result::Result<T, crate::safari::items::cookie::CookiesGetterError>;

Expand Down
1 change: 1 addition & 0 deletions crates/decrypt-cookies/src/utils/binary_cookies.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! reference
//!
//! <https://github.com/cixtor/binarycookies>
//! <https://github.com/libyal/dtformats/blob/main/documentation/Safari%20Cookies.asciidoc>
//! <https://github.com/interstateone/BinaryCookies>
Expand Down

0 comments on commit 09aab15

Please sign in to comment.