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: new iCloud terms to accept are said, not taken for a signed-in session

Yashwanth Kamireddi03d025ba27e1
diff --git a/crates/quince-auth/src/lib.rs b/crates/quince-auth/src/lib.rs
index 1c5c8f9..8931982 100644
--- a/crates/quince-auth/src/lib.rs
+++ b/crates/quince-auth/src/lib.rs
@@ -115,6 +115,10 @@ pub enum Error {
CoolingDown { seconds: u64 },
#[error("this needs a fresh sign-in — Apple won't accept a resumed session for it")]
ReauthRequired,
+ /// Apple holds the session back until new iCloud terms are accepted, which only a browser
+ /// or an Apple device can do.
+ #[error("Apple has new iCloud terms for this account. Sign in at icloud.com, accept them, then sign in here again.")]
+ TermsPending,
// Apple's 429 and its 503 on sign-in both mean "not now", whether from too many tries or
// its own load: say what to do, not which of the two it was.
#[error(
@@ -822,6 +826,8 @@ impl Client {
self.keep();
return Ok(true);
}
+ // Signing in again would only meet the same terms, and count as a failed attempt.
+ Err(Error::TermsPending) => return Err(Error::TermsPending),
Err(e) => e,
};
// Unreachable is not rejected. Offline — no network yet after login, or a resume
@@ -949,7 +955,8 @@ impl Client {
| Error::Network(_)
| Error::Keyring(_)
| Error::Io(_)
- | Error::Json(_),
+ | Error::Json(_)
+ | Error::TermsPending,
) => {}
Err(e) => {
self.session.consecutive_failures =
@@ -1345,7 +1352,15 @@ impl Client {
Error::Protocol(format!("couldn't open the account ({status})"))
}));
}
- Ok(serde_json::from_str(&text)?)
+ let data: Value = serde_json::from_str(&text)?;
+ // New iCloud terms not yet accepted: Apple answers 200 but opens the session only
+ // part-way, without the web cookies every service needs (rclone/rclone#9919), so every
+ // sync failed afterwards with nothing to say why. Only icloud.com or a device of the
+ // person's own can accept them.
+ if data.get("termsUpdateNeeded").and_then(Value::as_bool) == Some(true) {
+ return Err(Error::TermsPending);
+ }
+ Ok(data)
}
fn absorb(&mut self, data: &Value) {
diff --git a/crates/quince-auth/tests/auth_flow.rs b/crates/quince-auth/tests/auth_flow.rs
index be2cd61..38213bc 100644
--- a/crates/quince-auth/tests/auth_flow.rs
+++ b/crates/quince-auth/tests/auth_flow.rs
@@ -1258,3 +1258,70 @@ async fn trusted_numbers_at_the_top_are_still_texted() {
let body: serde_json::Value = serde_json::from_slice(&sent[0].body).unwrap();
assert_eq!(body, json!({ "phoneNumber": { "id": 7 }, "mode": "sms" }));
}
+
+/// New iCloud terms not yet accepted: `accountLogin` answers 200 with `termsUpdateNeeded`
+/// and opens the session only part-way (rclone/rclone#9919). Taken as signed in, every sync
+/// failed after with nothing to say why. It says so, and costs no wait: no password was wrong.
+#[tokio::test]
+async fn new_terms_to_accept_are_said_not_taken_for_a_sign_in() {
+ let server = MockServer::start().await;
+ mount_init(&server, 200).await;
+ mount_complete(&server, 200).await;
+ Mock::given(method("POST"))
+ .and(path("/setup/ws/1/accountLogin"))
+ .respond_with(ResponseTemplate::new(200).set_body_json(json!({
+ "termsUpdateNeeded": true,
+ "dsInfo": { "dsid": "1234567890" },
+ "webservices": {}
+ })))
+ .mount(&server)
+ .await;
+ let dir = tempfile::tempdir().unwrap();
+ let mut client = client_for(&server, dir.path());
+ for attempt in 0..2 {
+ let err = client
+ .sign_in("[email protected]", "hunter2")
+ .await
+ .unwrap_err();
+ assert!(
+ matches!(err, quince_auth::Error::TermsPending),
+ "attempt {attempt}: {err:?}"
+ );
+ assert!(err.to_string().contains("icloud.com"), "{err}");
+ }
+ assert!(client.session().webservices.is_none(), "not signed in");
+}
+
+/// The same for a session already kept: said, and kept, rather than signed in again with
+/// the password into the same terms.
+#[tokio::test]
+async fn new_terms_on_a_kept_session_keep_it() {
+ let dir = tempfile::tempdir().unwrap();
+ signed_in(dir.path()).await;
+ let server = MockServer::start().await;
+ Mock::given(method("POST"))
+ .and(path("/setup/ws/1/validate"))
+ .respond_with(ResponseTemplate::new(421))
+ .mount(&server)
+ .await;
+ Mock::given(method("POST"))
+ .and(path("/setup/ws/1/accountLogin"))
+ .respond_with(
+ ResponseTemplate::new(200).set_body_json(json!({ "termsUpdateNeeded": true })),
+ )
+ .mount(&server)
+ .await;
+ let mut client = client_for(&server, dir.path());
+ let err = client.resume().await.unwrap_err();
+ assert!(matches!(err, quince_auth::Error::TermsPending), "{err:?}");
+ assert!(
+ client.session().session_token.is_some(),
+ "the session is kept"
+ );
+ assert_eq!(client.session().password.as_deref(), Some("hunter2"));
+ let reqs = server.received_requests().await.unwrap();
+ assert!(
+ requests_to(&reqs, "/signin/init").is_empty(),
+ "no sign-in into the same terms"
+ );
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 5afe650..85611c2 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -1349,6 +1349,19 @@ async fn keep_signed_in(app: &tauri::AppHandle, client: &Arc<Mutex<Client>>) {
}
}
Ok(true) => TOLD.store(false, std::sync::atomic::Ordering::Relaxed),
+ // New iCloud terms to accept: nothing syncs until they are, and only icloud.com can
+ // take them. Said with its reason, where "Apple signed you out" would be untrue.
+ Err(e @ quince_auth::Error::TermsPending) => {
+ LIVE.store(false, Ordering::SeqCst);
+ app.emit(NEEDS_SIGNIN, e.to_string()).ok();
+ if !TOLD.swap(true, std::sync::atomic::Ordering::Relaxed) {
+ alerts::tell(
+ app,
+ "Accept Apple's new iCloud terms",
+ "Sign in at icloud.com and accept them. Your copy on this computer is still here.",
+ );
+ }
+ }
// Not reaching Apple says nothing about the session.
Err(_) => {}
}
diff --git a/src/App.tsx b/src/App.tsx
index 6a9bdbe..f25fa91 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -101,7 +101,11 @@ export default function App() {
// saying so, and the sign-in a click away rather than forced in its place.
const [lapsed, setLapsed] = useState(false);
useEffect(() => {
- const stop = listen(NEEDS_SIGNIN, () => setLapsed(true));
+ // Its reason, when it has one (new iCloud terms to accept), is what the line says.
+ const stop = listen<string | null>(NEEDS_SIGNIN, (event) => {
+ if (typeof event.payload === "string" && event.payload) setWhy(event.payload);
+ setLapsed(true);
+ });
return () => {
void stop.then((unlisten) => unlisten()).catch(() => {});
};