Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <libsecret/secret.h> | 10 #include <libsecret/secret.h> |
| 11 | 11 |
| 12 #include <limits> | 12 #include <limits> |
| 13 #include <list> | 13 #include <list> |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <utility> | 15 #include <utility> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "components/password_manager/core/browser/password_manager_metrics_util .h" | 23 #include "components/password_manager/core/browser/password_manager_metrics_util .h" |
| 24 #include "components/password_manager/core/browser/password_manager_util.h" | 24 #include "components/password_manager/core/browser/password_manager_util.h" |
| 25 #include "url/origin.h" | 25 #include "url/origin.h" |
| 26 | 26 |
| 27 using autofill::PasswordForm; | 27 using autofill::PasswordForm; |
| 28 using base::UTF8ToUTF16; | 28 using base::UTF8ToUTF16; |
| 29 using base::UTF16ToUTF8; | 29 using base::UTF16ToUTF8; |
| 30 using password_manager::PasswordStore; | |
| 30 | 31 |
| 31 namespace { | 32 namespace { |
| 32 const char kEmptyString[] = ""; | 33 const char kEmptyString[] = ""; |
| 33 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max(); | 34 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max(); |
| 34 } // namespace | 35 } // namespace |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 const char kLibsecretAppString[] = "chrome"; | 39 const char kLibsecretAppString[] = "chrome"; |
| 39 | 40 |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 form->skip_zero_click = true; | 292 form->skip_zero_click = true; |
| 292 if (!UpdateLogin(*form, changes)) | 293 if (!UpdateLogin(*form, changes)) |
| 293 return false; | 294 return false; |
| 294 } | 295 } |
| 295 } | 296 } |
| 296 | 297 |
| 297 return true; | 298 return true; |
| 298 } | 299 } |
| 299 | 300 |
| 300 bool NativeBackendLibsecret::GetLogins( | 301 bool NativeBackendLibsecret::GetLogins( |
| 301 const PasswordForm& form, | 302 const PasswordStore::FormDigest& form, |
| 302 ScopedVector<autofill::PasswordForm>* forms) { | 303 ScopedVector<autofill::PasswordForm>* forms) { |
| 303 return GetLoginsList(&form, ALL_LOGINS, forms); | 304 return GetLoginsList(&form, ALL_LOGINS, forms); |
| 304 } | 305 } |
| 305 | 306 |
| 306 bool NativeBackendLibsecret::AddUpdateLoginSearch( | 307 bool NativeBackendLibsecret::AddUpdateLoginSearch( |
| 307 const autofill::PasswordForm& lookup_form, | 308 const autofill::PasswordForm& lookup_form, |
| 308 ScopedVector<autofill::PasswordForm>* forms) { | 309 ScopedVector<autofill::PasswordForm>* forms) { |
| 309 LibsecretAttributesBuilder attrs; | 310 LibsecretAttributesBuilder attrs; |
| 310 attrs.Append("origin_url", lookup_form.origin.spec()); | 311 attrs.Append("origin_url", lookup_form.origin.spec()); |
| 311 attrs.Append("username_element", UTF16ToUTF8(lookup_form.username_element)); | 312 attrs.Append("username_element", UTF16ToUTF8(lookup_form.username_element)); |
| 312 attrs.Append("username_value", UTF16ToUTF8(lookup_form.username_value)); | 313 attrs.Append("username_value", UTF16ToUTF8(lookup_form.username_value)); |
| 313 attrs.Append("password_element", UTF16ToUTF8(lookup_form.password_element)); | 314 attrs.Append("password_element", UTF16ToUTF8(lookup_form.password_element)); |
| 314 attrs.Append("signon_realm", lookup_form.signon_realm); | 315 attrs.Append("signon_realm", lookup_form.signon_realm); |
| 315 attrs.Append("application", app_string_); | 316 attrs.Append("application", app_string_); |
| 316 | 317 |
| 317 GError* error = nullptr; | 318 GError* error = nullptr; |
| 318 GList* found = LibsecretLoader::secret_service_search_sync( | 319 GList* found = LibsecretLoader::secret_service_search_sync( |
| 319 nullptr, // default secret service | 320 nullptr, // default secret service |
| 320 &kLibsecretSchema, attrs.Get(), SECRET_SEARCH_ALL, | 321 &kLibsecretSchema, attrs.Get(), SECRET_SEARCH_ALL, |
| 321 nullptr, // no cancellable ojbect | 322 nullptr, // no cancellable ojbect |
| 322 &error); | 323 &error); |
| 323 if (error) { | 324 if (error) { |
| 324 LOG(ERROR) << "Unable to get logins " << error->message; | 325 LOG(ERROR) << "Unable to get logins " << error->message; |
| 325 g_error_free(error); | 326 g_error_free(error); |
| 326 if (found) | 327 if (found) |
| 327 g_list_free(found); | 328 g_list_free(found); |
| 328 return false; | 329 return false; |
| 329 } | 330 } |
| 330 | 331 |
| 331 *forms = ConvertFormList(found, &lookup_form); | 332 PasswordStore::FormDigest form = { |
|
dvadym
2016/07/20 13:43:02
nit: Why don't to use constructor of FormDigest th
vabr (Chromium)
2016/07/20 14:13:06
Done.
| |
| 333 lookup_form.scheme, lookup_form.signon_realm, lookup_form.origin}; | |
| 334 *forms = ConvertFormList(found, &form); | |
| 332 return true; | 335 return true; |
| 333 } | 336 } |
| 334 | 337 |
| 335 bool NativeBackendLibsecret::RawAddLogin(const PasswordForm& form) { | 338 bool NativeBackendLibsecret::RawAddLogin(const PasswordForm& form) { |
| 336 int64_t date_created = form.date_created.ToInternalValue(); | 339 int64_t date_created = form.date_created.ToInternalValue(); |
| 337 // If we are asked to save a password with 0 date, use the current time. | 340 // If we are asked to save a password with 0 date, use the current time. |
| 338 // We don't want to actually save passwords as though on January 1, 1601. | 341 // We don't want to actually save passwords as though on January 1, 1601. |
| 339 if (!date_created) | 342 if (!date_created) |
| 340 date_created = base::Time::Now().ToInternalValue(); | 343 date_created = base::Time::Now().ToInternalValue(); |
| 341 int64_t date_synced = form.date_synced.ToInternalValue(); | 344 int64_t date_synced = form.date_synced.ToInternalValue(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 395 ScopedVector<autofill::PasswordForm>* forms) { | 398 ScopedVector<autofill::PasswordForm>* forms) { |
| 396 return GetLoginsList(nullptr, BLACKLISTED_LOGINS, forms); | 399 return GetLoginsList(nullptr, BLACKLISTED_LOGINS, forms); |
| 397 } | 400 } |
| 398 | 401 |
| 399 bool NativeBackendLibsecret::GetAllLogins( | 402 bool NativeBackendLibsecret::GetAllLogins( |
| 400 ScopedVector<autofill::PasswordForm>* forms) { | 403 ScopedVector<autofill::PasswordForm>* forms) { |
| 401 return GetLoginsList(nullptr, ALL_LOGINS, forms); | 404 return GetLoginsList(nullptr, ALL_LOGINS, forms); |
| 402 } | 405 } |
| 403 | 406 |
| 404 bool NativeBackendLibsecret::GetLoginsList( | 407 bool NativeBackendLibsecret::GetLoginsList( |
| 405 const PasswordForm* lookup_form, | 408 const PasswordStore::FormDigest* lookup_form, |
| 406 GetLoginsListOptions options, | 409 GetLoginsListOptions options, |
| 407 ScopedVector<autofill::PasswordForm>* forms) { | 410 ScopedVector<autofill::PasswordForm>* forms) { |
| 408 LibsecretAttributesBuilder attrs; | 411 LibsecretAttributesBuilder attrs; |
| 409 attrs.Append("application", app_string_); | 412 attrs.Append("application", app_string_); |
| 410 if (options != ALL_LOGINS) | 413 if (options != ALL_LOGINS) |
| 411 attrs.Append("blacklisted_by_user", options == BLACKLISTED_LOGINS); | 414 attrs.Append("blacklisted_by_user", options == BLACKLISTED_LOGINS); |
| 412 if (lookup_form && | 415 if (lookup_form && |
| 413 !password_manager::ShouldPSLDomainMatchingApply( | 416 !password_manager::ShouldPSLDomainMatchingApply( |
| 414 password_manager::GetRegistryControlledDomain( | 417 password_manager::GetRegistryControlledDomain( |
| 415 GURL(lookup_form->signon_realm))) && | 418 GURL(lookup_form->signon_realm))) && |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 | 494 |
| 492 for (size_t i = 0; i < forms.size(); ++i) { | 495 for (size_t i = 0; i < forms.size(); ++i) { |
| 493 if (!RemoveLogin(*forms[i], changes)) | 496 if (!RemoveLogin(*forms[i], changes)) |
| 494 return false; | 497 return false; |
| 495 } | 498 } |
| 496 return true; | 499 return true; |
| 497 } | 500 } |
| 498 | 501 |
| 499 ScopedVector<autofill::PasswordForm> NativeBackendLibsecret::ConvertFormList( | 502 ScopedVector<autofill::PasswordForm> NativeBackendLibsecret::ConvertFormList( |
| 500 GList* found, | 503 GList* found, |
| 501 const PasswordForm* lookup_form) { | 504 const PasswordStore::FormDigest* lookup_form) { |
| 502 ScopedVector<autofill::PasswordForm> forms; | 505 ScopedVector<autofill::PasswordForm> forms; |
| 503 password_manager::PSLDomainMatchMetric psl_domain_match_metric = | 506 password_manager::PSLDomainMatchMetric psl_domain_match_metric = |
| 504 password_manager::PSL_DOMAIN_MATCH_NONE; | 507 password_manager::PSL_DOMAIN_MATCH_NONE; |
| 505 GError* error = nullptr; | 508 GError* error = nullptr; |
| 506 const bool allow_psl_match = | 509 const bool allow_psl_match = |
| 507 lookup_form && password_manager::ShouldPSLDomainMatchingApply( | 510 lookup_form && password_manager::ShouldPSLDomainMatchingApply( |
| 508 password_manager::GetRegistryControlledDomain( | 511 password_manager::GetRegistryControlledDomain( |
| 509 GURL(lookup_form->signon_realm))); | 512 GURL(lookup_form->signon_realm))); |
| 510 for (GList* element = g_list_first(found); element != nullptr; | 513 for (GList* element = g_list_first(found); element != nullptr; |
| 511 element = g_list_next(element)) { | 514 element = g_list_next(element)) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 556 if (lookup_form) { | 559 if (lookup_form) { |
| 557 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", | 560 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", |
| 558 allow_psl_match | 561 allow_psl_match |
| 559 ? psl_domain_match_metric | 562 ? psl_domain_match_metric |
| 560 : password_manager::PSL_DOMAIN_MATCH_NOT_USED, | 563 : password_manager::PSL_DOMAIN_MATCH_NOT_USED, |
| 561 password_manager::PSL_DOMAIN_MATCH_COUNT); | 564 password_manager::PSL_DOMAIN_MATCH_COUNT); |
| 562 } | 565 } |
| 563 g_list_free(found); | 566 g_list_free(found); |
| 564 return forms; | 567 return forms; |
| 565 } | 568 } |
| OLD | NEW |