| 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> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/location.h" | 10 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 10 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 12 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
| 13 #include "chromeos/dbus/cryptohome_client.h" | 15 #include "chromeos/dbus/cryptohome_client.h" |
| 14 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
| 15 | 17 |
| 16 namespace chromeos { | 18 namespace chromeos { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 47 LOG(ERROR) << "WaitForServiceToBeAvailable failed."; | 49 LOG(ERROR) << "WaitForServiceToBeAvailable failed."; |
| 48 callback.Run(std::string()); | 50 callback.Run(std::string()); |
| 49 return; | 51 return; |
| 50 } | 52 } |
| 51 DBusThreadManager::Get()->GetCryptohomeClient()->GetSystemSalt( | 53 DBusThreadManager::Get()->GetCryptohomeClient()->GetSystemSalt( |
| 52 base::Bind(&SystemSaltGetter::DidGetSystemSalt, | 54 base::Bind(&SystemSaltGetter::DidGetSystemSalt, |
| 53 weak_ptr_factory_.GetWeakPtr(), | 55 weak_ptr_factory_.GetWeakPtr(), |
| 54 callback)); | 56 callback)); |
| 55 } | 57 } |
| 56 | 58 |
| 57 void SystemSaltGetter::DidGetSystemSalt(const GetSystemSaltCallback& callback, | 59 void SystemSaltGetter::DidGetSystemSalt( |
| 58 DBusMethodCallStatus call_status, | 60 const GetSystemSaltCallback& callback, |
| 59 const std::vector<uint8>& system_salt) { | 61 DBusMethodCallStatus call_status, |
| 62 const std::vector<uint8_t>& system_salt) { |
| 60 if (call_status == DBUS_METHOD_CALL_SUCCESS && | 63 if (call_status == DBUS_METHOD_CALL_SUCCESS && |
| 61 !system_salt.empty() && | 64 !system_salt.empty() && |
| 62 system_salt.size() % 2 == 0U) | 65 system_salt.size() % 2 == 0U) |
| 63 system_salt_ = ConvertRawSaltToHexString(system_salt); | 66 system_salt_ = ConvertRawSaltToHexString(system_salt); |
| 64 else | 67 else |
| 65 LOG(WARNING) << "System salt not available"; | 68 LOG(WARNING) << "System salt not available"; |
| 66 | 69 |
| 67 callback.Run(system_salt_); | 70 callback.Run(system_salt_); |
| 68 } | 71 } |
| 69 | 72 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 87 | 90 |
| 88 // static | 91 // static |
| 89 SystemSaltGetter* SystemSaltGetter::Get() { | 92 SystemSaltGetter* SystemSaltGetter::Get() { |
| 90 CHECK(g_system_salt_getter) | 93 CHECK(g_system_salt_getter) |
| 91 << "SystemSaltGetter::Get() called before Initialize()"; | 94 << "SystemSaltGetter::Get() called before Initialize()"; |
| 92 return g_system_salt_getter; | 95 return g_system_salt_getter; |
| 93 } | 96 } |
| 94 | 97 |
| 95 // static | 98 // static |
| 96 std::string SystemSaltGetter::ConvertRawSaltToHexString( | 99 std::string SystemSaltGetter::ConvertRawSaltToHexString( |
| 97 const std::vector<uint8>& salt) { | 100 const std::vector<uint8_t>& salt) { |
| 98 return base::ToLowerASCII( | 101 return base::ToLowerASCII( |
| 99 base::HexEncode(reinterpret_cast<const void*>(salt.data()), salt.size())); | 102 base::HexEncode(reinterpret_cast<const void*>(salt.data()), salt.size())); |
| 100 } | 103 } |
| 101 | 104 |
| 102 } // namespace chromeos | 105 } // namespace chromeos |
| OLD | NEW |