📄 p7settype.c
字号:
VtPkcs7Object pkcs7Obj,
Pointer info,
unsigned int flag
)
{
int status;
VoltPkcs7Object *obj = (VoltPkcs7Object *)pkcs7Obj;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltPkcs7ReadEnvCtx *readCtx = (VoltPkcs7ReadEnvCtx *)(obj->localCtx);
VtPkcs7RecipientIndexInfo *indexInfo;
VtKeyObject newKey = (VtKeyObject)0;
VtIdentityObject getId;
VtPolicyCtx policy;
VtStorageCtx storage;
VtTransportCtx transport;
VtSurrenderCallback surrenderCtx;
VtSurrenderCallback *surrenderToUse = (VtSurrenderCallback *)0;
VoltSurrenderCtx *surrCtx;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* This Param cannot get info.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_GET;
if (flag == VOLT_PKCS7_GET_TYPE_FLAG)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_PKCS7_SET_TYPE_FLAG)
break;
/* The state must be VOLT_P7_STATE_ENV_READ_PREPARE_ENC.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_CALL_ORDER;
if (obj->state != VOLT_P7_STATE_ENV_READ_PREPARE_ENC)
break;
/* This cannot be called if the ctx already contains a private key.
*/
VOLT_SET_FNCT_LINE (fnctLine)
if ( (readCtx->priKey != (VtKeyObject)0) ||
(readCtx->priKeyRef != (VtKeyObject)0) )
break;
/* The info should be a pointer to a VtPkcs7RecipientIndexInfo
* struct.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info == (Pointer)0)
break;
indexInfo = (VtPkcs7RecipientIndexInfo *)info;
/* Get the identity object associated with the given index.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetIdentityListIdentity (
readCtx->recipList, indexInfo->index, &getId);
if (status != 0)
break;
policy = indexInfo->policyCtx;
storage = indexInfo->storageCtx;
transport = indexInfo->transportCtx;
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltCheckSupportObjects (
obj->voltObject.libraryCtx, &policy, &storage,
&transport, (VtCertVerifyCtx *)0, (VtVerifyFailureList *)0,
(VtRandomObject *)0, (VtDerCoder ***)0, (unsigned int *)0,
(VtIdentitySchemaDecode ***)0, (unsigned int *)0);
if (status != 0)
break;
/* Create a key object into which the IBE private key will be
* loaded.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateKeyObject (
(VtLibCtx)libCtx, VtKeyImplMpCtx, (Pointer)(readCtx->mpCtx), &newKey);
if (status != 0)
break;
if (obj->voltObject.surrenderCtx != (Pointer)0)
{
surrCtx = (VoltSurrenderCtx *)(obj->voltObject.surrenderCtx);
surrenderCtx.Surrender = surrCtx->Surrender;
surrenderCtx.appData = surrCtx->appData;
surrenderCtx.AppDataCopy = surrCtx->AppDataCopy;
surrenderCtx.AppDataFree = surrCtx->AppDataFree;
surrenderToUse = &surrenderCtx;
}
/* Now obtain the private key for the given identity.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtObtainPrivateKeysAndCert (
getId, (VtRandomObject)0, 0, policy, storage, transport,
(VtKeyObject)0, (VtCertObject)0, newKey);
if (status != 0)
break;
/* Now that we have a private key, set the reference so later on
* code can check that value to know a pri key is available. Also,
* set the chosenRecipient field, now that we know.
*/
readCtx->priKey = newKey;
readCtx->priKeyRef = readCtx->priKey;
readCtx->chosenRecipient = indexInfo->index;
} while (0);
/* If there was no error, we're done.
*/
if (status == 0)
return (status);
/* If there was an error, destroy the key object we (may have)
* created and did not return.
*/
VtDestroyKeyObject (&newKey);
VOLT_LOG_ERROR_INFO (
0, pkcs7Obj, status, 0, errorType,
(char *)0, "VtPkcs7ParamRecipientIndex", fnctLine, (char *)0)
return (status);
}
int VtPkcs7ParamRecipient (
VtPkcs7Object pkcs7Obj,
Pointer info,
unsigned int flag
)
{
int status;
VoltPkcs7Object *obj = (VoltPkcs7Object *)pkcs7Obj;
VoltPkcs7ReadEnvCtx *readCtx = (VoltPkcs7ReadEnvCtx *)(obj->localCtx);
VtPkcs7RecipientInfo *recipInfo;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* This Param cannot get info.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_GET;
if (flag == VOLT_PKCS7_GET_TYPE_FLAG)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_PKCS7_SET_TYPE_FLAG)
break;
/* The object must be set to read EnvelopedData.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_P7_OBJ;
if (obj->contentType != VOLT_PKCS7_ENVELOPED_DATA_READ)
break;
/* This cannot be called if the ctx already contains a private key.
*/
VOLT_SET_FNCT_LINE (fnctLine)
if ( (readCtx->priKey != (VtKeyObject)0) ||
(readCtx->priKeyRef != (VtKeyObject)0) ||
(readCtx->specifiedIdentity != (VtIdentityObject)0) )
break;
/* The info should be a pointer to a VtPkcs7RecipientInfo
* struct.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info == (Pointer)0)
break;
recipInfo = (VtPkcs7RecipientInfo *)info;
VOLT_SET_FNCT_LINE (fnctLine)
if (recipInfo->identity == (VtIdentityObject)0)
break;
if (VOLT_OBJECT_TYPE_NOT_EQUAL (
recipInfo->identity, VOLT_OBJECT_TYPE_IDENTITY))
break;
VOLT_SET_FNCT_LINE (fnctLine)
if (recipInfo->priKey == (VtKeyObject)0)
break;
if (VOLT_OBJECT_TYPE_NOT_EQUAL (recipInfo->priKey, VOLT_OBJECT_TYPE_KEY))
break;
/* Copy a reference to the key inside the object.
*/
readCtx->priKeyRef = recipInfo->priKey;
/* Clone the Identity object.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCloneObject (
(Pointer)(recipInfo->identity), (Pointer *)&(readCtx->specifiedIdentity));
} while (0);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, pkcs7Obj, status, 0, errorType,
(char *)0, "VtPkcs7ParamRecipient", fnctLine, (char *)0)
return (status);
}
int VtPkcs7ParamSignerList (
VtPkcs7Object pkcs7Obj,
Pointer info,
unsigned int flag
)
{
int status, tStatus;
unsigned int index, indexC, indexI, bufferSize, encodedIdLen;
Pointer *getInfo;
VoltPkcs7Object *obj = (VoltPkcs7Object *)pkcs7Obj;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltPkcs7ReadSignCtx *readCtx;
VtIdentityList signerList = (VtIdentityList)0;
VtIdentityObject newId = (VtIdentityObject)0;
Asn1SignerInfo *signerInfo;
VoltCertObject *signerCert;
unsigned char *encodedId = (unsigned char *)0;
VtCertObjectList msgCerts;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
bufferSize = 0;
do
{
/* This param can Get only.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SET;
if (flag == VOLT_PKCS7_SET_TYPE_FLAG)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_PKCS7_GET_TYPE_FLAG)
break;
getInfo = (Pointer *)info;
/* Get the info only if we're done reading SignedData.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (obj->state != VOLT_P7_STATE_SIGN_READ_FINAL)
break;
readCtx = (VoltPkcs7ReadSignCtx *)(obj->localCtx);
if (readCtx->signerList != (VtIdentityList)0)
{
*getInfo = (Pointer)(readCtx->signerList);
status = 0;
break;
}
/* Create an identity list object to which we'll add identities.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateIdentityList (
(VtLibCtx)libCtx, VtIdentityListImplMpCtx,
(Pointer)(readCtx->mpCtx), &signerList);
if (status != 0)
break;
/* Run through all the SignerInfo's, collecting encodedId's at each
* stop. Use the encodedId's to build identity objects.
*/
msgCerts.certObjects = readCtx->msgCerts;
msgCerts.count = readCtx->msgCertsCount;
status = 0;
for (index = 0; index < readCtx->signerInfosCount; ++index)
{
signerInfo = readCtx->signerInfos[index].signerInfo;
tStatus = VoltFindCertByReference (
libCtx, VOLT_FIND_CERT_BY_ISSUER_SERIAL,
signerInfo->issuerSerial->issuerName->base.data,
(unsigned int)(signerInfo->issuerSerial->issuerName->base.length),
signerInfo->issuerSerial->serialNumber->data,
(unsigned int)(signerInfo->issuerSerial->serialNumber->length),
&indexC, &msgCerts, (VtCertObject *)&signerCert);
if ( (tStatus != 0) || (signerCert == (VoltCertObject *)0) )
continue;
tStatus = VoltGetEncodedIdFromCert (
(VtCertObject)signerCert, encodedId, bufferSize, &encodedIdLen);
if (tStatus == VT_ERROR_BUFFER_TOO_SMALL)
{
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize = encodedIdLen;
encodedId = (unsigned char *)Z2Realloc (encodedId, bufferSize);
if (encodedId == (unsigned char *)0)
break;
status = 0;
tStatus = VoltGetEncodedIdFromCert (
(VtCertObject)signerCert, encodedId, bufferSize, &encodedIdLen);
}
if (tStatus != 0)
continue;
/* Create an identity object from the encodedID. The variable may
* already be an object from a previous iteration.
*/
VtDestroyIdentityObject (&newId);
tStatus = VtCreateIdentityObject (
(VtLibCtx)libCtx, VtIdentityImplMpCtx, (Pointer)(readCtx->mpCtx),
&newId);
if (tStatus != 0)
continue;
tStatus = VtDecodeIdentity (
encodedId, encodedIdLen, readCtx->Decoders, readCtx->decoderCount,
&indexI, newId);
if (tStatus != 0)
continue;
/* Add this identity to the list.
*/
tStatus = VtAddIdObjectToIdentityList (signerList, newId, &indexI);
}
/* Now that we have a list, return int.
*/
readCtx->signerList = signerList;
*getInfo = (Pointer)(readCtx->signerList);
status = 0;
} while (0);
VtDestroyIdentityObject (&newId);
if (encodedId != (unsigned char *)0)
Z2Free (encodedId);
/* If success, we're done.
*/
if (status == 0)
return (0);
/* If error, destroy what we created.
*/
VtDestroyIdentityList (&signerList);
VOLT_LOG_ERROR_INFO (
0, pkcs7Obj, status, 0, errorType,
(char *)0, "VtPkcs7ParamSignerList", fnctLine, (char *)0)
return (status);
}
int VtPkcs7ParamSigningTime (
VtPkcs7Object pkcs7Obj,
Pointer info,
unsigned int flag
)
{
int status;
Pointer *getInfo;
VoltPkcs7Object *obj = (VoltPkcs7Object *)pkcs7Obj;
VoltPkcs7ReadSignCtx *readCtx;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* This param can Get only.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SET;
if (flag == VOLT_PKCS7_SET_TYPE_FLAG)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_PKCS7_GET_TYPE_FLAG)
break;
getInfo = (Pointer *)info;
/* Get the info only if we're done reading SignedData.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (obj->state != VOLT_P7_STATE_SIGN_READ_FINAL)
break;
VOLT_SET_FNCT_LINE (fnctLine)
readCtx = (VoltPkcs7ReadSignCtx *)(obj->localCtx);
if (readCtx->signerInfosCount == 0)
break;
// If multiple signers, check that all times the same?
*getInfo = (Pointer)&(readCtx->signerInfos[0].signingTime);
status = 0;
} while (0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -