📄 clientstore.c
字号:
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltConvertTimeToSeconds (
libCtx, &(distObj->validityEnd), &seconds);
if (status != 0)
break;
VoltConvertTimeToVoltage (&seconds, validityEnd);
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
nameCopy = (unsigned char *)Z2Malloc (districtLen, 0);
if (nameCopy == (unsigned char *)0)
break;
Z2Memcpy (nameCopy, district, districtLen);
/* If we are here means everything worked and we have found the district
*/
*currentDistrictResult = VOLT_CURRENT_DIST_FOUND;
*currentDistrict = nameCopy;
status = 0;
} while (0);
/* Close any handles we opened and free any data we allocated.
*/
if (cdKey != (HKEY)0)
RegCloseKey(cdKey);
if (updateKey != (HKEY)0)
RegCloseKey (updateKey);
if (paramKey != (HKEY)0)
RegCloseKey (paramKey);
/* free the buffer allocated for public params
* we don't need it anymore.
*/
if (params != (unsigned char *)0)
Z2Free (params);
/* Destroy the temporary objects that we created.
*/
VtDestroyMpIntCtx (&mpCtx);
VtDestroyDistrictObject (&distObj);
if (status == 0)
return (0);
/* If there was an error, we won't return this buffer.
*/
if (nameCopy != (unsigned char *)0)
Z2Free (nameCopy);
VOLT_LOG_ERROR_INFO (
0, storageCtx, status, ret, errorType,
(char *)0, "VoltClientRetrieveCurrentDistrictAlloc", fnctLine, (char *)0)
return (status);
}
int VoltClientRetrieveDistrictParameters (
VtStorageCtx storageCtx,
VtDistrictObject entry,
unsigned int index,
VtTime *timeOfStore
)
{
int status, ret;
unsigned int paramTextLen, valueCount;
HKEY paramKey = (HKEY)0;
HKEY updateKey = (HKEY)0;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltDefaultStorageCtx *defStorageCtx =
(VoltDefaultStorageCtx *)(ctx->localStorageCtx);
VoltFileCtx *fileCtx = (VoltFileCtx *)(defStorageCtx->fCtx);
VoltDistrictObject *distObj = (VoltDistrictObject *)entry;
unsigned char *fileName = (unsigned char *)0;
unsigned char *password = (unsigned char *)0;
unsigned char *contents = (unsigned char *)0;
unsigned char *nameToUse;
unsigned char distName[256];
unsigned int distNameLen;
unsigned int updateLen;
VoltFileHandle fileHandle = (VoltFileHandle)0;
VtFileNameList *nameList = (VtFileNameList *)0;
time_t updateTime;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
updateLen = sizeof (updateTime);
distNameLen = sizeof (distName);
nameToUse = distName;
ret = ERROR_SUCCESS;
do
{
/* If the entry obj is already set, error.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_STORAGE_ENTRY;
if ( (distObj->paramsText != (unsigned char *)0) ||
(distObj->paramObj != (VtParameterObject)0) )
break;
/* Open the parameters registry key
*/
VOLT_SET_ERROR_TYPE (
errorType, VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_OPEN_REGISTRY_KEY;
ret = RegOpenKey (
HKEY_CURRENT_USER,
_T("Software\\Voltage\\VSCOM\\parameters"), ¶mKey);
/* If there is no registry entry for this key it means no district.
* Hence no params were found.
*/
if (ret != ERROR_SUCCESS)
{
if (ret == ERROR_FILE_NOT_FOUND)
status = VT_ERROR_UNKNOWN_DISTRICT;
break;
}
/* Now open the update key to find the last update time
* for public params.
*/
VOLT_SET_FNCT_LINE (fnctLine)
ret = RegOpenKey (
HKEY_CURRENT_USER,
_T("Software\\Voltage\\VSCOM\\paramUpdates"), &updateKey);
if (ret != ERROR_SUCCESS)
break;
status = VT_ERROR_INVALID_STORAGE_REF;
if (distObj->qualDistrictName.data == (unsigned char *)0)
{
/* If there's no qualified name, there can be no domain name.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
if (distObj->unqualDistrictName.data != (unsigned char *)0)
break;
/* We have to get the value based on the index now.
*/
VOLT_SET_ERROR_TYPE (
errorType, VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM)
VOLT_SET_FNCT_LINE (fnctLine)
valueCount = 0;
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;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_ENTRY_NOT_FOUND;
if (valueCount == 0)
break;
if (index >= valueCount)
break;
VOLT_SET_ERROR_TYPE (
errorType, VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_READ_REGISTRY_VALUE;
ret = RegEnumValue (
paramKey, index, distName, &distNameLen,
NULL, NULL, NULL, ¶mTextLen);
if (ret != ERROR_SUCCESS)
break;
distName[distNameLen] = 0;
}
else
{
/* We get the entry based on district
*/
VOLT_SET_ERROR_TYPE (
errorType, VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_READ_REGISTRY_VALUE;
ret = RegQueryValueEx (
paramKey, distObj->qualDistrictName.data, NULL,
NULL, (unsigned char *)0, ¶mTextLen);
if (ret == ERROR_FILE_NOT_FOUND)
status = VT_ERROR_UNKNOWN_DISTRICT;
if (ret != ERROR_SUCCESS)
break;
nameToUse = distObj->qualDistrictName.data;
}
/* Allocate the memory to read the public parameters
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
contents = (unsigned char *)Z2Malloc (paramTextLen, 0);
if (contents == (unsigned char *)0)
break;
VOLT_SET_ERROR_TYPE (
errorType, VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_READ_REGISTRY_VALUE;
ret = RegQueryValueEx (
paramKey, nameToUse, NULL, NULL, contents, ¶mTextLen);
if (ret != ERROR_SUCCESS)
break;
VOLT_SET_FNCT_LINE (fnctLine)
ret = RegQueryValueEx (
updateKey, nameToUse, NULL, NULL, (unsigned char *)&updateTime,
&updateLen);
if (ret != ERROR_SUCCESS)
break;
/* Convert the time_t struct to Voltage time
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
VoltConvertTimeToVoltage ((VoltTime *)&updateTime , timeOfStore);
/* Now set the district object with the param text
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltSetDistFromParamsText (
contents, paramTextLen, distObj, distObj->mpCtx, libCtx);
} while (0);
if (paramKey != (HKEY)0)
RegCloseKey(paramKey);
if (updateKey != (HKEY)0)
RegCloseKey(updateKey);
if (contents != (unsigned char *)0)
Z2Free (contents);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, storageCtx, status, ret,
VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM,
(char *)0, "VoltClientDeleteCurrentDistrict", fnctLine, (char *)0)
return (status);
}
int VoltClientDeleteCurrentDistrict (
VtStorageCtx storageCtx,
unsigned char *reference
)
{
HKEY cdKey = (HKEY)0;
HKEY updateKey = (HKEY)0;
int status, ret;
int cdExists, updateExists;
VoltStorageCtx *ctx = (VoltStorageCtx *)storageCtx;
VoltLibCtx *libCtx = (VoltLibCtx *)(ctx->voltObject.libraryCtx);
VoltDefaultStorageCtx *defStorageCtx =
(VoltDefaultStorageCtx *)(ctx->localStorageCtx);
VoltFileCtx *fileCtx = (VoltFileCtx *)(defStorageCtx->fCtx);
unsigned char *fileName = (unsigned char *)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
cdExists = 1;
updateExists = 1;
do
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_OPEN_REGISTRY_KEY;
ret = RegOpenKey (
HKEY_CURRENT_USER,
_T("Software\\Voltage\\VSCOM\\currentDistricts"), &cdKey);
if (ret != ERROR_SUCCESS)
{
if (ret == ERROR_FILE_NOT_FOUND)
cdExists = 0;
else
break;
}
VOLT_SET_FNCT_LINE (fnctLine)
ret = RegOpenKey (
HKEY_CURRENT_USER, _T("Software\\Voltage\\VSCOM\\cdUpdates"),
&updateKey);
if (ret != ERROR_SUCCESS)
{
if (ret == ERROR_FILE_NOT_FOUND)
updateExists = 0;
else
break;
}
/* Delete the district entries from the registry
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_DELETE_REGISTRY_VALUE;
if (cdExists == 1)
{
ret = RegDeleteValue (cdKey, reference);
if ( (ret != ERROR_SUCCESS) && (ret != ERROR_FILE_NOT_FOUND) )
break;
}
if (updateExists == 1)
{
ret = RegDeleteValue (updateKey, reference);
if ( (ret != ERROR_SUCCESS) && (ret != ERROR_FILE_NOT_FOUND) )
break;
}
status = 0;
} while (0);
if (cdKey != (HKEY)0)
RegCloseKey (cdKey);
if (updateKey != (HKEY)0)
RegCloseKey (updateKey);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, storageCtx, status, ret,
VT_ERROR_TYPE_PRIMARY | VT_ERROR_TYPE_SYSTEM,
(char *)0, "VoltClientDeleteCurrentDistrict", fnctLine, (char *)0)
return (status);
}
int VoltClientRetrievePublicSigningCert (
VtStorageCtx storageCtx,
VtIdentityObject reference,
unsigned int index,
VtCertObject certObj
)
{
int status;
VoltFileInt fileSize;
unsigned int fileNameLen, contentsLen;
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 *contents = (unsigned char *)0;
unsigned char *nameToUse;
VtFileNameList *nameList = (VtFileNameList *)0;
VtCertInfo certInfo;
VtDerCoder *derCoders[1] = { VtDerCoderDSAPublicKey };
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
/* This implementation works only on X.509 certs and only with DSA as
* the public key and the signing key.
*/
/* Get the File Ctx
*/
defStorageCtx = (VoltDefaultStorageCtx *)ctx->localStorageCtx;
fileCtx = (VoltFileCtx *)defStorageCtx->fCtx;
Z2Memset (&certInfo, 0, sizeof (VtCertInfo));
do
{
/* 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_SIGN_CERTS_CLIENT, VOLT_STORE_DIR_SIGN_CERTS_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.
*/
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_CLIENT, &fileName, &fileNameLen);
if (status != 0)
break;
nameToUse = fileName;
}
/* Try to open this file.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = fileCtx->CtxOpenFile (
fileCtx, &fileHandle, nameToUse, VOLT_FILE_MO
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -