OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/policy/enterprise_install_attributes.h" | 5 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/metrics/histogram_base.h" | |
15 #include "base/metrics/histogram_macros.h" | |
16 #include "base/time/time.h" | |
14 #include "chrome/browser/chromeos/policy/proto/install_attributes.pb.h" | 17 #include "chrome/browser/chromeos/policy/proto/install_attributes.pb.h" |
15 #include "chromeos/cryptohome/cryptohome_util.h" | 18 #include "chromeos/cryptohome/cryptohome_util.h" |
16 #include "chromeos/dbus/dbus_thread_manager.h" | 19 #include "chromeos/dbus/dbus_thread_manager.h" |
17 #include "google_apis/gaia/gaia_auth_util.h" | 20 #include "google_apis/gaia/gaia_auth_util.h" |
18 | 21 |
19 namespace policy { | 22 namespace policy { |
20 | 23 |
21 namespace cryptohome_util = chromeos::cryptohome_util; | 24 namespace cryptohome_util = chromeos::cryptohome_util; |
22 | 25 |
23 namespace { | 26 namespace { |
24 | 27 |
28 // Retry interval for consistency check against TPM lock state. | |
29 int kDbusRetryIntervalInSeconds = 5; | |
30 | |
31 // Total time during which of TPM lock state queries are retried. | |
32 int kDbusRetryDurationInSeconds = 60; | |
33 | |
25 bool ReadMapKey(const std::map<std::string, std::string>& map, | 34 bool ReadMapKey(const std::map<std::string, std::string>& map, |
26 const std::string& key, | 35 const std::string& key, |
27 std::string* value) { | 36 std::string* value) { |
28 std::map<std::string, std::string>::const_iterator entry = map.find(key); | 37 std::map<std::string, std::string>::const_iterator entry = map.find(key); |
29 if (entry == map.end()) | 38 if (entry == map.end()) |
30 return false; | 39 return false; |
31 | 40 |
32 *value = entry->second; | 41 *value = entry->second; |
33 return true; | 42 return true; |
34 } | 43 } |
(...skipping 14 matching lines...) Expand all Loading... | |
49 attribute = install_attrs_proto.add_attributes(); | 58 attribute = install_attrs_proto.add_attributes(); |
50 attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseUser); | 59 attribute->set_name(EnterpriseInstallAttributes::kAttrEnterpriseUser); |
51 attribute->set_value(user_name); | 60 attribute->set_value(user_name); |
52 | 61 |
53 return install_attrs_proto.SerializeAsString(); | 62 return install_attrs_proto.SerializeAsString(); |
54 } | 63 } |
55 | 64 |
56 EnterpriseInstallAttributes::EnterpriseInstallAttributes( | 65 EnterpriseInstallAttributes::EnterpriseInstallAttributes( |
57 chromeos::CryptohomeClient* cryptohome_client) | 66 chromeos::CryptohomeClient* cryptohome_client) |
58 : device_locked_(false), | 67 : device_locked_(false), |
68 consistency_check_running_(false), | |
59 registration_mode_(DEVICE_MODE_PENDING), | 69 registration_mode_(DEVICE_MODE_PENDING), |
60 cryptohome_client_(cryptohome_client), | 70 cryptohome_client_(cryptohome_client), |
61 weak_ptr_factory_(this) { | 71 weak_ptr_factory_(this) { |
62 } | 72 } |
63 | 73 |
64 EnterpriseInstallAttributes::~EnterpriseInstallAttributes() {} | 74 EnterpriseInstallAttributes::~EnterpriseInstallAttributes() {} |
65 | 75 |
66 void EnterpriseInstallAttributes::ReadCacheFile( | 76 void EnterpriseInstallAttributes::Init(const base::FilePath& cache_file) { |
67 const base::FilePath& cache_file) { | 77 DCHECK_EQ(false, device_locked_); |
68 if (device_locked_ || !base::PathExists(cache_file)) | 78 |
79 // The actual check happens asynchronously, thus it is ok to trigger it before | |
80 // Init() has completed. | |
81 TriggerConsistencyCheck( | |
82 kDbusRetryDurationInSeconds / kDbusRetryIntervalInSeconds); | |
Mattias Nissler (ping if slow)
2015/06/24 08:34:39
Why not just a number-of-retries constant?
Thiemo Nagel
2015/06/24 10:43:36
I think it is easier to reason about retries in te
Mattias Nissler (ping if slow)
2015/06/24 11:55:03
I found myself doing the exact inverse of what you
Thiemo Nagel
2015/06/24 12:49:52
Done.
| |
83 | |
84 if (!base::PathExists(cache_file)) | |
69 return; | 85 return; |
70 | 86 |
71 device_locked_ = true; | 87 device_locked_ = true; |
72 | 88 |
73 char buf[16384]; | 89 char buf[16384]; |
74 int len = base::ReadFile(cache_file, buf, sizeof(buf)); | 90 int len = base::ReadFile(cache_file, buf, sizeof(buf)); |
75 if (len == -1 || len >= static_cast<int>(sizeof(buf))) { | 91 if (len == -1 || len >= static_cast<int>(sizeof(buf))) { |
76 PLOG(ERROR) << "Failed to read " << cache_file.value(); | 92 PLOG(ERROR) << "Failed to read " << cache_file.value(); |
77 return; | 93 return; |
78 } | 94 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 case DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH: | 195 case DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH: |
180 // The user parameter is ignored for consumer devices. | 196 // The user parameter is ignored for consumer devices. |
181 break; | 197 break; |
182 } | 198 } |
183 | 199 |
184 // Already locked in the right mode, signal success. | 200 // Already locked in the right mode, signal success. |
185 callback.Run(LOCK_SUCCESS); | 201 callback.Run(LOCK_SUCCESS); |
186 return; | 202 return; |
187 } | 203 } |
188 | 204 |
205 // In case the consistency check is still running, postpone the device locking | |
206 // until it has finished. This should not introduce additional delay since | |
207 // device locking must wait for TPM initialization as well. | |
208 if (consistency_check_running_) { | |
209 post_check_action_ = base::Bind(&EnterpriseInstallAttributes::LockDevice, | |
Mattias Nissler (ping if slow)
2015/06/24 08:34:39
So in theory this opens up an error condition wher
Thiemo Nagel
2015/06/24 10:43:36
Sounds good. Done.
| |
210 weak_ptr_factory_.GetWeakPtr(), | |
211 user, | |
212 device_mode, | |
213 device_id, | |
214 callback); | |
215 return; | |
216 } | |
217 | |
189 cryptohome_client_->InstallAttributesIsReady( | 218 cryptohome_client_->InstallAttributesIsReady( |
190 base::Bind(&EnterpriseInstallAttributes::LockDeviceIfAttributesIsReady, | 219 base::Bind(&EnterpriseInstallAttributes::LockDeviceIfAttributesIsReady, |
191 weak_ptr_factory_.GetWeakPtr(), | 220 weak_ptr_factory_.GetWeakPtr(), |
192 user, | 221 user, |
193 device_mode, | 222 device_mode, |
194 device_id, | 223 device_id, |
195 callback)); | 224 callback)); |
196 } | 225 } |
197 | 226 |
198 void EnterpriseInstallAttributes::LockDeviceIfAttributesIsReady( | 227 void EnterpriseInstallAttributes::LockDeviceIfAttributesIsReady( |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 if (!IsEnterpriseDevice()) | 340 if (!IsEnterpriseDevice()) |
312 return std::string(); | 341 return std::string(); |
313 | 342 |
314 return registration_device_id_; | 343 return registration_device_id_; |
315 } | 344 } |
316 | 345 |
317 DeviceMode EnterpriseInstallAttributes::GetMode() { | 346 DeviceMode EnterpriseInstallAttributes::GetMode() { |
318 return registration_mode_; | 347 return registration_mode_; |
319 } | 348 } |
320 | 349 |
350 void EnterpriseInstallAttributes::TriggerConsistencyCheck( | |
351 int dbus_tries_remaining) { | |
352 consistency_check_running_ = true; | |
353 cryptohome_client_->TpmIsOwned(base::Bind( | |
354 &EnterpriseInstallAttributes::OnTpmIsOwned, | |
355 weak_ptr_factory_.GetWeakPtr(), | |
356 dbus_tries_remaining)); | |
357 } | |
358 | |
359 void EnterpriseInstallAttributes::OnTpmIsOwned( | |
360 int dbus_tries_remaining, | |
361 chromeos::DBusMethodCallStatus call_status, | |
362 bool result) { | |
363 if (call_status != chromeos::DBUS_METHOD_CALL_SUCCESS && | |
364 dbus_tries_remaining) { | |
365 base::MessageLoop::current()->PostDelayedTask( | |
366 FROM_HERE, | |
367 base::Bind(&EnterpriseInstallAttributes::TriggerConsistencyCheck, | |
368 weak_ptr_factory_.GetWeakPtr(), | |
369 dbus_tries_remaining - 1), | |
370 base::TimeDelta::FromSeconds(kDbusRetryIntervalInSeconds)); | |
371 return; | |
372 } | |
373 | |
374 base::HistogramBase::Sample state = device_locked_; | |
375 state |= 0x2 * (registration_mode_ == DEVICE_MODE_ENTERPRISE); | |
376 if (call_status == chromeos::DBUS_METHOD_CALL_SUCCESS) | |
377 state |= 0x4 * result; | |
378 else | |
379 state |= 0x8; | |
Mattias Nissler (ping if slow)
2015/06/24 08:34:39
Think more about this bitset - does it make sense
Thiemo Nagel
2015/06/24 10:43:36
If the TPM check fails, there's something amiss, a
Mattias Nissler (ping if slow)
2015/06/24 11:55:03
I don't think the install attributes state bit giv
Thiemo Nagel
2015/06/24 12:49:52
Alright. I've condensed the 4 error cases into a
Mattias Nissler (ping if slow)
2015/06/24 13:26:06
I don't see how a separate would introduce signifi
Thiemo Nagel
2015/06/24 14:05:39
Basically, it pollutes the namespace. Scrolling t
Mattias Nissler (ping if slow)
2015/06/24 18:37:10
I agree with these, although I would personally co
Thiemo Nagel
2015/06/25 09:04:06
I wasn't entirely clear, either. I think my point
| |
380 UMA_HISTOGRAM_ENUMERATION("Enterprise.AttributesTPMConsistency", state, 12); | |
381 | |
382 // Run any action (LockDevice call) that might have queued behind the | |
383 // consistency check. | |
384 consistency_check_running_ = false; | |
385 if (!post_check_action_.is_null()) | |
386 post_check_action_.Run(); | |
387 } | |
388 | |
321 // Warning: The values for these keys (but not the keys themselves) are stored | 389 // Warning: The values for these keys (but not the keys themselves) are stored |
322 // in the protobuf with a trailing zero. Also note that some of these constants | 390 // in the protobuf with a trailing zero. Also note that some of these constants |
323 // have been copied to login_manager/device_policy_service.cc. Please make sure | 391 // have been copied to login_manager/device_policy_service.cc. Please make sure |
324 // that all changes to the constants are reflected there as well. | 392 // that all changes to the constants are reflected there as well. |
325 const char EnterpriseInstallAttributes::kConsumerDeviceMode[] = "consumer"; | 393 const char EnterpriseInstallAttributes::kConsumerDeviceMode[] = "consumer"; |
326 const char EnterpriseInstallAttributes::kEnterpriseDeviceMode[] = "enterprise"; | 394 const char EnterpriseInstallAttributes::kEnterpriseDeviceMode[] = "enterprise"; |
327 const char EnterpriseInstallAttributes::kLegacyRetailDeviceMode[] = "kiosk"; | 395 const char EnterpriseInstallAttributes::kLegacyRetailDeviceMode[] = "kiosk"; |
328 const char EnterpriseInstallAttributes::kConsumerKioskDeviceMode[] = | 396 const char EnterpriseInstallAttributes::kConsumerKioskDeviceMode[] = |
329 "consumer_kiosk"; | 397 "consumer_kiosk"; |
330 const char EnterpriseInstallAttributes::kUnknownDeviceMode[] = "unknown"; | 398 const char EnterpriseInstallAttributes::kUnknownDeviceMode[] = "unknown"; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 &consumer_kiosk_enabled) && | 476 &consumer_kiosk_enabled) && |
409 consumer_kiosk_enabled == "true") { | 477 consumer_kiosk_enabled == "true") { |
410 registration_mode_ = DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH; | 478 registration_mode_ = DEVICE_MODE_CONSUMER_KIOSK_AUTOLAUNCH; |
411 } else if (enterprise_user.empty() && enterprise_owned != "true") { | 479 } else if (enterprise_user.empty() && enterprise_owned != "true") { |
412 // |registration_user_| is empty on consumer devices. | 480 // |registration_user_| is empty on consumer devices. |
413 registration_mode_ = DEVICE_MODE_CONSUMER; | 481 registration_mode_ = DEVICE_MODE_CONSUMER; |
414 } | 482 } |
415 } | 483 } |
416 | 484 |
417 } // namespace policy | 485 } // namespace policy |
OLD | NEW |