dpearson2699/swift-security
Use when working with iOS/macOS Keychain Services (SecItem queries, kSecClass, OSStatus errors), biometric authentication (LAContext, Face ID, Touch ID), CryptoKit (AES-GCM, ChaChaPoly, ECDSA, ECDH, HPKE, ML-KEM), Secure Enclave, secure credential storage (OAuth tokens, API keys), certificate pinning (SecTrust, SPKI), keychain sharing across apps/extensions, migrating secrets from UserDefaults or plists, or OWASP MASVS/MASTG mobile compliance on Apple platforms.
npx skills add https://github.com/dpearson2699/swift-ios-skills --skill swift-security
Use this skill for client-side Apple platform security work: Keychain Services,
access control, biometric-gated secrets, CryptoKit, Secure Enclave keys,
credential storage, certificate trust, keychain sharing, legacy secret
migration, security testing, and OWASP mobile compliance mapping.
Default to iOS 17+ and Swift concurrency examples when the deployment target is
unknown. Keep iOS 13+ compatibility notes when the user asks for older targets.
Treat iOS 26 CryptoKit post-quantum APIs as availability-gated.
Classify the request before loading references.
load common-anti-patterns.md plus the
domain reference for each failing area. Report severity, evidence, and the
corrected pattern.
and target-domain references, preserve existing data, verify the new item,
then remove legacy storage only after success.
provided correct patterns, include OSStatus handling and tests, then run the
relevant checklist.
Do not load every reference file by default. This skill is intentionally split
for progressive disclosure; load only the files needed by the user's task.
Use separate add, identity, and update dictionaries; handle every OSStatus:
func saveSecret(_ data: Data, account: String) throws {
let identity: [CFString: Any] = [
kSecClass: kSecClassGenericPassword,
kSecAttrService: "com.example.app",
kSecAttrAccount: account,
]
var add = identity
add[kSecValueData] = data
add[kSecAttrAccessible] = kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
switch SecItemAdd(add as CFDictionary, nil) {
case errSecSuccess:
return
case errSecDuplicateItem:
let status = SecItemUpdate(
identity as CFDictionary,
[kSecValueData: data] as CFDictionary
)
guard status == errSecSuccess else { throw KeychainError(status: status) }
case let status:
throw KeychainError(status: status)
}
}
Load keychain-fundamentals.md for read,
delete, access-control, locked-device, and test patterns.
| If the task involves | Load |
| --- | --- |
| General keychain CRUD or OSStatus handling | keychain-fundamentals.md |
| Choosing kSecClass or item identity | keychain-item-classes.md |
| Accessibility classes or SecAccessControl | keychain-access-control.md |
| Face ID, Touch ID, or biometric-gated secrets | biometric-authentication.md |
| Secure Enclave keys | secure-enclave.md |
| Hashing, HMAC, AES-GCM, ChaChaPoly, HKDF, PBKDF2 | cryptokit-symmetric.md |
| Signing, ECDH, HPKE, ML-KEM, ML-DSA | cryptokit-public-key.md |
| OAuth tokens, API keys, logout, refresh rotation | credential-storage-patterns.md |
| App/extension keychain sharing | keychain-sharing.md |
| Certificate trust, SPKI pinning, mTLS | certificate-trust.md |
| UserDefaults/plist/NSCoding migration | migration-legacy-stores.md |
| Unit, integration, simulator, device, or CI tests | testing-security-code.md |
| OWASP MASVS/MASTG or enterprise audit mapping | compliance-owasp-mapping.md |
| Full security review | common-anti-patterns.md, then each touched domain reference |
Use directive language only for these security invariants and the matching
anti-patterns in common-anti-patterns.md.
For architecture choices outside this list, use advisory language.
UserDefaults, Info.plist, .xcconfig, source code, logs, files, or
NSCoding archives. Use Keychain or fetch secrets at runtime.
OSStatus. Every SecItemAdd, SecItemCopyMatching,SecItemUpdate, and SecItemDelete path must handle success and expected
failures such as errSecDuplicateItem, errSecItemNotFound, and
errSecInteractionNotAllowed.
LAContext.evaluatePolicy() as the only gate for a secret. Bindprotected secrets to keychain items with SecAccessControl, then let
keychain access trigger LocalAuthentication.
kSecAttrAccessible or kSecAttrAccessControl explicitly whenadding keychain items.
as a normal update path.
SecItem* work off the main actor. Use an actor or serial queue forkeychain access.
kSecUseDataProtectionKeychain: true unless deliberately working with
legacy file-based keychain items.
SharedSecret bytes as a symmetric key. Derive with HKDFor X9.63 derivation.
Insecure.MD5 or Insecure.SHA1 for security purposes.This skill owns client-side storage, cryptographic primitives, hardware-backed
keys, and trust evaluation. Route adjacent work deliberately:
authentication for Sign in with Apple, passkeys, OAuth UI flows,ASAuthorizationController, credential state, and account sign-in UX.
cryptokit for primitive CryptoKit API syntax and examples when storage,key lifecycle, protocol/trust design, Secure Enclave policy, certificate
trust, misuse review, or compliance is not part of the task.
involves key ownership, derivation, storage, rotation/recovery, Secure Enclave,
HPKE/PQC migration, protocol trust boundaries, or misuse analysis.
device-integrity for DeviceCheck and App Attest attestation/assertionflows.
ios-networking for URLSession, request pipelines, ATS configuration,retries, caching, reachability, and transport architecture.
app-store-review for privacy manifests, ATT, App Review guidelinecompliance, and submission readiness.
This skill may mention those areas only to identify a security handoff.
Use this checklist for code reviews and migration plans. Mark each item pass,
fail, or not applicable; for each failure, cite the reference file and severity.
UserDefaults, plists, source, logs, files, orarchives.
SecItem* call checks OSStatus and handles common recoverable errors.SecAccessControl, not astandalone Bool from LAContext.evaluatePolicy().
kSecClass matches the item type and primary-key attributes.hardcoded keys.
rotation/recovery, availability gates, and protocol/trust boundaries.
persists only dataRepresentation, and designs for device-bound keys.
entitlements on every target.
SecTrust APIs, validates hostname/policy, anduses SPKI or CA pinning when pinning is required.
keychain behavior.
and migration paths where applicable.
errSecItemNotFound handling.
control.
kSecAttrAccessibleWhenUnlocked implicitly by omitting the attribute.kSecAttrAccessibleAlways orkSecAttrAccessibleAlwaysThisDeviceOnly, both deprecated.
kSecAttrAccessible and kSecAttrAccessControl on the same add query.for symmetric encryption.
iOS 26.
correct SPKI representation.
review guidance instead of handing off to sibling skills.
cryptography failures, HIGH for silent security boundary/data-loss issues, and
MEDIUM for brittle or incomplete hardening.
concrete anti-pattern is present.
OSStatus handling and explicit accessibility inexamples.
## Reference Files andlist the loaded references with a one-line purpose.
present in the loaded references or official Apple documentation, say it needs
verification.
kSecClass selection, primary keys, certificates, identities.SecAccessControl, background access, data protection.LAContext, enrollment-change handling.NSPinnedDomains, client certificates.Take dpearson2699/swift-security from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.