📄 districtprov.c
字号:
break;
}
}
/* If this is theDSA params extension, copy the params.
*/
if (currentExtension->oid.len == VoltParamExtDsaParamsOidBytesLen)
{
if (Z2Memcmp (
currentExtension->oid.data, dsaParamsExtOid,
VoltParamExtDsaParamsOidBytesLen) == 0)
{
/* This is the DSA params extension.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = GetDSAParams (
currentExtension->value.data, currentExtension->value.len, obj);
if (status != 0)
break;
}
}
}
if (status != 0)
break;
}
/* Get the certs out of the icParams and into the district object.
*/
for (certIndex = 0; certIndex < obj->trustedCerts.count; ++certIndex)
VtDestroyCertObject (&(obj->trustedCerts.certObjects[certIndex]));
if (obj->trustedCerts.certObjects != (VtCertObject *)0)
Z2Free (obj->trustedCerts.certObjects);
obj->trustedCerts.count = 0;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
obj->trustedCerts.certObjects = (VtCertObject *)Z2Malloc (
icParams->certCount * sizeof (VtCertObject), 0);
if (obj->trustedCerts.certObjects == (VtCertObject *)0)
break;
Z2Memset (
obj->trustedCerts.certObjects, 0,
icParams->certCount * sizeof (VtCertObject));
obj->trustedCerts.count = icParams->certCount;
for (certIndex = 0; certIndex < icParams->certCount; ++certIndex)
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCloneObject (
(Pointer)(icParams->certList[certIndex]),
(Pointer *)&(obj->trustedCerts.certObjects[certIndex]));
if (status != 0)
break;
}
if (status != 0)
break;
/* Copy the paramsText. Add a NULL-terminating character.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
obj->paramsText = (unsigned char *)Z2Malloc (paramsTextLen + 1, 0);
if (obj->paramsText == (unsigned char *)0)
break;
Z2Memcpy (obj->paramsText, paramsText, paramsTextLen);
obj->paramsText[paramsTextLen] = 0;
status = 0;
} while (0);
if (certBuffer != (unsigned char *)0)
Z2Free (certBuffer);
VtDestroyCertObject (&newCert);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, errorType, fnctLine,
"VoltSetDistFromIcParams", (char *)0)
return (status);
}
int mIcDistParamsGetDistrictName (
icDistrictParameters *icParams,
VoltDistrictObject *distObj
)
{
int status, index;
unsigned int nameLen, lengthLen;
char *name = (char *)0;
VoltLibCtx *libCtx = (VoltLibCtx *)(distObj->voltObject.libraryCtx);
Asn1X509Extension *ext = (Asn1X509Extension *)0;
unsigned char dNameOid[VoltParamExtDistNameOidBytesLen] =
{ VoltParamExtDistNameOidBytes };
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Is the qualified name already set?
*/
if (distObj->qualDistrictName.data == (unsigned char *)0)
{
/* Run through the extensions, find the district name extension.
*/
for (index = 0; index < icParams->pubParams->extensions->num; ++index)
{
ext = (Asn1X509Extension *)sk_value (
icParams->pubParams->extensions, index);
if (ext->oid->base.length != VoltParamExtDistNameOidBytesLen)
continue;
if (Z2Memcmp (
ext->oid->base.data, dNameOid,
VoltParamExtDistNameOidBytesLen) == 0)
break;
}
/* Was the extension there?
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
if (index >= icParams->pubParams->extensions->num)
break;
/* The district name will be the UTF-8 string in the data of the
* extension value.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltDecodeDerLength (
ext->value->data, (unsigned int)(ext->value->length),
&lengthLen, &nameLen);
if (status != 0)
break;
/* Now copy it into the district object.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
distObj->qualDistrictName.data = (unsigned char *)Z2Malloc (
nameLen + 1, 0);
if (distObj->qualDistrictName.data == (unsigned char *)0)
break;
Z2Memcpy (
distObj->qualDistrictName.data, ext->value->data + 1 + lengthLen,
nameLen);
distObj->qualDistrictName.data[nameLen] = 0;
distObj->qualDistrictName.len = nameLen;
}
/* If the unqualified name is set, we're done.
*/
status = 0;
if (distObj->unqualDistrictName.data != (unsigned char *)0)
break;
/* The name is not set, set it.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltUnqualFromQual (distObj);
} while (0);
if (name != (char *)0)
Z2Free (name);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, errorType, fnctLine,
"mIcDistParamsGetDistrictName", (char *)0)
return (status);
}
static int BuildParamObject (
VtLibCtx libraryCtx,
VoltMpIntCtx *mpCtx,
EC_PARAMETERS *ecParams,
ASN1_OCTET_STRING *pubPoint,
VtParameterObject *paramObj
)
{
int status;
VoltLibCtx *libCtx = (VoltLibCtx *)libraryCtx;
VtParameterObject newObj = (VtParameterObject)0;
VtBFType1IBEParamInfo paramInfo;
VOLT_DECLARE_FNCT_LINE (fnctLine)
*paramObj = (VtParameterObject)0;
Z2Memset (¶mInfo, 0, sizeof (VtBFType1IBEParamInfo));
do
{
/* We don't have the y-coordinates, but the Set function should
* work with only the x-coordinates.
*/
paramInfo.curve.primeP.data = ecParams->fieldID->p->data;
paramInfo.curve.primeP.len = (unsigned int)(ecParams->fieldID->p->length);
paramInfo.curve.subprimeQ.data = ecParams->order->data;
paramInfo.curve.subprimeQ.len = (unsigned int)(ecParams->order->length);
paramInfo.curve.basePointG.isInfinity = 0;
paramInfo.curve.basePointG.xCoord.data = ecParams->base->data;
paramInfo.curve.basePointG.xCoord.len =
(unsigned int)(ecParams->base->length);
paramInfo.pubPointP.isInfinity = 0;
paramInfo.pubPointP.xCoord.data = pubPoint->data;
paramInfo.pubPointP.xCoord.len = (unsigned int)(pubPoint->length);
/* Create and set the parameter object.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCreateParameterObject (
libraryCtx, VtParameterImplMpCtx, (Pointer)mpCtx, &newObj);
if (status != 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VtSetParameterParam (
newObj, VtParameterParamBFType1IBEParams, (Pointer)¶mInfo);
if (status != 0)
break;
/* If successful, return the newly-created object.
*/
*paramObj = newObj;
} while (0);
/* If successful, we're done.
*/
if (status == 0)
return (0);
/* If there was an error, destroy what we created.
*/
VtDestroyParameterObject (&newObj);
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, status, 0, fnctLine, "BuildParamObject", (char *)0)
return (status);
}
static int GetKeySchemas (
unsigned char *schemasBer,
unsigned int schemasBerLen,
VoltDistrictObject *obj
)
{
int status, totalLen;
unsigned int length, lengthLen, count, index;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
unsigned char *temp;
VtItem *currentOid;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Is there anything?
*/
status = 0;
if ( (schemasBer == (unsigned char *)0) || (schemasBerLen < 5) )
break;
/* If there is already an OID list in the district object, we've
* already encountered a key schemas extension. There can only be one.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
if (obj->keySchemas.oids != (VtItem *)0)
break;
/* This is supposed to be a SEQUENCE.
*/
VOLT_SET_FNCT_LINE (fnctLine)
if (schemasBer[0] != 0x30)
break;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltDecodeDerLength (
schemasBer, schemasBerLen, &lengthLen, &length);
if (status != 0)
break;
schemasBer += (1 + lengthLen);
schemasBerLen -= (1 + lengthLen);
/* How many OID's are there?
*/
count = 0;
totalLen = (int)schemasBerLen;
temp = schemasBer;
while (totalLen > 0)
{
/* Make sure we have an OID.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
if (temp[0] != 6)
break;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltDecodeDerLength (
temp, (unsigned int)totalLen, &lengthLen, &length);
if (status != 0)
break;
temp += (1 + lengthLen + length);
totalLen -= (int)(1 + lengthLen + length);
count++;
}
if (status != 0)
break;
/* Allocate the rquired number of VtItem's.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
obj->keySchemas.oids = (VtItem *)Z2Malloc (sizeof (VtItem) * count, 0);
if (obj->keySchemas.oids == (VtItem *)0)
break;
Z2Memset (obj->keySchemas.oids, 0, sizeof (VtItem) * count);
obj->keySchemas.count = count;
/* Go through the encoding again, collecting the OID's this time.
*/
totalLen = (int)schemasBerLen;
for (index = 0; index < count; ++index)
{
/* Paranoid programming sanity check.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ENCODING;
if (totalLen <= 0)
break;
currentOid = &(obj->keySchemas.oids[index]);
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltDecodeDerLength (
schemasBer, (unsigned int)totalLen, &lengthLen, &length);
if (status != 0)
break;
/* Copy the data.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
currentOid->data = (unsigned char *)Z2Malloc (length, 0);
if (currentOid->data == (unsigned char *)0)
break;
Z2Memcpy (currentOid->data, schemasBer + 1 + lengthLen, length);
currentOid->len = length;
totalLen -= (int)(1 + lengthLen + length);
schemasBer += (1 + lengthLen + length);
status = 0;
}
} while (0);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, errorType, fnctLine,
"GetKeySchemas", (char *)0)
return (status);
}
static int GetDSAParams (
unsigned char *paramsBer,
unsigned int paramsBerLen,
VoltDistrictObject *obj
)
{
int status;
unsigned int bufferSize, offset;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
Asn1DsaParams *dsaParams = (Asn1DsaParams *)0;
unsigned char *temp;
unsigned char *buffer = (unsigned char *)0;
VtDSAParamInfo *paramInfo;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Decode the params.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
dsaParams = Asn1DsaParams_new ();
if (dsaParams == (Asn1DsaParams *)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_UNKNOWN_BER;
temp = paramsBer;
d2i_Asn1DsaParams (&dsaParams, &temp, (int)paramsBerLen);
/* Did it work?
*/
if (dsaParams == (Asn1DsaParams *)0)
break;
/* If the object already contains params, clear them.
*/
if (obj->districtDSAParams != (VtDSAParamInfo *)0)
Z2Free (obj->districtDSAParams);
obj->districtDSAParams = (VtDSAParamInfo *)0;
/* Allocate a buffer big enough to hold the DSAParamInfo shell and
* each of the values.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize =
sizeof (VtDSAParamInfo) + (unsigned int)(dsaParams->prime->length) +
(unsigned int)(dsaParams->subprime->length) +
(unsigned int)(dsaParams->base->length);
buffer = (unsigned char *)Z2Malloc (bufferSize, 0);
if (buffer == (unsigned char *)0)
break;
Z2Memset (buffer, 0, bufferSize);
/* Set the pointers.
*/
paramInfo = (VtDSAParamInfo *)buffer;
offset = sizeof (VtDSAParamInfo);
paramInfo->primeP.data = buffer + offset;
offset += (unsigned int)(dsaParams->prime->length);
paramInfo->subprimeQ.data = buffer + offset;
offset += (unsigned int)(dsaParams->subprime->length);
paramInfo->baseG.data = buffer + offset;
/* Copy the data.
*/
Z2Memcpy (
paramInfo->primeP.data, dsaParams->prime->data,
dsaParams->prime->length);
paramInfo->primeP.len = (unsigned int)(dsaParams->prime->length);
Z2Memcpy (
paramInfo->subprimeQ.data, dsaParams->subprime->data,
dsaParams->subprime->length);
paramInfo->subprimeQ.len = (unsigned int)(dsaParams->subprime->length);
Z2Memcpy (
paramInfo->baseG.data, dsaParams->base->data, dsaParams->base->length);
paramInfo->baseG.len = (unsigned int)(dsaParams->base->length);
obj->districtDSAParams = paramInfo;
status = 0;
} while (0);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, VT_ERROR_TYPE_PRIMARY, fnctLine,
"GetDSAParams", (char *)0)
return (status);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -