/src/mozilla-central/security/nss/lib/ssl/cmpcert.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * NSS utility functions |
3 | | * |
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 | | |
8 | | #include <stdio.h> |
9 | | #include <string.h> |
10 | | #include "prerror.h" |
11 | | #include "secitem.h" |
12 | | #include "prnetdb.h" |
13 | | #include "cert.h" |
14 | | #include "nspr.h" |
15 | | #include "secder.h" |
16 | | #include "keyhi.h" |
17 | | #include "nss.h" |
18 | | |
19 | | /* |
20 | | * Look to see if any of the signers in the cert chain for "cert" are found |
21 | | * in the list of caNames. |
22 | | * Returns SECSuccess if so, SECFailure if not. |
23 | | */ |
24 | | SECStatus |
25 | | NSS_CmpCertChainWCANames(CERTCertificate *cert, CERTDistNames *caNames) |
26 | 0 | { |
27 | 0 | SECItem *caname; |
28 | 0 | CERTCertificate *curcert; |
29 | 0 | CERTCertificate *oldcert; |
30 | 0 | int j; |
31 | 0 | int depth; |
32 | 0 | SECItem issuerName; |
33 | 0 |
|
34 | 0 | if (!cert || !caNames || !caNames->nnames || !caNames->names || |
35 | 0 | !caNames->names->data) |
36 | 0 | return SECFailure; |
37 | 0 | depth = 0; |
38 | 0 | curcert = CERT_DupCertificate(cert); |
39 | 0 |
|
40 | 0 | while (curcert) { |
41 | 0 | issuerName = curcert->derIssuer; |
42 | 0 |
|
43 | 0 | for (j = 0; j < caNames->nnames; j++) { |
44 | 0 | caname = &caNames->names[j]; |
45 | 0 | if (SECITEM_CompareItem(&issuerName, caname) == SECEqual) { |
46 | 0 | CERT_DestroyCertificate(curcert); |
47 | 0 | return SECSuccess; |
48 | 0 | } |
49 | 0 | } |
50 | 0 | if ((depth <= 20) && |
51 | 0 | (SECITEM_CompareItem(&curcert->derIssuer, &curcert->derSubject) != |
52 | 0 | SECEqual)) { |
53 | 0 | oldcert = curcert; |
54 | 0 | curcert = CERT_FindCertByName(curcert->dbhandle, |
55 | 0 | &curcert->derIssuer); |
56 | 0 | CERT_DestroyCertificate(oldcert); |
57 | 0 | depth++; |
58 | 0 | } else { |
59 | 0 | CERT_DestroyCertificate(curcert); |
60 | 0 | curcert = NULL; |
61 | 0 | } |
62 | 0 | } |
63 | 0 | return SECFailure; |
64 | 0 | } |