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

Side by Side Diff: chrome/browser/password_manager/password_store_mac.cc

Issue 10875029: Rename MacKeychain to AppleKeychain (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address Avi's code review: add NStoCFCast and other nits. Created 8 years, 3 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 (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 #include "chrome/browser/password_manager/password_store_mac_internal.h" 6 #include "chrome/browser/password_manager/password_store_mac_internal.h"
7 7
8 #include <CoreServices/CoreServices.h> 8 #include <CoreServices/CoreServices.h>
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/mac/mac_logging.h" 15 #include "base/mac/mac_logging.h"
16 #include "base/mac/mac_util.h" 16 #include "base/mac/mac_util.h"
17 #include "base/message_loop.h" 17 #include "base/message_loop.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/string_util.h" 19 #include "base/string_util.h"
20 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
21 #include "chrome/browser/password_manager/login_database.h" 21 #include "chrome/browser/password_manager/login_database.h"
22 #include "chrome/browser/password_manager/password_store_change.h" 22 #include "chrome/browser/password_manager/password_store_change.h"
23 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
24 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
25 #include "crypto/keychain_mac.h" 25 #include "crypto/apple_keychain.h"
26 26
27 using crypto::MacKeychain; 27 using crypto::AppleKeychain;
28 using webkit::forms::PasswordForm; 28 using webkit::forms::PasswordForm;
29 29
30 // Utility class to handle the details of constructing and running a keychain 30 // Utility class to handle the details of constructing and running a keychain
31 // search from a set of attributes. 31 // search from a set of attributes.
32 class KeychainSearch { 32 class KeychainSearch {
33 public: 33 public:
34 explicit KeychainSearch(const MacKeychain& keychain); 34 explicit KeychainSearch(const AppleKeychain& keychain);
35 ~KeychainSearch(); 35 ~KeychainSearch();
36 36
37 // Sets up a keycahin search based on an non "null" (NULL for char*, 37 // Sets up a keycahin search based on an non "null" (NULL for char*,
38 // The appropriate "Any" entry for other types) arguments. 38 // The appropriate "Any" entry for other types) arguments.
39 // 39 //
40 // IMPORTANT: Any paramaters passed in *must* remain valid for as long as the 40 // IMPORTANT: Any paramaters passed in *must* remain valid for as long as the
41 // KeychainSearch object, since the search uses them by reference. 41 // KeychainSearch object, since the search uses them by reference.
42 void Init(const char* server, const UInt32& port, 42 void Init(const char* server, const UInt32& port,
43 const SecProtocolType& protocol, 43 const SecProtocolType& protocol,
44 const SecAuthenticationType& auth_type, const char* security_domain, 44 const SecAuthenticationType& auth_type, const char* security_domain,
45 const char* path, const char* username, OSType creator); 45 const char* path, const char* username, OSType creator);
46 46
47 // Fills |items| with all Keychain items that match the Init'd search. 47 // Fills |items| with all Keychain items that match the Init'd search.
48 // If the search fails for any reason, |items| will be unchanged. 48 // If the search fails for any reason, |items| will be unchanged.
49 void FindMatchingItems(std::vector<SecKeychainItemRef>* matches); 49 void FindMatchingItems(std::vector<SecKeychainItemRef>* matches);
50 50
51 private: 51 private:
52 const MacKeychain* keychain_; 52 const AppleKeychain* keychain_;
53 SecKeychainAttributeList search_attributes_; 53 SecKeychainAttributeList search_attributes_;
54 SecKeychainSearchRef search_ref_; 54 SecKeychainSearchRef search_ref_;
55 }; 55 };
56 56
57 KeychainSearch::KeychainSearch(const MacKeychain& keychain) 57 KeychainSearch::KeychainSearch(const AppleKeychain& keychain)
58 : keychain_(&keychain), search_ref_(NULL) { 58 : keychain_(&keychain), search_ref_(NULL) {
59 search_attributes_.count = 0; 59 search_attributes_.count = 0;
60 search_attributes_.attr = NULL; 60 search_attributes_.attr = NULL;
61 } 61 }
62 62
63 KeychainSearch::~KeychainSearch() { 63 KeychainSearch::~KeychainSearch() {
64 if (search_attributes_.attr) { 64 if (search_attributes_.attr) {
65 free(search_attributes_.attr); 65 free(search_attributes_.attr);
66 } 66 }
67 } 67 }
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // Returns the PasswordForm Scheme corresponding to |auth_type|. 224 // Returns the PasswordForm Scheme corresponding to |auth_type|.
225 PasswordForm::Scheme SchemeForAuthType(SecAuthenticationType auth_type) { 225 PasswordForm::Scheme SchemeForAuthType(SecAuthenticationType auth_type) {
226 switch (auth_type) { 226 switch (auth_type) {
227 case kSecAuthenticationTypeHTMLForm: return PasswordForm::SCHEME_HTML; 227 case kSecAuthenticationTypeHTMLForm: return PasswordForm::SCHEME_HTML;
228 case kSecAuthenticationTypeHTTPBasic: return PasswordForm::SCHEME_BASIC; 228 case kSecAuthenticationTypeHTTPBasic: return PasswordForm::SCHEME_BASIC;
229 case kSecAuthenticationTypeHTTPDigest: return PasswordForm::SCHEME_DIGEST; 229 case kSecAuthenticationTypeHTTPDigest: return PasswordForm::SCHEME_DIGEST;
230 default: return PasswordForm::SCHEME_OTHER; 230 default: return PasswordForm::SCHEME_OTHER;
231 } 231 }
232 } 232 }
233 233
234 bool FillPasswordFormFromKeychainItem(const MacKeychain& keychain, 234 bool FillPasswordFormFromKeychainItem(const AppleKeychain& keychain,
235 const SecKeychainItemRef& keychain_item, 235 const SecKeychainItemRef& keychain_item,
236 PasswordForm* form) { 236 PasswordForm* form) {
237 DCHECK(form); 237 DCHECK(form);
238 238
239 SecKeychainAttributeInfo attrInfo; 239 SecKeychainAttributeInfo attrInfo;
240 UInt32 tags[] = { kSecAccountItemAttr, 240 UInt32 tags[] = { kSecAccountItemAttr,
241 kSecServerItemAttr, 241 kSecServerItemAttr,
242 kSecPortItemAttr, 242 kSecPortItemAttr,
243 kSecPathItemAttr, 243 kSecPathItemAttr,
244 kSecProtocolItemAttr, 244 kSecProtocolItemAttr,
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 // Add in the blacklist entries from the database. 437 // Add in the blacklist entries from the database.
438 merged_forms->insert(merged_forms->end(), 438 merged_forms->insert(merged_forms->end(),
439 database_blacklist_forms.begin(), 439 database_blacklist_forms.begin(),
440 database_blacklist_forms.end()); 440 database_blacklist_forms.end());
441 441
442 // Clear out all the Keychain entries we used. 442 // Clear out all the Keychain entries we used.
443 DeleteVectorElementsInSet(keychain_forms, used_keychain_forms); 443 DeleteVectorElementsInSet(keychain_forms, used_keychain_forms);
444 } 444 }
445 445
446 std::vector<PasswordForm*> GetPasswordsForForms( 446 std::vector<PasswordForm*> GetPasswordsForForms(
447 const MacKeychain& keychain, std::vector<PasswordForm*>* database_forms) { 447 const AppleKeychain& keychain,
448 std::vector<PasswordForm*>* database_forms) {
448 MacKeychainPasswordFormAdapter keychain_adapter(&keychain); 449 MacKeychainPasswordFormAdapter keychain_adapter(&keychain);
449 450
450 std::vector<PasswordForm*> merged_forms; 451 std::vector<PasswordForm*> merged_forms;
451 for (std::vector<PasswordForm*>::iterator i = database_forms->begin(); 452 for (std::vector<PasswordForm*>::iterator i = database_forms->begin();
452 i != database_forms->end();) { 453 i != database_forms->end();) {
453 std::vector<PasswordForm*> db_form_container(1, *i); 454 std::vector<PasswordForm*> db_form_container(1, *i);
454 std::vector<PasswordForm*> keychain_matches = 455 std::vector<PasswordForm*> keychain_matches =
455 keychain_adapter.PasswordsMergeableWithForm(**i); 456 keychain_adapter.PasswordsMergeableWithForm(**i);
456 MergePasswordForms(&keychain_matches, &db_form_container, &merged_forms); 457 MergePasswordForms(&keychain_matches, &db_form_container, &merged_forms);
457 if (db_form_container.empty()) { 458 if (db_form_container.empty()) {
458 i = database_forms->erase(i); 459 i = database_forms->erase(i);
459 } else { 460 } else {
460 ++i; 461 ++i;
461 } 462 }
462 STLDeleteElements(&keychain_matches); 463 STLDeleteElements(&keychain_matches);
463 } 464 }
464 return merged_forms; 465 return merged_forms;
465 } 466 }
466 467
467 } // namespace internal_keychain_helpers 468 } // namespace internal_keychain_helpers
468 469
469 #pragma mark - 470 #pragma mark -
470 471
471 MacKeychainPasswordFormAdapter::MacKeychainPasswordFormAdapter( 472 MacKeychainPasswordFormAdapter::MacKeychainPasswordFormAdapter(
472 const MacKeychain* keychain) 473 const AppleKeychain* keychain)
473 : keychain_(keychain), finds_only_owned_(false) { 474 : keychain_(keychain), finds_only_owned_(false) {
474 } 475 }
475 476
476 std::vector<PasswordForm*> 477 std::vector<PasswordForm*>
477 MacKeychainPasswordFormAdapter::PasswordsFillingForm( 478 MacKeychainPasswordFormAdapter::PasswordsFillingForm(
478 const PasswordForm& query_form) { 479 const PasswordForm& query_form) {
479 std::vector<SecKeychainItemRef> keychain_items = 480 std::vector<SecKeychainItemRef> keychain_items =
480 MatchingKeychainItems(query_form.signon_realm, query_form.scheme, 481 MatchingKeychainItems(query_form.signon_realm, query_form.scheme,
481 NULL, NULL); 482 NULL, NULL);
482 483
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 &attrList, 0, NULL); 728 &attrList, 0, NULL);
728 return result == noErr; 729 return result == noErr;
729 } 730 }
730 731
731 OSType MacKeychainPasswordFormAdapter::CreatorCodeForSearch() { 732 OSType MacKeychainPasswordFormAdapter::CreatorCodeForSearch() {
732 return finds_only_owned_ ? base::mac::CreatorCodeForApplication() : 0; 733 return finds_only_owned_ ? base::mac::CreatorCodeForApplication() : 0;
733 } 734 }
734 735
735 #pragma mark - 736 #pragma mark -
736 737
737 PasswordStoreMac::PasswordStoreMac(MacKeychain* keychain, 738 PasswordStoreMac::PasswordStoreMac(AppleKeychain* keychain,
738 LoginDatabase* login_db) 739 LoginDatabase* login_db)
739 : keychain_(keychain), login_metadata_db_(login_db) { 740 : keychain_(keychain), login_metadata_db_(login_db) {
740 DCHECK(keychain_.get()); 741 DCHECK(keychain_.get());
741 DCHECK(login_metadata_db_.get()); 742 DCHECK(login_metadata_db_.get());
742 } 743 }
743 744
744 PasswordStoreMac::~PasswordStoreMac() { 745 PasswordStoreMac::~PasswordStoreMac() {
745 if (thread_.get()) { 746 if (thread_.get()) {
746 thread_->message_loop()->DeleteSoon(FROM_HERE, 747 thread_->message_loop()->DeleteSoon(FROM_HERE,
747 notification_service_.release()); 748 notification_service_.release());
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1012 owned_keychain_adapter.SetFindsOnlyOwnedItems(true); 1013 owned_keychain_adapter.SetFindsOnlyOwnedItems(true);
1013 for (std::vector<PasswordForm*>::const_iterator i = forms.begin(); 1014 for (std::vector<PasswordForm*>::const_iterator i = forms.begin();
1014 i != forms.end(); ++i) { 1015 i != forms.end(); ++i) {
1015 owned_keychain_adapter.RemovePassword(**i); 1016 owned_keychain_adapter.RemovePassword(**i);
1016 } 1017 }
1017 } 1018 }
1018 1019
1019 void PasswordStoreMac::CreateNotificationService() { 1020 void PasswordStoreMac::CreateNotificationService() {
1020 notification_service_.reset(content::NotificationService::Create()); 1021 notification_service_.reset(content::NotificationService::Create());
1021 } 1022 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_mac.h ('k') | chrome/browser/password_manager/password_store_mac_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698