]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/regressions/si-34-one-true-keychain.c
Security-57740.31.2.tar.gz
[apple/security.git] / OSX / libsecurity_keychain / regressions / si-34-one-true-keychain.c
1 /*
2 * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #include <CoreFoundation/CoreFoundation.h>
25 #include <TargetConditionals.h>
26 #include <stdio.h>
27
28 #include "keychain_regressions.h"
29 #include <utilities/SecCFRelease.h>
30
31 #include <Security/SecBase.h>
32 #include <Security/SecItem.h>
33 #include <Security/SecItemPriv.h>
34 #include <libaks.h>
35 #include <AssertMacros.h>
36
37
38 /* Test whether the one true keychain pertains to the iOS keychain and only to the iOS keychain. */
39 static void tests(void)
40 {
41 int v_eighty = 80;
42 CFNumberRef eighty = CFNumberCreate(NULL, kCFNumberSInt32Type, &v_eighty);
43 const char *v_data = "test";
44 const char *v_data2 = "test";
45 CFDataRef pwdata = CFDataCreate(NULL, (UInt8 *)v_data, strlen(v_data));
46 CFDataRef pwdata2 = CFDataCreate(NULL, (UInt8 *)v_data2, strlen(v_data2));
47 CFMutableDictionaryRef query = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
48 CFTypeRef result = NULL;
49 CFDictionaryAddValue(query, kSecClass, kSecClassInternetPassword);
50 CFDictionaryAddValue(query, kSecAttrServer, CFSTR("members.spamcop.net"));
51 CFDictionaryAddValue(query, kSecAttrAccount, CFSTR("smith"));
52 CFDictionaryAddValue(query, kSecAttrPort, eighty);
53 CFDictionaryAddValue(query, kSecAttrProtocol, kSecAttrProtocolHTTP);
54 CFDictionaryAddValue(query, kSecAttrAuthenticationType, kSecAttrAuthenticationTypeDefault);
55
56 CFMutableDictionaryRef noLegacyQuery = CFDictionaryCreateMutableCopy(NULL, 0, query);
57 CFMutableDictionaryRef syncAnyQuery = CFDictionaryCreateMutableCopy(NULL, 0, query);
58 CFMutableDictionaryRef syncQuery = CFDictionaryCreateMutableCopy(NULL, 0, query);
59
60 CFDictionaryAddValue(noLegacyQuery, kSecAttrNoLegacy, kCFBooleanTrue);
61 CFDictionaryAddValue(syncAnyQuery, kSecAttrSynchronizable, kSecAttrSynchronizableAny);
62 CFDictionaryAddValue(syncQuery, kSecAttrSynchronizable, kCFBooleanTrue);
63
64 SecItemDelete(query);
65 SecItemDelete(noLegacyQuery);
66 SecItemDelete(syncQuery);
67 SecItemDelete(syncAnyQuery);
68
69 CFDictionaryAddValue(query, kSecValueData, pwdata);
70 ok_status(SecItemAdd(query, NULL), "add internet password in OS X keychain");
71 CFDictionaryRemoveValue(query, kSecValueData);
72
73 ok_status(SecItemCopyMatching(query, &result), "find the osx item");
74 CFReleaseNull(result);
75 is_status(SecItemCopyMatching(noLegacyQuery, &result), errSecItemNotFound, "do not find the osx item with noLegacy");
76 CFReleaseNull(result);
77 ok_status(SecItemCopyMatching(syncAnyQuery, &result), "find the osx item with synchronizableAny");
78 CFReleaseNull(result);
79 is_status(SecItemCopyMatching(syncQuery, &result), errSecItemNotFound, "do not find the osx item with synchronizable");
80 CFReleaseNull(result);
81
82 CFMutableDictionaryRef toUpdate = CFDictionaryCreateMutable(NULL, 1, NULL, NULL);
83
84 CFDictionaryAddValue(toUpdate, kSecValueData, pwdata2);
85
86 ok_status(SecItemUpdate(query, toUpdate), "update the osx item");
87 is_status(SecItemUpdate(noLegacyQuery, toUpdate), errSecItemNotFound, "do not update the osx item with noLegacy");
88 ok_status(SecItemUpdate(syncAnyQuery, toUpdate), "update the osx item with synchronizableAny");
89
90 is_status(SecItemDelete(noLegacyQuery), errSecItemNotFound, "do not delete the osx item with noLegacy");
91 ok_status(SecItemDelete(syncAnyQuery), "delete the osx item with synchronizableAny");
92
93
94
95
96 CFDictionaryAddValue(noLegacyQuery, kSecValueData, pwdata);
97 ok_status(SecItemAdd(noLegacyQuery, &result), "add internet password in iOS keychain");
98 CFDictionaryRemoveValue(noLegacyQuery, kSecValueData);
99
100 ok_status(SecItemCopyMatching(query, &result), "find the ios item with generic query");
101 CFReleaseNull(result);
102 ok_status(SecItemCopyMatching(noLegacyQuery, &result), "find the ios item with noLegacy");
103 CFReleaseNull(result);
104 ok_status(SecItemCopyMatching(syncAnyQuery, &result), "find the ios item with synchronizableAny");
105 CFReleaseNull(result);
106 is_status(SecItemCopyMatching(syncQuery, &result), errSecItemNotFound, "do not find the ios item with synchronizable");
107 CFReleaseNull(result);
108
109 ok_status(SecItemUpdate(query, toUpdate), "update the ios item without any flags");
110 ok_status(SecItemUpdate(noLegacyQuery, toUpdate), "update the ios item with noLegacy");
111 ok_status(SecItemUpdate(syncAnyQuery, toUpdate), "update the ios item with synchronizableAny");
112
113 CFDictionaryRemoveValue(noLegacyQuery, kSecValueData);
114
115 ok_status(SecItemDelete(noLegacyQuery), "delete the item with noLegacy");
116
117 }
118
119 int si_34_one_true_keychain(int argc, char *const *argv)
120 {
121 plan_tests(19);
122
123
124 tests();
125
126 return 0;
127 }