2 * Copyright (c) 2006-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * SecItemSchema.c - CoreFoundation-based constants and functions for
26 access to Security items (certificates, keys, identities, and
30 #include "SecItemSchema.h"
31 #include <securityd/SecDbKeychainItem.h>
34 // MARK Keychain version 6 schema
36 #define __FLAGS(ARG, ...) SECDBFLAGS(__VA_ARGS__)
37 #define SECDBFLAGS(ARG, ...) __FLAGS_##ARG | __FLAGS(__VA_ARGS__)
39 #define SecDbFlags(P,L,I,S,A,D,R,C,H,B,Z,E,N,U) (__FLAGS_##P|__FLAGS_##L|__FLAGS_##I|__FLAGS_##S|__FLAGS_##A|__FLAGS_##D|__FLAGS_##R|__FLAGS_##C|__FLAGS_##H|__FLAGS_##B|__FLAGS_##Z|__FLAGS_##E|__FLAGS_##N|__FLAGS_##U)
42 #define __FLAGS_P kSecDbPrimaryKeyFlag
43 #define __FLAGS_L kSecDbInFlag
44 #define __FLAGS_I kSecDbIndexFlag
45 #define __FLAGS_S kSecDbSHA1ValueInFlag
46 #define __FLAGS_A kSecDbReturnAttrFlag
47 #define __FLAGS_D kSecDbReturnDataFlag
48 #define __FLAGS_R kSecDbReturnRefFlag
49 #define __FLAGS_C kSecDbInCryptoDataFlag
50 #define __FLAGS_H kSecDbInHashFlag
51 #define __FLAGS_B kSecDbInBackupFlag
52 #define __FLAGS_Z kSecDbDefault0Flag
53 #define __FLAGS_E kSecDbDefaultEmptyFlag
54 #define __FLAGS_N kSecDbNotNullFlag
55 #define __FLAGS_U kSecDbInAuthenticatedDataFlag
57 // ,-------------- P : Part of primary key
58 // / ,------------- L : Stored in local database
59 // / / ,------------ I : Attribute wants an index in the database
60 // / / / ,----------- S : SHA1 hashed attribute value in database (implies L)
61 // / / / / ,---------- A : Returned to client as attribute in queries
62 // / / / / / ,--------- D : Returned to client as data in queries
63 // / / / / / / ,-------- R : Returned to client as ref/persistent ref in queries
64 // / / / / / / / ,------- C : Part of encrypted blob
65 // / / / / / / / / ,------ H : Attribute is part of item SHA1 hash (Implied by C)
66 // / / / / / / / / / ,----- B : Attribute is part of iTunes/iCloud backup bag
67 // / / / / / / / / / / ,---- Z : Attribute has a default value of 0
68 // / / / / / / / / / / / ,--- E : Attribute has a default value of "" or empty data
69 // / / / / / / / / / / / / ,-- N : Attribute must have a value
70 // / / / / / / / / / / / / / ,- U : Attribute is stored in authenticated, but not necessarily encrypted data
71 // / / / / / / / / / / / / / /
72 // / / / / / / / / / / / / / /
73 // | | | | | | | | | | | | | |
74 // common to all | | | | | | | | | | | | | |
75 SECDB_ATTR(v6rowid
, "rowid", RowId
, SecDbFlags( ,L
, , , , ,R
, , ,B
, , , , ), NULL
, NULL
);
76 SECDB_ATTR(v6cdat
, "cdat", CreationDate
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), SecDbKeychainItemCopyCurrentDate
, NULL
);
77 SECDB_ATTR(v6mdat
, "mdat",ModificationDate
,SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), SecDbKeychainItemCopyCurrentDate
, NULL
);
78 SECDB_ATTR(v6labl
, "labl", Blob
, SecDbFlags( ,L
, ,S
,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
79 SECDB_ATTR(v6data
, "data", EncryptedData
, SecDbFlags( ,L
, , , , , , , ,B
, , , , ), SecDbKeychainItemCopyEncryptedData
, NULL
);
80 SECDB_ATTR(v6agrp
, "agrp", String
, SecDbFlags(P
,L
, , ,A
, , , ,H
, , , ,N
,U
), NULL
, NULL
);
81 SECDB_ATTR(v6pdmn
, "pdmn", Access
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
82 SECDB_ATTR(v6sync
, "sync", Sync
, SecDbFlags(P
,L
,I
, ,A
, , , ,H
, ,Z
, ,N
,U
), NULL
, NULL
);
83 SECDB_ATTR(v6tomb
, "tomb", Tomb
, SecDbFlags( ,L
, , , , , , ,H
, ,Z
, ,N
,U
), NULL
, NULL
);
84 SECDB_ATTR(v6sha1
, "sha1", SHA1
, SecDbFlags( ,L
,I
, ,A
, ,R
, , , , , , , ), SecDbKeychainItemCopySHA1
, NULL
);
85 SECDB_ATTR(v6accc
, "accc", AccessControl
, SecDbFlags( , , , ,A
, , , , , , , , , ), NULL
, NULL
);
86 SECDB_ATTR(v6v_Data
, "v_Data", Data
, SecDbFlags( , , , , ,D
, ,C
,H
, , , , , ), NULL
, NULL
);
87 SECDB_ATTR(v6v_pk
, "v_pk", PrimaryKey
, SecDbFlags( , , , , , , , , , , , , , ), SecDbKeychainItemCopyPrimaryKey
, NULL
);
88 SECDB_ATTR(v7vwht
, "vwht", String
, SecDbFlags(P
,L
, , ,A
, , , ,H
, , , , ,U
), NULL
, NULL
);
89 SECDB_ATTR(v7tkid
, "tkid", String
, SecDbFlags(P
,L
, , ,A
, , , ,H
, , , , ,U
), NULL
, NULL
);
90 SECDB_ATTR(v7utomb
, "u_Tomb", UTomb
, SecDbFlags( , , , , , , , , , , , , , ), NULL
, NULL
);
91 // genp and inet and keys | | | | | | | | | | | | | |
92 SECDB_ATTR(v6crtr
, "crtr", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
93 SECDB_ATTR(v6alis
, "alis", Blob
, SecDbFlags( ,L
, ,S
,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
94 // genp and inet | | | | | | | | | | | | | |
95 SECDB_ATTR(v6desc
, "desc", Blob
, SecDbFlags( ,L
, ,S
,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
96 SECDB_ATTR(v6icmt
, "icmt", Blob
, SecDbFlags( ,L
, ,S
,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
97 SECDB_ATTR(v6type
, "type", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
98 SECDB_ATTR(v6invi
, "invi", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
99 SECDB_ATTR(v6nega
, "nega", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
100 SECDB_ATTR(v6cusi
, "cusi", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
101 SECDB_ATTR(v6prot
, "prot", Blob
, SecDbFlags( ,L
, ,S
,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
102 SECDB_ATTR(v6scrp
, "scrp", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
103 SECDB_ATTR(v6acct
, "acct", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ), NULL
, NULL
);
104 // genp only | | | | | | | | | | | | | |
105 SECDB_ATTR(v6svce
, "svce", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ), NULL
, NULL
);
106 SECDB_ATTR(v6gena
, "gena", Blob
, SecDbFlags( ,L
, ,S
,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
107 // inet only | | | | | | | | | | | | | |
108 SECDB_ATTR(v6sdmn
, "sdmn", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ), NULL
, NULL
);
109 SECDB_ATTR(v6srvr
, "srvr", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ), NULL
, NULL
);
110 SECDB_ATTR(v6ptcl
, "ptcl", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ), NULL
, NULL
);
111 SECDB_ATTR(v6atyp
, "atyp", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ), NULL
, NULL
);
112 SECDB_ATTR(v6port
, "port", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ), NULL
, NULL
);
113 SECDB_ATTR(v6path
, "path", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ), NULL
, NULL
);
114 // cert only | | | | | | | | | | | | | |
115 SECDB_ATTR(v6ctyp
, "ctyp", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ), NULL
, NULL
);
116 SECDB_ATTR(v6cenc
, "cenc", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
117 SECDB_ATTR(v6subj
, "subj", Data
, SecDbFlags( ,L
,I
,S
,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
118 SECDB_ATTR(v6issr
, "issr", Data
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ), NULL
, NULL
);
119 SECDB_ATTR(v6slnr
, "slnr", Data
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ), NULL
, NULL
);
120 SECDB_ATTR(v6skid
, "skid", Data
, SecDbFlags( ,L
,I
,S
,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
121 SECDB_ATTR(v6pkhh
, "pkhh", Data
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
122 // cert attributes that share names with common ones but have different flags
123 SECDB_ATTR(v6certalis
, "alis", Blob
, SecDbFlags( ,L
,I
,S
,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
124 // keys only | | | | | | | | | | | | | |
125 SECDB_ATTR(v6kcls
, "kcls", Number
, SecDbFlags(P
,L
,I
,S
,A
, , ,C
,H
, ,Z
, ,N
, ), NULL
, NULL
);
126 SECDB_ATTR(v6perm
, "perm", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
127 SECDB_ATTR(v6priv
, "priv", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
128 SECDB_ATTR(v6modi
, "modi", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
129 SECDB_ATTR(v6klbl
, "klbl", Data
, SecDbFlags(P
,L
,I
, ,A
, , ,C
,H
, , ,E
,N
, ), NULL
, NULL
);
130 SECDB_ATTR(v6atag
, "atag", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ), NULL
, NULL
);
131 SECDB_ATTR(v6bsiz
, "bsiz", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ), NULL
, NULL
);
132 SECDB_ATTR(v6esiz
, "esiz", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ), NULL
, NULL
);
133 SECDB_ATTR(v6sdat
, "sdat", Date
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ), NULL
, NULL
);
134 SECDB_ATTR(v6edat
, "edat", Date
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ), NULL
, NULL
);
135 SECDB_ATTR(v6sens
, "sens", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
136 SECDB_ATTR(v6asen
, "asen", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
137 SECDB_ATTR(v6extr
, "extr", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
138 SECDB_ATTR(v6next
, "next", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
139 SECDB_ATTR(v6encr
, "encr", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
140 SECDB_ATTR(v6decr
, "decr", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
141 SECDB_ATTR(v6drve
, "drve", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
142 SECDB_ATTR(v6sign
, "sign", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
143 SECDB_ATTR(v6vrfy
, "vrfy", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
144 SECDB_ATTR(v6snrc
, "snrc", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
145 SECDB_ATTR(v6vyrc
, "vyrc", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
146 SECDB_ATTR(v6wrap
, "wrap", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
147 SECDB_ATTR(v6unwp
, "unwp", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ), NULL
, NULL
);
148 // keys attributes that share names with common ones but have different flags
149 SECDB_ATTR(v6keytype
, "type", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ), NULL
, NULL
);
150 SECDB_ATTR(v6keycrtr
, "crtr", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ), NULL
, NULL
);
151 // | | | | | | | | | | | | | |
152 SECDB_ATTR(v6version
, "version", Number
, SecDbFlags(P
,L
, , , , , , , , , , ,N
, ), NULL
, NULL
);
154 const SecDbClass genp_class
= {
155 .name
= CFSTR("genp"),
190 const SecDbClass inet_class
= {
191 .name
= CFSTR("inet"),
230 const SecDbClass cert_class
= {
231 .name
= CFSTR("cert"),
261 const SecDbClass keys_class
= {
262 .name
= CFSTR("keys"),
310 const SecDbClass tversion_class
= {
311 .name
= CFSTR("tversion"),
318 /* An identity which is really a cert + a key, so all cert and keys attrs are
320 const SecDbClass identity_class
= {
321 .name
= CFSTR("idnt"),
327 const SecDbSchema v7_schema
= {
340 // Version 6 (iOS 7 and OSX 10.9) database schema
341 static const SecDbClass v6genp_class
= {
342 .name
= CFSTR("genp6"),
374 static const SecDbClass v6inet_class
= {
375 .name
= CFSTR("inet6"),
411 static const SecDbClass v6cert_class
= {
412 .name
= CFSTR("cert6"),
439 static const SecDbClass v6keys_class
= {
440 .name
= CFSTR("keys6"),
485 static const SecDbSchema v6_schema
= {
498 // Version 5 (iOS 5 & iOS 6) database schema.
499 static const SecDbClass v5genp_class
= {
500 .name
= CFSTR("genp5"),
527 static const SecDbClass v5inet_class
= {
528 .name
= CFSTR("inet5"),
559 static const SecDbClass v5cert_class
= {
560 .name
= CFSTR("cert5"),
582 static const SecDbClass v5keys_class
= {
583 .name
= CFSTR("keys5"),
623 static const SecDbSchema v5_schema
= {
635 const SecDbSchema
*kc_schemas
[] = {