2 * Copyright (c) 2007-2010,2012-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 #include <CoreFoundation/CoreFoundation.h>
26 #include <Security/SecCertificate.h>
27 #include <Security/SecCertificatePriv.h>
28 #include <Security/SecCertificateInternal.h>
29 #include <Security/SecKey.h>
30 #include <Security/SecRSAKey.h>
31 #include <Security/SecItem.h>
32 #include <Security/SecItemPriv.h>
33 #include <Security/SecIdentityPriv.h>
34 #include <Security/SecIdentity.h>
35 #include <utilities/array_size.h>
39 #include "Security_regressions.h"
41 #define CFReleaseNull(CF) { CFTypeRef _cf = (CF); if (_cf) { (CF) = NULL; CFRelease(_cf); } }
43 static const uint8_t _c0
[] = {
44 0x30, 0x82, 0x04, 0xbb, 0x30, 0x82, 0x03, 0xa3,
45 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x02,
46 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
47 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30,
48 0x62, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55,
49 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x13,
50 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13,
51 0x0a, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20, 0x49,
52 0x6e, 0x63, 0x2e, 0x31, 0x26, 0x30, 0x24, 0x06,
53 0x03, 0x55, 0x04, 0x0b, 0x13, 0x1d, 0x41, 0x70,
54 0x70, 0x6c, 0x65, 0x20, 0x43, 0x65, 0x72, 0x74,
55 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,
56 0x6e, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72,
57 0x69, 0x74, 0x79, 0x31, 0x16, 0x30, 0x14, 0x06,
58 0x03, 0x55, 0x04, 0x03, 0x13, 0x0d, 0x41, 0x70,
59 0x70, 0x6c, 0x65, 0x20, 0x52, 0x6f, 0x6f, 0x74,
60 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x30,
61 0x36, 0x30, 0x34, 0x32, 0x35, 0x32, 0x31, 0x34,
62 0x30, 0x33, 0x36, 0x5a, 0x17, 0x0d, 0x33, 0x35,
63 0x30, 0x32, 0x30, 0x39, 0x32, 0x31, 0x34, 0x30,
64 0x33, 0x36, 0x5a, 0x30, 0x62, 0x31, 0x0b, 0x30,
65 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02,
66 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03,
67 0x55, 0x04, 0x0a, 0x13, 0x0a, 0x41, 0x70, 0x70,
68 0x6c, 0x65, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x31,
69 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x0b,
70 0x13, 0x1d, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20,
71 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63,
72 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x41, 0x75,
73 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x31,
74 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x03,
75 0x13, 0x0d, 0x41, 0x70, 0x70, 0x6c, 0x65, 0x20,
76 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x30,
77 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a,
78 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
79 0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30,
80 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00,
81 0xe4, 0x91, 0xa9, 0x09, 0x1f, 0x91, 0xdb, 0x1e,
82 0x47, 0x50, 0xeb, 0x05, 0xed, 0x5e, 0x79, 0x84,
83 0x2d, 0xeb, 0x36, 0xa2, 0x57, 0x4c, 0x55, 0xec,
84 0x8b, 0x19, 0x89, 0xde, 0xf9, 0x4b, 0x6c, 0xf5,
85 0x07, 0xab, 0x22, 0x30, 0x02, 0xe8, 0x18, 0x3e,
86 0xf8, 0x50, 0x09, 0xd3, 0x7f, 0x41, 0xa8, 0x98,
87 0xf9, 0xd1, 0xca, 0x66, 0x9c, 0x24, 0x6b, 0x11,
88 0xd0, 0xa3, 0xbb, 0xe4, 0x1b, 0x2a, 0xc3, 0x1f,
89 0x95, 0x9e, 0x7a, 0x0c, 0xa4, 0x47, 0x8b, 0x5b,
90 0xd4, 0x16, 0x37, 0x33, 0xcb, 0xc4, 0x0f, 0x4d,
91 0xce, 0x14, 0x69, 0xd1, 0xc9, 0x19, 0x72, 0xf5,
92 0x5d, 0x0e, 0xd5, 0x7f, 0x5f, 0x9b, 0xf2, 0x25,
93 0x03, 0xba, 0x55, 0x8f, 0x4d, 0x5d, 0x0d, 0xf1,
94 0x64, 0x35, 0x23, 0x15, 0x4b, 0x15, 0x59, 0x1d,
95 0xb3, 0x94, 0xf7, 0xf6, 0x9c, 0x9e, 0xcf, 0x50,
96 0xba, 0xc1, 0x58, 0x50, 0x67, 0x8f, 0x08, 0xb4,
97 0x20, 0xf7, 0xcb, 0xac, 0x2c, 0x20, 0x6f, 0x70,
98 0xb6, 0x3f, 0x01, 0x30, 0x8c, 0xb7, 0x43, 0xcf,
99 0x0f, 0x9d, 0x3d, 0xf3, 0x2b, 0x49, 0x28, 0x1a,
100 0xc8, 0xfe, 0xce, 0xb5, 0xb9, 0x0e, 0xd9, 0x5e,
101 0x1c, 0xd6, 0xcb, 0x3d, 0xb5, 0x3a, 0xad, 0xf4,
102 0x0f, 0x0e, 0x00, 0x92, 0x0b, 0xb1, 0x21, 0x16,
103 0x2e, 0x74, 0xd5, 0x3c, 0x0d, 0xdb, 0x62, 0x16,
104 0xab, 0xa3, 0x71, 0x92, 0x47, 0x53, 0x55, 0xc1,
105 0xaf, 0x2f, 0x41, 0xb3, 0xf8, 0xfb, 0xe3, 0x70,
106 0xcd, 0xe6, 0xa3, 0x4c, 0x45, 0x7e, 0x1f, 0x4c,
107 0x6b, 0x50, 0x96, 0x41, 0x89, 0xc4, 0x74, 0x62,
108 0x0b, 0x10, 0x83, 0x41, 0x87, 0x33, 0x8a, 0x81,
109 0xb1, 0x30, 0x58, 0xec, 0x5a, 0x04, 0x32, 0x8c,
110 0x68, 0xb3, 0x8f, 0x1d, 0xde, 0x65, 0x73, 0xff,
111 0x67, 0x5e, 0x65, 0xbc, 0x49, 0xd8, 0x76, 0x9f,
112 0x33, 0x14, 0x65, 0xa1, 0x77, 0x94, 0xc9, 0x2d,
113 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01,
114 0x7a, 0x30, 0x82, 0x01, 0x76, 0x30, 0x0e, 0x06,
115 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04,
116 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x0f, 0x06,
117 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04,
118 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d,
119 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04,
120 0x14, 0x2b, 0xd0, 0x69, 0x47, 0x94, 0x76, 0x09,
121 0xfe, 0xf4, 0x6b, 0x8d, 0x2e, 0x40, 0xa6, 0xf7,
122 0x47, 0x4d, 0x7f, 0x08, 0x5e, 0x30, 0x1f, 0x06,
123 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16,
124 0x80, 0x14, 0x2b, 0xd0, 0x69, 0x47, 0x94, 0x76,
125 0x09, 0xfe, 0xf4, 0x6b, 0x8d, 0x2e, 0x40, 0xa6,
126 0xf7, 0x47, 0x4d, 0x7f, 0x08, 0x5e, 0x30, 0x82,
127 0x01, 0x11, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04,
128 0x82, 0x01, 0x08, 0x30, 0x82, 0x01, 0x04, 0x30,
129 0x82, 0x01, 0x00, 0x06, 0x09, 0x2a, 0x86, 0x48,
130 0x86, 0xf7, 0x63, 0x64, 0x05, 0x01, 0x30, 0x81,
131 0xf2, 0x30, 0x2a, 0x06, 0x08, 0x2b, 0x06, 0x01,
132 0x05, 0x05, 0x07, 0x02, 0x01, 0x16, 0x1e, 0x68,
133 0x74, 0x74, 0x70, 0x73, 0x3a, 0x2f, 0x2f, 0x77,
134 0x77, 0x77, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65,
135 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x61, 0x70, 0x70,
136 0x6c, 0x65, 0x63, 0x61, 0x2f, 0x30, 0x81, 0xc3,
137 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07,
138 0x02, 0x02, 0x30, 0x81, 0xb6, 0x1a, 0x81, 0xb3,
139 0x52, 0x65, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65,
140 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x69, 0x73,
141 0x20, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69,
142 0x63, 0x61, 0x74, 0x65, 0x20, 0x62, 0x79, 0x20,
143 0x61, 0x6e, 0x79, 0x20, 0x70, 0x61, 0x72, 0x74,
144 0x79, 0x20, 0x61, 0x73, 0x73, 0x75, 0x6d, 0x65,
145 0x73, 0x20, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74,
146 0x61, 0x6e, 0x63, 0x65, 0x20, 0x6f, 0x66, 0x20,
147 0x74, 0x68, 0x65, 0x20, 0x74, 0x68, 0x65, 0x6e,
148 0x20, 0x61, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61,
149 0x62, 0x6c, 0x65, 0x20, 0x73, 0x74, 0x61, 0x6e,
150 0x64, 0x61, 0x72, 0x64, 0x20, 0x74, 0x65, 0x72,
151 0x6d, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x63,
152 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e,
153 0x73, 0x20, 0x6f, 0x66, 0x20, 0x75, 0x73, 0x65,
154 0x2c, 0x20, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66,
155 0x69, 0x63, 0x61, 0x74, 0x65, 0x20, 0x70, 0x6f,
156 0x6c, 0x69, 0x63, 0x79, 0x20, 0x61, 0x6e, 0x64,
157 0x20, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69,
158 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x70,
159 0x72, 0x61, 0x63, 0x74, 0x69, 0x63, 0x65, 0x20,
160 0x73, 0x74, 0x61, 0x74, 0x65, 0x6d, 0x65, 0x6e,
161 0x74, 0x73, 0x2e, 0x30, 0x0d, 0x06, 0x09, 0x2a,
162 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05,
163 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x5c,
164 0x36, 0x99, 0x4c, 0x2d, 0x78, 0xb7, 0xed, 0x8c,
165 0x9b, 0xdc, 0xf3, 0x77, 0x9b, 0xf2, 0x76, 0xd2,
166 0x77, 0x30, 0x4f, 0xc1, 0x1f, 0x85, 0x83, 0x85,
167 0x1b, 0x99, 0x3d, 0x47, 0x37, 0xf2, 0xa9, 0x9b,
168 0x40, 0x8e, 0x2c, 0xd4, 0xb1, 0x90, 0x12, 0xd8,
169 0xbe, 0xf4, 0x73, 0x9b, 0xee, 0xd2, 0x64, 0x0f,
170 0xcb, 0x79, 0x4f, 0x34, 0xd8, 0xa2, 0x3e, 0xf9,
171 0x78, 0xff, 0x6b, 0xc8, 0x07, 0xec, 0x7d, 0x39,
172 0x83, 0x8b, 0x53, 0x20, 0xd3, 0x38, 0xc4, 0xb1,
173 0xbf, 0x9a, 0x4f, 0x0a, 0x6b, 0xff, 0x2b, 0xfc,
174 0x59, 0xa7, 0x05, 0x09, 0x7c, 0x17, 0x40, 0x56,
175 0x11, 0x1e, 0x74, 0xd3, 0xb7, 0x8b, 0x23, 0x3b,
176 0x47, 0xa3, 0xd5, 0x6f, 0x24, 0xe2, 0xeb, 0xd1,
177 0xb7, 0x70, 0xdf, 0x0f, 0x45, 0xe1, 0x27, 0xca,
178 0xf1, 0x6d, 0x78, 0xed, 0xe7, 0xb5, 0x17, 0x17,
179 0xa8, 0xdc, 0x7e, 0x22, 0x35, 0xca, 0x25, 0xd5,
180 0xd9, 0x0f, 0xd6, 0x6b, 0xd4, 0xa2, 0x24, 0x23,
181 0x11, 0xf7, 0xa1, 0xac, 0x8f, 0x73, 0x81, 0x60,
182 0xc6, 0x1b, 0x5b, 0x09, 0x2f, 0x92, 0xb2, 0xf8,
183 0x44, 0x48, 0xf0, 0x60, 0x38, 0x9e, 0x15, 0xf5,
184 0x3d, 0x26, 0x67, 0x20, 0x8a, 0x33, 0x6a, 0xf7,
185 0x0d, 0x82, 0xcf, 0xde, 0xeb, 0xa3, 0x2f, 0xf9,
186 0x53, 0x6a, 0x5b, 0x64, 0xc0, 0x63, 0x33, 0x77,
187 0xf7, 0x3a, 0x07, 0x2c, 0x56, 0xeb, 0xda, 0x0f,
188 0x21, 0x0e, 0xda, 0xba, 0x73, 0x19, 0x4f, 0xb5,
189 0xd9, 0x36, 0x7f, 0xc1, 0x87, 0x55, 0xd9, 0xa7,
190 0x99, 0xb9, 0x32, 0x42, 0xfb, 0xd8, 0xd5, 0x71,
191 0x9e, 0x7e, 0xa1, 0x52, 0xb7, 0x1b, 0xbd, 0x93,
192 0x42, 0x24, 0x12, 0x2a, 0xc7, 0x0f, 0x1d, 0xb6,
193 0x4d, 0x9c, 0x5e, 0x63, 0xc8, 0x4b, 0x80, 0x17,
194 0x50, 0xaa, 0x8a, 0xd5, 0xda, 0xe4, 0xfc, 0xd0,
195 0x09, 0x07, 0x37, 0xb0, 0x75, 0x75, 0x21,
201 friendlyName: uranusLeaf
202 localKeyID: 46 E0 8A 05 63 4D 17 3F CA A4 AA B6 5A DA CF BA 84 22 7C 23
203 subject=/CN=uranusLeaf/emailAddress=uranus@uranus.com
204 issuer=/CN=plutoCA/emailAddress=pluto@pluto.com
206 static const uint8_t _c1
[] = {
207 0x30, 0x82, 0x02, 0xe0, 0x30, 0x82, 0x01, 0xc8,
208 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x01, 0x02,
209 0x30, 0x0b, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
210 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x30, 0x32, 0x31,
211 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03,
212 0x0c, 0x07, 0x70, 0x6c, 0x75, 0x74, 0x6f, 0x43,
213 0x41, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x09, 0x2a,
214 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01,
215 0x0c, 0x0f, 0x70, 0x6c, 0x75, 0x74, 0x6f, 0x40,
216 0x70, 0x6c, 0x75, 0x74, 0x6f, 0x2e, 0x63, 0x6f,
217 0x6d, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x35, 0x31,
218 0x32, 0x31, 0x37, 0x30, 0x30, 0x30, 0x34, 0x32,
219 0x35, 0x5a, 0x17, 0x0d, 0x30, 0x36, 0x31, 0x32,
220 0x31, 0x37, 0x30, 0x30, 0x30, 0x34, 0x32, 0x35,
221 0x5a, 0x30, 0x37, 0x31, 0x13, 0x30, 0x11, 0x06,
222 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0a, 0x75, 0x72,
223 0x61, 0x6e, 0x75, 0x73, 0x4c, 0x65, 0x61, 0x66,
224 0x31, 0x20, 0x30, 0x1e, 0x06, 0x09, 0x2a, 0x86,
225 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x0c,
226 0x11, 0x75, 0x72, 0x61, 0x6e, 0x75, 0x73, 0x40,
227 0x75, 0x72, 0x61, 0x6e, 0x75, 0x73, 0x2e, 0x63,
228 0x6f, 0x6d, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d,
229 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
230 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01,
231 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82,
232 0x01, 0x01, 0x00, 0xa6, 0x82, 0x8e, 0xc6, 0x7e,
233 0xc9, 0x8c, 0x99, 0x6f, 0xb0, 0x62, 0x32, 0x35,
234 0xe7, 0xdb, 0xff, 0x34, 0x84, 0xdc, 0x72, 0xa8,
235 0xef, 0x22, 0x6f, 0x93, 0x63, 0x64, 0x80, 0x80,
236 0x5d, 0x50, 0x7e, 0xb4, 0x2e, 0x1b, 0x93, 0x93,
237 0x49, 0xca, 0xae, 0xcd, 0x34, 0x44, 0x4b, 0xd7,
238 0xfa, 0x9f, 0x3c, 0xfc, 0x9e, 0x65, 0xa9, 0xfb,
239 0x5e, 0x5d, 0x18, 0xa3, 0xf8, 0xb0, 0x08, 0xac,
240 0x8f, 0xfd, 0x03, 0xcb, 0xbd, 0x7f, 0xa0, 0x2a,
241 0xa6, 0xea, 0xca, 0xa3, 0x24, 0xef, 0x7c, 0xc3,
242 0xeb, 0x95, 0xcb, 0x90, 0x3f, 0x5e, 0xde, 0x78,
243 0xf2, 0x3d, 0x32, 0x72, 0xdb, 0x33, 0x6e, 0x9b,
244 0x52, 0x9f, 0x0c, 0x60, 0x4a, 0x24, 0xa1, 0xf6,
245 0x3b, 0x80, 0xbd, 0xa1, 0xdc, 0x40, 0x03, 0xe7,
246 0xa0, 0x59, 0x1f, 0xdb, 0xb4, 0xed, 0x57, 0xdc,
247 0x74, 0x0d, 0x99, 0x5a, 0x12, 0x74, 0x64, 0xaa,
248 0xb6, 0xa5, 0x96, 0x75, 0xf9, 0x42, 0x43, 0xe2,
249 0x52, 0xc2, 0x57, 0x23, 0x75, 0xd7, 0xa9, 0x4f,
250 0x07, 0x32, 0x99, 0xbd, 0x3d, 0x44, 0xbd, 0x04,
251 0x62, 0xe5, 0xb7, 0x2c, 0x0c, 0x11, 0xc5, 0xb2,
252 0x2e, 0xc4, 0x12, 0x1d, 0x7f, 0x42, 0x1e, 0x71,
253 0xaf, 0x39, 0x2b, 0x78, 0x47, 0x92, 0x23, 0x44,
254 0xef, 0xe3, 0xc1, 0x47, 0x69, 0x5a, 0xf1, 0x48,
255 0xaa, 0x37, 0xa4, 0x94, 0x6b, 0x96, 0xe5, 0x4b,
256 0xfd, 0x05, 0xc7, 0x9c, 0xcc, 0x38, 0xd1, 0x47,
257 0x85, 0x60, 0x7f, 0xef, 0xe9, 0x2e, 0x25, 0x08,
258 0xf8, 0x7d, 0x98, 0xdd, 0x6c, 0xeb, 0x4a, 0x32,
259 0x33, 0x44, 0x0b, 0x61, 0xb3, 0xf9, 0xae, 0x26,
260 0x41, 0xb5, 0x38, 0xdb, 0xcf, 0x13, 0x72, 0x23,
261 0x5b, 0x66, 0x20, 0x86, 0x4d, 0x24, 0xc2, 0xd4,
262 0x94, 0xde, 0xe3, 0x24, 0xb7, 0xcd, 0x75, 0x9e,
263 0x1d, 0x9f, 0xbc, 0xd0, 0x60, 0x34, 0x7d, 0xf8,
264 0xcb, 0x41, 0x39, 0x02, 0x03, 0x01, 0x00, 0x01,
265 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
266 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03,
267 0x82, 0x01, 0x01, 0x00, 0x17, 0xa5, 0x22, 0xed,
268 0xb8, 0x3e, 0x1f, 0x11, 0x99, 0xc5, 0xba, 0x28,
269 0x3e, 0x7e, 0xa6, 0xeb, 0x02, 0x81, 0x06, 0xa1,
270 0xc6, 0x80, 0xb9, 0x7e, 0x5c, 0x5a, 0x63, 0xe0,
271 0x8d, 0xeb, 0xd0, 0xec, 0x9c, 0x3a, 0x94, 0x64,
272 0x7c, 0x13, 0x54, 0x0d, 0xd6, 0xe3, 0x27, 0x88,
273 0xa6, 0xd2, 0x4b, 0x36, 0xdd, 0x2e, 0xfa, 0x94,
274 0xe5, 0x03, 0x27, 0xc9, 0xa6, 0x31, 0x02, 0xea,
275 0x40, 0x77, 0x2e, 0x93, 0xc4, 0x4d, 0xe2, 0x70,
276 0xe2, 0x67, 0x1c, 0xa8, 0x0d, 0xcd, 0x1a, 0x72,
277 0x86, 0x2c, 0xea, 0xdc, 0x7f, 0x8c, 0x49, 0x2c,
278 0xe7, 0x99, 0x13, 0xda, 0x3f, 0x58, 0x9e, 0xf5,
279 0x4d, 0x3c, 0x8c, 0x1c, 0xed, 0x85, 0xa7, 0xe2,
280 0xae, 0xda, 0x5f, 0xbe, 0x36, 0x1c, 0x9f, 0x5a,
281 0xa0, 0xdc, 0x2a, 0xc0, 0xee, 0x71, 0x07, 0x26,
282 0x8b, 0xe8, 0x8a, 0xf8, 0x2d, 0x36, 0x78, 0xc9,
283 0x79, 0xfa, 0xbe, 0x98, 0x59, 0x95, 0x12, 0x24,
284 0xf1, 0xda, 0x20, 0xc7, 0x78, 0xf9, 0x7c, 0x6a,
285 0x24, 0x43, 0x82, 0xa8, 0x0f, 0xb1, 0x7d, 0x94,
286 0xaa, 0x30, 0x35, 0xe5, 0x69, 0xdc, 0x0a, 0x0e,
287 0xaf, 0x10, 0x5e, 0x1a, 0x81, 0x50, 0x5c, 0x7e,
288 0x24, 0xb3, 0x07, 0x65, 0x4b, 0xc1, 0x7e, 0xc6,
289 0x38, 0xdb, 0xd3, 0x6a, 0xf0, 0xd8, 0x85, 0x61,
290 0x9a, 0x9f, 0xfe, 0x02, 0x46, 0x29, 0xb2, 0x9a,
291 0xe2, 0x04, 0xe7, 0x72, 0xcc, 0x87, 0x46, 0xba,
292 0x7d, 0xa8, 0xf9, 0xd0, 0x0f, 0x29, 0xfc, 0xfd,
293 0xd1, 0xd0, 0x7f, 0x36, 0xc1, 0xd8, 0x7d, 0x88,
294 0x03, 0x62, 0xf5, 0x8c, 0x00, 0xb5, 0xc2, 0x81,
295 0x44, 0x67, 0x58, 0x11, 0xb4, 0x3a, 0xbb, 0xd1,
296 0x8c, 0x94, 0x20, 0x60, 0xea, 0xa0, 0xac, 0xc1,
297 0xf1, 0x08, 0x54, 0xb8, 0xf6, 0x5e, 0xac, 0xf1,
298 0xec, 0x78, 0x69, 0x9d, 0x7e, 0x4d, 0x06, 0x3b,
299 0x9b, 0x78, 0x78, 0x10
304 friendlyName: uranusLeaf
305 localKeyID: 46 E0 8A 05 63 4D 17 3F CA A4 AA B6 5A DA CF BA 84 22 7C 23
306 Key Attributes: <No Attributes>
308 static const uint8_t _k1
[] = {
309 0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02,
310 0x82, 0x01, 0x01, 0x00, 0xa6, 0x82, 0x8e, 0xc6,
311 0x7e, 0xc9, 0x8c, 0x99, 0x6f, 0xb0, 0x62, 0x32,
312 0x35, 0xe7, 0xdb, 0xff, 0x34, 0x84, 0xdc, 0x72,
313 0xa8, 0xef, 0x22, 0x6f, 0x93, 0x63, 0x64, 0x80,
314 0x80, 0x5d, 0x50, 0x7e, 0xb4, 0x2e, 0x1b, 0x93,
315 0x93, 0x49, 0xca, 0xae, 0xcd, 0x34, 0x44, 0x4b,
316 0xd7, 0xfa, 0x9f, 0x3c, 0xfc, 0x9e, 0x65, 0xa9,
317 0xfb, 0x5e, 0x5d, 0x18, 0xa3, 0xf8, 0xb0, 0x08,
318 0xac, 0x8f, 0xfd, 0x03, 0xcb, 0xbd, 0x7f, 0xa0,
319 0x2a, 0xa6, 0xea, 0xca, 0xa3, 0x24, 0xef, 0x7c,
320 0xc3, 0xeb, 0x95, 0xcb, 0x90, 0x3f, 0x5e, 0xde,
321 0x78, 0xf2, 0x3d, 0x32, 0x72, 0xdb, 0x33, 0x6e,
322 0x9b, 0x52, 0x9f, 0x0c, 0x60, 0x4a, 0x24, 0xa1,
323 0xf6, 0x3b, 0x80, 0xbd, 0xa1, 0xdc, 0x40, 0x03,
324 0xe7, 0xa0, 0x59, 0x1f, 0xdb, 0xb4, 0xed, 0x57,
325 0xdc, 0x74, 0x0d, 0x99, 0x5a, 0x12, 0x74, 0x64,
326 0xaa, 0xb6, 0xa5, 0x96, 0x75, 0xf9, 0x42, 0x43,
327 0xe2, 0x52, 0xc2, 0x57, 0x23, 0x75, 0xd7, 0xa9,
328 0x4f, 0x07, 0x32, 0x99, 0xbd, 0x3d, 0x44, 0xbd,
329 0x04, 0x62, 0xe5, 0xb7, 0x2c, 0x0c, 0x11, 0xc5,
330 0xb2, 0x2e, 0xc4, 0x12, 0x1d, 0x7f, 0x42, 0x1e,
331 0x71, 0xaf, 0x39, 0x2b, 0x78, 0x47, 0x92, 0x23,
332 0x44, 0xef, 0xe3, 0xc1, 0x47, 0x69, 0x5a, 0xf1,
333 0x48, 0xaa, 0x37, 0xa4, 0x94, 0x6b, 0x96, 0xe5,
334 0x4b, 0xfd, 0x05, 0xc7, 0x9c, 0xcc, 0x38, 0xd1,
335 0x47, 0x85, 0x60, 0x7f, 0xef, 0xe9, 0x2e, 0x25,
336 0x08, 0xf8, 0x7d, 0x98, 0xdd, 0x6c, 0xeb, 0x4a,
337 0x32, 0x33, 0x44, 0x0b, 0x61, 0xb3, 0xf9, 0xae,
338 0x26, 0x41, 0xb5, 0x38, 0xdb, 0xcf, 0x13, 0x72,
339 0x23, 0x5b, 0x66, 0x20, 0x86, 0x4d, 0x24, 0xc2,
340 0xd4, 0x94, 0xde, 0xe3, 0x24, 0xb7, 0xcd, 0x75,
341 0x9e, 0x1d, 0x9f, 0xbc, 0xd0, 0x60, 0x34, 0x7d,
342 0xf8, 0xcb, 0x41, 0x39, 0x02, 0x03, 0x01, 0x00,
343 0x01, 0x02, 0x82, 0x01, 0x00, 0x4d, 0x27, 0xf2,
344 0x40, 0xc8, 0x3f, 0x5c, 0x87, 0x3c, 0xd9, 0xde,
345 0xa6, 0xa5, 0x93, 0xea, 0xbd, 0x36, 0xf8, 0xd9,
346 0xad, 0xc7, 0xda, 0x07, 0x7a, 0xec, 0x31, 0x02,
347 0x41, 0x09, 0x3a, 0x34, 0x32, 0x82, 0x0b, 0x5b,
348 0x7b, 0xe6, 0xa4, 0x2a, 0xe7, 0x14, 0xef, 0x43,
349 0x36, 0x61, 0xbe, 0x20, 0x4b, 0x82, 0x43, 0x63,
350 0x98, 0x80, 0x82, 0x19, 0x61, 0x71, 0x99, 0xaa,
351 0xf8, 0x59, 0xfd, 0xde, 0xa0, 0x03, 0xa8, 0xab,
352 0x9a, 0xec, 0x28, 0xac, 0x63, 0x79, 0x75, 0x84,
353 0x03, 0xac, 0x45, 0x5e, 0x04, 0x15, 0xb3, 0x47,
354 0xa2, 0x8f, 0x28, 0xb0, 0x72, 0xd0, 0x06, 0x02,
355 0xaf, 0x1e, 0x0a, 0x0a, 0xe9, 0x11, 0x35, 0x4a,
356 0x04, 0x42, 0xb5, 0x0f, 0xd2, 0xcf, 0x4d, 0xdf,
357 0xdb, 0xef, 0x58, 0xbd, 0xf3, 0xa5, 0x3b, 0x11,
358 0x3f, 0xc5, 0x47, 0x81, 0x85, 0xad, 0xd7, 0x1f,
359 0x58, 0x06, 0x42, 0xdc, 0x37, 0x3c, 0xdb, 0x98,
360 0x33, 0xa1, 0xc6, 0x80, 0x07, 0xe0, 0x2b, 0xc5,
361 0xf5, 0x60, 0x35, 0x6a, 0xa2, 0x06, 0x40, 0x4a,
362 0xac, 0x64, 0x02, 0x58, 0x4d, 0x07, 0xe3, 0x69,
363 0xd7, 0xe0, 0x8f, 0xb5, 0xf4, 0xbc, 0xfa, 0xab,
364 0x1a, 0xb0, 0xfa, 0x29, 0xf8, 0xca, 0xde, 0x78,
365 0xf0, 0x89, 0xe2, 0xf9, 0xb7, 0x68, 0x5b, 0x0e,
366 0xdc, 0x4e, 0x8a, 0x56, 0x8d, 0x33, 0x20, 0x2e,
367 0xed, 0x2e, 0xab, 0x6f, 0xba, 0x77, 0xef, 0xe6,
368 0x12, 0x62, 0x49, 0x9e, 0x87, 0x76, 0x1c, 0x1e,
369 0xf4, 0x0e, 0x9e, 0x78, 0x98, 0x91, 0x1a, 0xe3,
370 0xb4, 0x51, 0x4b, 0x8c, 0x2f, 0x08, 0x97, 0x8f,
371 0xf9, 0x68, 0x61, 0x40, 0xcd, 0xb6, 0x10, 0xb4,
372 0xfb, 0x75, 0xb4, 0x20, 0xc1, 0x5a, 0xda, 0x64,
373 0xfd, 0x51, 0x06, 0x85, 0x9a, 0x9e, 0x5d, 0x82,
374 0x14, 0xd4, 0x41, 0x4e, 0x75, 0x10, 0xb5, 0x7b,
375 0xd0, 0x4c, 0xd1, 0x00, 0x01, 0x02, 0x81, 0x81,
376 0x00, 0xcf, 0x8e, 0x68, 0x04, 0x67, 0x09, 0xa9,
377 0x6e, 0xff, 0x11, 0x8c, 0xe5, 0xe4, 0x16, 0xdd,
378 0xb6, 0xa6, 0x55, 0xca, 0x4b, 0x0b, 0xbb, 0xb7,
379 0xf5, 0xe5, 0x73, 0xf3, 0x24, 0x84, 0x29, 0xb2,
380 0xc3, 0xbc, 0x7f, 0x2b, 0x4a, 0xc7, 0xdf, 0x46,
381 0x8e, 0xe1, 0x35, 0x69, 0x1b, 0x8e, 0x9f, 0x6b,
382 0x4d, 0xf3, 0x65, 0xae, 0x3d, 0x87, 0x2b, 0xc9,
383 0xf0, 0x8c, 0xf2, 0x88, 0x2f, 0x1b, 0x79, 0x80,
384 0xd2, 0xb2, 0x64, 0x0a, 0xcc, 0x66, 0x69, 0x4c,
385 0xa1, 0x85, 0xc4, 0x6a, 0x94, 0x46, 0x70, 0x69,
386 0xbc, 0x8c, 0x1c, 0x62, 0x65, 0x4d, 0x68, 0xcc,
387 0xe3, 0x3c, 0x6c, 0xe7, 0xd1, 0x09, 0xed, 0xdd,
388 0x42, 0x10, 0x11, 0x6b, 0xdd, 0x7c, 0xe3, 0xe1,
389 0x3b, 0x3b, 0x0d, 0x01, 0x6d, 0xca, 0x2f, 0x4b,
390 0x45, 0x5e, 0x76, 0x5d, 0x5c, 0x6f, 0x53, 0xa4,
391 0x38, 0x74, 0x75, 0x94, 0x2c, 0xda, 0xf8, 0xa6,
392 0x01, 0x02, 0x81, 0x81, 0x00, 0xcd, 0x5f, 0x9d,
393 0x6c, 0x94, 0xf6, 0x44, 0x37, 0x72, 0xfe, 0xcf,
394 0xbe, 0x82, 0x96, 0x24, 0x22, 0x12, 0x07, 0x6f,
395 0xd1, 0x57, 0x7b, 0xc7, 0x63, 0x20, 0xf5, 0x93,
396 0x79, 0x70, 0x0b, 0xe4, 0x38, 0x19, 0x62, 0x7b,
397 0x89, 0x3e, 0x45, 0xdf, 0xd6, 0xae, 0x9d, 0x0d,
398 0xa8, 0x76, 0xc1, 0xbd, 0x04, 0x2b, 0xaa, 0x30,
399 0x6a, 0xac, 0x65, 0x91, 0x61, 0xf0, 0xf8, 0x5d,
400 0xa3, 0x53, 0xa4, 0xfb, 0x99, 0xac, 0x46, 0x7a,
401 0x12, 0x4b, 0xf7, 0xa7, 0x48, 0x41, 0x61, 0x48,
402 0x26, 0x5c, 0x68, 0x2f, 0x73, 0x91, 0xe4, 0x74,
403 0xcd, 0xc9, 0x8b, 0xe7, 0x26, 0xe4, 0x35, 0xde,
404 0x32, 0x6b, 0x24, 0x49, 0xf2, 0x04, 0x67, 0x3d,
405 0x31, 0x8f, 0x22, 0xe5, 0x49, 0xae, 0x49, 0x94,
406 0xb3, 0x45, 0x2b, 0xed, 0x6f, 0x9c, 0xc7, 0x80,
407 0xf0, 0x42, 0xd5, 0x8f, 0x27, 0xd6, 0xd6, 0x49,
408 0xf2, 0x16, 0xcc, 0x4b, 0x39, 0x02, 0x81, 0x81,
409 0x00, 0xbb, 0xb7, 0xd7, 0x59, 0xcb, 0xfb, 0x10,
410 0x13, 0xc4, 0x7b, 0x92, 0x0c, 0x45, 0xcb, 0x6c,
411 0x81, 0x0a, 0x55, 0x63, 0x1d, 0x96, 0xa2, 0x13,
412 0xd2, 0x40, 0xd1, 0x2a, 0xa1, 0xe7, 0x2a, 0x73,
413 0x74, 0xd6, 0x61, 0xc9, 0xbc, 0xdb, 0xa2, 0x93,
414 0x85, 0x1c, 0x28, 0x9b, 0x44, 0x82, 0x2c, 0xaa,
415 0xf7, 0x18, 0x60, 0xe9, 0x42, 0xda, 0xa2, 0xff,
416 0x04, 0x21, 0xe6, 0x24, 0xc7, 0x3e, 0x39, 0x19,
417 0x0a, 0xf6, 0xae, 0xc6, 0x99, 0x71, 0x32, 0x61,
418 0x4d, 0x60, 0xd7, 0x71, 0x71, 0x63, 0x77, 0xbe,
419 0x19, 0xfa, 0x3a, 0x9d, 0xbf, 0x73, 0x50, 0x8a,
420 0xa6, 0x26, 0x7b, 0x74, 0xfa, 0x39, 0xd9, 0xb9,
421 0x18, 0x4b, 0xc2, 0x05, 0xe5, 0x8f, 0x53, 0xe6,
422 0xdc, 0x14, 0x1f, 0x42, 0x20, 0x93, 0x11, 0x4d,
423 0x29, 0x93, 0x32, 0xc8, 0x63, 0x96, 0x88, 0x76,
424 0x69, 0x5c, 0xe3, 0x0e, 0xbd, 0xb6, 0xd9, 0xd6,
425 0x01, 0x02, 0x81, 0x80, 0x62, 0xa2, 0xed, 0x84,
426 0xdc, 0xf6, 0x7a, 0x44, 0xf7, 0x62, 0x12, 0x7c,
427 0xb9, 0x53, 0x4a, 0xff, 0x62, 0x11, 0x58, 0x4e,
428 0xfe, 0xe9, 0x60, 0x15, 0xe8, 0x1a, 0x8a, 0x3d,
429 0xe4, 0xe6, 0x91, 0x31, 0xb0, 0x5f, 0x70, 0x5d,
430 0xb6, 0x1e, 0xf1, 0x26, 0xb6, 0xae, 0x8f, 0x84,
431 0xbd, 0xa4, 0xc7, 0x17, 0x5d, 0xb1, 0x5b, 0x97,
432 0xa0, 0x3d, 0x17, 0xda, 0x26, 0x55, 0xe3, 0x03,
433 0x32, 0x85, 0x26, 0xa1, 0xe3, 0xef, 0xe5, 0x69,
434 0x2c, 0x3b, 0x41, 0x88, 0x9e, 0x7e, 0x0e, 0x9c,
435 0xfd, 0xfc, 0xbb, 0xed, 0x91, 0xc0, 0x5b, 0xa9,
436 0x0a, 0x87, 0xba, 0xf9, 0x1e, 0xda, 0x10, 0x61,
437 0xbe, 0xbb, 0xab, 0x18, 0x25, 0xad, 0x3f, 0xe2,
438 0xb1, 0x90, 0x5c, 0xf7, 0x4a, 0x51, 0xe4, 0xad,
439 0x45, 0x27, 0x97, 0xdd, 0xe7, 0x3a, 0x9a, 0x5e,
440 0xca, 0x7a, 0xaf, 0x4a, 0xbf, 0x10, 0x24, 0x6b,
441 0xb5, 0x2f, 0x61, 0x61, 0x02, 0x81, 0x81, 0x00,
442 0x85, 0x7c, 0x78, 0xa5, 0x11, 0xdf, 0xc3, 0x6a,
443 0x38, 0x48, 0xfa, 0x7e, 0x48, 0xf0, 0x5a, 0x58,
444 0xe2, 0xc5, 0x83, 0x4e, 0x38, 0x3f, 0x4a, 0x2b,
445 0x07, 0x57, 0x31, 0xe7, 0xbe, 0x50, 0xb1, 0xbb,
446 0x24, 0xf3, 0x3d, 0x8b, 0x53, 0xb7, 0xd1, 0x47,
447 0x72, 0x5e, 0xd5, 0xd6, 0x4c, 0xce, 0x2c, 0x46,
448 0x61, 0x9a, 0xaa, 0xc3, 0x0e, 0xd4, 0x23, 0x2c,
449 0xdd, 0xf5, 0xb7, 0xad, 0x38, 0x52, 0x17, 0xc4,
450 0x16, 0xbb, 0xda, 0x1c, 0x61, 0xb1, 0xca, 0x8d,
451 0xb2, 0xa0, 0xbe, 0x4f, 0x3d, 0x19, 0x0e, 0xe0,
452 0x0e, 0x52, 0xad, 0xf3, 0xaf, 0xd9, 0xcc, 0x78,
453 0xc2, 0xb1, 0x5e, 0x05, 0x5e, 0xf2, 0x27, 0x84,
454 0x15, 0xe4, 0x8f, 0xca, 0xc5, 0x92, 0x43, 0xe0,
455 0x24, 0x8d, 0xf2, 0x5d, 0x55, 0xcc, 0x9d, 0x2f,
456 0xa9, 0xf6, 0x9b, 0x67, 0x6a, 0x87, 0x74, 0x36,
457 0x34, 0x7c, 0xd4, 0x9d, 0xff, 0xad, 0xee, 0x69
460 static const uint8_t _k1_digest
[] = {
461 0x46, 0xE0, 0x8A, 0x05, 0x63, 0x4D, 0x17, 0x3F,
462 0xCA, 0xA4, 0xAA, 0xB6, 0x5A, 0xDA, 0xCF, 0xBA,
463 0x84, 0x22, 0x7C, 0x23
466 /* Create and identity and try to retrieve it. */
467 static void tests(void)
469 SecCertificateRef cert
= NULL
;
470 SecKeyRef privKey
= NULL
;
471 SecIdentityRef identity
= NULL
;
473 isnt(cert
= SecCertificateCreateWithBytes(NULL
, _c1
, sizeof(_c1
)),
474 NULL
, "create certificate");
475 isnt(privKey
= SecKeyCreateRSAPrivateKey(NULL
, _k1
, sizeof(_k1
),
476 kSecKeyEncodingPkcs1
), NULL
, "create private key");
478 const void *certkeys
[] = {
481 const void *certvalues
[] = {
484 CFDictionaryRef certDict
= CFDictionaryCreate(NULL
, certkeys
, certvalues
,
485 array_size(certkeys
), NULL
, NULL
);
486 ok_status(SecItemAdd(certDict
, NULL
), "add certificate");
487 CFReleaseNull(certDict
);
489 const void *privkeys
[] = {
492 const void *privvalues
[] = {
495 CFDictionaryRef privDict
= CFDictionaryCreate(NULL
, privkeys
, privvalues
,
496 array_size(privkeys
), NULL
, NULL
);
497 ok_status(SecItemAdd(privDict
, NULL
), "add private key");
498 CFReleaseNull(privDict
);
500 isnt(identity
= SecIdentityCreate(NULL
, cert
, privKey
), NULL
, "create identity");
502 /* Lookup the key and certificate using SecItemCopyMatching(). */
503 CFDataRef pk_digest
= CFDataCreate(NULL
, _k1_digest
, sizeof(_k1_digest
));
504 const void *q_keys
[] = {
506 kSecAttrApplicationLabel
,
509 const void *q_values
[] = {
514 CFDictionaryRef query
= CFDictionaryCreate(NULL
, q_keys
, q_values
,
515 array_size(q_keys
), NULL
, NULL
);
516 CFTypeRef result_key
;
517 ok_status(SecItemCopyMatching(query
, &result_key
), "lookup key");
519 isnt(CFEqual(privKey
, result_key
), 0, "keys match");
520 CFReleaseNull(query
);
522 q_keys
[1] = kSecAttrPublicKeyHash
;
523 q_values
[0] = kSecClassCertificate
;
524 query
= CFDictionaryCreate(NULL
, q_keys
, q_values
,
525 array_size(q_keys
), NULL
, NULL
);
526 CFTypeRef result_cert
;
527 ok_status(SecItemCopyMatching(query
, &result_cert
), "lookup certificate");
528 isnt(CFEqual(cert
, result_cert
), 0, "certificates match");
529 CFReleaseNull(query
);
532 CFReleaseNull(result_key
);
533 CFReleaseNull(result_cert
);
535 /* identity lookup */
536 const void *idnt_keys
[] = {
538 kSecAttrApplicationLabel
,
541 const void *idnt_values
[] = {
546 CFTypeRef result_idnt
;
547 SecCertificateRef result_cert2
;
548 query
= CFDictionaryCreate(NULL
, idnt_keys
, idnt_values
,
549 array_size(idnt_keys
), NULL
, NULL
);
550 ok_status(SecItemCopyMatching(query
, &result_idnt
), "lookup identity");
551 isnt(result_idnt
, NULL
, "found identity?");
552 is(CFGetRetainCount(result_idnt
), 1, "result_idnt rc = 1");
553 isnt(CFEqual(identity
, result_idnt
), 0, "identities match");
554 CFReleaseNull(identity
);
556 ok_status(SecIdentityCopyCertificate((SecIdentityRef
)result_idnt
, &result_cert2
), "get cert from identity");
557 isnt(CFEqual(cert
, result_cert2
), 0, "certificates match");
559 CFRelease(pk_digest
);
560 CFReleaseNull(result_cert2
);
562 certDict
= CFDictionaryCreate(NULL
, certkeys
, certvalues
,
563 array_size(certkeys
), NULL
, NULL
);
564 ok_status(SecItemDelete(certDict
), "delete certificate via ref");
565 is_status(errSecItemNotFound
, SecItemCopyMatching(certDict
, NULL
), "verify certificate is gone");
567 CFReleaseNull(certDict
);
569 privDict
= CFDictionaryCreate(NULL
, privkeys
, privvalues
,
570 array_size(privkeys
), NULL
, NULL
);
571 ok_status(SecItemDelete(privDict
), "delete key via ref");
572 is_status(errSecItemNotFound
, SecItemCopyMatching(privDict
, NULL
), "verify key is gone");
573 CFReleaseNull(privDict
);
575 /* add certificate to offset cert row id from key row id */
576 SecCertificateRef apple_ca_cert
= NULL
;
577 isnt(apple_ca_cert
= SecCertificateCreateWithBytes(NULL
, _c0
, sizeof(_c0
)),
578 NULL
, "create apple ca certificate");
579 CFDictionaryRef appleCertDict
= CFDictionaryCreate(NULL
, (const void **)&kSecValueRef
, (const void **)&apple_ca_cert
, 1, NULL
, NULL
);
580 ok_status(SecItemAdd(appleCertDict
, NULL
), "add apple ca certificate to offset key and cert rowid");
582 /* add identity, get persistent ref */
583 const void *keys_identity
[] = { kSecValueRef
, kSecReturnPersistentRef
};
584 const void *values_identity
[] = { result_idnt
, kCFBooleanTrue
};
585 CFDictionaryRef identity_add
= CFDictionaryCreate(NULL
, keys_identity
, values_identity
,
586 array_size(keys_identity
), NULL
, NULL
);
587 CFTypeRef persist
= NULL
;
588 ok_status(SecItemAdd(identity_add
, &persist
), "add identity ref");
589 ok(persist
, "got back persistent ref");
590 /* <rdar://problem/6537195> SecItemAdd returns success when it shouldn't */
591 CFTypeRef persist_again
= NULL
;
592 is_status(errSecDuplicateItem
, SecItemAdd(identity_add
, &persist_again
),
593 "fail to add identity ref again");
594 ok(!persist_again
, "no persistent ref this time");
596 /* find by persistent ref */
597 const void *keys_persist
[] = { kSecReturnRef
, kSecValuePersistentRef
};
598 const void *values_persist
[] = { kCFBooleanTrue
, persist
};
599 CFDictionaryRef persist_find
= CFDictionaryCreate(NULL
, keys_persist
, values_persist
,
600 (array_size(keys_persist
)), NULL
, NULL
);
601 CFTypeRef results2
= NULL
;
602 ok_status(SecItemCopyMatching(persist_find
, &results2
), "find identity by persistent ref");
603 is(CFGetRetainCount(results2
), 1, "results2 rc = 1");
604 // not implemented ok(CFEqual(result_idnt, results2), "same item (attributes)");
605 CFReleaseNull(results2
);
607 /* find identity, key and cert by ref and return persistent ref */
608 const void *keys_ref_to_persist
[] = { kSecReturnPersistentRef
, kSecValueRef
};
609 const void *values_ref_to_persist
[] = { kCFBooleanTrue
, NULL
};
610 CFTypeRef items
[] = { result_idnt
, privKey
, cert
, NULL
};
611 CFTypeRef
*item
= items
;
613 values_ref_to_persist
[1] = *item
;
614 CFDictionaryRef ref_to_persist_find
= CFDictionaryCreate(NULL
, keys_ref_to_persist
, values_ref_to_persist
,
615 (array_size(keys_ref_to_persist
)), NULL
, NULL
);
617 ok_status(SecItemCopyMatching(ref_to_persist_find
, &results2
), "find persistent ref for identity ref");
618 ok(NULL
!= results2
, "good persistent ref");
619 is(CFGetRetainCount(results2
), 1, "results2 rc = 1");
620 CFReleaseNull(results2
);
621 CFReleaseNull(ref_to_persist_find
);
625 /* delete identity by identity ref */
626 ok_status(SecItemDelete(identity_add
), "delete identity by identity ref");
627 is(SecItemCopyMatching(persist_find
, &results2
), errSecItemNotFound
,
628 "make sure identity by persistent ref is no longer there");
629 CFRelease(persist_find
);
630 CFReleaseNull(persist
);
631 ok_status(SecItemAdd(identity_add
, &persist
), "add identity ref back");
632 CFRelease(identity_add
);
634 /* delete identity by persistent ref */
635 CFDictionaryRef persist_delete
= CFDictionaryCreate(NULL
,
636 (const void **)&kSecValuePersistentRef
, &persist
, 1, NULL
, NULL
);
637 ok_status(SecItemDelete(persist_delete
),
638 "delete identity by persistent ref");
639 is(SecItemCopyMatching(persist_delete
, &results2
), errSecItemNotFound
,
640 "make sure identity by persistent ref is no longer there");
641 CFRelease(persist_delete
);
642 CFReleaseNull(persist
);
644 /* add identity with a label set */
645 CFStringRef zomg_label
= CFSTR("zomg");
646 CFMutableDictionaryRef lbl_idnt_query
=
647 CFDictionaryCreateMutable(kCFAllocatorDefault
, 0,
648 &kCFTypeDictionaryKeyCallBacks
, &kCFTypeDictionaryValueCallBacks
);
649 CFDictionarySetValue(lbl_idnt_query
, kSecValueRef
, result_idnt
);
650 CFDictionarySetValue(lbl_idnt_query
, kSecAttrLabel
, zomg_label
);
651 ok_status(SecItemAdd(lbl_idnt_query
, NULL
), "add identity ref");
653 /* find identity with label*/
654 CFDictionaryRemoveAllValues(lbl_idnt_query
);
655 CFDictionarySetValue(lbl_idnt_query
, kSecClass
, kSecClassIdentity
);
656 CFDictionarySetValue(lbl_idnt_query
, kSecAttrLabel
, zomg_label
);
657 ok_status(SecItemCopyMatching(lbl_idnt_query
, NULL
), "find identity by label");
659 /* find certs with label */
661 CFDictionaryRemoveAllValues(lbl_idnt_query
);
662 CFDictionarySetValue(lbl_idnt_query
, kSecClass
, kSecClassCertificate
);
663 CFDictionarySetValue(lbl_idnt_query
, kSecAttrLabel
, zomg_label
);
664 CFDictionarySetValue(lbl_idnt_query
, kSecReturnRef
, kCFBooleanTrue
);
665 ok_status(SecItemCopyMatching(lbl_idnt_query
, &zomg_cert
), "find cert by label");
667 /* find keys with label */
669 CFDictionaryRemoveAllValues(lbl_idnt_query
);
670 CFDictionarySetValue(lbl_idnt_query
, kSecClass
, kSecClassKey
);
671 CFDictionarySetValue(lbl_idnt_query
, kSecAttrLabel
, zomg_label
);
672 CFDictionarySetValue(lbl_idnt_query
, kSecReturnRef
, kCFBooleanTrue
);
673 ok_status(SecItemCopyMatching(lbl_idnt_query
, &zomg_key
), "find key by label");
675 /* update label on key */
676 CFStringRef new_label_value
= CFSTR("zzzomg");
677 CFDictionaryRef new_label
= CFDictionaryCreate(kCFAllocatorDefault
, (const void **)&kSecAttrLabel
, (const void **)&new_label_value
, 1, NULL
, NULL
);
678 CFDictionaryRemoveAllValues(lbl_idnt_query
);
679 CFDictionarySetValue(lbl_idnt_query
, kSecValueRef
, zomg_key
);
680 ok_status(SecItemUpdate(lbl_idnt_query
, new_label
), "update label to zzzomg for key");
682 CFTypeRef zomg_idnt
= NULL
;
683 CFDictionaryRemoveAllValues(lbl_idnt_query
);
684 CFDictionarySetValue(lbl_idnt_query
, kSecReturnRef
, kCFBooleanTrue
);
685 CFDictionarySetValue(lbl_idnt_query
, kSecAttrLabel
, zomg_label
);
686 CFDictionarySetValue(lbl_idnt_query
, kSecClass
, kSecClassIdentity
);
687 ok_status(SecItemCopyMatching(lbl_idnt_query
, &zomg_idnt
), "still finding zomg ident");
688 CFReleaseNull(zomg_idnt
);
691 CFDictionaryRemoveAllValues(lbl_idnt_query
);
692 CFDictionarySetValue(lbl_idnt_query
, kSecValueRef
, zomg_cert
);
693 ok_status(SecItemUpdate(lbl_idnt_query
, new_label
), "update label to zzzomg for cert");
694 CFReleaseNull(new_label
);
696 CFDictionaryRemoveAllValues(lbl_idnt_query
);
697 CFDictionarySetValue(lbl_idnt_query
, kSecReturnRef
, kCFBooleanTrue
);
698 CFDictionarySetValue(lbl_idnt_query
, kSecAttrLabel
, zomg_label
);
699 CFDictionarySetValue(lbl_idnt_query
, kSecClass
, kSecClassIdentity
);
700 is_status(errSecItemNotFound
, SecItemCopyMatching(lbl_idnt_query
, &zomg_idnt
), "no longer find identity by label");
702 CFDictionaryRemoveAllValues(lbl_idnt_query
);
703 CFDictionarySetValue(lbl_idnt_query
, kSecReturnRef
, kCFBooleanTrue
);
704 CFDictionarySetValue(lbl_idnt_query
, kSecAttrLabel
, new_label_value
);
705 CFDictionarySetValue(lbl_idnt_query
, kSecClass
, kSecClassIdentity
);
706 ok_status(SecItemCopyMatching(lbl_idnt_query
, &zomg_idnt
), "finding ident with zzzomg label");
708 /* Find zomg identity with canonical issuer */
710 unsigned char DN
[] = {
711 0x30, 0x32, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c,
712 0x07, 0x70, 0x6c, 0x75, 0x74, 0x6f, 0x43, 0x41, 0x31, 0x1e, 0x30, 0x1c,
713 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x0c,
714 0x0f, 0x70, 0x6c, 0x75, 0x74, 0x6f, 0x40, 0x70, 0x6c, 0x75, 0x74, 0x6f,
715 0x2e, 0x63, 0x6f, 0x6d
717 unsigned int DN_len
= 52;
718 CFMutableDictionaryRef find_by_issuer
= CFDictionaryCreateMutable(NULL
, 0, NULL
, NULL
);
719 CFDataRef issuer
= SecCertificateGetNormalizedIssuerContent(cert
);
720 CFTypeRef found_by_issuer
= NULL
;
721 CFDictionarySetValue(find_by_issuer
, kSecAttrIssuer
, issuer
);
722 CFDictionarySetValue(find_by_issuer
, kSecClass
, kSecClassIdentity
);
723 CFDictionarySetValue(find_by_issuer
, kSecReturnRef
, kCFBooleanTrue
);
724 ok_status(SecItemCopyMatching(find_by_issuer
, &found_by_issuer
), "find identity by cert issuer");
725 ok(CFEqual(found_by_issuer
, zomg_idnt
), "should be same as zomg_idnt");
726 CFReleaseNull(found_by_issuer
);
727 issuer
= CFDataCreate(kCFAllocatorDefault
, DN
, DN_len
);
728 CFDictionarySetValue(find_by_issuer
, kSecAttrIssuer
, issuer
);
729 ok_status(SecItemCopyMatching(find_by_issuer
, &found_by_issuer
), "find identity by cert issuer");
730 CFReleaseNull(issuer
);
731 ok(CFEqual(found_by_issuer
, zomg_idnt
), "should be same as zomg_idnt");
732 CFReleaseNull(found_by_issuer
);
733 CFReleaseNull(find_by_issuer
);
736 ok_status(SecItemDelete(lbl_idnt_query
), "delete ident with zzzomg label");
738 /* Delete the apple cert last */
739 ok_status(SecItemDelete(appleCertDict
), "delete apple ca certificate");
740 CFReleaseNull(appleCertDict
);
741 CFReleaseNull(apple_ca_cert
);
744 CFRelease(zomg_cert
);
745 CFRelease(zomg_idnt
);
746 CFRelease(zomg_label
);
747 CFRelease(new_label_value
);
748 CFRelease(lbl_idnt_query
);
750 CFReleaseNull(result_idnt
);
751 CFReleaseNull(privKey
);
755 int si_42_identity(int argc
, char *const *argv
)