~ubuntu-branches/ubuntu/jaunty/nss/jaunty-proposed

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack, Fabien Tassin, Alexander Sack
  • Date: 2009-01-11 15:06:17 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20090111150617-iz4lw05qgy2odorl
Tags: 3.12.2~rc1-0ubuntu1
* New upstream snapshot: 3.12.2 RC1

[ Fabien Tassin <fta@ubuntu.com> ]
* Remove patch applied upstream:
  - drop debian/patches/80_security_tools.patch
  - update debian/patches/series
* Update diverged patches:
  - update debian/patches/38_kbsd.patch
  - update debian/patches/38_mips64_build.patch
* Add new symbols to symbols file
  - update debian/libnss3-1d.symbols

[ Alexander Sack <asac@ubuntu.com> ]
* disable soname patch to become binary compatible with upstream
  - update debian/patches/series
* flip links: libnss3.so <- libnss3.so.1d (before: libnss3.so ->
  libnss3.so.1d); same link flipping was done for all other previously
  soname patched libs: libnssutil3.so, libsmime3.so.1d, libssl3.so.1d
  - update debian/libnss3-1d.links
  - update debian/libnss3-1d.symbols
* properly transition links in preinst and postrm; also cover abort-
  cases in the other maintainer scripts
  - add debian/libnss3-1d.postinst
  - add debian/libnss3-1d.postrm
  - add debian/libnss3-1d.preinst
  - add debian/libnss3-1d.prerm
* remove hack from debian/rules that debian uses to recreate
  libsoftokn3.so with a versioned SONAME
  - update debian/rules
* install the unversioned .so binaries
  - update debian/rules
* only install the 4 main libraries into /usr/lib; all the others
  go to pkglibdir
  - update debian/rules
* higher bar for libnspr4 Build-Depend to >= 4.7.3~, which is
  the version where the soname droppage is going to happen
  - update debian/control
* explitily pass libraries to be used for dpkg-gensymbols run of
  dh_makeshlibs
  - update debian/rules
* fix lintian complain about no-shlibs-control-file
  - update debian/rules

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_nameconstraintschecker.c
 
39
 *
 
40
 * Functions for Name Constraints Checkers
 
41
 *
 
42
 */
 
43
 
 
44
#include "pkix_nameconstraintschecker.h"
 
45
 
 
46
/* --Private-NameConstraintsCheckerState-Functions---------------------- */
 
47
 
 
48
/*
 
49
 * FUNCTION: pkix_NameConstraintsCheckerstate_Destroy
 
50
 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h)
 
51
 */
 
52
static PKIX_Error *
 
53
pkix_NameConstraintsCheckerState_Destroy(
 
54
        PKIX_PL_Object *object,
 
55
        void *plContext)
 
56
{
 
57
        pkix_NameConstraintsCheckerState *state = NULL;
 
58
 
 
59
        PKIX_ENTER(CERTNAMECONSTRAINTSCHECKERSTATE,
 
60
                    "pkix_NameConstraintsCheckerState_Destroy");
 
61
        PKIX_NULLCHECK_ONE(object);
 
62
 
 
63
        /* Check that object type */
 
64
        PKIX_CHECK(pkix_CheckType
 
65
            (object, PKIX_CERTNAMECONSTRAINTSCHECKERSTATE_TYPE, plContext),
 
66
            PKIX_OBJECTNOTNAMECONSTRAINTSCHECKERSTATE);
 
67
 
 
68
        state = (pkix_NameConstraintsCheckerState *)object;
 
69
 
 
70
        PKIX_DECREF(state->nameConstraints);
 
71
        PKIX_DECREF(state->nameConstraintsOID);
 
72
 
 
73
cleanup:
 
74
 
 
75
        PKIX_RETURN(CERTNAMECONSTRAINTSCHECKERSTATE);
 
76
}
 
77
 
 
78
/*
 
79
 * FUNCTION: pkix_NameConstraintsCheckerState_RegisterSelf
 
80
 *
 
81
 * DESCRIPTION:
 
82
 *  Registers PKIX_CERTNAMECONSTRAINTSCHECKERSTATE_TYPE and its related
 
83
 *  functions with systemClasses[]
 
84
 *
 
85
 * THREAD SAFETY:
 
86
 *  Not Thread Safe - for performance and complexity reasons
 
87
 *
 
88
 *  Since this function is only called by PKIX_PL_Initialize, which should
 
89
 *  only be called once, it is acceptable that this function is not
 
90
 *  thread-safe.
 
91
 */
 
92
PKIX_Error *
 
93
pkix_NameConstraintsCheckerState_RegisterSelf(void *plContext)
 
94
{
 
95
        extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES];
 
96
        pkix_ClassTable_Entry entry;
 
97
 
 
98
        PKIX_ENTER(CERTNAMECONSTRAINTSCHECKERSTATE,
 
99
                    "pkix_NameConstraintsCheckerState_RegisterSelf");
 
100
 
 
101
        entry.description = "NameConstraintsCheckerState";
 
102
        entry.objCounter = 0;
 
103
        entry.typeObjectSize = sizeof(pkix_NameConstraintsCheckerState);
 
104
        entry.destructor = pkix_NameConstraintsCheckerState_Destroy;
 
105
        entry.equalsFunction = NULL;
 
106
        entry.hashcodeFunction = NULL;
 
107
        entry.toStringFunction = NULL;
 
108
        entry.comparator = NULL;
 
109
        entry.duplicateFunction = NULL;
 
110
 
 
111
        systemClasses[PKIX_CERTNAMECONSTRAINTSCHECKERSTATE_TYPE] = entry;
 
112
 
 
113
        PKIX_RETURN(CERTNAMECONSTRAINTSCHECKERSTATE);
 
114
}
 
115
 
 
116
/*
 
117
 * FUNCTION: pkix_NameConstraintsCheckerState_Create
 
118
 *
 
119
 * DESCRIPTION:
 
120
 *  Allocate and initialize NameConstraintsChecker state data.
 
121
 *
 
122
 * PARAMETERS
 
123
 *  "nameConstraints"
 
124
 *      Address of NameConstraints to be stored in state. May be NULL.
 
125
 *  "numCerts"
 
126
 *      Number of certificates in the validation chain. This data is used
 
127
 *      to identify end-entity.
 
128
 *  "pCheckerState"
 
129
 *      Address of NameConstraintsCheckerState that is returned. Must be
 
130
 *      non-NULL.
 
131
 *  "plContext" - Platform-specific context pointer.
 
132
 *
 
133
 * THREAD SAFETY:
 
134
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 
135
 *
 
136
 * RETURNS:
 
137
 *  Returns NULL if the function succeeds.
 
138
 *  Returns a CERTNAMECONSTRAINTSCHECKERSTATE Error if the function fails in
 
139
 *  a non-fatal way.
 
140
 *  Returns a Fatal Error
 
141
 */
 
142
static PKIX_Error *
 
143
pkix_NameConstraintsCheckerState_Create(
 
144
    PKIX_PL_CertNameConstraints *nameConstraints,
 
145
    PKIX_UInt32 numCerts,
 
146
    pkix_NameConstraintsCheckerState **pCheckerState,
 
147
    void *plContext)
 
148
{
 
149
        pkix_NameConstraintsCheckerState *state = NULL;
 
150
 
 
151
        PKIX_ENTER(CERTNAMECONSTRAINTSCHECKERSTATE,
 
152
                    "pkix_NameConstraintsCheckerState_Create");
 
153
        PKIX_NULLCHECK_ONE(pCheckerState);
 
154
 
 
155
        PKIX_CHECK(PKIX_PL_Object_Alloc
 
156
                    (PKIX_CERTNAMECONSTRAINTSCHECKERSTATE_TYPE,
 
157
                    sizeof (pkix_NameConstraintsCheckerState),
 
158
                    (PKIX_PL_Object **)&state,
 
159
                    plContext),
 
160
                    PKIX_COULDNOTCREATENAMECONSTRAINTSCHECKERSTATEOBJECT);
 
161
 
 
162
        /* Initialize fields */
 
163
 
 
164
        PKIX_CHECK(PKIX_PL_OID_Create
 
165
                    (PKIX_NAMECONSTRAINTS_OID,
 
166
                    &state->nameConstraintsOID,
 
167
                    plContext),
 
168
                    PKIX_OIDCREATEFAILED);
 
169
 
 
170
        PKIX_INCREF(nameConstraints);
 
171
 
 
172
        state->nameConstraints = nameConstraints;
 
173
        state->certsRemaining = numCerts;
 
174
 
 
175
        *pCheckerState = state;
 
176
        state = NULL;
 
177
 
 
178
cleanup:
 
179
 
 
180
        PKIX_DECREF(state);
 
181
 
 
182
        PKIX_RETURN(CERTNAMECONSTRAINTSCHECKERSTATE);
 
183
}
 
184
 
 
185
/* --Private-NameConstraintsChecker-Functions------------------------- */
 
186
 
 
187
/*
 
188
 * FUNCTION: pkix_NameConstraintsChecker_Check
 
189
 * (see comments for PKIX_CertChainChecker_CheckCallback in pkix_checker.h)
 
190
 */
 
191
static PKIX_Error *
 
192
pkix_NameConstraintsChecker_Check(
 
193
        PKIX_CertChainChecker *checker,
 
194
        PKIX_PL_Cert *cert,
 
195
        PKIX_List *unresolvedCriticalExtensions,
 
196
        void **pNBIOContext,
 
197
        void *plContext)
 
198
{
 
199
        pkix_NameConstraintsCheckerState *state = NULL;
 
200
        PKIX_PL_CertNameConstraints *nameConstraints = NULL;
 
201
        PKIX_PL_CertNameConstraints *mergedNameConstraints = NULL;
 
202
        PKIX_Boolean selfIssued = PKIX_FALSE;
 
203
 
 
204
        PKIX_ENTER(CERTCHAINCHECKER, "pkix_NameConstraintsChecker_Check");
 
205
        PKIX_NULLCHECK_THREE(checker, cert, pNBIOContext);
 
206
 
 
207
        *pNBIOContext = NULL; /* we never block on pending I/O */
 
208
 
 
209
        PKIX_CHECK(PKIX_CertChainChecker_GetCertChainCheckerState
 
210
                    (checker, (PKIX_PL_Object **)&state, plContext),
 
211
                    PKIX_CERTCHAINCHECKERGETCERTCHAINCHECKERSTATEFAILED);
 
212
 
 
213
        state->certsRemaining--;
 
214
 
 
215
        /* Get status of self issued */
 
216
        PKIX_CHECK(pkix_IsCertSelfIssued(cert, &selfIssued, plContext),
 
217
                    PKIX_ISCERTSELFISSUEDFAILED);
 
218
 
 
219
        /* Check on non self-issued and if so only for last cert */
 
220
        if (selfIssued == PKIX_FALSE ||
 
221
            (selfIssued == PKIX_TRUE && state->certsRemaining == 0)) {
 
222
                PKIX_CHECK(PKIX_PL_Cert_CheckNameConstraints
 
223
                    (cert, state->nameConstraints, plContext),
 
224
                    PKIX_CERTCHECKNAMECONSTRAINTSFAILED);
 
225
        }
 
226
 
 
227
        if (state->certsRemaining != 0) {
 
228
 
 
229
            PKIX_CHECK(PKIX_PL_Cert_GetNameConstraints
 
230
                    (cert, &nameConstraints, plContext),
 
231
                    PKIX_CERTGETNAMECONSTRAINTSFAILED);
 
232
 
 
233
            /* Merge with previous name constraints kept in state */
 
234
 
 
235
            if (nameConstraints != NULL) {
 
236
 
 
237
                if (state->nameConstraints == NULL) {
 
238
 
 
239
                        state->nameConstraints = nameConstraints;
 
240
 
 
241
                } else {
 
242
 
 
243
                        PKIX_CHECK(PKIX_PL_Cert_MergeNameConstraints
 
244
                                (nameConstraints,
 
245
                                state->nameConstraints,
 
246
                                &mergedNameConstraints,
 
247
                                plContext),
 
248
                                PKIX_CERTMERGENAMECONSTRAINTSFAILED);
 
249
 
 
250
                        PKIX_DECREF(nameConstraints);
 
251
                        PKIX_DECREF(state->nameConstraints);
 
252
 
 
253
                        state->nameConstraints = mergedNameConstraints;
 
254
                }
 
255
 
 
256
                /* Remove Name Constraints Extension OID from list */
 
257
                if (unresolvedCriticalExtensions != NULL) {
 
258
                        PKIX_CHECK(pkix_List_Remove
 
259
                                    (unresolvedCriticalExtensions,
 
260
                                    (PKIX_PL_Object *)state->nameConstraintsOID,
 
261
                                    plContext),
 
262
                                    PKIX_LISTREMOVEFAILED);
 
263
                }
 
264
            }
 
265
        }
 
266
 
 
267
        PKIX_CHECK(PKIX_CertChainChecker_SetCertChainCheckerState
 
268
                    (checker, (PKIX_PL_Object *)state, plContext),
 
269
                    PKIX_CERTCHAINCHECKERSETCERTCHAINCHECKERSTATEFAILED);
 
270
 
 
271
cleanup:
 
272
 
 
273
        PKIX_DECREF(state);
 
274
 
 
275
        PKIX_RETURN(CERTCHAINCHECKER);
 
276
}
 
277
 
 
278
/*
 
279
 * FUNCTION: pkix_NameConstraintsChecker_Initialize
 
280
 *
 
281
 * DESCRIPTION:
 
282
 *  Create a CertChainChecker with a NameConstraintsCheckerState. The
 
283
 *  NameConstraintsCheckerState is created with "trustedNC" and "numCerts"
 
284
 *  as its initial state. The CertChainChecker for the NameConstraints is
 
285
 *  returned at address of "pChecker".
 
286
 *
 
287
 * PARAMETERS
 
288
 *  "trustedNC"
 
289
 *      The NameConstraints from trusted anchor Cert is stored at "trustedNC"
 
290
 *      for initialization. May be NULL.
 
291
 *  "numCerts"
 
292
 *      Number of certificates in the validation chain. This data is used
 
293
 *      to identify end-entity.
 
294
 *  "pChecker"
 
295
 *      Address of CertChainChecker to bo created and returned.
 
296
 *      Must be non-NULL.
 
297
 *  "plContext" - Platform-specific context pointer.
 
298
 *
 
299
 * THREAD SAFETY:
 
300
 *  Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 
301
 *
 
302
 * RETURNS:
 
303
 *  Returns NULL if the function succeeds.
 
304
 *  Returns a CERTCHAINCHECKER Error if the function fails in a non-fatal way.
 
305
 *  Returns a Fatal Error
 
306
 */
 
307
PKIX_Error *
 
308
pkix_NameConstraintsChecker_Initialize(
 
309
        PKIX_PL_CertNameConstraints *trustedNC,
 
310
        PKIX_UInt32 numCerts,
 
311
        PKIX_CertChainChecker **pChecker,
 
312
        void *plContext)
 
313
{
 
314
        pkix_NameConstraintsCheckerState *state = NULL;
 
315
 
 
316
        PKIX_ENTER(CERTCHAINCHECKER, "pkix_NameConstraintsChecker_Initialize");
 
317
        PKIX_NULLCHECK_ONE(pChecker);
 
318
 
 
319
        PKIX_CHECK(pkix_NameConstraintsCheckerState_Create
 
320
                    (trustedNC, numCerts, &state, plContext),
 
321
                    PKIX_NAMECONSTRAINTSCHECKERSTATECREATEFAILED);
 
322
 
 
323
        PKIX_CHECK(PKIX_CertChainChecker_Create
 
324
                    (pkix_NameConstraintsChecker_Check,
 
325
                    PKIX_FALSE,
 
326
                    PKIX_FALSE,
 
327
                    NULL,
 
328
                    (PKIX_PL_Object *) state,
 
329
                    pChecker,
 
330
                    plContext),
 
331
                    PKIX_CERTCHAINCHECKERCREATEFAILED);
 
332
 
 
333
cleanup:
 
334
 
 
335
        PKIX_DECREF(state);
 
336
 
 
337
        PKIX_RETURN(CERTCHAINCHECKER);
 
338
}