Db
MultiDLDbImpl::database(const DLDbIdentifier &dlDbIdentifier)
{
	StLock<Mutex> _(mLock);
	DbMap::const_iterator it = mDbMap.find(dlDbIdentifier);
	if (it != mDbMap.end())
		return it->second;

	Module module(dlDbIdentifier.ssuid().guid(), cssm());
	DL dl;
	if (dlDbIdentifier.ssuid().subserviceType() & CSSM_SERVICE_CSP)
	{
		if (mUseSecureStorage)
			dl = SSCSPDL(module);
		else
			dl = CSPDL(module);
	}
	else
		dl = DL(module);

	dl->subserviceId(dlDbIdentifier.ssuid().subserviceId());
	dl->version(dlDbIdentifier.ssuid().version());
	Db db(dl, dlDbIdentifier.dbName());
	if (find(mListRef->begin(), mListRef->end(), dlDbIdentifier) != mListRef->end())
		mDbMap.insert(DbMap::value_type(dlDbIdentifier, db));

	return db;
}
Item ItemImpl::makeFromPersistentReference(const CFDataRef persistentRef, bool *isIdentityRef)
{
	CssmData dictData((void*)::CFDataGetBytePtr(persistentRef), ::CFDataGetLength(persistentRef));
	NameValueDictionary dict(dictData);

	Keychain keychain;
	Item item = (ItemImpl *) NULL;

	if (isIdentityRef) {
		*isIdentityRef = (dict.FindByName(IDENTITY_KEY) != 0) ? true : false;
	}

	// make sure we have a database identifier
	if (dict.FindByName(SSUID_KEY) != 0)
	{
		DLDbIdentifier dlDbIdentifier = NameValueDictionary::MakeDLDbIdentifierFromNameValueDictionary(dict);
		DLDbIdentifier newDlDbIdentifier(dlDbIdentifier.ssuid(),
				DLDbListCFPref::ExpandTildesInPath(dlDbIdentifier.dbName()).c_str(),
				dlDbIdentifier.dbLocation());

		keychain = globals().storageManager.keychain(newDlDbIdentifier);

		const NameValuePair* aDictItem = dict.FindByName(ITEM_KEY);
		if (aDictItem && keychain)
		{
			PrimaryKey primaryKey(aDictItem->Value());
			item = keychain->item(primaryKey);
		}
	}
	KCThrowIf_( !item, errSecItemNotFound );
	return item;
}
void ItemImpl::copyPersistentReference(CFDataRef &outDataRef, bool isSecIdentityRef)
{
	if (secd_PersistentRef) {
		outDataRef = secd_PersistentRef;
		return;
	}
	StLock<Mutex>_(mMutex);
    // item must be in a keychain and have a primary key to be persistent
    if (!mKeychain || !mPrimaryKey) {
        MacOSError::throwMe(errSecItemNotFound);
    }
    DLDbIdentifier dlDbIdentifier = mKeychain->dlDbIdentifier();
    DLDbIdentifier newDlDbIdentifier(dlDbIdentifier.ssuid(),
        DLDbListCFPref::AbbreviatedPath(mKeychain->name()).c_str(),
        dlDbIdentifier.dbLocation());
    NameValueDictionary dict;
    NameValueDictionary::MakeNameValueDictionaryFromDLDbIdentifier(newDlDbIdentifier, dict);

    CssmData* pKey = mPrimaryKey;
    dict.Insert (new NameValuePair(ITEM_KEY, *pKey));

	if (isSecIdentityRef) {
		uint32_t value = -1;
		CssmData valueData((void*)&value, sizeof(value));
		dict.Insert (new NameValuePair(IDENTITY_KEY, valueData));
	}

    // flatten the NameValueDictionary
    CssmData dictData;
    dict.Export(dictData);
    outDataRef = ::CFDataCreate(kCFAllocatorDefault, dictData.Data, dictData.Length);
    free (dictData.Data);
}
Exemple #4
0
DefaultCredentials::KeychainList DefaultCredentials::fallbackSearchList(const DLDbIdentifier &ident)
{
    KeychainList list;
    globals().storageManager.getSearchList(list);
    list.erase(remove_if(list.begin(), list.end(), NotGuid(ident.ssuid().guid())), list.end());
    return list;
}
/* Assume mLock is locked already.  Remove a single database from the
   searchlist.  */
bool
DynamicDLDBList::_remove(const DLDbIdentifier &dlDbIdentifier)
{
	StLock<Mutex>_(mMutex);
	
	// search for subserviceUid but ignore the dbName, which is dynamic
	for (SearchList::iterator it = mSearchList.begin(); it != mSearchList.end(); it++)
		if (it->ssuid() == dlDbIdentifier.ssuid())
		{
			mSearchList.erase(it);

			// Remove from the storageManager cache if it was there.
			globals().storageManager.didRemoveKeychain(dlDbIdentifier);
			return true;
		}
	// not found
	return false;
}