]> git.saurik.com Git - apple/security.git/blob - keychain/ot/OTClientVoucherOperation.m
Security-59306.41.2.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 [self runBeforeGroupFinished:fetchKeysOp];
82
83 CKKSResultOperation* proceedWithKeys = [CKKSResultOperation named:@"vouch-with-keys"
84 withBlock:^{
85 STRONGIFY(self);
86 [self proceedWithKeys:fetchKeysOp.viewKeySets];
87 }];
88
89 [proceedWithKeys addDependency:fetchKeysOp];
90 [self runBeforeGroupFinished:proceedWithKeys];
91 }
92
93 - (void)proceedWithKeys:(NSArray<CKKSKeychainBackedKeySet*>*)viewKeySets
94 {
95 WEAKIFY(self);
96
97 secnotice("octagon", "vouching with %d keysets", (int)viewKeySets.count);
98
99 [self.operationDependencies.cuttlefishXPCWrapper vouchWithContainer:self.deviceInfo.containerName
100 context:self.deviceInfo.contextID
101 peerID:self.peerID
102 permanentInfo:self.permanentInfo
103 permanentInfoSig:self.permanentInfoSig
104 stableInfo:self.stableInfo
105 stableInfoSig:self.stableInfoSig
106 ckksKeys:viewKeySets
107 reply:^(NSData * _Nullable voucher,
108 NSData * _Nullable voucherSig,
109 NSError * _Nullable error)
110 {
111 STRONGIFY(self);
112 if(error){
113 secerror("octagon: Error preparing voucher: %@", error);
114 self.error = error;
115 }else{
116 self.voucher = voucher;
117 self.voucherSig = voucherSig;
118 self.nextState = self.intendedState;
119 }
120 [self runBeforeGroupFinished:self.finishedOp];
121 }];
122 }
123
124 @end
125
126 #endif // OCTAGON