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

📄 defaulttrans.c

📁 IBE是一种非对称密码技术
💻 C
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
 */
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "transport.h"
#include "deftrans.h"
#include "vsdistrict.h"
#include "idobj.h"
#include "distobj.h"
#include "certobj.h"
#include "vstorage.h"
#include "defaultstore.h"
#include "derhelp.h"
#include "oidlist.h"
#include "ibe.h"
#include "ibekeyber.h"
#include "errorctx.h"

/* If Windows, we don't support this version yet.
 */
#if VOLT_OS != VOLT_WINDOWS_32

int VtTransportImplHttpsCurl (
   VtTransportCtx *transportCtx,
   Pointer info,
   unsigned int flag
   )
{
  int status;
  unsigned int bufferSize , offset, pathLen;
  VoltTransportCtx *ctx = (VoltTransportCtx *)(*transportCtx);
  VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
  VtCurlTransportInfo *transInfo = (VtCurlTransportInfo *)info;
  VoltDefaultTransCtx *localCtx = (VoltDefaultTransCtx *)0;
  unsigned char *buffer = (unsigned char *)0;
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  do
  {
    /* Check the flag, it should be VOLT_OBJECT_TYPE_TRANSPORT_CTX.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_TYPE;
    if (flag != VOLT_TRANSPORT_CTX_SET_TYPE_FLAG)
      break;

    /* The associated info should be a pointer to VtCurlTransportInfo.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_ASSOCIATED_INFO;
    if (transInfo == (VtCurlTransportInfo *)0)
      break;    

    /* Allocate space for a local ctx.
     */
    pathLen = 0;
    if (transInfo->trustStore != (unsigned char *)0) 
      pathLen = Z2Strlen (transInfo->trustStore);
    bufferSize = sizeof (VoltDefaultTransCtx) + pathLen + 1;

    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_MEMORY;
    buffer = (unsigned char *) Z2Malloc (bufferSize, 0);
    if (buffer == (unsigned char *)0)
      break;
    Z2Memset (buffer, 0, bufferSize);
    localCtx = (VoltDefaultTransCtx *) buffer ;
    
    /* Fill in the context fields.
     */
    offset = sizeof (VoltDefaultTransCtx);
    localCtx->uiHandle = transInfo->uiHandle ;

    if (transInfo->trustStore != (unsigned char *)0)    
    {
      localCtx->trustStore = (unsigned char *)(buffer + offset);
      Z2Memcpy (localCtx->trustStore, transInfo->trustStore, pathLen);
    }

    localCtx->asyncFlag = transInfo->asyncFlag;    
    localCtx->DoHttp = mDoHTTP;

    ctx->flag = VOLT_TRANSPORT_FLAG_DEFAULT | VOLT_TRANSPORT_FLAG_PASSWORD;
    ctx->timeout = 10000;
    ctx->localCtx = (Pointer)localCtx;
    ctx->LocalCtxDestroy = DefaultLocalTransCtxDestroy;
    ctx->DownloadParameters = VoltDefaultDownloadParameters;
    ctx->DownloadKeyAndCert = VoltDefaultDownloadKeyAndCert;
    
    status = 0;

  } while (0);

  /* If successful, we're done.
   */
  if (status == 0)
    return (0);  

  /* Free anything we created and log the error
  */
  if (buffer != (unsigned char *)0)
    Z2Free (buffer);

  VOLT_LOG_ERROR (
    (VtLibCtx)libCtx, status, errorType, fnctLine,
    "VtTransportImplHttpsCurl", (char *)0)

  return (status);
}
#endif

int VtTransportParamTimeout (
   VtTransportCtx transportCtx,
   Pointer info,
   unsigned int flag
   )
{
  int status;
  unsigned int timeout;
  VoltTransportCtx *ctx = (VoltTransportCtx *)transportCtx;
  Pointer *getInfo;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  do
  {
    /* If Get, return the timeout.
     */
    if (flag == VOLT_TRANSPORT_CTX_GET_TYPE_FLAG)
    {
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VT_ERROR_NULL_ARG;
      if (info == (Pointer)0)
        break;

      getInfo = (Pointer *)info;
      *getInfo = (Pointer)&(ctx->timeout);
      status = 0;
      break;
    }

    /* Check the flag, it should be VOLT_STORAGE_CTX_SET_TYPE_FLAG.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_TYPE;
    if (flag != VOLT_TRANSPORT_CTX_SET_TYPE_FLAG)
      break;

    /* The associated info is a pointer to an unsigned int.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_ASSOCIATED_INFO;
    if (info == (Pointer)0)
      break;

    timeout = *((unsigned int *)info);

    ctx->timeout = timeout;

    status = 0;

  } while (0);

  VOLT_LOG_ERROR_COMPARE (
    status, ctx->voltObject.libraryCtx, status, VT_ERROR_TYPE_PRIMARY,
    fnctLine, "VtTransportParamTimeout", (char *)0)

  return (status);
}

int VtTransportParamUserPassCollector (
  VtTransportCtx transportCtx,
  Pointer info,
  unsigned int flag
  )
{
  int status;  
  VoltTransportCtx *ctx = (VoltTransportCtx *)transportCtx;
  VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
  VtUserPassCollectorCallback *passCtx = (VtUserPassCollectorCallback *)0;
  VOLT_DECLARE_FNCT_LINE (fnctLine)
  VOLT_DECLARE_ERROR_TYPE (errorType)

  do
  {
    /* This TransportParam only does the set operation
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_GET_INFO_UNAVAILABLE;
    if (flag == VOLT_TRANSPORT_CTX_GET_TYPE_FLAG)
      break;

    /* Check the flag, it should be VOLT_STORAGE_CTX_SET_TYPE_FLAG.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_TYPE;
    if (flag != VOLT_TRANSPORT_CTX_SET_TYPE_FLAG)
      break;    
    
    /* Is this a provider that uses a password manager.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_SET;
    if ( (ctx->flag & VOLT_TRANSPORT_FLAG_PASSWORD) == 0)
      break;

    /* If the password collector is already set its an error
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    if (ctx->userPassCtx.UserPassFunction != (VtUserPassCollector)0)
      break;

    /* The data associated with this setparam is a pointer to a
     * VtUserPassCollectorCallback struct
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_ASSOCIATED_INFO;
    if (info == (Pointer)0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    passCtx = (VtUserPassCollectorCallback *)info;
    if (passCtx->UserPassFunction == (VtUserPassCollector)0)
      break;

    /* Make sure that if there is a data copy function there is a data free
     * function too.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    if ( (passCtx->AppDataCopy != (VtPasswordAppDataCopy)0) &&
         (passCtx->AppDataFree == (VtPasswordAppDataFree)0)  )
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    if ( (passCtx->AppDataCopy == (VtPasswordAppDataCopy)0) &&
         (passCtx->AppDataFree != (VtPasswordAppDataFree)0)  )
      break;

    ctx->userPassCtx.UserPassFunction = passCtx->UserPassFunction;
    ctx->userPassCtx.AppDataCopy = passCtx->AppDataCopy ;
    ctx->userPassCtx.AppDataFree = passCtx->AppDataFree ;
    ctx->userPassCtx.appData = passCtx->appData ;
    if ( (passCtx->AppDataCopy != (VtPasswordAppDataCopy)0) &&
         (passCtx->appData != (Pointer)0) )
    {
      ctx->userPassCtx.appData = (Pointer)0;
      status = passCtx->AppDataCopy (
        (VtLibCtx)libCtx, passCtx->appData, &(ctx->userPassCtx.appData));
      if (status != 0)
        break;
    }   

    /* everything worked 
     */
    status = 0;

  } while (0);

  if (status == 0)
    return 0;

  VOLT_LOG_ERROR (
    (VtLibCtx)libCtx, status, errorType, fnctLine,
    "VtTransportParamUserPassCollector", (char *)0)

  return (status);

}

⌨️ 快捷键说明

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