Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: chrome/browser/password_manager/native_backend_libsecret.cc

Issue 2652243002: Implement Federated PSL Matches in Native Backends (Closed)
Patch Set: Addressed comments. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_macros.h" 19 #include "base/metrics/histogram_macros.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::MatchResult;
30 using password_manager::PasswordStore; 31 using password_manager::PasswordStore;
31 32
32 namespace { 33 namespace {
33 const char kEmptyString[] = ""; 34 const char kEmptyString[] = "";
34 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max(); 35 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max();
35 } // namespace 36 } // namespace
36 37
37 namespace { 38 namespace {
38 39
39 const char kLibsecretAppString[] = "chrome"; 40 const char kLibsecretAppString[] = "chrome";
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 510 }
510 511
511 std::vector<std::unique_ptr<PasswordForm>> 512 std::vector<std::unique_ptr<PasswordForm>>
512 NativeBackendLibsecret::ConvertFormList( 513 NativeBackendLibsecret::ConvertFormList(
513 GList* found, 514 GList* found,
514 const PasswordStore::FormDigest* lookup_form) { 515 const PasswordStore::FormDigest* lookup_form) {
515 std::vector<std::unique_ptr<PasswordForm>> forms; 516 std::vector<std::unique_ptr<PasswordForm>> forms;
516 password_manager::PSLDomainMatchMetric psl_domain_match_metric = 517 password_manager::PSLDomainMatchMetric psl_domain_match_metric =
517 password_manager::PSL_DOMAIN_MATCH_NONE; 518 password_manager::PSL_DOMAIN_MATCH_NONE;
518 GError* error = nullptr; 519 GError* error = nullptr;
519 const bool allow_psl_match =
520 lookup_form && password_manager::ShouldPSLDomainMatchingApply(
521 password_manager::GetRegistryControlledDomain(
522 GURL(lookup_form->signon_realm)));
523 for (GList* element = g_list_first(found); element != nullptr; 520 for (GList* element = g_list_first(found); element != nullptr;
524 element = g_list_next(element)) { 521 element = g_list_next(element)) {
525 SecretItem* secretItem = static_cast<SecretItem*>(element->data); 522 SecretItem* secretItem = static_cast<SecretItem*>(element->data);
526 LibsecretLoader::secret_item_load_secret_sync(secretItem, nullptr, &error); 523 LibsecretLoader::secret_item_load_secret_sync(secretItem, nullptr, &error);
527 if (error) { 524 if (error) {
528 LOG(ERROR) << "Unable to load secret item" << error->message; 525 LOG(ERROR) << "Unable to load secret item" << error->message;
529 g_error_free(error); 526 g_error_free(error);
530 error = nullptr; 527 error = nullptr;
531 continue; 528 continue;
532 } 529 }
533 GHashTable* attrs = LibsecretLoader::secret_item_get_attributes(secretItem); 530 GHashTable* attrs = LibsecretLoader::secret_item_get_attributes(secretItem);
534 std::unique_ptr<PasswordForm> form(FormOutOfAttributes(attrs)); 531 std::unique_ptr<PasswordForm> form(FormOutOfAttributes(attrs));
535 g_hash_table_unref(attrs); 532 g_hash_table_unref(attrs);
536 if (form) { 533 if (!form) {
537 if (lookup_form && form->signon_realm != lookup_form->signon_realm) { 534 VLOG(1) << "Could not initialize PasswordForm from attributes!";
538 if (lookup_form->scheme != PasswordForm::SCHEME_HTML || 535 continue;
539 form->scheme != PasswordForm::SCHEME_HTML) 536 }
537
538 if (lookup_form) {
539 switch (GetMatchResult(*form, *lookup_form)) {
540 case MatchResult::NO_MATCH:
540 continue; 541 continue;
541 // This is not an exact match, we try PSL matching and federated match. 542 case MatchResult::EXACT_MATCH:
542 if (allow_psl_match && 543 break;
543 password_manager::IsPublicSuffixDomainMatch( 544 case MatchResult::PSL_MATCH:
544 form->signon_realm, lookup_form->signon_realm)) {
545 psl_domain_match_metric = password_manager::PSL_DOMAIN_MATCH_FOUND; 545 psl_domain_match_metric = password_manager::PSL_DOMAIN_MATCH_FOUND;
546 form->is_public_suffix_match = true; 546 form->is_public_suffix_match = true;
547 } else if (!form->federation_origin.unique() && 547 break;
548 password_manager::IsFederatedMatch(form->signon_realm, 548 case MatchResult::FEDERATED_MATCH:
549 lookup_form->origin)) { 549 break;
550 } else { 550 case MatchResult::FEDERATED_PSL_MATCH:
551 continue; 551 psl_domain_match_metric =
552 } 552 password_manager::PSL_DOMAIN_MATCH_FOUND_FEDERATED;
553 form->is_public_suffix_match = true;
554 break;
553 } 555 }
554 SecretValue* secretValue = 556 }
555 LibsecretLoader::secret_item_get_secret(secretItem); 557
556 if (secretValue) { 558 SecretValue* secretValue =
557 form->password_value = 559 LibsecretLoader::secret_item_get_secret(secretItem);
558 UTF8ToUTF16(LibsecretLoader::secret_value_get_text(secretValue)); 560 if (secretValue) {
559 LibsecretLoader::secret_value_unref(secretValue); 561 form->password_value =
560 } else { 562 UTF8ToUTF16(LibsecretLoader::secret_value_get_text(secretValue));
561 LOG(WARNING) << "Unable to access password from list element!"; 563 LibsecretLoader::secret_value_unref(secretValue);
562 }
563 forms.push_back(std::move(form));
564 } else { 564 } else {
565 VLOG(1) << "Could not initialize PasswordForm from attributes!"; 565 LOG(WARNING) << "Unable to access password from list element!";
566 } 566 }
567 forms.push_back(std::move(form));
567 } 568 }
568 569
569 if (lookup_form) { 570 if (lookup_form) {
571 const bool allow_psl_match = password_manager::ShouldPSLDomainMatchingApply(
572 password_manager::GetRegistryControlledDomain(
573 GURL(lookup_form->signon_realm)));
570 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", 574 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering",
571 allow_psl_match 575 allow_psl_match
572 ? psl_domain_match_metric 576 ? psl_domain_match_metric
573 : password_manager::PSL_DOMAIN_MATCH_NOT_USED, 577 : password_manager::PSL_DOMAIN_MATCH_NOT_USED,
574 password_manager::PSL_DOMAIN_MATCH_COUNT); 578 password_manager::PSL_DOMAIN_MATCH_COUNT);
575 } 579 }
576 g_list_free(found); 580 g_list_free(found);
577 return forms; 581 return forms;
578 } 582 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698