2 * Copyright (c) 2019 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 "keychain/ot/OTFetchViewsOperation.h"
27 #import "keychain/ot/ObjCImprovements.h"
28 #import "keychain/TrustedPeersHelper/TrustedPeersHelperProtocol.h"
29 #import "keychain/ckks/CKKSAnalytics.h"
31 @interface OTFetchViewsOperation ()
32 @property OTOperationDependencies* deps;
33 @property NSOperation* finishedOp;
34 @property CKKSViewManager* ckm;
37 @implementation OTFetchViewsOperation
39 - (instancetype)initWithDependencies:(OTOperationDependencies*)dependencies
41 if ((self = [super init])) {
43 _ckm = dependencies.viewManager;
50 secnotice("octagon", "fetching views");
52 self.finishedOp = [[NSOperation alloc] init];
53 [self dependOnBeforeGroupFinished:self.finishedOp];
55 NSSet<NSString*>* sosViewList = [self.ckm viewList];
57 self.viewList = sosViewList;
59 if ([self.ckm useCKKSViewsFromPolicy]) {
62 NSXPCConnection<TrustedPeersHelperProtocol>* proxy = [self.deps.cuttlefishXPC remoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) {
64 secerror("octagon: Can't talk with TrustedPeersHelper: %@", error);
65 [[CKKSAnalytics logger] logUnrecoverableError:error forEvent:OctagonEventFetchViews withAttributes:nil];
67 [self runBeforeGroupFinished:self.finishedOp];
70 [proxy fetchPolicyWithContainer:self.deps.containerName context:self.deps.contextID reply:^(TPPolicy* _Nullable policy, NSError* _Nullable error) {
73 secerror("octagon: failed to retrieve policy: %@", error);
74 [[CKKSAnalytics logger] logResultForEvent:OctagonEventFetchViews hardFailure:true result:error];
76 [self runBeforeGroupFinished:self.finishedOp];
79 secerror("octagon: no policy returned");
83 NSArray<NSString*>* sosViews = [sosViewList allObjects];
84 [proxy getViewsWithContainer:self.deps.containerName context:self.deps.contextID inViews:sosViews reply:^(NSArray<NSString*>* _Nullable outViews, NSError* _Nullable error) {
87 secerror("octagon: failed to retrieve list of views: %@", error);
88 [[CKKSAnalytics logger] logResultForEvent:OctagonEventFetchViews hardFailure:true result:error];
90 [self runBeforeGroupFinished:self.finishedOp];
92 if (outViews == nil) {
93 secerror("octagon: bad results from getviews");
95 self.viewList = [NSSet setWithArray:outViews];
109 secnotice("octagon", "viewList: %@", self.viewList);
110 self.ckm.policy = self.policy;
111 self.ckm.viewList = self.viewList;
113 [self.ckm createViews];
114 [self.ckm beginCloudKitOperationOfAllViews];
115 [self runBeforeGroupFinished:self.finishedOp];