]> git.saurik.com Git - apple/security.git/blob - keychain/Trieste/OctagonTestHarnessXPCService/OctagonTestHarnessXPCService.m
Security-59306.11.20.tar.gz
[apple/security.git] / keychain / Trieste / OctagonTestHarnessXPCService / OctagonTestHarnessXPCService.m
1 // Copyright (c) 2018 Apple Inc. All rights reserved.
2
3 #import "OctagonTestHarnessXPCService.h"
4
5 #import <objc/runtime.h>
6 #import <Security/CKKSControlProtocol.h>
7 #import <Security/SecAccessControlPriv.h>
8 #import "SecDbKeychainItem.h"
9 #import "SecRemoteDevice.h"
10 #import "OTControl.h"
11
12 @interface OctagonTestHarnessXPCService ()
13 @property (strong) SecRemoteDevice *remoteDevice;
14 @end
15
16 #pragma clang diagnostic push
17 #pragma clang diagnostic ignored "-Wprotocol"
18
19 @implementation OctagonTestHarnessXPCService
20
21 - (instancetype)init {
22 if ((self = [super init]) != NULL) {
23 self.remoteDevice = [SecRemoteDevice new];
24 if (self.remoteDevice == nil) {
25 return nil;
26 }
27 }
28 return self;
29 }
30
31 - (void)octagonReset:(NSString *)altDSID complete:(void (^)(NSNumber *, NSError *))complete {
32 NSError *error = nil;
33
34 OTControl* rpc = [OTControl controlObject:true error:&error];
35 if (rpc == nil) {
36 complete(@NO, error);
37
38 return;
39 }
40
41 [rpc resetAndEstablish:NULL context:OTDefaultContext altDSID:altDSID reply:^(NSError * _Nullable e) {
42 complete([NSNumber numberWithBool:e != NULL], e);
43 }];
44 }
45
46 /* Oh, ObjC, you are my friend */
47 - (void)forwardInvocation:(NSInvocation *)invocation {
48 struct objc_method_description desc = protocol_getMethodDescription(@protocol(SecRemoteDeviceProtocol), [invocation selector], true, true);
49 if (desc.name == NULL) {
50 [super forwardInvocation:invocation];
51 } else {
52 [invocation invokeWithTarget:self.remoteDevice];
53 }
54 }
55
56 @end
57
58 #pragma clang diagnostic pop