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
2 changes: 1 addition & 1 deletion docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ Stage 2 and stage 4 of the multi-device roadmap ([#269](https://github.com/sudoH
| iPhone approver | Pairing an iPhone makes it an approver (ADR 0014 as amended by #336); there is no separate switch or code, and removing the pairing on either device ends it. Read requests go to approvers at once while the Mac is locked or its lock state is unknown, otherwise after 20 seconds without a decision or when it locks; the first decision wins; Allow needs Face ID or Touch ID and Deny does not; writes, organize operations and group allowances stay on the Mac. | **Keep** | `Sources/AskKeyDevices/Pairing/PairingSession.swift`<br>`Sources/AskKeyVault/Vault+Devices.swift`<br>`Sources/AskKeyAppKit/Devices/DeviceCoordinator+Approvers.swift`<br>`Sources/AskKeyAppKit/Devices/DeviceCoordinator+RemoteApproval.swift`<br>`Sources/AskKeyAppKit/Devices/DeviceCoordinator+RemoteDecisions.swift`<br>`Sources/AskKeyDevices/Approval/ApprovalRequest.swift`<br>`iOS/AskKeyiOSKit/Approvals/RequestCard.swift` | `Tests/AskKeyDevicesTests/PairingApproverTests.swift`<br>`Tests/AskKeyVaultTests/DeviceApproverFlagTests.swift`<br>`Tests/AskKeyAppTests/RemoteApprovalPairingTests.swift`<br>`Tests/AskKeyAppTests/RemoteApprovalSendingTests.swift`<br>`Tests/AskKeyAppTests/RemoteApprovalDecisionTests.swift`<br>`Tests/AskKeyDevicesTests/ApprovalVectorTests.swift`<br>`iOS/AskKeyiOSKitTests/ApprovalDecisionTests.swift` |
| What leaves the Mac | Until someone chooses **Pair a Device…**, update checks stay the only outbound requests: no identity, no CloudKit request, no push registration. Once the identity exists, until a local erase, the App uses the iCloud account's private CloudKit database and Apple's push service, sending routing data and end-to-end encrypted messages. A remote request carries the requester's name and purpose (not verified), the credential's name, the command line, the working directory, the executable's name, the delivered variable names with a bundle's component names, the deadline, the offers, the Mac App's launch time, a response ID and a binding digest; never a credential value, a component's content, file contents, inherited environment, write payload, the vault key, anything about Hidden credentials or the Mac's name. | **Keep** | `Sources/AskKeyAppKit/App/AppDelegate+Devices.swift`<br>`Sources/AskKeyAppKit/Devices/DeviceCoordinator.swift`<br>`Sources/AskKeyDevices/Approval/ApprovalRequestDisplay.swift`<br>`Sources/AskKeyDevices/CloudKit/CloudKitDeviceTransport.swift`<br>`scripts/build-app.sh` | `Tests/AskKeyAppTests/DeviceCoordinatorDevicesTests.swift`<br>`Tests/AskKeyAppTests/RemoteApprovalSendingTests.swift`<br>`Tests/AskKeyDevicesTests/ApprovalPayloadTests.swift`<br>`Tests/Automation/test_build_app_cloudkit.py` |
| iPhone notifications | The notification extension shows the card sentence (requester, the iPhone's name for the Mac, credential and executable name) only for a request it fetched, decrypted and verified from a Mac the iPhone approves for, and generic text otherwise; never a credential value, arguments, the working directory or variable names. Show Previews decides what the Lock Screen shows, and Notification Center keeps them until removed. Ask Key never asks the person to act on a notification's text. | **Keep** | `iOS/AskKeyiOSNotificationService/Sources/NotificationProcessor.swift`<br>`iOS/AskKeyiOSNotificationService/Sources/NotificationText.swift`<br>`Sources/AskKeyDevices/Approval/DeviceMessageVerifier.swift` | `iOS/AskKeyiOSNotificationService/Tests/NotificationProcessorTests.swift`<br>`iOS/AskKeyiOSNotificationService/Tests/NotificationContentTests.swift` |
| iPhone home | The iPhone app has three tabs: Requests (requests that can still be decided or wait for the Mac, with a badge counting those that can still be decided), History and Macs (the paired Macs, pairing, and this iPhone's iCloud, notification, delivery-check and version status). A finished request moves to History once its open page is closed, or at once if its page was closed; a request arriving while the app is open shows a banner and never opens its page by itself; a page opened from a notification shows a placeholder without content, never the notification's text, until the app has verified the request. Specified in ADR 0014 as amended by #345 and built by #346, #347 and #348, which update this row's files. | **Keep** (planned) | `iOS/AskKeyiOSKit/Views/RootView.swift`<br>`iOS/AskKeyiOSKit/Views/PairedMacsView.swift`<br>`iOS/AskKeyiOSKit/Views/RequestCardView.swift` | `iOS/AskKeyiOSKitTests/ScreenRenderTests.swift` |
| iPhone home | The iPhone app has three tabs: Requests (requests that can still be decided or wait for the Mac, with a badge counting those that can still be decided), History and Macs (the paired Macs, pairing, and this iPhone's iCloud, notification, delivery-check and version status). A finished request moves to History once its open page is closed, or at once if its page was closed; a request arriving while the app is open shows a banner and never opens its page by itself; a page opened from a notification shows a placeholder without content, never the notification's text, until the app has verified the request. Specified in ADR 0014 as amended by #345. #346 built the tabs, the badge, the banners and the foreground banner; #347 and #348 build the request page's outcomes and the opening states and update this row's files. | **Keep** (planned) | `iOS/AskKeyiOSKit/Views/RootView.swift`<br>`iOS/AskKeyiOSKit/Views/RequestsView.swift`<br>`iOS/AskKeyiOSKit/Views/HistoryView.swift`<br>`iOS/AskKeyiOSKit/Views/MacsView.swift`<br>`iOS/AskKeyiOSKit/Views/MacDetailView.swift`<br>`iOS/AskKeyiOSKit/Views/Components.swift`<br>`iOS/AskKeyiOSKit/Views/RequestCardView.swift`<br>`iOS/AskKeyiOSKit/App/AppModel+Macs.swift`<br>`iOS/AskKeyiOSKit/App/AskKeyAppDelegate.swift` | `iOS/AskKeyiOSKitTests/HomeTests.swift`<br>`iOS/AskKeyiOSKitTests/ScreenRenderTests.swift` |
| iPhone history | The iPhone keeps a summary of each request its app verified, for 30 days after the request ends (deleted the next time the app runs after that) and at most 500 entries with the oldest dropped first: the requester, the credential, the executable's name, the iPhone's name for the Mac at the time, the received and ended times and the outcome, plus identifiers and this iPhone's decision; never the command line, the working directory, the delivered names, the purpose or any credential value. The file is encrypted under a this-device-only keychain key, has the request store's data protection, is bound to the iCloud account, excluded from backups and out of the notification extension's reach. Opening it needs no Face ID or Touch ID; **Clear All History** deletes it; removing a Mac keeps its entries until they age out; an account change, sign-out or restriction and an identity reset delete it. It lists only requests this app verified; the Mac's access records stay the complete record. Specified in ADR 0014 as amended by #345; #349 builds it and replaces this row's files. | **Keep** (planned) | `docs/adr/0014-remote-approval.md` | Added by #349 |

## Fixed removals
Expand Down
85 changes: 85 additions & 0 deletions iOS/AskKeyiOSKit/App/AppModel+Macs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,88 @@ extension AppModel {
}
}
}

/// The home's three tabs (ADR 0014 → iPhone app, Home, amended by #345).
public enum HomeTab: Hashable, Sendable, CaseIterable {
/// Requests that can still be decided or wait for the Mac.
case requests
/// Requests this app verified, once they ended (#349).
case history
/// The paired Macs, pairing and this iPhone's own status.
case macs
}

/// What the home shows besides the Macs: the Requests tab's rows and badge,
/// the notification authorization and the last delivery check.
extension AppModel {
// MARK: Home

/// The Requests tab's rows: requests that can still be decided or wait
/// for the Mac. A finished request leaves the tab (decision 7 of #344);
/// its open page keeps showing it until the person closes the page.
public func activeRequests(at now: Date) -> [RequestCard] {
requests.filter { !$0.phase(at: now).isFinished }
}

/// The Requests tab's badge: the requests that can still be decided. A
/// card fetched by name for a tapped notification counts once the zone
/// poll after that fetch showed it can be decided (#337).
public func decidableRequestCount(at now: Date) -> Int {
requests.filter { $0.phase(at: now) == .pending && !$0.isChecking }.count
}

/// When the badge can next change without a new card: each undecided
/// request's countdown end.
public var decidableCountChanges: [Date] {
requests.filter { $0.decision == nil && $0.outcome == nil && !$0.isGone }.map(\.countdownEnd).sorted()
}

/// The Macs whose requests this iPhone accepts.
public var approvingMacCount: Int {
pairedMacs.filter(\.isApprover).count
}

/// Notifications are off for Ask Key, so a request arrives unannounced.
public var notificationsOff: Bool {
notificationAuthorization == .denied
}

/// When this iPhone last answered a delivery check; nil before the first.
public var lastDeliveryCheck: Date? {
deliveryRecords.map(\.arrivedAt).max()
}

/// Keeps the arrivals current: a card that appears after launch reopened
/// the stored requests arrived, whichever tab shows; one that leaves is
/// no longer highlighted.
func noteArrivals(after previous: [RequestCard]) {
let current = Set(requests.map(\.id))
var unseen = unseenArrivals.intersection(current)
if storedRequestsRestored { unseen.formUnion(current.subtracting(previous.map(\.id))) }
if unseen != unseenArrivals { unseenArrivals = unseen }
}

/// The Requests tab showed these rows highlighted for a moment.
public func markArrivalsSeen(_ ids: Set<String>) {
unseenArrivals.subtract(ids)
}

/// The scene became active: read the notification authorization again,
/// since the person may have changed it in Settings, then collect the
/// pushes and process the inbox.
public func sceneBecameActive() async {
await refreshNotificationAuthorization()
await becameActive()
}

func refreshNotificationAuthorization() async {
notificationAuthorization = await environment.notifications.authorization()
}

func readBiometryKind() {
switch environment.biometry.status() {
case .enrolled(let kind), .notEnrolled(let kind), .deniedForApp(let kind): biometryKind = kind
case .passcodeNotSet, .unavailable: break
}
}
}
26 changes: 24 additions & 2 deletions iOS/AskKeyiOSKit/App/AppModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ public final class AppModel {
/// The pairing flow while its sheet is open.
public var pairing: PairingFlowModel?
/// Request cards: pending ones first, by time left, then finished ones.
public internal(set) var requests: [RequestCard] = []
public internal(set) var requests: [RequestCard] = [] {
didSet { noteArrivals(after: oldValue) }
}
/// Requests that arrived after launch reopened the stored ones and whose
/// rows the Requests tab has not shown yet; those rows are highlighted.
public internal(set) var unseenArrivals: Set<String> = []
/// The request whose decision is being built, with its Face ID prompt.
public internal(set) var decidingRequest: String?
public internal(set) var decisionProblems: [String: DecisionProblem] = [:]
Expand All @@ -33,11 +38,22 @@ public final class AppModel {
public internal(set) var opening: OpeningRequest?
/// A newly paired Mac got a numbered name; the person may rename it.
public var renamePrompt: RenamePrompt?
/// The home's tab. A request that arrives never changes it (ADR 0014 →
/// iPhone app, Finished and arriving requests).
public var selectedTab: HomeTab = .requests
/// Whether Ask Key may show notifications, as last read: at launch,
/// after the welcome's prompt and whenever the app becomes active; nil
/// until the first read.
public internal(set) var notificationAuthorization: NotificationAuthorization?
/// Face ID or Touch ID, for the Requests tab's footnote.
public internal(set) var biometryKind: BiometryKind = .faceID

@ObservationIgnored let environment: AppEnvironment
@ObservationIgnored var services: DeviceServices?
@ObservationIgnored var pendingSetup: PendingSetup?
@ObservationIgnored var accountChecked = false
/// The iCloud account was checked since the identity was restored or
/// created; observed, so This iPhone says nothing about iCloud before.
var accountChecked = false
@ObservationIgnored var pushHints: [String: PushHint] = [:]
/// Pushes that arrived before the identity was restored at launch.
@ObservationIgnored var earlyPushes: [EarlyPush] = []
Expand Down Expand Up @@ -83,6 +99,8 @@ public final class AppModel {
@ObservationIgnored var seenPairings: Set<PairingID>?
/// The list as last read, for the Macs' names on the cards.
@ObservationIgnored var knownList: PairedDeviceList?
/// Launch reopened the stored requests; cards that appear from now on arrived.
@ObservationIgnored var storedRequestsRestored = false
@ObservationIgnored private var accountWatch: Task<Void, Never>?
@ObservationIgnored private var started = false

Expand Down Expand Up @@ -140,6 +158,7 @@ public final class AppModel {
let token = environment.localState.inboxPosition?.token.map(InboxChangeToken.init(data:))
await activate(makeServices(identity: identity, transport: transport, inboxToken: token))
await environment.notifications.registerAtLaunch()
await refreshNotificationAuthorization()
}

/// The services with this model as the approver: the handler of
Expand All @@ -163,11 +182,13 @@ public final class AppModel {
// Loaded before anything can suspend, so a request handled while
// the stored ones are opened again is added to them, not lost.
loadApprovals()
readBiometryKind()
adoptEarlyPushes(for: services.deviceID)
stage = .ready
watchAccount()
await refreshList()
await restoreApprovals(services)
storedRequestsRestored = true
}

// MARK: Welcome
Expand Down Expand Up @@ -260,6 +281,7 @@ public final class AppModel {
case .temporarilyUnavailable: return .iCloudUnavailable
}
await environment.notifications.requestAuthorizationAndRegister()
await refreshNotificationAuthorization()
let deviceID = DeviceID(messagePublicKey: setup.identity.messagePublicKey)
if !setup.stored {
do {
Expand Down
12 changes: 10 additions & 2 deletions iOS/AskKeyiOSKit/App/AskKeyAppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ public final class AskKeyAppDelegate: NSObject, UIApplicationDelegate, UNUserNot
}
}

/// A push for the app in front: fetch at once and show no banner.
/// How a notification shows while the app is in front: the system
/// banner, in Notification Center and with its sound, as when the app is
/// not (decision 8 of #344). Whatever the extension could verify, the
/// notification shows as it would in the background.
static let foregroundPresentation: UNNotificationPresentationOptions = [.banner, .list, .sound]

/// A push for the app in front: the banner shows as usual and the
/// app fetches at once. The request's page does not open by itself; the
/// Requests tab's badge and its highlighted row show the new request.
public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
let arrivedAt = notification.date
let identifier = notification.request.identifier
completionHandler([])
completionHandler(Self.foregroundPresentation)
Task { @MainActor in
await model.receivedPush(userInfo: userInfo, arrivedAt: arrivedAt, notificationIdentifier: identifier)
}
Expand Down
Loading
Loading