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<content::PasswordForm*> PasswordsFillingForm( |
29 const content::PasswordForm& query_form); | 29 const content::PasswordForm& query_form, |
| 30 PasswordStore::AuthorizationPromptPermission |
| 31 authorization_prompt_permission); |
30 | 32 |
31 // Returns PasswordForms for each keychain entry that could be merged with | 33 // Returns PasswordForms for each keychain entry that could be merged with |
32 // |form|. Differs from PasswordsFillingForm in that the username must match. | 34 // |form|. Differs from PasswordsFillingForm in that the username must match. |
33 // Caller is responsible for deleting the returned forms. | 35 // Caller is responsible for deleting the returned forms. |
34 std::vector<content::PasswordForm*> PasswordsMergeableWithForm( | 36 std::vector<content::PasswordForm*> PasswordsMergeableWithForm( |
35 const content::PasswordForm& query_form); | 37 const content::PasswordForm& query_form); |
36 | 38 |
37 // Returns the PasswordForm for the Keychain entry that matches |form| on all | 39 // 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 | 40 // of the fields that uniquely identify a Keychain item, or NULL if there is |
39 // no such entry. | 41 // no such entry. |
40 // Caller is responsible for deleting the returned form. | 42 // Caller is responsible for deleting the returned form. |
41 content::PasswordForm* PasswordExactlyMatchingForm( | 43 content::PasswordForm* PasswordExactlyMatchingForm( |
42 const content::PasswordForm& query_form); | 44 const content::PasswordForm& query_form, |
| 45 PasswordStore::AuthorizationPromptPermission |
| 46 authorization_prompt_permission); |
43 | 47 |
44 // Returns true if PasswordsMergeableWithForm would return any items. This is | 48 // Returns true if PasswordsMergeableWithForm would return any items. This is |
45 // a separate method because calling PasswordsMergeableWithForm and checking | 49 // a separate method because calling PasswordsMergeableWithForm and checking |
46 // the return count would require reading the passwords from the keychain, | 50 // the return count would require reading the passwords from the keychain, |
47 // thus potentially triggering authorizaiton UI, whereas this won't. | 51 // thus potentially triggering authorizaiton UI, whereas this won't. |
48 bool HasPasswordsMergeableWithForm( | 52 bool HasPasswordsMergeableWithForm( |
49 const content::PasswordForm& query_form); | 53 const content::PasswordForm& query_form); |
50 | 54 |
51 // Returns all keychain items of types corresponding to password forms. | 55 // Returns all keychain items of types corresponding to password forms. |
52 std::vector<content::PasswordForm*> GetAllPasswordFormPasswords(); | 56 std::vector<content::PasswordForm*> GetAllPasswordFormPasswords(); |
53 | 57 |
54 // Creates a new keychain entry from |form|, or updates the password of an | 58 // 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 | 59 // existing keychain entry if there is a collision. Returns true if a keychain |
56 // entry was successfully added/updated. | 60 // entry was successfully added/updated. |
57 bool AddPassword(const content::PasswordForm& form); | 61 bool AddPassword(const content::PasswordForm& form); |
58 | 62 |
59 // Removes the keychain password matching |form| if any. Returns true if a | 63 // Removes the keychain password matching |form| if any. Returns true if a |
60 // keychain item was found and successfully removed. | 64 // keychain item was found and successfully removed. |
61 bool RemovePassword(const content::PasswordForm& form); | 65 bool RemovePassword(const content::PasswordForm& form); |
62 | 66 |
63 // Controls whether or not Chrome will restrict Keychain searches to items | 67 // Controls whether or not Chrome will restrict Keychain searches to items |
64 // that it created. Defaults to false. | 68 // that it created. Defaults to false. |
65 void SetFindsOnlyOwnedItems(bool finds_only_owned); | 69 void SetFindsOnlyOwnedItems(bool finds_only_owned); |
66 | 70 |
67 private: | 71 private: |
68 // Returns PasswordForms constructed from the given Keychain items, calling | 72 // Returns PasswordForms constructed from the given Keychain items, calling |
69 // AppleKeychain::Free on all of the keychain items and clearing the vector. | 73 // AppleKeychain::Free on all of the keychain items and clearing the vector. |
70 // Caller is responsible for deleting the returned forms. | 74 // Caller is responsible for deleting the returned forms. |
71 std::vector<content::PasswordForm*> ConvertKeychainItemsToForms( | 75 std::vector<content::PasswordForm*> ConvertKeychainItemsToForms( |
72 std::vector<SecKeychainItemRef>* items); | 76 std::vector<SecKeychainItemRef>* items, |
| 77 PasswordStore::AuthorizationPromptPermission |
| 78 authorization_prompt_permission); |
73 | 79 |
74 // Searches |keychain| for the specific keychain entry that corresponds to the | 80 // 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 | 81 // 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. | 82 // responsible for calling AppleKeychain::Free on on the returned item. |
77 SecKeychainItemRef KeychainItemForForm( | 83 SecKeychainItemRef KeychainItemForForm( |
78 const content::PasswordForm& form); | 84 const content::PasswordForm& form); |
79 | 85 |
80 // Returns the Keychain items matching the given signon_realm, scheme, and | 86 // Returns the Keychain items matching the given signon_realm, scheme, and |
81 // optionally path and username (either of both can be NULL). | 87 // optionally path and username (either of both can be NULL). |
82 // The caller is responsible for calling AppleKeychain::Free on the | 88 // The caller is responsible for calling AppleKeychain::Free on the |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 // Fills in the passwords for as many of the forms in |database_forms| as | 171 // 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, | 172 // possible using entries from |keychain| and returns them. On return, |
167 // |database_forms| will contain only the forms for which no password was found. | 173 // |database_forms| will contain only the forms for which no password was found. |
168 std::vector<content::PasswordForm*> GetPasswordsForForms( | 174 std::vector<content::PasswordForm*> GetPasswordsForForms( |
169 const AppleKeychain& keychain, | 175 const AppleKeychain& keychain, |
170 std::vector<content::PasswordForm*>* database_forms); | 176 std::vector<content::PasswordForm*>* database_forms); |
171 | 177 |
172 } // namespace internal_keychain_helpers | 178 } // namespace internal_keychain_helpers |
173 | 179 |
174 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ | 180 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ |
OLD | NEW |