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

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

Issue 980583002: Serialize form_data in Gnome keyring password store service. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 9
10 #include <map> 10 #include <map>
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 int64 date_synced = 0; 151 int64 date_synced = 0;
152 base::StringToInt64(string_attr_map["date_synced"], &date_synced); 152 base::StringToInt64(string_attr_map["date_synced"], &date_synced);
153 form->date_synced = base::Time::FromInternalValue(date_synced); 153 form->date_synced = base::Time::FromInternalValue(date_synced);
154 form->display_name = UTF8ToUTF16(string_attr_map["display_name"]); 154 form->display_name = UTF8ToUTF16(string_attr_map["display_name"]);
155 form->avatar_url = GURL(string_attr_map["avatar_url"]); 155 form->avatar_url = GURL(string_attr_map["avatar_url"]);
156 form->federation_url = GURL(string_attr_map["federation_url"]); 156 form->federation_url = GURL(string_attr_map["federation_url"]);
157 form->skip_zero_click = uint_attr_map["skip_zero_click"]; 157 form->skip_zero_click = uint_attr_map["skip_zero_click"];
158 form->generation_upload_status = 158 form->generation_upload_status =
159 static_cast<PasswordForm::GenerationUploadStatus>( 159 static_cast<PasswordForm::GenerationUploadStatus>(
160 uint_attr_map["generation_upload_status"]); 160 uint_attr_map["generation_upload_status"]);
161 161 DeserializeFormData(string_attr_map["form_data"].c_str(), &form->form_data);
162 return form.Pass(); 162 return form.Pass();
163 } 163 }
164 164
165 // Parse all the results from the given GList into a 165 // Parse all the results from the given GList into a
166 // ScopedVector<autofill::PasswordForm>, and free the GList. PasswordForms are 166 // ScopedVector<autofill::PasswordForm>, and free the GList. PasswordForms are
167 // allocated on the heap, and should be deleted by the consumer. If not NULL, 167 // allocated on the heap, and should be deleted by the consumer. If not NULL,
168 // |lookup_form| is used to filter out results -- only credentials with signon 168 // |lookup_form| is used to filter out results -- only credentials with signon
169 // realms passing the PSL matching against |lookup_form->signon_realm| will be 169 // realms passing the PSL matching against |lookup_form->signon_realm| will be
170 // kept. PSL matched results get their signon_realm, origin, and action 170 // kept. PSL matched results get their signon_realm, origin, and action
171 // rewritten to those of |lookup_form_|, with the original signon_realm saved 171 // rewritten to those of |lookup_form_|, with the original signon_realm saved
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 UMA_HISTOGRAM_ENUMERATION( 213 UMA_HISTOGRAM_ENUMERATION(
214 "PasswordManager.PslDomainMatchTriggering", 214 "PasswordManager.PslDomainMatchTriggering",
215 password_manager::ShouldPSLDomainMatchingApply(registered_domain) 215 password_manager::ShouldPSLDomainMatchingApply(registered_domain)
216 ? psl_domain_match_metric 216 ? psl_domain_match_metric
217 : password_manager::PSL_DOMAIN_MATCH_NOT_USED, 217 : password_manager::PSL_DOMAIN_MATCH_NOT_USED,
218 password_manager::PSL_DOMAIN_MATCH_COUNT); 218 password_manager::PSL_DOMAIN_MATCH_COUNT);
219 } 219 }
220 } 220 }
221 221
222 // Schema is analagous to the fields in PasswordForm. 222 // Schema is analagous to the fields in PasswordForm.
223 // TODO(gcasto): Adding 'form_data' would be nice, but we would need to
224 // serialize in a way that is guaranteed to not have any embedded NULLs. Pickle
225 // doesn't make this guarantee, so we just don't serialize this field. Since
226 // it's only used to crowd source data collection it doesn't matter that much
227 // if it's not available on this platform.
228 const GnomeKeyringPasswordSchema kGnomeSchema = { 223 const GnomeKeyringPasswordSchema kGnomeSchema = {
229 GNOME_KEYRING_ITEM_GENERIC_SECRET, { 224 GNOME_KEYRING_ITEM_GENERIC_SECRET, {
230 { "origin_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 225 { "origin_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
231 { "action_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 226 { "action_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
232 { "username_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 227 { "username_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
233 { "username_value", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 228 { "username_value", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
234 { "password_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 229 { "password_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
235 { "submit_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 230 { "submit_element", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
236 { "signon_realm", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 231 { "signon_realm", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
237 { "ssl_valid", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 }, 232 { "ssl_valid", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
238 { "preferred", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 }, 233 { "preferred", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
239 { "date_created", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 234 { "date_created", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
240 { "blacklisted_by_user", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 }, 235 { "blacklisted_by_user", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
241 { "scheme", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 }, 236 { "scheme", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
242 { "type", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 }, 237 { "type", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
243 { "times_used", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 }, 238 { "times_used", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
244 { "date_synced", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 239 { "date_synced", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
245 { "display_name", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 240 { "display_name", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
246 { "avatar_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 241 { "avatar_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
247 { "federation_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 242 { "federation_url", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
248 { "skip_zero_click", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 }, 243 { "skip_zero_click", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
249 { "generation_upload_status", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 }, 244 { "generation_upload_status", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32 },
245 { "form_data", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
250 // This field is always "chrome" so that we can search for it. 246 // This field is always "chrome" so that we can search for it.
251 { "application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING }, 247 { "application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
252 { nullptr } 248 { nullptr }
253 } 249 }
254 }; 250 };
255 251
256 // Sadly, PasswordStore goes to great lengths to switch from the originally 252 // Sadly, PasswordStore goes to great lengths to switch from the originally
257 // calling thread to the DB thread, and to provide an asynchronous API to 253 // calling thread to the DB thread, and to provide an asynchronous API to
258 // callers while using a synchronous (virtual) API provided by subclasses like 254 // callers while using a synchronous (virtual) API provided by subclasses like
259 // PasswordStoreX -- but GNOME Keyring really wants to be on the GLib main 255 // PasswordStoreX -- but GNOME Keyring really wants to be on the GLib main
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 }; 328 };
333 329
334 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) { 330 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) {
335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 331 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
336 int64 date_created = form.date_created.ToInternalValue(); 332 int64 date_created = form.date_created.ToInternalValue();
337 // If we are asked to save a password with 0 date, use the current time. 333 // 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. 334 // We don't want to actually save passwords as though on January 1, 1601.
339 if (!date_created) 335 if (!date_created)
340 date_created = base::Time::Now().ToInternalValue(); 336 date_created = base::Time::Now().ToInternalValue();
341 int64 date_synced = form.date_synced.ToInternalValue(); 337 int64 date_synced = form.date_synced.ToInternalValue();
338 std::string form_data;
339 SerializeFormData(form.form_data, &form_data);
342 gnome_keyring_store_password( 340 gnome_keyring_store_password(
343 &kGnomeSchema, 341 &kGnomeSchema,
344 nullptr, // Default keyring. 342 nullptr, // Default keyring.
345 form.origin.spec().c_str(), // Display name. 343 form.origin.spec().c_str(), // Display name.
346 UTF16ToUTF8(form.password_value).c_str(), 344 UTF16ToUTF8(form.password_value).c_str(),
347 OnOperationDone, 345 OnOperationDone,
348 this, // data 346 this, // data
349 nullptr, // destroy_data 347 nullptr, // destroy_data
350 "origin_url", form.origin.spec().c_str(), 348 "origin_url", form.origin.spec().c_str(),
351 "action_url", form.action.spec().c_str(), 349 "action_url", form.action.spec().c_str(),
352 "username_element", UTF16ToUTF8(form.username_element).c_str(), 350 "username_element", UTF16ToUTF8(form.username_element).c_str(),
353 "username_value", UTF16ToUTF8(form.username_value).c_str(), 351 "username_value", UTF16ToUTF8(form.username_value).c_str(),
354 "password_element", UTF16ToUTF8(form.password_element).c_str(), 352 "password_element", UTF16ToUTF8(form.password_element).c_str(),
355 "submit_element", UTF16ToUTF8(form.submit_element).c_str(), 353 "submit_element", UTF16ToUTF8(form.submit_element).c_str(),
356 "signon_realm", form.signon_realm.c_str(), 354 "signon_realm", form.signon_realm.c_str(),
357 "ssl_valid", form.ssl_valid, 355 "ssl_valid", form.ssl_valid,
358 "preferred", form.preferred, 356 "preferred", form.preferred,
359 "date_created", base::Int64ToString(date_created).c_str(), 357 "date_created", base::Int64ToString(date_created).c_str(),
360 "blacklisted_by_user", form.blacklisted_by_user, 358 "blacklisted_by_user", form.blacklisted_by_user,
361 "type", form.type, 359 "type", form.type,
362 "times_used", form.times_used, 360 "times_used", form.times_used,
363 "scheme", form.scheme, 361 "scheme", form.scheme,
364 "date_synced", base::Int64ToString(date_synced).c_str(), 362 "date_synced", base::Int64ToString(date_synced).c_str(),
365 "display_name", UTF16ToUTF8(form.display_name).c_str(), 363 "display_name", UTF16ToUTF8(form.display_name).c_str(),
366 "avatar_url", form.avatar_url.spec().c_str(), 364 "avatar_url", form.avatar_url.spec().c_str(),
367 "federation_url", form.federation_url.spec().c_str(), 365 "federation_url", form.federation_url.spec().c_str(),
368 "skip_zero_click", form.skip_zero_click, 366 "skip_zero_click", form.skip_zero_click,
369 "generation_upload_status", form.generation_upload_status, 367 "generation_upload_status", form.generation_upload_status,
368 "form_data", form_data.c_str(),
370 "application", app_string, 369 "application", app_string,
371 nullptr); 370 nullptr);
372 } 371 }
373 372
374 void GKRMethod::AddLoginSearch(const PasswordForm& form, 373 void GKRMethod::AddLoginSearch(const PasswordForm& form,
375 const char* app_string) { 374 const char* app_string) {
376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 375 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
377 lookup_form_.reset(nullptr); 376 lookup_form_.reset(nullptr);
378 // Search GNOME Keyring for matching passwords to update. 377 // Search GNOME Keyring for matching passwords to update.
379 ScopedAttributeList attrs(gnome_keyring_attribute_list_new()); 378 ScopedAttributeList attrs(gnome_keyring_attribute_list_new());
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 } 805 }
807 return ok; 806 return ok;
808 } 807 }
809 808
810 std::string NativeBackendGnome::GetProfileSpecificAppString() const { 809 std::string NativeBackendGnome::GetProfileSpecificAppString() const {
811 // Originally, the application string was always just "chrome" and used only 810 // Originally, the application string was always just "chrome" and used only
812 // so that we had *something* to search for since GNOME Keyring won't search 811 // so that we had *something* to search for since GNOME Keyring won't search
813 // for nothing. Now we use it to distinguish passwords for different profiles. 812 // for nothing. Now we use it to distinguish passwords for different profiles.
814 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); 813 return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_);
815 } 814 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698