jsloop
5/15/2019 - 12:50 PM

Useful resources for working with iOS/ macOS Keychain API

Useful resources for working with iOS/ macOS Keychain API

Keychain API

kSecAttrAccessible Mapping

Protection Domain (pdmn)Keychain Accessibility Values
ckkSecAttrAccessibleAfterFirstUnlock
ckukSecAttrAccessibleAfterFirstUnlockThisDeviceOnly
dkkSecAttrAccessibleAlways
akpukSecAttrAccessibleWhenPasscodeSetThisDeviceOnly
dkukSecAttrAccessibleAlwaysThisDeviceOnly
akkSecAttrAccessibleWhenUnlocked
akukSecAttrAccessibleWhenUnlockedThisDeviceOnly

Source(s):

Database (keychain-2.db) Structure

In the iOS keychain, all the keychain items are stored in 4 tables

TablekSecClass
genpkSecClassGenericPassword
inetkSecClassInternetPassword
certkSecClassCertificate
keykSecClassKey

kSecClassIdentity = kSecClassCertificate + kSecClassKey

Keychain tables column names mapped to the corresponding keychain item class attributes

ColumnAttributeDescription
cdatkSecAttrCreationDateItem creation date in Unix epoch time format
mdatkSecAttrModificationDateItem modification date in Unix epoch time format
desckSecAttrDescriptionUser visible string that describes the item
icmtkSecAttrCommentUser editable comment for the item
crtrkSecAttrCreatorApplication created (4 char) code
typekSecAttrTypeItem type
scrpkSecAttrScriptCodeString script code (such as encoding type)
lablkSecAttrLabelLabel to be displayed to the user (print name)
aliskSecAttrAliasItem alias
invikSecAttrIsInvisibleInvisible
negakSecAttrIsNegativeInvalid item
cusikSecAttrHasCustomIconExistence of application specific icon (Boolean)
protkSecProtectedDataItemAttr? Item’s data is protected (Boolean)
acctkSecAttrAccountAccount key (such as user id)
svcekSecAttrServiceService name (such as Application identifier)
genakSecAttrGenericUser defined attribute
datakSecValueDataActual data (such as password, crypto key…)
agrpkSecAttrAccessGroupKeychain access group
pdmnkSecAttrAccessibleAccess restrictions (Data protection classes)

Source(s):

Apple Material