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 3 // found in the LICENSE file. 4 5 #ifndef CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ 6 #define CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ 7 8 #include <string> 9 #include <vector> 10 11 #include "base/basictypes.h" 12 #include "base/callback_forward.h" 13 #include "base/memory/weak_ptr.h" 14 #include "chromeos/chromeos_export.h" 15 #include "chromeos/dbus/dbus_method_call_status.h" 16 17 namespace chromeos { 18 19 // This class is used to get the system salt from cryptohome and cache it. 20 class CHROMEOS_EXPORT SystemSaltGetter { 21 public: 22 typedef base::Callback<void(const std::string& system_salt)> 23 GetSystemSaltCallback; 24 25 // Manage an explicitly initialized global instance. 26 static void Initialize(); 27 static bool IsInitialized(); 28 static void Shutdown(); 29 static SystemSaltGetter* Get(); 30 31 // Converts |salt| to a hex encoded string. 32 static std::string ConvertRawSaltToHexString(const std::vector<uint8>& salt); 33 34 // Returns system hash in hex encoded ascii format. Note: this may return 35 // an empty string (e.g. errors in D-Bus layer) 36 void GetSystemSalt(const GetSystemSaltCallback& callback); 37 38 protected: 39 SystemSaltGetter(); 40 ~SystemSaltGetter(); 41 42 private: 43 // Used to implement GetSystemSalt(). 44 void DidWaitForServiceToBeAvailable(const GetSystemSaltCallback& callback, 45 bool service_is_available); 46 void DidGetSystemSalt(const GetSystemSaltCallback& callback, 47 DBusMethodCallStatus call_status, 48 const std::vector<uint8>& system_salt); 49 50 std::string system_salt_; 51 52 base::WeakPtrFactory<SystemSaltGetter> weak_ptr_factory_; 53 54 DISALLOW_COPY_AND_ASSIGN(SystemSaltGetter); 55 }; 56 57 } // namespace chromeos 58 59 #endif // CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ 60