2 * Copyright (c) 2017 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@
24 #import <Foundation/Foundation.h>
27 #import "Analytics/SFAnalytics.h"
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
;
41 extern NSString
* const OctagonAnalyticsStateMachineState
;
42 extern NSString
* const OctagonAnalyticIcloudAccountState
;
43 extern NSString
* const OctagonAnalyticsTrustState
;
44 extern NSString
* const OctagonAnalyticsAttemptedJoin
;
45 extern NSString
* const OctagonAnalyticsLastHealthCheck
;
46 extern NSString
* const OctagonAnalyticsSOSStatus
;
47 extern NSString
* const OctagonAnalyticsDateOfLastPreflightPreapprovedJoin
;
48 extern NSString
* const OctagonAnalyticsLastKeystateReady
;
49 extern NSString
* const OctagonAnalyticsLastCoreFollowup
;
50 extern NSString
* const OctagonAnalyticsCoreFollowupFailureCount
;
51 extern NSString
* const OctagonAnalyticsCoreFollowupLastFailureTime
;
52 extern NSString
* const OctagonAnalyticsPrerecordPending
;
53 extern NSString
* const OctagonAnalyticsCDPStateRun
;
55 extern NSString
* const OctagonAnalyticsHaveMachineID
;
56 extern NSString
* const OctagonAnalyticsMIDOnMemoizedList
;
57 extern NSString
* const OctagonAnalyticsPeersWithMID
;
59 extern NSString
* const CKKSAnalyticsLastCKKSPush
;
60 extern NSString
* const CKKSAnalyticsLastOctagonPush
;
62 extern NSString
* const OctagonAnalyticsKVSProvisioned
;
63 extern NSString
* const OctagonAnalyticsKVSEnabled
;
64 extern NSString
* const OctagonAnalyticsKeychainSyncProvisioned
;
65 extern NSString
* const OctagonAnalyticsKeychainSyncEnabled
;
66 extern NSString
* const OctagonAnalyticsCloudKitProvisioned
;
67 extern NSString
* const OctagonAnalyticsCloudKitEnabled
;
69 @
class CKKSKeychainView
;
71 @protocol CKKSAnalyticsFailableEvent
<NSObject
>
73 typedef NSString
<CKKSAnalyticsFailableEvent
> CKKSAnalyticsFailableEvent
;
74 extern CKKSAnalyticsFailableEvent
* const CKKSEventProcessIncomingQueueClassA
;
75 extern CKKSAnalyticsFailableEvent
* const CKKSEventProcessIncomingQueueClassC
;
76 extern CKKSAnalyticsFailableEvent
* const CKKSEventProcessOutgoingQueue
;
77 extern CKKSAnalyticsFailableEvent
* const CKKSEventUploadChanges
;
78 extern CKKSAnalyticsFailableEvent
* const CKKSEventStateError
;
79 extern CKKSAnalyticsFailableEvent
* const CKKSEventProcessHealKeyHierarchy
;
80 extern CKKSAnalyticsFailableEvent
* const CKKSEventProcessReencryption
;
82 extern CKKSAnalyticsFailableEvent
* const OctagonEventPreflightBottle
;
83 extern CKKSAnalyticsFailableEvent
* const OctagonEventLaunchBottle
;
84 extern CKKSAnalyticsFailableEvent
* const OctagonEventScrubBottle
;
85 extern CKKSAnalyticsFailableEvent
* const OctagonEventSignIn
;
86 extern CKKSAnalyticsFailableEvent
* const OctagonEventSignOut
;
87 extern CKKSAnalyticsFailableEvent
* const OctagonEventRestoreBottle
;
88 extern CKKSAnalyticsFailableEvent
* const OctagonEventRamp
;
89 extern CKKSAnalyticsFailableEvent
* const OctagonEventBottleCheck
;
90 extern CKKSAnalyticsFailableEvent
* const OctagonEventCoreFollowUp
;
91 extern CKKSAnalyticsFailableEvent
* const OctagonEventUpdateBottle
;
93 extern CKKSAnalyticsFailableEvent
* const OctagonEventRecoverBottle
;
94 extern CKKSAnalyticsFailableEvent
* const OctagonEventFetchAllBottles
;
95 extern CKKSAnalyticsFailableEvent
* const OctagonEventFetchEscrowContents
;
97 extern CKKSAnalyticsFailableEvent
* const OctagonEventRestoredSignedBottlePeer
;
98 extern CKKSAnalyticsFailableEvent
* const OctagonEventRestoredOctagonPeerEncryptionKey
;
99 extern CKKSAnalyticsFailableEvent
* const OctagonEventRestoredOctagonPeerSigningKey
;
100 extern CKKSAnalyticsFailableEvent
* const OctagonEventRestoreComplete
;
102 /* Initial health check */
103 extern CKKSAnalyticsFailableEvent
* const OctagonEventCheckTrustState
;
105 /* Outer calls as seen by the client */
106 extern CKKSAnalyticsFailableEvent
* const OctagonEventBottledPeerRestore
;
107 extern CKKSAnalyticsFailableEvent
* const OctagonEventFetchEscrowContents
;
108 extern CKKSAnalyticsFailableEvent
* const OctagonEventResetAndEstablish
;
109 extern CKKSAnalyticsFailableEvent
* const OctagonEventEstablish
;
110 extern CKKSAnalyticsFailableEvent
* const OctagonEventLeaveClique
;
111 extern CKKSAnalyticsFailableEvent
* const OctagonEventRemoveFriendsInClique
;
112 extern CKKSAnalyticsFailableEvent
* const OctagonEventRecoveryKey
;
114 /* Inner calls as seen by TPH and securityd */
116 extern CKKSAnalyticsFailableEvent
* const OctagonEventUpgradeFetchDeviceIDs
;
117 extern CKKSAnalyticsFailableEvent
* const OctagonEventUpgradeSetAllowList
;
118 extern CKKSAnalyticsFailableEvent
* const OctagonEventUpgradeSilentEscrow
;
119 extern CKKSAnalyticsFailableEvent
* const OctagonEventUpgradePreapprovedJoin
;
120 extern CKKSAnalyticsFailableEvent
* const OctagonEventUpgradePreflightPreapprovedJoin
;
121 extern CKKSAnalyticsFailableEvent
* const OctagonEventUpgradePrepare
;
122 extern CKKSAnalyticsFailableEvent
* const OctagonEventUpgradePreapprovedJoinAfterPairing
;
124 /* inner: join with voucher */
125 extern CKKSAnalyticsFailableEvent
* const OctagonEventJoinWithVoucher
;
127 /* inner: join with bottle */
128 extern CKKSAnalyticsFailableEvent
* const OctagonEventPreflightVouchWithBottle
;
129 extern CKKSAnalyticsFailableEvent
* const OctagonEventVoucherWithBottle
;
131 /* inner: join with recovery key */
132 extern CKKSAnalyticsFailableEvent
* const OctagonEventVoucherWithRecoveryKey
;
133 extern CKKSAnalyticsFailableEvent
* const OctagonEventJoinRecoveryKeyValidationFailed
;
134 extern CKKSAnalyticsFailableEvent
* const OctagonEventJoinRecoveryKeyFailed
;
135 extern CKKSAnalyticsFailableEvent
* const OctagonEventJoinRecoveryKeyCircleReset
;
136 extern CKKSAnalyticsFailableEvent
* const OctagonEventJoinRecoveryKeyCircleResetFailed
;
137 extern CKKSAnalyticsFailableEvent
* const OctagonEventJoinRecoveryKeyEnrollFailed
;
139 /* inner: set recovery key */
140 extern CKKSAnalyticsFailableEvent
* const OctagonEventSetRecoveryKey
;
141 extern CKKSAnalyticsFailableEvent
* const OctagonEventSetRecoveryKeyValidationFailed
;
144 extern CKKSAnalyticsFailableEvent
* const OctagonEventReset
;
147 extern CKKSAnalyticsFailableEvent
* const OctagonEventPrepareIdentity
;
149 /* inner: establish */
150 extern CKKSAnalyticsFailableEvent
* const OctagonEventEstablishIdentity
;
152 /* inner: fetchviews */
153 extern CKKSAnalyticsFailableEvent
* const OctagonEventFetchViews
;
156 extern CKKSAnalyticsFailableEvent
* const OctagonEventStateTransition
;
158 /* become untrusted */
159 extern CKKSAnalyticsFailableEvent
* const OctagonEventCheckTrustForCFU
;
161 /* watchOS only: pairing with companion */
162 extern CKKSAnalyticsFailableEvent
* const OctagonEventCompanionPairing
;
164 /* trust state from trusted peers helper*/
165 extern CKKSAnalyticsFailableEvent
* const OctagonEventTPHHealthCheckStatus
;
167 extern CKKSAnalyticsFailableEvent
* const OctagonEventAuthKitDeviceList
;
169 @protocol CKKSAnalyticsSignpostEvent
<NSObject
>
171 typedef NSString
<CKKSAnalyticsSignpostEvent
> CKKSAnalyticsSignpostEvent
;
172 extern CKKSAnalyticsSignpostEvent
* const CKKSEventPushNotificationReceived
;
173 extern CKKSAnalyticsSignpostEvent
* const CKKSEventItemAddedToOutgoingQueue
;
174 extern CKKSAnalyticsSignpostEvent
* const CKKSEventReachabilityTimerExpired
;
175 extern CKKSAnalyticsSignpostEvent
* const CKKSEventMissingLocalItemsFound
;
177 @protocol CKKSAnalyticsActivity
<NSObject
>
179 typedef NSString
<CKKSAnalyticsActivity
> CKKSAnalyticsActivity
;
180 extern CKKSAnalyticsActivity
* const CKKSActivityOTFetchRampState
;
181 extern CKKSAnalyticsActivity
* const CKKSActivityOctagonPreflightBottle
;
182 extern CKKSAnalyticsActivity
* const CKKSActivityOctagonLaunchBottle
;
183 extern CKKSAnalyticsActivity
* const CKKSActivityOctagonRestore
;
184 extern CKKSAnalyticsActivity
* const CKKSActivityScrubBottle
;
185 extern CKKSAnalyticsActivity
* const CKKSActivityBottleCheck
;
186 extern CKKSAnalyticsActivity
* const CKKSActivityOctagonUpdateBottle
;
188 extern CKKSAnalyticsActivity
* const OctagonActivityAccountAvailable
;
189 extern CKKSAnalyticsActivity
* const OctagonActivityAccountNotAvailable
;
190 extern CKKSAnalyticsActivity
* const OctagonActivityResetAndEstablish
;
191 extern CKKSAnalyticsActivity
* const OctagonActivityEstablish
;
192 extern CKKSAnalyticsActivity
* const OctagonActivityFetchAllViableBottles
;
193 extern CKKSAnalyticsActivity
* const OctagonActivityFetchEscrowContents
;
194 extern CKKSAnalyticsActivity
* const OctagonActivityBottledPeerRestore
;
195 extern CKKSAnalyticsActivity
* const OctagonActivitySetRecoveryKey
;
196 extern CKKSAnalyticsActivity
* const OctagonActivityLeaveClique
;
197 extern CKKSAnalyticsActivity
* const OctagonActivityRemoveFriendsInClique
;
198 extern CKKSAnalyticsActivity
* const OctagonActivityJoinWithRecoveryKey
;
199 extern CKKSAnalyticsActivity
* const OctagonSOSAdapterUpdateKeys
;
202 @interface CKKSAnalytics
: SFAnalytics
204 + (instancetype
)logger
;
206 - (void)logSuccessForEvent
:(CKKSAnalyticsFailableEvent
*)event inView
:(CKKSKeychainView
*)view
;
207 - (void)logRecoverableError
:(NSError
*)error
208 forEvent
:(CKKSAnalyticsFailableEvent
*)event
209 inView
:(CKKSKeychainView
*)view
210 withAttributes
:(NSDictionary
*)attributes
;
212 - (void)logRecoverableError
:(NSError
*)error
213 forEvent
:(CKKSAnalyticsFailableEvent
*)event
214 zoneName
:(NSString
*)zoneName
215 withAttributes
:(NSDictionary
*)attributes
;
217 - (void)logRecoverableError
:(NSError
*)error
218 forEvent
:(CKKSAnalyticsFailableEvent
*)event
219 withAttributes
:(NSDictionary
*)attributes
;
221 - (void)logUnrecoverableError
:(NSError
*)error
222 forEvent
:(CKKSAnalyticsFailableEvent
*)event
223 withAttributes
:(NSDictionary
*)attributes
;
225 - (void)logUnrecoverableError
:(NSError
*)error
226 forEvent
:(CKKSAnalyticsFailableEvent
*)event
227 inView
:(CKKSKeychainView
*)view
228 withAttributes
:(NSDictionary
*)attributes
;
230 - (void)noteEvent
:(CKKSAnalyticsSignpostEvent
*)event
;
231 - (void)noteEvent
:(CKKSAnalyticsSignpostEvent
*)event inView
:(CKKSKeychainView
*)view
;
233 - (void)setDateProperty
:(NSDate
*)date forKey
:(NSString
*)key inView
:(CKKSKeychainView
*)view
;
234 - (NSDate
*)datePropertyForKey
:(NSString
*)key inView
:(CKKSKeychainView
*)view
;
238 @interface
CKKSAnalytics (UnitTesting
)
240 - (NSDate
*)dateOfLastSuccessForEvent
:(CKKSAnalyticsFailableEvent
*)event
241 inView
:(CKKSKeychainView
*)view
;
242 - (NSDictionary
*)errorChain
:(NSError
*)error
243 depth
:(NSUInteger
)depth
;
244 - (NSDictionary
*)createErrorAttributes
:(NSError
*)error
245 depth
:(NSUInteger
)depth
246 attributes
:(NSDictionary
*)attributes
;