Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/login/enrollment/auto_enrollment_controller.h" | 5 #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 13 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 14 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" | 14 #include "chrome/browser/chromeos/policy/server_backed_state_keys_broker.h" |
| 15 #include "chromeos/chromeos_switches.h" | 15 #include "chromeos/chromeos_switches.h" |
| 16 #include "chromeos/dbus/cryptohome/rpc.pb.h" | |
| 17 #include "chromeos/dbus/cryptohome_client.h" | |
| 18 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 16 #include "chromeos/system/statistics_provider.h" | 19 #include "chromeos/system/statistics_provider.h" |
| 17 #include "components/policy/core/common/cloud/device_management_service.h" | 20 #include "components/policy/core/common/cloud/device_management_service.h" |
| 18 #include "net/url_request/url_request_context_getter.h" | 21 #include "net/url_request/url_request_context_getter.h" |
| 19 | 22 |
| 20 namespace chromeos { | 23 namespace chromeos { |
| 21 | 24 |
| 22 namespace { | 25 namespace { |
| 23 | 26 |
| 24 // Maximum time to wait before forcing a decision. Note that download time for | 27 // Maximum time to wait before forcing a decision. Note that download time for |
| 25 // state key buckets can be non-negligible, especially on 2G connections. | 28 // state key buckets can be non-negligible, especially on 2G connections. |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 } else if (command_line_mode == kForcedReEnrollmentNever) { | 130 } else if (command_line_mode == kForcedReEnrollmentNever) { |
| 128 return MODE_NONE; | 131 return MODE_NONE; |
| 129 } | 132 } |
| 130 | 133 |
| 131 LOG(FATAL) << "Unknown auto-enrollment mode " << command_line_mode; | 134 LOG(FATAL) << "Unknown auto-enrollment mode " << command_line_mode; |
| 132 return MODE_NONE; | 135 return MODE_NONE; |
| 133 } | 136 } |
| 134 | 137 |
| 135 AutoEnrollmentController::AutoEnrollmentController() | 138 AutoEnrollmentController::AutoEnrollmentController() |
| 136 : state_(policy::AUTO_ENROLLMENT_STATE_IDLE), | 139 : state_(policy::AUTO_ENROLLMENT_STATE_IDLE), |
| 137 safeguard_timer_(false, false), | 140 safeguard_timer_(false, false) {} |
|
Thiemo Nagel
2017/03/29 16:09:40
Nit: For consistency, I'd suggest to move the othe
igorcov
2017/03/29 16:35:03
Done.
| |
| 138 client_start_weak_factory_(this) {} | |
| 139 | 141 |
| 140 AutoEnrollmentController::~AutoEnrollmentController() {} | 142 AutoEnrollmentController::~AutoEnrollmentController() {} |
| 141 | 143 |
| 142 void AutoEnrollmentController::Start() { | 144 void AutoEnrollmentController::Start() { |
| 143 // This method is called at the point in the OOBE/login flow at which the | 145 // This method is called at the point in the OOBE/login flow at which the |
| 144 // auto-enrollment check can start. This happens either after the EULA is | 146 // auto-enrollment check can start. This happens either after the EULA is |
| 145 // accepted, or right after a reboot if the EULA has already been accepted. | 147 // accepted, or right after a reboot if the EULA has already been accepted. |
| 146 | 148 |
| 147 // Skip if GAIA is disabled or modulus configuration is not present. | 149 // Skip if GAIA is disabled or modulus configuration is not present. |
| 148 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 150 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 171 return; | 173 return; |
| 172 } | 174 } |
| 173 | 175 |
| 174 // If a client is being created or already existing, bail out. | 176 // If a client is being created or already existing, bail out. |
| 175 if (client_start_weak_factory_.HasWeakPtrs() || client_) { | 177 if (client_start_weak_factory_.HasWeakPtrs() || client_) { |
| 176 LOG(ERROR) << "Auto-enrollment client is already running."; | 178 LOG(ERROR) << "Auto-enrollment client is already running."; |
| 177 return; | 179 return; |
| 178 } | 180 } |
| 179 | 181 |
| 180 // Arm the belts-and-suspenders timer to avoid hangs. | 182 // Arm the belts-and-suspenders timer to avoid hangs. |
| 181 safeguard_timer_.Start( | 183 safeguard_timer_.Start(FROM_HERE, |
| 182 FROM_HERE, base::TimeDelta::FromSeconds(kSafeguardTimeoutSeconds), | 184 base::TimeDelta::FromSeconds(kSafeguardTimeoutSeconds), |
| 183 base::Bind(&AutoEnrollmentController::Timeout, base::Unretained(this))); | 185 base::Bind(&AutoEnrollmentController::Timeout, |
| 186 weak_ptr_factory_.GetWeakPtr())); | |
| 184 | 187 |
| 185 // Start by checking if the device has already been owned. | 188 // Start by checking if the device has already been owned. |
| 186 UpdateState(policy::AUTO_ENROLLMENT_STATE_PENDING); | 189 UpdateState(policy::AUTO_ENROLLMENT_STATE_PENDING); |
| 187 DeviceSettingsService::Get()->GetOwnershipStatusAsync( | 190 DeviceSettingsService::Get()->GetOwnershipStatusAsync( |
| 188 base::Bind(&AutoEnrollmentController::OnOwnershipStatusCheckDone, | 191 base::Bind(&AutoEnrollmentController::OnOwnershipStatusCheckDone, |
| 189 client_start_weak_factory_.GetWeakPtr())); | 192 client_start_weak_factory_.GetWeakPtr())); |
| 190 } | 193 } |
| 191 | 194 |
| 192 void AutoEnrollmentController::Cancel() { | 195 void AutoEnrollmentController::Cancel() { |
| 193 if (client_) { | 196 if (client_) { |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 int power_initial = GetSanitizedArg( | 265 int power_initial = GetSanitizedArg( |
| 263 chromeos::switches::kEnterpriseEnrollmentInitialModulus); | 266 chromeos::switches::kEnterpriseEnrollmentInitialModulus); |
| 264 int power_limit = GetSanitizedArg( | 267 int power_limit = GetSanitizedArg( |
| 265 chromeos::switches::kEnterpriseEnrollmentModulusLimit); | 268 chromeos::switches::kEnterpriseEnrollmentModulusLimit); |
| 266 if (power_initial > power_limit) { | 269 if (power_initial > power_limit) { |
| 267 LOG(ERROR) << "Initial auto-enrollment modulus is larger than the limit, " | 270 LOG(ERROR) << "Initial auto-enrollment modulus is larger than the limit, " |
| 268 "clamping to the limit."; | 271 "clamping to the limit."; |
| 269 power_initial = power_limit; | 272 power_initial = power_limit; |
| 270 } | 273 } |
| 271 | 274 |
| 272 client_.reset(new policy::AutoEnrollmentClient( | 275 client_ = base::MakeUnique<policy::AutoEnrollmentClient>( |
| 273 base::Bind(&AutoEnrollmentController::UpdateState, | 276 base::Bind(&AutoEnrollmentController::UpdateState, |
| 274 base::Unretained(this)), | 277 weak_ptr_factory_.GetWeakPtr()), |
| 275 service, | 278 service, g_browser_process->local_state(), |
| 276 g_browser_process->local_state(), | 279 g_browser_process->system_request_context(), state_keys.front(), |
| 277 g_browser_process->system_request_context(), | 280 power_initial, power_limit); |
| 278 state_keys.front(), | |
| 279 power_initial, | |
| 280 power_limit)); | |
| 281 | 281 |
| 282 VLOG(1) << "Starting auto-enrollment client."; | 282 VLOG(1) << "Starting auto-enrollment client."; |
| 283 client_->Start(); | 283 client_->Start(); |
| 284 } | 284 } |
| 285 | 285 |
| 286 void AutoEnrollmentController::UpdateState( | 286 void AutoEnrollmentController::UpdateState( |
| 287 policy::AutoEnrollmentState new_state) { | 287 policy::AutoEnrollmentState new_state) { |
| 288 VLOG(1) << "New auto-enrollment state: " << new_state; | 288 VLOG(1) << "New auto-enrollment state: " << new_state; |
| 289 state_ = new_state; | 289 state_ = new_state; |
| 290 | 290 |
| 291 // Stop the safeguard timer once a result comes in. | 291 // Stop the safeguard timer once a result comes in. |
| 292 switch (state_) { | 292 switch (state_) { |
| 293 case policy::AUTO_ENROLLMENT_STATE_IDLE: | 293 case policy::AUTO_ENROLLMENT_STATE_IDLE: |
| 294 case policy::AUTO_ENROLLMENT_STATE_PENDING: | 294 case policy::AUTO_ENROLLMENT_STATE_PENDING: |
| 295 break; | 295 break; |
| 296 case policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR: | 296 case policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR: |
| 297 case policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR: | 297 case policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR: |
| 298 case policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT: | 298 case policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT: |
| 299 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT: | 299 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT: |
| 300 safeguard_timer_.Stop(); | 300 safeguard_timer_.Stop(); |
| 301 break; | 301 break; |
| 302 } | 302 } |
| 303 | 303 |
| 304 if (state_ == policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT) { | |
| 305 StartRemoveFirmwareManagementParameters(); | |
| 306 } else { | |
| 307 progress_callbacks_.Notify(state_); | |
| 308 } | |
| 309 } | |
| 310 | |
| 311 void AutoEnrollmentController::StartRemoveFirmwareManagementParameters() { | |
| 312 DCHECK_EQ(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT, state_); | |
| 313 | |
| 314 cryptohome::RemoveFirmwareManagementParametersRequest request; | |
| 315 chromeos::DBusThreadManager::Get() | |
| 316 ->GetCryptohomeClient() | |
| 317 ->RemoveFirmwareManagementParametersFromTpm( | |
| 318 request, | |
| 319 base::Bind( | |
| 320 &AutoEnrollmentController::OnFirmwareManagementParametersRemoved, | |
| 321 weak_ptr_factory_.GetWeakPtr())); | |
| 322 } | |
| 323 | |
| 324 void AutoEnrollmentController::OnFirmwareManagementParametersRemoved( | |
| 325 chromeos::DBusMethodCallStatus call_status, | |
| 326 bool result, | |
| 327 const cryptohome::BaseReply& reply) { | |
| 328 if (!result) { | |
| 329 LOG(ERROR) << "Failed to remove firmware management parameters, error: " | |
| 330 << reply.error(); | |
| 331 } | |
| 332 | |
| 304 progress_callbacks_.Notify(state_); | 333 progress_callbacks_.Notify(state_); |
| 305 } | 334 } |
| 306 | 335 |
| 307 void AutoEnrollmentController::Timeout() { | 336 void AutoEnrollmentController::Timeout() { |
| 308 // TODO(mnissler): Add UMA to track results of auto-enrollment checks. | 337 // TODO(mnissler): Add UMA to track results of auto-enrollment checks. |
| 309 if (client_start_weak_factory_.HasWeakPtrs() && | 338 if (client_start_weak_factory_.HasWeakPtrs() && |
| 310 fre_requirement_ != EXPLICITLY_REQUIRED) { | 339 fre_requirement_ != EXPLICITLY_REQUIRED) { |
| 311 // If the callbacks to check ownership status or state keys are still | 340 // If the callbacks to check ownership status or state keys are still |
| 312 // pending, there's a bug in the code running on the device. No use in | 341 // pending, there's a bug in the code running on the device. No use in |
| 313 // retrying anything, need to fix that bug. | 342 // retrying anything, need to fix that bug. |
| 314 LOG(ERROR) << "Failed to start auto-enrollment check, fix the code!"; | 343 LOG(ERROR) << "Failed to start auto-enrollment check, fix the code!"; |
| 315 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); | 344 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); |
| 316 } else { | 345 } else { |
| 317 // This can actually happen in some cases, for example when state key | 346 // This can actually happen in some cases, for example when state key |
| 318 // generation is waiting for time sync or the server just doesn't reply and | 347 // generation is waiting for time sync or the server just doesn't reply and |
| 319 // keeps the connection open. | 348 // keeps the connection open. |
| 320 LOG(ERROR) << "AutoEnrollmentClient didn't complete within time limit."; | 349 LOG(ERROR) << "AutoEnrollmentClient didn't complete within time limit."; |
| 321 UpdateState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR); | 350 UpdateState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR); |
| 322 } | 351 } |
| 323 | 352 |
| 324 // Reset state. | 353 // Reset state. |
| 325 Cancel(); | 354 Cancel(); |
| 326 } | 355 } |
| 327 | 356 |
| 328 } // namespace chromeos | 357 } // namespace chromeos |
| OLD | NEW |