1 /* Copyright (c) 2013 Apple Inc. All rights reserved. */
3 #include "AppleKeyStoreEvents.h"
8 #include <AssertMacros.h>
9 #include <IOKit/IOKitLib.h>
10 #include <Kernel/IOKit/crypto/AppleKeyStoreDefs.h>
11 #include <xpc/event_private.h>
13 static void aksNotificationCallback(void *refcon
,io_service_t service
, natural_t messageType
, void *messageArgument
)
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
);
24 static void start(dispatch_queue_t queue
)
27 io_service_t aksService
= IO_OBJECT_NULL
;
28 IONotificationPortRef aksNotifyPort
= IO_OBJECT_NULL
;
29 io_object_t notification
= IO_OBJECT_NULL
;
31 aksService
= IOServiceGetMatchingService(kIOMasterPortDefault
, IOServiceMatching(kAppleKeyStoreServiceName
));
32 require_action(aksService
, cleanup
, syslog(LOG_ERR
, "KeyStoreNotifier - Can't find %s service", kAppleKeyStoreServiceName
));
34 aksNotifyPort
= IONotificationPortCreate(kIOMasterPortDefault
);
35 require_action(aksNotifyPort
, cleanup
, syslog(LOG_ERR
, "KeyStoreNotifier - Can't create notification port"));
37 IONotificationPortSetDispatchQueue(aksNotifyPort
, queue
);
39 result
= IOServiceAddInterestNotification(aksNotifyPort
, aksService
, kIOGeneralInterest
, aksNotificationCallback
, NULL
, ¬ification
);
40 require_noerr_action(result
, cleanup
, syslog(LOG_ERR
, "KeyStoreNotifier - Can't register for notification: %08x", result
));
44 if (aksNotifyPort
) IONotificationPortDestroy(aksNotifyPort
);
45 if (notification
) IOObjectRelease(notification
);
46 if (aksService
) IOObjectRelease(aksService
);
51 init_keystore_events(xpc_event_module_t
module)
53 start(xpc_event_module_get_queue(module));