| 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/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/scoped_vector.h" | |
| 15 #include "components/autofill/core/common/password_form.h" | 14 #include "components/autofill/core/common/password_form.h" |
| 16 #include "crypto/apple_keychain.h" | 15 #include "crypto/apple_keychain.h" |
| 17 | 16 |
| 18 using crypto::AppleKeychain; | 17 using crypto::AppleKeychain; |
| 19 | 18 |
| 20 // Adapter that wraps a AppleKeychain and provides interaction in terms of | 19 // Adapter that wraps a AppleKeychain and provides interaction in terms of |
| 21 // PasswordForms instead of Keychain items. | 20 // PasswordForms instead of Keychain items. |
| 22 class MacKeychainPasswordFormAdapter { | 21 class MacKeychainPasswordFormAdapter { |
| 23 public: | 22 public: |
| 24 // 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 |
| 25 // |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 |
| 26 // created object. | 25 // created object. |
| 27 explicit MacKeychainPasswordFormAdapter(const AppleKeychain* keychain); | 26 explicit MacKeychainPasswordFormAdapter(const AppleKeychain* keychain); |
| 28 | 27 |
| 29 // Returns all keychain entries matching |signon_realm| and |scheme|. | 28 // Returns all keychain entries matching |signon_realm| and |scheme|. |
| 30 ScopedVector<autofill::PasswordForm> PasswordsFillingForm( | 29 std::vector<std::unique_ptr<autofill::PasswordForm>> PasswordsFillingForm( |
| 31 const std::string& signon_realm, | 30 const std::string& signon_realm, |
| 32 autofill::PasswordForm::Scheme scheme); | 31 autofill::PasswordForm::Scheme scheme); |
| 33 | 32 |
| 34 // 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 |
| 35 // all of the fields that uniquely identify a Keychain item. | 34 // all of the fields that uniquely identify a Keychain item. |
| 36 bool HasPasswordExactlyMatchingForm(const autofill::PasswordForm& query_form); | 35 bool HasPasswordExactlyMatchingForm(const autofill::PasswordForm& query_form); |
| 37 | 36 |
| 38 // 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 |
| 39 // |query_form|. This is different from actually extracting the passwords | 38 // |query_form|. This is different from actually extracting the passwords |
| 40 // 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 |
| 41 // passwords from the keychain, thus potentially triggering authorizaiton UI, | 40 // passwords from the keychain, thus potentially triggering authorizaiton UI, |
| 42 // whereas this won't. | 41 // whereas this won't. |
| 43 bool HasPasswordsMergeableWithForm( | 42 bool HasPasswordsMergeableWithForm( |
| 44 const autofill::PasswordForm& query_form); | 43 const autofill::PasswordForm& query_form); |
| 45 | 44 |
| 46 // Returns all keychain items of types corresponding to password forms. | 45 // Returns all keychain items of types corresponding to password forms. |
| 47 std::vector<SecKeychainItemRef> GetAllPasswordFormKeychainItems(); | 46 std::vector<SecKeychainItemRef> GetAllPasswordFormKeychainItems(); |
| 48 | 47 |
| 49 // Returns all keychain entries corresponding to password forms. | 48 // Returns all keychain entries corresponding to password forms. |
| 50 // TODO(vabr): This is only used in tests, should be moved there. | 49 // TODO(vabr): This is only used in tests, should be moved there. |
| 51 ScopedVector<autofill::PasswordForm> GetAllPasswordFormPasswords(); | 50 std::vector<std::unique_ptr<autofill::PasswordForm>> |
| 51 GetAllPasswordFormPasswords(); |
| 52 | 52 |
| 53 // Creates a new keychain entry from |form|, or updates the password of an | 53 // Creates a new keychain entry from |form|, or updates the password of an |
| 54 // existing keychain entry if there is a collision. Returns true if a keychain | 54 // existing keychain entry if there is a collision. Returns true if a keychain |
| 55 // entry was successfully added/updated. | 55 // entry was successfully added/updated. |
| 56 bool AddPassword(const autofill::PasswordForm& form); | 56 bool AddPassword(const autofill::PasswordForm& form); |
| 57 | 57 |
| 58 // Removes the keychain password matching |form| if any. Returns true if a | 58 // Removes the keychain password matching |form| if any. Returns true if a |
| 59 // keychain item was found and successfully removed. | 59 // keychain item was found and successfully removed. |
| 60 bool RemovePassword(const autofill::PasswordForm& form); | 60 bool RemovePassword(const autofill::PasswordForm& form); |
| 61 | 61 |
| 62 // Controls whether or not Chrome will restrict Keychain searches to items | 62 // Controls whether or not Chrome will restrict Keychain searches to items |
| 63 // that it created. Defaults to false. | 63 // that it created. Defaults to false. |
| 64 void SetFindsOnlyOwnedItems(bool finds_only_owned); | 64 void SetFindsOnlyOwnedItems(bool finds_only_owned); |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 // Returns PasswordForm instances transformed from |items|. Also calls | 67 // Returns PasswordForm instances transformed from |items|. Also calls |
| 68 // AppleKeychain::Free on all of the keychain items and clears |items|. | 68 // AppleKeychain::Free on all of the keychain items and clears |items|. |
| 69 ScopedVector<autofill::PasswordForm> ConvertKeychainItemsToForms( | 69 std::vector<std::unique_ptr<autofill::PasswordForm>> |
| 70 std::vector<SecKeychainItemRef>* items); | 70 ConvertKeychainItemsToForms(std::vector<SecKeychainItemRef>* items); |
| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 164 |
| 165 // Populates merged_forms by combining the password data from keychain_forms and | 165 // Populates merged_forms by combining the password data from keychain_forms and |
| 166 // the metadata from database_forms, removing used entries from the two source | 166 // the metadata from database_forms, removing used entries from the two source |
| 167 // lists. | 167 // lists. |
| 168 // | 168 // |
| 169 // On return, database_forms and keychain_forms will have only unused | 169 // On return, database_forms and keychain_forms will have only unused |
| 170 // entries; for database_forms that means entries for which no corresponding | 170 // entries; for database_forms that means entries for which no corresponding |
| 171 // password can be found (and which aren't blacklist entries), and for | 171 // password can be found (and which aren't blacklist entries), and for |
| 172 // keychain_forms its entries that weren't merged into at least one database | 172 // keychain_forms its entries that weren't merged into at least one database |
| 173 // form. | 173 // form. |
| 174 void MergePasswordForms(ScopedVector<autofill::PasswordForm>* keychain_forms, | 174 void MergePasswordForms( |
| 175 ScopedVector<autofill::PasswordForm>* database_forms, | 175 std::vector<std::unique_ptr<autofill::PasswordForm>>* keychain_forms, |
| 176 ScopedVector<autofill::PasswordForm>* merged_forms); | 176 std::vector<std::unique_ptr<autofill::PasswordForm>>* database_forms, |
| 177 std::vector<std::unique_ptr<autofill::PasswordForm>>* merged_forms); |
| 177 | 178 |
| 178 // For every form in |database_forms|, if such a form has a corresponding entry | 179 // For every form in |database_forms|, if such a form has a corresponding entry |
| 179 // in |keychain|, this adds the password from the entry and moves that form from | 180 // in |keychain|, this adds the password from the entry and moves that form from |
| 180 // |database_forms| into |passwords|. | 181 // |database_forms| into |passwords|. |
| 181 void GetPasswordsForForms(const AppleKeychain& keychain, | 182 void GetPasswordsForForms( |
| 182 ScopedVector<autofill::PasswordForm>* database_forms, | 183 const AppleKeychain& keychain, |
| 183 ScopedVector<autofill::PasswordForm>* passwords); | 184 std::vector<std::unique_ptr<autofill::PasswordForm>>* database_forms, |
| 185 std::vector<std::unique_ptr<autofill::PasswordForm>>* passwords); |
| 184 | 186 |
| 185 // Loads all items in the system keychain into |keychain_items|, creates for | 187 // Loads all items in the system keychain into |keychain_items|, creates for |
| 186 // each keychain item a corresponding PasswordForm that doesn't contain any | 188 // each keychain item a corresponding PasswordForm that doesn't contain any |
| 187 // password data, and returns the two collections as a vector of ItemFormPairs. | 189 // password data, and returns the two collections as a vector of ItemFormPairs. |
| 188 // Used by GetPasswordsForForms for optimized matching of keychain items with | 190 // Used by GetPasswordsForForms for optimized matching of keychain items with |
| 189 // PasswordForms in the database. | 191 // PasswordForms in the database. |
| 190 // Note: Since no password data is loaded here, the resulting PasswordForms | 192 // Note: Since no password data is loaded here, the resulting PasswordForms |
| 191 // will include blacklist entries, which will have to be filtered out later. | 193 // will include blacklist entries, which will have to be filtered out later. |
| 192 // Caller owns the SecKeychainItemRefs and PasswordForms that are returned. | 194 // Caller owns the SecKeychainItemRefs and PasswordForms that are returned. |
| 193 // This operation does not require OS authorization. | 195 // This operation does not require OS authorization. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 206 bool* is_secure, | 208 bool* is_secure, |
| 207 std::string* security_domain); | 209 std::string* security_domain); |
| 208 | 210 |
| 209 // Returns true if the signon_realm of |query_form| can be successfully parsed | 211 // Returns true if the signon_realm of |query_form| can be successfully parsed |
| 210 // by ExtractSignonRealmComponents, and if |query_form| matches |other_form|. | 212 // by ExtractSignonRealmComponents, and if |query_form| matches |other_form|. |
| 211 bool FormIsValidAndMatchesOtherForm(const autofill::PasswordForm& query_form, | 213 bool FormIsValidAndMatchesOtherForm(const autofill::PasswordForm& query_form, |
| 212 const autofill::PasswordForm& other_form); | 214 const autofill::PasswordForm& other_form); |
| 213 | 215 |
| 214 // Returns PasswordForm instances populated with password data for each keychain | 216 // Returns PasswordForm instances populated with password data for each keychain |
| 215 // entry in |item_form_pairs| that could be merged with |query_form|. | 217 // entry in |item_form_pairs| that could be merged with |query_form|. |
| 216 ScopedVector<autofill::PasswordForm> ExtractPasswordsMergeableWithForm( | 218 std::vector<std::unique_ptr<autofill::PasswordForm>> |
| 219 ExtractPasswordsMergeableWithForm( |
| 217 const AppleKeychain& keychain, | 220 const AppleKeychain& keychain, |
| 218 const std::vector<ItemFormPair>& item_form_pairs, | 221 const std::vector<ItemFormPair>& item_form_pairs, |
| 219 const autofill::PasswordForm& query_form); | 222 const autofill::PasswordForm& query_form); |
| 220 | 223 |
| 221 } // namespace internal_keychain_helpers | 224 } // namespace internal_keychain_helpers |
| 222 | 225 |
| 223 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ | 226 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ |
| OLD | NEW |