📄 p7settype.c
字号:
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, pkcs7Obj, status, 0, VT_ERROR_TYPE_PRIMARY,
(char *)0, "VtPkcs7ParamSigningTime", fnctLine, (char *)0)
return (status);
}
int VoltGetSignerIdObjRef (
VtPkcs7Object p7Obj,
unsigned int index,
VtIdentityObject *signerRef
)
{
int status;
VoltPkcs7Object *obj = (VoltPkcs7Object *)p7Obj;
VoltPkcs7WriteSignCtx *signCtx = (VoltPkcs7WriteSignCtx *)(obj->localCtx);
VOLT_DECLARE_FNCT_LINE (fnctLine)
*signerRef = (VtIdentityObject)0;
do
{
/* It must be a SignedData object.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NO_ID_AT_INDEX;
if (obj->contentType != VT_PKCS7_SIGNED_DATA)
break;
/* Is there a signer at the index?
*/
VOLT_SET_FNCT_LINE (fnctLine)
if (index >= signCtx->signerInfosCount)
break;
/* Do we have an ID object for this signer?
*/
VOLT_SET_FNCT_LINE (fnctLine)
if (signCtx->signerInfos[index].signerId == (VtIdentityObject)0)
break;
*signerRef = signCtx->signerInfos[index].signerId;
status = 0;
} while (0);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, p7Obj, status, 0, VT_ERROR_TYPE_PRIMARY,
(char *)0, "VoltGetSignerIdObjRef", fnctLine, (char *)0)
return (status);
}
int VtPkcs7ParamRecipientInfoList (
VtPkcs7Object pkcs7Obj,
Pointer info,
unsigned int flag
)
{
int status;
unsigned int algorithm, bufferSize, index, listIndex;
VoltPkcs7Object *obj = (VoltPkcs7Object *)pkcs7Obj;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltAlgorithmObject *algObj;
VoltCipherClassCtx *cipherCtx;
VoltPkcs7WriteEnvCtx *envCtx;
VoltRecipientInfoList *rList;
VoltRecipientInfoObject *recipObj;
VoltRecipientData *recipData;
unsigned char *temp;
VtSetAlgIdInfo algIdInfo;
VtDerCoderInfo coderInfo;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
if (flag == VOLT_PKCS7_GET_TYPE_FLAG)
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = P7GetRecipientInfoList (obj, (Pointer *)info);
break;
}
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;
/* We're setting, so the state must be set to Write EnvelopedData.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SET;
if (obj->state != VOLT_P7_STATE_ENV_WRITE_SET)
break;
envCtx = (VoltPkcs7WriteEnvCtx *)(obj->localCtx);
/* The object cannot have been set with recipients or symmetric
* algorithm.
*/
VOLT_SET_FNCT_LINE (fnctLine)
if ( (envCtx->recipList != (VtIdentityList)0) ||
(envCtx->recipients != (VoltRecipientData *)0) ||
(envCtx->symEncryptor != (VtAlgorithmObject)0) ||
(envCtx->symEncryptorAlgId.data != (unsigned char *)0) ||
(envCtx->symKey != (VtKeyObject)0) )
break;
/* The associated info must be a RecipientInfoList.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info == (Pointer)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
if (VOLT_OBJECT_TYPE_NOT_EQUAL (
info, VOLT_OBJECT_TYPE_RECIP_INFO_LIST))
break;
rList = (VoltRecipientInfoList *)info;
/* The list must have the symmetric alg and key set, there must be
* at least one RecipientInfo.
*/
VOLT_SET_FNCT_LINE (fnctLine)
if ( (rList->SymAlg == (VtDerCoder *)0) ||
(rList->symKeyData.data == (unsigned char *)0) ||
(rList->theListSize == 0) )
break;
/* Decode the algID to get the KeyParam.
*/
coderInfo.info.getAlgData.libCtx = libCtx;
coderInfo.info.getAlgData.oid = rList->symAlgID.data + 4;
coderInfo.info.getAlgData.oidLen =
(unsigned int)(rList->symAlgID.data[3]);
coderInfo.info.getAlgData.encodingType = VOLT_ENCODING_TYPE_ALG_ID;
coderInfo.info.getAlgData.algorithm = &algorithm;
coderInfo.info.getAlgData.SymKeyParam = (VtKeyParam *)0;
coderInfo.info.getAlgData.DigestImpl = (VtAlgorithmImpl *)0;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = rList->SymAlg (
&coderInfo, (Pointer)0, VOLT_DER_TYPE_GET_ALG_FLAG);
if (status != 0)
break;
envCtx->SymKeyParam = coderInfo.info.getAlgData.SymKeyParam;
/* Copy the AlgID.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltCopyItemDataAlloc (
(VtLibCtx)libCtx, 0, 0, &(rList->symAlgID),
&(envCtx->symEncryptorAlgId));
if (status != 0)
break;
/* Build the symmetric algorithm from the algID.
*/
algIdInfo.derCoders = &(rList->SymAlg);
algIdInfo.derCoderCount = 1;
algIdInfo.berEncoding = rList->symAlgID.data;
algIdInfo.maxEncodingLen = rList->symAlgID.len;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateAlgorithmObject (
(VtLibCtx)libCtx, VtAlgorithmImplAlgId, (Pointer)&algIdInfo,
&(envCtx->symEncryptor));
if (status != 0)
break;
/* Get the block size.
*/
algObj = (VoltAlgorithmObject *)(envCtx->symEncryptor);
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if ((algObj->algClass & VOLT_CLASS_CIPHER) == 0)
break;
cipherCtx = (VoltCipherClassCtx *)(algObj->classCtx);
envCtx->blockSize = cipherCtx->cipherBlockSize;
/* Build the key object.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateKeyObject (
(VtLibCtx)libCtx, VtKeyImplDefault, (Pointer)0, &(envCtx->symKey));
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtSetKeyParam (
envCtx->symKey, envCtx->SymKeyParam, (Pointer)&(rList->symKeyData));
if (status != 0)
break;
envCtx->symKeyBits = rList->symKeyData.len * 8;
/* We'll need the IdentityList version of the recipients.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateIdentityList (
(VtLibCtx)libCtx, VtIdentityListImplMpCtx, (Pointer)(rList->mpCtx),
&(envCtx->recipList));
if (status != 0)
break;
/* Build the array of recipientDatas. Use index as a temp variable.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize = rList->theListCount * sizeof (VoltRecipientData);
envCtx->recipients = (VoltRecipientData *)Z2Malloc (bufferSize, 0);
if (envCtx->recipients == (VoltRecipientData *)0)
break;
Z2Memset (envCtx->recipients, 0, bufferSize);
envCtx->recipientsCount = rList->theListCount;
for (index = 0; index < rList->theListCount; ++index)
{
recipData = &(envCtx->recipients[index]);
recipObj = (VoltRecipientInfoObject *)(rList->theList[index]);
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
recipData->recipInfo = Asn1RecipientInfo_new ();
/* The recipObj must be encoded.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (recipObj->encodedInfo.data == (unsigned char *)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
temp = recipObj->encodedInfo.data;
d2i_Asn1RecipientInfo (
&(recipData->recipInfo), &temp, recipObj->encodedInfo.len);
if (recipObj->encodedInfo.data == (unsigned char *)0)
break;
/* Compute the length.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
recipData->recipInfoLen = i2d_Asn1RecipientInfo (
recipData->recipInfo, (unsigned char **)0);
if (recipData->recipInfoLen == 0)
break;
/* Add the identity object from tht recipObj to the identity list
* version of the recipients.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtAddIdObjectToIdentityList (
envCtx->recipList, (VtIdentityObject)(recipObj->idObj), &listIndex);
if (status != 0)
break;
}
} while (0);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, pkcs7Obj, status, 0, errorType,
(char *)0, "VtPkcs7ParamRecipientInfoList", fnctLine, (char *)0)
return (status);
}
int P7GetRecipientInfoList (
VoltPkcs7Object *obj,
Pointer *getInfo
)
{
int status;
unsigned int index, encodingLen;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltPkcs7ReadEnvCtx *ctx;
VtRecipientInfoList newList = (VtRecipientInfoList)0;
VtRecipientInfoObject rInfo = (VtRecipientInfoObject)0;
unsigned char *buffer = (unsigned char *)0;
unsigned char *temp;
VtSetAlgIdInfo setAlgIdInfo;
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)
/* We're getting, so the state must be set to Read EnvelopedData,
* and the entire messag must be read.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_GET;
if (obj->state != VOLT_P7_STATE_ENV_READ_FINAL)
break;
ctx = (VoltPkcs7ReadEnvCtx *)(obj->localCtx);
/* If the rInfoList is already built, return it.
*/
status = 0;
*getInfo = (Pointer)(ctx->rInfoList);
if (ctx->rInfoList != (VtRecipientInfoList)0)
break;
/* Build the RecipientInfoList.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateRecipientInfoList (
(VtLibCtx)libCtx, VtRecipientInfoListImplMpCtx,
(Pointer)(ctx->mpCtx), &newList);
if (status != 0)
break;
/* Set the symmetric algorithm.
*/
setAlgIdInfo.derCoders = ctx->DerCoders;
setAlgIdInfo.derCoderCount = ctx->derCoderCount;
setAlgIdInfo.berEncoding = ctx->symAlgID;
setAlgIdInfo.maxEncodingLen = ctx->symAlgIDLen;
status = VtSetRecipientInfoListParam (
newList, VtRecipientInfoListParamSymmetricAlgorithm,
(Pointer)&setAlgIdInfo);
if (status != 0)
break;
/* For each recipient, build a RecipientInfoObject.
*/
for (index = 0; index < ctx->recipInfoCount; ++index)
{
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
encodingLen = i2d_Asn1RecipientInfo (
ctx->recipInfoList[index], (unsigned char **)0);
if (encodingLen == 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
buffer = (unsigned char *)Z2Realloc (buffer, encodingLen);
if (buffer == (unsigned char *)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
temp = buffer;
encodingLen = i2d_Asn1RecipientInfo (ctx->recipInfoList[index], &temp);
if (encodingLen == 0)
break;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateRecipientInfoObject (
libCtx, VtRecipientInfoImplMpCtx, (Pointer)(ctx->mpCtx), &rInfo);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtDecodeRecipientInfo (
buffer, encodingLen, ctx->Decoders, ctx->decoderCount,
(unsigned int *)0, ctx->DerCoders, ctx->derCoderCount,
(unsigned int *)0, rInfo);
if (status != 0)
break;
/* If this is the recipient that decrypted the symmetric key,
* load the symmetric key into this object.
*/
if (index == (unsigned int)(ctx->chosenRecipient))
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VtSetRecipientInfoParam (
rInfo, VtRecipientInfoParamSymmetricKey,
(Pointer)&(ctx->symKeyData));
if (status != 0)
break;
}
VOLT_SET_FNCT_LINE (fnctLine)
status = VtAddRecipientInfoToList (newList, rInfo, (unsigned int *)0);
if (status != 0)
break;
VtDestroyRecipientInfoObject (&rInfo);
}
if (status != 0)
break;
ctx->rInfoList = newList;
*getInfo = (Pointer)ctx->rInfoList;
newList = (VtRecipientInfoList)0;
} while (0);
if (buffer != (unsigned char *)0)
Z2Free (buffer);
VtDestroyRecipientInfoObject (&rInfo);
VtDestroyRecipientInfoList (&newList);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, obj, status, 0, errorType,
(char *)0, "P7GetRecipientInfoList", fnctLine, (char *)0)
return (status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -