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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 137 safeguard_timer_(false, false), | 140 safeguard_timer_(false, false), |
| 138 client_start_weak_factory_(this) {} | 141 client_start_weak_factory_(this) {} |
| 139 | 142 |
| 140 AutoEnrollmentController::~AutoEnrollmentController() {} | 143 AutoEnrollmentController::~AutoEnrollmentController() {} |
| 141 | 144 |
| 142 void AutoEnrollmentController::Start() { | 145 void AutoEnrollmentController::Start() { |
| 143 // This method is called at the point in the OOBE/login flow at which the | 146 // 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 | 147 // 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. | 148 // accepted, or right after a reboot if the EULA has already been accepted. |
| 146 | 149 |
| 150 // If a client is being created or already existing, bail out. | |
|
Daniel Erat
2017/03/09 22:15:22
i'm not familiar with this code, but can you updat
igorcov
2017/03/10 11:05:44
Updated the CL description. Basically this change
| |
| 151 if (client_start_weak_factory_.HasWeakPtrs() || client_) { | |
| 152 LOG(ERROR) << "Auto-enrollment client is already running."; | |
| 153 return; | |
| 154 } | |
| 155 | |
| 156 // Arm the belts-and-suspenders timer to avoid hangs. | |
| 157 safeguard_timer_.Start( | |
| 158 FROM_HERE, base::TimeDelta::FromSeconds(kSafeguardTimeoutSeconds), | |
| 159 base::Bind(&AutoEnrollmentController::Timeout, base::Unretained(this))); | |
| 160 | |
| 147 // Skip if GAIA is disabled or modulus configuration is not present. | 161 // Skip if GAIA is disabled or modulus configuration is not present. |
| 148 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 162 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 149 if (command_line->HasSwitch(chromeos::switches::kDisableGaiaServices) || | 163 if (command_line->HasSwitch(chromeos::switches::kDisableGaiaServices) || |
| 150 (!command_line->HasSwitch( | 164 (!command_line->HasSwitch( |
| 151 chromeos::switches::kEnterpriseEnrollmentInitialModulus) && | 165 chromeos::switches::kEnterpriseEnrollmentInitialModulus) && |
| 152 !command_line->HasSwitch( | 166 !command_line->HasSwitch( |
| 153 chromeos::switches::kEnterpriseEnrollmentModulusLimit))) { | 167 chromeos::switches::kEnterpriseEnrollmentModulusLimit))) { |
| 154 VLOG(1) << "Auto-enrollment disabled: command line."; | 168 VLOG(1) << "Auto-enrollment disabled: command line."; |
| 155 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); | 169 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); |
| 156 return; | 170 return; |
| 157 } | 171 } |
| 158 | 172 |
| 159 // Skip if mode comes up as none. | 173 // Skip if mode comes up as none. |
| 160 if (GetMode() == MODE_NONE) { | 174 if (GetMode() == MODE_NONE) { |
| 161 VLOG(1) << "Auto-enrollment disabled: no mode."; | 175 VLOG(1) << "Auto-enrollment disabled: no mode."; |
| 162 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); | 176 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); |
| 163 return; | 177 return; |
| 164 } | 178 } |
| 165 | 179 |
| 166 fre_requirement_ = GetFRERequirement(); | 180 fre_requirement_ = GetFRERequirement(); |
| 167 VLOG(1) << FRERequirementToString(fre_requirement_); | 181 VLOG(1) << FRERequirementToString(fre_requirement_); |
| 168 if (fre_requirement_ == EXPLICITLY_NOT_REQUIRED || | 182 if (fre_requirement_ == EXPLICITLY_NOT_REQUIRED || |
| 169 fre_requirement_ == NOT_REQUIRED) { | 183 fre_requirement_ == NOT_REQUIRED) { |
| 170 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); | 184 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); |
| 171 return; | 185 return; |
| 172 } | 186 } |
| 173 | 187 |
| 174 // If a client is being created or already existing, bail out. | |
| 175 if (client_start_weak_factory_.HasWeakPtrs() || client_) { | |
| 176 LOG(ERROR) << "Auto-enrollment client is already running."; | |
| 177 return; | |
| 178 } | |
| 179 | |
| 180 // Arm the belts-and-suspenders timer to avoid hangs. | |
| 181 safeguard_timer_.Start( | |
| 182 FROM_HERE, base::TimeDelta::FromSeconds(kSafeguardTimeoutSeconds), | |
| 183 base::Bind(&AutoEnrollmentController::Timeout, base::Unretained(this))); | |
| 184 | |
| 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_) { |
| 194 // Cancelling the |client_| allows it to determine whether | 197 // Cancelling the |client_| allows it to determine whether |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 state_ = new_state; | 287 state_ = new_state; |
| 285 | 288 |
| 286 // Stop the safeguard timer once a result comes in. | 289 // Stop the safeguard timer once a result comes in. |
| 287 switch (state_) { | 290 switch (state_) { |
| 288 case policy::AUTO_ENROLLMENT_STATE_IDLE: | 291 case policy::AUTO_ENROLLMENT_STATE_IDLE: |
| 289 case policy::AUTO_ENROLLMENT_STATE_PENDING: | 292 case policy::AUTO_ENROLLMENT_STATE_PENDING: |
| 290 break; | 293 break; |
| 291 case policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR: | 294 case policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR: |
| 292 case policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR: | 295 case policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR: |
| 293 case policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT: | 296 case policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT: |
| 294 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT: | |
| 295 safeguard_timer_.Stop(); | 297 safeguard_timer_.Stop(); |
| 296 break; | 298 break; |
| 299 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT: | |
| 300 RemoveFirmwareManagementParameters(); | |
| 301 return; | |
| 297 } | 302 } |
| 298 | 303 |
| 299 progress_callbacks_.Notify(state_); | 304 progress_callbacks_.Notify(state_); |
| 300 } | 305 } |
| 301 | 306 |
| 307 void AutoEnrollmentController::RemoveFirmwareManagementParameters() { | |
| 308 DCHECK_EQ(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT, state_); | |
| 309 | |
| 310 cryptohome::RemoveFirmwareManagementParametersRequest request; | |
| 311 chromeos::DBusThreadManager::Get() | |
| 312 ->GetCryptohomeClient() | |
| 313 ->RemoveFirmwareManagementParametersInTpm( | |
| 314 request, | |
| 315 base::Bind( | |
| 316 &AutoEnrollmentController::OnFirmwareManagementParametersRemoved, | |
| 317 client_start_weak_factory_.GetWeakPtr())); | |
| 318 } | |
| 319 | |
| 320 void AutoEnrollmentController::OnFirmwareManagementParametersRemoved( | |
| 321 chromeos::DBusMethodCallStatus call_status, | |
| 322 bool result, | |
| 323 const cryptohome::BaseReply& reply) { | |
| 324 if (!result) | |
| 325 LOG(ERROR) << "Failed to remove firmware management parameters, error: " | |
|
Daniel Erat
2017/03/09 22:15:22
the style guide requires curly brackets around mul
igorcov
2017/03/10 11:05:44
Done.
| |
| 326 << reply.error(); | |
| 327 | |
| 328 if (safeguard_timer_.IsRunning()) { | |
| 329 safeguard_timer_.Stop(); | |
| 330 progress_callbacks_.Notify(state_); | |
| 331 } | |
| 332 } | |
| 333 | |
| 302 void AutoEnrollmentController::Timeout() { | 334 void AutoEnrollmentController::Timeout() { |
| 303 // TODO(mnissler): Add UMA to track results of auto-enrollment checks. | 335 // TODO(mnissler): Add UMA to track results of auto-enrollment checks. |
| 304 if (client_start_weak_factory_.HasWeakPtrs() && | 336 if (client_start_weak_factory_.HasWeakPtrs() && |
| 305 fre_requirement_ != EXPLICITLY_REQUIRED) { | 337 fre_requirement_ != EXPLICITLY_REQUIRED) { |
| 306 // If the callbacks to check ownership status or state keys are still | 338 // 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 | 339 // pending, there's a bug in the code running on the device. No use in |
| 308 // retrying anything, need to fix that bug. | 340 // retrying anything, need to fix that bug. |
| 309 LOG(ERROR) << "Failed to start auto-enrollment check, fix the code!"; | 341 LOG(ERROR) << "Failed to start auto-enrollment check, fix the code!"; |
| 310 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); | 342 state_ = policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT; |
| 311 } else { | 343 } else { |
| 312 // This can actually happen in some cases, for example when state key | 344 // 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 | 345 // generation is waiting for time sync or the server just doesn't reply and |
| 314 // keeps the connection open. | 346 // keeps the connection open. |
| 315 LOG(ERROR) << "AutoEnrollmentClient didn't complete within time limit."; | 347 LOG(ERROR) << "AutoEnrollmentClient didn't complete within time limit."; |
| 316 UpdateState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR); | 348 state_ = policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR; |
| 317 } | 349 } |
| 318 | 350 |
| 351 safeguard_timer_.Stop(); | |
| 352 progress_callbacks_.Notify(state_); | |
| 353 | |
| 319 // Reset state. | 354 // Reset state. |
| 320 Cancel(); | 355 Cancel(); |
| 321 } | 356 } |
| 322 | 357 |
| 323 } // namespace chromeos | 358 } // namespace chromeos |
| OLD | NEW |