Chromium Code Reviews| 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> |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 21 // Creates an adapter for |keychain|. This class does not take ownership of | 21 // 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 | 22 // |keychain|, so the caller must make sure that the keychain outlives the |
| 23 // created object. | 23 // created object. |
| 24 explicit MacKeychainPasswordFormAdapter(const AppleKeychain* keychain); | 24 explicit MacKeychainPasswordFormAdapter(const AppleKeychain* keychain); |
| 25 | 25 |
| 26 // Returns PasswordForms for each keychain entry that could be used to fill | 26 // Returns PasswordForms for each keychain entry that could be used to fill |
| 27 // |form|. Caller is responsible for deleting the returned forms. | 27 // |form|. Caller is responsible for deleting the returned forms. |
| 28 std::vector<autofill::PasswordForm*> PasswordsFillingForm( | 28 std::vector<autofill::PasswordForm*> PasswordsFillingForm( |
| 29 const autofill::PasswordForm& query_form); | 29 const autofill::PasswordForm& query_form); |
| 30 | 30 |
| 31 // Returns PasswordForms for each keychain entry that could be merged with | |
| 32 // |form|. Differs from PasswordsFillingForm in that the username must match. | |
| 33 // Caller is responsible for deleting the returned forms. | |
| 34 std::vector<autofill::PasswordForm*> PasswordsMergeableWithForm( | |
| 35 const autofill::PasswordForm& query_form); | |
| 36 | |
| 37 // Returns the PasswordForm for the Keychain entry that matches |form| on all | 31 // 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 | 32 // of the fields that uniquely identify a Keychain item, or NULL if there is |
| 39 // no such entry. | 33 // no such entry. |
| 40 // Caller is responsible for deleting the returned form. | 34 // Caller is responsible for deleting the returned form. |
| 41 autofill::PasswordForm* PasswordExactlyMatchingForm( | 35 autofill::PasswordForm* PasswordExactlyMatchingForm( |
| 42 const autofill::PasswordForm& query_form); | 36 const autofill::PasswordForm& query_form); |
| 43 | 37 |
| 44 // Returns true if PasswordsMergeableWithForm would return any items. This is | 38 // Returns true if the keychain contains any items that are mergeable with |
| 45 // a separate method because calling PasswordsMergeableWithForm and checking | 39 // |query_form|. This is different form actually extracting the passwords |
|
stuartmorgan
2013/10/09 23:49:25
s/different form/different from/
Raghu Simha
2013/10/10 00:32:19
Good catch. Done.
| |
| 46 // the return count would require reading the passwords from the keychain, | 40 // and checking the return count, since it would require reading the passwords |
|
stuartmorgan
2013/10/09 23:49:25
s/it/doing that/
Raghu Simha
2013/10/10 00:32:19
Done.
| |
| 47 // thus potentially triggering authorizaiton UI, whereas this won't. | 41 // from the keychain, thus potentially triggering authorizaiton UI, whereas |
| 42 // this won't. | |
| 48 bool HasPasswordsMergeableWithForm( | 43 bool HasPasswordsMergeableWithForm( |
| 49 const autofill::PasswordForm& query_form); | 44 const autofill::PasswordForm& query_form); |
| 50 | 45 |
| 51 // Returns all keychain items of types corresponding to password forms. | 46 // Returns all keychain items of types corresponding to password forms. |
| 47 std::vector<SecKeychainItemRef> GetAllPasswordFormKeychainItems(); | |
| 48 | |
| 49 // Returns password data from all keychain items of types corresponding to | |
| 50 // password forms. Caller is responsible for deleting the returned forms. | |
| 52 std::vector<autofill::PasswordForm*> GetAllPasswordFormPasswords(); | 51 std::vector<autofill::PasswordForm*> GetAllPasswordFormPasswords(); |
| 53 | 52 |
| 54 // 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 |
| 55 // 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 |
| 56 // entry was successfully added/updated. | 55 // entry was successfully added/updated. |
| 57 bool AddPassword(const autofill::PasswordForm& form); | 56 bool AddPassword(const autofill::PasswordForm& form); |
| 58 | 57 |
| 59 // 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 |
| 60 // keychain item was found and successfully removed. | 59 // keychain item was found and successfully removed. |
| 61 bool RemovePassword(const autofill::PasswordForm& form); | 60 bool RemovePassword(const autofill::PasswordForm& form); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 80 // Returns the Keychain items matching the given signon_realm, scheme, and | 79 // Returns the Keychain items matching the given signon_realm, scheme, and |
| 81 // optionally path and username (either of both can be NULL). | 80 // optionally path and username (either of both can be NULL). |
| 82 // The caller is responsible for calling AppleKeychain::Free on the | 81 // The caller is responsible for calling AppleKeychain::Free on the |
| 83 // returned items. | 82 // returned items. |
| 84 std::vector<SecKeychainItemRef> MatchingKeychainItems( | 83 std::vector<SecKeychainItemRef> MatchingKeychainItems( |
| 85 const std::string& signon_realm, | 84 const std::string& signon_realm, |
| 86 autofill::PasswordForm::Scheme scheme, | 85 autofill::PasswordForm::Scheme scheme, |
| 87 const char* path, | 86 const char* path, |
| 88 const char* username); | 87 const char* username); |
| 89 | 88 |
| 90 // Takes a PasswordForm's signon_realm and parses it into its component parts, | |
| 91 // which are returned though the appropriate out parameters. | |
| 92 // 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. | |
| 94 // If the return value is false, the state of the out params is undefined. | |
| 95 bool ExtractSignonRealmComponents(const std::string& signon_realm, | |
| 96 std::string* server, int* port, | |
| 97 bool* is_secure, | |
| 98 std::string* security_domain); | |
| 99 | |
| 100 // Returns the Keychain SecAuthenticationType type corresponding to |scheme|. | 89 // Returns the Keychain SecAuthenticationType type corresponding to |scheme|. |
| 101 SecAuthenticationType AuthTypeForScheme( | 90 SecAuthenticationType AuthTypeForScheme( |
| 102 autofill::PasswordForm::Scheme scheme); | 91 autofill::PasswordForm::Scheme scheme); |
| 103 | 92 |
| 104 // Changes the password for keychain_item to |password|; returns true if the | 93 // Changes the password for keychain_item to |password|; returns true if the |
| 105 // password was successfully changed. | 94 // password was successfully changed. |
| 106 bool SetKeychainItemPassword(const SecKeychainItemRef& keychain_item, | 95 bool SetKeychainItemPassword(const SecKeychainItemRef& keychain_item, |
| 107 const std::string& password); | 96 const std::string& password); |
| 108 | 97 |
| 109 // Sets the creator code of keychain_item to creator_code; returns true if the | 98 // Sets the creator code of keychain_item to creator_code; returns true if the |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 121 const AppleKeychain* keychain_; | 110 const AppleKeychain* keychain_; |
| 122 | 111 |
| 123 // If true, Keychain searches are restricted to items created by Chrome. | 112 // If true, Keychain searches are restricted to items created by Chrome. |
| 124 bool finds_only_owned_; | 113 bool finds_only_owned_; |
| 125 | 114 |
| 126 DISALLOW_COPY_AND_ASSIGN(MacKeychainPasswordFormAdapter); | 115 DISALLOW_COPY_AND_ASSIGN(MacKeychainPasswordFormAdapter); |
| 127 }; | 116 }; |
| 128 | 117 |
| 129 namespace internal_keychain_helpers { | 118 namespace internal_keychain_helpers { |
| 130 | 119 |
| 120 // Pair of pointers to a SecKeychainItemRef and a corresponding PasswordForm. | |
| 121 typedef std::pair<SecKeychainItemRef*, autofill::PasswordForm*> ItemFormPair; | |
| 122 | |
| 131 // Sets the fields of |form| based on the keychain data from |keychain_item|. | 123 // 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. | 124 // Fields that can't be determined from |keychain_item| will be unchanged. If |
| 125 // |extract_password_data| is true, the password data will be copied from | |
| 126 // |keychain_item| in addition to its attributes, and the |blacklisted_by_user| | |
| 127 // field will be set to true for empty passwords ("" or " "). | |
| 128 // If |extract_password_data| is false, only the password attributes will be | |
| 129 // copied, and the |blacklisted_by_user| field will remain false for empty | |
| 130 // passwords ("" or " "). | |
|
stuartmorgan
2013/10/09 23:49:25
s/remain false for [...]/always be false/
Raghu Simha
2013/10/10 00:32:19
Done.
| |
| 133 // | 131 // |
| 134 // IMPORTANT: This function can cause the OS to trigger UI (to allow access to | 132 // 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 | 133 // to trigger UI (to allow access to the keychain item if we aren't trusted for |
| 136 // is dismissed. | 134 // the item), and block until the UI is dismissed. |
| 137 // | 135 // |
| 138 // If excessive prompting for access to other applications' keychain items | 136 // If excessive prompting for access to other applications' keychain items |
| 139 // becomes an issue, the password storage API will need to be refactored to | 137 // 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 | 138 // function with |extract_password_data| set to false, and retrieve the password |
| 141 // require authorization). | 139 // later (accessing other fields doesn't require authorization). |
| 142 bool FillPasswordFormFromKeychainItem(const AppleKeychain& keychain, | 140 bool FillPasswordFormFromKeychainItem(const AppleKeychain& keychain, |
| 143 const SecKeychainItemRef& keychain_item, | 141 const SecKeychainItemRef& keychain_item, |
| 144 autofill::PasswordForm* form); | 142 autofill::PasswordForm* form, |
| 143 bool extract_password_data); | |
| 145 | 144 |
| 146 // Returns true if the two given forms match based on signon_reaml, scheme, and | 145 // 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). | 146 // username_value, and are thus suitable for merging (see MergePasswordForms). |
| 148 bool FormsMatchForMerge(const autofill::PasswordForm& form_a, | 147 bool FormsMatchForMerge(const autofill::PasswordForm& form_a, |
| 149 const autofill::PasswordForm& form_b); | 148 const autofill::PasswordForm& form_b); |
| 150 | 149 |
| 151 // Populates merged_forms by combining the password data from keychain_forms and | 150 // 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 | 151 // the metadata from database_forms, removing used entries from the two source |
| 153 // lists. | 152 // lists. |
| 154 // | 153 // |
| 155 // On return, database_forms and keychain_forms will have only unused | 154 // On return, database_forms and keychain_forms will have only unused |
| 156 // entries; for database_forms that means entries for which no corresponding | 155 // entries; for database_forms that means entries for which no corresponding |
| 157 // password can be found (and which aren't blacklist entries), and for | 156 // 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 | 157 // keychain_forms its entries that weren't merged into at least one database |
| 159 // form. | 158 // form. |
| 160 void MergePasswordForms( | 159 void MergePasswordForms( |
| 161 std::vector<autofill::PasswordForm*>* keychain_forms, | 160 std::vector<autofill::PasswordForm*>* keychain_forms, |
| 162 std::vector<autofill::PasswordForm*>* database_forms, | 161 std::vector<autofill::PasswordForm*>* database_forms, |
| 163 std::vector<autofill::PasswordForm*>* merged_forms); | 162 std::vector<autofill::PasswordForm*>* merged_forms); |
| 164 | 163 |
| 165 // Fills in the passwords for as many of the forms in |database_forms| as | 164 // 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, | 165 // possible using entries from |keychain| and returns them. On return, |
| 167 // |database_forms| will contain only the forms for which no password was found. | 166 // |database_forms| will contain only the forms for which no password was found. |
| 168 std::vector<autofill::PasswordForm*> GetPasswordsForForms( | 167 std::vector<autofill::PasswordForm*> GetPasswordsForForms( |
| 169 const AppleKeychain& keychain, | 168 const AppleKeychain& keychain, |
| 170 std::vector<autofill::PasswordForm*>* database_forms); | 169 std::vector<autofill::PasswordForm*>* database_forms); |
| 171 | 170 |
| 171 // Loads all items in the system keychain into |keychain_items|, creates for | |
| 172 // each keychain item a corresponding PasswordForm that doesn't contain any | |
| 173 // password data, and returns the two collections as a vector of ItemFormPairs. | |
| 174 // Used by GetPasswordsForForms for optimized matching of keychain items with | |
| 175 // PasswordForms in the database. | |
| 176 // Note: Since no password data is loaded here, the resulting PasswordForms | |
| 177 // will include blacklist entries, which will have to be filtered out later. | |
| 178 // Caller owns the SecKeychainItemRefs and PasswordForms that are returned. | |
| 179 // This operation does not require OS authorization. | |
| 180 std::vector<ItemFormPair> ExtractAllKeychainItemAttributesIntoPasswordForms( | |
| 181 std::vector<SecKeychainItemRef>* keychain_items, | |
| 182 const AppleKeychain& keychain); | |
| 183 | |
| 184 // Takes a PasswordForm's signon_realm and parses it into its component parts, | |
| 185 // which are returned though the appropriate out parameters. | |
| 186 // Returns true if it can be successfully parsed, in which case all out params | |
| 187 // that are non-NULL will be set. If there is no port, port will be 0. | |
| 188 // If the return value is false, the state of the out params is undefined. | |
| 189 bool ExtractSignonRealmComponents(const std::string& signon_realm, | |
| 190 std::string* server, int* port, | |
| 191 bool* is_secure, | |
| 192 std::string* security_domain); | |
| 193 | |
| 194 // Returns true if the signon_realm of |query_form| can be successfully parsed | |
| 195 // by ExtractSignonRealmComponents, and if |query_form| matches |other_form|. | |
| 196 bool FormIsValidAndMatchesOtherForm(const autofill::PasswordForm& query_form, | |
| 197 const autofill::PasswordForm& other_form); | |
| 198 | |
| 199 // Returns PasswordForms populated with password data for each keychain entry | |
| 200 // in |item_form_pairs| that could be merged with |query_form|. | |
| 201 // Caller is responsible for deleting the returned forms. | |
| 202 std::vector<autofill::PasswordForm*> ExtractPasswordsMergeableWithForm( | |
| 203 const AppleKeychain& keychain, | |
| 204 const std::vector<ItemFormPair>& item_form_pairs, | |
| 205 const autofill::PasswordForm& query_form); | |
| 206 | |
| 172 } // namespace internal_keychain_helpers | 207 } // namespace internal_keychain_helpers |
| 173 | 208 |
| 174 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ | 209 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ |
| OLD | NEW |