Macintosh Key Chain Manager
Engineering Specifications
Last Modified: 1/16/1997
Version: 1.0Contact: Vinne Moscaritolo, vinnie@vmeng.com
Introduction to the KeyChain Manager
some text here.....
some text here.....
This section discuses the data types and routines provided by the Key Chain Manager. It describes the general purpose data types Key Chain Manager defines and all the routine that relate to manipulating the Key Chain, Key Chain services, etc.
The KeyChain Manager uses the following constants:#define kKCInvalidKeyChainRef ((KeyChainRef)0)
This section discuses the general-purpose data types defined for the Key Chain Manager.Key Chain Manager uses the
KeyChainRefto refer to a Key Chain. This reference is only meaningful to the Key Chain Managertypedef void* KeyChainRef;
The following is a simple example of how the Key Chain Manager might be used.KeyChainRef kcRef; OSErr status; status = KCOpenSystemKeyChain(&kcRef); status = KCUnLockKeyChain(kcRef, nil); status = KCAddKey(kcRef,locator,data,metaData);
This section discuses the Key Chain Manager function for manipulatingthe Key Chain. UseKCGetSystemKeyChainRefto obtain the default Key Chain reference. UseKCGetKeyChainRefto open and get a reference for another Key Chain file. UseKCLockKeyChainandKCUnlockKeyChainto change the lock state of the Key Chain. UseKCGetKeyChainLockStatusto get the determine the lock state of the Key Chain. UseKCChangeKeyChainPasswordto change the Key Chain Password.
The KCGetKeyChainRef function opens a specified keychain file. Your application identifies the keychain file with a file system specification.
pascal OSErr KCGetKeyChainRef(const FSSpec *keychainFile, KeyChainRef* kcRef);
keychainFileContains a pointer to the file system specification for the Key Chain file to be opened.
kcRefContains a pointer to a field that is to receive the keychain reference number for the opened keychain file. Your application must use this value when calling other Key Chain Manager function that work with keychain files.
Your application must open a keychain file before reading or writing any data from it. You can open a keychain file more than once.
noErr 0 No Error paramErr -50 Parameter Error (unexpected nil pointer; out of range value)
The KCGetSystemKeyChainRef function opens the current system keychain file.
pascal OSErr KCGetSystemKeyChainRef(KeyChainRef* kcRef);
kcRefContains a pointer to a field that is to receive the keychain reference number for the opened keychain file. Your application must use this value when calling other Key Chain Manager function that work with keychain files.
xxxx xxxx xxxxxxx xxxxxxx xxxxxxx xxxx xxxxxxx x x x xxxxxxxxxxxx x x xxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxx x x x xxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxx.
noErr 0 No Error paramErr -50 Parameter Error (unexpected nil pointer; out of range value)
The KCSetSystemKeyChain function.......Key Chain specified by the Key Chain reference.
pascal OSErr KCSetSystemKeyChain(KeyChainRef kcRef);
kcRefSpecifies the Key Chain for this operation. Your application obtains this keychain reference from such functions as KCOpenSystemKeyChainandKCOpenKeyChain.
xxxx xxxx xxxxxxx xxxxxxx xxxxxxx xxxx xxxxxxx x x x xxxxxxxxxxxx x x xxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxx x x x xxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxx.
noErr 0 No Error paramErr -50 Parameter Error (unexpected nil pointer; out of range value) kKCRefInvalidErr -1581 Key Chain reference invalid
The KCDisposeKeyChainRef function.......Key Chain specified by the Key Chain reference.
pascal OSErr KCDisposeKeyChainRef(KeyChainRef kcRef);
kcRefSpecifies the Key Chain for this operation. Your application obtains this keychain reference from such functions as KCOpenSystemKeyChainandKCOpenKeyChain.
xxxx xxxx xxxxxxx xxxxxxx xxxxxxx xxxx xxxxxxx x x x xxxxxxxxxxxx x x xxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxx x x x xxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxx.
noErr 0 No Error paramErr -50 Parameter Error (unexpected nil pointer; out of range value) kKCRefInvalidErr -1581 Key Chain reference invalid
The KCLockKeyChain function unlocks the Key Chain specified by the Key Chain reference.
pascal OSErr KCUnlockKeyChain(KeyChainRef kcRef, ConstTextObject password);
kcRefSpecifies the Key Chain for this operation. Your application obtains this keychain reference from such functions as KCOpenSystemKeyChainandKCOpenKeyChain.
passwordPassword with with to unlock the Key Chain.
xxxx xxxx xxxxxxx xxxxxxx xxxxxxx xxxx xxxxxxx x x x xxxxxxxxxxxx x x xxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxx x x x xxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxx.
If the Key Chain specified was already unlocked,KCLockKeyChainreturns ankKCAlreadyUnlockedErrerror. This is because if a user attemost to unlock the Key Chain with a bad password, it is unclear whether the Key Chain should remain unlocked or should become locked.
noErr 0 No Error paramErr -50 Parameter Error (unexpected nil pointer; out of range value) kKCPasswordBadErr -1580 Password invalid kKCRefInvalidErr -1581 Key Chain reference invalid kKCAlreadyUnlockedErr -1595 Key Chain is already unlocked
The KCLockKeyChain function locks the Key Chain specified by the Key Chain reference.
pascal OSErr KCLockKeyChain(KeyChainRef kcRef);
kcRefSpecifies the Key Chain for this operation. Your application obtains this keychain reference from such functions as KCOpenSystemKeyChainandKCOpenKeyChain.
xxxx xxxx xxxxxxx xxxxxxx xxxxxxx xxxx xxxxxxx x x x xxxxxxxxxxxx x x xxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxx x x x xxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxx.
noErr 0 No Error paramErr -50 Parameter Error (unexpected nil pointer; out of range value) kKCRefInvalidErr -1581 Key Chain reference invalid
The KCGetKeyChainLockStatus function allows you to query the lock status of the Key Chain specified by the Key Chain reference.
pascal OSErr KCGetKeyChainLockStatus(KeyChainRef kcRef, KeyChainLockStatus* status);
kcRefSpecifies the Key Chain for this operation. Your application obtains this keychain reference from such functions as KCOpenSystemKeyChainandKCOpenKeyChain.
statusContains a pointer to a field that is to receive the Key Chain lock status. The status parameter can have any of the following values:
kKCLocked- The Key Chain is locked.
kKCUnlocked- The Key Chain is not locked.
xxxx xxxx xxxxxxx xxxxxxx xxxxxxx xxxx xxxxxxx x x x xxxxxxxxxxxx x x xxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxx x x x xxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxx.
noErr 0 No Error paramErr -50 Parameter Error (unexpected nil pointer; out of range value) kKCRefInvalidErr -1581 Key Chain reference invalid
TheKCChangeKeyChainPasswordfunction changes the Key Chain password to the value in specified innewPassword. This function checks the value ofoldPasswordand fails if you do not provide the current Key Chain password.
pascal OSErr KCChangeKeyChainPassword(KeyChainRef kcRef, ConstTextObject oldPassword, ConstTextObject newPassword));
kcRefSpecifies the Key Chain for this operation. Your application obtains this keychain reference from such functions as KCOpenSystemKeyChainandKCOpenKeyChain.
passwordPassword with with to unlock the Key Chain.
xxxx xxxx xxxxxxx xxxxxxx xxxxxxx xxxx xxxxxxx x x x xxxxxxxxxxxx x x xxxxxxxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxx x x x xxxxxxxxxxxx xxxxxxx x x x xxxxxxxxxxxxxxx.
noErr 0 No Error paramErr -50 Parameter Error (unexpected nil pointer; out of range value) kKCPasswordBadErr -1580 Password invalid kKCRefInvalidErr -1581 Key Chain reference invalid kKCLockedErr -1583 Password can not be changed when Key Chain is Locked
Constants
#define kKCInvalidKeyChainRef ((KeyChainRef)0) /* Invalid Key Chain Reference */
enum {
kKCLocked = 0, // Key Chain is locked
kKCUnlocked = 1 // Key Chain is not locked
}; // KeyChainLockStatus
enum {
kKCLockHard = 0, // Service is only accessable when KeyChain is unlocked
kKCLockNever = 1 // Service is accessable independant of lock state
}; // KeyChainLockOptions
Data Typestypedef struct OpaqueKeyChainRef* KeyChainRef; typedef UInt32 KeyChainLockStatus; typedef UInt32 KeyChainLockOptions;Key Chain Management Routines
pascal OSErr KCGetKeyChainRef (const FSSpec* keychainFile, KeyChainRef* kcRef, Boolean createKeyChain); pascal OSErr KCGetSystemKeyChainRef (KeyChainRef* kcRef); pascal OSErr KCSetSystemKeyChain (KeyChainRef kcRef); pascal OSErr KCDisposeKeyChainRef (KeyChainRef kcRef); pascal OSErr KCLockKeyChain (KeyChainRef kcRef); pascal OSErr KCUnLockKeyChain (KeyChainRef kcRef, ConstTextObject password); pascal OSErr KCGetKeyChainLockStatus (KeyChainRef kcRef, KeyChainLockStatus* status); pascal OSErr KCChangeKeyChainPassword (KeyChainRef* kcRef, ConstTextObject oldPassword, ConstTextObject newPassword);
pascal OSErr KCAddKeyChainService (KeyChainRef kcRef, ConstTextObject serviceName, KeyChainLockOptions lockOpts, KCServiceRef* sRef); pascal OSErr KCGetKeyChainService (KeyChainRef kcRef, ConstTextObject serviceName, KCServiceRef* sRef); pascal OSErr KCDeleteKeyChainService (KeyChainRef kcRef, KCServiceRef sRef); pascal OSErr KCGetKeyChainServiceIterator (KeyChainRef kcRef, metaData, kcIterator* itx); pascal OSErr KCIterate (kcIterator* itx, Locator *Locator); pascal OSErr KCDisposeIterator (kcIterator* itx);
pascal OSErr KCGetIterator (KeyChainRef kcRef, metaData, kcIterator* itx); pascal OSErr KCIterate (kcIterator* itx, Locator *Locator); pascal OSErr KCDisposeIterator (kcIterator* itx);Result Codes
noErr 0 No Error paramErr -50 Parameter Error (unexpected nil pointer; out of range value) kKCPasswordBadErr -1580 Password invalid kKCRefInvalidErr -1581 Key Chain reference invalid kKCNoKeyChainErr -1582 Cannot create Key Chain kKCLockedErr -1583 Key Chain Locked kKCAlreadyUnlockedErr -1595 Key Chain is already unlocked