Chromium Code Reviews| 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_kwallet_x.h" | 5 #include "chrome/browser/password_manager/native_backend_kwallet_x.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/pickle.h" | 11 #include "base/pickle.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/synchronization/waitable_event.h" | 14 #include "base/synchronization/waitable_event.h" |
| 15 #include "base/threading/thread_restrictions.h" | 15 #include "base/threading/thread_restrictions.h" |
| 16 #include "chrome/grit/chromium_strings.h" | 16 #include "chrome/grit/chromium_strings.h" |
| 17 #include "components/autofill/core/common/password_form.h" | 17 #include "components/autofill/core/common/password_form.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "dbus/bus.h" | 19 #include "dbus/bus.h" |
| 20 #include "dbus/message.h" | 20 #include "dbus/message.h" |
| 21 #include "dbus/object_path.h" | 21 #include "dbus/object_path.h" |
| 22 #include "dbus/object_proxy.h" | 22 #include "dbus/object_proxy.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 | 24 |
| 25 using autofill::PasswordForm; | 25 using autofill::PasswordForm; |
| 26 using content::BrowserThread; | 26 using content::BrowserThread; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // In case the fields in the pickle ever change, version them so we can try to | |
| 31 // read old pickles. (Note: do not eat old pickles past the expiration date.) | |
| 32 const int kPickleVersion = 6; | |
| 33 | |
| 30 // We could localize this string, but then changing your locale would cause | 34 // We could localize this string, but then changing your locale would cause |
| 31 // you to lose access to all your stored passwords. Maybe best not to do that. | 35 // you to lose access to all your stored passwords. Maybe best not to do that. |
| 32 // Name of the folder to store passwords in. | 36 // Name of the folder to store passwords in. |
| 33 const char kKWalletFolder[] = "Chrome Form Data"; | 37 const char kKWalletFolder[] = "Chrome Form Data"; |
| 34 | 38 |
| 35 // DBus service, path, and interface names for klauncher and kwalletd. | 39 // DBus service, path, and interface names for klauncher and kwalletd. |
| 36 const char kKWalletServiceName[] = "org.kde.kwalletd"; | 40 const char kKWalletServiceName[] = "org.kde.kwalletd"; |
| 37 const char kKWalletPath[] = "/modules/kwalletd"; | 41 const char kKWalletPath[] = "/modules/kwalletd"; |
| 38 const char kKWalletInterface[] = "org.kde.KWallet"; | 42 const char kKWalletInterface[] = "org.kde.KWallet"; |
| 39 const char kKLauncherServiceName[] = "org.kde.klauncher"; | 43 const char kKLauncherServiceName[] = "org.kde.klauncher"; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 93 LOG(WARNING) << "Failed to deserialize version " << version | 97 LOG(WARNING) << "Failed to deserialize version " << version |
| 94 << " KWallet entry (realm: " << signon_realm | 98 << " KWallet entry (realm: " << signon_realm |
| 95 << ") with native architecture size; will try alternate " | 99 << ") with native architecture size; will try alternate " |
| 96 << "size."; | 100 << "size."; |
| 97 } else { | 101 } else { |
| 98 LOG(ERROR) << "Failed to deserialize version " << version | 102 LOG(ERROR) << "Failed to deserialize version " << version |
| 99 << " KWallet entry (realm: " << signon_realm << ")"; | 103 << " KWallet entry (realm: " << signon_realm << ")"; |
| 100 } | 104 } |
| 101 } | 105 } |
| 102 | 106 |
| 107 // Deserializes a list of credentials from the wallet to |forms| (replacing | |
| 108 // |forms| contents). |size_32| controls reading the size field within the | |
|
engedy
2015/02/25 15:17:48
Nit: the contents of |forms|
vabr (Chromium)
2015/03/09 10:56:18
Done.
| |
| 109 // pickle as 32 bits. We used to use Pickle::WriteSize() to write the number of | |
| 110 // password forms, but that has a different size on 32- and 64-bit systems. So, | |
| 111 // now we always write a 64-bit quantity, but we support trying to read it as | |
| 112 // either size when reading old pickles that fail to deserialize using the | |
| 113 // native size. Returns true on success, false on failure (erasing |forms| in | |
| 114 // that case). | |
| 115 bool DeserializeValueSize(const std::string& signon_realm, | |
| 116 const PickleIterator& init_iter, | |
| 117 int version, | |
| 118 bool size_32, | |
| 119 bool warn_only, | |
| 120 ScopedVector<autofill::PasswordForm>* forms) { | |
| 121 forms->clear(); | |
| 122 PickleIterator iter = init_iter; | |
| 123 | |
| 124 size_t count = 0; | |
| 125 if (size_32) { | |
| 126 uint32_t count_32 = 0; | |
| 127 if (!iter.ReadUInt32(&count_32)) { | |
| 128 LOG(ERROR) << "Failed to deserialize KWallet entry " | |
| 129 << "(realm: " << signon_realm << ")"; | |
| 130 return false; | |
| 131 } | |
| 132 count = count_32; | |
| 133 } else { | |
| 134 if (!iter.ReadSizeT(&count)) { | |
| 135 LOG(ERROR) << "Failed to deserialize KWallet entry " | |
| 136 << "(realm: " << signon_realm << ")"; | |
| 137 return false; | |
| 138 } | |
| 139 } | |
| 140 | |
| 141 if (count > 0xFFFF) { | |
| 142 // Trying to pin down the cause of http://crbug.com/80728 (or fix it). | |
| 143 // This is a very large number of passwords to be saved for a single realm. | |
| 144 // It is almost certainly a corrupt pickle and not real data. Ignore it. | |
| 145 // This very well might actually be http://crbug.com/107701, so if we're | |
| 146 // reading an old pickle, we don't even log this the first time we try to | |
| 147 // read it. (That is, when we're reading the native architecture size.) | |
| 148 if (!warn_only) { | |
| 149 LOG(ERROR) << "Suspiciously large number of entries in KWallet entry " | |
| 150 << "(" << count << "; realm: " << signon_realm << ")"; | |
| 151 } | |
| 152 return false; | |
| 153 } | |
| 154 | |
| 155 // We'll swap |converted_forms| with |*forms| on success, to make sure we | |
| 156 // don't return partial results on failure. | |
| 157 ScopedVector<autofill::PasswordForm> converted_forms; | |
| 158 converted_forms.reserve(count); | |
| 159 for (size_t i = 0; i < count; ++i) { | |
| 160 scoped_ptr<PasswordForm> form(new PasswordForm()); | |
| 161 form->signon_realm.assign(signon_realm); | |
| 162 | |
| 163 int scheme = 0; | |
| 164 int64 date_created = 0; | |
| 165 int type = 0; | |
| 166 int generation_upload_status = 0; | |
| 167 // Note that these will be read back in the order listed due to | |
| 168 // short-circuit evaluation. This is important. | |
| 169 if (!iter.ReadInt(&scheme) || | |
| 170 !ReadGURL(&iter, warn_only, &form->origin) || | |
| 171 !ReadGURL(&iter, warn_only, &form->action) || | |
| 172 !iter.ReadString16(&form->username_element) || | |
| 173 !iter.ReadString16(&form->username_value) || | |
| 174 !iter.ReadString16(&form->password_element) || | |
| 175 !iter.ReadString16(&form->password_value) || | |
| 176 !iter.ReadString16(&form->submit_element) || | |
| 177 !iter.ReadBool(&form->ssl_valid) || | |
| 178 !iter.ReadBool(&form->preferred) || | |
| 179 !iter.ReadBool(&form->blacklisted_by_user) || | |
| 180 !iter.ReadInt64(&date_created)) { | |
| 181 LogDeserializationWarning(version, signon_realm, warn_only); | |
| 182 return false; | |
| 183 } | |
| 184 form->scheme = static_cast<PasswordForm::Scheme>(scheme); | |
| 185 | |
| 186 if (version > 1) { | |
| 187 if (!iter.ReadInt(&type) || | |
| 188 !iter.ReadInt(&form->times_used) || | |
| 189 !autofill::DeserializeFormData(&iter, &form->form_data)) { | |
| 190 LogDeserializationWarning(version, signon_realm, false); | |
| 191 return false; | |
| 192 } | |
| 193 form->type = static_cast<PasswordForm::Type>(type); | |
| 194 } | |
| 195 | |
| 196 if (version > 2) { | |
| 197 int64 date_synced = 0; | |
| 198 if (!iter.ReadInt64(&date_synced)) { | |
| 199 LogDeserializationWarning(version, signon_realm, false); | |
| 200 return false; | |
| 201 } | |
| 202 form->date_synced = base::Time::FromInternalValue(date_synced); | |
| 203 } | |
| 204 | |
| 205 if (version > 3) { | |
| 206 if (!iter.ReadString16(&form->display_name) || | |
| 207 !ReadGURL(&iter, warn_only, &form->avatar_url) || | |
| 208 !ReadGURL(&iter, warn_only, &form->federation_url) || | |
| 209 !iter.ReadBool(&form->skip_zero_click)) { | |
| 210 LogDeserializationWarning(version, signon_realm, false); | |
| 211 return false; | |
| 212 } | |
| 213 } | |
| 214 | |
| 215 if (version > 4) { | |
| 216 form->date_created = base::Time::FromInternalValue(date_created); | |
| 217 } else { | |
| 218 form->date_created = base::Time::FromTimeT(date_created); | |
| 219 } | |
| 220 | |
| 221 if (version > 5) { | |
| 222 if (!iter.ReadInt(&generation_upload_status)) { | |
| 223 LogDeserializationWarning(version, signon_realm, false); | |
| 224 } | |
| 225 form->generation_upload_status = | |
| 226 static_cast<PasswordForm::GenerationUploadStatus>( | |
| 227 generation_upload_status); | |
| 228 } | |
| 229 | |
| 230 converted_forms.push_back(form.release()); | |
| 231 } | |
| 232 | |
| 233 forms->swap(converted_forms); | |
| 234 return true; | |
| 235 } | |
| 236 | |
| 237 // Serializes a list of PasswordForms to be stored in the wallet. | |
| 238 void SerializeValue(const std::vector<autofill::PasswordForm*>& forms, | |
| 239 Pickle* pickle) { | |
| 240 pickle->WriteInt(kPickleVersion); | |
| 241 pickle->WriteSizeT(forms.size()); | |
| 242 for (autofill::PasswordForm* form : forms) { | |
| 243 pickle->WriteInt(form->scheme); | |
| 244 pickle->WriteString(form->origin.spec()); | |
| 245 pickle->WriteString(form->action.spec()); | |
| 246 pickle->WriteString16(form->username_element); | |
| 247 pickle->WriteString16(form->username_value); | |
| 248 pickle->WriteString16(form->password_element); | |
| 249 pickle->WriteString16(form->password_value); | |
| 250 pickle->WriteString16(form->submit_element); | |
| 251 pickle->WriteBool(form->ssl_valid); | |
| 252 pickle->WriteBool(form->preferred); | |
| 253 pickle->WriteBool(form->blacklisted_by_user); | |
| 254 pickle->WriteInt64(form->date_created.ToInternalValue()); | |
| 255 pickle->WriteInt(form->type); | |
| 256 pickle->WriteInt(form->times_used); | |
| 257 autofill::SerializeFormData(form->form_data, pickle); | |
| 258 pickle->WriteInt64(form->date_synced.ToInternalValue()); | |
| 259 pickle->WriteString16(form->display_name); | |
| 260 pickle->WriteString(form->avatar_url.spec()); | |
| 261 pickle->WriteString(form->federation_url.spec()); | |
| 262 pickle->WriteBool(form->skip_zero_click); | |
| 263 } | |
| 264 } | |
| 265 | |
| 266 // Moves the content of |second| to the end of |first|. | |
| 267 void AppendSecondToFirst(ScopedVector<autofill::PasswordForm>* first, | |
|
engedy
2015/02/25 15:17:48
In the long run, we should contribute such a metho
vabr (Chromium)
2015/03/09 10:56:18
Sadly, cannot be done: https://groups.google.com/a
engedy
2015/03/09 13:33:17
Thanks a lot for investigating! I think it is actu
| |
| 268 ScopedVector<autofill::PasswordForm> second) { | |
| 269 first->reserve(first->size() + second.size()); | |
| 270 first->insert(first->end(), second.begin(), second.end()); | |
| 271 second.weak_clear(); | |
| 272 } | |
| 273 | |
| 103 } // namespace | 274 } // namespace |
| 104 | 275 |
| 105 NativeBackendKWallet::NativeBackendKWallet(LocalProfileId id) | 276 NativeBackendKWallet::NativeBackendKWallet(LocalProfileId id) |
| 106 : profile_id_(id), | 277 : profile_id_(id), |
| 107 kwallet_proxy_(nullptr), | 278 kwallet_proxy_(nullptr), |
| 108 app_name_(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME)) { | 279 app_name_(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME)) { |
| 109 folder_name_ = GetProfileSpecificFolderName(); | 280 folder_name_ = GetProfileSpecificFolderName(); |
| 110 } | 281 } |
| 111 | 282 |
| 112 NativeBackendKWallet::~NativeBackendKWallet() { | 283 NativeBackendKWallet::~NativeBackendKWallet() { |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 364 bool NativeBackendKWallet::RemoveLoginsSyncedBetween( | 535 bool NativeBackendKWallet::RemoveLoginsSyncedBetween( |
| 365 base::Time delete_begin, | 536 base::Time delete_begin, |
| 366 base::Time delete_end, | 537 base::Time delete_end, |
| 367 password_manager::PasswordStoreChangeList* changes) { | 538 password_manager::PasswordStoreChangeList* changes) { |
| 368 return RemoveLoginsBetween(delete_begin, delete_end, SYNC_TIMESTAMP, changes); | 539 return RemoveLoginsBetween(delete_begin, delete_end, SYNC_TIMESTAMP, changes); |
| 369 } | 540 } |
| 370 | 541 |
| 371 bool NativeBackendKWallet::GetLogins( | 542 bool NativeBackendKWallet::GetLogins( |
| 372 const PasswordForm& form, | 543 const PasswordForm& form, |
| 373 ScopedVector<autofill::PasswordForm>* forms) { | 544 ScopedVector<autofill::PasswordForm>* forms) { |
| 374 int wallet_handle = WalletHandle(); | 545 int wallet_handle = WalletHandle(); |
|
engedy
2015/02/25 15:17:48
Need to clear |forms| here (or above this line). 3
vabr (Chromium)
2015/03/09 10:56:18
Done.
Since I removed the comment guarantees abou
| |
| 375 if (wallet_handle == kInvalidKWalletHandle) | 546 if (wallet_handle == kInvalidKWalletHandle) |
| 376 return false; | 547 return false; |
| 377 return GetLoginsList(form.signon_realm, wallet_handle, forms); | 548 return GetLoginsList(form.signon_realm, wallet_handle, forms); |
| 378 } | 549 } |
| 379 | 550 |
| 380 bool NativeBackendKWallet::GetAutofillableLogins( | 551 bool NativeBackendKWallet::GetAutofillableLogins( |
| 381 ScopedVector<autofill::PasswordForm>* forms) { | 552 ScopedVector<autofill::PasswordForm>* forms) { |
| 382 int wallet_handle = WalletHandle(); | 553 int wallet_handle = WalletHandle(); |
| 383 if (wallet_handle == kInvalidKWalletHandle) | 554 if (wallet_handle == kInvalidKWalletHandle) |
| 384 return false; | 555 return false; |
| 385 return GetLoginsList(true, wallet_handle, forms); | 556 return GetLoginsList(BlacklistOptions::AUTOFILLABLE, wallet_handle, forms); |
| 386 } | 557 } |
| 387 | 558 |
| 388 bool NativeBackendKWallet::GetBlacklistLogins( | 559 bool NativeBackendKWallet::GetBlacklistLogins( |
| 389 ScopedVector<autofill::PasswordForm>* forms) { | 560 ScopedVector<autofill::PasswordForm>* forms) { |
| 390 int wallet_handle = WalletHandle(); | 561 int wallet_handle = WalletHandle(); |
| 391 if (wallet_handle == kInvalidKWalletHandle) | 562 if (wallet_handle == kInvalidKWalletHandle) |
| 392 return false; | 563 return false; |
| 393 return GetLoginsList(false, wallet_handle, forms); | 564 return GetLoginsList(BlacklistOptions::BLACKLISTED, wallet_handle, forms); |
| 394 } | 565 } |
| 395 | 566 |
| 396 bool NativeBackendKWallet::GetLoginsList( | 567 bool NativeBackendKWallet::GetLoginsList( |
| 397 const std::string& signon_realm, | 568 const std::string& signon_realm, |
| 398 int wallet_handle, | 569 int wallet_handle, |
| 399 ScopedVector<autofill::PasswordForm>* forms) { | 570 ScopedVector<autofill::PasswordForm>* forms) { |
| 571 forms->clear(); | |
| 400 // Is there an entry in the wallet? | 572 // Is there an entry in the wallet? |
| 401 { | 573 { |
| 402 dbus::MethodCall method_call(kKWalletInterface, "hasEntry"); | 574 dbus::MethodCall method_call(kKWalletInterface, "hasEntry"); |
| 403 dbus::MessageWriter builder(&method_call); | 575 dbus::MessageWriter builder(&method_call); |
| 404 builder.AppendInt32(wallet_handle); // handle | 576 builder.AppendInt32(wallet_handle); // handle |
| 405 builder.AppendString(folder_name_); // folder | 577 builder.AppendString(folder_name_); // folder |
| 406 builder.AppendString(signon_realm); // key | 578 builder.AppendString(signon_realm); // key |
| 407 builder.AppendString(app_name_); // appid | 579 builder.AppendString(app_name_); // appid |
| 408 scoped_ptr<dbus::Response> response( | 580 scoped_ptr<dbus::Response> response( |
| 409 kwallet_proxy_->CallMethodAndBlock( | 581 kwallet_proxy_->CallMethodAndBlock( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 if (!CheckSerializedValue(bytes, length, signon_realm)) { | 624 if (!CheckSerializedValue(bytes, length, signon_realm)) { |
| 453 // This is weird, but we choose not to call it an error. There is an | 625 // This is weird, but we choose not to call it an error. There is an |
| 454 // invalid entry somehow, but by just ignoring it, we make it easier to | 626 // invalid entry somehow, but by just ignoring it, we make it easier to |
| 455 // repair without having to delete it using kwalletmanager (that is, by | 627 // repair without having to delete it using kwalletmanager (that is, by |
| 456 // just saving a new password within this realm to overwrite it). | 628 // just saving a new password within this realm to overwrite it). |
| 457 return true; | 629 return true; |
| 458 } | 630 } |
| 459 | 631 |
| 460 // Can't we all just agree on whether bytes are signed or not? Please? | 632 // Can't we all just agree on whether bytes are signed or not? Please? |
| 461 Pickle pickle(reinterpret_cast<const char*>(bytes), length); | 633 Pickle pickle(reinterpret_cast<const char*>(bytes), length); |
| 462 DeserializeValue(signon_realm, pickle, forms); | 634 *forms = DeserializeValue(signon_realm, pickle); |
| 463 } | 635 } |
| 464 | 636 |
| 465 return true; | 637 return true; |
| 466 } | 638 } |
| 467 | 639 |
| 468 bool NativeBackendKWallet::GetLoginsList( | 640 bool NativeBackendKWallet::GetLoginsList( |
| 469 bool autofillable, | 641 BlacklistOptions options, |
| 470 int wallet_handle, | 642 int wallet_handle, |
| 471 ScopedVector<autofill::PasswordForm>* forms) { | 643 ScopedVector<autofill::PasswordForm>* forms) { |
| 644 forms->clear(); | |
| 472 ScopedVector<autofill::PasswordForm> all_forms; | 645 ScopedVector<autofill::PasswordForm> all_forms; |
| 473 if (!GetAllLogins(wallet_handle, &all_forms)) | 646 if (!GetAllLogins(wallet_handle, &all_forms)) |
| 474 return false; | 647 return false; |
| 475 | 648 |
| 476 // We have to read all the entries, and then filter them here. | 649 // We have to read all the entries, and then filter them here. |
| 477 forms->reserve(forms->size() + all_forms.size()); | 650 forms->reserve(all_forms.size()); |
| 478 for (auto& saved_form : all_forms) { | 651 for (auto& saved_form : all_forms) { |
| 479 if (saved_form->blacklisted_by_user == !autofillable) { | 652 if (saved_form->blacklisted_by_user == |
| 653 (options == BlacklistOptions::BLACKLISTED)) { | |
| 480 forms->push_back(saved_form); | 654 forms->push_back(saved_form); |
| 481 saved_form = nullptr; | 655 saved_form = nullptr; |
| 482 } | 656 } |
| 483 } | 657 } |
| 484 | 658 |
| 485 return true; | 659 return true; |
| 486 } | 660 } |
| 487 | 661 |
| 488 bool NativeBackendKWallet::GetAllLogins( | 662 bool NativeBackendKWallet::GetAllLogins( |
| 489 int wallet_handle, | 663 int wallet_handle, |
| 490 ScopedVector<autofill::PasswordForm>* forms) { | 664 ScopedVector<autofill::PasswordForm>* forms) { |
| 665 forms->clear(); | |
| 491 // We could probably also use readEntryList here. | 666 // We could probably also use readEntryList here. |
| 492 std::vector<std::string> realm_list; | 667 std::vector<std::string> realm_list; |
| 493 { | 668 { |
| 494 dbus::MethodCall method_call(kKWalletInterface, "entryList"); | 669 dbus::MethodCall method_call(kKWalletInterface, "entryList"); |
| 495 dbus::MessageWriter builder(&method_call); | 670 dbus::MessageWriter builder(&method_call); |
| 496 builder.AppendInt32(wallet_handle); // handle | 671 builder.AppendInt32(wallet_handle); // handle |
| 497 builder.AppendString(folder_name_); // folder | 672 builder.AppendString(folder_name_); // folder |
| 498 builder.AppendString(app_name_); // appid | 673 builder.AppendString(app_name_); // appid |
| 499 scoped_ptr<dbus::Response> response( | 674 scoped_ptr<dbus::Response> response( |
| 500 kwallet_proxy_->CallMethodAndBlock( | 675 kwallet_proxy_->CallMethodAndBlock( |
| 501 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | 676 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 502 if (!response.get()) { | 677 if (!response.get()) { |
| 503 LOG(ERROR) << "Error contacting kwalletd (entryList)"; | 678 LOG(ERROR) << "Error contacting kwalletd (entryList)"; |
| 504 return false; | 679 return false; |
| 505 } | 680 } |
| 506 dbus::MessageReader reader(response.get()); | 681 dbus::MessageReader reader(response.get()); |
| 507 if (!reader.PopArrayOfStrings(&realm_list)) { | 682 if (!reader.PopArrayOfStrings(&realm_list)) { |
| 508 LOG(ERROR) << "Error reading response from kwalletd (entryList): " | 683 LOG(ERROR) << "Error reading response from kwalletd (entryList): " |
| 509 << response->ToString(); | 684 << response->ToString(); |
| 510 return false; | 685 return false; |
| 511 } | 686 } |
| 512 } | 687 } |
| 513 | 688 |
| 514 for (size_t i = 0; i < realm_list.size(); ++i) { | 689 // Swapping |collected_forms| with |*forms| just before "return true" makes |
| 515 const std::string& signon_realm = realm_list[i]; | 690 // sure partial results are not returned on failure. |
| 691 ScopedVector<autofill::PasswordForm> collected_forms; | |
| 692 for (const std::string& signon_realm : realm_list) { | |
| 516 dbus::MethodCall method_call(kKWalletInterface, "readEntry"); | 693 dbus::MethodCall method_call(kKWalletInterface, "readEntry"); |
| 517 dbus::MessageWriter builder(&method_call); | 694 dbus::MessageWriter builder(&method_call); |
| 518 builder.AppendInt32(wallet_handle); // handle | 695 builder.AppendInt32(wallet_handle); // handle |
| 519 builder.AppendString(folder_name_); // folder | 696 builder.AppendString(folder_name_); // folder |
| 520 builder.AppendString(signon_realm); // key | 697 builder.AppendString(signon_realm); // key |
| 521 builder.AppendString(app_name_); // appid | 698 builder.AppendString(app_name_); // appid |
| 522 scoped_ptr<dbus::Response> response( | 699 scoped_ptr<dbus::Response> response( |
| 523 kwallet_proxy_->CallMethodAndBlock( | 700 kwallet_proxy_->CallMethodAndBlock( |
| 524 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | 701 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
| 525 if (!response.get()) { | 702 if (!response.get()) { |
| 526 LOG(ERROR) << "Error contacting kwalletd (readEntry)"; | 703 LOG(ERROR) << "Error contacting kwalletd (readEntry)"; |
| 527 return false; | 704 return false; |
| 528 } | 705 } |
| 529 dbus::MessageReader reader(response.get()); | 706 dbus::MessageReader reader(response.get()); |
| 530 const uint8_t* bytes = nullptr; | 707 const uint8_t* bytes = nullptr; |
| 531 size_t length = 0; | 708 size_t length = 0; |
| 532 if (!reader.PopArrayOfBytes(&bytes, &length)) { | 709 if (!reader.PopArrayOfBytes(&bytes, &length)) { |
| 533 LOG(ERROR) << "Error reading response from kwalletd (readEntry): " | 710 LOG(ERROR) << "Error reading response from kwalletd (readEntry): " |
| 534 << response->ToString(); | 711 << response->ToString(); |
| 535 return false; | 712 return false; |
| 536 } | 713 } |
| 537 if (!bytes || !CheckSerializedValue(bytes, length, signon_realm)) | 714 if (!bytes || !CheckSerializedValue(bytes, length, signon_realm)) |
| 538 continue; | 715 continue; |
| 539 | 716 |
| 540 // Can't we all just agree on whether bytes are signed or not? Please? | 717 // Can't we all just agree on whether bytes are signed or not? Please? |
| 541 Pickle pickle(reinterpret_cast<const char*>(bytes), length); | 718 Pickle pickle(reinterpret_cast<const char*>(bytes), length); |
| 542 DeserializeValue(signon_realm, pickle, forms); | 719 AppendSecondToFirst(&collected_forms, |
| 720 DeserializeValue(signon_realm, pickle)); | |
| 543 } | 721 } |
| 722 forms->swap(collected_forms); | |
| 544 return true; | 723 return true; |
| 545 } | 724 } |
| 546 | 725 |
| 547 bool NativeBackendKWallet::SetLoginsList( | 726 bool NativeBackendKWallet::SetLoginsList( |
| 548 const std::vector<autofill::PasswordForm*>& forms, | 727 const std::vector<autofill::PasswordForm*>& forms, |
| 549 const std::string& signon_realm, | 728 const std::string& signon_realm, |
| 550 int wallet_handle) { | 729 int wallet_handle) { |
| 551 if (forms.empty()) { | 730 if (forms.empty()) { |
| 552 // No items left? Remove the entry from the wallet. | 731 // No items left? Remove the entry from the wallet. |
| 553 dbus::MethodCall method_call(kKWalletInterface, "removeEntry"); | 732 dbus::MethodCall method_call(kKWalletInterface, "removeEntry"); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 if (!reader.PopArrayOfBytes(&bytes, &length)) { | 848 if (!reader.PopArrayOfBytes(&bytes, &length)) { |
| 670 LOG(ERROR) << "Error reading response from kwalletd (readEntry): " | 849 LOG(ERROR) << "Error reading response from kwalletd (readEntry): " |
| 671 << response->ToString(); | 850 << response->ToString(); |
| 672 continue; | 851 continue; |
| 673 } | 852 } |
| 674 if (!bytes || !CheckSerializedValue(bytes, length, signon_realm)) | 853 if (!bytes || !CheckSerializedValue(bytes, length, signon_realm)) |
| 675 continue; | 854 continue; |
| 676 | 855 |
| 677 // Can't we all just agree on whether bytes are signed or not? Please? | 856 // Can't we all just agree on whether bytes are signed or not? Please? |
| 678 Pickle pickle(reinterpret_cast<const char*>(bytes), length); | 857 Pickle pickle(reinterpret_cast<const char*>(bytes), length); |
| 679 ScopedVector<autofill::PasswordForm> all_forms; | 858 ScopedVector<autofill::PasswordForm> all_forms = |
| 680 DeserializeValue(signon_realm, pickle, &all_forms); | 859 DeserializeValue(signon_realm, pickle); |
| 681 | 860 |
| 682 ScopedVector<autofill::PasswordForm> kept_forms; | 861 ScopedVector<autofill::PasswordForm> kept_forms; |
| 683 kept_forms.reserve(all_forms.size()); | 862 kept_forms.reserve(all_forms.size()); |
| 684 base::Time autofill::PasswordForm::*date_member = | 863 base::Time autofill::PasswordForm::*date_member = |
| 685 date_to_compare == CREATION_TIMESTAMP | 864 date_to_compare == CREATION_TIMESTAMP |
| 686 ? &autofill::PasswordForm::date_created | 865 ? &autofill::PasswordForm::date_created |
| 687 : &autofill::PasswordForm::date_synced; | 866 : &autofill::PasswordForm::date_synced; |
| 688 for (auto& saved_form : all_forms) { | 867 for (auto& saved_form : all_forms) { |
| 689 if (delete_begin <= saved_form->*date_member && | 868 if (delete_begin <= saved_form->*date_member && |
| 690 (delete_end.is_null() || saved_form->*date_member < delete_end)) { | 869 (delete_end.is_null() || saved_form->*date_member < delete_end)) { |
| 691 changes->push_back(password_manager::PasswordStoreChange( | 870 changes->push_back(password_manager::PasswordStoreChange( |
| 692 password_manager::PasswordStoreChange::REMOVE, *saved_form)); | 871 password_manager::PasswordStoreChange::REMOVE, *saved_form)); |
| 693 } else { | 872 } else { |
| 694 kept_forms.push_back(saved_form); | 873 kept_forms.push_back(saved_form); |
| 695 saved_form = nullptr; | 874 saved_form = nullptr; |
| 696 } | 875 } |
| 697 } | 876 } |
| 698 | 877 |
| 699 if (!SetLoginsList(kept_forms.get(), signon_realm, wallet_handle)) { | 878 if (!SetLoginsList(kept_forms.get(), signon_realm, wallet_handle)) { |
| 700 ok = false; | 879 ok = false; |
| 701 changes->clear(); | 880 changes->clear(); |
| 702 } | 881 } |
| 703 } | 882 } |
| 704 return ok; | 883 return ok; |
| 705 } | 884 } |
| 706 | 885 |
| 707 // static | 886 // static |
| 708 void NativeBackendKWallet::SerializeValue( | 887 ScopedVector<autofill::PasswordForm> NativeBackendKWallet::DeserializeValue( |
| 709 const std::vector<autofill::PasswordForm*>& forms, | |
| 710 Pickle* pickle) { | |
| 711 pickle->WriteInt(kPickleVersion); | |
| 712 pickle->WriteSizeT(forms.size()); | |
| 713 for (autofill::PasswordForm* form : forms) { | |
| 714 pickle->WriteInt(form->scheme); | |
| 715 pickle->WriteString(form->origin.spec()); | |
| 716 pickle->WriteString(form->action.spec()); | |
| 717 pickle->WriteString16(form->username_element); | |
| 718 pickle->WriteString16(form->username_value); | |
| 719 pickle->WriteString16(form->password_element); | |
| 720 pickle->WriteString16(form->password_value); | |
| 721 pickle->WriteString16(form->submit_element); | |
| 722 pickle->WriteBool(form->ssl_valid); | |
| 723 pickle->WriteBool(form->preferred); | |
| 724 pickle->WriteBool(form->blacklisted_by_user); | |
| 725 pickle->WriteInt64(form->date_created.ToInternalValue()); | |
| 726 pickle->WriteInt(form->type); | |
| 727 pickle->WriteInt(form->times_used); | |
| 728 autofill::SerializeFormData(form->form_data, pickle); | |
| 729 pickle->WriteInt64(form->date_synced.ToInternalValue()); | |
| 730 pickle->WriteString16(form->display_name); | |
| 731 pickle->WriteString(form->avatar_url.spec()); | |
| 732 pickle->WriteString(form->federation_url.spec()); | |
| 733 pickle->WriteBool(form->skip_zero_click); | |
| 734 pickle->WriteInt(form->generation_upload_status); | |
| 735 } | |
| 736 } | |
| 737 | |
| 738 // static | |
| 739 bool NativeBackendKWallet::DeserializeValueSize( | |
| 740 const std::string& signon_realm, | 888 const std::string& signon_realm, |
| 741 const PickleIterator& init_iter, | 889 const Pickle& pickle) { |
| 742 int version, | |
| 743 bool size_32, | |
| 744 bool warn_only, | |
| 745 ScopedVector<autofill::PasswordForm>* forms) { | |
| 746 PickleIterator iter = init_iter; | |
| 747 | |
| 748 size_t count = 0; | |
| 749 if (size_32) { | |
| 750 uint32_t count_32 = 0; | |
| 751 if (!iter.ReadUInt32(&count_32)) { | |
| 752 LOG(ERROR) << "Failed to deserialize KWallet entry " | |
| 753 << "(realm: " << signon_realm << ")"; | |
| 754 return false; | |
| 755 } | |
| 756 count = count_32; | |
| 757 } else { | |
| 758 if (!iter.ReadSizeT(&count)) { | |
| 759 LOG(ERROR) << "Failed to deserialize KWallet entry " | |
| 760 << "(realm: " << signon_realm << ")"; | |
| 761 return false; | |
| 762 } | |
| 763 } | |
| 764 | |
| 765 if (count > 0xFFFF) { | |
| 766 // Trying to pin down the cause of http://crbug.com/80728 (or fix it). | |
| 767 // This is a very large number of passwords to be saved for a single realm. | |
| 768 // It is almost certainly a corrupt pickle and not real data. Ignore it. | |
| 769 // This very well might actually be http://crbug.com/107701, so if we're | |
| 770 // reading an old pickle, we don't even log this the first time we try to | |
| 771 // read it. (That is, when we're reading the native architecture size.) | |
| 772 if (!warn_only) { | |
| 773 LOG(ERROR) << "Suspiciously large number of entries in KWallet entry " | |
| 774 << "(" << count << "; realm: " << signon_realm << ")"; | |
| 775 } | |
| 776 return false; | |
| 777 } | |
| 778 | |
| 779 forms->reserve(forms->size() + count); | |
| 780 for (size_t i = 0; i < count; ++i) { | |
| 781 scoped_ptr<PasswordForm> form(new PasswordForm()); | |
| 782 form->signon_realm.assign(signon_realm); | |
| 783 | |
| 784 int scheme = 0; | |
| 785 int64 date_created = 0; | |
| 786 int type = 0; | |
| 787 int generation_upload_status = 0; | |
| 788 // Note that these will be read back in the order listed due to | |
| 789 // short-circuit evaluation. This is important. | |
| 790 if (!iter.ReadInt(&scheme) || | |
| 791 !ReadGURL(&iter, warn_only, &form->origin) || | |
| 792 !ReadGURL(&iter, warn_only, &form->action) || | |
| 793 !iter.ReadString16(&form->username_element) || | |
| 794 !iter.ReadString16(&form->username_value) || | |
| 795 !iter.ReadString16(&form->password_element) || | |
| 796 !iter.ReadString16(&form->password_value) || | |
| 797 !iter.ReadString16(&form->submit_element) || | |
| 798 !iter.ReadBool(&form->ssl_valid) || | |
| 799 !iter.ReadBool(&form->preferred) || | |
| 800 !iter.ReadBool(&form->blacklisted_by_user) || | |
| 801 !iter.ReadInt64(&date_created)) { | |
| 802 LogDeserializationWarning(version, signon_realm, warn_only); | |
| 803 return false; | |
| 804 } | |
| 805 form->scheme = static_cast<PasswordForm::Scheme>(scheme); | |
| 806 | |
| 807 if (version > 1) { | |
| 808 if (!iter.ReadInt(&type) || | |
| 809 !iter.ReadInt(&form->times_used) || | |
| 810 !autofill::DeserializeFormData(&iter, &form->form_data)) { | |
| 811 LogDeserializationWarning(version, signon_realm, false); | |
| 812 return false; | |
| 813 } | |
| 814 form->type = static_cast<PasswordForm::Type>(type); | |
| 815 } | |
| 816 | |
| 817 if (version > 2) { | |
| 818 int64 date_synced = 0; | |
| 819 if (!iter.ReadInt64(&date_synced)) { | |
| 820 LogDeserializationWarning(version, signon_realm, false); | |
| 821 return false; | |
| 822 } | |
| 823 form->date_synced = base::Time::FromInternalValue(date_synced); | |
| 824 } | |
| 825 | |
| 826 if (version > 3) { | |
| 827 if (!iter.ReadString16(&form->display_name) || | |
| 828 !ReadGURL(&iter, warn_only, &form->avatar_url) || | |
| 829 !ReadGURL(&iter, warn_only, &form->federation_url) || | |
| 830 !iter.ReadBool(&form->skip_zero_click)) { | |
| 831 LogDeserializationWarning(version, signon_realm, false); | |
| 832 return false; | |
| 833 } | |
| 834 } | |
| 835 | |
| 836 if (version > 4) { | |
| 837 form->date_created = base::Time::FromInternalValue(date_created); | |
| 838 } else { | |
| 839 form->date_created = base::Time::FromTimeT(date_created); | |
| 840 } | |
| 841 | |
| 842 if (version > 5) { | |
| 843 if (!iter.ReadInt(&generation_upload_status)) { | |
| 844 LogDeserializationWarning(version, signon_realm, false); | |
| 845 } | |
| 846 form->generation_upload_status = | |
| 847 static_cast<PasswordForm::GenerationUploadStatus>( | |
| 848 generation_upload_status); | |
| 849 } | |
| 850 | |
| 851 forms->push_back(form.release()); | |
| 852 } | |
| 853 | |
| 854 return true; | |
| 855 } | |
| 856 | |
| 857 // static | |
| 858 void NativeBackendKWallet::DeserializeValue( | |
| 859 const std::string& signon_realm, | |
| 860 const Pickle& pickle, | |
| 861 ScopedVector<autofill::PasswordForm>* forms) { | |
| 862 PickleIterator iter(pickle); | 890 PickleIterator iter(pickle); |
| 863 | 891 |
| 864 int version = -1; | 892 int version = -1; |
| 865 if (!iter.ReadInt(&version) || | 893 if (!iter.ReadInt(&version) || |
| 866 version < 0 || version > kPickleVersion) { | 894 version < 0 || version > kPickleVersion) { |
| 867 LOG(ERROR) << "Failed to deserialize KWallet entry " | 895 LOG(ERROR) << "Failed to deserialize KWallet entry " |
| 868 << "(realm: " << signon_realm << ")"; | 896 << "(realm: " << signon_realm << ")"; |
| 869 return; | 897 return ScopedVector<autofill::PasswordForm>(); |
| 870 } | 898 } |
| 871 | 899 |
| 900 ScopedVector<autofill::PasswordForm> forms; | |
| 872 if (version > 0) { | 901 if (version > 0) { |
| 873 // In current pickles, we expect 64-bit sizes. Failure is an error. | 902 // In current pickles, we expect 64-bit sizes. Failure is an error. |
| 874 DeserializeValueSize(signon_realm, iter, version, false, false, forms); | 903 DeserializeValueSize(signon_realm, iter, version, false, false, &forms); |
| 875 return; | 904 return forms.Pass(); |
| 876 } | 905 } |
| 877 | 906 |
| 878 const size_t saved_forms_size = forms->size(); | |
| 879 const bool size_32 = sizeof(size_t) == sizeof(uint32_t); | 907 const bool size_32 = sizeof(size_t) == sizeof(uint32_t); |
| 880 if (!DeserializeValueSize( | 908 if (!DeserializeValueSize( |
| 881 signon_realm, iter, version, size_32, true, forms)) { | 909 signon_realm, iter, version, size_32, true, &forms)) { |
| 882 // We failed to read the pickle using the native architecture of the system. | 910 // We failed to read the pickle using the native architecture of the system. |
| 883 // Try again with the opposite architecture. Note that we do this even on | 911 // Try again with the opposite architecture. Note that we do this even on |
| 884 // 32-bit machines, in case we're reading a 64-bit pickle. (Probably rare, | 912 // 32-bit machines, in case we're reading a 64-bit pickle. (Probably rare, |
| 885 // since mostly we expect upgrades, not downgrades, but both are possible.) | 913 // since mostly we expect upgrades, not downgrades, but both are possible.) |
| 886 forms->resize(saved_forms_size); | 914 DeserializeValueSize(signon_realm, iter, version, !size_32, false, &forms); |
| 887 DeserializeValueSize(signon_realm, iter, version, !size_32, false, forms); | |
| 888 } | 915 } |
| 916 return forms.Pass(); | |
| 889 } | 917 } |
| 890 | 918 |
| 891 int NativeBackendKWallet::WalletHandle() { | 919 int NativeBackendKWallet::WalletHandle() { |
| 892 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 920 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 893 | 921 |
| 894 // Open the wallet. | 922 // Open the wallet. |
| 895 // TODO(mdm): Are we leaking these handles? Find out. | 923 // TODO(mdm): Are we leaking these handles? Find out. |
| 896 int32_t handle = kInvalidKWalletHandle; | 924 int32_t handle = kInvalidKWalletHandle; |
| 897 { | 925 { |
| 898 dbus::MethodCall method_call(kKWalletInterface, "open"); | 926 dbus::MethodCall method_call(kKWalletInterface, "open"); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 970 } | 998 } |
| 971 | 999 |
| 972 return handle; | 1000 return handle; |
| 973 } | 1001 } |
| 974 | 1002 |
| 975 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { | 1003 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { |
| 976 // Originally, the folder name was always just "Chrome Form Data". | 1004 // Originally, the folder name was always just "Chrome Form Data". |
| 977 // Now we use it to distinguish passwords for different profiles. | 1005 // Now we use it to distinguish passwords for different profiles. |
| 978 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); | 1006 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); |
| 979 } | 1007 } |
| OLD | NEW |