📄 defaultstorageprov.c
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "vstorage.h"
#include "defaultstore.h"
#include "idobj.h"
#include "keyobj.h"
#include "ibe.h"
#include "certobj.h"
#include "ibekeyber.h"
#include "prikeyder.h"
#include "distobj.h"
#include "vsdistrict.h"
#include "vsstore.h"
#include "voltfile.h"
#include "vtime.h"
#include "errorctx.h"
int VOLT_CALLING_CONV VoltSpecialRetrieveIBEPrivateKey VOLT_PROTO_LIST ((
VtStorageCtx storageCtx,
VtIdentityObject reference,
VtPolicyCtx policyCtx,
unsigned int index,
VtKeyObject keyObj
));
int VoltDefaultSetExtraPassword (
VtStorageCtx storageCtx,
Pointer info
)
{
int status;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VOLT_DECLARE_FNCT_LINE (fnctLine)
/* For null storage impl return VT_ERROR_NO_STORAGE_PROVIDER_LOADED,
* otherwise return VT_ERROR_NOT_IMPLEMENTED
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_UNIMPLEMENTED;
if (ctx->providerNum == -2)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NO_STORAGE_PROVIDER_LOADED;
}
VOLT_LOG_ERROR_INFO (
0, storageCtx, status, 0, VT_ERROR_TYPE_PRIMARY,
(char *)0, "VoltDefaultSetExtraPassword", fnctLine, (char *)0)
return (status);
}
int VoltDefaultGetEnvelopeKey (
VtStorageCtx storageCtx,
unsigned char *key,
unsigned int bufferSize,
unsigned int *keyLen
)
{
int status;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VOLT_DECLARE_FNCT_LINE (fnctLine)
/* For VtStorageImplNull return VT_ERROR_NO_STORAGE_PROVIDER_LOADED,
* otherwise return VT_ERROR_ENTRY_NOT_FOUND, this provider returns
* no enveloping key.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_ENTRY_NOT_FOUND;
if (ctx->providerNum == -2)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_NO_STORAGE_PROVIDER_LOADED;
}
VOLT_LOG_ERROR_INFO (
0, storageCtx, status, 0, VT_ERROR_TYPE_PRIMARY,
(char *)0, "VoltDefaultGetEnvelopeKey", fnctLine, (char *)0)
return (status);
}
int VoltDefaultStoreCurrentDistrict (
VtStorageCtx storageCtx,
unsigned char *domainName,
unsigned char *currentDistrict,
VtTime *storeTime,
VtTime *validityStart,
VtTime *validityEnd
)
{
int status;
unsigned int fileNameLen, distNameLen, bufferSize, offset;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltDefaultStorageCtx *defStorageCtx =
(VoltDefaultStorageCtx *)(ctx->localStorageCtx);
VoltFileCtx *fileCtx = (VoltFileCtx *)0;
VoltFileHandle fileHandle = (VoltFileHandle)0;
unsigned char *distName;
unsigned char *fileName = (unsigned char *)0;
unsigned char *contents = (unsigned char *)0;
VtTime currentTime;
VtTime *theTime;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_DECLARE_ERROR_TYPE (errorType)
/* If this function was called by the VtStorageImplNull
* simply return VT_ERROR_NO_STORAGE_PROVIDER_LOADED
*/
if (ctx->providerNum == -2)
return VT_ERROR_NO_STORAGE_PROVIDER_LOADED;
fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;
distName = (unsigned char *)0;
distNameLen = 0;
theTime = storeTime;
/* If no domain we don't need to do anything
*/
if (domainName == (unsigned char *)0)
return 0;
do
{
if (theTime == (VtTime *)0 )
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetTime ((VtLibCtx)libCtx, ¤tTime);
if (status != 0)
break;
theTime = ¤tTime;
}
/* Are we storing a current district? Or the info that no current
* district exists?
*/
if (currentDistrict != (unsigned char *)0)
{
distName = currentDistrict;
distNameLen = Z2Strlen (distName);
/* If there are no validity dates in the district object, error.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_STORAGE_ENTRY;
if ( (validityStart->month == 0) ||
(validityEnd->month == 0) )
break;
}
/* Get the file name.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetFileNameFromValueAlloc (
ctx, (unsigned char *)0, 0, domainName, Z2Strlen (domainName),
VOLT_FILE_NAME_VALUE_TYPE_CURR_DIST, &fileName, &fileNameLen);
if (status != 0)
break;
/* Make sure the directories exist.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtx->CtxCreateDirectories(fileCtx, fileName);
if (status != 0)
break;
/* Open this file to write. If it exists, destory the contents.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtx->CtxOpenFile (
fileCtx, &fileHandle, fileName, VOLT_FILE_MODE_READ_OVERWRITE, 0600);
if (status != 0)
break;
/* Store the time of store along with the validity dates and the
* UTF-8 version of the qualified district name.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize = distNameLen + (3 * VOLT_TIME_ARRAY_SIZE);
contents = Z2Malloc (bufferSize, 0);
if (contents == (unsigned char *)0)
break;
VoltConvertTimeToArray (theTime, contents);
offset = VOLT_TIME_ARRAY_SIZE;
if (distNameLen != 0)
{
VoltConvertTimeToArray (validityStart, contents + offset);
offset += VOLT_TIME_ARRAY_SIZE;
VoltConvertTimeToArray (validityEnd, contents + offset);
offset += VOLT_TIME_ARRAY_SIZE;
Z2Memcpy (contents + offset, distName, distNameLen);
offset += distNameLen;
}
/* Current district info is protected using default credentials
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = mIcStoreData (
ctx, contents, offset, (unsigned char *)0, 0, fileCtx, fileHandle);
} while (0);
if (fileHandle != (VoltFileHandle)0)
fileCtx->CtxCloseFile(fileCtx, &fileHandle);
if (contents != (unsigned char *)0)
Z2Free (contents);
if (fileName != (unsigned char *)0)
Z2Free (fileName);
if (status == 0)
return 0;
/* Log the error and return
*/
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, status, errorType, fnctLine,
"VoltDefaultStoreCurrentDistrict", (char *)0)
return (status);
}
int VoltDefaultStoreDistrictParameters (
VtStorageCtx storageCtx,
VtTime *storeTime,
VtDistrictObject entry
)
{
int status;
unsigned int fileNameLen, paramsTextLen;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltDistrictObject *distObj = (VoltDistrictObject *)entry;
VoltFileCtx *fileCtx = (VoltFileCtx *)0;
VoltFileHandle fileHandle = (VoltFileHandle)0;
VoltDefaultStorageCtx *defStorageCtx;
unsigned char *fileName = (unsigned char *)0;
unsigned char *contents = (unsigned char *)0;
VtTime *theTime;
VtTime currentTime;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_DECLARE_ERROR_TYPE (errorType)
/* If this function was called by the VtStorageImplNull
* simply return VT_ERROR_NO_STORAGE_PROVIDER_LOADED
*/
if (ctx->providerNum == -2)
return VT_ERROR_NO_STORAGE_PROVIDER_LOADED;
/* Get the File Ctx
*/
defStorageCtx = (VoltDefaultStorageCtx *)ctx->localStorageCtx;
fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;
theTime = storeTime;
do
{
if (theTime == (VtTime *)0 )
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtGetTime ((VtLibCtx)libCtx, ¤tTime);
if (status != 0)
break;
theTime = ¤tTime;
}
/* We need the district data as the standard params text.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_ENTRY_NOT_STORED;
if (distObj->paramsText == (unsigned char *)0)
break;
paramsTextLen = Z2Strlen (distObj->paramsText);
/* Make sure the district object contains a qualified name.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_STORAGE_REF;
if (distObj->qualDistrictName.data == (unsigned char *)0)
break;
/* Get the file name.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetFileNameFromValueAlloc (
ctx, (unsigned char *)0, 0, distObj->qualDistrictName.data,
distObj->qualDistrictName.len, VOLT_FILE_NAME_VALUE_TYPE_DIST_PARAMS,
&fileName, &fileNameLen);
if (status != 0)
break;
/* Make sure the directories exist.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtx->CtxCreateDirectories(fileCtx, fileName);
if (status != 0)
break;
/* Open this file to write. If it exists, destory the contents.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtx->CtxOpenFile (
fileCtx, &fileHandle, fileName, VOLT_FILE_MODE_READ_OVERWRITE, 0600);
if (status != 0)
break;
/* Store the params text along with the time of store.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
contents = (unsigned char *)Z2Malloc (
paramsTextLen + VOLT_TIME_ARRAY_SIZE, 0);
if (contents == (unsigned char *)0)
break;
VoltConvertTimeToArray (theTime, contents);
Z2Memcpy (
contents + VOLT_TIME_ARRAY_SIZE, distObj->paramsText, paramsTextLen);
/* District parameters are stored with default credentials
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = mIcStoreData (
ctx, contents, paramsTextLen + VOLT_TIME_ARRAY_SIZE,
(unsigned char *)0, 0, fileCtx, fileHandle);
} while (0);
if (fileHandle != (VoltFileHandle)0)
fileCtx->CtxCloseFile (fileCtx, &fileHandle);
if (contents != (unsigned char *)0)
Z2Free (contents);
if (fileName != (unsigned char *)0)
Z2Free (fileName);
if (status == 0)
return 0;
/* Log errors and return
*/
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, status, errorType, fnctLine,
"VoltDefaultStoreDistrictParameters", (char *)0)
return (status);
}
int VoltStoreAuthTokenForDistrict (
VtStorageCtx storageCtx,
VtDistrictObject reference,
unsigned char *authToken,
unsigned int valueType
)
{
int status;
unsigned int tokenLen, fileNameLen, passwordLen;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltDistrictObject *distObj = (VoltDistrictObject *)reference;
VoltFileCtx *fileCtx = (VoltFileCtx *)0;
VoltFileHandle fileHandle = (VoltFileHandle)0;
VoltDefaultStorageCtx *defStorageCtx;
unsigned char *fileName = (unsigned char *)0;
unsigned char *password = (unsigned char *)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_DECLARE_ERROR_TYPE (errorType)
/* If this function was called by the VtStorageImplNull
* simply return VT_ERROR_NO_STORAGE_PROVIDER_LOADED
*/
if (ctx->providerNum == -2)
return VT_ERROR_NO_STORAGE_PROVIDER_LOADED;
/* Get the File Ctx
*/
defStorageCtx = (VoltDefaultStorageCtx *)ctx->localStorageCtx;
fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;
do
{
/* Make sure we have a token.
*/
status = 0;
if (authToken == (unsigned char *)0)
break;
/* include the NULL character in token as part of it.
*/
tokenLen = Z2Strlen (authToken) + 1;
/* Make sure the district object contains a qualified name.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_STORAGE_REF;
if (distObj->qualDistrictName.data == (unsigned char *)0)
break;
/* Get the file name.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetFileNameFromValueAlloc (
ctx, distObj->qualDistrictName.data, distObj->qualDistrictName.len,
(unsigned char *)authToken, tokenLen, valueType, &fileName, &fileNameLen);
if (status != 0)
break;
/* Make sure the directories exist.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtx->CtxCreateDirectories(fileCtx, fileName);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -