| 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 VLOG(1) << "Adding dummy entry to keyring to ensure that it unlocked " |
| 131 "properly."; |
| 132 |
| 133 const SecretSchema kDummySchema = { |
| 134 "_chrome_dummy_schema_for_unlocking", |
| 135 SECRET_SCHEMA_NONE, |
| 136 {{"explanation", SECRET_SCHEMA_ATTRIBUTE_STRING}, |
| 137 {nullptr, SECRET_SCHEMA_ATTRIBUTE_STRING}}}; |
| 138 |
| 139 GError* error = nullptr; |
| 140 bool success = LibsecretLoader::secret_password_store_sync( |
| 141 &kDummySchema, nullptr /* default keyring */, |
| 142 "Chrome Safe Storage Control" /* entry title */, |
| 143 "The meaning of life" /* password */, nullptr, &error, "explanation", |
| 144 kExplanationMessage, |
| 145 nullptr /* null-terminated variable argument list */); |
| 146 if (error) { |
| 147 VLOG(1) << "Dummy store to unlock the default keyring failed: " |
| 148 << error->message; |
| 149 g_error_free(error); |
| 150 } |
| 151 if (!success) |
| 152 VLOG(1) << "Dummy store to unlock the default keyring failed."; |
| 153 } |
| 154 |
| 116 // | 155 // |
| 117 // LibsecretAttributesBuilder | 156 // LibsecretAttributesBuilder |
| 118 // | 157 // |
| 119 | 158 |
| 120 LibsecretAttributesBuilder::LibsecretAttributesBuilder() { | 159 LibsecretAttributesBuilder::LibsecretAttributesBuilder() { |
| 121 attrs_ = g_hash_table_new_full(g_str_hash, g_str_equal, | 160 attrs_ = g_hash_table_new_full(g_str_hash, g_str_equal, |
| 122 nullptr, // no deleter for keys | 161 nullptr, // no deleter for keys |
| 123 nullptr); // no deleter for values | 162 nullptr); // no deleter for values |
| 124 } | 163 } |
| 125 | 164 |
| 126 LibsecretAttributesBuilder::~LibsecretAttributesBuilder() { | 165 LibsecretAttributesBuilder::~LibsecretAttributesBuilder() { |
| 127 g_hash_table_destroy(attrs_); | 166 g_hash_table_destroy(attrs_); |
| 128 } | 167 } |
| 129 | 168 |
| 130 void LibsecretAttributesBuilder::Append(const std::string& name, | 169 void LibsecretAttributesBuilder::Append(const std::string& name, |
| 131 const std::string& value) { | 170 const std::string& value) { |
| 132 name_values_.push_back(name); | 171 name_values_.push_back(name); |
| 133 gpointer name_str = | 172 gpointer name_str = |
| 134 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); | 173 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); |
| 135 name_values_.push_back(value); | 174 name_values_.push_back(value); |
| 136 gpointer value_str = | 175 gpointer value_str = |
| 137 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); | 176 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); |
| 138 g_hash_table_insert(attrs_, name_str, value_str); | 177 g_hash_table_insert(attrs_, name_str, value_str); |
| 139 } | 178 } |
| 140 | 179 |
| 141 void LibsecretAttributesBuilder::Append(const std::string& name, | 180 void LibsecretAttributesBuilder::Append(const std::string& name, |
| 142 int64_t value) { | 181 int64_t value) { |
| 143 Append(name, base::Int64ToString(value)); | 182 Append(name, base::Int64ToString(value)); |
| 144 } | 183 } |
| OLD | NEW |