From 38a9185e04316270b8a5a1ac9c52ac76c2c2e3ea Mon Sep 17 00:00:00 2001 From: Grega Kespret Date: Wed, 14 Oct 2026 00:25:38 +0200 Subject: [PATCH 1/7] Preserve Android anisette identity for escrow authentication --- src/icloud/keychain.rs | 51 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/src/icloud/keychain.rs b/src/icloud/keychain.rs index 06928e0..919ec2a 100644 --- a/src/icloud/keychain.rs +++ b/src/icloud/keychain.rs @@ -1089,6 +1089,15 @@ pub struct KeychainClientState { pub items: HashMap, } +fn escrow_anisette_headers(mut headers: HashMap, service_info: String) -> HashMap { + // Preserve the Android identity supplied with these anisette headers; + // the service's iPhone persona would reintroduce an identity mismatch. + if !headers["X-Mme-Client-Info"].contains(" Option { Some(KeychainClientState { @@ -2298,9 +2307,9 @@ impl KeychainClient

{ map.insert("X-Apple-I-Locale", "en_US".parse().unwrap()); drop(state_lock); - let mut base_headers = self.anisette.lock().await.get_headers().await?.clone(); - - base_headers.insert("X-Mme-Client-Info".to_string(), self.config.get_adi_mme_info("com.apple.AuthKit/1 (com.apple.sbd/638.100.48)", !base_headers["X-Mme-Client-Info"].contains("iPhone OS"))); + let base_headers = self.anisette.lock().await.get_headers().await?.clone(); + let service_info = self.config.get_adi_mme_info("com.apple.AuthKit/1 (com.apple.sbd/638.100.48)", !base_headers["X-Mme-Client-Info"].contains("iPhone OS")); + let base_headers = escrow_anisette_headers(base_headers, service_info); map.extend(base_headers.into_iter().map(|(a, b)| (HeaderName::from_str(&a).unwrap(), b.parse().unwrap()))); @@ -2312,15 +2321,21 @@ impl KeychainClient

{ let email = self.token_provider.get_gsa_email().await.expect("no email!"); let state = self.state.read().await; + let headers = self.get_escrow_headers().await?; + let profile = if headers["X-Mme-Client-Info"].to_str().unwrap().contains(" ".into()); + assert_eq!(result["X-Mme-Client-Info"], android); + assert_eq!(result["X-Apple-I-MD"], "test-otp"); + } + + #[test] + fn escrow_retains_service_profile_for_apple_anisette() { + let headers = HashMap::from([("X-Mme-Client-Info".into(), " ".into())]); + let service = " "; + let result = escrow_anisette_headers(headers, service.into()); + assert_eq!(result["X-Mme-Client-Info"], service); + } +} From 7363665ad1e2781af89f3599378c857be6c8fc24 Mon Sep 17 00:00:00 2001 From: Grega Kespret Date: Wed, 14 Oct 2026 09:19:42 +0200 Subject: [PATCH 2/7] Preserve native Mac platform in escrow service identity --- src/icloud/keychain.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/icloud/keychain.rs b/src/icloud/keychain.rs index 919ec2a..b3c4879 100644 --- a/src/icloud/keychain.rs +++ b/src/icloud/keychain.rs @@ -1090,11 +1090,17 @@ pub struct KeychainClientState { } fn escrow_anisette_headers(mut headers: HashMap, service_info: String) -> HashMap { - // Preserve the Android identity supplied with these anisette headers; - // the service's iPhone persona would reintroduce an identity mismatch. - if !headers["X-Mme-Client-Info"].contains(" <"), service_info.rsplit_once("> <")) { + (Some((platform, _)), Some((_, application))) => format!("{platform}> <{application}"), + _ => identity.clone(), + } + } else { service_info }; + headers.insert("X-Mme-Client-Info".to_string(), service_info); headers } @@ -2322,7 +2328,10 @@ impl KeychainClient

{ let state = self.state.read().await; let headers = self.get_escrow_headers().await?; - let profile = if headers["X-Mme-Client-Info"].to_str().unwrap().contains(" "); + } } From a0b03995c908d5edae22bc18061921702be2cc6a Mon Sep 17 00:00:00 2001 From: Grega Kespret Date: Mon, 26 Oct 2026 08:55:31 +0100 Subject: [PATCH 3/7] Pin apple-private-apis: 2FA failures log Apple's error code, not its reply A rejected security code logged Apple's whole reply, which echoes the typed code and the trusted phone numbers. Now only the HTTP status and serviceErrors code, title and message are logged. No API change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01JvDrSTtCSuxsh3iMaZ8sPX --- apple-private-apis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple-private-apis b/apple-private-apis index d0832be..b645577 160000 --- a/apple-private-apis +++ b/apple-private-apis @@ -1 +1 @@ -Subproject commit d0832be473a6753846d95fd70b66e6f1a291f68d +Subproject commit b6455776f7b827e4a254a2f2dbcdfd2396c001df From 06d79cc8b22560fb68afabfa83e304ef81973f6d Mon Sep 17 00:00:00 2001 From: Grega Kespret Date: Mon, 26 Oct 2026 09:07:33 +0100 Subject: [PATCH 4/7] Pin apple-private-apis: a wrong SMS code can be retyped On Apple's -21669 ("Try entering your verification code again.") the login now asks for the code again for the same text instead of failing with Bad2faCode. The 2FA closure takes a TfaPrompt (the texted phone, plus how many codes Apple has refused for this text) and returns Option; the console callers in src/test.rs ignore the prompt. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01JvDrSTtCSuxsh3iMaZ8sPX --- apple-private-apis | 2 +- src/test.rs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apple-private-apis b/apple-private-apis index d0832be..56f0dea 160000 --- a/apple-private-apis +++ b/apple-private-apis @@ -1 +1 @@ -Subproject commit d0832be473a6753846d95fd70b66e6f1a291f68d +Subproject commit 56f0dead30c37b89a549df3690e4187824445711 diff --git a/src/test.rs b/src/test.rs index 5e5e5fa..936105f 100644 --- a/src/test.rs +++ b/src/test.rs @@ -346,11 +346,11 @@ async fn main() { state.users.clone() } else { // ask console for 2fa code, make sure it is only 6 digits, no extra characters - let tfa_closure = |_sent_to: Option<&str>| { + let tfa_closure = |_prompt: icloud_auth::TfaPrompt| { println!("Enter 2FA code: "); let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); - input.trim().to_string() + Some(input.trim().to_string()) }; let mut account = AppleAccount::new_with_anisette(config.get_gsa_config(&*connection.state.read().await, false), anisette_client.clone()).unwrap(); @@ -433,11 +433,11 @@ async fn main() { let conf = (gsa.user.clone(), gsa.pass.as_ref().to_vec()); let appleid_closure = move || conf.clone(); // ask console for 2fa code, make sure it is only 6 digits, no extra characters - let tfa_closure = |_sent_to: Option<&str>| { + let tfa_closure = |_prompt: icloud_auth::TfaPrompt| { println!("Enter 2FA code: "); let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); - input.trim().to_string() + Some(input.trim().to_string()) }; let acc = AppleAccount::login(appleid_closure, tfa_closure, From ba58bddf4947c0d03ab45f908e2cc629eec010ad Mon Sep 17 00:00:00 2001 From: Grega Kespret Date: Fri, 6 Nov 2026 11:24:04 +0100 Subject: [PATCH 5/7] Pin apple-private-apis 28fde51: retype only a plain wrong code Moves the submodule to the head of apple-private-apis#8, which retypes a refused code only when -21669 is Apple's sole reason. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018qVCoJNNwwmBEafaSpCBiG --- apple-private-apis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple-private-apis b/apple-private-apis index 56f0dea..28fde51 160000 --- a/apple-private-apis +++ b/apple-private-apis @@ -1 +1 @@ -Subproject commit 56f0dead30c37b89a549df3690e4187824445711 +Subproject commit 28fde5160af4238a5d28799c2209d5fd1af5f2ad From a8c410751bea7cf961bf5b5223142bd0598ec75f Mon Sep 17 00:00:00 2001 From: Grega Kespret Date: Fri, 6 Nov 2026 13:58:23 +0100 Subject: [PATCH 6/7] Pin apple-private-apis to the default-phone change Moves the submodule to 6557333, where the SMS code goes to Apple's default trusted phone and the 2FA prompt answers with `TfaAnswer` (a code, or another phone to text). The two console prompts in src/test.rs answer with `TfaAnswer::Code`. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018qVCoJNNwwmBEafaSpCBiG --- apple-private-apis | 2 +- src/test.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/apple-private-apis b/apple-private-apis index 28fde51..6557333 160000 --- a/apple-private-apis +++ b/apple-private-apis @@ -1 +1 @@ -Subproject commit 28fde5160af4238a5d28799c2209d5fd1af5f2ad +Subproject commit 6557333a865b6a0a967fd0a73273c6ed8ac70f75 diff --git a/src/test.rs b/src/test.rs index 936105f..0c9ba4f 100644 --- a/src/test.rs +++ b/src/test.rs @@ -350,7 +350,7 @@ async fn main() { println!("Enter 2FA code: "); let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); - Some(input.trim().to_string()) + Some(icloud_auth::TfaAnswer::Code(input.trim().to_string())) }; let mut account = AppleAccount::new_with_anisette(config.get_gsa_config(&*connection.state.read().await, false), anisette_client.clone()).unwrap(); @@ -437,7 +437,7 @@ async fn main() { println!("Enter 2FA code: "); let mut input = String::new(); std::io::stdin().read_line(&mut input).unwrap(); - Some(input.trim().to_string()) + Some(icloud_auth::TfaAnswer::Code(input.trim().to_string())) }; let acc = AppleAccount::login(appleid_closure, tfa_closure, From 77fb266d23e9d0d84a2462038efaa99fe96e5780 Mon Sep 17 00:00:00 2001 From: Grega Kespret Date: Fri, 6 Nov 2026 16:57:29 +0100 Subject: [PATCH 7/7] Pin apple-private-apis to the refused-switch fix Moves the submodule to 1eaf3e0: a phone switch Apple will not send goes back to the text already sent instead of failing the sign-in, and TfaPrompt gains `texts` and `switch_refused`. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_018qVCoJNNwwmBEafaSpCBiG --- apple-private-apis | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apple-private-apis b/apple-private-apis index 6557333..1eaf3e0 160000 --- a/apple-private-apis +++ b/apple-private-apis @@ -1 +1 @@ -Subproject commit 6557333a865b6a0a967fd0a73273c6ed8ac70f75 +Subproject commit 1eaf3e0c0460dedfa1b73b644c2953ff5716edf2