📄 defaultstorageprov.c
字号:
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;
if (defStorageCtx->GetExtraPassword != (VGetExtraPassword)0)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = defStorageCtx->GetExtraPassword (ctx, &password, &passwordLen);
if (status != 0)
break;
}
VOLT_SET_FNCT_LINE (fnctLine)
status = mIcStoreData (
ctx, authToken, tokenLen, password, passwordLen, fileCtx, fileHandle);
} while (0);
if (password != (unsigned char *)0)
defStorageCtx->ReleaseExtraPassword (ctx, &password, &passwordLen);
if (fileHandle != (VoltFileHandle)0)
fileCtx->CtxCloseFile(fileCtx, &fileHandle);
if (fileName != (unsigned char *)0)
Z2Free (fileName);
if (status == 0)
return 0;
/* Log any errors and return the error
*/
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, status, errorType, fnctLine,
"VoltStoreAuthTokenForDistrict", (char *)0)
return (status);
}
int VoltDefaultStoreAuthToken (
VtStorageCtx storageCtx,
VtDistrictObject reference,
unsigned char *authToken
)
{
return VoltStoreAuthTokenForDistrict (
storageCtx, reference, authToken, VOLT_FILE_NAME_VALUE_TYPE_IBE_TOKEN);
}
int VoltDefaultStoreIBEPrivateKey (
VtStorageCtx storageCtx,
VtIdentityObject reference,
VtKeyObject entry
)
{
int status;
unsigned int fileNameLen, contentsLen, passwordLen;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltIdentityObject *idObj = (VoltIdentityObject *)reference;
VoltKeyObject *keyObj = (VoltKeyObject *)entry;
VoltFileCtx *fileCtx = (VoltFileCtx *)0;
VoltFileHandle fileHandle = (VoltFileHandle)0;
VoltDefaultStorageCtx *defStorageCtx;
unsigned char *contents = (unsigned char *)0;
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
{
/* 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;
/* The data to store will be the DER of the private key which
* will be wrapped inside a PrivateKeyInfo object.
* First, how big does the buffer need to be?
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtDerEncodeKey (
(VtLibCtx)libCtx, VtDerCoderBFType1IBEPrivateKey , (Pointer)keyObj,
(unsigned char *)0, 0, &contentsLen);
if (status == 0)
status = VT_ERROR_INVALID_KEY_OBJ;
if (status != VT_ERROR_BUFFER_TOO_SMALL)
break;
/* Allocate the space.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
contents = (unsigned char *)Z2Malloc (contentsLen, VOLT_MEMORY_SENSITIVE);
if (contents == (unsigned char *)0)
break;
/* Encode into the buffer.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtDerEncodeKey (
(VtLibCtx)libCtx, VtDerCoderBFType1IBEPrivateKey , (Pointer)keyObj,
contents, contentsLen, &contentsLen);
if (status != 0)
break;
/* Get the file name to store the encoded private key info.
*/
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_KEY, &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;
if (defStorageCtx->GetExtraPassword != (VGetExtraPassword)0)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = defStorageCtx->GetExtraPassword (ctx, &password, &passwordLen);
if (status != 0)
break;
}
/* Store the encoding.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = mIcStoreData (
ctx, contents, contentsLen, password, passwordLen, fileCtx, fileHandle);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltAddIdentityToIdList (storageCtx, reference);
} while (0);
if (password != (unsigned char *)0)
defStorageCtx->ReleaseExtraPassword (ctx, &password, &passwordLen);
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;
/* In case of error log it and return
*/
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, status, errorType, fnctLine,
"VoltDefaultStoreIBEPrivateKey", (char *)0)
return (status);
}
int VoltDefaultStorePrivateSigningKey (
VtStorageCtx storageCtx,
VtIdentityObject reference,
VtKeyObject keyObj
)
{
int status;
unsigned int fileNameLen, contentsLen, passwordLen;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltIdentityObject *idObj = (VoltIdentityObject *)reference;
VoltFileCtx *fileCtx = (VoltFileCtx *)0;
VoltFileHandle fileHandle = (VoltFileHandle)0;
VoltDefaultStorageCtx *defStorageCtx;
unsigned char *fileName = (unsigned char *)0;
unsigned char *password = (unsigned char *)0;
unsigned char *contents = (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;
/* This implementation stores DSA private keys only.
*/
/* Get the File Ctx
*/
defStorageCtx = (VoltDefaultStorageCtx *)ctx->localStorageCtx;
fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;
do
{
/* 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;
/* The data to store will be the DER of the private key.
* Note that this implementation only deals with DSA keys.
* First, how big does the buffer need to be?
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtDerEncodeKey (
(VtLibCtx)libCtx, VtDerCoderDSAPrivateKey, (Pointer)keyObj,
(unsigned char *)0, 0, &contentsLen);
if (status == 0)
status = VT_ERROR_INVALID_KEY_OBJ;
if (status != VT_ERROR_BUFFER_TOO_SMALL)
break;
/* Allocate the space.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
contents = (unsigned char *)Z2Malloc (contentsLen, VOLT_MEMORY_SENSITIVE);
if (contents == (unsigned char *)0)
break;
/* Encode into the buffer.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtDerEncodeKey (
(VtLibCtx)libCtx, VtDerCoderDSAPrivateKey, (Pointer)keyObj,
contents, contentsLen, &contentsLen);
if (status != 0)
break;
/* Get the file name.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetFileNameFromValueAlloc (
ctx, (unsigned char *)0, 0, idObj->encoding.data, idObj->encoding.len,
VOLT_FILE_NAME_VALUE_TYPE_SIGN_PRI, &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;
if (defStorageCtx->GetExtraPassword != (VGetExtraPassword)0)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = defStorageCtx->GetExtraPassword (ctx, &password, &passwordLen);
if (status != 0)
break;
}
/* Store the encoding.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = mIcStoreData (
ctx, contents, contentsLen, password, passwordLen, fileCtx, fileHandle);
} while (0);
if (password != (unsigned char *)0)
defStorageCtx->ReleaseExtraPassword (ctx, &password, &passwordLen);
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,
"VoltDefaultStorePrivateSigningKey", (char *)0)
return (status);
}
int VoltDefaultStorePublicSigningCert (
VtStorageCtx storageCtx,
VtIdentityObject reference,
VtItem *cert
)
{
int status;
unsigned int fileNameLen;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltIdentityObject *idObj = (VoltIdentityObject *)reference;
VoltFileCtx *fileCtx = (VoltFileCtx *)0;
VoltFileHandle fileHandle = (VoltFileHandle)0;
VoltDefaultStorageCtx *defStorageCtx;
unsigned char *fileName = (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
{
/* 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.
*/
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_CERT, &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;
/* Signing certs are encrypted with default credentials
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = mIcStoreData (
ctx, cert->data, cert->len, (unsigned char *)0, 0, fileCtx, fileHandle);
} while (0);
if (fileHandle != (VoltFileHandle)0)
fileCtx->CtxCloseFile (fileCtx, &fileHandle);
if (fileName != (unsigned char *)0)
Z2Free (fileName);
if (status == 0)
return 0;
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, status, errorType, fnctLine,
"VoltDefaultStorePublicSigningCert", (char *)0)
return (status);
}
int VoltDefaultGetDistrictParameterCount (
VtStorageCtx storageCtx,
VtDistrictObject reference,
unsigned int *count
)
{
int status;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VtDistrictObject tempObject = (VtDistrictObject)0;
VoltDistrictObject *obj = (VoltDistrictObject *)reference;
VtFileNameList *nameList = (VtFileNameList *)0;
unsigned char *qualName, *unqualName;
VtTime timeOfStore;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_DECLARE_ERROR_TYPE (errorType)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -