]> git.saurik.com Git - apple/security.git/blob - OSX/sec/Security/Regressions/secitem/si-17-item-system-bluetooth.m
Security-58286.251.4.tar.gz
[apple/security.git] / OSX / sec / Security / Regressions / secitem / si-17-item-system-bluetooth.m
1 /*
2 * Copyright (c) 2015 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 #define __KEYCHAINCORE__ 1
25
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/SecCFRelease.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34
35 #include "Security_regressions.h"
36
37 // If we're running no server this test isn't valid
38 #if defined(NO_SERVER) && NO_SERVER
39 #define DO_TESTS false
40 #else
41 #define DO_TESTS true
42 #endif
43
44
45 static NSString* const kBlueToothServiceName = @"BluetoothGlobal";
46
47 /* Test presence of properly migrated items into system keychain. */
48 static void tests(void)
49 {
50 NSDictionary *query;
51 NSDictionary *whoami = NULL;
52
53 whoami = CFBridgingRelease(_SecSecuritydCopyWhoAmI(NULL));
54
55 NSLog(@"whoami: %@", whoami);
56
57 /*
58 * Check for multi user mode and its expected behavior (since its different)
59 */
60
61 bool multiUser = (whoami[@"musr"]) ? true : false;
62
63 /*
64 * Check we can't find it in our keychain
65 */
66 SKIP: {
67 skip("No Server mode, test not valid", 2, DO_TESTS)
68 query = @{
69 (__bridge id)kSecClass : (__bridge id)kSecClassGenericPassword,
70 (__bridge id)kSecAttrService : kBlueToothServiceName,
71 };
72
73 is(SecItemCopyMatching((CFTypeRef)query, NULL), multiUser ? errSecItemNotFound : noErr, "Bluetooth item - user keychain");
74
75 query = @{
76 (__bridge id)kSecClass : (__bridge id)kSecClassGenericPassword,
77 (__bridge id)kSecAttrService : kBlueToothServiceName,
78 (__bridge id)kSecUseSystemKeychain : @YES,
79 };
80
81 is(SecItemCopyMatching((CFTypeRef)query, NULL), noErr, "Bluetooth item - system keychain");
82 }
83 }
84
85 int si_17_item_system_bluetooth(int argc, char *const *argv)
86 {
87 plan_tests(2);
88
89 @autoreleasepool {
90 tests();
91 }
92
93 return 0;
94 }