]> git.saurik.com Git - apple/security.git/blob - RegressionTests/secedumodetest/secedumodetest.m
Security-58286.200.222.tar.gz
[apple/security.git] / RegressionTests / secedumodetest / secedumodetest.m
1 //
2 // Copyright 2016 Apple. All rights reserved.
3 //
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 #include <Foundation/Foundation.h>
13 #include <Security/Security.h>
14 #include <Security/SecItemPriv.h>
15 #include <TargetConditionals.h>
16 #include <err.h>
17
18
19 int main (int argc, const char * argv[])
20 {
21 @autoreleasepool {
22
23 NSDictionary *addItem = @{
24 (id)kSecClass : (id)kSecClassGenericPassword,
25 (id)kSecAttrLabel : @"vpn-test-label",
26 (id)kSecAttrAccount : @"vpn-test-account",
27 (id)kSecValueData : @"password",
28 (id)kSecUseSystemKeychain : @YES,
29 };
30
31 NSDictionary *querySystemItem = @{
32 (id)kSecClass : (id)kSecClassGenericPassword,
33 (id)kSecAttrLabel : @"vpn-test-label",
34 (id)kSecAttrAccount : @"vpn-test-account",
35 (id)kSecUseSystemKeychain : @YES,
36 };
37
38 NSDictionary *queryItem = @{
39 (id)kSecClass : (id)kSecClassGenericPassword,
40 (id)kSecAttrLabel : @"vpn-test-label",
41 (id)kSecAttrAccount : @"vpn-test-account",
42 };
43
44 (void)SecItemDelete((__bridge CFDictionaryRef)querySystemItem);
45
46
47 if (!SecItemAdd((__bridge CFDictionaryRef)addItem, NULL))
48 errx(1, "failed to add");
49
50
51 if (!SecItemCopyMatching((__bridge CFDictionaryRef)queryItem, NULL))
52 errx(1, "failed to find in user + system");
53
54 if (!SecItemCopyMatching((__bridge CFDictionaryRef)querySystemItem, NULL))
55 errx(1, "failed to find in system");
56
57
58 if (!SecItemDelete((__bridge CFDictionaryRef)querySystemItem))
59 errx(1, "failed to clean up");
60
61 return 0;
62 }
63 }
64
65