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

📄 browsertoken.cpp

📁 voltage 公司提供的一个开发Ibe的工具包
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    node = *storeList;
    while (node != (StorageStatus *)0 )
    {
      if (node->path == (unsigned char *)0 || location == (unsigned char *)0)
      {
        if (node->path == location)
          return 0;
        else
          goto NextNode;
      }    

      if (strcmp ( (const char *)node->path, (const char *)location) == 0)
        return 0;

NextNode :
      tempNode = node;
      node = node->next;
    }
  }

  /* The location doesn't exist so we need to create and add it
  */
  len = 0;
  if (location != (unsigned char *)0)
    len = (int)strlen ( (const char *)location) + 1;

  bufferSize = len + sizeof (StorageStatus) ;
  temp = (StorageStatus *)malloc (bufferSize);
  if (temp == (StorageStatus *)0)
    return VT_ERROR_MEMORY;

  ptr = (unsigned char *)temp;
  offset = sizeof (StorageStatus);  
  temp->requestStatus = status;
  temp->next = (StorageStatus *)0;
  temp->path = (unsigned char *)0;
  if (location != (unsigned char *)0)
  {
    memcpy (ptr + offset, location, len);  
    temp->path = ptr + offset; 
  }

  if (*storeList == (StorageStatus *)0) 
  {
    *storeList = temp;
    return 0;
  }

  /* We have to add this location to the end of the list
  */
  node = *storeList;
  while (node->next != (StorageStatus *)0)
    node = node->next;

  node->next = temp;

  return 0;
}

int GetRequestStatusForLocation (
  StorageStatus *storeList, 
  unsigned char *location)
{
  StorageStatus *node ;
  if (storeList == (StorageStatus *)0)
    return STORAGE_STATUS_PENDING;

  node = storeList;
  do
  {
    /* If one is NULL and the other is not, return 0.
     * if both of them are null return 1
     */
    if (node->path == (unsigned char *)0 ||
      location == (unsigned char *)0)
    {
      if (location == node->path)
        return node->requestStatus;

      goto NEXT_NODE;
    }

    /* both of the paths are non NULL. So do a string comparision
     */
    if (strcmp ((const char *)node->path , (const char *)location) == 0)
      return node->requestStatus;

NEXT_NODE :
    node = node->next;

  } while (node != (StorageStatus *)0) ;

  return STORAGE_STATUS_PENDING;
}

void FreeCompletedLocationList (StorageStatus *storeList)
{
  StorageStatus *node, *preNode ;

  if (storeList == (StorageStatus *)0)
    return ;

  node = preNode = storeList;
  while (node != (StorageStatus *)0)
  {
    node = preNode->next;
    free (preNode);
    preNode = node;
  }
}

int FulfillClientRequests (
  VtLibCtx libCtx, 
  VtMpIntCtx mpIntCtx,
  VtStorageCtx storageCtx, 
  VtTransportCtx transportCtx,
  VtIdentityObject idObj,
  icServerResponseData *response)
{
  int status;  
  VoltFileCtx *fileCtx = (VoltFileCtx *)0;
  VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
  VoltIdentityObject *obj = (VoltIdentityObject *)0;
  VtParameterObject dsaParamObj = (VtParameterObject)0;
  VtKeyObject dsaPubKey = (VtKeyObject)0;
  VtKeyObject dsaPriKey = (VtKeyObject)0;  
  VtKeyObject ibePriKey = (VtKeyObject)0;  
  VtRandomObject random = (VtRandomObject)0;
  VtCertRequestObject certReq = (VtCertRequestObject)0;
  VtCertObject signingCert = (VtCertObject)0;   

  obj = (VoltIdentityObject *)idObj;
  do
  {
    /* Store the auth token to the client storage if it is not null.
     */	
    if (response->authToken != (char *)0)
    {
      status = VoltClientStoreAuthToken (
        storageCtx, obj->district, (unsigned char *)response->authToken);   	
      if (status != 0)
        break;
    }

    /* For client we need to create a new DSA key pair and request
     * private key and signing cert.
     */
    /* First create all the required objects
     */
    status = VtCreateRandomObject (
      libCtx, VtRandomImplOpenSSLAutoSeed, (Pointer)mpIntCtx, &random);
    if (status != 0)
      break;
    status = GetFixedDsaParams (libCtx, mpIntCtx, &dsaParamObj);
    if (status != 0)
      break;      
    status = BuildDsaKeyPair (
      libCtx, mpIntCtx, random, dsaParamObj, &dsaPubKey, &dsaPriKey);
    if (status != 0)
      break;
    status = VtCreateCertRequestObject (
      libCtx, VtCertRequestImplMpCtx, (Pointer)mpIntCtx, &certReq);
    if (status != 0)
      break;  
    status = VtGenerateCertRequest (
      idObj, dsaPubKey, dsaPriKey, VtCertRequestTypeP10DSA,
      (Pointer)random, certReq);      
    if (status != 0)
      break;  

    /* Get the private key.
    */
    status = VtCreateKeyObject (
      libCtx, VtKeyImplMpCtx, (Pointer)mpIntCtx, &ibePriKey);
    if (status != 0)
      break;
    status = VtCreateCertObject (
      libCtx, VtCertImplMpCtx, (Pointer)mpIntCtx, &signingCert);
    if (status != 0)
      break;
    status = VtObtainIBEPrivateKeyAndSigningCert (
      idObj, (VtPolicyCtx)0, storageCtx, transportCtx,
      certReq, signingCert, ibePriKey);
    if (status != 0)
      break;
    status = VtStoreEntry (
      libCtx, VT_ENTRY_TYPE_SIGNING_PRI_KEY, 
      (Pointer)idObj, (Pointer)dsaPriKey, storageCtx);

  } while (0);

  /* Destroy whatever we created
   */
  VtDestroyRandomObject (&random);
  VtDestroyCertRequestObject (&certReq);
  VtDestroyCertObject (&signingCert);
  VtDestroyParameterObject (&dsaParamObj);
  VtDestroyKeyObject (&ibePriKey);
  VtDestroyKeyObject (&dsaPubKey);
  VtDestroyKeyObject (&dsaPriKey);  

  return status;
}

int isClientRequestPending (
  VtLibCtx libraryCtx, 
  VtStorageCtx storageCtx,
  VtIdentityObject idObj, 
  int *result)
{
  int status;  
  unsigned int districtNameLen, fileNameLen, offset ;
  unsigned char filePath [MAX_FILE_PATH];
  VoltIdentityObject *obj = (VoltIdentityObject *)idObj;  
  VoltLibCtx *libCtx = (VoltLibCtx *)libraryCtx;
  VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
  VoltFileCtx *fileCtx = (VoltFileCtx *)0;  
  VoltFileHandle fileHandle = (VoltFileHandle)0;
  VoltDefaultStorageCtx *defStorageCtx;
  VtItem *getName = (VtItem *)0;
  unsigned char *fileName = (unsigned char *)0;
  unsigned char *districtName ;

  districtName = obj->district->qualDistrictName.data ;
  districtNameLen = obj->district->qualDistrictName.len;

  /* Get the File Ctx
  */
  defStorageCtx = (VoltDefaultStorageCtx *)ctx->localStorageCtx;
  fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;

  *result = 0;
  do
  {
    /* Get the email from the identity
     */
    status = VtGetIdentityParam (idObj, VtIdentityParamCommonName, (Pointer *)&getName);
    if (status != 0)
      break;
    status = VoltGetFileNameFromValueAlloc (
      ctx, districtName, districtNameLen,
      (unsigned char *)0, 0, VOLT_FILE_NAME_VALUE_TYPE_ACTIVE_ENROLLMENT,
      &fileName, &fileNameLen);
    if (status != 0)
      break;

    offset = fileNameLen;
    Z2Memcpy (filePath, fileName, fileNameLen);
    filePath [offset] = '\\';
    offset++;
    Z2Memcpy (filePath + offset, getName->data, getName->len);
    offset += getName->len;
    filePath[offset] = 0;

    /* If the file with this path exists we have a pending request otherwise not
     */
    status = fileCtx->CtxOpenFile (
      fileCtx, &fileHandle, filePath, VOLT_FILE_MODE_READ_ONLY, 0600);
    if (status == VT_ERROR_FILE_DOES_NOT_EXIST)
    {
      status = 0;
      break;
    }

    /* Other errors pass on..
     */
    if (status != 0)
      break;

    *result = 1;

  } while (0);

   fileCtx->CtxCloseFile(fileCtx, &fileHandle);
   if (fileName != (unsigned char *)0)
     Z2Free (fileName);

   return status;
}

void DeleteClientRequestFile (
VtLibCtx libraryCtx, 
VtStorageCtx storageCtx, 
VtIdentityObject idObj)
{
  int status;  
  unsigned int districtNameLen, fileNameLen, offset ;
  unsigned char filePath [MAX_FILE_PATH];
  VoltIdentityObject *obj = (VoltIdentityObject *)idObj;  
  VoltLibCtx *libCtx = (VoltLibCtx *)libraryCtx;
  VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
  VoltFileCtx *fileCtx = (VoltFileCtx *)0;    
  VoltDefaultStorageCtx *defStorageCtx;
  VtItem *getName = (VtItem *)0;
  unsigned char *fileName = (unsigned char *)0;
  unsigned char *districtName ;

  districtName = obj->district->qualDistrictName.data ;
  districtNameLen = obj->district->qualDistrictName.len;

  /* Get the File Ctx
  */
  defStorageCtx = (VoltDefaultStorageCtx *)ctx->localStorageCtx;
  fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;

  do
  {
    /* Get the email from the identity
     */
    status = VtGetIdentityParam (idObj, VtIdentityParamCommonName, (Pointer *)&getName);
    if (status != 0)
      break;
    status = VoltGetFileNameFromValueAlloc (
      ctx, districtName, districtNameLen,
      (unsigned char *)0, 0, VOLT_FILE_NAME_VALUE_TYPE_ACTIVE_ENROLLMENT,
      &fileName, &fileNameLen);
    if (status != 0)
      break;

    offset = fileNameLen;
    Z2Memcpy (filePath, fileName, fileNameLen);
    filePath [offset] = '\\';
    offset++;
    Z2Memcpy (filePath + offset, getName->data, getName->len);
    offset += getName->len;
    filePath[offset] = 0;

    fileCtx->CtxDeleteFile (fileCtx, (VoltFileHandle *)0, filePath);

  } while (0);
  

   if (fileName != (unsigned char *)0)
     Z2Free (fileName);
}

#ifdef  __cplusplus
}
#endif

⌨️ 快捷键说明

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