]>
Commit | Line | Data |
---|---|---|
d64be36e A |
1 | /* |
2 | * Copyright (c) 2016,2020 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 | */ | |
fa7225c8 A |
23 | |
24 | /* | |
25 | * This is to fool os services to not provide the Keychain manager | |
26 | * interface tht doens't work since we don't have unified headers | |
27 | * between iOS and OS X. rdar://23405418/ | |
28 | */ | |
29 | #define __KEYCHAINCORE__ 1 | |
30 | ||
31 | #include <Foundation/Foundation.h> | |
32 | #include <Security/Security.h> | |
33 | #include <Security/SecItemPriv.h> | |
34 | #include <notify.h> | |
35 | #include <err.h> | |
d64be36e | 36 | #import <TargetConditionals.h> |
fa7225c8 A |
37 | |
38 | int | |
39 | main(int argc, const char ** argv) | |
40 | { | |
41 | dispatch_queue_t queue = dispatch_queue_create("notifications-queue", NULL); | |
42 | __block int got_notification = false; | |
43 | OSStatus status; | |
44 | int token; | |
45 | ||
46 | NSDictionary *query = @{ | |
47 | (id)kSecClass : (id)kSecClassGenericPassword, | |
48 | (id)kSecAttrAccessGroup : @"keychain-test1", | |
49 | (id)kSecAttrSyncViewHint : @"PCS-Master", | |
50 | (id)kSecAttrAccount : @"account-delete-me", | |
51 | (id)kSecAttrSynchronizable : (id)kCFBooleanTrue, | |
52 | (id)kSecAttrAccessible : (id)kSecAttrAccessibleAfterFirstUnlock, | |
53 | }; | |
54 | status = SecItemDelete((__bridge CFDictionaryRef)query); | |
d64be36e | 55 | if (status != errSecSuccess && status != errSecItemNotFound) { |
fa7225c8 | 56 | errx(1, "cleanup item: %d", (int)status); |
d64be36e | 57 | } |
fa7225c8 A |
58 | |
59 | notify_register_dispatch("com.apple.security.view-change.PCS", &token, queue, ^(int __unused token2) { | |
60 | printf("got notification\n"); | |
61 | got_notification = true; | |
62 | }); | |
63 | ||
64 | /* | |
65 | * now check add notification | |
66 | */ | |
67 | ||
68 | status = SecItemAdd((__bridge CFDictionaryRef)query, NULL); | |
d64be36e | 69 | if (status != errSecSuccess) { |
fa7225c8 | 70 | errx(1, "add item: %d", (int)status); |
d64be36e | 71 | } |
fa7225c8 A |
72 | |
73 | sleep(3); | |
74 | ||
d64be36e A |
75 | // Bridge explicitly disables notify phase, no PCS, octagon or sos on this platform |
76 | #if !TARGET_OS_BRIDGE | |
77 | if (!got_notification) { | |
fa7225c8 | 78 | errx(1, "failed to get notification on add"); |
d64be36e A |
79 | } |
80 | #else | |
81 | if (got_notification) { | |
82 | errx(1, "received unexpected notification on add"); | |
83 | } | |
84 | #endif | |
fa7225c8 A |
85 | got_notification = false; |
86 | ||
87 | /* | |
88 | * clean up and check delete notification too | |
89 | */ | |
90 | ||
91 | status = SecItemDelete((__bridge CFDictionaryRef)query); | |
d64be36e | 92 | if (status != errSecSuccess) { |
fa7225c8 | 93 | errx(1, "cleanup2 item: %d", (int)status); |
d64be36e | 94 | } |
fa7225c8 A |
95 | |
96 | sleep(3); | |
97 | ||
d64be36e A |
98 | #if !TARGET_OS_BRIDGE |
99 | if (!got_notification) { | |
fa7225c8 | 100 | errx(1, "failed to get notification on delete"); |
d64be36e A |
101 | } |
102 | #else | |
103 | if (got_notification) { | |
104 | errx(1, "received unexpected notification on delete"); | |
105 | } | |
106 | #endif | |
fa7225c8 A |
107 | |
108 | return 0; | |
109 | } |