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

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: comment+rebase+fix test 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
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()) {
203 SetStep(STEP_POLICY_FETCH); 206 SetStep(STEP_POLICY_FETCH);
204 device_mode_ = client_->device_mode(); 207 device_mode_ = client_->device_mode();
205 if (!((device_mode_ == DEVICE_MODE_ENTERPRISE && 208 if (device_mode_ == DEVICE_MODE_ENTERPRISE_AD) {
Thiemo Nagel 2017/02/14 14:45:00 Nit: That section might be more readable if factor
Roman Sorokin (ftl) 2017/02/14 16:01:33 Done.
206 enrollment_config_.management_realm.empty()) || 209 if (chrome::GetChannel() == version_info::Channel::BETA ||
207 (device_mode_ == DEVICE_MODE_ENTERPRISE_AD && 210 chrome::GetChannel() == version_info::Channel::STABLE) {
208 !enrollment_config_.management_realm.empty()))) { 211 LOG(ERROR) << "Active Directory management is not enabled on the "
209 LOG(ERROR) << "Bad device mode " << device_mode_; 212 "current channel";
213 ReportResult(EnrollmentStatus::ForStatus(
214 EnrollmentStatus::REGISTRATION_BAD_MODE));
215 return;
216 }
217 chromeos::DBusThreadManager::Get()
218 ->GetUpstartClient()
219 ->StartAuthPolicyService();
220 }
221 if (device_mode_ != DEVICE_MODE_ENTERPRISE &&
222 device_mode_ != DEVICE_MODE_ENTERPRISE_AD) {
223 LOG(ERROR) << "Supplied device mode is not supported:" << device_mode_;
210 ReportResult( 224 ReportResult(
211 EnrollmentStatus::ForStatus(EnrollmentStatus::REGISTRATION_BAD_MODE)); 225 EnrollmentStatus::ForStatus(EnrollmentStatus::REGISTRATION_BAD_MODE));
212 return; 226 return;
213 } 227 }
214 client_->FetchPolicy(); 228 client_->FetchPolicy();
215 } else { 229 } else {
216 LOG(FATAL) << "Registration state changed to " << client_->is_registered() 230 LOG(FATAL) << "Registration state changed to " << client_->is_registered()
217 << " in step " << enrollment_step_ << "."; 231 << " in step " << enrollment_step_ << ".";
218 } 232 }
219 } 233 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 void EnrollmentHandlerChromeOS::HandlePolicyValidationResult( 331 void EnrollmentHandlerChromeOS::HandlePolicyValidationResult(
318 DeviceCloudPolicyValidator* validator) { 332 DeviceCloudPolicyValidator* validator) {
319 DCHECK_EQ(STEP_VALIDATION, enrollment_step_); 333 DCHECK_EQ(STEP_VALIDATION, enrollment_step_);
320 if (validator->success()) { 334 if (validator->success()) {
321 std::string username = validator->policy_data()->username(); 335 std::string username = validator->policy_data()->username();
322 device_id_ = validator->policy_data()->device_id(); 336 device_id_ = validator->policy_data()->device_id();
323 policy_ = std::move(validator->policy()); 337 policy_ = std::move(validator->policy());
324 if (device_mode_ == DEVICE_MODE_ENTERPRISE_AD) { 338 if (device_mode_ == DEVICE_MODE_ENTERPRISE_AD) {
325 // Don't use robot account for the Active Directory managed devices. 339 // Don't use robot account for the Active Directory managed devices.
326 skip_robot_auth_ = true; 340 skip_robot_auth_ = true;
327 SetStep(STEP_LOCK_DEVICE); 341 SetStep(STEP_AD_DOMAIN_JOIN);
328 StartLockDevice(); 342 StartJoinAdDomain();
329 } else { 343 } else {
330 domain_ = gaia::ExtractDomainName(gaia::CanonicalizeEmail(username)); 344 domain_ = gaia::ExtractDomainName(gaia::CanonicalizeEmail(username));
331 SetStep(STEP_ROBOT_AUTH_FETCH); 345 SetStep(STEP_ROBOT_AUTH_FETCH);
332 client_->FetchRobotAuthCodes(auth_token_); 346 client_->FetchRobotAuthCodes(auth_token_);
333 } 347 }
334 } else { 348 } else {
335 ReportResult(EnrollmentStatus::ForValidationError(validator->status())); 349 ReportResult(EnrollmentStatus::ForValidationError(validator->status()));
336 } 350 }
337 } 351 }
338 352
339 void EnrollmentHandlerChromeOS::OnRobotAuthCodesFetched( 353 void EnrollmentHandlerChromeOS::OnRobotAuthCodesFetched(
340 CloudPolicyClient* client) { 354 CloudPolicyClient* client) {
341 DCHECK_EQ(client_.get(), client); 355 DCHECK_EQ(client_.get(), client);
342 CHECK_EQ(STEP_ROBOT_AUTH_FETCH, enrollment_step_); 356 CHECK_EQ(STEP_ROBOT_AUTH_FETCH, enrollment_step_);
343 357
344 if (client->robot_api_auth_code().empty()) { 358 if (client->robot_api_auth_code().empty()) {
345 // If the server doesn't provide an auth code, skip the robot auth setup. 359 // 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 360 // This allows clients running against the test server to transparently skip
347 // robot auth. 361 // robot auth.
348 skip_robot_auth_ = true; 362 skip_robot_auth_ = true;
349 SetStep(STEP_LOCK_DEVICE); 363 SetStep(STEP_AD_DOMAIN_JOIN);
350 StartLockDevice(); 364 StartJoinAdDomain();
351 return; 365 return;
352 } 366 }
353 367
354 SetStep(STEP_ROBOT_AUTH_REFRESH); 368 SetStep(STEP_ROBOT_AUTH_REFRESH);
355 gaia::OAuthClientInfo client_info; 369 gaia::OAuthClientInfo client_info;
356 client_info.client_id = GaiaUrls::GetInstance()->oauth2_chrome_client_id(); 370 client_info.client_id = GaiaUrls::GetInstance()->oauth2_chrome_client_id();
357 client_info.client_secret = 371 client_info.client_secret =
358 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(); 372 GaiaUrls::GetInstance()->oauth2_chrome_client_secret();
359 client_info.redirect_uri = "oob"; 373 client_info.redirect_uri = "oob";
360 374
361 // Use the system request context to avoid sending user cookies. 375 // Use the system request context to avoid sending user cookies.
362 gaia_oauth_client_.reset(new gaia::GaiaOAuthClient( 376 gaia_oauth_client_.reset(new gaia::GaiaOAuthClient(
363 g_browser_process->system_request_context())); 377 g_browser_process->system_request_context()));
364 gaia_oauth_client_->GetTokensFromAuthCode(client_info, 378 gaia_oauth_client_->GetTokensFromAuthCode(client_info,
365 client->robot_api_auth_code(), 379 client->robot_api_auth_code(),
366 0 /* max_retries */, 380 0 /* max_retries */,
367 this); 381 this);
368 } 382 }
369 383
370 // GaiaOAuthClient::Delegate callback for OAuth2 refresh token fetched. 384 // GaiaOAuthClient::Delegate callback for OAuth2 refresh token fetched.
371 void EnrollmentHandlerChromeOS::OnGetTokensResponse( 385 void EnrollmentHandlerChromeOS::OnGetTokensResponse(
372 const std::string& refresh_token, 386 const std::string& refresh_token,
373 const std::string& access_token, 387 const std::string& access_token,
374 int expires_in_seconds) { 388 int expires_in_seconds) {
375 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_); 389 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_);
376 390
377 robot_refresh_token_ = refresh_token; 391 robot_refresh_token_ = refresh_token;
378 392
379 SetStep(STEP_LOCK_DEVICE); 393 SetStep(STEP_AD_DOMAIN_JOIN);
380 StartLockDevice(); 394 StartJoinAdDomain();
381 } 395 }
382 396
383 // GaiaOAuthClient::Delegate 397 // GaiaOAuthClient::Delegate
384 void EnrollmentHandlerChromeOS::OnRefreshTokenResponse( 398 void EnrollmentHandlerChromeOS::OnRefreshTokenResponse(
385 const std::string& access_token, 399 const std::string& access_token,
386 int expires_in_seconds) { 400 int expires_in_seconds) {
387 // We never use the code that should trigger this callback. 401 // We never use the code that should trigger this callback.
388 LOG(FATAL) << "Unexpected callback invoked."; 402 LOG(FATAL) << "Unexpected callback invoked.";
389 } 403 }
390 404
391 // GaiaOAuthClient::Delegate OAuth2 error when fetching refresh token request. 405 // GaiaOAuthClient::Delegate OAuth2 error when fetching refresh token request.
392 void EnrollmentHandlerChromeOS::OnOAuthError() { 406 void EnrollmentHandlerChromeOS::OnOAuthError() {
393 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_); 407 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_);
394 // OnOAuthError is only called if the request is bad (malformed) or the 408 // OnOAuthError is only called if the request is bad (malformed) or the
395 // response is bad (empty access token returned). 409 // response is bad (empty access token returned).
396 LOG(ERROR) << "OAuth protocol error while fetching API refresh token."; 410 LOG(ERROR) << "OAuth protocol error while fetching API refresh token.";
397 ReportResult( 411 ReportResult(
398 EnrollmentStatus::ForRobotRefreshFetchError(net::HTTP_BAD_REQUEST)); 412 EnrollmentStatus::ForRobotRefreshFetchError(net::HTTP_BAD_REQUEST));
399 } 413 }
400 414
401 // GaiaOAuthClient::Delegate network error when fetching refresh token. 415 // GaiaOAuthClient::Delegate network error when fetching refresh token.
402 void EnrollmentHandlerChromeOS::OnNetworkError(int response_code) { 416 void EnrollmentHandlerChromeOS::OnNetworkError(int response_code) {
403 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_); 417 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_);
404 LOG(ERROR) << "Network error while fetching API refresh token: " 418 LOG(ERROR) << "Network error while fetching API refresh token: "
405 << response_code; 419 << response_code;
406 ReportResult( 420 ReportResult(
407 EnrollmentStatus::ForRobotRefreshFetchError(response_code)); 421 EnrollmentStatus::ForRobotRefreshFetchError(response_code));
408 } 422 }
409 423
424 void EnrollmentHandlerChromeOS::StartJoinAdDomain() {
425 DCHECK_EQ(STEP_AD_DOMAIN_JOIN, enrollment_step_);
426 if (device_mode_ != DEVICE_MODE_ENTERPRISE_AD) {
427 SetStep(STEP_LOCK_DEVICE);
428 StartLockDevice();
429 return;
430 }
431 ad_join_delegate_->JoinDomain(
432 base::BindOnce(&EnrollmentHandlerChromeOS::OnAdDomainJoined,
433 weak_ptr_factory_.GetWeakPtr()));
434 }
435
436 void EnrollmentHandlerChromeOS::OnAdDomainJoined(const std::string& realm) {
437 DCHECK_EQ(STEP_AD_DOMAIN_JOIN, enrollment_step_);
438 CHECK(!realm.empty());
439 realm_ = realm;
440 SetStep(STEP_LOCK_DEVICE);
441 StartLockDevice();
442 }
443
410 void EnrollmentHandlerChromeOS::StartLockDevice() { 444 void EnrollmentHandlerChromeOS::StartLockDevice() {
411 DCHECK_EQ(STEP_LOCK_DEVICE, enrollment_step_); 445 DCHECK_EQ(STEP_LOCK_DEVICE, enrollment_step_);
412 // Since this method is also called directly. 446 // Since this method is also called directly.
413 weak_ptr_factory_.InvalidateWeakPtrs(); 447 weak_ptr_factory_.InvalidateWeakPtrs();
414 448
415 install_attributes_->LockDevice( 449 install_attributes_->LockDevice(
416 device_mode_, domain_, enrollment_config_.management_realm, device_id_, 450 device_mode_, domain_, realm_, device_id_,
417 base::Bind(&EnrollmentHandlerChromeOS::HandleLockDeviceResult, 451 base::Bind(&EnrollmentHandlerChromeOS::HandleLockDeviceResult,
418 weak_ptr_factory_.GetWeakPtr())); 452 weak_ptr_factory_.GetWeakPtr()));
419 } 453 }
420 454
421 void EnrollmentHandlerChromeOS::HandleDMTokenStoreResult(bool success) { 455 void EnrollmentHandlerChromeOS::HandleDMTokenStoreResult(bool success) {
422 CHECK_EQ(STEP_STORE_TOKEN, enrollment_step_); 456 CHECK_EQ(STEP_STORE_TOKEN, enrollment_step_);
423 if (!success) { 457 if (!success) {
424 ReportResult( 458 ReportResult(
425 EnrollmentStatus::ForStatus(EnrollmentStatus::DM_TOKEN_STORE_FAILED)); 459 EnrollmentStatus::ForStatus(EnrollmentStatus::DM_TOKEN_STORE_FAILED));
426 return; 460 return;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 callback.Run(status); 595 callback.Run(status);
562 } 596 }
563 597
564 void EnrollmentHandlerChromeOS::SetStep(EnrollmentStep step) { 598 void EnrollmentHandlerChromeOS::SetStep(EnrollmentStep step) {
565 DCHECK_LE(enrollment_step_, step); 599 DCHECK_LE(enrollment_step_, step);
566 VLOG(1) << "Step: " << step; 600 VLOG(1) << "Step: " << step;
567 enrollment_step_ = step; 601 enrollment_step_ = step;
568 } 602 }
569 603
570 } // namespace policy 604 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698