andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: /* andre@0: * pkix_pl_nsscontext.c andre@0: * andre@0: * NSSContext Function Definitions andre@0: * andre@0: */ andre@0: andre@0: andre@0: #include "pkix_pl_nsscontext.h" andre@0: andre@0: #define PKIX_DEFAULT_MAX_RESPONSE_LENGTH 64 * 1024 andre@0: #define PKIX_DEFAULT_COMM_TIMEOUT_SECONDS 60 andre@0: andre@0: #define PKIX_DEFAULT_CRL_RELOAD_DELAY_SECONDS 6 * 24 * 60 * 60 andre@0: #define PKIX_DEFAULT_BAD_CRL_RELOAD_DELAY_SECONDS 60 * 60 andre@0: andre@0: /* --Public-NSSContext-Functions--------------------------- */ andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PL_NssContext_Create andre@0: * (see comments in pkix_samples_modules.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PL_NssContext_Create( andre@0: PKIX_UInt32 certificateUsage, andre@0: PKIX_Boolean useNssArena, andre@0: void *wincx, andre@0: void **pNssContext) andre@0: { andre@0: PKIX_PL_NssContext *context = NULL; andre@0: PLArenaPool *arena = NULL; andre@0: void *plContext = NULL; andre@0: andre@0: PKIX_ENTER(CONTEXT, "PKIX_PL_NssContext_Create"); andre@0: PKIX_NULLCHECK_ONE(pNssContext); andre@0: andre@0: PKIX_CHECK(PKIX_PL_Malloc andre@0: (sizeof(PKIX_PL_NssContext), (void **)&context, NULL), andre@0: PKIX_MALLOCFAILED); andre@0: andre@0: if (useNssArena == PKIX_TRUE) { andre@0: PKIX_CONTEXT_DEBUG("\t\tCalling PORT_NewArena\n"); andre@0: arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); andre@0: } andre@0: andre@0: context->arena = arena; andre@0: context->certificateUsage = (SECCertificateUsage)certificateUsage; andre@0: context->wincx = wincx; andre@0: context->timeoutSeconds = PKIX_DEFAULT_COMM_TIMEOUT_SECONDS; andre@0: context->maxResponseLength = PKIX_DEFAULT_MAX_RESPONSE_LENGTH; andre@0: context->crlReloadDelay = PKIX_DEFAULT_CRL_RELOAD_DELAY_SECONDS; andre@0: context->badDerCrlReloadDelay = andre@0: PKIX_DEFAULT_BAD_CRL_RELOAD_DELAY_SECONDS; andre@0: context->chainVerifyCallback.isChainValid = NULL; andre@0: context->chainVerifyCallback.isChainValidArg = NULL; andre@0: *pNssContext = context; andre@0: andre@0: cleanup: andre@0: andre@0: PKIX_RETURN(CONTEXT); andre@0: } andre@0: andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PL_NssContext_Destroy andre@0: * (see comments in pkix_samples_modules.h) andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PL_NssContext_Destroy( andre@0: void *nssContext) andre@0: { andre@0: void *plContext = NULL; andre@0: PKIX_PL_NssContext *context = NULL; andre@0: andre@0: PKIX_ENTER(CONTEXT, "PKIX_PL_NssContext_Destroy"); andre@0: PKIX_NULLCHECK_ONE(nssContext); andre@0: andre@0: context = (PKIX_PL_NssContext*)nssContext; andre@0: andre@0: if (context->arena != NULL) { andre@0: PKIX_CONTEXT_DEBUG("\t\tCalling PORT_FreeArena\n"); andre@0: PORT_FreeArena(context->arena, PKIX_FALSE); andre@0: } andre@0: andre@0: PKIX_PL_Free(nssContext, NULL); andre@0: andre@0: PKIX_RETURN(CONTEXT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_NssContext_GetCertUsage andre@0: * DESCRIPTION: andre@0: * andre@0: * This function obtains the platform-dependent SECCertificateUsage parameter andre@0: * from the context object pointed to by "nssContext", storing the result at andre@0: * "pCertUsage". andre@0: * andre@0: * PARAMETERS: andre@0: * "nssContext" andre@0: * The address of the context object whose wincx parameter is to be andre@0: * obtained. Must be non-NULL. andre@0: * "pCertUsage" andre@0: * The address where the result is stored. Must be non-NULL. andre@0: * THREAD SAFETY: andre@0: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if the function succeeds. andre@0: * Returns a Fatal Error if the function fails in an unrecoverable way. andre@0: */ andre@0: PKIX_Error * andre@0: pkix_pl_NssContext_GetCertUsage( andre@0: PKIX_PL_NssContext *nssContext, andre@0: SECCertificateUsage *pCertUsage) andre@0: { andre@0: void *plContext = NULL; andre@0: andre@0: PKIX_ENTER(CONTEXT, "pkix_pl_NssContext_GetCertUsage"); andre@0: PKIX_NULLCHECK_TWO(nssContext, pCertUsage); andre@0: andre@0: *pCertUsage = nssContext->certificateUsage; andre@0: andre@0: PKIX_RETURN(CONTEXT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_NssContext_SetCertUsage andre@0: * DESCRIPTION: andre@0: * andre@0: * This function sets the platform-dependent SECCertificateUsage parameter in andre@0: * the context object pointed to by "nssContext" to the value provided in andre@0: * "certUsage". andre@0: * andre@0: * PARAMETERS: andre@0: * "certUsage" andre@0: * Platform-dependent value to be stored. andre@0: * "nssContext" andre@0: * The address of the context object whose wincx parameter is to be andre@0: * obtained. Must be non-NULL. andre@0: * THREAD SAFETY: andre@0: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if the function succeeds. andre@0: * Returns a Fatal Error if the function fails in an unrecoverable way. andre@0: */ andre@0: PKIX_Error * andre@0: pkix_pl_NssContext_SetCertUsage( andre@0: SECCertificateUsage certUsage, andre@0: PKIX_PL_NssContext *nssContext) andre@0: { andre@0: void *plContext = NULL; andre@0: andre@0: PKIX_ENTER(CONTEXT, "pkix_pl_NssContext_SetCertUsage"); andre@0: PKIX_NULLCHECK_ONE(nssContext); andre@0: andre@0: nssContext->certificateUsage = certUsage; andre@0: andre@0: PKIX_RETURN(CONTEXT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_NssContext_GetWincx andre@0: * DESCRIPTION: andre@0: * andre@0: * This function obtains the platform-dependent wincx parameter from the andre@0: * context object pointed to by "nssContext", storing the result at "pWincx". andre@0: * andre@0: * PARAMETERS: andre@0: * "nssContext" andre@0: * The address of the context object whose wincx parameter is to be andre@0: * obtained. Must be non-NULL. andre@0: * "pWincx" andre@0: * The address where the result is stored. Must be non-NULL. andre@0: * THREAD SAFETY: andre@0: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if the function succeeds. andre@0: * Returns a Fatal Error if the function fails in an unrecoverable way. andre@0: */ andre@0: PKIX_Error * andre@0: pkix_pl_NssContext_GetWincx( andre@0: PKIX_PL_NssContext *nssContext, andre@0: void **pWincx) andre@0: { andre@0: void *plContext = NULL; andre@0: PKIX_PL_NssContext *context = NULL; andre@0: andre@0: PKIX_ENTER(CONTEXT, "pkix_pl_NssContext_GetWincx"); andre@0: PKIX_NULLCHECK_TWO(nssContext, pWincx); andre@0: andre@0: context = (PKIX_PL_NssContext *)nssContext; andre@0: andre@0: *pWincx = context->wincx; andre@0: andre@0: PKIX_RETURN(CONTEXT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: pkix_pl_NssContext_SetWincx andre@0: * DESCRIPTION: andre@0: * andre@0: * This function sets the platform-dependent wincx parameter in the context andre@0: * object pointed to by "nssContext" to the value provided in "wincx". andre@0: * andre@0: * PARAMETERS: andre@0: * "wincx" andre@0: * Platform-dependent value to be stored. andre@0: * "nssContext" andre@0: * The address of the context object whose wincx parameter is to be andre@0: * obtained. Must be non-NULL. andre@0: * THREAD SAFETY: andre@0: * Thread Safe (see Thread Safety Definitions in Programmer's Guide) andre@0: * RETURNS: andre@0: * Returns NULL if the function succeeds. andre@0: * Returns a Fatal Error if the function fails in an unrecoverable way. andre@0: */ andre@0: PKIX_Error * andre@0: pkix_pl_NssContext_SetWincx( andre@0: void *wincx, andre@0: PKIX_PL_NssContext *nssContext) andre@0: { andre@0: void *plContext = NULL; andre@0: andre@0: PKIX_ENTER(CONTEXT, "pkix_pl_NssContext_SetWincx"); andre@0: PKIX_NULLCHECK_ONE(nssContext); andre@0: andre@0: nssContext->wincx = wincx; andre@0: andre@0: PKIX_RETURN(CONTEXT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PL_NssContext_SetTimeout andre@0: * DESCRIPTION: andre@0: * andre@0: * Sets user defined socket timeout for the validation andre@0: * session. Default is 60 seconds. andre@0: * andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PL_NssContext_SetTimeout(PKIX_UInt32 timeout, andre@0: PKIX_PL_NssContext *nssContext) andre@0: { andre@0: void *plContext = NULL; andre@0: andre@0: PKIX_ENTER(CONTEXT, "PKIX_PL_NssContext_SetTimeout"); andre@0: PKIX_NULLCHECK_ONE(nssContext); andre@0: andre@0: nssContext->timeoutSeconds = timeout; andre@0: andre@0: PKIX_RETURN(CONTEXT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PL_NssContext_SetMaxResponseLen andre@0: * DESCRIPTION: andre@0: * andre@0: * Sets user defined maximum transmission length of a message. andre@0: * andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PL_NssContext_SetMaxResponseLen(PKIX_UInt32 len, andre@0: PKIX_PL_NssContext *nssContext) andre@0: { andre@0: void *plContext = NULL; andre@0: andre@0: PKIX_ENTER(CONTEXT, "PKIX_PL_NssContext_SetMaxResponseLen"); andre@0: PKIX_NULLCHECK_ONE(nssContext); andre@0: andre@0: nssContext->maxResponseLength = len; andre@0: andre@0: PKIX_RETURN(CONTEXT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PL_NssContext_SetCrlReloadDelay andre@0: * DESCRIPTION: andre@0: * andre@0: * Sets user defined delay between attempts to load crl using andre@0: * CRLDP. andre@0: * andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PL_NssContext_SetCrlReloadDelay(PKIX_UInt32 delay, andre@0: PKIX_PL_NssContext *nssContext) andre@0: { andre@0: void *plContext = NULL; andre@0: andre@0: PKIX_ENTER(CONTEXT, "PKIX_PL_NssContext_SetCrlReloadDelay"); andre@0: PKIX_NULLCHECK_ONE(nssContext); andre@0: andre@0: nssContext->crlReloadDelay = delay; andre@0: andre@0: PKIX_RETURN(CONTEXT); andre@0: } andre@0: andre@0: /* andre@0: * FUNCTION: PKIX_PL_NssContext_SetBadDerCrlReloadDelay andre@0: * DESCRIPTION: andre@0: * andre@0: * Sets user defined delay between attempts to load crl that andre@0: * failed to decode. andre@0: * andre@0: */ andre@0: PKIX_Error * andre@0: PKIX_PL_NssContext_SetBadDerCrlReloadDelay(PKIX_UInt32 delay, andre@0: PKIX_PL_NssContext *nssContext) andre@0: { andre@0: void *plContext = NULL; andre@0: andre@0: PKIX_ENTER(CONTEXT, "PKIX_PL_NssContext_SetBadDerCrlReloadDelay"); andre@0: PKIX_NULLCHECK_ONE(nssContext); andre@0: andre@0: nssContext->badDerCrlReloadDelay = delay; andre@0: andre@0: PKIX_RETURN(CONTEXT); andre@0: }