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