]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSAnalytics.m
Security-59306.41.2.tar.gz
[apple/security.git] / keychain / ckks / CKKSAnalytics.m
1 /*
2 * Copyright (c) 2017 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 <CloudKit/CloudKit.h>
27 #import <CloudKit/CloudKit_Private.h>
28 #import <os/log.h>
29
30 #import "keychain/ckks/CKKSAnalytics.h"
31 #import "keychain/ot/OTDefines.h"
32 #import "keychain/ckks/CKKS.h"
33 #import "keychain/ckks/CKKSViewManager.h"
34 #import "keychain/ckks/CKKSKeychainView.h"
35 #include <utilities/SecFileLocations.h>
36 #include <sys/stat.h>
37
38 NSString* const CKKSAnalyticsInCircle = @"inCircle";
39 NSString* const CKKSAnalyticsHasTLKs = @"TLKs";
40 NSString* const CKKSAnalyticsSyncedClassARecently = @"inSyncA";
41 NSString* const CKKSAnalyticsSyncedClassCRecently = @"inSyncC";
42 NSString* const CKKSAnalyticsIncomingQueueIsErrorFree = @"IQNOE";
43 NSString* const CKKSAnalyticsOutgoingQueueIsErrorFree = @"OQNOE";
44 NSString* const CKKSAnalyticsInSync = @"inSync";
45 NSString* const CKKSAnalyticsValidCredentials = @"validCredentials";
46 NSString* const CKKSAnalyticsLastUnlock = @"lastUnlock";
47 NSString* const CKKSAnalyticsLastKeystateReady = @"lastKSR";
48 NSString* const CKKSAnalyticsLastInCircle = @"lastInCircle";
49
50 NSString* const OctagonAnalyticsStateMachineState = @"OASMState";
51 NSString* const OctagonAnalyticIcloudAccountState = @"OAiC";
52 NSString* const OctagonAnalyticsTrustState = @"OATrust";
53 NSString* const OctagonAnalyticsLastHealthCheck = @"OAHealthCheck";
54 NSString* const OctagonAnalyticsSOSStatus = @"OASOSStatus";
55 NSString* const OctagonAnalyticsDateOfLastPreflightPreapprovedJoin = @"OALastPPJ";
56 NSString* const OctagonAnalyticsLastKeystateReady = @"OALastKSR";
57 NSString* const OctagonAnalyticsLastCoreFollowup = @"OALastCFU";
58 //NSString* const OctagonAnalyticsCoreFollowupStatus = @"OACFUStatus";
59 NSString* const OctagonAnalyticsCoreFollowupFailureCount = @"OACFUTFailureCount";
60 NSString* const OctagonAnalyticsCoreFollowupLastFailureTime = @"OACFULastFailureTime";
61 NSString* const OctagonAnalyticsPrerecordPending = @"OAPrerecordPending";
62 NSString* const OctagonAnalyticsCDPStateRun = @"OACDPStateRun";
63
64 NSString* const CKKSAnalyticsLastCKKSPush = @"lastCKKSPush";
65 NSString* const CKKSAnalyticsLastOctagonPush = @"lastOctagonPush";
66
67 NSString* const OctagonAnalyticsKVSProvisioned = @"OADCKVSProvisioned";
68 NSString* const OctagonAnalyticsKVSEnabled = @"OADCKVSEnabled";
69 NSString* const OctagonAnalyticsKeychainSyncProvisioned = @"OADCKCSProvisioned";
70 NSString* const OctagonAnalyticsKeychainSyncEnabled = @"OADCKCSEnabled";
71 NSString* const OctagonAnalyticsCloudKitProvisioned = @"OADCCKProvisioned";
72 NSString* const OctagonAnalyticsCloudKitEnabled = @"OADCCKEnabled";
73
74 static NSString* const CKKSAnalyticsAttributeRecoverableError = @"recoverableError";
75 static NSString* const CKKSAnalyticsAttributeZoneName = @"zone";
76 static NSString* const CKKSAnalyticsAttributeErrorDomain = @"errorDomain";
77 static NSString* const CKKSAnalyticsAttributeErrorCode = @"errorCode";
78 static NSString* const CKKSAnalyticsAttributeErrorChain = @"errorChain";
79
80 CKKSAnalyticsFailableEvent* const CKKSEventProcessIncomingQueueClassA = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessIncomingQueueClassA";
81 CKKSAnalyticsFailableEvent* const CKKSEventProcessIncomingQueueClassC = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessIncomingQueueClassC";
82 CKKSAnalyticsFailableEvent* const CKKSEventProcessOutgoingQueue = (CKKSAnalyticsFailableEvent*)@"CKKSEventProcessOutgoingQueue";
83 CKKSAnalyticsFailableEvent* const CKKSEventUploadChanges = (CKKSAnalyticsFailableEvent*)@"CKKSEventUploadChanges";
84 CKKSAnalyticsFailableEvent* const CKKSEventStateError = (CKKSAnalyticsFailableEvent*)@"CKKSEventStateError";
85 CKKSAnalyticsFailableEvent* const CKKSEventProcessHealKeyHierarchy = (CKKSAnalyticsFailableEvent *)@"CKKSEventProcessHealKeyHierarchy";
86 CKKSAnalyticsFailableEvent* const CKKSEventProcessReencryption = (CKKSAnalyticsFailableEvent *)@"CKKSEventProcessReencryption";
87
88 NSString* const OctagonEventFailureReason = @"FailureReason";
89
90 CKKSAnalyticsFailableEvent* const OctagonEventPreflightBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightBottle";
91 CKKSAnalyticsFailableEvent* const OctagonEventLaunchBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventLaunchBottle";
92 CKKSAnalyticsFailableEvent* const OctagonEventRestoreBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventRestoreBottle";
93 CKKSAnalyticsFailableEvent* const OctagonEventScrubBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventScrubBottle";
94 CKKSAnalyticsFailableEvent* const OctagonEventSignIn = (CKKSAnalyticsFailableEvent *)@"OctagonEventSignIn";
95 CKKSAnalyticsFailableEvent* const OctagonEventSignOut = (CKKSAnalyticsFailableEvent *)@"OctagonEventSignIn";
96 CKKSAnalyticsFailableEvent* const OctagonEventRamp = (CKKSAnalyticsFailableEvent *)@"OctagonEventRamp";
97 CKKSAnalyticsFailableEvent* const OctagonEventBottleCheck = (CKKSAnalyticsFailableEvent *)@"OctagonEventBottleCheck";
98 CKKSAnalyticsFailableEvent* const OctagonEventCoreFollowUp = (CKKSAnalyticsFailableEvent *)@"OctagonEventCoreFollowUp";
99 CKKSAnalyticsFailableEvent* const OctagonEventUpdateBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpdateBottle";
100
101 CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustState = (CKKSAnalyticsFailableEvent *)@"OctagonEventCheckTrustState";
102
103 CKKSAnalyticsFailableEvent* const OctagonEventBottledPeerRestore = (CKKSAnalyticsFailableEvent*)@"OctagonEventBottledPeerRestore";
104 CKKSAnalyticsFailableEvent* const OctagonEventRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventRecoveryKey";
105
106 CKKSAnalyticsFailableEvent* const OctagonEventFetchAllBottles = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchAllBottles";
107 CKKSAnalyticsFailableEvent* const OctagonEventFetchEscrowContents = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchEscrowContents";
108 CKKSAnalyticsFailableEvent* const OctagonEventResetAndEstablish = (CKKSAnalyticsFailableEvent*)@"OctagonEventResetAndEstablish";
109 CKKSAnalyticsFailableEvent* const OctagonEventEstablish = (CKKSAnalyticsFailableEvent*)@"OctagonEventEstablish";
110 CKKSAnalyticsFailableEvent* const OctagonEventLeaveClique = (CKKSAnalyticsFailableEvent*)@"OctagonEventLeaveClique";
111 CKKSAnalyticsFailableEvent* const OctagonEventRemoveFriendsInClique = (CKKSAnalyticsFailableEvent*)@"OctagonEventRemoveFriendsInClique";
112
113 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeFetchDeviceIDs = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeFetchDeviceIDs";
114 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeSetAllowList = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeSetAllowList";
115 CKKSAnalyticsFailableEvent* const OctagonEventUpgradeSilentEscrow = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradeSilentEscrow";
116 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreapprovedJoin = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreapprovedJoin";
117 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreflightPreapprovedJoin = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreflightPreapprovedJoin";
118 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreapprovedJoinAfterPairing = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePreapprovedJoinAfterPairing";
119 CKKSAnalyticsFailableEvent* const OctagonEventUpgradePrepare = (CKKSAnalyticsFailableEvent*)@"OctagonEventUpgradePrepare";
120
121 CKKSAnalyticsFailableEvent* const OctagonEventJoinWithVoucher = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinWithVoucher";
122
123 CKKSAnalyticsFailableEvent* const OctagonEventPreflightVouchWithBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventPreflightVouchWithBottle";
124 CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithBottle = (CKKSAnalyticsFailableEvent*)@"OctagonEventVoucherWithBottle";
125
126 CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventVoucherWithRecoveryKey";
127
128 CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKey = (CKKSAnalyticsFailableEvent*)@"OctagonEventSetRecoveryKey";
129
130 CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKeyValidationFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventSetRecoveryKeyValidationFailed";
131 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyValidationFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyValidationFailed";
132 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyCircleReset = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyCircleReset";
133 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyCircleResetFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyCircleResetFailed";
134 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyEnrollFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyEnrollFailed";
135 CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyFailed = (CKKSAnalyticsFailableEvent*)@"OctagonEventJoinRecoveryKeyFailed";
136
137 CKKSAnalyticsFailableEvent* const OctagonEventReset = (CKKSAnalyticsFailableEvent*)@"OctagonEventReset";
138
139 CKKSAnalyticsFailableEvent* const OctagonEventPrepareIdentity = (CKKSAnalyticsFailableEvent*)@"OctagonEventPrepareIdentity";
140
141 CKKSAnalyticsFailableEvent* const OctagonEventEstablishIdentity = (CKKSAnalyticsFailableEvent*)@"OctagonEventEstablishIdentity";
142 CKKSAnalyticsFailableEvent* const OctagonEventFetchViews = (CKKSAnalyticsFailableEvent*)@"OctagonEventFetchViews";
143
144 CKKSAnalyticsFailableEvent* const OctagonEventStateTransition = (CKKSAnalyticsFailableEvent*)@"OctagonEventStateTransition";
145
146 CKKSAnalyticsFailableEvent* const OctagonEventCompanionPairing = (CKKSAnalyticsFailableEvent*)@"OctagonEventCompanionPairing";
147
148 CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustForCFU = (CKKSAnalyticsFailableEvent*)@"OctagonEventCheckTrustForCFU";
149
150 CKKSAnalyticsSignpostEvent* const CKKSEventPushNotificationReceived = (CKKSAnalyticsSignpostEvent*)@"CKKSEventPushNotificationReceived";
151 CKKSAnalyticsSignpostEvent* const CKKSEventItemAddedToOutgoingQueue = (CKKSAnalyticsSignpostEvent*)@"CKKSEventItemAddedToOutgoingQueue";
152 CKKSAnalyticsSignpostEvent* const CKKSEventMissingLocalItemsFound = (CKKSAnalyticsSignpostEvent*)@"CKKSEventMissingLocalItemsFound";
153 CKKSAnalyticsSignpostEvent* const CKKSEventReachabilityTimerExpired = (CKKSAnalyticsSignpostEvent *)@"CKKSEventReachabilityTimerExpired";
154
155 CKKSAnalyticsFailableEvent* const OctagonEventTPHHealthCheckStatus = (CKKSAnalyticsFailableEvent*)@"OctagonEventTPHHealthCheckStatus";
156
157 CKKSAnalyticsActivity* const CKKSActivityOTFetchRampState = (CKKSAnalyticsActivity *)@"CKKSActivityOTFetchRampState";
158 CKKSAnalyticsActivity* const CKKSActivityOctagonPreflightBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonPreflightBottle";
159 CKKSAnalyticsActivity* const CKKSActivityOctagonLaunchBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonLaunchBottle";
160 CKKSAnalyticsActivity* const CKKSActivityOctagonRestore = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonRestore";
161 CKKSAnalyticsActivity* const CKKSActivityScrubBottle = (CKKSAnalyticsActivity *)@"CKKSActivityScrubBottle";
162 CKKSAnalyticsActivity* const CKKSActivityBottleCheck = (CKKSAnalyticsActivity *)@"CKKSActivityBottleCheck";
163 CKKSAnalyticsActivity* const CKKSActivityOctagonUpdateBottle = (CKKSAnalyticsActivity *)@"CKKSActivityOctagonUpdateBottle";
164
165 CKKSAnalyticsActivity* const OctagonActivityAccountAvailable = (CKKSAnalyticsActivity *)@"OctagonActivityAccountAvailable";
166 CKKSAnalyticsActivity* const OctagonActivityAccountNotAvailable = (CKKSAnalyticsActivity *)@"OctagonActivityAccountNotAvailable";
167 CKKSAnalyticsActivity* const OctagonActivityResetAndEstablish = (CKKSAnalyticsActivity *)@"OctagonActivityResetAndEstablish";
168 CKKSAnalyticsActivity* const OctagonActivityEstablish = (CKKSAnalyticsActivity *)@"OctagonActivityEstablish";
169 CKKSAnalyticsActivity* const OctagonSOSAdapterUpdateKeys = (CKKSAnalyticsActivity*)@"OctagonSOSAdapterUpdateKeys";
170
171 CKKSAnalyticsActivity* const OctagonActivityFetchAllViableBottles = (CKKSAnalyticsActivity *)@"OctagonActivityFetchAllViableBottles";
172 CKKSAnalyticsActivity* const OctagonActivityFetchEscrowContents = (CKKSAnalyticsActivity *)@"OctagonActivityFetchEscrowContents";
173 CKKSAnalyticsActivity* const OctagonActivityBottledPeerRestore = (CKKSAnalyticsActivity *)@"OctagonActivityBottledPeerRestore";
174 CKKSAnalyticsActivity* const OctagonActivitySetRecoveryKey = (CKKSAnalyticsActivity *)@"OctagonActivitySetRecoveryKey";
175 CKKSAnalyticsActivity* const OctagonActivityJoinWithRecoveryKey = (CKKSAnalyticsActivity *)@"OctagonActivityJoinWithRecoveryKey";
176
177 CKKSAnalyticsActivity* const OctagonActivityLeaveClique = (CKKSAnalyticsActivity *)@"OctagonActivityLeaveClique";
178 CKKSAnalyticsActivity* const OctagonActivityRemoveFriendsInClique = (CKKSAnalyticsActivity *)@"OctagonActivityRemoveFriendsInClique";
179
180
181
182 @implementation CKKSAnalytics
183
184 + (NSString*)databasePath
185 {
186 // This block exists because we moved database locations in 11.3 for easier sandboxing of securityuploadd, so we're cleaning up.
187 static dispatch_once_t onceToken;
188 dispatch_once(&onceToken, ^{
189 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db"), ^(const char *filename) {
190 remove(filename);
191 });
192 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db-wal"), ^(const char *filename) {
193 remove(filename);
194 });
195 WithPathInKeychainDirectory(CFSTR("ckks_analytics_v2.db-shm"), ^(const char *filename) {
196 remove(filename);
197 });
198 });
199 return [CKKSAnalytics defaultAnalyticsDatabasePath:@"ckks_analytics"];
200 }
201
202 + (instancetype)logger
203 {
204 // just here because I want it in the header for discoverability
205 return [super logger];
206 }
207
208 - (void)logSuccessForEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view
209 {
210 [self logSuccessForEventNamed:[NSString stringWithFormat:@"%@-%@", view.zoneName, event]];
211 [self setDateProperty:[NSDate date] forKey:[NSString stringWithFormat:@"last_success_%@-%@", view.zoneName, event]];
212 }
213
214 - (bool)isCKPartialError:(NSError *)error
215 {
216 return [error.domain isEqualToString:CKErrorDomain] && error.code == CKErrorPartialFailure;
217 }
218
219 - (void)addCKPartialError:(NSMutableDictionary *)errorDictionary error:(NSError *)error depth:(NSUInteger)depth
220 {
221 // capture one random underlaying error
222 if ([self isCKPartialError:error]) {
223 NSDictionary<NSString *,NSError *> *partialErrors = error.userInfo[CKPartialErrorsByItemIDKey];
224 if ([partialErrors isKindOfClass:[NSDictionary class]]) {
225 for (NSString *key in partialErrors) {
226 NSError* ckError = partialErrors[key];
227 if (![ckError isKindOfClass:[NSError class]])
228 continue;
229 if ([ckError.domain isEqualToString:CKErrorDomain] && ckError.code == CKErrorBatchRequestFailed) {
230 continue;
231 }
232 NSDictionary *res = [self errorChain:ckError depth:(depth + 1)];
233 if (res) {
234 errorDictionary[@"oneCloudKitPartialFailure"] = res;
235 break;
236 }
237 }
238 }
239 }
240 }
241
242 // if we have underlying errors, capture the chain below the top-most error
243 - (NSDictionary *)errorChain:(NSError *)error depth:(NSUInteger)depth
244 {
245 NSMutableDictionary *errorDictionary = nil;
246
247 if (depth > 5 || ![error isKindOfClass:[NSError class]])
248 return nil;
249
250 errorDictionary = [@{
251 @"domain" : error.domain,
252 @"code" : @(error.code),
253 } mutableCopy];
254
255 errorDictionary[@"child"] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:(depth + 1)];
256 [self addCKPartialError:errorDictionary error:error depth:(depth + 1)];
257
258 return errorDictionary;
259 }
260
261 - (NSDictionary *)createErrorAttributes:(NSError *)error
262 depth:(NSUInteger)depth
263 attributes:(NSDictionary *)attributes
264 {
265 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
266
267 /* Don't allow caller to overwrite our attributes, lets merge them first */
268 if (attributes) {
269 [eventAttributes setValuesForKeysWithDictionary:attributes];
270 }
271
272 [eventAttributes setValuesForKeysWithDictionary:@{
273 CKKSAnalyticsAttributeRecoverableError : @(YES),
274 CKKSAnalyticsAttributeErrorDomain : error.domain,
275 CKKSAnalyticsAttributeErrorCode : @(error.code)
276 }];
277
278 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
279 [self addCKPartialError:eventAttributes error:error depth:0];
280
281 return eventAttributes;
282 }
283
284 - (void)logRecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event zoneName:(NSString*)zoneName withAttributes:(NSDictionary *)attributes
285 {
286 if (error == nil){
287 return;
288 }
289 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
290
291 /* Don't allow caller to overwrite our attributes, lets merge them first */
292 if (attributes) {
293 [eventAttributes setValuesForKeysWithDictionary:attributes];
294 }
295
296 [eventAttributes setValuesForKeysWithDictionary:@{
297 CKKSAnalyticsAttributeRecoverableError : @(YES),
298 CKKSAnalyticsAttributeZoneName : zoneName,
299 CKKSAnalyticsAttributeErrorDomain : error.domain,
300 CKKSAnalyticsAttributeErrorCode : @(error.code)
301 }];
302
303 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
304 [self addCKPartialError:eventAttributes error:error depth:0];
305
306 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
307 }
308
309 - (void)logRecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event withAttributes:(NSDictionary *)attributes
310 {
311 if (error == nil){
312 return;
313 }
314 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
315
316 /* Don't allow caller to overwrite our attributes, lets merge them first */
317 if (attributes) {
318 [eventAttributes setValuesForKeysWithDictionary:attributes];
319 }
320
321 [eventAttributes setValuesForKeysWithDictionary:@{
322 CKKSAnalyticsAttributeRecoverableError : @(YES),
323 CKKSAnalyticsAttributeErrorDomain : error.domain,
324 CKKSAnalyticsAttributeErrorCode : @(error.code)
325 }];
326
327 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
328 [self addCKPartialError:eventAttributes error:error depth:0];
329
330 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
331 }
332
333 - (void)logRecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view withAttributes:(NSDictionary *)attributes
334 {
335 if (error == nil){
336 return;
337 }
338 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
339
340 /* Don't allow caller to overwrite our attributes, lets merge them first */
341 if (attributes) {
342 [eventAttributes setValuesForKeysWithDictionary:attributes];
343 }
344
345 [eventAttributes setValuesForKeysWithDictionary:@{
346 CKKSAnalyticsAttributeRecoverableError : @(YES),
347 CKKSAnalyticsAttributeZoneName : view.zoneName,
348 CKKSAnalyticsAttributeErrorDomain : error.domain,
349 CKKSAnalyticsAttributeErrorCode : @(error.code)
350 }];
351
352 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
353 [self addCKPartialError:eventAttributes error:error depth:0];
354
355 [super logSoftFailureForEventNamed:event withAttributes:eventAttributes];
356 }
357
358 - (void)logUnrecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view withAttributes:(NSDictionary *)attributes
359 {
360 if (error == nil){
361 return;
362 }
363 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
364 if (attributes) {
365 [eventAttributes setValuesForKeysWithDictionary:attributes];
366 }
367
368 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
369 [self addCKPartialError:eventAttributes error:error depth:0];
370
371 [eventAttributes setValuesForKeysWithDictionary:@{
372 CKKSAnalyticsAttributeRecoverableError : @(NO),
373 CKKSAnalyticsAttributeZoneName : view.zoneName,
374 CKKSAnalyticsAttributeErrorDomain : error.domain,
375 CKKSAnalyticsAttributeErrorCode : @(error.code)
376 }];
377
378 [self logHardFailureForEventNamed:event withAttributes:eventAttributes];
379 }
380
381 - (void)logUnrecoverableError:(NSError*)error forEvent:(CKKSAnalyticsFailableEvent*)event withAttributes:(NSDictionary *)attributes
382 {
383 if (error == nil){
384 return;
385 }
386 NSMutableDictionary* eventAttributes = [NSMutableDictionary dictionary];
387
388 /* Don't allow caller to overwrite our attributes, lets merge them first */
389 if (attributes) {
390 [eventAttributes setValuesForKeysWithDictionary:attributes];
391 }
392
393 eventAttributes[CKKSAnalyticsAttributeErrorChain] = [self errorChain:error.userInfo[NSUnderlyingErrorKey] depth:0];
394 [self addCKPartialError:eventAttributes error:error depth:0];
395
396 [eventAttributes setValuesForKeysWithDictionary:@{
397 CKKSAnalyticsAttributeRecoverableError : @(NO),
398 CKKSAnalyticsAttributeZoneName : OctagonEventAttributeZoneName,
399 CKKSAnalyticsAttributeErrorDomain : error.domain,
400 CKKSAnalyticsAttributeErrorCode : @(error.code)
401 }];
402
403 [self logHardFailureForEventNamed:event withAttributes:eventAttributes];
404 }
405
406 - (void)noteEvent:(CKKSAnalyticsSignpostEvent*)event
407 {
408 [self noteEventNamed:event];
409 }
410 - (void)noteEvent:(CKKSAnalyticsSignpostEvent*)event inView:(CKKSKeychainView*)view
411 {
412 [self noteEventNamed:[NSString stringWithFormat:@"%@-%@", view.zoneName, event]];
413 }
414
415 - (NSDate*)dateOfLastSuccessForEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view
416 {
417 return [self datePropertyForKey:[NSString stringWithFormat:@"last_success_%@-%@", view.zoneName, event]];
418 }
419
420 - (void)setDateProperty:(NSDate*)date forKey:(NSString*)key inView:(CKKSKeychainView *)view
421 {
422 [self setDateProperty:date forKey:[NSString stringWithFormat:@"%@-%@", key, view.zoneName]];
423 }
424 - (NSDate *)datePropertyForKey:(NSString *)key inView:(CKKSKeychainView *)view
425 {
426 return [self datePropertyForKey:[NSString stringWithFormat:@"%@-%@", key, view.zoneName]];
427 }
428
429 @end
430
431 #endif // OCTAGON