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 #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 "base/memory/scoped_vector.h" |
13 #include "components/autofill/core/common/password_form.h" | 14 #include "components/autofill/core/common/password_form.h" |
14 #include "crypto/apple_keychain.h" | 15 #include "crypto/apple_keychain.h" |
15 | 16 |
16 using crypto::AppleKeychain; | 17 using crypto::AppleKeychain; |
17 | 18 |
18 // Adapter that wraps a AppleKeychain and provides interaction in terms of | 19 // Adapter that wraps a AppleKeychain and provides interaction in terms of |
19 // PasswordForms instead of Keychain items. | 20 // PasswordForms instead of Keychain items. |
20 class MacKeychainPasswordFormAdapter { | 21 class MacKeychainPasswordFormAdapter { |
21 public: | 22 public: |
22 // Creates an adapter for |keychain|. This class does not take ownership of | 23 // Creates an adapter for |keychain|. This class does not take ownership of |
23 // |keychain|, so the caller must make sure that the keychain outlives the | 24 // |keychain|, so the caller must make sure that the keychain outlives the |
24 // created object. | 25 // created object. |
25 explicit MacKeychainPasswordFormAdapter(const AppleKeychain* keychain); | 26 explicit MacKeychainPasswordFormAdapter(const AppleKeychain* keychain); |
26 | 27 |
27 // Returns PasswordForms for each keychain entry that could be used to fill | 28 // Appends to |forms| all keychain entries matching |signon_realm| and |
28 // |form|. Caller is responsible for deleting the returned forms. | 29 // |scheme|. |
29 std::vector<autofill::PasswordForm*> PasswordsFillingForm( | 30 void PasswordsFillingForm(const std::string& signon_realm, |
30 const std::string& signon_realm, | 31 autofill::PasswordForm::Scheme scheme, |
31 autofill::PasswordForm::Scheme scheme); | 32 ScopedVector<autofill::PasswordForm>* forms); |
32 | 33 |
33 // Returns true if there is the Keychain entry that matches |query_form| on | 34 // Returns true if there is the Keychain entry that matches |query_form| on |
34 // all of the fields that uniquely identify a Keychain item. | 35 // all of the fields that uniquely identify a Keychain item. |
35 bool HasPasswordExactlyMatchingForm(const autofill::PasswordForm& query_form); | 36 bool HasPasswordExactlyMatchingForm(const autofill::PasswordForm& query_form); |
36 | 37 |
37 // Returns true if the keychain contains any items that are mergeable with | 38 // Returns true if the keychain contains any items that are mergeable with |
38 // |query_form|. This is different from actually extracting the passwords | 39 // |query_form|. This is different from actually extracting the passwords |
39 // and checking the return count, since doing that would require reading the | 40 // and checking the return count, since doing that would require reading the |
40 // passwords from the keychain, thus potentially triggering authorizaiton UI, | 41 // passwords from the keychain, thus potentially triggering authorizaiton UI, |
41 // whereas this won't. | 42 // whereas this won't. |
42 bool HasPasswordsMergeableWithForm( | 43 bool HasPasswordsMergeableWithForm( |
43 const autofill::PasswordForm& query_form); | 44 const autofill::PasswordForm& query_form); |
44 | 45 |
45 // Returns all keychain items of types corresponding to password forms. | 46 // Returns all keychain items of types corresponding to password forms. |
46 std::vector<SecKeychainItemRef> GetAllPasswordFormKeychainItems(); | 47 std::vector<SecKeychainItemRef> GetAllPasswordFormKeychainItems(); |
47 | 48 |
48 // Returns password data from all keychain items of types corresponding to | 49 // Appends to |forms| all keychain entries corresponding to password forms. |
49 // password forms. Caller is responsible for deleting the returned forms. | 50 void GetAllPasswordFormPasswords(ScopedVector<autofill::PasswordForm>* forms); |
50 std::vector<autofill::PasswordForm*> GetAllPasswordFormPasswords(); | |
51 | 51 |
52 // Creates a new keychain entry from |form|, or updates the password of an | 52 // Creates a new keychain entry from |form|, or updates the password of an |
53 // existing keychain entry if there is a collision. Returns true if a keychain | 53 // existing keychain entry if there is a collision. Returns true if a keychain |
54 // entry was successfully added/updated. | 54 // entry was successfully added/updated. |
55 bool AddPassword(const autofill::PasswordForm& form); | 55 bool AddPassword(const autofill::PasswordForm& form); |
56 | 56 |
57 // Removes the keychain password matching |form| if any. Returns true if a | 57 // Removes the keychain password matching |form| if any. Returns true if a |
58 // keychain item was found and successfully removed. | 58 // keychain item was found and successfully removed. |
59 bool RemovePassword(const autofill::PasswordForm& form); | 59 bool RemovePassword(const autofill::PasswordForm& form); |
60 | 60 |
61 // Controls whether or not Chrome will restrict Keychain searches to items | 61 // Controls whether or not Chrome will restrict Keychain searches to items |
62 // that it created. Defaults to false. | 62 // that it created. Defaults to false. |
63 void SetFindsOnlyOwnedItems(bool finds_only_owned); | 63 void SetFindsOnlyOwnedItems(bool finds_only_owned); |
64 | 64 |
65 private: | 65 private: |
66 // Returns PasswordForms constructed from the given Keychain items, calling | 66 // Transforms |items| to PasswordForm instances and appends them to |forms|. |
67 // AppleKeychain::Free on all of the keychain items and clearing the vector. | 67 // Also calls AppleKeychain::Free on all of the keychain items and clears |
68 // Caller is responsible for deleting the returned forms. | 68 // |items|. |
69 std::vector<autofill::PasswordForm*> ConvertKeychainItemsToForms( | 69 void ConvertKeychainItemsToForms(std::vector<SecKeychainItemRef>* items, |
70 std::vector<SecKeychainItemRef>* items); | 70 ScopedVector<autofill::PasswordForm>* forms); |
71 | 71 |
72 // Searches |keychain| for the specific keychain entry that corresponds to the | 72 // Searches |keychain| for the specific keychain entry that corresponds to the |
73 // given form, and returns it (or NULL if no match is found). The caller is | 73 // given form, and returns it (or NULL if no match is found). The caller is |
74 // responsible for calling AppleKeychain::Free on on the returned item. | 74 // responsible for calling AppleKeychain::Free on on the returned item. |
75 SecKeychainItemRef KeychainItemForForm( | 75 SecKeychainItemRef KeychainItemForForm( |
76 const autofill::PasswordForm& form); | 76 const autofill::PasswordForm& form); |
77 | 77 |
78 // Returns the Keychain items matching the given signon_realm, scheme, and | 78 // Returns the Keychain items matching the given signon_realm, scheme, and |
79 // optionally path and username (either of both can be NULL). | 79 // optionally path and username (either of both can be NULL). |
80 // The caller is responsible for calling AppleKeychain::Free on the | 80 // The caller is responsible for calling AppleKeychain::Free on the |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 158 |
159 // Populates merged_forms by combining the password data from keychain_forms and | 159 // Populates merged_forms by combining the password data from keychain_forms and |
160 // the metadata from database_forms, removing used entries from the two source | 160 // the metadata from database_forms, removing used entries from the two source |
161 // lists. | 161 // lists. |
162 // | 162 // |
163 // On return, database_forms and keychain_forms will have only unused | 163 // On return, database_forms and keychain_forms will have only unused |
164 // entries; for database_forms that means entries for which no corresponding | 164 // entries; for database_forms that means entries for which no corresponding |
165 // password can be found (and which aren't blacklist entries), and for | 165 // password can be found (and which aren't blacklist entries), and for |
166 // keychain_forms its entries that weren't merged into at least one database | 166 // keychain_forms its entries that weren't merged into at least one database |
167 // form. | 167 // form. |
168 void MergePasswordForms( | 168 void MergePasswordForms(ScopedVector<autofill::PasswordForm>* keychain_forms, |
169 std::vector<autofill::PasswordForm*>* keychain_forms, | 169 ScopedVector<autofill::PasswordForm>* database_forms, |
170 std::vector<autofill::PasswordForm*>* database_forms, | 170 ScopedVector<autofill::PasswordForm>* merged_forms); |
171 std::vector<autofill::PasswordForm*>* merged_forms); | |
172 | 171 |
173 // Fills in the passwords for as many of the forms in |database_forms| as | 172 // For every form in |database_forms|, if such a form has a corresponding entry |
174 // possible using entries from |keychain| and returns them. On return, | 173 // in |keychain|, this adds the password from the entry and moves that form from |
175 // |database_forms| will contain only the forms for which no password was found. | 174 // |database_forms| into |passwords|. |
176 std::vector<autofill::PasswordForm*> GetPasswordsForForms( | 175 void GetPasswordsForForms(const AppleKeychain& keychain, |
177 const AppleKeychain& keychain, | 176 ScopedVector<autofill::PasswordForm>* database_forms, |
178 std::vector<autofill::PasswordForm*>* database_forms); | 177 ScopedVector<autofill::PasswordForm>* passwords); |
179 | 178 |
180 // Loads all items in the system keychain into |keychain_items|, creates for | 179 // Loads all items in the system keychain into |keychain_items|, creates for |
181 // each keychain item a corresponding PasswordForm that doesn't contain any | 180 // each keychain item a corresponding PasswordForm that doesn't contain any |
182 // password data, and returns the two collections as a vector of ItemFormPairs. | 181 // password data, and returns the two collections as a vector of ItemFormPairs. |
183 // Used by GetPasswordsForForms for optimized matching of keychain items with | 182 // Used by GetPasswordsForForms for optimized matching of keychain items with |
184 // PasswordForms in the database. | 183 // PasswordForms in the database. |
185 // Note: Since no password data is loaded here, the resulting PasswordForms | 184 // Note: Since no password data is loaded here, the resulting PasswordForms |
186 // will include blacklist entries, which will have to be filtered out later. | 185 // will include blacklist entries, which will have to be filtered out later. |
187 // Caller owns the SecKeychainItemRefs and PasswordForms that are returned. | 186 // Caller owns the SecKeychainItemRefs and PasswordForms that are returned. |
188 // This operation does not require OS authorization. | 187 // This operation does not require OS authorization. |
(...skipping 10 matching lines...) Expand all Loading... |
199 std::string* server, | 198 std::string* server, |
200 UInt32* port, | 199 UInt32* port, |
201 bool* is_secure, | 200 bool* is_secure, |
202 std::string* security_domain); | 201 std::string* security_domain); |
203 | 202 |
204 // Returns true if the signon_realm of |query_form| can be successfully parsed | 203 // Returns true if the signon_realm of |query_form| can be successfully parsed |
205 // by ExtractSignonRealmComponents, and if |query_form| matches |other_form|. | 204 // by ExtractSignonRealmComponents, and if |query_form| matches |other_form|. |
206 bool FormIsValidAndMatchesOtherForm(const autofill::PasswordForm& query_form, | 205 bool FormIsValidAndMatchesOtherForm(const autofill::PasswordForm& query_form, |
207 const autofill::PasswordForm& other_form); | 206 const autofill::PasswordForm& other_form); |
208 | 207 |
209 // Returns PasswordForms populated with password data for each keychain entry | 208 // Appends, to |matches|, PasswordForm instances populated with password data |
210 // in |item_form_pairs| that could be merged with |query_form|. | 209 // for each keychain entry in |item_form_pairs| that could be merged with |
211 // Caller is responsible for deleting the returned forms. | 210 // |query_form|. |
212 std::vector<autofill::PasswordForm*> ExtractPasswordsMergeableWithForm( | 211 void ExtractPasswordsMergeableWithForm( |
213 const AppleKeychain& keychain, | 212 const AppleKeychain& keychain, |
214 const std::vector<ItemFormPair>& item_form_pairs, | 213 const std::vector<ItemFormPair>& item_form_pairs, |
215 const autofill::PasswordForm& query_form); | 214 const autofill::PasswordForm& query_form, |
| 215 ScopedVector<autofill::PasswordForm>* matches); |
216 | 216 |
217 } // namespace internal_keychain_helpers | 217 } // namespace internal_keychain_helpers |
218 | 218 |
219 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ | 219 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ |
OLD | NEW |