1 |
|
|
/* $OpenBSD: v3_crld.c,v 1.19 2015/07/29 16:13:48 jsing Exp $ */ |
2 |
|
|
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 |
|
|
* project 1999. |
4 |
|
|
*/ |
5 |
|
|
/* ==================================================================== |
6 |
|
|
* Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved. |
7 |
|
|
* |
8 |
|
|
* Redistribution and use in source and binary forms, with or without |
9 |
|
|
* modification, are permitted provided that the following conditions |
10 |
|
|
* are met: |
11 |
|
|
* |
12 |
|
|
* 1. Redistributions of source code must retain the above copyright |
13 |
|
|
* notice, this list of conditions and the following disclaimer. |
14 |
|
|
* |
15 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright |
16 |
|
|
* notice, this list of conditions and the following disclaimer in |
17 |
|
|
* the documentation and/or other materials provided with the |
18 |
|
|
* distribution. |
19 |
|
|
* |
20 |
|
|
* 3. All advertising materials mentioning features or use of this |
21 |
|
|
* software must display the following acknowledgment: |
22 |
|
|
* "This product includes software developed by the OpenSSL Project |
23 |
|
|
* for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" |
24 |
|
|
* |
25 |
|
|
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
26 |
|
|
* endorse or promote products derived from this software without |
27 |
|
|
* prior written permission. For written permission, please contact |
28 |
|
|
* licensing@OpenSSL.org. |
29 |
|
|
* |
30 |
|
|
* 5. Products derived from this software may not be called "OpenSSL" |
31 |
|
|
* nor may "OpenSSL" appear in their names without prior written |
32 |
|
|
* permission of the OpenSSL Project. |
33 |
|
|
* |
34 |
|
|
* 6. Redistributions of any form whatsoever must retain the following |
35 |
|
|
* acknowledgment: |
36 |
|
|
* "This product includes software developed by the OpenSSL Project |
37 |
|
|
* for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" |
38 |
|
|
* |
39 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
40 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
41 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
42 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
43 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
44 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
45 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
46 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
47 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
48 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
49 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
50 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE. |
51 |
|
|
* ==================================================================== |
52 |
|
|
* |
53 |
|
|
* This product includes cryptographic software written by Eric Young |
54 |
|
|
* (eay@cryptsoft.com). This product includes software written by Tim |
55 |
|
|
* Hudson (tjh@cryptsoft.com). |
56 |
|
|
* |
57 |
|
|
*/ |
58 |
|
|
|
59 |
|
|
#include <stdio.h> |
60 |
|
|
#include <string.h> |
61 |
|
|
|
62 |
|
|
#include <openssl/asn1.h> |
63 |
|
|
#include <openssl/asn1t.h> |
64 |
|
|
#include <openssl/conf.h> |
65 |
|
|
#include <openssl/err.h> |
66 |
|
|
#include <openssl/x509v3.h> |
67 |
|
|
|
68 |
|
|
static void *v2i_crld(const X509V3_EXT_METHOD *method, |
69 |
|
|
X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); |
70 |
|
|
static int i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out, |
71 |
|
|
int indent); |
72 |
|
|
|
73 |
|
|
const X509V3_EXT_METHOD v3_crld = { |
74 |
|
|
.ext_nid = NID_crl_distribution_points, |
75 |
|
|
.ext_flags = 0, |
76 |
|
|
.it = ASN1_ITEM_ref(CRL_DIST_POINTS), |
77 |
|
|
.ext_new = NULL, |
78 |
|
|
.ext_free = NULL, |
79 |
|
|
.d2i = NULL, |
80 |
|
|
.i2d = NULL, |
81 |
|
|
.i2s = NULL, |
82 |
|
|
.s2i = NULL, |
83 |
|
|
.i2v = NULL, |
84 |
|
|
.v2i = v2i_crld, |
85 |
|
|
.i2r = i2r_crldp, |
86 |
|
|
.r2i = NULL, |
87 |
|
|
.usr_data = NULL, |
88 |
|
|
}; |
89 |
|
|
|
90 |
|
|
const X509V3_EXT_METHOD v3_freshest_crl = { |
91 |
|
|
.ext_nid = NID_freshest_crl, |
92 |
|
|
.ext_flags = 0, |
93 |
|
|
.it = ASN1_ITEM_ref(CRL_DIST_POINTS), |
94 |
|
|
.ext_new = NULL, |
95 |
|
|
.ext_free = NULL, |
96 |
|
|
.d2i = NULL, |
97 |
|
|
.i2d = NULL, |
98 |
|
|
.i2s = NULL, |
99 |
|
|
.s2i = NULL, |
100 |
|
|
.i2v = NULL, |
101 |
|
|
.v2i = v2i_crld, |
102 |
|
|
.i2r = i2r_crldp, |
103 |
|
|
.r2i = NULL, |
104 |
|
|
.usr_data = NULL, |
105 |
|
|
}; |
106 |
|
|
|
107 |
|
|
static |
108 |
|
|
STACK_OF(GENERAL_NAME) *gnames_from_sectname(X509V3_CTX *ctx, char *sect) |
109 |
|
|
{ |
110 |
|
|
STACK_OF(CONF_VALUE) *gnsect; |
111 |
|
|
STACK_OF(GENERAL_NAME) *gens; |
112 |
|
|
|
113 |
|
|
if (*sect == '@') |
114 |
|
|
gnsect = X509V3_get_section(ctx, sect + 1); |
115 |
|
|
else |
116 |
|
|
gnsect = X509V3_parse_list(sect); |
117 |
|
|
if (!gnsect) { |
118 |
|
|
X509V3err(X509V3_F_GNAMES_FROM_SECTNAME, |
119 |
|
|
X509V3_R_SECTION_NOT_FOUND); |
120 |
|
|
return NULL; |
121 |
|
|
} |
122 |
|
|
gens = v2i_GENERAL_NAMES(NULL, ctx, gnsect); |
123 |
|
|
if (*sect == '@') |
124 |
|
|
X509V3_section_free(ctx, gnsect); |
125 |
|
|
else |
126 |
|
|
sk_CONF_VALUE_pop_free(gnsect, X509V3_conf_free); |
127 |
|
|
return gens; |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
static int |
131 |
|
|
set_dist_point_name(DIST_POINT_NAME **pdp, X509V3_CTX *ctx, CONF_VALUE *cnf) |
132 |
|
|
{ |
133 |
|
|
STACK_OF(GENERAL_NAME) *fnm = NULL; |
134 |
|
|
STACK_OF(X509_NAME_ENTRY) *rnm = NULL; |
135 |
|
|
|
136 |
|
|
if (!strncmp(cnf->name, "fullname", 9)) { |
137 |
|
|
fnm = gnames_from_sectname(ctx, cnf->value); |
138 |
|
|
if (!fnm) |
139 |
|
|
goto err; |
140 |
|
|
} else if (!strcmp(cnf->name, "relativename")) { |
141 |
|
|
int ret; |
142 |
|
|
STACK_OF(CONF_VALUE) *dnsect; |
143 |
|
|
X509_NAME *nm; |
144 |
|
|
nm = X509_NAME_new(); |
145 |
|
|
if (!nm) |
146 |
|
|
return -1; |
147 |
|
|
dnsect = X509V3_get_section(ctx, cnf->value); |
148 |
|
|
if (!dnsect) { |
149 |
|
|
X509V3err(X509V3_F_SET_DIST_POINT_NAME, |
150 |
|
|
X509V3_R_SECTION_NOT_FOUND); |
151 |
|
|
X509_NAME_free(nm); |
152 |
|
|
return -1; |
153 |
|
|
} |
154 |
|
|
ret = X509V3_NAME_from_section(nm, dnsect, MBSTRING_ASC); |
155 |
|
|
X509V3_section_free(ctx, dnsect); |
156 |
|
|
rnm = nm->entries; |
157 |
|
|
nm->entries = NULL; |
158 |
|
|
X509_NAME_free(nm); |
159 |
|
|
if (!ret || sk_X509_NAME_ENTRY_num(rnm) <= 0) |
160 |
|
|
goto err; |
161 |
|
|
/* Since its a name fragment can't have more than one |
162 |
|
|
* RDNSequence |
163 |
|
|
*/ |
164 |
|
|
if (sk_X509_NAME_ENTRY_value(rnm, |
165 |
|
|
sk_X509_NAME_ENTRY_num(rnm) - 1)->set) { |
166 |
|
|
X509V3err(X509V3_F_SET_DIST_POINT_NAME, |
167 |
|
|
X509V3_R_INVALID_MULTIPLE_RDNS); |
168 |
|
|
goto err; |
169 |
|
|
} |
170 |
|
|
} else |
171 |
|
|
return 0; |
172 |
|
|
|
173 |
|
|
if (*pdp) { |
174 |
|
|
X509V3err(X509V3_F_SET_DIST_POINT_NAME, |
175 |
|
|
X509V3_R_DISTPOINT_ALREADY_SET); |
176 |
|
|
goto err; |
177 |
|
|
} |
178 |
|
|
|
179 |
|
|
*pdp = DIST_POINT_NAME_new(); |
180 |
|
|
if (!*pdp) |
181 |
|
|
goto err; |
182 |
|
|
if (fnm) { |
183 |
|
|
(*pdp)->type = 0; |
184 |
|
|
(*pdp)->name.fullname = fnm; |
185 |
|
|
} else { |
186 |
|
|
(*pdp)->type = 1; |
187 |
|
|
(*pdp)->name.relativename = rnm; |
188 |
|
|
} |
189 |
|
|
|
190 |
|
|
return 1; |
191 |
|
|
|
192 |
|
|
err: |
193 |
|
|
if (fnm) |
194 |
|
|
sk_GENERAL_NAME_pop_free(fnm, GENERAL_NAME_free); |
195 |
|
|
if (rnm) |
196 |
|
|
sk_X509_NAME_ENTRY_pop_free(rnm, X509_NAME_ENTRY_free); |
197 |
|
|
return -1; |
198 |
|
|
} |
199 |
|
|
|
200 |
|
|
static const BIT_STRING_BITNAME reason_flags[] = { |
201 |
|
|
{0, "Unused", "unused"}, |
202 |
|
|
{1, "Key Compromise", "keyCompromise"}, |
203 |
|
|
{2, "CA Compromise", "CACompromise"}, |
204 |
|
|
{3, "Affiliation Changed", "affiliationChanged"}, |
205 |
|
|
{4, "Superseded", "superseded"}, |
206 |
|
|
{5, "Cessation Of Operation", "cessationOfOperation"}, |
207 |
|
|
{6, "Certificate Hold", "certificateHold"}, |
208 |
|
|
{7, "Privilege Withdrawn", "privilegeWithdrawn"}, |
209 |
|
|
{8, "AA Compromise", "AACompromise"}, |
210 |
|
|
{-1, NULL, NULL} |
211 |
|
|
}; |
212 |
|
|
|
213 |
|
|
static int |
214 |
|
|
set_reasons(ASN1_BIT_STRING **preas, char *value) |
215 |
|
|
{ |
216 |
|
|
STACK_OF(CONF_VALUE) *rsk = NULL; |
217 |
|
|
const BIT_STRING_BITNAME *pbn; |
218 |
|
|
const char *bnam; |
219 |
|
|
int i, ret = 0; |
220 |
|
|
|
221 |
|
|
if (*preas != NULL) |
222 |
|
|
return 0; |
223 |
|
|
rsk = X509V3_parse_list(value); |
224 |
|
|
if (rsk == NULL) |
225 |
|
|
return 0; |
226 |
|
|
for (i = 0; i < sk_CONF_VALUE_num(rsk); i++) { |
227 |
|
|
bnam = sk_CONF_VALUE_value(rsk, i)->name; |
228 |
|
|
if (!*preas) { |
229 |
|
|
*preas = ASN1_BIT_STRING_new(); |
230 |
|
|
if (!*preas) |
231 |
|
|
goto err; |
232 |
|
|
} |
233 |
|
|
for (pbn = reason_flags; pbn->lname; pbn++) { |
234 |
|
|
if (!strcmp(pbn->sname, bnam)) { |
235 |
|
|
if (!ASN1_BIT_STRING_set_bit(*preas, |
236 |
|
|
pbn->bitnum, 1)) |
237 |
|
|
goto err; |
238 |
|
|
break; |
239 |
|
|
} |
240 |
|
|
} |
241 |
|
|
if (!pbn->lname) |
242 |
|
|
goto err; |
243 |
|
|
} |
244 |
|
|
ret = 1; |
245 |
|
|
|
246 |
|
|
err: |
247 |
|
|
sk_CONF_VALUE_pop_free(rsk, X509V3_conf_free); |
248 |
|
|
return ret; |
249 |
|
|
} |
250 |
|
|
|
251 |
|
|
static int |
252 |
|
|
print_reasons(BIO *out, const char *rname, ASN1_BIT_STRING *rflags, int indent) |
253 |
|
|
{ |
254 |
|
|
int first = 1; |
255 |
|
|
const BIT_STRING_BITNAME *pbn; |
256 |
|
|
|
257 |
|
|
BIO_printf(out, "%*s%s:\n%*s", indent, "", rname, indent + 2, ""); |
258 |
|
|
for (pbn = reason_flags; pbn->lname; pbn++) { |
259 |
|
|
if (ASN1_BIT_STRING_get_bit(rflags, pbn->bitnum)) { |
260 |
|
|
if (first) |
261 |
|
|
first = 0; |
262 |
|
|
else |
263 |
|
|
BIO_puts(out, ", "); |
264 |
|
|
BIO_puts(out, pbn->lname); |
265 |
|
|
} |
266 |
|
|
} |
267 |
|
|
if (first) |
268 |
|
|
BIO_puts(out, "<EMPTY>\n"); |
269 |
|
|
else |
270 |
|
|
BIO_puts(out, "\n"); |
271 |
|
|
return 1; |
272 |
|
|
} |
273 |
|
|
|
274 |
|
|
static DIST_POINT * |
275 |
|
|
crldp_from_section(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) |
276 |
|
|
{ |
277 |
|
|
int i; |
278 |
|
|
CONF_VALUE *cnf; |
279 |
|
|
DIST_POINT *point = NULL; |
280 |
|
|
|
281 |
|
|
point = DIST_POINT_new(); |
282 |
|
|
if (!point) |
283 |
|
|
goto err; |
284 |
|
|
for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
285 |
|
|
int ret; |
286 |
|
|
cnf = sk_CONF_VALUE_value(nval, i); |
287 |
|
|
ret = set_dist_point_name(&point->distpoint, ctx, cnf); |
288 |
|
|
if (ret > 0) |
289 |
|
|
continue; |
290 |
|
|
if (ret < 0) |
291 |
|
|
goto err; |
292 |
|
|
if (!strcmp(cnf->name, "reasons")) { |
293 |
|
|
if (!set_reasons(&point->reasons, cnf->value)) |
294 |
|
|
goto err; |
295 |
|
|
} |
296 |
|
|
else if (!strcmp(cnf->name, "CRLissuer")) { |
297 |
|
|
point->CRLissuer = |
298 |
|
|
gnames_from_sectname(ctx, cnf->value); |
299 |
|
|
if (!point->CRLissuer) |
300 |
|
|
goto err; |
301 |
|
|
} |
302 |
|
|
} |
303 |
|
|
|
304 |
|
|
return point; |
305 |
|
|
|
306 |
|
|
err: |
307 |
|
|
if (point) |
308 |
|
|
DIST_POINT_free(point); |
309 |
|
|
return NULL; |
310 |
|
|
} |
311 |
|
|
|
312 |
|
|
static void * |
313 |
|
|
v2i_crld(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, |
314 |
|
|
STACK_OF(CONF_VALUE) *nval) |
315 |
|
|
{ |
316 |
|
|
STACK_OF(DIST_POINT) *crld = NULL; |
317 |
|
|
GENERAL_NAMES *gens = NULL; |
318 |
|
|
GENERAL_NAME *gen = NULL; |
319 |
|
|
CONF_VALUE *cnf; |
320 |
|
|
int i; |
321 |
|
|
|
322 |
|
|
if (!(crld = sk_DIST_POINT_new_null())) |
323 |
|
|
goto merr; |
324 |
|
|
for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
325 |
|
|
DIST_POINT *point; |
326 |
|
|
cnf = sk_CONF_VALUE_value(nval, i); |
327 |
|
|
if (!cnf->value) { |
328 |
|
|
STACK_OF(CONF_VALUE) *dpsect; |
329 |
|
|
dpsect = X509V3_get_section(ctx, cnf->name); |
330 |
|
|
if (!dpsect) |
331 |
|
|
goto err; |
332 |
|
|
point = crldp_from_section(ctx, dpsect); |
333 |
|
|
X509V3_section_free(ctx, dpsect); |
334 |
|
|
if (!point) |
335 |
|
|
goto err; |
336 |
|
|
if (!sk_DIST_POINT_push(crld, point)) { |
337 |
|
|
DIST_POINT_free(point); |
338 |
|
|
goto merr; |
339 |
|
|
} |
340 |
|
|
} else { |
341 |
|
|
if (!(gen = v2i_GENERAL_NAME(method, ctx, cnf))) |
342 |
|
|
goto err; |
343 |
|
|
if (!(gens = GENERAL_NAMES_new())) |
344 |
|
|
goto merr; |
345 |
|
|
if (!sk_GENERAL_NAME_push(gens, gen)) |
346 |
|
|
goto merr; |
347 |
|
|
gen = NULL; |
348 |
|
|
if (!(point = DIST_POINT_new())) |
349 |
|
|
goto merr; |
350 |
|
|
if (!sk_DIST_POINT_push(crld, point)) { |
351 |
|
|
DIST_POINT_free(point); |
352 |
|
|
goto merr; |
353 |
|
|
} |
354 |
|
|
if (!(point->distpoint = DIST_POINT_NAME_new())) |
355 |
|
|
goto merr; |
356 |
|
|
point->distpoint->name.fullname = gens; |
357 |
|
|
point->distpoint->type = 0; |
358 |
|
|
gens = NULL; |
359 |
|
|
} |
360 |
|
|
} |
361 |
|
|
return crld; |
362 |
|
|
|
363 |
|
|
merr: |
364 |
|
|
X509V3err(X509V3_F_V2I_CRLD, ERR_R_MALLOC_FAILURE); |
365 |
|
|
err: |
366 |
|
|
GENERAL_NAME_free(gen); |
367 |
|
|
GENERAL_NAMES_free(gens); |
368 |
|
|
sk_DIST_POINT_pop_free(crld, DIST_POINT_free); |
369 |
|
|
return NULL; |
370 |
|
|
} |
371 |
|
|
|
372 |
|
|
static int |
373 |
|
|
dpn_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg) |
374 |
|
20 |
{ |
375 |
|
20 |
DIST_POINT_NAME *dpn = (DIST_POINT_NAME *)*pval; |
376 |
|
|
|
377 |
✓✗✓ |
20 |
switch (operation) { |
378 |
|
|
case ASN1_OP_NEW_POST: |
379 |
|
5 |
dpn->dpname = NULL; |
380 |
|
5 |
break; |
381 |
|
|
|
382 |
|
|
case ASN1_OP_FREE_POST: |
383 |
|
|
if (dpn->dpname) |
384 |
|
|
X509_NAME_free(dpn->dpname); |
385 |
|
|
break; |
386 |
|
|
} |
387 |
|
20 |
return 1; |
388 |
|
|
} |
389 |
|
|
|
390 |
|
|
|
391 |
|
|
static const ASN1_AUX DIST_POINT_NAME_aux = { |
392 |
|
|
.app_data = NULL, |
393 |
|
|
.flags = 0, |
394 |
|
|
.ref_offset = 0, |
395 |
|
|
.ref_lock = 0, |
396 |
|
|
.asn1_cb = dpn_cb, |
397 |
|
|
.enc_offset = 0, |
398 |
|
|
}; |
399 |
|
|
static const ASN1_TEMPLATE DIST_POINT_NAME_ch_tt[] = { |
400 |
|
|
{ |
401 |
|
|
.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SEQUENCE_OF, |
402 |
|
|
.tag = 0, |
403 |
|
|
.offset = offsetof(DIST_POINT_NAME, name.fullname), |
404 |
|
|
.field_name = "name.fullname", |
405 |
|
|
.item = &GENERAL_NAME_it, |
406 |
|
|
}, |
407 |
|
|
{ |
408 |
|
|
.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SET_OF, |
409 |
|
|
.tag = 1, |
410 |
|
|
.offset = offsetof(DIST_POINT_NAME, name.relativename), |
411 |
|
|
.field_name = "name.relativename", |
412 |
|
|
.item = &X509_NAME_ENTRY_it, |
413 |
|
|
}, |
414 |
|
|
}; |
415 |
|
|
|
416 |
|
|
const ASN1_ITEM DIST_POINT_NAME_it = { |
417 |
|
|
.itype = ASN1_ITYPE_CHOICE, |
418 |
|
|
.utype = offsetof(DIST_POINT_NAME, type), |
419 |
|
|
.templates = DIST_POINT_NAME_ch_tt, |
420 |
|
|
.tcount = sizeof(DIST_POINT_NAME_ch_tt) / sizeof(ASN1_TEMPLATE), |
421 |
|
|
.funcs = &DIST_POINT_NAME_aux, |
422 |
|
|
.size = sizeof(DIST_POINT_NAME), |
423 |
|
|
.sname = "DIST_POINT_NAME", |
424 |
|
|
}; |
425 |
|
|
|
426 |
|
|
|
427 |
|
|
|
428 |
|
|
DIST_POINT_NAME * |
429 |
|
|
d2i_DIST_POINT_NAME(DIST_POINT_NAME **a, const unsigned char **in, long len) |
430 |
|
|
{ |
431 |
|
|
return (DIST_POINT_NAME *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, |
432 |
|
|
&DIST_POINT_NAME_it); |
433 |
|
|
} |
434 |
|
|
|
435 |
|
|
int |
436 |
|
|
i2d_DIST_POINT_NAME(DIST_POINT_NAME *a, unsigned char **out) |
437 |
|
|
{ |
438 |
|
|
return ASN1_item_i2d((ASN1_VALUE *)a, out, &DIST_POINT_NAME_it); |
439 |
|
|
} |
440 |
|
|
|
441 |
|
|
DIST_POINT_NAME * |
442 |
|
|
DIST_POINT_NAME_new(void) |
443 |
|
|
{ |
444 |
|
|
return (DIST_POINT_NAME *)ASN1_item_new(&DIST_POINT_NAME_it); |
445 |
|
|
} |
446 |
|
|
|
447 |
|
|
void |
448 |
|
|
DIST_POINT_NAME_free(DIST_POINT_NAME *a) |
449 |
|
|
{ |
450 |
|
|
ASN1_item_free((ASN1_VALUE *)a, &DIST_POINT_NAME_it); |
451 |
|
|
} |
452 |
|
|
|
453 |
|
|
static const ASN1_TEMPLATE DIST_POINT_seq_tt[] = { |
454 |
|
|
{ |
455 |
|
|
.flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL, |
456 |
|
|
.tag = 0, |
457 |
|
|
.offset = offsetof(DIST_POINT, distpoint), |
458 |
|
|
.field_name = "distpoint", |
459 |
|
|
.item = &DIST_POINT_NAME_it, |
460 |
|
|
}, |
461 |
|
|
{ |
462 |
|
|
.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_OPTIONAL, |
463 |
|
|
.tag = 1, |
464 |
|
|
.offset = offsetof(DIST_POINT, reasons), |
465 |
|
|
.field_name = "reasons", |
466 |
|
|
.item = &ASN1_BIT_STRING_it, |
467 |
|
|
}, |
468 |
|
|
{ |
469 |
|
|
.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_OPTIONAL, |
470 |
|
|
.tag = 2, |
471 |
|
|
.offset = offsetof(DIST_POINT, CRLissuer), |
472 |
|
|
.field_name = "CRLissuer", |
473 |
|
|
.item = &GENERAL_NAME_it, |
474 |
|
|
}, |
475 |
|
|
}; |
476 |
|
|
|
477 |
|
|
const ASN1_ITEM DIST_POINT_it = { |
478 |
|
|
.itype = ASN1_ITYPE_SEQUENCE, |
479 |
|
|
.utype = V_ASN1_SEQUENCE, |
480 |
|
|
.templates = DIST_POINT_seq_tt, |
481 |
|
|
.tcount = sizeof(DIST_POINT_seq_tt) / sizeof(ASN1_TEMPLATE), |
482 |
|
|
.funcs = NULL, |
483 |
|
|
.size = sizeof(DIST_POINT), |
484 |
|
|
.sname = "DIST_POINT", |
485 |
|
|
}; |
486 |
|
|
|
487 |
|
|
|
488 |
|
|
DIST_POINT * |
489 |
|
|
d2i_DIST_POINT(DIST_POINT **a, const unsigned char **in, long len) |
490 |
|
|
{ |
491 |
|
|
return (DIST_POINT *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, |
492 |
|
|
&DIST_POINT_it); |
493 |
|
|
} |
494 |
|
|
|
495 |
|
|
int |
496 |
|
|
i2d_DIST_POINT(DIST_POINT *a, unsigned char **out) |
497 |
|
|
{ |
498 |
|
|
return ASN1_item_i2d((ASN1_VALUE *)a, out, &DIST_POINT_it); |
499 |
|
|
} |
500 |
|
|
|
501 |
|
|
DIST_POINT * |
502 |
|
|
DIST_POINT_new(void) |
503 |
|
|
{ |
504 |
|
|
return (DIST_POINT *)ASN1_item_new(&DIST_POINT_it); |
505 |
|
|
} |
506 |
|
|
|
507 |
|
|
void |
508 |
|
|
DIST_POINT_free(DIST_POINT *a) |
509 |
|
|
{ |
510 |
|
|
ASN1_item_free((ASN1_VALUE *)a, &DIST_POINT_it); |
511 |
|
|
} |
512 |
|
|
|
513 |
|
|
static const ASN1_TEMPLATE CRL_DIST_POINTS_item_tt = { |
514 |
|
|
.flags = ASN1_TFLG_SEQUENCE_OF, |
515 |
|
|
.tag = 0, |
516 |
|
|
.offset = 0, |
517 |
|
|
.field_name = "CRLDistributionPoints", |
518 |
|
|
.item = &DIST_POINT_it, |
519 |
|
|
}; |
520 |
|
|
|
521 |
|
|
const ASN1_ITEM CRL_DIST_POINTS_it = { |
522 |
|
|
.itype = ASN1_ITYPE_PRIMITIVE, |
523 |
|
|
.utype = -1, |
524 |
|
|
.templates = &CRL_DIST_POINTS_item_tt, |
525 |
|
|
.tcount = 0, |
526 |
|
|
.funcs = NULL, |
527 |
|
|
.size = 0, |
528 |
|
|
.sname = "CRL_DIST_POINTS", |
529 |
|
|
}; |
530 |
|
|
|
531 |
|
|
|
532 |
|
|
CRL_DIST_POINTS * |
533 |
|
|
d2i_CRL_DIST_POINTS(CRL_DIST_POINTS **a, const unsigned char **in, long len) |
534 |
|
|
{ |
535 |
|
|
return (CRL_DIST_POINTS *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, |
536 |
|
|
&CRL_DIST_POINTS_it); |
537 |
|
|
} |
538 |
|
|
|
539 |
|
|
int |
540 |
|
|
i2d_CRL_DIST_POINTS(CRL_DIST_POINTS *a, unsigned char **out) |
541 |
|
|
{ |
542 |
|
|
return ASN1_item_i2d((ASN1_VALUE *)a, out, &CRL_DIST_POINTS_it); |
543 |
|
|
} |
544 |
|
|
|
545 |
|
|
CRL_DIST_POINTS * |
546 |
|
|
CRL_DIST_POINTS_new(void) |
547 |
|
|
{ |
548 |
|
|
return (CRL_DIST_POINTS *)ASN1_item_new(&CRL_DIST_POINTS_it); |
549 |
|
|
} |
550 |
|
|
|
551 |
|
|
void |
552 |
|
|
CRL_DIST_POINTS_free(CRL_DIST_POINTS *a) |
553 |
|
|
{ |
554 |
|
|
ASN1_item_free((ASN1_VALUE *)a, &CRL_DIST_POINTS_it); |
555 |
|
|
} |
556 |
|
|
|
557 |
|
|
static const ASN1_TEMPLATE ISSUING_DIST_POINT_seq_tt[] = { |
558 |
|
|
{ |
559 |
|
|
.flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL, |
560 |
|
|
.tag = 0, |
561 |
|
|
.offset = offsetof(ISSUING_DIST_POINT, distpoint), |
562 |
|
|
.field_name = "distpoint", |
563 |
|
|
.item = &DIST_POINT_NAME_it, |
564 |
|
|
}, |
565 |
|
|
{ |
566 |
|
|
.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_OPTIONAL, |
567 |
|
|
.tag = 1, |
568 |
|
|
.offset = offsetof(ISSUING_DIST_POINT, onlyuser), |
569 |
|
|
.field_name = "onlyuser", |
570 |
|
|
.item = &ASN1_FBOOLEAN_it, |
571 |
|
|
}, |
572 |
|
|
{ |
573 |
|
|
.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_OPTIONAL, |
574 |
|
|
.tag = 2, |
575 |
|
|
.offset = offsetof(ISSUING_DIST_POINT, onlyCA), |
576 |
|
|
.field_name = "onlyCA", |
577 |
|
|
.item = &ASN1_FBOOLEAN_it, |
578 |
|
|
}, |
579 |
|
|
{ |
580 |
|
|
.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_OPTIONAL, |
581 |
|
|
.tag = 3, |
582 |
|
|
.offset = offsetof(ISSUING_DIST_POINT, onlysomereasons), |
583 |
|
|
.field_name = "onlysomereasons", |
584 |
|
|
.item = &ASN1_BIT_STRING_it, |
585 |
|
|
}, |
586 |
|
|
{ |
587 |
|
|
.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_OPTIONAL, |
588 |
|
|
.tag = 4, |
589 |
|
|
.offset = offsetof(ISSUING_DIST_POINT, indirectCRL), |
590 |
|
|
.field_name = "indirectCRL", |
591 |
|
|
.item = &ASN1_FBOOLEAN_it, |
592 |
|
|
}, |
593 |
|
|
{ |
594 |
|
|
.flags = ASN1_TFLG_IMPLICIT | ASN1_TFLG_OPTIONAL, |
595 |
|
|
.tag = 5, |
596 |
|
|
.offset = offsetof(ISSUING_DIST_POINT, onlyattr), |
597 |
|
|
.field_name = "onlyattr", |
598 |
|
|
.item = &ASN1_FBOOLEAN_it, |
599 |
|
|
}, |
600 |
|
|
}; |
601 |
|
|
|
602 |
|
|
const ASN1_ITEM ISSUING_DIST_POINT_it = { |
603 |
|
|
.itype = ASN1_ITYPE_SEQUENCE, |
604 |
|
|
.utype = V_ASN1_SEQUENCE, |
605 |
|
|
.templates = ISSUING_DIST_POINT_seq_tt, |
606 |
|
|
.tcount = sizeof(ISSUING_DIST_POINT_seq_tt) / sizeof(ASN1_TEMPLATE), |
607 |
|
|
.funcs = NULL, |
608 |
|
|
.size = sizeof(ISSUING_DIST_POINT), |
609 |
|
|
.sname = "ISSUING_DIST_POINT", |
610 |
|
|
}; |
611 |
|
|
|
612 |
|
|
|
613 |
|
|
ISSUING_DIST_POINT * |
614 |
|
|
d2i_ISSUING_DIST_POINT(ISSUING_DIST_POINT **a, const unsigned char **in, long len) |
615 |
|
|
{ |
616 |
|
|
return (ISSUING_DIST_POINT *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, |
617 |
|
|
&ISSUING_DIST_POINT_it); |
618 |
|
|
} |
619 |
|
|
|
620 |
|
|
int |
621 |
|
|
i2d_ISSUING_DIST_POINT(ISSUING_DIST_POINT *a, unsigned char **out) |
622 |
|
|
{ |
623 |
|
|
return ASN1_item_i2d((ASN1_VALUE *)a, out, &ISSUING_DIST_POINT_it); |
624 |
|
|
} |
625 |
|
|
|
626 |
|
|
ISSUING_DIST_POINT * |
627 |
|
|
ISSUING_DIST_POINT_new(void) |
628 |
|
|
{ |
629 |
|
|
return (ISSUING_DIST_POINT *)ASN1_item_new(&ISSUING_DIST_POINT_it); |
630 |
|
|
} |
631 |
|
|
|
632 |
|
|
void |
633 |
|
|
ISSUING_DIST_POINT_free(ISSUING_DIST_POINT *a) |
634 |
|
|
{ |
635 |
|
|
ASN1_item_free((ASN1_VALUE *)a, &ISSUING_DIST_POINT_it); |
636 |
|
|
} |
637 |
|
|
|
638 |
|
|
static int i2r_idp(const X509V3_EXT_METHOD *method, void *pidp, BIO *out, |
639 |
|
|
int indent); |
640 |
|
|
static void *v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, |
641 |
|
|
STACK_OF(CONF_VALUE) *nval); |
642 |
|
|
|
643 |
|
|
const X509V3_EXT_METHOD v3_idp = { |
644 |
|
|
NID_issuing_distribution_point, X509V3_EXT_MULTILINE, |
645 |
|
|
ASN1_ITEM_ref(ISSUING_DIST_POINT), |
646 |
|
|
0, 0, 0, 0, |
647 |
|
|
0, 0, |
648 |
|
|
0, |
649 |
|
|
v2i_idp, |
650 |
|
|
i2r_idp, 0, |
651 |
|
|
NULL |
652 |
|
|
}; |
653 |
|
|
|
654 |
|
|
static void * |
655 |
|
|
v2i_idp(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, |
656 |
|
|
STACK_OF(CONF_VALUE) *nval) |
657 |
|
|
{ |
658 |
|
|
ISSUING_DIST_POINT *idp = NULL; |
659 |
|
|
CONF_VALUE *cnf; |
660 |
|
|
char *name, *val; |
661 |
|
|
int i, ret; |
662 |
|
|
|
663 |
|
|
idp = ISSUING_DIST_POINT_new(); |
664 |
|
|
if (!idp) |
665 |
|
|
goto merr; |
666 |
|
|
for (i = 0; i < sk_CONF_VALUE_num(nval); i++) { |
667 |
|
|
cnf = sk_CONF_VALUE_value(nval, i); |
668 |
|
|
name = cnf->name; |
669 |
|
|
val = cnf->value; |
670 |
|
|
ret = set_dist_point_name(&idp->distpoint, ctx, cnf); |
671 |
|
|
if (ret > 0) |
672 |
|
|
continue; |
673 |
|
|
if (ret < 0) |
674 |
|
|
goto err; |
675 |
|
|
if (!strcmp(name, "onlyuser")) { |
676 |
|
|
if (!X509V3_get_value_bool(cnf, &idp->onlyuser)) |
677 |
|
|
goto err; |
678 |
|
|
} |
679 |
|
|
else if (!strcmp(name, "onlyCA")) { |
680 |
|
|
if (!X509V3_get_value_bool(cnf, &idp->onlyCA)) |
681 |
|
|
goto err; |
682 |
|
|
} |
683 |
|
|
else if (!strcmp(name, "onlyAA")) { |
684 |
|
|
if (!X509V3_get_value_bool(cnf, &idp->onlyattr)) |
685 |
|
|
goto err; |
686 |
|
|
} |
687 |
|
|
else if (!strcmp(name, "indirectCRL")) { |
688 |
|
|
if (!X509V3_get_value_bool(cnf, &idp->indirectCRL)) |
689 |
|
|
goto err; |
690 |
|
|
} |
691 |
|
|
else if (!strcmp(name, "onlysomereasons")) { |
692 |
|
|
if (!set_reasons(&idp->onlysomereasons, val)) |
693 |
|
|
goto err; |
694 |
|
|
} else { |
695 |
|
|
X509V3err(X509V3_F_V2I_IDP, X509V3_R_INVALID_NAME); |
696 |
|
|
X509V3_conf_err(cnf); |
697 |
|
|
goto err; |
698 |
|
|
} |
699 |
|
|
} |
700 |
|
|
return idp; |
701 |
|
|
|
702 |
|
|
merr: |
703 |
|
|
X509V3err(X509V3_F_V2I_IDP, ERR_R_MALLOC_FAILURE); |
704 |
|
|
err: |
705 |
|
|
ISSUING_DIST_POINT_free(idp); |
706 |
|
|
return NULL; |
707 |
|
|
} |
708 |
|
|
|
709 |
|
|
static int |
710 |
|
|
print_gens(BIO *out, STACK_OF(GENERAL_NAME) *gens, int indent) |
711 |
|
|
{ |
712 |
|
|
int i; |
713 |
|
|
|
714 |
|
|
for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) { |
715 |
|
|
BIO_printf(out, "%*s", indent + 2, ""); |
716 |
|
|
GENERAL_NAME_print(out, sk_GENERAL_NAME_value(gens, i)); |
717 |
|
|
BIO_puts(out, "\n"); |
718 |
|
|
} |
719 |
|
|
return 1; |
720 |
|
|
} |
721 |
|
|
|
722 |
|
|
static int |
723 |
|
|
print_distpoint(BIO *out, DIST_POINT_NAME *dpn, int indent) |
724 |
|
|
{ |
725 |
|
|
if (dpn->type == 0) { |
726 |
|
|
BIO_printf(out, "%*sFull Name:\n", indent, ""); |
727 |
|
|
print_gens(out, dpn->name.fullname, indent); |
728 |
|
|
} else { |
729 |
|
|
X509_NAME ntmp; |
730 |
|
|
ntmp.entries = dpn->name.relativename; |
731 |
|
|
BIO_printf(out, "%*sRelative Name:\n%*s", |
732 |
|
|
indent, "", indent + 2, ""); |
733 |
|
|
X509_NAME_print_ex(out, &ntmp, 0, XN_FLAG_ONELINE); |
734 |
|
|
BIO_puts(out, "\n"); |
735 |
|
|
} |
736 |
|
|
return 1; |
737 |
|
|
} |
738 |
|
|
|
739 |
|
|
static int |
740 |
|
|
i2r_idp(const X509V3_EXT_METHOD *method, void *pidp, BIO *out, int indent) |
741 |
|
|
{ |
742 |
|
|
ISSUING_DIST_POINT *idp = pidp; |
743 |
|
|
|
744 |
|
|
if (idp->distpoint) |
745 |
|
|
print_distpoint(out, idp->distpoint, indent); |
746 |
|
|
if (idp->onlyuser > 0) |
747 |
|
|
BIO_printf(out, "%*sOnly User Certificates\n", indent, ""); |
748 |
|
|
if (idp->onlyCA > 0) |
749 |
|
|
BIO_printf(out, "%*sOnly CA Certificates\n", indent, ""); |
750 |
|
|
if (idp->indirectCRL > 0) |
751 |
|
|
BIO_printf(out, "%*sIndirect CRL\n", indent, ""); |
752 |
|
|
if (idp->onlysomereasons) |
753 |
|
|
print_reasons(out, "Only Some Reasons", |
754 |
|
|
idp->onlysomereasons, indent); |
755 |
|
|
if (idp->onlyattr > 0) |
756 |
|
|
BIO_printf(out, "%*sOnly Attribute Certificates\n", indent, ""); |
757 |
|
|
if (!idp->distpoint && (idp->onlyuser <= 0) && (idp->onlyCA <= 0) && |
758 |
|
|
(idp->indirectCRL <= 0) && !idp->onlysomereasons && |
759 |
|
|
(idp->onlyattr <= 0)) |
760 |
|
|
BIO_printf(out, "%*s<EMPTY>\n", indent, ""); |
761 |
|
|
|
762 |
|
|
return 1; |
763 |
|
|
} |
764 |
|
|
|
765 |
|
|
static int |
766 |
|
|
i2r_crldp(const X509V3_EXT_METHOD *method, void *pcrldp, BIO *out, int indent) |
767 |
|
|
{ |
768 |
|
|
STACK_OF(DIST_POINT) *crld = pcrldp; |
769 |
|
|
DIST_POINT *point; |
770 |
|
|
int i; |
771 |
|
|
|
772 |
|
|
for (i = 0; i < sk_DIST_POINT_num(crld); i++) { |
773 |
|
|
BIO_puts(out, "\n"); |
774 |
|
|
point = sk_DIST_POINT_value(crld, i); |
775 |
|
|
if (point->distpoint) |
776 |
|
|
print_distpoint(out, point->distpoint, indent); |
777 |
|
|
if (point->reasons) |
778 |
|
|
print_reasons(out, "Reasons", point->reasons, |
779 |
|
|
indent); |
780 |
|
|
if (point->CRLissuer) { |
781 |
|
|
BIO_printf(out, "%*sCRL Issuer:\n", indent, ""); |
782 |
|
|
print_gens(out, point->CRLissuer, indent); |
783 |
|
|
} |
784 |
|
|
} |
785 |
|
|
return 1; |
786 |
|
|
} |
787 |
|
|
|
788 |
|
|
int |
789 |
|
|
DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname) |
790 |
|
|
{ |
791 |
|
|
int i; |
792 |
|
|
STACK_OF(X509_NAME_ENTRY) *frag; |
793 |
|
|
X509_NAME_ENTRY *ne; |
794 |
|
|
|
795 |
|
|
if (!dpn || (dpn->type != 1)) |
796 |
|
|
return 1; |
797 |
|
|
frag = dpn->name.relativename; |
798 |
|
|
dpn->dpname = X509_NAME_dup(iname); |
799 |
|
|
if (!dpn->dpname) |
800 |
|
|
return 0; |
801 |
|
|
for (i = 0; i < sk_X509_NAME_ENTRY_num(frag); i++) { |
802 |
|
|
ne = sk_X509_NAME_ENTRY_value(frag, i); |
803 |
|
|
if (!X509_NAME_add_entry(dpn->dpname, ne, -1, i ? 0 : 1)) { |
804 |
|
|
X509_NAME_free(dpn->dpname); |
805 |
|
|
dpn->dpname = NULL; |
806 |
|
|
return 0; |
807 |
|
|
} |
808 |
|
|
} |
809 |
|
|
/* generate cached encoding of name */ |
810 |
|
|
if (i2d_X509_NAME(dpn->dpname, NULL) < 0) { |
811 |
|
|
X509_NAME_free(dpn->dpname); |
812 |
|
|
dpn->dpname = NULL; |
813 |
|
|
return 0; |
814 |
|
|
} |
815 |
|
|
return 1; |
816 |
|
|
} |