]> git.saurik.com Git - apple/security.git/blob - securityd/securityd_service/KeyStore/KeyStoreEvents.c
Security-57337.50.23.tar.gz
[apple/security.git] / securityd / securityd_service / KeyStore / KeyStoreEvents.c
1 /* Copyright (c) 2013 Apple Inc. All Rights Reserved. */
2
3 #include "AppleKeyStoreEvents.h"
4
5 #include <unistd.h>
6 #include <notify.h>
7 #include <syslog.h>
8 #include <AssertMacros.h>
9 #include <IOKit/IOKitLib.h>
10 #include <Kernel/IOKit/crypto/AppleKeyStoreDefs.h>
11 #include <xpc/event_private.h>
12
13 static void aksNotificationCallback(void *refcon,io_service_t service, natural_t messageType, void *messageArgument)
14 {
15 if(messageType == kAppleKeyStoreLockStateChangeMessage) {
16 // syslog(LOG_ERR, "KeyStoreNotifier - %s posting notification: %s\n", __func__, kAppleKeyStoreLockStatusNotificationID);
17 notify_post(kAppleKeyStoreLockStatusNotificationID);
18 } else if (messageType == kAppleKeyStoreFirstUnlockMessage) {
19 // syslog(LOG_ERR, "KeyStoreNotifier - %s posting notification: %s\n", __func__, kAppleKeyStoreFirstUnlockNotificationID);
20 notify_post(kAppleKeyStoreFirstUnlockNotificationID);
21 }
22 }
23
24 static void start(dispatch_queue_t queue)
25 {
26 IOReturn result;
27 io_service_t aksService = IO_OBJECT_NULL;
28 IONotificationPortRef aksNotifyPort = IO_OBJECT_NULL;
29 io_object_t notification = IO_OBJECT_NULL;
30
31 aksService = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kAppleKeyStoreServiceName));
32 require_action(aksService, cleanup, syslog(LOG_ERR, "KeyStoreNotifier - Can't find %s service", kAppleKeyStoreServiceName));
33
34 aksNotifyPort = IONotificationPortCreate(kIOMasterPortDefault);
35 require_action(aksNotifyPort, cleanup, syslog(LOG_ERR, "KeyStoreNotifier - Can't create notification port"));
36
37 IONotificationPortSetDispatchQueue(aksNotifyPort, queue);
38
39 result = IOServiceAddInterestNotification(aksNotifyPort, aksService, kIOGeneralInterest, aksNotificationCallback, NULL, &notification);
40 require_noerr_action(result, cleanup, syslog(LOG_ERR, "KeyStoreNotifier - Can't register for notification: %08x", result));
41 return;
42
43 cleanup:
44 if (aksNotifyPort) IONotificationPortDestroy(aksNotifyPort);
45 if (notification) IOObjectRelease(notification);
46 if (aksService) IOObjectRelease(aksService);
47 return;
48 }
49
50 void
51 init_keystore_events(xpc_event_module_t module)
52 {
53 start(xpc_event_module_get_queue(module));
54 }