]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSLocalResetOperation.m
Security-59754.80.3.tar.gz
[apple/security.git] / keychain / ckks / CKKSLocalResetOperation.m
1
2 #if OCTAGON
3
4 #import "keychain/categories/NSError+UsefulConstructors.h"
5 #import "keychain/ckks/CKKSLocalResetOperation.h"
6 #import "keychain/ckks/CKKSZoneStateEntry.h"
7 #import "keychain/ckks/CKKSOutgoingQueueEntry.h"
8 #import "keychain/ckks/CKKSIncomingQueueEntry.h"
9 #import "keychain/ckks/CKKSCurrentItemPointer.h"
10 #import "keychain/ckks/CKKSMirrorEntry.h"
11 #import "keychain/ot/OTDefines.h"
12
13 @implementation CKKSLocalResetOperation
14
15 @synthesize nextState = _nextState;
16 @synthesize intendedState = _intendedState;
17
18 - (instancetype)initWithDependencies:(CKKSOperationDependencies*)dependencies
19 intendedState:(OctagonState*)intendedState
20 errorState:(OctagonState*)errorState
21 {
22 if(self = [super init]) {
23 _deps = dependencies;
24
25 _intendedState = intendedState;
26 _nextState = errorState;
27
28 self.name = @"ckks-local-reset";
29 }
30 return self;
31 }
32
33 - (void)main {
34 [self.deps.databaseProvider dispatchSyncWithSQLTransaction:^CKKSDatabaseTransactionResult {
35 [self onqueuePerformLocalReset];
36 return CKKSDatabaseTransactionCommit;
37 }];
38 }
39
40 - (void)onqueuePerformLocalReset
41 {
42 NSError* localerror = nil;
43
44 CKKSZoneStateEntry* ckse = [CKKSZoneStateEntry state:self.deps.zoneID.zoneName];
45 ckse.ckzonecreated = false;
46 ckse.ckzonesubscribed = false; // I'm actually not sure about this: can you be subscribed to a non-existent zone?
47 ckse.changeToken = NULL;
48 [ckse saveToDatabase:&localerror];
49 if(localerror && self.error == nil) {
50 ckkserror("local-reset", self.deps.zoneID, "couldn't reset zone status: %@", localerror);
51 self.error = localerror;
52 localerror = nil;
53 }
54
55 [CKKSMirrorEntry deleteAll:self.deps.zoneID error:&localerror];
56 if(localerror && self.error == nil) {
57 ckkserror("local-reset", self.deps.zoneID, "couldn't delete all CKKSMirrorEntry: %@", localerror);
58 self.error = localerror;
59 localerror = nil;
60 }
61
62 [CKKSOutgoingQueueEntry deleteAll:self.deps.zoneID error:&localerror];
63 if(localerror && self.error == nil) {
64 ckkserror("local-reset", self.deps.zoneID, "couldn't delete all CKKSOutgoingQueueEntry: %@", localerror);
65 self.error = localerror;
66 localerror = nil;
67 }
68
69 [CKKSIncomingQueueEntry deleteAll:self.deps.zoneID error:&localerror];
70 if(localerror && self.error == nil) {
71 ckkserror("local-reset", self.deps.zoneID, "couldn't delete all CKKSIncomingQueueEntry: %@", localerror);
72 self.error = localerror;
73 localerror = nil;
74 }
75
76 [CKKSKey deleteAll:self.deps.zoneID error:&localerror];
77 if(localerror && self.error == nil) {
78 ckkserror("local-reset", self.deps.zoneID, "couldn't delete all CKKSKey: %@", localerror);
79 self.error = localerror;
80 localerror = nil;
81 }
82
83 [CKKSTLKShareRecord deleteAll:self.deps.zoneID error:&localerror];
84 if(localerror && self.error == nil) {
85 ckkserror("local-reset", self.deps.zoneID, "couldn't delete all CKKSTLKShare: %@", localerror);
86 self.error = localerror;
87 localerror = nil;
88 }
89
90 [CKKSCurrentKeyPointer deleteAll:self.deps.zoneID error:&localerror];
91 if(localerror && self.error == nil) {
92 ckkserror("local-reset", self.deps.zoneID, "couldn't delete all CKKSCurrentKeyPointer: %@", localerror);
93 self.error = localerror;
94 localerror = nil;
95 }
96
97 [CKKSCurrentItemPointer deleteAll:self.deps.zoneID error:&localerror];
98 if(localerror && self.error == nil) {
99 ckkserror("local-reset", self.deps.zoneID, "couldn't delete all CKKSCurrentItemPointer: %@", localerror);
100 self.error = localerror;
101 localerror = nil;
102 }
103
104 [CKKSDeviceStateEntry deleteAll:self.deps.zoneID error:&localerror];
105 if(localerror && self.error == nil) {
106 ckkserror("local-reset", self.deps.zoneID, "couldn't delete all CKKSDeviceStateEntry: %@", localerror);
107 self.error = localerror;
108 localerror = nil;
109 }
110
111 if(!self.error) {
112 ckksnotice("local-reset", self.deps.zoneID, "Successfully deleted all local data");
113 self.nextState = self.intendedState;
114 }
115 }
116
117 @end
118
119 #endif // OCTAGON
120