2 * parseTrustedRootList.cpp - parse the contents of a TrustedRootList record.
4 * Created May 26 2005 by dmitch.
11 #include "parseTrustedRootList.h"
12 #include "rootUtils.h"
14 #include <Security/TrustSettingsSchema.h> /* private header */
15 #include <Security/SecTrustSettings.h>
16 #include <CoreFoundation/CoreFoundation.h>
17 #include <security_utilities/cfutilities.h>
20 * Data is obtained from a SecKeychainItemRef; it's expected to be the XML encoding
21 * of a CFPropertyList (specifically of a CFDictionaryRef).
23 int parseTrustedRootList(
26 /* First decode the XML */
27 CFStringRef errStr
= NULL
;
28 CFRef
<CFPropertyListRef
> rawPropList
;
32 rawPropList
.take(CFPropertyListCreateFromXMLData(
35 kCFPropertyListImmutable
,
37 CFPropertyListRef cfRawPropList
= rawPropList
;
38 if(cfRawPropList
== NULL
) {
39 printf("***parseTrustedRootList: Error decoding TrustedRootList XML data\n");
41 printf("Error string: "); CFShow(errStr
);
50 CFDictionaryRef topDict
= (CFDictionaryRef
)cfRawPropList
;
51 if(CFGetTypeID(topDict
) != CFDictionaryGetTypeID()) {
52 printf("***parseTrustedRootList: malformed propList");
56 printf("=== Parsed User Trust Record ===\n");
58 /* that dictionary has two entries */
59 CFNumberRef cfVers
= (CFNumberRef
)CFDictionaryGetValue(topDict
, kTrustRecordVersion
);
60 if((cfVers
== NULL
) || (CFGetTypeID(cfVers
) != CFNumberGetTypeID())) {
61 printf("***parseTrustedRootList: malformed version");
65 if(!CFNumberGetValue(cfVers
, kCFNumberSInt32Type
, &vers
)) {
66 printf("***parseTrustedRootList: malformed version");
69 printf("Version = %ld\n", vers
);
73 CFDictionaryRef certsDict
= (CFDictionaryRef
)CFDictionaryGetValue(topDict
,
74 kTrustRecordTrustList
);
75 if((certsDict
== NULL
) || (CFGetTypeID(certsDict
) != CFDictionaryGetTypeID())) {
76 printf("***parseTrustedRootList: malformed mTrustArray");
80 CFIndex numCerts
= CFDictionaryGetCount(certsDict
);
81 const void *dictKeys
[numCerts
];
82 const void *dictValues
[numCerts
];
83 CFDictionaryGetKeysAndValues(certsDict
, dictKeys
, dictValues
);
87 CFDictionaryRef ucDict
;
88 CFArrayRef usageConstraints
;
90 CFIndex numUsageConstraints
;
91 CFStringRef policyStr
;
95 printf("Number of cert entries: %ld\n", numCerts
);
97 for(CFIndex dex
=0; dex
<numCerts
; dex
++) {
98 printf("Cert %ld:\n", dex
);
101 /* per-cert key is ASCII representation of SHA1(cert) */
102 CFStringRef certHashStr
= (CFStringRef
)dictKeys
[dex
];
103 if(CFGetTypeID(certHashStr
) != CFStringGetTypeID()) {
104 printf("***parseTrustedRootList: malformed certsDict key");
108 indent(); printf("Cert Hash : ");
109 printCfStr(certHashStr
);
112 /* get per-cert dictionary */
113 CFDictionaryRef certDict
= (CFDictionaryRef
)dictValues
[dex
];
114 if(CFGetTypeID(certDict
) != CFDictionaryGetTypeID()) {
115 printf("***parseTrustedRootList: malformed certDict");
121 * That dictionary has exactly four entries...but the first
123 * First, the issuer. This is in non-normalized form.
125 cfd
= (CFDataRef
)CFDictionaryGetValue(certDict
, kTrustRecordIssuer
);
127 printf("***parseTrustedRootList: missing issuer");
131 if(CFGetTypeID(cfd
) != CFDataGetTypeID()) {
132 printf("***parseTrustedRootList: malformed issuer");
137 if(CFDataGetLength(cfd
) == 0) {
138 /* that's for a default setting */
139 printf("Issuer : <none>\n");
142 printf("Issuer : \n");
143 indentIncr(); printCfName(cfd
, parser
);
148 cfd
= (CFDataRef
)CFDictionaryGetValue(certDict
, kTrustRecordSerialNumber
);
150 printf("***parseTrustedRootList: missing serial number");
154 if(CFGetTypeID(cfd
) != CFDataGetTypeID()) {
155 printf("***parseTrustedRootList: malformed serial number");
159 indent(); printData("Serial Number ", cfd
, PD_Hex
, parser
);
161 /* modification date */
162 modDate
= (CFDateRef
)CFDictionaryGetValue(certDict
, kTrustRecordModDate
);
163 if(modDate
== NULL
) {
164 printf("***parseTrustedRootList: missing modification date");
168 if(CFGetTypeID(modDate
) != CFDateGetTypeID()) {
169 printf("***parseTrustedRootList: malformed modification date");
174 printf("Modification Date : ");
175 printCFDate(modDate
);
179 * Array of usageConstraint dictionaries - the array itself must be there,
180 * though it might be empty.
182 usageConstraints
= (CFArrayRef
)CFDictionaryGetValue(certDict
,
183 kTrustRecordTrustSettings
);
184 numUsageConstraints
= 0;
185 if(usageConstraints
!= NULL
) {
186 if(CFGetTypeID(usageConstraints
) != CFArrayGetTypeID()) {
187 printf("***parseTrustedRootList: malformed Usage Constraints array");
192 numUsageConstraints
= CFArrayGetCount(usageConstraints
);
194 indent(); printf("Num usage constraints : ");
195 if(usageConstraints
) {
196 printf("%ld\n", numUsageConstraints
);
199 printf("<not present>\n");
202 /* grind thru the usageConstraint dictionaries */
203 for(CFIndex apDex
=0; apDex
<numUsageConstraints
; apDex
++) {
204 indent(); printf("Usage constraint %ld:\n", apDex
);
207 ucDict
= (CFDictionaryRef
)CFArrayGetValueAtIndex(usageConstraints
, apDex
);
208 if(CFGetTypeID(ucDict
) != CFDictionaryGetTypeID()) {
209 printf("***parseTrustedRootList: malformed usageConstraint dictionary");
214 /* policy - optional - an OID */
215 certPolicy
= (CFDataRef
)CFDictionaryGetValue(ucDict
, kSecTrustSettingsPolicy
);
216 if(certPolicy
!= NULL
) {
217 if(CFGetTypeID(certPolicy
) != CFDataGetTypeID()) {
218 printf("***parseTrustedRootList: malformed certPolicy");
222 indent(); printData("Policy OID ", certPolicy
, PD_OID
, parser
);
225 /* app - optional - data - opaque */
226 certApp
= (CFDataRef
)CFDictionaryGetValue(ucDict
, kSecTrustSettingsApplication
);
227 if(certApp
!= NULL
) {
228 if(CFGetTypeID(certApp
) != CFDataGetTypeID()) {
229 printf("***parseTrustedRootList: malformed certApp");
233 indent(); printData("Application ", certApp
, PD_Hex
, parser
);
237 policyStr
= (CFStringRef
)CFDictionaryGetValue(ucDict
, kSecTrustSettingsPolicyString
);
238 if(policyStr
!= NULL
) {
239 if(CFGetTypeID(policyStr
) != CFStringGetTypeID()) {
240 printf("***parseTrustedRootList: malformed policyStr");
244 indent(); printf("Policy String : ");
245 printCfStr(policyStr
); printf("\n");
249 cfNum
= (CFNumberRef
)CFDictionaryGetValue(ucDict
, kSecTrustSettingsAllowedError
);
251 if(CFGetTypeID(cfNum
) != CFNumberGetTypeID()) {
252 printf("***parseTrustedRootList: malformed allowedError");
256 indent(); printf("Allowed Error : ");
257 printCssmErr(cfNum
); printf("\n");
261 cfNum
= (CFNumberRef
)CFDictionaryGetValue(ucDict
, kSecTrustSettingsResult
);
263 if(CFGetTypeID(cfNum
) != CFNumberGetTypeID()) {
264 printf("***parseTrustedRootList: malformed Result");
268 indent(); printf("Result Type : ");
269 printResult(cfNum
); printf("\n");
273 cfNum
= (CFNumberRef
)CFDictionaryGetValue(ucDict
, kSecTrustSettingsKeyUsage
);
275 if(CFGetTypeID(cfNum
) != CFNumberGetTypeID()) {
276 printf("***parseTrustedRootList: malformed keyUsage");
280 indent(); printf("Key Usage : ");
281 printKeyUsage(cfNum
); printf("\n");
290 } /* for each cert dictionary in top-level array */
292 printf("=== End of Parsed User Trust Record ===\n");