?? readsigntype.c
字號:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "p7obj.h"
#include "idobj.h"
#include "derhelp.h"
#include "oidlist.h"
#include "errorctx.h"
int VtPkcs7ImplReadSignedData (
VtPkcs7Object *object,
Pointer info,
unsigned int flag
)
{
int status;
#if VOLT_ALIGNMENT != 1
unsigned int pad;
#endif
unsigned int bufferSize, offset, index;
unsigned int listToUseCount = 0, decodersToUseCount = 0;
VoltPkcs7Object *obj = (VoltPkcs7Object *)(*object);
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VtReadPkcs7Info *readInfo;
VtDerCoder **ListToUse = (VtDerCoder **)0;
VtIdentitySchemaDecode **DecodersToUse = (VtIdentitySchemaDecode **)0;
VtDERCoderArray *derCoderArray;
VtSchemaDecodeArray *schemaDecodeArray;
VtMpIntCtx mpCtxToUse = (VtMpIntCtx)0;
unsigned char *buffer = (unsigned char *)0;
VoltPkcs7ReadSignCtx *readCtx;
VtMpIntCtx newMpCtx = (VtMpIntCtx)0;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_PKCS7_SET_TYPE_FLAG)
break;
/* Make sure the object is empty.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_P7_OBJ;
if ( (obj->contentType != 0) || (obj->localCtx != (Pointer)0) )
break;
/* Check the info. If there's no info, get it from the libCtx.
*/
if (info != (Pointer)0)
{
readInfo = (VtReadPkcs7Info *)info;
ListToUse = readInfo->derCoders;
listToUseCount = readInfo->derCoderCount;
DecodersToUse = readInfo->decoders;
decodersToUseCount = readInfo->decoderCount;
mpCtxToUse = readInfo->mpCtx;
}
/* If we don't have any DerCoder's get the ones in the libCtx. If
* there are none there, break, that's an error.
*/
if ( (ListToUse == (VtDerCoder **)0) || (listToUseCount == 0) )
{
derCoderArray = (VtDERCoderArray *)VoltGetLibCtxInfo (
obj->voltObject.libraryCtx, VOLT_LIB_CTX_INFO_TYPE_DER_CODERS);
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NO_DER_CODERS;
if (derCoderArray == (VtDERCoderArray *)0)
break;
ListToUse = derCoderArray->derCoders;
listToUseCount = derCoderArray->derCoderCount;
}
/* If we don't have any SchemaDecode's get the ones in the libCtx.
* If there are none there, break, that's an error.
*/
if ( (DecodersToUse == (VtIdentitySchemaDecode **)0) ||
(decodersToUseCount == 0) )
{
schemaDecodeArray = (VtSchemaDecodeArray *)VoltGetLibCtxInfo (
obj->voltObject.libraryCtx, VOLT_LIB_CTX_INFO_TYPE_SCHEMA_DECODES);
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NO_SCHEMA_DECODERS;
if (schemaDecodeArray == (VtSchemaDecodeArray *)0)
break;
DecodersToUse = schemaDecodeArray->decoders;
decodersToUseCount = schemaDecodeArray->decoderCount;
}
/* If we don't have an mpCtx, get one from the libCtx. If there is
* not one there, break, that's an error.
*/
if (mpCtxToUse == (VtMpIntCtx)0)
{
mpCtxToUse = (VtMpIntCtx)VoltGetLibCtxInfo (
obj->voltObject.libraryCtx, VOLT_LIB_CTX_INFO_TYPE_MP_CTX);
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NO_MATH_LIBRARY;
if (mpCtxToUse == (VtMpIntCtx)0)
break;
}
/* Paranoid programming check.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_MP_INT_CTX;
if (VOLT_OBJECT_TYPE_NOT_EQUAL (mpCtxToUse, VOLT_OBJECT_TYPE_MP_INT_CTX))
break;
/* Build a buffer big enough to hold the readSignCtx and the coder
* array.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize =
sizeof (VoltPkcs7ReadSignCtx) + (listToUseCount * sizeof (VtDerCoder *) +
(decodersToUseCount * sizeof (VtSchemaDecodeArray *)));
#if VOLT_ALIGNMENT != 1
/* If the alignment is 1, there's no need to pad. If not, compute
* the pad length.
*/
VOLT_COMPUTE_ALIGN_PAD (
VOLT_ALIGNMENT, sizeof (VoltPkcs7ReadSignCtx), pad)
bufferSize += pad;
#endif
buffer = (unsigned char *)Z2Malloc (bufferSize, 0);
if (buffer == (unsigned char *)0)
break;
Z2Memset (buffer, 0, bufferSize);
/* Locate the pointers.
*/
readCtx = (VoltPkcs7ReadSignCtx *)buffer;
offset = sizeof (VoltPkcs7ReadSignCtx);
#if VOLT_ALIGNMENT != 1
offset += pad;
#endif
/* Copy the DerCoders array.
*/
readCtx->DerCoders =(VtDerCoder **)(buffer + offset);
for (index = 0; index < listToUseCount; ++index)
readCtx->DerCoders[index] = ListToUse[index];
readCtx->derCoderCount = listToUseCount;
/* Copy the schemaDecode's.
*/
offset += listToUseCount * sizeof (VtDerCoder *);
readCtx->Decoders = (VtIdentitySchemaDecode **)(buffer + offset);
for (index = 0; index < decodersToUseCount; ++index)
readCtx->Decoders[index] = DecodersToUse[index];
readCtx->decoderCount = decodersToUseCount;
/* Clone the mpCtx.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCloneObject ((Pointer)mpCtxToUse, (Pointer *)&newMpCtx);
if (status != 0)
break;
readCtx->mpCtx = newMpCtx;
obj->state = VOLT_P7_STATE_SIGN_READ_SET;
obj->localCtx = (Pointer)readCtx;
obj->LocalCtxDestroy = VoltReadSignCtxDestroy;
obj->contentType = VOLT_PKCS7_SIGNED_DATA_READ;
obj->ReadInit = VoltP7ReadSignedInit;
obj->ReadUpdate = VoltP7ReadSignedUpdate;
obj->ReadFinal = VoltP7ReadSignedFinal;
obj->VerifySignerInfo = VoltP7VerifySignerInfo;
} while (0);
/* If success, we're done.
*/
if (status == 0)
return (0);
/* If there was an error, destroy what we created.
*/
VtDestroyMpIntCtx (&newMpCtx);
if (buffer != (unsigned char *)0)
Z2Free (buffer);
VOLT_LOG_ERROR_INFO (
0, *object, status, 0, errorType,
(char *)0, "VtPkcs7ImplReadSignedData", fnctLine, (char *)0)
return (status);
}
void VoltReadSignCtxDestroy (
Pointer obj,
Pointer ctx
)
{
unsigned int index, indexA;
VoltObject *voltObj = (VoltObject *)obj;
VoltLibCtx *libCtx;
VoltPkcs7ReadSignCtx *readCtx = (VoltPkcs7ReadSignCtx *)ctx;
/* Anything to destroy?
*/
if ( (obj == (Pointer)0) || (ctx == (Pointer)0) )
return;
libCtx = (VoltLibCtx *)(voltObj->libraryCtx);
VtDestroyMpIntCtx (&(readCtx->mpCtx));
VtDestroyAlgorithmObject (&(readCtx->digestObj));
VtDestroyIdentityList (&(readCtx->signerList));
for (index = 0; index < readCtx->signerInfosCount; ++index)
{
if (readCtx->signerInfos[index].signerInfo != (Asn1SignerInfo *)0)
Asn1SignerInfo_free (readCtx->signerInfos[index].signerInfo);
for (indexA = 0; indexA < readCtx->signerInfos[index].authAttrsCount;
++indexA)
Asn1P9Attribute_free (readCtx->signerInfos[index].authAttrs[indexA]);
Z2Free (readCtx->signerInfos[index].authAttrs);
}
if (readCtx->signerInfos != (VoltSignerInfoData *)0)
Z2Free (readCtx->signerInfos);
for (index = 0; index < readCtx->msgCertsCount; ++index)
VtDestroyCertObject (&(readCtx->msgCerts[index]));
if (readCtx->msgCerts != (VtCertObject *)0)
Z2Free (readCtx->msgCerts);
if (readCtx->currentElement.element != (unsigned char *)0)
Z2Free (readCtx->currentElement.element);
if (readCtx->digest != (unsigned char *)0)
Z2Free (readCtx->digest);
if (readCtx->contentOid != (unsigned char *)0)
Z2Free (readCtx->contentOid);
Z2Free (ctx);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -