Skip to content

Commit a479208

Browse files
Yves ArrouyeYves Arrouye
authored andcommitted
Upload EIDs as bytes.
Formally changed the type in the proto (as on server). Also include a zero byte in the EID in unit tests. BUG=chromium:840496 TEST=unit_tests Change-Id: I4e0acaf70547658421c16a8d4731f72f7dc2caa1 Reviewed-on: https://chromium-review.googlesource.com/1079255 Commit-Queue: Yves Arrouye <[email protected]> Reviewed-by: Maksim Ivanov <[email protected]> Reviewed-by: Xiyuan Xia <[email protected]> Cr-Original-Commit-Position: refs/heads/master@{#563024}(cherry picked from commit 819405b) Reviewed-on: https://chromium-review.googlesource.com/1080972 Reviewed-by: Yves Arrouye <[email protected]> Cr-Commit-Position: refs/branch-heads/3440@{#73} Cr-Branched-From: 010ddcf-refs/heads/master@{#561733}
1 parent 7b3fb48 commit a479208

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

chrome/browser/chromeos/attestation/enrollment_policy_observer.cc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,14 @@ void EnrollmentPolicyObserver::GetEnrollmentId() {
187187

188188
void EnrollmentPolicyObserver::HandleEnrollmentId(
189189
const std::string& enrollment_id) {
190+
if (enrollment_id.empty()) {
191+
LOG(WARNING) << "EnrollmentPolicyObserver: The enrollment identifier"
192+
" obtained is empty.";
193+
}
190194
policy_client_->UploadEnterpriseEnrollmentId(
191195
enrollment_id,
192-
base::Bind(&EnrollmentPolicyObserver::OnUploadComplete,
193-
weak_factory_.GetWeakPtr(), "Enrollment Identifier"));
196+
base::BindRepeating(&EnrollmentPolicyObserver::OnUploadComplete,
197+
weak_factory_.GetWeakPtr(), "Enrollment Identifier"));
194198
}
195199

196200
void EnrollmentPolicyObserver::RescheduleGetEnrollmentId() {

chrome/browser/chromeos/attestation/enrollment_policy_observer_unittest.cc

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "base/location.h"
1212
#include "base/run_loop.h"
1313
#include "base/single_thread_task_runner.h"
14+
#include "base/strings/string_number_conversions.h"
1415
#include "base/threading/thread_task_runner_handle.h"
1516
#include "chrome/browser/chromeos/attestation/enrollment_policy_observer.h"
1617
#include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
@@ -61,17 +62,18 @@ class EnrollmentPolicyObserverTest : public DeviceSettingsTestBase {
6162
public:
6263
EnrollmentPolicyObserverTest() {
6364
policy_client_.SetDMToken("fake_dm_token");
65+
66+
std::vector<uint8_t> eid;
67+
EXPECT_TRUE(base::HexStringToBytes(kEnrollmentId, &eid));
68+
enrollment_id_.assign(reinterpret_cast<const char*>(eid.data()),
69+
eid.size());
70+
cryptohome_client_.set_tpm_attestation_enrollment_id(
71+
true /* ignore_cache */, enrollment_id_);
6472
}
6573

6674
protected:
6775
static constexpr char kEnrollmentId[] =
68-
"6fcc0ebddec3db95cdcf82476d594f4d60db934c5b47fa6085c707b2a93e205b";
69-
70-
void SetUp() override {
71-
DeviceSettingsTestBase::SetUp();
72-
cryptohome_client_.set_tpm_attestation_enrollment_id(
73-
true /* ignore_cache */, kEnrollmentId);
74-
}
76+
"6fcc0ebddec3db9500cf82476d594f4d60db934c5b47fa6085c707b2a93e205b";
7577

7678
void SetUpEnrollmentIdNeeded(bool enrollment_id_needed) {
7779
if (enrollment_id_needed) {
@@ -103,6 +105,7 @@ class EnrollmentPolicyObserverTest : public DeviceSettingsTestBase {
103105
FakeCryptohomeClient cryptohome_client_;
104106
StrictMock<MockAttestationFlow> attestation_flow_;
105107
StrictMock<policy::MockCloudPolicyClient> policy_client_;
108+
std::string enrollment_id_;
106109
};
107110

108111
constexpr char EnrollmentPolicyObserverTest::kEnrollmentId[];
@@ -132,7 +135,7 @@ TEST_F(EnrollmentPolicyObserverTest, GetCertificateUnspecifiedFailure) {
132135
TEST_F(EnrollmentPolicyObserverTest, GetCertificateBadRequestFailure) {
133136
EXPECT_CALL(attestation_flow_, GetCertificate(_, _, _, _, _))
134137
.WillOnce(WithArgs<4>(Invoke(CertCallbackBadRequestFailure)));
135-
EXPECT_CALL(policy_client_, UploadEnterpriseEnrollmentId(kEnrollmentId, _))
138+
EXPECT_CALL(policy_client_, UploadEnterpriseEnrollmentId(enrollment_id_, _))
136139
.WillOnce(WithArgs<1>(Invoke(StatusCallbackSuccess)));
137140
SetUpDevicePolicy(true);
138141
Run();

components/policy/proto/device_management_backend.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ message DeviceCertUploadRequest {
213213
// Type of certificate. If omitted, will be guessed from the other fields.
214214
optional CertificateType certificate_type = 2;
215215
// Enrollment identifier if provided.
216-
optional string enrollment_id = 3;
216+
optional bytes enrollment_id = 3;
217217
}
218218

219219
// Response from server to device for cert upload request.

0 commit comments

Comments
 (0)