OLD | NEW |
---|---|
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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 client_->AddObserver(this); | 145 client_->AddObserver(this); |
146 client_->AddPolicyTypeToFetch(dm_protocol::kChromeDevicePolicyType, | 146 client_->AddPolicyTypeToFetch(dm_protocol::kChromeDevicePolicyType, |
147 std::string()); | 147 std::string()); |
148 } | 148 } |
149 | 149 |
150 EnrollmentHandlerChromeOS::~EnrollmentHandlerChromeOS() { | 150 EnrollmentHandlerChromeOS::~EnrollmentHandlerChromeOS() { |
151 Stop(); | 151 Stop(); |
152 store_->RemoveObserver(this); | 152 store_->RemoveObserver(this); |
153 } | 153 } |
154 | 154 |
155 void EnrollmentHandlerChromeOS::CheckAvailableLicenses( | |
156 const AvailableLicensesCallback& license_callback) { | |
157 CHECK_EQ(STEP_PENDING, enrollment_step_); | |
158 available_licenses_callback_ = license_callback; | |
159 client_->RequestAvailableLicenses( | |
160 auth_token_, | |
161 base::Bind(&EnrollmentHandlerChromeOS::HandleAvailableLicensesResult, | |
162 weak_ptr_factory_.GetWeakPtr())); | |
163 } | |
164 | |
165 void EnrollmentHandlerChromeOS::HandleAvailableLicensesResult( | |
166 bool success, | |
167 const policy::CloudPolicyClient::LicenseMap& license_map) { | |
emaxx
2017/08/03 18:31:50
nit: s/policy:://
| |
168 if (!success) { | |
169 ReportResult( | |
170 EnrollmentStatus::ForStatus(EnrollmentStatus::LICENSE_REQUEST_FAILED)); | |
171 return; | |
172 } | |
173 if (!available_licenses_callback_) | |
174 available_licenses_callback_.Run(license_map); | |
175 } | |
176 | |
177 void EnrollmentHandlerChromeOS::StartEnrollmentWithLicense( | |
178 LicenseType license_type) { | |
179 CHECK_EQ(STEP_PENDING, enrollment_step_); | |
180 CHECK_NE(license_type, ::policy::LicenseType::UNKNOWN); | |
181 switch (license_type) { | |
182 case ::policy::LicenseType::PERPETUAL: | |
emaxx
2017/08/03 18:31:50
nit: s/::policy:://
| |
183 license_type_ = ::em::LicenseType::CDM_PERPETUAL; | |
184 break; | |
185 case ::policy::LicenseType::ANNUAL: | |
186 license_type_ = ::em::LicenseType::CDM_ANNUAL; | |
187 break; | |
188 case ::policy::LicenseType::KIOSK: | |
189 license_type_ = ::em::LicenseType::KIOSK; | |
190 break; | |
191 case ::policy::LicenseType::UNKNOWN: | |
192 NOTREACHED(); | |
193 } | |
194 StartEnrollment(); | |
195 } | |
196 | |
155 void EnrollmentHandlerChromeOS::StartEnrollment() { | 197 void EnrollmentHandlerChromeOS::StartEnrollment() { |
156 CHECK_EQ(STEP_PENDING, enrollment_step_); | 198 CHECK_EQ(STEP_PENDING, enrollment_step_); |
157 SetStep(STEP_STATE_KEYS); | 199 SetStep(STEP_STATE_KEYS); |
158 | 200 |
159 if (client_->machine_id().empty()) { | 201 if (client_->machine_id().empty()) { |
160 LOG(ERROR) << "Machine id empty."; | 202 LOG(ERROR) << "Machine id empty."; |
161 ReportResult(EnrollmentStatus::ForStatus( | 203 ReportResult(EnrollmentStatus::ForStatus( |
162 EnrollmentStatus::NO_MACHINE_IDENTIFICATION)); | 204 EnrollmentStatus::NO_MACHINE_IDENTIFICATION)); |
163 return; | 205 return; |
164 } | 206 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 // after the CloudPolicyStore has initialized. | 357 // after the CloudPolicyStore has initialized. |
316 return; | 358 return; |
317 } | 359 } |
318 SetStep(STEP_REGISTRATION); | 360 SetStep(STEP_REGISTRATION); |
319 if (enrollment_config_.is_mode_attestation()) { | 361 if (enrollment_config_.is_mode_attestation()) { |
320 StartAttestationBasedEnrollmentFlow(); | 362 StartAttestationBasedEnrollmentFlow(); |
321 } else { | 363 } else { |
322 client_->Register( | 364 client_->Register( |
323 em::DeviceRegisterRequest::DEVICE, | 365 em::DeviceRegisterRequest::DEVICE, |
324 EnrollmentModeToRegistrationFlavor(enrollment_config_.mode), | 366 EnrollmentModeToRegistrationFlavor(enrollment_config_.mode), |
325 auth_token_, client_id_, requisition_, current_state_key_); | 367 license_type_, auth_token_, client_id_, requisition_, |
368 current_state_key_); | |
326 } | 369 } |
327 } | 370 } |
328 | 371 |
329 void EnrollmentHandlerChromeOS::StartAttestationBasedEnrollmentFlow() { | 372 void EnrollmentHandlerChromeOS::StartAttestationBasedEnrollmentFlow() { |
330 const chromeos::attestation::AttestationFlow::CertificateCallback callback = | 373 const chromeos::attestation::AttestationFlow::CertificateCallback callback = |
331 base::Bind( | 374 base::Bind( |
332 &EnrollmentHandlerChromeOS::HandleRegistrationCertificateResult, | 375 &EnrollmentHandlerChromeOS::HandleRegistrationCertificateResult, |
333 weak_ptr_factory_.GetWeakPtr()); | 376 weak_ptr_factory_.GetWeakPtr()); |
334 attestation_flow_->GetCertificate( | 377 attestation_flow_->GetCertificate( |
335 chromeos::attestation::PROFILE_ENTERPRISE_ENROLLMENT_CERTIFICATE, | 378 chromeos::attestation::PROFILE_ENTERPRISE_ENROLLMENT_CERTIFICATE, |
336 EmptyAccountId(), "" /* request_origin */, false /* force_new_key */, | 379 EmptyAccountId(), "" /* request_origin */, false /* force_new_key */, |
337 callback); | 380 callback); |
338 } | 381 } |
339 | 382 |
340 void EnrollmentHandlerChromeOS::HandleRegistrationCertificateResult( | 383 void EnrollmentHandlerChromeOS::HandleRegistrationCertificateResult( |
341 bool success, | 384 bool success, |
342 const std::string& pem_certificate_chain) { | 385 const std::string& pem_certificate_chain) { |
343 if (success) | 386 if (success) |
344 client_->RegisterWithCertificate( | 387 client_->RegisterWithCertificate( |
345 em::DeviceRegisterRequest::DEVICE, | 388 em::DeviceRegisterRequest::DEVICE, |
346 EnrollmentModeToRegistrationFlavor(enrollment_config_.mode), | 389 EnrollmentModeToRegistrationFlavor(enrollment_config_.mode), |
347 pem_certificate_chain, client_id_, requisition_, current_state_key_); | 390 license_type_, pem_certificate_chain, client_id_, requisition_, |
391 current_state_key_); | |
348 else | 392 else |
349 ReportResult(EnrollmentStatus::ForStatus( | 393 ReportResult(EnrollmentStatus::ForStatus( |
350 EnrollmentStatus::REGISTRATION_CERT_FETCH_FAILED)); | 394 EnrollmentStatus::REGISTRATION_CERT_FETCH_FAILED)); |
351 } | 395 } |
352 | 396 |
353 void EnrollmentHandlerChromeOS::HandlePolicyValidationResult( | 397 void EnrollmentHandlerChromeOS::HandlePolicyValidationResult( |
354 DeviceCloudPolicyValidator* validator) { | 398 DeviceCloudPolicyValidator* validator) { |
355 DCHECK_EQ(STEP_VALIDATION, enrollment_step_); | 399 DCHECK_EQ(STEP_VALIDATION, enrollment_step_); |
356 if (validator->success()) { | 400 if (validator->success()) { |
357 std::string username = validator->policy_data()->username(); | 401 std::string username = validator->policy_data()->username(); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
628 // After that, the enrollment flow continues in one of the OnStore* observers. | 672 // After that, the enrollment flow continues in one of the OnStore* observers. |
629 store_->Load(); | 673 store_->Load(); |
630 } | 674 } |
631 | 675 |
632 void EnrollmentHandlerChromeOS::Stop() { | 676 void EnrollmentHandlerChromeOS::Stop() { |
633 if (client_.get()) | 677 if (client_.get()) |
634 client_->RemoveObserver(this); | 678 client_->RemoveObserver(this); |
635 SetStep(STEP_FINISHED); | 679 SetStep(STEP_FINISHED); |
636 weak_ptr_factory_.InvalidateWeakPtrs(); | 680 weak_ptr_factory_.InvalidateWeakPtrs(); |
637 completion_callback_.Reset(); | 681 completion_callback_.Reset(); |
682 available_licenses_callback_.Reset(); | |
638 } | 683 } |
639 | 684 |
640 void EnrollmentHandlerChromeOS::ReportResult(EnrollmentStatus status) { | 685 void EnrollmentHandlerChromeOS::ReportResult(EnrollmentStatus status) { |
641 EnrollmentCallback callback = completion_callback_; | 686 EnrollmentCallback callback = completion_callback_; |
642 Stop(); | 687 Stop(); |
643 | 688 |
644 if (status.status() != EnrollmentStatus::SUCCESS) { | 689 if (status.status() != EnrollmentStatus::SUCCESS) { |
645 LOG(WARNING) << "Enrollment failed: " << status.status() | 690 LOG(WARNING) << "Enrollment failed: " << status.status() |
646 << ", client: " << status.client_status() | 691 << ", client: " << status.client_status() |
647 << ", validation: " << status.validation_status() | 692 << ", validation: " << status.validation_status() |
648 << ", store: " << status.store_status() | 693 << ", store: " << status.store_status() |
649 << ", lock: " << status.lock_status(); | 694 << ", lock: " << status.lock_status(); |
650 } | 695 } |
651 | 696 |
652 if (!callback.is_null()) | 697 if (!callback.is_null()) |
653 callback.Run(status); | 698 callback.Run(status); |
654 } | 699 } |
655 | 700 |
656 void EnrollmentHandlerChromeOS::SetStep(EnrollmentStep step) { | 701 void EnrollmentHandlerChromeOS::SetStep(EnrollmentStep step) { |
657 DCHECK_LE(enrollment_step_, step); | 702 DCHECK_LE(enrollment_step_, step); |
658 VLOG(1) << "Step: " << step; | 703 VLOG(1) << "Step: " << step; |
659 enrollment_step_ = step; | 704 enrollment_step_ = step; |
660 } | 705 } |
661 | 706 |
662 } // namespace policy | 707 } // namespace policy |
OLD | NEW |