| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/os_crypt/libsecret_util_linux.h" | 5 #include "components/os_crypt/libsecret_util_linux.h" |
| 6 | 6 |
| 7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 | 11 |
| 12 // | 12 // |
| 13 // LibsecretLoader | 13 // LibsecretLoader |
| 14 // | 14 // |
| 15 | 15 |
| 16 namespace { |
| 17 |
| 18 // TODO(crbug.com/660005) A message that is attached to useless entries that we |
| 19 // create, to explain its existence. |
| 20 const char kExplanationMessage[] = |
| 21 "Because of quirks in the gnome libsecret API, Chrome needs to store a " |
| 22 "dummy entry to quarantee that this keyring was properly unlocked. More " |
| 23 "details at http://crbug.com/660005."; |
| 24 |
| 25 } // namespace |
| 26 |
| 16 decltype( | 27 decltype( |
| 17 &::secret_password_store_sync) LibsecretLoader::secret_password_store_sync; | 28 &::secret_password_store_sync) LibsecretLoader::secret_password_store_sync; |
| 18 decltype( | 29 decltype( |
| 19 &::secret_service_search_sync) LibsecretLoader::secret_service_search_sync; | 30 &::secret_service_search_sync) LibsecretLoader::secret_service_search_sync; |
| 20 decltype( | 31 decltype( |
| 21 &::secret_password_clear_sync) LibsecretLoader::secret_password_clear_sync; | 32 &::secret_password_clear_sync) LibsecretLoader::secret_password_clear_sync; |
| 22 decltype(&::secret_item_get_secret) LibsecretLoader::secret_item_get_secret; | 33 decltype(&::secret_item_get_secret) LibsecretLoader::secret_item_get_secret; |
| 23 decltype(&::secret_value_get_text) LibsecretLoader::secret_value_get_text; | 34 decltype(&::secret_value_get_text) LibsecretLoader::secret_value_get_text; |
| 24 decltype( | 35 decltype( |
| 25 &::secret_item_get_attributes) LibsecretLoader::secret_item_get_attributes; | 36 &::secret_item_get_attributes) LibsecretLoader::secret_item_get_attributes; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 &error); | 117 &error); |
| 107 bool success = (error == nullptr); | 118 bool success = (error == nullptr); |
| 108 if (error) | 119 if (error) |
| 109 g_error_free(error); | 120 g_error_free(error); |
| 110 if (found) | 121 if (found) |
| 111 g_list_free(found); | 122 g_list_free(found); |
| 112 | 123 |
| 113 return success; | 124 return success; |
| 114 } | 125 } |
| 115 | 126 |
| 127 // TODO(crbug.com/660005) This is needed to properly unlock the default keyring. |
| 128 // We don't need to ever read it. |
| 129 void LibsecretLoader::EnsureKeyringUnlocked() { |
| 130 const SecretSchema kDummySchema = { |
| 131 "_chrome_dummy_schema_for_unlocking", |
| 132 SECRET_SCHEMA_NONE, |
| 133 {{"explanation", SECRET_SCHEMA_ATTRIBUTE_STRING}, |
| 134 {nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}}; |
| 135 |
| 136 GError* error = nullptr; |
| 137 bool success = LibsecretLoader::secret_password_store_sync( |
| 138 &kDummySchema, nullptr /* default keyring */, |
| 139 "Chrome Safe Storage Control" /* entry title */, |
| 140 "The meaning of life" /* password */, nullptr, &error, "explanation", |
| 141 kExplanationMessage, |
| 142 nullptr /* null-terminated variable argument list */); |
| 143 if (error) { |
| 144 VLOG(1) << "Dummy store to unlock the default keyring failed: " |
| 145 << error->message; |
| 146 g_error_free(error); |
| 147 } else if (!success) { |
| 148 VLOG(1) << "Dummy store to unlock the default keyring failed."; |
| 149 } |
| 150 } |
| 151 |
| 116 // | 152 // |
| 117 // LibsecretAttributesBuilder | 153 // LibsecretAttributesBuilder |
| 118 // | 154 // |
| 119 | 155 |
| 120 LibsecretAttributesBuilder::LibsecretAttributesBuilder() { | 156 LibsecretAttributesBuilder::LibsecretAttributesBuilder() { |
| 121 attrs_ = g_hash_table_new_full(g_str_hash, g_str_equal, | 157 attrs_ = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 122 nullptr, // no deleter for keys | 158 nullptr, // no deleter for keys |
| 123 nullptr); // no deleter for values | 159 nullptr); // no deleter for values |
| 124 } | 160 } |
| 125 | 161 |
| 126 LibsecretAttributesBuilder::~LibsecretAttributesBuilder() { | 162 LibsecretAttributesBuilder::~LibsecretAttributesBuilder() { |
| 127 g_hash_table_destroy(attrs_); | 163 g_hash_table_destroy(attrs_); |
| 128 } | 164 } |
| 129 | 165 |
| 130 void LibsecretAttributesBuilder::Append(const std::string& name, | 166 void LibsecretAttributesBuilder::Append(const std::string& name, |
| 131 const std::string& value) { | 167 const std::string& value) { |
| 132 name_values_.push_back(name); | 168 name_values_.push_back(name); |
| 133 gpointer name_str = | 169 gpointer name_str = |
| 134 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); | 170 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); |
| 135 name_values_.push_back(value); | 171 name_values_.push_back(value); |
| 136 gpointer value_str = | 172 gpointer value_str = |
| 137 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); | 173 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); |
| 138 g_hash_table_insert(attrs_, name_str, value_str); | 174 g_hash_table_insert(attrs_, name_str, value_str); |
| 139 } | 175 } |
| 140 | 176 |
| 141 void LibsecretAttributesBuilder::Append(const std::string& name, | 177 void LibsecretAttributesBuilder::Append(const std::string& name, |
| 142 int64_t value) { | 178 int64_t value) { |
| 143 Append(name, base::Int64ToString(value)); | 179 Append(name, base::Int64ToString(value)); |
| 144 } | 180 } |
| OLD | NEW |