OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 "chrome/browser/password_manager/native_backend_libsecret.h" | 5 #include "chrome/browser/password_manager/native_backend_libsecret.h" |
6 | 6 |
7 #include <dlfcn.h> | 7 #include <dlfcn.h> |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
8 #include <list> | 10 #include <list> |
9 | 11 |
10 #include "base/basictypes.h" | |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" | 18 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" |
18 #include "components/password_manager/core/browser/password_manager_util.h" | 19 #include "components/password_manager/core/browser/password_manager_util.h" |
19 | 20 |
20 using autofill::PasswordForm; | 21 using autofill::PasswordForm; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 UTF8ToUTF16(GetStringFromAttributes(attrs, "username_element")); | 154 UTF8ToUTF16(GetStringFromAttributes(attrs, "username_element")); |
154 form->username_value = | 155 form->username_value = |
155 UTF8ToUTF16(GetStringFromAttributes(attrs, "username_value")); | 156 UTF8ToUTF16(GetStringFromAttributes(attrs, "username_value")); |
156 form->password_element = | 157 form->password_element = |
157 UTF8ToUTF16(GetStringFromAttributes(attrs, "password_element")); | 158 UTF8ToUTF16(GetStringFromAttributes(attrs, "password_element")); |
158 form->submit_element = | 159 form->submit_element = |
159 UTF8ToUTF16(GetStringFromAttributes(attrs, "submit_element")); | 160 UTF8ToUTF16(GetStringFromAttributes(attrs, "submit_element")); |
160 form->signon_realm = GetStringFromAttributes(attrs, "signon_realm"); | 161 form->signon_realm = GetStringFromAttributes(attrs, "signon_realm"); |
161 form->ssl_valid = GetUintFromAttributes(attrs, "ssl_valid"); | 162 form->ssl_valid = GetUintFromAttributes(attrs, "ssl_valid"); |
162 form->preferred = GetUintFromAttributes(attrs, "preferred"); | 163 form->preferred = GetUintFromAttributes(attrs, "preferred"); |
163 int64 date_created = 0; | 164 int64_t date_created = 0; |
164 bool date_ok = base::StringToInt64( | 165 bool date_ok = base::StringToInt64( |
165 GetStringFromAttributes(attrs, "date_created"), &date_created); | 166 GetStringFromAttributes(attrs, "date_created"), &date_created); |
166 DCHECK(date_ok); | 167 DCHECK(date_ok); |
167 // In the past |date_created| was stored as time_t. Currently is stored as | 168 // In the past |date_created| was stored as time_t. Currently is stored as |
168 // base::Time's internal value. We need to distinguish, which format the | 169 // base::Time's internal value. We need to distinguish, which format the |
169 // number in |date_created| was stored in. We use the fact that | 170 // number in |date_created| was stored in. We use the fact that |
170 // kMaxPossibleTimeTValue interpreted as the internal value corresponds to an | 171 // kMaxPossibleTimeTValue interpreted as the internal value corresponds to an |
171 // unlikely date back in 17th century, and anything above | 172 // unlikely date back in 17th century, and anything above |
172 // kMaxPossibleTimeTValue clearly must be in the internal value format. | 173 // kMaxPossibleTimeTValue clearly must be in the internal value format. |
173 form->date_created = date_created < kMaxPossibleTimeTValue | 174 form->date_created = date_created < kMaxPossibleTimeTValue |
174 ? base::Time::FromTimeT(date_created) | 175 ? base::Time::FromTimeT(date_created) |
175 : base::Time::FromInternalValue(date_created); | 176 : base::Time::FromInternalValue(date_created); |
176 form->blacklisted_by_user = | 177 form->blacklisted_by_user = |
177 GetUintFromAttributes(attrs, "blacklisted_by_user"); | 178 GetUintFromAttributes(attrs, "blacklisted_by_user"); |
178 form->type = | 179 form->type = |
179 static_cast<PasswordForm::Type>(GetUintFromAttributes(attrs, "type")); | 180 static_cast<PasswordForm::Type>(GetUintFromAttributes(attrs, "type")); |
180 form->times_used = GetUintFromAttributes(attrs, "times_used"); | 181 form->times_used = GetUintFromAttributes(attrs, "times_used"); |
181 form->scheme = | 182 form->scheme = |
182 static_cast<PasswordForm::Scheme>(GetUintFromAttributes(attrs, "scheme")); | 183 static_cast<PasswordForm::Scheme>(GetUintFromAttributes(attrs, "scheme")); |
183 int64 date_synced = 0; | 184 int64_t date_synced = 0; |
184 base::StringToInt64(GetStringFromAttributes(attrs, "date_synced"), | 185 base::StringToInt64(GetStringFromAttributes(attrs, "date_synced"), |
185 &date_synced); | 186 &date_synced); |
186 form->date_synced = base::Time::FromInternalValue(date_synced); | 187 form->date_synced = base::Time::FromInternalValue(date_synced); |
187 form->display_name = | 188 form->display_name = |
188 UTF8ToUTF16(GetStringFromAttributes(attrs, "display_name")); | 189 UTF8ToUTF16(GetStringFromAttributes(attrs, "display_name")); |
189 form->icon_url = GURL(GetStringFromAttributes(attrs, "avatar_url")); | 190 form->icon_url = GURL(GetStringFromAttributes(attrs, "avatar_url")); |
190 form->federation_url = GURL(GetStringFromAttributes(attrs, "federation_url")); | 191 form->federation_url = GURL(GetStringFromAttributes(attrs, "federation_url")); |
191 form->skip_zero_click = GetUintFromAttributes(attrs, "skip_zero_click"); | 192 form->skip_zero_click = GetUintFromAttributes(attrs, "skip_zero_click"); |
192 form->generation_upload_status = | 193 form->generation_upload_status = |
193 static_cast<PasswordForm::GenerationUploadStatus>( | 194 static_cast<PasswordForm::GenerationUploadStatus>( |
194 GetUintFromAttributes(attrs, "generation_upload_status")); | 195 GetUintFromAttributes(attrs, "generation_upload_status")); |
195 base::StringPiece encoded_form_data = | 196 base::StringPiece encoded_form_data = |
196 GetStringFromAttributes(attrs, "form_data"); | 197 GetStringFromAttributes(attrs, "form_data"); |
197 if (!encoded_form_data.empty()) { | 198 if (!encoded_form_data.empty()) { |
198 bool success = DeserializeFormDataFromBase64String(encoded_form_data, | 199 bool success = DeserializeFormDataFromBase64String(encoded_form_data, |
199 &form->form_data); | 200 &form->form_data); |
200 password_manager::metrics_util::FormDeserializationStatus status = | 201 password_manager::metrics_util::FormDeserializationStatus status = |
201 success ? password_manager::metrics_util::GNOME_SUCCESS | 202 success ? password_manager::metrics_util::GNOME_SUCCESS |
202 : password_manager::metrics_util::GNOME_FAILURE; | 203 : password_manager::metrics_util::GNOME_FAILURE; |
203 LogFormDataDeserializationStatus(status); | 204 LogFormDataDeserializationStatus(status); |
204 } | 205 } |
205 return form.Pass(); | 206 return form.Pass(); |
206 } | 207 } |
207 | 208 |
208 class LibsecretAttributesBuilder { | 209 class LibsecretAttributesBuilder { |
209 public: | 210 public: |
210 LibsecretAttributesBuilder(); | 211 LibsecretAttributesBuilder(); |
211 ~LibsecretAttributesBuilder(); | 212 ~LibsecretAttributesBuilder(); |
212 void Append(const std::string& name, const std::string& value); | 213 void Append(const std::string& name, const std::string& value); |
213 void Append(const std::string& name, int64 value); | 214 void Append(const std::string& name, int64_t value); |
214 // GHashTable, its keys and values returned from Get() are destroyed in | 215 // GHashTable, its keys and values returned from Get() are destroyed in |
215 // |LibsecretAttributesBuilder| desctructor. | 216 // |LibsecretAttributesBuilder| desctructor. |
216 GHashTable* Get() { return attrs_; } | 217 GHashTable* Get() { return attrs_; } |
217 | 218 |
218 private: | 219 private: |
219 // |name_values_| is a storage for strings referenced in |attrs_|. | 220 // |name_values_| is a storage for strings referenced in |attrs_|. |
220 std::list<std::string> name_values_; | 221 std::list<std::string> name_values_; |
221 GHashTable* attrs_; | 222 GHashTable* attrs_; |
222 }; | 223 }; |
223 | 224 |
(...skipping 11 matching lines...) Expand all Loading... |
235 const std::string& value) { | 236 const std::string& value) { |
236 name_values_.push_back(name); | 237 name_values_.push_back(name); |
237 gpointer name_str = | 238 gpointer name_str = |
238 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); | 239 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); |
239 name_values_.push_back(value); | 240 name_values_.push_back(value); |
240 gpointer value_str = | 241 gpointer value_str = |
241 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); | 242 static_cast<gpointer>(const_cast<char*>(name_values_.back().c_str())); |
242 g_hash_table_insert(attrs_, name_str, value_str); | 243 g_hash_table_insert(attrs_, name_str, value_str); |
243 } | 244 } |
244 | 245 |
245 void LibsecretAttributesBuilder::Append(const std::string& name, int64 value) { | 246 void LibsecretAttributesBuilder::Append(const std::string& name, |
| 247 int64_t value) { |
246 Append(name, base::Int64ToString(value)); | 248 Append(name, base::Int64ToString(value)); |
247 } | 249 } |
248 | 250 |
249 // Generates a profile-specific app string based on profile_id_. | 251 // Generates a profile-specific app string based on profile_id_. |
250 std::string GetProfileSpecificAppString(LocalProfileId id) { | 252 std::string GetProfileSpecificAppString(LocalProfileId id) { |
251 // Originally, the application string was always just "chrome" and used only | 253 // Originally, the application string was always just "chrome" and used only |
252 // so that we had *something* to search for since GNOME Keyring won't search | 254 // so that we had *something* to search for since GNOME Keyring won't search |
253 // for nothing. Now we use it to distinguish passwords for different profiles. | 255 // for nothing. Now we use it to distinguish passwords for different profiles. |
254 return base::StringPrintf("%s-%d", kLibsecretAppString, id); | 256 return base::StringPrintf("%s-%d", kLibsecretAppString, id); |
255 } | 257 } |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 if (found) | 428 if (found) |
427 g_list_free(found); | 429 g_list_free(found); |
428 return false; | 430 return false; |
429 } | 431 } |
430 | 432 |
431 *forms = ConvertFormList(found, &lookup_form); | 433 *forms = ConvertFormList(found, &lookup_form); |
432 return true; | 434 return true; |
433 } | 435 } |
434 | 436 |
435 bool NativeBackendLibsecret::RawAddLogin(const PasswordForm& form) { | 437 bool NativeBackendLibsecret::RawAddLogin(const PasswordForm& form) { |
436 int64 date_created = form.date_created.ToInternalValue(); | 438 int64_t date_created = form.date_created.ToInternalValue(); |
437 // If we are asked to save a password with 0 date, use the current time. | 439 // If we are asked to save a password with 0 date, use the current time. |
438 // We don't want to actually save passwords as though on January 1, 1601. | 440 // We don't want to actually save passwords as though on January 1, 1601. |
439 if (!date_created) | 441 if (!date_created) |
440 date_created = base::Time::Now().ToInternalValue(); | 442 date_created = base::Time::Now().ToInternalValue(); |
441 int64 date_synced = form.date_synced.ToInternalValue(); | 443 int64_t date_synced = form.date_synced.ToInternalValue(); |
442 std::string form_data; | 444 std::string form_data; |
443 SerializeFormDataToBase64String(form.form_data, &form_data); | 445 SerializeFormDataToBase64String(form.form_data, &form_data); |
444 GError* error = nullptr; | 446 GError* error = nullptr; |
445 secret_password_store_sync( | 447 secret_password_store_sync( |
446 &kLibsecretSchema, | 448 &kLibsecretSchema, |
447 nullptr, // Default collection. | 449 nullptr, // Default collection. |
448 form.origin.spec().c_str(), // Display name. | 450 form.origin.spec().c_str(), // Display name. |
449 UTF16ToUTF8(form.password_value).c_str(), | 451 UTF16ToUTF8(form.password_value).c_str(), |
450 nullptr, // no cancellable ojbect | 452 nullptr, // no cancellable ojbect |
451 &error, | 453 &error, |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 UMA_HISTOGRAM_ENUMERATION( | 638 UMA_HISTOGRAM_ENUMERATION( |
637 "PasswordManager.PslDomainMatchTriggering", | 639 "PasswordManager.PslDomainMatchTriggering", |
638 password_manager::ShouldPSLDomainMatchingApply(registered_domain) | 640 password_manager::ShouldPSLDomainMatchingApply(registered_domain) |
639 ? psl_domain_match_metric | 641 ? psl_domain_match_metric |
640 : password_manager::PSL_DOMAIN_MATCH_NOT_USED, | 642 : password_manager::PSL_DOMAIN_MATCH_NOT_USED, |
641 password_manager::PSL_DOMAIN_MATCH_COUNT); | 643 password_manager::PSL_DOMAIN_MATCH_COUNT); |
642 } | 644 } |
643 g_list_free(found); | 645 g_list_free(found); |
644 return forms.Pass(); | 646 return forms.Pass(); |
645 } | 647 } |
OLD | NEW |