]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_cdsa_client/lib/dl_standard.cpp
Security-59754.41.1.tar.gz
[apple/security.git] / OSX / libsecurity_cdsa_client / lib / dl_standard.cpp
1 /*
2 * Copyright (c) 2000-2004,2011,2014 Apple Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // mds_standard - standard-defined MDS record types
21 //
22 #include <security_cdsa_client/dl_standard.h>
23 #include <security_cdsa_client/dlquery.h>
24
25
26 namespace Security {
27 namespace CssmClient {
28
29
30 //
31 // CDSA Common relation (one record per module)
32 //
33 static const char * const commonAttributes[] = {
34 "PrintName",
35 "Alias",
36 NULL
37 };
38 DLCommonFields::DLCommonFields(const char * const * names)
39 : Record(commonAttributes)
40 {
41 addAttributes(names);
42 }
43
44 string DLCommonFields::printName() const { return mAttributes[0]; }
45 string DLCommonFields::alias() const
46 { return mAttributes[1].size() ? string(mAttributes[1]) : "(no value)"; }
47
48
49 //
50 // The all-record-types pseudo-record
51 //
52 AllDLRecords::AllDLRecords()
53 : DLCommonFields(NULL)
54 { }
55
56
57 //
58 // CDSA Generic record attributes
59 //
60 static const char * const genericAttributes[] = {
61 NULL
62 };
63 GenericRecord::GenericRecord()
64 : DLCommonFields(genericAttributes)
65 {
66 }
67
68
69 //
70 // Apple "Generic Password" records
71 //
72 static const char * const genericPasswordAttributes[] = {
73 // if you find yourself here, you should add the attributes and their functions
74 NULL
75 };
76 GenericPasswordRecord::GenericPasswordRecord()
77 : DLCommonFields(genericPasswordAttributes)
78 {
79 }
80
81
82 //
83 // Common key attributes
84 //
85 static const char * const keyAttributes[] = {
86 "KeyClass",
87 "KeyType",
88 "KeySizeInBits",
89 "EffectiveKeySize",
90 "Label",
91 "ApplicationTag",
92 "Permanent",
93 "Private",
94 "Modifiable",
95 "Sensitive",
96 "AlwaysSensitive",
97 "Extractable",
98 "NeverExtractable",
99 "Encrypt",
100 "Decrypt",
101 "Derive",
102 "Sign",
103 "Verify",
104 "Wrap",
105 "Unwrap",
106 NULL
107 };
108
109 KeyRecord::KeyRecord()
110 : DLCommonFields(keyAttributes)
111 {
112 }
113
114 uint32 KeyRecord::keyClass() const { return mAttributes[2]; }
115 uint32 KeyRecord::type() const { return mAttributes[3]; }
116 uint32 KeyRecord::size() const { return mAttributes[4]; }
117 uint32 KeyRecord::effectiveSize() const { return mAttributes[5]; }
118 const CssmData &KeyRecord::label() const { return mAttributes[6]; }
119 const CssmData &KeyRecord::applicationTag() const { return mAttributes[7]; }
120 bool KeyRecord::isPermanent() const { return mAttributes[8]; }
121 bool KeyRecord::isPrivate() const { return mAttributes[9]; }
122 bool KeyRecord::isModifiable() const { return mAttributes[10]; }
123 bool KeyRecord::isSensitive() const { return mAttributes[11]; }
124 bool KeyRecord::wasAlwaysSensitive() const { return mAttributes[12]; }
125 bool KeyRecord::isExtractable() const { return mAttributes[13]; }
126 bool KeyRecord::wasNeverExtractable() const { return mAttributes[14]; }
127 bool KeyRecord::canEncrypt() const { return mAttributes[15]; }
128 bool KeyRecord::canDecrypt() const { return mAttributes[16]; }
129 bool KeyRecord::canDerive() const { return mAttributes[17]; }
130 bool KeyRecord::canSign() const { return mAttributes[18]; }
131 bool KeyRecord::canVerify() const { return mAttributes[19]; }
132 bool KeyRecord::canWrap() const { return mAttributes[20]; }
133 bool KeyRecord::canUnwrap() const { return mAttributes[21]; }
134
135
136 //
137 // Certificate attributes
138 //
139 static const char * const certAttributes[] = {
140 "CertType",
141 "CertEncoding",
142 "Subject",
143 "Issuer",
144 "SerialNumber",
145 "SubjectKeyIdentifier",
146 "PublicKeyHash",
147 NULL
148 };
149
150 X509CertRecord::X509CertRecord()
151 : DLCommonFields(certAttributes)
152 {
153 }
154
155 CSSM_CERT_TYPE X509CertRecord::type() const { return mAttributes[2]; }
156 CSSM_CERT_ENCODING X509CertRecord::encoding() const { return mAttributes[3]; }
157 const CssmData &X509CertRecord::subject() const { return mAttributes[4]; }
158 const CssmData &X509CertRecord::issuer() const { return mAttributes[5]; }
159 const CssmData &X509CertRecord::serial() const { return mAttributes[6]; }
160 const CssmData &X509CertRecord::subjectKeyIdentifier() const { return mAttributes[7]; }
161 const CssmData &X509CertRecord::publicKeyHash() const { return mAttributes[8]; }
162
163
164 //
165 // UnlockReferral attributes
166 //
167 static const char * const unlockReferralAttributes[] = {
168 "Type",
169 "DbName",
170 "DbNetname",
171 "DbGuid",
172 "DbSSID",
173 "DbSSType",
174 "KeyLabel",
175 "KeyAppTag",
176 NULL
177 };
178
179 UnlockReferralRecord::UnlockReferralRecord()
180 : DLCommonFields(unlockReferralAttributes)
181 {
182 }
183
184 uint32 UnlockReferralRecord::type() const { return mAttributes[2]; }
185 string UnlockReferralRecord::dbName() const { return mAttributes[3]; }
186 const CssmData &UnlockReferralRecord::dbNetname() const { return mAttributes[4]; }
187 const Guid &UnlockReferralRecord::dbGuid() const { return mAttributes[5]; }
188 uint32 UnlockReferralRecord::dbSSID() const { return mAttributes[6]; }
189 uint32 UnlockReferralRecord::dbSSType() const { return mAttributes[7]; }
190 const CssmData &UnlockReferralRecord::keyLabel() const { return mAttributes[8]; }
191 const CssmData &UnlockReferralRecord::keyApplicationTag() const { return mAttributes[9]; }
192
193
194 } // end namespace CssmClient
195 } // end namespace Security