| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/password_reuse_detector.h" | 5 #include "components/password_manager/core/browser/password_reuse_detector.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "components/autofill/core/common/password_form.h" | 9 #include "components/autofill/core/common/password_form.h" |
| 10 #include "components/password_manager/core/browser/password_manager_util.h" | 10 #include "components/password_manager/core/browser/password_manager_util.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 bool IsSuffix(const base::string16& str, | 30 bool IsSuffix(const base::string16& str, |
| 31 const base::string16& suffix_candidate) { | 31 const base::string16& suffix_candidate) { |
| 32 if (str.size() < suffix_candidate.size()) | 32 if (str.size() < suffix_candidate.size()) |
| 33 return false; | 33 return false; |
| 34 return std::equal(suffix_candidate.rbegin(), suffix_candidate.rend(), | 34 return std::equal(suffix_candidate.rbegin(), suffix_candidate.rend(), |
| 35 str.rbegin()); | 35 str.rbegin()); |
| 36 } | 36 } |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 const char kSyncPasswordDomain[] = "CHROME SYNC"; |
| 41 |
| 40 bool ReverseStringLess::operator()(const base::string16& lhs, | 42 bool ReverseStringLess::operator()(const base::string16& lhs, |
| 41 const base::string16& rhs) const { | 43 const base::string16& rhs) const { |
| 42 return std::lexicographical_compare(lhs.rbegin(), lhs.rend(), rhs.rbegin(), | 44 return std::lexicographical_compare(lhs.rbegin(), lhs.rend(), rhs.rbegin(), |
| 43 rhs.rend()); | 45 rhs.rend()); |
| 44 } | 46 } |
| 45 | 47 |
| 46 PasswordReuseDetector::PasswordReuseDetector(PrefService* prefs) | 48 PasswordReuseDetector::PasswordReuseDetector(PrefService* prefs) |
| 47 : prefs_(prefs) {} | 49 : prefs_(prefs) {} |
| 48 | 50 |
| 49 PasswordReuseDetector::~PasswordReuseDetector() {} | 51 PasswordReuseDetector::~PasswordReuseDetector() {} |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 | 89 |
| 88 const Origin gaia_origin(GaiaUrls::GetInstance()->gaia_url().GetOrigin()); | 90 const Origin gaia_origin(GaiaUrls::GetInstance()->gaia_url().GetOrigin()); |
| 89 if (Origin(GURL(domain)).IsSameOriginWith(gaia_origin)) | 91 if (Origin(GURL(domain)).IsSameOriginWith(gaia_origin)) |
| 90 return false; | 92 return false; |
| 91 | 93 |
| 92 // Check that some suffix of |input| has the same hash as the sync password. | 94 // Check that some suffix of |input| has the same hash as the sync password. |
| 93 for (size_t i = 0; i + kMinPasswordLengthToCheck <= input.size(); ++i) { | 95 for (size_t i = 0; i + kMinPasswordLengthToCheck <= input.size(); ++i) { |
| 94 base::StringPiece16 input_suffix(input.c_str() + i, input.size() - i); | 96 base::StringPiece16 input_suffix(input.c_str() + i, input.size() - i); |
| 95 if (password_manager_util::Calculate37BitsOfSHA256Hash(input_suffix) == | 97 if (password_manager_util::Calculate37BitsOfSHA256Hash(input_suffix) == |
| 96 sync_password_hash_.value()) { | 98 sync_password_hash_.value()) { |
| 97 consumer->OnReuseFound(input_suffix.as_string(), gaia_origin.host(), 1, | 99 consumer->OnReuseFound(input_suffix.as_string(), |
| 98 0); | 100 std::string(kSyncPasswordDomain), 1, 0); |
| 99 return true; | 101 return true; |
| 100 } | 102 } |
| 101 } | 103 } |
| 102 | 104 |
| 103 return false; | 105 return false; |
| 104 } | 106 } |
| 105 | 107 |
| 106 bool PasswordReuseDetector::CheckSavedPasswordReuse( | 108 bool PasswordReuseDetector::CheckSavedPasswordReuse( |
| 107 const base::string16& input, | 109 const base::string16& input, |
| 108 const std::string& domain, | 110 const std::string& domain, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 | 176 |
| 175 // Otherwise the previous key is a candidate for password reuse. | 177 // Otherwise the previous key is a candidate for password reuse. |
| 176 if (it == passwords_.begin()) | 178 if (it == passwords_.begin()) |
| 177 return passwords_.end(); | 179 return passwords_.end(); |
| 178 | 180 |
| 179 --it; | 181 --it; |
| 180 return IsSuffix(input, it->first) ? it : passwords_.end(); | 182 return IsSuffix(input, it->first) ? it : passwords_.end(); |
| 181 } | 183 } |
| 182 | 184 |
| 183 } // namespace password_manager | 185 } // namespace password_manager |
| OLD | NEW |