Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert icloud-auth to async, integrate anisette-v3 and support SMS auth #18

Merged
merged 19 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions apple-dev-apis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ omnisette = {path = "../omnisette"}
icloud_auth = {path = "../icloud-auth"}
hmac = "0.12.1"
sha2 = "0.10.6"

[dev-dependencies]
tokio = { version = "1", features = ["rt", "macros"] }
6 changes: 3 additions & 3 deletions apple-dev-apis/tests/xcsession.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ mod tests {
use apple_dev_apis::XcodeSession;
use icloud_auth::*;

#[test]
fn xcsession_test() {
#[tokio::test]
async fn xcsession_test() {
println!("gsa auth test");

let email = std::env::var("apple_email").unwrap_or_else(|_| {
Expand All @@ -29,7 +29,7 @@ mod tests {
std::io::stdin().read_line(&mut input).unwrap();
input.trim().to_string()
};
let acc = AppleAccount::login(appleid_closure, tfa_closure);
let acc = AppleAccount::login(appleid_closure, tfa_closure).await;
let session = XcodeSession::with(&acc.unwrap());
}
}
7 changes: 6 additions & 1 deletion icloud-auth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ cbc = { version = "0.1.2", features = ["std"] }
aes = "0.8.2"
pkcs7 = "0.3.0"
reqwest = { version = "0.11.14", features = ["blocking", "json", "default-tls"] }
omnisette = {path = "../omnisette"}
omnisette = {path = "../omnisette", features = ["remote-anisette-v3"]}
thiserror = "1.0.58"
tokio = "1"

[dev-dependencies]
tokio = { version = "1", features = ["rt", "macros"] }
40 changes: 24 additions & 16 deletions icloud-auth/src/anisette.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
use crate::Error;
use omnisette::{AnisetteConfiguration, AnisetteHeaders};
use std::{collections::HashMap, path::PathBuf};
use std::{collections::HashMap, time::SystemTime};

#[derive(Debug, Clone)]
pub struct AnisetteData {
pub base_headers: HashMap<String, String>,
pub generated_at: SystemTime,
pub config: AnisetteConfiguration,
}

impl AnisetteData {
/// Fetches the data at an anisette server
pub fn new() -> Result<Self, crate::Error> {
let base_headers = match AnisetteHeaders::get_anisette_headers_provider(
AnisetteConfiguration::new()
.set_configuration_path(PathBuf::new().join("anisette_test"))
.set_anisette_url("https://ani.f1sh.me".to_string()),
) {
Ok(mut b) => match b.get_authentication_headers() {
Ok(b) => b,
Err(_) => return Err(Error::ErrorGettingAnisette),
},
Err(_) => {
return Err(Error::HttpRequest);
}
};
pub async fn new(config: AnisetteConfiguration) -> Result<Self, crate::Error> {
let mut b = AnisetteHeaders::get_anisette_headers_provider(config.clone())?;
let base_headers = b.provider.get_authentication_headers().await?;

Ok(AnisetteData { base_headers })
Ok(AnisetteData { base_headers, generated_at: SystemTime::now(), config })
}

pub fn needs_refresh(&self) -> bool {
let elapsed = self.generated_at.elapsed().unwrap();
elapsed.as_secs() > 60
}

pub fn is_valid(&self) -> bool {
let elapsed = self.generated_at.elapsed().unwrap();
elapsed.as_secs() < 90
}

pub async fn refresh(&self) -> Result<Self, crate::Error> {
Self::new(self.config.clone()).await
}

pub fn generate_headers(
Expand All @@ -33,6 +38,9 @@ impl AnisetteData {
client_info: bool,
app_info: bool,
) -> HashMap<String, String> {
if !self.is_valid() {
panic!("Invalid data!")
}
let mut headers = self.base_headers.clone();
let old_client_info = headers.remove("X-Mme-Client-Info");
if client_info {
Expand Down
Loading
Loading