Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / apple / Passwords / README.md
| 1 | # EverySync Passwords — Apple shell (Phase 3a) |
| 2 | |
| 3 | SwiftUI shell. **All merge / transport / crypto lives in the shared |
| 4 | XCFramework** (`everysync-core` KMP); this target renders UI, talks Keychain, |
| 5 | hosts the Credential Provider extension, and schedules background sync. Zero |
| 6 | sync logic in Swift. |
| 7 | |
| 8 | ## Architecture |
| 9 | |
| 10 | ``` |
| 11 | PasswordsApp (SwiftUI) ──► EverysyncCore.xcframework ──► relay |
| 12 | │ │ |
| 13 | │ UI state only │ merge / TOTP / PQC / |
| 14 | │ │ transport / cursors |
| 15 | ▼ ▼ |
| 16 | Keychain (SecureStore) App-Group envelope IPC |
| 17 | BGTaskScheduler periodic (see ../IPC_CONTRACT.md) |
| 18 | ASCredentialProvider ext. |
| 19 | ``` |
| 20 | |
| 21 | ## KMP entry points this shell will call (nothing else) |
| 22 | |
| 23 | | Kotlin FQN | Used for | |
| 24 | |---|---| |
| 25 | | `core.data.RemotePassword` | Envelope JSON on `passwords:<vaultId>` (see `recordChannel`) | |
| 26 | | `core.passwords.mergeCredentials` / `passkeysFor` | List + detail pairing. Explicit `PasskeyLink` wins both directions; auto-match needs domain AND username agreement on exactly one candidate; ties stay standalone. Deterministic order `(creationTime, syncId)`. Swift never re-implements this. | |
| 27 | | `core.passwords.Totp.generate(secret, epochSecond)` | 6-digit codes. Base32 RFC 4648 (padding stripped, unknown chars ignored), 30 s step, big-endian counter, dynamic truncation. HMAC-SHA1 actual is `HmacIos` (CryptoKit `HMAC<Insecure.SHA1>`). Swift only passes `Date().epochSeconds`. | |
| 28 | | `core.passwords.DomainMatch` / `PasskeyLink` | Autofill candidate matching + explicit link/detach. | |
| 29 | | `core.sync.adapters.PasswordKind` | `syncId=uid`, LWW on `updatedAt`, `contentHash = relayContentHash(canonical + "\0deleted=…")`, `contentKey` password `name␀username` / passkey `rpId␀credentialId`. Only explicit `deleted=true` envelopes are deletes (`isTombstoneEnvelope`). | |
| 30 | | `core.provider.SyncDriver` + `core.platform.RelayCursorStore` | Sync cycles; cursor keys `relay_cursor:<type>:<vault>:<channel>`. | |
| 31 | | `core.network.IosRelayTransport` | Ktor-Darwin + trust pinning (lands Phase 3; stub today). Envelopes: `Base64(AES_GCM)` per item; invites PQC-sealed to `inbox:<deviceId>`. | |
| 32 | | `core.network.RelayRoles` | Passwords vaults offer **EDITOR only — never VIEWER** (read-only passwords still disclose every secret). | |
| 33 | | `core.network.RelayLinks` | `everysync://join/<vault>?owner=…&type=…` + `https://maproj.org/es/share#id=…&owner=…&type=…`. | |
| 34 | | PQC cinterop (`IOS_PQC_NOTES.md`) | Exactly 10 fns: `pqc_kem_keygen/encaps/decaps`, `pqc_dsa_keygen/sign/verify`, `pqc_bundle_build/split`, `pqc_free/secure_zero` via `e2eePqc.def`. Never `identity_keygen`, `link_*`, `security_code`. | |
| 35 | |
| 36 | ## Delete semantics — HARD delete |
| 37 | |
| 38 | Passwords hard-delete: rows vanish locally; only the app-side snapshot |
| 39 | remembers them. `PasswordKind.localDeletesAreAuthoritative == false`, so a |
| 40 | healthy-read absence IS a genuine local delete. `SyncSink.delete` removes the |
| 41 | row; merge-driven deletes always arrive as tombstone envelopes, never raw |
| 42 | deletes. See `../IPC_CONTRACT.md`. |
| 43 | |
| 44 | ## Credential Provider extension |
| 45 | |
| 46 | `ASCredentialProviderViewController` subclass (see `PasswordsApp.swift`) links |
| 47 | the same XCFramework and calls `DomainMatch` — no Swift matching logic. It |
| 48 | reads via XPC from the containing app (App-Group container + |
| 49 | `NSFileCoordinator`; the extension never touches the relay directly). |
| 50 | |
| 51 | ## Keychain SecureStore |
| 52 | |
| 53 | KMP `SecureStore` actual = Keychain `kSecClassGenericPassword`. |
| 54 | Keychain group shared with the Credential Provider extension; vault AES keys |
| 55 | never user-visible (share links carry ids only; keys move via PQC-sealed |
| 56 | inbox invites). |
| 57 | |
| 58 | ## BGTaskScheduler |
| 59 | |
| 60 | `BGAppRefreshTaskRequest(identifier: "com.vayunmathur.everysync.passwords.refresh")` |
| 61 | periodic pull → hands records to `SyncDriver`; one-shot |
| 62 | `BGProcessingTaskRequest` after local edits. Scheduling only — the cycle runs |
| 63 | in the XCFramework. |
| 64 | |
| 65 | ## Info.plist / entitlements notes |
| 66 | |
| 67 | - `NSFaceIDUsageDescription` — vault unlock (no password material leaves Keychain). |
| 68 | - `com.apple.security.application-groups`: `group.<team>.everysync.shared` (envelope IPC). |
| 69 | - `keychain-access-groups`: `$(AppIdentifierPrefix)com.vayunmathur.everysync.passwords(.autofill)`. |
| 70 | - `com.apple.developer.authentication-services.autofill-credential-provider` = YES (extension target). |
| 71 | |
| 72 | ## Swift must NOT |
| 73 | |
| 74 | Re-implement merge pairing, TOTP framing/math, canonical JSON/hash, envelope |
| 75 | Base64/AES, role checks, or link parsing. If logic exists in Swift that also |
| 76 | exists in `everysync-core`, delete the Swift copy. |
| 77 | |
| 78 | ## Files (Phase 3) |
| 79 | |
| 80 | | File | Role | |
| 81 | |---|---| |
| 82 | | `PasswordsApp.swift` | SwiftUI entry + vault list/detail contract; zero sync logic | |
| 83 | | `CredentialProvider.swift` | `ASCredentialProviderViewController`; reads over XPC, ranks via `DomainMatch` | |
| 84 | | `PasswordsXPCService.swift` | `com.vayunmathur.everysync.envelope-ipc` — exactly the 3 IPC ops | |
| 85 | | `Info.plist.reference` | Face ID string, BGTask id, `everysync://join` scheme | |
| 86 | | `Passwords.entitlements.reference` | App Group + shared Keychain group | |
| 87 | | `CredentialProvider.entitlements.reference` | Autofill entitlement (extension target only) | |
| 88 | | `../Shared/EnvelopeIPC.swift` | SQLite IPC store (shared with Notes/Hub) | |
| 89 | | `../Shared/BlobStore.swift` | Blob sidecar (shared) | |
| 90 | | `../Shared/KeychainSecureStore.swift` | Keychain layout contract (Kotlin implements) | |
| 91 | | `../Shared/EverysyncCoreCrypto.swift` | CryptoKit AES-GCM C bridge (fills the Rust AES gap) | |
| 92 | | `../Shared/BackgroundSync.swift` | BGTask registration helpers | |