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, // A valid lock can't be confirmed. | |
30 STATE_NOT_LOCKED = 1, | |
31 STATE_LOCKING = 2, // Lock attempt in process. | |
32 STATE_LOCKED = 3, // Valid lock confirmed by attribute read. | |
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 to work around slow cryptohome startup, which takes |
Mattias Nissler (ping if slow)
2015/06/19 07:32:45
nit: Your edit makes this sentence ambiguous. Now
Thiemo Nagel
2015/06/19 17:47:04
Done.
| |
57 // which takes a while to register its DBus interface. See | 64 // a while to register its DBus interface. (See http://crosbug.com/37367 for |
58 // http://crosbug.com/37367 for background on this. | 65 // background on this.) May only be called once for initialization. |
59 void ReadCacheFile(const base::FilePath& cache_file); | 66 void ReadCacheFile(const base::FilePath& cache_file); |
60 | 67 |
61 // Makes sure the local caches for enterprise-related install attributes are | 68 // 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 | 69 // 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 | 70 // attributes and read them if ready. Actual read will be performed in |
64 // ReadAttributesIfReady(). | 71 // ReadAttributesIfReady(). |
65 void ReadImmutableAttributes(const base::Closure& callback); | 72 void ReadImmutableAttributes(const base::Closure& callback); |
66 | 73 |
67 // Locks the device to be an enterprise device registered by the given user. | 74 // 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 | 75 // This can also be called after the lock has already been taken, in which |
(...skipping 20 matching lines...) Expand all Loading... | |
89 | 96 |
90 // Gets the device id that was generated when the device was registered. | 97 // 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 | 98 // 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). | 99 // device id was not stored in the lockbox (prior to R19). |
93 std::string GetDeviceId(); | 100 std::string GetDeviceId(); |
94 | 101 |
95 // Gets the mode the device was enrolled to. The return value for devices that | 102 // Gets the mode the device was enrolled to. The return value for devices that |
96 // are not locked yet will be DEVICE_MODE_UNKNOWN. | 103 // are not locked yet will be DEVICE_MODE_UNKNOWN. |
97 DeviceMode GetMode(); | 104 DeviceMode GetMode(); |
98 | 105 |
106 void CheckConsistency(); | |
107 | |
99 protected: | 108 protected: |
100 bool device_locked_; | 109 LockState lock_state_; |
101 std::string registration_user_; | 110 std::string registration_user_; |
102 std::string registration_domain_; | 111 std::string registration_domain_; |
103 std::string registration_device_id_; | 112 std::string registration_device_id_; |
104 DeviceMode registration_mode_; | 113 DeviceMode registration_mode_; |
105 | 114 |
106 private: | 115 private: |
107 FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest, | 116 FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest, |
108 DeviceLockedFromOlderVersion); | 117 DeviceLockedFromOlderVersion); |
109 FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest, | 118 FRIEND_TEST_ALL_PREFIXES(EnterpriseInstallAttributesTest, |
110 ReadCacheFile); | 119 ReadCacheFile); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 DeviceMode device_mode, | 160 DeviceMode device_mode, |
152 const std::string& device_id, | 161 const std::string& device_id, |
153 const LockResultCallback& callback, | 162 const LockResultCallback& callback, |
154 chromeos::DBusMethodCallStatus call_status, | 163 chromeos::DBusMethodCallStatus call_status, |
155 bool result); | 164 bool result); |
156 | 165 |
157 // Confirms the registered user and invoke the callback. | 166 // Confirms the registered user and invoke the callback. |
158 void OnReadImmutableAttributes(const std::string& user, | 167 void OnReadImmutableAttributes(const std::string& user, |
159 const LockResultCallback& callback); | 168 const LockResultCallback& callback); |
160 | 169 |
170 void CheckConsistencyAgainstTpmOwnershipState( | |
171 chromeos::DBusMethodCallStatus call_status, | |
172 bool result); | |
173 | |
161 chromeos::CryptohomeClient* cryptohome_client_; | 174 chromeos::CryptohomeClient* cryptohome_client_; |
162 | 175 |
163 base::WeakPtrFactory<EnterpriseInstallAttributes> weak_ptr_factory_; | 176 base::WeakPtrFactory<EnterpriseInstallAttributes> weak_ptr_factory_; |
164 | 177 |
165 DISALLOW_COPY_AND_ASSIGN(EnterpriseInstallAttributes); | 178 DISALLOW_COPY_AND_ASSIGN(EnterpriseInstallAttributes); |
166 }; | 179 }; |
167 | 180 |
168 } // namespace policy | 181 } // namespace policy |
169 | 182 |
170 #endif // CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ | 183 #endif // CHROME_BROWSER_CHROMEOS_POLICY_ENTERPRISE_INSTALL_ATTRIBUTES_H_ |
OLD | NEW |