]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/Regressions/secitem/si-28-sectrustsettings.c
Security-57336.1.9.tar.gz
[apple/security.git] / OSX / sec / Security / Regressions / secitem / si-28-sectrustsettings.c
1 /*
2 * Copyright (c) 2008-2010,2012 Apple Inc. All Rights Reserved.
3 */
4
5 #include <CoreFoundation/CoreFoundation.h>
6 #include <Security/SecCertificate.h>
7 #include <Security/SecCertificatePriv.h>
8 #include <Security/SecTrustStore.h>
9 #include <Security/SecItemPriv.h>
10 #include <stdlib.h>
11 #include <unistd.h>
12
13 #include "Security_regressions.h"
14
15 /*
16 subject= /C=US/ST=California/L=Cupertino/O=Apple Computer, Inc./OU=Apple Internet Services/OU=Terms of use at www.verisign.com/rpa (c)00/CN=store.apple.com
17 issuer= /O=VeriSign Trust Network/OU=VeriSign, Inc./OU=VeriSign International Server CA - Class 3/OU=www.verisign.com/CPS Incorp.by Ref. LIABILITY LTD.(c)97 VeriSign
18 serial=4450E623F57E734FF85C1DEEFB976C86
19 */
20 static const uint8_t _c0[] = {
21 0x30, 0x82, 0x04, 0x82, 0x30, 0x82, 0x03, 0xeb,
22 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x10, 0x44,
23 0x50, 0xe6, 0x23, 0xf5, 0x7e, 0x73, 0x4f, 0xf8,
24 0x5c, 0x1d, 0xee, 0xfb, 0x97, 0x6c, 0x86, 0x30,
25 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
26 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x81,
27 0xba, 0x31, 0x1f, 0x30, 0x1d, 0x06, 0x03, 0x55,
28 0x04, 0x0a, 0x13, 0x16, 0x56, 0x65, 0x72, 0x69,
29 0x53, 0x69, 0x67, 0x6e, 0x20, 0x54, 0x72, 0x75,
30 0x73, 0x74, 0x20, 0x4e, 0x65, 0x74, 0x77, 0x6f,
31 0x72, 0x6b, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03,
32 0x55, 0x04, 0x0b, 0x13, 0x0e, 0x56, 0x65, 0x72,
33 0x69, 0x53, 0x69, 0x67, 0x6e, 0x2c, 0x20, 0x49,
34 0x6e, 0x63, 0x2e, 0x31, 0x33, 0x30, 0x31, 0x06,
35 0x03, 0x55, 0x04, 0x0b, 0x13, 0x2a, 0x56, 0x65,
36 0x72, 0x69, 0x53, 0x69, 0x67, 0x6e, 0x20, 0x49,
37 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x74, 0x69,
38 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x53, 0x65, 0x72,
39 0x76, 0x65, 0x72, 0x20, 0x43, 0x41, 0x20, 0x2d,
40 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x33,
41 0x31, 0x49, 0x30, 0x47, 0x06, 0x03, 0x55, 0x04,
42 0x0b, 0x13, 0x40, 0x77, 0x77, 0x77, 0x2e, 0x76,
43 0x65, 0x72, 0x69, 0x73, 0x69, 0x67, 0x6e, 0x2e,
44 0x63, 0x6f, 0x6d, 0x2f, 0x43, 0x50, 0x53, 0x20,
45 0x49, 0x6e, 0x63, 0x6f, 0x72, 0x70, 0x2e, 0x62,
46 0x79, 0x20, 0x52, 0x65, 0x66, 0x2e, 0x20, 0x4c,
47 0x49, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54, 0x59,
48 0x20, 0x4c, 0x54, 0x44, 0x2e, 0x28, 0x63, 0x29,
49 0x39, 0x37, 0x20, 0x56, 0x65, 0x72, 0x69, 0x53,
50 0x69, 0x67, 0x6e, 0x30, 0x1e, 0x17, 0x0d, 0x30,
51 0x35, 0x30, 0x33, 0x30, 0x32, 0x30, 0x30, 0x30,
52 0x30, 0x30, 0x30, 0x5a, 0x17, 0x0d, 0x30, 0x37,
53 0x30, 0x34, 0x30, 0x31, 0x32, 0x33, 0x35, 0x39,
54 0x35, 0x39, 0x5a, 0x30, 0x81, 0xc6, 0x31, 0x0b,
55 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
56 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06,
57 0x03, 0x55, 0x04, 0x08, 0x13, 0x0a, 0x43, 0x61,
58 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61,
59 0x31, 0x12, 0x30, 0x10, 0x06, 0x03, 0x55, 0x04,
60 0x07, 0x14, 0x09, 0x43, 0x75, 0x70, 0x65, 0x72,
61 0x74, 0x69, 0x6e, 0x6f, 0x31, 0x1d, 0x30, 0x1b,
62 0x06, 0x03, 0x55, 0x04, 0x0a, 0x14, 0x14, 0x41,
63 0x70, 0x70, 0x6c, 0x65, 0x20, 0x43, 0x6f, 0x6d,
64 0x70, 0x75, 0x74, 0x65, 0x72, 0x2c, 0x20, 0x49,
65 0x6e, 0x63, 0x2e, 0x31, 0x20, 0x30, 0x1e, 0x06,
66 0x03, 0x55, 0x04, 0x0b, 0x14, 0x17, 0x41, 0x70,
67 0x70, 0x6c, 0x65, 0x20, 0x49, 0x6e, 0x74, 0x65,
68 0x72, 0x6e, 0x65, 0x74, 0x20, 0x53, 0x65, 0x72,
69 0x76, 0x69, 0x63, 0x65, 0x73, 0x31, 0x33, 0x30,
70 0x31, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x14, 0x2a,
71 0x54, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66,
72 0x20, 0x75, 0x73, 0x65, 0x20, 0x61, 0x74, 0x20,
73 0x77, 0x77, 0x77, 0x2e, 0x76, 0x65, 0x72, 0x69,
74 0x73, 0x69, 0x67, 0x6e, 0x2e, 0x63, 0x6f, 0x6d,
75 0x2f, 0x72, 0x70, 0x61, 0x20, 0x28, 0x63, 0x29,
76 0x30, 0x30, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03,
77 0x55, 0x04, 0x03, 0x14, 0x0f, 0x73, 0x74, 0x6f,
78 0x72, 0x65, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65,
79 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x81, 0x9f, 0x30,
80 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
81 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81,
82 0x8d, 0x00, 0x30, 0x81, 0x89, 0x02, 0x81, 0x81,
83 0x00, 0xbf, 0x8f, 0x59, 0x14, 0xbb, 0x91, 0xa4,
84 0xe6, 0x3e, 0x75, 0xf8, 0x38, 0x36, 0xfe, 0xcd,
85 0x9e, 0x5d, 0x3f, 0x14, 0x62, 0xfc, 0xe7, 0x48,
86 0x5f, 0x7e, 0x6b, 0x6e, 0x87, 0xd2, 0x31, 0x6e,
87 0x9d, 0x19, 0x92, 0x6f, 0xe3, 0xbc, 0x7e, 0x48,
88 0xb1, 0x2f, 0x9d, 0x70, 0x2c, 0x11, 0xdf, 0x35,
89 0xd1, 0xee, 0xd2, 0xd5, 0x37, 0x92, 0x4e, 0x06,
90 0x66, 0xb3, 0xc9, 0x9c, 0x99, 0xec, 0x09, 0xc6,
91 0xc4, 0xd6, 0xe6, 0x62, 0xb7, 0x97, 0x24, 0xd8,
92 0x38, 0x40, 0xf1, 0xa0, 0x1c, 0x0f, 0xf2, 0x3d,
93 0xaf, 0x4a, 0x93, 0xba, 0x11, 0xad, 0x67, 0xc4,
94 0x4b, 0x1d, 0x74, 0x33, 0x7c, 0xb9, 0x6b, 0x2d,
95 0xc5, 0x9b, 0x6a, 0xd2, 0xf2, 0x28, 0x08, 0x05,
96 0x18, 0x7d, 0xf0, 0xde, 0x28, 0x61, 0xf1, 0x81,
97 0xd5, 0x56, 0x4f, 0x20, 0x6e, 0xf3, 0x34, 0x89,
98 0x67, 0xd3, 0xa7, 0x09, 0xda, 0xc7, 0x89, 0x4d,
99 0xe1, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82,
100 0x01, 0x79, 0x30, 0x82, 0x01, 0x75, 0x30, 0x09,
101 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04, 0x02, 0x30,
102 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f,
103 0x04, 0x04, 0x03, 0x02, 0x05, 0xa0, 0x30, 0x46,
104 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x3f, 0x30,
105 0x3d, 0x30, 0x3b, 0xa0, 0x39, 0xa0, 0x37, 0x86,
106 0x35, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f,
107 0x63, 0x72, 0x6c, 0x2e, 0x76, 0x65, 0x72, 0x69,
108 0x73, 0x69, 0x67, 0x6e, 0x2e, 0x63, 0x6f, 0x6d,
109 0x2f, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x33, 0x49,
110 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x74, 0x69,
111 0x6f, 0x6e, 0x61, 0x6c, 0x53, 0x65, 0x72, 0x76,
112 0x65, 0x72, 0x2e, 0x63, 0x72, 0x6c, 0x30, 0x44,
113 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x3d, 0x30,
114 0x3b, 0x30, 0x39, 0x06, 0x0b, 0x60, 0x86, 0x48,
115 0x01, 0x86, 0xf8, 0x45, 0x01, 0x07, 0x17, 0x03,
116 0x30, 0x2a, 0x30, 0x28, 0x06, 0x08, 0x2b, 0x06,
117 0x01, 0x05, 0x05, 0x07, 0x02, 0x01, 0x16, 0x1c,
118 0x68, 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f,
119 0x77, 0x77, 0x77, 0x2e, 0x76, 0x65, 0x72, 0x69,
120 0x73, 0x69, 0x67, 0x6e, 0x2e, 0x63, 0x6f, 0x6d,
121 0x2f, 0x72, 0x70, 0x61, 0x30, 0x28, 0x06, 0x03,
122 0x55, 0x1d, 0x25, 0x04, 0x21, 0x30, 0x1f, 0x06,
123 0x09, 0x60, 0x86, 0x48, 0x01, 0x86, 0xf8, 0x42,
124 0x04, 0x01, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05,
125 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06,
126 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x30, 0x34,
127 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07,
128 0x01, 0x01, 0x04, 0x28, 0x30, 0x26, 0x30, 0x24,
129 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07,
130 0x30, 0x01, 0x86, 0x18, 0x68, 0x74, 0x74, 0x70,
131 0x3a, 0x2f, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2e,
132 0x76, 0x65, 0x72, 0x69, 0x73, 0x69, 0x67, 0x6e,
133 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x6d, 0x06, 0x08,
134 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x01, 0x0c,
135 0x04, 0x61, 0x30, 0x5f, 0xa1, 0x5d, 0xa0, 0x5b,
136 0x30, 0x59, 0x30, 0x57, 0x30, 0x55, 0x16, 0x09,
137 0x69, 0x6d, 0x61, 0x67, 0x65, 0x2f, 0x67, 0x69,
138 0x66, 0x30, 0x21, 0x30, 0x1f, 0x30, 0x07, 0x06,
139 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x04, 0x14,
140 0x8f, 0xe5, 0xd3, 0x1a, 0x86, 0xac, 0x8d, 0x8e,
141 0x6b, 0xc3, 0xcf, 0x80, 0x6a, 0xd4, 0x48, 0x18,
142 0x2c, 0x7b, 0x19, 0x2e, 0x30, 0x25, 0x16, 0x23,
143 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6c,
144 0x6f, 0x67, 0x6f, 0x2e, 0x76, 0x65, 0x72, 0x69,
145 0x73, 0x69, 0x67, 0x6e, 0x2e, 0x63, 0x6f, 0x6d,
146 0x2f, 0x76, 0x73, 0x6c, 0x6f, 0x67, 0x6f, 0x2e,
147 0x67, 0x69, 0x66, 0x30, 0x0d, 0x06, 0x09, 0x2a,
148 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05,
149 0x05, 0x00, 0x03, 0x81, 0x81, 0x00, 0x01, 0x5e,
150 0x47, 0x3c, 0x5f, 0x38, 0x4f, 0x4d, 0x64, 0xf1,
151 0x33, 0x13, 0xd3, 0xcf, 0x80, 0xf9, 0x88, 0x93,
152 0xba, 0x44, 0x7b, 0xf0, 0xbd, 0x60, 0x96, 0x39,
153 0xa8, 0xc5, 0x76, 0x18, 0x01, 0xa7, 0x03, 0x53,
154 0x8b, 0x92, 0xda, 0x97, 0xaa, 0x85, 0xc7, 0xb7,
155 0x7d, 0x58, 0x83, 0x68, 0x4a, 0xd9, 0x54, 0x78,
156 0x7f, 0xa0, 0xe9, 0x8f, 0xc5, 0xb4, 0x3a, 0xb7,
157 0x3c, 0xa1, 0x70, 0x40, 0xac, 0xc2, 0xc6, 0x5b,
158 0xbd, 0x70, 0x90, 0xb9, 0xc6, 0x7d, 0x7e, 0x49,
159 0xe4, 0xbd, 0xc1, 0x5d, 0x1a, 0x0f, 0x9e, 0x0a,
160 0x93, 0xfd, 0xc7, 0x7a, 0x8b, 0x9c, 0x61, 0x61,
161 0x34, 0x02, 0xcc, 0x68, 0xdd, 0x2b, 0x29, 0xbc,
162 0x83, 0x8d, 0x7a, 0x8b, 0x22, 0xb9, 0x1e, 0x79,
163 0x3a, 0x5a, 0xc6, 0xda, 0xb3, 0xaf, 0xaf, 0x0b,
164 0x41, 0x16, 0xda, 0xd2, 0x8e, 0xcd, 0xc1, 0xc0,
165 0x43, 0xfc, 0xb3, 0x10, 0xb7, 0x27
166 };
167
168 #define CFReleaseSafe(CF) { CFTypeRef _cf = (CF); if (_cf) CFRelease(_cf); }
169
170 static void tests(void)
171 {
172 SecCertificateRef cert0;
173 isnt(cert0 = SecCertificateCreateWithBytes(NULL, _c0, sizeof(_c0)),
174 NULL, "create cert0");
175 SecTrustStoreRef user_store;
176 isnt(user_store = SecTrustStoreForDomain(kSecTrustStoreDomainUser),
177 NULL, "get user trust settings store handle");
178 ok(!SecTrustStoreContains(user_store, cert0),
179 "cert0 is not yet present");
180 ok_status(SecTrustStoreSetTrustSettings(user_store, cert0, NULL),
181 "make cert0 trusted for anything");
182 ok(SecTrustStoreContains(user_store, cert0),
183 "cert0 is present");
184 ok_status(SecTrustStoreSetTrustSettings(user_store, cert0, NULL),
185 "make cert0 trusted for anything - again, should update now");
186 ok(SecTrustStoreContains(user_store, cert0),
187 "cert0 is still present");
188 ok_status(SecTrustStoreRemoveCertificate(user_store, cert0),
189 "removing cert0");
190 ok(!SecTrustStoreContains(user_store, cert0),
191 "cert0 is no longer present");
192
193 /* Adding again...*/
194 ok_status(SecTrustStoreSetTrustSettings(user_store, cert0, NULL),
195 "make cert0 trusted for anything");
196 ok(SecTrustStoreContains(user_store, cert0),
197 "cert0 is present");
198
199 /* Remove it */
200 ok_status(SecTrustStoreRemoveCertificate(user_store, cert0),
201 "removing cert0");
202 ok(!SecTrustStoreContains(user_store, cert0),
203 "cert0 is no longer present");
204
205 CFReleaseSafe(cert0);
206 }
207
208 int si_28_sectrustsettings(int argc, char *const *argv)
209 {
210 plan_tests(13);
211
212 tests();
213
214 return 0;
215 }