?? districtprov.c
字號(hào):
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "vsdistrict.h"
#include "derhelp.h"
#include "oidlist.h"
#include "ibe.h"
#include "dsaparamsder.h"
#include "vtime.h"
#include "errorctx.h"
#if VOLT_OS == VOLT_WINDOWS_32
#include <windows.h>
#include <wininet.h>
#endif
/* Build a VtParameterObject from the given parameters and public
* point. The public point is the x-coordinate only.
* <p>This call will create a new object and deposit at the address
* given by paramObj.
*
* @param libraryCtx The lib ctx to use.
* @param mpCtx
* @param ecParams The EC params (prime, subprime, etc.) to use.
* @param pubPoint The public point to use (x-coordinate).
* @param paramObj The address where the function will deposit the
* created and set parameter object.
* @return an int, 0 if the function completed successfully or a
* non-zero error code.
*/
static int VOLT_CALLING_CONV BuildParamObject VOLT_PROTO_LIST ((
VtLibCtx libraryCtx,
VoltMpIntCtx *mpCtx,
EC_PARAMETERS *ecParams,
ASN1_OCTET_STRING *pubPoint,
VtParameterObject *paramObj
));
/* Extract the key schemas from the BER value and build the VtOidList
* in the district object.
* <p>The schemasBer is the BER encoding of the following ASN.1
* definition.
*
* SEQUENCE OF {
* oid OBJECT IDENTIFIER }
*
* @param schemasBer The BER of the schemas, the value of the parameter
* extension.
* @param schemasBerLen The length, in bytes, of the input data.
* @param obj The district object containing the VtOidList to fill with
* the schemas.
* @return an int, 0 if the function completed successfully or a
* non-zero error code.
*/
static int VOLT_CALLING_CONV GetKeySchemas VOLT_PROTO_LIST ((
unsigned char *schemasBer,
unsigned int schemasBerLen,
VoltDistrictObject *obj
));
/* Extract the DSA Params from the BER value and build the
* VtDSAParamInfo struct in the district object.
* <p>The paramsBer is the BER encoding of the following ASN.1
* definition.
*
* SEQUENCE {
* prime INTEGER,
* subprime INTEGER,
* base INTEGER }
*
* @param paramsBer The BER of the params, the value of the parameter
* extension.
* @param paramsBerLen The length, in bytes, of the input data.
* @param obj The district object where the DSA params are to be
* deposited.
* @return an int, 0 if the function completed successfully or a
* non-zero error code.
*/
static int VOLT_CALLING_CONV GetDSAParams VOLT_PROTO_LIST ((
unsigned char *paramsBer,
unsigned int paramsBerLen,
VoltDistrictObject *obj
));
int mIcDistrictCreateObject (
VtLibCtx libraryCtx,
VDoHttp DoHttp,
Pointer uiHandle,
unsigned char *trustStore,
unsigned long timeOut,
mIcDistrictObject **mIcDistObj
)
{
mIcDistrictObject *newObj = (mIcDistrictObject *)0;
VoltLibCtx *libCtx = (VoltLibCtx *)libraryCtx;
VOLT_DECLARE_FNCT_LINE (fnctLine)
/* Create an empty struct.
*/
VOLT_SET_FNCT_LINE (fnctLine)
newObj = (mIcDistrictObject *)Z2Malloc (sizeof (mIcDistrictObject), 0);
if (newObj == (mIcDistrictObject *)0)
{
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, VT_ERROR_MEMORY, VT_ERROR_TYPE_PRIMARY, fnctLine,
"mIcDistrictCreateObject", (char *)0)
return (VT_ERROR_MEMORY);
}
Z2Memset (newObj, 0, sizeof (mIcDistrictObject));
/* Fill in the fields.
*/
newObj->libCtx = libCtx;
newObj->DoHttp = mDoHTTP;
newObj->uiHandle = uiHandle;
newObj->trustStore = trustStore;
newObj->timeOut = timeOut;
if (DoHttp != (VDoHttp)0)
newObj->DoHttp = DoHttp;
*mIcDistObj = newObj;
return (0);
}
void mIcDistrictDestroyObject (
mIcDistrictObject **mIcDistObj
)
{
mIcDistrictObject *obj;
VoltLibCtx *libCtx;
/* Anything to destroy?
*/
if (mIcDistObj == (mIcDistrictObject **)0)
return;
if (*mIcDistObj == (mIcDistrictObject *)0)
return;
obj = *mIcDistObj;
libCtx = obj->libCtx;
/* If the fields are not NULL, free them.
*/
if (obj->icParams != (icDistrictParameters *)0)
icDistrictParametersFree (obj->icParams, libCtx);
if (obj->paramsText != (char *)0)
Z2Free (obj->paramsText);
/* Free the outer shell.
*/
Z2Free (obj);
}
int mIcDistrictRetrieveParams (
unsigned char *domain,
unsigned char *district,
mIcDistrictObject *mIcDistObj,
VtMpIntCtx mpCtx,
VoltLibCtx *libCtx
)
{
int status;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_SET_FNCT_LINE (fnctLine)
status = icRetrieveDistrictParameters (
&(mIcDistObj->icParams), &(mIcDistObj->paramsText), domain, district,
mIcDistObj->DoHttp, (void *)(mIcDistObj->uiHandle), mIcDistObj->trustStore,
mIcDistObj->timeOut, mpCtx, libCtx);
/* If successful, we're done.
*/
if (status == 0)
return (0);
/* If NETWORK_CONNECT, we couldn't find a server of the given name. Convert that
* to UNKNOWN_DISTRICT.
*/
if (status = VT_ERROR_NETWORK_CONNECT)
status = VT_ERROR_UNKNOWN_DISTRICT;
/* If error, free memory.
*/
if (mIcDistObj->icParams != (icDistrictParameters *)0)
icDistrictParametersFree (mIcDistObj->icParams, libCtx);
if (mIcDistObj->paramsText != (char *)0)
Z2Free (mIcDistObj->paramsText);
mIcDistObj->icParams = (icDistrictParameters *)0;
mIcDistObj->paramsText = (char *)0;
VOLT_LOG_ERROR (
(VtLibCtx)libCtx, status, 0, fnctLine,
"mIcDistrictRetrieveParams", (char *)0)
return (status);
}
int VoltSetDistFromParamsText (
char *paramsText,
unsigned int paramsTextLen,
VoltDistrictObject *distObj,
VoltMpIntCtx *mpCtx,
VoltLibCtx *libCtx
)
{
int status;
icDistrictParameters *icParams = (icDistrictParameters *)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Build the icParams struct from the paramsText.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = icDistrictParametersNew (
&icParams, paramsText, paramsTextLen, (VtMpIntCtx)mpCtx, libCtx);
if (status != 0)
break;
/* Now set from the icParams.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltSetDistFromIcParams (
paramsText, paramsTextLen, icParams, mpCtx, distObj);
} while (0);
if (icParams != (icDistrictParameters *)0)
icDistrictParametersFree (icParams, libCtx);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, 0, fnctLine,
"mIcDistrictRetrieveParams", (char *)0)
return (status);
}
int VoltSetDistFromIcParams (
char *paramsText,
unsigned int paramsTextLen,
icDistrictParameters *icParams,
VoltMpIntCtx *mpCtx,
VoltDistrictObject *obj
)
{
int status, count, index;
unsigned int certIndex, tempLen;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
unsigned char *temp;
IC_USAGE_PARAMS *usageParams;
VtUsageParams *currentUsageParams;
EC_PARAMETERS *paramsToUse;
Asn1X509Extension *extension;
VtX509Extension *currentExtension;
VtCertObject newCert = (VtCertObject)0;
unsigned char *certBuffer = (unsigned char *)0;
VtDerCoder *derCoders[1] = { VtDerCoderDSAPublicKey };
VtCertInfo certInfo;
unsigned char type1Oid[VoltBFType1IBECurveOidBytesLen] =
{ VoltBFType1IBECurveOidBytes };
unsigned char keySchemaOid[VoltParamExtKeySchemaOidBytesLen] =
{ VoltParamExtKeySchemaOidBytes };
unsigned char dsaParamsExtOid[VoltParamExtDsaParamsOidBytesLen] =
{ VoltParamExtDsaParamsOidBytes };
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
/* This supports only one kind of cert.
*/
certInfo.derCoders = derCoders;
certInfo.derCoderCount = 1;
do
{
/* Make sure these are type 1 params.
*/
tempLen = (unsigned int)(icParams->pubParams->defECParams->curve->type->length);
temp = icParams->pubParams->defECParams->curve->type->data;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_CURVE_TYPE_NOT_SUPPORTED;
if (tempLen != VoltBFType1IBECurveOidBytesLen)
break;
if (Z2Memcmp (temp, type1Oid, VoltBFType1IBECurveOidBytesLen) != 0)
break;
/* Get the validity dates. Convert to VtTime. The time in the
* encoding is either UTC or GeneralizedTime.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
temp = icParams->pubParams->validity->notBefore->data;
tempLen = (unsigned int)
(icParams->pubParams->validity->notBefore->length);
if (tempLen == VOLT_UTC_LEN)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltConvertUTCToVtTime (libCtx, temp, &(obj->validityStart));
}
else
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltConvertGenTimeToVtTime (
libCtx, temp, tempLen, &(obj->validityStart));
}
if (status != 0)
break;
temp = icParams->pubParams->validity->notAfter->data;
tempLen = (unsigned int)
(icParams->pubParams->validity->notAfter->length);
if (tempLen == VOLT_UTC_LEN)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltConvertUTCToVtTime (libCtx, temp, &(obj->validityEnd));
}
else
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltConvertGenTimeToVtTime (
libCtx, temp, tempLen, &(obj->validityEnd));
}
if (status != 0)
break;
/* Build the default parameter object.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = BuildParamObject (
obj->voltObject.libraryCtx, mpCtx, icParams->pubParams->defECParams,
icParams->pubParams->defReference, &(obj->paramObj));
if (status != 0)
break;
/* We need the qualified district name.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = mIcDistParamsGetDistrictName (icParams, obj);
if (status != 0)
break;
/* Get UsageParams out.
*/
count = sk_num (icParams->pubParams->usageParams);
if (count != 0)
{
/* Create the array of UsageParams structs.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
obj->usageParamsList.paramsList = (VtUsageParams *)Z2Malloc (
sizeof (VtUsageParams) * count, 0);
if (obj->usageParamsList.paramsList == (VtUsageParams *)0)
break;
Z2Memset (
obj->usageParamsList.paramsList, 0, sizeof (VtUsageParams) * count);
obj->usageParamsList.count = (unsigned int )count;
*/
for (index = 0; index < count; ++index)
{
usageParams = (IC_USAGE_PARAMS *)sk_value (
icParams->pubParams->usageParams, index);
currentUsageParams =
(VtUsageParams *)&(obj->usageParamsList.paramsList[index]);
/* Copy the OID.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
currentUsageParams->oid.data = (unsigned char *)Z2Malloc (
usageParams->usage->length, 0);
if (currentUsageParams->oid.data == (unsigned char *)0)
break;
Z2Memcpy (
currentUsageParams->oid.data, usageParams->usage->data,
usageParams->usage->length);
currentUsageParams->oid.len =
(unsigned int)(usageParams->usage->length);
/* Build the param object. If the given usage params do not
* include the EC Params, use the default params.
*/
paramsToUse = usageParams->ecParams;
if (paramsToUse == (EC_PARAMETERS *)0)
paramsToUse = icParams->pubParams->defECParams;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = BuildParamObject (
obj->voltObject.libraryCtx, mpCtx, paramsToUse,
usageParams->reference, &(currentUsageParams->params));
if (status != 0)
break;
}
if (status != 0)
break;
}
/* Get the extensions out.
*/
count = sk_num (icParams->pubParams->extensions);
if (count != 0)
{
/* Create the array of Extension structs.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
obj->extensionList.extensions = (VtX509Extension *)Z2Malloc (
sizeof (VtX509Extension) * count, 0);
if (obj->extensionList.extensions == (VtX509Extension *)0)
break;
Z2Memset (
obj->extensionList.extensions, 0, sizeof (VtX509Extension) * count);
obj->extensionList.count = (unsigned int )count;
/* Copy each extension. At the same time, look for the supported
* key schemas extension and the DSA params extension.
*/
for (index = 0; index < count; ++index)
{
extension = (Asn1X509Extension *)sk_value (
icParams->pubParams->extensions, index);
currentExtension = &(obj->extensionList.extensions[index]);
/* Copy the OID.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
currentExtension->oid.data = (unsigned char *)Z2Malloc (
extension->oid->base.length, 0);
if (currentExtension->oid.data == (unsigned char *)0)
break;
Z2Memcpy (
currentExtension->oid.data, extension->oid->base.data,
extension->oid->base.length);
currentExtension->oid.len = (unsigned int)(extension->oid->base.length);
/* Copy the extension data.
*/
currentExtension->value.data = (unsigned char *)Z2Malloc (
extension->value->length, 0);
if (currentExtension->value.data == (unsigned char *)0)
break;
Z2Memcpy (
currentExtension->value.data, extension->value->data,
extension->value->length);
currentExtension->value.len = (unsigned int)(extension->value->length);
/* Set the criticality.
*/
currentExtension->critical = 0;
if (extension->critical != 0)
currentExtension->critical = 1;
status = 0;
/* If this is the supported key schemas extension, copy the
* OID's out.
*/
if (currentExtension->oid.len == VoltParamExtKeySchemaOidBytesLen)
{
if (Z2Memcmp (
currentExtension->oid.data, keySchemaOid,
VoltParamExtKeySchemaOidBytesLen) == 0)
{
/* This is the key schema extension.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = GetKeySchemas (
currentExtension->value.data, currentExtension->value.len, obj);
if (status != 0)
break;
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -