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

📄 clientstore.c

📁 IBE是一种非对称密码技术
💻 C
📖 第 1 页 / 共 5 页
字号:
     * we don't have any entries so count is 0 in that case.
     */
    if (ret == ERROR_FILE_NOT_FOUND)
    {
      *count = 0;
      status = 0;
      break;
    }

    /* Any other error pass on
    */
    if (ret != ERROR_SUCCESS)
      break;

    /* If there's no reference, return the count of all parameter sets.
     */
    if (qualName == (unsigned char *)0)
    {
      /* If an unqualified name is given, but no qualified name, this
       * provider can't return a count.
       */
      VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VT_ERROR_INVALID_STORAGE_REF;
      if (unqualName != (unsigned char *)0)
        break;

      VOLT_SET_ERROR_TYPE (
        errorType, VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM)
      status = VT_ERROR_READ_REGISTRY_VALUE ;
      ret = RegQueryInfoKey (
        paramKey, NULL, NULL, NULL, NULL, NULL, 
        NULL, &valueCount, NULL, NULL, NULL, NULL);
      if (ret != ERROR_SUCCESS)
        break;

      *count = valueCount;
      status = 0;
      break;
    }

    /* If there's no qualified name, this provider can't come up with
     * an answer.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_STORAGE_REF;
    if (obj->qualDistrictName.data == (unsigned char *)0)
      break;

    /* If there is a value in registry for given district
     * we have got parameters otherwise not
     */
    VOLT_SET_ERROR_TYPE (
      errorType, VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM)
    status = VT_ERROR_READ_REGISTRY_VALUE;
    ret = RegQueryValueEx (
        paramKey, obj->qualDistrictName.data, NULL, NULL, NULL, &paramLen);
    if (ret == ERROR_FILE_NOT_FOUND)
    {   
      *count = 0;
      status = 0;
      break;
    }
    if (ret != ERROR_SUCCESS)    
      break;

    /* If we are here, We were able to retrieve the registry value.
     * Make sure its not empty.
     */
    status = 0;
    *count = 1;
    if (paramLen <= 1)
      *count = 0;

  } while (0);

  if (paramKey != (HKEY)0)
    RegCloseKey (paramKey);

  VOLT_LOG_ERROR_INFO_COMPARE (
    status, 0, storageCtx, status, ret, errorType,
    (char *)0, "VoltClientGetDistrictParameterCount", fnctLine, (char *)0)

  return (status);
}

int VoltClientGetPrivateSigningKeyCount (
   VtStorageCtx storageCtx,
   VtIdentityObject reference,
   unsigned int *count
   )
{
  int status;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  VOLT_SET_FNCT_LINE (fnctLine)
  status = VoltGetEntryCountFromIdentity (
    storageCtx, reference, count, VOLT_STORE_DIR_SIGN_KEYS_CLIENT,
    VOLT_STORE_DIR_SIGN_KEYS_CLIENT_LEN,
    VOLT_FILE_NAME_VALUE_TYPE_SIGN_PRI_CLIENT);

  VOLT_LOG_ERROR_INFO_COMPARE (
    status, 0, storageCtx, status, 0, 0,
    (char *)0, "VoltClientGetPrivateSigningKeyCount", fnctLine, (char *)0)

  return (status);
}

int VoltClientGetIBEPrivateKeyCount (
   VtStorageCtx storageCtx,
   VtIdentityObject reference,
   unsigned int *count
   )
{
  int status;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  VOLT_SET_FNCT_LINE (fnctLine)
  status = VoltGetEntryCountFromIdentity (
    storageCtx, reference, count, VOLT_STORE_DIR_IBE_KEYS_CLIENT,
    VOLT_STORE_DIR_IBE_KEYS_CLIENT_LEN,
    VOLT_FILE_NAME_VALUE_TYPE_IBE_PRI_CLIENT);

  VOLT_LOG_ERROR_INFO_COMPARE (
    status, 0, storageCtx, status, 0, 0,
    (char *)0, "VoltClientGetIBEPrivateKeyCount", fnctLine, (char *)0)

  return (status);
}

int VoltClientGetPublicSigningCertCount (
   VtStorageCtx storageCtx,
   VtIdentityObject reference,
   unsigned int *count
   )
{
  int status;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  VOLT_SET_FNCT_LINE (fnctLine)
  status = VoltGetEntryCountFromIdentity (
    storageCtx, reference, count, VOLT_STORE_DIR_SIGN_CERTS_CLIENT,
    VOLT_STORE_DIR_SIGN_CERTS_CLIENT_LEN,
    VOLT_FILE_NAME_VALUE_TYPE_CERT_CLIENT);

  VOLT_LOG_ERROR_INFO_COMPARE (
    status, 0, storageCtx, status, 0, 0,
    (char *)0, "VoltClientGetPublicSigningCertCount", fnctLine, (char *)0)

  return (status);
}

int VoltClientGetAuthTokenCount (
   VtStorageCtx storageCtx,
   VtDistrictObject reference,
   unsigned int *count
   )
{
  int status;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  VOLT_SET_FNCT_LINE (fnctLine)
  status =  VoltGetAuthTokenCountForDistrict (
    storageCtx, reference, count, VOLT_FILE_NAME_VALUE_TYPE_IBE_TOKEN_CLIENT);

  VOLT_LOG_ERROR_INFO_COMPARE (
    status, 0, storageCtx, status, 0, 0,
    (char *)0, "VoltClientGetAuthTokenCount", fnctLine, (char *)0)

  return (status);
}

int VoltClientRetrieveNewAuthTokens (
   VtStorageCtx storageCtx,
   VtDistrictObject reference,
   VoltAuthTokenListObject *tokenListObj,
   unsigned int *newTokenCount
   )
{
  int status;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  VOLT_SET_FNCT_LINE (fnctLine)
  status = VoltRetrieveNewAuthTokensForDistrict (
    storageCtx, reference, tokenListObj, 
    newTokenCount,VOLT_FILE_NAME_VALUE_TYPE_IBE_TOKEN_CLIENT);

  VOLT_LOG_ERROR_INFO_COMPARE (
    status, 0, storageCtx, status, 0, 0,
    (char *)0, "VoltClientRetrieveNewAuthTokens", fnctLine, (char *)0)

  return (status);
}

int VoltClientRetrieveIBEPrivateKey (
   VtStorageCtx storageCtx,
   VtIdentityObject reference,
   VtPolicyCtx policyCtx,
   unsigned int index,
   VtKeyObject keyObj
   )
{
  int status;
  unsigned int fileNameLen, contentsLen, distNameLen, bufferSize;
  unsigned int passwordLen;
  VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
  VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
  VoltDefaultStorageCtx *defStorageCtx =
    (VoltDefaultStorageCtx *)(ctx->localStorageCtx);
  VoltFileCtx *fileCtx = (VoltFileCtx *)(defStorageCtx->fCtx);
  VoltIdentityObject *idObj = (VoltIdentityObject *)reference;
  VtDistrictObject district = (VtDistrictObject)0;
  VoltDistrictObject *distObj;
  VoltParameterObject *paramObj;
  VoltKeyObject *key = (VoltKeyObject *)keyObj;
  unsigned char *password = (unsigned char *)0;
  unsigned char *fileName = (unsigned char *)0;
  unsigned char *backupName = (unsigned char *)0;
  unsigned char *nameToUse;
  unsigned char *contents = (unsigned char *)0;
  unsigned char *distName = (unsigned char *)0;
  VoltFileHandle fileHandle = (VoltFileHandle)0;
  VtFileNameList *nameList = (VtFileNameList *)0;
  Asn1IBEPrivateKey *asn1PriKey = (Asn1IBEPrivateKey *)0;
  VtBFType1IBEPoint *ibePoint = (VtBFType1IBEPoint *)0;
  VtBFType1IBEPriKeyInfo priKeyInfo;
  VtTime timeOfStore;
  VtDerCoder *derCoders[1] = { VtDerCoderBFType1IBEPrivateKey };
  unsigned int derCoderCount = 1;
  VtSetKeyBerInfo berInfo;
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  Z2Memset (&berInfo, 0, sizeof (VtSetKeyBerInfo));
  Z2Memset (&priKeyInfo, 0, sizeof (VtBFType1IBEPriKeyInfo));

  do
  {
    /* If the keyObj is already set, error.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_KEY_OBJ;
    if (key->keyType != 0)
      break;

    /* If there's no reference, get whatever value is at the index.
     */
    if (reference == (VtIdentityObject)0)
    {
      VOLT_SET_ERROR_TYPE (errorType, 0)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VoltGetStorageFileListAlloc (
        ctx, VOLT_STORE_DIR_IBE_KEYS_CLIENT,
        VOLT_STORE_DIR_IBE_KEYS_CLIENT_LEN, 0, &nameList);
      if (status != 0)
        break;
      
      VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VT_ERROR_ENTRY_NOT_FOUND;
      if (nameList == (VtFileNameList *)0)
        break;
      
      if (index >= nameList->nameCount)
        break;

      nameToUse = nameList->nameList[index];
    }
    else
    {
      /* We need the identity encoded.
       */
      VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VT_ERROR_INVALID_STORAGE_REF;
      if (idObj->encoding.data == (unsigned char *)0)
        break;

      /* Get the file name as if it's in the toolkit directory.
       */
      VOLT_SET_ERROR_TYPE (errorType, 0)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VoltGetFileNameFromValueAlloc (
        ctx, (unsigned char *)0, 0, idObj->encoding.data, idObj->encoding.len,
        VOLT_FILE_NAME_VALUE_TYPE_IBE_PRI_CLIENT, &fileName, &fileNameLen);
      if (status != 0)
        break;

      nameToUse = fileName;
    }

    /* Try to open the file containing the IBE private key.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = fileCtx->CtxOpenFile (
      fileCtx, &fileHandle, nameToUse, VOLT_FILE_MODE_READ_ONLY, 0);

    /* If the file doesn't exist the error return should be 
     * VT_ERROR_ENTRY_NOT_FOUND.
     */    
    if (status != 0)
    {      
      VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
      VOLT_SET_FNCT_LINE (fnctLine)
      if (status == VT_ERROR_FILE_DOES_NOT_EXIST)
        status = VT_ERROR_ENTRY_NOT_FOUND;

      break;
    }

    /* Get the client storage password if any
     */
    if (defStorageCtx->GetExtraPassword != (VGetExtraPassword)0)
    {
      VOLT_SET_ERROR_TYPE (errorType, 0)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = defStorageCtx->GetExtraPassword (ctx, &password, &passwordLen);
      if (status != 0)
        break;
    }

    /* Get the contents of the file.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = mIcLoadDataAlloc (
      ctx, fileCtx, fileHandle, password, passwordLen, &contents, &contentsLen);
    if (status != 0)
      break;
    
    /* Decode the file contents as the ASN1 private key
    */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VoltDecodeIBEPriKeyDataCreate (
      libCtx, contents, contentsLen, &asn1PriKey);
    if (status != 0)
      break;
    
    /* We need the district params. If we don't have an idObject with
     * a district object, get the params. If not, get them out of
     * storage
     */
    paramObj = (VoltParameterObject *)0;
    if (idObj != (VoltIdentityObject *)0)
    {
      if (idObj->district != (VtDistrictObject)0)
      {
        distObj = (VoltDistrictObject *)(idObj->district);
        if (distObj->paramObj != (VtParameterObject)0)
          paramObj = (VoltParameterObject *)(distObj->paramObj);
      }
    }
    
    if (paramObj == (VoltParameterObject *)0)
    {
      /* Get a district object based on the encoded Id in the private
       * key.
      */
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VtDecodeIdentityDistrict (
        (VtLibCtx)libCtx, asn1PriKey->pubKey->base.data,
        (unsigned int)(asn1PriKey->pubKey->base.length),
        (unsigned char *)0, 0, &bufferSize);
      if (status == 0)
        status = VT_ERROR_GENERAL;
      if (status != VT_ERROR_BUFFER_TOO_SMALL)
        break;
      
      VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VT_ERROR_MEMORY;
      distName = (unsigned char *)Z2Malloc (bufferSize + 1, 0);
      if (distName == (unsigned char *)0)
        break;
      
      VOLT_SET_ERROR_TYPE (errorType, 0)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VtDecodeIdentityDistrict (
        (VtLibCtx)libCtx, asn1PriKey->pubKey->base.data,
        (unsigned int)(asn1PriKey->pubKey->base.length),
        distName, bufferSize, &distNameLen);
      if (status != 0)
        break;
      
      distName[distNameLen] = 0;
      
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VtCreateDistrictObject (
        (VtLibCtx)libCtx, VtDistrictImplMpCtx, (Pointer)(key->mpCtx),
        &district);
      if (status != 0)
        break;
      
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VtSetDistrictParam (
        district, VtDistrictParamQualifiedName, (Pointer)distName);
      if (status != 0)
        break;
      
      /* We can now get the params for this district.
       */
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VtRetrieveEntry (
        (VtLibCtx)libCtx, storageCtx, VT_ENTRY_TYPE_DISTRICT_PARAMS,
        0, (Pointer)0, (Pointer)district, &timeOfStore);
      if (status != 0)
        break;
      
      distObj= (VoltDistrictObject *)district;
      paramObj = (VoltParameterObject *)(distObj->paramObj);
    }
    
    /* Get the private point as a VtBFType1IBEPoint, it's currently
     * an OCTET STRING.
    */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VoltIBEPriPointFromEncodingAlloc (
      libCtx, paramObj, asn1PriKey->privateData, &ibePoint);
    if (status != 0)
      break;

⌨️ 快捷键说明

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