| 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 #include "chromeos/cryptohome/system_salt_getter.h" | 5 #include "chromeos/cryptohome/system_salt_getter.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 FROM_HERE, base::Bind(callback, system_salt_)); | 35 FROM_HERE, base::Bind(callback, system_salt_)); |
| 36 return; | 36 return; |
| 37 } | 37 } |
| 38 | 38 |
| 39 DBusThreadManager::Get()->GetCryptohomeClient()->WaitForServiceToBeAvailable( | 39 DBusThreadManager::Get()->GetCryptohomeClient()->WaitForServiceToBeAvailable( |
| 40 base::Bind(&SystemSaltGetter::DidWaitForServiceToBeAvailable, | 40 base::Bind(&SystemSaltGetter::DidWaitForServiceToBeAvailable, |
| 41 weak_ptr_factory_.GetWeakPtr(), | 41 weak_ptr_factory_.GetWeakPtr(), |
| 42 callback)); | 42 callback)); |
| 43 } | 43 } |
| 44 | 44 |
| 45 const SystemSaltGetter::RawSalt* SystemSaltGetter::GetRawSalt() const { |
| 46 return raw_salt_.empty() ? nullptr : &raw_salt_; |
| 47 } |
| 48 |
| 49 void SystemSaltGetter::SetRawSaltForTesting( |
| 50 const SystemSaltGetter::RawSalt& raw_salt) { |
| 51 raw_salt_ = raw_salt; |
| 52 } |
| 53 |
| 45 void SystemSaltGetter::DidWaitForServiceToBeAvailable( | 54 void SystemSaltGetter::DidWaitForServiceToBeAvailable( |
| 46 const GetSystemSaltCallback& callback, | 55 const GetSystemSaltCallback& callback, |
| 47 bool service_is_available) { | 56 bool service_is_available) { |
| 48 if (!service_is_available) { | 57 if (!service_is_available) { |
| 49 LOG(ERROR) << "WaitForServiceToBeAvailable failed."; | 58 LOG(ERROR) << "WaitForServiceToBeAvailable failed."; |
| 50 callback.Run(std::string()); | 59 callback.Run(std::string()); |
| 51 return; | 60 return; |
| 52 } | 61 } |
| 53 DBusThreadManager::Get()->GetCryptohomeClient()->GetSystemSalt( | 62 DBusThreadManager::Get()->GetCryptohomeClient()->GetSystemSalt( |
| 54 base::Bind(&SystemSaltGetter::DidGetSystemSalt, | 63 base::Bind(&SystemSaltGetter::DidGetSystemSalt, |
| 55 weak_ptr_factory_.GetWeakPtr(), | 64 weak_ptr_factory_.GetWeakPtr(), |
| 56 callback)); | 65 callback)); |
| 57 } | 66 } |
| 58 | 67 |
| 59 void SystemSaltGetter::DidGetSystemSalt( | 68 void SystemSaltGetter::DidGetSystemSalt( |
| 60 const GetSystemSaltCallback& callback, | 69 const GetSystemSaltCallback& callback, |
| 61 DBusMethodCallStatus call_status, | 70 DBusMethodCallStatus call_status, |
| 62 const std::vector<uint8_t>& system_salt) { | 71 const std::vector<uint8_t>& system_salt) { |
| 63 if (call_status == DBUS_METHOD_CALL_SUCCESS && | 72 if (call_status == DBUS_METHOD_CALL_SUCCESS && |
| 64 !system_salt.empty() && | 73 !system_salt.empty() && |
| 65 system_salt.size() % 2 == 0U) | 74 system_salt.size() % 2 == 0U) { |
| 75 raw_salt_ = system_salt; |
| 66 system_salt_ = ConvertRawSaltToHexString(system_salt); | 76 system_salt_ = ConvertRawSaltToHexString(system_salt); |
| 67 else | 77 } else { |
| 68 LOG(WARNING) << "System salt not available"; | 78 LOG(WARNING) << "System salt not available"; |
| 79 } |
| 69 | 80 |
| 70 callback.Run(system_salt_); | 81 callback.Run(system_salt_); |
| 71 } | 82 } |
| 72 | 83 |
| 73 // static | 84 // static |
| 74 void SystemSaltGetter::Initialize() { | 85 void SystemSaltGetter::Initialize() { |
| 75 CHECK(!g_system_salt_getter); | 86 CHECK(!g_system_salt_getter); |
| 76 g_system_salt_getter = new SystemSaltGetter(); | 87 g_system_salt_getter = new SystemSaltGetter(); |
| 77 } | 88 } |
| 78 | 89 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 96 } | 107 } |
| 97 | 108 |
| 98 // static | 109 // static |
| 99 std::string SystemSaltGetter::ConvertRawSaltToHexString( | 110 std::string SystemSaltGetter::ConvertRawSaltToHexString( |
| 100 const std::vector<uint8_t>& salt) { | 111 const std::vector<uint8_t>& salt) { |
| 101 return base::ToLowerASCII( | 112 return base::ToLowerASCII( |
| 102 base::HexEncode(reinterpret_cast<const void*>(salt.data()), salt.size())); | 113 base::HexEncode(reinterpret_cast<const void*>(salt.data()), salt.size())); |
| 103 } | 114 } |
| 104 | 115 |
| 105 } // namespace chromeos | 116 } // namespace chromeos |
| OLD | NEW |