isl_archive.c

来自「Next BIOS Source code : Extensible Firmw」· C语言 代码 · 共 1,134 行 · 第 1/3 页

C
1,134
字号
	SignerPtr = PKCS7SignatureMethods.FindSigner(SignaturePtr, CertificatePtr);
	if (SignerPtr == NULL)
	{
        return ISL_FAIL;
	}
	if (ISL_OK != PKCS7SignerMethods.VerifyUsingCert(
					SignerPtr, 
					CertMethods, 
					CertificatePtr) )
	{
        return ISL_FAIL;
	}

    /* verify the integrity of the manifest sections */
	
	/* 
	 * for each signature section in the signer's information list, locate
	 * the corresponding manifest section, compute the digest of that manfiest
	 * section using the digest algorithm indicated in the signature information
	 * file.  Compare the computed digest against the value listed in the 
	 * signature file
	 */
    {
        uint32 Index;

        SigObjGrpPtr = SignedListMethods.GetSignedObjectInfos(
            SigInfoPtr->SignedListPtr);
        if (SigObjGrpPtr == NULL) return ISL_FAIL;

        for(Index =0;
            Index < SigObjGrpPtr->NumberOfSignedObjects;
            Index++)
	    {
            ISL_SIG_SECTION_PTR SignedObjectPtr;
            ISL_STATUS SignedObjectVerified;

            SignedObjectPtr = SigObjGrpPtr->SignedObjects[Index];
            SignedObjectVerified = isl_VerifyManSectWithAllDigestValues(
                SignedObjectPtr);
		    if (SignedObjectVerified != ISL_OK) goto FAIL;
	    }
        SignedListMethods.FreeSignedObjectInfos(
            SigInfoPtr->SignedListPtr,
            SigObjGrpPtr);
    }
    return ISL_OK;
FAIL:
    {
        SignedListMethods.FreeSignedObjectInfos(
            SigInfoPtr->SignedListPtr,
            SigObjGrpPtr);

        return ISL_FAIL;
    }
}

/*-----------------------------------------------------------------------------
 * Name: SetLocationMap
 *
 * Description: 
 * This function will update the Location Maps based on the information in the
 * MapEntryPtr array.
 *
 * Parameters:
 * MapEntryPtr (input) - 
 * NumberOfEntries (input)
 *
 * Return value:
 * 
 * Error Codes:
 *---------------------------------------------------------------------------*/
ISL_STATUS
SetLocationMap(
    ISL_ARCHIVE_CONTEXT_PTR ArchivePtr,
	ISL_LMAP Map)
{
    ISL_LMAP TempMap;
	uint32 i;

	if (ArchivePtr == NULL) 
	{
		return ISL_FAIL;
	}

    if (Map.NumberOfEntries == 0)
    {
        ArchivePtr->Map.NumberOfEntries = 0;
        ArchivePtr->Map.MapEntries = NULL;
        return ISL_OK;
    }

    TempMap.MapEntries = NULL;
    {
        /* code is a bit leaky as it allocates from the ArchivePtr
           to be more aggressive should give it its own MemoryPtr */
        TempMap.NumberOfEntries = Map.NumberOfEntries;
        TempMap.MapEntries = isl_AllocateMemory(
            ArchivePtr->Memory,
            sizeof(ISL_LMAP_ENTRY) * TempMap.NumberOfEntries);
        if (TempMap.MapEntries == NULL) goto FAIL;

        for(i=0; i < Map.NumberOfEntries; i++)
	    {
            ISL_LMAP_ENTRY_PTR ArchiveEntryPtr = 
                &TempMap.MapEntries[i];

            ArchiveEntryPtr->GetDataMethod = 
                Map.MapEntries[i].GetDataMethod;

            ArchiveEntryPtr->GetParameters.Length =
                Map.MapEntries[i].GetParameters.Length;
            if (ArchiveEntryPtr->GetParameters.Length != 0)
            {
                ArchiveEntryPtr->GetParameters.Data = isl_CopyMemory(
                    ArchivePtr->Memory,
                    Map.MapEntries[i].GetParameters.Data,
                    Map.MapEntries[i].GetParameters.Length);
                if (ArchiveEntryPtr->GetParameters.Data == NULL) goto FAIL;
            }
            else
            {
                ArchiveEntryPtr->GetParameters.Data = NULL;
            }

            ArchiveEntryPtr->JoinName.Length =
                Map.MapEntries[i].JoinName.Length;
            if (ArchiveEntryPtr->JoinName.Length != 0)
            {
                ArchiveEntryPtr->JoinName.Data = isl_CopyMemory(
                    ArchivePtr->Memory,
                    Map.MapEntries[i].JoinName.Data,
                    Map.MapEntries[i].JoinName.Length);
                if (ArchiveEntryPtr->JoinName.Data == NULL) goto FAIL;
            }
            else
            {
                ArchiveEntryPtr->JoinName.Data = NULL;
            }
        }

        ArchivePtr->Map = TempMap;
	    return ISL_OK;
    }
FAIL:
    {
        return ISL_FAIL;
    }
}

/*-----------------------------------------------------------------------------
 * Name: GetLocationMap
 *
 * Description:
 * This function returns an SM Specific representation of a location map
 *
 * Parameters:
 * ArchivePtr (input)
 * MapPtr (output)
 *
 * Return value:
 * 
 * Error Codes:
 *---------------------------------------------------------------------------*/
static
ISL_LMAP_PTR
GetLocationMap(
	ISL_ARCHIVE_CONTEXT_PTR ArchivePtr)
{
    /* not going to replicate the map (for now) */
	if (ArchivePtr == NULL) return NULL;
    return &ArchivePtr->Map;
}

/*-----------------------------------------------------------------------------
 * Name: FindAttributeValue
 *
 * Description:
 * This function find metadata in the archive header.
 *
 * Parameters:
 * Context (input) - archive context
 * Attribute (input) - attribute "name"
 * Value (output) - fill in Value if found
 *
 * Return value:
 * 
 * Error Codes:
 *---------------------------------------------------------------------------*/
static
ISL_STATUS
FindAttributeValue(		
	ISL_ARCHIVE_CONTEXT_PTR Context,
	ISL_CONST_DATA Attribute,
	ISL_CONST_DATA_PTR Value)
{
    ISL_STATUS FoundAttributeStatus;

    if (Context == NULL) return ISL_FAIL;

    FoundAttributeStatus = isl_FindAttributeInHeader(
        &Context->Manifest.Header,
        Attribute,
        Value);

    return FoundAttributeStatus;
}

/*-----------------------------------------------------------------------------
 * Name: GetSignatureGroup
 *
 * Description:
 * This function returns a group of signature objects contained in the archive.
 *
 * Parameters:
 * Context(input)
 *
 * Return value:
 * 
 * Error Codes:
 *
 * Notes:
 * Use FreeSignatureGroup to release memory.
 *---------------------------------------------------------------------------*/
static
ISL_SIGNATURE_INFO_GROUP_PTR 
GetSignatureGroup(
    ISL_ARCHIVE_CONTEXT_PTR Context)
{
    ISL_SIGNATURE_INFO_GROUP_PTR SignatureGrpPtr;
    ISL_LIST_PTR CurrNodePtr;
    ISL_SIGNATURE_INFO_PTR SigInfoPtr;
    uint32 NumberOfSignatures;

    if (Context == NULL) return NULL;

    SignatureGrpPtr = isl_AllocateMemory(
        Context->Memory,
        sizeof(ISL_SIGNATURE_INFO_GROUP));
    if (SignatureGrpPtr == NULL) return NULL;

    NumberOfSignatures = isl_CountItemsInList(Context->Signatures);
    if (NumberOfSignatures == 0)
    {
        SignatureGrpPtr->NumberOfSignatures = 0;
        SignatureGrpPtr->SignatureInfoPtr = NULL;
        return SignatureGrpPtr;
    }

    SignatureGrpPtr->NumberOfSignatures = NumberOfSignatures;
    SigInfoPtr = isl_AllocateMemory(
        Context->Memory,
        sizeof(ISL_SIGNATURE_INFO) * NumberOfSignatures);
    if (SigInfoPtr == NULL)
    {
        goto FAIL;
    }

    SignatureGrpPtr->SignatureInfoPtr = SigInfoPtr;    
    for(CurrNodePtr = Context->Signatures;
        CurrNodePtr != NULL;
        CurrNodePtr = CurrNodePtr->Next)
    {
        ISL_SIGNATURE_INFO_PTR ListSigInfoPtr;

        ListSigInfoPtr = CurrNodePtr->Node;
        *SigInfoPtr = *ListSigInfoPtr;
        SigInfoPtr++;
    }
    return SignatureGrpPtr;

FAIL:
    {
        isl_FreeMemory(Context->Memory, SignatureGrpPtr);
        return NULL;
    }
}

/*-----------------------------------------------------------------------------
 * Name: FreeSignatureGroup
 *
 * Description:
 * This function returns an SM Specific representation of a location map
 *
 * Parameters:
 * Context (input)
 * SignatureInfoGroupPtr (input)
 *
 * Return value:
 * 
 * Error Codes:
 *---------------------------------------------------------------------------*/
static
ISL_STATUS 
FreeSignatureGroup(
    ISL_ARCHIVE_CONTEXT_PTR Context,
    ISL_SIGNATURE_INFO_GROUP_PTR SignatureInfoGroupPtr)
{
    if (Context == NULL) return ISL_FAIL;

    if (SignatureInfoGroupPtr == NULL) return ISL_OK;
    isl_FreeMemory(Context->Memory, SignatureInfoGroupPtr->SignatureInfoPtr);
    isl_FreeMemory(Context->Memory, SignatureInfoGroupPtr);
    return ISL_OK;
}

/*-----------------------------------------------------------------------------
 * Name: GetCertificateGroup
 *
 * Description:
 * This function returns a group of certificate objects contained in the 
 * archive.
 *
 * Parameters:
 * Context (input)
 *
 * Return value:
 * 
 * Error Codes:
 *
 * Notes:
 * Use FreeCertificateGroup to release memory
 *---------------------------------------------------------------------------*/
static
ISL_CERTIFICATE_GROUP_PTR 
GetCertificateGroup(
    ISL_ARCHIVE_CONTEXT_PTR Context)
{
    if (Context == NULL) return NULL;

    return isl_BuildCertificateGroup(
        Context->Certs,
        Context->Memory);
}

/*-----------------------------------------------------------------------------
 * Name: FreeCertificateGroup
 *
 * Description:
 * This function returns an SM Specific representation of a location map
 *
 * Parameters:
 * Context (input)
 * CertificateGroupPtr (input)
 *
 * Return value:
 * 
 * Error Codes:
 *---------------------------------------------------------------------------*/
static
ISL_STATUS
FreeCertificateGroup(
    ISL_ARCHIVE_CONTEXT_PTR Context,
    ISL_CERTIFICATE_GROUP_PTR CertificateGroupPtr)
{
    if (Context == NULL) return ISL_FAIL;
    if (CertificateGroupPtr == NULL) return ISL_OK;

    isl_FreeMemory(Context->Memory, CertificateGroupPtr->Certificates);
    isl_FreeMemory(Context->Memory, CertificateGroupPtr);
    return ISL_OK;
}

ISL_ARCHIVE_METHODS ArchiveMethods = {
	{NULL, NULL},
	ArchiveSizeofObject,
	InitializeFromMemory,
	isl_RecycleArchiveContext,
	FindSignableObject,
    Verify,
    GetLocationMap,
    SetLocationMap,
    FindAttributeValue,		
    GetSignatureGroup,
    FreeSignatureGroup,
    GetCertificateGroup,
    FreeCertificateGroup
};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?