Skip to content

Native iCloud apps for Windows and Linux, built in Rust. Notes, Reminders, Calendar, Contacts, Drive and Photos, offline and in sync with your iPhone.

Sign-in: ask Apple to send the code, as it now has to be asked

Yashwanth Kamireddi690dea2abd20
diff --git a/crates/quince-auth/src/lib.rs b/crates/quince-auth/src/lib.rs
index 9201891..0721d93 100644
--- a/crates/quince-auth/src/lib.rs
+++ b/crates/quince-auth/src/lib.rs
@@ -641,6 +641,15 @@ impl Client {
match status {
StatusCode::CONFLICT => {
self.persist()?;
+ // Ask for the code. Apple used to push it to trusted devices on this 409 by
+ // itself; since iOS 26.4 it waits to be asked (PUT verify/trusteddevice/
+ // securitycode), and until asked no "Allow sign-in?" ever reaches a phone —
+ // which is why the only way a code ever arrived here was Airplane Mode and
+ // Settings, or pressing "Send again". Not fatal if it fails: the code screen
+ // still offers sending it again, and a text.
+ if let Err(e) = self.resend_to_devices().await {
+ eprintln!("asking Apple to send the code: {e}");
+ }
Ok(SignInOutcome::NeedsTwoFactor)
}
s if s.is_success() => {
@@ -803,7 +812,13 @@ impl Client {
self.capture(&r);
let status = r.status();
let body = r.text().await.unwrap_or_default();
- if !status.is_success() && status != StatusCode::NO_CONTENT {
+ // Since iOS 26.4 a correct code is answered 409 with `securityCode.valid: true`.
+ let accepted = status == StatusCode::CONFLICT
+ && serde_json::from_str::<Value>(&body)
+ .ok()
+ .and_then(|v| v.pointer("/securityCode/valid").and_then(Value::as_bool))
+ == Some(true);
+ if !status.is_success() && status != StatusCode::NO_CONTENT && !accepted {
let err = apple_error("checking that code", status, &body);
// A genuinely wrong code is final; don't burn an attempt probing further.
if matches!(err, Error::BadCode) {
diff --git a/crates/quince-auth/tests/auth_flow.rs b/crates/quince-auth/tests/auth_flow.rs
index e1921a3..3597497 100644
--- a/crates/quince-auth/tests/auth_flow.rs
+++ b/crates/quince-auth/tests/auth_flow.rs
@@ -737,3 +737,38 @@ async fn a_password_is_kept_only_once_it_has_worked_and_forgotten_on_sign_out()
"gone on sign-out"
);
}
+
+/// "I never receive the verification code." Since iOS 26.4 Apple no longer pushes it on the
+/// 409 by itself — the client has to ask, with a PUT to verify/trusteddevice/securitycode —
+/// so a sign-in that needs a code asks straight away, from the icloud.com origin.
+#[tokio::test]
+async fn a_sign_in_that_needs_a_code_asks_apple_to_send_it() {
+ let server = MockServer::start().await;
+ mount_init(&server, 200).await;
+ mount_complete(&server, 409).await;
+ Mock::given(method("PUT"))
+ .and(path("/appleauth/auth/verify/trusteddevice/securitycode"))
+ .respond_with(ResponseTemplate::new(202))
+ .mount(&server)
+ .await;
+ let dir = tempfile::tempdir().unwrap();
+ let mut client = client_for(&server, dir.path());
+ let outcome = client
+ .sign_in("[email protected]", "hunter2")
+ .await
+ .unwrap();
+ assert_eq!(outcome, SignInOutcome::NeedsTwoFactor);
+
+ let reqs = server.received_requests().await.unwrap();
+ let asked: Vec<_> = requests_to(&reqs, "/verify/trusteddevice/securitycode")
+ .into_iter()
+ .filter(|r| r.method.as_str() == "PUT")
+ .collect();
+ assert_eq!(asked.len(), 1, "the code was asked for");
+ let origin = asked[0].headers.get("origin").and_then(|v| v.to_str().ok());
+ assert_ne!(
+ origin,
+ Some(SRP_ORIGIN),
+ "from the icloud.com origin, not idmsa's"
+ );
+}