2 * Copyright (c) 2018 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 #import <utilities/debugging.h>
28 #import "keychain/ot/OTClientVoucherOperation.h"
29 #import "keychain/ot/OTClientStateMachine.h"
30 #import "keychain/ot/OTOperationDependencies.h"
31 #import "keychain/ot/OTFetchCKKSKeysOperation.h"
33 #import "keychain/TrustedPeersHelper/TrustedPeersHelperProtocol.h"
34 #import "keychain/ot/ObjCImprovements.h"
36 @interface OTClientVoucherOperation ()
37 @property OTOperationDependencies* operationDependencies;
38 @property NSOperation* finishedOp;
41 @implementation OTClientVoucherOperation
42 @synthesize intendedState = _intendedState;
44 - (instancetype)initWithDependencies:(OTOperationDependencies*)dependencies
45 intendedState:(OctagonState*)intendedState
46 errorState:(OctagonState*)errorState
47 deviceInfo:(nonnull OTDeviceInformation *)deviceInfo
48 peerID:(nonnull NSString *)peerID
49 permanentInfo:(nonnull NSData *)permanentInfo
50 permanentInfoSig:(nonnull NSData *)permanentInfoSig
51 stableInfo:(nonnull NSData *)stableInfo
52 stableInfoSig:(nonnull NSData *)stableInfoSig
54 if((self = [super init])) {
55 _intendedState = intendedState;
56 _nextState = errorState;
58 _operationDependencies = dependencies;
61 self.permanentInfo = permanentInfo;
62 self.permanentInfoSig = permanentInfoSig;
63 self.stableInfo = stableInfo;
64 self.stableInfoSig = stableInfoSig;
65 self.deviceInfo = deviceInfo;
72 secnotice("octagon", "creating voucher");
74 self.finishedOp = [[NSOperation alloc] init];
75 [self dependOnBeforeGroupFinished:self.finishedOp];
79 // Acquire the CKKS TLKs to pass in
80 OTFetchCKKSKeysOperation* fetchKeysOp = [[OTFetchCKKSKeysOperation alloc] initWithDependencies:self.operationDependencies];
81 [self runBeforeGroupFinished:fetchKeysOp];
83 CKKSResultOperation* proceedWithKeys = [CKKSResultOperation named:@"vouch-with-keys"
86 [self proceedWithKeys:fetchKeysOp.viewKeySets];
89 [proceedWithKeys addDependency:fetchKeysOp];
90 [self runBeforeGroupFinished:proceedWithKeys];
93 - (void)proceedWithKeys:(NSArray<CKKSKeychainBackedKeySet*>*)viewKeySets
97 secnotice("octagon", "vouching with %d keysets", (int)viewKeySets.count);
99 [self.operationDependencies.cuttlefishXPCWrapper vouchWithContainer:self.deviceInfo.containerName
100 context:self.deviceInfo.contextID
102 permanentInfo:self.permanentInfo
103 permanentInfoSig:self.permanentInfoSig
104 stableInfo:self.stableInfo
105 stableInfoSig:self.stableInfoSig
107 reply:^(NSData * _Nullable voucher,
108 NSData * _Nullable voucherSig,
109 NSError * _Nullable error)
113 secerror("octagon: Error preparing voucher: %@", error);
116 self.voucher = voucher;
117 self.voucherSig = voucherSig;
118 self.nextState = self.intendedState;
120 [self runBeforeGroupFinished:self.finishedOp];