2 // Copyright 2016 Apple. All rights reserved.
6 * This is to fool os services to not provide the Keychain manager
7 * interface tht doens't work since we don't have unified headers
8 * between iOS and OS X. rdar://23405418/
10 #define __KEYCHAINCORE__ 1
12 #include <Foundation/Foundation.h>
13 #include <Security/Security.h>
14 #include <Security/SecItemPriv.h>
19 main(int argc, const char ** argv)
21 dispatch_queue_t queue = dispatch_queue_create("notifications-queue", NULL);
22 __block int got_notification = false;
26 NSDictionary *query = @{
27 (id)kSecClass : (id)kSecClassGenericPassword,
28 (id)kSecAttrAccessGroup : @"keychain-test1",
29 (id)kSecAttrSyncViewHint : @"PCS-Master",
30 (id)kSecAttrAccount : @"account-delete-me",
31 (id)kSecAttrSynchronizable : (id)kCFBooleanTrue,
32 (id)kSecAttrAccessible : (id)kSecAttrAccessibleAfterFirstUnlock,
34 status = SecItemDelete((__bridge CFDictionaryRef)query);
35 if (status != errSecSuccess && status != errSecItemNotFound)
36 errx(1, "cleanup item: %d", (int)status);
38 notify_register_dispatch("com.apple.security.view-change.PCS", &token, queue, ^(int __unused token2) {
39 printf("got notification\n");
40 got_notification = true;
44 * now check add notification
47 status = SecItemAdd((__bridge CFDictionaryRef)query, NULL);
48 if (status != errSecSuccess)
49 errx(1, "add item: %d", (int)status);
53 if (!got_notification)
54 errx(1, "failed to get notification on add");
55 got_notification = false;
58 * clean up and check delete notification too
61 status = SecItemDelete((__bridge CFDictionaryRef)query);
62 if (status != errSecSuccess)
63 errx(1, "cleanup2 item: %d", (int)status);
67 if (!got_notification)
68 errx(1, "failed to get notification on delete");