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 CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ | 5 #ifndef CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ |
6 #define CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ | 6 #define CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "chromeos/chromeos_export.h" | 14 #include "chromeos/chromeos_export.h" |
| 15 #include "chromeos/dbus/dbus_method_call_status.h" |
15 | 16 |
16 namespace chromeos { | 17 namespace chromeos { |
17 | 18 |
18 // This class is used to get the system salt from cryptohome and cache it. | 19 // This class is used to get the system salt from cryptohome and cache it. |
19 class CHROMEOS_EXPORT SystemSaltGetter { | 20 class CHROMEOS_EXPORT SystemSaltGetter { |
20 public: | 21 public: |
21 typedef base::Callback<void(const std::string& system_salt)> | 22 typedef base::Callback<void(const std::string& system_salt)> |
22 GetSystemSaltCallback; | 23 GetSystemSaltCallback; |
23 | 24 |
24 // Manage an explicitly initialized global instance. | 25 // Manage an explicitly initialized global instance. |
25 static void Initialize(); | 26 static void Initialize(); |
26 static bool IsInitialized(); | 27 static bool IsInitialized(); |
27 static void Shutdown(); | 28 static void Shutdown(); |
28 static SystemSaltGetter* Get(); | 29 static SystemSaltGetter* Get(); |
29 | 30 |
30 // Converts |salt| to a hex encoded string. | 31 // Converts |salt| to a hex encoded string. |
31 static std::string ConvertRawSaltToHexString(const std::vector<uint8>& salt); | 32 static std::string ConvertRawSaltToHexString(const std::vector<uint8>& salt); |
32 | 33 |
33 // Returns system hash in hex encoded ascii format. Note: this may return | 34 // Returns system hash in hex encoded ascii format. Note: this may return |
34 // an empty string (e.g. if cryptohome is not running). It is up to the | 35 // an empty string (e.g. errors in D-Bus layer) |
35 // calling function to try again after a delay if desired. | |
36 void GetSystemSalt(const GetSystemSaltCallback& callback); | 36 void GetSystemSalt(const GetSystemSaltCallback& callback); |
37 | 37 |
38 // Synchronous version of GetSystemSalt(). | |
39 // Blocks the UI thread until the Cryptohome service returns the result. | |
40 // DEPRECATED: DO NOT USE. | |
41 std::string GetSystemSaltSync(); | |
42 | |
43 protected: | 38 protected: |
44 SystemSaltGetter(); | 39 SystemSaltGetter(); |
45 ~SystemSaltGetter(); | 40 ~SystemSaltGetter(); |
46 | 41 |
47 private: | 42 private: |
48 // Used to implement GetSystemSalt(). | 43 // Used to implement GetSystemSalt(). |
49 void GetSystemSaltInternal(const GetSystemSaltCallback& callback, | 44 void DidWaitForServiceToBeAvailable(const GetSystemSaltCallback& callback, |
50 bool service_is_available); | 45 bool service_is_available); |
51 | 46 void DidGetSystemSalt(const GetSystemSaltCallback& callback, |
52 // Loads the system salt from cryptohome and caches it. | 47 DBusMethodCallStatus call_status, |
53 void LoadSystemSalt(); | 48 const std::vector<uint8>& system_salt); |
54 | 49 |
55 std::string system_salt_; | 50 std::string system_salt_; |
56 | 51 |
57 base::WeakPtrFactory<SystemSaltGetter> weak_ptr_factory_; | 52 base::WeakPtrFactory<SystemSaltGetter> weak_ptr_factory_; |
58 | 53 |
59 DISALLOW_COPY_AND_ASSIGN(SystemSaltGetter); | 54 DISALLOW_COPY_AND_ASSIGN(SystemSaltGetter); |
60 }; | 55 }; |
61 | 56 |
62 } // namespace chromeos | 57 } // namespace chromeos |
63 | 58 |
64 #endif // CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ | 59 #endif // CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ |
OLD | NEW |