Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: chrome/browser/chromeos/policy/enrollment_handler_chromeos.cc

Issue 2977033002: Mixed Licenses Enrollment (Closed)
Patch Set: Fix CloudPolicyClientTest Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/policy/enrollment_handler_chromeos.h" 5 #include "chrome/browser/chromeos/policy/enrollment_handler_chromeos.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 state_keys_broker_(state_keys_broker), 124 state_keys_broker_(state_keys_broker),
125 attestation_flow_(attestation_flow), 125 attestation_flow_(attestation_flow),
126 client_(std::move(client)), 126 client_(std::move(client)),
127 background_task_runner_(background_task_runner), 127 background_task_runner_(background_task_runner),
128 ad_join_delegate_(ad_join_delegate), 128 ad_join_delegate_(ad_join_delegate),
129 enrollment_config_(enrollment_config), 129 enrollment_config_(enrollment_config),
130 auth_token_(auth_token), 130 auth_token_(auth_token),
131 client_id_(client_id), 131 client_id_(client_id),
132 requisition_(requisition), 132 requisition_(requisition),
133 completion_callback_(completion_callback), 133 completion_callback_(completion_callback),
134 license_type_(em::LicenseType::UNDEFINED),
achuithb 2017/07/31 21:03:23 Initialize in header
Denis Kuznetsov (DE-MUC) 2017/08/01 10:50:54 Done.
134 enrollment_step_(STEP_PENDING), 135 enrollment_step_(STEP_PENDING),
135 weak_ptr_factory_(this) { 136 weak_ptr_factory_(this) {
136 CHECK(!client_->is_registered()); 137 CHECK(!client_->is_registered());
137 CHECK_EQ(DM_STATUS_SUCCESS, client_->status()); 138 CHECK_EQ(DM_STATUS_SUCCESS, client_->status());
138 CHECK((enrollment_config_.mode == EnrollmentConfig::MODE_ATTESTATION || 139 CHECK((enrollment_config_.mode == EnrollmentConfig::MODE_ATTESTATION ||
139 enrollment_config_.mode == 140 enrollment_config_.mode ==
140 EnrollmentConfig::MODE_ATTESTATION_FORCED) == auth_token_.empty()); 141 EnrollmentConfig::MODE_ATTESTATION_FORCED) == auth_token_.empty());
141 CHECK(enrollment_config_.auth_mechanism != 142 CHECK(enrollment_config_.auth_mechanism !=
142 EnrollmentConfig::AUTH_MECHANISM_ATTESTATION || 143 EnrollmentConfig::AUTH_MECHANISM_ATTESTATION ||
143 attestation_flow_); 144 attestation_flow_);
144 store_->AddObserver(this); 145 store_->AddObserver(this);
145 client_->AddObserver(this); 146 client_->AddObserver(this);
146 client_->AddPolicyTypeToFetch(dm_protocol::kChromeDevicePolicyType, 147 client_->AddPolicyTypeToFetch(dm_protocol::kChromeDevicePolicyType,
147 std::string()); 148 std::string());
148 } 149 }
149 150
150 EnrollmentHandlerChromeOS::~EnrollmentHandlerChromeOS() { 151 EnrollmentHandlerChromeOS::~EnrollmentHandlerChromeOS() {
151 Stop(); 152 Stop();
152 store_->RemoveObserver(this); 153 store_->RemoveObserver(this);
153 } 154 }
154 155
156 void EnrollmentHandlerChromeOS::CheckAvailableLicenses(
157 const AvailableLicensesCallback& license_callback) {
158 CHECK_EQ(STEP_PENDING, enrollment_step_);
159 available_licenses_callback_ = license_callback;
160 client_->RequestAvailableLicenses(
161 auth_token_,
162 base::Bind(&EnrollmentHandlerChromeOS::HandleAvailableLicensesResult,
163 weak_ptr_factory_.GetWeakPtr()));
164 }
165
166 void EnrollmentHandlerChromeOS::HandleAvailableLicensesResult(
167 bool success,
168 const policy::CloudPolicyClient::LicenseMap& license_map) {
169 if (!success) {
170 ReportResult(
171 EnrollmentStatus::ForStatus(EnrollmentStatus::LICENSE_REQUEST_FAILED));
172 return;
173 }
174 if (!available_licenses_callback_) {
achuithb 2017/07/31 21:03:23 Drop {} is_null?
Denis Kuznetsov (DE-MUC) 2017/08/01 10:50:54 Done
175 available_licenses_callback_.Run(license_map);
176 }
177 }
178
179 void EnrollmentHandlerChromeOS::StartEnrollmentWithLicense(
180 LicenseType license_type) {
181 CHECK_EQ(STEP_PENDING, enrollment_step_);
182 CHECK_NE(license_type, ::policy::LicenseType::UNKNOWN);
183 switch (license_type) {
184 case ::policy::LicenseType::PERPETUAL:
185 license_type_ = ::em::LicenseType::CDM_PERPETUAL;
186 return;
187 case ::policy::LicenseType::ANNUAL:
188 license_type_ = ::em::LicenseType::CDM_ANNUAL;
189 return;
190 case ::policy::LicenseType::KIOSK:
191 license_type_ = ::em::LicenseType::KIOSK;
192 return;
193 case ::policy::LicenseType::UNKNOWN:
194 NOTREACHED();
195 }
196 StartEnrollment();
197 }
198
155 void EnrollmentHandlerChromeOS::StartEnrollment() { 199 void EnrollmentHandlerChromeOS::StartEnrollment() {
156 CHECK_EQ(STEP_PENDING, enrollment_step_); 200 CHECK_EQ(STEP_PENDING, enrollment_step_);
157 SetStep(STEP_STATE_KEYS); 201 SetStep(STEP_STATE_KEYS);
158 202
159 if (client_->machine_id().empty()) { 203 if (client_->machine_id().empty()) {
160 LOG(ERROR) << "Machine id empty."; 204 LOG(ERROR) << "Machine id empty.";
161 ReportResult(EnrollmentStatus::ForStatus( 205 ReportResult(EnrollmentStatus::ForStatus(
162 EnrollmentStatus::NO_MACHINE_IDENTIFICATION)); 206 EnrollmentStatus::NO_MACHINE_IDENTIFICATION));
163 return; 207 return;
164 } 208 }
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // after the CloudPolicyStore has initialized. 359 // after the CloudPolicyStore has initialized.
316 return; 360 return;
317 } 361 }
318 SetStep(STEP_REGISTRATION); 362 SetStep(STEP_REGISTRATION);
319 if (enrollment_config_.is_mode_attestation()) { 363 if (enrollment_config_.is_mode_attestation()) {
320 StartAttestationBasedEnrollmentFlow(); 364 StartAttestationBasedEnrollmentFlow();
321 } else { 365 } else {
322 client_->Register( 366 client_->Register(
323 em::DeviceRegisterRequest::DEVICE, 367 em::DeviceRegisterRequest::DEVICE,
324 EnrollmentModeToRegistrationFlavor(enrollment_config_.mode), 368 EnrollmentModeToRegistrationFlavor(enrollment_config_.mode),
325 auth_token_, client_id_, requisition_, current_state_key_); 369 license_type_, auth_token_, client_id_, requisition_,
370 current_state_key_);
326 } 371 }
327 } 372 }
328 373
329 void EnrollmentHandlerChromeOS::StartAttestationBasedEnrollmentFlow() { 374 void EnrollmentHandlerChromeOS::StartAttestationBasedEnrollmentFlow() {
330 const chromeos::attestation::AttestationFlow::CertificateCallback callback = 375 const chromeos::attestation::AttestationFlow::CertificateCallback callback =
331 base::Bind( 376 base::Bind(
332 &EnrollmentHandlerChromeOS::HandleRegistrationCertificateResult, 377 &EnrollmentHandlerChromeOS::HandleRegistrationCertificateResult,
333 weak_ptr_factory_.GetWeakPtr()); 378 weak_ptr_factory_.GetWeakPtr());
334 attestation_flow_->GetCertificate( 379 attestation_flow_->GetCertificate(
335 chromeos::attestation::PROFILE_ENTERPRISE_ENROLLMENT_CERTIFICATE, 380 chromeos::attestation::PROFILE_ENTERPRISE_ENROLLMENT_CERTIFICATE,
336 EmptyAccountId(), "" /* request_origin */, false /* force_new_key */, 381 EmptyAccountId(), "" /* request_origin */, false /* force_new_key */,
337 callback); 382 callback);
338 } 383 }
339 384
340 void EnrollmentHandlerChromeOS::HandleRegistrationCertificateResult( 385 void EnrollmentHandlerChromeOS::HandleRegistrationCertificateResult(
341 bool success, 386 bool success,
342 const std::string& pem_certificate_chain) { 387 const std::string& pem_certificate_chain) {
343 if (success) 388 if (success)
344 client_->RegisterWithCertificate( 389 client_->RegisterWithCertificate(
345 em::DeviceRegisterRequest::DEVICE, 390 em::DeviceRegisterRequest::DEVICE,
346 EnrollmentModeToRegistrationFlavor(enrollment_config_.mode), 391 EnrollmentModeToRegistrationFlavor(enrollment_config_.mode),
347 pem_certificate_chain, client_id_, requisition_, current_state_key_); 392 license_type_, pem_certificate_chain, client_id_, requisition_,
393 current_state_key_);
348 else 394 else
349 ReportResult(EnrollmentStatus::ForStatus( 395 ReportResult(EnrollmentStatus::ForStatus(
350 EnrollmentStatus::REGISTRATION_CERT_FETCH_FAILED)); 396 EnrollmentStatus::REGISTRATION_CERT_FETCH_FAILED));
351 } 397 }
352 398
353 void EnrollmentHandlerChromeOS::HandlePolicyValidationResult( 399 void EnrollmentHandlerChromeOS::HandlePolicyValidationResult(
354 DeviceCloudPolicyValidator* validator) { 400 DeviceCloudPolicyValidator* validator) {
355 DCHECK_EQ(STEP_VALIDATION, enrollment_step_); 401 DCHECK_EQ(STEP_VALIDATION, enrollment_step_);
356 if (validator->success()) { 402 if (validator->success()) {
357 std::string username = validator->policy_data()->username(); 403 std::string username = validator->policy_data()->username();
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 // After that, the enrollment flow continues in one of the OnStore* observers. 674 // After that, the enrollment flow continues in one of the OnStore* observers.
629 store_->Load(); 675 store_->Load();
630 } 676 }
631 677
632 void EnrollmentHandlerChromeOS::Stop() { 678 void EnrollmentHandlerChromeOS::Stop() {
633 if (client_.get()) 679 if (client_.get())
634 client_->RemoveObserver(this); 680 client_->RemoveObserver(this);
635 SetStep(STEP_FINISHED); 681 SetStep(STEP_FINISHED);
636 weak_ptr_factory_.InvalidateWeakPtrs(); 682 weak_ptr_factory_.InvalidateWeakPtrs();
637 completion_callback_.Reset(); 683 completion_callback_.Reset();
684 available_licenses_callback_.Reset();
638 } 685 }
639 686
640 void EnrollmentHandlerChromeOS::ReportResult(EnrollmentStatus status) { 687 void EnrollmentHandlerChromeOS::ReportResult(EnrollmentStatus status) {
641 EnrollmentCallback callback = completion_callback_; 688 EnrollmentCallback callback = completion_callback_;
642 Stop(); 689 Stop();
643 690
644 if (status.status() != EnrollmentStatus::SUCCESS) { 691 if (status.status() != EnrollmentStatus::SUCCESS) {
645 LOG(WARNING) << "Enrollment failed: " << status.status() 692 LOG(WARNING) << "Enrollment failed: " << status.status()
646 << ", client: " << status.client_status() 693 << ", client: " << status.client_status()
647 << ", validation: " << status.validation_status() 694 << ", validation: " << status.validation_status()
648 << ", store: " << status.store_status() 695 << ", store: " << status.store_status()
649 << ", lock: " << status.lock_status(); 696 << ", lock: " << status.lock_status();
650 } 697 }
651 698
652 if (!callback.is_null()) 699 if (!callback.is_null())
653 callback.Run(status); 700 callback.Run(status);
654 } 701 }
655 702
656 void EnrollmentHandlerChromeOS::SetStep(EnrollmentStep step) { 703 void EnrollmentHandlerChromeOS::SetStep(EnrollmentStep step) {
657 DCHECK_LE(enrollment_step_, step); 704 DCHECK_LE(enrollment_step_, step);
658 VLOG(1) << "Step: " << step; 705 VLOG(1) << "Step: " << step;
659 enrollment_step_ = step; 706 enrollment_step_ = step;
660 } 707 }
661 708
662 } // namespace policy 709 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698