# swift-security

Guides AI agents through Apple Keychain, Secure Enclave, and CryptoKit workflows. Useful for securing client data storage on iOS and macOS.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 3000 installs · ★ 1237
- Author: dpearson2699
- License: MIT · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/dpearson2699/swift-ios-skills/tree/HEAD/skills/swift-security/SKILL.md
- Updated: 2026-07-31
- HTML: https://affpapa.org/en/nevibecode/skills/swift-security

## What it does

The skill sets strict patterns for client-side Apple security, focusing on Keychain Services and CryptoKit. When the deployment target is unknown, it defaults to iOS 17+ and Swift concurrency while keeping notes for iOS 13+.

Under the hood, it enforces hard security invariants. Storing tokens or API keys in `UserDefaults` or property lists is blocked. Because `SecItem*` calls can freeze the interface, the skill requires offloading keychain operations from the `MainActor` to a serial queue or custom actor. It also forces handling every `OSStatus` return code, rejecting blind delete-then-add update logic.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add dpearson2699/swift-ios-skills --skill swift-security -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/swift-security/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/swift-security/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add dpearson2699/swift-ios-skills --skill swift-security -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/swift-security/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add dpearson2699/swift-ios-skills --skill swift-security -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/swift-security/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install dpearson2699/swift-ios-skills swift-security
```

2. **Manually: put the files in place**
- File: `.github/skills/swift-security/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add dpearson2699/swift-ios-skills --skill swift-security -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/dpearson2699/swift-ios-skills --path skills/swift-security
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/swift-security/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add dpearson2699/swift-ios-skills --skill swift-security -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/dpearson2699/swift-ios-skills/tree/HEAD/skills/swift-security/SKILL.md

## When to use it
- store tokens and credentials safely in Keychain Services
- gate access to secrets using Face ID and Touch ID via `SecAccessControl`
- implement CryptoKit public key flows and Secure Enclave operations
- migrate credentials out of `UserDefaults` into secure storage

## Example prompts
- Review our Keychain wrapper to make sure all OSStatus error codes are handled properly
- Implement Secure Enclave key generation with biometric access control for iOS 17
- Write a safe migration routine to move existing tokens from UserDefaults into Keychain

## Source text · SKILL.md · MIT

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 4bf4d181b80f9b64.

BEGIN THIRD-PARTY FILE 4bf4d181b80f9b64
````text
---
name: swift-security
description: 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.
license: MIT
---

# 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.

## Contents

- [Workflow](#workflow)
- [Reference Loading](#reference-loading)
- [Security Invariants](#security-invariants)
- [Sibling Boundaries](#sibling-boundaries)
- [Review Checklist](#review-checklist)
- [Common Mistakes](#common-mistakes)
- [Output Rules](#output-rules)
- [References](#references)

## Workflow

Classify the request before loading references.

1. Review existing code: run the [Review Checklist](#review-checklist), then
   load [common-anti-patterns.md](references/common-anti-patterns.md) plus the
   domain reference for each failing area. Report severity, evidence, and the
   corrected pattern.
2. Improve or migrate code: identify the migration type, load the migration
   and target-domain references, preserve existing data, verify the new item,
   then remove legacy storage only after success.
3. Implement new security code: load the minimum domain references, use the
   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.

### Minimum Safe Keychain Write

Use separate add, identity, and update dictionaries; handle every `OSStatus`:

```swift
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
        )
````
END THIRD-PARTY FILE 4bf4d181b80f9b64

The third-party file has ended. Everything between the 4bf4d181b80f9b64 tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 2951 of 12978 bytes. © dpearson2699 · MIT · https://github.com/dpearson2699/swift-ios-skills/tree/HEAD/skills/swift-security/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
