diff options
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_gen.c')
-rw-r--r-- | src/lib/libcrypto/asn1/asn1_gen.c | 242 |
1 files changed, 121 insertions, 121 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_gen.c b/src/lib/libcrypto/asn1/asn1_gen.c index 8194beeb30..f78aac7148 100644 --- a/src/lib/libcrypto/asn1/asn1_gen.c +++ b/src/lib/libcrypto/asn1/asn1_gen.c | |||
@@ -70,7 +70,7 @@ | |||
70 | #define ASN1_GEN_FLAG_SETWRAP (ASN1_GEN_FLAG|7) | 70 | #define ASN1_GEN_FLAG_SETWRAP (ASN1_GEN_FLAG|7) |
71 | #define ASN1_GEN_FLAG_FORMAT (ASN1_GEN_FLAG|8) | 71 | #define ASN1_GEN_FLAG_FORMAT (ASN1_GEN_FLAG|8) |
72 | 72 | ||
73 | #define ASN1_GEN_STR(str,val) {str, sizeof(str) - 1, val} | 73 | #define ASN1_GEN_STR(str,val){str, sizeof(str) - 1, val} |
74 | 74 | ||
75 | #define ASN1_FLAG_EXP_MAX 20 | 75 | #define ASN1_FLAG_EXP_MAX 20 |
76 | 76 | ||
@@ -87,23 +87,23 @@ | |||
87 | 87 | ||
88 | 88 | ||
89 | struct tag_name_st | 89 | struct tag_name_st |
90 | { | 90 | { |
91 | const char *strnam; | 91 | const char *strnam; |
92 | int len; | 92 | int len; |
93 | int tag; | 93 | int tag; |
94 | }; | 94 | }; |
95 | 95 | ||
96 | typedef struct | 96 | typedef struct |
97 | { | 97 | { |
98 | int exp_tag; | 98 | int exp_tag; |
99 | int exp_class; | 99 | int exp_class; |
100 | int exp_constructed; | 100 | int exp_constructed; |
101 | int exp_pad; | 101 | int exp_pad; |
102 | long exp_len; | 102 | long exp_len; |
103 | } tag_exp_type; | 103 | } tag_exp_type; |
104 | 104 | ||
105 | typedef struct | 105 | typedef struct |
106 | { | 106 | { |
107 | int imp_tag; | 107 | int imp_tag; |
108 | int imp_class; | 108 | int imp_class; |
109 | int utype; | 109 | int utype; |
@@ -111,7 +111,7 @@ typedef struct | |||
111 | const char *str; | 111 | const char *str; |
112 | tag_exp_type exp_list[ASN1_FLAG_EXP_MAX]; | 112 | tag_exp_type exp_list[ASN1_FLAG_EXP_MAX]; |
113 | int exp_count; | 113 | int exp_count; |
114 | } tag_exp_arg; | 114 | } tag_exp_arg; |
115 | 115 | ||
116 | static int bitstr_cb(const char *elem, int len, void *bitstr); | 116 | static int bitstr_cb(const char *elem, int len, void *bitstr); |
117 | static int asn1_cb(const char *elem, int len, void *bitstr); | 117 | static int asn1_cb(const char *elem, int len, void *bitstr); |
@@ -122,7 +122,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype); | |||
122 | static int asn1_str2tag(const char *tagstr, int len); | 122 | static int asn1_str2tag(const char *tagstr, int len); |
123 | 123 | ||
124 | ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) | 124 | ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) |
125 | { | 125 | { |
126 | X509V3_CTX cnf; | 126 | X509V3_CTX cnf; |
127 | 127 | ||
128 | if (!nconf) | 128 | if (!nconf) |
@@ -130,10 +130,10 @@ ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf) | |||
130 | 130 | ||
131 | X509V3_set_nconf(&cnf, nconf); | 131 | X509V3_set_nconf(&cnf, nconf); |
132 | return ASN1_generate_v3(str, &cnf); | 132 | return ASN1_generate_v3(str, &cnf); |
133 | } | 133 | } |
134 | 134 | ||
135 | ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | 135 | ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) |
136 | { | 136 | { |
137 | ASN1_TYPE *ret; | 137 | ASN1_TYPE *ret; |
138 | tag_exp_arg asn1_tags; | 138 | tag_exp_arg asn1_tags; |
139 | tag_exp_type *etmp; | 139 | tag_exp_type *etmp; |
@@ -157,14 +157,14 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
157 | return NULL; | 157 | return NULL; |
158 | 158 | ||
159 | if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) | 159 | if ((asn1_tags.utype == V_ASN1_SEQUENCE) || (asn1_tags.utype == V_ASN1_SET)) |
160 | { | 160 | { |
161 | if (!cnf) | 161 | if (!cnf) |
162 | { | 162 | { |
163 | ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); | 163 | ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); |
164 | return NULL; | 164 | return NULL; |
165 | } | ||
166 | ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf); | ||
167 | } | 165 | } |
166 | ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf); | ||
167 | } | ||
168 | else | 168 | else |
169 | ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype); | 169 | ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype); |
170 | 170 | ||
@@ -184,7 +184,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
184 | 184 | ||
185 | /* Do we need IMPLICIT tagging? */ | 185 | /* Do we need IMPLICIT tagging? */ |
186 | if (asn1_tags.imp_tag != -1) | 186 | if (asn1_tags.imp_tag != -1) |
187 | { | 187 | { |
188 | /* If IMPLICIT we will replace the underlying tag */ | 188 | /* If IMPLICIT we will replace the underlying tag */ |
189 | /* Skip existing tag+len */ | 189 | /* Skip existing tag+len */ |
190 | r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len); | 190 | r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len); |
@@ -197,11 +197,11 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
197 | * consistent. | 197 | * consistent. |
198 | */ | 198 | */ |
199 | if (r & 0x1) | 199 | if (r & 0x1) |
200 | { | 200 | { |
201 | /* Indefinite length constructed */ | 201 | /* Indefinite length constructed */ |
202 | hdr_constructed = 2; | 202 | hdr_constructed = 2; |
203 | hdr_len = 0; | 203 | hdr_len = 0; |
204 | } | 204 | } |
205 | else | 205 | else |
206 | /* Just retain constructed flag */ | 206 | /* Just retain constructed flag */ |
207 | hdr_constructed = r & V_ASN1_CONSTRUCTED; | 207 | hdr_constructed = r & V_ASN1_CONSTRUCTED; |
@@ -209,20 +209,20 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
209 | * because it will mess up if indefinite length | 209 | * because it will mess up if indefinite length |
210 | */ | 210 | */ |
211 | len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag); | 211 | len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag); |
212 | } | 212 | } |
213 | else | 213 | else |
214 | len = cpy_len; | 214 | len = cpy_len; |
215 | 215 | ||
216 | /* Work out length in any EXPLICIT, starting from end */ | 216 | /* Work out length in any EXPLICIT, starting from end */ |
217 | 217 | ||
218 | for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) | 218 | for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) |
219 | { | 219 | { |
220 | /* Content length: number of content octets + any padding */ | 220 | /* Content length: number of content octets + any padding */ |
221 | len += etmp->exp_pad; | 221 | len += etmp->exp_pad; |
222 | etmp->exp_len = len; | 222 | etmp->exp_len = len; |
223 | /* Total object length: length including new header */ | 223 | /* Total object length: length including new header */ |
224 | len = ASN1_object_size(0, len, etmp->exp_tag); | 224 | len = ASN1_object_size(0, len, etmp->exp_tag); |
225 | } | 225 | } |
226 | 226 | ||
227 | /* Allocate buffer for new encoding */ | 227 | /* Allocate buffer for new encoding */ |
228 | 228 | ||
@@ -237,24 +237,24 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
237 | /* Output explicit tags first */ | 237 | /* Output explicit tags first */ |
238 | 238 | ||
239 | for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) | 239 | for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) |
240 | { | 240 | { |
241 | ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, | 241 | ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, |
242 | etmp->exp_tag, etmp->exp_class); | 242 | etmp->exp_tag, etmp->exp_class); |
243 | if (etmp->exp_pad) | 243 | if (etmp->exp_pad) |
244 | *p++ = 0; | 244 | *p++ = 0; |
245 | } | 245 | } |
246 | 246 | ||
247 | /* If IMPLICIT, output tag */ | 247 | /* If IMPLICIT, output tag */ |
248 | 248 | ||
249 | if (asn1_tags.imp_tag != -1) | 249 | if (asn1_tags.imp_tag != -1) |
250 | { | 250 | { |
251 | if (asn1_tags.imp_class == V_ASN1_UNIVERSAL | 251 | if (asn1_tags.imp_class == V_ASN1_UNIVERSAL |
252 | && (asn1_tags.imp_tag == V_ASN1_SEQUENCE | 252 | && (asn1_tags.imp_tag == V_ASN1_SEQUENCE |
253 | || asn1_tags.imp_tag == V_ASN1_SET) ) | 253 | || asn1_tags.imp_tag == V_ASN1_SET) ) |
254 | hdr_constructed = V_ASN1_CONSTRUCTED; | 254 | hdr_constructed = V_ASN1_CONSTRUCTED; |
255 | ASN1_put_object(&p, hdr_constructed, hdr_len, | 255 | ASN1_put_object(&p, hdr_constructed, hdr_len, |
256 | asn1_tags.imp_tag, asn1_tags.imp_class); | 256 | asn1_tags.imp_tag, asn1_tags.imp_class); |
257 | } | 257 | } |
258 | 258 | ||
259 | /* Copy across original encoding */ | 259 | /* Copy across original encoding */ |
260 | memcpy(p, cpy_start, cpy_len); | 260 | memcpy(p, cpy_start, cpy_len); |
@@ -272,10 +272,10 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) | |||
272 | 272 | ||
273 | return ret; | 273 | return ret; |
274 | 274 | ||
275 | } | 275 | } |
276 | 276 | ||
277 | static int asn1_cb(const char *elem, int len, void *bitstr) | 277 | static int asn1_cb(const char *elem, int len, void *bitstr) |
278 | { | 278 | { |
279 | tag_exp_arg *arg = bitstr; | 279 | tag_exp_arg *arg = bitstr; |
280 | int i; | 280 | int i; |
281 | int utype; | 281 | int utype; |
@@ -285,50 +285,50 @@ static int asn1_cb(const char *elem, int len, void *bitstr) | |||
285 | int tmp_tag, tmp_class; | 285 | int tmp_tag, tmp_class; |
286 | 286 | ||
287 | for(i = 0, p = elem; i < len; p++, i++) | 287 | for(i = 0, p = elem; i < len; p++, i++) |
288 | { | 288 | { |
289 | /* Look for the ':' in name value pairs */ | 289 | /* Look for the ':' in name value pairs */ |
290 | if (*p == ':') | 290 | if (*p == ':') |
291 | { | 291 | { |
292 | vstart = p + 1; | 292 | vstart = p + 1; |
293 | vlen = len - (vstart - elem); | 293 | vlen = len - (vstart - elem); |
294 | len = p - elem; | 294 | len = p - elem; |
295 | break; | 295 | break; |
296 | } | ||
297 | } | 296 | } |
297 | } | ||
298 | 298 | ||
299 | utype = asn1_str2tag(elem, len); | 299 | utype = asn1_str2tag(elem, len); |
300 | 300 | ||
301 | if (utype == -1) | 301 | if (utype == -1) |
302 | { | 302 | { |
303 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG); | 303 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG); |
304 | ERR_add_error_data(2, "tag=", elem); | 304 | ERR_add_error_data(2, "tag=", elem); |
305 | return -1; | 305 | return -1; |
306 | } | 306 | } |
307 | 307 | ||
308 | /* If this is not a modifier mark end of string and exit */ | 308 | /* If this is not a modifier mark end of string and exit */ |
309 | if (!(utype & ASN1_GEN_FLAG)) | 309 | if (!(utype & ASN1_GEN_FLAG)) |
310 | { | 310 | { |
311 | arg->utype = utype; | 311 | arg->utype = utype; |
312 | arg->str = vstart; | 312 | arg->str = vstart; |
313 | /* If no value and not end of string, error */ | 313 | /* If no value and not end of string, error */ |
314 | if (!vstart && elem[len]) | 314 | if (!vstart && elem[len]) |
315 | { | 315 | { |
316 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE); | 316 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE); |
317 | return -1; | 317 | return -1; |
318 | } | ||
319 | return 0; | ||
320 | } | 318 | } |
319 | return 0; | ||
320 | } | ||
321 | 321 | ||
322 | switch(utype) | 322 | switch(utype) |
323 | { | 323 | { |
324 | 324 | ||
325 | case ASN1_GEN_FLAG_IMP: | 325 | case ASN1_GEN_FLAG_IMP: |
326 | /* Check for illegal multiple IMPLICIT tagging */ | 326 | /* Check for illegal multiple IMPLICIT tagging */ |
327 | if (arg->imp_tag != -1) | 327 | if (arg->imp_tag != -1) |
328 | { | 328 | { |
329 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); | 329 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); |
330 | return -1; | 330 | return -1; |
331 | } | 331 | } |
332 | if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class)) | 332 | if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class)) |
333 | return -1; | 333 | return -1; |
334 | break; | 334 | break; |
@@ -371,20 +371,20 @@ static int asn1_cb(const char *elem, int len, void *bitstr) | |||
371 | else if (!strncmp(vstart, "BITLIST", 7)) | 371 | else if (!strncmp(vstart, "BITLIST", 7)) |
372 | arg->format = ASN1_GEN_FORMAT_BITLIST; | 372 | arg->format = ASN1_GEN_FORMAT_BITLIST; |
373 | else | 373 | else |
374 | { | 374 | { |
375 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT); | 375 | ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT); |
376 | return -1; | 376 | return -1; |
377 | } | 377 | } |
378 | break; | 378 | break; |
379 | 379 | ||
380 | } | 380 | } |
381 | 381 | ||
382 | return 1; | 382 | return 1; |
383 | 383 | ||
384 | } | 384 | } |
385 | 385 | ||
386 | static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | 386 | static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) |
387 | { | 387 | { |
388 | char erch[2]; | 388 | char erch[2]; |
389 | long tag_num; | 389 | long tag_num; |
390 | char *eptr; | 390 | char *eptr; |
@@ -395,10 +395,10 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
395 | if (eptr && *eptr && (eptr > vstart + vlen)) | 395 | if (eptr && *eptr && (eptr > vstart + vlen)) |
396 | return 0; | 396 | return 0; |
397 | if (tag_num < 0) | 397 | if (tag_num < 0) |
398 | { | 398 | { |
399 | ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER); | 399 | ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER); |
400 | return 0; | 400 | return 0; |
401 | } | 401 | } |
402 | *ptag = tag_num; | 402 | *ptag = tag_num; |
403 | /* If we have non numeric characters, parse them */ | 403 | /* If we have non numeric characters, parse them */ |
404 | if (eptr) | 404 | if (eptr) |
@@ -406,9 +406,9 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
406 | else | 406 | else |
407 | vlen = 0; | 407 | vlen = 0; |
408 | if (vlen) | 408 | if (vlen) |
409 | { | 409 | { |
410 | switch (*eptr) | 410 | switch (*eptr) |
411 | { | 411 | { |
412 | 412 | ||
413 | case 'U': | 413 | case 'U': |
414 | *pclass = V_ASN1_UNIVERSAL; | 414 | *pclass = V_ASN1_UNIVERSAL; |
@@ -434,19 +434,19 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass) | |||
434 | return 0; | 434 | return 0; |
435 | break; | 435 | break; |
436 | 436 | ||
437 | } | ||
438 | } | 437 | } |
438 | } | ||
439 | else | 439 | else |
440 | *pclass = V_ASN1_CONTEXT_SPECIFIC; | 440 | *pclass = V_ASN1_CONTEXT_SPECIFIC; |
441 | 441 | ||
442 | return 1; | 442 | return 1; |
443 | 443 | ||
444 | } | 444 | } |
445 | 445 | ||
446 | /* Handle multiple types: SET and SEQUENCE */ | 446 | /* Handle multiple types: SET and SEQUENCE */ |
447 | 447 | ||
448 | static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | 448 | static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) |
449 | { | 449 | { |
450 | ASN1_TYPE *ret = NULL; | 450 | ASN1_TYPE *ret = NULL; |
451 | STACK_OF(ASN1_TYPE) *sk = NULL; | 451 | STACK_OF(ASN1_TYPE) *sk = NULL; |
452 | STACK_OF(CONF_VALUE) *sect = NULL; | 452 | STACK_OF(CONF_VALUE) *sect = NULL; |
@@ -457,21 +457,21 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | |||
457 | if (!sk) | 457 | if (!sk) |
458 | goto bad; | 458 | goto bad; |
459 | if (section) | 459 | if (section) |
460 | { | 460 | { |
461 | if (!cnf) | 461 | if (!cnf) |
462 | goto bad; | 462 | goto bad; |
463 | sect = X509V3_get_section(cnf, (char *)section); | 463 | sect = X509V3_get_section(cnf, (char *)section); |
464 | if (!sect) | 464 | if (!sect) |
465 | goto bad; | 465 | goto bad; |
466 | for (i = 0; i < sk_CONF_VALUE_num(sect); i++) | 466 | for (i = 0; i < sk_CONF_VALUE_num(sect); i++) |
467 | { | 467 | { |
468 | ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf); | 468 | ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf); |
469 | if (!typ) | 469 | if (!typ) |
470 | goto bad; | 470 | goto bad; |
471 | if (!sk_ASN1_TYPE_push(sk, typ)) | 471 | if (!sk_ASN1_TYPE_push(sk, typ)) |
472 | goto bad; | 472 | goto bad; |
473 | } | ||
474 | } | 473 | } |
474 | } | ||
475 | 475 | ||
476 | /* Now we has a STACK of the components, convert to the correct form */ | 476 | /* Now we has a STACK of the components, convert to the correct form */ |
477 | 477 | ||
@@ -507,23 +507,23 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) | |||
507 | X509V3_section_free(cnf, sect); | 507 | X509V3_section_free(cnf, sect); |
508 | 508 | ||
509 | return ret; | 509 | return ret; |
510 | } | 510 | } |
511 | 511 | ||
512 | static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok) | 512 | static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok) |
513 | { | 513 | { |
514 | tag_exp_type *exp_tmp; | 514 | tag_exp_type *exp_tmp; |
515 | /* Can only have IMPLICIT if permitted */ | 515 | /* Can only have IMPLICIT if permitted */ |
516 | if ((arg->imp_tag != -1) && !imp_ok) | 516 | if ((arg->imp_tag != -1) && !imp_ok) |
517 | { | 517 | { |
518 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); | 518 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); |
519 | return 0; | 519 | return 0; |
520 | } | 520 | } |
521 | 521 | ||
522 | if (arg->exp_count == ASN1_FLAG_EXP_MAX) | 522 | if (arg->exp_count == ASN1_FLAG_EXP_MAX) |
523 | { | 523 | { |
524 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED); | 524 | ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED); |
525 | return 0; | 525 | return 0; |
526 | } | 526 | } |
527 | 527 | ||
528 | exp_tmp = &arg->exp_list[arg->exp_count++]; | 528 | exp_tmp = &arg->exp_list[arg->exp_count++]; |
529 | 529 | ||
@@ -531,26 +531,26 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons | |||
531 | * reset implicit tag since it has been used. | 531 | * reset implicit tag since it has been used. |
532 | */ | 532 | */ |
533 | if (arg->imp_tag != -1) | 533 | if (arg->imp_tag != -1) |
534 | { | 534 | { |
535 | exp_tmp->exp_tag = arg->imp_tag; | 535 | exp_tmp->exp_tag = arg->imp_tag; |
536 | exp_tmp->exp_class = arg->imp_class; | 536 | exp_tmp->exp_class = arg->imp_class; |
537 | arg->imp_tag = -1; | 537 | arg->imp_tag = -1; |
538 | arg->imp_class = -1; | 538 | arg->imp_class = -1; |
539 | } | 539 | } |
540 | else | 540 | else |
541 | { | 541 | { |
542 | exp_tmp->exp_tag = exp_tag; | 542 | exp_tmp->exp_tag = exp_tag; |
543 | exp_tmp->exp_class = exp_class; | 543 | exp_tmp->exp_class = exp_class; |
544 | } | 544 | } |
545 | exp_tmp->exp_constructed = exp_constructed; | 545 | exp_tmp->exp_constructed = exp_constructed; |
546 | exp_tmp->exp_pad = exp_pad; | 546 | exp_tmp->exp_pad = exp_pad; |
547 | 547 | ||
548 | return 1; | 548 | return 1; |
549 | } | 549 | } |
550 | 550 | ||
551 | 551 | ||
552 | static int asn1_str2tag(const char *tagstr, int len) | 552 | static int asn1_str2tag(const char *tagstr, int len) |
553 | { | 553 | { |
554 | unsigned int i; | 554 | unsigned int i; |
555 | static const struct tag_name_st *tntmp, tnst [] = { | 555 | static const struct tag_name_st *tntmp, tnst [] = { |
556 | ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN), | 556 | ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN), |
@@ -611,23 +611,23 @@ static int asn1_str2tag(const char *tagstr, int len) | |||
611 | ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP), | 611 | ASN1_GEN_STR("BITWRAP", ASN1_GEN_FLAG_BITWRAP), |
612 | ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT), | 612 | ASN1_GEN_STR("FORM", ASN1_GEN_FLAG_FORMAT), |
613 | ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT), | 613 | ASN1_GEN_STR("FORMAT", ASN1_GEN_FLAG_FORMAT), |
614 | }; | 614 | }; |
615 | 615 | ||
616 | if (len == -1) | 616 | if (len == -1) |
617 | len = strlen(tagstr); | 617 | len = strlen(tagstr); |
618 | 618 | ||
619 | tntmp = tnst; | 619 | tntmp = tnst; |
620 | for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) | 620 | for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) |
621 | { | 621 | { |
622 | if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) | 622 | if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) |
623 | return tntmp->tag; | 623 | return tntmp->tag; |
624 | } | 624 | } |
625 | 625 | ||
626 | return -1; | 626 | return -1; |
627 | } | 627 | } |
628 | 628 | ||
629 | static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | 629 | static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) |
630 | { | 630 | { |
631 | ASN1_TYPE *atmp = NULL; | 631 | ASN1_TYPE *atmp = NULL; |
632 | 632 | ||
633 | CONF_VALUE vtmp; | 633 | CONF_VALUE vtmp; |
@@ -638,91 +638,91 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
638 | int no_unused = 1; | 638 | int no_unused = 1; |
639 | 639 | ||
640 | if (!(atmp = ASN1_TYPE_new())) | 640 | if (!(atmp = ASN1_TYPE_new())) |
641 | { | 641 | { |
642 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 642 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
643 | return NULL; | 643 | return NULL; |
644 | } | 644 | } |
645 | 645 | ||
646 | if (!str) | 646 | if (!str) |
647 | str = ""; | 647 | str = ""; |
648 | 648 | ||
649 | switch(utype) | 649 | switch(utype) |
650 | { | 650 | { |
651 | 651 | ||
652 | case V_ASN1_NULL: | 652 | case V_ASN1_NULL: |
653 | if (str && *str) | 653 | if (str && *str) |
654 | { | 654 | { |
655 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE); | 655 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE); |
656 | goto bad_form; | 656 | goto bad_form; |
657 | } | 657 | } |
658 | break; | 658 | break; |
659 | 659 | ||
660 | case V_ASN1_BOOLEAN: | 660 | case V_ASN1_BOOLEAN: |
661 | if (format != ASN1_GEN_FORMAT_ASCII) | 661 | if (format != ASN1_GEN_FORMAT_ASCII) |
662 | { | 662 | { |
663 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); | 663 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); |
664 | goto bad_form; | 664 | goto bad_form; |
665 | } | 665 | } |
666 | vtmp.name = NULL; | 666 | vtmp.name = NULL; |
667 | vtmp.section = NULL; | 667 | vtmp.section = NULL; |
668 | vtmp.value = (char *)str; | 668 | vtmp.value = (char *)str; |
669 | if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) | 669 | if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) |
670 | { | 670 | { |
671 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN); | 671 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN); |
672 | goto bad_str; | 672 | goto bad_str; |
673 | } | 673 | } |
674 | break; | 674 | break; |
675 | 675 | ||
676 | case V_ASN1_INTEGER: | 676 | case V_ASN1_INTEGER: |
677 | case V_ASN1_ENUMERATED: | 677 | case V_ASN1_ENUMERATED: |
678 | if (format != ASN1_GEN_FORMAT_ASCII) | 678 | if (format != ASN1_GEN_FORMAT_ASCII) |
679 | { | 679 | { |
680 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); | 680 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); |
681 | goto bad_form; | 681 | goto bad_form; |
682 | } | 682 | } |
683 | if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) | 683 | if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) |
684 | { | 684 | { |
685 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); | 685 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); |
686 | goto bad_str; | 686 | goto bad_str; |
687 | } | 687 | } |
688 | break; | 688 | break; |
689 | 689 | ||
690 | case V_ASN1_OBJECT: | 690 | case V_ASN1_OBJECT: |
691 | if (format != ASN1_GEN_FORMAT_ASCII) | 691 | if (format != ASN1_GEN_FORMAT_ASCII) |
692 | { | 692 | { |
693 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); | 693 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); |
694 | goto bad_form; | 694 | goto bad_form; |
695 | } | 695 | } |
696 | if (!(atmp->value.object = OBJ_txt2obj(str, 0))) | 696 | if (!(atmp->value.object = OBJ_txt2obj(str, 0))) |
697 | { | 697 | { |
698 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); | 698 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); |
699 | goto bad_str; | 699 | goto bad_str; |
700 | } | 700 | } |
701 | break; | 701 | break; |
702 | 702 | ||
703 | case V_ASN1_UTCTIME: | 703 | case V_ASN1_UTCTIME: |
704 | case V_ASN1_GENERALIZEDTIME: | 704 | case V_ASN1_GENERALIZEDTIME: |
705 | if (format != ASN1_GEN_FORMAT_ASCII) | 705 | if (format != ASN1_GEN_FORMAT_ASCII) |
706 | { | 706 | { |
707 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); | 707 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); |
708 | goto bad_form; | 708 | goto bad_form; |
709 | } | 709 | } |
710 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) | 710 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) |
711 | { | 711 | { |
712 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 712 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
713 | goto bad_str; | 713 | goto bad_str; |
714 | } | 714 | } |
715 | if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) | 715 | if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) |
716 | { | 716 | { |
717 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 717 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
718 | goto bad_str; | 718 | goto bad_str; |
719 | } | 719 | } |
720 | atmp->value.asn1_string->type = utype; | 720 | atmp->value.asn1_string->type = utype; |
721 | if (!ASN1_TIME_check(atmp->value.asn1_string)) | 721 | if (!ASN1_TIME_check(atmp->value.asn1_string)) |
722 | { | 722 | { |
723 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE); | 723 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE); |
724 | goto bad_str; | 724 | goto bad_str; |
725 | } | 725 | } |
726 | 726 | ||
727 | break; | 727 | break; |
728 | 728 | ||
@@ -741,18 +741,18 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
741 | else if (format == ASN1_GEN_FORMAT_UTF8) | 741 | else if (format == ASN1_GEN_FORMAT_UTF8) |
742 | format = MBSTRING_UTF8; | 742 | format = MBSTRING_UTF8; |
743 | else | 743 | else |
744 | { | 744 | { |
745 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT); | 745 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT); |
746 | goto bad_form; | 746 | goto bad_form; |
747 | } | 747 | } |
748 | 748 | ||
749 | 749 | ||
750 | if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str, | 750 | if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str, |
751 | -1, format, ASN1_tag2bit(utype)) <= 0) | 751 | -1, format, ASN1_tag2bit(utype)) <= 0) |
752 | { | 752 | { |
753 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 753 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
754 | goto bad_str; | 754 | goto bad_str; |
755 | } | 755 | } |
756 | 756 | ||
757 | 757 | ||
758 | break; | 758 | break; |
@@ -762,50 +762,50 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
762 | case V_ASN1_OCTET_STRING: | 762 | case V_ASN1_OCTET_STRING: |
763 | 763 | ||
764 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) | 764 | if (!(atmp->value.asn1_string = ASN1_STRING_new())) |
765 | { | 765 | { |
766 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); | 766 | ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); |
767 | goto bad_form; | 767 | goto bad_form; |
768 | } | 768 | } |
769 | 769 | ||
770 | if (format == ASN1_GEN_FORMAT_HEX) | 770 | if (format == ASN1_GEN_FORMAT_HEX) |
771 | { | 771 | { |
772 | 772 | ||
773 | if (!(rdata = string_to_hex((char *)str, &rdlen))) | 773 | if (!(rdata = string_to_hex((char *)str, &rdlen))) |
774 | { | 774 | { |
775 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); | 775 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); |
776 | goto bad_str; | 776 | goto bad_str; |
777 | } | 777 | } |
778 | 778 | ||
779 | atmp->value.asn1_string->data = rdata; | 779 | atmp->value.asn1_string->data = rdata; |
780 | atmp->value.asn1_string->length = rdlen; | 780 | atmp->value.asn1_string->length = rdlen; |
781 | atmp->value.asn1_string->type = utype; | 781 | atmp->value.asn1_string->type = utype; |
782 | 782 | ||
783 | } | 783 | } |
784 | else if (format == ASN1_GEN_FORMAT_ASCII) | 784 | else if (format == ASN1_GEN_FORMAT_ASCII) |
785 | ASN1_STRING_set(atmp->value.asn1_string, str, -1); | 785 | ASN1_STRING_set(atmp->value.asn1_string, str, -1); |
786 | else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) | 786 | else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) |
787 | { | 787 | { |
788 | if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) | 788 | if (!CONF_parse_list(str, ',', 1, bitstr_cb, atmp->value.bit_string)) |
789 | { | 789 | { |
790 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR); | 790 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR); |
791 | goto bad_str; | 791 | goto bad_str; |
792 | } | 792 | } |
793 | no_unused = 0; | 793 | no_unused = 0; |
794 | 794 | ||
795 | } | 795 | } |
796 | else | 796 | else |
797 | { | 797 | { |
798 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT); | 798 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT); |
799 | goto bad_form; | 799 | goto bad_form; |
800 | } | 800 | } |
801 | 801 | ||
802 | if ((utype == V_ASN1_BIT_STRING) && no_unused) | 802 | if ((utype == V_ASN1_BIT_STRING) && no_unused) |
803 | { | 803 | { |
804 | atmp->value.asn1_string->flags | 804 | atmp->value.asn1_string->flags |
805 | &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); | 805 | &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); |
806 | atmp->value.asn1_string->flags | 806 | atmp->value.asn1_string->flags |
807 | |= ASN1_STRING_FLAG_BITS_LEFT; | 807 | |= ASN1_STRING_FLAG_BITS_LEFT; |
808 | } | 808 | } |
809 | 809 | ||
810 | 810 | ||
811 | break; | 811 | break; |
@@ -814,7 +814,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
814 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE); | 814 | ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE); |
815 | goto bad_str; | 815 | goto bad_str; |
816 | break; | 816 | break; |
817 | } | 817 | } |
818 | 818 | ||
819 | 819 | ||
820 | atmp->type = utype; | 820 | atmp->type = utype; |
@@ -828,10 +828,10 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype) | |||
828 | ASN1_TYPE_free(atmp); | 828 | ASN1_TYPE_free(atmp); |
829 | return NULL; | 829 | return NULL; |
830 | 830 | ||
831 | } | 831 | } |
832 | 832 | ||
833 | static int bitstr_cb(const char *elem, int len, void *bitstr) | 833 | static int bitstr_cb(const char *elem, int len, void *bitstr) |
834 | { | 834 | { |
835 | long bitnum; | 835 | long bitnum; |
836 | char *eptr; | 836 | char *eptr; |
837 | if (!elem) | 837 | if (!elem) |
@@ -840,15 +840,15 @@ static int bitstr_cb(const char *elem, int len, void *bitstr) | |||
840 | if (eptr && *eptr && (eptr != elem + len)) | 840 | if (eptr && *eptr && (eptr != elem + len)) |
841 | return 0; | 841 | return 0; |
842 | if (bitnum < 0) | 842 | if (bitnum < 0) |
843 | { | 843 | { |
844 | ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER); | 844 | ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER); |
845 | return 0; | 845 | return 0; |
846 | } | 846 | } |
847 | if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) | 847 | if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) |
848 | { | 848 | { |
849 | ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE); | 849 | ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE); |
850 | return 0; | 850 | return 0; |
851 | } | ||
852 | return 1; | ||
853 | } | 851 | } |
852 | return 1; | ||
853 | } | ||
854 | 854 | ||