BioAPI_RETURN BioAPI mdsutil_GetRecordByUuidAndDeviceId(CSSM_DL_DB_HANDLE hDLDB, char* UuidStr, uint32 DeviceId, CSSM_DB_RECORDTYPE RecordType, uint32 NumAttributes, CSSM_HANDLE_PTR ResultsHandle, CSSM_DB_ATTRIBUTE_DATA *OutputAttributeData) { BioAPI_RETURN retValue = CSSM_OK; CSSM_QUERY Query; CSSM_SELECTION_PREDICATE Predicate[2]; memset (&Query, 0, sizeof (CSSM_QUERY)); memset (&Predicate[0], 0, sizeof (CSSM_SELECTION_PREDICATE)); memset (&Predicate[1], 0, sizeof (CSSM_SELECTION_PREDICATE)); Query.RecordType = RecordType; Query.Conjunctive = CSSM_DB_AND; Query.NumSelectionPredicates = 2; Query.SelectionPredicate = Predicate; Query.QueryLimits.TimeLimit = CSSM_QUERY_TIMELIMIT_NONE; Query.QueryLimits.SizeLimit = CSSM_QUERY_SIZELIMIT_NONE; Query.QueryFlags = 0; Predicate[0].DbOperator = CSSM_DB_EQUAL; Predicate[0].Attribute.Info = s_BioApiAttrInfo_ModuleId; Predicate[0].Attribute.Value = (CSSM_DATA *) BioAPI_malloc(sizeof (CSSM_DATA), NULL); if (Predicate[0].Attribute.Value == NULL) return CSSM_ERRCODE_MEMORY_ERROR; Predicate[0].Attribute.NumberOfValues = 1; Predicate[0].Attribute.Value->Data = (unsigned char *)UuidStr; Predicate[0].Attribute.Value->Length = (uint32)strlen (UuidStr) + 1; Predicate[1].DbOperator = CSSM_DB_EQUAL; Predicate[1].Attribute.Info = s_BioApiAttrInfo_DeviceId; Predicate[1].Attribute.Value = (CSSM_DATA *) BioAPI_malloc(sizeof (CSSM_DATA), NULL); if (Predicate[1].Attribute.Value == NULL) { BioAPI_free(Predicate[0].Attribute.Value, NULL); return CSSM_ERRCODE_MEMORY_ERROR; } Predicate[1].Attribute.NumberOfValues = 1; Predicate[1].Attribute.Value->Data = (unsigned char *)&DeviceId; Predicate[1].Attribute.Value->Length = (uint32)sizeof(uint32); retValue = mdsutil_GetRecord(hDLDB, Query, RecordType, NumAttributes, ResultsHandle, OutputAttributeData); BioAPI_free(Predicate[0].Attribute.Value, NULL); BioAPI_free(Predicate[1].Attribute.Value, NULL); return retValue; }
CSSM_RETURN ffutil_CopyData(CSSM_DATA_PTR pDestination, DAL_CONST_DATA_PTR pSource) { VERIFY_PTR(pDestination); VERIFY_PTR(pSource); if (pDestination->Data) { BioAPI_free(pDestination->Data, NULL); pDestination->Data = NULL; } /* Destination->Data is now NULL */ pDestination->Length = pSource->Length; if (!pDestination->Length) return CSSM_OK; pDestination->Data = (uint8*)BioAPI_calloc(pDestination->Length, 1, NULL); if (!pDestination->Data) { pDestination->Length = 0; return CSSMERR_DL_MEMORY_ERROR; } memcpy(pDestination->Data, pSource->Data, pDestination->Length); return CSSM_OK; }
BioAPI_RETURN _biospi_FreeBIRHandle( ADDIN_ATTACH_DATA *pAttachData, BioAPI_BIR_HANDLE BIRHandle ) { BIR_LIST_NODE *pCurListNode = NULL, *pPrevListNode = NULL, *pTempListNode = NULL; if (NULL == (pCurListNode = pPrevListNode = pAttachData->BIRList)) return (BioAPI_ERRCODE_INTERNAL_ERROR); /* Burn through the linked list of BIRs until the correct * header is found or nothing remains in the list */ while (pCurListNode->BIRHandle != BIRHandle && pCurListNode->NextNode != NULL) { pPrevListNode = pCurListNode; pCurListNode = (BIR_LIST_NODE*)pCurListNode->NextNode; } /* if the BIR was successfully found */ if (pCurListNode->BIRHandle == BIRHandle) { pTempListNode = (BIR_LIST_NODE*)pCurListNode->NextNode; /* Free the dynamically allocated biometric data * field of the stored BIR */ BioAPI_free(pCurListNode->BIR.BiometricData, NULL); /* If the BIR to free is the first one in the list */ if (pCurListNode == pPrevListNode) { BioAPI_free(pAttachData->BIRList, NULL); pAttachData->BIRList = pTempListNode; } else { BioAPI_free(pCurListNode, NULL); pPrevListNode->NextNode = pTempListNode; } } else /* TODO: return (BioAPIERR_BSP_INVALID_BIR_HANDLE); */ return (BioAPI_ERRCODE_INTERNAL_ERROR); return BioAPI_OK; }
/*----------------------------------------------------------------------------- * Name: dlbe_DestroyDatabase * * Description: * Will destroy a database that was created by Create/Open Database. * * Parameters: * hDatabase (input) Handle to the database created by Create/Open Db * * Return value: * none. * * Error Codes: * none. *---------------------------------------------------------------------------*/ void dlbe_DestroyDatabase(DATABASE_BACKEND_HANDLE hDatabase) { FF_FUNCTION_BEGIN(dlbe_DestroyDatabase); ASSERT(hDatabase); BioAPI_free((void *)hDatabase, NULL); }
void BioAPI mdsutil_FreeRecord (uint32 NumAttributes, CSSM_DB_ATTRIBUTE_DATA *OutputAttributeData) { uint32 i; for (i = 0; i < NumAttributes; i++) { if (OutputAttributeData[i].Value) { if (OutputAttributeData[i].Value->Data) { BioAPI_free (OutputAttributeData[i].Value->Data, NULL); } BioAPI_free (OutputAttributeData[i].Value, NULL); } } }
/*----------------------------------------------------------------------------- * Name: ffutil_nrFreeData * * Description: * Frees an array of CSSM_DATA structures (w/ DL's mem functions) * * Parameters: * prgData (output) : Pointer to a CSSM_DATA_PTR to hold the beggining address of the array * NumDataStructs (input) : Number of CSSM_DATA structs in the array * * Return value: * None. * * Error Codes: * None. *---------------------------------------------------------------------------*/ void ffutil_nrFreeData(CSSM_DATA_PTR rgData, uint32 NumDataStructs) { if (rgData) { uint32 i; for (i = 0; i < NumDataStructs; i++) { if (rgData[i].Data) { BioAPI_free(rgData[i].Data, NULL); rgData[i].Data = NULL; } } BioAPI_free(rgData, NULL); } else { ASSERT(NumDataStructs == 0); } }
/*--------------------------------------------------------------- * *Name: cssm_FreeDBAttributeInfo * *Description: * Free memory associated with the DB_ATTRIBUTE structure * *Parameters: * Info (input) - pointer to DB_ATTRIBUTE Info * *Returns: * CSSM_FAIL - unable to free * CSSM_OK - free memory * *-------------------------------------------------------------*/ void cssm_FreeDbAttributeInfo(CSSM_DB_ATTRIBUTE_INFO_PTR Info) { if( Info != NULL) { if (Info->AttributeNameFormat == CSSM_DB_ATTRIBUTE_NAME_AS_STRING) { if (Info->Label.AttributeName != NULL) { BioAPI_free(Info->Label.AttributeName, NULL); Info->Label.AttributeName = NULL; } } else if (Info->AttributeNameFormat == CSSM_DB_ATTRIBUTE_NAME_AS_OID) { if (Info->Label.AttributeOID.Data != NULL) { BioAPI_free(Info->Label.AttributeOID.Data, NULL); Info->Label.AttributeOID.Data = NULL; } } } }
CSSM_RETURN freeDbInfoRecord (CSSM_DBINFO_PTR Info, uint32 index) { uint32 j; if (Info->RecordAttributeNames[index].AttributeInfo) { if (port_IsBadReadPtr (Info->RecordAttributeNames[index].AttributeInfo, sizeof (CSSM_DB_ATTRIBUTE_INFO) * Info->RecordAttributeNames[index].NumberOfAttributes)) { return (CSSMERR_CSSM_INVALID_POINTER); } for (j = 0; j < Info->RecordAttributeNames[index].NumberOfAttributes; j++) { cssm_FreeDbAttributeInfo(&Info->RecordAttributeNames[index].AttributeInfo[j]); } BioAPI_free (Info->RecordAttributeNames[index].AttributeInfo, NULL); } if (Info->RecordIndexes[index].IndexInfo) { if (port_IsBadReadPtr (Info->RecordIndexes[index].IndexInfo, sizeof (CSSM_DB_INDEX_INFO) * Info->RecordIndexes[index].NumberOfIndexes)) { return (CSSMERR_CSSM_INVALID_POINTER); } for (j = 0; j < Info->RecordIndexes[index].NumberOfIndexes; j++) { cssm_FreeDbAttributeInfo(&Info->RecordIndexes[index].IndexInfo[j].Info); } BioAPI_free (Info->RecordIndexes[index].IndexInfo, NULL); } return CSSM_OK; }
BioAPI_RETURN BioAPI mdsutil_DeleteRecordByUuid(CSSM_DL_DB_HANDLE hDLDB, const BioAPI_UUID *uuid, CSSM_DB_RECORDTYPE RecordType) { CSSM_QUERY Query; CSSM_SELECTION_PREDICATE Predicate; CSSM_DB_UNIQUE_RECORD_PTR RecordId = NULL; BioAPI_RETURN retValue = CSSM_OK; CSSM_HANDLE ResultsHandle = 0; char UuidStr[BioAPI_PRINTABLE_UUID_LENGTH]; memset (&Query, 0, sizeof (CSSM_QUERY)); memset (&Predicate, 0, sizeof (CSSM_SELECTION_PREDICATE)); Query.RecordType = RecordType; Query.Conjunctive = CSSM_DB_NONE; Query.NumSelectionPredicates = 1; Query.SelectionPredicate = &Predicate; Query.QueryLimits.TimeLimit = CSSM_QUERY_TIMELIMIT_NONE; Query.QueryLimits.SizeLimit = CSSM_QUERY_SIZELIMIT_NONE; Query.QueryFlags = 0; Predicate.DbOperator = CSSM_DB_EQUAL; /* * Convert the Uuid to a string. */ BioAPI_GetPrintableUUID (uuid, UuidStr); Predicate.Attribute.Info = s_BioApiAttrInfo_ModuleId; Predicate.Attribute.Value = (CSSM_DATA *) BioAPI_malloc(sizeof (CSSM_DATA), 0); if (Predicate.Attribute.Value == NULL) return (CSSM_ERRCODE_MEMORY_ERROR); Predicate.Attribute.NumberOfValues = 1; Predicate.Attribute.Value->Data = (unsigned char *)UuidStr; Predicate.Attribute.Value->Length = (uint32)strlen (UuidStr) + 1; if( !IsBadCodePtr((CSSM_PROC_ADDR)MDSFuncs.DataGetFirst)) retValue = MDSFuncs.DataGetFirst(hDLDB, /* DLDBHandle */ &Query, &ResultsHandle, NULL, NULL, &RecordId); while (CSSM_OK == retValue) { if( !IsBadCodePtr((CSSM_PROC_ADDR)MDSFuncs.DataDelete)) retValue = MDSFuncs.DataDelete(hDLDB, RecordId); if( !IsBadCodePtr((CSSM_PROC_ADDR)MDSFuncs.FreeUniqueRecord)) MDSFuncs.FreeUniqueRecord(hDLDB, RecordId); if( !IsBadCodePtr((CSSM_PROC_ADDR)MDSFuncs.DataGetNext)) retValue = MDSFuncs.DataGetNext(hDLDB, /* DLDBHandle */ ResultsHandle, NULL, NULL, &RecordId); } if (CSSMERR_DL_ENDOFDATA == retValue) { retValue = CSSM_OK; } MDSFuncs.DataAbortQuery( hDLDB, ResultsHandle ); BioAPI_free(Predicate.Attribute.Value, NULL); return (retValue); }
BioAPI_RETURN _biospi_Process( ADDIN_ATTACH_DATA *pAttachData, const void *pLoadData, const BioAPI_BIR *pBIRtoProcess, BioAPI_BIR_HANDLE_PTR ProcessedBIR ) { BIR_LIST_NODE *pOldList = NULL, *pHeadNode = NULL; BIO_DATA_HEADER bioDataHeader; uint32 newBioDataLength; uint8 *pNewBioData; /*--------------------------------* * Check for the proper BIR flags * *--------------------------------*/ /*----------------------------------------------------------------------------* * Note about signed BIRs: if this BSP could somehow support signed BIRs, the * * signature would be verified at this point. Note that this means that flag * * can be discarded below to account for the check which could occur at this * * point in the future, if signatures were implemented here. * *----------------------------------------------------------------------------*/ /* Only raw BIRs should be processed. Signed raw data is OK, * so strip that flag off before the check. This is to allow * for the possibility of signed BIRs in the future; see above. */ if (pBIRtoProcess->Header.Type & ~BioAPI_BIR_DATA_TYPE_SIGNED != BioAPI_BIR_DATA_TYPE_RAW) return (BioAPIERR_BSP_INVALID_BIR); /* Only enrollment purpose is supported. Since the Verify * function requires that the BIR captured for verification comes * to it with the password in plaintext, even the * CSSM_HRS_PURPOSE_VERIFY is not supported in this function. * When a BIR is "processed" within the context of this BSP, * it can then be used to "enroll" a BIR for a payload which is * stored in plaintext, instead of encrypted. */ if (BioAPI_PURPOSE_ENROLL_FOR_VERIFICATION_ONLY != pBIRtoProcess->Header.PurposeMask) return (BioAPIERR_BSP_PURPOSE_NOT_SUPPORTED); /* Only BIRs utilizing the proper biometric data format can be used */ if (BIO_DATA_FORMAT_ID != LocalEndian2 (pBIRtoProcess->Header.Format.FormatID) || BIO_DATA_FORMAT_OWNER != LocalEndian2 (pBIRtoProcess->Header.Format.FormatOwner)) return (BioAPIERR_BSP_UNSUPPORTED_FORMAT); /*----------------------* * Create processed BIR * *----------------------*/ /* copy the biometric header */ port_memcpy((void*)&bioDataHeader, (void*)pBIRtoProcess->BiometricData, sizeof(BIO_DATA_HEADER)); /* calc length of biometric data */ newBioDataLength = bioDataHeader.PWLength + bioDataHeader.PayloadLength + sizeof(BIO_DATA_HEADER); /* allocate memory for the "biometric" data */ pNewBioData = BioAPI_malloc(newBioDataLength, NULL); if (NULL == pNewBioData) return (BioAPIERR_BSP_MEMORY_ERROR); /* In this biometric format, the header describing the length * of the password and payload, the cryptographic salts, and the * cryptographic initialization data vector is included in the * opaque biometric data first, followed by the password, then * the payload. We copy the headers and PW data over first */ port_memcpy((void*)pNewBioData, (void*)&bioDataHeader, sizeof(BIO_DATA_HEADER)); port_memcpy((void*)(pNewBioData + sizeof(BIO_DATA_HEADER)), (void*)(pBIRtoProcess->BiometricData + sizeof(BIO_DATA_HEADER)), bioDataHeader.PWLength); /* Then we copy over the payload */ port_memcpy((void*)(pNewBioData + sizeof(BIO_DATA_HEADER) + bioDataHeader.PWLength), (void*)(pBIRtoProcess->BiometricData + sizeof(BIO_DATA_HEADER) + bioDataHeader.PWLength), bioDataHeader.PayloadLength); /* Keep track of BIR in addin until function FreeBIRHandle(...) * releases it */ pOldList = pAttachData->BIRList; pAttachData->BIRList = pHeadNode = (BIR_LIST_NODE*) BioAPI_malloc(sizeof(BIR_LIST_NODE), NULL); if (NULL == pHeadNode) { BioAPI_free (pNewBioData, NULL); return (BioAPIERR_BSP_MEMORY_ERROR); } pHeadNode->NextNode = (void*)pOldList; /* Build BIR Header */ pHeadNode->BIRHandle = *ProcessedBIR = pAttachData->HandleIndex++; pHeadNode->BIR.Header.HeaderVersion = BIR_HEADER_VERSION; pHeadNode->BIR.Header.Type = BioAPI_BIR_DATA_TYPE_PROCESSED; pHeadNode->BIR.Header.Format.FormatOwner = LittleEndian2 (BIO_DATA_FORMAT_OWNER); pHeadNode->BIR.Header.Format.FormatID = LittleEndian2 (BIO_DATA_FORMAT_ID); pHeadNode->BIR.Header.Quality = 100; /* by definition */ pHeadNode->BIR.Header.FactorsMask = LittleEndian4 (BioAPI_FACTOR_PASSWORD); /* The input BIR's header has the length already converted to little-endian */ pHeadNode->BIR.Header.Length = pBIRtoProcess->Header.Length; /* This BIR is just another incarnation of the input BIR - * it has the same purpose */ pHeadNode->BIR.Header.PurposeMask = pBIRtoProcess->Header.PurposeMask; /* Finish BIR */ pHeadNode->BIR.Signature = NULL; pHeadNode->BIR.BiometricData = (BioAPI_BIR_BIOMETRIC_DATA*)pNewBioData; return BioAPI_OK; }
/*--------------------------------------------------------------- * *Name: cssm_FreeDBInfo * *Description: * Free memory associated with the DBINFO structure * *Parameters: * Info (input) - pointer to DB Info * *Returns: * CSSM_FAIL - unable to free * CSSM_OK - free memory * *-------------------------------------------------------------*/ CSSM_RETURN cssm_FreeDbInfo (CSSM_DBINFO_PTR Info) { uint32 i; if( Info != NULL) { if (port_IsBadReadPtr (Info->RecordAttributeNames, sizeof (CSSM_DB_RECORD_ATTRIBUTE_INFO) * Info->NumberOfRecordTypes)) { return(CSSMERR_CSSM_INVALID_POINTER); } if (port_IsBadReadPtr (Info->RecordIndexes, sizeof (CSSM_DB_RECORD_INDEX_INFO) * Info->NumberOfRecordTypes)) { return(CSSMERR_CSSM_INVALID_POINTER); } /* free all record types */ for (i = 0; i < Info->NumberOfRecordTypes; i++) { uint32 j; if (Info->RecordAttributeNames[i].AttributeInfo) { if (port_IsBadReadPtr (Info->RecordAttributeNames[i].AttributeInfo, sizeof (CSSM_DB_ATTRIBUTE_INFO) * Info->RecordAttributeNames[i].NumberOfAttributes)) { return(CSSMERR_CSSM_INVALID_POINTER); } for (j = 0; j < Info->RecordAttributeNames[i].NumberOfAttributes; j++) { cssm_FreeDbAttributeInfo(&Info->RecordAttributeNames[i].AttributeInfo[j]); } BioAPI_free (Info->RecordAttributeNames[i].AttributeInfo, NULL); Info->RecordAttributeNames[i].AttributeInfo = NULL; } if (Info->RecordIndexes[i].IndexInfo) { if (port_IsBadReadPtr (Info->RecordIndexes[i].IndexInfo, sizeof (CSSM_DB_INDEX_INFO) * Info->RecordIndexes[i].NumberOfIndexes)) { return(CSSMERR_CSSM_INVALID_POINTER); } for (j = 0; j < Info->RecordIndexes[i].NumberOfIndexes; j++) { cssm_FreeDbAttributeInfo(&Info->RecordIndexes[i].IndexInfo[j].Info); } BioAPI_free (Info->RecordIndexes[i].IndexInfo, NULL); Info->RecordIndexes[i].IndexInfo = NULL; } } if (Info->DefaultParsingModules) { BioAPI_free (Info->DefaultParsingModules, NULL); Info->DefaultParsingModules = NULL; } if (Info->RecordAttributeNames) { BioAPI_free (Info->RecordAttributeNames, NULL); Info->RecordAttributeNames = NULL; } if (Info->RecordIndexes) { BioAPI_free (Info->RecordIndexes, NULL); Info->RecordIndexes = NULL; } if (Info->AccessPath) { BioAPI_free (Info->AccessPath, NULL); Info->AccessPath = NULL; } if (Info->Reserved && ((CSSM_DATA_PTR)Info->Reserved)->Data) { BioAPI_free (((CSSM_DATA_PTR)Info->Reserved)->Data, NULL); } } return(CSSM_OK); }