2 * Copyright (c) 2016,2020 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@
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/
29 #define __KEYCHAINCORE__ 1
31 #include <Foundation/Foundation.h>
32 #include <Security/Security.h>
33 #include <Security/SecItemPriv.h>
36 #import <TargetConditionals.h>
39 main(int argc, const char ** argv)
41 dispatch_queue_t queue = dispatch_queue_create("notifications-queue", NULL);
42 __block int got_notification = false;
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,
54 status = SecItemDelete((__bridge CFDictionaryRef)query);
55 if (status != errSecSuccess && status != errSecItemNotFound) {
56 errx(1, "cleanup item: %d", (int)status);
59 notify_register_dispatch("com.apple.security.view-change.PCS", &token, queue, ^(int __unused token2) {
60 printf("got notification\n");
61 got_notification = true;
65 * now check add notification
68 status = SecItemAdd((__bridge CFDictionaryRef)query, NULL);
69 if (status != errSecSuccess) {
70 errx(1, "add item: %d", (int)status);
75 // Bridge explicitly disables notify phase, no PCS, octagon or sos on this platform
77 if (!got_notification) {
78 errx(1, "failed to get notification on add");
81 if (got_notification) {
82 errx(1, "received unexpected notification on add");
85 got_notification = false;
88 * clean up and check delete notification too
91 status = SecItemDelete((__bridge CFDictionaryRef)query);
92 if (status != errSecSuccess) {
93 errx(1, "cleanup2 item: %d", (int)status);
99 if (!got_notification) {
100 errx(1, "failed to get notification on delete");
103 if (got_notification) {
104 errx(1, "received unexpected notification on delete");