Skip to content

Commit

Permalink
Upload EIDs as bytes.
Browse files Browse the repository at this point in the history
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 <drcrash@chromium.org>
Reviewed-by: Maksim Ivanov <emaxx@chromium.org>
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#563024}
  • Loading branch information
Yves Arrouye authored and Commit Bot committed May 30, 2018
1 parent a7886bc commit 819405b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,14 @@ void EnrollmentPolicyObserver::GetEnrollmentId() {

void EnrollmentPolicyObserver::HandleEnrollmentId(
const std::string& enrollment_id) {
if (enrollment_id.empty()) {
LOG(WARNING) << "EnrollmentPolicyObserver: The enrollment identifier"
" obtained is empty.";
}
policy_client_->UploadEnterpriseEnrollmentId(
enrollment_id,
base::Bind(&EnrollmentPolicyObserver::OnUploadComplete,
weak_factory_.GetWeakPtr(), "Enrollment Identifier"));
base::BindRepeating(&EnrollmentPolicyObserver::OnUploadComplete,
weak_factory_.GetWeakPtr(), "Enrollment Identifier"));
}

void EnrollmentPolicyObserver::RescheduleGetEnrollmentId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/location.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/chromeos/attestation/enrollment_policy_observer.h"
#include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
Expand Down Expand Up @@ -61,17 +62,18 @@ class EnrollmentPolicyObserverTest : public DeviceSettingsTestBase {
public:
EnrollmentPolicyObserverTest() {
policy_client_.SetDMToken("fake_dm_token");

std::vector<uint8_t> eid;
EXPECT_TRUE(base::HexStringToBytes(kEnrollmentId, &eid));
enrollment_id_.assign(reinterpret_cast<const char*>(eid.data()),
eid.size());
cryptohome_client_.set_tpm_attestation_enrollment_id(
true /* ignore_cache */, enrollment_id_);
}

protected:
static constexpr char kEnrollmentId[] =
"6fcc0ebddec3db95cdcf82476d594f4d60db934c5b47fa6085c707b2a93e205b";

void SetUp() override {
DeviceSettingsTestBase::SetUp();
cryptohome_client_.set_tpm_attestation_enrollment_id(
true /* ignore_cache */, kEnrollmentId);
}
"6fcc0ebddec3db9500cf82476d594f4d60db934c5b47fa6085c707b2a93e205b";

void SetUpEnrollmentIdNeeded(bool enrollment_id_needed) {
if (enrollment_id_needed) {
Expand Down Expand Up @@ -103,6 +105,7 @@ class EnrollmentPolicyObserverTest : public DeviceSettingsTestBase {
FakeCryptohomeClient cryptohome_client_;
StrictMock<MockAttestationFlow> attestation_flow_;
StrictMock<policy::MockCloudPolicyClient> policy_client_;
std::string enrollment_id_;
};

constexpr char EnrollmentPolicyObserverTest::kEnrollmentId[];
Expand Down Expand Up @@ -132,7 +135,7 @@ TEST_F(EnrollmentPolicyObserverTest, GetCertificateUnspecifiedFailure) {
TEST_F(EnrollmentPolicyObserverTest, GetCertificateBadRequestFailure) {
EXPECT_CALL(attestation_flow_, GetCertificate(_, _, _, _, _))
.WillOnce(WithArgs<4>(Invoke(CertCallbackBadRequestFailure)));
EXPECT_CALL(policy_client_, UploadEnterpriseEnrollmentId(kEnrollmentId, _))
EXPECT_CALL(policy_client_, UploadEnterpriseEnrollmentId(enrollment_id_, _))
.WillOnce(WithArgs<1>(Invoke(StatusCallbackSuccess)));
SetUpDevicePolicy(true);
Run();
Expand Down
2 changes: 1 addition & 1 deletion components/policy/proto/device_management_backend.proto
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ message DeviceCertUploadRequest {
// Type of certificate. If omitted, will be guessed from the other fields.
optional CertificateType certificate_type = 2;
// Enrollment identifier if provided.
optional string enrollment_id = 3;
optional bytes enrollment_id = 3;
}

// Response from server to device for cert upload request.
Expand Down

0 comments on commit 819405b

Please sign in to comment.