Report keychain failures during AppKeychain and SharedKeychain access#25702
Report keychain failures during AppKeychain and SharedKeychain access#25702crazytonyli wants to merge 1 commit into
Conversation
Generated by 🚫 Danger |
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 32829 | |
| Version | PR #25702 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | c29ac79 | |
| Installation URL | 20kfs2sfc7ft8 |
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 32829 | |
| Version | PR #25702 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | c29ac79 | |
| Installation URL | 2v949hp4t80sg |
Both keychain wrappers now route every read, write, and delete failure through a shared reporter. The expected not-found stays silent, other real failures are logged via swift-log together with the failing call site, and an entitlement mismatch crashes because it means the access group is unreachable for the entire build rather than a recoverable runtime condition. This adds a swift-log dependency to the WordPressShared target.
f8900b9 to
c29ac79
Compare
| return nsError.domain == sfhfKeychainErrorDomain | ||
| && nsError.code != Int(errSecItemNotFound) | ||
| guard nsError.domain == sfhfKeychainErrorDomain else { return nil } | ||
| return OSStatus(nsError.code) |
There was a problem hiding this comment.
Keychain shouldn't return anything outside of Int32, but we can be extra careful:
| return OSStatus(nsError.code) | |
| return OSStatus(truncatingIfNeeded: nsError.code) |
jkmassel
left a comment
There was a problem hiding this comment.
This looks generally correct, though I wonder if we can collapse a bunch of the repeated do/catch statements?
| return code != errSecItemNotFound | ||
| } | ||
|
|
||
| private let keychainLogger = Logger(label: (Bundle.main.bundleIdentifier ?? "org.wordpress") + ".keychain") |
There was a problem hiding this comment.
| private let keychainLogger = Logger(label: (Bundle.main.bundleIdentifier ?? "org.wordpress") + ".keychain") | |
| private let keychainLogger = Logger(label: (Bundle.main.bundleIdentifier!) + ".keychain") |
I'm pretty comfortable crashing if we don't have a bundle identifier set – something has gone very wrong in this case.


Both keychain wrappers now route every read, write, and delete failure through a shared reporter. The expected not-found stays silent, other real failures are logged via swift-log together with the failing call site, and an entitlement mismatch crashes because it means the access group is unreachable for the entire build rather than a recoverable runtime condition. This adds a swift-log dependency to the WordPressShared target.