Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: chrome/browser/password_manager/password_store_mac_internal.h

Issue 149160: Add an exact search method to the Keychain adapter, and modify unit tests to ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "chrome/browser/keychain_mac.h" 14 #include "chrome/browser/keychain_mac.h"
15 15
16 // Adapter that wraps a MacKeychain and provides interaction in terms of 16 // Adapter that wraps a MacKeychain and provides interaction in terms of
17 // PasswordForms instead of Keychain items. 17 // PasswordForms instead of Keychain items.
18 class MacKeychainPasswordFormAdapter { 18 class MacKeychainPasswordFormAdapter {
19 public: 19 public:
20 // Creates an adapter for |keychain|. This class does not take ownership of 20 // Creates an adapter for |keychain|. This class does not take ownership of
21 // |keychain|, so the caller must make sure that the keychain outlives the 21 // |keychain|, so the caller must make sure that the keychain outlives the
22 // created object. 22 // created object.
23 explicit MacKeychainPasswordFormAdapter(MacKeychain* keychain); 23 explicit MacKeychainPasswordFormAdapter(MacKeychain* keychain);
24 24
25 // Returns PasswordForms for each keychain entry matching |form|. 25 // Returns PasswordForms for each keychain entry that could be used to fill
26 // Caller is responsible for deleting the returned forms. 26 // |form|. Caller is responsible for deleting the returned forms.
27 std::vector<webkit_glue::PasswordForm*> PasswordsMatchingForm( 27 std::vector<webkit_glue::PasswordForm*> PasswordsMatchingForm(
28 const webkit_glue::PasswordForm& query_form); 28 const webkit_glue::PasswordForm& query_form);
29 29
30 // Returns the PasswordForm for the Keychain entry that matches |form| on all
31 // of the fields that uniquely identify a Keychain item, or NULL if there is
32 // no such entry.
33 // Caller is responsible for deleting the returned form.
34 webkit_glue::PasswordForm* PasswordExactlyMatchingForm(
35 const webkit_glue::PasswordForm& query_form);
36
30 // Creates a new keychain entry from |form|, or updates the password of an 37 // Creates a new keychain entry from |form|, or updates the password of an
31 // existing keychain entry if there is a collision. Returns true if a keychain 38 // existing keychain entry if there is a collision. Returns true if a keychain
32 // entry was successfully added/updated. 39 // entry was successfully added/updated.
33 bool AddLogin(const webkit_glue::PasswordForm& form); 40 bool AddLogin(const webkit_glue::PasswordForm& form);
34 41
35 private: 42 private:
36 // Returns PasswordForms constructed from the given Keychain items. 43 // Returns PasswordForms constructed from the given Keychain items.
37 // Caller is responsible for deleting the returned forms. 44 // Caller is responsible for deleting the returned forms.
38 std::vector<webkit_glue::PasswordForm*> CreateFormsFromKeychainItems( 45 std::vector<webkit_glue::PasswordForm*> CreateFormsFromKeychainItems(
39 const std::vector<SecKeychainItemRef>& items); 46 const std::vector<SecKeychainItemRef>& items);
40 47
41 // Searches |keychain| for all items usable for the given signon_realm, and 48 // Searches |keychain| for all items usable for the given form, and returns
42 // puts them in |items|. The caller is responsible for calling keychain->Free 49 // them. The caller is responsible for calling MacKeychain::Free on the
43 // on each of them when it is finished with them. 50 // returned items.
51 std::vector<SecKeychainItemRef> KeychainItemsForFillingForm(
52 const webkit_glue::PasswordForm& form);
53
54 // Searches |keychain| for the specific keychain entry that corresponds to the
55 // given form, and returns it (or NULL if no match is found). The caller is
56 // responsible for calling MacKeychain::Free on on the returned item.
57 SecKeychainItemRef KeychainItemForForm(
58 const webkit_glue::PasswordForm& form);
59
60 // Returns the Keychain items matching the given signon_realm, scheme, and
61 // optionally path and username (either of both can be NULL).
62 // them. The caller is responsible for calling MacKeychain::Free on the
63 // returned items.
44 std::vector<SecKeychainItemRef> MatchingKeychainItems( 64 std::vector<SecKeychainItemRef> MatchingKeychainItems(
45 const std::string& signon_realm, 65 const std::string& signon_realm, webkit_glue::PasswordForm::Scheme scheme,
66 const char* path, const char* username);
67
68 // Takes a PasswordForm's signon_realm and parses it into its component parts,
69 // which are returned though the appropriate out parameters.
70 // Returns true if it can be successfully parsed, in which case all out params
71 // that are non-NULL will be set. If there is no port, port will be 0.
72 // If the return value is false, the state of the out params is undefined.
73 bool ExtractSignonRealmComponents(const std::string& signon_realm,
74 std::string* server, int* port,
75 bool* is_secure,
76 std::string* security_domain);
77
78 // Returns the Keychain SecAuthenticationType type corresponding to |scheme|.
79 SecAuthenticationType AuthTypeForScheme(
46 webkit_glue::PasswordForm::Scheme scheme); 80 webkit_glue::PasswordForm::Scheme scheme);
47 81
48 // Changes the password for keychain_item to |password|; returns true if the 82 // Changes the password for keychain_item to |password|; returns true if the
49 // password was successfully changed. 83 // password was successfully changed.
50 bool SetKeychainItemPassword(const SecKeychainItemRef& keychain_item, 84 bool SetKeychainItemPassword(const SecKeychainItemRef& keychain_item,
51 const std::string& password); 85 const std::string& password);
52 86
53 // Sets the creator code of keychain_item to creator_code; returns true if the 87 // Sets the creator code of keychain_item to creator_code; returns true if the
54 // creator code was successfully set. 88 // creator code was successfully set.
55 bool SetKeychainItemCreatorCode(const SecKeychainItemRef& keychain_item, 89 bool SetKeychainItemCreatorCode(const SecKeychainItemRef& keychain_item,
56 OSType creator_code); 90 OSType creator_code);
57 91
58 MacKeychain* keychain_; 92 MacKeychain* keychain_;
59 93
60 DISALLOW_COPY_AND_ASSIGN(MacKeychainPasswordFormAdapter); 94 DISALLOW_COPY_AND_ASSIGN(MacKeychainPasswordFormAdapter);
61 }; 95 };
62 96
63 namespace internal_keychain_helpers { 97 namespace internal_keychain_helpers {
64 98
65 // Searches |keychain| for the specific keychain entry matching the given form,
66 // and returns it (or NULL if no match is found).
67 // The caller is responsible for calling keychain->Free on the returned item.
68 SecKeychainItemRef MatchingKeychainItem(const MacKeychain& keychain,
69 const webkit_glue::PasswordForm& form);
70
71 // Sets the fields of |form| based on the keychain data from |keychain_item|. 99 // Sets the fields of |form| based on the keychain data from |keychain_item|.
72 // Fields that can't be determined from |keychain_item| will be unchanged. 100 // Fields that can't be determined from |keychain_item| will be unchanged.
73 // 101 //
74 // IMPORTANT: This function can cause the OS to trigger UI (to allow access to 102 // IMPORTANT: This function can cause the OS to trigger UI (to allow access to
75 // the keychain item if we aren't trusted for the item), and block until the UI 103 // the keychain item if we aren't trusted for the item), and block until the UI
76 // is dismissed. 104 // is dismissed.
77 // 105 //
78 // If excessive prompting for access to other applications' keychain items 106 // If excessive prompting for access to other applications' keychain items
79 // becomes an issue, the password storage API will need to be refactored to 107 // becomes an issue, the password storage API will need to be refactored to
80 // allow the password to be retrieved later (accessing other fields doesn't 108 // allow the password to be retrieved later (accessing other fields doesn't
(...skipping 21 matching lines...) Expand all
102 // blacklist entries from other browsers). Keychain entries that we have no 130 // blacklist entries from other browsers). Keychain entries that we have no
103 // database matches for will still end up in merged_forms, since they have 131 // database matches for will still end up in merged_forms, since they have
104 // enough information to be used as imported passwords. 132 // enough information to be used as imported passwords.
105 void MergePasswordForms(std::vector<webkit_glue::PasswordForm*>* keychain_forms, 133 void MergePasswordForms(std::vector<webkit_glue::PasswordForm*>* keychain_forms,
106 std::vector<webkit_glue::PasswordForm*>* database_forms, 134 std::vector<webkit_glue::PasswordForm*>* database_forms,
107 std::vector<webkit_glue::PasswordForm*>* merged_forms); 135 std::vector<webkit_glue::PasswordForm*>* merged_forms);
108 136
109 } // internal_keychain_helpers 137 } // internal_keychain_helpers
110 138
111 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_ 139 #endif // CHROME_BROWSER_PASSWORD_MANAGER_PASSWORD_STORE_MAC_INTERNAL_H_
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_mac.cc ('k') | chrome/browser/password_manager/password_store_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698