]> git.saurik.com Git - apple/security.git/blob - Keychain/StorageManager.h
Security-54.1.tar.gz
[apple/security.git] / Keychain / StorageManager.h
1 /*
2 * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 //
20 // StorageManager.h -- Working with multiple keychains
21 //
22 #ifndef _SECURITY_STORAGEMANAGER_H_
23 #define _SECURITY_STORAGEMANAGER_H_
24
25 #include <list>
26 #include <Security/multidldb.h>
27 #include <Security/DLDBListCFPref.h>
28 #include <Security/Keychains.h>
29
30 namespace Security
31 {
32
33 namespace KeychainCore
34 {
35
36 class StorageManager
37 {
38 NOCOPY(StorageManager)
39 public:
40 typedef vector<Keychain> KeychainList;
41
42 StorageManager();
43 ~StorageManager() {}
44
45 //bool onlist(const Keychain & keychain);
46
47 // These will call addAndNotify() if the specified keychain already exists
48 Keychain make(const char *fullPathName);
49 void created(const Keychain &keychain); // Be notified a Keychain just got created.
50
51 // Misc
52 void lockAll();
53
54 void add(const Keychain& keychainToAdd); // Only add if not there yet. Doesn't write out CFPref
55
56 // Vector-like methods.
57 size_t size();
58 Keychain at(unsigned int ix);
59 Keychain operator[](unsigned int ix);
60
61 KCCursor createCursor(const SecKeychainAttributeList *attrList);
62 KCCursor createCursor(SecItemClass itemClass, const SecKeychainAttributeList *attrList);
63
64 // Create KC if it doesn't exist, add to cache, but don't modify search list.
65 Keychain keychain(const DLDbIdentifier &dLDbIdentifier);
66
67 // Same as keychain(const DLDbIdentifier &) but assumes mLock is already held.
68 Keychain _keychain(const DLDbIdentifier &dLDbIdentifier);
69
70 // Create KC if it doesn't exist, add it to the search list if it exists and is not already on it.
71 Keychain makeKeychain(const DLDbIdentifier &dLDbIdentifier);
72
73
74 // Keychain list maintenance
75
76 // remove kcsToRemove from the search list
77 void remove(const KeychainList &kcsToRemove, bool deleteDb = false);
78
79 void getSearchList(KeychainList &keychainList);
80 void setSearchList(const KeychainList &keychainList);
81
82 // Iff keychainOrArray is NULL return the default KeychainList in keychainList otherwise
83 // if keychainOrArray is a CFArrayRef containing SecKeychainRef's convernt it to KeychainList,
84 // if keychainOrArray is a SecKeychainRef return a KeychainList with one element.
85 void optionalSearchList(CFTypeRef keychainOrArray, KeychainList &keychainList);
86
87 // Convert CFArrayRef of SecKeychainRef's a KeychainList. The array must not be NULL
88 static void convertToKeychainList(CFArrayRef keychainArray, KeychainList &keychainList);
89
90 // Convert KeychainList to a CFArrayRef of SecKeychainRef's.
91 static CFArrayRef convertFromKeychainList(const KeychainList &keychainList);
92
93 // Login keychain support
94 void login(ConstStringPtr name, ConstStringPtr password);
95 void login(UInt32 nameLength, const void *name, UInt32 passwordLength, const void *password);
96 void logout();
97 void changeLoginPassword(ConstStringPtr oldPassword, ConstStringPtr newPassword);
98 void changeLoginPassword(UInt32 oldPasswordLength, const void *oldPassword, UInt32 newPasswordLength, const void *newPassword);
99
100 // Reload mSearchList from mList if the searchList on disk has changed.
101 void reload(bool force = false);
102
103 private:
104 typedef map<DLDbIdentifier, Keychain> KeychainMap;
105 typedef set<KeychainSchema> KeychainSchemaSet;
106
107 // Reload mSearchList from mList and add new keychains to mKeychains if not already there
108 // Assumes mLock is already locked.
109 void _doReload();
110
111 // Reload mSearchList from mList if the searchList on disk has changed.
112 // Assumes mLock is already locked.
113 void _reload(bool force = false);
114
115 // Only add if not there yet. Writes out CFPref and broadcasts KCPrefListChanged notification
116 void addAndNotify(const Keychain& keychainToAdd);
117 KeychainSchema keychainSchemaFor(const CssmClient::Db &db);
118
119 DLDbListCFPref mSavedList;
120 KeychainMap mKeychains; // the cache of Keychains
121 KeychainList mSearchList;
122 KeychainSchemaSet mKeychainSchemaSet;
123 Mutex mLock;
124 };
125
126 } // end namespace KeychainCore
127
128 } // end namespace Security
129
130 #endif // !_SECURITY_STORAGEMANAGER_H_