summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/asn1_gen.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/asn1_gen.c')
-rw-r--r--src/lib/libcrypto/asn1/asn1_gen.c213
1 files changed, 81 insertions, 132 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_gen.c b/src/lib/libcrypto/asn1/asn1_gen.c
index f78aac7148..314df379f9 100644
--- a/src/lib/libcrypto/asn1/asn1_gen.c
+++ b/src/lib/libcrypto/asn1/asn1_gen.c
@@ -156,10 +156,8 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
156 if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0) 156 if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0)
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 if (!cnf) {
161 if (!cnf)
162 {
163 ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); 161 ASN1err(ASN1_F_ASN1_GENERATE_V3, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG);
164 return NULL; 162 return NULL;
165 } 163 }
@@ -183,8 +181,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
183 cpy_start = orig_der; 181 cpy_start = orig_der;
184 182
185 /* Do we need IMPLICIT tagging? */ 183 /* Do we need IMPLICIT tagging? */
186 if (asn1_tags.imp_tag != -1) 184 if (asn1_tags.imp_tag != -1) {
187 {
188 /* If IMPLICIT we will replace the underlying tag */ 185 /* If IMPLICIT we will replace the underlying tag */
189 /* Skip existing tag+len */ 186 /* Skip existing tag+len */
190 r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len); 187 r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class, cpy_len);
@@ -196,8 +193,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
196 * original length and constructed flag should be 193 * original length and constructed flag should be
197 * consistent. 194 * consistent.
198 */ 195 */
199 if (r & 0x1) 196 if (r & 0x1) {
200 {
201 /* Indefinite length constructed */ 197 /* Indefinite length constructed */
202 hdr_constructed = 2; 198 hdr_constructed = 2;
203 hdr_len = 0; 199 hdr_len = 0;
@@ -215,8 +211,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
215 211
216 /* Work out length in any EXPLICIT, starting from end */ 212 /* Work out length in any EXPLICIT, starting from end */
217 213
218 for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) 214 for(i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1; i < asn1_tags.exp_count; i++, etmp--) {
219 {
220 /* Content length: number of content octets + any padding */ 215 /* Content length: number of content octets + any padding */
221 len += etmp->exp_pad; 216 len += etmp->exp_pad;
222 etmp->exp_len = len; 217 etmp->exp_len = len;
@@ -236,8 +231,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
236 231
237 /* Output explicit tags first */ 232 /* Output explicit tags first */
238 233
239 for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) 234 for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count; i++, etmp++) {
240 {
241 ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len, 235 ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len,
242 etmp->exp_tag, etmp->exp_class); 236 etmp->exp_tag, etmp->exp_class);
243 if (etmp->exp_pad) 237 if (etmp->exp_pad)
@@ -246,8 +240,7 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
246 240
247 /* If IMPLICIT, output tag */ 241 /* If IMPLICIT, output tag */
248 242
249 if (asn1_tags.imp_tag != -1) 243 if (asn1_tags.imp_tag != -1) {
250 {
251 if (asn1_tags.imp_class == V_ASN1_UNIVERSAL 244 if (asn1_tags.imp_class == V_ASN1_UNIVERSAL
252 && (asn1_tags.imp_tag == V_ASN1_SEQUENCE 245 && (asn1_tags.imp_tag == V_ASN1_SEQUENCE
253 || asn1_tags.imp_tag == V_ASN1_SET) ) 246 || asn1_tags.imp_tag == V_ASN1_SET) )
@@ -284,11 +277,9 @@ static int asn1_cb(const char *elem, int len, void *bitstr)
284 277
285 int tmp_tag, tmp_class; 278 int tmp_tag, tmp_class;
286 279
287 for(i = 0, p = elem; i < len; p++, i++) 280 for(i = 0, p = elem; i < len; p++, i++) {
288 {
289 /* Look for the ':' in name value pairs */ 281 /* Look for the ':' in name value pairs */
290 if (*p == ':') 282 if (*p == ':') {
291 {
292 vstart = p + 1; 283 vstart = p + 1;
293 vlen = len - (vstart - elem); 284 vlen = len - (vstart - elem);
294 len = p - elem; 285 len = p - elem;
@@ -298,34 +289,29 @@ static int asn1_cb(const char *elem, int len, void *bitstr)
298 289
299 utype = asn1_str2tag(elem, len); 290 utype = asn1_str2tag(elem, len);
300 291
301 if (utype == -1) 292 if (utype == -1) {
302 {
303 ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG); 293 ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKNOWN_TAG);
304 ERR_add_error_data(2, "tag=", elem); 294 ERR_add_error_data(2, "tag=", elem);
305 return -1; 295 return -1;
306 } 296 }
307 297
308 /* If this is not a modifier mark end of string and exit */ 298 /* If this is not a modifier mark end of string and exit */
309 if (!(utype & ASN1_GEN_FLAG)) 299 if (!(utype & ASN1_GEN_FLAG)) {
310 {
311 arg->utype = utype; 300 arg->utype = utype;
312 arg->str = vstart; 301 arg->str = vstart;
313 /* If no value and not end of string, error */ 302 /* If no value and not end of string, error */
314 if (!vstart && elem[len]) 303 if (!vstart && elem[len]) {
315 {
316 ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE); 304 ASN1err(ASN1_F_ASN1_CB, ASN1_R_MISSING_VALUE);
317 return -1; 305 return -1;
318 } 306 }
319 return 0; 307 return 0;
320 } 308 }
321 309
322 switch(utype) 310 switch(utype) {
323 {
324 311
325 case ASN1_GEN_FLAG_IMP: 312 case ASN1_GEN_FLAG_IMP:
326 /* Check for illegal multiple IMPLICIT tagging */ 313 /* Check for illegal multiple IMPLICIT tagging */
327 if (arg->imp_tag != -1) 314 if (arg->imp_tag != -1) {
328 {
329 ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING); 315 ASN1err(ASN1_F_ASN1_CB, ASN1_R_ILLEGAL_NESTED_TAGGING);
330 return -1; 316 return -1;
331 } 317 }
@@ -333,7 +319,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr)
333 return -1; 319 return -1;
334 break; 320 break;
335 321
336 case ASN1_GEN_FLAG_EXP: 322 case ASN1_GEN_FLAG_EXP:
337 323
338 if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class)) 324 if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class))
339 return -1; 325 return -1;
@@ -341,27 +327,27 @@ static int asn1_cb(const char *elem, int len, void *bitstr)
341 return -1; 327 return -1;
342 break; 328 break;
343 329
344 case ASN1_GEN_FLAG_SEQWRAP: 330 case ASN1_GEN_FLAG_SEQWRAP:
345 if (!append_exp(arg, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, 1, 0, 1)) 331 if (!append_exp(arg, V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL, 1, 0, 1))
346 return -1; 332 return -1;
347 break; 333 break;
348 334
349 case ASN1_GEN_FLAG_SETWRAP: 335 case ASN1_GEN_FLAG_SETWRAP:
350 if (!append_exp(arg, V_ASN1_SET, V_ASN1_UNIVERSAL, 1, 0, 1)) 336 if (!append_exp(arg, V_ASN1_SET, V_ASN1_UNIVERSAL, 1, 0, 1))
351 return -1; 337 return -1;
352 break; 338 break;
353 339
354 case ASN1_GEN_FLAG_BITWRAP: 340 case ASN1_GEN_FLAG_BITWRAP:
355 if (!append_exp(arg, V_ASN1_BIT_STRING, V_ASN1_UNIVERSAL, 0, 1, 1)) 341 if (!append_exp(arg, V_ASN1_BIT_STRING, V_ASN1_UNIVERSAL, 0, 1, 1))
356 return -1; 342 return -1;
357 break; 343 break;
358 344
359 case ASN1_GEN_FLAG_OCTWRAP: 345 case ASN1_GEN_FLAG_OCTWRAP:
360 if (!append_exp(arg, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL, 0, 0, 1)) 346 if (!append_exp(arg, V_ASN1_OCTET_STRING, V_ASN1_UNIVERSAL, 0, 0, 1))
361 return -1; 347 return -1;
362 break; 348 break;
363 349
364 case ASN1_GEN_FLAG_FORMAT: 350 case ASN1_GEN_FLAG_FORMAT:
365 if (!strncmp(vstart, "ASCII", 5)) 351 if (!strncmp(vstart, "ASCII", 5))
366 arg->format = ASN1_GEN_FORMAT_ASCII; 352 arg->format = ASN1_GEN_FORMAT_ASCII;
367 else if (!strncmp(vstart, "UTF8", 4)) 353 else if (!strncmp(vstart, "UTF8", 4))
@@ -370,8 +356,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr)
370 arg->format = ASN1_GEN_FORMAT_HEX; 356 arg->format = ASN1_GEN_FORMAT_HEX;
371 else if (!strncmp(vstart, "BITLIST", 7)) 357 else if (!strncmp(vstart, "BITLIST", 7))
372 arg->format = ASN1_GEN_FORMAT_BITLIST; 358 arg->format = ASN1_GEN_FORMAT_BITLIST;
373 else 359 else {
374 {
375 ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT); 360 ASN1err(ASN1_F_ASN1_CB, ASN1_R_UNKOWN_FORMAT);
376 return -1; 361 return -1;
377 } 362 }
@@ -394,8 +379,7 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
394 /* Check we haven't gone past max length: should be impossible */ 379 /* Check we haven't gone past max length: should be impossible */
395 if (eptr && *eptr && (eptr > vstart + vlen)) 380 if (eptr && *eptr && (eptr > vstart + vlen))
396 return 0; 381 return 0;
397 if (tag_num < 0) 382 if (tag_num < 0) {
398 {
399 ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER); 383 ASN1err(ASN1_F_PARSE_TAGGING, ASN1_R_INVALID_NUMBER);
400 return 0; 384 return 0;
401 } 385 }
@@ -405,24 +389,22 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
405 vlen -= eptr - vstart; 389 vlen -= eptr - vstart;
406 else 390 else
407 vlen = 0; 391 vlen = 0;
408 if (vlen) 392 if (vlen) {
409 { 393 switch (*eptr) {
410 switch (*eptr)
411 {
412 394
413 case 'U': 395 case 'U':
414 *pclass = V_ASN1_UNIVERSAL; 396 *pclass = V_ASN1_UNIVERSAL;
415 break; 397 break;
416 398
417 case 'A': 399 case 'A':
418 *pclass = V_ASN1_APPLICATION; 400 *pclass = V_ASN1_APPLICATION;
419 break; 401 break;
420 402
421 case 'P': 403 case 'P':
422 *pclass = V_ASN1_PRIVATE; 404 *pclass = V_ASN1_PRIVATE;
423 break; 405 break;
424 406
425 case 'C': 407 case 'C':
426 *pclass = V_ASN1_CONTEXT_SPECIFIC; 408 *pclass = V_ASN1_CONTEXT_SPECIFIC;
427 break; 409 break;
428 410
@@ -456,15 +438,13 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf)
456 sk = sk_ASN1_TYPE_new_null(); 438 sk = sk_ASN1_TYPE_new_null();
457 if (!sk) 439 if (!sk)
458 goto bad; 440 goto bad;
459 if (section) 441 if (section) {
460 {
461 if (!cnf) 442 if (!cnf)
462 goto bad; 443 goto bad;
463 sect = X509V3_get_section(cnf, (char *)section); 444 sect = X509V3_get_section(cnf, (char *)section);
464 if (!sect) 445 if (!sect)
465 goto bad; 446 goto bad;
466 for (i = 0; i < sk_CONF_VALUE_num(sect); i++) 447 for (i = 0; i < sk_CONF_VALUE_num(sect); i++) {
467 {
468 ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf); 448 ASN1_TYPE *typ = ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf);
469 if (!typ) 449 if (!typ)
470 goto bad; 450 goto bad;
@@ -513,14 +493,12 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons
513{ 493{
514 tag_exp_type *exp_tmp; 494 tag_exp_type *exp_tmp;
515 /* Can only have IMPLICIT if permitted */ 495 /* Can only have IMPLICIT if permitted */
516 if ((arg->imp_tag != -1) && !imp_ok) 496 if ((arg->imp_tag != -1) && !imp_ok) {
517 {
518 ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG); 497 ASN1err(ASN1_F_APPEND_EXP, ASN1_R_ILLEGAL_IMPLICIT_TAG);
519 return 0; 498 return 0;
520 } 499 }
521 500
522 if (arg->exp_count == ASN1_FLAG_EXP_MAX) 501 if (arg->exp_count == ASN1_FLAG_EXP_MAX) {
523 {
524 ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED); 502 ASN1err(ASN1_F_APPEND_EXP, ASN1_R_DEPTH_EXCEEDED);
525 return 0; 503 return 0;
526 } 504 }
@@ -530,15 +508,12 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons
530 /* If IMPLICIT set tag to implicit value then 508 /* If IMPLICIT set tag to implicit value then
531 * reset implicit tag since it has been used. 509 * reset implicit tag since it has been used.
532 */ 510 */
533 if (arg->imp_tag != -1) 511 if (arg->imp_tag != -1) {
534 {
535 exp_tmp->exp_tag = arg->imp_tag; 512 exp_tmp->exp_tag = arg->imp_tag;
536 exp_tmp->exp_class = arg->imp_class; 513 exp_tmp->exp_class = arg->imp_class;
537 arg->imp_tag = -1; 514 arg->imp_tag = -1;
538 arg->imp_class = -1; 515 arg->imp_class = -1;
539 } 516 } else {
540 else
541 {
542 exp_tmp->exp_tag = exp_tag; 517 exp_tmp->exp_tag = exp_tag;
543 exp_tmp->exp_class = exp_class; 518 exp_tmp->exp_class = exp_class;
544 } 519 }
@@ -617,8 +592,7 @@ static int asn1_str2tag(const char *tagstr, int len)
617 len = strlen(tagstr); 592 len = strlen(tagstr);
618 593
619 tntmp = tnst; 594 tntmp = tnst;
620 for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) 595 for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) {
621 {
622 if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len)) 596 if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len))
623 return tntmp->tag; 597 return tntmp->tag;
624 } 598 }
@@ -637,8 +611,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
637 611
638 int no_unused = 1; 612 int no_unused = 1;
639 613
640 if (!(atmp = ASN1_TYPE_new())) 614 if (!(atmp = ASN1_TYPE_new())) {
641 {
642 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); 615 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
643 return NULL; 616 return NULL;
644 } 617 }
@@ -646,110 +619,96 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
646 if (!str) 619 if (!str)
647 str = ""; 620 str = "";
648 621
649 switch(utype) 622 switch(utype) {
650 {
651 623
652 case V_ASN1_NULL: 624 case V_ASN1_NULL:
653 if (str && *str) 625 if (str && *str) {
654 {
655 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE); 626 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_NULL_VALUE);
656 goto bad_form; 627 goto bad_form;
657 } 628 }
658 break; 629 break;
659 630
660 case V_ASN1_BOOLEAN: 631 case V_ASN1_BOOLEAN:
661 if (format != ASN1_GEN_FORMAT_ASCII) 632 if (format != ASN1_GEN_FORMAT_ASCII) {
662 {
663 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT); 633 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_NOT_ASCII_FORMAT);
664 goto bad_form; 634 goto bad_form;
665 } 635 }
666 vtmp.name = NULL; 636 vtmp.name = NULL;
667 vtmp.section = NULL; 637 vtmp.section = NULL;
668 vtmp.value = (char *)str; 638 vtmp.value = (char *)str;
669 if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) 639 if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) {
670 {
671 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN); 640 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BOOLEAN);
672 goto bad_str; 641 goto bad_str;
673 } 642 }
674 break; 643 break;
675 644
676 case V_ASN1_INTEGER: 645 case V_ASN1_INTEGER:
677 case V_ASN1_ENUMERATED: 646 case V_ASN1_ENUMERATED:
678 if (format != ASN1_GEN_FORMAT_ASCII) 647 if (format != ASN1_GEN_FORMAT_ASCII) {
679 {
680 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT); 648 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_INTEGER_NOT_ASCII_FORMAT);
681 goto bad_form; 649 goto bad_form;
682 } 650 }
683 if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) 651 if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) {
684 {
685 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER); 652 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_INTEGER);
686 goto bad_str; 653 goto bad_str;
687 } 654 }
688 break; 655 break;
689 656
690 case V_ASN1_OBJECT: 657 case V_ASN1_OBJECT:
691 if (format != ASN1_GEN_FORMAT_ASCII) 658 if (format != ASN1_GEN_FORMAT_ASCII) {
692 {
693 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT); 659 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_OBJECT_NOT_ASCII_FORMAT);
694 goto bad_form; 660 goto bad_form;
695 } 661 }
696 if (!(atmp->value.object = OBJ_txt2obj(str, 0))) 662 if (!(atmp->value.object = OBJ_txt2obj(str, 0))) {
697 {
698 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT); 663 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_OBJECT);
699 goto bad_str; 664 goto bad_str;
700 } 665 }
701 break; 666 break;
702 667
703 case V_ASN1_UTCTIME: 668 case V_ASN1_UTCTIME:
704 case V_ASN1_GENERALIZEDTIME: 669 case V_ASN1_GENERALIZEDTIME:
705 if (format != ASN1_GEN_FORMAT_ASCII) 670 if (format != ASN1_GEN_FORMAT_ASCII) {
706 {
707 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT); 671 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_TIME_NOT_ASCII_FORMAT);
708 goto bad_form; 672 goto bad_form;
709 } 673 }
710 if (!(atmp->value.asn1_string = ASN1_STRING_new())) 674 if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
711 {
712 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); 675 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
713 goto bad_str; 676 goto bad_str;
714 } 677 }
715 if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) 678 if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) {
716 {
717 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); 679 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
718 goto bad_str; 680 goto bad_str;
719 } 681 }
720 atmp->value.asn1_string->type = utype; 682 atmp->value.asn1_string->type = utype;
721 if (!ASN1_TIME_check(atmp->value.asn1_string)) 683 if (!ASN1_TIME_check(atmp->value.asn1_string)) {
722 {
723 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE); 684 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_TIME_VALUE);
724 goto bad_str; 685 goto bad_str;
725 } 686 }
726 687
727 break; 688 break;
728 689
729 case V_ASN1_BMPSTRING: 690 case V_ASN1_BMPSTRING:
730 case V_ASN1_PRINTABLESTRING: 691 case V_ASN1_PRINTABLESTRING:
731 case V_ASN1_IA5STRING: 692 case V_ASN1_IA5STRING:
732 case V_ASN1_T61STRING: 693 case V_ASN1_T61STRING:
733 case V_ASN1_UTF8STRING: 694 case V_ASN1_UTF8STRING:
734 case V_ASN1_VISIBLESTRING: 695 case V_ASN1_VISIBLESTRING:
735 case V_ASN1_UNIVERSALSTRING: 696 case V_ASN1_UNIVERSALSTRING:
736 case V_ASN1_GENERALSTRING: 697 case V_ASN1_GENERALSTRING:
737 case V_ASN1_NUMERICSTRING: 698 case V_ASN1_NUMERICSTRING:
738 699
739 if (format == ASN1_GEN_FORMAT_ASCII) 700 if (format == ASN1_GEN_FORMAT_ASCII)
740 format = MBSTRING_ASC; 701 format = MBSTRING_ASC;
741 else if (format == ASN1_GEN_FORMAT_UTF8) 702 else if (format == ASN1_GEN_FORMAT_UTF8)
742 format = MBSTRING_UTF8; 703 format = MBSTRING_UTF8;
743 else 704 else {
744 {
745 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT); 705 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_FORMAT);
746 goto bad_form; 706 goto bad_form;
747 } 707 }
748 708
749 709
750 if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str, 710 if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str,
751 -1, format, ASN1_tag2bit(utype)) <= 0) 711 -1, format, ASN1_tag2bit(utype)) <= 0) {
752 {
753 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); 712 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
754 goto bad_str; 713 goto bad_str;
755 } 714 }
@@ -757,21 +716,18 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
757 716
758 break; 717 break;
759 718
760 case V_ASN1_BIT_STRING: 719 case V_ASN1_BIT_STRING:
761 720
762 case V_ASN1_OCTET_STRING: 721 case V_ASN1_OCTET_STRING:
763 722
764 if (!(atmp->value.asn1_string = ASN1_STRING_new())) 723 if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
765 {
766 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE); 724 ASN1err(ASN1_F_ASN1_STR2TYPE, ERR_R_MALLOC_FAILURE);
767 goto bad_form; 725 goto bad_form;
768 } 726 }
769 727
770 if (format == ASN1_GEN_FORMAT_HEX) 728 if (format == ASN1_GEN_FORMAT_HEX) {
771 {
772 729
773 if (!(rdata = string_to_hex((char *)str, &rdlen))) 730 if (!(rdata = string_to_hex((char *)str, &rdlen))) {
774 {
775 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX); 731 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_HEX);
776 goto bad_str; 732 goto bad_str;
777 } 733 }
@@ -783,24 +739,19 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
783 } 739 }
784 else if (format == ASN1_GEN_FORMAT_ASCII) 740 else if (format == ASN1_GEN_FORMAT_ASCII)
785 ASN1_STRING_set(atmp->value.asn1_string, str, -1); 741 ASN1_STRING_set(atmp->value.asn1_string, str, -1);
786 else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) 742 else if ((format == ASN1_GEN_FORMAT_BITLIST) && (utype == V_ASN1_BIT_STRING)) {
787 { 743 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 {
790 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR); 744 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_LIST_ERROR);
791 goto bad_str; 745 goto bad_str;
792 } 746 }
793 no_unused = 0; 747 no_unused = 0;
794 748
795 } 749 } else {
796 else
797 {
798 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT); 750 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_ILLEGAL_BITSTRING_FORMAT);
799 goto bad_form; 751 goto bad_form;
800 } 752 }
801 753
802 if ((utype == V_ASN1_BIT_STRING) && no_unused) 754 if ((utype == V_ASN1_BIT_STRING) && no_unused) {
803 {
804 atmp->value.asn1_string->flags 755 atmp->value.asn1_string->flags
805 &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); 756 &= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
806 atmp->value.asn1_string->flags 757 atmp->value.asn1_string->flags
@@ -810,7 +761,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
810 761
811 break; 762 break;
812 763
813 default: 764 default:
814 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE); 765 ASN1err(ASN1_F_ASN1_STR2TYPE, ASN1_R_UNSUPPORTED_TYPE);
815 goto bad_str; 766 goto bad_str;
816 break; 767 break;
@@ -821,9 +772,9 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
821 return atmp; 772 return atmp;
822 773
823 774
824 bad_str: 775bad_str:
825 ERR_add_error_data(2, "string=", str); 776 ERR_add_error_data(2, "string=", str);
826 bad_form: 777bad_form:
827 778
828 ASN1_TYPE_free(atmp); 779 ASN1_TYPE_free(atmp);
829 return NULL; 780 return NULL;
@@ -839,13 +790,11 @@ static int bitstr_cb(const char *elem, int len, void *bitstr)
839 bitnum = strtoul(elem, &eptr, 10); 790 bitnum = strtoul(elem, &eptr, 10);
840 if (eptr && *eptr && (eptr != elem + len)) 791 if (eptr && *eptr && (eptr != elem + len))
841 return 0; 792 return 0;
842 if (bitnum < 0) 793 if (bitnum < 0) {
843 {
844 ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER); 794 ASN1err(ASN1_F_BITSTR_CB, ASN1_R_INVALID_NUMBER);
845 return 0; 795 return 0;
846 } 796 }
847 if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) 797 if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) {
848 {
849 ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE); 798 ASN1err(ASN1_F_BITSTR_CB, ERR_R_MALLOC_FAILURE);
850 return 0; 799 return 0;
851 } 800 }