fix(keychain): remove destructive migration + Apple-correct API refactor#972
Merged
fix(keychain): remove destructive migration + Apple-correct API refactor#972
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two stacked commits on the keychain layer:
1. Bug fix — saved connection passwords no longer disappear on app restart.
Root cause: the legacy-keychain migration ran on every launch, found items written through the Data Protection keychain (because on sandboxed configs the legacy query returns those too), copied them to itself, then deleted the only copy via
SecItemDelete. Trace fromlog stream subsystem == \"com.TablePro\" category == \"KeychainHelper\": launch 1 writes succeed; launch 2 logsSuccessfully migrated, deletes the entry, and the next form load returnserrSecItemNotFound (-25300). RemovedmigrateFromLegacyKeychainIfNeededandmigratePasswordSyncStateplus their callers inAppDelegateandSyncSection. Also removed themigrationKeyUserDefaults flag and themigrationLockNSLock.2. Refactor —
KeychainHelperAPI consolidated and tightened to match Apple's documented contracts.kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly. Excludes them from unencrypted device backups (Apple-recommended pairing). Syncing items keepkSecAttrAccessibleAfterFirstUnlockbecause iCloud Keychain requires non-ThisDeviceOnlyaccessibility. Existing items keep their original class until next save.write(_:forKey:)/writeString(_:forKey:)/read(forKey:)/readString(forKey:)/readStringResult(forKey:)/delete(forKey:). All argument labels are nowforKey:.KeychainResultandKeychainStringResultenums with.found/.notFound/.lockedcases. Surfaces the keychain-locked state to all callers instead of silently returning nil.ConnectionStorage,SSHProfileStorage,AIKeyStorage,LicenseStorage) updated. Each one now logs the locked case via OSLog with a contextual identifier (connection ID, profile ID, provider ID) instead of swallowing the failure.KeychainHelperis nowSendable. Failure logging routes throughSecCopyErrorMessageStringfor human-readable diagnostics instead of bareOSStatusnumbers.Settings > Sync > Passwordsadds a one-line caption explaining the toggle only affects new saves; existing passwords keep their current sync state until re-saved (matches Apple's documentedkSecAttrSynchronizablesemantics).PluginDiagnosticItem.classifymarked@MainActor(it calls a@MainActor-isolated method onPluginManager.shared; only call site is already insideawait MainActor.run { ... }).Test plan
log stream --predicate 'subsystem == \"com.TablePro\" AND category == \"KeychainHelper\"'during the above. Confirm: nomigrate*log lines (functions removed), noKeychain write/read/delete failederrors during normal operation.Settings > Sync > PasswordsON, save a new connection password, verify the new item haskSecAttrSynchronizable: true(via Keychain Access). Toggle OFF, save another, verify new item is non-synchronizable. Existing items retain their original sync state. Caption is visible under the toggle.Keychain lockedwarning with the connection ID, and the form shows an empty password field rather than a misleading "saved successfully" state.swiftlint lint --strict TablePro/Core/Storage/KeychainHelper.swift TablePro/Core/Storage/ConnectionStorage.swift TablePro/Core/Storage/SSHProfileStorage.swift TablePro/Core/Storage/AIKeyStorage.swift TablePro/Core/Storage/LicenseStorage.swift TablePro/Views/Settings/Sections/SyncSection.swift TablePro/Views/Connection/PluginDiagnosticSheet.swift— 0 violations.KeychainHelperTestsandKeychainAccessControlTestspass.