asn1_gen.c
Go to the documentation of this file.
1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young (eay@cryptsoft.com).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to. The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  * notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  * notice, this list of conditions and the following disclaimer in the
29  * documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  * must display the following acknowledgement:
32  * "This product includes cryptographic software written by
33  * Eric Young (eay@cryptsoft.com)"
34  * The word 'cryptographic' can be left out if the rouines from the library
35  * being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  * the apps directory (application code) you must include an acknowledgement:
38  * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed. i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.] */
56 
57 #include <openssl/x509.h>
58 
59 #include <string.h>
60 
61 #include <openssl/asn1.h>
62 #include <openssl/err.h>
63 #include <openssl/mem.h>
64 #include <openssl/obj.h>
65 #include <openssl/x509v3.h>
66 
67 #include "../internal.h"
68 #include "../x509v3/internal.h"
69 #include "internal.h"
70 
71 /*
72  * Although this file is in crypto/x509 for layering purposes, it emits
73  * errors from the ASN.1 module for OpenSSL compatibility.
74  */
75 
76 #define ASN1_GEN_FLAG 0x10000
77 #define ASN1_GEN_FLAG_IMP (ASN1_GEN_FLAG|1)
78 #define ASN1_GEN_FLAG_EXP (ASN1_GEN_FLAG|2)
79 #define ASN1_GEN_FLAG_TAG (ASN1_GEN_FLAG|3)
80 #define ASN1_GEN_FLAG_BITWRAP (ASN1_GEN_FLAG|4)
81 #define ASN1_GEN_FLAG_OCTWRAP (ASN1_GEN_FLAG|5)
82 #define ASN1_GEN_FLAG_SEQWRAP (ASN1_GEN_FLAG|6)
83 #define ASN1_GEN_FLAG_SETWRAP (ASN1_GEN_FLAG|7)
84 #define ASN1_GEN_FLAG_FORMAT (ASN1_GEN_FLAG|8)
85 
86 #define ASN1_GEN_STR(str,val) {str, sizeof(str) - 1, val}
87 
88 #define ASN1_FLAG_EXP_MAX 20
89 /* Maximum number of nested sequences */
90 #define ASN1_GEN_SEQ_MAX_DEPTH 50
91 
92 /* Input formats */
93 
94 /* ASCII: default */
95 #define ASN1_GEN_FORMAT_ASCII 1
96 /* UTF8 */
97 #define ASN1_GEN_FORMAT_UTF8 2
98 /* Hex */
99 #define ASN1_GEN_FORMAT_HEX 3
100 /* List of bits */
101 #define ASN1_GEN_FORMAT_BITLIST 4
102 
103 struct tag_name_st {
104  const char *strnam;
105  int len;
106  int tag;
107 };
108 
109 typedef struct {
110  int exp_tag;
113  int exp_pad;
114  long exp_len;
115 } tag_exp_type;
116 
117 typedef struct {
118  int imp_tag;
120  int utype;
121  int format;
122  const char *str;
125 } tag_exp_arg;
126 
127 static ASN1_TYPE *generate_v3(const char *str, X509V3_CTX *cnf, int depth,
128  int *perr);
129 static int bitstr_cb(const char *elem, int len, void *bitstr);
130 static int asn1_cb(const char *elem, int len, void *bitstr);
131 static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class,
132  int exp_constructed, int exp_pad, int imp_ok);
133 static int parse_tagging(const char *vstart, int vlen, int *ptag,
134  int *pclass);
135 static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf,
136  int depth, int *perr);
137 static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype);
138 static int asn1_str2tag(const char *tagstr, int len);
139 
141 {
142  int err = 0;
143  ASN1_TYPE *ret = generate_v3(str, cnf, 0, &err);
144  if (err)
145  OPENSSL_PUT_ERROR(ASN1, err);
146  return ret;
147 }
148 
149 static ASN1_TYPE *generate_v3(const char *str, X509V3_CTX *cnf, int depth,
150  int *perr)
151 {
152  ASN1_TYPE *ret;
153  tag_exp_arg asn1_tags;
154  tag_exp_type *etmp;
155 
156  int i, len;
157 
158  unsigned char *orig_der = NULL, *new_der = NULL;
159  const unsigned char *cpy_start;
160  unsigned char *p;
161  const unsigned char *cp;
162  int cpy_len;
163  long hdr_len = 0;
164  int hdr_constructed = 0, hdr_tag, hdr_class;
165  int r;
166 
167  asn1_tags.imp_tag = -1;
168  asn1_tags.imp_class = -1;
169  asn1_tags.format = ASN1_GEN_FORMAT_ASCII;
170  asn1_tags.exp_count = 0;
171  if (CONF_parse_list(str, ',', 1, asn1_cb, &asn1_tags) != 0) {
172  *perr = ASN1_R_UNKNOWN_TAG;
173  return NULL;
174  }
175 
176  if ((asn1_tags.utype == V_ASN1_SEQUENCE)
177  || (asn1_tags.utype == V_ASN1_SET)) {
178  if (!cnf) {
180  return NULL;
181  }
182  if (depth >= ASN1_GEN_SEQ_MAX_DEPTH) {
184  return NULL;
185  }
186  ret = asn1_multi(asn1_tags.utype, asn1_tags.str, cnf, depth, perr);
187  } else
188  ret = asn1_str2type(asn1_tags.str, asn1_tags.format, asn1_tags.utype);
189 
190  if (!ret)
191  return NULL;
192 
193  /* If no tagging return base type */
194  if ((asn1_tags.imp_tag == -1) && (asn1_tags.exp_count == 0))
195  return ret;
196 
197  /* Generate the encoding */
198  cpy_len = i2d_ASN1_TYPE(ret, &orig_der);
200  ret = NULL;
201  /* Set point to start copying for modified encoding */
202  cpy_start = orig_der;
203 
204  /* Do we need IMPLICIT tagging? */
205  if (asn1_tags.imp_tag != -1) {
206  /* If IMPLICIT we will replace the underlying tag */
207  /* Skip existing tag+len */
208  r = ASN1_get_object(&cpy_start, &hdr_len, &hdr_tag, &hdr_class,
209  cpy_len);
210  if (r & 0x80)
211  goto err;
212  /* Update copy length */
213  cpy_len -= cpy_start - orig_der;
214  /*
215  * For IMPLICIT tagging the length should match the original length
216  * and constructed flag should be consistent.
217  */
218  hdr_constructed = r & V_ASN1_CONSTRUCTED;
219  /*
220  * Work out new length with IMPLICIT tag: ignore constructed because
221  * it will mess up if indefinite length
222  */
223  len = ASN1_object_size(0, hdr_len, asn1_tags.imp_tag);
224  } else
225  len = cpy_len;
226 
227  /* Work out length in any EXPLICIT, starting from end */
228 
229  for (i = 0, etmp = asn1_tags.exp_list + asn1_tags.exp_count - 1;
230  i < asn1_tags.exp_count; i++, etmp--) {
231  /* Content length: number of content octets + any padding */
232  len += etmp->exp_pad;
233  etmp->exp_len = len;
234  /* Total object length: length including new header */
235  len = ASN1_object_size(0, len, etmp->exp_tag);
236  }
237 
238  /* Allocate buffer for new encoding */
239 
240  new_der = OPENSSL_malloc(len);
241  if (!new_der)
242  goto err;
243 
244  /* Generate tagged encoding */
245 
246  p = new_der;
247 
248  /* Output explicit tags first */
249 
250  for (i = 0, etmp = asn1_tags.exp_list; i < asn1_tags.exp_count;
251  i++, etmp++) {
252  ASN1_put_object(&p, etmp->exp_constructed, etmp->exp_len,
253  etmp->exp_tag, etmp->exp_class);
254  if (etmp->exp_pad)
255  *p++ = 0;
256  }
257 
258  /* If IMPLICIT, output tag */
259 
260  if (asn1_tags.imp_tag != -1) {
261  if (asn1_tags.imp_class == V_ASN1_UNIVERSAL
262  && (asn1_tags.imp_tag == V_ASN1_SEQUENCE
263  || asn1_tags.imp_tag == V_ASN1_SET))
264  hdr_constructed = V_ASN1_CONSTRUCTED;
265  ASN1_put_object(&p, hdr_constructed, hdr_len,
266  asn1_tags.imp_tag, asn1_tags.imp_class);
267  }
268 
269  /* Copy across original encoding */
270  OPENSSL_memcpy(p, cpy_start, cpy_len);
271 
272  cp = new_der;
273 
274  /* Obtain new ASN1_TYPE structure */
275  ret = d2i_ASN1_TYPE(NULL, &cp, len);
276 
277  err:
278  if (orig_der)
279  OPENSSL_free(orig_der);
280  if (new_der)
281  OPENSSL_free(new_der);
282 
283  return ret;
284 
285 }
286 
287 static int asn1_cb(const char *elem, int len, void *bitstr)
288 {
289  tag_exp_arg *arg = bitstr;
290  int i;
291  int utype;
292  int vlen = 0;
293  const char *p, *vstart = NULL;
294 
295  int tmp_tag, tmp_class;
296 
297  if (elem == NULL)
298  return -1;
299 
300  for (i = 0, p = elem; i < len; p++, i++) {
301  /* Look for the ':' in name value pairs */
302  if (*p == ':') {
303  vstart = p + 1;
304  vlen = len - (vstart - elem);
305  len = p - elem;
306  break;
307  }
308  }
309 
310  utype = asn1_str2tag(elem, len);
311 
312  if (utype == -1) {
314  ERR_add_error_data(2, "tag=", elem);
315  return -1;
316  }
317 
318  /* If this is not a modifier mark end of string and exit */
319  if (!(utype & ASN1_GEN_FLAG)) {
320  arg->utype = utype;
321  arg->str = vstart;
322  /* If no value and not end of string, error */
323  if (!vstart && elem[len]) {
325  return -1;
326  }
327  return 0;
328  }
329 
330  switch (utype) {
331 
332  case ASN1_GEN_FLAG_IMP:
333  /* Check for illegal multiple IMPLICIT tagging */
334  if (arg->imp_tag != -1) {
336  return -1;
337  }
338  if (!parse_tagging(vstart, vlen, &arg->imp_tag, &arg->imp_class))
339  return -1;
340  break;
341 
342  case ASN1_GEN_FLAG_EXP:
343 
344  if (!parse_tagging(vstart, vlen, &tmp_tag, &tmp_class))
345  return -1;
346  if (!append_exp(arg, tmp_tag, tmp_class, 1, 0, 0))
347  return -1;
348  break;
349 
352  return -1;
353  break;
354 
356  if (!append_exp(arg, V_ASN1_SET, V_ASN1_UNIVERSAL, 1, 0, 1))
357  return -1;
358  break;
359 
362  return -1;
363  break;
364 
367  return -1;
368  break;
369 
371  if (!vstart) {
373  return -1;
374  }
375  if (!strncmp(vstart, "ASCII", 5))
376  arg->format = ASN1_GEN_FORMAT_ASCII;
377  else if (!strncmp(vstart, "UTF8", 4))
378  arg->format = ASN1_GEN_FORMAT_UTF8;
379  else if (!strncmp(vstart, "HEX", 3))
380  arg->format = ASN1_GEN_FORMAT_HEX;
381  else if (!strncmp(vstart, "BITLIST", 7))
382  arg->format = ASN1_GEN_FORMAT_BITLIST;
383  else {
385  return -1;
386  }
387  break;
388 
389  }
390 
391  return 1;
392 
393 }
394 
395 static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
396 {
397  char erch[2];
398  long tag_num;
399  char *eptr;
400  if (!vstart)
401  return 0;
402  tag_num = strtoul(vstart, &eptr, 10);
403  /* Check we haven't gone past max length: should be impossible */
404  if (eptr && *eptr && (eptr > vstart + vlen))
405  return 0;
406  if (tag_num < 0) {
408  return 0;
409  }
410  *ptag = tag_num;
411  /* If we have non numeric characters, parse them */
412  if (eptr)
413  vlen -= eptr - vstart;
414  else
415  vlen = 0;
416  if (vlen) {
417  switch (*eptr) {
418 
419  case 'U':
420  *pclass = V_ASN1_UNIVERSAL;
421  break;
422 
423  case 'A':
424  *pclass = V_ASN1_APPLICATION;
425  break;
426 
427  case 'P':
428  *pclass = V_ASN1_PRIVATE;
429  break;
430 
431  case 'C':
432  *pclass = V_ASN1_CONTEXT_SPECIFIC;
433  break;
434 
435  default:
436  erch[0] = *eptr;
437  erch[1] = 0;
439  ERR_add_error_data(2, "Char=", erch);
440  return 0;
441  break;
442 
443  }
444  } else
445  *pclass = V_ASN1_CONTEXT_SPECIFIC;
446 
447  return 1;
448 
449 }
450 
451 /* Handle multiple types: SET and SEQUENCE */
452 
453 static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf,
454  int depth, int *perr)
455 {
456  ASN1_TYPE *ret = NULL;
457  STACK_OF(ASN1_TYPE) *sk = NULL;
458  STACK_OF(CONF_VALUE) *sect = NULL;
459  unsigned char *der = NULL;
460  int derlen;
461  size_t i;
462  sk = sk_ASN1_TYPE_new_null();
463  if (!sk)
464  goto bad;
465  if (section) {
466  if (!cnf)
467  goto bad;
468  sect = X509V3_get_section(cnf, (char *)section);
469  if (!sect)
470  goto bad;
471  for (i = 0; i < sk_CONF_VALUE_num(sect); i++) {
472  ASN1_TYPE *typ =
473  generate_v3(sk_CONF_VALUE_value(sect, i)->value, cnf,
474  depth + 1, perr);
475  if (!typ)
476  goto bad;
477  if (!sk_ASN1_TYPE_push(sk, typ))
478  goto bad;
479  }
480  }
481 
482  /*
483  * Now we has a STACK of the components, convert to the correct form
484  */
485 
486  if (utype == V_ASN1_SET)
487  derlen = i2d_ASN1_SET_ANY(sk, &der);
488  else
489  derlen = i2d_ASN1_SEQUENCE_ANY(sk, &der);
490 
491  if (derlen < 0)
492  goto bad;
493 
494  if (!(ret = ASN1_TYPE_new()))
495  goto bad;
496 
497  if (!(ret->value.asn1_string = ASN1_STRING_type_new(utype)))
498  goto bad;
499 
500  ret->type = utype;
501 
502  ret->value.asn1_string->data = der;
503  ret->value.asn1_string->length = derlen;
504 
505  der = NULL;
506 
507  bad:
508 
509  if (der)
510  OPENSSL_free(der);
511 
512  if (sk)
513  sk_ASN1_TYPE_pop_free(sk, ASN1_TYPE_free);
514  if (sect)
515  X509V3_section_free(cnf, sect);
516 
517  return ret;
518 }
519 
520 static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class,
521  int exp_constructed, int exp_pad, int imp_ok)
522 {
523  tag_exp_type *exp_tmp;
524  /* Can only have IMPLICIT if permitted */
525  if ((arg->imp_tag != -1) && !imp_ok) {
527  return 0;
528  }
529 
530  if (arg->exp_count == ASN1_FLAG_EXP_MAX) {
532  return 0;
533  }
534 
535  exp_tmp = &arg->exp_list[arg->exp_count++];
536 
537  /*
538  * If IMPLICIT set tag to implicit value then reset implicit tag since it
539  * has been used.
540  */
541  if (arg->imp_tag != -1) {
542  exp_tmp->exp_tag = arg->imp_tag;
543  exp_tmp->exp_class = arg->imp_class;
544  arg->imp_tag = -1;
545  arg->imp_class = -1;
546  } else {
547  exp_tmp->exp_tag = exp_tag;
548  exp_tmp->exp_class = exp_class;
549  }
550  exp_tmp->exp_constructed = exp_constructed;
551  exp_tmp->exp_pad = exp_pad;
552 
553  return 1;
554 }
555 
556 static int asn1_str2tag(const char *tagstr, int len)
557 {
558  unsigned int i;
559  static const struct tag_name_st *tntmp, tnst[] = {
560  ASN1_GEN_STR("BOOL", V_ASN1_BOOLEAN),
561  ASN1_GEN_STR("BOOLEAN", V_ASN1_BOOLEAN),
562  ASN1_GEN_STR("NULL", V_ASN1_NULL),
564  ASN1_GEN_STR("INTEGER", V_ASN1_INTEGER),
566  ASN1_GEN_STR("ENUMERATED", V_ASN1_ENUMERATED),
567  ASN1_GEN_STR("OID", V_ASN1_OBJECT),
568  ASN1_GEN_STR("OBJECT", V_ASN1_OBJECT),
569  ASN1_GEN_STR("UTCTIME", V_ASN1_UTCTIME),
571  ASN1_GEN_STR("GENERALIZEDTIME", V_ASN1_GENERALIZEDTIME),
574  ASN1_GEN_STR("OCTETSTRING", V_ASN1_OCTET_STRING),
575  ASN1_GEN_STR("BITSTR", V_ASN1_BIT_STRING),
576  ASN1_GEN_STR("BITSTRING", V_ASN1_BIT_STRING),
577  ASN1_GEN_STR("UNIVERSALSTRING", V_ASN1_UNIVERSALSTRING),
580  ASN1_GEN_STR("IA5STRING", V_ASN1_IA5STRING),
582  ASN1_GEN_STR("UTF8String", V_ASN1_UTF8STRING),
584  ASN1_GEN_STR("BMPSTRING", V_ASN1_BMPSTRING),
585  ASN1_GEN_STR("VISIBLESTRING", V_ASN1_VISIBLESTRING),
587  ASN1_GEN_STR("PRINTABLESTRING", V_ASN1_PRINTABLESTRING),
588  ASN1_GEN_STR("PRINTABLE", V_ASN1_PRINTABLESTRING),
590  ASN1_GEN_STR("T61STRING", V_ASN1_T61STRING),
591  ASN1_GEN_STR("TELETEXSTRING", V_ASN1_T61STRING),
592  ASN1_GEN_STR("GeneralString", V_ASN1_GENERALSTRING),
595  ASN1_GEN_STR("NUMERICSTRING", V_ASN1_NUMERICSTRING),
596 
597  /* Special cases */
598  ASN1_GEN_STR("SEQUENCE", V_ASN1_SEQUENCE),
600  ASN1_GEN_STR("SET", V_ASN1_SET),
601  /* type modifiers */
602  /* Explicit tag */
604  ASN1_GEN_STR("EXPLICIT", ASN1_GEN_FLAG_EXP),
605  /* Implicit tag */
607  ASN1_GEN_STR("IMPLICIT", ASN1_GEN_FLAG_IMP),
608  /* OCTET STRING wrapper */
610  /* SEQUENCE wrapper */
612  /* SET wrapper */
614  /* BIT STRING wrapper */
618  };
619 
620  if (len == -1)
621  len = strlen(tagstr);
622 
623  tntmp = tnst;
624  for (i = 0; i < sizeof(tnst) / sizeof(struct tag_name_st); i++, tntmp++) {
625  if ((len == tntmp->len) && !strncmp(tntmp->strnam, tagstr, len))
626  return tntmp->tag;
627  }
628 
629  return -1;
630 }
631 
632 static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype)
633 {
634  ASN1_TYPE *atmp = NULL;
635 
636  CONF_VALUE vtmp;
637 
638  unsigned char *rdata;
639  long rdlen;
640 
641  int no_unused = 1;
642 
643  if (!(atmp = ASN1_TYPE_new())) {
645  return NULL;
646  }
647 
648  if (!str)
649  str = "";
650 
651  switch (utype) {
652 
653  case V_ASN1_NULL:
654  if (str && *str) {
656  goto bad_form;
657  }
658  break;
659 
660  case V_ASN1_BOOLEAN:
661  if (format != ASN1_GEN_FORMAT_ASCII) {
663  goto bad_form;
664  }
665  vtmp.name = NULL;
666  vtmp.section = NULL;
667  vtmp.value = (char *)str;
668  if (!X509V3_get_value_bool(&vtmp, &atmp->value.boolean)) {
670  goto bad_str;
671  }
672  break;
673 
674  case V_ASN1_INTEGER:
675  case V_ASN1_ENUMERATED:
676  if (format != ASN1_GEN_FORMAT_ASCII) {
678  goto bad_form;
679  }
680  if (!(atmp->value.integer = s2i_ASN1_INTEGER(NULL, (char *)str))) {
682  goto bad_str;
683  }
684  break;
685 
686  case V_ASN1_OBJECT:
687  if (format != ASN1_GEN_FORMAT_ASCII) {
689  goto bad_form;
690  }
691  if (!(atmp->value.object = OBJ_txt2obj(str, 0))) {
693  goto bad_str;
694  }
695  break;
696 
697  case V_ASN1_UTCTIME:
699  if (format != ASN1_GEN_FORMAT_ASCII) {
701  goto bad_form;
702  }
703  if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
705  goto bad_str;
706  }
707  if (!ASN1_STRING_set(atmp->value.asn1_string, str, -1)) {
709  goto bad_str;
710  }
711  atmp->value.asn1_string->type = utype;
712  if (!ASN1_TIME_check(atmp->value.asn1_string)) {
714  goto bad_str;
715  }
716 
717  break;
718 
719  case V_ASN1_BMPSTRING:
721  case V_ASN1_IA5STRING:
722  case V_ASN1_T61STRING:
723  case V_ASN1_UTF8STRING:
728 
731  else if (format == ASN1_GEN_FORMAT_UTF8)
733  else {
735  goto bad_form;
736  }
737 
738  if (ASN1_mbstring_copy(&atmp->value.asn1_string, (unsigned char *)str,
739  -1, format, ASN1_tag2bit(utype)) <= 0) {
741  goto bad_str;
742  }
743 
744  break;
745 
746  case V_ASN1_BIT_STRING:
747 
748  case V_ASN1_OCTET_STRING:
749 
750  if (!(atmp->value.asn1_string = ASN1_STRING_new())) {
752  goto bad_form;
753  }
754 
755  if (format == ASN1_GEN_FORMAT_HEX) {
756 
757  if (!(rdata = x509v3_hex_to_bytes((char *)str, &rdlen))) {
759  goto bad_str;
760  }
761 
762  atmp->value.asn1_string->data = rdata;
763  atmp->value.asn1_string->length = rdlen;
764  atmp->value.asn1_string->type = utype;
765 
766  } else if (format == ASN1_GEN_FORMAT_ASCII)
767  ASN1_STRING_set(atmp->value.asn1_string, str, -1);
768  else if ((format == ASN1_GEN_FORMAT_BITLIST)
769  && (utype == V_ASN1_BIT_STRING)) {
770  if (!CONF_parse_list
771  (str, ',', 1, bitstr_cb, atmp->value.bit_string)) {
773  goto bad_str;
774  }
775  no_unused = 0;
776 
777  } else {
779  goto bad_form;
780  }
781 
782  if ((utype == V_ASN1_BIT_STRING) && no_unused) {
783  atmp->value.asn1_string->flags
784  &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07);
786  }
787 
788  break;
789 
790  default:
792  goto bad_str;
793  break;
794  }
795 
796  atmp->type = utype;
797  return atmp;
798 
799  bad_str:
800  ERR_add_error_data(2, "string=", str);
801  bad_form:
802 
803  ASN1_TYPE_free(atmp);
804  return NULL;
805 
806 }
807 
808 static int bitstr_cb(const char *elem, int len, void *bitstr)
809 {
810  long bitnum;
811  char *eptr;
812  if (!elem)
813  return 0;
814  bitnum = strtoul(elem, &eptr, 10);
815  if (eptr && *eptr && (eptr != elem + len))
816  return 0;
817  if (bitnum < 0) {
819  return 0;
820  }
821  if (!ASN1_BIT_STRING_set_bit(bitstr, bitnum, 1)) {
823  return 0;
824  }
825  return 1;
826 }
conf_value_st::section
char * section
Definition: conf.h:83
xds_interop_client.str
str
Definition: xds_interop_client.py:487
tag_exp_type::exp_class
int exp_class
Definition: asn1_gen.c:111
asn1_type_st::asn1_string
ASN1_STRING * asn1_string
Definition: asn1.h:1486
asn1_type_st::object
ASN1_OBJECT * object
Definition: asn1.h:1487
ASN1_GEN_FLAG_OCTWRAP
#define ASN1_GEN_FLAG_OCTWRAP
Definition: asn1_gen.c:81
tag_name_st
Definition: asn1_gen.c:103
check_banned_filenames.bad
bad
Definition: check_banned_filenames.py:26
http2_test_server.format
format
Definition: http2_test_server.py:118
ASN1_put_object
#define ASN1_put_object
Definition: boringssl_prefix_symbols.h:761
tag_exp_arg::utype
int utype
Definition: asn1_gen.c:120
generate_v3
static ASN1_TYPE * generate_v3(const char *str, X509V3_CTX *cnf, int depth, int *perr)
Definition: asn1_gen.c:149
v3_ext_ctx
Definition: x509v3.h:136
i2d_ASN1_TYPE
OPENSSL_EXPORT int i2d_ASN1_TYPE(const ASN1_TYPE *in, uint8_t **outp)
ASN1_R_INVALID_MODIFIER
#define ASN1_R_INVALID_MODIFIER
Definition: asn1.h:1987
tag_name_st::len
int len
Definition: asn1_gen.c:105
asn1_type_st::boolean
ASN1_BOOLEAN boolean
Definition: asn1.h:1485
ASN1_GEN_FLAG_BITWRAP
#define ASN1_GEN_FLAG_BITWRAP
Definition: asn1_gen.c:80
V_ASN1_PRINTABLESTRING
#define V_ASN1_PRINTABLESTRING
Definition: asn1.h:139
tag_exp_arg
Definition: asn1_gen.c:117
ASN1_R_ILLEGAL_OBJECT
#define ASN1_R_ILLEGAL_OBJECT
Definition: asn1.h:1977
ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG
#define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG
Definition: asn1.h:2013
OPENSSL_PUT_ERROR
#define OPENSSL_PUT_ERROR(library, reason)
Definition: err.h:423
internal.h
string.h
V_ASN1_SEQUENCE
#define V_ASN1_SEQUENCE
Definition: asn1.h:136
CONF_parse_list
#define CONF_parse_list
Definition: boringssl_prefix_symbols.h:1108
x509v3_hex_to_bytes
#define x509v3_hex_to_bytes
Definition: boringssl_prefix_symbols.h:3460
ASN1_STRING_type_new
#define ASN1_STRING_type_new
Definition: boringssl_prefix_symbols.h:695
elem
Timer elem
Definition: event_engine/iomgr_event_engine/timer_heap_test.cc:109
ASN1_R_ILLEGAL_IMPLICIT_TAG
#define ASN1_R_ILLEGAL_IMPLICIT_TAG
Definition: asn1.h:1972
error_ref_leak.err
err
Definition: error_ref_leak.py:35
V_ASN1_SET
#define V_ASN1_SET
Definition: asn1.h:137
V_ASN1_UTF8STRING
#define V_ASN1_UTF8STRING
Definition: asn1.h:135
tag_exp_type::exp_tag
int exp_tag
Definition: asn1_gen.c:110
x509v3.h
X509V3_get_section
#define X509V3_get_section
Definition: boringssl_prefix_symbols.h:2241
V_ASN1_OCTET_STRING
#define V_ASN1_OCTET_STRING
Definition: asn1.h:128
ASN1_R_INTEGER_NOT_ASCII_FORMAT
#define ASN1_R_INTEGER_NOT_ASCII_FORMAT
Definition: asn1.h:1982
asn1_cb
static int asn1_cb(const char *elem, int len, void *bitstr)
Definition: asn1_gen.c:287
ASN1_R_INVALID_NUMBER
#define ASN1_R_INVALID_NUMBER
Definition: asn1.h:1988
tag_exp_type
Definition: asn1_gen.c:109
ASN1_GEN_FORMAT_UTF8
#define ASN1_GEN_FORMAT_UTF8
Definition: asn1_gen.c:97
ASN1_BIT_STRING_set_bit
#define ASN1_BIT_STRING_set_bit
Definition: boringssl_prefix_symbols.h:616
ASN1_GEN_FLAG_FORMAT
#define ASN1_GEN_FLAG_FORMAT
Definition: asn1_gen.c:84
xds_manager.p
p
Definition: xds_manager.py:60
ASN1_R_ILLEGAL_BOOLEAN
#define ASN1_R_ILLEGAL_BOOLEAN
Definition: asn1.h:1968
tag_exp_arg::imp_tag
int imp_tag
Definition: asn1_gen.c:118
ASN1_R_MISSING_VALUE
#define ASN1_R_MISSING_VALUE
Definition: asn1.h:1998
ASN1_R_UNKNOWN_TAG
#define ASN1_R_UNKNOWN_TAG
Definition: asn1.h:2028
V_ASN1_GENERALSTRING
#define V_ASN1_GENERALSTRING
Definition: asn1.h:149
asn1_string_st::data
unsigned char * data
Definition: asn1.h:546
ASN1_R_TIME_NOT_ASCII_FORMAT
#define ASN1_R_TIME_NOT_ASCII_FORMAT
Definition: asn1.h:2019
ASN1_STRING_new
#define ASN1_STRING_new
Definition: boringssl_prefix_symbols.h:684
V_ASN1_GENERALIZEDTIME
#define V_ASN1_GENERALIZEDTIME
Definition: asn1.h:145
OPENSSL_malloc
#define OPENSSL_malloc
Definition: boringssl_prefix_symbols.h:1885
asn1_string_st::flags
long flags
Definition: asn1.h:547
ASN1_R_UNKNOWN_FORMAT
#define ASN1_R_UNKNOWN_FORMAT
Definition: asn1.h:2025
V_ASN1_BMPSTRING
#define V_ASN1_BMPSTRING
Definition: asn1.h:151
ASN1_GEN_FORMAT_BITLIST
#define ASN1_GEN_FORMAT_BITLIST
Definition: asn1_gen.c:101
ASN1_STRING_set
#define ASN1_STRING_set
Definition: boringssl_prefix_symbols.h:688
asn1_type_st::type
int type
Definition: asn1.h:1482
ASN1_GEN_STR
#define ASN1_GEN_STR(str, val)
Definition: asn1_gen.c:86
V_ASN1_UNIVERSAL
#define V_ASN1_UNIVERSAL
Definition: asn1.h:92
asn1_type_st::bit_string
ASN1_BIT_STRING * bit_string
Definition: asn1.h:1490
ASN1_FLAG_EXP_MAX
#define ASN1_FLAG_EXP_MAX
Definition: asn1_gen.c:88
conf_value_st::value
char * value
Definition: conf.h:85
STACK_OF
#define STACK_OF(type)
Definition: stack.h:125
V_ASN1_ENUMERATED
#define V_ASN1_ENUMERATED
Definition: asn1.h:134
asn1_string_st::length
int length
Definition: asn1.h:544
ASN1_R_UNSUPPORTED_TYPE
#define ASN1_R_UNSUPPORTED_TYPE
Definition: asn1.h:2031
asn1_str2tag
static int asn1_str2tag(const char *tagstr, int len)
Definition: asn1_gen.c:556
bitstr_cb
static int bitstr_cb(const char *elem, int len, void *bitstr)
Definition: asn1_gen.c:808
ASN1_TYPE_free
OPENSSL_EXPORT void ASN1_TYPE_free(ASN1_TYPE *a)
ASN1_GEN_FLAG_EXP
#define ASN1_GEN_FLAG_EXP
Definition: asn1_gen.c:78
V_ASN1_VISIBLESTRING
#define V_ASN1_VISIBLESTRING
Definition: asn1.h:148
OBJ_txt2obj
#define OBJ_txt2obj
Definition: boringssl_prefix_symbols.h:1861
X509V3_section_free
#define X509V3_section_free
Definition: boringssl_prefix_symbols.h:2246
tag_exp_arg::str
const char * str
Definition: asn1_gen.c:122
tag_exp_arg::imp_class
int imp_class
Definition: asn1_gen.c:119
OPENSSL_memcpy
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
Definition: third_party/boringssl-with-bazel/src/crypto/internal.h:819
ASN1_R_ILLEGAL_TIME_VALUE
#define ASN1_R_ILLEGAL_TIME_VALUE
Definition: asn1.h:1981
ASN1_R_ILLEGAL_NULL_VALUE
#define ASN1_R_ILLEGAL_NULL_VALUE
Definition: asn1.h:1976
err.h
arg
Definition: cmdline.cc:40
V_ASN1_NUMERICSTRING
#define V_ASN1_NUMERICSTRING
Definition: asn1.h:138
d2i_ASN1_TYPE
OPENSSL_EXPORT ASN1_TYPE * d2i_ASN1_TYPE(ASN1_TYPE **out, const uint8_t **inp, long len)
ASN1_generate_v3
ASN1_TYPE * ASN1_generate_v3(const char *str, X509V3_CTX *cnf)
Definition: asn1_gen.c:140
MBSTRING_UTF8
#define MBSTRING_UTF8
Definition: asn1.h:722
ASN1_STRING_FLAG_BITS_LEFT
#define ASN1_STRING_FLAG_BITS_LEFT
Definition: asn1.h:554
ASN1_mbstring_copy
#define ASN1_mbstring_copy
Definition: boringssl_prefix_symbols.h:756
V_ASN1_BIT_STRING
#define V_ASN1_BIT_STRING
Definition: asn1.h:127
ASN1_R_ILLEGAL_INTEGER
#define ASN1_R_ILLEGAL_INTEGER
Definition: asn1.h:1973
V_ASN1_APPLICATION
#define V_ASN1_APPLICATION
Definition: asn1.h:93
ASN1_R_OBJECT_NOT_ASCII_FORMAT
#define ASN1_R_OBJECT_NOT_ASCII_FORMAT
Definition: asn1.h:2008
V_ASN1_CONSTRUCTED
#define V_ASN1_CONSTRUCTED
Definition: asn1.h:99
V_ASN1_UTCTIME
#define V_ASN1_UTCTIME
Definition: asn1.h:144
V_ASN1_BOOLEAN
#define V_ASN1_BOOLEAN
Definition: asn1.h:125
V_ASN1_IA5STRING
#define V_ASN1_IA5STRING
Definition: asn1.h:143
ASN1_GEN_FLAG_IMP
#define ASN1_GEN_FLAG_IMP
Definition: asn1_gen.c:77
section
Definition: loader.h:337
ASN1_tag2bit
#define ASN1_tag2bit
Definition: boringssl_prefix_symbols.h:762
asn1_str2type
static ASN1_TYPE * asn1_str2type(const char *str, int format, int utype)
Definition: asn1_gen.c:632
V_ASN1_T61STRING
#define V_ASN1_T61STRING
Definition: asn1.h:140
value
const char * value
Definition: hpack_parser_table.cc:165
ASN1_GEN_FORMAT_ASCII
#define ASN1_GEN_FORMAT_ASCII
Definition: asn1_gen.c:95
tag_name_st::tag
int tag
Definition: asn1_gen.c:106
ASN1_R_ILLEGAL_FORMAT
#define ASN1_R_ILLEGAL_FORMAT
Definition: asn1.h:1970
s2i_ASN1_INTEGER
#define s2i_ASN1_INTEGER
Definition: boringssl_prefix_symbols.h:3369
tag_exp_type::exp_pad
int exp_pad
Definition: asn1_gen.c:113
ASN1_GEN_SEQ_MAX_DEPTH
#define ASN1_GEN_SEQ_MAX_DEPTH
Definition: asn1_gen.c:90
ASN1_R_LIST_ERROR
#define ASN1_R_LIST_ERROR
Definition: asn1.h:1994
tag_exp_arg::exp_count
int exp_count
Definition: asn1_gen.c:124
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
fix_build_deps.r
r
Definition: fix_build_deps.py:491
V_ASN1_PRIVATE
#define V_ASN1_PRIVATE
Definition: asn1.h:95
ERR_add_error_data
#define ERR_add_error_data
Definition: boringssl_prefix_symbols.h:1411
ASN1_get_object
#define ASN1_get_object
Definition: boringssl_prefix_symbols.h:736
MBSTRING_ASC
#define MBSTRING_ASC
Definition: asn1.h:723
V_ASN1_NULL
#define V_ASN1_NULL
Definition: asn1.h:129
ASN1_TIME_check
#define ASN1_TIME_check
Definition: boringssl_prefix_symbols.h:701
V_ASN1_CONTEXT_SPECIFIC
#define V_ASN1_CONTEXT_SPECIFIC
Definition: asn1.h:94
ASN1_TYPE_new
OPENSSL_EXPORT ASN1_TYPE * ASN1_TYPE_new(void)
asn1_string_st::type
int type
Definition: asn1.h:545
X509V3_get_value_bool
#define X509V3_get_value_bool
Definition: boringssl_prefix_symbols.h:2243
tag_name_st::strnam
const char * strnam
Definition: asn1_gen.c:104
ASN1_R_ILLEGAL_BITSTRING_FORMAT
#define ASN1_R_ILLEGAL_BITSTRING_FORMAT
Definition: asn1.h:1967
obj.h
asn1_type_st::value
union asn1_type_st::@361 value
i2d_ASN1_SET_ANY
OPENSSL_EXPORT int i2d_ASN1_SET_ANY(const ASN1_SEQUENCE_ANY *in, uint8_t **outp)
append_exp
static int append_exp(tag_exp_arg *arg, int exp_tag, int exp_class, int exp_constructed, int exp_pad, int imp_ok)
Definition: asn1_gen.c:520
ASN1_GEN_FLAG_SEQWRAP
#define ASN1_GEN_FLAG_SEQWRAP
Definition: asn1_gen.c:82
ASN1_R_ILLEGAL_NESTED_TAGGING
#define ASN1_R_ILLEGAL_NESTED_TAGGING
Definition: asn1.h:1974
parse_tagging
static int parse_tagging(const char *vstart, int vlen, int *ptag, int *pclass)
Definition: asn1_gen.c:395
mem.h
ASN1_GEN_FLAG
#define ASN1_GEN_FLAG
Definition: asn1_gen.c:76
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
asn1_type_st
Definition: asn1.h:1481
tag_exp_type::exp_constructed
int exp_constructed
Definition: asn1_gen.c:112
ASN1_R_DEPTH_EXCEEDED
#define ASN1_R_DEPTH_EXCEEDED
Definition: asn1.h:1953
tag_exp_arg::exp_list
tag_exp_type exp_list[ASN1_FLAG_EXP_MAX]
Definition: asn1_gen.c:123
mkowners.depth
depth
Definition: mkowners.py:114
ASN1_object_size
#define ASN1_object_size
Definition: boringssl_prefix_symbols.h:758
asn1_type_st::integer
ASN1_INTEGER * integer
Definition: asn1.h:1488
ASN1_GEN_FLAG_SETWRAP
#define ASN1_GEN_FLAG_SETWRAP
Definition: asn1_gen.c:83
OPENSSL_free
#define OPENSSL_free
Definition: boringssl_prefix_symbols.h:1869
V_ASN1_OBJECT
#define V_ASN1_OBJECT
Definition: asn1.h:130
ASN1_R_ILLEGAL_HEX
#define ASN1_R_ILLEGAL_HEX
Definition: asn1.h:1971
V_ASN1_UNIVERSALSTRING
#define V_ASN1_UNIVERSALSTRING
Definition: asn1.h:150
asn1_multi
static ASN1_TYPE * asn1_multi(int utype, const char *section, X509V3_CTX *cnf, int depth, int *perr)
Definition: asn1_gen.c:453
ASN1_R_NOT_ASCII_FORMAT
#define ASN1_R_NOT_ASCII_FORMAT
Definition: asn1.h:2004
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
asn1.h
ERR_R_MALLOC_FAILURE
#define ERR_R_MALLOC_FAILURE
Definition: err.h:371
i2d_ASN1_SEQUENCE_ANY
OPENSSL_EXPORT int i2d_ASN1_SEQUENCE_ANY(const ASN1_SEQUENCE_ANY *in, uint8_t **outp)
tag_exp_arg::format
int format
Definition: asn1_gen.c:121
conf_value_st
Definition: conf.h:82
ASN1_GEN_FORMAT_HEX
#define ASN1_GEN_FORMAT_HEX
Definition: asn1_gen.c:99
tag_exp_type::exp_len
long exp_len
Definition: asn1_gen.c:114
x509.h
conf_value_st::name
char * name
Definition: conf.h:84
V_ASN1_INTEGER
#define V_ASN1_INTEGER
Definition: asn1.h:126


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:44