Sync asn1_gen.c with upstream 1.0.2.

This imports bf5b8ff17dd7039b15cbc6468cd865cbc219581d and
a696708ae6bbe42f409748b3e31bb2f3034edbf3 from upstream. I missed them at
some point.

Change-Id: I882d995868e4c0461b7ca51a854691cf4faa7260
Reviewed-on: https://boringssl-review.googlesource.com/17384
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
David Benjamin 2017-06-26 17:02:48 -04:00 committed by Adam Langley
parent a6bae93bf8
commit e59703c72b

View File

@ -84,6 +84,8 @@
#define ASN1_GEN_STR(str,val) {str, sizeof(str) - 1, val} #define ASN1_GEN_STR(str,val) {str, sizeof(str) - 1, val}
#define ASN1_FLAG_EXP_MAX 20 #define ASN1_FLAG_EXP_MAX 20
/* Maximum number of nested sequences */
#define ASN1_GEN_SEQ_MAX_DEPTH 50
/* Input formats */ /* Input formats */
@ -120,13 +122,16 @@ typedef struct {
int exp_count; int exp_count;
} tag_exp_arg; } tag_exp_arg;
static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth,
int *perr);
static int bitstr_cb(const char *elem, int len, void *bitstr); static int bitstr_cb(const char *elem, int len, void *bitstr);
static int asn1_cb(const char *elem, int len, void *bitstr); static int asn1_cb(const char *elem, int len, void *bitstr);
static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class,
int exp_constructed, int exp_pad, int imp_ok); int exp_constructed, int exp_pad, int imp_ok);
static int parse_tagging(const char *vstart, int vlen, int *ptag, static int parse_tagging(const char *vstart, int vlen, int *ptag,
int *pclass); int *pclass);
static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf); static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf,
int depth, int *perr);
static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype); static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype);
static int asn1_str2tag(const char *tagstr, int len); static int asn1_str2tag(const char *tagstr, int len);
@ -142,6 +147,16 @@ ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf)
} }
ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf) ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
{
int err = 0;
ASN1_TYPE *ret = generate_v3(str, cnf, 0, &err);
if (err)
OPENSSL_PUT_ERROR(ASN1, err);
return ret;
}
static ASN1_TYPE *generate_v3(char *str, X509V3_CTX *cnf, int depth,
int *perr)
{ {
ASN1_TYPE *ret; ASN1_TYPE *ret;
tag_exp_arg asn1_tags; tag_exp_arg asn1_tags;
@ -162,16 +177,22 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf)
asn1_tags.imp_class = -1; asn1_tags.imp_class = -1;
asn1_tags.format = ASN1_GEN_FORMAT_ASCII; asn1_tags.format = ASN1_GEN_FORMAT_ASCII;
asn1_tags.exp_count = 0; asn1_tags.exp_count = 0;
if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0) if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0) {
*perr = ASN1_R_UNKNOWN_TAG;
return NULL; return NULL;
}
if ((asn1_tags.utype == V_ASN1_SEQUENCE) if ((asn1_tags.utype == V_ASN1_SEQUENCE)
|| (asn1_tags.utype == V_ASN1_SET)) { || (asn1_tags.utype == V_ASN1_SET)) {
if (!cnf) { if (!cnf) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG); *perr = ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG;
return NULL; return NULL;
} }
ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf); if (depth >= ASN1_GEN_SEQ_MAX_DEPTH) {
*perr = ASN1_R_ILLEGAL_NESTED_TAGGING;
return NULL;
}
ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf, depth, perr);
} else } else
ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype); ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype);
@ -289,7 +310,7 @@ static int asn1_cb(const char *elem, int len, void *bitstr)
int tmp_tag, tmp_class; int tmp_tag, tmp_class;
if (elem == NULL) if (elem == NULL)
return 0; return -1;
for (i = 0, p = elem; i < len; p++, i++) { for (i = 0, p = elem; i < len; p++, i++) {
/* Look for the ':' in name value pairs */ /* Look for the ':' in name value pairs */
@ -444,7 +465,8 @@ static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
/* Handle multiple types: SET and SEQUENCE */ /* Handle multiple types: SET and SEQUENCE */
static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf) static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf,
int depth, int *perr)
{ {
ASN1_TYPE *ret = NULL; ASN1_TYPE *ret = NULL;
STACK_OF(ASN1_TYPE) *sk = NULL; STACK_OF(ASN1_TYPE) *sk = NULL;
@ -463,7 +485,8 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf)
goto bad; goto bad;
for (i = 0; i < sk_CONF_VALUE_num(sect); i++) { for (i = 0; i < sk_CONF_VALUE_num(sect); i++) {
ASN1_TYPE *typ = ASN1_TYPE *typ =
ASN1_generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf); generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf,
depth + 1, perr);
if (!typ) if (!typ)
goto bad; goto bad;
if (!sk_ASN1_TYPE_push(sk, typ)) if (!sk_ASN1_TYPE_push(sk, typ))