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

📄 browsertoken.cpp

📁 voltage 公司提供的一个开发Ibe的工具包
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    {
      MessageBox (
      NULL, ERROR_FIND_CLIENT_REQUEST_MSG, "Toolkit Token Handler", MB_OK);
    }
    else
    {
      if (clientRequest == 1)
      {
        status = FulfillClientRequests (
          libCtx, mpIntCtx, clientStorage, 
          transportCtx, idObj, &responseData);
        if (status != 0) 
        {
          MessageBox (
          NULL, ERROR_FULFILL_CLIENT_REQUEST_MSG,
          APP_LABEL, MB_OK);
        }
        else
        {
          MessageBox (
            NULL, SUCCESS_FULFILL_CLIENT_REQUEST_MSG,
            APP_LABEL, MB_OK);
          DeleteClientRequestFile (libCtx, clientStorage, idObj);
        }
      }
    }

    /* Get a list of all the request infos for this identity
     */
    status = VoltArbitraryGetEntryHandle (
      arbitObj, (Pointer)&(responseData.id), &arbitHandle);
    if (status != 0)
      break;    

    if (arbitHandle->entryCount > 1)
    {      
      MessageBox (
        NULL, MULTIPLE_REQUEST_WARNING_MSG, APP_LABEL, MB_OK);
      printf ("\nThis may take some time. Please wait..");
    }

    storageIndex = 0;
    while (storageIndex < (arbitHandle->entryCount) )    
    {      
      deleteRequest = 0;
      status = VoltArbitraryRetrieveEntry (
        arbitObj, arbitHandle, storageIndex, (Pointer *)&getEntry);
      if (status != 0)
        break;

      /* First see if the storage location in the request info has already 
       * received the key and cert using toolkit. If yes contniue to the
       * next entry in the list.
       */
      reqStatus = GetRequestStatusForLocation (
        storeList, getEntry->storageLocation);
      if (reqStatus == STORAGE_STATUS_COMPLETED)
      {
        deleteRequest = 1;        
        goto cleanup;
      }     
      if (reqStatus == STORAGE_STATUS_FAILED)
      {
        storageIndex++;
        status = VT_ERROR_GENERAL;
        continue;
      }

      /* Find the latest request entry for a given location
       */
      for (unsigned int index2 = 1; index2 < arbitHandle->entryCount; index2++)
      {
        VoltTime seconds1, seconds2;
        VoltRequestInfoData *getEntry2;

        status = VoltArbitraryRetrieveEntry (
          arbitObj, arbitHandle, index2, (Pointer *)&getEntry2);
        if (status != 0)
          break;

        if (getEntry->storageLocation == (unsigned char *)0 || 
            getEntry2->storageLocation == (unsigned char *)0 )
        {
          if (getEntry->storageLocation != getEntry2->storageLocation)
            continue;
        }
        if (getEntry->storageLocation != (unsigned char *)0)
        {
          if (strcmp ( (const char *)getEntry->storageLocation,
            (const char *)getEntry2->storageLocation) != 0)
            continue;
        }
        status = VoltConvertTimeToSeconds (& (getEntry->requestTime), &seconds1);
        if (status != 0)
          break;
        status = VoltConvertTimeToSeconds (& (getEntry2->requestTime), &seconds2);
        if (status != 0)
          continue;
        if (seconds2 > seconds1)
          getEntry = getEntry2;
      }                 
      
      if (getEntry->storageType == VOLT_STORAGE_TYPE_TOOLKIT)
      {
        storageInfo.path = getEntry->storageLocation;
        passwordInfo.appData = (Pointer)getEntry->storageLocation;  

        /* Create a storage object to store the private key and signing certs
         * in the location specified in the request info.
         */
        status = VtCreateStorageCtx(
          libraryCtx, VtStorageImplBasic, (Pointer)0, &toolkitStorage);
        if (status != 0)
          break;
        status = VtAddStorageProvider (
          toolkitStorage, VtStorageFileWin32, (Pointer)&storageInfo);
        if (status != 0)
          break;

        /* Add the password manager to the storage ctx. Pass the location
         * in the local app data so that the password manager will not
         * ask for it again if it already has the password for that
         * location.
         */
        status = VtSetStorageParam (
          toolkitStorage, VtStorageParamPasswordManager,
          (Pointer)&passwordInfo);
        if (status != 0)
          break; 
        storageCtx = toolkitStorage;
      }
      else
      {
        passwordInfo.appData = (Pointer)0;
        storageCtx = clientStorage;      
      }
      if (status != 0)
        break;      

      /* First store the token in the appropriate location.
       */
      if (responseData.authToken != (char *)0)
      {
        status = storageCtx->StoreAuthToken (
          storageCtx, obj->district, (unsigned char *)responseData.authToken);   	
        if (status != 0)
          goto cleanup;
      }

      /* Now we need to download the key and cert for each pending request.
       * Even though private keys will be the same certs will be different
       * and currently there is no way to separate the two. So we have to
       * request both keys and certs for each pending request.
       */             
      if ( (getEntry->certRequestDER != (unsigned char *)0 ) &&
           (getEntry->certRequestDERLen != 0) )
      {
        status = VtCreateCertObject (
          libCtx, VtCertImplMpCtx, (Pointer)mpIntCtx, &signingCert);
        if (status != 0)
          break;

        /* create a cert request object and set the DER encoding from
         * request info file.
         */
        status = VtCreateCertRequestObject (
          libCtx, VtCertRequestImplMpCtx, (Pointer)mpIntCtx, &certReq);
        if (status != 0)
          break; 

        certInfo.derCoders = derCoders;
        certInfo.derCoderCount = coderCount;
        certInfo.certRequest = getEntry->certRequestDER;
        certInfo.certRequestLen = getEntry->certRequestDERLen;
        status = VtSetCertRequestParam (
          certReq, VtCertRequestParamP10Der, (Pointer)&certInfo);
        if (status != 0)
          goto cleanup;
      }

      /* Create the key Objects to hold the keys
       */
      if (getEntry->ibeKeyRequest != 0)
      {
        status = VtCreateKeyObject (
          libCtx, VtKeyImplMpCtx, (Pointer)mpIntCtx, &ibePriKey);
        if (status != 0)
          break;
      }   
      /* download the key and cert. We never build our own key pairs
       * or cert requests, so random object is not required.
       */
      status = VtDownloadIBEPrivateKeyAndCert (
        idObj, (VtPolicyCtx)0, storageCtx,
        transportCtx, certReq, signingCert, ibePriKey);
      if (status != 0)
        goto cleanup;  

      /* Now store the keys and certs we just downloaded
       */
      if (signingCert != (VtCertObject)0)
      {
        status = VtStoreEntry (
          libCtx, VT_ENTRY_TYPE_CERTIFICATE, 
          (Pointer)idObj, (Pointer)signingCert, storageCtx);
        if (status != 0)
        {
          _snprintf (
            errorString, 512, "%s%s", 
            "Couldn't store the downloaded cert to the location ",
            getStorageLocation (libCtx, getEntry->storageLocation)
            );
          MessageBox (NULL, errorString, APP_LABEL, MB_OK);   
        }
      }
      if (ibePriKey != (VtKeyObject)0)
      {
        status = VtStoreEntry (
          libCtx, VT_ENTRY_TYPE_IBE_PRI_KEY,
          (Pointer)idObj, (Pointer)ibePriKey, storageCtx);
        if (status != 0)
        {
          _snprintf (
            errorString, 512, "%s%s", 
            "Couldn't store the downloaded key to the location ",
            getStorageLocation (libCtx, getEntry->storageLocation)
            );
          MessageBox (NULL, errorString, APP_LABEL, MB_OK);  
        }
      }      

cleanup :           
      reqStatus = STORAGE_STATUS_COMPLETED;
      if (status != 0)
      {
        reqStatus = STORAGE_STATUS_FAILED; 
        storageIndex++;
        if (getEntry->storageLocation != NULL)
        {
          strncpy (
            errorString,
            "Some errors ocurred while processing the requests for..", 512);
          strncat (errorString, (const char *)getEntry->storageLocation, 512);
        }
        else
        {
          strncpy (
            errorString,
            "Some errors ocurred while processing the requests for storage", 512);
        }
        MessageBox (NULL, errorString, APP_LABEL, MB_OK);
      }
      /* Add this storage location to the list of locations that have
       * been serviced by the token handler whether successful or not.
       */
      AddLocationToCompletedList (
        &storeList, getEntry->storageLocation, reqStatus);

      VtDestroyCertRequestObject (&certReq);
      VtDestroyKeyObject (&ibePriKey);
      VtDestroyCertObject (&signingCert);
      VtDestroyStorageCtx (&toolkitStorage);     

      /* Delete the request info entry only if the request was fulfilled
       */
      if (deleteRequest == 1)
        VoltArbitraryDeleteEntry (arbitObj, arbitHandle, storageIndex) ;      
    }   

  } while (0);

  /* if we broke the loop because of an error we have to cleanup everything
  */
  VtDestroyIdentityObject (&idObj);
  VtDestroyCertRequestObject (&certReq);
  VtDestroyKeyObject (&ibePriKey);
  VtDestroyCertObject (&signingCert);   
  VtDestroyStorageCtx (&clientStorage);
  VtDestroyStorageCtx (&toolkitStorage);

  VoltArbitraryReleaseHandle (arbitObj, &arbitHandle);
  VoltDestroyArbitraryStorageObject (&arbitObj);

  if (status == 0)   
  {
    MessageBox (
    NULL, TOKEN_HANDLER_SUCCESSFUL_MSG , APP_LABEL , MB_OK);
  }

  else
  {    
    MessageBox (
      NULL, TOKEN_HANDLER_UNSUCCESSFUL_MSG, APP_LABEL, MB_OK);
  }

  if (contents != (unsigned char *)0)
    Z2Free (contents);  

  /* Close the file Handle and Delete the temporary file
   * That was passs in argv[2]
   */
  if( fileHandle != (VoltFileHandle)0 ) {
    fileCtx->CtxCloseFile(fileCtx, &fileHandle);
    fileCtx->CtxDeleteFile (fileCtx, &fileHandle, fileName);
  }

  /* Free the icServerResponseData and destroy all the contexts
  */
  FreeResponseData (&responseData, libCtx);  
  FreeCompletedLocationList (storeList);  

  /* Destroy the password manager.
   */
   PasswordManager (
     libraryCtx , (Pointer)0, PASSWORD_MGR_PURPOSE_DESTROY, 
     (unsigned char **)0, (unsigned int *)0, 
     (unsigned char **)0, (unsigned int *)0);

  VtDestroyFileCtx (&fCtx); 
  VtDestroyTransportCtx (&transportCtx);
  VtDestroyMpIntCtx (&mpIntCtx);  
  VtDestroyLibCtx (&libraryCtx);

  return 0;
}

int AddLocationToCompletedList (
  StorageStatus **storeList, 
  unsigned char *location,
  int status)
{  
  StorageStatus *temp = (StorageStatus *)0;
  unsigned char *ptr ;
  StorageStatus *node, *tempNode ;
  int len, offset, bufferSize;

  /* First see if this location already exists. If yes nothing to be done
  */
  if (*storeList != (StorageStatus *)0)
  {

⌨️ 快捷键说明

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