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

📄 deffilestore.c

📁 voltage 公司提供的一个开发Ibe的工具包
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright 2003-2005, Voltage Security, all rights reserved. */#include <errno.h>#include "vibe.h"#include "environment.h"#include "base.h"#include "libctx.h"#include "vsstore.h"#include "voltfile.h"#include "defaultstore.h"#include "errorctx.h"#include "stringutil.h"#if VOLT_OS != VOLT_WINDOWS_32#if VOLT_OS != VOLT_MACOSX#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/types.h>#include <sys/stat.h>#include <unistd.h>#include <dirent.h>int getICDirectory (  VoltLibCtx *libCtx,  unsigned char *buf,  int bufLen  );int VtStorageFileUnix (  VtStorageCtx storageCtx,  Pointer info,  unsigned int flag,  int providerNum   ){  int status;  unsigned int pathNameLen, bufferSize, offset;#if VOLT_ALIGNMENT != 1  unsigned int pad;#endif  VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;  VtLibCtx libraryCtx = ctx->voltObject.libraryCtx;  VoltLibCtx *libCtx = (VoltLibCtx *)libraryCtx;  unsigned char *buffer = (unsigned char *)0;  unsigned char *pathName = (unsigned char *)0;  VoltDefaultStorageCtx *localCtx =      (VoltDefaultStorageCtx *) 0;  VtFileCtx fCtx = (VtFileCtx)0;    VtFileCtxUseInfo *fInfo = (VtFileCtxUseInfo *) 0;  VOLT_DECLARE_FNCT_LINE (fnctLine)  VOLT_DECLARE_ERROR_TYPE (errorType)  do  {    /* 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_STORAGE_CTX_SET_TYPE_FLAG)      break;    /* If the associated info is not NULL pointer, it should be a     * VtFileCtxUseInfo pointer.     */    pathName = (unsigned char *)0;    pathNameLen = 0;    if (info != (Pointer)0)    {      fInfo = (VtFileCtxUseInfo *) info;      pathName = (unsigned char *)fInfo->path;      pathNameLen = Z2Strlen (pathName);      fCtx = fInfo->fileCtx;    }
       
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_ASSOCIATED_INFO;        /* If File Ctx has not been provided by the caller     * Try to use one from the Lib Ctx.     */        if( fCtx == (VtFileCtx)0 )     {      fCtx = (VtFileCtx)VoltGetLibCtxInfo (        (VtLibCtx)libCtx, VOLT_LIB_CTX_INFO_TYPE_FILE_CTX);            /* If we still don't have a valid file ctx        * We can't work. return error       */      if( fCtx == (VtFileCtx) 0 )        break;          }
    if (VOLT_OBJECT_TYPE_NOT_EQUAL (fCtx, VOLT_OBJECT_TYPE_FILE_CTX))
      break;    /* Create the local ctx along with the pathName.     */        status = VT_ERROR_MEMORY;    bufferSize =      sizeof (VoltDefaultStorageCtx) + sizeof (mIcStoreCtx) +      pathNameLen + 1 ;#if VOLT_ALIGNMENT != 1    /* If the alignment is 1, there's no need to pad. If not, compute     * the pad length.     */    VOLT_COMPUTE_ALIGN_PAD      (VOLT_ALIGNMENT, sizeof (VoltDefaultStorageCtx), pad)    bufferSize += pad;#endif    VOLT_SET_FNCT_LINE (fnctLine)    buffer = (unsigned char *)Z2Malloc (bufferSize, 0);    if (buffer == (unsigned char *)0)      break;    Z2Memset (buffer, 0, bufferSize);    /* Set the fields.     */    localCtx = (VoltDefaultStorageCtx *)buffer;    offset = sizeof (VoltDefaultStorageCtx);#if VOLT_ALIGNMENT != 1    offset += pad;#endif    localCtx->icStoreCtx = (Pointer)(buffer + offset);    if (pathNameLen != 0)    {      offset += sizeof (mIcStoreCtx);      localCtx->pathName = (char *)(buffer + offset);      Z2Memcpy (localCtx->pathName, pathName, pathNameLen);      localCtx->pathNameLen = pathNameLen;    }    /* Clone the File context object to keep a local copy    * of file context. We may need it later..    */    VOLT_SET_ERROR_TYPE (errorType, 0)    VOLT_SET_FNCT_LINE (fnctLine)    status = VtCloneObject ((Pointer)fCtx, (Pointer *)&(localCtx->fCtx) );    if( status != 0)        break;    VOLT_SET_FNCT_LINE (fnctLine)    status = mIcStorageSetup (      libCtx, (mIcStoreCtx *)(localCtx->icStoreCtx));    if (status != 0)      break;    /* Set the fields of the provider struct.     */    ctx->providerNum                  = providerNum;    ctx->storageTypeFlag              = VOLT_STORAGE_TYPE_TOOLKIT;    ctx->localStorageCtx              = (Pointer)localCtx;    ctx->LocalStorageCtxDestroy       = VoltDefaultStorageCtxDestroy;    ctx->SetExtraPassword             = VoltDefaultSetExtraPassword;    ctx->GetEnvelopeKey               = VoltDefaultGetEnvelopeKey;    ctx->StoreCurrentDistrict         = VoltDefaultStoreCurrentDistrict;    ctx->StoreDistrictParameters      = VoltDefaultStoreDistrictParameters;    ctx->StoreAuthToken               = VoltDefaultStoreAuthToken;    ctx->StoreIBEPrivateKey           = VoltDefaultStoreIBEPrivateKey;    ctx->StorePrivateSigningKey       = VoltDefaultStorePrivateSigningKey;    ctx->StorePublicSigningCert       = VoltDefaultStorePublicSigningCert;    ctx->GetDistrictParameterCount    = VoltDefaultGetDistrictParameterCount;    ctx->GetIBEPrivateKeyCount        = VoltDefaultGetIBEPrivateKeyCount;    ctx->GetPrivateSigningKeyCount    = VoltDefaultGetPrivateSigningKeyCount;    ctx->GetPublicSigningCertCount    = VoltDefaultGetPublicSigningCertCount;    ctx->GetAuthTokenCount            = VoltDefaultGetAuthTokenCount;    ctx->RetrieveNewAuthTokens        = VoltDefaultRetrieveNewAuthTokens;    ctx->RetrieveCurrentDistrictAlloc = VoltDefaultRetrieveCurrentDistrictAlloc;    ctx->RetrieveDistrictParameters   = VoltDefaultRetrieveDistrictParameters;    ctx->RetrieveIBEPrivateKey        = VoltDefaultRetrieveIBEPrivateKey;    ctx->RetrievePrivateSigningKey    = VoltDefaultRetrievePrivateSigningKey;    ctx->RetrievePublicSigningCert    = VoltDefaultRetrievePublicSigningCert;    ctx->DeleteCurrentDistrict        = VoltDefaultDeleteCurrentDistrict;    ctx->DeleteDistrictParameters     = VoltDefaultDeleteDistrictParameters;    ctx->DeleteIBEPrivateKey          = VoltDefaultDeleteIBEPrivateKey;    ctx->DeletePrivateSigningKey      = VoltDefaultDeletePrivateSigningKey;    ctx->DeletePublicSigningCert      = VoltDefaultDeletePublicSigningCert;    ctx->DeleteAuthToken              = VoltDefaultDeleteAuthToken;  } while (0);  /* If success, we're done.   */  if (status == 0)    return (0);  /* If error, free up any memory we allocated.   */  VoltDefaultStorageCtxDestroy ((Pointer)storageCtx, (Pointer) localCtx);    return (status);}int getICDirectory (  VoltLibCtx *libCtx,  unsigned char *buf,  int bufLen  ){    char *VoltageName = ".Voltage"; /* hidden directory */  char *home_dir;  char *cur_dir = (char *)0 ;  char *dir_path;  int len, VoltageNameLen;     Z2Memset (buf, 0, bufLen);  VoltageNameLen = Z2Strlen (VoltageName);  /* The default directory where the crypto data is stored   * is <HOME_DIR>/.Voltage   */  home_dir = getenv ("HOME");  dir_path = home_dir;  /* unlikely but getenv can return NULL for home dir   * In that case use current dir   */  if (home_dir == (char *)0 )   {    cur_dir = getcwd ( (char *)0, VOLT_MAX_PATH );    dir_path = cur_dir;      }  do   {    /* If we still don't have a valid path return empty string     * No need to free cur_dir var.     */    if ( dir_path == (char *)0 )     {      buf[0] = '\0';      break;    }    len = Z2Strlen (dir_path);    /* Full path is dir_path + '/' + ".Voltage"     */    if ( bufLen < len + VoltageNameLen + 2 )      break;    /* dir_path may point to a memory that belongs to the system     * Don't modify the pointers returned by getenv function     * instead make a copy and use it     */    Z2Memcpy (buf, dir_path, len);     /* Append /Voltage to the buf + string terminationg character.     */    buf[len] = '/';    Z2Memcpy (buf + len +1, VoltageName, VoltageNameLen+1);  } while (0);  /* Free any memory that was allocated by getcwd. Since getcwd uses  *  malloc to allocate the memory we must use free to free it.   */  if (cur_dir != (char *)0 )    free (cur_dir); 

  return (0);}int mIcStoreData (   VoltStorageCtx *prov,   unsigned char *data,   unsigned int dataLen,     unsigned char *extraPassword,   unsigned int extraPasswordLen,   VoltFileCtx *fileCtx,   VoltFileHandle fileHandle   ){  int status;  /* On unix we don't store the crypto data encrypted   * Rather we set the permissions on the file so that   * only authorized people can access them.   */  status = fileCtx->CtxWriteFile (      fileCtx,       fileHandle,       data,       dataLen);    return (status);}int mIcLoadDataAlloc (   VoltStorageCtx *prov,   VoltFileCtx *fileCtx,   VoltFileHandle fileHandle,   unsigned char *extraPassword,   unsigned int extraPassowrdLen,   unsigned char **data,   unsigned int *dataLen      ){  int status;   unsigned int contentsLen;  VoltFileInt fileSize;

⌨️ 快捷键说明

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