2 * Copyright (c) 2000-2002 Apple Computer, Inc. All Rights Reserved.
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
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.
20 // StorageManager.h -- Working with multiple keychains
22 #ifndef _SECURITY_STORAGEMANAGER_H_
23 #define _SECURITY_STORAGEMANAGER_H_
26 #include <Security/multidldb.h>
27 #include <Security/DLDBListCFPref.h>
28 #include <Security/Keychains.h>
33 namespace KeychainCore
38 NOCOPY(StorageManager
)
40 typedef vector
<Keychain
> KeychainList
;
45 //bool onlist(const Keychain & keychain);
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.
54 void add(const Keychain
& keychainToAdd
); // Only add if not there yet. Doesn't write out CFPref
56 // Vector-like methods.
58 Keychain
at(unsigned int ix
);
59 Keychain
operator[](unsigned int ix
);
61 KCCursor
createCursor(const SecKeychainAttributeList
*attrList
);
62 KCCursor
createCursor(SecItemClass itemClass
, const SecKeychainAttributeList
*attrList
);
64 // Create KC if it doesn't exist, add to cache, but don't modify search list.
65 Keychain
keychain(const DLDbIdentifier
&dLDbIdentifier
);
67 // Same as keychain(const DLDbIdentifier &) but assumes mLock is already held.
68 Keychain
_keychain(const DLDbIdentifier
&dLDbIdentifier
);
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
);
74 // Keychain list maintenance
76 // remove kcsToRemove from the search list
77 void remove(const KeychainList
&kcsToRemove
, bool deleteDb
= false);
79 void getSearchList(KeychainList
&keychainList
);
80 void setSearchList(const KeychainList
&keychainList
);
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
);
87 // Convert CFArrayRef of SecKeychainRef's a KeychainList. The array must not be NULL
88 static void convertToKeychainList(CFArrayRef keychainArray
, KeychainList
&keychainList
);
90 // Convert KeychainList to a CFArrayRef of SecKeychainRef's.
91 static CFArrayRef
convertFromKeychainList(const KeychainList
&keychainList
);
93 // Login keychain support
94 void login(ConstStringPtr name
, ConstStringPtr password
);
95 void login(UInt32 nameLength
, const void *name
, UInt32 passwordLength
, const void *password
);
97 void changeLoginPassword(ConstStringPtr oldPassword
, ConstStringPtr newPassword
);
98 void changeLoginPassword(UInt32 oldPasswordLength
, const void *oldPassword
, UInt32 newPasswordLength
, const void *newPassword
);
100 // Reload mSearchList from mList if the searchList on disk has changed.
101 void reload(bool force
= false);
104 typedef map
<DLDbIdentifier
, Keychain
> KeychainMap
;
105 typedef set
<KeychainSchema
> KeychainSchemaSet
;
107 // Reload mSearchList from mList and add new keychains to mKeychains if not already there
108 // Assumes mLock is already locked.
111 // Reload mSearchList from mList if the searchList on disk has changed.
112 // Assumes mLock is already locked.
113 void _reload(bool force
= false);
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
);
119 DLDbListCFPref mSavedList
;
120 KeychainMap mKeychains
; // the cache of Keychains
121 KeychainList mSearchList
;
122 KeychainSchemaSet mKeychainSchemaSet
;
126 } // end namespace KeychainCore
128 } // end namespace Security
130 #endif // !_SECURITY_STORAGEMANAGER_H_