#ifdef __MWERKS__
#define _CPP_KEYCHAINACL
#endif
#include "keychainacl.h"
#include <Security/cssmwalkers.h>
using namespace CssmClient;
KeychainAclFactory::KeychainAclFactory(CssmAllocator &alloc)
: allocator(alloc), nullCred(alloc, 1), kcCred(alloc, 2), kcUnlockCred(alloc, 1)
{
nullCred.sample(0) = TypedList(alloc, CSSM_SAMPLE_TYPE_THRESHOLD);
kcCred.sample(0) = TypedList(alloc, CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT);
kcCred.sample(1) = TypedList(alloc, CSSM_SAMPLE_TYPE_THRESHOLD,
new(alloc) ListElement(TypedList(alloc, CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT)));
kcUnlockCred.sample(0) = TypedList(alloc, CSSM_SAMPLE_TYPE_KEYCHAIN_LOCK,
new(alloc) ListElement(CSSM_SAMPLE_TYPE_KEYCHAIN_PROMPT));
}
KeychainAclFactory::~KeychainAclFactory()
{
}
const AccessCredentials *KeychainAclFactory::nullCredentials()
{
return &nullCred;
}
const AccessCredentials *KeychainAclFactory::keychainPromptCredentials()
{
return &kcCred;
}
const AccessCredentials *KeychainAclFactory::keychainPromptUnlockCredentials()
{
return &kcUnlockCred;
}
const AutoCredentials *KeychainAclFactory::passwordChangeCredentials(const CssmData &password)
{
AutoCredentials *cred = new AutoCredentials(allocator, 1);
cred->sample(0) = TypedList(allocator, CSSM_SAMPLE_TYPE_KEYCHAIN_CHANGE_LOCK,
new(allocator) ListElement(CSSM_SAMPLE_TYPE_PASSWORD),
new(allocator) ListElement(password));
return cred;
}
const AutoCredentials *KeychainAclFactory::passwordUnlockCredentials(const CssmData &password)
{
AutoCredentials *cred = new AutoCredentials(allocator, 1);
cred->sample(0) = TypedList(allocator, CSSM_SAMPLE_TYPE_KEYCHAIN_LOCK,
new(allocator) ListElement(CSSM_SAMPLE_TYPE_PASSWORD),
new(allocator) ListElement(password));
return cred;
}
AclEntryInput *KeychainAclFactory::keychainPromptOwner(const CssmData &description)
{
AclEntryPrototype proto(TypedList(allocator, CSSM_ACL_SUBJECT_TYPE_KEYCHAIN_PROMPT,
new(allocator) ListElement(allocator, description)));
return new(allocator) AclEntryInput(proto);
}
AclEntryInput *KeychainAclFactory::anyOwner()
{
AclEntryPrototype proto(TypedList(allocator, CSSM_ACL_SUBJECT_TYPE_ANY));
return new(allocator) AclEntryInput(proto);
}
void KeychainAclFactory::release(AclEntryInput *input)
{
DataWalkers::chunkFree(input, allocator);
}
void KeychainAclFactory::comment(TypedList &subject)
{
subject.insert(new(allocator) ListElement(CSSM_ACL_SUBJECT_TYPE_COMMENT),
subject.first());
}
void KeychainAclFactory::uncomment(TypedList &subject)
{
ListElement *first = subject.first();
assert(*first == CSSM_ACL_SUBJECT_TYPE_COMMENT);
subject -= first;
destroy(first, allocator);
}