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.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/lib/libcrypto/asn1/asn1_gen.c b/src/lib/libcrypto/asn1/asn1_gen.c
index 2da38292c8..4fc241908f 100644
--- a/src/lib/libcrypto/asn1/asn1_gen.c
+++ b/src/lib/libcrypto/asn1/asn1_gen.c
@@ -227,6 +227,8 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
227 /* Allocate buffer for new encoding */ 227 /* Allocate buffer for new encoding */
228 228
229 new_der = OPENSSL_malloc(len); 229 new_der = OPENSSL_malloc(len);
230 if (!new_der)
231 goto err;
230 232
231 /* Generate tagged encoding */ 233 /* Generate tagged encoding */
232 234
@@ -245,8 +247,14 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
245 /* If IMPLICIT, output tag */ 247 /* If IMPLICIT, output tag */
246 248
247 if (asn1_tags.imp_tag != -1) 249 if (asn1_tags.imp_tag != -1)
250 {
251 if (asn1_tags.imp_class == V_ASN1_UNIVERSAL
252 && (asn1_tags.imp_tag == V_ASN1_SEQUENCE
253 || asn1_tags.imp_tag == V_ASN1_SET) )
254 hdr_constructed = V_ASN1_CONSTRUCTED;
248 ASN1_put_object(&p, hdr_constructed, hdr_len, 255 ASN1_put_object(&p, hdr_constructed, hdr_len,
249 asn1_tags.imp_tag, asn1_tags.imp_class); 256 asn1_tags.imp_tag, asn1_tags.imp_class);
257 }
250 258
251 /* Copy across original encoding */ 259 /* Copy across original encoding */
252 memcpy(p, cpy_start, cpy_len); 260 memcpy(p, cpy_start, cpy_len);
@@ -439,13 +447,15 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
439 447
440static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) 448static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf)
441 { 449 {
442 ASN1_TYPE *ret = NULL, *typ = NULL; 450 ASN1_TYPE *ret = NULL;
443 STACK_OF(ASN1_TYPE) *sk = NULL; 451 STACK_OF(ASN1_TYPE) *sk = NULL;
444 STACK_OF(CONF_VALUE) *sect = NULL; 452 STACK_OF(CONF_VALUE) *sect = NULL;
445 unsigned char *der = NULL, *p; 453 unsigned char *der = NULL;
446 int derlen; 454 int derlen;
447 int i, is_set; 455 int i;
448 sk = sk_ASN1_TYPE_new_null(); 456 sk = sk_ASN1_TYPE_new_null();
457 if (!sk)
458 goto bad;
449 if (section) 459 if (section)
450 { 460 {
451 if (!cnf) 461 if (!cnf)
@@ -455,28 +465,23 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf)
455 goto bad; 465 goto bad;
456 for (i = 0; i < sk_CONF_VALUE_num(sect); i++) 466 for (i = 0; i < sk_CONF_VALUE_num(sect); i++)
457 { 467 {
458 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);
459 if (!typ) 469 if (!typ)
460 goto bad; 470 goto bad;
461 sk_ASN1_TYPE_push(sk, typ); 471 if (!sk_ASN1_TYPE_push(sk, typ))
462 typ = NULL; 472 goto bad;
463 } 473 }
464 } 474 }
465 475
466 /* 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 */
467 477
468 if (utype == V_ASN1_SET) 478 if (utype == V_ASN1_SET)
469 is_set = 1; 479 derlen = i2d_ASN1_SET_ANY(sk, &der);
470 else 480 else
471 is_set = 0; 481 derlen = i2d_ASN1_SEQUENCE_ANY(sk, &der);
472
473 482
474 derlen = i2d_ASN1_SET_OF_ASN1_TYPE(sk, NULL, i2d_ASN1_TYPE, utype, 483 if (derlen < 0)
475 V_ASN1_UNIVERSAL, is_set); 484 goto bad;
476 der = OPENSSL_malloc(derlen);
477 p = der;
478 i2d_ASN1_SET_OF_ASN1_TYPE(sk, &p, i2d_ASN1_TYPE, utype,
479 V_ASN1_UNIVERSAL, is_set);
480 485
481 if (!(ret = ASN1_TYPE_new())) 486 if (!(ret = ASN1_TYPE_new()))
482 goto bad; 487 goto bad;
@@ -498,8 +503,6 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf)
498 503
499 if (sk) 504 if (sk)
500 sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free); 505 sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
501 if (typ)
502 ASN1_TYPE_free(typ);
503 if (sect) 506 if (sect)
504 X509V3_section_free(cnf, sect); 507 X509V3_section_free(cnf, sect);
505 508
@@ -549,7 +552,7 @@ static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_cons
549static int asn1_str2tag(const char *tagstr, int len) 552static int asn1_str2tag(const char *tagstr, int len)
550 { 553 {
551 unsigned int i; 554 unsigned int i;
552 static struct tag_name_st *tntmp, tnst [] = { 555 static const struct tag_name_st *tntmp, tnst [] = {
553 ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN), 556 ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN),
554 ASN1_GEN_STR("BOOLEAN", V_ASN1_BOOLEAN), 557 ASN1_GEN_STR("BOOLEAN", V_ASN1_BOOLEAN),
555 ASN1_GEN_STR("NULL", V_ASN1_NULL), 558 ASN1_GEN_STR("NULL", V_ASN1_NULL),
@@ -584,6 +587,8 @@ static int asn1_str2tag(const char *tagstr, int len)
584 ASN1_GEN_STR("TELETEXSTRING", V_ASN1_T61STRING), 587 ASN1_GEN_STR("TELETEXSTRING", V_ASN1_T61STRING),
585 ASN1_GEN_STR("GeneralString", V_ASN1_GENERALSTRING), 588 ASN1_GEN_STR("GeneralString", V_ASN1_GENERALSTRING),
586 ASN1_GEN_STR("GENSTR", V_ASN1_GENERALSTRING), 589 ASN1_GEN_STR("GENSTR", V_ASN1_GENERALSTRING),
590 ASN1_GEN_STR("NUMERIC", V_ASN1_NUMERICSTRING),
591 ASN1_GEN_STR("NUMERICSTRING", V_ASN1_NUMERICSTRING),
587 592
588 /* Special cases */ 593 /* Special cases */
589 ASN1_GEN_STR("SEQUENCE", V_ASN1_SEQUENCE), 594 ASN1_GEN_STR("SEQUENCE", V_ASN1_SEQUENCE),
@@ -729,6 +734,7 @@ static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
729 case V_ASN1_VISIBLESTRING: 734 case V_ASN1_VISIBLESTRING:
730 case V_ASN1_UNIVERSALSTRING: 735 case V_ASN1_UNIVERSALSTRING:
731 case V_ASN1_GENERALSTRING: 736 case V_ASN1_GENERALSTRING:
737 case V_ASN1_NUMERICSTRING:
732 738
733 if (format == ASN1_GEN_FORMAT_ASCII) 739 if (format == ASN1_GEN_FORMAT_ASCII)
734 format = MBSTRING_ASC; 740 format = MBSTRING_ASC;