SwiftArkTSStorageGoodCRM

Decrypting a Backup Is the Easy Part: Restore Boundaries in GoodCRM

GoodCRM 1.0 just shipped on the US App Store for iPhone, iPad, and Mac, with HarmonyOS in preparation. With no developer CRM servers, the only cross-ecosystem exit path is the .gcrmbak encrypted backup. A pre-launch audit caught the subtle state-corruption bugs hiding between decryption and switching live databases.

GoodCRM (1.0) is now live on the US App Store for iPhone, iPad, and Mac, with a native HarmonyOS app for phones and tablets in preparation. From day one, there are no developer-operated CRM servers: Apple uses local SQLite and HarmonyOS uses RelationalStore, with optional private sync strictly isolated to the user’s own CloudKit Private Database or Huawei Cloud.

Because the two platforms never share a backend, the .gcrmbak (GCRMBAK1) encrypted backup is the sole cross-platform migration path and the user’s data-exit guarantee.

Getting AES-256-GCM encryption and decryption right across Swift and ArkTS wasn’t the hard part. During the November 25 deep review on 7db1048 (docs/architecture/DEEP_REVIEW_REMEDIATION.md), the bugs that could actually corrupt or lose a customer database were all sitting in the ordering between decrypting a backup, detaching cloud sync, and rolling back a failed switch.

A Neutral Container Format Across Swift and ArkTS

Apple’s CryptoKit makes AES.GCM.seal(...).combined effortless, but SealedBox.combined isn’t a portable wire format for HarmonyOS, and loading a large attachment-heavy backup into RAM on a phone blows past memory budgets.

BackupContainer4.swift on Apple and Backup1Container.ts on HarmonyOS share an identical layout:

  • Magic prefix GCRMBAK1 followed by a canonical 9-key JSON header (<= 64 KiB) locking format, kdf, iterations, salt_base64, nonce_prefix_base64, chunk_size, chunk_count, plaintext_total_bytes, and manifest_sha256.
  • PBKDF2-HMAC-SHA256 at 600,000 iterations (with fresh random salt and nonce prefix on every product write).
  • Chunked AES-256-GCM payloads wrapping an inner GCRMPAY1 manifest whose per-member SHA-256 hashes are verified before any data is exposed.
  • Preview without switching (switchesLibrary = false): BackupContainer4.preview() authenticates every chunk and lets the user inspect counts and paths before touching the live store, reading member ranges lazily from an unlinked temporary scratch file and wiping sensitive byte buffers with memset_s.

Seven Places Restore and Export Could Leave a Dirty Store (R01–R09)

Once cross-platform decryption passed synthetic vectors, the audit (R01–R09) uncovered ordering gaps around failures and interruptions:

  1. Switching libraries before recording sync detachment (R02): On Apple (WorkspaceModel.swift), swapping in the restored library before persisting sync detachment meant a crash in between would reconnect the restored database to the live CloudKit space on relaunch.
  2. Rollback restoring only the business SQLite (R03): LibraryBackup4.swift replaces the business SQLite, capture queue database, and attachment files together, yet rollback previously restored only the business SQLite, leaving orphaned capture rows and mismatched file hashes.
  3. Readable ZIP export truncating targets before validation (R04): ReadableExport4.swift could overwrite a user’s existing file before validation succeeded, destroying the prior export on failure. Replacement now publishes only after full verification.
  4. HarmonyOS adopting cloud state before persisting its protection snapshot (R05): Model4LocalService.ts overwrote local state before ensuring the rollback snapshot was written and verified.
  5. Mutating Preferences drafts before SQL commit (R07): On HarmonyOS, updating Preferences prior to committing the SQLite transaction meant an SQL rollback left draft state stranded out of sync.
  6. Silent 64 MiB protection snapshot drops (R08): SnapshotStore4.ts allowed protection snapshots larger than 64 MiB to be written, then silently dropped them on restart read — easily triggered by two 25 MiB capture attachments. If protection cannot be guaranteed, GoodCRM now refuses to overwrite the live store and surfaces an explicit error.
  7. Account-switch sync carryover (R01): Switching Apple accounts A -> B in AppleSyncTransports4.swift could reuse A’s sync binding and pending upload queue across an in-flight sync round.

The cross-check (R09) also caught a case where an Apple database restored from backup and re-exported failed initialization-proof validation on HarmonyOS (LibraryBackup1.ts), now covered by cross-platform round-trip tests.

Verification Scope

These R01–R09 fixes are backed by host and fault-injection suites: 586 Apple host tests (including HarmonyOS synthetic backup interop, with 1 optional legacy vector skipped), 936 HarmonyOS host tests, and 183 Python tooling tests. Physical tablet hardware and live multi-account CloudKit/Huawei Cloud switching remain tracked separately on the hardware release checklist rather than being claimed from host runs.

✦

Comments

  • Loading…

Comments are reviewed before publishing; email is visible only to me.