OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/password_manager/core/browser/login_database.h" | 5 #include "components/password_manager/core/browser/login_database.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
| 11 #include <map> |
11 #include <utility> | 12 #include <utility> |
12 | 13 |
13 #include "base/bind.h" | 14 #include "base/bind.h" |
14 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/metrics/histogram_macros.h" | 18 #include "base/metrics/histogram_macros.h" |
18 #include "base/metrics/sparse_histogram.h" | 19 #include "base/metrics/sparse_histogram.h" |
19 #include "base/pickle.h" | 20 #include "base/pickle.h" |
20 #include "base/stl_util.h" | 21 #include "base/stl_util.h" |
(...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 bool LoginDatabase::DisableAutoSignInForAllLogins() { | 1051 bool LoginDatabase::DisableAutoSignInForAllLogins() { |
1051 sql::Statement s(db_.GetCachedStatement( | 1052 sql::Statement s(db_.GetCachedStatement( |
1052 SQL_FROM_HERE, "UPDATE logins SET skip_zero_click = 1;")); | 1053 SQL_FROM_HERE, "UPDATE logins SET skip_zero_click = 1;")); |
1053 | 1054 |
1054 return s.Run(); | 1055 return s.Run(); |
1055 } | 1056 } |
1056 | 1057 |
1057 // static | 1058 // static |
1058 LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement( | 1059 LoginDatabase::EncryptionResult LoginDatabase::InitPasswordFormFromStatement( |
1059 PasswordForm* form, | 1060 PasswordForm* form, |
1060 sql::Statement& s) { | 1061 sql::Statement* s) { |
1061 std::string encrypted_password; | 1062 std::string encrypted_password; |
1062 s.ColumnBlobAsString(COLUMN_PASSWORD_VALUE, &encrypted_password); | 1063 s->ColumnBlobAsString(COLUMN_PASSWORD_VALUE, &encrypted_password); |
1063 base::string16 decrypted_password; | 1064 base::string16 decrypted_password; |
1064 EncryptionResult encryption_result = | 1065 EncryptionResult encryption_result = |
1065 DecryptedString(encrypted_password, &decrypted_password); | 1066 DecryptedString(encrypted_password, &decrypted_password); |
1066 if (encryption_result != ENCRYPTION_RESULT_SUCCESS) { | 1067 if (encryption_result != ENCRYPTION_RESULT_SUCCESS) { |
1067 VLOG(0) << "Password decryption failed, encryption_result is " | 1068 VLOG(0) << "Password decryption failed, encryption_result is " |
1068 << encryption_result; | 1069 << encryption_result; |
1069 return encryption_result; | 1070 return encryption_result; |
1070 } | 1071 } |
1071 | 1072 |
1072 std::string tmp = s.ColumnString(COLUMN_ORIGIN_URL); | 1073 std::string tmp = s->ColumnString(COLUMN_ORIGIN_URL); |
1073 form->origin = GURL(tmp); | 1074 form->origin = GURL(tmp); |
1074 tmp = s.ColumnString(COLUMN_ACTION_URL); | 1075 tmp = s->ColumnString(COLUMN_ACTION_URL); |
1075 form->action = GURL(tmp); | 1076 form->action = GURL(tmp); |
1076 form->username_element = s.ColumnString16(COLUMN_USERNAME_ELEMENT); | 1077 form->username_element = s->ColumnString16(COLUMN_USERNAME_ELEMENT); |
1077 form->username_value = s.ColumnString16(COLUMN_USERNAME_VALUE); | 1078 form->username_value = s->ColumnString16(COLUMN_USERNAME_VALUE); |
1078 form->password_element = s.ColumnString16(COLUMN_PASSWORD_ELEMENT); | 1079 form->password_element = s->ColumnString16(COLUMN_PASSWORD_ELEMENT); |
1079 form->password_value = decrypted_password; | 1080 form->password_value = decrypted_password; |
1080 form->submit_element = s.ColumnString16(COLUMN_SUBMIT_ELEMENT); | 1081 form->submit_element = s->ColumnString16(COLUMN_SUBMIT_ELEMENT); |
1081 tmp = s.ColumnString(COLUMN_SIGNON_REALM); | 1082 tmp = s->ColumnString(COLUMN_SIGNON_REALM); |
1082 form->signon_realm = tmp; | 1083 form->signon_realm = tmp; |
1083 form->ssl_valid = (s.ColumnInt(COLUMN_SSL_VALID) > 0); | 1084 form->ssl_valid = (s->ColumnInt(COLUMN_SSL_VALID) > 0); |
1084 form->preferred = (s.ColumnInt(COLUMN_PREFERRED) > 0); | 1085 form->preferred = (s->ColumnInt(COLUMN_PREFERRED) > 0); |
1085 form->date_created = | 1086 form->date_created = |
1086 base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE_CREATED)); | 1087 base::Time::FromInternalValue(s->ColumnInt64(COLUMN_DATE_CREATED)); |
1087 form->blacklisted_by_user = (s.ColumnInt(COLUMN_BLACKLISTED_BY_USER) > 0); | 1088 form->blacklisted_by_user = (s->ColumnInt(COLUMN_BLACKLISTED_BY_USER) > 0); |
1088 int scheme_int = s.ColumnInt(COLUMN_SCHEME); | 1089 int scheme_int = s->ColumnInt(COLUMN_SCHEME); |
1089 DCHECK_LE(0, scheme_int); | 1090 DCHECK_LE(0, scheme_int); |
1090 DCHECK_GE(PasswordForm::SCHEME_LAST, scheme_int); | 1091 DCHECK_GE(PasswordForm::SCHEME_LAST, scheme_int); |
1091 form->scheme = static_cast<PasswordForm::Scheme>(scheme_int); | 1092 form->scheme = static_cast<PasswordForm::Scheme>(scheme_int); |
1092 int type_int = s.ColumnInt(COLUMN_PASSWORD_TYPE); | 1093 int type_int = s->ColumnInt(COLUMN_PASSWORD_TYPE); |
1093 DCHECK(type_int >= 0 && type_int <= PasswordForm::TYPE_LAST) << type_int; | 1094 DCHECK(type_int >= 0 && type_int <= PasswordForm::TYPE_LAST) << type_int; |
1094 form->type = static_cast<PasswordForm::Type>(type_int); | 1095 form->type = static_cast<PasswordForm::Type>(type_int); |
1095 if (s.ColumnByteLength(COLUMN_POSSIBLE_USERNAMES)) { | 1096 if (s->ColumnByteLength(COLUMN_POSSIBLE_USERNAMES)) { |
1096 base::Pickle pickle( | 1097 base::Pickle pickle( |
1097 static_cast<const char*>(s.ColumnBlob(COLUMN_POSSIBLE_USERNAMES)), | 1098 static_cast<const char*>(s->ColumnBlob(COLUMN_POSSIBLE_USERNAMES)), |
1098 s.ColumnByteLength(COLUMN_POSSIBLE_USERNAMES)); | 1099 s->ColumnByteLength(COLUMN_POSSIBLE_USERNAMES)); |
1099 form->other_possible_usernames = DeserializeVector(pickle); | 1100 form->other_possible_usernames = DeserializeVector(pickle); |
1100 } | 1101 } |
1101 form->times_used = s.ColumnInt(COLUMN_TIMES_USED); | 1102 form->times_used = s->ColumnInt(COLUMN_TIMES_USED); |
1102 if (s.ColumnByteLength(COLUMN_FORM_DATA)) { | 1103 if (s->ColumnByteLength(COLUMN_FORM_DATA)) { |
1103 base::Pickle form_data_pickle( | 1104 base::Pickle form_data_pickle( |
1104 static_cast<const char*>(s.ColumnBlob(COLUMN_FORM_DATA)), | 1105 static_cast<const char*>(s->ColumnBlob(COLUMN_FORM_DATA)), |
1105 s.ColumnByteLength(COLUMN_FORM_DATA)); | 1106 s->ColumnByteLength(COLUMN_FORM_DATA)); |
1106 base::PickleIterator form_data_iter(form_data_pickle); | 1107 base::PickleIterator form_data_iter(form_data_pickle); |
1107 bool success = | 1108 bool success = |
1108 autofill::DeserializeFormData(&form_data_iter, &form->form_data); | 1109 autofill::DeserializeFormData(&form_data_iter, &form->form_data); |
1109 metrics_util::FormDeserializationStatus status = | 1110 metrics_util::FormDeserializationStatus status = |
1110 success ? metrics_util::LOGIN_DATABASE_SUCCESS | 1111 success ? metrics_util::LOGIN_DATABASE_SUCCESS |
1111 : metrics_util::LOGIN_DATABASE_FAILURE; | 1112 : metrics_util::LOGIN_DATABASE_FAILURE; |
1112 metrics_util::LogFormDataDeserializationStatus(status); | 1113 metrics_util::LogFormDataDeserializationStatus(status); |
1113 } | 1114 } |
1114 form->date_synced = | 1115 form->date_synced = |
1115 base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE_SYNCED)); | 1116 base::Time::FromInternalValue(s->ColumnInt64(COLUMN_DATE_SYNCED)); |
1116 form->display_name = s.ColumnString16(COLUMN_DISPLAY_NAME); | 1117 form->display_name = s->ColumnString16(COLUMN_DISPLAY_NAME); |
1117 form->icon_url = GURL(s.ColumnString(COLUMN_ICON_URL)); | 1118 form->icon_url = GURL(s->ColumnString(COLUMN_ICON_URL)); |
1118 form->federation_origin = | 1119 form->federation_origin = |
1119 url::Origin(GURL(s.ColumnString(COLUMN_FEDERATION_URL))); | 1120 url::Origin(GURL(s->ColumnString(COLUMN_FEDERATION_URL))); |
1120 form->skip_zero_click = (s.ColumnInt(COLUMN_SKIP_ZERO_CLICK) > 0); | 1121 form->skip_zero_click = (s->ColumnInt(COLUMN_SKIP_ZERO_CLICK) > 0); |
1121 int generation_upload_status_int = | 1122 int generation_upload_status_int = |
1122 s.ColumnInt(COLUMN_GENERATION_UPLOAD_STATUS); | 1123 s->ColumnInt(COLUMN_GENERATION_UPLOAD_STATUS); |
1123 DCHECK(generation_upload_status_int >= 0 && | 1124 DCHECK(generation_upload_status_int >= 0 && |
1124 generation_upload_status_int <= PasswordForm::UNKNOWN_STATUS); | 1125 generation_upload_status_int <= PasswordForm::UNKNOWN_STATUS); |
1125 form->generation_upload_status = | 1126 form->generation_upload_status = |
1126 static_cast<PasswordForm::GenerationUploadStatus>( | 1127 static_cast<PasswordForm::GenerationUploadStatus>( |
1127 generation_upload_status_int); | 1128 generation_upload_status_int); |
1128 return ENCRYPTION_RESULT_SUCCESS; | 1129 return ENCRYPTION_RESULT_SUCCESS; |
1129 } | 1130 } |
1130 | 1131 |
1131 bool LoginDatabase::GetLogins( | 1132 bool LoginDatabase::GetLogins( |
1132 const PasswordForm& form, | 1133 const PasswordForm& form, |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 bool LoginDatabase::StatementToForms( | 1317 bool LoginDatabase::StatementToForms( |
1317 sql::Statement* statement, | 1318 sql::Statement* statement, |
1318 const autofill::PasswordForm* matched_form, | 1319 const autofill::PasswordForm* matched_form, |
1319 ScopedVector<autofill::PasswordForm>* forms) { | 1320 ScopedVector<autofill::PasswordForm>* forms) { |
1320 PSLDomainMatchMetric psl_domain_match_metric = PSL_DOMAIN_MATCH_NONE; | 1321 PSLDomainMatchMetric psl_domain_match_metric = PSL_DOMAIN_MATCH_NONE; |
1321 | 1322 |
1322 forms->clear(); | 1323 forms->clear(); |
1323 while (statement->Step()) { | 1324 while (statement->Step()) { |
1324 std::unique_ptr<PasswordForm> new_form(new PasswordForm()); | 1325 std::unique_ptr<PasswordForm> new_form(new PasswordForm()); |
1325 EncryptionResult result = | 1326 EncryptionResult result = |
1326 InitPasswordFormFromStatement(new_form.get(), *statement); | 1327 InitPasswordFormFromStatement(new_form.get(), statement); |
1327 if (result == ENCRYPTION_RESULT_SERVICE_FAILURE) | 1328 if (result == ENCRYPTION_RESULT_SERVICE_FAILURE) |
1328 return false; | 1329 return false; |
1329 if (result == ENCRYPTION_RESULT_ITEM_FAILURE) | 1330 if (result == ENCRYPTION_RESULT_ITEM_FAILURE) |
1330 continue; | 1331 continue; |
1331 DCHECK_EQ(ENCRYPTION_RESULT_SUCCESS, result); | 1332 DCHECK_EQ(ENCRYPTION_RESULT_SUCCESS, result); |
1332 if (matched_form && matched_form->signon_realm != new_form->signon_realm) { | 1333 if (matched_form && matched_form->signon_realm != new_form->signon_realm) { |
1333 if (new_form->scheme != PasswordForm::SCHEME_HTML) | 1334 if (new_form->scheme != PasswordForm::SCHEME_HTML) |
1334 continue; // Ignore non-HTML matches. | 1335 continue; // Ignore non-HTML matches. |
1335 | 1336 |
1336 if (IsPublicSuffixDomainMatch(new_form->signon_realm, | 1337 if (IsPublicSuffixDomainMatch(new_form->signon_realm, |
(...skipping 14 matching lines...) Expand all Loading... |
1351 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", | 1352 UMA_HISTOGRAM_ENUMERATION("PasswordManager.PslDomainMatchTriggering", |
1352 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT); | 1353 psl_domain_match_metric, PSL_DOMAIN_MATCH_COUNT); |
1353 } | 1354 } |
1354 | 1355 |
1355 if (!statement->Succeeded()) | 1356 if (!statement->Succeeded()) |
1356 return false; | 1357 return false; |
1357 return true; | 1358 return true; |
1358 } | 1359 } |
1359 | 1360 |
1360 } // namespace password_manager | 1361 } // namespace password_manager |
OLD | NEW |