2 * NSS utility functions
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 /* $Id: cmpcert.c,v 1.7 2012/04/25 14:50:12 gerv%gerv.net Exp $ */
21 * Look to see if any of the signers in the cert chain for "cert" are found
22 * in the list of caNames.
23 * Returns SECSuccess if so, SECFailure if not.
26 NSS_CmpCertChainWCANames(CERTCertificate
*cert
, CERTDistNames
*caNames
)
29 CERTCertificate
* curcert
;
30 CERTCertificate
* oldcert
;
37 SECItem compatIssuerName
;
39 if (!cert
|| !caNames
|| !caNames
->nnames
|| !caNames
->names
||
40 !caNames
->names
->data
)
43 curcert
= CERT_DupCertificate(cert
);
46 issuerName
= curcert
->derIssuer
;
48 /* compute an alternate issuer name for compatibility with 2.0
49 * enterprise server, which send the CA names without
50 * the outer layer of DER header
52 rv
= DER_Lengths(&issuerName
, &headerlen
, (PRUint32
*)&contentlen
);
53 if ( rv
== SECSuccess
) {
54 compatIssuerName
.data
= &issuerName
.data
[headerlen
];
55 compatIssuerName
.len
= issuerName
.len
- headerlen
;
57 compatIssuerName
.data
= NULL
;
58 compatIssuerName
.len
= 0;
61 for (j
= 0; j
< caNames
->nnames
; j
++) {
62 caname
= &caNames
->names
[j
];
63 if (SECITEM_CompareItem(&issuerName
, caname
) == SECEqual
) {
65 CERT_DestroyCertificate(curcert
);
67 } else if (SECITEM_CompareItem(&compatIssuerName
, caname
) == SECEqual
) {
69 CERT_DestroyCertificate(curcert
);
73 if ( ( depth
<= 20 ) &&
74 ( SECITEM_CompareItem(&curcert
->derIssuer
, &curcert
->derSubject
)
77 curcert
= CERT_FindCertByName(curcert
->dbhandle
,
79 CERT_DestroyCertificate(oldcert
);
82 CERT_DestroyCertificate(curcert
);