Skip to content

Report keychain failures during AppKeychain and SharedKeychain access#25702

Open
crazytonyli wants to merge 1 commit into
trunkfrom
task/keychain-error-handling
Open

Report keychain failures during AppKeychain and SharedKeychain access#25702
crazytonyli wants to merge 1 commit into
trunkfrom
task/keychain-error-handling

Conversation

@crazytonyli

Copy link
Copy Markdown
Contributor

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.

@crazytonyli crazytonyli added this to the 27.1 milestone Jun 25, 2026
@crazytonyli crazytonyli requested a review from jkmassel June 25, 2026 04:05
@dangermattic

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ Modules/Package.swift was changed without updating its corresponding Package.resolved.

If the change includes adding, removing, or editing a dependency please resolve the Swift packages as appropriate to your project setup (e.g. in Xcode or by running swift package resolve).

If the change to the Package.swift did not modify dependencies, ignoring this warning should be safe, but we recommend double checking and running the package resolution just in case.
.

Generated by 🚫 Danger

@wpmobilebot

wpmobilebot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number32829
VersionPR #25702
Bundle IDorg.wordpress.alpha
Commitc29ac79
Installation URL20kfs2sfc7ft8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number32829
VersionPR #25702
Bundle IDcom.jetpack.alpha
Commitc29ac79
Installation URL2v949hp4t80sg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

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.
@crazytonyli crazytonyli force-pushed the task/keychain-error-handling branch from f8900b9 to c29ac79 Compare June 25, 2026 05:45
return nsError.domain == sfhfKeychainErrorDomain
&& nsError.code != Int(errSecItemNotFound)
guard nsError.domain == sfhfKeychainErrorDomain else { return nil }
return OSStatus(nsError.code)

@jkmassel jkmassel Jun 25, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keychain shouldn't return anything outside of Int32, but we can be extra careful:

Suggested change
return OSStatus(nsError.code)
return OSStatus(truncatingIfNeeded: nsError.code)

@jkmassel jkmassel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants