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

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

Issue 2133953002: PasswordForm -> FormDigest for GetLogins (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@413020_ssl_valid
Patch Set: Nits addressed Created 4 years, 5 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_gnome_x.h" 5 #include "chrome/browser/password_manager/native_backend_gnome_x.h"
6 6
7 #include <dlfcn.h> 7 #include <dlfcn.h>
8 #include <gnome-keyring.h> 8 #include <gnome-keyring.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
(...skipping 17 matching lines...) Expand all
28 #include "components/password_manager/core/browser/password_manager_metrics_util .h" 28 #include "components/password_manager/core/browser/password_manager_metrics_util .h"
29 #include "components/password_manager/core/browser/password_manager_util.h" 29 #include "components/password_manager/core/browser/password_manager_util.h"
30 #include "components/password_manager/core/browser/psl_matching_helper.h" 30 #include "components/password_manager/core/browser/psl_matching_helper.h"
31 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
32 32
33 using autofill::PasswordForm; 33 using autofill::PasswordForm;
34 using base::UTF8ToUTF16; 34 using base::UTF8ToUTF16;
35 using base::UTF16ToUTF8; 35 using base::UTF16ToUTF8;
36 using content::BrowserThread; 36 using content::BrowserThread;
37 using namespace password_manager::metrics_util; 37 using namespace password_manager::metrics_util;
38 using password_manager::PasswordStore;
38 39
39 namespace { 40 namespace {
40 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max(); 41 const int kMaxPossibleTimeTValue = std::numeric_limits<int>::max();
41 } 42 }
42 43
43 #define GNOME_KEYRING_DEFINE_POINTER(name) \ 44 #define GNOME_KEYRING_DEFINE_POINTER(name) \
44 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name; 45 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name;
45 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER) 46 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_DEFINE_POINTER)
46 #undef GNOME_KEYRING_DEFINE_POINTER 47 #undef GNOME_KEYRING_DEFINE_POINTER
47 48
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 175 }
175 return form; 176 return form;
176 } 177 }
177 178
178 // Converts native credentials in |found| to PasswordForms. If not NULL, 179 // Converts native credentials in |found| to PasswordForms. If not NULL,
179 // |lookup_form| is used to filter out results -- only credentials with signon 180 // |lookup_form| is used to filter out results -- only credentials with signon
180 // realms passing the PSL matching against |lookup_form->signon_realm| will be 181 // realms passing the PSL matching against |lookup_form->signon_realm| will be
181 // kept. PSL matched results get their signon_realm, origin, and action 182 // kept. PSL matched results get their signon_realm, origin, and action
182 // rewritten to those of |lookup_form_|, with the original signon_realm saved 183 // rewritten to those of |lookup_form_|, with the original signon_realm saved
183 // into the result's original_signon_realm data member. 184 // into the result's original_signon_realm data member.
184 ScopedVector<PasswordForm> ConvertFormList(GList* found, 185 ScopedVector<PasswordForm> ConvertFormList(
185 const PasswordForm* lookup_form) { 186 GList* found,
187 const PasswordStore::FormDigest* lookup_form) {
186 ScopedVector<PasswordForm> forms; 188 ScopedVector<PasswordForm> forms;
187 password_manager::PSLDomainMatchMetric psl_domain_match_metric = 189 password_manager::PSLDomainMatchMetric psl_domain_match_metric =
188 password_manager::PSL_DOMAIN_MATCH_NONE; 190 password_manager::PSL_DOMAIN_MATCH_NONE;
189 const bool allow_psl_match = 191 const bool allow_psl_match =
190 lookup_form && password_manager::ShouldPSLDomainMatchingApply( 192 lookup_form && password_manager::ShouldPSLDomainMatchingApply(
191 password_manager::GetRegistryControlledDomain( 193 password_manager::GetRegistryControlledDomain(
192 GURL(lookup_form->signon_realm))); 194 GURL(lookup_form->signon_realm)));
193 for (GList* element = g_list_first(found); element; 195 for (GList* element = g_list_first(found); element;
194 element = g_list_next(element)) { 196 element = g_list_next(element)) {
195 GnomeKeyringFound* data = static_cast<GnomeKeyringFound*>(element->data); 197 GnomeKeyringFound* data = static_cast<GnomeKeyringFound*>(element->data);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 GKRMethod() 284 GKRMethod()
283 : event_(base::WaitableEvent::ResetPolicy::AUTOMATIC, 285 : event_(base::WaitableEvent::ResetPolicy::AUTOMATIC,
284 base::WaitableEvent::InitialState::NOT_SIGNALED), 286 base::WaitableEvent::InitialState::NOT_SIGNALED),
285 result_(GNOME_KEYRING_RESULT_CANCELLED) {} 287 result_(GNOME_KEYRING_RESULT_CANCELLED) {}
286 288
287 // Action methods. These call gnome_keyring_* functions. Call from UI thread. 289 // Action methods. These call gnome_keyring_* functions. Call from UI thread.
288 // See GetProfileSpecificAppString() for more information on the app string. 290 // See GetProfileSpecificAppString() for more information on the app string.
289 void AddLogin(const PasswordForm& form, const char* app_string); 291 void AddLogin(const PasswordForm& form, const char* app_string);
290 void LoginSearch(const PasswordForm& form, const char* app_string); 292 void LoginSearch(const PasswordForm& form, const char* app_string);
291 void RemoveLogin(const PasswordForm& form, const char* app_string); 293 void RemoveLogin(const PasswordForm& form, const char* app_string);
292 void GetLogins(const PasswordForm& form, const char* app_string); 294 void GetLogins(const PasswordStore::FormDigest& form, const char* app_string);
293 void GetLoginsList(uint32_t blacklisted_by_user, const char* app_string); 295 void GetLoginsList(uint32_t blacklisted_by_user, const char* app_string);
294 void GetAllLogins(const char* app_string); 296 void GetAllLogins(const char* app_string);
295 297
296 // Use after AddLogin, RemoveLogin. 298 // Use after AddLogin, RemoveLogin.
297 GnomeKeyringResult WaitResult(); 299 GnomeKeyringResult WaitResult();
298 300
299 // Use after LoginSearch, GetLogins, GetLoginsList, GetAllLogins. Replaces the 301 // Use after LoginSearch, GetLogins, GetLoginsList, GetAllLogins. Replaces the
300 // content of |forms| with found logins. 302 // content of |forms| with found logins.
301 GnomeKeyringResult WaitResult(ScopedVector<PasswordForm>* forms); 303 GnomeKeyringResult WaitResult(ScopedVector<PasswordForm>* forms);
302 304
(...skipping 25 matching lines...) Expand all
328 330
329 // This is marked as static, but acts on the GKRMethod instance that |data| 331 // This is marked as static, but acts on the GKRMethod instance that |data|
330 // points to. Saves |result| to |result_|. If the result is OK, overwrites 332 // points to. Saves |result| to |result_|. If the result is OK, overwrites
331 // |forms_| with the found credentials. Clears |forms_| otherwise. 333 // |forms_| with the found credentials. Clears |forms_| otherwise.
332 static void OnOperationGetList(GnomeKeyringResult result, GList* list, 334 static void OnOperationGetList(GnomeKeyringResult result, GList* list,
333 gpointer data); 335 gpointer data);
334 336
335 base::WaitableEvent event_; 337 base::WaitableEvent event_;
336 GnomeKeyringResult result_; 338 GnomeKeyringResult result_;
337 ScopedVector<PasswordForm> forms_; 339 ScopedVector<PasswordForm> forms_;
338 // If the credential search is specified by a single form and needs to use PSL 340 // If the credential search is specified by a single form and needs to use
339 // matching, then the specifying form is stored in |lookup_form_|. If PSL 341 // PSL matching, then the specifying form is stored in |lookup_form_|. If
340 // matching is used to find a result, then the results signon realm, origin 342 // PSL matching is used to find a result, then the results signon realm and
341 // and action are stored are replaced by those of |lookup_form_|. 343 // origin are stored are replaced by those of |lookup_form_|. Additionally,
342 // Additionally, |lookup_form_->signon_realm| is also used to narrow down the 344 // |lookup_form_->signon_realm| is also used to narrow down the found logins
343 // found logins to those which indeed PSL-match the look-up. And finally, 345 // to those which indeed PSL-match the look-up. And finally, |lookup_form_|
344 // |lookup_form_| set to NULL means that PSL matching is not required. 346 // set to NULL means that PSL matching is not required.
345 std::unique_ptr<PasswordForm> lookup_form_; 347 std::unique_ptr<const PasswordStore::FormDigest> lookup_form_;
346 }; 348 };
347 349
348 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) { 350 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) {
349 DCHECK_CURRENTLY_ON(BrowserThread::UI); 351 DCHECK_CURRENTLY_ON(BrowserThread::UI);
350 int64_t date_created = form.date_created.ToInternalValue(); 352 int64_t date_created = form.date_created.ToInternalValue();
351 // If we are asked to save a password with 0 date, use the current time. 353 // If we are asked to save a password with 0 date, use the current time.
352 // We don't want to actually save passwords as though on January 1, 1601. 354 // We don't want to actually save passwords as though on January 1, 1601.
353 if (!date_created) 355 if (!date_created)
354 date_created = base::Time::Now().ToInternalValue(); 356 date_created = base::Time::Now().ToInternalValue();
355 int64_t date_synced = form.date_synced.ToInternalValue(); 357 int64_t date_synced = form.date_synced.ToInternalValue();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 nullptr, // destroy_data 423 nullptr, // destroy_data
422 "origin_url", form.origin.spec().c_str(), 424 "origin_url", form.origin.spec().c_str(),
423 "username_element", UTF16ToUTF8(form.username_element).c_str(), 425 "username_element", UTF16ToUTF8(form.username_element).c_str(),
424 "username_value", UTF16ToUTF8(form.username_value).c_str(), 426 "username_value", UTF16ToUTF8(form.username_value).c_str(),
425 "password_element", UTF16ToUTF8(form.password_element).c_str(), 427 "password_element", UTF16ToUTF8(form.password_element).c_str(),
426 "signon_realm", form.signon_realm.c_str(), 428 "signon_realm", form.signon_realm.c_str(),
427 "application", app_string, 429 "application", app_string,
428 nullptr); 430 nullptr);
429 } 431 }
430 432
431 void GKRMethod::GetLogins(const PasswordForm& form, const char* app_string) { 433 void GKRMethod::GetLogins(const PasswordStore::FormDigest& form,
434 const char* app_string) {
432 DCHECK_CURRENTLY_ON(BrowserThread::UI); 435 DCHECK_CURRENTLY_ON(BrowserThread::UI);
433 lookup_form_.reset(new PasswordForm(form)); 436 lookup_form_.reset(new PasswordStore::FormDigest(form));
434 // Search GNOME Keyring for matching passwords. 437 // Search GNOME Keyring for matching passwords.
435 ScopedAttributeList attrs(gnome_keyring_attribute_list_new()); 438 ScopedAttributeList attrs(gnome_keyring_attribute_list_new());
436 if (!password_manager::ShouldPSLDomainMatchingApply( 439 if (!password_manager::ShouldPSLDomainMatchingApply(
437 password_manager::GetRegistryControlledDomain( 440 password_manager::GetRegistryControlledDomain(
438 GURL(form.signon_realm))) && 441 GURL(form.signon_realm))) &&
439 form.scheme != PasswordForm::SCHEME_HTML) { 442 form.scheme != PasswordForm::SCHEME_HTML) {
440 // Don't retrieve the PSL matched and federated credentials. 443 // Don't retrieve the PSL matched and federated credentials.
441 AppendString(&attrs, "signon_realm", form.signon_realm); 444 AppendString(&attrs, "signon_realm", form.signon_realm);
442 } 445 }
443 AppendString(&attrs, "application", app_string); 446 AppendString(&attrs, "application", app_string);
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 if (origin_filter.Run(form->origin) && !form->skip_zero_click) { 710 if (origin_filter.Run(form->origin) && !form->skip_zero_click) {
708 form->skip_zero_click = true; 711 form->skip_zero_click = true;
709 if (!UpdateLogin(*form, changes)) 712 if (!UpdateLogin(*form, changes))
710 return false; 713 return false;
711 } 714 }
712 } 715 }
713 716
714 return true; 717 return true;
715 } 718 }
716 719
717 bool NativeBackendGnome::GetLogins(const PasswordForm& form, 720 bool NativeBackendGnome::GetLogins(const PasswordStore::FormDigest& form,
718 ScopedVector<PasswordForm>* forms) { 721 ScopedVector<PasswordForm>* forms) {
719 DCHECK_CURRENTLY_ON(BrowserThread::DB); 722 DCHECK_CURRENTLY_ON(BrowserThread::DB);
720 GKRMethod method; 723 GKRMethod method;
721 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 724 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
722 base::Bind(&GKRMethod::GetLogins, 725 base::Bind(&GKRMethod::GetLogins,
723 base::Unretained(&method), 726 base::Unretained(&method),
724 form, app_string_.c_str())); 727 form, app_string_.c_str()));
725 GnomeKeyringResult result = method.WaitResult(forms); 728 GnomeKeyringResult result = method.WaitResult(forms);
726 if (result == GNOME_KEYRING_RESULT_NO_MATCH) 729 if (result == GNOME_KEYRING_RESULT_NO_MATCH)
727 return true; 730 return true;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 ScopedVector<PasswordForm> forms; 840 ScopedVector<PasswordForm> forms;
838 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms)) 841 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms))
839 return false; 842 return false;
840 843
841 for (size_t i = 0; i < forms.size(); ++i) { 844 for (size_t i = 0; i < forms.size(); ++i) {
842 if (!RemoveLogin(*forms[i], changes)) 845 if (!RemoveLogin(*forms[i], changes))
843 return false; 846 return false;
844 } 847 }
845 return true; 848 return true;
846 } 849 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698