]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-83-item-match-policy.m
Security-57740.31.2.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-83-item-match-policy.m
1 //
2 // secd-81-item-match-policy.m
3 // sec
4
5 /*
6 * This is to fool os services to not provide the Keychain manager
7 * interface tht doens't work since we don't have unified headers
8 * between iOS and OS X. rdar://23405418/
9 */
10 #define __KEYCHAINCORE__ 1
11
12 #import <Foundation/Foundation.h>
13 #import <Security/SecCertificate.h>
14 #import <Security/SecItem.h>
15 #import <Security/SecBase.h>
16 #import <utilities/SecCFWrappers.h>
17
18
19 #import "secd_regressions.h"
20 #import "SecdTestKeychainUtilities.h"
21 #import "secd-83-item-match.h"
22
23 //Test SSL SMIME2
24 NSString *secdTestSMIME1BASE64String = @"MIIDUzCCAjugAwIBAgIBATANBgkqhkiG9w0BAQsFADBHMRQwEgYDVQQDDAtUZXN0IFNNSU1FMTELMAkGA1UEBhMCQ1oxIjAgBgkqhkiG9w0BCQEWE3Rlc3RjZXJ0MUBhcHBsZS5jb20wHhcNMTYwNDA3MDYzNDM0WhcNMTcwNDA3MDYzNDM0WjBHMRQwEgYDVQQDDAtUZXN0IFNNSU1FMTELMAkGA1UEBhMCQ1oxIjAgBgkqhkiG9w0BCQEWE3Rlc3RjZXJ0MUBhcHBsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDHedMsbVecoqyZwoTTE85bm3QImVz45HYFGKq/L6E5dVPamiiMRZ2BX1XnIdthbIRZhg7OU0zk2KiQKyg+bjnk+l3ZW/C6N3sAx4blq/UemOg6XtdI1Iq/HwLw5qJW8hiy9INA2nMJnSXZrnM6Ezsj92l0PQ2+8oOa95sLfi2e9NJZONESY/XNyc6tclaUYHSQR+BAzllKRorrqvpa3T2o6lmcUG+29TsRUHth6OHZLccMoA6ITk8Eq/vlAsaH4BnD7rFfBwcE/GhkkbZrmH1xaFziEIwMx3uvhsQCpspt50Pf9RW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xcNG9b1NeDkG5t1RQgUL5JwP8bg==";
35
36 void addTestCertificates(void) {
37 NSData *certDerData = [[NSData alloc] initWithBase64EncodedString:secdTestSMIME1BASE64String options:NSDataBase64DecodingIgnoreUnknownCharacters];
38 SecCertificateRef certRef = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)certDerData);
39 ok_status(SecItemAdd((__bridge CFDictionaryRef) @{ (id)kSecValueRef : (__bridge id) certRef }, NULL), "Add tet certificate");
40 CFRelease(certRef);
41
42 certDerData = [[NSData alloc] initWithBase64EncodedString:secdTestSMIME2BASE64String options:NSDataBase64DecodingIgnoreUnknownCharacters];
43 certRef = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)certDerData);
44 ok_status(SecItemAdd((__bridge CFDictionaryRef) @{ (id)kSecValueRef : (__bridge id) certRef }, NULL), "Add tet certificate");
45 CFRelease(certRef);
46
47 certDerData = [[NSData alloc] initWithBase64EncodedString:secdTestSSLClient1BASE64String options:NSDataBase64DecodingIgnoreUnknownCharacters];
48 certRef = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)certDerData);
49 ok_status(SecItemAdd((__bridge CFDictionaryRef) @{ (id)kSecValueRef : (__bridge id) certRef }, NULL), "Add tet certificate");
50 CFRelease(certRef);
51
52 certDerData = [[NSData alloc] initWithBase64EncodedString:secdTestSSLClient2BASE64String options:NSDataBase64DecodingIgnoreUnknownCharacters];
53 certRef = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)certDerData);
54 ok_status(SecItemAdd((__bridge CFDictionaryRef) @{ (id)kSecValueRef : (__bridge id) certRef }, NULL), "Add tet certificate");
55 CFRelease(certRef);
56
57 certDerData = [[NSData alloc] initWithBase64EncodedString:secdTestSSLServer1BASE64String options:NSDataBase64DecodingIgnoreUnknownCharacters];
58 certRef = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)certDerData);
59 ok_status(SecItemAdd((__bridge CFDictionaryRef) @{ (id)kSecValueRef : (__bridge id) certRef }, NULL), "Add tet certificate");
60 CFRelease(certRef);
61
62 certDerData = [[NSData alloc] initWithBase64EncodedString:secdTestSSLServer2BASE64String options:NSDataBase64DecodingIgnoreUnknownCharacters];
63 certRef = SecCertificateCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)certDerData);
64 ok_status(SecItemAdd((__bridge CFDictionaryRef) @{ (id)kSecValueRef : (__bridge id) certRef }, NULL), "Add tet certificate");
65 CFRelease(certRef);
66 }
67
68 static void test(id returnKeyName) {
69 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
70 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz"];
71 [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"us_EN"]];
72 NSDate *validDate = [dateFormatter dateFromString: @"2016-04-07 16:00:00 GMT"];
73 NSDate *dateBefore = [dateFormatter dateFromString: @"2016-04-06 16:00:00 GMT"];
74 NSDate *dateAfter = [dateFormatter dateFromString: @"2017-04-08 16:00:00 GMT"];
75
76 CFTypeRef result = NULL;
77 ok_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
78 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
79 returnKeyName : @YES }, &result));
80 ok(result && CFArrayGetCount(result) == 6);
81 CFReleaseNull(result);
82 #if TARGET_OS_IPHONE
83 SecPolicyRef policy = SecPolicyCreateWithProperties(kSecPolicyAppleSMIME, NULL);
84 #else
85 SecPolicyRef policy = SecPolicyCreateWithProperties(kSecPolicyAppleSMIME, (__bridge CFDictionaryRef)@{ (id)kSecPolicyKU_DigitalSignature : @YES });
86 #endif
87 ok_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
88 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
89 (id)kSecMatchPolicy : (__bridge id)policy,
90 returnKeyName : @YES }, &result));
91 ok(result && CFArrayGetCount(result) == 2);
92 CFReleaseNull(policy);
93 CFReleaseNull(result);
94
95 #if TARGET_OS_IPHONE
96 policy = SecPolicyCreateWithProperties(kSecPolicyAppleSMIME, (__bridge CFDictionaryRef)@{
97 #else
98 policy = SecPolicyCreateWithProperties(kSecPolicyAppleSMIME, (__bridge CFDictionaryRef)@{ (id)kSecPolicyKU_DigitalSignature : @YES,
99 #endif
100 (id)kSecPolicyName : @"testcert1@apple.com" });
101 ok_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
102 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
103 (id)kSecMatchPolicy : (__bridge id)policy,
104 returnKeyName : @YES }, &result));
105 ok(result && CFArrayGetCount(result) == 1);
106 CFReleaseNull(result);
107
108 ok_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
109 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
110 (id)kSecMatchPolicy : (__bridge id)policy,
111 (id)kSecMatchValidOnDate : validDate,
112 returnKeyName : @YES }, &result));
113 ok(result && CFArrayGetCount(result) == 1);
114 CFReleaseNull(result);
115
116 is_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
117 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
118 (id)kSecMatchPolicy : (__bridge id)policy,
119 (id)kSecMatchValidOnDate : dateBefore,
120 returnKeyName : @YES }, &result), errSecItemNotFound);
121 CFReleaseNull(result);
122
123 is_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
124 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
125 (id)kSecMatchPolicy : (__bridge id)policy,
126 (id)kSecMatchValidOnDate : dateAfter,
127 returnKeyName : @YES }, &result), errSecItemNotFound);
128 CFReleaseNull(policy);
129 CFReleaseNull(result);
130 #if TARGET_OS_IPHONE
131 policy = SecPolicyCreateWithProperties(kSecPolicyAppleSSL, NULL);
132 #else
133 policy = SecPolicyCreateWithProperties(kSecPolicyAppleSSL, (__bridge CFDictionaryRef)@{ (id)kSecPolicyKU_DigitalSignature : @YES });
134 #endif
135 ok_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
136 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
137 (id)kSecMatchPolicy : (__bridge id)policy,
138 returnKeyName : @YES }, &result));
139 ok(result && CFArrayGetCount(result) == 2);
140 CFReleaseNull(policy);
141 CFReleaseNull(result);
142
143 #if TARGET_OS_IPHONE
144 policy = SecPolicyCreateWithProperties(kSecPolicyAppleSSL, (__bridge CFDictionaryRef)@{
145 #else
146 policy = SecPolicyCreateWithProperties(kSecPolicyAppleSSL, (__bridge CFDictionaryRef)@{ (id)kSecPolicyKU_DigitalSignature : @YES,
147 #endif
148 (id)kSecPolicyName : @"secdtest1.apple.com" });
149 ok_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
150 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
151 (id)kSecMatchPolicy : (__bridge id)policy,
152 returnKeyName : @YES }, &result));
153 ok(result && CFArrayGetCount(result) == 1);
154 CFReleaseNull(result);
155
156 ok_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
157 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
158 (id)kSecMatchPolicy : (__bridge id)policy,
159 (id)kSecMatchValidOnDate : validDate,
160 returnKeyName : @YES }, &result));
161 ok(result && CFArrayGetCount(result) == 1);
162 CFReleaseNull(result);
163
164 is_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
165 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
166 (id)kSecMatchPolicy : (__bridge id)policy,
167 (id)kSecMatchValidOnDate : dateBefore,
168 returnKeyName : @YES }, &result), errSecItemNotFound);
169 CFReleaseNull(result);
170
171 is_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
172 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
173 (id)kSecMatchPolicy : (__bridge id)policy,
174 (id)kSecMatchValidOnDate : dateAfter,
175 returnKeyName : @YES }, &result), errSecItemNotFound);
176 CFReleaseNull(policy);
177 CFReleaseNull(result);
178
179 #if TARGET_OS_IPHONE
180 policy = SecPolicyCreateWithProperties(kSecPolicyAppleSSL, (__bridge CFDictionaryRef)@{
181 #else
182 policy = SecPolicyCreateWithProperties(kSecPolicyAppleSSL, (__bridge CFDictionaryRef)@{ (id)kSecPolicyKU_DigitalSignature : @YES,
183 #endif
184 (id)kSecPolicyClient : @YES });
185 ok_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
186 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
187 (id)kSecMatchPolicy : (__bridge id)policy,
188 returnKeyName : @YES }, &result));
189 ok(result && CFArrayGetCount(result) == 2);
190 CFReleaseNull(result);
191
192 ok_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
193 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
194 (id)kSecMatchPolicy : (__bridge id)policy,
195 (id)kSecMatchValidOnDate : validDate,
196 returnKeyName : @YES }, &result));
197 ok(result && CFArrayGetCount(result) == 2);
198 CFReleaseNull(result);
199
200 is_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
201 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
202 (id)kSecMatchPolicy : (__bridge id)policy,
203 (id)kSecMatchValidOnDate : dateBefore,
204 returnKeyName : @YES }, &result), errSecItemNotFound);
205 CFReleaseNull(result);
206
207 is_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
208 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
209 (id)kSecMatchPolicy : (__bridge id)policy,
210 (id)kSecMatchValidOnDate : dateAfter,
211 returnKeyName : @YES }, &result), errSecItemNotFound);
212 CFReleaseNull(policy);
213 CFReleaseNull(result);
214 }
215
216 int secd_83_item_match_policy(int argc, char *const *argv)
217 {
218 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
219 plan_tests(103);
220
221 @autoreleasepool {
222 addTestCertificates();
223 NSArray *returnKeyNames = @[(id)kSecReturnAttributes, (id)kSecReturnData, (id)kSecReturnRef, (id)kSecReturnPersistentRef];
224 for (id returnKeyName in returnKeyNames)
225 test(returnKeyName);
226 }
227
228 return 0;
229 }