]> git.saurik.com Git - apple/security.git/blob - keychain/ot/OTFetchViewsOperation.m
Security-59306.61.1.tar.gz
[apple/security.git] / keychain / ot / OTFetchViewsOperation.m
1 /*
2 * Copyright (c) 2019 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 "keychain/ot/OTFetchViewsOperation.h"
27 #import "keychain/ot/ObjCImprovements.h"
28 #import "keychain/TrustedPeersHelper/TrustedPeersHelperProtocol.h"
29 #import "keychain/ckks/CKKSAnalytics.h"
30
31 @interface OTFetchViewsOperation ()
32 @property OTOperationDependencies* deps;
33 @property NSOperation* finishedOp;
34 @property CKKSViewManager* ckm;
35 @end
36
37 @implementation OTFetchViewsOperation
38
39 - (instancetype)initWithDependencies:(OTOperationDependencies*)dependencies
40 {
41 if ((self = [super init])) {
42 _deps = dependencies;
43 _ckm = dependencies.viewManager;
44 }
45 return self;
46 }
47
48 - (void)groupStart
49 {
50 secnotice("octagon", "fetching views");
51
52 self.finishedOp = [[NSOperation alloc] init];
53 [self dependOnBeforeGroupFinished:self.finishedOp];
54
55 NSSet<NSString*>* sosViewList = [self.ckm viewList];
56 self.policy = nil;
57 self.viewList = sosViewList;
58
59 if ([self.ckm useCKKSViewsFromPolicy]) {
60 WEAKIFY(self);
61
62 [self.deps.cuttlefishXPCWrapper fetchPolicyWithContainer:self.deps.containerName context:self.deps.contextID reply:^(TPPolicy* _Nullable policy, NSError* _Nullable error) {
63 STRONGIFY(self);
64 if (error) {
65 secerror("octagon: failed to retrieve policy: %@", error);
66 [[CKKSAnalytics logger] logResultForEvent:OctagonEventFetchViews hardFailure:true result:error];
67 self.error = error;
68 [self runBeforeGroupFinished:self.finishedOp];
69 } else {
70 if (policy == nil) {
71 secerror("octagon: no policy returned");
72 }
73 self.policy = policy;
74 NSArray<NSString*>* sosViews = [sosViewList allObjects];
75 [self.deps.cuttlefishXPCWrapper getViewsWithContainer:self.deps.containerName context:self.deps.contextID inViews:sosViews reply:^(NSArray<NSString*>* _Nullable outViews, NSError* _Nullable error) {
76 STRONGIFY(self);
77 if (error) {
78 secerror("octagon: failed to retrieve list of views: %@", error);
79 [[CKKSAnalytics logger] logResultForEvent:OctagonEventFetchViews hardFailure:true result:error];
80 self.error = error;
81 [self runBeforeGroupFinished:self.finishedOp];
82 } else {
83 if (outViews == nil) {
84 secerror("octagon: bad results from getviews");
85 } else {
86 self.viewList = [NSSet setWithArray:outViews];
87 }
88 [self complete];
89 }
90 }];
91 }
92 }];
93 } else {
94 [self complete];
95 }
96 }
97
98 - (void)complete {
99 secnotice("octagon", "viewList: %@", self.viewList);
100 self.ckm.policy = self.policy;
101 self.ckm.viewList = self.viewList;
102
103 [self.ckm createViews];
104 [self.ckm beginCloudKitOperationOfAllViews];
105 [self runBeforeGroupFinished:self.finishedOp];
106 }
107
108 @end
109
110 #endif // OCTAGON