| OLD | NEW |
| 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> |
| 11 |
| 11 #include <map> | 12 #include <map> |
| 13 #include <memory> |
| 12 #include <string> | 14 #include <string> |
| 13 #include <utility> | 15 #include <utility> |
| 14 #include <vector> | 16 #include <vector> |
| 15 | 17 |
| 16 #include "base/logging.h" | 18 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | |
| 18 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_piece.h" | 21 #include "base/strings/string_piece.h" |
| 21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 22 #include "base/strings/stringprintf.h" | 23 #include "base/strings/stringprintf.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 24 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/synchronization/waitable_event.h" | 25 #include "base/synchronization/waitable_event.h" |
| 25 #include "base/time/time.h" | 26 #include "base/time/time.h" |
| 26 #include "components/autofill/core/common/password_form.h" | 27 #include "components/autofill/core/common/password_form.h" |
| 27 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" | 28 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 103 |
| 103 #endif // defined(DLOPEN_GNOME_KEYRING) | 104 #endif // defined(DLOPEN_GNOME_KEYRING) |
| 104 | 105 |
| 105 namespace { | 106 namespace { |
| 106 | 107 |
| 107 const char kGnomeKeyringAppString[] = "chrome"; | 108 const char kGnomeKeyringAppString[] = "chrome"; |
| 108 | 109 |
| 109 // Convert the attributes of a given keyring entry into a new PasswordForm. | 110 // Convert the attributes of a given keyring entry into a new PasswordForm. |
| 110 // Note: does *not* get the actual password, as that is not a key attribute! | 111 // Note: does *not* get the actual password, as that is not a key attribute! |
| 111 // Returns NULL if the attributes are for the wrong application. | 112 // Returns NULL if the attributes are for the wrong application. |
| 112 scoped_ptr<PasswordForm> FormFromAttributes(GnomeKeyringAttributeList* attrs) { | 113 std::unique_ptr<PasswordForm> FormFromAttributes( |
| 114 GnomeKeyringAttributeList* attrs) { |
| 113 // Read the string and int attributes into the appropriate map. | 115 // Read the string and int attributes into the appropriate map. |
| 114 std::map<std::string, std::string> string_attr_map; | 116 std::map<std::string, std::string> string_attr_map; |
| 115 std::map<std::string, uint32_t> uint_attr_map; | 117 std::map<std::string, uint32_t> uint_attr_map; |
| 116 for (guint i = 0; i < attrs->len; ++i) { | 118 for (guint i = 0; i < attrs->len; ++i) { |
| 117 GnomeKeyringAttribute attr = gnome_keyring_attribute_list_index(attrs, i); | 119 GnomeKeyringAttribute attr = gnome_keyring_attribute_list_index(attrs, i); |
| 118 if (attr.type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) | 120 if (attr.type == GNOME_KEYRING_ATTRIBUTE_TYPE_STRING) |
| 119 string_attr_map[attr.name] = attr.value.string; | 121 string_attr_map[attr.name] = attr.value.string; |
| 120 else if (attr.type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32) | 122 else if (attr.type == GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32) |
| 121 uint_attr_map[attr.name] = attr.value.integer; | 123 uint_attr_map[attr.name] = attr.value.integer; |
| 122 } | 124 } |
| 123 // Check to make sure this is a password we care about. | 125 // Check to make sure this is a password we care about. |
| 124 const std::string& app_value = string_attr_map["application"]; | 126 const std::string& app_value = string_attr_map["application"]; |
| 125 if (!base::StringPiece(app_value).starts_with(kGnomeKeyringAppString)) | 127 if (!base::StringPiece(app_value).starts_with(kGnomeKeyringAppString)) |
| 126 return scoped_ptr<PasswordForm>(); | 128 return std::unique_ptr<PasswordForm>(); |
| 127 | 129 |
| 128 scoped_ptr<PasswordForm> form(new PasswordForm()); | 130 std::unique_ptr<PasswordForm> form(new PasswordForm()); |
| 129 form->origin = GURL(string_attr_map["origin_url"]); | 131 form->origin = GURL(string_attr_map["origin_url"]); |
| 130 form->action = GURL(string_attr_map["action_url"]); | 132 form->action = GURL(string_attr_map["action_url"]); |
| 131 form->username_element = UTF8ToUTF16(string_attr_map["username_element"]); | 133 form->username_element = UTF8ToUTF16(string_attr_map["username_element"]); |
| 132 form->username_value = UTF8ToUTF16(string_attr_map["username_value"]); | 134 form->username_value = UTF8ToUTF16(string_attr_map["username_value"]); |
| 133 form->password_element = UTF8ToUTF16(string_attr_map["password_element"]); | 135 form->password_element = UTF8ToUTF16(string_attr_map["password_element"]); |
| 134 form->submit_element = UTF8ToUTF16(string_attr_map["submit_element"]); | 136 form->submit_element = UTF8ToUTF16(string_attr_map["submit_element"]); |
| 135 form->signon_realm = string_attr_map["signon_realm"]; | 137 form->signon_realm = string_attr_map["signon_realm"]; |
| 136 form->ssl_valid = uint_attr_map["ssl_valid"]; | 138 form->ssl_valid = uint_attr_map["ssl_valid"]; |
| 137 form->preferred = uint_attr_map["preferred"]; | 139 form->preferred = uint_attr_map["preferred"]; |
| 138 int64_t date_created = 0; | 140 int64_t date_created = 0; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 password_manager::PSL_DOMAIN_MATCH_NONE; | 189 password_manager::PSL_DOMAIN_MATCH_NONE; |
| 188 const bool allow_psl_match = | 190 const bool allow_psl_match = |
| 189 lookup_form && password_manager::ShouldPSLDomainMatchingApply( | 191 lookup_form && password_manager::ShouldPSLDomainMatchingApply( |
| 190 password_manager::GetRegistryControlledDomain( | 192 password_manager::GetRegistryControlledDomain( |
| 191 GURL(lookup_form->signon_realm))); | 193 GURL(lookup_form->signon_realm))); |
| 192 for (GList* element = g_list_first(found); element; | 194 for (GList* element = g_list_first(found); element; |
| 193 element = g_list_next(element)) { | 195 element = g_list_next(element)) { |
| 194 GnomeKeyringFound* data = static_cast<GnomeKeyringFound*>(element->data); | 196 GnomeKeyringFound* data = static_cast<GnomeKeyringFound*>(element->data); |
| 195 GnomeKeyringAttributeList* attrs = data->attributes; | 197 GnomeKeyringAttributeList* attrs = data->attributes; |
| 196 | 198 |
| 197 scoped_ptr<PasswordForm> form(FormFromAttributes(attrs)); | 199 std::unique_ptr<PasswordForm> form(FormFromAttributes(attrs)); |
| 198 if (form) { | 200 if (form) { |
| 199 if (lookup_form && form->signon_realm != lookup_form->signon_realm) { | 201 if (lookup_form && form->signon_realm != lookup_form->signon_realm) { |
| 200 if (lookup_form->scheme != PasswordForm::SCHEME_HTML || | 202 if (lookup_form->scheme != PasswordForm::SCHEME_HTML || |
| 201 form->scheme != PasswordForm::SCHEME_HTML) | 203 form->scheme != PasswordForm::SCHEME_HTML) |
| 202 continue; // Ignore non-HTML matches. | 204 continue; // Ignore non-HTML matches. |
| 203 // This is not an exact match, we try PSL matching and federated match. | 205 // This is not an exact match, we try PSL matching and federated match. |
| 204 if (allow_psl_match && | 206 if (allow_psl_match && |
| 205 password_manager::IsPublicSuffixDomainMatch( | 207 password_manager::IsPublicSuffixDomainMatch( |
| 206 form->signon_realm, lookup_form->signon_realm)) { | 208 form->signon_realm, lookup_form->signon_realm)) { |
| 207 psl_domain_match_metric = password_manager::PSL_DOMAIN_MATCH_FOUND; | 209 psl_domain_match_metric = password_manager::PSL_DOMAIN_MATCH_FOUND; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 GnomeKeyringResult WaitResult(ScopedVector<PasswordForm>* forms); | 300 GnomeKeyringResult WaitResult(ScopedVector<PasswordForm>* forms); |
| 299 | 301 |
| 300 private: | 302 private: |
| 301 struct GnomeKeyringAttributeListFreeDeleter { | 303 struct GnomeKeyringAttributeListFreeDeleter { |
| 302 inline void operator()(void* list) const { | 304 inline void operator()(void* list) const { |
| 303 gnome_keyring_attribute_list_free( | 305 gnome_keyring_attribute_list_free( |
| 304 static_cast<GnomeKeyringAttributeList*>(list)); | 306 static_cast<GnomeKeyringAttributeList*>(list)); |
| 305 } | 307 } |
| 306 }; | 308 }; |
| 307 | 309 |
| 308 typedef scoped_ptr<GnomeKeyringAttributeList, | 310 typedef std::unique_ptr<GnomeKeyringAttributeList, |
| 309 GnomeKeyringAttributeListFreeDeleter> ScopedAttributeList; | 311 GnomeKeyringAttributeListFreeDeleter> |
| 312 ScopedAttributeList; |
| 310 | 313 |
| 311 // Helper methods to abbreviate Gnome Keyring long API names. | 314 // Helper methods to abbreviate Gnome Keyring long API names. |
| 312 static void AppendString(ScopedAttributeList* list, | 315 static void AppendString(ScopedAttributeList* list, |
| 313 const char* name, | 316 const char* name, |
| 314 const char* value); | 317 const char* value); |
| 315 static void AppendString(ScopedAttributeList* list, | 318 static void AppendString(ScopedAttributeList* list, |
| 316 const char* name, | 319 const char* name, |
| 317 const std::string& value); | 320 const std::string& value); |
| 318 static void AppendUint32(ScopedAttributeList* list, | 321 static void AppendUint32(ScopedAttributeList* list, |
| 319 const char* name, | 322 const char* name, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 331 base::WaitableEvent event_; | 334 base::WaitableEvent event_; |
| 332 GnomeKeyringResult result_; | 335 GnomeKeyringResult result_; |
| 333 ScopedVector<PasswordForm> forms_; | 336 ScopedVector<PasswordForm> forms_; |
| 334 // If the credential search is specified by a single form and needs to use PSL | 337 // If the credential search is specified by a single form and needs to use PSL |
| 335 // matching, then the specifying form is stored in |lookup_form_|. If PSL | 338 // matching, then the specifying form is stored in |lookup_form_|. If PSL |
| 336 // matching is used to find a result, then the results signon realm, origin | 339 // matching is used to find a result, then the results signon realm, origin |
| 337 // and action are stored are replaced by those of |lookup_form_|. | 340 // and action are stored are replaced by those of |lookup_form_|. |
| 338 // Additionally, |lookup_form_->signon_realm| is also used to narrow down the | 341 // Additionally, |lookup_form_->signon_realm| is also used to narrow down the |
| 339 // found logins to those which indeed PSL-match the look-up. And finally, | 342 // found logins to those which indeed PSL-match the look-up. And finally, |
| 340 // |lookup_form_| set to NULL means that PSL matching is not required. | 343 // |lookup_form_| set to NULL means that PSL matching is not required. |
| 341 scoped_ptr<PasswordForm> lookup_form_; | 344 std::unique_ptr<PasswordForm> lookup_form_; |
| 342 }; | 345 }; |
| 343 | 346 |
| 344 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) { | 347 void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) { |
| 345 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 348 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 346 int64_t date_created = form.date_created.ToInternalValue(); | 349 int64_t date_created = form.date_created.ToInternalValue(); |
| 347 // If we are asked to save a password with 0 date, use the current time. | 350 // If we are asked to save a password with 0 date, use the current time. |
| 348 // We don't want to actually save passwords as though on January 1, 1601. | 351 // We don't want to actually save passwords as though on January 1, 1601. |
| 349 if (!date_created) | 352 if (!date_created) |
| 350 date_created = base::Time::Now().ToInternalValue(); | 353 date_created = base::Time::Now().ToInternalValue(); |
| 351 int64_t date_synced = form.date_synced.ToInternalValue(); | 354 int64_t date_synced = form.date_synced.ToInternalValue(); |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 ScopedVector<PasswordForm> forms; | 836 ScopedVector<PasswordForm> forms; |
| 834 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms)) | 837 if (!GetLoginsBetween(get_begin, get_end, date_to_compare, &forms)) |
| 835 return false; | 838 return false; |
| 836 | 839 |
| 837 for (size_t i = 0; i < forms.size(); ++i) { | 840 for (size_t i = 0; i < forms.size(); ++i) { |
| 838 if (!RemoveLogin(*forms[i], changes)) | 841 if (!RemoveLogin(*forms[i], changes)) |
| 839 return false; | 842 return false; |
| 840 } | 843 } |
| 841 return true; | 844 return true; |
| 842 } | 845 } |
| OLD | NEW |