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

Side by Side Diff: components/password_manager/core/browser/login_database.cc

Issue 2899083004: Implement PasswordStore::GetLoginsForSameOrganizationName. (Closed)
Patch Set: Rebase. Created 3 years, 6 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 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>
(...skipping 12 matching lines...) Expand all
23 #include "base/stl_util.h" 23 #include "base/stl_util.h"
24 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
25 #include "base/strings/stringprintf.h" 25 #include "base/strings/stringprintf.h"
26 #include "base/time/time.h" 26 #include "base/time/time.h"
27 #include "build/build_config.h" 27 #include "build/build_config.h"
28 #include "components/autofill/core/common/password_form.h" 28 #include "components/autofill/core/common/password_form.h"
29 #include "components/password_manager/core/browser/affiliation_utils.h" 29 #include "components/password_manager/core/browser/affiliation_utils.h"
30 #include "components/password_manager/core/browser/password_manager_client.h" 30 #include "components/password_manager/core/browser/password_manager_client.h"
31 #include "components/password_manager/core/browser/password_manager_metrics_util .h" 31 #include "components/password_manager/core/browser/password_manager_metrics_util .h"
32 #include "components/password_manager/core/browser/password_manager_util.h" 32 #include "components/password_manager/core/browser/password_manager_util.h"
33 #include "components/password_manager/core/browser/psl_matching_helper.h"
33 #include "components/password_manager/core/browser/sql_table_builder.h" 34 #include "components/password_manager/core/browser/sql_table_builder.h"
34 #include "google_apis/gaia/gaia_auth_util.h" 35 #include "google_apis/gaia/gaia_auth_util.h"
35 #include "google_apis/gaia/gaia_urls.h" 36 #include "google_apis/gaia/gaia_urls.h"
36 #include "sql/connection.h" 37 #include "sql/connection.h"
37 #include "sql/statement.h" 38 #include "sql/statement.h"
38 #include "sql/transaction.h" 39 #include "sql/transaction.h"
40 #include "third_party/re2/src/re2/re2.h"
39 #include "url/origin.h" 41 #include "url/origin.h"
40 #include "url/url_constants.h" 42 #include "url/url_constants.h"
41 43
42 using autofill::PasswordForm; 44 using autofill::PasswordForm;
43 45
44 namespace password_manager { 46 namespace password_manager {
45 47
46 // The current version number of the login database schema. 48 // The current version number of the login database schema.
47 const int kCurrentVersionNumber = 19; 49 const int kCurrentVersionNumber = 19;
48 // The oldest version of the schema such that a legacy Chrome client using that 50 // The oldest version of the schema such that a legacy Chrome client using that
(...skipping 1077 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 1128
1127 bool success = StatementToForms( 1129 bool success = StatementToForms(
1128 &s, should_PSL_matching_apply || should_federated_apply ? &form : nullptr, 1130 &s, should_PSL_matching_apply || should_federated_apply ? &form : nullptr,
1129 forms); 1131 forms);
1130 if (success) 1132 if (success)
1131 return true; 1133 return true;
1132 forms->clear(); 1134 forms->clear();
1133 return false; 1135 return false;
1134 } 1136 }
1135 1137
1138 bool LoginDatabase::GetLoginsForSameOrganizationName(
1139 const std::string& signon_realm,
1140 std::vector<std::unique_ptr<autofill::PasswordForm>>* forms) const {
1141 DCHECK(forms);
1142 forms->clear();
1143
1144 GURL signon_realm_as_url(signon_realm);
1145 if (!signon_realm_as_url.SchemeIsHTTPOrHTTPS())
1146 return true;
1147
1148 std::string organization_name =
1149 GetOrganizationIdentifyingName(signon_realm_as_url);
1150 if (organization_name.empty())
1151 return true;
1152
1153 // SQLite does not provide a function to escape special characters, but
1154 // seemingly uses POSIX Extended Regular Expressions (ERE), and so does RE2.
1155 // In the worst case the bogus results will be filtered out below.
1156 static constexpr char kRESchemeAndSubdomains[] = "^https?://([\\w+%-]+\\.)*";
1157 static constexpr char kREDotAndEffectiveTLD[] = "(\\.[\\w+%-]+)+/$";
1158 const std::string signon_realms_with_same_organization_name_regexp =
1159 kRESchemeAndSubdomains + RE2::QuoteMeta(organization_name) +
1160 kREDotAndEffectiveTLD;
1161 sql::Statement s(db_.GetCachedStatement(
1162 SQL_FROM_HERE, get_same_organization_name_logins_statement_.c_str()));
1163 s.BindString(0, signon_realms_with_same_organization_name_regexp);
1164
1165 bool success = StatementToForms(&s, nullptr, forms);
1166
1167 using PasswordFormPtr = std::unique_ptr<autofill::PasswordForm>;
1168 base::EraseIf(*forms, [&organization_name](const PasswordFormPtr& form) {
1169 GURL candidate_signon_realm_as_url(form->signon_realm);
1170 DCHECK_EQ(form->scheme, PasswordForm::SCHEME_HTML);
1171 DCHECK(candidate_signon_realm_as_url.SchemeIsHTTPOrHTTPS());
1172 std::string candidate_form_organization_name =
1173 GetOrganizationIdentifyingName(candidate_signon_realm_as_url);
1174 return candidate_form_organization_name != organization_name;
1175 });
1176
1177 return success;
1178 }
1179
1136 bool LoginDatabase::GetLoginsCreatedBetween( 1180 bool LoginDatabase::GetLoginsCreatedBetween(
1137 const base::Time begin, 1181 const base::Time begin,
1138 const base::Time end, 1182 const base::Time end,
1139 std::vector<std::unique_ptr<PasswordForm>>* forms) const { 1183 std::vector<std::unique_ptr<PasswordForm>>* forms) const {
1140 DCHECK(forms); 1184 DCHECK(forms);
1141 DCHECK(!created_statement_.empty()); 1185 DCHECK(!created_statement_.empty());
1142 sql::Statement s( 1186 sql::Statement s(
1143 db_.GetCachedStatement(SQL_FROM_HERE, created_statement_.c_str())); 1187 db_.GetCachedStatement(SQL_FROM_HERE, created_statement_.c_str()));
1144 s.BindInt64(0, begin.ToInternalValue()); 1188 s.BindInt64(0, begin.ToInternalValue());
1145 s.BindInt64(1, end.is_null() ? std::numeric_limits<int64_t>::max() 1189 s.BindInt64(1, end.is_null() ? std::numeric_limits<int64_t>::max()
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 "OR (signon_realm LIKE ? AND password_type == 2) "; 1352 "OR (signon_realm LIKE ? AND password_type == 2) ";
1309 std::string psl_federated_statement = 1353 std::string psl_federated_statement =
1310 "OR (signon_realm REGEXP ? AND password_type == 2) "; 1354 "OR (signon_realm REGEXP ? AND password_type == 2) ";
1311 DCHECK(get_statement_psl_.empty()); 1355 DCHECK(get_statement_psl_.empty());
1312 get_statement_psl_ = get_statement_ + psl_statement; 1356 get_statement_psl_ = get_statement_ + psl_statement;
1313 DCHECK(get_statement_federated_.empty()); 1357 DCHECK(get_statement_federated_.empty());
1314 get_statement_federated_ = get_statement_ + federated_statement; 1358 get_statement_federated_ = get_statement_ + federated_statement;
1315 DCHECK(get_statement_psl_federated_.empty()); 1359 DCHECK(get_statement_psl_federated_.empty());
1316 get_statement_psl_federated_ = 1360 get_statement_psl_federated_ =
1317 get_statement_ + psl_statement + psl_federated_statement; 1361 get_statement_ + psl_statement + psl_federated_statement;
1362 DCHECK(get_same_organization_name_logins_statement_.empty());
1363 get_same_organization_name_logins_statement_ =
1364 "SELECT " + all_column_names +
1365 " FROM LOGINS"
1366 " WHERE scheme == 0 AND signon_realm REGEXP ?";
1318 DCHECK(created_statement_.empty()); 1367 DCHECK(created_statement_.empty());
1319 created_statement_ = 1368 created_statement_ =
1320 "SELECT " + all_column_names + 1369 "SELECT " + all_column_names +
1321 " FROM logins WHERE date_created >= ? AND date_created < " 1370 " FROM logins WHERE date_created >= ? AND date_created < "
1322 "? ORDER BY origin_url"; 1371 "? ORDER BY origin_url";
1323 DCHECK(synced_statement_.empty()); 1372 DCHECK(synced_statement_.empty());
1324 synced_statement_ = "SELECT " + all_column_names + 1373 synced_statement_ = "SELECT " + all_column_names +
1325 " FROM logins WHERE date_synced >= ? AND date_synced < " 1374 " FROM logins WHERE date_synced >= ? AND date_synced < "
1326 "? ORDER BY origin_url"; 1375 "? ORDER BY origin_url";
1327 DCHECK(blacklisted_statement_.empty()); 1376 DCHECK(blacklisted_statement_.empty());
1328 blacklisted_statement_ = 1377 blacklisted_statement_ =
1329 "SELECT " + all_column_names + 1378 "SELECT " + all_column_names +
1330 " FROM logins WHERE blacklisted_by_user == ? ORDER BY origin_url"; 1379 " FROM logins WHERE blacklisted_by_user == ? ORDER BY origin_url";
1331 DCHECK(encrypted_statement_.empty()); 1380 DCHECK(encrypted_statement_.empty());
1332 encrypted_statement_ = 1381 encrypted_statement_ =
1333 "SELECT password_value FROM logins WHERE " + all_unique_key_column_names; 1382 "SELECT password_value FROM logins WHERE " + all_unique_key_column_names;
1334 } 1383 }
1335 1384
1336 } // namespace password_manager 1385 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698