| 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/time.h" | 13 #include "base/time.h" |
| 14 #include "crypto/apple_keychain.h" | 14 #include "crypto/apple_keychain.h" |
| 15 | 15 |
| 16 using crypto::AppleKeychain; | 16 using crypto::AppleKeychain; |
| 17 | 17 |
| 18 // Adapter that wraps a AppleKeychain and provides interaction in terms of | 18 // Adapter that wraps a AppleKeychain and provides interaction in terms of |
| 19 // PasswordForms instead of Keychain items. | 19 // PasswordForms instead of Keychain items. |
| 20 class MacKeychainPasswordFormAdapter { | 20 class MacKeychainPasswordFormAdapter { |
| 21 public: | 21 public: |
| 22 // Creates an adapter for |keychain|. This class does not take ownership of | 22 // 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 | 23 // |keychain|, so the caller must make sure that the keychain outlives the |
| 24 // created object. | 24 // created object. |
| 25 explicit MacKeychainPasswordFormAdapter(const AppleKeychain* keychain); | 25 explicit MacKeychainPasswordFormAdapter(const AppleKeychain* keychain); |
| 26 | 26 |
| 27 // Returns PasswordForms for each keychain entry that could be used to fill | 27 // Returns PasswordForms for each keychain entry that could be used to fill |
| 28 // |form|. Caller is responsible for deleting the returned forms. | 28 // |form|. Caller is responsible for deleting the returned forms. |
| 29 std::vector<webkit::forms::PasswordForm*> PasswordsFillingForm( | 29 std::vector<content::PasswordForm*> PasswordsFillingForm( |
| 30 const webkit::forms::PasswordForm& query_form); | 30 const content::PasswordForm& query_form); |
| 31 | 31 |
| 32 // Returns PasswordForms for each keychain entry that could be merged with | 32 // Returns PasswordForms for each keychain entry that could be merged with |
| 33 // |form|. Differs from PasswordsFillingForm in that the username must match. | 33 // |form|. Differs from PasswordsFillingForm in that the username must match. |
| 34 // Caller is responsible for deleting the returned forms. | 34 // Caller is responsible for deleting the returned forms. |
| 35 std::vector<webkit::forms::PasswordForm*> PasswordsMergeableWithForm( | 35 std::vector<content::PasswordForm*> PasswordsMergeableWithForm( |
| 36 const webkit::forms::PasswordForm& query_form); | 36 const content::PasswordForm& query_form); |
| 37 | 37 |
| 38 // Returns the PasswordForm for the Keychain entry that matches |form| on all | 38 // Returns the PasswordForm for the Keychain entry that matches |form| on all |
| 39 // of the fields that uniquely identify a Keychain item, or NULL if there is | 39 // of the fields that uniquely identify a Keychain item, or NULL if there is |
| 40 // no such entry. | 40 // no such entry. |
| 41 // Caller is responsible for deleting the returned form. | 41 // Caller is responsible for deleting the returned form. |
| 42 webkit::forms::PasswordForm* PasswordExactlyMatchingForm( | 42 content::PasswordForm* PasswordExactlyMatchingForm( |
| 43 const webkit::forms::PasswordForm& query_form); | 43 const content::PasswordForm& query_form); |
| 44 | 44 |
| 45 // Returns true if PasswordsMergeableWithForm would return any items. This is | 45 // Returns true if PasswordsMergeableWithForm would return any items. This is |
| 46 // a separate method because calling PasswordsMergeableWithForm and checking | 46 // a separate method because calling PasswordsMergeableWithForm and checking |
| 47 // the return count would require reading the passwords from the keychain, | 47 // the return count would require reading the passwords from the keychain, |
| 48 // thus potentially triggering authorizaiton UI, whereas this won't. | 48 // thus potentially triggering authorizaiton UI, whereas this won't. |
| 49 bool HasPasswordsMergeableWithForm( | 49 bool HasPasswordsMergeableWithForm( |
| 50 const webkit::forms::PasswordForm& query_form); | 50 const content::PasswordForm& query_form); |
| 51 | 51 |
| 52 // Returns all keychain items of types corresponding to password forms. | 52 // Returns all keychain items of types corresponding to password forms. |
| 53 std::vector<webkit::forms::PasswordForm*> GetAllPasswordFormPasswords(); | 53 std::vector<content::PasswordForm*> GetAllPasswordFormPasswords(); |
| 54 | 54 |
| 55 // Creates a new keychain entry from |form|, or updates the password of an | 55 // Creates a new keychain entry from |form|, or updates the password of an |
| 56 // existing keychain entry if there is a collision. Returns true if a keychain | 56 // existing keychain entry if there is a collision. Returns true if a keychain |
| 57 // entry was successfully added/updated. | 57 // entry was successfully added/updated. |
| 58 bool AddPassword(const webkit::forms::PasswordForm& form); | 58 bool AddPassword(const content::PasswordForm& form); |
| 59 | 59 |
| 60 // Removes the keychain password matching |form| if any. Returns true if a | 60 // Removes the keychain password matching |form| if any. Returns true if a |
| 61 // keychain item was found and successfully removed. | 61 // keychain item was found and successfully removed. |
| 62 bool RemovePassword(const webkit::forms::PasswordForm& form); | 62 bool RemovePassword(const content::PasswordForm& form); |
| 63 | 63 |
| 64 // Controls whether or not Chrome will restrict Keychain searches to items | 64 // Controls whether or not Chrome will restrict Keychain searches to items |
| 65 // that it created. Defaults to false. | 65 // that it created. Defaults to false. |
| 66 void SetFindsOnlyOwnedItems(bool finds_only_owned); | 66 void SetFindsOnlyOwnedItems(bool finds_only_owned); |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 // Returns PasswordForms constructed from the given Keychain items, calling | 69 // Returns PasswordForms constructed from the given Keychain items, calling |
| 70 // AppleKeychain::Free on all of the keychain items and clearing the vector. | 70 // AppleKeychain::Free on all of the keychain items and clearing the vector. |
| 71 // Caller is responsible for deleting the returned forms. | 71 // Caller is responsible for deleting the returned forms. |
| 72 std::vector<webkit::forms::PasswordForm*> ConvertKeychainItemsToForms( | 72 std::vector<content::PasswordForm*> ConvertKeychainItemsToForms( |
| 73 std::vector<SecKeychainItemRef>* items); | 73 std::vector<SecKeychainItemRef>* items); |
| 74 | 74 |
| 75 // Searches |keychain| for the specific keychain entry that corresponds to the | 75 // Searches |keychain| for the specific keychain entry that corresponds to the |
| 76 // given form, and returns it (or NULL if no match is found). The caller is | 76 // given form, and returns it (or NULL if no match is found). The caller is |
| 77 // responsible for calling AppleKeychain::Free on on the returned item. | 77 // responsible for calling AppleKeychain::Free on on the returned item. |
| 78 SecKeychainItemRef KeychainItemForForm( | 78 SecKeychainItemRef KeychainItemForForm( |
| 79 const webkit::forms::PasswordForm& form); | 79 const content::PasswordForm& form); |
| 80 | 80 |
| 81 // Returns the Keychain items matching the given signon_realm, scheme, and | 81 // Returns the Keychain items matching the given signon_realm, scheme, and |
| 82 // optionally path and username (either of both can be NULL). | 82 // optionally path and username (either of both can be NULL). |
| 83 // The caller is responsible for calling AppleKeychain::Free on the | 83 // The caller is responsible for calling AppleKeychain::Free on the |
| 84 // returned items. | 84 // returned items. |
| 85 std::vector<SecKeychainItemRef> MatchingKeychainItems( | 85 std::vector<SecKeychainItemRef> MatchingKeychainItems( |
| 86 const std::string& signon_realm, | 86 const std::string& signon_realm, |
| 87 webkit::forms::PasswordForm::Scheme scheme, | 87 content::PasswordForm::Scheme scheme, |
| 88 const char* path, | 88 const char* path, |
| 89 const char* username); | 89 const char* username); |
| 90 | 90 |
| 91 // Takes a PasswordForm's signon_realm and parses it into its component parts, | 91 // Takes a PasswordForm's signon_realm and parses it into its component parts, |
| 92 // which are returned though the appropriate out parameters. | 92 // which are returned though the appropriate out parameters. |
| 93 // Returns true if it can be successfully parsed, in which case all out params | 93 // Returns true if it can be successfully parsed, in which case all out params |
| 94 // that are non-NULL will be set. If there is no port, port will be 0. | 94 // that are non-NULL will be set. If there is no port, port will be 0. |
| 95 // If the return value is false, the state of the out params is undefined. | 95 // If the return value is false, the state of the out params is undefined. |
| 96 bool ExtractSignonRealmComponents(const std::string& signon_realm, | 96 bool ExtractSignonRealmComponents(const std::string& signon_realm, |
| 97 std::string* server, int* port, | 97 std::string* server, int* port, |
| 98 bool* is_secure, | 98 bool* is_secure, |
| 99 std::string* security_domain); | 99 std::string* security_domain); |
| 100 | 100 |
| 101 // Returns the Keychain SecAuthenticationType type corresponding to |scheme|. | 101 // Returns the Keychain SecAuthenticationType type corresponding to |scheme|. |
| 102 SecAuthenticationType AuthTypeForScheme( | 102 SecAuthenticationType AuthTypeForScheme( |
| 103 webkit::forms::PasswordForm::Scheme scheme); | 103 content::PasswordForm::Scheme scheme); |
| 104 | 104 |
| 105 // Changes the password for keychain_item to |password|; returns true if the | 105 // Changes the password for keychain_item to |password|; returns true if the |
| 106 // password was successfully changed. | 106 // password was successfully changed. |
| 107 bool SetKeychainItemPassword(const SecKeychainItemRef& keychain_item, | 107 bool SetKeychainItemPassword(const SecKeychainItemRef& keychain_item, |
| 108 const std::string& password); | 108 const std::string& password); |
| 109 | 109 |
| 110 // Sets the creator code of keychain_item to creator_code; returns true if the | 110 // Sets the creator code of keychain_item to creator_code; returns true if the |
| 111 // creator code was successfully set. | 111 // creator code was successfully set. |
| 112 bool SetKeychainItemCreatorCode(const SecKeychainItemRef& keychain_item, | 112 bool SetKeychainItemCreatorCode(const SecKeychainItemRef& keychain_item, |
| 113 OSType creator_code); | 113 OSType creator_code); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 135 // IMPORTANT: This function can cause the OS to trigger UI (to allow access to | 135 // IMPORTANT: This function can cause the OS to trigger UI (to allow access to |
| 136 // the keychain item if we aren't trusted for the item), and block until the UI | 136 // the keychain item if we aren't trusted for the item), and block until the UI |
| 137 // is dismissed. | 137 // is dismissed. |
| 138 // | 138 // |
| 139 // If excessive prompting for access to other applications' keychain items | 139 // If excessive prompting for access to other applications' keychain items |
| 140 // becomes an issue, the password storage API will need to be refactored to | 140 // becomes an issue, the password storage API will need to be refactored to |
| 141 // allow the password to be retrieved later (accessing other fields doesn't | 141 // allow the password to be retrieved later (accessing other fields doesn't |
| 142 // require authorization). | 142 // require authorization). |
| 143 bool FillPasswordFormFromKeychainItem(const AppleKeychain& keychain, | 143 bool FillPasswordFormFromKeychainItem(const AppleKeychain& keychain, |
| 144 const SecKeychainItemRef& keychain_item, | 144 const SecKeychainItemRef& keychain_item, |
| 145 webkit::forms::PasswordForm* form); | 145 content::PasswordForm* form); |
| 146 | 146 |
| 147 // Returns true if the two given forms match based on signon_reaml, scheme, and | 147 // Returns true if the two given forms match based on signon_reaml, scheme, and |
| 148 // username_value, and are thus suitable for merging (see MergePasswordForms). | 148 // username_value, and are thus suitable for merging (see MergePasswordForms). |
| 149 bool FormsMatchForMerge(const webkit::forms::PasswordForm& form_a, | 149 bool FormsMatchForMerge(const content::PasswordForm& form_a, |
| 150 const webkit::forms::PasswordForm& form_b); | 150 const content::PasswordForm& form_b); |
| 151 | 151 |
| 152 // Populates merged_forms by combining the password data from keychain_forms and | 152 // Populates merged_forms by combining the password data from keychain_forms and |
| 153 // the metadata from database_forms, removing used entries from the two source | 153 // the metadata from database_forms, removing used entries from the two source |
| 154 // lists. | 154 // lists. |
| 155 // | 155 // |
| 156 // On return, database_forms and keychain_forms will have only unused | 156 // On return, database_forms and keychain_forms will have only unused |
| 157 // entries; for database_forms that means entries for which no corresponding | 157 // entries; for database_forms that means entries for which no corresponding |
| 158 // password can be found (and which aren't blacklist entries), and for | 158 // password can be found (and which aren't blacklist entries), and for |
| 159 // keychain_forms its entries that weren't merged into at least one database | 159 // keychain_forms its entries that weren't merged into at least one database |
| 160 // form. | 160 // form. |
| 161 void MergePasswordForms( | 161 void MergePasswordForms( |
| 162 std::vector<webkit::forms::PasswordForm*>* keychain_forms, | 162 std::vector<content::PasswordForm*>* keychain_forms, |
| 163 std::vector<webkit::forms::PasswordForm*>* database_forms, | 163 std::vector<content::PasswordForm*>* database_forms, |
| 164 std::vector<webkit::forms::PasswordForm*>* merged_forms); | 164 std::vector<content::PasswordForm*>* merged_forms); |
| 165 | 165 |
| 166 // Fills in the passwords for as many of the forms in |database_forms| as | 166 // Fills in the passwords for as many of the forms in |database_forms| as |
| 167 // possible using entries from |keychain| and returns them. On return, | 167 // possible using entries from |keychain| and returns them. On return, |
| 168 // |database_forms| will contain only the forms for which no password was found. | 168 // |database_forms| will contain only the forms for which no password was found. |
| 169 std::vector<webkit::forms::PasswordForm*> GetPasswordsForForms( | 169 std::vector<content::PasswordForm*> GetPasswordsForForms( |
| 170 const AppleKeychain& keychain, | 170 const AppleKeychain& keychain, |
| 171 std::vector<webkit::forms::PasswordForm*>* database_forms); | 171 std::vector<content::PasswordForm*>* database_forms); |
| 172 | 172 |
| 173 } // internal_keychain_helpers | 173 } // internal_keychain_helpers |
| 174 | 174 |
| 175 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ | 175 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ |
| OLD | NEW |