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

📄 vsserver.c

📁 IBE是一种非对称密码技术
💻 C
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
 */
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "vsdistrict.h"
#include "errorctx.h"

int mIcServerCreateObject (
   VtLibCtx libraryCtx,
   VDoHttp DoHttp,
   Pointer uiHandle,
   unsigned char *trustStore,
   unsigned long timeOut,
   mIcServerObject **mIcServerObj
   )
{
  int status;
  mIcServerObject *newObj = (mIcServerObject *)0;
  VoltLibCtx *libCtx = (VoltLibCtx *)libraryCtx;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  do
  {
    /* Create an empty struct.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_MEMORY;
    newObj = (mIcServerObject *)Z2Malloc (sizeof (mIcServerObject), 0);
    if (newObj == (mIcServerObject *)0)
      break;
    Z2Memset (newObj, 0, sizeof (mIcServerObject));

    /* Fill in the fields.
     */
    newObj->libCtx = libCtx;
    newObj->DoHttp = mDoHTTP;
    newObj->uiHandle = uiHandle;
    newObj->trustStore = trustStore;
    newObj->timeOut = timeOut;
    if (DoHttp != (VDoHttp)0)
      newObj->DoHttp = DoHttp;

    *mIcServerObj = newObj;

    status = 0;

  } while (0);

  VOLT_LOG_ERROR_COMPARE (
    status, (VtLibCtx)libCtx, status, VT_ERROR_TYPE_PRIMARY, fnctLine,
    "mIcServerCreateObject", (char *)0)

  return (status);
}

void mIcServerDestroyObject (
   mIcServerObject **mIcServerObj
   )
{
  mIcServerObject *obj;
  VoltLibCtx *libCtx;

  /* Anything to destroy?
   */
  if (mIcServerObj == (mIcServerObject **)0)
    return;
  if (*mIcServerObj == (mIcServerObject *)0)
    return;

  obj = *mIcServerObj;
  libCtx = obj->libCtx;

  if (obj->serverResponseData.authToken != (char *)0)
    Z2Free (obj->serverResponseData.authToken);
  if (obj->serverResponseData.url != (char *)0)
    Z2Free (obj->serverResponseData.url);

  if (obj->serverResponseData.privateKey != (unsigned char *)0)
    Z2Free (obj->serverResponseData.privateKey);

  /* The outer shell used the libCtx Malloc.
   */
  Z2Free (obj);
  *mIcServerObj = (mIcServerObject *)0;
}

int mIcServerRequest (
   mIcServerObject *mIcServerObj,
   VoltIdentityObject *idObj,
   VoltTransportCtx *transCtx
   )
{
  int status;
  VoltLibCtx *libCtx = (VoltLibCtx *)transCtx->voltObject.libraryCtx;
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)
  
  VOLT_SET_ERROR_TYPE (errorType, 0)
  VOLT_SET_FNCT_LINE (fnctLine);
  status = icServerRequest (
    idObj, &(mIcServerObj->serverResponseData), &(mIcServerObj->icRet),
    mIcServerObj->serverRequestData, mIcServerObj->DoHttp,
    (void *)(mIcServerObj->uiHandle), mIcServerObj->trustStore,
    mIcServerObj->timeOut, transCtx);

  if (status == 0)
  {
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    switch (mIcServerObj->icRet)
    {
      case 0:
      case IC_SERVER_KEY_RETURNED_RESPONSE:
        /* If the return was 0 or KEY_RETURNED_RESPONSE, the function
         * obtained the values and they are located in the
         * serverResponseData struct.
         */
        break;

      default:
        VOLT_SET_FNCT_LINE (fnctLine)
        status = VT_ERROR_INVALID_INPUT;
        break;

      case VT_ERROR_MEMORY :
        VOLT_SET_FNCT_LINE (fnctLine)
        status = VT_ERROR_MEMORY;
        break;

      case IC_SERVER_GOTO_URL_RESPONSE:
        VOLT_SET_FNCT_LINE (fnctLine)
        status = VT_ERROR_ASYNC_DOWNLOAD;
        break;

      case IC_SERVER_AUTHORIZATION_DENIED_RESPONSE:
        /* Authentication worked, the identity was simply not authorized.
         */
        VOLT_SET_FNCT_LINE (fnctLine)
        status = VT_ERROR_AUTHORIZATION_DENIED;
        break;

      case IC_SERVER_SYSTEM_ERROR_RESPONSE:
      case IC_SERVER_CLIENT_OBSOLETE_RESPONSE:
      case IC_SERVER_INVALID_REQUEST_RESPONSE:
      case IC_SERVER_BAD_RESPONSE_ERR:
        /* Malformed request.
         */
        VOLT_SET_FNCT_LINE (fnctLine)
        status = VT_ERROR_INVALID_ENCODING;
        break;

      case IC_SERVER_INVALID_DISTRICT_RESPONSE:
        /* District doesn't handle the identity.
         */
        VOLT_SET_FNCT_LINE (fnctLine)
        status = VT_ERROR_WRONG_DISTRICT;
        break;

      case IC_SERVER_CONNECT_ERR:
        /* Couldn't connect to the server.
         */
        VOLT_SET_FNCT_LINE (fnctLine)
        status = VT_ERROR_NETWORK_CONNECT;
    }
  }

  VOLT_LOG_ERROR_COMPARE (
    status, (VtLibCtx)libCtx, status, errorType, fnctLine,
    "mIcServerRequest", (char *)0)

  return (status);
}

int mIcDistrictToServerAlloc (
   VoltLibCtx *libCtx,
   VoltDistrictObject *distObj,
   char **policyServer
   )
{
  int status;
  unsigned int nameLen;
  char *temp = (char *)0;
  char *retVal = (char *)0;
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  do
  {
    /* Get the district name as a NULL-terminated string.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_DIST_OBJ;
    if (distObj->qualDistrictName.data == (unsigned char *)0)
      break;

    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = icDistrictToServer (
      (char *)(distObj->qualDistrictName.data), &temp, libCtx);
    if (status != 0)
      break;

    /* Copy the name into a Z2 buffer. One extra character for the
     * NULL-terminating character.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_MEMORY;
    nameLen = Z2Strlen (temp);
    retVal = Z2Malloc (nameLen + 1, 0);
    if (retVal == (char *)0)
      break;
    Z2Memcpy (retVal, temp, nameLen);
    retVal[nameLen] = 0;

    *policyServer = retVal;

    status = 0;

  } while (0);

  if (temp != (char *)0)
    Z2Free (temp);

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

  /* If error, free the memory we allocated.
   */
  if (retVal != (char *)0)
    Z2Free (retVal);

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

  return (status);
}

⌨️ 快捷键说明

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