15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 58bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#ifndef CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ 68bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#define CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 94e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include <vector> 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "base/basictypes.h" 124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/callback_forward.h" 138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "base/memory/weak_ptr.h" 14c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chromeos/chromeos_export.h" 151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chromeos/dbus/dbus_method_call_status.h" 16c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace chromeos { 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// This class is used to get the system salt from cryptohome and cache it. 208bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class CHROMEOS_EXPORT SystemSaltGetter { 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) typedef base::Callback<void(const std::string& system_salt)> 234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) GetSystemSaltCallback; 244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 25c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Manage an explicitly initialized global instance. 26c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static void Initialize(); 27c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static bool IsInitialized(); 28c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) static void Shutdown(); 298bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) static SystemSaltGetter* Get(); 30c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Converts |salt| to a hex encoded string. 324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) static std::string ConvertRawSaltToHexString(const std::vector<uint8>& salt); 335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Returns system hash in hex encoded ascii format. Note: this may return 351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // an empty string (e.g. errors in D-Bus layer) 364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void GetSystemSalt(const GetSystemSaltCallback& callback); 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) protected: 398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) SystemSaltGetter(); 408bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) ~SystemSaltGetter(); 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Used to implement GetSystemSalt(). 441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void DidWaitForServiceToBeAvailable(const GetSystemSaltCallback& callback, 451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool service_is_available); 461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void DidGetSystemSalt(const GetSystemSaltCallback& callback, 471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) DBusMethodCallStatus call_status, 481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const std::vector<uint8>& system_salt); 494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string system_salt_; 514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) base::WeakPtrFactory<SystemSaltGetter> weak_ptr_factory_; 538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 548bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(SystemSaltGetter); 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace chromeos 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#endif // CHROMEOS_CRYPTOHOME_SYSTEM_SALT_GETTER_H_ 60