| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/callback_forward.h" | 13 #include "base/callback_forward.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "chromeos/chromeos_export.h" | 16 #include "chromeos/chromeos_export.h" |
| 17 #include "chromeos/dbus/dbus_method_call_status.h" | 17 #include "chromeos/dbus/dbus_method_call_status.h" |
| 18 | 18 |
| 19 namespace chromeos { | 19 namespace chromeos { |
| 20 | 20 |
| 21 // This class is used to get the system salt from cryptohome and cache it. | 21 // This class is used to get the system salt from cryptohome and cache it. |
| 22 class CHROMEOS_EXPORT SystemSaltGetter { | 22 class CHROMEOS_EXPORT SystemSaltGetter { |
| 23 public: | 23 public: |
| 24 typedef base::Callback<void(const std::string& system_salt)> | 24 typedef base::Callback<void(const std::string& system_salt)> |
| 25 GetSystemSaltCallback; | 25 GetSystemSaltCallback; |
| 26 | 26 |
| 27 using RawSalt = std::vector<uint8_t>; | |
| 28 | |
| 29 // Manage an explicitly initialized global instance. | 27 // Manage an explicitly initialized global instance. |
| 30 static void Initialize(); | 28 static void Initialize(); |
| 31 static bool IsInitialized(); | 29 static bool IsInitialized(); |
| 32 static void Shutdown(); | 30 static void Shutdown(); |
| 33 static SystemSaltGetter* Get(); | 31 static SystemSaltGetter* Get(); |
| 34 | 32 |
| 35 // Converts |salt| to a hex encoded string. | 33 // Converts |salt| to a hex encoded string. |
| 36 static std::string ConvertRawSaltToHexString(const RawSalt& salt); | 34 static std::string ConvertRawSaltToHexString( |
| 35 const std::vector<uint8_t>& salt); |
| 37 | 36 |
| 38 // Returns system hash in hex encoded ascii format. Note: this may return | 37 // Returns system hash in hex encoded ascii format. Note: this may return |
| 39 // an empty string (e.g. errors in D-Bus layer) | 38 // an empty string (e.g. errors in D-Bus layer) |
| 40 void GetSystemSalt(const GetSystemSaltCallback& callback); | 39 void GetSystemSalt(const GetSystemSaltCallback& callback); |
| 41 | 40 |
| 42 // Returns pointer to binary system salt if it is already known. | |
| 43 // Returns nullptr if system salt is not known. | |
| 44 const RawSalt* GetRawSalt() const; | |
| 45 | |
| 46 // This is for browser tests API. | |
| 47 void SetRawSaltForTesting(const RawSalt& raw_salt); | |
| 48 | |
| 49 protected: | 41 protected: |
| 50 SystemSaltGetter(); | 42 SystemSaltGetter(); |
| 51 ~SystemSaltGetter(); | 43 ~SystemSaltGetter(); |
| 52 | 44 |
| 53 private: | 45 private: |
| 54 // Used to implement GetSystemSalt(). | 46 // Used to implement GetSystemSalt(). |
| 55 void DidWaitForServiceToBeAvailable(const GetSystemSaltCallback& callback, | 47 void DidWaitForServiceToBeAvailable(const GetSystemSaltCallback& callback, |
| 56 bool service_is_available); | 48 bool service_is_available); |
| 57 void DidGetSystemSalt(const GetSystemSaltCallback& callback, | 49 void DidGetSystemSalt(const GetSystemSaltCallback& callback, |
| 58 DBusMethodCallStatus call_status, | 50 DBusMethodCallStatus call_status, |
| 59 const RawSalt& system_salt); | 51 const std::vector<uint8_t>& system_salt); |
| 60 | 52 |
| 61 RawSalt raw_salt_; | |
| 62 std::string system_salt_; | 53 std::string system_salt_; |
| 63 | 54 |
| 64 base::WeakPtrFactory<SystemSaltGetter> weak_ptr_factory_; | 55 base::WeakPtrFactory<SystemSaltGetter> weak_ptr_factory_; |
| 65 | 56 |
| 66 DISALLOW_COPY_AND_ASSIGN(SystemSaltGetter); | 57 DISALLOW_COPY_AND_ASSIGN(SystemSaltGetter); |
| 67 }; | 58 }; |
| 68 | 59 |
| 69 } // namespace chromeos | 60 } // namespace chromeos |
| 70 | 61 |
| 71 #endif // CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ | 62 #endif // CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ |
| OLD | NEW |