Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ | 6 #define CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
| 16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
| 17 #include "chromeos/dbus/cryptohome_client.h" | 17 #include "chromeos/dbus/cryptohome_client.h" |
| 18 #include "chromeos/dbus/dbus_method_call_status.h" | 18 #include "chromeos/dbus/dbus_method_call_status.h" |
| 19 #include "components/policy/core/common/cloud/cloud_policy_constants.h" | 19 #include "components/policy/core/common/cloud/cloud_policy_constants.h" |
| 20 | 20 |
| 21 namespace policy { | 21 namespace policy { |
| 22 | 22 |
| 23 // Brokers access to the enterprise-related installation-time attributes on | 23 // Brokers access to the enterprise-related installation-time attributes on |
| 24 // ChromeOS. | 24 // ChromeOS. |
| 25 // TODO(zelidrag, mnissler): Rename + move this class - http://crbug.com/249513. | 25 // TODO(zelidrag, mnissler): Rename + move this class - http://crbug.com/249513. |
| 26 class EnterpriseInstallAttributes { | 26 class EnterpriseInstallAttributes { |
| 27 public: | 27 public: |
| 28 enum LockState { | |
| 29 STATE_UNKNOWN = 0, // Not initialized, yet. | |
|
Mattias Nissler (ping if slow)
2015/06/23 11:34:09
suggestion: remove comma
Thiemo Nagel
2015/06/23 13:17:55
Done. (I was told in school that a comma was requ
| |
| 30 STATE_NOT_LOCKED = 1, // Install attributes not present. | |
| 31 STATE_LOCKING = 2, // Lock attempt in process. | |
| 32 STATE_LOCKED = 3, // Valid install attributes have been obtained. | |
| 33 }; | |
| 34 | |
| 28 // EnterpriseInstallAttributes status codes. Do not change the numeric ids or | 35 // EnterpriseInstallAttributes status codes. Do not change the numeric ids or |
| 29 // the meaning of the existing codes to preserve the interpretability of old | 36 // the meaning of the existing codes to preserve the interpretability of old |
| 30 // logfiles. | 37 // logfiles. |
| 31 enum LockResult { | 38 enum LockResult { |
| 32 LOCK_SUCCESS = 0, // Success. | 39 LOCK_SUCCESS = 0, // Success. |
| 33 LOCK_NOT_READY = 1, // Backend/TPM still initializing. | 40 LOCK_NOT_READY = 1, // Backend/TPM still initializing. |
| 34 LOCK_TIMEOUT = 2, // Backend/TPM timed out. | 41 LOCK_TIMEOUT = 2, // Backend/TPM timed out. |
| 35 LOCK_BACKEND_INVALID = 3, // Backend failed to initialize. | 42 LOCK_BACKEND_INVALID = 3, // Backend failed to initialize. |
| 36 LOCK_ALREADY_LOCKED = 4, // TPM has already been locked. | 43 LOCK_ALREADY_LOCKED = 4, // TPM has already been locked. |
| 37 LOCK_SET_ERROR = 5, // Failed to set attributes. | 44 LOCK_SET_ERROR = 5, // Failed to set attributes. |
| 38 LOCK_FINALIZE_ERROR = 6, // Backend failed to lock. | 45 LOCK_FINALIZE_ERROR = 6, // Backend failed to lock. |
| 39 LOCK_READBACK_ERROR = 7, // Inconsistency reading back registration data. | 46 LOCK_READBACK_ERROR = 7, // Inconsistency reading back registration data. |
| 40 LOCK_WRONG_DOMAIN = 8, // Device already registered to another domain. | 47 LOCK_WRONG_DOMAIN = 8, // Device already registered to another domain. |
| 41 LOCK_WRONG_MODE = 9, // Device already locked to a different mode. | 48 LOCK_WRONG_MODE = 9, // Device already locked to a different mode. |
| 42 }; | 49 }; |
| 43 | 50 |
| 44 // A callback to handle responses of methods returning a LockResult value. | 51 // A callback to handle responses of methods returning a LockResult value. |
| 45 typedef base::Callback<void(LockResult lock_result)> LockResultCallback; | 52 typedef base::Callback<void(LockResult lock_result)> LockResultCallback; |
| 46 | 53 |
| 47 // Return serialized InstallAttributes of an enterprise-owned configuration. | 54 // Return serialized InstallAttributes of an enterprise-owned configuration. |
| 48 static std::string GetEnterpriseOwnedInstallAttributesBlobForTesting( | 55 static std::string GetEnterpriseOwnedInstallAttributesBlobForTesting( |
| 49 const std::string& user_name); | 56 const std::string& user_name); |
| 50 | 57 |
| 51 explicit EnterpriseInstallAttributes( | 58 explicit EnterpriseInstallAttributes( |
| 52 chromeos::CryptohomeClient* cryptohome_client); | 59 chromeos::CryptohomeClient* cryptohome_client); |
| 53 ~EnterpriseInstallAttributes(); | 60 ~EnterpriseInstallAttributes(); |
| 54 | 61 |
| 55 // Reads data from the cache file which is created early during the boot | 62 // Tries to read install attributes from the cache file which is created early |
| 56 // process. The cache file is used to work around slow cryptohome startup, | 63 // during the boot process. The cache file is used to work around slow |
| 57 // which takes a while to register its DBus interface. See | 64 // cryptohome startup, which takes a while to register its DBus interface. |
| 58 // http://crosbug.com/37367 for background on this. | 65 // (See http://crosbug.com/37367 for background on this.) This method may |
| 66 // only be called once for initialization. | |
| 59 void ReadCacheFile(const base::FilePath& cache_file); | 67 void ReadCacheFile(const base::FilePath& cache_file); |
| 60 | 68 |
| 61 // Makes sure the local caches for enterprise-related install attributes are | 69 // Makes sure the local caches for enterprise-related install attributes are |
| 62 // up-to-date with what cryptohome has. This method checks the readiness of | 70 // up-to-date with what cryptohome has. This method checks the readiness of |
| 63 // attributes and read them if ready. Actual read will be performed in | 71 // attributes and read them if ready. Actual read will be performed in |
| 64 // ReadAttributesIfReady(). | 72 // ReadAttributesIfReady(). |
| 65 void ReadImmutableAttributes(const base::Closure& callback); | 73 void ReadImmutableAttributes(const base::Closure& callback); |
| 66 | 74 |
| 67 // Locks the device to be an enterprise device registered by the given user. | 75 // Locks the device to be an enterprise device registered by the given user. |
| 68 // This can also be called after the lock has already been taken, in which | 76 // This can also be called after the lock has already been taken, in which |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 89 | 97 |
| 90 // Gets the device id that was generated when the device was registered. | 98 // Gets the device id that was generated when the device was registered. |
| 91 // Returns an empty string if the device is not an enterprise device or the | 99 // Returns an empty string if the device is not an enterprise device or the |
| 92 // device id was not stored in the lockbox (prior to R19). | 100 // device id was not stored in the lockbox (prior to R19). |
| 93 std::string GetDeviceId(); | 101 std::string GetDeviceId(); |
| 94 | 102 |
| 95 // Gets the mode the device was enrolled to. The return value for devices that | 103 // Gets the mode the device was enrolled to. The return value for devices that |
| 96 // are not locked yet will be DEVICE_MODE_UNKNOWN. | 104 // are not locked yet will be DEVICE_MODE_UNKNOWN. |
| 97 DeviceMode GetMode(); | 105 DeviceMode GetMode(); |
| 98 | 106 |
| 107 // Check state of install attributes against TPM lock state and generate UMA | |
| 108 // for the result. Retry asynchronously for up to 60 seconds in case of DBUS | |
| 109 // errors (cryptohomed startup is slow). | |
| 110 void TriggerConsistencyCheck(); | |
|
Mattias Nissler (ping if slow)
2015/06/23 11:34:09
Does it make sense to trigger this externally? Mig
Thiemo Nagel
2015/06/23 13:17:55
I only want to call it after ReadCacheFile() becau
| |
| 111 | |
| 99 protected: | 112 protected: |
| 100 bool device_locked_; | 113 LockState lock_state_; |
| 114 int dbus_tries_remaining_; | |
| 101 std::string registration_user_; | 115 std::string registration_user_; |
| 102 std::string registration_domain_; | 116 std::string registration_domain_; |
| 103 std::string registration_device_id_; | 117 std::string registration_device_id_; |
| 104 DeviceMode registration_mode_; | 118 DeviceMode registration_mode_; |
| 105 | 119 |
| 106 private: | 120 private: |
| 107 FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest, | 121 FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest, |
| 108 DeviceLockedFromOlderVersion); | 122 DeviceLockedFromOlderVersion); |
| 109 FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest, | 123 FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest, |
| 110 ReadCacheFile); | 124 ReadCacheFile); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 DeviceMode device_mode, | 165 DeviceMode device_mode, |
| 152 const std::string& device_id, | 166 const std::string& device_id, |
| 153 const LockResultCallback& callback, | 167 const LockResultCallback& callback, |
| 154 chromeos::DBusMethodCallStatus call_status, | 168 chromeos::DBusMethodCallStatus call_status, |
| 155 bool result); | 169 bool result); |
| 156 | 170 |
| 157 // Confirms the registered user and invoke the callback. | 171 // Confirms the registered user and invoke the callback. |
| 158 void OnReadImmutableAttributes(const std::string& user, | 172 void OnReadImmutableAttributes(const std::string& user, |
| 159 const LockResultCallback& callback); | 173 const LockResultCallback& callback); |
| 160 | 174 |
| 175 // Callback for TpmIsOwned() DBUS call. Generates UMA or schedules retry in | |
| 176 // case of DBUS error. | |
| 177 void CheckConsistencyAgainstTpmOwnershipState( | |
| 178 chromeos::DBusMethodCallStatus call_status, | |
| 179 bool result); | |
| 180 | |
| 161 chromeos::CryptohomeClient* cryptohome_client_; | 181 chromeos::CryptohomeClient* cryptohome_client_; |
| 162 | 182 |
| 163 base::WeakPtrFactory<EnterpriseInstallAttributes> weak_ptr_factory_; | 183 base::WeakPtrFactory<EnterpriseInstallAttributes> weak_ptr_factory_; |
| 164 | 184 |
| 165 DISALLOW_COPY_AND_ASSIGN(EnterpriseInstallAttributes); | 185 DISALLOW_COPY_AND_ASSIGN(EnterpriseInstallAttributes); |
| 166 }; | 186 }; |
| 167 | 187 |
| 168 } // namespace policy | 188 } // namespace policy |
| 169 | 189 |
| 170 #endif // CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ | 190 #endif // CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ |
| OLD | NEW |