Token导航 LogoToken导航

Agent Skill · 研究检索

axiom-keychain-ref(Axiom 钥匙扣参考)

axiom-keychain-ref 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

axiom-keychain-ref 是研究检索类 Agent Skill,可用宿主为 Codex、Claude、Cursor、Gemini CLI,通过GitHub 仓库获取,权限为接触敏感数据;许可证信息还不明确,第三方扫描已通过,按安装量在研究检索类的 73,675 个 Skill 里排第 45,360。

总安装 855周安装 36GitHub Stars 873下载 476核验 2026-05-01

安装说明

本站只整理中文说明,不托管安装包,也不代用户安装。
GitHub
许可证
unknown

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:axiom-keychain-ref(Axiom 钥匙扣参考)
来源仓库:https://github.com/charleswiltgen/axiom
仓库路径:skills/axiom-keychain-ref
安装命令:
npx skills add https://github.com/charleswiltgen/axiom --skill axiom-keychain-ref
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/charleswiltgen/axiom --skill axiom-keychain-ref

这个 Skill 是做什么的

研究检索类 Skill 主要解决「找资料、核对事实、把来源整理清楚」的问题,通常会让助手先检索再总结。

用于查找、检索和筛选相关信息。适合在 Codex、Claude、Cursor、Gemini CLI 中根据关键词、任务场景或来源线索快速定位候选结果。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

axiom-keychain-ref 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

来源仓库内路径:skills/axiom-keychain-ref

上手步骤

4 步
  1. 1

    确认自己的宿主工具

    公开资料标注支持 Codex、Claude、Cursor、Gemini CLI;先确认自己用的是其中之一,再按对应工具的 Skills 目录放置。

  2. 2

    拿到安装命令

    可以直接复制的命令是 npx skills add https://github.com/charleswiltgen/axiom --skill axiom-keychain-re…;命令里的占位符换成自己的路径或密钥再执行。

  3. 3

    安装后重启宿主

    命令执行完要完全退出宿主工具再打开,让新装的 Skill 被重新扫描到,否则列表里可能看不到。

  4. 4

    按最小权限试用

    它需要接触敏感数据,先在测试目录或测试账号里跑,确认没问题再放到正式项目。

常见问题

6 条

axiom-keychain-ref 怎么安装?

在终端执行 npx skills add https://github.com/charleswiltgen/axiom --skill axiom-keychain-ref。装完完全退出宿主工具再打开,让它重新扫描本地 Skill。

axiom-keychain-ref 支持哪些 AI 工具?

公开资料标注支持 Codex、Claude、Cursor、Gemini CLI。其他工具只要能读取本地 Skill 目录,一般也能手动放进去,但要自己确认触发方式是否一致。

axiom-keychain-ref 需要什么权限?

权限级别是接触敏感数据。该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

axiom-keychain-ref 是免费的吗?

公开资料没有标注明确许可证,收费和商用限制都无法确认。正式使用前请到来源仓库核对授权说明。

axiom-keychain-ref 用的人多吗?

公开数据是累计安装 855 次,近一周安装 36 次,下载 476 次,GitHub 873 星。这些数字来自第三方目录统计,只能当作热度参考,不代表质量或安全性。

axiom-keychain-ref 安全吗?

第三方扫描结果为通过,但这只覆盖已知的静态检查项,不能替代自己读一遍源码和安装命令。

值得选的地方和要先想清楚的地方

值得选的地方

  • 同时适配 4 种工具,换客户端不用重新找替代品。
  • 第三方扫描已通过,常见的高风险行为没有命中。

先想清楚的地方

  • 需要接触敏感数据,装到常用环境前要先评估影响面。
  • 许可证没有明确标注,能不能商用、能不能再分发都不确定。
  • 第三方目录整理,版本更新和行为细节以来源仓库为准。

适不适合你

更适合

  • 已经在用 Codex,想直接扩展它能力的人。
  • 需要处理研究检索类任务、又不想每次都手写提示词的人。

不太适合

  • 环境里有大量密钥、凭证,不方便给第三方 Skill 读取的人。
  • 需要明确授权才能用到公司项目里的场景。
  • 需要厂商级技术支持和 SLA 的生产系统。

研究检索类 Skill 对比

6 个同类
Skill总安装GitHub 星权限许可证扫描
find-skills

寻找技能 · Codex、Claude

31,199,81316,486操作浏览器MIT有提醒
self-improving-agent

自我改进 Agent · OpenClaw

16,464,0023,396接触敏感数据MIT-0通过
soultrace

灵魂追踪 · Codex、Claude

7,588,94412需要联网未明确有提醒
self-improving

自我完善 · OpenClaw

6,829,2841,046需要联网MIT-0通过
microsoft-foundry

微软代工厂 · Codex、Claude

6,614,144764调用外部服务未明确有提醒
axiom-keychain-ref

Axiom 钥匙扣参考 · 本页

855873接触敏感数据未明确通过

按安装量取同分类前几名;数字来自第三方目录统计,只作热度参考,不代表质量结论。

SKILL.md 原文

Keychain Services API Reference

Comprehensive API reference for iOS/macOS Keychain Services: SecItem CRUD functions, item class attributes, uniqueness constraints, accessibility levels, access control flags, biometric integration, and error codes.

Quick Reference

// Add a generic password
let addQuery: [String: Any] = [
    kSecClass as String: kSecClassGenericPassword,
    kSecAttrService as String: "com.example.app",
    kSecAttrAccount as String: "user@example.com",
    kSecValueData as String: "secret".data(using: .utf8)!
]
let addStatus = SecItemAdd(addQuery as CFDictionary, nil)

// Read a generic password
let readQuery: [String: Any] = [
    kSecClass as String: kSecClassGenericPassword,
    kSecAttrService as String: "com.example.app",
    kSecAttrAccount as String: "user@example.com",
    kSecReturnData as String: true,
    kSecMatchLimit as String: kSecMatchLimitOne
]
var result: AnyObject?
let readStatus = SecItemCopyMatching(readQuery as CFDictionary, &result)
let data = result as? Data

// Update a generic password
let updateQuery: [String: Any] = [
    kSecClass as String: kSecClassGenericPassword,
    kSecAttrService as String: "com.example.app",
    kSecAttrAccount as String: "user@example.com"
]
let updateAttributes: [String: Any] = [
    kSecValueData as String: "newSecret".data(using: .utf8)!
]
let updateStatus = SecItemUpdate(updateQuery as CFDictionary, updateAttributes as CFDictionary)

// Delete a generic password
let deleteQuery: [String: Any] = [
    kSecClass as String: kSecClassGenericPassword,
    kSecAttrService as String: "com.example.app",
    kSecAttrAccount as String: "user@example.com"
]
let deleteStatus = SecItemDelete(deleteQuery as CFDictionary)

SecItem Functions

SecItemAdd

func SecItemAdd(_ attributes: CFDictionary, _ result: UnsafeMutablePointer<CFTypeRef?>?) -> OSStatus

attributes dictionary accepts: Item class + item attributes + value properties + return type properties.

Does NOT accept search properties (kSecMatch*). Providing kSecMatchLimit in an add query is an error.

result: Pass nil if you don't need the added item back. Pass a pointer to receive the item in the format specified by kSecReturn* keys. Pass nil in most cases — requesting the result back forces an extra read.

SecItemCopyMatching

func SecItemCopyMatching(_ query: CFDictionary, _ result: UnsafeMutablePointer<CFTypeRef?>?) -> OSStatus

query dictionary accepts: Item class + item attributes + search properties + return type properties.

Does NOT accept value properties (kSecValueData) as search criteria.

result: The type depends on which kSecReturn* keys are set:

  • kSecReturnData alone → CFData
  • kSecReturnAttributes alone → CFDictionary
  • kSecReturnRef alone → SecKey / SecCertificate / SecIdentity
  • kSecReturnPersistentRef alone → CFData (persistent reference)
  • Multiple kSecReturn* keys → CFDictionary containing requested types
  • kSecMatchLimit = kSecMatchLimitAll → CFArray of the above

SecItemUpdate

func SecItemUpdate(_ query: CFDictionary, _ attributesToUpdate: CFDictionary) -> OSStatus

query dictionary accepts: Item class + item attributes + search properties. Used to find items to update.

attributesToUpdate dictionary accepts: Item attributes + value properties. These are applied to matched items. Does NOT accept item class or search properties.

Updating kSecValueData replaces the stored secret. Updating attributes (e.g., kSecAttrLabel) changes metadata without touching the secret.

SecItemDelete

func SecItemDelete(_ query: CFDictionary) -> OSStatus

query dictionary accepts: Item class + item attributes + search properties.

On macOS, deletes ALL matching items by default (implicit kSecMatchLimitAll). On iOS, also deletes all matches. There is no confirmation — deletion is immediate.


Item Classes

kSecClassGenericPassword

General-purpose secret storage. The most commonly used class.

AttributeKeyType
ServicekSecAttrServiceCFString
AccountkSecAttrAccountCFString
Access GroupkSecAttrAccessGroupCFString
AccessiblekSecAttrAccessibleCFString (constant)
SynchronizablekSecAttrSynchronizableCFBoolean
LabelkSecAttrLabelCFString
DescriptionkSecAttrDescriptionCFString
CommentkSecAttrCommentCFString
GenerickSecAttrGenericCFData
CreatorkSecAttrCreatorCFNumber (FourCharCode)
TypekSecAttrTypeCFNumber (FourCharCode)
Creation DatekSecAttrCreationDateCFDate (read-only)
Modification DatekSecAttrModificationDateCFDate (read-only)

kSecClassInternetPassword

URL-associated credentials. Rarely needed — most apps use generic passwords.

AttributeKeyType
ServerkSecAttrServerCFString
ProtocolkSecAttrProtocolCFString (constant)
PortkSecAttrPortCFNumber
PathkSecAttrPathCFString
AccountkSecAttrAccountCFString
Authentication TypekSecAttrAuthenticationTypeCFString (constant)
Security DomainkSecAttrSecurityDomainCFString
AccessiblekSecAttrAccessibleCFString (constant)
Access GroupkSecAttrAccessGroupCFString
SynchronizablekSecAttrSynchronizableCFBoolean
LabelkSecAttrLabelCFString
CommentkSecAttrCommentCFString
CreatorkSecAttrCreatorCFNumber (FourCharCode)
TypekSecAttrTypeCFNumber (FourCharCode)

kSecClassCertificate

X.509 certificates. Typically managed by the system, not app code.

AttributeKeyType
SubjectkSecAttrSubjectCFData (read-only)
IssuerkSecAttrIssuerCFData (read-only)
Serial NumberkSecAttrSerialNumberCFData (read-only)
Subject Key IDkSecAttrSubjectKeyIDCFData (read-only)
Public Key HashkSecAttrPublicKeyHashCFData (read-only)
Certificate TypekSecAttrCertificateTypeCFNumber
Certificate EncodingkSecAttrCertificateEncodingCFNumber
LabelkSecAttrLabelCFString
Access GroupkSecAttrAccessGroupCFString
SynchronizablekSecAttrSynchronizableCFBoolean

kSecClassKey

Cryptographic keys (RSA, EC, AES). Used for encryption, signing, key agreement.

AttributeKeyType
Key ClasskSecAttrKeyClassCFString (constant)
Application LabelkSecAttrApplicationLabelCFData
Application TagkSecAttrApplicationTagCFData
Key TypekSecAttrKeyTypeCFString (constant)
Key Size in BitskSecAttrKeySizeInBitsCFNumber
Effective Key SizekSecAttrEffectiveKeySizeCFNumber
PermanentkSecAttrIsPermanentCFBoolean
SensitivekSecAttrIsSensitiveCFBoolean
ExtractablekSecAttrIsExtractableCFBoolean
LabelkSecAttrLabelCFString
Access GroupkSecAttrAccessGroupCFString
SynchronizablekSecAttrSynchronizableCFBoolean
Token IDkSecAttrTokenIDCFString

kSecClassIdentity

A digital identity is a certificate paired with its private key. Not a distinct storage class — the system synthesizes it from a matching certificate and key. You cannot add a kSecClassIdentity item directly; add the certificate and key separately. Queries return an identity when both halves share the same kSecAttrPublicKeyHash.

See Quinn "The Eskimo!"'s technote: "SecItem: Pitfalls and Best Practices" (forums/thread/724013) — digital identities are a virtual join, not a stored item.


Uniqueness Constraints Per Class

Each keychain item is uniquely identified by a subset of its attributes. Adding a second item with the same primary key returns errSecDuplicateItem (-25299). Use SecItemUpdate to modify existing items.

ClassPrimary Key Attributes
Generic PasswordkSecAttrService + kSecAttrAccount + kSecAttrAccessGroup + kSecAttrSynchronizable
Internet PasswordkSecAttrServer + kSecAttrPort + kSecAttrProtocol + kSecAttrAuthenticationType + kSecAttrPath + kSecAttrAccount + kSecAttrAccessGroup + kSecAttrSynchronizable
CertificatekSecAttrCertificateType + kSecAttrIssuer + kSecAttrSerialNumber + kSecAttrAccessGroup + kSecAttrSynchronizable
KeykSecAttrApplicationLabel + kSecAttrApplicationTag + kSecAttrKeyType + kSecAttrKeySizeInBits + kSecAttrEffectiveKeySize + kSecAttrKeyClass + kSecAttrAccessGroup + kSecAttrSynchronizable
IdentityN/A (virtual join of certificate + key)

Consequence: If you store tokens for multiple users under the same kSecAttrService without unique kSecAttrAccount values, SecItemAdd returns errSecDuplicateItem for the second user.


Attribute Constants Reference

Identity Attributes

ConstantTypeUsed By
kSecAttrServiceCFStringGenericPassword
kSecAttrAccountCFStringGenericPassword, InternetPassword
kSecAttrServerCFStringInternetPassword
kSecAttrLabelCFStringAll classes
kSecAttrDescriptionCFStringGenericPassword, InternetPassword
kSecAttrCommentCFStringGenericPassword, InternetPassword
kSecAttrGenericCFDataGenericPassword

Security Attributes

ConstantTypeUsed By
kSecAttrAccessibleCFString (constant)All classes
kSecAttrAccessControlSecAccessControlAll classes
kSecAttrAccessGroupCFStringAll classes
kSecAttrSynchronizableCFBooleanAll classes

kSecAttrAccessible and kSecAttrAccessControl are mutually exclusive. Setting both is an error — kSecAttrAccessControl includes an accessibility level in its creation.

Token Attributes

ConstantTypePurpose
kSecAttrTokenIDCFStringBind key to hardware token
kSecAttrTokenIDSecureEnclaveCFString (value)Secure Enclave — EC keys only (256-bit)

Key Metadata Attributes

ConstantTypeValues
kSecAttrKeyTypeCFStringkSecAttrKeyTypeRSA, kSecAttrKeyTypeECSECPrimeRandom
kSecAttrKeySizeInBitsCFNumber256 (EC), 2048/4096 (RSA)
kSecAttrKeyClassCFStringkSecAttrKeyClassPublic, kSecAttrKeyClassPrivate, kSecAttrKeyClassSymmetric
kSecAttrApplicationTagCFDataApp-defined tag for key lookup
kSecAttrApplicationLabelCFDataSHA-1 hash of public key (auto-generated)

Search Properties

Used in SecItemCopyMatching, SecItemUpdate (query parameter), and SecItemDelete queries.

ConstantTypePurpose
kSecMatchLimitCFString or CFNumberMax results — kSecMatchLimitOne, kSecMatchLimitAll, or CFNumber for explicit integer limits (e.g., limit to 5 results)
kSecMatchCaseInsensitiveCFBooleanCase-insensitive string attribute matching

kSecMatchLimit Defaults

The default depends on context and is a common source of bugs:

FunctionDefaultBehavior
SecItemCopyMatchingkSecMatchLimitOneReturns first match
SecItemDeleteAll matchesDeletes every matching item

Always set kSecMatchLimit explicitly in SecItemCopyMatching to make intent clear. For SecItemDelete, omitting kSecMatchLimit deletes all matches — this is by design, not a bug.


Return Type Properties

Control what SecItemCopyMatching and SecItemAdd return. Set in the query dictionary.

ConstantReturnsResult Type
kSecReturnDataThe secret (password bytes, key data)CFData
kSecReturnAttributesItem metadata dictionaryCFDictionary
kSecReturnRefKeychain object referenceSecKey, SecCertificate, or SecIdentity
kSecReturnPersistentRefPersistent reference (survives app relaunch)CFData

Return Type Behavior Per Class

ClasskSecReturnDatakSecReturnRef
Generic PasswordPassword bytesN/A (no ref type)
Internet PasswordPassword bytesN/A (no ref type)
CertificateDER-encoded certificate dataSecCertificate
KeyKey data (if extractable)SecKey
IdentityN/ASecIdentity

Multiple Return Types

When multiple kSecReturn* keys are true, the result is a CFDictionary with keys:

  • kSecValueData → the data
  • kSecValueRef → the ref
  • kSecValuePersistentRef → the persistent ref
  • Plus all attribute keys if kSecReturnAttributes is true

When kSecMatchLimitAll is set, the result is a CFArray of the above.


Value Type Properties

Used to provide or extract values in add, query, and update dictionaries.

ConstantTypePurpose
kSecValueDataCFDataThe secret (password, key material)
kSecValueRefSecKey / SecCertificate / SecIdentityKeychain object reference
kSecValuePersistentRefCFDataPersistent reference to an item

Behavior Per Operation

PropertySecItemAddSecItemCopyMatchingSecItemUpdate
kSecValueDataSets the secretNot valid as search criteriaReplaces the secret
kSecValueRefAdds the referenced objectFinds by referenceNot valid
kSecValuePersistentRefNot validFinds by persistent refNot valid

Accessibility Constants

Controls when keychain items are readable. Set via kSecAttrAccessible.

ConstantAvailable WhenSurvives BackupSyncs via iCloud
kSecAttrAccessibleWhenUnlockedDevice unlockedYesYes (default)
kSecAttrAccessibleAfterFirstUnlockAfter first unlock until rebootYesYes
kSecAttrAccessibleWhenPasscodeSetThisDeviceOnlyDevice unlocked + passcode setNoNo
kSecAttrAccessibleWhenUnlockedThisDeviceOnlyDevice unlockedNoNo
kSecAttrAccessibleAfterFirstUnlockThisDeviceOnlyAfter first unlock until rebootNoNo

Default: kSecAttrAccessibleWhenUnlocked for new items.

ThisDeviceOnly variants: Item is not included in encrypted backups and does not sync via iCloud Keychain. Use for device-bound secrets (biometric-gated tokens, Secure Enclave keys).

WhenPasscodeSetThisDeviceOnly: Item is deleted if the user removes their passcode. Use for secrets that must not survive passcode removal.

AfterFirstUnlock: Available in the background after the user unlocks once post-reboot. Required for background fetch, push notification handlers, and background URLSession completions.

Deprecated (do not use): kSecAttrAccessibleAlways, kSecAttrAccessibleAlwaysThisDeviceOnly.


SecAccessControlCreateFlags

Fine-grained access control for keychain items. Created with SecAccessControlCreateWithFlags and set via kSecAttrAccessControl.

All Flags

FlagPurpose
.userPresenceAny biometric OR device passcode
.biometryAnyAny enrolled biometric (survives new enrollment)
.biometryCurrentSetCurrent biometric set only (invalidated if biometrics change)
.devicePasscodeDevice passcode required
.privateKeyUsageRequired for Secure Enclave key signing operations
.applicationPasswordApp-provided password (in addition to other factors)
.watchPaired Apple Watch can satisfy authentication
.orCombine flags with logical OR (any one satisfies)
.andCombine flags with logical AND (all must satisfy)

Creating Access Control

var error: Unmanaged<CFError>?
guard let accessControl = SecAccessControlCreateWithFlags(
    kCFAllocatorDefault,
    kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly,
    [.biometryCurrentSet, .or, .devicePasscode],
    &error
) else {
    let nsError = error!.takeRetainedValue() as Error
    fatalError("Failed to create access control: \(nsError)")
}

let query: [String: Any] = [
    kSecClass as String: kSecClassGenericPassword,
    kSecAttrService as String: "com.example.app",
    kSecAttrAccount as String: "auth-token",
    kSecAttrAccessControl as String: accessControl,
    kSecValueData as String: tokenData
]
let status = SecItemAdd(query as CFDictionary, nil)

Flag Combinations

CombinationMeaning
[.biometryAny]Any enrolled fingerprint/face
[.biometryCurrentSet]Current fingerprint/face set (re-enroll invalidates)
[.biometryCurrentSet,.or,.devicePasscode]Biometric OR passcode fallback
[.biometryCurrentSet,.and,.applicationPassword]Biometric AND app password
[.privateKeyUsage]Secure Enclave key operations (sign, decrypt)
[.biometryAny,.or,.watch]Biometric OR paired Watch

.biometryAny vs .biometryCurrentSet: Use .biometryCurrentSet for high-security items (banking tokens). If the user enrolls a new fingerprint, the item becomes inaccessible — your app must re-authenticate and re-store. Use .biometryAny for convenience items where new enrollment should not invalidate access.


LocalAuthentication Integration

LAContext with Keychain

Pre-evaluate biometrics with LAContext, then pass the context to the keychain query to avoid a second biometric prompt.

import LocalAuthentication

let context = LAContext()
context.localizedReason = "Access your credentials"

var authError: NSError?
guard context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &authError) else {
    // Biometrics unavailable — handle error or fall back to passcode
    return
}

context.evaluatePolicy(
    .deviceOwnerAuthenticationWithBiometrics,
    localizedReason: "Authenticate to access credentials"
) { success, error in
    guard success else { return }

    let query: [String: Any] = [
        kSecClass as String: kSecClassGenericPassword,
        kSecAttrService as String: "com.example.app",
        kSecAttrAccount as String: "auth-token",
        kSecReturnData as String: true,
        kSecMatchLimit as String: kSecMatchLimitOne,
        kSecUseAuthenticationContext as String: context
    ]
    var result: AnyObject?
    let status = SecItemCopyMatching(query as CFDictionary, &result)
}

LAContext Keychain Keys

KeyTypePurpose
kSecUseAuthenticationContextLAContextReuse authenticated context (avoids double prompt)
kSecUseAuthenticationUICFStringControl UI behavior: kSecUseAuthenticationUIAllow (default), kSecUseAuthenticationUIFail, kSecUseAuthenticationUISkip

kSecUseAuthenticationUIFail: Returns errSecInteractionNotAllowed instead of showing the biometric prompt. Use to check if an item exists without triggering UI.

LAPolicy Types

PolicyRequires
.deviceOwnerAuthenticationWithBiometricsFace ID or Touch ID only
.deviceOwnerAuthenticationBiometrics or passcode fallback

BiometryType Detection

let context = LAContext()
var error: NSError?
context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error)

switch context.biometryType {
case .faceID:    // Face ID available
case .touchID:   // Touch ID available
case .opticID:   // Optic ID available (visionOS)
case .none:      // No biometric hardware
@unknown default: break
}

LAError Codes

ErrorCodeCause
.authenticationFailed-1User failed authentication
.userCancel-2User tapped Cancel
.userFallback-3User tapped "Enter Password"
.systemCancel-4System cancelled (app backgrounded)
.passcodeNotSet-5No passcode configured
.biometryNotAvailable-6Hardware unavailable or restricted
.biometryNotEnrolled-7No biometrics enrolled
.biometryLockout-8Too many failed attempts

OSStatus Error Codes

Common keychain OSStatus values and their root causes.

ErrorCodeDescriptionCommon Cause
errSecSuccess0Operation succeeded—
errSecDuplicateItem-25299Item already existsAdding with same primary key — use SecItemUpdate instead
errSecItemNotFound-25300No matching itemWrong query attributes or item never stored
errSecInteractionNotAllowed-25308UI prompt blockedItem requires auth but device locked, or kSecUseAuthenticationUIFail set
errSecAuthFailed-25293Authentication failedWrong password, failed biometric, or ACL denied
errSecMissingEntitlement-34018Missing keychain entitlementApp lacks keychain-access-groups entitlement — common in unit test targets
errSecNoSuchAttr-25303Attribute not foundQuerying an attribute not valid for the item class
errSecParam-50Invalid parameterMalformed query dictionary — check for type mismatches (e.g., String where Data expected)
errSecAllocate-108Memory allocation failedSystem resource exhaustion
errSecDecode-26275Unable to decode dataCorrupted item or encoding mismatch
errSecNotAvailable-25291Keychain not availableNo keychain database (rare — Simulator reset or corrupted install)

Interpreting OSStatus in Swift

let status = SecItemAdd(query as CFDictionary, nil)
if status != errSecSuccess {
    let message = SecCopyErrorMessageString(status, nil) as? String ?? "Unknown error"
    print("Keychain error \(status): \(message)")
}

-34018 on Test Targets

Unit test runners (XCTest) often lack the keychain-access-groups entitlement. Workarounds:

  1. Add a Host Application to the test target (Xcode → Test Target → General → Host Application)
  2. Use an in-memory mock for unit tests, real keychain for integration tests only

Keychain Sharing

Access Groups

Items are isolated per app by default. To share between apps or extensions:

  1. Enable "Keychain Sharing" capability in Xcode
  2. Add shared access group identifiers
  3. Set kSecAttrAccessGroup when adding items
let query: [String: Any] = [
    kSecClass as String: kSecClassGenericPassword,
    kSecAttrService as String: "com.example.shared",
    kSecAttrAccount as String: "shared-token",
    kSecAttrAccessGroup as String: "TEAMID.com.example.shared",
    kSecValueData as String: tokenData
]

The access group format is $(TeamIdentifierPrefix)$(GroupIdentifier). Items without an explicit access group default to the app's first access group in its entitlements.

iCloud Keychain Sync

Set kSecAttrSynchronizable to true to sync via iCloud Keychain:

let query: [String: Any] = [
    kSecClass as String: kSecClassGenericPassword,
    kSecAttrService as String: "com.example.app",
    kSecAttrAccount as String: "sync-token",
    kSecAttrSynchronizable as String: true,
    kSecValueData as String: tokenData
]

Synchronizable items cannot use ThisDeviceOnly accessibility levels or SecAccessControl. They must use kSecAttrAccessibleWhenUnlocked or kSecAttrAccessibleAfterFirstUnlock.

When querying, kSecAttrSynchronizable defaults to kSecAttrSynchronizableAny (returns both local and synced items). Set explicitly to true or false to filter.


Resources

WWDC: 2013-709, 2014-711, 2020-10147

Docs: /security/keychain_services, /localauthentication, /security/secaccesscontrolcreateflags, /security/secitemadd(*:*:)

Skills: axiom-code-signing-ref, axiom-app-attest

平台分布

Codex

36.14%
按下载量换算172

Claude

29.39%
按下载量换算140

Cursor

19.66%
按下载量换算94

Gemini CLI

9.69%
按下载量换算46

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

接触敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。目前只有一个公开来源,建议同时核对源仓库。

继续浏览同类 Skills