📄 defaulttransprov.c
字号:
localCtx->asyncFlag, icServer);
if (status != 0)
break;
case VOLT_ASYNC_STATE_START:
case VOLT_ASYNC_STATE_CONTINUE:
/* We must have a storage ctx in order to work with
* asynchronous operations
*/
status = VT_ERROR_INVALID_STORAGE_ASYNC;
if (storageCtx == (VtStorageCtx)0)
break;
/* If START, we haven't called Continue yet, but we will now. If
* CONTINUE, we're calling it again.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltContinueDownloadKeyAndCert (
transportCtx, identity, policyCtx, storageCtx,
signingCert, ibePriKey, &tokenList, &asyncContinueFlag,
appSpecificData);
if (status != 0)
break;
/* Did this call obtain key and/or cert?
*/
if ((asyncContinueFlag & VOLT_ASYNC_CONTINUE_KEY) != 0)
keyFlag = 0;
if ((asyncContinueFlag & VOLT_ASYNC_CONTINUE_CERT) != 0)
certFlag = 0;
}
do
{
/* If there was an error in the switch, quit now.
*/
if (status != 0)
break;
/* If we completed the download, one more call to surrender.
*/
if (surrCtx != (VoltSurrenderCtx *)0)
{
surrCtx->surrenderInfo.callingFlag = VT_SURRENDER_FNCT_IBE_KEY_DOWNLOAD;
surrCtx->surrenderInfo.callCount = 2;
surrCtx->surrenderInfo.callNumber = 2;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = surrCtx->Surrender (
surrCtx->libraryCtx, surrCtx->appData, &(surrCtx->surrenderInfo));
if (status != 0)
break;
}
/* Extract the private key and cert from the ServerResponse struct.
* If any of these objects are NULL it means caller is not interested
* in receiving that value.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
if (keyFlag != 0)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltSetPrivateKeyObject (
libCtx, distObj->paramObj, obj->encoding.data, obj->encoding.len,
icServer->serverResponseData.privateKey,
(unsigned int)(icServer->serverResponseData.privateKeyLen),
ibePriKey);
if (status != 0)
break;
}
if (certFlag != 0)
{
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltSetCertObject (
libCtx, icServer->serverResponseData.asn1Cert, signingCert);
if (status != 0)
break;
}
} while (0);
VoltDestroyArbitraryStorageObject (&arbitObj);
if (asnCertReq != (Asn1P10Request *)0)
Asn1P10Request_free (asnCertReq);
if (policyServer != (unsigned char *)0)
Z2Free (policyServer);
if (icServer != (mIcServerObject *)0)
{
/* Null the fields we took care of explicitly in this routine.
*/
icServer->serverRequestData.server = (char *)0;
icServer->serverRequestData.authTokens = (char **)0;
icServer->serverRequestData.authTokensCount = 0;
icServer->serverRequestData.id = (unsigned char *)0;
icServer->serverRequestData.idLen = 0;
icServer->serverRequestData.request = (Asn1P10Request *)0;
mIcServerDestroyObject (&icServer);
}
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, errorType, fnctLine,
"VoltDefaultDownloadKeyAndCert", (char *)0)
return (status);
}
int VoltSetPrivateKeyObject (
VoltLibCtx *libCtx,
VtParameterObject ibeParams,
unsigned char *encodedId,
unsigned int encodedIdLen,
unsigned char *priKeyDer,
unsigned int priKeyDerLen,
VtKeyObject keyObj
)
{
int status;
VtBFType1IBEPriKeyInfo priKeyInfo;
Asn1IBEPrivateKey *ibeKey = (Asn1IBEPrivateKey *)0;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Decode the key.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltDecodeIBEPriKeyDataCreate (
libCtx, priKeyDer, priKeyDerLen, &ibeKey);
if (status != 0)
break;
/* Set the key object with this data. This came from the key
* server, so we have only the y-coordinate of the point.
*/
priKeyInfo.ibeParams = ibeParams;
priKeyInfo.encodedId.data = encodedId;
priKeyInfo.encodedId.len = encodedIdLen;
priKeyInfo.privatePoint.isInfinity = 0;
priKeyInfo.privatePoint.xCoord.data = (unsigned char *)0;
priKeyInfo.privatePoint.xCoord.len = 0;
priKeyInfo.privatePoint.yCoord.data = ibeKey->privateData->value->data;
priKeyInfo.privatePoint.yCoord.len =
(unsigned int)(ibeKey->privateData->value->length);
VOLT_SET_FNCT_LINE (fnctLine)
status = VtSetKeyParam (
keyObj, VtKeyParamBFType1IBEPrivate, (Pointer)&priKeyInfo);
} while (0);
if (ibeKey != (Asn1IBEPrivateKey *)0)
Asn1IBEPrivateKey_free (ibeKey);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, 0, fnctLine,
"VoltSetPrivateKeyObject", (char *)0)
return (status);
}
int VoltSetCertObject (
VoltLibCtx *libCtx,
Asn1X509Cert *cert,
VtCertObject certObj
)
{
int status;
unsigned int certLen;
unsigned char *certDer = (unsigned char *)0;
unsigned char *temp;
VtCertInfo certInfo;
/* This transport provider recognizes only DSA certs.
*/
VtDerCoder *derCoders[1] = { VtDerCoderDSAPublicKey };
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Get the DER of the cert.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_INPUT;
certLen = i2d_Asn1X509Cert (cert, (unsigned char **)0);
if (certLen == 0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
certDer = (unsigned char *)Z2Malloc (certLen, 0);
if (certDer == (unsigned char *)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_INPUT;
temp = certDer;
certLen = i2d_Asn1X509Cert (cert, &temp);
if (certLen == 0)
break;
/* Set the key object using VtKeySetTypeX509Cert.
*/
certInfo.derCoders = derCoders;
certInfo.derCoderCount = sizeof (derCoders);
certInfo.cert = certDer;
certInfo.certLen = certLen;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtSetCertParam (
certObj, VtCertParamX509Der, (Pointer)&certInfo);
} while (0);
if (certDer != (unsigned char *)0)
Z2Free (certDer);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, errorType, fnctLine,
"VoltSetCertObject", (char *)0)
return (status);
}
int VoltSetTransportAsync (
VtTransportCtx transportCtx,
VtIdentityObject idObj,
VtArbitraryStorageObject arbitObj,
VoltRequestInfoData *reqInfoData,
int previousStatus,
unsigned int asyncFlag,
mIcServerObject *icServer
)
{
int status;
unsigned int bufferSize, urlLen;
VoltIdentityObject *obj = (VoltIdentityObject *)idObj;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltAsyncSaveInfo *asyncInfo = (VoltAsyncSaveInfo *)0;
VoltArbitraryStorageHandle *arbitHandle = (VoltArbitraryStorageHandle *)0;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
switch (previousStatus)
{
default:
/* The previousStatus is the reason someone calls this function.
* It must be 0, PREVIOUS, ASYNC or PENDING. If not, just return
* that error.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = previousStatus;
break;
case 0:
/* The previousStatus is 0, meaning we just want to build the
* shell of the asyncInfo.
*/
obj->asyncStatus = 0;
/* If there is already some info, destroy it.
*/
if ( (obj->asyncDownloadInfo != (Pointer)0) &&
(obj->AsyncDownloadInfoDestroy != (VCtxDestroy)0) )
obj->AsyncDownloadInfoDestroy ((Pointer)obj, obj->asyncDownloadInfo);
obj->asyncDownloadInfo = (Pointer)0;
obj->AsyncDownloadInfoDestroy = (VCtxDestroy)0;
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize = sizeof (VoltAsyncSaveInfo);
asyncInfo = (VoltAsyncSaveInfo *)Z2Malloc (bufferSize, 0);
if (asyncInfo == (VoltAsyncSaveInfo *)0)
break;
Z2Memset (asyncInfo, 0, bufferSize);
obj->asyncDownloadInfo = (Pointer)asyncInfo;
obj->AsyncDownloadInfoDestroy = AsyncInfoDestroy;
/* Build the tokenListObj.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltCreateAuthTokenListObject (
(VtLibCtx)libCtx, &(asyncInfo->tokenListObj));
/* If successful, initialize the state to SETUP.
*/
if (status == 0)
asyncInfo->state = VOLT_ASYNC_STATE_SETUP;
break;
case VT_ERROR_ASYNC_DOWNLOAD:
asyncInfo = (VoltAsyncSaveInfo *)(obj->asyncDownloadInfo);
obj->asyncStatus = VT_ERROR_ASYNC_DOWNLOAD;
/* We discovered ASYNC, we don't know if we're going to execute
* the async op yet.
* First, get an arbitrary storage handle so we can see if we're
* PREVIOUS as well.
*/
if (arbitObj != (VtArbitraryStorageObject)0)
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltArbitraryGetEntryHandle (
arbitObj, (Pointer)&(obj->encoding), &arbitHandle);
if (status != 0)
break;
}
/* Copy the URL in the serverResponseData.
* Although the field should be NULL, use Realloc just to be safe.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
urlLen = Z2Strlen (icServer->serverResponseData.url);
asyncInfo->url = (unsigned char *)Z2Realloc (
asyncInfo->url, urlLen + 1);
if (asyncInfo->url == (unsigned char *)0)
break;
Z2Memcpy (asyncInfo->url, icServer->serverResponseData.url, urlLen);
asyncInfo->url[urlLen] = 0;
/* Set the async state to WAIT, if it turns out we don't wait,
* we'll change it back.
*/
asyncInfo->state = VOLT_ASYNC_STATE_WAIT;
/* Do we have a PREVIOUS?
*/
if (arbitHandle != (VoltArbitraryStorageHandle *)0)
{
if (arbitHandle->entryCount != 0)
{
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_DOWNLOAD_PREVIOUS;
obj->asyncStatus = status;
if ((asyncFlag & VT_PREVIOUS_RESPONSE_ALERT) != 0)
break;
}
}
/* Either there is no previous or the asyncFlag indicates we
* should ignore PREVIOUS.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_ASYNC_DOWNLOAD;
obj->asyncStatus = status;
if ((asyncFlag & VT_ASYNC_RESPONSE_ALERT) != 0)
break;
/* Indicate we should go ahead and start the async op.
*/
status = 0;
obj->asyncStatus = VT_ERROR_DOWNLOAD_PENDING;
asyncInfo->state = VOLT_ASYNC_STATE_START;
break;
case VT_ERROR_DOWNLOAD_PREVIOUS:
/* There is a PREVIOUS request and the caller wants to go ahead
* and start the new request, we'll need to store the request
* info. In order to do that, we'll need a handle.
*/
asyncInfo = (VoltAsyncSaveInfo *)(obj->asyncDownloadInfo);
asyncInfo->state = VOLT_ASYNC_STATE_START;
status = 0;
obj->asyncStatus = VT_ERROR_DOWNLOAD_PENDING;
if (arbitObj != (VtArbitraryStorageObject)0)
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltArbitraryGetEntryHandle (
arbitObj, (Pointer)&(obj->encoding), &arbitHandle);
}
break;
case VT_ERROR_DOWNLOAD_PENDING:
/* If PENDING, either this is the continuation call after the
* discovery of ASYNC because the transport was set to
* VT_ASYNC_RESPONSE_CONTINUE, or this is a later call, checking
* to see if the download is done.
* Either way, just make sure the state is set to CONTINUE.
*/
status = 0;
obj->asyncStatus = VT_ERROR_DOWNLOAD_PENDING;
asyncInfo = (VoltAsyncSaveInfo *)(obj->asyncDownloadInfo);
asyncInfo->state = VOLT_ASYNC_STATE_CONTINUE;
}
if (status == 0)
{
if (asyncInfo->state == VOLT_ASYNC_STATE_START)
{
if (arbitObj != (VtArbitraryStorageObject)0)
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltArbitraryStoreEntry (
arbitObj, arbitHandle, (Pointer)reqInfoData);
}
}
}
VoltArbitraryReleaseHandle (arbitObj, &arbitHandle);
VOLT_LOG_ERROR_COMPARE (
status, (VtLibCtx)libCtx, status, errorType, fnctLine,
"VoltSetTransportAsync", (char *)0)
return (status);
}
void AsyncInfoDestroy (
Pointer obj,
Pointer ctx
)
{
VoltObject *voltObj;
VoltAsyncSaveInfo *asyncInfo;
VoltLibCtx *libCtx;
/* Anything to destroy?
*/
if ( (obj == (Pointer)0) || (ctx == (Pointer)0) )
return;
voltObj = (VoltObject *)obj;
libCtx = (VoltLibCtx *)(voltObj->libraryCtx);
asyncInfo = (VoltAsyncSaveInfo *)ctx;
if (asyncInfo->url != (unsigned char *)0)
Z2Free (asyncInfo->url);
VoltDestroyAuthTokenListObject (&(asyncInfo->tokenListObj));
Z2Free (ctx);
}
void DefaultLocalTransCtxDestroy (
Pointer obj,
Pointer ctx
)
{
VoltObject *voltObj = (VoltObject *)obj;
VoltLibCtx *libCtx;
/* Anything to destroy?
*/
if ( (obj == (Pointer)0) || (ctx == (Pointer)0) )
return;
libCtx = (VoltLibCtx *)(voltObj->libraryCtx);
/* Free the shell.
*/
Z2Free (ctx);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -