| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return MODE_NONE; | 128 return MODE_NONE; |
| 126 #endif | 129 #endif |
| 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), | |
| 137 safeguard_timer_(false, false), | |
| 138 client_start_weak_factory_(this) {} | |
| 139 | 139 |
| 140 AutoEnrollmentController::~AutoEnrollmentController() {} | 140 AutoEnrollmentController::~AutoEnrollmentController() {} |
| 141 | 141 |
| 142 void AutoEnrollmentController::Start() { | 142 void AutoEnrollmentController::Start() { |
| 143 // This method is called at the point in the OOBE/login flow at which the | 143 // 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 | 144 // 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. | 145 // accepted, or right after a reboot if the EULA has already been accepted. |
| 146 | 146 |
| 147 // Skip if GAIA is disabled or modulus configuration is not present. | 147 // Skip if GAIA is disabled or modulus configuration is not present. |
| 148 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 148 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 171 return; | 171 return; |
| 172 } | 172 } |
| 173 | 173 |
| 174 // If a client is being created or already existing, bail out. | 174 // If a client is being created or already existing, bail out. |
| 175 if (client_start_weak_factory_.HasWeakPtrs() || client_) { | 175 if (client_start_weak_factory_.HasWeakPtrs() || client_) { |
| 176 LOG(ERROR) << "Auto-enrollment client is already running."; | 176 LOG(ERROR) << "Auto-enrollment client is already running."; |
| 177 return; | 177 return; |
| 178 } | 178 } |
| 179 | 179 |
| 180 // Arm the belts-and-suspenders timer to avoid hangs. | 180 // Arm the belts-and-suspenders timer to avoid hangs. |
| 181 safeguard_timer_.Start( | 181 safeguard_timer_.Start(FROM_HERE, |
| 182 FROM_HERE, base::TimeDelta::FromSeconds(kSafeguardTimeoutSeconds), | 182 base::TimeDelta::FromSeconds(kSafeguardTimeoutSeconds), |
| 183 base::Bind(&AutoEnrollmentController::Timeout, base::Unretained(this))); | 183 base::Bind(&AutoEnrollmentController::Timeout, |
| 184 weak_ptr_factory_.GetWeakPtr())); |
| 184 | 185 |
| 185 // Start by checking if the device has already been owned. | 186 // Start by checking if the device has already been owned. |
| 186 UpdateState(policy::AUTO_ENROLLMENT_STATE_PENDING); | 187 UpdateState(policy::AUTO_ENROLLMENT_STATE_PENDING); |
| 187 DeviceSettingsService::Get()->GetOwnershipStatusAsync( | 188 DeviceSettingsService::Get()->GetOwnershipStatusAsync( |
| 188 base::Bind(&AutoEnrollmentController::OnOwnershipStatusCheckDone, | 189 base::Bind(&AutoEnrollmentController::OnOwnershipStatusCheckDone, |
| 189 client_start_weak_factory_.GetWeakPtr())); | 190 client_start_weak_factory_.GetWeakPtr())); |
| 190 } | 191 } |
| 191 | 192 |
| 192 void AutoEnrollmentController::Cancel() { | 193 void AutoEnrollmentController::Cancel() { |
| 193 if (client_) { | 194 if (client_) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 int power_initial = GetSanitizedArg( | 258 int power_initial = GetSanitizedArg( |
| 258 chromeos::switches::kEnterpriseEnrollmentInitialModulus); | 259 chromeos::switches::kEnterpriseEnrollmentInitialModulus); |
| 259 int power_limit = GetSanitizedArg( | 260 int power_limit = GetSanitizedArg( |
| 260 chromeos::switches::kEnterpriseEnrollmentModulusLimit); | 261 chromeos::switches::kEnterpriseEnrollmentModulusLimit); |
| 261 if (power_initial > power_limit) { | 262 if (power_initial > power_limit) { |
| 262 LOG(ERROR) << "Initial auto-enrollment modulus is larger than the limit, " | 263 LOG(ERROR) << "Initial auto-enrollment modulus is larger than the limit, " |
| 263 "clamping to the limit."; | 264 "clamping to the limit."; |
| 264 power_initial = power_limit; | 265 power_initial = power_limit; |
| 265 } | 266 } |
| 266 | 267 |
| 267 client_.reset(new policy::AutoEnrollmentClient( | 268 client_ = base::MakeUnique<policy::AutoEnrollmentClient>( |
| 268 base::Bind(&AutoEnrollmentController::UpdateState, | 269 base::Bind(&AutoEnrollmentController::UpdateState, |
| 269 base::Unretained(this)), | 270 weak_ptr_factory_.GetWeakPtr()), |
| 270 service, | 271 service, g_browser_process->local_state(), |
| 271 g_browser_process->local_state(), | 272 g_browser_process->system_request_context(), state_keys.front(), |
| 272 g_browser_process->system_request_context(), | 273 power_initial, power_limit); |
| 273 state_keys.front(), | |
| 274 power_initial, | |
| 275 power_limit)); | |
| 276 | 274 |
| 277 VLOG(1) << "Starting auto-enrollment client."; | 275 VLOG(1) << "Starting auto-enrollment client."; |
| 278 client_->Start(); | 276 client_->Start(); |
| 279 } | 277 } |
| 280 | 278 |
| 281 void AutoEnrollmentController::UpdateState( | 279 void AutoEnrollmentController::UpdateState( |
| 282 policy::AutoEnrollmentState new_state) { | 280 policy::AutoEnrollmentState new_state) { |
| 283 VLOG(1) << "New auto-enrollment state: " << new_state; | 281 VLOG(1) << "New auto-enrollment state: " << new_state; |
| 284 state_ = new_state; | 282 state_ = new_state; |
| 285 | 283 |
| 286 // Stop the safeguard timer once a result comes in. | 284 // Stop the safeguard timer once a result comes in. |
| 287 switch (state_) { | 285 switch (state_) { |
| 288 case policy::AUTO_ENROLLMENT_STATE_IDLE: | 286 case policy::AUTO_ENROLLMENT_STATE_IDLE: |
| 289 case policy::AUTO_ENROLLMENT_STATE_PENDING: | 287 case policy::AUTO_ENROLLMENT_STATE_PENDING: |
| 290 break; | 288 break; |
| 291 case policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR: | 289 case policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR: |
| 292 case policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR: | 290 case policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR: |
| 293 case policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT: | 291 case policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT: |
| 294 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT: | 292 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT: |
| 295 safeguard_timer_.Stop(); | 293 safeguard_timer_.Stop(); |
| 296 break; | 294 break; |
| 297 } | 295 } |
| 298 | 296 |
| 297 if (state_ == policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT) { |
| 298 StartRemoveFirmwareManagementParameters(); |
| 299 } else { |
| 300 progress_callbacks_.Notify(state_); |
| 301 } |
| 302 } |
| 303 |
| 304 void AutoEnrollmentController::StartRemoveFirmwareManagementParameters() { |
| 305 DCHECK_EQ(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT, state_); |
| 306 |
| 307 cryptohome::RemoveFirmwareManagementParametersRequest request; |
| 308 chromeos::DBusThreadManager::Get() |
| 309 ->GetCryptohomeClient() |
| 310 ->RemoveFirmwareManagementParametersFromTpm( |
| 311 request, |
| 312 base::Bind( |
| 313 &AutoEnrollmentController::OnFirmwareManagementParametersRemoved, |
| 314 weak_ptr_factory_.GetWeakPtr())); |
| 315 } |
| 316 |
| 317 void AutoEnrollmentController::OnFirmwareManagementParametersRemoved( |
| 318 chromeos::DBusMethodCallStatus call_status, |
| 319 bool result, |
| 320 const cryptohome::BaseReply& reply) { |
| 321 if (!result) { |
| 322 LOG(ERROR) << "Failed to remove firmware management parameters, error: " |
| 323 << reply.error(); |
| 324 } |
| 325 |
| 299 progress_callbacks_.Notify(state_); | 326 progress_callbacks_.Notify(state_); |
| 300 } | 327 } |
| 301 | 328 |
| 302 void AutoEnrollmentController::Timeout() { | 329 void AutoEnrollmentController::Timeout() { |
| 303 // TODO(mnissler): Add UMA to track results of auto-enrollment checks. | 330 // TODO(mnissler): Add UMA to track results of auto-enrollment checks. |
| 304 if (client_start_weak_factory_.HasWeakPtrs() && | 331 if (client_start_weak_factory_.HasWeakPtrs() && |
| 305 fre_requirement_ != EXPLICITLY_REQUIRED) { | 332 fre_requirement_ != EXPLICITLY_REQUIRED) { |
| 306 // If the callbacks to check ownership status or state keys are still | 333 // If the callbacks to check ownership status or state keys are still |
| 307 // pending, there's a bug in the code running on the device. No use in | 334 // pending, there's a bug in the code running on the device. No use in |
| 308 // retrying anything, need to fix that bug. | 335 // retrying anything, need to fix that bug. |
| 309 LOG(ERROR) << "Failed to start auto-enrollment check, fix the code!"; | 336 LOG(ERROR) << "Failed to start auto-enrollment check, fix the code!"; |
| 310 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); | 337 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); |
| 311 } else { | 338 } else { |
| 312 // This can actually happen in some cases, for example when state key | 339 // This can actually happen in some cases, for example when state key |
| 313 // generation is waiting for time sync or the server just doesn't reply and | 340 // generation is waiting for time sync or the server just doesn't reply and |
| 314 // keeps the connection open. | 341 // keeps the connection open. |
| 315 LOG(ERROR) << "AutoEnrollmentClient didn't complete within time limit."; | 342 LOG(ERROR) << "AutoEnrollmentClient didn't complete within time limit."; |
| 316 UpdateState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR); | 343 UpdateState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR); |
| 317 } | 344 } |
| 318 | 345 |
| 319 // Reset state. | 346 // Reset state. |
| 320 Cancel(); | 347 Cancel(); |
| 321 } | 348 } |
| 322 | 349 |
| 323 } // namespace chromeos | 350 } // namespace chromeos |
| OLD | NEW |