Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.
Rust apple-notesapple-reminderscloudkitcrdtdesktop-appicloudicloud-calendaricloud-driveicloud-notesicloud-photosiphonelinuxlinux-desktoplocal-firstoffline-firstprivacyrusttauritauri-appwindows
Sign-in takes an older account's low key-derivation count
Yashwanth Kamireddieca94c40e9ca
diff --git a/crates/quince-auth/src/lib.rs b/crates/quince-auth/src/lib.rsindex 077fac8..1524f08 100644--- a/crates/quince-auth/src/lib.rs+++ b/crates/quince-auth/src/lib.rs@@ -80,9 +80,12 @@ impl Endpoints {/// iCloud web's first-party OAuth widget key. Not a secret — it is public in the web client.const WIDGET_KEY: &str = "d39ba9916b7251055b22c7f910e2ea796ee65e98b2ddecea8f5dde8d9d1a815d";-/// Bounds on Apple's PBKDF2 iteration count. Apple uses roughly 20k; anything far outside-/// this is either a corrupted response or something trying to make us burn CPU.-const MIN_PBKDF2_ITERATIONS: u32 = 1_000;+/// Bounds on Apple's PBKDF2 iteration count. Apple sends each account's own: most see about+/// 20,000, but older accounts far fewer (806 for one, issue #8), and every other client takes+/// whatever comes. So any count is taken but none, which is no derivation at all; only the+/// ceiling guards something, a response that would have us burn the CPU. Apple chose the count+/// over TLS, so a low one is not something an attacker in the middle can ask for.+const MIN_PBKDF2_ITERATIONS: u32 = 1;const MAX_PBKDF2_ITERATIONS: u32 = 1_000_000;/// Version strings the iCloud web client sends. Cosmetic to Apple in practice, but sendingdiff --git a/crates/quince-auth/tests/auth_flow.rs b/crates/quince-auth/tests/auth_flow.rsindex 986e7e4..8dc6a7a 100644--- a/crates/quince-auth/tests/auth_flow.rs+++ b/crates/quince-auth/tests/auth_flow.rs@@ -478,7 +478,7 @@ async fn signing_out_clears_a_cooldown() {/// rather than truncated into a cast or left to burn CPU.#[tokio::test]async fn an_implausible_work_factor_is_refused() {- for absurd in [u64::from(u32::MAX) + 1, 5_000_000_000, 3] {+ for absurd in [u64::from(u32::MAX) + 1, 5_000_000_000, 1_000_001, 0] {let server = MockServer::start().await;Mock::given(method("POST")).and(path("/appleauth/auth/signin/init"))@@ -505,6 +505,40 @@ async fn an_implausible_work_factor_is_refused() {}}+/// An older account's own count, as Apple sent it to one person (806, issue #8): taken, and the+/// sign-in goes on to send its proof, rather than stopping at "implausible".+#[tokio::test]+async fn an_older_accounts_low_work_factor_is_taken() {+ let server = MockServer::start().await;+ Mock::given(method("POST"))+ .and(path("/appleauth/auth/signin/init"))+ .respond_with(ResponseTemplate::new(200).set_body_json(json!({+ "salt": b64(&[0x77; 16]),+ "b": b64(&[0x5e; 256]),+ "c": "challenge-c",+ "iteration": 806,+ "protocol": "s2k",+ })))+ .mount(&server)+ .await;+ Mock::given(method("POST"))+ .and(path("/appleauth/auth/signin/complete"))+ .respond_with(ResponseTemplate::new(401).set_body_json(json!({})))+ .expect(1)+ .mount(&server)+ .await;+ let dir = tempfile::tempdir().unwrap();+ let mut client = client_for(&server, dir.path());+ let err = client+ .sign_in("[email protected]", "hunter2")+ .await+ .unwrap_err();+ assert!(+ !err.to_string().contains("implausible"),+ "806 rounds was refused: {err}"+ );+}+/// Apple's service endpoints authenticate by cookie. If the cookies are lost but the tokens/// survive — a copied install, a cleared cache, cookies expiring before the trust token —/// resuming must re-establish them rather than leaving the app looking signed in while every