⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osptnepinit.c

📁 mgcp协议源代码。支持多种编码:g711
💻 C
📖 第 1 页 / 共 5 页
字号:
        retVal =             OSPPInitNonSSLCommMgrParams(                 ospvEnrollParamsIn->CAUrl,                ospvCommParamsIn,                 *ospvCommOut );        if ( retVal != OSPC_ERR_NO_ERROR )        {            OSPM_DBGERRORLOG(                 retVal,                 "Unable to initialize the communication manager's parameters for the CA.\n" );        }    }    OSPM_DBGEXIT(( "OSPPInitNonSecureCommMgr\n" ));    return retVal;}    /* * Initialize the communications manager's SSL-related parameters. In this * case, we'll need: the CA certificate ( given in the CACert field of * the enrollment parameters ); the service point to be accessed * ( given in the SSLUrl field of the enrollment parameters ); the * lifetime of an SSL session ( given in the SSLLifetime field of the * communications parameters ); and the communications manager itself. * * Input: a list of enrollment parameters ( for the CACert and SSLUrl fields of *        the OSPTENROLLPARAMS* ); a list of communications parameters *        ( for the SSLLifetime field of the OSPTCOMMPARAMS* ); and a *        reference to a communications manager. * * Output: the communications manager will have its parameters set, if *         possible. A return value of OSPC_ERR_NO_ERROR should indicate that *         there have been no problems. Any other return value will indicate *         an error. */int OSPPInitSSLCommMgrParams(    OSPTENROLLPARAMS* ospvEnrollParamsIn,    OSPTCOMMPARAMS*   ospvCommParamsIn,    OSPTCOMM*         ospvCommOut){    int retVal = OSPC_ERR_NO_ERROR;    OSPM_DBGENTER(( "ENTER: OSPPInitSSLCommMgrParams\n" ));    /* Check the references to the parameters first. We'll be using     * the SSLUrl field of the enrollment parameters list for the     * service point, so we'll need to check that as well:     */    if ( ( ospvEnrollParamsIn == OSPC_OSNULL ) ||          ( ospvEnrollParamsIn->SSLUrl == OSPC_OSNULL ) ||         ( ospvCommParamsIn == OSPC_OSNULL ) ||          ( ospvCommOut == OSPC_OSNULL ) )    {        retVal = OSPC_ERR_ENROLL_INVALID_ARG;        OSPM_DBGERRORLOG(             retVal,             "The parameters for initializing the enrollment server communications were invalid.\n" );    }    /* If ( there were no problems ) then     *  o set all of the communication manager's parameters, including     *    connectivity parameters and the CA certificate.      *    The CA certificate will be retrieved if necessary.     */    if ( retVal == OSPC_ERR_NO_ERROR )    {        /* Create a new security object. Note that we need the address         * of the communication's manager's security object pointer, so         * we need to dereference the ospvCommOut, access its security         * object, and then take its address. Not pretty.         */        retVal = OSPPSecNew( &(ospvCommOut->Security) );        if ( retVal != OSPC_ERR_NO_ERROR )        {            OSPM_DBGERRORLOG(                 retVal, "Unable to create security object for comm mgr." );        }    }    /* If ( there weren't any problems ) then     *  o set the SSL lifetime and max number of connections     *  o record any errors.      */    if ( retVal == OSPC_ERR_NO_ERROR )    {        OSPPSecSetSSLLifetime(             ospvCommOut->Security, ospvCommParamsIn->SSLLifetime );        OSPM_DBGMISC(( "CA cert: \n" ));        OSPPDumpHex( ospvEnrollParamsIn->CACert, ospvEnrollParamsIn->CACertLen );        retVal =             OSPPSecSetAuthorityCertificates(                ospvCommOut->Security,                 1,                &(ospvEnrollParamsIn->CACert) );        if ( retVal != OSPC_ERR_NO_ERROR )        {            OSPM_DBGERRORLOG(                 retVal,                 "Unable to set the authority certs for the communications manager.\n" );        }    }	/* Initialize the SSL context for the communication manager.	 * If we fail, then report the error and set an error code.	 */	if ( retVal == OSPC_ERR_NO_ERROR )	{		retVal = OSPPSSLWrapInit( (void*)(ospvCommOut->Security) );		if ( retVal != OSPC_ERR_NO_ERROR )		{			OSPM_DBGERRORLOG( retVal, "Unable to initialize SSL context.\n" );		}	}    OSPM_DBGMISC(( "Return value: <%d>\n", retVal ));    OSPM_DBGEXIT(( "EXIT: OSPPInitSSLCommMgrParams\n" ));    return retVal;}/* Initialize all of the non-SSL related parameters; we'll set the * retry delay, http timeout, persistence values, and so on. All of * the SSL-related parameters are set in the OSPPInitSSLCommMgrParams, * which won't be necessary for certain functions ( like retrieving the * CA certificate, which is currently done without SSL. ) * * We'll be using this function for establishing basic parameters that * aren't dependent on the use of the communications manager, so we'll * need a generic service point specification, instead of assuming that * it will be in the CAUrl or SSLUrl fields of an OSPTENROLLPARAM*  * structure. Doing the service point initialization here just eliminates * duplication of effort. * * Input: pointers to the communications parameters and the service point's *        url, as well as the outgoing communications manager.  * * Output: The communication manager's parameters should be set up. *         A return value of OSPC_ERR_NO_ERROR is returned if everything *         worked out; otherwise, an error code is returned. */int OSPPInitNonSSLCommMgrParams(    unsigned char*    ospvServicePtUrlIn,    OSPTCOMMPARAMS*   ospvCommParamsIn,    OSPTCOMM*         ospvCommOut ){    int retVal = OSPC_ERR_NO_ERROR;    OSPM_DBGENTER(( "ENTER: OSPPInitNonSSLCommMgrParams\n" ));    /* set an error code and complain if we can't use the input parameters: */    if ( ( ospvCommParamsIn == OSPC_OSNULL ) ||         ( ospvCommOut == OSPC_OSNULL ) )    {        retVal = OSPC_ERR_ENROLL_INVALID_ARG;        OSPM_DBGERRORLOG(             retVal,             "At least one parameter is invalid (null)\n");    }    /* If ( there weren't any problems ) then     *  o set the HTTP persistence      *  o record any errors.      */    if ( retVal == OSPC_ERR_NO_ERROR )    {        retVal =            OSPPCommSetPersistence(                 ospvCommOut,                 ospvCommParamsIn->HTTPPersistence );        if ( retVal != OSPC_ERR_NO_ERROR )        {            OSPM_DBGERRORLOG(                 retVal,                 "Unable to set HTTP persistence" );        }    }    /* If ( there weren't any problems ) then     *  o set the http retry delay      *  o record any errors.      */    if ( retVal == OSPC_ERR_NO_ERROR )    {        retVal =             OSPPCommSetRetryDelay(                 ospvCommOut,                 ospvCommParamsIn->HTTPRetryDelay );                if ( retVal != OSPC_ERR_NO_ERROR )        {            OSPM_DBGERRORLOG(                 retVal,                 "Unable to set HTTP retry delay." );        }    }    /* If ( there weren't any problems ) then     *  o set the http retry limit      *  o record any errors.      */    if ( retVal == OSPC_ERR_NO_ERROR )    {        retVal =             OSPPCommSetRetryLimit(                 ospvCommOut,                 ospvCommParamsIn->HTTPRetryLimit );                if ( retVal != OSPC_ERR_NO_ERROR )        {            OSPM_DBGERRORLOG(                 retVal,                 "Unable to set HTTP Retry Limit." );        }    }            /* If ( there weren't any problems ) then     *  o set the http timeout     *  o record any errors.      */    if ( retVal == OSPC_ERR_NO_ERROR )    {        retVal =             OSPPCommSetTimeout(                 ospvCommOut,                 ospvCommParamsIn->HTTPTimeout );                if ( retVal != OSPC_ERR_NO_ERROR )        {            OSPM_DBGERRORLOG(                 retVal,                 "Unable to set HTTP timeout." );        }    }    /* Now set the service point and record any errors: */    if ( retVal == OSPC_ERR_NO_ERROR )    {        OSPM_DBGMISC(( "enrollment url: <%s>\n", ospvServicePtUrlIn ));         retVal =             OSPPCommSetServicePoints(                 ospvCommOut,                 1,                 (const char**)&(ospvServicePtUrlIn) );        if ( retVal != OSPC_ERR_NO_ERROR )        {            OSPM_DBGMISC(( "Unable to set service points: <%d>\n", retVal ));        }    }    OSPM_DBGEXIT(( "EXIT: OSPPInitNonSSLCommMgrParams\n" ));    return retVal;}/* * This function will: initialize a communications manager; construct * a message to be sent to a service point; parse the results; and validate * the contents of the certificate. We'll need the enrollment parameters * so that we know which CA to contact for  a certificate, and we'll * need the communications parameters for initializing the communications * manager. The enrollment parameters will also be used to store the * CA certificate that is returned ( accessed by  * ospvEnrollParamsInOut->CACert ). * * Input: a pointer to the enrollment parameter list and a pointer to the *        communications parameter list. * * Output: the CA certificate ( if it was found ) in the enrollment parameter *         list ( under the CACert field ). OSPC_ERR_NO_ERROR is returned *         if everything went ok; otherwise, some other error code is returned. */int OSPPRetrieveCACert (    OSPTENROLLPARAMS* ospvEnrollParamsInOut,    OSPTCOMMPARAMS*   ospvCommParamsIn){    int retVal = OSPC_ERR_NO_ERROR;    /* The structure used for encapsulating the request and response: */    OSPTMSGINFO*   certReqMsg  = OSPC_OSNULL;    /* The request that we'll be building and sending to the CA via the     * certReqMsg ( which will also hold the response. )     */    unsigned char* caRequest      = OSPC_OSNULL;    /* The communications manager used for contacting the enrollment server     * ( or its CA ) and requesting the CA certificate:     */    OSPTCOMM*      caCommMgr      = OSPC_OSNULL;    /* The CA certificate response that will be null-terminated: */    unsigned char* caCertResponse = OSPC_OSNULL;    OSPM_DBGENTER(( "ENTER: OSPPRetrieveCACert\n" ));    /* Check the input parameters for null values first: */    if ( ( ospvCommParamsIn == OSPC_OSNULL ) ||          ( ospvEnrollParamsInOut == OSPC_OSNULL ) )    {        retVal = OSPC_ERR_ENROLL_INVALID_ARG;        OSPM_DBGERRORLOG(             retVal,             "Parameters were invalid; at least one was null.\n" );    }    /* Now initialize the communications manager: */    if ( retVal == OSPC_ERR_NO_ERROR )    {        retVal =             OSPPInitNonSecureCommMgr(                 ospvEnrollParamsInOut,                 ospvCommParamsIn,                 &caCommMgr );        if ( retVal != OSPC_ERR_NO_ERROR )        {            OSPM_DBGERRORLOG(                 retVal,                 "Unable to init communication with the CA.\n" );        }    }    /* If ( the parameters were ok ) then     *  o initialize the memory for the outbound message.     *  o if ( we coldn't initialize it ) then     *      - set an error code and complain.     */    if ( retVal == OSPC_ERR_NO_ERROR )    {        retVal = OSPPMsgInfoNew( &certReqMsg );        OSPM_MALLOC(             certReqMsg->ContentType,             unsigned char,             OSPM_STRLEN( OSPC_COMM_TEXT_MSG ) + 1 );        if ( certReqMsg->ContentType == OSPC_OSNULL )         {            retVal = OSPC_ERR_ENROLL_NO_MEMORY;            OSPM_DBGERRORLOG(                 retVal,                 "No memory is available for the CA certificate request.\n" );        }    }    /* If ( we could create the message info structure ) then     *  o create the retrieval request to be sent     */    if ( retVal == OSPC_ERR_NO_ERROR )    {        retVal =             OSPPCreateCARetrievalRequest(                 ospvEnrollParamsInOut, &caRequest );        /* Print out an error if there was something wrong: */        if ( retVal != OSPC_ERR_NO_ERROR )        {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -