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

Side by Side Diff: chrome/browser/password_manager/password_store_mac_internal.h

Issue 23477015: [sync] Significantly speed up password model association on mac (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback Created 7 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 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_
6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ 6 #define CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_
7 7
8 #include <Security/Security.h> 8 #include <Security/Security.h>
9 9
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "crypto/apple_keychain.h" 13 #include "crypto/apple_keychain.h"
14 14
15 using crypto::AppleKeychain; 15 using crypto::AppleKeychain;
16 16
17 // Adapter that wraps a AppleKeychain and provides interaction in terms of 17 // Adapter that wraps a AppleKeychain and provides interaction in terms of
18 // PasswordForms instead of Keychain items. 18 // PasswordForms instead of Keychain items.
19 class MacKeychainPasswordFormAdapter { 19 class MacKeychainPasswordFormAdapter {
20 public: 20 public:
21 // Pair of pointers to a SecKeychainItemRef and a corresponding PasswordForm.
22 typedef std::pair<SecKeychainItemRef*, autofill::PasswordForm*> ItemFormPair;
23
21 // Creates an adapter for |keychain|. This class does not take ownership of 24 // Creates an adapter for |keychain|. This class does not take ownership of
22 // |keychain|, so the caller must make sure that the keychain outlives the 25 // |keychain|, so the caller must make sure that the keychain outlives the
23 // created object. 26 // created object.
24 explicit MacKeychainPasswordFormAdapter(const AppleKeychain* keychain); 27 explicit MacKeychainPasswordFormAdapter(const AppleKeychain* keychain);
25 28
26 // Returns PasswordForms for each keychain entry that could be used to fill 29 // Returns PasswordForms for each keychain entry that could be used to fill
27 // |form|. Caller is responsible for deleting the returned forms. 30 // |form|. Caller is responsible for deleting the returned forms.
28 std::vector<autofill::PasswordForm*> PasswordsFillingForm( 31 std::vector<autofill::PasswordForm*> PasswordsFillingForm(
29 const autofill::PasswordForm& query_form); 32 const autofill::PasswordForm& query_form);
30 33
31 // Returns PasswordForms for each keychain entry that could be merged with 34 // Returns PasswordForms populated with password data for each keychain entry
32 // |form|. Differs from PasswordsFillingForm in that the username must match. 35 // in |item_form_pairs| that could be merged with |query_form|.
33 // Caller is responsible for deleting the returned forms. 36 // Caller is responsible for deleting the returned forms.
34 std::vector<autofill::PasswordForm*> PasswordsMergeableWithForm( 37 std::vector<autofill::PasswordForm*> ExtractPasswordsMergeableWithForm(
38 const std::vector<ItemFormPair>& item_form_pairs,
35 const autofill::PasswordForm& query_form); 39 const autofill::PasswordForm& query_form);
36 40
37 // Returns the PasswordForm for the Keychain entry that matches |form| on all 41 // Returns the PasswordForm for the Keychain entry that matches |form| on all
38 // of the fields that uniquely identify a Keychain item, or NULL if there is 42 // of the fields that uniquely identify a Keychain item, or NULL if there is
39 // no such entry. 43 // no such entry.
40 // Caller is responsible for deleting the returned form. 44 // Caller is responsible for deleting the returned form.
41 autofill::PasswordForm* PasswordExactlyMatchingForm( 45 autofill::PasswordForm* PasswordExactlyMatchingForm(
42 const autofill::PasswordForm& query_form); 46 const autofill::PasswordForm& query_form);
43 47
44 // Returns true if PasswordsMergeableWithForm would return any items. This is 48 // Returns true if the keychain contains any items that are mergeable with
45 // a separate method because calling PasswordsMergeableWithForm and checking 49 // |query_form|. This is different form actually extracting the passwords
46 // the return count would require reading the passwords from the keychain, 50 // and checking the return count, since it would require reading the passwords
47 // thus potentially triggering authorizaiton UI, whereas this won't. 51 // from the keychain, thus potentially triggering authorizaiton UI, whereas
52 // this won't.
48 bool HasPasswordsMergeableWithForm( 53 bool HasPasswordsMergeableWithForm(
49 const autofill::PasswordForm& query_form); 54 const autofill::PasswordForm& query_form);
50 55
51 // Returns all keychain items of types corresponding to password forms. 56 // Returns all keychain items of types corresponding to password forms.
57 std::vector<SecKeychainItemRef> GetAllPasswordFormKeychainItems();
58
59 // Returns password data from all keychain items of types corresponding to
60 // password forms. Caller is responsible for deleting the returned forms.
52 std::vector<autofill::PasswordForm*> GetAllPasswordFormPasswords(); 61 std::vector<autofill::PasswordForm*> GetAllPasswordFormPasswords();
53 62
54 // Creates a new keychain entry from |form|, or updates the password of an 63 // Creates a new keychain entry from |form|, or updates the password of an
55 // existing keychain entry if there is a collision. Returns true if a keychain 64 // existing keychain entry if there is a collision. Returns true if a keychain
56 // entry was successfully added/updated. 65 // entry was successfully added/updated.
57 bool AddPassword(const autofill::PasswordForm& form); 66 bool AddPassword(const autofill::PasswordForm& form);
58 67
59 // Removes the keychain password matching |form| if any. Returns true if a 68 // Removes the keychain password matching |form| if any. Returns true if a
60 // keychain item was found and successfully removed. 69 // keychain item was found and successfully removed.
61 bool RemovePassword(const autofill::PasswordForm& form); 70 bool RemovePassword(const autofill::PasswordForm& form);
(...skipping 18 matching lines...) Expand all
80 // Returns the Keychain items matching the given signon_realm, scheme, and 89 // Returns the Keychain items matching the given signon_realm, scheme, and
81 // optionally path and username (either of both can be NULL). 90 // optionally path and username (either of both can be NULL).
82 // The caller is responsible for calling AppleKeychain::Free on the 91 // The caller is responsible for calling AppleKeychain::Free on the
83 // returned items. 92 // returned items.
84 std::vector<SecKeychainItemRef> MatchingKeychainItems( 93 std::vector<SecKeychainItemRef> MatchingKeychainItems(
85 const std::string& signon_realm, 94 const std::string& signon_realm,
86 autofill::PasswordForm::Scheme scheme, 95 autofill::PasswordForm::Scheme scheme,
87 const char* path, 96 const char* path,
88 const char* username); 97 const char* username);
89 98
99 // Returns true if the signon_realm of |query_form| can be successfully parsed
100 // by ExtractSignonRealmComponents, and if |query_form| matches |other_form|.
101 bool FormIsValidAndMatchesOtherForm(
102 const autofill::PasswordForm& query_form,
103 const autofill::PasswordForm& other_form);
104
90 // Takes a PasswordForm's signon_realm and parses it into its component parts, 105 // Takes a PasswordForm's signon_realm and parses it into its component parts,
91 // which are returned though the appropriate out parameters. 106 // which are returned though the appropriate out parameters.
92 // Returns true if it can be successfully parsed, in which case all out params 107 // Returns true if it can be successfully parsed, in which case all out params
93 // that are non-NULL will be set. If there is no port, port will be 0. 108 // that are non-NULL will be set. If there is no port, port will be 0.
94 // If the return value is false, the state of the out params is undefined. 109 // If the return value is false, the state of the out params is undefined.
95 bool ExtractSignonRealmComponents(const std::string& signon_realm, 110 bool ExtractSignonRealmComponents(const std::string& signon_realm,
96 std::string* server, int* port, 111 std::string* server, int* port,
97 bool* is_secure, 112 bool* is_secure,
98 std::string* security_domain); 113 std::string* security_domain);
99 114
(...skipping 22 matching lines...) Expand all
122 137
123 // If true, Keychain searches are restricted to items created by Chrome. 138 // If true, Keychain searches are restricted to items created by Chrome.
124 bool finds_only_owned_; 139 bool finds_only_owned_;
125 140
126 DISALLOW_COPY_AND_ASSIGN(MacKeychainPasswordFormAdapter); 141 DISALLOW_COPY_AND_ASSIGN(MacKeychainPasswordFormAdapter);
127 }; 142 };
128 143
129 namespace internal_keychain_helpers { 144 namespace internal_keychain_helpers {
130 145
131 // Sets the fields of |form| based on the keychain data from |keychain_item|. 146 // Sets the fields of |form| based on the keychain data from |keychain_item|.
132 // Fields that can't be determined from |keychain_item| will be unchanged. 147 // Fields that can't be determined from |keychain_item| will be unchanged. If
148 // |extract_password_data| is true, the password data will be copied from
149 // |keychain_item| in addition to its attributes. If it is false, only the
150 // password attributes will be copied.
stuartmorgan 2013/09/30 22:39:12 See comment below; there's a critical caveat you'v
Raghu Simha 2013/10/02 02:09:50 Comment updated.
133 // 151 //
134 // IMPORTANT: This function can cause the OS to trigger UI (to allow access to 152 // IMPORTANT: If |extract_password_data| is true, this function can cause the OS
135 // the keychain item if we aren't trusted for the item), and block until the UI 153 // to trigger UI (to allow access to the keychain item if we aren't trusted for
136 // is dismissed. 154 // the item), and block until the UI is dismissed.
137 // 155 //
138 // If excessive prompting for access to other applications' keychain items 156 // If excessive prompting for access to other applications' keychain items
139 // becomes an issue, the password storage API will need to be refactored to 157 // becomes an issue, the password storage API will need to intially call this
140 // allow the password to be retrieved later (accessing other fields doesn't 158 // function with |extract_password_data| set to false, and retrieve the password
141 // require authorization). 159 // later (accessing other fields doesn't require authorization).
142 bool FillPasswordFormFromKeychainItem(const AppleKeychain& keychain, 160 bool FillPasswordFormFromKeychainItem(const AppleKeychain& keychain,
143 const SecKeychainItemRef& keychain_item, 161 const SecKeychainItemRef& keychain_item,
144 autofill::PasswordForm* form); 162 autofill::PasswordForm* form,
163 bool extract_password_data);
145 164
146 // Returns true if the two given forms match based on signon_reaml, scheme, and 165 // Returns true if the two given forms match based on signon_reaml, scheme, and
147 // username_value, and are thus suitable for merging (see MergePasswordForms). 166 // username_value, and are thus suitable for merging (see MergePasswordForms).
148 bool FormsMatchForMerge(const autofill::PasswordForm& form_a, 167 bool FormsMatchForMerge(const autofill::PasswordForm& form_a,
149 const autofill::PasswordForm& form_b); 168 const autofill::PasswordForm& form_b);
150 169
151 // Populates merged_forms by combining the password data from keychain_forms and 170 // Populates merged_forms by combining the password data from keychain_forms and
152 // the metadata from database_forms, removing used entries from the two source 171 // the metadata from database_forms, removing used entries from the two source
153 // lists. 172 // lists.
154 // 173 //
155 // On return, database_forms and keychain_forms will have only unused 174 // On return, database_forms and keychain_forms will have only unused
156 // entries; for database_forms that means entries for which no corresponding 175 // entries; for database_forms that means entries for which no corresponding
157 // password can be found (and which aren't blacklist entries), and for 176 // password can be found (and which aren't blacklist entries), and for
158 // keychain_forms its entries that weren't merged into at least one database 177 // keychain_forms its entries that weren't merged into at least one database
159 // form. 178 // form.
160 void MergePasswordForms( 179 void MergePasswordForms(
161 std::vector<autofill::PasswordForm*>* keychain_forms, 180 std::vector<autofill::PasswordForm*>* keychain_forms,
162 std::vector<autofill::PasswordForm*>* database_forms, 181 std::vector<autofill::PasswordForm*>* database_forms,
163 std::vector<autofill::PasswordForm*>* merged_forms); 182 std::vector<autofill::PasswordForm*>* merged_forms);
164 183
165 // Fills in the passwords for as many of the forms in |database_forms| as 184 // Fills in the passwords for as many of the forms in |database_forms| as
166 // possible using entries from |keychain| and returns them. On return, 185 // possible using entries from |keychain| and returns them. On return,
167 // |database_forms| will contain only the forms for which no password was found. 186 // |database_forms| will contain only the forms for which no password was found.
168 std::vector<autofill::PasswordForm*> GetPasswordsForForms( 187 std::vector<autofill::PasswordForm*> GetPasswordsForForms(
169 const AppleKeychain& keychain, 188 const AppleKeychain& keychain,
170 std::vector<autofill::PasswordForm*>* database_forms); 189 std::vector<autofill::PasswordForm*>* database_forms);
171 190
191 // Loads all items in the system keychain into |keychain_items|, and copies all
192 // their attributes into a container of pairs of pointers to PasswordForms and
193 // SecKeychainItemRefs without copying any password data. Caller owns the
194 // SecKeychainItemRefs and PasswordForms that are returned. This operation does
195 // not require OS authorization.
stuartmorgan 2013/09/30 22:39:12 You should mention that the resulting PasswordForm
Raghu Simha 2013/10/02 02:09:50 I've rewritten this comment and mentioned blacklis
196 std::vector<MacKeychainPasswordFormAdapter::ItemFormPair>
197 GetAllKeychainItemAttributesAsPasswordForms(
stuartmorgan 2013/09/30 22:39:12 I don't understand the use of the word "attributes
Raghu Simha 2013/10/02 02:09:50 Good point :) I've renamed this ExtractAllKeychai
198 std::vector<SecKeychainItemRef>* keychain_items,
199 const AppleKeychain& keychain);
200
172 } // namespace internal_keychain_helpers 201 } // namespace internal_keychain_helpers
173 202
174 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ 203 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698