~ubuntu-branches/ubuntu/karmic/nss/karmic-updates

« back to all changes in this revision

Viewing changes to mozilla/security/nss/lib/libpkix/pkix/checker/pkix_defaultrevchecker.c

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2009-06-16 13:23:47 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090616132347-311ysb8oep74b98y
Tags: 3.12.3-0ubuntu1
* new upstream release 3.12.3 RTM (NSS_3_12_3_RTM) (LP: #387751)
* adjust patches to changed upstream code base
  - update debian/patches/38_kbsd.patch
* needs nspr >= 4.7.4
  - update debian/control
* update 85_security_load.patch to latest debian version
  - update debian/patches/85_security_load.patch
* add new symbols for 3.12.3
  - update debian/libnss3-1d.symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ***** BEGIN LICENSE BLOCK *****
2
 
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3
 
 *
4
 
 * The contents of this file are subject to the Mozilla Public License Version
5
 
 * 1.1 (the "License"); you may not use this file except in compliance with
6
 
 * the License. You may obtain a copy of the License at
7
 
 * http://www.mozilla.org/MPL/
8
 
 *
9
 
 * Software distributed under the License is distributed on an "AS IS" basis,
10
 
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
 
 * for the specific language governing rights and limitations under the
12
 
 * License.
13
 
 *
14
 
 * The Original Code is the PKIX-C library.
15
 
 *
16
 
 * The Initial Developer of the Original Code is
17
 
 * Sun Microsystems, Inc.
18
 
 * Portions created by the Initial Developer are
19
 
 * Copyright 2004-2007 Sun Microsystems, Inc.  All Rights Reserved.
20
 
 *
21
 
 * Contributor(s):
22
 
 *   Sun Microsystems, Inc.
23
 
 *
24
 
 * Alternatively, the contents of this file may be used under the terms of
25
 
 * either the GNU General Public License Version 2 or later (the "GPL"), or
26
 
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
 
 * in which case the provisions of the GPL or the LGPL are applicable instead
28
 
 * of those above. If you wish to allow use of your version of this file only
29
 
 * under the terms of either the GPL or the LGPL, and not to allow others to
30
 
 * use your version of this file under the terms of the MPL, indicate your
31
 
 * decision by deleting the provisions above and replace them with the notice
32
 
 * and other provisions required by the GPL or the LGPL. If you do not delete
33
 
 * the provisions above, a recipient may use your version of this file under
34
 
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 
 *
36
 
 * ***** END LICENSE BLOCK ***** */
37
 
/*
38
 
 * pkix_defaultrevchecker.c
39
 
 *
40
 
 * Functions for default Revocation Checker
41
 
 *
42
 
 */
43
 
 
44
 
#include "pkix_defaultrevchecker.h"
45
 
 
46
 
/* --Private-DefaultRevChecker-Functions------------------------------- */
47
 
 
48
 
/*
49
 
 * FUNCTION: pkix_DefaultRevChecker_Destroy
50
 
 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h)
51
 
 */
52
 
static PKIX_Error *
53
 
pkix_DefaultRevChecker_Destroy(
54
 
        PKIX_PL_Object *object,
55
 
        void *plContext)
56
 
{
57
 
        PKIX_DefaultRevocationChecker *revChecker = NULL;
58
 
 
59
 
        PKIX_ENTER(DEFAULTREVOCATIONCHECKER,
60
 
                    "pkix_DefaultRevChecker_Destroy");
61
 
        PKIX_NULLCHECK_ONE(object);
62
 
 
63
 
        /* Check that this object is a DefaultRevocationChecker */
64
 
        PKIX_CHECK(pkix_CheckType
65
 
                (object, PKIX_DEFAULTREVOCATIONCHECKER_TYPE, plContext),
66
 
                PKIX_OBJECTNOTDEFAULTREVOCATIONCHECKER);
67
 
 
68
 
        revChecker = (PKIX_DefaultRevocationChecker *)object;
69
 
 
70
 
        PKIX_DECREF(revChecker->certChainChecker);
71
 
        PKIX_DECREF(revChecker->certStores);
72
 
        PKIX_DECREF(revChecker->testDate);
73
 
        PKIX_DECREF(revChecker->trustedPubKey);
74
 
 
75
 
cleanup:
76
 
 
77
 
        PKIX_RETURN(DEFAULTREVOCATIONCHECKER);
78
 
}
79
 
 
80
 
/*
81
 
 * FUNCTION: pkix_DefaultRevocationChecker_RegisterSelf
82
 
 *
83
 
 * DESCRIPTION:
84
 
 *  Registers PKIX_DEFAULTREVOCATIONCHECKER_TYPE and its related functions
85
 
 *  with systemClasses[]
86
 
 *
87
 
 * THREAD SAFETY:
88
 
 *  Not Thread Safe (see Thread Safety Definitions in Programmer's Guide)
89
 
 *
90
 
 *  Since this function is only called by PKIX_PL_Initialize, which should
91
 
 *  only be called once, it is acceptable that this function is not
92
 
 *  thread-safe.
93
 
 */
94
 
PKIX_Error *
95
 
pkix_DefaultRevocationChecker_RegisterSelf(void *plContext)
96
 
{
97
 
        extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES];
98
 
        pkix_ClassTable_Entry entry;
99
 
 
100
 
        PKIX_ENTER(DEFAULTREVOCATIONCHECKER,
101
 
                    "pkix_DefaultRevocationChecker_RegisterSelf");
102
 
 
103
 
        entry.description = "DefaultRevocationChecker";
104
 
        entry.objCounter = 0;
105
 
        entry.typeObjectSize = sizeof(PKIX_DefaultRevocationChecker);
106
 
        entry.destructor = pkix_DefaultRevChecker_Destroy;
107
 
        entry.equalsFunction = NULL;
108
 
        entry.hashcodeFunction = NULL;
109
 
        entry.toStringFunction = NULL;
110
 
        entry.comparator = NULL;
111
 
        entry.duplicateFunction = NULL;
112
 
 
113
 
        systemClasses[PKIX_DEFAULTREVOCATIONCHECKER_TYPE] = entry;
114
 
 
115
 
        PKIX_RETURN(DEFAULTREVOCATIONCHECKER);
116
 
}
117
 
 
118
 
/*
119
 
 * FUNCTION: pkix_DefaultRevChecker_Create
120
 
 *
121
 
 * DESCRIPTION:
122
 
 *  This function uses the List of certStores given by "certStores", the Date
123
 
 *  given by "testDate", the PublicKey given by "trustedPubKey", and the number
124
 
 *  of certs remaining in the chain given by "certsRemaining" to create a
125
 
 *  DefaultRevocationChecker, which is stored at "pRevChecker".
126
 
 *
127
 
 * PARAMETERS
128
 
 *  "certStores"
129
 
 *      Address of CertStore List to be stored in state. Must be non-NULL.
130
 
 *  "testDate"
131
 
 *      Address of PKIX_PL_Date to be checked. May be NULL.
132
 
 *  "trustedPubKey"
133
 
 *      Address of Public Key of Trust Anchor. Must be non-NULL.
134
 
 *  "certsRemaining"
135
 
 *      Number of certificates remaining in the chain.
136
 
 *  "pRevChecker"
137
 
 *      Address of DefaultRevocationChecker that is returned. Must be non-NULL.
138
 
 *  "plContext"
139
 
 *      Platform-specific context pointer.
140
 
 *
141
 
 * THREAD SAFETY:
142
 
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
143
 
 *
144
 
 * RETURNS:
145
 
 *  Returns NULL if the function succeeds.
146
 
 *  Returns a DefaultRevocationChecker Error if the function fails in a
147
 
 *  non-fatal way.
148
 
 *  Returns a Fatal Error
149
 
 */
150
 
static PKIX_Error *
151
 
pkix_DefaultRevChecker_Create(
152
 
        PKIX_List *certStores,
153
 
        PKIX_PL_Date *testDate,
154
 
        PKIX_PL_PublicKey *trustedPubKey,
155
 
        PKIX_UInt32 certsRemaining,
156
 
        PKIX_DefaultRevocationChecker **pRevChecker,
157
 
        void *plContext)
158
 
{
159
 
        PKIX_DefaultRevocationChecker *revChecker = NULL;
160
 
 
161
 
        PKIX_ENTER(DEFAULTREVOCATIONCHECKER, "pkix_DefaultRevChecker_Create");
162
 
        PKIX_NULLCHECK_THREE(certStores, trustedPubKey, pRevChecker);
163
 
 
164
 
        PKIX_CHECK(PKIX_PL_Object_Alloc
165
 
                (PKIX_DEFAULTREVOCATIONCHECKER_TYPE,
166
 
                sizeof (PKIX_DefaultRevocationChecker),
167
 
                (PKIX_PL_Object **)&revChecker,
168
 
                plContext),
169
 
                PKIX_COULDNOTCREATEDEFAULTREVOCATIONCHECKEROBJECT);
170
 
 
171
 
        /* Initialize fields */
172
 
 
173
 
        revChecker->certChainChecker = NULL;
174
 
        revChecker->check = NULL;
175
 
 
176
 
        PKIX_INCREF(certStores);
177
 
        revChecker->certStores = certStores;
178
 
 
179
 
        PKIX_INCREF(testDate);
180
 
        revChecker->testDate = testDate;
181
 
 
182
 
        PKIX_INCREF(trustedPubKey);
183
 
        revChecker->trustedPubKey = trustedPubKey;
184
 
 
185
 
        revChecker->certsRemaining = certsRemaining;
186
 
 
187
 
        *pRevChecker = revChecker;
188
 
        revChecker = NULL;
189
 
 
190
 
cleanup:
191
 
 
192
 
        PKIX_DECREF(revChecker);
193
 
 
194
 
        PKIX_RETURN(DEFAULTREVOCATIONCHECKER);
195
 
}
196
 
 
197
 
/* --Private-DefaultRevChecker-Functions------------------------------------ */
198
 
 
199
 
/*
200
 
 * FUNCTION: pkix_DefaultRevChecker_Check
201
 
 *
202
 
 * DESCRIPTION:
203
 
 *  Check if the Cert has been revoked based on the CRLs data.  This function
204
 
 *  maintains the checker state to be current.
205
 
 *
206
 
 * PARAMETERS
207
 
 *  "checkerContext"
208
 
 *      Address of RevocationCheckerContext which has the state data.
209
 
 *      Must be non-NULL.
210
 
 *  "cert"
211
 
 *      Address of Certificate that is to be validated. Must be non-NULL.
212
 
 *  "procParams"
213
 
 *      Address of ProcessingParams used to initialize the ExpirationChecker
214
 
 *      and TargetCertChecker. Must be non-NULL.
215
 
 *  "pNBIOContext"
216
 
 *      Address at which platform-dependent non-blocking I/O context is stored.
217
 
 *      Must be non-NULL.
218
 
 *  "pResultCode"
219
 
 *      Address where revocation status will be stored. Must be non-NULL.
220
 
 *  "plContext"
221
 
 *      Platform-specific context pointer.
222
 
 *
223
 
 * THREAD SAFETY:
224
 
 *  Not Thread Safe
225
 
 *      (see Thread Safety Definitions in Programmer's Guide)
226
 
 *
227
 
 * RETURNS:
228
 
 *  Returns NULL if the function succeeds.
229
 
 *  Returns a RevocationChecker Error if the function fails in a non-fatal way.
230
 
 *  Returns a Fatal Error
231
 
 */
232
 
static PKIX_Error *
233
 
pkix_DefaultRevChecker_Check(
234
 
        PKIX_PL_Object *checkerContext,
235
 
        PKIX_PL_Cert *cert,
236
 
        PKIX_ProcessingParams *procParams,
237
 
        void **pNBIOContext,
238
 
        PKIX_UInt32 *pReasonCode,
239
 
        void *plContext)
240
 
{
241
 
        PKIX_DefaultRevocationChecker *defaultRevChecker = NULL;
242
 
        PKIX_CertChainChecker *crlChecker = NULL;
243
 
        PKIX_PL_Object *crlCheckerState = NULL;
244
 
        PKIX_CertChainChecker_CheckCallback check = NULL;
245
 
        void *nbioContext = NULL;
246
 
 
247
 
        PKIX_ENTER(REVOCATIONCHECKER, "pkix_DefaultRevChecker_Check");
248
 
        PKIX_NULLCHECK_FOUR(checkerContext, cert, pNBIOContext, pReasonCode);
249
 
 
250
 
        /* Check that this object is a DefaultRevocationChecker */
251
 
        PKIX_CHECK(pkix_CheckType
252
 
                ((PKIX_PL_Object *)checkerContext,
253
 
                PKIX_DEFAULTREVOCATIONCHECKER_TYPE,
254
 
                plContext),
255
 
                PKIX_OBJECTNOTDEFAULTREVOCATIONCHECKER);
256
 
 
257
 
        defaultRevChecker = (PKIX_DefaultRevocationChecker *)checkerContext;
258
 
 
259
 
        nbioContext = *pNBIOContext;
260
 
        *pNBIOContext = 0;
261
 
        *pReasonCode = 0;
262
 
 
263
 
        /*
264
 
         * If we haven't yet created a defaultCrlChecker to do the actual work,
265
 
         * create one now.
266
 
         */
267
 
        if (defaultRevChecker->certChainChecker == NULL) {
268
 
                PKIX_Boolean nistCRLPolicyEnabled = PR_TRUE;
269
 
                if (procParams) {
270
 
                    PKIX_CHECK(
271
 
                        pkix_ProcessingParams_GetNISTRevocationPolicyEnabled
272
 
                        (procParams, &nistCRLPolicyEnabled, plContext),
273
 
                        PKIX_PROCESSINGPARAMSGETNISTREVPOLICYENABLEDFAILED);
274
 
                }
275
 
 
276
 
                PKIX_CHECK(pkix_DefaultCRLChecker_Initialize
277
 
                        (defaultRevChecker->certStores,
278
 
                        defaultRevChecker->testDate,
279
 
                        defaultRevChecker->trustedPubKey,
280
 
                        defaultRevChecker->certsRemaining,
281
 
                        nistCRLPolicyEnabled,
282
 
                        &crlChecker,
283
 
                        plContext),
284
 
                        PKIX_DEFAULTCRLCHECKERINITIALIZEFAILED);
285
 
 
286
 
                PKIX_CHECK(PKIX_CertChainChecker_GetCheckCallback
287
 
                        (crlChecker, &check, plContext),
288
 
                        PKIX_CERTCHAINCHECKERGETCHECKCALLBACKFAILED);
289
 
 
290
 
                defaultRevChecker->certChainChecker = crlChecker;
291
 
                defaultRevChecker->check = check;
292
 
        }
293
 
 
294
 
        /*
295
 
         * The defaultCRLChecker, which we are using, wants a CRLSelector
296
 
         * (in its state) to select the Issuer of the target Cert.
297
 
         */
298
 
        PKIX_CHECK(PKIX_CertChainChecker_GetCertChainCheckerState
299
 
                (defaultRevChecker->certChainChecker,
300
 
                &crlCheckerState,
301
 
                plContext),
302
 
                PKIX_CERTCHAINCHECKERGETCERTCHAINCHECKERSTATEFAILED);
303
 
 
304
 
        PKIX_CHECK(pkix_CheckType
305
 
                (crlCheckerState, PKIX_DEFAULTCRLCHECKERSTATE_TYPE, plContext),
306
 
                PKIX_OBJECTNOTDEFAULTCRLCHECKERSTATE);
307
 
 
308
 
        /* Set up CRLSelector */
309
 
        PKIX_CHECK(pkix_DefaultCRLChecker_Check_SetSelector
310
 
                (cert,
311
 
                (pkix_DefaultCRLCheckerState *)crlCheckerState,
312
 
                plContext),
313
 
                PKIX_DEFAULTCRLCHECKERCHECKSETSELECTORFAILED);
314
 
 
315
 
        PKIX_CHECK
316
 
                (PKIX_CertChainChecker_SetCertChainCheckerState
317
 
                (defaultRevChecker->certChainChecker,
318
 
                crlCheckerState,
319
 
                plContext),
320
 
                PKIX_CERTCHAINCHECKERSETCERTCHAINCHECKERSTATEFAILED);
321
 
 
322
 
        PKIX_CHECK(defaultRevChecker->check
323
 
                (defaultRevChecker->certChainChecker,
324
 
                cert,
325
 
                NULL,
326
 
                &nbioContext,
327
 
                plContext),
328
 
                PKIX_CERTCHAINCHECKERCHECKCALLBACKFAILED);
329
 
 
330
 
        *pNBIOContext = nbioContext;
331
 
 
332
 
cleanup:
333
 
 
334
 
        PKIX_DECREF(crlCheckerState);
335
 
 
336
 
        PKIX_RETURN(REVOCATIONCHECKER);
337
 
}
338
 
 
339
 
/*
340
 
 * FUNCTION: pkix_DefaultRevChecker_Initialize
341
 
 *
342
 
 * DESCRIPTION:
343
 
 *  Create a CertChainChecker with DefaultRevChecker.
344
 
 *
345
 
 * PARAMETERS
346
 
 *  "certStores"
347
 
 *      Address of CertStore List to be stored in state. Must be non-NULL.
348
 
 *  "testDate"
349
 
 *      Address of PKIX_PL_Date to be checked. May be NULL.
350
 
 *  "trustedPubKey"
351
 
 *      Address of Public Key of Trust Anchor. Must be non-NULL.
352
 
 *  "certsRemaining"
353
 
 *      Number of certificates remaining in the chain.
354
 
 *  "pChecker"
355
 
 *      Address where object pointer will be stored. Must be non-NULL.
356
 
 *      Must be non-NULL.
357
 
 *  "plContext"
358
 
 *      Platform-specific context pointer.
359
 
 *
360
 
 * THREAD SAFETY:
361
 
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
362
 
 *
363
 
 * RETURNS:
364
 
 *  Returns NULL if the function succeeds.
365
 
 *  Returns a CertChainChecker Error if the function fails in a non-fatal way.
366
 
 *  Returns a Fatal Error
367
 
 */
368
 
PKIX_Error *
369
 
pkix_DefaultRevChecker_Initialize(
370
 
        PKIX_List *certStores,
371
 
        PKIX_PL_Date *testDate,
372
 
        PKIX_PL_PublicKey *trustedPubKey,
373
 
        PKIX_UInt32 certsRemaining,
374
 
        PKIX_RevocationChecker **pChecker,
375
 
        void *plContext)
376
 
{
377
 
        PKIX_DefaultRevocationChecker *revChecker = NULL;
378
 
 
379
 
        PKIX_ENTER(REVOCATIONCHECKER, "pkix_DefaultRevChecker_Initialize");
380
 
        PKIX_NULLCHECK_TWO(certStores, pChecker);
381
 
 
382
 
        PKIX_CHECK(pkix_DefaultRevChecker_Create
383
 
                (certStores,
384
 
                testDate,
385
 
                trustedPubKey,
386
 
                certsRemaining,
387
 
                &revChecker,
388
 
                plContext),
389
 
                PKIX_DEFAULTREVCHECKERCREATEFAILED);
390
 
 
391
 
        PKIX_CHECK(PKIX_RevocationChecker_Create
392
 
                (pkix_DefaultRevChecker_Check,
393
 
                (PKIX_PL_Object *)revChecker,
394
 
                pChecker,
395
 
                plContext),
396
 
                PKIX_REVOCATIONCHECKERCREATEFAILED);
397
 
 
398
 
cleanup:
399
 
 
400
 
        PKIX_DECREF(revChecker);
401
 
 
402
 
        PKIX_RETURN(REVOCATIONCHECKER);
403
 
}