~ubuntu-branches/ubuntu/raring/nss/raring-security

« back to all changes in this revision

Viewing changes to mozilla/security/nss/lib/libpkix/pkix_pl_nss/pki/pkix_pl_crldp.c

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2010-03-25 13:46:06 UTC
  • mfrom: (1.1.11 upstream)
  • Revision ID: james.westby@ubuntu.com-20100325134606-bl6liuok2w9l7snv
Tags: 3.12.6-0ubuntu1
* New upstream release 3.12.6 RTM (NSS_3_12_6_RTM)
  - fixes CVE-2009-3555 aka US-CERT VU#120541
* Adjust patches to changed upstream code base
  - update debian/patches/38_kbsd.patch
  - update debian/patches/38_mips64_build.patch
  - update debian/patches/85_security_load.patch
* Remove patches that are merged upstream
  - delete debian/patches/91_nonexec_stack.patch
  - update debian/patches/series
* Bump nspr dependency to 4.8
  - update debian/control
* Add new symbols for 3.12.6
  - 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_pl_crldp.c
 
39
 *
 
40
 * Crl DP Object Functions
 
41
 *
 
42
 */
 
43
 
 
44
#include "pkix_pl_crldp.h"
 
45
 
 
46
static PKIX_Error *
 
47
pkix_pl_CrlDp_Destroy(
 
48
        PKIX_PL_Object *object,
 
49
        void *plContext)
 
50
{
 
51
    pkix_pl_CrlDp *crldp = NULL;
 
52
    
 
53
    PKIX_ENTER(CRLCHECKER, "pkix_CrlDp_Destroy");
 
54
    PKIX_NULLCHECK_ONE(object);
 
55
    
 
56
    /* Check that this object is a default CRL checker state */
 
57
    PKIX_CHECK(
 
58
        pkix_CheckType(object, PKIX_CRLDP_TYPE, plContext),
 
59
        PKIX_OBJECTNOTCRLCHECKER);
 
60
    
 
61
    crldp = (pkix_pl_CrlDp *)object;
 
62
    if (crldp->distPointType == relativeDistinguishedName) {
 
63
        CERT_DestroyName(crldp->name.issuerName);
 
64
        crldp->name.issuerName = NULL;
 
65
    }
 
66
    crldp->nssdp = NULL;
 
67
cleanup:
 
68
    PKIX_RETURN(CRLCHECKER);
 
69
}
 
70
 
 
71
/*
 
72
 * FUNCTION: pkix_pl_CrlDp_RegisterSelf
 
73
 *
 
74
 * DESCRIPTION:
 
75
 *  Registers PKIX_CRLDP_TYPE and its related functions
 
76
 *  with systemClasses[]
 
77
 *
 
78
 * THREAD SAFETY:
 
79
 *  Not Thread Safe (see Thread Safety Definitions in Programmer's Guide)
 
80
 *
 
81
 *  Since this function is only called by PKIX_PL_Initialize, which should
 
82
 *  only be called once, it is acceptable that this function is not
 
83
 *  thread-safe.
 
84
 */
 
85
PKIX_Error *
 
86
pkix_pl_CrlDp_RegisterSelf(void *plContext)
 
87
{
 
88
        extern pkix_ClassTable_Entry systemClasses[PKIX_NUMTYPES];
 
89
        pkix_ClassTable_Entry* entry = &systemClasses[PKIX_CRLDP_TYPE];
 
90
 
 
91
        PKIX_ENTER(CRLCHECKER, "pkix_CrlDp_RegisterSelf");
 
92
 
 
93
        entry->description = "CrlDistPoint";
 
94
        entry->typeObjectSize = sizeof(pkix_pl_CrlDp);
 
95
        entry->destructor = pkix_pl_CrlDp_Destroy;
 
96
        entry->duplicateFunction = pkix_duplicateImmutable;
 
97
 
 
98
        PKIX_RETURN(CRLCHECKER);
 
99
}
 
100
 
 
101
 
 
102
 
 
103
PKIX_Error *
 
104
pkix_pl_CrlDp_Create(
 
105
    const CRLDistributionPoint *dp,
 
106
    const CERTName *certIssuerName,
 
107
    pkix_pl_CrlDp **pPkixDP,
 
108
    void *plContext)
 
109
{
 
110
    PRArenaPool *rdnArena = NULL;
 
111
    CERTName *issuerNameCopy = NULL;
 
112
    pkix_pl_CrlDp *dpl = NULL;
 
113
 
 
114
    /* Need to save the following info to update crl cache:
 
115
     * - reasons if partitioned(but can not return revocation check
 
116
     *   success if not all crl are downloaded)
 
117
     * - issuer name if different from issuer of the cert
 
118
     * - url to upload a crl if needed.
 
119
     * */
 
120
    PKIX_ENTER(CRLDP, "pkix_pl_CrlDp_Create");
 
121
    PKIX_NULLCHECK_ONE(dp);
 
122
 
 
123
    PKIX_CHECK(
 
124
        PKIX_PL_Object_Alloc(PKIX_CRLDP_TYPE,
 
125
                             sizeof (pkix_pl_CrlDp),
 
126
                             (PKIX_PL_Object **)&dpl,
 
127
                             plContext),
 
128
        PKIX_COULDNOTCREATEOBJECT);
 
129
 
 
130
    dpl->nssdp = dp;
 
131
    dpl->isPartitionedByReasonCode = PKIX_FALSE;
 
132
    if (dp->reasons.data) {
 
133
        dpl->isPartitionedByReasonCode = PKIX_TRUE;
 
134
    }
 
135
    if (dp->distPointType == generalName) {
 
136
        dpl->distPointType = generalName;
 
137
        dpl->name.fullName = dp->distPoint.fullName;
 
138
    } else {
 
139
        SECStatus rv;
 
140
        const CERTName *issuerName = NULL;
 
141
        const CERTRDN *relName = &dp->distPoint.relativeName;
 
142
 
 
143
        if (dp->crlIssuer) {
 
144
            if (dp->crlIssuer->l.next) {
 
145
                /* Violate RFC 5280: in this case crlIssuer
 
146
                 * should have only one name and should be
 
147
                 * a distinguish name. */
 
148
                PKIX_ERROR(PKIX_NOTCONFORMINGCRLDP);
 
149
            }
 
150
            issuerName = &dp->crlIssuer->name.directoryName;
 
151
        } else {
 
152
            issuerName = certIssuerName;
 
153
        }
 
154
        rdnArena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE);
 
155
        if (!rdnArena) {
 
156
            PKIX_ERROR(PKIX_PORTARENAALLOCFAILED);
 
157
        }
 
158
        issuerNameCopy = (CERTName *)PORT_ArenaZNew(rdnArena, CERTName*);
 
159
        if (!issuerNameCopy) {
 
160
            PKIX_ERROR(PKIX_ALLOCERROR);
 
161
        }
 
162
        rv = CERT_CopyName(rdnArena, issuerNameCopy, (CERTName*)issuerName);
 
163
        if (rv == SECFailure) {
 
164
            PKIX_ERROR(PKIX_ALLOCERROR);
 
165
        }
 
166
        rv = CERT_AddRDN(issuerNameCopy, (CERTRDN*)relName);
 
167
        if (rv == SECFailure) {
 
168
            PKIX_ERROR(PKIX_ALLOCERROR);
 
169
        }
 
170
        dpl->distPointType = relativeDistinguishedName;
 
171
        dpl->name.issuerName = issuerNameCopy;
 
172
        rdnArena = NULL;
 
173
    }
 
174
    *pPkixDP = dpl;
 
175
    dpl = NULL;
 
176
 
 
177
cleanup:
 
178
    if (rdnArena) {
 
179
        PORT_FreeArena(rdnArena, PR_FALSE);
 
180
    }
 
181
    PKIX_DECREF(dpl);
 
182
 
 
183
    PKIX_RETURN(CRLDP);
 
184
}