1 #import <Foundation/Foundation.h>
2 #import <Foundation/NSXPCConnection_Private.h>
4 #import "SecEntitlements.h"
5 #import "keychain/ckks/CKKS.h"
6 #import "keychain/ckks/CKKSControlProtocol.h"
7 #import "keychain/ckks/CKKSControlServer.h"
8 #import "keychain/ckks/CKKSViewManager.h"
10 @interface CKKSControlServer : NSObject <NSXPCListenerDelegate>
13 @implementation CKKSControlServer
15 - (BOOL)listener:(__unused NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
17 NSNumber *num = [newConnection valueForEntitlement:(__bridge NSString *)kSecEntitlementPrivateCKKS];
18 if (![num isKindOfClass:[NSNumber class]] || ![num boolValue]) {
19 secerror("ckks: Client pid: %d doesn't have entitlement: %@",
20 [newConnection processIdentifier], kSecEntitlementPrivateCKKS);
24 // In the future, we should consider vending a proxy object that can return a nicer error.
25 if (!SecCKKSIsEnabled()) {
26 secerror("ckks: Client pid: %d attempted to use CKKS, but CKKS is not enabled.",
27 newConnection.processIdentifier);
31 newConnection.exportedInterface = CKKSSetupControlProtocol([NSXPCInterface interfaceWithProtocol:@protocol(CKKSControlProtocol)]);
32 newConnection.exportedObject = [CKKSViewManager manager];
34 [newConnection resume];
45 CKKSControlServerInitialize(void)
47 static dispatch_once_t once;
48 static CKKSControlServer *server;
49 static NSXPCListener *listener;
51 dispatch_once(&once, ^{
53 server = [CKKSControlServer new];
55 listener = [[NSXPCListener alloc] initWithMachServiceName:@(kSecuritydCKKSServiceName)];
56 listener.delegate = server;