]> git.saurik.com Git - apple/security.git/blob - keychain/ot/OTClientVoucherOperation.m
Security-59754.41.1.tar.gz
[apple/security.git] / keychain / ot / OTClientVoucherOperation.m
1 /*
2 * Copyright (c) 2018 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #if OCTAGON
25
26 #import <utilities/debugging.h>
27
28 #import "keychain/ot/OTClientVoucherOperation.h"
29 #import "keychain/ot/OTClientStateMachine.h"
30 #import "keychain/ot/OTOperationDependencies.h"
31 #import "keychain/ot/OTFetchCKKSKeysOperation.h"
32
33 #import "keychain/TrustedPeersHelper/TrustedPeersHelperProtocol.h"
34 #import "keychain/ot/ObjCImprovements.h"
35
36 @interface OTClientVoucherOperation ()
37 @property OTOperationDependencies* operationDependencies;
38 @property NSOperation* finishedOp;
39 @end
40
41 @implementation OTClientVoucherOperation
42 @synthesize intendedState = _intendedState;
43
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
53 {
54 if((self = [super init])) {
55 _intendedState = intendedState;
56 _nextState = errorState;
57
58 _operationDependencies = dependencies;
59
60 self.peerID = peerID;
61 self.permanentInfo = permanentInfo;
62 self.permanentInfoSig = permanentInfoSig;
63 self.stableInfo = stableInfo;
64 self.stableInfoSig = stableInfoSig;
65 self.deviceInfo = deviceInfo;
66 }
67 return self;
68 }
69
70 - (void)groupStart
71 {
72 secnotice("octagon", "creating voucher");
73
74 self.finishedOp = [[NSOperation alloc] init];
75 [self dependOnBeforeGroupFinished:self.finishedOp];
76
77 WEAKIFY(self);
78
79 // Acquire the CKKS TLKs to pass in
80 OTFetchCKKSKeysOperation* fetchKeysOp = [[OTFetchCKKSKeysOperation alloc] initWithDependencies:self.operationDependencies
81 refetchNeeded:NO];
82 [self runBeforeGroupFinished:fetchKeysOp];
83
84 CKKSResultOperation* proceedWithKeys = [CKKSResultOperation named:@"vouch-with-keys"
85 withBlock:^{
86 STRONGIFY(self);
87 [self proceedWithKeys:fetchKeysOp.viewKeySets];
88 }];
89
90 [proceedWithKeys addDependency:fetchKeysOp];
91 [self runBeforeGroupFinished:proceedWithKeys];
92 }
93
94 - (void)proceedWithKeys:(NSArray<CKKSKeychainBackedKeySet*>*)viewKeySets
95 {
96 WEAKIFY(self);
97
98 secnotice("octagon", "vouching with %d keysets", (int)viewKeySets.count);
99
100 [self.operationDependencies.cuttlefishXPCWrapper vouchWithContainer:self.deviceInfo.containerName
101 context:self.deviceInfo.contextID
102 peerID:self.peerID
103 permanentInfo:self.permanentInfo
104 permanentInfoSig:self.permanentInfoSig
105 stableInfo:self.stableInfo
106 stableInfoSig:self.stableInfoSig
107 ckksKeys:viewKeySets
108 reply:^(NSData * _Nullable voucher,
109 NSData * _Nullable voucherSig,
110 NSError * _Nullable error)
111 {
112 STRONGIFY(self);
113 if(error){
114 secerror("octagon: Error preparing voucher: %@", error);
115 self.error = error;
116 }else{
117 self.voucher = voucher;
118 self.voucherSig = voucherSig;
119 self.nextState = self.intendedState;
120 }
121 [self runBeforeGroupFinished:self.finishedOp];
122 }];
123 }
124
125 @end
126
127 #endif // OCTAGON