4 #import "keychain/ckks/CKKSNewTLKOperation.h"
5 #import "keychain/ot/OTFetchCKKSKeysOperation.h"
6 #import "keychain/ot/ObjCImprovements.h"
8 @interface OTFetchCKKSKeysOperation ()
9 @property NSSet<CKKSKeychainView*>* views;
10 @property CKKSViewManager* manager;
13 @implementation OTFetchCKKSKeysOperation
15 - (instancetype)initWithDependencies:(OTOperationDependencies*)dependencies
17 if((self = [super init])) {
18 _manager = dependencies.viewManager;
22 _pendingTLKShares = @[];
23 _incompleteKeySets = @[];
28 - (instancetype)initWithViews:(NSSet<CKKSKeychainView*>*)views
30 if((self = [super init])) {
35 _pendingTLKShares = @[];
36 _incompleteKeySets = @[];
43 NSMutableArray<CKKSResultOperation<CKKSKeySetProviderOperationProtocol>*>* keyOps = [NSMutableArray array];
45 if (self.views == nil) {
46 NSMutableSet<CKKSKeychainView*>* mutViews = [NSMutableSet<CKKSKeychainView*> set];
47 for (id key in self.manager.views) {
48 CKKSKeychainView* view = self.manager.views[key];
49 [mutViews addObject: view];
51 self.views = mutViews;
54 for (CKKSKeychainView* view in self.views) {
55 secnotice("octagon-ckks", "Waiting for %@", view);
56 [keyOps addObject:[[view findKeySet] timeout:45*NSEC_PER_SEC]];
60 CKKSResultOperation* proceedWithKeys = [CKKSResultOperation named:@"proceed-with-ckks-keys"
64 NSMutableArray<CKKSKeychainBackedKeySet*>* viewKeySets = [NSMutableArray array];
65 NSMutableArray<CKKSCurrentKeySet*>* ckksBrokenKeySets = [NSMutableArray array];
66 NSMutableArray<CKKSTLKShare*>* tlkShares = [NSMutableArray array];
67 NSMutableArray<CKKSTLKShare*>* pendingTLKShares = [NSMutableArray array];
69 for(CKKSResultOperation<CKKSKeySetProviderOperationProtocol>* op in keyOps) {
71 secnotice("octagon-ckks", "No keys for zone %@: %@", op.zoneName, op.error);
75 NSError* localerror = nil;
76 CKKSKeychainBackedKeySet* keyset = [op.keyset asKeychainBackedSet:&localerror];
79 secnotice("octagon-ckks", "Have proposed keys: %@", op.keyset);
80 [viewKeySets addObject:keyset];
82 secnotice("octagon-ckks", "Unable to convert proposed keys: %@ %@", op.keyset, localerror);
84 [ckksBrokenKeySets addObject:op.keyset];
88 for(CKKSTLKShareRecord* tlkShareRecord in op.keyset.tlkShares) {
89 [tlkShares addObject:tlkShareRecord.share];
91 secnotice("octagon-ckks", "Have %u tlk shares", (uint32_t)op.keyset.tlkShares.count);
93 for(CKKSTLKShareRecord* tlkShareRecord in op.keyset.pendingTLKShares) {
94 [pendingTLKShares addObject:tlkShareRecord.share];
96 secnotice("octagon-ckks", "Have %u pending tlk shares", (uint32_t)op.keyset.pendingTLKShares.count);
99 self.viewKeySets = viewKeySets;
100 self.incompleteKeySets = ckksBrokenKeySets;
101 self.tlkShares = tlkShares;
102 self.pendingTLKShares = pendingTLKShares;
104 secnotice("octagon-ckks", "Fetched %d key sets, %d broken key set,s %d tlk shares, and %d pendingTLKShares",
105 (int)self.viewKeySets.count,
106 (int)self.incompleteKeySets.count,
107 (int)self.tlkShares.count,
108 (int)self.pendingTLKShares.count);
111 for(CKKSResultOperation<CKKSKeySetProviderOperationProtocol>* op in keyOps) {
112 [proceedWithKeys addDependency: op];
115 [self runBeforeGroupFinished:proceedWithKeys];