michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: /* michael@0: * pkix_store.c michael@0: * michael@0: * CertStore Function Definitions michael@0: * michael@0: */ michael@0: michael@0: #include "pkix_store.h" michael@0: michael@0: /* --CertStore-Private-Functions----------------------------------------- */ michael@0: michael@0: /* michael@0: * FUNCTION: pkix_CertStore_Destroy michael@0: * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h) michael@0: */ michael@0: static PKIX_Error * michael@0: pkix_CertStore_Destroy( michael@0: PKIX_PL_Object *object, michael@0: void *plContext) michael@0: { michael@0: PKIX_CertStore *certStore = NULL; michael@0: michael@0: PKIX_ENTER(CERTSTORE, "pkix_CertStore_Destroy"); michael@0: PKIX_NULLCHECK_ONE(object); michael@0: michael@0: /* Check that this object is a CertStore object */ michael@0: PKIX_CHECK(pkix_CheckType(object, PKIX_CERTSTORE_TYPE, plContext), michael@0: PKIX_OBJECTNOTCERTSTORE); michael@0: michael@0: certStore = (PKIX_CertStore *)object; michael@0: michael@0: certStore->certCallback = NULL; michael@0: certStore->crlCallback = NULL; michael@0: certStore->certContinue = NULL; michael@0: certStore->crlContinue = NULL; michael@0: certStore->trustCallback = NULL; michael@0: michael@0: PKIX_DECREF(certStore->certStoreContext); michael@0: michael@0: cleanup: michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: pkix_CertStore_Hashcode michael@0: * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h) michael@0: */ michael@0: static PKIX_Error * michael@0: pkix_CertStore_Hashcode( michael@0: PKIX_PL_Object *object, michael@0: PKIX_UInt32 *pHashcode, michael@0: void *plContext) michael@0: { michael@0: PKIX_CertStore *certStore = NULL; michael@0: PKIX_UInt32 tempHash = 0; michael@0: michael@0: PKIX_ENTER(CERTSTORE, "pkix_CertStore_Hashcode"); michael@0: PKIX_NULLCHECK_TWO(object, pHashcode); michael@0: michael@0: PKIX_CHECK(pkix_CheckType(object, PKIX_CERTSTORE_TYPE, plContext), michael@0: PKIX_OBJECTNOTCERTSTORE); michael@0: michael@0: certStore = (PKIX_CertStore *)object; michael@0: michael@0: if (certStore->certStoreContext) { michael@0: PKIX_CHECK(PKIX_PL_Object_Hashcode michael@0: ((PKIX_PL_Object *) certStore->certStoreContext, michael@0: &tempHash, michael@0: plContext), michael@0: PKIX_CERTSTOREHASHCODEFAILED); michael@0: } michael@0: michael@0: *pHashcode = (PKIX_UInt32) certStore->certCallback + michael@0: (PKIX_UInt32) certStore->crlCallback + michael@0: (PKIX_UInt32) certStore->certContinue + michael@0: (PKIX_UInt32) certStore->crlContinue + michael@0: (PKIX_UInt32) certStore->trustCallback + michael@0: (tempHash << 7); michael@0: michael@0: cleanup: michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: pkix_CertStore_Equals michael@0: * (see comments for PKIX_PL_EqualsCallback in pkix_pl_system.h) michael@0: */ michael@0: static PKIX_Error * michael@0: pkix_CertStore_Equals( michael@0: PKIX_PL_Object *firstObject, michael@0: PKIX_PL_Object *secondObject, michael@0: PKIX_Int32 *pResult, michael@0: void *plContext) michael@0: { michael@0: PKIX_CertStore *firstCS = NULL; michael@0: PKIX_CertStore *secondCS = NULL; michael@0: PKIX_Boolean cmpResult = PKIX_FALSE; michael@0: michael@0: PKIX_ENTER(CERTSTORE, "pkix_CertStore_Equals"); michael@0: PKIX_NULLCHECK_THREE(firstObject, secondObject, pResult); michael@0: michael@0: PKIX_CHECK(pkix_CheckTypes michael@0: (firstObject, secondObject, PKIX_CERTSTORE_TYPE, plContext), michael@0: PKIX_ARGUMENTSNOTDATES); michael@0: michael@0: firstCS = (PKIX_CertStore *)firstObject; michael@0: secondCS = (PKIX_CertStore *)secondObject; michael@0: michael@0: cmpResult = (firstCS->certCallback == secondCS->certCallback) && michael@0: (firstCS->crlCallback == secondCS->crlCallback) && michael@0: (firstCS->certContinue == secondCS->certContinue) && michael@0: (firstCS->crlContinue == secondCS->crlContinue) && michael@0: (firstCS->trustCallback == secondCS->trustCallback); michael@0: michael@0: if (cmpResult && michael@0: (firstCS->certStoreContext != secondCS->certStoreContext)) { michael@0: michael@0: PKIX_CHECK(PKIX_PL_Object_Equals michael@0: ((PKIX_PL_Object *) firstCS->certStoreContext, michael@0: (PKIX_PL_Object *) secondCS->certStoreContext, michael@0: &cmpResult, michael@0: plContext), michael@0: PKIX_CERTSTOREEQUALSFAILED); michael@0: } michael@0: michael@0: *pResult = cmpResult; michael@0: michael@0: cleanup: michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: pkix_CertStore_RegisterSelf michael@0: * DESCRIPTION: michael@0: * Registers PKIX_CERTSTORE_TYPE and its related functions with michael@0: * systemClasses[] michael@0: * THREAD SAFETY: michael@0: * Not Thread Safe - for performance and complexity reasons michael@0: * michael@0: * Since this function is only called by PKIX_PL_Initialize, which should michael@0: * only be called once, it is acceptable that this function is not michael@0: * thread-safe. michael@0: */ michael@0: PKIX_Error * michael@0: pkix_CertStore_RegisterSelf(void *plContext) michael@0: { michael@0: extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES]; michael@0: pkix_ClassTable_Entry entry; michael@0: michael@0: PKIX_ENTER(CERTSTORE, "pkix_CertStore_RegisterSelf"); michael@0: michael@0: entry.description = "CertStore"; michael@0: entry.objCounter = 0; michael@0: entry.typeObjectSize = sizeof(PKIX_CertStore); michael@0: entry.destructor = pkix_CertStore_Destroy; michael@0: entry.equalsFunction = pkix_CertStore_Equals; michael@0: entry.hashcodeFunction = pkix_CertStore_Hashcode; michael@0: entry.toStringFunction = NULL; michael@0: entry.comparator = NULL; michael@0: entry.duplicateFunction = pkix_duplicateImmutable; michael@0: michael@0: systemClasses[PKIX_CERTSTORE_TYPE] = entry; michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* --CertStore-Public-Functions------------------------------------------ */ michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertStore_Create (see comments in pkix_certstore.h) michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertStore_Create( michael@0: PKIX_CertStore_CertCallback certCallback, michael@0: PKIX_CertStore_CRLCallback crlCallback, michael@0: PKIX_CertStore_CertContinueFunction certContinue, michael@0: PKIX_CertStore_CrlContinueFunction crlContinue, michael@0: PKIX_CertStore_CheckTrustCallback trustCallback, michael@0: PKIX_CertStore_ImportCrlCallback importCrlCallback, michael@0: PKIX_CertStore_CheckRevokationByCrlCallback checkRevByCrlCallback, michael@0: PKIX_PL_Object *certStoreContext, michael@0: PKIX_Boolean cacheFlag, michael@0: PKIX_Boolean localFlag, michael@0: PKIX_CertStore **pStore, michael@0: void *plContext) michael@0: { michael@0: PKIX_CertStore *certStore = NULL; michael@0: michael@0: PKIX_ENTER(CERTSTORE, "PKIX_CertStore_Create"); michael@0: PKIX_NULLCHECK_THREE(certCallback, crlCallback, pStore); michael@0: michael@0: PKIX_CHECK(PKIX_PL_Object_Alloc michael@0: (PKIX_CERTSTORE_TYPE, michael@0: sizeof (PKIX_CertStore), michael@0: (PKIX_PL_Object **)&certStore, michael@0: plContext), michael@0: PKIX_COULDNOTCREATECERTSTOREOBJECT); michael@0: michael@0: certStore->certCallback = certCallback; michael@0: certStore->crlCallback = crlCallback; michael@0: certStore->certContinue = certContinue; michael@0: certStore->crlContinue = crlContinue; michael@0: certStore->trustCallback = trustCallback; michael@0: certStore->importCrlCallback = importCrlCallback; michael@0: certStore->checkRevByCrlCallback = checkRevByCrlCallback; michael@0: certStore->cacheFlag = cacheFlag; michael@0: certStore->localFlag = localFlag; michael@0: michael@0: PKIX_INCREF(certStoreContext); michael@0: certStore->certStoreContext = certStoreContext; michael@0: michael@0: *pStore = certStore; michael@0: certStore = NULL; michael@0: michael@0: cleanup: michael@0: michael@0: PKIX_DECREF(certStore); michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertStore_GetCertCallback (see comments in pkix_certstore.h) michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertStore_GetCertCallback( michael@0: PKIX_CertStore *store, michael@0: PKIX_CertStore_CertCallback *pCallback, michael@0: void *plContext) michael@0: { michael@0: PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetCertCallback"); michael@0: PKIX_NULLCHECK_TWO(store, pCallback); michael@0: michael@0: *pCallback = store->certCallback; michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertStore_GetCRLCallback (see comments in pkix_certstore.h) michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertStore_GetCRLCallback( michael@0: PKIX_CertStore *store, michael@0: PKIX_CertStore_CRLCallback *pCallback, michael@0: void *plContext) michael@0: { michael@0: PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetCRLCallback"); michael@0: PKIX_NULLCHECK_TWO(store, pCallback); michael@0: michael@0: *pCallback = store->crlCallback; michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertStore_CertContinue (see comments in pkix_certstore.h) michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertStore_CertContinue( michael@0: PKIX_CertStore *store, michael@0: PKIX_CertSelector *selector, michael@0: PKIX_VerifyNode *verifyNode, michael@0: void **pNBIOContext, michael@0: PKIX_List **pCertList, michael@0: void *plContext) michael@0: { michael@0: PKIX_ENTER(CERTSTORE, "PKIX_CertStore_CertContinue"); michael@0: PKIX_NULLCHECK_FOUR(store, selector, pNBIOContext, pCertList); michael@0: michael@0: PKIX_CHECK(store->certContinue michael@0: (store, selector, verifyNode, michael@0: pNBIOContext, pCertList, plContext), michael@0: PKIX_CERTSTORECERTCONTINUEFUNCTIONFAILED); michael@0: michael@0: cleanup: michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertStore_CrlContinue (see comments in pkix_certstore.h) michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertStore_CrlContinue( michael@0: PKIX_CertStore *store, michael@0: PKIX_CRLSelector *selector, michael@0: void **pNBIOContext, michael@0: PKIX_List **pCrlList, michael@0: void *plContext) michael@0: { michael@0: PKIX_ENTER(CERTSTORE, "PKIX_CertStore_CrlContinue"); michael@0: PKIX_NULLCHECK_FOUR(store, selector, pNBIOContext, pCrlList); michael@0: michael@0: PKIX_CHECK(store->crlContinue michael@0: (store, selector, pNBIOContext, pCrlList, plContext), michael@0: PKIX_CERTSTORECRLCONTINUEFAILED); michael@0: michael@0: cleanup: michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertStore_GetTrustCallback (see comments in pkix_certstore.h) michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertStore_GetTrustCallback( michael@0: PKIX_CertStore *store, michael@0: PKIX_CertStore_CheckTrustCallback *pCallback, michael@0: void *plContext) michael@0: { michael@0: PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetTrustCallback"); michael@0: PKIX_NULLCHECK_TWO(store, pCallback); michael@0: michael@0: *pCallback = store->trustCallback; michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertStore_GetImportCrlCallback (see comments in pkix_certstore.h) michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertStore_GetImportCrlCallback( michael@0: PKIX_CertStore *store, michael@0: PKIX_CertStore_ImportCrlCallback *pCallback, michael@0: void *plContext) michael@0: { michael@0: PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetTrustCallback"); michael@0: PKIX_NULLCHECK_TWO(store, pCallback); michael@0: michael@0: *pCallback = store->importCrlCallback; michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertStore_GetCheckRevByCrl (see comments in pkix_certstore.h) michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertStore_GetCrlCheckerFn( michael@0: PKIX_CertStore *store, michael@0: PKIX_CertStore_CheckRevokationByCrlCallback *pCallback, michael@0: void *plContext) michael@0: { michael@0: PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetTrustCallback"); michael@0: PKIX_NULLCHECK_TWO(store, pCallback); michael@0: michael@0: *pCallback = store->checkRevByCrlCallback; michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertStore_GetCertStoreContext michael@0: * (see comments in pkix_certstore.h) michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertStore_GetCertStoreContext( michael@0: PKIX_CertStore *store, michael@0: PKIX_PL_Object **pCertStoreContext, michael@0: void *plContext) michael@0: { michael@0: PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetCertStoreContext"); michael@0: PKIX_NULLCHECK_TWO(store, pCertStoreContext); michael@0: michael@0: PKIX_INCREF(store->certStoreContext); michael@0: *pCertStoreContext = store->certStoreContext; michael@0: michael@0: cleanup: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertStore_GetCertStoreCacheFlag michael@0: * (see comments in pkix_certstore.h) michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertStore_GetCertStoreCacheFlag( michael@0: PKIX_CertStore *store, michael@0: PKIX_Boolean *pCacheFlag, michael@0: void *plContext) michael@0: { michael@0: PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetCertStoreCacheFlag"); michael@0: PKIX_NULLCHECK_TWO(store, pCacheFlag); michael@0: michael@0: *pCacheFlag = store->cacheFlag; michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: } michael@0: michael@0: /* michael@0: * FUNCTION: PKIX_CertStore_GetLocalFlag michael@0: * (see comments in pkix_certstore.h) michael@0: */ michael@0: PKIX_Error * michael@0: PKIX_CertStore_GetLocalFlag( michael@0: PKIX_CertStore *store, michael@0: PKIX_Boolean *pLocalFlag, michael@0: void *plContext) michael@0: { michael@0: PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetLocalFlag"); michael@0: PKIX_NULLCHECK_TWO(store, pLocalFlag); michael@0: michael@0: *pLocalFlag = store->localFlag; michael@0: michael@0: PKIX_RETURN(CERTSTORE); michael@0: }