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 // Returns all keychain entries matching |signon_realm| and |scheme|. |
28 // |form|. Caller is responsible for deleting the returned forms. | 29 ScopedVector<autofill::PasswordForm> PasswordsFillingForm( |
29 std::vector<autofill::PasswordForm*> PasswordsFillingForm( | |
30 const std::string& signon_realm, | 30 const std::string& signon_realm, |
31 autofill::PasswordForm::Scheme scheme); | 31 autofill::PasswordForm::Scheme scheme); |
32 | 32 |
33 // Returns true if there is the Keychain entry that matches |query_form| on | 33 // Returns true if there is the Keychain entry that matches |query_form| on |
34 // all of the fields that uniquely identify a Keychain item. | 34 // all of the fields that uniquely identify a Keychain item. |
35 bool HasPasswordExactlyMatchingForm(const autofill::PasswordForm& query_form); | 35 bool HasPasswordExactlyMatchingForm(const autofill::PasswordForm& query_form); |
36 | 36 |
37 // Returns true if the keychain contains any items that are mergeable with | 37 // Returns true if the keychain contains any items that are mergeable with |
38 // |query_form|. This is different from actually extracting the passwords | 38 // |query_form|. This is different from actually extracting the passwords |
39 // and checking the return count, since doing that would require reading the | 39 // and checking the return count, since doing that would require reading the |
40 // passwords from the keychain, thus potentially triggering authorizaiton UI, | 40 // passwords from the keychain, thus potentially triggering authorizaiton UI, |
41 // whereas this won't. | 41 // whereas this won't. |
42 bool HasPasswordsMergeableWithForm( | 42 bool HasPasswordsMergeableWithForm( |
43 const autofill::PasswordForm& query_form); | 43 const autofill::PasswordForm& query_form); |
44 | 44 |
45 // Returns all keychain items of types corresponding to password forms. | 45 // Returns all keychain items of types corresponding to password forms. |
46 std::vector<SecKeychainItemRef> GetAllPasswordFormKeychainItems(); | 46 std::vector<SecKeychainItemRef> GetAllPasswordFormKeychainItems(); |
47 | 47 |
48 // Returns password data from all keychain items of types corresponding to | 48 // Returns all keychain entries corresponding to password forms. |
49 // password forms. Caller is responsible for deleting the returned forms. | 49 // TODO(vabr): This is only used in tests, should be moved there. |
50 std::vector<autofill::PasswordForm*> GetAllPasswordFormPasswords(); | 50 ScopedVector<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 // Returns PasswordForm instances transformed from |items|. Also calls |
67 // AppleKeychain::Free on all of the keychain items and clearing the vector. | 67 // AppleKeychain::Free on all of the keychain items and clears |items|. |
68 // Caller is responsible for deleting the returned forms. | 68 ScopedVector<autofill::PasswordForm> ConvertKeychainItemsToForms( |
69 std::vector<autofill::PasswordForm*> ConvertKeychainItemsToForms( | |
70 std::vector<SecKeychainItemRef>* items); | 69 std::vector<SecKeychainItemRef>* items); |
71 | 70 |
72 // Searches |keychain| for the specific keychain entry that corresponds to the | 71 // 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 | 72 // 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. | 73 // responsible for calling AppleKeychain::Free on on the returned item. |
75 SecKeychainItemRef KeychainItemForForm( | 74 SecKeychainItemRef KeychainItemForForm( |
76 const autofill::PasswordForm& form); | 75 const autofill::PasswordForm& form); |
77 | 76 |
78 // Returns the Keychain items matching the given signon_realm, scheme, and | 77 // Returns the Keychain items matching the given signon_realm, scheme, and |
79 // optionally path and username (either of both can be NULL). | 78 // optionally path and username (either of both can be NULL). |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 | 157 |
159 // Populates merged_forms by combining the password data from keychain_forms and | 158 // 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 | 159 // the metadata from database_forms, removing used entries from the two source |
161 // lists. | 160 // lists. |
162 // | 161 // |
163 // On return, database_forms and keychain_forms will have only unused | 162 // On return, database_forms and keychain_forms will have only unused |
164 // entries; for database_forms that means entries for which no corresponding | 163 // entries; for database_forms that means entries for which no corresponding |
165 // password can be found (and which aren't blacklist entries), and for | 164 // 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 | 165 // keychain_forms its entries that weren't merged into at least one database |
167 // form. | 166 // form. |
168 void MergePasswordForms( | 167 void MergePasswordForms(ScopedVector<autofill::PasswordForm>* keychain_forms, |
169 std::vector<autofill::PasswordForm*>* keychain_forms, | 168 ScopedVector<autofill::PasswordForm>* database_forms, |
170 std::vector<autofill::PasswordForm*>* database_forms, | 169 ScopedVector<autofill::PasswordForm>* merged_forms); |
171 std::vector<autofill::PasswordForm*>* merged_forms); | |
172 | 170 |
173 // Fills in the passwords for as many of the forms in |database_forms| as | 171 // 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, | 172 // 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. | 173 // |database_forms| into |passwords|. |
176 std::vector<autofill::PasswordForm*> GetPasswordsForForms( | 174 void GetPasswordsForForms(const AppleKeychain& keychain, |
177 const AppleKeychain& keychain, | 175 ScopedVector<autofill::PasswordForm>* database_forms, |
178 std::vector<autofill::PasswordForm*>* database_forms); | 176 ScopedVector<autofill::PasswordForm>* passwords); |
179 | 177 |
180 // Loads all items in the system keychain into |keychain_items|, creates for | 178 // Loads all items in the system keychain into |keychain_items|, creates for |
181 // each keychain item a corresponding PasswordForm that doesn't contain any | 179 // each keychain item a corresponding PasswordForm that doesn't contain any |
182 // password data, and returns the two collections as a vector of ItemFormPairs. | 180 // password data, and returns the two collections as a vector of ItemFormPairs. |
183 // Used by GetPasswordsForForms for optimized matching of keychain items with | 181 // Used by GetPasswordsForForms for optimized matching of keychain items with |
184 // PasswordForms in the database. | 182 // PasswordForms in the database. |
185 // Note: Since no password data is loaded here, the resulting PasswordForms | 183 // Note: Since no password data is loaded here, the resulting PasswordForms |
186 // will include blacklist entries, which will have to be filtered out later. | 184 // will include blacklist entries, which will have to be filtered out later. |
187 // Caller owns the SecKeychainItemRefs and PasswordForms that are returned. | 185 // Caller owns the SecKeychainItemRefs and PasswordForms that are returned. |
188 // This operation does not require OS authorization. | 186 // This operation does not require OS authorization. |
(...skipping 10 matching lines...) Expand all Loading... |
199 std::string* server, | 197 std::string* server, |
200 UInt32* port, | 198 UInt32* port, |
201 bool* is_secure, | 199 bool* is_secure, |
202 std::string* security_domain); | 200 std::string* security_domain); |
203 | 201 |
204 // Returns true if the signon_realm of |query_form| can be successfully parsed | 202 // Returns true if the signon_realm of |query_form| can be successfully parsed |
205 // by ExtractSignonRealmComponents, and if |query_form| matches |other_form|. | 203 // by ExtractSignonRealmComponents, and if |query_form| matches |other_form|. |
206 bool FormIsValidAndMatchesOtherForm(const autofill::PasswordForm& query_form, | 204 bool FormIsValidAndMatchesOtherForm(const autofill::PasswordForm& query_form, |
207 const autofill::PasswordForm& other_form); | 205 const autofill::PasswordForm& other_form); |
208 | 206 |
209 // Returns PasswordForms populated with password data for each keychain entry | 207 // Returns PasswordForm instances populated with password data for each keychain |
210 // in |item_form_pairs| that could be merged with |query_form|. | 208 // entry in |item_form_pairs| that could be merged with |query_form|. |
211 // Caller is responsible for deleting the returned forms. | 209 ScopedVector<autofill::PasswordForm> ExtractPasswordsMergeableWithForm( |
212 std::vector<autofill::PasswordForm*> ExtractPasswordsMergeableWithForm( | |
213 const AppleKeychain& keychain, | 210 const AppleKeychain& keychain, |
214 const std::vector<ItemFormPair>& item_form_pairs, | 211 const std::vector<ItemFormPair>& item_form_pairs, |
215 const autofill::PasswordForm& query_form); | 212 const autofill::PasswordForm& query_form); |
216 | 213 |
217 } // namespace internal_keychain_helpers | 214 } // namespace internal_keychain_helpers |
218 | 215 |
219 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ | 216 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ |
OLD | NEW |