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"
33 // MARK Keychain version 6 schema
35 #define __FLAGS(ARG, ...) SECDBFLAGS(__VA_ARGS__)
36 #define SECDBFLAGS(ARG, ...) __FLAGS_##ARG | __FLAGS(__VA_ARGS__)
38 #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)
41 #define __FLAGS_P kSecDbPrimaryKeyFlag
42 #define __FLAGS_L kSecDbInFlag
43 #define __FLAGS_I kSecDbIndexFlag
44 #define __FLAGS_S kSecDbSHA1ValueInFlag
45 #define __FLAGS_A kSecDbReturnAttrFlag
46 #define __FLAGS_D kSecDbReturnDataFlag
47 #define __FLAGS_R kSecDbReturnRefFlag
48 #define __FLAGS_C kSecDbInCryptoDataFlag
49 #define __FLAGS_H kSecDbInHashFlag
50 #define __FLAGS_B kSecDbInBackupFlag
51 #define __FLAGS_Z kSecDbDefault0Flag
52 #define __FLAGS_E kSecDbDefaultEmptyFlag
53 #define __FLAGS_N kSecDbNotNullFlag
54 #define __FLAGS_U kSecDbInAuthenticatedDataFlag
56 // ,-------------- P : Part of primary key
57 // / ,------------- L : Stored in local database
58 // / / ,------------ I : Attribute wants an index in the database
59 // / / / ,----------- S : SHA1 hashed attribute value in database (implies L)
60 // / / / / ,---------- A : Returned to client as attribute in queries
61 // / / / / / ,--------- D : Returned to client as data in queries
62 // / / / / / / ,-------- R : Returned to client as ref/persistant ref in queries
63 // / / / / / / / ,------- C : Part of encrypted blob
64 // / / / / / / / / ,------ H : Attribute is part of item SHA1 hash (Implied by C)
65 // / / / / / / / / / ,----- B : Attribute is part of iTunes/iCloud backup bag
66 // / / / / / / / / / / ,---- Z : Attribute has a default value of 0
67 // / / / / / / / / / / / ,--- E : Attribute has a default value of "" or empty data
68 // / / / / / / / / / / / / ,-- N : Attribute must have a value
69 // / / / / / / / / / / / / / ,- U : Attribute is stored in authenticated, but not necessarily encrypted data
70 // / / / / / / / / / / / / / /
71 // / / / / / / / / / / / / / /
72 // | | | | | | | | | | | | | |
73 // common to all | | | | | | | | | | | | | |
74 SECDB_ATTR(v6rowid
, "rowid", RowId
, SecDbFlags( ,L
, , , , ,R
, , ,B
, , , , ));
75 SECDB_ATTR(v6cdat
, "cdat", CreationDate
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
76 SECDB_ATTR(v6mdat
, "mdat",ModificationDate
,SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
77 SECDB_ATTR(v6labl
, "labl", Blob
, SecDbFlags( ,L
, ,S
,A
, , ,C
,H
, , , , , ));
78 SECDB_ATTR(v6data
, "data", EncryptedData
, SecDbFlags( ,L
, , , , , , , ,B
, , , , ));
79 SECDB_ATTR(v6agrp
, "agrp", String
, SecDbFlags(P
,L
, , ,A
, , , ,H
, , , , ,U
));
80 SECDB_ATTR(v6pdmn
, "pdmn", Access
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
81 SECDB_ATTR(v6sync
, "sync", Sync
, SecDbFlags(P
,L
,I
, ,A
, , , ,H
, ,Z
, ,N
,U
));
82 SECDB_ATTR(v6tomb
, "tomb", Tomb
, SecDbFlags( ,L
, , , , , , ,H
, ,Z
, ,N
,U
));
83 SECDB_ATTR(v6sha1
, "sha1", SHA1
, SecDbFlags( ,L
,I
, ,A
, ,R
, , , , , , , ));
84 SECDB_ATTR(v6accc
, "accc", AccessControl
, SecDbFlags( , , , ,A
, , , , , , , , , ));
85 SECDB_ATTR(v6v_Data
, "v_Data", Data
, SecDbFlags( , , , , ,D
, ,C
,H
, , , , , ));
86 SECDB_ATTR(v6v_pk
, "v_pk", PrimaryKey
, SecDbFlags( , , , , , , , , , , , , , ));
87 // genp and inet and keys | | | | | | | | | | | | |
88 SECDB_ATTR(v6crtr
, "crtr", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
89 SECDB_ATTR(v6alis
, "alis", Blob
, SecDbFlags( ,L
, ,S
,A
, , ,C
,H
, , , , , ));
90 // genp and inet | | | | | | | | | | | | |
91 SECDB_ATTR(v6desc
, "desc", Blob
, SecDbFlags( ,L
, ,S
,A
, , ,C
,H
, , , , , ));
92 SECDB_ATTR(v6icmt
, "icmt", Blob
, SecDbFlags( ,L
, ,S
,A
, , ,C
,H
, , , , , ));
93 SECDB_ATTR(v6type
, "type", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
94 SECDB_ATTR(v6invi
, "invi", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
95 SECDB_ATTR(v6nega
, "nega", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
96 SECDB_ATTR(v6cusi
, "cusi", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
97 SECDB_ATTR(v6prot
, "prot", Blob
, SecDbFlags( ,L
, ,S
,A
, , ,C
,H
, , , , , ));
98 SECDB_ATTR(v6scrp
, "scrp", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
99 SECDB_ATTR(v6acct
, "acct", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ));
100 // genp only | | | | | | | | | | | | |
101 SECDB_ATTR(v6svce
, "svce", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ));
102 SECDB_ATTR(v6gena
, "gena", Blob
, SecDbFlags( ,L
, ,S
,A
, , ,C
,H
, , , , , ));
103 // inet only | | | | | | | | | | | | |
104 SECDB_ATTR(v6sdmn
, "sdmn", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ));
105 SECDB_ATTR(v6srvr
, "srvr", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ));
106 SECDB_ATTR(v6ptcl
, "ptcl", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ));
107 SECDB_ATTR(v6atyp
, "atyp", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ));
108 SECDB_ATTR(v6port
, "port", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ));
109 SECDB_ATTR(v6path
, "path", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ));
110 // cert only | | | | | | | | | | | | |
111 SECDB_ATTR(v6ctyp
, "ctyp", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ));
112 SECDB_ATTR(v6cenc
, "cenc", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
113 SECDB_ATTR(v6subj
, "subj", Data
, SecDbFlags( ,L
,I
,S
,A
, , ,C
,H
, , , , , ));
114 SECDB_ATTR(v6issr
, "issr", Data
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ));
115 SECDB_ATTR(v6slnr
, "slnr", Data
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ));
116 SECDB_ATTR(v6skid
, "skid", Data
, SecDbFlags( ,L
,I
,S
,A
, , ,C
,H
, , , , , ));
117 SECDB_ATTR(v6pkhh
, "pkhh", Data
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ));
118 // cert attributes that share names with common ones but have different flags
119 SECDB_ATTR(v6certalis
, "alis", Blob
, SecDbFlags( ,L
,I
,S
,A
, , ,C
,H
, , , , , ));
120 // keys only | | | | | | | | | | | | |
121 SECDB_ATTR(v6kcls
, "kcls", Number
, SecDbFlags(P
,L
,I
,S
,A
, , ,C
,H
, ,Z
, ,N
, ));
122 SECDB_ATTR(v6perm
, "perm", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
123 SECDB_ATTR(v6priv
, "priv", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
124 SECDB_ATTR(v6modi
, "modi", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
125 SECDB_ATTR(v6klbl
, "klbl", Data
, SecDbFlags(P
,L
,I
, ,A
, , ,C
,H
, , ,E
,N
, ));
126 SECDB_ATTR(v6atag
, "atag", Blob
, SecDbFlags(P
,L
, ,S
,A
, , ,C
,H
, , ,E
,N
, ));
127 SECDB_ATTR(v6bsiz
, "bsiz", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ));
128 SECDB_ATTR(v6esiz
, "esiz", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ));
129 SECDB_ATTR(v6sdat
, "sdat", Date
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ));
130 SECDB_ATTR(v6edat
, "edat", Date
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ));
131 SECDB_ATTR(v6sens
, "sens", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
132 SECDB_ATTR(v6asen
, "asen", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
133 SECDB_ATTR(v6extr
, "extr", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
134 SECDB_ATTR(v6next
, "next", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
135 SECDB_ATTR(v6encr
, "encr", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ));
136 SECDB_ATTR(v6decr
, "decr", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ));
137 SECDB_ATTR(v6drve
, "drve", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ));
138 SECDB_ATTR(v6sign
, "sign", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ));
139 SECDB_ATTR(v6vrfy
, "vrfy", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ));
140 SECDB_ATTR(v6snrc
, "snrc", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
141 SECDB_ATTR(v6vyrc
, "vyrc", Number
, SecDbFlags( ,L
, , ,A
, , ,C
,H
, , , , , ));
142 SECDB_ATTR(v6wrap
, "wrap", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ));
143 SECDB_ATTR(v6unwp
, "unwp", Number
, SecDbFlags( ,L
,I
, ,A
, , ,C
,H
, , , , , ));
144 // keys attributes that share names with common ones but have different flags
145 SECDB_ATTR(v6keytype
, "type", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ));
146 SECDB_ATTR(v6keycrtr
, "crtr", Number
, SecDbFlags(P
,L
, , ,A
, , ,C
,H
, ,Z
, ,N
, ));
148 const SecDbClass genp_class
= {
149 .name
= CFSTR("genp"),
181 const SecDbClass inet_class
= {
182 .name
= CFSTR("inet"),
218 const SecDbClass cert_class
= {
219 .name
= CFSTR("cert"),
246 const SecDbClass keys_class
= {
247 .name
= CFSTR("keys"),
292 /* An identity which is really a cert + a key, so all cert and keys attrs are
294 const SecDbClass identity_class
= {
295 .name
= CFSTR("idnt"),