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

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

Issue 2677563005: Chromad: Use DM server reply to determine enrollment type (Closed)
Patch Set: More comments Created 3 years, 10 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"
11 #include "base/location.h" 11 #include "base/location.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/single_thread_task_runner.h" 13 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h" 14 #include "base/threading/thread_task_runner_handle.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" 16 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h"
17 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 17 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
18 #include "chrome/browser/chromeos/policy/active_directory_join_delegate.h"
18 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" 19 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
19 #include "chrome/browser/chromeos/policy/dm_token_storage.h" 20 #include "chrome/browser/chromeos/policy/dm_token_storage.h"
20 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" 21 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h"
21 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 22 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
22 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" 23 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h"
23 #include "chrome/browser/chromeos/profiles/profile_helper.h" 24 #include "chrome/browser/chromeos/profiles/profile_helper.h"
24 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 25 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
25 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 26 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
26 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/common/channel_info.h"
27 #include "chromeos/attestation/attestation_flow.h" 29 #include "chromeos/attestation/attestation_flow.h"
28 #include "chromeos/chromeos_switches.h" 30 #include "chromeos/chromeos_switches.h"
29 #include "chromeos/dbus/auth_policy_client.h" 31 #include "chromeos/dbus/auth_policy_client.h"
30 #include "chromeos/dbus/dbus_thread_manager.h" 32 #include "chromeos/dbus/dbus_thread_manager.h"
33 #include "chromeos/dbus/upstart_client.h"
34 #include "components/version_info/version_info.h"
31 #include "google_apis/gaia/gaia_auth_util.h" 35 #include "google_apis/gaia/gaia_auth_util.h"
32 #include "google_apis/gaia/gaia_urls.h" 36 #include "google_apis/gaia/gaia_urls.h"
33 #include "net/http/http_status_code.h" 37 #include "net/http/http_status_code.h"
34 38
35 namespace em = enterprise_management; 39 namespace em = enterprise_management;
36 40
37 namespace policy { 41 namespace policy {
38 42
39 namespace { 43 namespace {
40 44
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 78
75 } // namespace 79 } // namespace
76 80
77 EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS( 81 EnrollmentHandlerChromeOS::EnrollmentHandlerChromeOS(
78 DeviceCloudPolicyStoreChromeOS* store, 82 DeviceCloudPolicyStoreChromeOS* store,
79 chromeos::InstallAttributes* install_attributes, 83 chromeos::InstallAttributes* install_attributes,
80 ServerBackedStateKeysBroker* state_keys_broker, 84 ServerBackedStateKeysBroker* state_keys_broker,
81 chromeos::attestation::AttestationFlow* attestation_flow, 85 chromeos::attestation::AttestationFlow* attestation_flow,
82 std::unique_ptr<CloudPolicyClient> client, 86 std::unique_ptr<CloudPolicyClient> client,
83 scoped_refptr<base::SequencedTaskRunner> background_task_runner, 87 scoped_refptr<base::SequencedTaskRunner> background_task_runner,
88 chromeos::ActiveDirectoryJoinDelegate* ad_join_delegate,
84 const EnrollmentConfig& enrollment_config, 89 const EnrollmentConfig& enrollment_config,
85 const std::string& auth_token, 90 const std::string& auth_token,
86 const std::string& client_id, 91 const std::string& client_id,
87 const std::string& requisition, 92 const std::string& requisition,
88 const EnrollmentCallback& completion_callback) 93 const EnrollmentCallback& completion_callback)
89 : store_(store), 94 : store_(store),
90 install_attributes_(install_attributes), 95 install_attributes_(install_attributes),
91 state_keys_broker_(state_keys_broker), 96 state_keys_broker_(state_keys_broker),
92 attestation_flow_(attestation_flow), 97 attestation_flow_(attestation_flow),
93 client_(std::move(client)), 98 client_(std::move(client)),
94 background_task_runner_(background_task_runner), 99 background_task_runner_(background_task_runner),
100 ad_join_delegate_(ad_join_delegate),
95 enrollment_config_(enrollment_config), 101 enrollment_config_(enrollment_config),
96 auth_token_(auth_token), 102 auth_token_(auth_token),
97 client_id_(client_id), 103 client_id_(client_id),
98 requisition_(requisition), 104 requisition_(requisition),
99 completion_callback_(completion_callback), 105 completion_callback_(completion_callback),
100 device_mode_(DEVICE_MODE_NOT_SET),
101 skip_robot_auth_(false),
102 enrollment_step_(STEP_PENDING), 106 enrollment_step_(STEP_PENDING),
103 lockbox_init_duration_(0),
104 weak_ptr_factory_(this) { 107 weak_ptr_factory_(this) {
105 CHECK(!client_->is_registered()); 108 CHECK(!client_->is_registered());
106 CHECK_EQ(DM_STATUS_SUCCESS, client_->status()); 109 CHECK_EQ(DM_STATUS_SUCCESS, client_->status());
107 CHECK((enrollment_config_.mode == EnrollmentConfig::MODE_ATTESTATION || 110 CHECK((enrollment_config_.mode == EnrollmentConfig::MODE_ATTESTATION ||
108 enrollment_config_.mode == 111 enrollment_config_.mode ==
109 EnrollmentConfig::MODE_ATTESTATION_FORCED) == auth_token_.empty()); 112 EnrollmentConfig::MODE_ATTESTATION_FORCED) == auth_token_.empty());
110 CHECK(enrollment_config_.auth_mechanism != 113 CHECK(enrollment_config_.auth_mechanism !=
111 EnrollmentConfig::AUTH_MECHANISM_ATTESTATION || 114 EnrollmentConfig::AUTH_MECHANISM_ATTESTATION ||
112 attestation_flow_); 115 attestation_flow_);
113 store_->AddObserver(this); 116 store_->AddObserver(this);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 validator.release()->StartValidation( 196 validator.release()->StartValidation(
194 base::Bind(&EnrollmentHandlerChromeOS::HandlePolicyValidationResult, 197 base::Bind(&EnrollmentHandlerChromeOS::HandlePolicyValidationResult,
195 weak_ptr_factory_.GetWeakPtr())); 198 weak_ptr_factory_.GetWeakPtr()));
196 } 199 }
197 200
198 void EnrollmentHandlerChromeOS::OnRegistrationStateChanged( 201 void EnrollmentHandlerChromeOS::OnRegistrationStateChanged(
199 CloudPolicyClient* client) { 202 CloudPolicyClient* client) {
200 DCHECK_EQ(client_.get(), client); 203 DCHECK_EQ(client_.get(), client);
201 204
202 if (enrollment_step_ == STEP_REGISTRATION && client_->is_registered()) { 205 if (enrollment_step_ == STEP_REGISTRATION && client_->is_registered()) {
206 device_mode_ = client_->device_mode();
207 switch (device_mode_) {
208 case DEVICE_MODE_ENTERPRISE:
209 // Do nothing.
210 break;
211 case DEVICE_MODE_ENTERPRISE_AD:
212 if (chrome::GetChannel() == version_info::Channel::BETA ||
213 chrome::GetChannel() == version_info::Channel::STABLE) {
214 LOG(ERROR) << "Active Directory management is not enabled on the "
215 "current channel";
216 ReportResult(EnrollmentStatus::ForStatus(
217 EnrollmentStatus::REGISTRATION_BAD_MODE));
218 return;
219 }
220 chromeos::DBusThreadManager::Get()
221 ->GetUpstartClient()
222 ->StartAuthPolicyService();
223 break;
224 default:
225 LOG(ERROR) << "Supplied device mode is not supported:" << device_mode_;
226 ReportResult(EnrollmentStatus::ForStatus(
227 EnrollmentStatus::REGISTRATION_BAD_MODE));
228 return;
229 }
203 SetStep(STEP_POLICY_FETCH); 230 SetStep(STEP_POLICY_FETCH);
204 device_mode_ = client_->device_mode();
205 if (!((device_mode_ == DEVICE_MODE_ENTERPRISE &&
206 enrollment_config_.management_realm.empty()) ||
207 (device_mode_ == DEVICE_MODE_ENTERPRISE_AD &&
208 !enrollment_config_.management_realm.empty()))) {
209 LOG(ERROR) << "Bad device mode " << device_mode_;
210 ReportResult(
211 EnrollmentStatus::ForStatus(EnrollmentStatus::REGISTRATION_BAD_MODE));
212 return;
213 }
214 client_->FetchPolicy(); 231 client_->FetchPolicy();
215 } else { 232 } else {
216 LOG(FATAL) << "Registration state changed to " << client_->is_registered() 233 LOG(FATAL) << "Registration state changed to " << client_->is_registered()
217 << " in step " << enrollment_step_ << "."; 234 << " in step " << enrollment_step_ << ".";
218 } 235 }
219 } 236 }
220 237
221 void EnrollmentHandlerChromeOS::OnClientError(CloudPolicyClient* client) { 238 void EnrollmentHandlerChromeOS::OnClientError(CloudPolicyClient* client) {
222 DCHECK_EQ(client_.get(), client); 239 DCHECK_EQ(client_.get(), client);
223 240
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 void EnrollmentHandlerChromeOS::HandlePolicyValidationResult( 334 void EnrollmentHandlerChromeOS::HandlePolicyValidationResult(
318 DeviceCloudPolicyValidator* validator) { 335 DeviceCloudPolicyValidator* validator) {
319 DCHECK_EQ(STEP_VALIDATION, enrollment_step_); 336 DCHECK_EQ(STEP_VALIDATION, enrollment_step_);
320 if (validator->success()) { 337 if (validator->success()) {
321 std::string username = validator->policy_data()->username(); 338 std::string username = validator->policy_data()->username();
322 device_id_ = validator->policy_data()->device_id(); 339 device_id_ = validator->policy_data()->device_id();
323 policy_ = std::move(validator->policy()); 340 policy_ = std::move(validator->policy());
324 if (device_mode_ == DEVICE_MODE_ENTERPRISE_AD) { 341 if (device_mode_ == DEVICE_MODE_ENTERPRISE_AD) {
325 // Don't use robot account for the Active Directory managed devices. 342 // Don't use robot account for the Active Directory managed devices.
326 skip_robot_auth_ = true; 343 skip_robot_auth_ = true;
327 SetStep(STEP_LOCK_DEVICE); 344 SetStep(STEP_AD_DOMAIN_JOIN);
328 StartLockDevice(); 345 StartJoinAdDomain();
329 } else { 346 } else {
330 domain_ = gaia::ExtractDomainName(gaia::CanonicalizeEmail(username)); 347 domain_ = gaia::ExtractDomainName(gaia::CanonicalizeEmail(username));
331 SetStep(STEP_ROBOT_AUTH_FETCH); 348 SetStep(STEP_ROBOT_AUTH_FETCH);
332 client_->FetchRobotAuthCodes(auth_token_); 349 client_->FetchRobotAuthCodes(auth_token_);
333 } 350 }
334 } else { 351 } else {
335 ReportResult(EnrollmentStatus::ForValidationError(validator->status())); 352 ReportResult(EnrollmentStatus::ForValidationError(validator->status()));
336 } 353 }
337 } 354 }
338 355
339 void EnrollmentHandlerChromeOS::OnRobotAuthCodesFetched( 356 void EnrollmentHandlerChromeOS::OnRobotAuthCodesFetched(
340 CloudPolicyClient* client) { 357 CloudPolicyClient* client) {
341 DCHECK_EQ(client_.get(), client); 358 DCHECK_EQ(client_.get(), client);
342 CHECK_EQ(STEP_ROBOT_AUTH_FETCH, enrollment_step_); 359 CHECK_EQ(STEP_ROBOT_AUTH_FETCH, enrollment_step_);
343 360
344 if (client->robot_api_auth_code().empty()) { 361 if (client->robot_api_auth_code().empty()) {
345 // If the server doesn't provide an auth code, skip the robot auth setup. 362 // If the server doesn't provide an auth code, skip the robot auth setup.
346 // This allows clients running against the test server to transparently skip 363 // This allows clients running against the test server to transparently skip
347 // robot auth. 364 // robot auth.
348 skip_robot_auth_ = true; 365 skip_robot_auth_ = true;
349 SetStep(STEP_LOCK_DEVICE); 366 SetStep(STEP_AD_DOMAIN_JOIN);
350 StartLockDevice(); 367 StartJoinAdDomain();
351 return; 368 return;
352 } 369 }
353 370
354 SetStep(STEP_ROBOT_AUTH_REFRESH); 371 SetStep(STEP_ROBOT_AUTH_REFRESH);
355 gaia::OAuthClientInfo client_info; 372 gaia::OAuthClientInfo client_info;
356 client_info.client_id = GaiaUrls::GetInstance()->oauth2_chrome_client_id(); 373 client_info.client_id = GaiaUrls::GetInstance()->oauth2_chrome_client_id();
357 client_info.client_secret = 374 client_info.client_secret =
358 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(); 375 GaiaUrls::GetInstance()->oauth2_chrome_client_secret();
359 client_info.redirect_uri = "oob"; 376 client_info.redirect_uri = "oob";
360 377
361 // Use the system request context to avoid sending user cookies. 378 // Use the system request context to avoid sending user cookies.
362 gaia_oauth_client_.reset(new gaia::GaiaOAuthClient( 379 gaia_oauth_client_.reset(new gaia::GaiaOAuthClient(
363 g_browser_process->system_request_context())); 380 g_browser_process->system_request_context()));
364 gaia_oauth_client_->GetTokensFromAuthCode(client_info, 381 gaia_oauth_client_->GetTokensFromAuthCode(client_info,
365 client->robot_api_auth_code(), 382 client->robot_api_auth_code(),
366 0 /* max_retries */, 383 0 /* max_retries */,
367 this); 384 this);
368 } 385 }
369 386
370 // GaiaOAuthClient::Delegate callback for OAuth2 refresh token fetched. 387 // GaiaOAuthClient::Delegate callback for OAuth2 refresh token fetched.
371 void EnrollmentHandlerChromeOS::OnGetTokensResponse( 388 void EnrollmentHandlerChromeOS::OnGetTokensResponse(
372 const std::string& refresh_token, 389 const std::string& refresh_token,
373 const std::string& access_token, 390 const std::string& access_token,
374 int expires_in_seconds) { 391 int expires_in_seconds) {
375 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_); 392 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_);
376 393
377 robot_refresh_token_ = refresh_token; 394 robot_refresh_token_ = refresh_token;
378 395
379 SetStep(STEP_LOCK_DEVICE); 396 SetStep(STEP_AD_DOMAIN_JOIN);
380 StartLockDevice(); 397 StartJoinAdDomain();
381 } 398 }
382 399
383 // GaiaOAuthClient::Delegate 400 // GaiaOAuthClient::Delegate
384 void EnrollmentHandlerChromeOS::OnRefreshTokenResponse( 401 void EnrollmentHandlerChromeOS::OnRefreshTokenResponse(
385 const std::string& access_token, 402 const std::string& access_token,
386 int expires_in_seconds) { 403 int expires_in_seconds) {
387 // We never use the code that should trigger this callback. 404 // We never use the code that should trigger this callback.
388 LOG(FATAL) << "Unexpected callback invoked."; 405 LOG(FATAL) << "Unexpected callback invoked.";
389 } 406 }
390 407
391 // GaiaOAuthClient::Delegate OAuth2 error when fetching refresh token request. 408 // GaiaOAuthClient::Delegate OAuth2 error when fetching refresh token request.
392 void EnrollmentHandlerChromeOS::OnOAuthError() { 409 void EnrollmentHandlerChromeOS::OnOAuthError() {
393 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_); 410 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_);
394 // OnOAuthError is only called if the request is bad (malformed) or the 411 // OnOAuthError is only called if the request is bad (malformed) or the
395 // response is bad (empty access token returned). 412 // response is bad (empty access token returned).
396 LOG(ERROR) << "OAuth protocol error while fetching API refresh token."; 413 LOG(ERROR) << "OAuth protocol error while fetching API refresh token.";
397 ReportResult( 414 ReportResult(
398 EnrollmentStatus::ForRobotRefreshFetchError(net::HTTP_BAD_REQUEST)); 415 EnrollmentStatus::ForRobotRefreshFetchError(net::HTTP_BAD_REQUEST));
399 } 416 }
400 417
401 // GaiaOAuthClient::Delegate network error when fetching refresh token. 418 // GaiaOAuthClient::Delegate network error when fetching refresh token.
402 void EnrollmentHandlerChromeOS::OnNetworkError(int response_code) { 419 void EnrollmentHandlerChromeOS::OnNetworkError(int response_code) {
403 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_); 420 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_);
404 LOG(ERROR) << "Network error while fetching API refresh token: " 421 LOG(ERROR) << "Network error while fetching API refresh token: "
405 << response_code; 422 << response_code;
406 ReportResult( 423 ReportResult(
407 EnrollmentStatus::ForRobotRefreshFetchError(response_code)); 424 EnrollmentStatus::ForRobotRefreshFetchError(response_code));
408 } 425 }
409 426
427 void EnrollmentHandlerChromeOS::StartJoinAdDomain() {
428 DCHECK_EQ(STEP_AD_DOMAIN_JOIN, enrollment_step_);
429 if (device_mode_ != DEVICE_MODE_ENTERPRISE_AD) {
430 SetStep(STEP_LOCK_DEVICE);
431 StartLockDevice();
432 return;
433 }
434 DCHECK(ad_join_delegate_);
435 ad_join_delegate_->JoinDomain(
436 base::BindOnce(&EnrollmentHandlerChromeOS::OnAdDomainJoined,
437 weak_ptr_factory_.GetWeakPtr()));
438 }
439
440 void EnrollmentHandlerChromeOS::OnAdDomainJoined(const std::string& realm) {
441 DCHECK_EQ(STEP_AD_DOMAIN_JOIN, enrollment_step_);
442 CHECK(!realm.empty());
443 realm_ = realm;
444 SetStep(STEP_LOCK_DEVICE);
445 StartLockDevice();
446 }
447
410 void EnrollmentHandlerChromeOS::StartLockDevice() { 448 void EnrollmentHandlerChromeOS::StartLockDevice() {
411 DCHECK_EQ(STEP_LOCK_DEVICE, enrollment_step_); 449 DCHECK_EQ(STEP_LOCK_DEVICE, enrollment_step_);
412 // Since this method is also called directly. 450 // Since this method is also called directly.
413 weak_ptr_factory_.InvalidateWeakPtrs(); 451 weak_ptr_factory_.InvalidateWeakPtrs();
414 452
415 install_attributes_->LockDevice( 453 install_attributes_->LockDevice(
416 device_mode_, domain_, enrollment_config_.management_realm, device_id_, 454 device_mode_, domain_, realm_, device_id_,
417 base::Bind(&EnrollmentHandlerChromeOS::HandleLockDeviceResult, 455 base::Bind(&EnrollmentHandlerChromeOS::HandleLockDeviceResult,
418 weak_ptr_factory_.GetWeakPtr())); 456 weak_ptr_factory_.GetWeakPtr()));
419 } 457 }
420 458
421 void EnrollmentHandlerChromeOS::HandleDMTokenStoreResult(bool success) { 459 void EnrollmentHandlerChromeOS::HandleDMTokenStoreResult(bool success) {
422 CHECK_EQ(STEP_STORE_TOKEN, enrollment_step_); 460 CHECK_EQ(STEP_STORE_TOKEN, enrollment_step_);
423 if (!success) { 461 if (!success) {
424 ReportResult( 462 ReportResult(
425 EnrollmentStatus::ForStatus(EnrollmentStatus::DM_TOKEN_STORE_FAILED)); 463 EnrollmentStatus::ForStatus(EnrollmentStatus::DM_TOKEN_STORE_FAILED));
426 return; 464 return;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 callback.Run(status); 599 callback.Run(status);
562 } 600 }
563 601
564 void EnrollmentHandlerChromeOS::SetStep(EnrollmentStep step) { 602 void EnrollmentHandlerChromeOS::SetStep(EnrollmentStep step) {
565 DCHECK_LE(enrollment_step_, step); 603 DCHECK_LE(enrollment_step_, step);
566 VLOG(1) << "Step: " << step; 604 VLOG(1) << "Step: " << step;
567 enrollment_step_ = step; 605 enrollment_step_ = step;
568 } 606 }
569 607
570 } // namespace policy 608 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698