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>
14 static void aksNotificationCallback(void *refcon
,io_service_t service
, natural_t messageType
, void *messageArgument
)
16 if(messageType
== kAppleKeyStoreLockStateChangeMessage
) {
17 os_log(OS_LOG_DEFAULT
, "KeyStoreNotifier posting lockstate change");
18 notify_post(kAppleKeyStoreLockStatusNotificationID
);
19 } else if (messageType
== kAppleKeyStoreFirstUnlockMessage
) {
20 os_log(OS_LOG_DEFAULT
, "KeyStoreNotifier posting first unlock");
21 notify_post(kAppleKeyStoreFirstUnlockNotificationID
);
25 static void start(dispatch_queue_t queue
)
28 io_service_t aksService
= IO_OBJECT_NULL
;
29 IONotificationPortRef aksNotifyPort
= NULL
;
30 io_object_t notification
= IO_OBJECT_NULL
;
32 aksService
= IOServiceGetMatchingService(kIOMasterPortDefault
, IOServiceMatching(kAppleKeyStoreServiceName
));
33 require_action(aksService
, cleanup
, syslog(LOG_ERR
, "KeyStoreNotifier - Can't find %s service", kAppleKeyStoreServiceName
));
35 aksNotifyPort
= IONotificationPortCreate(kIOMasterPortDefault
);
36 require_action(aksNotifyPort
, cleanup
, syslog(LOG_ERR
, "KeyStoreNotifier - Can't create notification port"));
38 IONotificationPortSetDispatchQueue(aksNotifyPort
, queue
);
40 result
= IOServiceAddInterestNotification(aksNotifyPort
, aksService
, kIOGeneralInterest
, aksNotificationCallback
, NULL
, ¬ification
);
41 require_noerr_action(result
, cleanup
, syslog(LOG_ERR
, "KeyStoreNotifier - Can't register for notification: %08x", result
));
45 if (aksNotifyPort
) IONotificationPortDestroy(aksNotifyPort
);
46 if (notification
) IOObjectRelease(notification
);
47 if (aksService
) IOObjectRelease(aksService
);
52 init_keystore_events(xpc_event_module_t
module)
54 start(xpc_event_module_get_queue(module));