Commit e4c4cbd1 authored by Leo Lai's avatar Leo Lai Committed by Commit Bot

chromeos attestation: Move out GetKeyNameForProfile

In order to make a better unittest for this function and to re-use the
function in the rewritten attestation flow in the future, the mentioned
function is moved out as a stand-alone function.

BUG=b:158955123

Change-Id: Ia83e7bf701fe013a2d4935e7e779783e407a104b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2279254Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Auto-Submit: Leo Lai <cylai@google.com>
Cr-Commit-Position: refs/heads/master@{#784846}
parent 290bcf03
......@@ -28,6 +28,7 @@
#include "chrome/common/chrome_content_client.h"
#include "chrome/common/pref_names.h"
#include "chromeos/attestation/attestation_flow.h"
#include "chromeos/attestation/attestation_flow_utils.h"
#include "chromeos/constants/chromeos_switches.h"
#include "chromeos/cryptohome/async_method_caller.h"
#include "chromeos/cryptohome/cryptohome_parameters.h"
......@@ -387,9 +388,7 @@ void DeviceCloudPolicyInitializer::TpmEnrollmentKeySigningService::SignData(
chromeos::attestation::AttestationFlow::GetKeyTypeForProfile(
cert_profile),
identification,
chromeos::attestation::AttestationFlow::GetKeyNameForProfile(cert_profile,
""),
data,
chromeos::attestation::GetKeyNameForProfile(cert_profile, ""), data,
base::BindOnce(&DeviceCloudPolicyInitializer::
TpmEnrollmentKeySigningService::OnDataSigned,
weak_ptr_factory_.GetWeakPtr(), data,
......
......@@ -22,6 +22,7 @@ component("attestation") {
sources = [
"attestation_flow.cc",
"attestation_flow.h",
"attestation_flow_utils.cc",
]
}
......@@ -52,5 +53,8 @@ source_set("unit_tests") {
"//testing/gmock",
"//testing/gtest",
]
sources = [ "attestation_flow_unittest.cc" ]
sources = [
"attestation_flow_unittest.cc",
"attestation_flow_utils_unittest.cc",
]
}
......@@ -13,6 +13,7 @@
#include "base/optional.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/timer/timer.h"
#include "chromeos/attestation/attestation_flow_utils.h"
#include "chromeos/cryptohome/async_method_caller.h"
#include "chromeos/cryptohome/cryptohome_parameters.h"
#include "chromeos/dbus/attestation/attestation_client.h"
......@@ -77,23 +78,6 @@ AttestationKeyType AttestationFlow::GetKeyTypeForProfile(
return KEY_USER;
}
std::string AttestationFlow::GetKeyNameForProfile(
AttestationCertificateProfile certificate_profile,
const std::string& request_origin) {
switch (certificate_profile) {
case PROFILE_ENTERPRISE_MACHINE_CERTIFICATE:
return kEnterpriseMachineKey;
case PROFILE_ENTERPRISE_ENROLLMENT_CERTIFICATE:
return kEnterpriseEnrollmentKey;
case PROFILE_ENTERPRISE_USER_CERTIFICATE:
return kEnterpriseUserKey;
case PROFILE_CONTENT_PROTECTION_CERTIFICATE:
return std::string(kContentProtectionKeyPrefix) + request_origin;
}
NOTREACHED();
return "";
}
AttestationFlow::AttestationFlow(cryptohome::AsyncMethodCaller* async_caller,
CryptohomeClient* cryptohome_client,
std::unique_ptr<ServerProxy> server_proxy)
......
......@@ -71,19 +71,6 @@ class COMPONENT_EXPORT(CHROMEOS_ATTESTATION) AttestationFlow {
static AttestationKeyType GetKeyTypeForProfile(
AttestationCertificateProfile certificate_profile);
// Returns the name of the key for a given certificate profile. The
// |request_origin| parameter is for PROFILE_CONTENT_PROTECTION_CERTIFICATE
// profiles and is ignored for other profiles.
//
// Parameters
// certificate_profile - Specifies what kind of certificate the key is for.
// request_origin - For content protection profiles, certificate requests
// are origin-specific. This string must uniquely identify
// the origin of the request.
static std::string GetKeyNameForProfile(
AttestationCertificateProfile certificate_profile,
const std::string& request_origin);
AttestationFlow(cryptohome::AsyncMethodCaller* async_caller,
CryptohomeClient* cryptohome_client,
std::unique_ptr<ServerProxy> server_proxy);
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/attestation/attestation_flow_utils.h"
#include <string>
#include "base/notreached.h"
#include "chromeos/dbus/constants/attestation_constants.h"
namespace chromeos {
namespace attestation {
std::string GetKeyNameForProfile(
AttestationCertificateProfile certificate_profile,
const std::string& request_origin) {
switch (certificate_profile) {
case PROFILE_ENTERPRISE_MACHINE_CERTIFICATE:
return kEnterpriseMachineKey;
case PROFILE_ENTERPRISE_ENROLLMENT_CERTIFICATE:
return kEnterpriseEnrollmentKey;
case PROFILE_ENTERPRISE_USER_CERTIFICATE:
return kEnterpriseUserKey;
case PROFILE_CONTENT_PROTECTION_CERTIFICATE:
return std::string(kContentProtectionKeyPrefix) + request_origin;
}
NOTREACHED();
return "";
}
} // namespace attestation
} // namespace chromeos
// Copyright 2020 The Chromium 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 CHROMEOS_ATTESTATION_ATTESTATION_FLOW_UTILS_H_
#define CHROMEOS_ATTESTATION_ATTESTATION_FLOW_UTILS_H_
#include <string>
#include "base/component_export.h"
#include "chromeos/dbus/constants/attestation_constants.h"
namespace chromeos {
namespace attestation {
// Returns the name of the key for a given certificate profile. The
// |request_origin| parameter is for PROFILE_CONTENT_PROTECTION_CERTIFICATE
// profiles and is ignored for other profiles.
//
// Parameters
// certificate_profile - Specifies what kind of certificate the key is for.
// request_origin - For content protection profiles, certificate requests
// are origin-specific. This string must uniquely identify
// the origin of the request.
COMPONENT_EXPORT(CHROMEOS_ATTESTATION)
std::string GetKeyNameForProfile(
AttestationCertificateProfile certificate_profile,
const std::string& request_origin);
} // namespace attestation
} // namespace chromeos
#endif // CHROMEOS_ATTESTATION_ATTESTATION_FLOW_UTILS_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromeos/attestation/attestation_flow_utils.h"
#include <string>
#include "chromeos/dbus/constants/attestation_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace attestation {
namespace {
constexpr char kFakeOrigin[] = "origin";
} // namespace
TEST(AttestationFlowUtilsTest, GetKeyNameForProfile) {
EXPECT_EQ(
GetKeyNameForProfile(PROFILE_ENTERPRISE_MACHINE_CERTIFICATE, kFakeOrigin),
kEnterpriseMachineKey);
EXPECT_EQ(GetKeyNameForProfile(PROFILE_ENTERPRISE_ENROLLMENT_CERTIFICATE,
kFakeOrigin),
kEnterpriseEnrollmentKey);
EXPECT_EQ(
GetKeyNameForProfile(PROFILE_ENTERPRISE_USER_CERTIFICATE, kFakeOrigin),
kEnterpriseUserKey);
EXPECT_EQ(
GetKeyNameForProfile(PROFILE_CONTENT_PROTECTION_CERTIFICATE, kFakeOrigin),
std::string(kContentProtectionKeyPrefix) + kFakeOrigin);
}
} // namespace attestation
} // namespace chromeos
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment