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

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: 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/login/enrollment/enrollment_screen_actor.h"
18 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
17 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" 19 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h"
18 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" 20 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h"
19 #include "chrome/browser/chromeos/policy/dm_token_storage.h" 21 #include "chrome/browser/chromeos/policy/dm_token_storage.h"
20 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" 22 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h"
21 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" 23 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
22 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" 24 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h"
23 #include "chrome/browser/chromeos/profiles/profile_helper.h" 25 #include "chrome/browser/chromeos/profiles/profile_helper.h"
24 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" 26 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h"
25 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h " 27 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
26 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
30 #include "chrome/common/channel_info.h"
27 #include "chromeos/attestation/attestation_flow.h" 31 #include "chromeos/attestation/attestation_flow.h"
28 #include "chromeos/chromeos_switches.h" 32 #include "chromeos/chromeos_switches.h"
29 #include "chromeos/dbus/auth_policy_client.h" 33 #include "chromeos/dbus/auth_policy_client.h"
30 #include "chromeos/dbus/dbus_thread_manager.h" 34 #include "chromeos/dbus/dbus_thread_manager.h"
35 #include "chromeos/dbus/upstart_client.h"
36 #include "components/version_info/version_info.h"
31 #include "google_apis/gaia/gaia_auth_util.h" 37 #include "google_apis/gaia/gaia_auth_util.h"
32 #include "google_apis/gaia/gaia_urls.h" 38 #include "google_apis/gaia/gaia_urls.h"
33 #include "net/http/http_status_code.h" 39 #include "net/http/http_status_code.h"
34 40
35 namespace em = enterprise_management; 41 namespace em = enterprise_management;
36 42
37 namespace policy { 43 namespace policy {
38 44
39 namespace { 45 namespace {
40 46
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 weak_ptr_factory_.GetWeakPtr())); 201 weak_ptr_factory_.GetWeakPtr()));
196 } 202 }
197 203
198 void EnrollmentHandlerChromeOS::OnRegistrationStateChanged( 204 void EnrollmentHandlerChromeOS::OnRegistrationStateChanged(
199 CloudPolicyClient* client) { 205 CloudPolicyClient* client) {
200 DCHECK_EQ(client_.get(), client); 206 DCHECK_EQ(client_.get(), client);
201 207
202 if (enrollment_step_ == STEP_REGISTRATION && client_->is_registered()) { 208 if (enrollment_step_ == STEP_REGISTRATION && client_->is_registered()) {
203 SetStep(STEP_POLICY_FETCH); 209 SetStep(STEP_POLICY_FETCH);
204 device_mode_ = client_->device_mode(); 210 device_mode_ = client_->device_mode();
205 if (!((device_mode_ == DEVICE_MODE_ENTERPRISE && 211 if (device_mode_ == DEVICE_MODE_ENTERPRISE_AD) {
206 enrollment_config_.management_realm.empty()) || 212 if (chrome::GetChannel() == version_info::Channel::BETA ||
207 (device_mode_ == DEVICE_MODE_ENTERPRISE_AD && 213 chrome::GetChannel() == version_info::Channel::STABLE) {
208 !enrollment_config_.management_realm.empty()))) { 214 LOG(ERROR) << "Bad device mode " << device_mode_;
achuithb 2017/02/07 20:27:16 This error message is unclear. This device mode sh
Roman Sorokin (ftl) 2017/02/10 14:57:10 Done.
215 ReportResult(EnrollmentStatus::ForStatus(
216 EnrollmentStatus::REGISTRATION_BAD_MODE));
217 return;
218 }
219 chromeos::DBusThreadManager::Get()
220 ->GetUpstartClient()
221 ->StartAuthPolicyService();
222 }
223 if (device_mode_ != DEVICE_MODE_ENTERPRISE &&
224 device_mode_ != DEVICE_MODE_ENTERPRISE_AD) {
209 LOG(ERROR) << "Bad device mode " << device_mode_; 225 LOG(ERROR) << "Bad device mode " << device_mode_;
achuithb 2017/02/07 20:27:16 Make this more explicit/clear too.
Roman Sorokin (ftl) 2017/02/10 14:57:10 Done.
210 ReportResult( 226 ReportResult(
211 EnrollmentStatus::ForStatus(EnrollmentStatus::REGISTRATION_BAD_MODE)); 227 EnrollmentStatus::ForStatus(EnrollmentStatus::REGISTRATION_BAD_MODE));
212 return; 228 return;
213 } 229 }
214 client_->FetchPolicy(); 230 client_->FetchPolicy();
215 } else { 231 } else {
216 LOG(FATAL) << "Registration state changed to " << client_->is_registered() 232 LOG(FATAL) << "Registration state changed to " << client_->is_registered()
217 << " in step " << enrollment_step_ << "."; 233 << " in step " << enrollment_step_ << ".";
218 } 234 }
219 } 235 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 void EnrollmentHandlerChromeOS::HandlePolicyValidationResult( 333 void EnrollmentHandlerChromeOS::HandlePolicyValidationResult(
318 DeviceCloudPolicyValidator* validator) { 334 DeviceCloudPolicyValidator* validator) {
319 DCHECK_EQ(STEP_VALIDATION, enrollment_step_); 335 DCHECK_EQ(STEP_VALIDATION, enrollment_step_);
320 if (validator->success()) { 336 if (validator->success()) {
321 std::string username = validator->policy_data()->username(); 337 std::string username = validator->policy_data()->username();
322 device_id_ = validator->policy_data()->device_id(); 338 device_id_ = validator->policy_data()->device_id();
323 policy_ = std::move(validator->policy()); 339 policy_ = std::move(validator->policy());
324 if (device_mode_ == DEVICE_MODE_ENTERPRISE_AD) { 340 if (device_mode_ == DEVICE_MODE_ENTERPRISE_AD) {
325 // Don't use robot account for the Active Directory managed devices. 341 // Don't use robot account for the Active Directory managed devices.
326 skip_robot_auth_ = true; 342 skip_robot_auth_ = true;
327 SetStep(STEP_LOCK_DEVICE); 343 SetStep(STEP_AD_DOMAIN_JOIN);
328 StartLockDevice(); 344 StartJoinAdDomain();
329 } else { 345 } else {
330 domain_ = gaia::ExtractDomainName(gaia::CanonicalizeEmail(username)); 346 domain_ = gaia::ExtractDomainName(gaia::CanonicalizeEmail(username));
331 SetStep(STEP_ROBOT_AUTH_FETCH); 347 SetStep(STEP_ROBOT_AUTH_FETCH);
332 client_->FetchRobotAuthCodes(auth_token_); 348 client_->FetchRobotAuthCodes(auth_token_);
333 } 349 }
334 } else { 350 } else {
335 ReportResult(EnrollmentStatus::ForValidationError(validator->status())); 351 ReportResult(EnrollmentStatus::ForValidationError(validator->status()));
336 } 352 }
337 } 353 }
338 354
339 void EnrollmentHandlerChromeOS::OnRobotAuthCodesFetched( 355 void EnrollmentHandlerChromeOS::OnRobotAuthCodesFetched(
340 CloudPolicyClient* client) { 356 CloudPolicyClient* client) {
341 DCHECK_EQ(client_.get(), client); 357 DCHECK_EQ(client_.get(), client);
342 CHECK_EQ(STEP_ROBOT_AUTH_FETCH, enrollment_step_); 358 CHECK_EQ(STEP_ROBOT_AUTH_FETCH, enrollment_step_);
343 359
344 if (client->robot_api_auth_code().empty()) { 360 if (client->robot_api_auth_code().empty()) {
345 // If the server doesn't provide an auth code, skip the robot auth setup. 361 // 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 362 // This allows clients running against the test server to transparently skip
347 // robot auth. 363 // robot auth.
348 skip_robot_auth_ = true; 364 skip_robot_auth_ = true;
349 SetStep(STEP_LOCK_DEVICE); 365 SetStep(STEP_AD_DOMAIN_JOIN);
350 StartLockDevice(); 366 StartJoinAdDomain();
351 return; 367 return;
352 } 368 }
353 369
354 SetStep(STEP_ROBOT_AUTH_REFRESH); 370 SetStep(STEP_ROBOT_AUTH_REFRESH);
355 gaia::OAuthClientInfo client_info; 371 gaia::OAuthClientInfo client_info;
356 client_info.client_id = GaiaUrls::GetInstance()->oauth2_chrome_client_id(); 372 client_info.client_id = GaiaUrls::GetInstance()->oauth2_chrome_client_id();
357 client_info.client_secret = 373 client_info.client_secret =
358 GaiaUrls::GetInstance()->oauth2_chrome_client_secret(); 374 GaiaUrls::GetInstance()->oauth2_chrome_client_secret();
359 client_info.redirect_uri = "oob"; 375 client_info.redirect_uri = "oob";
360 376
361 // Use the system request context to avoid sending user cookies. 377 // Use the system request context to avoid sending user cookies.
362 gaia_oauth_client_.reset(new gaia::GaiaOAuthClient( 378 gaia_oauth_client_.reset(new gaia::GaiaOAuthClient(
363 g_browser_process->system_request_context())); 379 g_browser_process->system_request_context()));
364 gaia_oauth_client_->GetTokensFromAuthCode(client_info, 380 gaia_oauth_client_->GetTokensFromAuthCode(client_info,
365 client->robot_api_auth_code(), 381 client->robot_api_auth_code(),
366 0 /* max_retries */, 382 0 /* max_retries */,
367 this); 383 this);
368 } 384 }
369 385
370 // GaiaOAuthClient::Delegate callback for OAuth2 refresh token fetched. 386 // GaiaOAuthClient::Delegate callback for OAuth2 refresh token fetched.
371 void EnrollmentHandlerChromeOS::OnGetTokensResponse( 387 void EnrollmentHandlerChromeOS::OnGetTokensResponse(
372 const std::string& refresh_token, 388 const std::string& refresh_token,
373 const std::string& access_token, 389 const std::string& access_token,
374 int expires_in_seconds) { 390 int expires_in_seconds) {
375 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_); 391 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_);
376 392
377 robot_refresh_token_ = refresh_token; 393 robot_refresh_token_ = refresh_token;
378 394
379 SetStep(STEP_LOCK_DEVICE); 395 SetStep(STEP_AD_DOMAIN_JOIN);
380 StartLockDevice(); 396 StartJoinAdDomain();
381 } 397 }
382 398
383 // GaiaOAuthClient::Delegate 399 // GaiaOAuthClient::Delegate
384 void EnrollmentHandlerChromeOS::OnRefreshTokenResponse( 400 void EnrollmentHandlerChromeOS::OnRefreshTokenResponse(
385 const std::string& access_token, 401 const std::string& access_token,
386 int expires_in_seconds) { 402 int expires_in_seconds) {
387 // We never use the code that should trigger this callback. 403 // We never use the code that should trigger this callback.
388 LOG(FATAL) << "Unexpected callback invoked."; 404 LOG(FATAL) << "Unexpected callback invoked.";
389 } 405 }
390 406
391 // GaiaOAuthClient::Delegate OAuth2 error when fetching refresh token request. 407 // GaiaOAuthClient::Delegate OAuth2 error when fetching refresh token request.
392 void EnrollmentHandlerChromeOS::OnOAuthError() { 408 void EnrollmentHandlerChromeOS::OnOAuthError() {
393 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_); 409 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_);
394 // OnOAuthError is only called if the request is bad (malformed) or the 410 // OnOAuthError is only called if the request is bad (malformed) or the
395 // response is bad (empty access token returned). 411 // response is bad (empty access token returned).
396 LOG(ERROR) << "OAuth protocol error while fetching API refresh token."; 412 LOG(ERROR) << "OAuth protocol error while fetching API refresh token.";
397 ReportResult( 413 ReportResult(
398 EnrollmentStatus::ForRobotRefreshFetchError(net::HTTP_BAD_REQUEST)); 414 EnrollmentStatus::ForRobotRefreshFetchError(net::HTTP_BAD_REQUEST));
399 } 415 }
400 416
401 // GaiaOAuthClient::Delegate network error when fetching refresh token. 417 // GaiaOAuthClient::Delegate network error when fetching refresh token.
402 void EnrollmentHandlerChromeOS::OnNetworkError(int response_code) { 418 void EnrollmentHandlerChromeOS::OnNetworkError(int response_code) {
403 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_); 419 CHECK_EQ(STEP_ROBOT_AUTH_REFRESH, enrollment_step_);
404 LOG(ERROR) << "Network error while fetching API refresh token: " 420 LOG(ERROR) << "Network error while fetching API refresh token: "
405 << response_code; 421 << response_code;
406 ReportResult( 422 ReportResult(
407 EnrollmentStatus::ForRobotRefreshFetchError(response_code)); 423 EnrollmentStatus::ForRobotRefreshFetchError(response_code));
408 } 424 }
409 425
426 void EnrollmentHandlerChromeOS::StartJoinAdDomain() {
427 DCHECK_EQ(STEP_AD_DOMAIN_JOIN, enrollment_step_);
428 if (device_mode_ != DEVICE_MODE_ENTERPRISE_AD) {
429 SetStep(STEP_LOCK_DEVICE);
430 StartLockDevice();
431 return;
432 }
433 chromeos::LoginDisplayHost::default_host()
434 ->GetOobeUI()
435 ->GetEnrollmentScreenActor()
Roman Sorokin (ftl) 2017/02/03 15:02:43 Not sure if it's a good way to start showing AD ui
achuithb 2017/02/07 20:27:16 Pretty sure it's not.
Roman Sorokin (ftl) 2017/02/07 21:41:05 You got any idea of a proper way to do that? Shoul
achuithb 2017/02/07 21:50:50 Off the top of my head, I don't; I'd have to resea
Roman Sorokin (ftl) 2017/02/10 14:57:10 Created ActiveDirectoryJoinDelegate
achuithb 2017/02/13 13:39:02 Acknowledged.
436 ->ShowAdJoin(base::BindOnce(&EnrollmentHandlerChromeOS::OnAdDomainJoined,
437 weak_ptr_factory_.GetWeakPtr()));
438 }
439
440 void EnrollmentHandlerChromeOS::OnAdDomainJoined(std::string realm) {
441 DCHECK_EQ(STEP_AD_DOMAIN_JOIN, enrollment_step_);
442 CHECK(!realm.empty());
443 realm_ = std::move(realm);
achuithb 2017/02/07 20:27:16 Why not realm_ = realm;
Roman Sorokin (ftl) 2017/02/10 14:57:10 Done.
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