]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-83-item-match-valid-on-date.m
Security-57740.1.18.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-83-item-match-valid-on-date.m
1 //
2 // secd-83-item-match-valid-on-date.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/SecItem.h>
14 #import <Security/SecBase.h>
15 #import <utilities/SecCFWrappers.h>
16
17
18 #import "secd_regressions.h"
19 #import "SecdTestKeychainUtilities.h"
20 #import "secd-83-item-match.h"
21
22 static void test(id returnKeyName) {
23 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
24 [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss zzz"];
25 [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"us_EN"]];
26 NSDate *validDate = [dateFormatter dateFromString: @"2016-04-07 16:00:00 GMT"];
27 NSDate *dateBefore = [dateFormatter dateFromString: @"2016-04-06 16:00:00 GMT"];
28 NSDate *dateAfter = [dateFormatter dateFromString: @"2017-04-08 16:00:00 GMT"];
29
30 CFTypeRef result = NULL;
31 ok_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
32 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
33 returnKeyName : @YES }, &result));
34 ok(result && CFArrayGetCount(result) == 6);
35 CFReleaseNull(result);
36
37 ok_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
38 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
39 (id)kSecMatchValidOnDate : validDate,
40 returnKeyName : @YES }, &result));
41 ok(result && CFArrayGetCount(result) == 6);
42
43 is_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
44 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
45 (id)kSecMatchValidOnDate : dateBefore,
46 returnKeyName : @YES }, &result), errSecItemNotFound);
47 ok(result && CFArrayGetCount(result) == 6);
48 is_status(SecItemCopyMatching( (__bridge CFDictionaryRef)@{ (id)kSecClass : (id)kSecClassCertificate,
49 (id)kSecMatchLimit : (id)kSecMatchLimitAll,
50 (id)kSecMatchValidOnDate : dateAfter,
51 returnKeyName : @YES }, &result), errSecItemNotFound);
52 ok(result && CFArrayGetCount(result) == 6);
53 }
54
55 int secd_83_item_match_valid_on_date(int argc, char *const *argv)
56 {
57 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
58 plan_tests(39);
59
60 @autoreleasepool {
61 addTestCertificates();
62 NSArray *returnKeyNames = @[(id)kSecReturnAttributes, (id)kSecReturnData, (id)kSecReturnRef, (id)kSecReturnPersistentRef];
63 for (id returnKeyName in returnKeyNames)
64 test(returnKeyName);
65 }
66
67 return 0;
68 }