📄 saread.c
字号:
if (*final)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtPkcs7ReadFinal(readCtx->mSignedData, buffer,
bufferSize, &readSize, dataBuffer, dataBufferSize, &dataSize);
}
else
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtPkcs7ReadUpdate(readCtx->mSignedData, buffer,
bufferSize, &readSize, dataBuffer, dataBufferSize, &dataSize);
}
if (status == VT_ERROR_BUFFER_TOO_SMALL)
{
VT_ASSERT(dataSize > dataBufferSize);
/* Reallocate the output bufferh */
Z2Free(dataBuffer);
dataBuffer = (unsigned char*) Z3Malloc(dataSize);
if (dataBuffer == (unsigned char*)0)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_MEMORY;
break;
}
dataBufferSize = dataSize;
buffer += readSize;
bufferSize -= readSize;
/* Now try again with the resized data buffer */
if (*final)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtPkcs7ReadFinal(readCtx->mSignedData, buffer,
bufferSize, &readSize, dataBuffer, dataBufferSize, &dataSize);
}
else
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtPkcs7ReadUpdate(readCtx->mSignedData, buffer,
bufferSize, &readSize, dataBuffer, dataBufferSize, &dataSize);
}
}
if (status != 0)
break;
VT_ASSERT(readSize == bufferSize);
/* Copy the data over to the output stream */
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(outputStream, dataBuffer, dataSize);
if (status != 0)
break;
}
while (!*final);
}
while (0);
/* Free up the buffers */
Z2Free(envelopedDataBuffer);
Z2Free(signedDataBuffer);
Z2Free(dataBuffer);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine,"VoltSecureArchiveDecryptData", (unsigned char*)0)
return status;
}
static int VoltSecureArchiveSplitIndexStream(
VtLibCtx libCtx,
VtStreamObject indexStream,
VtStreamObject headerStream,
VtStreamObject dataStream
)
{
int status = 0;
unsigned int bufferSize = 1000;
unsigned char* buffer = (unsigned char*)0;
VtStreamSize readSize;
unsigned char previous = 0;
unsigned char c;
unsigned char* p;
unsigned char* end;
int eolCount = 0;
int parsingHeaders = 1;
int isCRLF;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VOLT_SET_ERROR_TYPE(errorType, 0)
do
{
buffer = (unsigned char*) Z3Malloc(bufferSize);
if (buffer == (unsigned char*)0)
{
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE(fnctLine)
status = VT_ERROR_MEMORY;
break;
}
for (;;)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamRead(indexStream, buffer, bufferSize, &readSize);
if (status == VT_ERROR_END_OF_STREAM)
{
status = 0;
break;
}
if (status != 0)
break;
p = buffer;
end = buffer + readSize;
if (parsingHeaders)
{
/* Look for a blank line which delimits the end of the headers */
while (p < end)
{
c = *p;
isCRLF = (c == '\n') && (previous == '\r');
if (!isCRLF)
{
if (eolCount == 2)
{
parsingHeaders = 0;
break;
}
if ((c == '\r') || (c == '\n'))
eolCount++;
else
eolCount = 0;
}
previous = c;
p++;
}
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(headerStream, buffer, p - buffer);
if (status != 0)
break;
}
if (!parsingHeaders)
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamWrite(dataStream, p, end - p);
if (status != 0)
break;
}
}
}
while (0);
Z2Free(buffer);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine,"VoltSecureArchiveSplitIndexStream", (unsigned char*)0)
return status;
}
static int VoltSecureArchiveParseHeaderStream(
VtSecureArchiveObject secureArchiveObj,
VtStreamObject headerStream
)
{
int status = 0;
VtLibCtx libCtx;
VoltSecureArchiveReadLocalCtx* readCtx;
unsigned char label[100];
unsigned int labelLength;
unsigned char* headerText;
VtStreamSize headerSize;
unsigned char* p;
VtStreamSize readSize;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(secureArchiveObj != (VoltSecureArchiveObject*)0);
VOLT_SET_ERROR_TYPE(errorType, 0)
libCtx = secureArchiveObj->voltObject.libraryCtx;
VT_ASSERT(libCtx != (VtLibCtx)0);
readCtx = (VoltSecureArchiveReadLocalCtx*) secureArchiveObj->localCtx;
VT_ASSERT(readCtx != (VoltSecureArchiveReadLocalCtx*)0);
do
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamGetSize(headerStream, &headerSize);
if (status != 0)
break;
headerText = (unsigned char*) Z3Malloc(headerSize + 1);
if (headerText == (unsigned char*)0)
{
VOLT_SET_FNCT_LINE(fnctLine)
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
status = VT_ERROR_MEMORY;
break;
}
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamRead(headerStream, headerText, headerSize, &readSize);
if (status != 0)
break;
VT_ASSERT(readSize == headerSize);
headerText[headerSize] = 0;
p = headerText;
/* Skip whitespace */
for (;;)
{
if ((*p != ' ') && (*p != '\t'))
break;
p++;
}
/* The ZDM headers start with a MIME-style label called
* "ZDMv2Headers:", so we need to skip past that label to
* reach the actual XML data.
*/
labelLength = Z2Strlen(VoltSecureArchiveHeadersName);
Z2Memcpy(label, VoltSecureArchiveHeadersName, labelLength);
label[labelLength] = ':';
labelLength++;
if (VoltCaseInsensitiveCompareBuffers(p, labelLength,
label, labelLength, libCtx) != 0)
{
VOLT_SET_FNCT_LINE(fnctLine)
VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
status = VT_ERROR_ARCHIVE_READ;
break;
}
p += labelLength;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtCreateDataNodeObjectFromXML(libCtx, p, &readCtx->mAttributes);
if (status != 0)
break;
}
while (0);
Z2Free(headerText);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine,"VoltSecureArchiveParseHeaderStream", (unsigned char*)0)
return status;
}
static int VoltSecureArchiveDecryptIndex(
VtSecureArchiveObject secureArchiveObj
)
{
int status = 0;
VtLibCtx libCtx;
VoltSecureArchiveReadLocalCtx* readCtx;
VtStreamObject indexStream = (VtStreamObject)0;
int final;
unsigned char* buffer = (unsigned char*)0;
VtStreamObject headerStream = (VtStreamObject)0;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(secureArchiveObj != (VoltSecureArchiveObject*)0);
VOLT_SET_ERROR_TYPE(errorType, 0)
libCtx = secureArchiveObj->voltObject.libraryCtx;
VT_ASSERT(libCtx != (VtLibCtx)0);
readCtx = (VoltSecureArchiveReadLocalCtx*) secureArchiveObj->localCtx;
VT_ASSERT(readCtx != (VoltSecureArchiveReadLocalCtx*)0);
do
{
if (readCtx->mIndexDataStream != (VtStreamObject)0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureArchiveDecryptDataInit(secureArchiveObj);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtSetArchiveParam(readCtx->mArchive,
VtArchiveParamCurrentEntryPath,
(Pointer)VoltSecureArchiveIndexFilePathName);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCreateTempBufferStream(libCtx,
&readCtx->mBufferTypeInfo, &indexStream);
if (status != 0)
break;
VT_ASSERT(indexStream != (VtStreamObject)0);
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureArchiveDecryptData(secureArchiveObj, indexStream, &final);
if (status != 0)
break;
VT_ASSERT(final != 0);
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCreateTempBufferStream(libCtx,
&readCtx->mBufferTypeInfo, &headerStream);
if (status != 0)
break;
VT_ASSERT(headerStream != (VtStreamObject)0);
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltCreateTempBufferStream(libCtx,
&readCtx->mBufferTypeInfo, &readCtx->mIndexDataStream);
if (status != 0)
break;
VT_ASSERT(readCtx->mIndexDataStream != (VtStreamObject)0);
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamSetPosition(indexStream, 0, VT_STREAM_FROM_START);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureArchiveSplitIndexStream(libCtx,
indexStream, headerStream, readCtx->mIndexDataStream);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamSetPosition(headerStream, 0, VT_STREAM_FROM_START);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtStreamSetPosition(readCtx->mIndexDataStream, 0, VT_STREAM_FROM_START);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureArchiveParseHeaderStream(secureArchiveObj,
headerStream);
if (status != 0)
break;
}
while (0);
Z2Free(buffer);
VtDestroyStreamObject(&indexStream);
VtDestroyStreamObject(&headerStream);
VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
fnctLine,"VoltSecureArchiveDecryptIndex", (unsigned char*)0)
return status;
}
static int VoltSecureArchiveGetArchiveAttribute(
VtSecureArchiveObject secureArchiveObj,
const unsigned char* name,
const unsigned char** value
)
{
int status = 0;
VtLibCtx libCtx;
VoltSecureArchiveReadLocalCtx* readCtx;
VtDataNodeObject node;
VOLT_DECLARE_FNCT_LINE(fnctLine)
VOLT_DECLARE_ERROR_TYPE(errorType)
VT_ASSERT(secureArchiveObj != (VoltSecureArchiveObject*)0);
VT_ASSERT(name != (unsigned char*)0);
VT_ASSERT(value != (unsigned char**)0);
VOLT_SET_ERROR_TYPE(errorType, 0)
libCtx = secureArchiveObj->voltObject.libraryCtx;
VT_ASSERT(libCtx != (VtLibCtx)0);
readCtx = (VoltSecureArchiveReadLocalCtx*) secureArchiveObj->localCtx;
VT_ASSERT(readCtx != (VoltSecureArchiveReadLocalCtx*)0);
do
{
VOLT_SET_FNCT_LINE(fnctLine)
status = VoltSecureArchiveDecryptIndex(secureArchiveObj);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtDataNodeResolveChild(readCtx->mAttributes, name, 0, &node);
if (status != 0)
break;
VOLT_SET_FNCT_LINE(fnctLine)
status = VtDataNodeGetStringValue(node, value);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -