security/nss/lib/libpkix/pkix/store/pkix_store.c

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rwxr-xr-x

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial