Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: mozilla/security/nss/lib/libpkix/pkix/checker/pkix_crlchecker.c

Issue 14249009: Change the NSS and NSPR source tree to the new directory structure to be (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/nss/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_defaultcrlchecker.c
6 *
7 * Functions for default CRL Checkers
8 *
9 */
10 #include "pkix.h"
11 #include "pkix_crlchecker.h"
12 #include "pkix_tools.h"
13
14 /* --Private-CRLChecker-Data-and-Types------------------------------- */
15
16 typedef struct pkix_CrlCheckerStruct {
17 /* RevocationMethod is the super class of CrlChecker. */
18 pkix_RevocationMethod method;
19 PKIX_List *certStores; /* list of CertStore */
20 PKIX_PL_VerifyCallback crlVerifyFn;
21 } pkix_CrlChecker;
22
23
24 /* --Private-CRLChecker-Functions----------------------------------- */
25
26 /*
27 * FUNCTION: pkix_CrlCheckerstate_Destroy
28 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h)
29 */
30 static PKIX_Error *
31 pkix_CrlChecker_Destroy(
32 PKIX_PL_Object *object,
33 void *plContext)
34 {
35 pkix_CrlChecker *state = NULL;
36
37 PKIX_ENTER(CRLCHECKER, "pkix_CrlChecker_Destroy");
38 PKIX_NULLCHECK_ONE(object);
39
40 /* Check that this object is a default CRL checker state */
41 PKIX_CHECK(
42 pkix_CheckType(object, PKIX_CRLCHECKER_TYPE, plContext),
43 PKIX_OBJECTNOTCRLCHECKER);
44
45 state = (pkix_CrlChecker *)object;
46
47 PKIX_DECREF(state->certStores);
48
49 cleanup:
50
51 PKIX_RETURN(CRLCHECKER);
52 }
53
54 /*
55 * FUNCTION: pkix_CrlChecker_RegisterSelf
56 *
57 * DESCRIPTION:
58 * Registers PKIX_CRLCHECKER_TYPE and its related functions
59 * with systemClasses[]
60 *
61 * THREAD SAFETY:
62 * Not Thread Safe (see Thread Safety Definitions in Programmer's Guide)
63 *
64 * Since this function is only called by PKIX_PL_Initialize, which should
65 * only be called once, it is acceptable that this function is not
66 * thread-safe.
67 */
68 PKIX_Error *
69 pkix_CrlChecker_RegisterSelf(void *plContext)
70 {
71 extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES];
72 pkix_ClassTable_Entry* entry = &systemClasses[PKIX_CRLCHECKER_TYPE];
73
74 PKIX_ENTER(CRLCHECKER, "pkix_CrlChecker_RegisterSelf");
75
76 entry->description = "CRLChecker";
77 entry->typeObjectSize = sizeof(pkix_CrlChecker);
78 entry->destructor = pkix_CrlChecker_Destroy;
79
80 PKIX_RETURN(CRLCHECKER);
81 }
82
83 /*
84 * FUNCTION: pkix_CrlChecker_Create
85 *
86 * DESCRIPTION:
87 * Allocate and initialize CRLChecker state data.
88 *
89 * PARAMETERS
90 * "certStores"
91 * Address of CertStore List to be stored in state. Must be non-NULL.
92 * "testDate"
93 * Address of PKIX_PL_Date to be checked. May be NULL.
94 * "trustedPubKey"
95 * Trusted Anchor Public Key for verifying first Cert in the chain.
96 * Must be non-NULL.
97 * "certsRemaining"
98 * Number of certificates remaining in the chain.
99 * "nistCRLPolicyEnabled"
100 * If enabled, enforce nist crl policy.
101 * "pChecker"
102 * Address of CRLChecker that is returned. Must be non-NULL.
103 * "plContext"
104 * Platform-specific context pointer.
105 *
106 * THREAD SAFETY:
107 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
108 *
109 * RETURNS:
110 * Returns NULL if the function succeeds.
111 * Returns a DefaultCrlChecker Error if the function fails in a
112 * non-fatal way.
113 * Returns a Fatal Error
114 */
115 PKIX_Error *
116 pkix_CrlChecker_Create(PKIX_RevocationMethodType methodType,
117 PKIX_UInt32 flags,
118 PKIX_UInt32 priority,
119 pkix_LocalRevocationCheckFn localRevChecker,
120 pkix_ExternalRevocationCheckFn externalRevChecker,
121 PKIX_List *certStores,
122 PKIX_PL_VerifyCallback crlVerifyFn,
123 pkix_RevocationMethod **pChecker,
124 void *plContext)
125 {
126 pkix_CrlChecker *crlChecker = NULL;
127
128 PKIX_ENTER(CRLCHECKER, "pkix_CrlChecker_Create");
129 PKIX_NULLCHECK_TWO(certStores, pChecker);
130
131 PKIX_CHECK(PKIX_PL_Object_Alloc
132 (PKIX_CRLCHECKER_TYPE,
133 sizeof (pkix_CrlChecker),
134 (PKIX_PL_Object **)&crlChecker,
135 plContext),
136 PKIX_COULDNOTCREATECRLCHECKEROBJECT);
137
138 pkixErrorResult = pkix_RevocationMethod_Init(
139 (pkix_RevocationMethod*)crlChecker, methodType, flags, priority,
140 localRevChecker, externalRevChecker, plContext);
141 if (pkixErrorResult) {
142 goto cleanup;
143 }
144
145 /* Initialize fields */
146 PKIX_INCREF(certStores);
147 crlChecker->certStores = certStores;
148
149 crlChecker->crlVerifyFn = crlVerifyFn;
150 *pChecker = (pkix_RevocationMethod*)crlChecker;
151 crlChecker = NULL;
152
153 cleanup:
154 PKIX_DECREF(crlChecker);
155
156 PKIX_RETURN(CRLCHECKER);
157 }
158
159 /* --Private-CRLChecker-Functions------------------------------------ */
160
161 /*
162 * FUNCTION: pkix_CrlChecker_CheckLocal
163 *
164 * DESCRIPTION:
165 * Check if the Cert has been revoked based the CRLs data. This function
166 * maintains the checker state to be current.
167 *
168 * PARAMETERS
169 * "checker"
170 * Address of CertChainChecker which has the state data.
171 * Must be non-NULL.
172 * "cert"
173 * Address of Certificate that is to be validated. Must be non-NULL.
174 * "unreslvdCrtExts"
175 * A List OIDs. Not **yet** used in this checker function.
176 * "plContext"
177 * Platform-specific context pointer.
178 *
179 * THREAD SAFETY:
180 * Not Thread Safe
181 * (see Thread Safety Definitions in Programmer's Guide)
182 *
183 * RETURNS:
184 * Returns NULL if the function succeeds.
185 * Returns a CertChainChecker Error if the function fails in a non-fatal way.
186 * Returns a Fatal Error
187 */
188 PKIX_Error *
189 pkix_CrlChecker_CheckLocal(
190 PKIX_PL_Cert *cert,
191 PKIX_PL_Cert *issuer,
192 PKIX_PL_Date *date,
193 pkix_RevocationMethod *checkerObject,
194 PKIX_ProcessingParams *procParams,
195 PKIX_UInt32 methodFlags,
196 PKIX_Boolean chainVerificationState,
197 PKIX_RevocationStatus *pRevStatus,
198 PKIX_UInt32 *pReasonCode,
199 void *plContext)
200 {
201 PKIX_CertStore_CheckRevokationByCrlCallback storeCheckRevocationFn;
202 PKIX_CertStore *certStore = NULL;
203 pkix_CrlChecker *state = NULL;
204 PKIX_UInt32 reasonCode = 0;
205 PKIX_UInt32 crlStoreIndex = 0;
206 PKIX_UInt32 numCrlStores = 0;
207 PKIX_Boolean storeIsLocal = PKIX_FALSE;
208 PKIX_RevocationStatus revStatus = PKIX_RevStatus_NoInfo;
209
210 PKIX_ENTER(CERTCHAINCHECKER, "pkix_CrlChecker_CheckLocal");
211 PKIX_NULLCHECK_FOUR(cert, issuer, checkerObject, checkerObject);
212
213 state = (pkix_CrlChecker*)checkerObject;
214
215 PKIX_CHECK(
216 PKIX_List_GetLength(state->certStores, &numCrlStores, plContext),
217 PKIX_LISTGETLENGTHFAILED);
218
219 for (;crlStoreIndex < numCrlStores;crlStoreIndex++) {
220 PKIX_CHECK(
221 PKIX_List_GetItem(state->certStores, crlStoreIndex,
222 (PKIX_PL_Object **)&certStore,
223 plContext),
224 PKIX_LISTGETITEMFAILED);
225
226 PKIX_CHECK(
227 PKIX_CertStore_GetLocalFlag(certStore, &storeIsLocal,
228 plContext),
229 PKIX_CERTSTOREGETLOCALFLAGFAILED);
230 if (storeIsLocal) {
231 PKIX_CHECK(
232 PKIX_CertStore_GetCrlCheckerFn(certStore,
233 &storeCheckRevocationFn,
234 plContext),
235 PKIX_CERTSTOREGETCHECKREVBYCRLFAILED);
236
237 if (storeCheckRevocationFn) {
238 PKIX_CHECK(
239 (*storeCheckRevocationFn)(certStore, cert, issuer,
240 /* delay sig check if building
241 * a chain by not specifying the time*/
242 chainVerificationState ? date : NULL,
243 /* crl downloading is not done. */
244 PKIX_FALSE,
245 &reasonCode, &revStatus, plContext),
246 PKIX_CERTSTORECRLCHECKFAILED);
247 if (revStatus == PKIX_RevStatus_Revoked) {
248 break;
249 }
250 }
251 }
252 PKIX_DECREF(certStore);
253 } /* while */
254
255 cleanup:
256 *pRevStatus = revStatus;
257 PKIX_DECREF(certStore);
258
259 PKIX_RETURN(CERTCHAINCHECKER);
260 }
261
262 /*
263 * FUNCTION: pkix_CrlChecker_CheckRemote
264 *
265 * DESCRIPTION:
266 * Check if the Cert has been revoked based the CRLs data. This function
267 * maintains the checker state to be current.
268 *
269 * PARAMETERS
270 * "checker"
271 * Address of CertChainChecker which has the state data.
272 * Must be non-NULL.
273 * "cert"
274 * Address of Certificate that is to be validated. Must be non-NULL.
275 * "unreslvdCrtExts"
276 * A List OIDs. Not **yet** used in this checker function.
277 * "plContext"
278 * Platform-specific context pointer.
279 *
280 * THREAD SAFETY:
281 * Not Thread Safe
282 * (see Thread Safety Definitions in Programmer's Guide)
283 *
284 * RETURNS:
285 * Returns NULL if the function succeeds.
286 * Returns a CertChainChecker Error if the function fails in a non-fatal way.
287 * Returns a Fatal Error
288 */
289 PKIX_Error *
290 pkix_CrlChecker_CheckExternal(
291 PKIX_PL_Cert *cert,
292 PKIX_PL_Cert *issuer,
293 PKIX_PL_Date *date,
294 pkix_RevocationMethod *checkerObject,
295 PKIX_ProcessingParams *procParams,
296 PKIX_UInt32 methodFlags,
297 PKIX_RevocationStatus *pRevStatus,
298 PKIX_UInt32 *pReasonCode,
299 void **pNBIOContext,
300 void *plContext)
301 {
302 PKIX_CertStore_CheckRevokationByCrlCallback storeCheckRevocationFn = NULL;
303 PKIX_CertStore_ImportCrlCallback storeImportCrlFn = NULL;
304 PKIX_RevocationStatus revStatus = PKIX_RevStatus_NoInfo;
305 PKIX_CertStore *certStore = NULL;
306 PKIX_CertStore *localStore = NULL;
307 PKIX_CRLSelector *crlSelector = NULL;
308 PKIX_PL_X500Name *issuerName = NULL;
309 pkix_CrlChecker *state = NULL;
310 PKIX_UInt32 reasonCode = 0;
311 PKIX_UInt32 crlStoreIndex = 0;
312 PKIX_UInt32 numCrlStores = 0;
313 PKIX_Boolean storeIsLocal = PKIX_FALSE;
314 PKIX_List *crlList = NULL;
315 PKIX_List *dpList = NULL;
316 void *nbioContext = NULL;
317
318 PKIX_ENTER(CERTCHAINCHECKER, "pkix_CrlChecker_CheckExternal");
319 PKIX_NULLCHECK_FOUR(cert, issuer, checkerObject, pNBIOContext);
320
321 nbioContext = *pNBIOContext;
322 *pNBIOContext = NULL; /* prepare for Error exit */
323
324 state = (pkix_CrlChecker*)checkerObject;
325
326 PKIX_CHECK(
327 PKIX_List_GetLength(state->certStores, &numCrlStores, plContext),
328 PKIX_LISTGETLENGTHFAILED);
329
330 /* Find a cert store that is capable of storing crls */
331 for (;crlStoreIndex < numCrlStores;crlStoreIndex++) {
332 PKIX_CHECK(
333 PKIX_List_GetItem(state->certStores, crlStoreIndex,
334 (PKIX_PL_Object **)&certStore,
335 plContext),
336 PKIX_LISTGETITEMFAILED);
337
338 PKIX_CHECK(
339 PKIX_CertStore_GetLocalFlag(certStore, &storeIsLocal,
340 plContext),
341 PKIX_CERTSTOREGETLOCALFLAGFAILED);
342 if (storeIsLocal) {
343 PKIX_CHECK(
344 PKIX_CertStore_GetImportCrlCallback(certStore,
345 &storeImportCrlFn,
346 plContext),
347 PKIX_CERTSTOREGETCHECKREVBYCRLFAILED);
348
349 PKIX_CHECK(
350 PKIX_CertStore_GetCrlCheckerFn(certStore,
351 &storeCheckRevocationFn,
352 plContext),
353 PKIX_CERTSTOREGETCHECKREVBYCRLFAILED);
354
355 if (storeImportCrlFn && storeCheckRevocationFn) {
356 localStore = certStore;
357 certStore = NULL;
358 break;
359 }
360 }
361 PKIX_DECREF(certStore);
362 } /* while */
363
364 /* Report unknown status if we can not check crl in one of the
365 * local stores. */
366 if (!localStore) {
367 PKIX_ERROR_FATAL(PKIX_CRLCHECKERNOLOCALCERTSTOREFOUND);
368 }
369 PKIX_CHECK(
370 PKIX_PL_Cert_VerifyKeyUsage(issuer, PKIX_CRL_SIGN, plContext),
371 PKIX_CERTCHECKKEYUSAGEFAILED);
372 PKIX_CHECK(
373 PKIX_PL_Cert_GetCrlDp(cert, &dpList, plContext),
374 PKIX_CERTGETCRLDPFAILED);
375 if (!(methodFlags & PKIX_REV_M_REQUIRE_INFO_ON_MISSING_SOURCE) &&
376 (!dpList || !dpList->length)) {
377 goto cleanup;
378 }
379 PKIX_CHECK(
380 PKIX_PL_Cert_GetIssuer(cert, &issuerName, plContext),
381 PKIX_CERTGETISSUERFAILED);
382 PKIX_CHECK(
383 PKIX_CRLSelector_Create(issuer, dpList, date, &crlSelector, plContext),
384 PKIX_CRLCHECKERSETSELECTORFAILED);
385 /* Fetch crl and store in a local cert store */
386 for (crlStoreIndex = 0;crlStoreIndex < numCrlStores;crlStoreIndex++) {
387 PKIX_CertStore_CRLCallback getCrlsFn;
388
389 PKIX_CHECK(
390 PKIX_List_GetItem(state->certStores, crlStoreIndex,
391 (PKIX_PL_Object **)&certStore,
392 plContext),
393 PKIX_LISTGETITEMFAILED);
394
395 PKIX_CHECK(
396 PKIX_CertStore_GetCRLCallback(certStore, &getCrlsFn,
397 plContext),
398 PKIX_CERTSTOREGETCRLCALLBACKFAILED);
399
400 PKIX_CHECK(
401 (*getCrlsFn)(certStore, crlSelector, &nbioContext,
402 &crlList, plContext),
403 PKIX_GETCRLSFAILED);
404
405 PKIX_CHECK(
406 (*storeImportCrlFn)(localStore, issuerName, crlList, plContext),
407 PKIX_CERTSTOREFAILTOIMPORTCRLLIST);
408
409 PKIX_CHECK(
410 (*storeCheckRevocationFn)(certStore, cert, issuer, date,
411 /* done with crl downloading */
412 PKIX_TRUE,
413 &reasonCode, &revStatus, plContext),
414 PKIX_CERTSTORECRLCHECKFAILED);
415 if (revStatus != PKIX_RevStatus_NoInfo) {
416 break;
417 }
418 PKIX_DECREF(crlList);
419 PKIX_DECREF(certStore);
420 } /* while */
421
422 cleanup:
423 /* Update return flags */
424 if (revStatus == PKIX_RevStatus_NoInfo &&
425 ((dpList && dpList->length > 0) ||
426 (methodFlags & PKIX_REV_M_REQUIRE_INFO_ON_MISSING_SOURCE)) &&
427 methodFlags & PKIX_REV_M_FAIL_ON_MISSING_FRESH_INFO) {
428 revStatus = PKIX_RevStatus_Revoked;
429 }
430 *pRevStatus = revStatus;
431
432 PKIX_DECREF(dpList);
433 PKIX_DECREF(crlList);
434 PKIX_DECREF(certStore);
435 PKIX_DECREF(issuerName);
436 PKIX_DECREF(localStore);
437 PKIX_DECREF(crlSelector);
438
439 PKIX_RETURN(CERTCHAINCHECKER);
440 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698