2 /* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
5 /* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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/)"
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.
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.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
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 * ====================================================================
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).
66 static STACK
*i2v_crld(X509V3_EXT_METHOD
*method
, STACK_OF(DIST_POINT
) *crld
,
68 static STACK_OF(DIST_POINT
) *v2i_crld(X509V3_EXT_METHOD
*method
,
69 X509V3_CTX
*ctx
, STACK
*nval
);
71 X509V3_EXT_METHOD v3_crld
= {
72 NID_crl_distribution_points
, X509V3_EXT_MULTILINE
,
73 (X509V3_EXT_NEW
)CRL_DIST_POINTS_new
,
75 (X509V3_EXT_D2I
)d2i_CRL_DIST_POINTS
,
78 (X509V3_EXT_I2V
)i2v_crld
,
79 (X509V3_EXT_V2I
)v2i_crld
,
84 * ASN1err(ASN1_F_DIST_POINT_NEW,ERR_R_MALLOC_FAILURE);
85 * ASN1err(ASN1_F_D2I_DIST_POINT,ERR_R_MALLOC_FAILURE);
86 * ASN1err(ASN1_F_DIST_POINT_NAME_NEW,ERR_R_MALLOC_FAILURE);
87 * ASN1err(ASN1_F_D2I_DIST_POINT_NAME,ERR_R_MALLOC_FAILURE);
90 static STACK
*i2v_crld(X509V3_EXT_METHOD
*method
, STACK_OF(DIST_POINT
) *crld
,
95 for(i
= 0; i
< sk_DIST_POINT_num(crld
); i
++) {
96 point
= sk_DIST_POINT_value(crld
, i
);
97 if(point
->distpoint
->fullname
) {
98 exts
= i2v_GENERAL_NAMES(NULL
,
99 point
->distpoint
->fullname
, exts
);
102 X509V3_add_value("reasons","<UNSUPPORTED>", &exts
);
104 X509V3_add_value("CRLissuer","<UNSUPPORTED>", &exts
);
105 if(point
->distpoint
->relativename
)
106 X509V3_add_value("RelativeName","<UNSUPPORTED>", &exts
);
111 static STACK_OF(DIST_POINT
) *v2i_crld(X509V3_EXT_METHOD
*method
,
112 X509V3_CTX
*ctx
, STACK
*nval
)
114 STACK_OF(DIST_POINT
) *crld
= NULL
;
115 STACK_OF(GENERAL_NAME
) *gens
= NULL
;
116 GENERAL_NAME
*gen
= NULL
;
119 if(!(crld
= sk_DIST_POINT_new(NULL
))) goto merr
;
120 for(i
= 0; i
< sk_num(nval
); i
++) {
122 cnf
= (CONF_VALUE
*)sk_value(nval
, i
);
123 if(!(gen
= v2i_GENERAL_NAME(method
, ctx
, cnf
))) goto err
;
124 if(!(gens
= GENERAL_NAMES_new())) goto merr
;
125 if(!sk_GENERAL_NAME_push(gens
, gen
)) goto merr
;
127 if(!(point
= DIST_POINT_new())) goto merr
;
128 if(!sk_DIST_POINT_push(crld
, point
)) {
129 DIST_POINT_free(point
);
132 if(!(point
->distpoint
= DIST_POINT_NAME_new())) goto merr
;
133 point
->distpoint
->fullname
= gens
;
139 X509V3err(X509V3_F_V2I_CRLD
,ERR_R_MALLOC_FAILURE
);
141 GENERAL_NAME_free(gen
);
142 GENERAL_NAMES_free(gens
);
143 sk_DIST_POINT_pop_free(crld
, DIST_POINT_free
);
147 int i2d_CRL_DIST_POINTS(STACK_OF(DIST_POINT
) *a
, unsigned char **pp
)
150 return i2d_ASN1_SET_OF_DIST_POINT(a
, pp
, i2d_DIST_POINT
, V_ASN1_SEQUENCE
,
151 V_ASN1_UNIVERSAL
, IS_SEQUENCE
);}
153 STACK_OF(DIST_POINT
) *CRL_DIST_POINTS_new(void)
155 return sk_DIST_POINT_new_null();
158 void CRL_DIST_POINTS_free(STACK_OF(DIST_POINT
) *a
)
160 sk_DIST_POINT_pop_free(a
, DIST_POINT_free
);
163 STACK_OF(DIST_POINT
) *d2i_CRL_DIST_POINTS(STACK_OF(DIST_POINT
) **a
,
164 unsigned char **pp
,long length
)
166 return d2i_ASN1_SET_OF_DIST_POINT(a
, pp
, length
, d2i_DIST_POINT
,
167 DIST_POINT_free
, V_ASN1_SEQUENCE
, V_ASN1_UNIVERSAL
);
171 IMPLEMENT_STACK_OF(DIST_POINT
)
172 IMPLEMENT_ASN1_SET_OF(DIST_POINT
)
174 int i2d_DIST_POINT(DIST_POINT
*a
, unsigned char **pp
)
178 /* NB: underlying type is a CHOICE so need EXPLICIT tagging */
179 M_ASN1_I2D_len_EXP_opt (a
->distpoint
, i2d_DIST_POINT_NAME
, 0, v
);
180 M_ASN1_I2D_len_IMP_opt (a
->reasons
, i2d_ASN1_BIT_STRING
);
181 M_ASN1_I2D_len_IMP_opt (a
->CRLissuer
, i2d_GENERAL_NAMES
);
183 M_ASN1_I2D_seq_total();
185 M_ASN1_I2D_put_EXP_opt (a
->distpoint
, i2d_DIST_POINT_NAME
, 0, v
);
186 M_ASN1_I2D_put_IMP_opt (a
->reasons
, i2d_ASN1_BIT_STRING
, 1);
187 M_ASN1_I2D_put_IMP_opt (a
->CRLissuer
, i2d_GENERAL_NAMES
, 2);
192 DIST_POINT
*DIST_POINT_new(void)
194 DIST_POINT
*ret
=NULL
;
196 M_ASN1_New_Malloc(ret
, DIST_POINT
);
197 ret
->distpoint
= NULL
;
199 ret
->CRLissuer
= NULL
;
201 M_ASN1_New_Error(ASN1_F_DIST_POINT_NEW
);
204 DIST_POINT
*d2i_DIST_POINT(DIST_POINT
**a
, unsigned char **pp
, long length
)
206 M_ASN1_D2I_vars(a
,DIST_POINT
*,DIST_POINT_new
);
208 M_ASN1_D2I_start_sequence();
209 M_ASN1_D2I_get_EXP_opt (ret
->distpoint
, d2i_DIST_POINT_NAME
, 0);
210 M_ASN1_D2I_get_IMP_opt (ret
->reasons
, d2i_ASN1_BIT_STRING
, 1,
212 M_ASN1_D2I_get_IMP_opt (ret
->CRLissuer
, d2i_GENERAL_NAMES
, 2,
214 M_ASN1_D2I_Finish(a
, DIST_POINT_free
, ASN1_F_D2I_DIST_POINT
);
217 void DIST_POINT_free(DIST_POINT
*a
)
219 if (a
== NULL
) return;
220 DIST_POINT_NAME_free(a
->distpoint
);
221 ASN1_BIT_STRING_free(a
->reasons
);
222 sk_GENERAL_NAME_pop_free(a
->CRLissuer
, GENERAL_NAME_free
);
226 int i2d_DIST_POINT_NAME(DIST_POINT_NAME
*a
, unsigned char **pp
)
232 M_ASN1_I2D_len_IMP_opt (a
->fullname
, i2d_GENERAL_NAMES
);
234 M_ASN1_I2D_len_EXP_opt (a
->relativename
, i2d_X509_NAME
, 1, v
);
237 /* Don't want a SEQUENCE so... */
238 if(pp
== NULL
) return ret
;
242 M_ASN1_I2D_put_IMP_opt (a
->fullname
, i2d_GENERAL_NAMES
, 0);
244 M_ASN1_I2D_put_EXP_opt (a
->relativename
, i2d_X509_NAME
, 1, v
);
249 DIST_POINT_NAME
*DIST_POINT_NAME_new(void)
251 DIST_POINT_NAME
*ret
=NULL
;
253 M_ASN1_New_Malloc(ret
, DIST_POINT_NAME
);
254 ret
->fullname
= NULL
;
255 ret
->relativename
= NULL
;
257 M_ASN1_New_Error(ASN1_F_DIST_POINT_NAME_NEW
);
260 void DIST_POINT_NAME_free(DIST_POINT_NAME
*a
)
262 if (a
== NULL
) return;
263 X509_NAME_free(a
->relativename
);
264 sk_GENERAL_NAME_pop_free(a
->fullname
, GENERAL_NAME_free
);
268 DIST_POINT_NAME
*d2i_DIST_POINT_NAME(DIST_POINT_NAME
**a
, unsigned char **pp
,
271 unsigned char _tmp
, tag
;
272 M_ASN1_D2I_vars(a
,DIST_POINT_NAME
*,DIST_POINT_NAME_new
);
277 tag
= _tmp
& ~V_ASN1_CONSTRUCTED
;
279 if(tag
== (0|V_ASN1_CONTEXT_SPECIFIC
)) {
280 M_ASN1_D2I_get_imp(ret
->fullname
, d2i_GENERAL_NAMES
,
282 } else if (tag
== (1|V_ASN1_CONTEXT_SPECIFIC
)) {
283 M_ASN1_D2I_get_EXP_opt (ret
->relativename
, d2i_X509_NAME
, 1);
285 c
.error
= ASN1_R_BAD_TAG
;
289 M_ASN1_D2I_Finish(a
, DIST_POINT_NAME_free
, ASN1_F_D2I_DIST_POINT_NAME
);