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

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

Issue 134923004: Revert 244286 "Password manager: Gnome support for Public Suffix..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 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 | Annotate | Revision Log
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 9
10 #include <map> 10 #include <map>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/metrics/histogram.h"
17 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/string_piece.h" 17 #include "base/strings/string_piece.h"
19 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
22 #include "base/synchronization/waitable_event.h" 21 #include "base/synchronization/waitable_event.h"
23 #include "base/time/time.h" 22 #include "base/time/time.h"
24 #include "chrome/browser/password_manager/psl_matching_helper.h"
25 #include "components/autofill/core/common/password_form.h" 23 #include "components/autofill/core/common/password_form.h"
26 #include "content/public/browser/browser_thread.h" 24 #include "content/public/browser/browser_thread.h"
27 25
28 using autofill::PasswordForm; 26 using autofill::PasswordForm;
29 using base::UTF8ToUTF16; 27 using base::UTF8ToUTF16;
30 using base::UTF16ToUTF8; 28 using base::UTF16ToUTF8;
31 using content::BrowserThread; 29 using content::BrowserThread;
32 30
33 #define GNOME_KEYRING_DEFINE_POINTER(name) \ 31 #define GNOME_KEYRING_DEFINE_POINTER(name) \
34 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name; 32 typeof(&::gnome_keyring_##name) GnomeKeyringLoader::gnome_keyring_##name;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 DCHECK(date_ok); 130 DCHECK(date_ok);
133 form->date_created = base::Time::FromTimeT(date_created); 131 form->date_created = base::Time::FromTimeT(date_created);
134 form->blacklisted_by_user = uint_attr_map["blacklisted_by_user"]; 132 form->blacklisted_by_user = uint_attr_map["blacklisted_by_user"];
135 form->scheme = static_cast<PasswordForm::Scheme>(uint_attr_map["scheme"]); 133 form->scheme = static_cast<PasswordForm::Scheme>(uint_attr_map["scheme"]);
136 134
137 return form; 135 return form;
138 } 136 }
139 137
140 // Parse all the results from the given GList into a PasswordFormList, and free 138 // Parse all the results from the given GList into a PasswordFormList, and free
141 // the GList. PasswordForms are allocated on the heap, and should be deleted by 139 // the GList. PasswordForms are allocated on the heap, and should be deleted by
142 // the consumer. If not empty, |filter_by_signon_realm| is used to filter out 140 // the consumer.
143 // results -- only credentials with signon realms passing the PSL matching
144 // (done by |helper|) against |filter_by_signon_realm| will be kept.
145 void ConvertFormList(GList* found, 141 void ConvertFormList(GList* found,
146 const std::string& filter_by_signon_realm,
147 const PSLMatchingHelper& helper,
148 NativeBackendGnome::PasswordFormList* forms) { 142 NativeBackendGnome::PasswordFormList* forms) {
149 PSLMatchingHelper::PSLDomainMatchMetric psl_domain_match_metric =
150 PSLMatchingHelper::PSL_DOMAIN_MATCH_NONE;
151 for (GList* element = g_list_first(found); element != NULL; 143 for (GList* element = g_list_first(found); element != NULL;
152 element = g_list_next(element)) { 144 element = g_list_next(element)) {
153 GnomeKeyringFound* data = static_cast<GnomeKeyringFound*>(element->data); 145 GnomeKeyringFound* data = static_cast<GnomeKeyringFound*>(element->data);
154 GnomeKeyringAttributeList* attrs = data->attributes; 146 GnomeKeyringAttributeList* attrs = data->attributes;
155 147
156 PasswordForm* form = FormFromAttributes(attrs); 148 PasswordForm* form = FormFromAttributes(attrs);
157 if (form) { 149 if (form) {
158 if (!filter_by_signon_realm.empty() &&
159 form->signon_realm != filter_by_signon_realm) {
160 // This is not an exact match, we try PSL matching.
161 if (!(PSLMatchingHelper::IsPublicSuffixDomainMatch(
162 filter_by_signon_realm, form->signon_realm))) {
163 continue;
164 }
165 psl_domain_match_metric = PSLMatchingHelper::PSL_DOMAIN_MATCH_FOUND;
166 form->original_signon_realm = form->signon_realm;
167 }
168 if (data->secret) { 150 if (data->secret) {
169 form->password_value = UTF8ToUTF16(data->secret); 151 form->password_value = UTF8ToUTF16(data->secret);
170 } else { 152 } else {
171 LOG(WARNING) << "Unable to access password from list element!"; 153 LOG(WARNING) << "Unable to access password from list element!";
172 } 154 }
173 forms->push_back(form); 155 forms->push_back(form);
174 } else { 156 } else {
175 LOG(WARNING) << "Could not initialize PasswordForm from attributes!"; 157 LOG(WARNING) << "Could not initialize PasswordForm from attributes!";
176 } 158 }
177 } 159 }
178 if (!filter_by_signon_realm.empty()) {
179 UMA_HISTOGRAM_ENUMERATION(
180 "PasswordManager.PslDomainMatchTriggering",
181 helper.IsMatchingEnabled()
182 ? psl_domain_match_metric
183 : PSLMatchingHelper::PSL_DOMAIN_MATCH_DISABLED,
184 PSLMatchingHelper::PSL_DOMAIN_MATCH_COUNT);
185 }
186 } 160 }
187 161
188 // Schema is analagous to the fields in PasswordForm. 162 // Schema is analagous to the fields in PasswordForm.
189 const GnomeKeyringPasswordSchema kGnomeSchema = { 163 const GnomeKeyringPasswordSchema kGnomeSchema = {
190 GNOME_KEYRING_ITEM_GENERIC_SECRET, { 164 GNOME_KEYRING_ITEM_GENERIC_SECRET, {
191 { "origin_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 165 { "origin_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
192 { "action_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 166 { "action_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
193 { "username_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 167 { "username_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
194 { "username_value", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 168 { "username_value", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
195 { "password_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 169 { "password_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 243
270 // All these callbacks are called on UI thread. 244 // All these callbacks are called on UI thread.
271 static void OnOperationDone(GnomeKeyringResult result, gpointer data); 245 static void OnOperationDone(GnomeKeyringResult result, gpointer data);
272 246
273 static void OnOperationGetList(GnomeKeyringResult result, GList* list, 247 static void OnOperationGetList(GnomeKeyringResult result, GList* list,
274 gpointer data); 248 gpointer data);
275 249
276 base::WaitableEvent event_; 250 base::WaitableEvent event_;
277 GnomeKeyringResult result_; 251 GnomeKeyringResult result_;
278 NativeBackendGnome::PasswordFormList forms_; 252 NativeBackendGnome::PasswordFormList forms_;
279 // Two additional arguments to OnOperationGetList:
280 // If the credential search is related to a particular form,
281 // |original_signon_realm_| contains the signon realm of that form. It is used
282 // to filter the relevant results out of all the found ones.
283 std::string original_signon_realm_;
284 const PSLMatchingHelper helper_;
285 }; 253 };
286 254
287 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) { 255 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) {
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
289 time_t date_created = form.date_created.ToTimeT(); 257 time_t date_created = form.date_created.ToTimeT();
290 // If we are asked to save a password with 0 date, use the current time. 258 // If we are asked to save a password with 0 date, use the current time.
291 // We don't want to actually save passwords as though on January 1, 1970. 259 // We don't want to actually save passwords as though on January 1, 1970.
292 if (!date_created) 260 if (!date_created)
293 date_created = time(NULL); 261 date_created = time(NULL);
294 gnome_keyring_store_password( 262 gnome_keyring_store_password(
(...skipping 16 matching lines...) Expand all
311 "date_created", base::Int64ToString(date_created).c_str(), 279 "date_created", base::Int64ToString(date_created).c_str(),
312 "blacklisted_by_user", form.blacklisted_by_user, 280 "blacklisted_by_user", form.blacklisted_by_user,
313 "scheme", form.scheme, 281 "scheme", form.scheme,
314 "application", app_string, 282 "application", app_string,
315 NULL); 283 NULL);
316 } 284 }
317 285
318 void GKRMethod::AddLoginSearch(const PasswordForm& form, 286 void GKRMethod::AddLoginSearch(const PasswordForm& form,
319 const char* app_string) { 287 const char* app_string) {
320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
321 original_signon_realm_ = form.signon_realm;
322 // Search GNOME Keyring for matching passwords to update. 289 // Search GNOME Keyring for matching passwords to update.
323 ScopedAttributeList attrs(gnome_keyring_attribute_list_new()); 290 ScopedAttributeList attrs(gnome_keyring_attribute_list_new());
324 AppendString(&attrs, "origin_url", form.origin.spec()); 291 AppendString(&attrs, "origin_url", form.origin.spec());
325 AppendString(&attrs, "username_element", UTF16ToUTF8(form.username_element)); 292 AppendString(&attrs, "username_element", UTF16ToUTF8(form.username_element));
326 AppendString(&attrs, "username_value", UTF16ToUTF8(form.username_value)); 293 AppendString(&attrs, "username_value", UTF16ToUTF8(form.username_value));
327 AppendString(&attrs, "password_element", UTF16ToUTF8(form.password_element)); 294 AppendString(&attrs, "password_element", UTF16ToUTF8(form.password_element));
328 AppendString(&attrs, "submit_element", UTF16ToUTF8(form.submit_element)); 295 AppendString(&attrs, "submit_element", UTF16ToUTF8(form.submit_element));
329 AppendString(&attrs, "signon_realm", form.signon_realm); 296 AppendString(&attrs, "signon_realm", form.signon_realm);
330 AppendString(&attrs, "application", app_string); 297 AppendString(&attrs, "application", app_string);
331 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET, 298 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET,
332 attrs.get(), 299 attrs.get(),
333 OnOperationGetList, 300 OnOperationGetList,
334 /*data=*/this, 301 /*data=*/this,
335 /*destroy_data=*/NULL); 302 /*destroy_data=*/NULL);
336 } 303 }
337 304
338 void GKRMethod::UpdateLoginSearch(const PasswordForm& form, 305 void GKRMethod::UpdateLoginSearch(const PasswordForm& form,
339 const char* app_string) { 306 const char* app_string) {
340 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
341 original_signon_realm_ = form.signon_realm;
342 // Search GNOME Keyring for matching passwords to update. 308 // Search GNOME Keyring for matching passwords to update.
343 ScopedAttributeList attrs(gnome_keyring_attribute_list_new()); 309 ScopedAttributeList attrs(gnome_keyring_attribute_list_new());
344 AppendString(&attrs, "origin_url", form.origin.spec()); 310 AppendString(&attrs, "origin_url", form.origin.spec());
345 AppendString(&attrs, "username_element", UTF16ToUTF8(form.username_element)); 311 AppendString(&attrs, "username_element", UTF16ToUTF8(form.username_element));
346 AppendString(&attrs, "username_value", UTF16ToUTF8(form.username_value)); 312 AppendString(&attrs, "username_value", UTF16ToUTF8(form.username_value));
347 AppendString(&attrs, "password_element", UTF16ToUTF8(form.password_element)); 313 AppendString(&attrs, "password_element", UTF16ToUTF8(form.password_element));
348 AppendString(&attrs, "signon_realm", form.signon_realm); 314 AppendString(&attrs, "signon_realm", form.signon_realm);
349 AppendString(&attrs, "application", app_string); 315 AppendString(&attrs, "application", app_string);
350 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET, 316 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET,
351 attrs.get(), 317 attrs.get(),
(...skipping 16 matching lines...) Expand all
368 "username_value", UTF16ToUTF8(form.username_value).c_str(), 334 "username_value", UTF16ToUTF8(form.username_value).c_str(),
369 "password_element", UTF16ToUTF8(form.password_element).c_str(), 335 "password_element", UTF16ToUTF8(form.password_element).c_str(),
370 "submit_element", UTF16ToUTF8(form.submit_element).c_str(), 336 "submit_element", UTF16ToUTF8(form.submit_element).c_str(),
371 "signon_realm", form.signon_realm.c_str(), 337 "signon_realm", form.signon_realm.c_str(),
372 "application", app_string, 338 "application", app_string,
373 NULL); 339 NULL);
374 } 340 }
375 341
376 void GKRMethod::GetLogins(const PasswordForm& form, const char* app_string) { 342 void GKRMethod::GetLogins(const PasswordForm& form, const char* app_string) {
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
378 original_signon_realm_ = form.signon_realm;
379 // Search GNOME Keyring for matching passwords. 344 // Search GNOME Keyring for matching passwords.
380 ScopedAttributeList attrs(gnome_keyring_attribute_list_new()); 345 ScopedAttributeList attrs(gnome_keyring_attribute_list_new());
381 if (!helper_.ShouldPSLDomainMatchingApply( 346 AppendString(&attrs, "signon_realm", form.signon_realm);
382 PSLMatchingHelper::GetRegistryControlledDomain(
383 GURL(form.signon_realm)))) {
384 AppendString(&attrs, "signon_realm", form.signon_realm);
385 }
386 AppendString(&attrs, "application", app_string); 347 AppendString(&attrs, "application", app_string);
387 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET, 348 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET,
388 attrs.get(), 349 attrs.get(),
389 OnOperationGetList, 350 OnOperationGetList,
390 /*data=*/this, 351 /*data=*/this,
391 /*destroy_data=*/NULL); 352 /*destroy_data=*/NULL);
392 } 353 }
393 354
394 void GKRMethod::GetLoginsList(uint32_t blacklisted_by_user, 355 void GKRMethod::GetLoginsList(uint32_t blacklisted_by_user,
395 const char* app_string) { 356 const char* app_string) {
396 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 357 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
397 original_signon_realm_.clear();
398 // Search GNOME Keyring for matching passwords. 358 // Search GNOME Keyring for matching passwords.
399 ScopedAttributeList attrs(gnome_keyring_attribute_list_new()); 359 ScopedAttributeList attrs(gnome_keyring_attribute_list_new());
400 AppendUint32(&attrs, "blacklisted_by_user", blacklisted_by_user); 360 AppendUint32(&attrs, "blacklisted_by_user", blacklisted_by_user);
401 AppendString(&attrs, "application", app_string); 361 AppendString(&attrs, "application", app_string);
402 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET, 362 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET,
403 attrs.get(), 363 attrs.get(),
404 OnOperationGetList, 364 OnOperationGetList,
405 /*data=*/this, 365 /*data=*/this,
406 /*destroy_data=*/NULL); 366 /*destroy_data=*/NULL);
407 } 367 }
408 368
409 void GKRMethod::GetAllLogins(const char* app_string) { 369 void GKRMethod::GetAllLogins(const char* app_string) {
410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
411 original_signon_realm_.clear();
412 // We need to search for something, otherwise we get no results - so 371 // We need to search for something, otherwise we get no results - so
413 // we search for the fixed application string. 372 // we search for the fixed application string.
414 ScopedAttributeList attrs(gnome_keyring_attribute_list_new()); 373 ScopedAttributeList attrs(gnome_keyring_attribute_list_new());
415 AppendString(&attrs, "application", app_string); 374 AppendString(&attrs, "application", app_string);
416 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET, 375 gnome_keyring_find_items(GNOME_KEYRING_ITEM_GENERIC_SECRET,
417 attrs.get(), 376 attrs.get(),
418 OnOperationGetList, 377 OnOperationGetList,
419 /*data=*/this, 378 /*data=*/this,
420 /*destroy_data=*/NULL); 379 /*destroy_data=*/NULL);
421 } 380 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 method->event_.Signal(); 427 method->event_.Signal();
469 } 428 }
470 429
471 // static 430 // static
472 void GKRMethod::OnOperationGetList(GnomeKeyringResult result, GList* list, 431 void GKRMethod::OnOperationGetList(GnomeKeyringResult result, GList* list,
473 gpointer data) { 432 gpointer data) {
474 GKRMethod* method = static_cast<GKRMethod*>(data); 433 GKRMethod* method = static_cast<GKRMethod*>(data);
475 method->result_ = result; 434 method->result_ = result;
476 method->forms_.clear(); 435 method->forms_.clear();
477 // |list| will be freed after this callback returns, so convert it now. 436 // |list| will be freed after this callback returns, so convert it now.
478 ConvertFormList( 437 ConvertFormList(list, &method->forms_);
479 list, method->original_signon_realm_, method->helper_, &method->forms_);
480 method->original_signon_realm_.clear();
481 method->event_.Signal(); 438 method->event_.Signal();
482 } 439 }
483 440
484 } // namespace 441 } // namespace
485 442
486 NativeBackendGnome::NativeBackendGnome(LocalProfileId id, PrefService* prefs) 443 NativeBackendGnome::NativeBackendGnome(LocalProfileId id, PrefService* prefs)
487 : profile_id_(id), prefs_(prefs) { 444 : profile_id_(id), prefs_(prefs) {
488 // TODO(mdm): after a few more releases, remove the code which is now dead due 445 // TODO(mdm): after a few more releases, remove the code which is now dead due
489 // to the true || here, and simplify this code. We don't do it yet to make it 446 // to the true || here, and simplify this code. We don't do it yet to make it
490 // easier to revert if necessary. 447 // easier to revert if necessary.
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 // Each other profile must be able to migrate the shared data as well, 757 // Each other profile must be able to migrate the shared data as well,
801 // so we must leave it alone. After a few releases, we'll add code to 758 // so we must leave it alone. After a few releases, we'll add code to
802 // delete them, and eventually remove this migration code. 759 // delete them, and eventually remove this migration code.
803 // TODO(mdm): follow through with the plan above. 760 // TODO(mdm): follow through with the plan above.
804 PasswordStoreX::SetPasswordsUseLocalProfileId(prefs_); 761 PasswordStoreX::SetPasswordsUseLocalProfileId(prefs_);
805 } else { 762 } else {
806 // We failed to migrate for some reason. Use the old app string. 763 // We failed to migrate for some reason. Use the old app string.
807 app_string_ = kGnomeKeyringAppString; 764 app_string_ = kGnomeKeyringAppString;
808 } 765 }
809 } 766 }
OLDNEW
« no previous file with comments | « trunk/src/chrome/browser/about_flags.cc ('k') | trunk/src/chrome/browser/password_manager/native_backend_gnome_x_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698