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

Side by Side Diff: chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.cc

Issue 2727713003: Update FWMP in TPM (Closed)
Patch Set: Nits Created 3 years, 8 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 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
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
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 int power_initial = GetSanitizedArg( 263 int power_initial = GetSanitizedArg(
263 chromeos::switches::kEnterpriseEnrollmentInitialModulus); 264 chromeos::switches::kEnterpriseEnrollmentInitialModulus);
264 int power_limit = GetSanitizedArg( 265 int power_limit = GetSanitizedArg(
265 chromeos::switches::kEnterpriseEnrollmentModulusLimit); 266 chromeos::switches::kEnterpriseEnrollmentModulusLimit);
266 if (power_initial > power_limit) { 267 if (power_initial > power_limit) {
267 LOG(ERROR) << "Initial auto-enrollment modulus is larger than the limit, " 268 LOG(ERROR) << "Initial auto-enrollment modulus is larger than the limit, "
268 "clamping to the limit."; 269 "clamping to the limit.";
269 power_initial = power_limit; 270 power_initial = power_limit;
270 } 271 }
271 272
272 client_.reset(new policy::AutoEnrollmentClient( 273 client_ = base::MakeUnique<policy::AutoEnrollmentClient>(
273 base::Bind(&AutoEnrollmentController::UpdateState, 274 base::Bind(&AutoEnrollmentController::UpdateState,
274 base::Unretained(this)), 275 weak_ptr_factory_.GetWeakPtr()),
275 service, 276 service, g_browser_process->local_state(),
276 g_browser_process->local_state(), 277 g_browser_process->system_request_context(), state_keys.front(),
277 g_browser_process->system_request_context(), 278 power_initial, power_limit);
278 state_keys.front(),
279 power_initial,
280 power_limit));
281 279
282 VLOG(1) << "Starting auto-enrollment client."; 280 VLOG(1) << "Starting auto-enrollment client.";
283 client_->Start(); 281 client_->Start();
284 } 282 }
285 283
286 void AutoEnrollmentController::UpdateState( 284 void AutoEnrollmentController::UpdateState(
287 policy::AutoEnrollmentState new_state) { 285 policy::AutoEnrollmentState new_state) {
288 VLOG(1) << "New auto-enrollment state: " << new_state; 286 VLOG(1) << "New auto-enrollment state: " << new_state;
289 state_ = new_state; 287 state_ = new_state;
290 288
291 // Stop the safeguard timer once a result comes in. 289 // Stop the safeguard timer once a result comes in.
292 switch (state_) { 290 switch (state_) {
293 case policy::AUTO_ENROLLMENT_STATE_IDLE: 291 case policy::AUTO_ENROLLMENT_STATE_IDLE:
294 case policy::AUTO_ENROLLMENT_STATE_PENDING: 292 case policy::AUTO_ENROLLMENT_STATE_PENDING:
295 break; 293 break;
296 case policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR: 294 case policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR:
297 case policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR: 295 case policy::AUTO_ENROLLMENT_STATE_SERVER_ERROR:
298 case policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT: 296 case policy::AUTO_ENROLLMENT_STATE_TRIGGER_ENROLLMENT:
299 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT: 297 case policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT:
300 safeguard_timer_.Stop(); 298 safeguard_timer_.Stop();
301 break; 299 break;
302 } 300 }
303 301
302 if (state_ == policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT) {
303 StartRemoveFirmwareManagementParameters();
304 } else {
305 progress_callbacks_.Notify(state_);
306 }
307 }
308
309 void AutoEnrollmentController::StartRemoveFirmwareManagementParameters() {
310 DCHECK_EQ(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT, state_);
311
312 cryptohome::RemoveFirmwareManagementParametersRequest request;
313 chromeos::DBusThreadManager::Get()
314 ->GetCryptohomeClient()
315 ->RemoveFirmwareManagementParametersFromTpm(
316 request,
317 base::Bind(
318 &AutoEnrollmentController::OnFirmwareManagementParametersRemoved,
319 weak_ptr_factory_.GetWeakPtr()));
320 }
321
322 void AutoEnrollmentController::OnFirmwareManagementParametersRemoved(
323 chromeos::DBusMethodCallStatus call_status,
324 bool result,
325 const cryptohome::BaseReply& reply) {
326 if (!result) {
327 LOG(ERROR) << "Failed to remove firmware management parameters, error: "
328 << reply.error();
329 }
330
304 progress_callbacks_.Notify(state_); 331 progress_callbacks_.Notify(state_);
305 } 332 }
306 333
307 void AutoEnrollmentController::Timeout() { 334 void AutoEnrollmentController::Timeout() {
308 // TODO(mnissler): Add UMA to track results of auto-enrollment checks. 335 // TODO(mnissler): Add UMA to track results of auto-enrollment checks.
309 if (client_start_weak_factory_.HasWeakPtrs() && 336 if (client_start_weak_factory_.HasWeakPtrs() &&
310 fre_requirement_ != EXPLICITLY_REQUIRED) { 337 fre_requirement_ != EXPLICITLY_REQUIRED) {
311 // 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
312 // 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
313 // retrying anything, need to fix that bug. 340 // retrying anything, need to fix that bug.
314 LOG(ERROR) << "Failed to start auto-enrollment check, fix the code!"; 341 LOG(ERROR) << "Failed to start auto-enrollment check, fix the code!";
315 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT); 342 UpdateState(policy::AUTO_ENROLLMENT_STATE_NO_ENROLLMENT);
316 } else { 343 } else {
317 // 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
318 // 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
319 // keeps the connection open. 346 // keeps the connection open.
320 LOG(ERROR) << "AutoEnrollmentClient didn't complete within time limit."; 347 LOG(ERROR) << "AutoEnrollmentClient didn't complete within time limit.";
321 UpdateState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR); 348 UpdateState(policy::AUTO_ENROLLMENT_STATE_CONNECTION_ERROR);
322 } 349 }
323 350
324 // Reset state. 351 // Reset state.
325 Cancel(); 352 Cancel();
326 } 353 }
327 354
328 } // namespace chromeos 355 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698