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: one explicit state model for where a session stands

Yashwanth Kamireddi0a6a5e92e893
diff --git a/crates/quince-auth/src/lib.rs b/crates/quince-auth/src/lib.rs
index 7e96d15..c99d899 100644
--- a/crates/quince-auth/src/lib.rs
+++ b/crates/quince-auth/src/lib.rs
@@ -27,6 +27,7 @@ pub mod releases;
mod sealed;
pub mod session;
pub mod srp;
+pub mod state;
use base64::{engine::general_purpose::STANDARD as B64, Engine};
use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
@@ -489,13 +490,9 @@ pub struct Client {
store: Store,
session: Session,
endpoints: Endpoints,
- /// An Apple ID and password being signed in with, kept only once the sign-in completes.
- pending: Option<(String, String)>,
- /// A lapsed session tried to sign itself back in and Apple wants a code first.
- awaiting_code: bool,
- /// Apple has been asked to send this sign-in's code — to the devices, or by text — so the
- /// code screen opening does not ask for another.
- code_sent: bool,
+ /// A sign-in in flight: its password, kept only once the sign-in completes, and the code
+ /// Apple wants for it (see [`state::SignIn`]).
+ sign: state::SignIn,
/// The keyring would not answer when this started — locked, or not up yet. Not the same
/// as nothing stored: it is asked again before anything else happens.
keyring_error: Option<String>,
@@ -673,9 +670,7 @@ impl Client {
store,
session,
endpoints,
- pending: None,
- awaiting_code: false,
- code_sent: false,
+ sign: state::SignIn::Idle,
keyring_error,
unsaved: None,
persisted: std::sync::Mutex::new(Persisted::default()),
@@ -720,7 +715,7 @@ impl Client {
/// trust this computer again. The code screen is the next thing to show.
#[must_use]
pub fn awaiting_code(&self) -> bool {
- self.awaiting_code
+ self.sign.awaiting_code()
}
pub fn session(&self) -> &Session {
@@ -977,7 +972,7 @@ impl Client {
return Err(e);
}
Ok(SignInOutcome::NeedsTwoFactor) => {
- self.awaiting_code = true;
+ self.sign.wants_code(true);
return Ok(false);
}
// The password was changed elsewhere: the kept one is worthless now.
@@ -1058,11 +1053,10 @@ impl Client {
self.session.retry_after = owed.retry_after;
// Kept only once Apple has accepted it all the way: see `absorb`.
- self.pending = Some((apple_id.trim().to_string(), password.to_string()));
- self.awaiting_code = false;
+ self.sign.start(apple_id, password);
let outcome = self.sign_in_inner(apple_id, password, code).await;
if outcome.is_err() {
- self.pending = None;
+ self.sign.fail();
}
match &outcome {
// Reaching the two-factor step means the password was accepted: not a failure.
@@ -1123,7 +1117,6 @@ impl Client {
self.clear_challenge_state();
// A new web session: its encrypted services' keys are its own to ask for.
self.data_access_forget();
- self.code_sent = false;
let client = srp::Client::new(apple_id);
@@ -1221,6 +1214,7 @@ impl Client {
//
// A sign-in nobody is watching (a lapse mended in the background) asks for
// nothing: the code screen asks once the person opens it ([`Self::request_code`]).
+ self.sign.wants_code(false);
if code == Code::Send {
if let Err(e) = self.resend_to_devices().await {
quiet!("asking Apple to send the code: {e}");
@@ -1303,7 +1297,7 @@ impl Client {
/// this sign-in (the person typed their password a moment ago, or had it texted). A lapse
/// mended in the background left it unasked on purpose — see [`Self::resume`].
pub async fn request_code(&mut self) -> Result<()> {
- if self.code_sent {
+ if self.sign.code_sent() {
return Ok(());
}
self.resend_to_devices().await
@@ -1328,7 +1322,7 @@ impl Client {
let body = r.text().await.unwrap_or_default();
return Err(apple_error("sending the code again", status, &body));
}
- self.code_sent = true;
+ self.sign.sent();
Ok(())
}
@@ -1352,7 +1346,7 @@ impl Client {
let body = r.text().await.unwrap_or_default();
return Err(apple_error("texting the code", status, &body));
}
- self.code_sent = true;
+ self.sign.sent();
Ok(())
}
@@ -1548,9 +1542,9 @@ impl Client {
/// The password for the escrow step after a code: the one just typed, or the one kept.
fn password_for_escrow(&self) -> Option<String> {
- self.pending
- .as_ref()
- .map(|(_, p)| p.clone())
+ self.sign
+ .password()
+ .map(str::to_string)
.or_else(|| self.session.password.clone())
}
@@ -1621,10 +1615,9 @@ impl Client {
fn absorb(&mut self, data: &Value) {
// A completed sign-in — with or without a code — is when a password has proved
// itself, so that is when it is kept.
- if let Some((apple_id, password)) = self.pending.take() {
+ if let Some((apple_id, password)) = self.sign.finish() {
self.session.apple_id = Some(apple_id);
self.session.password = Some(password);
- self.awaiting_code = false;
}
if let Some(ws) = data.get("webservices") {
self.session.webservices = Some(ws.clone());
@@ -1651,12 +1644,6 @@ impl Client {
if let Some(email) = text("/dsInfo/primaryEmail").or_else(|| text("/dsInfo/appleId")) {
self.session.account_email = Some(email);
}
- if let Some(allowed) = data
- .pointer("/dsInfo/isWebAccessAllowed")
- .and_then(Value::as_bool)
- {
- self.session.web_access_allowed = Some(allowed);
- }
if let Some(on) = data
.get("iCDPEnabled")
.or_else(|| data.pointer("/dsInfo/iCDPEnabled"))
@@ -1664,16 +1651,12 @@ impl Client {
{
self.session.data_protection = Some(on);
}
- // Read from every answer that carries them, so agreeing at icloud.com clears them at
- // the next `accountLogin` — the heartbeat's, or Try Again's.
- if let Some(needed) = data.get("termsUpdateNeeded").and_then(Value::as_bool) {
- if needed {
- quiet!("quince: Apple has iCloud terms waiting to be agreed to");
- }
- self.session.terms_update_needed = needed;
- }
- if let Some(needed) = data.get("isRepairNeeded").and_then(Value::as_bool) {
- self.session.repair_needed = needed;
+ // Web access, new terms and the account to finish, from every answer that carries
+ // them, so agreeing at icloud.com clears them at the next `accountLogin` — the
+ // heartbeat's, or Try Again's.
+ self.session.gate.absorb(data);
+ if self.session.gate.standing() == state::Standing::Terms {
+ quiet!("quince: Apple has iCloud terms waiting to be agreed to");
}
}
@@ -1691,7 +1674,13 @@ impl Client {
/// meanwhile, so nothing else is asked.
#[must_use]
pub fn waits_on_icloud_com(&self) -> bool {
- self.session.terms_update_needed || self.session.repair_needed
+ self.standing().at_icloud_com()
+ }
+
+ /// What, if anything, Apple has said holds the account's data back from this session.
+ #[must_use]
+ pub fn standing(&self) -> state::Standing {
+ self.session.gate.standing()
}
/// Query parameters every iCloud service endpoint expects alongside the session cookies.
diff --git a/crates/quince-auth/src/pcs.rs b/crates/quince-auth/src/pcs.rs
index 27b600a..9d32b02 100644
--- a/crates/quince-auth/src/pcs.rs
+++ b/crates/quince-auth/src/pcs.rs
@@ -193,7 +193,7 @@ impl Client {
pub fn data_access_missing(&self) -> Vec<&'static str> {
// Web access off, or terms waiting at icloud.com: no key is released either way (Apple
// answers requestPCS "Missing X-APPLE-WEBAUTH-TOKEN cookie"), so none is asked for.
- if self.session.web_access_allowed == Some(false) || self.waits_on_icloud_com() {
+ if self.session.gate.web_access_allowed() == Some(false) || self.waits_on_icloud_com() {
return Vec::new();
}
self.protected_here()
@@ -309,7 +309,7 @@ impl Client {
/// pass goes by — only the person's own action asks Apple ([`Self::data_access`]).
#[must_use]
pub fn data_access_standing(&self) -> DataAccess {
- if self.session.web_access_allowed == Some(false) {
+ if self.session.gate.web_access_allowed() == Some(false) {
return DataAccess::WebAccessOff;
}
if self.data_access_missing().is_empty() {
@@ -355,7 +355,7 @@ impl Client {
/// `ask` lets this put the approval itself on their devices when none is given; following
/// one already asked for, it is `false`.
pub async fn data_access(&mut self, ask: bool) -> Result<DataAccess> {
- if self.session.web_access_allowed == Some(false) {
+ if self.session.gate.web_access_allowed() == Some(false) {
return Ok(DataAccess::WebAccessOff);
}
let missing: Vec<&'static Protected> = self
@@ -374,7 +374,7 @@ impl Client {
)));
}
if state.flag("isWebAccessAllowed") == Some(false) {
- self.session.web_access_allowed = Some(false);
+ self.session.gate.web_access_off();
self.keep();
return Ok(DataAccess::WebAccessOff);
}
@@ -417,7 +417,7 @@ impl Client {
}
let sent = self.setup_post("enableDeviceConsentForPCS", None).await?;
if sent.flag("isWebAccessAllowed") == Some(false) {
- self.session.web_access_allowed = Some(false);
+ self.session.gate.web_access_off();
self.keep();
return Ok(DataAccess::WebAccessOff);
}
@@ -447,7 +447,7 @@ impl Client {
.and_then(Value::as_str)
.unwrap_or("");
if answer.flag("isWebAccessAllowed") == Some(false) {
- self.session.web_access_allowed = Some(false);
+ self.session.gate.web_access_off();
self.keep();
return Ok(DataAccess::WebAccessOff);
}
diff --git a/crates/quince-auth/src/session.rs b/crates/quince-auth/src/session.rs
index 15ad69b..0874664 100644
--- a/crates/quince-auth/src/session.rs
+++ b/crates/quince-auth/src/session.rs
@@ -104,11 +104,11 @@ pub struct Session {
pub account_name: Option<String>,
#[serde(default)]
pub account_email: Option<String>,
- /// Whether iCloud's data may be reached from the web at all (`dsInfo.isWebAccessAllowed`).
- /// Off on an account with Advanced Data Protection until the person turns on "Access
- /// iCloud Data on the Web" — and then nothing here can be read, whatever else is right.
- #[serde(default)]
- pub web_access_allowed: Option<bool>,
+ /// What Apple has said holds the account's data back from this session: "Access iCloud
+ /// Data on the Web" off, new iCloud terms, or the account to finish at icloud.com (issue
+ /// #5; rclone#9658). Kept under the names those facts have always had.
+ #[serde(flatten)]
+ pub gate: crate::state::Gate,
/// Advanced Data Protection, which Apple calls iCloud Data Protection (`iCDPEnabled`).
#[serde(default)]
pub data_protection: Option<bool>,
@@ -122,15 +122,6 @@ pub struct Session {
/// sign-in's flags say. `None` until Apple has shown either.
#[serde(default)]
pub data_protection_seen: Option<bool>,
- /// Apple has new iCloud terms the person has not agreed to (`termsUpdateNeeded`). Until
- /// they do, `accountLogin` opens only part of a web session — no `X-APPLE-WEBAUTH-TOKEN`
- /// — and every service, Calendar and Contacts too, answers "Missing X-APPLE-WEBAUTH-TOKEN
- /// cookie" or "no auth method found" (issue #5; rclone#9658).
- #[serde(default)]
- pub terms_update_needed: bool,
- /// Apple wants the account finished at icloud.com first (`isRepairNeeded`).
- #[serde(default)]
- pub repair_needed: bool,
/// Failed sign-ins in a row. Drives the local backoff.
#[serde(default)]
diff --git a/crates/quince-auth/src/state.rs b/crates/quince-auth/src/state.rs
new file mode 100644
index 0000000..a5b58a1
--- /dev/null
+++ b/crates/quince-auth/src/state.rs
@@ -0,0 +1,322 @@
+//! Where a session stands, in one place: each fact that decides what the person sees, the
+//! states it can be in, and the only ways it moves between them.
+//!
+//! Two machines, each with its own lifetime:
+//!
+//! * [`SignIn`]: a sign-in in flight this run. The password is held here only until Apple has
+//! accepted it all the way, the code it wants (and whether it has been asked for) with it.
+//! Never written anywhere.
+//! * [`Gate`]: what Apple has said holds the account's data back from this session. Kept
+//! with the session, read again from every answer that carries it.
+//!
+//! Advanced Data Protection's approval has its own explicit states, [`crate::pcs::DataAccess`],
+//! read once the gate is open: nothing is approved while Apple waits at icloud.com.
+
+use serde::{Deserialize, Serialize};
+use serde_json::Value;
+
+/// A sign-in in flight this run.
+///
+/// ```text
+/// start wants_code(lapse)
+/// Idle ───────────────► Proving ─────────────────────► Code { sent, lapse }
+/// ▲ │ │ │ │ ▲ │
+/// │ fail │ │ finish │ │ sent │ │ start
+/// ├──────────────────────┘ │ │ └──────┘ ▼
+/// │ finish ▼ │ Proving
+/// └─────────────────────────┴───────────────────────────┘
+/// ```
+///
+/// `finish` is a completed sign-in: the password proved itself and is handed over to be kept.
+/// `fail` is Apple, or this computer, ending the attempt before that.
+#[derive(Debug, Default, Clone, PartialEq, Eq)]
+pub(crate) enum SignIn {
+ /// No sign-in in flight: signed in, or not, but no password waiting to be kept.
+ #[default]
+ Idle,
+ /// A password is being tried.
+ Proving { apple_id: String, password: String },
+ /// Apple accepted the password and wants a code before it trusts this computer.
+ Code {
+ apple_id: String,
+ password: String,
+ /// Apple has been asked to send it, to the devices or by text, so the code screen
+ /// opening does not ask for another.
+ sent: bool,
+ /// A lapsed session met it signing itself back in, with nobody watching: nothing has
+ /// been asked of Apple, and the window shows the code screen next.
+ lapse: bool,
+ },
+}
+
+impl SignIn {
+ /// A password starts being tried, whatever came before: a new attempt starts clean.
+ pub(crate) fn start(&mut self, apple_id: &str, password: &str) {
+ *self = SignIn::Proving {
+ apple_id: apple_id.trim().to_string(),
+ password: password.to_string(),
+ };
+ }
+
+ /// Apple accepted the password and wants a code. `lapse` when no one is watching.
+ pub(crate) fn wants_code(&mut self, lapse: bool) {
+ *self = match std::mem::take(self) {
+ SignIn::Proving { apple_id, password } => SignIn::Code {
+ apple_id,
+ password,
+ sent: false,
+ lapse,
+ },
+ SignIn::Code {
+ apple_id,
+ password,
+ sent,
+ ..
+ } => SignIn::Code {
+ apple_id,
+ password,
+ sent,
+ lapse,
+ },
+ SignIn::Idle => SignIn::Idle,
+ };
+ }
+
+ /// Apple has been asked to send the code.
+ pub(crate) fn sent(&mut self) {
+ if let SignIn::Code { sent, .. } = self {
+ *sent = true;
+ }
+ }
+
+ /// The attempt ended before Apple accepted it: nothing is kept.
+ pub(crate) fn fail(&mut self) {
+ *self = SignIn::Idle;
+ }
+
+ /// The sign-in completed: the Apple ID and password to keep, if one was in flight.
+ pub(crate) fn finish(&mut self) -> Option<(String, String)> {
+ match std::mem::take(self) {
+ SignIn::Idle => None,
+ SignIn::Proving { apple_id, password }
+ | SignIn::Code {
+ apple_id, password, ..
+ } => Some((apple_id, password)),
+ }
+ }
+
+ /// A lapsed session wants a code before it carries on: the code screen is next.
+ pub(crate) fn awaiting_code(&self) -> bool {
+ matches!(self, SignIn::Code { lapse: true, .. })
+ }
+
+ /// The code this sign-in wants has already been asked for.
+ pub(crate) fn code_sent(&self) -> bool {
+ matches!(self, SignIn::Code { sent: true, .. })
+ }
+
+ /// The password in flight, if any.
+ pub(crate) fn password(&self) -> Option<&str> {
+ match self {
+ SignIn::Idle => None,
+ SignIn::Proving { password, .. } | SignIn::Code { password, .. } => Some(password),
+ }
+ }
+}
+
+/// What holds the account's data back from this session, as Apple last said it. At most one
+/// applies, in this order: each before the next is all the person can act on.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum Standing {
+ /// Nothing Apple has said holds the data back.
+ Open,
+ /// "Access iCloud Data on the Web" is off: nothing can be read until it is on.
+ WebAccessOff,
+ /// New iCloud terms to agree to at icloud.com (`termsUpdateNeeded`). Until then Apple opens
+ /// only part of a web session, and every service fails (issue #5).
+ Terms,
+ /// The account to finish at icloud.com (`isRepairNeeded`).
+ Repair,
+}
+
+impl Standing {
+ /// Waiting on something only icloud.com can do.
+ #[must_use]
+ pub fn at_icloud_com(self) -> bool {
+ matches!(self, Standing::Terms | Standing::Repair)
+ }
+}
+
+/// The facts behind [`Standing`], kept with the session under the names they have always had,
+/// so a session kept by an earlier version reads the same.
+#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
+pub struct Gate {
+ /// `dsInfo.isWebAccessAllowed`; `None` until Apple has said.
+ #[serde(default)]
+ web_access_allowed: Option<bool>,
+ #[serde(default)]
+ terms_update_needed: bool,
+ #[serde(default)]
+ repair_needed: bool,
+}
+
+impl Gate {
+ /// Where the account stands.
+ #[must_use]
+ pub fn standing(&self) -> Standing {
+ if self.web_access_allowed == Some(false) {
+ Standing::WebAccessOff
+ } else if self.terms_update_needed {
+ Standing::Terms
+ } else if self.repair_needed {
+ Standing::Repair
+ } else {
+ Standing::Open
+ }
+ }
+
+ /// Whether web access is allowed, as Apple last said; `None` until it has.
+ #[must_use]
+ pub fn web_access_allowed(&self) -> Option<bool> {
+ self.web_access_allowed
+ }
+
+ #[must_use]
+ pub fn terms_update_needed(&self) -> bool {
+ self.terms_update_needed
+ }
+
+ #[must_use]
+ pub fn repair_needed(&self) -> bool {
+ self.repair_needed
+ }
+
+ /// Read an account answer (`accountLogin`): each fact it carries replaces the one kept, so
+ /// agreeing at icloud.com clears it at the next answer. One it leaves out is left as it was.
+ pub fn absorb(&mut self, data: &Value) {
+ if let Some(allowed) = data
+ .pointer("/dsInfo/isWebAccessAllowed")
+ .and_then(Value::as_bool)
+ {
+ self.web_access_allowed = Some(allowed);
+ }
+ if let Some(needed) = data.get("termsUpdateNeeded").and_then(Value::as_bool) {
+ self.terms_update_needed = needed;
+ }
+ if let Some(needed) = data.get("isRepairNeeded").and_then(Value::as_bool) {
+ self.repair_needed = needed;
+ }
+ }
+
+ /// Apple said, outside an account answer, that web access is off.
+ pub fn web_access_off(&mut self) {
+ self.web_access_allowed = Some(false);
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use serde_json::json;
+
+ fn proving() -> SignIn {
+ let mut s = SignIn::default();
+ s.start(" [email protected] ", "hunter2");
+ s
+ }
+
+ #[test]
+ fn a_sign_in_without_a_code_hands_its_password_over_once() {
+ let mut s = proving();
+ assert_eq!(s.password(), Some("hunter2"));
+ assert!(!s.awaiting_code() && !s.code_sent());
+ assert_eq!(
+ s.finish(),
+ Some(("[email protected]".into(), "hunter2".into()))
+ );
+ assert_eq!(s, SignIn::Idle);
+ assert_eq!(s.finish(), None, "kept once");
+ }
+
+ #[test]
+ fn a_code_is_asked_for_once_and_survives_until_the_sign_in_completes() {
+ let mut s = proving();
+ s.sent();
+ assert!(!s.code_sent(), "nothing to send before Apple wants a code");
+ s.wants_code(false);
+ assert!(!s.code_sent() && !s.awaiting_code());
+ s.sent();
+ assert!(s.code_sent());
+ s.wants_code(false);
+ assert!(s.code_sent(), "asked again, still sent");
+ assert!(s.finish().is_some());
+ assert!(!s.code_sent());
+ }
+
+ #[test]
+ fn a_lapse_that_wants_a_code_shows_the_code_screen_with_nothing_sent() {
+ let mut s = proving();
+ s.wants_code(true);
+ assert!(s.awaiting_code());
+ assert!(
+ !s.code_sent(),
+ "nothing pushed to a phone from the background"
+ );
+ s.sent();
+ assert!(s.awaiting_code() && s.code_sent());
+ // The next attempt starts clean.
+ s.start("[email protected]", "hunter2");
+ assert!(!s.awaiting_code() && !s.code_sent());
+ }
+
+ #[test]
+ fn a_failed_attempt_keeps_nothing() {
+ let mut s = proving();
+ s.wants_code(false);
+ s.fail();
+ assert_eq!(s, SignIn::Idle);
+ assert_eq!(s.password(), None);
+ let mut idle = SignIn::Idle;
+ idle.wants_code(true);
+ assert_eq!(idle, SignIn::Idle, "no code without a password in flight");
+ }
+
+ #[test]
+ fn standing_reads_apple_answers_in_order_and_clears_with_them() {
+ let mut g = Gate::default();
+ assert_eq!(g.standing(), Standing::Open);
+ g.absorb(&json!({ "isRepairNeeded": true }));
+ assert_eq!(g.standing(), Standing::Repair);
+ g.absorb(&json!({ "termsUpdateNeeded": true }));
+ assert_eq!(g.standing(), Standing::Terms, "terms before repair");
+ assert!(g.standing().at_icloud_com());
+ g.absorb(&json!({ "dsInfo": { "isWebAccessAllowed": false } }));
+ assert_eq!(g.standing(), Standing::WebAccessOff, "web access first");
+ assert!(!g.standing().at_icloud_com());
+ // An answer that leaves a fact out leaves it as it was.
+ g.absorb(&json!({ "dsInfo": { "isWebAccessAllowed": true } }));
+ assert_eq!(g.standing(), Standing::Terms);
+ g.absorb(&json!({ "termsUpdateNeeded": false, "isRepairNeeded": false }));
+ assert_eq!(g.standing(), Standing::Open);
+ g.web_access_off();
+ assert_eq!(g.standing(), Standing::WebAccessOff);
+ assert_eq!(g.web_access_allowed(), Some(false));
+ }
+
+ #[test]
+ fn the_gate_keeps_the_names_a_kept_session_has_always_used() {
+ #[derive(Serialize, Deserialize)]
+ struct Holder {
+ #[serde(flatten)]
+ gate: Gate,
+ }
+ let old = r#"{"web_access_allowed":false,"terms_update_needed":true,"repair_needed":true}"#;
+ let read: Holder = serde_json::from_str(old).unwrap();
+ assert_eq!(read.gate.standing(), Standing::WebAccessOff);
+ assert!(read.gate.terms_update_needed() && read.gate.repair_needed());
+ let written = serde_json::to_value(&read).unwrap();
+ assert_eq!(written, serde_json::from_str::<Value>(old).unwrap());
+ let none: Holder = serde_json::from_str("{}").unwrap();
+ assert_eq!(none.gate, Gate::default());
+ }
+}
diff --git a/crates/quince-auth/tests/auth_flow.rs b/crates/quince-auth/tests/auth_flow.rs
index 54c7f1c..2c035dc 100644
--- a/crates/quince-auth/tests/auth_flow.rs
+++ b/crates/quince-auth/tests/auth_flow.rs
@@ -1285,7 +1285,10 @@ async fn new_terms_to_accept_are_said_and_cost_no_wait() {
.await
.unwrap_or_else(|e| panic!("attempt {attempt}: {e:?}"));
assert_eq!(outcome, SignInOutcome::Complete, "attempt {attempt}");
- assert!(client.session().terms_update_needed, "attempt {attempt}");
+ assert!(
+ client.session().gate.terms_update_needed(),
+ "attempt {attempt}"
+ );
assert!(client.waits_on_icloud_com());
assert_eq!(client.session().consecutive_failures, 0, "no wait");
assert!(client.session().retry_after.is_none(), "no wait");
@@ -1314,7 +1317,7 @@ async fn new_terms_on_a_kept_session_keep_it() {
.await;
let mut client = client_for(&server, dir.path());
assert!(client.resume().await.unwrap(), "the session holds");
- assert!(client.session().terms_update_needed);
+ assert!(client.session().gate.terms_update_needed());
assert!(client.waits_on_icloud_com());
assert!(
client.session().session_token.is_some(),
diff --git a/crates/quince-auth/tests/data_protection.rs b/crates/quince-auth/tests/data_protection.rs
index 38af424..ed178dd 100644
--- a/crates/quince-auth/tests/data_protection.rs
+++ b/crates/quince-auth/tests/data_protection.rs
@@ -318,7 +318,7 @@ async fn web_access_turned_off_since_is_read_from_apple() {
client.data_access(true).await.unwrap(),
DataAccess::WebAccessOff
);
- assert_eq!(client.session().web_access_allowed, Some(false));
+ assert_eq!(client.session().gate.web_access_allowed(), Some(false));
assert_eq!(asked(&server, CONSENT).await, 0);
}
diff --git a/crates/quince-auth/tests/icloud_terms.rs b/crates/quince-auth/tests/icloud_terms.rs
index 25c5467..a23f278 100644
--- a/crates/quince-auth/tests/icloud_terms.rs
+++ b/crates/quince-auth/tests/icloud_terms.rs
@@ -103,7 +103,10 @@ async fn new_terms_are_said_waited_on_and_cleared_once_agreed() {
.sign_in("[email protected]", "hunter2")
.await
.unwrap();
- assert!(client.session().terms_update_needed, "Apple's flag is kept");
+ assert!(
+ client.session().gate.terms_update_needed(),
+ "Apple's flag is kept"
+ );
assert!(client.waits_on_icloud_com());
// Advanced Data Protection's keys are not asked for meanwhile: Apple would refuse them.
assert!(client.data_access_missing().is_empty());
@@ -119,7 +122,7 @@ async fn new_terms_are_said_waited_on_and_cleared_once_agreed() {
// Agreed at icloud.com, then Try Again.
client.refresh_account().await.unwrap();
assert!(
- !client.session().terms_update_needed,
+ !client.session().gate.terms_update_needed(),
"cleared by the next accountLogin"
);
assert!(!client.waits_on_icloud_com());
@@ -129,11 +132,10 @@ async fn new_terms_are_said_waited_on_and_cleared_once_agreed() {
);
// And remembered across a restart either way.
drop(client);
- assert!(
- !client_for(&server, dir.path())
- .session()
- .terms_update_needed
- );
+ assert!(!client_for(&server, dir.path())
+ .session()
+ .gate
+ .terms_update_needed());
// Diagnostics: places, statuses, flags and cookie names — no value, token, name or address.
let lines = LINES.lock().unwrap().join("\n");
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index c6f7a3d..3b4073f 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -129,10 +129,10 @@ impl SessionFacts {
.unwrap_or_default(),
name: s.account_name.clone(),
email: s.account_email.clone().or_else(|| s.apple_id.clone()),
- web_access_allowed: s.web_access_allowed,
+ web_access_allowed: s.gate.web_access_allowed(),
data_protection: s.data_protection,
- terms_update_needed: s.terms_update_needed,
- repair_needed: s.repair_needed,
+ terms_update_needed: s.gate.terms_update_needed(),
+ repair_needed: s.gate.repair_needed(),
unsaved: client.unsaved().is_some(),
}
}
@@ -1380,7 +1380,7 @@ async fn keep_signed_in(app: &tauri::AppHandle, client: &Arc<Mutex<Client>>) {
// The window shows its own page for it; the desktop is told once, for someone
// with only the tray running. Never "Apple signed you out": it did not.
if !TOLD_ICLOUD.swap(true, std::sync::atomic::Ordering::Relaxed) {
- let (title, body) = if guard.session().terms_update_needed {
+ let (title, body) = if guard.standing() == quince_auth::state::Standing::Terms {
(
"Agree to Apple's new iCloud terms",
"Sign in at icloud.com and agree to them. Your copy on this computer is still here.",