| 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/password_store_mac.h" | 5 #include "chrome/browser/password_manager/password_store_mac.h" |
| 6 | 6 |
| 7 #include <CoreServices/CoreServices.h> | 7 #include <CoreServices/CoreServices.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 | 657 |
| 658 if (server) | 658 if (server) |
| 659 *server = realm_as_url.host(); | 659 *server = realm_as_url.host(); |
| 660 if (is_secure) | 660 if (is_secure) |
| 661 *is_secure = realm_as_url.SchemeIsCryptographic(); | 661 *is_secure = realm_as_url.SchemeIsCryptographic(); |
| 662 if (port) | 662 if (port) |
| 663 *port = realm_as_url.has_port() ? atoi(realm_as_url.port().c_str()) : 0; | 663 *port = realm_as_url.has_port() ? atoi(realm_as_url.port().c_str()) : 0; |
| 664 if (security_domain) { | 664 if (security_domain) { |
| 665 // Strip the leading '/' off of the path to get the security domain. | 665 // Strip the leading '/' off of the path to get the security domain. |
| 666 if (realm_as_url.path().length() > 0) | 666 if (realm_as_url.path().length() > 0) |
| 667 *security_domain = realm_as_url.path().substr(1); | 667 *security_domain = realm_as_url.path().substr(1).as_string(); |
| 668 else | 668 else |
| 669 security_domain->clear(); | 669 security_domain->clear(); |
| 670 } | 670 } |
| 671 return true; | 671 return true; |
| 672 } | 672 } |
| 673 | 673 |
| 674 bool FormIsValidAndMatchesOtherForm(const PasswordForm& query_form, | 674 bool FormIsValidAndMatchesOtherForm(const PasswordForm& query_form, |
| 675 const PasswordForm& other_form) { | 675 const PasswordForm& other_form) { |
| 676 std::string server; | 676 std::string server; |
| 677 std::string security_domain; | 677 std::string security_domain; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 std::string security_domain; | 787 std::string security_domain; |
| 788 UInt32 port; | 788 UInt32 port; |
| 789 bool is_secure; | 789 bool is_secure; |
| 790 if (!internal_keychain_helpers::ExtractSignonRealmComponents( | 790 if (!internal_keychain_helpers::ExtractSignonRealmComponents( |
| 791 form.signon_realm, &server, &port, &is_secure, &security_domain)) { | 791 form.signon_realm, &server, &port, &is_secure, &security_domain)) { |
| 792 return false; | 792 return false; |
| 793 } | 793 } |
| 794 std::string path; | 794 std::string path; |
| 795 // Path doesn't make sense for Android app credentials. | 795 // Path doesn't make sense for Android app credentials. |
| 796 if (!password_manager::IsValidAndroidFacetURI(form.signon_realm)) | 796 if (!password_manager::IsValidAndroidFacetURI(form.signon_realm)) |
| 797 path = form.origin.path(); | 797 path = form.origin.path().as_string(); |
| 798 std::string username = base::UTF16ToUTF8(form.username_value); | 798 std::string username = base::UTF16ToUTF8(form.username_value); |
| 799 std::string password = base::UTF16ToUTF8(form.password_value); | 799 std::string password = base::UTF16ToUTF8(form.password_value); |
| 800 SecProtocolType protocol = is_secure ? kSecProtocolTypeHTTPS | 800 SecProtocolType protocol = is_secure ? kSecProtocolTypeHTTPS |
| 801 : kSecProtocolTypeHTTP; | 801 : kSecProtocolTypeHTTP; |
| 802 SecKeychainItemRef new_item = NULL; | 802 SecKeychainItemRef new_item = NULL; |
| 803 OSStatus result = keychain_->AddInternetPassword( | 803 OSStatus result = keychain_->AddInternetPassword( |
| 804 NULL, server.size(), server.c_str(), | 804 NULL, server.size(), server.c_str(), |
| 805 security_domain.size(), security_domain.c_str(), | 805 security_domain.size(), security_domain.c_str(), |
| 806 username.size(), username.c_str(), | 806 username.size(), username.c_str(), |
| 807 path.size(), path.c_str(), | 807 path.size(), path.c_str(), |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 const PasswordForm& form) { | 860 const PasswordForm& form) { |
| 861 // We don't store blacklist entries in the keychain, so the answer to "what | 861 // We don't store blacklist entries in the keychain, so the answer to "what |
| 862 // Keychain item goes with this form" is always "nothing" for blacklists. | 862 // Keychain item goes with this form" is always "nothing" for blacklists. |
| 863 // Same goes for federated logins. | 863 // Same goes for federated logins. |
| 864 if (IsLoginDatabaseOnlyForm(form)) | 864 if (IsLoginDatabaseOnlyForm(form)) |
| 865 return NULL; | 865 return NULL; |
| 866 | 866 |
| 867 std::string path; | 867 std::string path; |
| 868 // Path doesn't make sense for Android app credentials. | 868 // Path doesn't make sense for Android app credentials. |
| 869 if (!password_manager::IsValidAndroidFacetURI(form.signon_realm)) | 869 if (!password_manager::IsValidAndroidFacetURI(form.signon_realm)) |
| 870 path = form.origin.path(); | 870 path = form.origin.path().as_string(); |
| 871 std::string username = base::UTF16ToUTF8(form.username_value); | 871 std::string username = base::UTF16ToUTF8(form.username_value); |
| 872 std::vector<SecKeychainItemRef> matches = MatchingKeychainItems( | 872 std::vector<SecKeychainItemRef> matches = MatchingKeychainItems( |
| 873 form.signon_realm, form.scheme, path.c_str(), username.c_str()); | 873 form.signon_realm, form.scheme, path.c_str(), username.c_str()); |
| 874 | 874 |
| 875 if (matches.empty()) { | 875 if (matches.empty()) { |
| 876 return NULL; | 876 return NULL; |
| 877 } | 877 } |
| 878 | 878 |
| 879 // Free all items after the first, since we won't be returning them. | 879 // Free all items after the first, since we won't be returning them. |
| 880 for (auto i = matches.begin() + 1; i != matches.end(); ++i) | 880 for (auto i = matches.begin() + 1; i != matches.end(); ++i) |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 ScopedVector<PasswordForm> forms_with_keychain_entry; | 1420 ScopedVector<PasswordForm> forms_with_keychain_entry; |
| 1421 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, | 1421 internal_keychain_helpers::GetPasswordsForForms(*keychain_, &database_forms, |
| 1422 &forms_with_keychain_entry); | 1422 &forms_with_keychain_entry); |
| 1423 | 1423 |
| 1424 // Clean up any orphaned database entries. | 1424 // Clean up any orphaned database entries. |
| 1425 RemoveDatabaseForms(&database_forms); | 1425 RemoveDatabaseForms(&database_forms); |
| 1426 | 1426 |
| 1427 // Move the orphaned DB forms to the output parameter. | 1427 // Move the orphaned DB forms to the output parameter. |
| 1428 AppendSecondToFirst(orphaned_forms, &database_forms); | 1428 AppendSecondToFirst(orphaned_forms, &database_forms); |
| 1429 } | 1429 } |
| OLD | NEW |