📄 sfparams.c
字号:
/* Copyright 2003-2005, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "securemail.h"
#include "stringutil.h"
int VtSecureFileParamRecipientList (
VtSecureFileObject secureFileObj,
Pointer info,
unsigned int flag
)
{
int status;
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureFileObj;
VoltSecureMailWriteCtx *writeCtx;
if (flag == VOLT_SECURE_FILE_SET_TYPE_FLAG)
{
/* The SecureMail object must be set to write.
*/
if (obj->state != VOLT_SECURE_MAIL_STATE_WRITE_SET)
return (VT_ERROR_INVALID_SECURE_FILE_OBJ);
/* Set the enveloper with this list.
*/
status = VtSetPkcs7Param (
obj->p7EnvelopedData, VtPkcs7ParamRecipientList, info);
if (status != 0)
return (status);
/* We need a reference to the recipient list.
*/
writeCtx = (VoltSecureMailWriteCtx *)(obj->localCtx);
return (VtGetPkcs7Param (
obj->p7EnvelopedData, VtPkcs7ParamRecipientList,
(Pointer *)&(writeCtx->recipListRef)));
}
if (flag == VOLT_SECURE_FILE_GET_TYPE_FLAG)
{
/* If getting, the SecureMail object must be set to read.
*/
if ((obj->state & VOLT_SECURE_MAIL_STATE_READ) == 0)
return (VT_ERROR_INVALID_SECURE_FILE_OBJ);
/* Get the list out of the enveloper.
*/
return (VtGetPkcs7Param (
obj->p7EnvelopedData, VtPkcs7ParamRecipientList, (Pointer *)info));
}
/* If we get this far, the flag was not appropriate.
*/
return (VT_ERROR_INVALID_TYPE);
}
int VtSecureFileParamRecipientIndex (
VtSecureFileObject secureFileObj,
Pointer info,
unsigned int flag
)
{
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureFileObj;
/* This Param cannot Get info.
*/
if (flag == VOLT_SECURE_FILE_GET_TYPE_FLAG)
return (VT_ERROR_INVALID_GET);
if (flag != VOLT_SECURE_FILE_SET_TYPE_FLAG)
return (VT_ERROR_INVALID_TYPE);
/* The SecureMail object must be set to read.
*/
if ((obj->state & VOLT_SECURE_MAIL_STATE_READ) == 0)
return (VT_ERROR_INVALID_SECURE_FILE_OBJ);
/* Set the enveloper with this list.
*/
return (VtSetPkcs7Param (
obj->p7EnvelopedData, VtPkcs7ParamRecipientIndex, info));
}
int VtSecureFileParamSignerList (
VtSecureFileObject secureFileObj,
Pointer info,
unsigned int flag
)
{
int status;
Pointer *getInfo;
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureFileObj;
do
{
/* This param can GetParam only.
*/
status = VT_ERROR_INVALID_SET;
if (flag == VOLT_SECURE_FILE_SET_TYPE_FLAG)
break;
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_SECURE_FILE_GET_TYPE_FLAG)
break;
getInfo = (Pointer *)info;
/* The object must be done reading a file.
*/
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (obj->state != VOLT_SECURE_FILE_STATE_READ_COMPLETE)
break;
/* Get the info out of the P7 object.
*/
status = VtGetPkcs7Param (
obj->p7SignedData, VtPkcs7ParamSignerList, getInfo);
} while (0);
return (status);
}
int VtSecureFileParamContentDescriptors (
VtSecureFileObject secureFileObj,
Pointer info,
unsigned int flag
)
{
int status;
unsigned int bufferSize, index;
Pointer *getInfo;
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureFileObj;
VoltSecureMailReadCtx *readCtx = (VoltSecureMailReadCtx *)(obj->localCtx);
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltContentMaterial *currentElement;
do
{
/* This param can GetParam only.
*/
status = VT_ERROR_INVALID_SET;
if (flag == VOLT_SECURE_FILE_SET_TYPE_FLAG)
break;
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_SECURE_FILE_GET_TYPE_FLAG)
break;
getInfo = (Pointer *)info;
status = VT_ERROR_UNIMPLEMENTED;
/* Make sure this object is set to read SecureFile and that the
* content descriptors have been read.
*/
status = VT_ERROR_INVALID_SECURE_FILE_OBJ;
if (readCtx->contentMaterialState != VOLT_CONTENT_MATERIAL_STATE_COMPLETE)
break;
/* If the list is not yet computed, compute it now.
*/
if (readCtx->contentDescriptors.count != readCtx->contentMaterialCount)
{
/* The buffer size is the size of an array, we'll just fill it
* with the pointers to the data already copied.
*/
status = VT_ERROR_MEMORY;
bufferSize = readCtx->contentMaterialCount * sizeof (unsigned char *);
readCtx->contentDescriptors.utf8Strings = (unsigned char **)Z2Realloc (
readCtx->contentDescriptors.utf8Strings, bufferSize);
if (readCtx->contentDescriptors.utf8Strings == (unsigned char **)0)
break;
Z2Memset (readCtx->contentDescriptors.utf8Strings, 0, bufferSize);
readCtx->contentDescriptors.count = readCtx->contentMaterialCount;
/* Load up all the addresses.
*/
currentElement = readCtx->contentMaterial;
for (index = 0; index < readCtx->contentMaterialCount; ++index)
{
readCtx->contentDescriptors.utf8Strings[index] =
currentElement->material.data;
currentElement = (VoltContentMaterial *)(currentElement->nextElement);
}
}
*getInfo = (Pointer)&(readCtx->contentDescriptors);
status = 0;
} while (0);
return (status);
}
int VtSecureFileParamMessageTime (
VtSecureFileObject secureFileObj,
Pointer info,
unsigned int flag
)
{
int status;
Pointer *getInfo;
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureFileObj;
do
{
/* This param can GetParam only.
*/
status = VT_ERROR_INVALID_SET;
if (flag == VOLT_SECURE_FILE_SET_TYPE_FLAG)
break;
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_SECURE_FILE_GET_TYPE_FLAG)
break;
getInfo = (Pointer *)info;
/* The object must be done reading a message.
*/
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (obj->state != VOLT_SECURE_FILE_STATE_READ_COMPLETE)
break;
/* Get the info out of the P7 object.
*/
status = VtGetPkcs7Param (
obj->p7SignedData, VtPkcs7ParamSigningTime, getInfo);
} while (0);
return (status);
}
int VtSecureFileParamContentType (
VtSecureFileObject secureFileObj,
Pointer info,
unsigned int flag
)
{
int status;
unsigned int contentLen, labelLen, index;
Pointer *getInfo;
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureFileObj;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltSecureMailWriteCtx *writeCtx = (VoltSecureMailWriteCtx *)0;
VoltSecureMailReadCtx *readCtx = (VoltSecureMailReadCtx *)0;
VtUtf8StringList *descriptors;
char *found;
char *labelName = "content-type: ";
if ((obj->state & VOLT_SECURE_MAIL_STATE_WRITE) != 0)
writeCtx = (VoltSecureMailWriteCtx *)(obj->localCtx);
else
readCtx = (VoltSecureMailReadCtx *)(obj->localCtx);
do
{
if (flag == VOLT_SECURE_FILE_SET_TYPE_FLAG)
{
/* The state must be VOLT_SECURE_MAIL_STATE_WRITE_SET.
*/
status = VT_ERROR_INVALID_CALL_ORDER;
if (obj->state != VOLT_SECURE_MAIL_STATE_WRITE_SET)
break;
/* Make sure the obj does not yet have the contentType set.
*/
status = VT_ERROR_INVALID_SECURE_FILE_OBJ;
if (obj->contentInfo.data != (unsigned char *)0)
break;
/* The info should be an unsigned char *.
*/
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info == (Pointer)0)
break;
contentLen = Z2Strlen (info);
/* Build a buffer with the contentType. Add a NULL-terminating
* character.
*/
status = VT_ERROR_MEMORY;
obj->contentInfo.data = (unsigned char *)Z3Malloc (contentLen + 1);
if (obj->contentInfo.data == (unsigned char *)0)
break;
Z2Memcpy (obj->contentInfo.data, info, contentLen);
obj->contentInfo.data[contentLen] = 0;
obj->contentInfo.len = contentLen;
status = 0;
break;
}
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_SECURE_FILE_GET_TYPE_FLAG)
break;
getInfo = (Pointer *)info;
/* If this is an object to write, the content-type is in the
* contentInfo.
*/
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (writeCtx != (VoltSecureMailWriteCtx *)0)
{
if (obj->contentInfo.data == (unsigned char *)0)
break;
*getInfo = (Pointer)(obj->contentInfo.data);
status = 0;
break;
}
status = VtGetSecureFileParam (
secureFileObj, VtSecureFileParamContentDescriptors,
(Pointer *)&descriptors);
if (status != 0)
break;
/* Search through the list, find the string that begins
* "content-type: ".
*/
labelLen = 14;
found = (char *)0;
for (index = 0; index < descriptors->count; ++index)
{
found = Strstr (
descriptors->utf8Strings[index], labelName, (VtLibCtx)libCtx);
if (found != (char *)0)
break;
}
/* If we went through the list and did not find content-type, the
* info is unavailable.
*/
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (found == (char *)0)
break;
/* Find the semicolon.
*/
labelName = found + labelLen;
labelLen = Z2Strlen (labelName);
found = Strchr (labelName, ';', (VtLibCtx)libCtx);
if (found != (char *)0)
labelLen = (unsigned int)found - (unsigned int)labelName;
/* Store the contentType in the contentInfo.
*/
status = VT_ERROR_MEMORY;
obj->contentInfo.data = (unsigned char *)Z2Realloc (
obj->contentInfo.data, labelLen + 1);
if (obj->contentInfo.data == (unsigned char *)0)
break;
Z2Memcpy (obj->contentInfo.data, labelName, labelLen);
obj->contentInfo.data[labelLen] = 0;
*getInfo = (Pointer)(obj->contentInfo.data);
status = 0;
} while (0);
return (status);
}
int VtSecureFileParamMessageType (
VtSecureFileObject secureFileObj,
Pointer info,
unsigned int flag
)
{
int status;
unsigned int value;
VoltSecureMailObject *obj = (VoltSecureMailObject *)secureFileObj;
VoltSecureMailWriteCtx *writeCtx;
do
{
/* This Param cannot Get info.
*/
status = VT_ERROR_INVALID_GET;
if (flag == VOLT_SECURE_FILE_GET_TYPE_FLAG)
break;
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_SECURE_FILE_SET_TYPE_FLAG)
break;
/* The SecureFile object must be set to write.
*/
status = VT_ERROR_INVALID_SECURE_FILE_OBJ;
if ((obj->state & VOLT_SECURE_MAIL_STATE_WRITE) == 0)
break;
/* The associatedInfo must be a pointer to an unsigned int.
*/
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info == (Pointer)0)
break;
value = *((unsigned int *)info);
writeCtx = (VoltSecureMailWriteCtx *)(obj->localCtx);
if (value == VT_SECURE_FILE_TYPE_FILE)
{
obj->formatType = VOLT_MESSAGE_FORMAT_SECURE_FILE;
writeCtx->itemArray[VOLT_WRITE_SM_ITEM_BEGIN_MSG].len =
VOLT_SECURE_FILE_BEGIN_MSG_LEN;
status = 0;
break;
}
if (value != VT_SECURE_FILE_TYPE_ATTACHMENT)
break;
obj->formatType = VOLT_MESSAGE_FORMAT_SECURE_MAIL_ATTACH;
writeCtx->itemArray[VOLT_WRITE_SM_ITEM_BEGIN_MSG].len = 0;
status = 0;
} while (0);
return (status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -