]> git.saurik.com Git - apple/security.git/blob - keychain/ckks/CKKSAnalytics.h
Security-59306.101.1.tar.gz
[apple/security.git] / keychain / ckks / CKKSAnalytics.h
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 #import <Foundation/Foundation.h>
25
26 #if OCTAGON
27 #import "Analytics/SFAnalytics.h"
28
29 extern NSString* const CKKSAnalyticsInCircle;
30 extern NSString* const CKKSAnalyticsHasTLKs;
31 extern NSString* const CKKSAnalyticsSyncedClassARecently;
32 extern NSString* const CKKSAnalyticsSyncedClassCRecently;
33 extern NSString* const CKKSAnalyticsIncomingQueueIsErrorFree;
34 extern NSString* const CKKSAnalyticsOutgoingQueueIsErrorFree;
35 extern NSString* const CKKSAnalyticsInSync;
36 extern NSString* const CKKSAnalyticsValidCredentials;
37 extern NSString* const CKKSAnalyticsLastUnlock;
38 extern NSString* const CKKSAnalyticsLastKeystateReady;
39 extern NSString* const CKKSAnalyticsLastInCircle;
40
41 extern NSString* const OctagonAnalyticsStateMachineState;
42 extern NSString* const OctagonAnalyticIcloudAccountState;
43 extern NSString* const OctagonAnalyticCDPBitStatus;
44 extern NSString* const OctagonAnalyticsTrustState;
45 extern NSString* const OctagonAnalyticsAttemptedJoin;
46 extern NSString* const OctagonAnalyticsLastHealthCheck;
47 extern NSString* const OctagonAnalyticsSOSStatus;
48 extern NSString* const OctagonAnalyticsDateOfLastPreflightPreapprovedJoin;
49 extern NSString* const OctagonAnalyticsLastKeystateReady;
50 extern NSString* const OctagonAnalyticsLastCoreFollowup;
51 extern NSString* const OctagonAnalyticsCoreFollowupFailureCount;
52 extern NSString* const OctagonAnalyticsCoreFollowupLastFailureTime;
53 extern NSString* const OctagonAnalyticsPrerecordPending;
54 extern NSString* const OctagonAnalyticsCDPStateRun;
55
56 extern NSString* const OctagonAnalyticsHaveMachineID;
57 extern NSString* const OctagonAnalyticsMIDOnMemoizedList;
58 extern NSString* const OctagonAnalyticsPeersWithMID;
59
60 extern NSString* const CKKSAnalyticsLastCKKSPush;
61 extern NSString* const CKKSAnalyticsLastOctagonPush;
62
63 extern NSString* const OctagonAnalyticsKVSProvisioned;
64 extern NSString* const OctagonAnalyticsKVSEnabled;
65 extern NSString* const OctagonAnalyticsKeychainSyncProvisioned;
66 extern NSString* const OctagonAnalyticsKeychainSyncEnabled;
67 extern NSString* const OctagonAnalyticsCloudKitProvisioned;
68 extern NSString* const OctagonAnalyticsCloudKitEnabled;
69
70 extern NSString* const OctagonAnalyticsBottledUniqueTLKsRecovered;
71 extern NSString* const OctagonAnalyticsBottledTotalTLKShares;
72 extern NSString* const OctagonAnalyticsBottledTotalTLKSharesRecovered;
73 extern NSString* const OctagonAnalyticsBottledUniqueTLKsWithSharesCount;
74 extern NSString* const OctagonAnalyticsBottledTLKUniqueViewCount;
75
76 @class CKKSKeychainView;
77
78 @protocol CKKSAnalyticsFailableEvent <NSObject>
79 @end
80 typedef NSString<CKKSAnalyticsFailableEvent> CKKSAnalyticsFailableEvent;
81 extern CKKSAnalyticsFailableEvent* const CKKSEventProcessIncomingQueueClassA;
82 extern CKKSAnalyticsFailableEvent* const CKKSEventProcessIncomingQueueClassC;
83 extern CKKSAnalyticsFailableEvent* const CKKSEventProcessOutgoingQueue;
84 extern CKKSAnalyticsFailableEvent* const CKKSEventUploadChanges;
85 extern CKKSAnalyticsFailableEvent* const CKKSEventStateError;
86 extern CKKSAnalyticsFailableEvent* const CKKSEventProcessHealKeyHierarchy;
87 extern CKKSAnalyticsFailableEvent* const CKKSEventProcessReencryption;
88
89 extern CKKSAnalyticsFailableEvent* const OctagonEventPreflightBottle;
90 extern CKKSAnalyticsFailableEvent* const OctagonEventLaunchBottle;
91 extern CKKSAnalyticsFailableEvent* const OctagonEventScrubBottle;
92 extern CKKSAnalyticsFailableEvent* const OctagonEventSignIn;
93 extern CKKSAnalyticsFailableEvent* const OctagonEventSignOut;
94 extern CKKSAnalyticsFailableEvent* const OctagonEventRestoreBottle;
95 extern CKKSAnalyticsFailableEvent* const OctagonEventRamp;
96 extern CKKSAnalyticsFailableEvent* const OctagonEventBottleCheck;
97 extern CKKSAnalyticsFailableEvent* const OctagonEventCoreFollowUp;
98 extern CKKSAnalyticsFailableEvent* const OctagonEventUpdateBottle;
99
100 extern CKKSAnalyticsFailableEvent* const OctagonEventRecoverBottle;
101 extern CKKSAnalyticsFailableEvent* const OctagonEventFetchAllBottles;
102 extern CKKSAnalyticsFailableEvent* const OctagonEventFetchEscrowContents;
103
104 extern CKKSAnalyticsFailableEvent* const OctagonEventRestoredSignedBottlePeer;
105 extern CKKSAnalyticsFailableEvent* const OctagonEventRestoredOctagonPeerEncryptionKey;
106 extern CKKSAnalyticsFailableEvent* const OctagonEventRestoredOctagonPeerSigningKey;
107 extern CKKSAnalyticsFailableEvent* const OctagonEventRestoreComplete;
108
109 /* Initial health check */
110 extern CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustState;
111
112 /* Outer calls as seen by the client */
113 extern CKKSAnalyticsFailableEvent* const OctagonEventBottledPeerRestore;
114 extern CKKSAnalyticsFailableEvent* const OctagonEventFetchEscrowContents;
115 extern CKKSAnalyticsFailableEvent* const OctagonEventResetAndEstablish;
116 extern CKKSAnalyticsFailableEvent* const OctagonEventEstablish;
117 extern CKKSAnalyticsFailableEvent* const OctagonEventLeaveClique;
118 extern CKKSAnalyticsFailableEvent* const OctagonEventRemoveFriendsInClique;
119 extern CKKSAnalyticsFailableEvent* const OctagonEventRecoveryKey;
120
121 /* Inner calls as seen by TPH and securityd */
122 /* inner: Upgrade */
123 extern CKKSAnalyticsFailableEvent* const OctagonEventUpgradeFetchDeviceIDs;
124 extern CKKSAnalyticsFailableEvent* const OctagonEventUpgradeSetAllowList;
125 extern CKKSAnalyticsFailableEvent* const OctagonEventUpgradeSilentEscrow;
126 extern CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreapprovedJoin;
127 extern CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreflightPreapprovedJoin;
128 extern CKKSAnalyticsFailableEvent* const OctagonEventUpgradePrepare;
129 extern CKKSAnalyticsFailableEvent* const OctagonEventUpgradePreapprovedJoinAfterPairing;
130
131 /* inner: join with voucher */
132 extern CKKSAnalyticsFailableEvent* const OctagonEventJoinWithVoucher;
133
134 /* inner: join with bottle */
135 extern CKKSAnalyticsFailableEvent* const OctagonEventPreflightVouchWithBottle;
136 extern CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithBottle;
137
138 /* inner: join with recovery key */
139 extern CKKSAnalyticsFailableEvent* const OctagonEventPreflightVouchWithRecoveryKey;
140 extern CKKSAnalyticsFailableEvent* const OctagonEventVoucherWithRecoveryKey;
141 extern CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyValidationFailed;
142 extern CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyFailed;
143 extern CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyCircleReset;
144 extern CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyCircleResetFailed;
145 extern CKKSAnalyticsFailableEvent* const OctagonEventJoinRecoveryKeyEnrollFailed;
146
147 /* inner: set recovery key */
148 extern CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKey;
149 extern CKKSAnalyticsFailableEvent* const OctagonEventSetRecoveryKeyValidationFailed;
150
151 /* inner: reset */
152 extern CKKSAnalyticsFailableEvent* const OctagonEventReset;
153
154 /* inner: prepare */
155 extern CKKSAnalyticsFailableEvent* const OctagonEventPrepareIdentity;
156
157 /* inner: establish */
158 extern CKKSAnalyticsFailableEvent* const OctagonEventEstablishIdentity;
159
160 /* inner: fetchviews */
161 extern CKKSAnalyticsFailableEvent* const OctagonEventFetchViews;
162
163 /* state machine */
164 extern CKKSAnalyticsFailableEvent* const OctagonEventStateTransition;
165
166 /* become untrusted */
167 extern CKKSAnalyticsFailableEvent* const OctagonEventCheckTrustForCFU;
168
169 /* watchOS only: pairing with companion */
170 extern CKKSAnalyticsFailableEvent* const OctagonEventCompanionPairing;
171
172 /* trust state from trusted peers helper*/
173 extern CKKSAnalyticsFailableEvent* const OctagonEventTPHHealthCheckStatus;
174
175 extern CKKSAnalyticsFailableEvent* const OctagonEventAuthKitDeviceList;
176
177 @protocol CKKSAnalyticsSignpostEvent <NSObject>
178 @end
179 typedef NSString<CKKSAnalyticsSignpostEvent> CKKSAnalyticsSignpostEvent;
180 extern CKKSAnalyticsSignpostEvent* const CKKSEventPushNotificationReceived;
181 extern CKKSAnalyticsSignpostEvent* const CKKSEventItemAddedToOutgoingQueue;
182 extern CKKSAnalyticsSignpostEvent* const CKKSEventReachabilityTimerExpired;
183 extern CKKSAnalyticsSignpostEvent* const CKKSEventMissingLocalItemsFound;
184
185 @protocol CKKSAnalyticsActivity <NSObject>
186 @end
187 typedef NSString<CKKSAnalyticsActivity> CKKSAnalyticsActivity;
188 extern CKKSAnalyticsActivity* const CKKSActivityOTFetchRampState;
189 extern CKKSAnalyticsActivity* const CKKSActivityOctagonPreflightBottle;
190 extern CKKSAnalyticsActivity* const CKKSActivityOctagonLaunchBottle;
191 extern CKKSAnalyticsActivity* const CKKSActivityOctagonRestore;
192 extern CKKSAnalyticsActivity* const CKKSActivityScrubBottle;
193 extern CKKSAnalyticsActivity* const CKKSActivityBottleCheck;
194 extern CKKSAnalyticsActivity* const CKKSActivityOctagonUpdateBottle;
195
196 extern CKKSAnalyticsActivity* const OctagonActivityAccountAvailable;
197 extern CKKSAnalyticsActivity* const OctagonActivityAccountNotAvailable;
198 extern CKKSAnalyticsActivity* const OctagonActivityResetAndEstablish;
199 extern CKKSAnalyticsActivity* const OctagonActivityEstablish;
200 extern CKKSAnalyticsActivity* const OctagonActivityFetchAllViableBottles;
201 extern CKKSAnalyticsActivity* const OctagonActivityFetchEscrowContents;
202 extern CKKSAnalyticsActivity* const OctagonActivityBottledPeerRestore;
203 extern CKKSAnalyticsActivity* const OctagonActivitySetRecoveryKey;
204 extern CKKSAnalyticsActivity* const OctagonActivityLeaveClique;
205 extern CKKSAnalyticsActivity* const OctagonActivityRemoveFriendsInClique;
206 extern CKKSAnalyticsActivity* const OctagonActivityJoinWithRecoveryKey;
207 extern CKKSAnalyticsActivity* const OctagonSOSAdapterUpdateKeys;
208
209
210 @interface CKKSAnalytics : SFAnalytics
211
212 + (instancetype)logger;
213
214 - (void)logSuccessForEvent:(CKKSAnalyticsFailableEvent*)event inView:(CKKSKeychainView*)view;
215 - (void)logRecoverableError:(NSError*)error
216 forEvent:(CKKSAnalyticsFailableEvent*)event
217 inView:(CKKSKeychainView*)view
218 withAttributes:(NSDictionary*)attributes;
219
220 - (void)logRecoverableError:(NSError*)error
221 forEvent:(CKKSAnalyticsFailableEvent*)event
222 zoneName:(NSString*)zoneName
223 withAttributes:(NSDictionary *)attributes;
224
225 - (void)logRecoverableError:(NSError*)error
226 forEvent:(CKKSAnalyticsFailableEvent*)event
227 withAttributes:(NSDictionary *)attributes;
228
229 - (void)logUnrecoverableError:(NSError*)error
230 forEvent:(CKKSAnalyticsFailableEvent*)event
231 withAttributes:(NSDictionary *)attributes;
232
233 - (void)logUnrecoverableError:(NSError*)error
234 forEvent:(CKKSAnalyticsFailableEvent*)event
235 inView:(CKKSKeychainView*)view
236 withAttributes:(NSDictionary*)attributes;
237
238 - (void)noteEvent:(CKKSAnalyticsSignpostEvent*)event;
239 - (void)noteEvent:(CKKSAnalyticsSignpostEvent*)event inView:(CKKSKeychainView*)view;
240
241 - (void)setDateProperty:(NSDate*)date forKey:(NSString*)key inView:(CKKSKeychainView *)view;
242 - (NSDate *)datePropertyForKey:(NSString *)key inView:(CKKSKeychainView *)view;
243
244 @end
245
246 @interface CKKSAnalytics (UnitTesting)
247
248 - (NSDate*)dateOfLastSuccessForEvent:(CKKSAnalyticsFailableEvent*)event
249 inView:(CKKSKeychainView*)view;
250 - (NSDictionary *)errorChain:(NSError *)error
251 depth:(NSUInteger)depth;
252 - (NSDictionary *)createErrorAttributes:(NSError *)error
253 depth:(NSUInteger)depth
254 attributes:(NSDictionary *)attributes;
255
256 @end
257
258 #endif
259
260