| OLD | NEW |
| (Empty) |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
| 4 /* | |
| 5 * pkix_store.c | |
| 6 * | |
| 7 * CertStore Function Definitions | |
| 8 * | |
| 9 */ | |
| 10 | |
| 11 #include "pkix_store.h" | |
| 12 | |
| 13 /* --CertStore-Private-Functions----------------------------------------- */ | |
| 14 | |
| 15 /* | |
| 16 * FUNCTION: pkix_CertStore_Destroy | |
| 17 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h) | |
| 18 */ | |
| 19 static PKIX_Error * | |
| 20 pkix_CertStore_Destroy( | |
| 21 PKIX_PL_Object *object, | |
| 22 void *plContext) | |
| 23 { | |
| 24 PKIX_CertStore *certStore = NULL; | |
| 25 | |
| 26 PKIX_ENTER(CERTSTORE, "pkix_CertStore_Destroy"); | |
| 27 PKIX_NULLCHECK_ONE(object); | |
| 28 | |
| 29 /* Check that this object is a CertStore object */ | |
| 30 PKIX_CHECK(pkix_CheckType(object, PKIX_CERTSTORE_TYPE, plContext), | |
| 31 PKIX_OBJECTNOTCERTSTORE); | |
| 32 | |
| 33 certStore = (PKIX_CertStore *)object; | |
| 34 | |
| 35 certStore->certCallback = NULL; | |
| 36 certStore->crlCallback = NULL; | |
| 37 certStore->certContinue = NULL; | |
| 38 certStore->crlContinue = NULL; | |
| 39 certStore->trustCallback = NULL; | |
| 40 | |
| 41 PKIX_DECREF(certStore->certStoreContext); | |
| 42 | |
| 43 cleanup: | |
| 44 | |
| 45 PKIX_RETURN(CERTSTORE); | |
| 46 } | |
| 47 | |
| 48 /* | |
| 49 * FUNCTION: pkix_CertStore_Hashcode | |
| 50 * (see comments for PKIX_PL_HashcodeCallback in pkix_pl_system.h) | |
| 51 */ | |
| 52 static PKIX_Error * | |
| 53 pkix_CertStore_Hashcode( | |
| 54 PKIX_PL_Object *object, | |
| 55 PKIX_UInt32 *pHashcode, | |
| 56 void *plContext) | |
| 57 { | |
| 58 PKIX_CertStore *certStore = NULL; | |
| 59 PKIX_UInt32 tempHash = 0; | |
| 60 | |
| 61 PKIX_ENTER(CERTSTORE, "pkix_CertStore_Hashcode"); | |
| 62 PKIX_NULLCHECK_TWO(object, pHashcode); | |
| 63 | |
| 64 PKIX_CHECK(pkix_CheckType(object, PKIX_CERTSTORE_TYPE, plContext), | |
| 65 PKIX_OBJECTNOTCERTSTORE); | |
| 66 | |
| 67 certStore = (PKIX_CertStore *)object; | |
| 68 | |
| 69 if (certStore->certStoreContext) { | |
| 70 PKIX_CHECK(PKIX_PL_Object_Hashcode | |
| 71 ((PKIX_PL_Object *) certStore->certStoreContext, | |
| 72 &tempHash, | |
| 73 plContext), | |
| 74 PKIX_CERTSTOREHASHCODEFAILED); | |
| 75 } | |
| 76 | |
| 77 *pHashcode = (PKIX_UInt32) certStore->certCallback + | |
| 78 (PKIX_UInt32) certStore->crlCallback + | |
| 79 (PKIX_UInt32) certStore->certContinue + | |
| 80 (PKIX_UInt32) certStore->crlContinue + | |
| 81 (PKIX_UInt32) certStore->trustCallback + | |
| 82 (tempHash << 7); | |
| 83 | |
| 84 cleanup: | |
| 85 | |
| 86 PKIX_RETURN(CERTSTORE); | |
| 87 } | |
| 88 | |
| 89 /* | |
| 90 * FUNCTION: pkix_CertStore_Equals | |
| 91 * (see comments for PKIX_PL_EqualsCallback in pkix_pl_system.h) | |
| 92 */ | |
| 93 static PKIX_Error * | |
| 94 pkix_CertStore_Equals( | |
| 95 PKIX_PL_Object *firstObject, | |
| 96 PKIX_PL_Object *secondObject, | |
| 97 PKIX_Int32 *pResult, | |
| 98 void *plContext) | |
| 99 { | |
| 100 PKIX_CertStore *firstCS = NULL; | |
| 101 PKIX_CertStore *secondCS = NULL; | |
| 102 PKIX_Boolean cmpResult = PKIX_FALSE; | |
| 103 | |
| 104 PKIX_ENTER(CERTSTORE, "pkix_CertStore_Equals"); | |
| 105 PKIX_NULLCHECK_THREE(firstObject, secondObject, pResult); | |
| 106 | |
| 107 PKIX_CHECK(pkix_CheckTypes | |
| 108 (firstObject, secondObject, PKIX_CERTSTORE_TYPE, plContext), | |
| 109 PKIX_ARGUMENTSNOTDATES); | |
| 110 | |
| 111 firstCS = (PKIX_CertStore *)firstObject; | |
| 112 secondCS = (PKIX_CertStore *)secondObject; | |
| 113 | |
| 114 cmpResult = (firstCS->certCallback == secondCS->certCallback) && | |
| 115 (firstCS->crlCallback == secondCS->crlCallback) && | |
| 116 (firstCS->certContinue == secondCS->certContinue) && | |
| 117 (firstCS->crlContinue == secondCS->crlContinue) && | |
| 118 (firstCS->trustCallback == secondCS->trustCallback); | |
| 119 | |
| 120 if (cmpResult && | |
| 121 (firstCS->certStoreContext != secondCS->certStoreContext)) { | |
| 122 | |
| 123 PKIX_CHECK(PKIX_PL_Object_Equals | |
| 124 ((PKIX_PL_Object *) firstCS->certStoreContext, | |
| 125 (PKIX_PL_Object *) secondCS->certStoreContext, | |
| 126 &cmpResult, | |
| 127 plContext), | |
| 128 PKIX_CERTSTOREEQUALSFAILED); | |
| 129 } | |
| 130 | |
| 131 *pResult = cmpResult; | |
| 132 | |
| 133 cleanup: | |
| 134 | |
| 135 PKIX_RETURN(CERTSTORE); | |
| 136 } | |
| 137 | |
| 138 /* | |
| 139 * FUNCTION: pkix_CertStore_RegisterSelf | |
| 140 * DESCRIPTION: | |
| 141 * Registers PKIX_CERTSTORE_TYPE and its related functions with | |
| 142 * systemClasses[] | |
| 143 * THREAD SAFETY: | |
| 144 * Not Thread Safe - for performance and complexity reasons | |
| 145 * | |
| 146 * Since this function is only called by PKIX_PL_Initialize, which should | |
| 147 * only be called once, it is acceptable that this function is not | |
| 148 * thread-safe. | |
| 149 */ | |
| 150 PKIX_Error * | |
| 151 pkix_CertStore_RegisterSelf(void *plContext) | |
| 152 { | |
| 153 extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES]; | |
| 154 pkix_ClassTable_Entry entry; | |
| 155 | |
| 156 PKIX_ENTER(CERTSTORE, "pkix_CertStore_RegisterSelf"); | |
| 157 | |
| 158 entry.description = "CertStore"; | |
| 159 entry.objCounter = 0; | |
| 160 entry.typeObjectSize = sizeof(PKIX_CertStore); | |
| 161 entry.destructor = pkix_CertStore_Destroy; | |
| 162 entry.equalsFunction = pkix_CertStore_Equals; | |
| 163 entry.hashcodeFunction = pkix_CertStore_Hashcode; | |
| 164 entry.toStringFunction = NULL; | |
| 165 entry.comparator = NULL; | |
| 166 entry.duplicateFunction = pkix_duplicateImmutable; | |
| 167 | |
| 168 systemClasses[PKIX_CERTSTORE_TYPE] = entry; | |
| 169 | |
| 170 PKIX_RETURN(CERTSTORE); | |
| 171 } | |
| 172 | |
| 173 /* --CertStore-Public-Functions------------------------------------------ */ | |
| 174 | |
| 175 /* | |
| 176 * FUNCTION: PKIX_CertStore_Create (see comments in pkix_certstore.h) | |
| 177 */ | |
| 178 PKIX_Error * | |
| 179 PKIX_CertStore_Create( | |
| 180 PKIX_CertStore_CertCallback certCallback, | |
| 181 PKIX_CertStore_CRLCallback crlCallback, | |
| 182 PKIX_CertStore_CertContinueFunction certContinue, | |
| 183 PKIX_CertStore_CrlContinueFunction crlContinue, | |
| 184 PKIX_CertStore_CheckTrustCallback trustCallback, | |
| 185 PKIX_CertStore_ImportCrlCallback importCrlCallback, | |
| 186 PKIX_CertStore_CheckRevokationByCrlCallback checkRevByCrlCallback, | |
| 187 PKIX_PL_Object *certStoreContext, | |
| 188 PKIX_Boolean cacheFlag, | |
| 189 PKIX_Boolean localFlag, | |
| 190 PKIX_CertStore **pStore, | |
| 191 void *plContext) | |
| 192 { | |
| 193 PKIX_CertStore *certStore = NULL; | |
| 194 | |
| 195 PKIX_ENTER(CERTSTORE, "PKIX_CertStore_Create"); | |
| 196 PKIX_NULLCHECK_THREE(certCallback, crlCallback, pStore); | |
| 197 | |
| 198 PKIX_CHECK(PKIX_PL_Object_Alloc | |
| 199 (PKIX_CERTSTORE_TYPE, | |
| 200 sizeof (PKIX_CertStore), | |
| 201 (PKIX_PL_Object **)&certStore, | |
| 202 plContext), | |
| 203 PKIX_COULDNOTCREATECERTSTOREOBJECT); | |
| 204 | |
| 205 certStore->certCallback = certCallback; | |
| 206 certStore->crlCallback = crlCallback; | |
| 207 certStore->certContinue = certContinue; | |
| 208 certStore->crlContinue = crlContinue; | |
| 209 certStore->trustCallback = trustCallback; | |
| 210 certStore->importCrlCallback = importCrlCallback; | |
| 211 certStore->checkRevByCrlCallback = checkRevByCrlCallback; | |
| 212 certStore->cacheFlag = cacheFlag; | |
| 213 certStore->localFlag = localFlag; | |
| 214 | |
| 215 PKIX_INCREF(certStoreContext); | |
| 216 certStore->certStoreContext = certStoreContext; | |
| 217 | |
| 218 *pStore = certStore; | |
| 219 certStore = NULL; | |
| 220 | |
| 221 cleanup: | |
| 222 | |
| 223 PKIX_DECREF(certStore); | |
| 224 | |
| 225 PKIX_RETURN(CERTSTORE); | |
| 226 } | |
| 227 | |
| 228 /* | |
| 229 * FUNCTION: PKIX_CertStore_GetCertCallback (see comments in pkix_certstore.h) | |
| 230 */ | |
| 231 PKIX_Error * | |
| 232 PKIX_CertStore_GetCertCallback( | |
| 233 PKIX_CertStore *store, | |
| 234 PKIX_CertStore_CertCallback *pCallback, | |
| 235 void *plContext) | |
| 236 { | |
| 237 PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetCertCallback"); | |
| 238 PKIX_NULLCHECK_TWO(store, pCallback); | |
| 239 | |
| 240 *pCallback = store->certCallback; | |
| 241 | |
| 242 PKIX_RETURN(CERTSTORE); | |
| 243 } | |
| 244 | |
| 245 /* | |
| 246 * FUNCTION: PKIX_CertStore_GetCRLCallback (see comments in pkix_certstore.h) | |
| 247 */ | |
| 248 PKIX_Error * | |
| 249 PKIX_CertStore_GetCRLCallback( | |
| 250 PKIX_CertStore *store, | |
| 251 PKIX_CertStore_CRLCallback *pCallback, | |
| 252 void *plContext) | |
| 253 { | |
| 254 PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetCRLCallback"); | |
| 255 PKIX_NULLCHECK_TWO(store, pCallback); | |
| 256 | |
| 257 *pCallback = store->crlCallback; | |
| 258 | |
| 259 PKIX_RETURN(CERTSTORE); | |
| 260 } | |
| 261 | |
| 262 /* | |
| 263 * FUNCTION: PKIX_CertStore_CertContinue (see comments in pkix_certstore.h) | |
| 264 */ | |
| 265 PKIX_Error * | |
| 266 PKIX_CertStore_CertContinue( | |
| 267 PKIX_CertStore *store, | |
| 268 PKIX_CertSelector *selector, | |
| 269 PKIX_VerifyNode *verifyNode, | |
| 270 void **pNBIOContext, | |
| 271 PKIX_List **pCertList, | |
| 272 void *plContext) | |
| 273 { | |
| 274 PKIX_ENTER(CERTSTORE, "PKIX_CertStore_CertContinue"); | |
| 275 PKIX_NULLCHECK_FOUR(store, selector, pNBIOContext, pCertList); | |
| 276 | |
| 277 PKIX_CHECK(store->certContinue | |
| 278 (store, selector, verifyNode, | |
| 279 pNBIOContext, pCertList, plContext), | |
| 280 PKIX_CERTSTORECERTCONTINUEFUNCTIONFAILED); | |
| 281 | |
| 282 cleanup: | |
| 283 | |
| 284 PKIX_RETURN(CERTSTORE); | |
| 285 } | |
| 286 | |
| 287 /* | |
| 288 * FUNCTION: PKIX_CertStore_CrlContinue (see comments in pkix_certstore.h) | |
| 289 */ | |
| 290 PKIX_Error * | |
| 291 PKIX_CertStore_CrlContinue( | |
| 292 PKIX_CertStore *store, | |
| 293 PKIX_CRLSelector *selector, | |
| 294 void **pNBIOContext, | |
| 295 PKIX_List **pCrlList, | |
| 296 void *plContext) | |
| 297 { | |
| 298 PKIX_ENTER(CERTSTORE, "PKIX_CertStore_CrlContinue"); | |
| 299 PKIX_NULLCHECK_FOUR(store, selector, pNBIOContext, pCrlList); | |
| 300 | |
| 301 PKIX_CHECK(store->crlContinue | |
| 302 (store, selector, pNBIOContext, pCrlList, plContext), | |
| 303 PKIX_CERTSTORECRLCONTINUEFAILED); | |
| 304 | |
| 305 cleanup: | |
| 306 | |
| 307 PKIX_RETURN(CERTSTORE); | |
| 308 } | |
| 309 | |
| 310 /* | |
| 311 * FUNCTION: PKIX_CertStore_GetTrustCallback (see comments in pkix_certstore.h) | |
| 312 */ | |
| 313 PKIX_Error * | |
| 314 PKIX_CertStore_GetTrustCallback( | |
| 315 PKIX_CertStore *store, | |
| 316 PKIX_CertStore_CheckTrustCallback *pCallback, | |
| 317 void *plContext) | |
| 318 { | |
| 319 PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetTrustCallback"); | |
| 320 PKIX_NULLCHECK_TWO(store, pCallback); | |
| 321 | |
| 322 *pCallback = store->trustCallback; | |
| 323 | |
| 324 PKIX_RETURN(CERTSTORE); | |
| 325 } | |
| 326 | |
| 327 /* | |
| 328 * FUNCTION: PKIX_CertStore_GetImportCrlCallback (see comments in pkix_certstore
.h) | |
| 329 */ | |
| 330 PKIX_Error * | |
| 331 PKIX_CertStore_GetImportCrlCallback( | |
| 332 PKIX_CertStore *store, | |
| 333 PKIX_CertStore_ImportCrlCallback *pCallback, | |
| 334 void *plContext) | |
| 335 { | |
| 336 PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetTrustCallback"); | |
| 337 PKIX_NULLCHECK_TWO(store, pCallback); | |
| 338 | |
| 339 *pCallback = store->importCrlCallback; | |
| 340 | |
| 341 PKIX_RETURN(CERTSTORE); | |
| 342 } | |
| 343 | |
| 344 /* | |
| 345 * FUNCTION: PKIX_CertStore_GetCheckRevByCrl (see comments in pkix_certstore.h) | |
| 346 */ | |
| 347 PKIX_Error * | |
| 348 PKIX_CertStore_GetCrlCheckerFn( | |
| 349 PKIX_CertStore *store, | |
| 350 PKIX_CertStore_CheckRevokationByCrlCallback *pCallback, | |
| 351 void *plContext) | |
| 352 { | |
| 353 PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetTrustCallback"); | |
| 354 PKIX_NULLCHECK_TWO(store, pCallback); | |
| 355 | |
| 356 *pCallback = store->checkRevByCrlCallback; | |
| 357 | |
| 358 PKIX_RETURN(CERTSTORE); | |
| 359 } | |
| 360 | |
| 361 /* | |
| 362 * FUNCTION: PKIX_CertStore_GetCertStoreContext | |
| 363 * (see comments in pkix_certstore.h) | |
| 364 */ | |
| 365 PKIX_Error * | |
| 366 PKIX_CertStore_GetCertStoreContext( | |
| 367 PKIX_CertStore *store, | |
| 368 PKIX_PL_Object **pCertStoreContext, | |
| 369 void *plContext) | |
| 370 { | |
| 371 PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetCertStoreContext"); | |
| 372 PKIX_NULLCHECK_TWO(store, pCertStoreContext); | |
| 373 | |
| 374 PKIX_INCREF(store->certStoreContext); | |
| 375 *pCertStoreContext = store->certStoreContext; | |
| 376 | |
| 377 cleanup: | |
| 378 PKIX_RETURN(CERTSTORE); | |
| 379 } | |
| 380 | |
| 381 /* | |
| 382 * FUNCTION: PKIX_CertStore_GetCertStoreCacheFlag | |
| 383 * (see comments in pkix_certstore.h) | |
| 384 */ | |
| 385 PKIX_Error * | |
| 386 PKIX_CertStore_GetCertStoreCacheFlag( | |
| 387 PKIX_CertStore *store, | |
| 388 PKIX_Boolean *pCacheFlag, | |
| 389 void *plContext) | |
| 390 { | |
| 391 PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetCertStoreCacheFlag"); | |
| 392 PKIX_NULLCHECK_TWO(store, pCacheFlag); | |
| 393 | |
| 394 *pCacheFlag = store->cacheFlag; | |
| 395 | |
| 396 PKIX_RETURN(CERTSTORE); | |
| 397 } | |
| 398 | |
| 399 /* | |
| 400 * FUNCTION: PKIX_CertStore_GetLocalFlag | |
| 401 * (see comments in pkix_certstore.h) | |
| 402 */ | |
| 403 PKIX_Error * | |
| 404 PKIX_CertStore_GetLocalFlag( | |
| 405 PKIX_CertStore *store, | |
| 406 PKIX_Boolean *pLocalFlag, | |
| 407 void *plContext) | |
| 408 { | |
| 409 PKIX_ENTER(CERTSTORE, "PKIX_CertStore_GetLocalFlag"); | |
| 410 PKIX_NULLCHECK_TWO(store, pLocalFlag); | |
| 411 | |
| 412 *pLocalFlag = store->localFlag; | |
| 413 | |
| 414 PKIX_RETURN(CERTSTORE); | |
| 415 } | |
| OLD | NEW |