Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apple/changelog.d/4774.fixed.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A Mac recovered with the recovery key could stay locked if TablePro quit partway through the recovery.
1 change: 1 addition & 0 deletions apple/changelog.d/4774.fixed.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A team key a teammate shared under their new key waited for the team's next change after you accepted that key.
1 change: 1 addition & 0 deletions apple/changelog.d/4774.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
After removing a device, a Mac that could not finish a team key change synced again and again without waiting.
1 change: 1 addition & 0 deletions apple/changelog.d/4774.security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removing a lost device could still give a member you marked the next team key after a recovery key change or Sign Out.
4 changes: 4 additions & 0 deletions core/crates/sync/src/api/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,9 @@ pub struct KeyComparisonRow {
pub enum PendingFlow {
// The team rotations an account rotation to this `av` still has to write, with its review's choices.
AccountRotation { av: Version },
// What such a rotation still owed its teams when Sign Out or a takeover erased the keys it was written with: the
// review's marks and the teams the account held then, for the next device approved on this file (0100).
OwedTeamSteps { av: Version },
Approval { request: RequestId },
ResetProposal { reset: ResetId },
// A stop report to withdraw, sent again after a restart until the server answers.
Expand All @@ -766,6 +769,7 @@ impl PendingFlow {
pub fn key_text(self) -> String {
match self {
Self::AccountRotation { av } => format!("rotation/{av}"),
Self::OwedTeamSteps { av } => format!("owed/{av}"),
Self::Approval { request } => format!("approval/{}", request.to_wire()),
Self::ResetProposal { reset } => format!("reset/{}", reset.to_wire()),
Self::StopWithdrawal { team } => format!("withdraw/{}", team.to_wire()),
Expand Down
6 changes: 4 additions & 2 deletions core/crates/sync/src/keys/account_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ impl KeyService {
.await?;
}
// Written with the candidates, so the team steps still run when the device stops after the push applies. It
// names the replace's certificate, so a rotation another device won at `av` is never taken for it.
// names the replace's certificate, so a rotation another device won at `av` is never taken for it, and carries
// the members an earlier removal marked, whose flow ends once this one applies (0100).
let state = self.replace_flow_state(txn.as_mut(), &built.objects).await?;
txn.put(Row::KeyPending(KeyPendingRow {
flow: PendingFlow::AccountRotation { av },
state: super::rotation::flow_state(&built.objects),
state,
}))
.await?;
// What the push changes is not known until a pull after it catches up.
Expand Down
20 changes: 18 additions & 2 deletions core/crates/sync/src/keys/account_sign_out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use super::account::SigningOut;
use crate::api::device_store::{DeviceItem, DeviceStoreError};
use crate::api::error::SyncError;
use crate::api::key_flows::SignOutOutcome;
use crate::api::state::{PendingFlow, Row, RowRange, ScopeRow, Table};
use crate::api::state::{KeyPendingRow, PendingFlow, Row, RowRange, ScopeRow, Table};
use crate::api::transport::{DpopKey, TransportError};

impl KeyService {
Expand Down Expand Up @@ -169,19 +169,35 @@ impl KeyService {
Ok(())
}

// Team steps a Sign Out kept name no key.
async fn holds_key_state(&self) -> Result<bool, SyncError> {
let mut txn = self.begin().await?;
for table in Table::KEY {
if !txn.scan(&RowRange::Table(table)).await?.is_empty() {
let held = txn.scan(&RowRange::Table(table)).await?.into_iter().any(|row| {
!matches!(
row,
Row::KeyPending(KeyPendingRow {
flow: PendingFlow::OwedTeamSteps { .. },
..
})
)
});
if held {
return Ok(true);
}
}
Ok(false)
}

// What the account's rotations still owe their teams outlives the keys: the members a removal marked and the
// teams the account held, which the next device approved on this file rotates (0100). Nothing else of a flow stays.
async fn clear_key_state(&self) -> Result<(), SyncError> {
let mut txn = self.begin().await?;
let owed = self.owed_team_steps(txn.as_mut()).await?;
txn.clear_key_tables().await?;
for row in owed {
txn.put(Row::KeyPending(row)).await?;
}
// The device joins again as a new one does, so the next pull of every scope, a team's included, starts from
// a snapshot that serves the key objects the tables no longer hold.
for row in txn.scan(&RowRange::Table(Table::Scopes)).await? {
Expand Down
4 changes: 2 additions & 2 deletions core/crates/sync/src/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl KeyService {
// The teams take the wraps their pulls kept while the rebuild took none, in the commit that ends it.
let mut judged = Vec::new();
for team in key_teams(txn.as_mut()).await? {
judged.push(self.judge_rebuilt_team(txn.as_mut(), team).await?);
judged.push(self.judge_team(txn.as_mut(), team).await?);
}
// The anchor stops owing the rebuild only once this commit lands, so a restart before it rebuilds again.
txn.settle_keys(KeysSettled::Rebuilt);
Expand Down Expand Up @@ -667,7 +667,7 @@ impl Rosters {
}

// Every team the key tables hold a version row or a key object of.
async fn key_teams(txn: &mut dyn StateTxn) -> Result<Vec<TeamId>, SyncError> {
pub(crate) async fn key_teams(txn: &mut dyn StateTxn) -> Result<Vec<TeamId>, SyncError> {
let mut teams = Vec::new();
for table in [Table::KeyVersions, Table::KeyObjects] {
for row in txn.scan(&RowRange::Table(table)).await? {
Expand Down
12 changes: 12 additions & 0 deletions core/crates/sync/src/keys/pins_alerts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,19 @@ impl KeyService {
replaced,
}))
.await?;
// What the account signed under the accepted IK waited for this, a restart of a team included: each team is
// judged again in the same commit, not only once its next object arrives. A stale file judges its teams when
// its rebuild ends.
let mut judged = Vec::new();
if !self.is_rebuilding() {
for team in super::key_teams(txn.as_mut()).await? {
judged.push(self.judge_team(txn.as_mut(), team).await?);
}
}
txn.commit().await?;
for judged in &judged {
self.tell_judged(judged).await?;
}
for notice in self.held_notices() {
if notice.kind == (KeyNoticeKind::KeysChanged { account }) {
self.dismiss(notice.id);
Expand Down
Loading
Loading