2 * Copyright (c) 2015 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@
24 #define __KEYCHAINCORE__ 1
26 #include <Foundation/Foundation.h>
27 #include <CoreFoundation/CoreFoundation.h>
28 #include <Security/Security.h>
29 #include <Security/SecItemPriv.h>
30 #include <utilities/array_size.h>
31 #include <utilities/SecCFWrappers.h>
35 #include "Security_regressions.h"
38 /* Test add api in all it's variants. */
39 static void tests(void)
41 NSDictionary *item, *query;
42 CFTypeRef result = NULL;
43 NSDictionary *whoami = NULL;
45 whoami = CFBridgingRelease(_SecSecuritydCopyWhoAmI(NULL));
47 NSLog(@"whoami: %@", whoami);
54 (id)kSecClass : (id)kSecClassGenericPassword,
55 (id)kSecAttrLabel : @"keychain label",
57 SecItemDelete((CFDictionaryRef)query);
60 (id)kSecClass : (id)kSecClassGenericPassword,
61 (id)kSecAttrLabel : @"keychain label",
62 (id)kSecUseSystemKeychain : @YES,
64 SecItemDelete((CFDictionaryRef)query);
71 (id)kSecClass : (id)kSecClassGenericPassword,
72 (id)kSecAttrLabel : @"keychain label",
73 (id)kSecUseSystemKeychain : @YES,
76 ok_status(SecItemAdd((CFDictionaryRef)item, NULL), "SecItemAdd");
79 * Check for multi user mode and its expected behavior (since its different)
82 bool multiUser = (whoami[@"musr"]) ? true : false;
85 * Check we can't find it in our keychain
89 (id)kSecClass : (id)kSecClassGenericPassword,
90 (id)kSecAttrLabel : @"keychain label",
93 is(SecItemCopyMatching((CFTypeRef)query, &result), multiUser ? errSecItemNotFound : noErr, "SecItemCopyMatching");
94 CFReleaseNull(result);
96 is(SecItemDelete((CFTypeRef)query), errSecItemNotFound, "SecItemDelete");
102 * Check we can find it in system keychain
106 (id)kSecClass : (id)kSecClassGenericPassword,
107 (id)kSecAttrLabel : @"keychain label",
108 (id)kSecUseSystemKeychain : @YES,
111 ok_status(SecItemCopyMatching((CFTypeRef)query, &result), "SecItemCopyMatching(system)");
113 ok_status(SecItemDelete((CFTypeRef)query), "SecItemDelete(system)");
116 int si_13_item_system(int argc, char *const *argv)