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