⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 p7settype.c

📁 voltage 公司提供的一个开发Ibe的工具包
💻 C
📖 第 1 页 / 共 2 页
字号:
     * 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);

  return (status);
}

int VtPkcs7ParamRecipient (
   VtPkcs7Object pkcs7Obj,
   Pointer info,
   unsigned int flag
   )
{
  int status;
  VoltPkcs7Object *obj = (VoltPkcs7Object *)pkcs7Obj;
  VoltPkcs7ReadEnvCtx *readCtx = (VoltPkcs7ReadEnvCtx *)(obj->localCtx);
  VtPkcs7RecipientInfo *recipInfo;

  do
  {
    /* This Param cannot get info.
     */
    status = VT_ERROR_INVALID_GET;
    if (flag == VOLT_PKCS7_GET_TYPE_FLAG)
      break;

    status = VT_ERROR_INVALID_TYPE;
    if (flag != VOLT_PKCS7_SET_TYPE_FLAG)
      break;

    /* The object must be set to read EnvelopedData.
     */
    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.
     */
    if ( (readCtx->priKey != (VtKeyObject)0) ||
         (readCtx->priKeyRef != (VtKeyObject)0) ||
         (readCtx->specifiedIdentity != (VtIdentityObject)0) )
      break;

    /* The info should be a pointer to a VtPkcs7RecipientInfo
     * struct.
     */
    status = VT_ERROR_INVALID_ASSOCIATED_INFO;
    if (info == (Pointer)0)
      break;

    recipInfo = (VtPkcs7RecipientInfo *)info;

    if (recipInfo->identity == (VtIdentityObject)0)
      break;
    if (VOLT_OBJECT_TYPE_NOT_EQUAL (
      recipInfo->identity, VOLT_OBJECT_TYPE_IDENTITY))
      break;

    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.
     */
    status = VtCloneObject (
      (Pointer)(recipInfo->identity), (Pointer *)&(readCtx->specifiedIdentity));

  } while (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;

  bufferSize = 0;

  do
  {
    /* This param can Get only.
     */
    status = VT_ERROR_INVALID_SET;
    if (flag == VOLT_PKCS7_SET_TYPE_FLAG)
      break;

    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.
     */
    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.
     */
    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)
      {
        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);

  return (status);
}

int VtPkcs7ParamSigningTime (
   VtPkcs7Object pkcs7Obj,
   Pointer info,
   unsigned int flag
   )
{
  int status;
  Pointer *getInfo;
  VoltPkcs7Object *obj = (VoltPkcs7Object *)pkcs7Obj;
  VoltPkcs7ReadSignCtx *readCtx;

  do
  {
    /* This param can Get only.
     */
    status = VT_ERROR_INVALID_SET;
    if (flag == VOLT_PKCS7_SET_TYPE_FLAG)
      break;

    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.
     */
    status = VT_ERROR_GET_INFO_UNAVAILABLE;
    if (obj->state != VOLT_P7_STATE_SIGN_READ_FINAL)
      break;

    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);

  return (status);
}

int VoltGetSignerIdObjRef (
   VtPkcs7Object p7Obj,
   unsigned int index,
   VtIdentityObject *signerRef
   )
{
  int status;
  VoltPkcs7Object *obj = (VoltPkcs7Object *)p7Obj;
  VoltPkcs7WriteSignCtx *signCtx = (VoltPkcs7WriteSignCtx *)(obj->localCtx);

  *signerRef = (VtIdentityObject)0;

  do
  {
    /* It must be a SignedData object.
     */
    status = VT_ERROR_NO_ID_AT_INDEX;
    if (obj->contentType != VT_PKCS7_SIGNED_DATA)
      break;

    /* Is there a signer at the index?
     */
    if (index >= signCtx->signerInfosCount)
      break;

    /* Do we have an ID object for this signer?
     */
    if (signCtx->signerInfos[index].signerId == (VtIdentityObject)0)
      break;

    *signerRef = signCtx->signerInfos[index].signerId;
    status = 0;

  } while (0);

  return (status);
}

⌨️ 快捷键说明

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