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
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/enterprise/connectors/device_trust/common/metrics_utils.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/stringprintf.h"
#include "build/build_config.h"
#include "chrome/browser/enterprise/connectors/device_trust/common/common_types.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "chromeos/ash/components/install_attributes/install_attributes.h"
#endif // BUILDFLAG(IS_CHROMEOS)
namespace enterprise_connectors {
namespace {
#if BUILDFLAG(IS_CHROMEOS)
// Enrollment status of the device where the Device Trust connector attestation
// is happening. These values are persisted to logs and should not be
// renumbered. Please update the DTEnrollmentStatus enum in enums.xml when
// adding a new step here.
enum class DTEnrollmentStatus {
kManaged = 0,
kUnmanaged = 1,
kMaxValue = kUnmanaged,
};
#endif // BUILDFLAG(IS_CHROMEOS)
DTHandshakeResult ResponseToResult(const DeviceTrustResponse& response) {
if (!response.error) {
return DTHandshakeResult::kSuccess;
}
switch (response.error.value()) {
case DeviceTrustError::kUnknown:
return DTHandshakeResult::kUnknown;
case DeviceTrustError::kTimeout:
return DTHandshakeResult::kTimeout;
case DeviceTrustError::kFailedToParseChallenge:
return DTHandshakeResult::kFailedToParseChallenge;
case DeviceTrustError::kFailedToCreateResponse:
return DTHandshakeResult::kFailedToCreateResponse;
}
}
bool ContainsPolicyLevel(const std::set<DTCPolicyLevel>& levels,
const DTCPolicyLevel& level) {
return levels.find(level) != levels.end();
}
DTAttestationPolicyLevel GetAttestationPolicyLevel(
const std::set<DTCPolicyLevel>& levels) {
if (levels.empty()) {
return DTAttestationPolicyLevel::kNone;
}
if (ContainsPolicyLevel(levels, DTCPolicyLevel::kBrowser)) {
if (ContainsPolicyLevel(levels, DTCPolicyLevel::kUser)) {
return DTAttestationPolicyLevel::kUserAndBrowser;
}
return DTAttestationPolicyLevel::kBrowser;
}
if (ContainsPolicyLevel(levels, DTCPolicyLevel::kUser)) {
return DTAttestationPolicyLevel::kUser;
}
return DTAttestationPolicyLevel::kUnknown;
}
} // namespace
void LogAttestationFunnelStep(DTAttestationFunnelStep step) {
static constexpr char kFunnelStepHistogram[] =
"Enterprise.DeviceTrust.Attestation.Funnel";
base::UmaHistogramEnumeration(kFunnelStepHistogram, step);
VLOG(1) << "Device Trust attestation step: " << static_cast<int>(step);
}
void LogAttestationPolicyLevel(const std::set<DTCPolicyLevel>& levels) {
static constexpr char kAttestationPolicyLevelHistogram[] =
"Enterprise.DeviceTrust.Attestation.PolicyLevel";
base::UmaHistogramEnumeration(kAttestationPolicyLevelHistogram,
GetAttestationPolicyLevel(levels));
}
void LogAttestationResult(DTAttestationResult result) {
static constexpr char kAttestationResultHistogram[] =
"Enterprise.DeviceTrust.Attestation.Result";
base::UmaHistogramEnumeration(kAttestationResultHistogram, result);
if (!IsSuccessAttestationResult(result)) {
LOG(ERROR) << "Device Trust attestation error: "
<< AttestationErrorToString(result);
}
}
void LogDeviceTrustResponse(const DeviceTrustResponse& response,
base::TimeTicks start_time) {
static constexpr char kLatencyHistogramFormat[] =
"Enterprise.DeviceTrust.Attestation.ResponseLatency.%s";
base::UmaHistogramTimes(
base::StringPrintf(kLatencyHistogramFormat,
response.error ? "Failure" : "Success"),
base::TimeTicks::Now() - start_time);
static constexpr char kHandshakeResultHistogram[] =
"Enterprise.DeviceTrust.Handshake.Result";
base::UmaHistogramEnumeration(kHandshakeResultHistogram,
ResponseToResult(response));
}
#if BUILDFLAG(IS_CHROMEOS)
void LogOrigin(DTOrigin origin) {
static constexpr char kOriginHistogram[] = "Enterprise.DeviceTrust.Origin";
base::UmaHistogramEnumeration(kOriginHistogram, origin);
}
void LogEnrollmentStatus() {
static constexpr char kEnrollmentStatusHistogram[] =
"Enterprise.DeviceTrust.EnrollmentStatus";
base::UmaHistogramEnumeration(
kEnrollmentStatusHistogram,
ash::InstallAttributes::Get()->IsEnterpriseManaged()
? DTEnrollmentStatus::kManaged
: DTEnrollmentStatus::kUnmanaged);
}
#endif // BUILDFLAG(IS_CHROMEOS)
} // namespace enterprise_connectors
|