/src/nss/lib/certhigh/crlv2.c
Line | Count | Source |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | /* |
6 | | * Code for dealing with x.509 v3 crl and crl entries extensions. |
7 | | */ |
8 | | |
9 | | #include "cert.h" |
10 | | #include "secitem.h" |
11 | | #include "secoid.h" |
12 | | #include "secoidt.h" |
13 | | #include "secder.h" |
14 | | #include "secasn1.h" |
15 | | #include "certxutl.h" |
16 | | |
17 | | /* Callback to set extensions and adjust verison */ |
18 | | static void |
19 | | SetCrlExts(void *object, CERTCertExtension **exts) |
20 | 0 | { |
21 | 0 | CERTCrl *crl = (CERTCrl *)object; |
22 | |
|
23 | 0 | crl->extensions = exts; |
24 | 0 | DER_SetUInteger(crl->arena, &crl->version, SEC_CRL_VERSION_2); |
25 | 0 | } |
26 | | |
27 | | void * |
28 | | CERT_StartCRLExtensions(CERTCrl *crl) |
29 | 0 | { |
30 | 0 | return (cert_StartExtensions((void *)crl, crl->arena, SetCrlExts)); |
31 | 0 | } |
32 | | |
33 | | static void |
34 | | SetCrlEntryExts(void *object, CERTCertExtension **exts) |
35 | 0 | { |
36 | 0 | CERTCrlEntry *crlEntry = (CERTCrlEntry *)object; |
37 | |
|
38 | 0 | crlEntry->extensions = exts; |
39 | 0 | } |
40 | | |
41 | | void * |
42 | | CERT_StartCRLEntryExtensions(CERTCrl *crl, CERTCrlEntry *entry) |
43 | 0 | { |
44 | 0 | return (cert_StartExtensions(entry, crl->arena, SetCrlEntryExts)); |
45 | 0 | } |
46 | | |
47 | | SECStatus |
48 | | CERT_FindCRLNumberExten(PLArenaPool *arena, CERTCrl *crl, |
49 | | SECItem *value) |
50 | 0 | { |
51 | 0 | SECItem encodedExtenValue; |
52 | 0 | SECItem *tmpItem = NULL; |
53 | 0 | SECStatus rv; |
54 | 0 | void *mark = NULL; |
55 | |
|
56 | 0 | encodedExtenValue.data = NULL; |
57 | 0 | encodedExtenValue.len = 0; |
58 | |
|
59 | 0 | rv = cert_FindExtension(crl->extensions, SEC_OID_X509_CRL_NUMBER, |
60 | 0 | &encodedExtenValue); |
61 | 0 | if (rv != SECSuccess) |
62 | 0 | return (rv); |
63 | | |
64 | 0 | mark = PORT_ArenaMark(arena); |
65 | |
|
66 | 0 | tmpItem = SECITEM_ArenaDupItem(arena, &encodedExtenValue); |
67 | 0 | if (tmpItem) { |
68 | 0 | rv = SEC_QuickDERDecodeItem(arena, value, |
69 | 0 | SEC_ASN1_GET(SEC_IntegerTemplate), |
70 | 0 | tmpItem); |
71 | 0 | } else { |
72 | 0 | rv = SECFailure; |
73 | 0 | } |
74 | |
|
75 | 0 | PORT_Free(encodedExtenValue.data); |
76 | 0 | if (rv == SECFailure) { |
77 | 0 | PORT_ArenaRelease(arena, mark); |
78 | 0 | } else { |
79 | 0 | PORT_ArenaUnmark(arena, mark); |
80 | 0 | } |
81 | 0 | return (rv); |
82 | 0 | } |
83 | | |
84 | | SECStatus |
85 | | CERT_FindCRLEntryReasonExten(CERTCrlEntry *crlEntry, |
86 | | CERTCRLEntryReasonCode *value) |
87 | 0 | { |
88 | 0 | SECItem wrapperItem = { siBuffer, 0 }; |
89 | 0 | SECItem tmpItem = { siBuffer, 0 }; |
90 | 0 | SECStatus rv; |
91 | 0 | PLArenaPool *arena = NULL; |
92 | |
|
93 | 0 | arena = PORT_NewArena(DER_DEFAULT_CHUNKSIZE); |
94 | 0 | if (!arena) { |
95 | 0 | return (SECFailure); |
96 | 0 | } |
97 | | |
98 | 0 | rv = cert_FindExtension(crlEntry->extensions, SEC_OID_X509_REASON_CODE, |
99 | 0 | &wrapperItem); |
100 | 0 | if (rv != SECSuccess) { |
101 | 0 | goto loser; |
102 | 0 | } |
103 | | |
104 | 0 | rv = SEC_QuickDERDecodeItem(arena, &tmpItem, |
105 | 0 | SEC_ASN1_GET(SEC_EnumeratedTemplate), |
106 | 0 | &wrapperItem); |
107 | |
|
108 | 0 | if (rv != SECSuccess) { |
109 | 0 | goto loser; |
110 | 0 | } |
111 | | |
112 | 0 | *value = (CERTCRLEntryReasonCode)DER_GetInteger(&tmpItem); |
113 | |
|
114 | 0 | loser: |
115 | 0 | if (arena) { |
116 | 0 | PORT_FreeArena(arena, PR_FALSE); |
117 | 0 | } |
118 | |
|
119 | 0 | if (wrapperItem.data) { |
120 | 0 | PORT_Free(wrapperItem.data); |
121 | 0 | } |
122 | |
|
123 | 0 | return (rv); |
124 | 0 | } |