-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcryptohome_metrics.h
426 lines (362 loc) · 15.2 KB
/
cryptohome_metrics.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
// Copyright 2014 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CRYPTOHOME_CRYPTOHOME_METRICS_H_
#define CRYPTOHOME_CRYPTOHOME_METRICS_H_
#include <string>
#include <base/files/file.h>
#include <base/time/time.h>
#include <metrics/metrics_library.h>
#include "cryptohome/le_credential_manager.h"
#include "cryptohome/migration_type.h"
#include "cryptohome/tpm.h"
#include "cryptohome/tpm_metrics.h"
namespace cryptohome {
// List of all the possible operation types. Used to construct the correct
// histogram while logging to UMA.
enum LECredOperationType {
LE_CRED_OP_RESET_TREE = 0,
LE_CRED_OP_INSERT,
LE_CRED_OP_CHECK,
LE_CRED_OP_RESET,
LE_CRED_OP_REMOVE,
LE_CRED_OP_SYNC,
LE_CRED_OP_MAX,
};
// List of all possible actions taken within an LE Credential operation.
// Used to construct the correct histogram while logging to UMA.
enum LECredActionType {
LE_CRED_ACTION_LOAD_FROM_DISK = 0,
LE_CRED_ACTION_BACKEND,
LE_CRED_ACTION_SAVE_TO_DISK,
LE_CRED_ACTION_BACKEND_GET_LOG,
LE_CRED_ACTION_BACKEND_REPLAY_LOG,
LE_CRED_ACTION_MAX,
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum CryptohomeError {
kTpmFail = 1,
kTcsKeyLoadFailed = 2,
kTpmDefendLockRunning = 3,
kDecryptAttemptButTpmKeyMissing = 4,
kDecryptAttemptButTpmNotOwned = 5,
kDecryptAttemptButTpmNotAvailable = 6,
kDecryptAttemptButTpmKeyMismatch = 7,
kDecryptAttemptWithTpmKeyFailed = 8,
kCannotLoadTpmSrk = 9,
kCannotReadTpmSrkPublic = 10,
kCannotLoadTpmKey = 11,
kCannotReadTpmPublicKey = 12,
kTpmBadKeyProperty = 13,
kLoadPkcs11TokenFailed = 14,
kEncryptWithTpmFailed = 15,
kTssCommunicationFailure = 16,
kTssInvalidHandle = 17,
kBothTpmAndScryptWrappedKeyset = 18,
kEphemeralCleanUpFailed = 19,
kCryptohomeErrorNumBuckets, // Must be the last entry.
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum TimerType {
kAsyncMountTimer, // Unused.
kSyncMountTimer,
kAsyncGuestMountTimer,
kSyncGuestMountTimer, // Unused.
kTpmTakeOwnershipTimer,
kPkcs11InitTimer,
kMountExTimer,
kDircryptoMigrationTimer,
kDircryptoMinimalMigrationTimer,
kNumTimerTypes // For the number of timer types.
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum DictionaryAttackResetStatus {
kResetNotNecessary,
kResetAttemptSucceeded,
kResetAttemptFailed,
kDelegateNotAllowed,
kDelegateNotAvailable,
kCounterQueryFailed,
kInvalidPcr0State,
kDictionaryAttackResetStatusNumBuckets
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum ChecksumStatus {
kChecksumOK,
kChecksumDoesNotExist,
kChecksumReadError,
kChecksumMismatch,
kChecksumOutOfSync,
kChecksumStatusNumBuckets
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum DircryptoMigrationStartStatus {
kMigrationStarted = 1,
kMigrationResumed = 2,
kMigrationStartStatusNumBuckets
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum DircryptoMigrationEndStatus {
kNewMigrationFailedGeneric = 1,
kNewMigrationFinished = 2,
kResumedMigrationFailedGeneric = 3,
kResumedMigrationFinished = 4,
kNewMigrationFailedLowDiskSpace = 5,
kResumedMigrationFailedLowDiskSpace = 6,
// The detail of the "FileError" failures (the failed file operation,
// error code, and the rough classification of the failed path) will be
// reported in separate metrics, too. Since there's no good way to relate the
// multi-dimensional metric however, we treat some combinations as special
// cases and distinguish them here as well.
kNewMigrationFailedFileError = 7,
kResumedMigrationFailedFileError = 8,
kNewMigrationFailedFileErrorOpenEIO = 9,
kResumedMigrationFailedFileErrorOpenEIO = 10,
kNewMigrationCancelled = 11,
kResumedMigrationCancelled = 12,
kMigrationEndStatusNumBuckets
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum DircryptoMigrationFailedOperationType {
kMigrationFailedAtOtherOperation = 1,
kMigrationFailedAtOpenSourceFile = 2,
kMigrationFailedAtOpenDestinationFile = 3,
kMigrationFailedAtCreateLink = 4,
kMigrationFailedAtDelete = 5,
kMigrationFailedAtGetAttribute = 6,
kMigrationFailedAtMkdir = 7,
kMigrationFailedAtReadLink = 8,
kMigrationFailedAtSeek = 9,
kMigrationFailedAtSendfile = 10,
kMigrationFailedAtSetAttribute = 11,
kMigrationFailedAtStat = 12,
kMigrationFailedAtSync = 13,
kMigrationFailedAtTruncate = 14,
kMigrationFailedAtOpenSourceFileNonFatal = 15,
kMigrationFailedAtRemoveAttribute = 16,
kMigrationFailedOperationTypeNumBuckets
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum DircryptoMigrationFailedPathType {
kMigrationFailedUnderOther = 1,
kMigrationFailedUnderAndroidOther = 2,
kMigrationFailedUnderAndroidCache = 3,
kMigrationFailedUnderDownloads = 4,
kMigrationFailedUnderCache = 5,
kMigrationFailedUnderGcache = 6,
kMigrationFailedPathTypeNumBuckets
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class HomedirEncryptionType {
kEcryptfs = 1,
kDircrypto = 2,
kHomedirEncryptionTypeNumBuckets
};
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
enum class DiskCleanupProgress {
kEphemeralUserProfilesCleaned = 1,
kBrowserCacheCleanedAboveTarget = 2,
kGoogleDriveCacheCleanedAboveTarget = 3,
kGoogleDriveCacheCleanedAboveMinimum = 4,
kAndroidCacheCleanedAboveTarget = 5,
kAndroidCacheCleanedAboveMinimum = 6,
kWholeUserProfilesCleanedAboveTarget = 7,
kWholeUserProfilesCleaned = 8,
kNoUnmountedCryptohomes = 9,
kNumBuckets
};
// Add new deprecated function event here.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.
// Note: All updates here must also update Chrome's enums.xml database.
// Please see this document for more details:
// https://chromium.googlesource.com/chromium/src/+/master/tools/metrics/histograms/
//
// You can view them live here:
// https://uma.googleplex.com/histograms/?histograms=Platform.Cryptohome.DeprecatedApiCalled
enum class DeprecatedApiEvent {
kInitializeCastKey = 0,
kGetBootAttribute, // 1
kSetBootAttribute, // 2
kFlushAndSignBootAttributes, // 3
kSignBootLockbox, // 4
kVerifyBootLockbox, // 5
kFinalizeBootLockbox, // 6
kTpmIsBeingOwned, // 7
kMaxValue, // 8
};
// List of the possible results of attempting a mount operation using the
// out-of-process mount helper.
enum class OOPMountOperationResult {
kSuccess = 0,
kFailedToStart = 1,
kFailedToWriteRequestProtobuf = 2,
kHelperProcessTimedOut = 3,
kFailedToReadResponseProtobuf = 4,
kMaxValue = kFailedToReadResponseProtobuf
};
// List of the possible results of attempting an unmount/mount clean-up
// using the out-of-process mount helper.
enum class OOPMountCleanupResult {
kSuccess = 0,
kFailedToPoke = 1,
kFailedToWait = 2,
kFailedToKill = 3,
kMaxValue = kFailedToKill
};
// Just to make sure I count correctly.
static_assert(static_cast<int>(DeprecatedApiEvent::kMaxValue) == 8,
"DeprecatedApiEvent Enum miscounted");
// Cros events emitted by cryptohome.
const char kAttestationOriginSpecificIdentifiersExhausted[] =
"Attestation.OriginSpecificExhausted";
// Constants related to LE Credential UMA logging.
constexpr char kLEOpResetTree[]= ".ResetTree";
constexpr char kLEOpInsert[]= ".Insert";
constexpr char kLEOpCheck[]= ".Check";
constexpr char kLEOpReset[]= ".Reset";
constexpr char kLEOpRemove[]= ".Remove";
constexpr char kLEOpSync[]= ".Sync";
constexpr char kLEActionLoadFromDisk[] = ".LoadFromDisk";
constexpr char kLEActionBackend[] = ".Backend";
constexpr char kLEActionSaveToDisk[] = ".SaveToDisk";
constexpr char kLEActionBackendGetLog[] = ".BackendGetLog";
constexpr char kLEActionBackendReplayLog[] = ".BackendReplayLog";
// Initializes cryptohome metrics. If this is not called, all calls to Report*
// will have no effect.
void InitializeMetrics();
// Cleans up and returns cryptohome metrics to an uninitialized state.
void TearDownMetrics();
// Override the internally used MetricsLibrary for testing purpose.
void OverrideMetricsLibraryForTesting(MetricsLibraryInterface* lib);
// Reset the internally used MetricsLibrary for testing purpose. This is usually
// used with OverrideMetricsLibraryForTesting().
void ClearMetricsLibraryForTesting();
// The |error| value is reported to the "Cryptohome.Errors" enum histogram.
void ReportCryptohomeError(CryptohomeError error);
// The |result| value is reported to the "Cryptohome.TpmResults" enum histogram.
void ReportTpmResult(TpmResult result);
// Cros events are translated to an enum and reported to the generic
// "Platform.CrOSEvent" enum histogram. The |event| string must be registered in
// metrics/metrics_library.cc:kCrosEventNames.
void ReportCrosEvent(const char* event);
// Starts a timer for the given |timer_type|.
void ReportTimerStart(TimerType timer_type);
// Stops a timer and reports in milliseconds. Timers are reported to the
// "Cryptohome.TimeTo*" histograms.
void ReportTimerStop(TimerType timer_type);
// Reports a status value on the "Platform.TPM.DictionaryAttackResetStatus"
// histogram.
void ReportDictionaryAttackResetStatus(DictionaryAttackResetStatus status);
// Reports a dictionary attack counter value to the
// "Platform.TPM.DictionaryAttackCounter" histogram.
void ReportDictionaryAttackCounter(int counter);
void ReportChecksum(ChecksumStatus status);
// Reports number of deleted user profiles to the
// "Cryptohome.DeletedUserProfiles" histogram.
void ReportDeletedUserProfiles(int user_profile_count);
// Reports total time taken by HomeDirs::FreeDiskSpace cleanup (milliseconds) to
// the "Cryptohome.FreeDiskSpaceTotalTime" histogram.
void ReportFreeDiskSpaceTotalTime(int ms);
// Reports total space freed by HomeDirs::FreeDiskSpace (in MiB) to
// the "Cryptohome.FreeDiskSpaceTotalTime" histogram.
void ReportFreeDiskSpaceTotalFreedInMb(int mb);
// Reports the time between HomeDirs::FreeDiskSpace cleanup calls (seconds) to
// the "Cryptohome.TimeBetweenFreeDiskSpace" histogram.
void ReportTimeBetweenFreeDiskSpace(int s);
// Reports removed GCache size by cryptohome to the
// "Cryptohome.FreedGCacheDiskSpaceInMb" histogram.
void ReportFreedGCacheDiskSpaceInMb(int mb);
// The |status| value is reported to the
// "Cryptohome.DircryptoMigrationStartStatus" (full migration)
// or the "Cryptohome.DircryptoMinimalMigrationStartStatus" (minimal migration)
// enum histogram.
void ReportDircryptoMigrationStartStatus(MigrationType migration_type,
DircryptoMigrationStartStatus status);
// The |status| value is reported to the
// "Cryptohome.DircryptoMigrationEndStatus" (full migration)
// or the "Cryptohome.DircryptoMinimalMigrationEndStatus" (minimal migration)
// enum histogram.
void ReportDircryptoMigrationEndStatus(MigrationType migration_type,
DircryptoMigrationEndStatus status);
// The |error_code| value is reported to the
// "Cryptohome.DircryptoMigrationFailedErrorCode"
// enum histogram.
void ReportDircryptoMigrationFailedErrorCode(base::File::Error error_code);
// The |type| value is reported to the
// "Cryptohome.DircryptoMigrationFailedOperationType"
// enum histogram.
void ReportDircryptoMigrationFailedOperationType(
DircryptoMigrationFailedOperationType type);
// The |alerts| data set is reported to the
// "Platform.TPM.HardwareAlerts" enum histogram.
void ReportAlertsData(const Tpm::AlertsData& alerts);
// The |type| value is reported to the
// "Cryptohome.DircryptoMigrationFailedPathType"
// enum histogram.
void ReportDircryptoMigrationFailedPathType(
DircryptoMigrationFailedPathType type);
// Reports the total byte count in MB to migrate to the
// "Cryptohome.DircryptoMigrationTotalByteCountInMb" histogram.
void ReportDircryptoMigrationTotalByteCountInMb(int total_byte_count_mb);
// Reports the total file count to migrate to the
// "Cryptohome.DircryptoMigrationTotalFileCount" histogram.
void ReportDircryptoMigrationTotalFileCount(int total_file_count);
// Reports which topmost priority was reached to fulfill a cleanup request
// to the "Cryptohome.DiskCleanupProgress" enum histogram.
void ReportDiskCleanupProgress(DiskCleanupProgress progress);
// The |type| value is reported to the "Cryptohome.HomedirEncryptionType" enum
// histogram.
void ReportHomedirEncryptionType(HomedirEncryptionType type);
// Reports the result of a Low Entropy (LE) Credential operation to the relevant
// LE Credential histogram.
void ReportLEResult(const char* type, const char* action,
LECredError result);
// Reports the overall outcome of a Low Entropy (LE) Credential Sync operation
// to the "Cryptohome.LECredential.SyncOutcome" enum histogram.
void ReportLESyncOutcome(LECredError result);
// Reports the TPM version fingerprint to the "Platform.TPM.VersionFingerprint"
// histogram.
void ReportVersionFingerprint(int fingerprint);
// Reports the free space in MB when the migration fails and what the free space
// was initially when the migration was started.
void ReportDircryptoMigrationFailedNoSpace(int initial_migration_free_space_mb,
int failure_free_space_mb);
// Reports the total size in bytes of the current xattrs already set on a file
// and the xattr that caused the setxattr call to fail.
void ReportDircryptoMigrationFailedNoSpaceXattrSizeInBytes(
int total_xattr_size_bytes);
// Reports the total running time of a dbus request.
void ReportAsyncDbusRequestTotalTime(std::string task_name,
base::TimeDelta running_time);
// Reports the total in-queue time of mount thread of a dbus request
void ReportAsyncDbusRequestInqueueTime(std::string task_name,
base::TimeDelta running_time);
// Reports the amount of total tasks waiting in the queue of mount thread.
void ReportParallelTasks(int amount_of_task);
// Reports when a deprecated function that is exposed on the DBus is called.
// This is used to determine which deprecated function is truly dead code,
// and removing it will not trigger side effects.
void ReportDeprecatedApiCalled(DeprecatedApiEvent event);
// Reports the result of an out-of-process mount operation.
void ReportOOPMountOperationResult(OOPMountOperationResult result);
// Reports the result of an out-of-process cleanup operation.
void ReportOOPMountCleanupResult(OOPMountCleanupResult result);
// Initialization helper.
class ScopedMetricsInitializer {
public:
ScopedMetricsInitializer() { InitializeMetrics(); }
~ScopedMetricsInitializer() { TearDownMetrics(); }
};
} // namespace cryptohome
#endif // CRYPTOHOME_CRYPTOHOME_METRICS_H_