blob: 8ee5b0c8586a50100071cec8b80e14197e953962 [file] [log] [blame]
Adam Langley95c29f32014-06-20 12:00:00 -07001/* 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
58#ifndef HEADER_ASN1_H
59#define HEADER_ASN1_H
60
61#include <openssl/base.h>
62
Adam Langley65a7e942015-05-07 18:28:27 -070063#include <time.h>
64
Adam Langley95c29f32014-06-20 12:00:00 -070065#include <openssl/bio.h>
Adam Langley95c29f32014-06-20 12:00:00 -070066#include <openssl/stack.h>
67
68#include <openssl/bn.h>
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
David Benjamin5e61d532017-01-05 21:01:49 -050074
75/* Legacy ASN.1 library.
76 *
77 * This header is part of OpenSSL's ASN.1 implementation. It is retained for
78 * compatibility but otherwise underdocumented and not actively maintained. Use
79 * the new |CBS| and |CBB| library in <openssl/bytestring.h> instead. */
80
81
Adam Langley95c29f32014-06-20 12:00:00 -070082#define V_ASN1_UNIVERSAL 0x00
83#define V_ASN1_APPLICATION 0x40
84#define V_ASN1_CONTEXT_SPECIFIC 0x80
85#define V_ASN1_PRIVATE 0xc0
86
87#define V_ASN1_CONSTRUCTED 0x20
88#define V_ASN1_PRIMITIVE_TAG 0x1f
89#define V_ASN1_PRIMATIVE_TAG 0x1f
90
91#define V_ASN1_APP_CHOOSE -2 /* let the recipient choose */
92#define V_ASN1_OTHER -3 /* used in ASN1_TYPE */
93#define V_ASN1_ANY -4 /* used in ASN1 template code */
94
95#define V_ASN1_NEG 0x100 /* negative flag */
David Benjaminfb2c6f82016-02-29 15:42:59 -050096/* No supported universal tags may exceed this value, to avoid ambiguity with
97 * V_ASN1_NEG. */
98#define V_ASN1_MAX_UNIVERSAL 0xff
Adam Langley95c29f32014-06-20 12:00:00 -070099
100#define V_ASN1_UNDEF -1
101#define V_ASN1_EOC 0
102#define V_ASN1_BOOLEAN 1 /**/
103#define V_ASN1_INTEGER 2
104#define V_ASN1_NEG_INTEGER (2 | V_ASN1_NEG)
105#define V_ASN1_BIT_STRING 3
106#define V_ASN1_OCTET_STRING 4
107#define V_ASN1_NULL 5
108#define V_ASN1_OBJECT 6
109#define V_ASN1_OBJECT_DESCRIPTOR 7
110#define V_ASN1_EXTERNAL 8
111#define V_ASN1_REAL 9
112#define V_ASN1_ENUMERATED 10
113#define V_ASN1_NEG_ENUMERATED (10 | V_ASN1_NEG)
114#define V_ASN1_UTF8STRING 12
115#define V_ASN1_SEQUENCE 16
116#define V_ASN1_SET 17
117#define V_ASN1_NUMERICSTRING 18 /**/
118#define V_ASN1_PRINTABLESTRING 19
119#define V_ASN1_T61STRING 20
120#define V_ASN1_TELETEXSTRING 20 /* alias */
121#define V_ASN1_VIDEOTEXSTRING 21 /**/
122#define V_ASN1_IA5STRING 22
123#define V_ASN1_UTCTIME 23
124#define V_ASN1_GENERALIZEDTIME 24 /**/
125#define V_ASN1_GRAPHICSTRING 25 /**/
126#define V_ASN1_ISO64STRING 26 /**/
127#define V_ASN1_VISIBLESTRING 26 /* alias */
128#define V_ASN1_GENERALSTRING 27 /**/
129#define V_ASN1_UNIVERSALSTRING 28 /**/
130#define V_ASN1_BMPSTRING 30
131
132/* For use with d2i_ASN1_type_bytes() */
133#define B_ASN1_NUMERICSTRING 0x0001
134#define B_ASN1_PRINTABLESTRING 0x0002
135#define B_ASN1_T61STRING 0x0004
136#define B_ASN1_TELETEXSTRING 0x0004
137#define B_ASN1_VIDEOTEXSTRING 0x0008
138#define B_ASN1_IA5STRING 0x0010
139#define B_ASN1_GRAPHICSTRING 0x0020
140#define B_ASN1_ISO64STRING 0x0040
141#define B_ASN1_VISIBLESTRING 0x0040
142#define B_ASN1_GENERALSTRING 0x0080
143#define B_ASN1_UNIVERSALSTRING 0x0100
144#define B_ASN1_OCTET_STRING 0x0200
145#define B_ASN1_BIT_STRING 0x0400
146#define B_ASN1_BMPSTRING 0x0800
147#define B_ASN1_UNKNOWN 0x1000
148#define B_ASN1_UTF8STRING 0x2000
149#define B_ASN1_UTCTIME 0x4000
150#define B_ASN1_GENERALIZEDTIME 0x8000
151#define B_ASN1_SEQUENCE 0x10000
152
153/* For use with ASN1_mbstring_copy() */
154#define MBSTRING_FLAG 0x1000
155#define MBSTRING_UTF8 (MBSTRING_FLAG)
156#define MBSTRING_ASC (MBSTRING_FLAG|1)
157#define MBSTRING_BMP (MBSTRING_FLAG|2)
158#define MBSTRING_UNIV (MBSTRING_FLAG|4)
159
160#define SMIME_OLDMIME 0x400
161#define SMIME_CRLFEOL 0x800
162#define SMIME_STREAM 0x1000
163
164#define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */
165#define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */
166
167/* We MUST make sure that, except for constness, asn1_ctx_st and
168 asn1_const_ctx are exactly the same. Fortunately, as soon as
169 the old ASN1 parsing macros are gone, we can throw this away
170 as well... */
171typedef struct asn1_ctx_st
172 {
173 unsigned char *p;/* work char pointer */
174 int eos; /* end of sequence read for indefinite encoding */
175 int error; /* error code to use when returning an error */
176 int inf; /* constructed if 0x20, indefinite is 0x21 */
177 int tag; /* tag from last 'get object' */
178 int xclass; /* class from last 'get object' */
179 long slen; /* length of last 'get object' */
180 unsigned char *max; /* largest value of p allowed */
181 unsigned char *q;/* temporary variable */
182 unsigned char **pp;/* variable */
183 int line; /* used in error processing */
184 } ASN1_CTX;
185
186typedef struct asn1_const_ctx_st
187 {
188 const unsigned char *p;/* work char pointer */
189 int eos; /* end of sequence read for indefinite encoding */
190 int error; /* error code to use when returning an error */
191 int inf; /* constructed if 0x20, indefinite is 0x21 */
192 int tag; /* tag from last 'get object' */
193 int xclass; /* class from last 'get object' */
194 long slen; /* length of last 'get object' */
195 const unsigned char *max; /* largest value of p allowed */
196 const unsigned char *q;/* temporary variable */
197 const unsigned char **pp;/* variable */
198 int line; /* used in error processing */
199 } ASN1_const_CTX;
200
201/* These are used internally in the ASN1_OBJECT to keep track of
202 * whether the names and data need to be free()ed */
203#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
204#define ASN1_OBJECT_FLAG_CRITICAL 0x02 /* critical x509v3 object id */
205#define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 /* internal use */
206#define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 /* internal use */
207struct asn1_object_st
208 {
209 const char *sn,*ln;
210 int nid;
211 int length;
212 const unsigned char *data; /* data remains const after init */
213 int flags; /* Should we free this one */
214 };
215
David Benjamin01f8a8c2017-04-15 18:12:55 -0400216DEFINE_STACK_OF(ASN1_OBJECT)
David Benjamindefe2a82016-09-13 18:10:38 -0400217
Adam Langley95c29f32014-06-20 12:00:00 -0700218#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
219/* This indicates that the ASN1_STRING is not a real value but just a place
220 * holder for the location where indefinite length constructed data should
221 * be inserted in the memory buffer
222 */
223#define ASN1_STRING_FLAG_NDEF 0x010
224
225/* This flag is used by the CMS code to indicate that a string is not
226 * complete and is a place holder for content when it had all been
227 * accessed. The flag will be reset when content has been written to it.
228 */
229
230#define ASN1_STRING_FLAG_CONT 0x020
231/* This flag is used by ASN1 code to indicate an ASN1_STRING is an MSTRING
232 * type.
233 */
234#define ASN1_STRING_FLAG_MSTRING 0x040
235/* This is the base type that holds just about everything :-) */
236struct asn1_string_st
237 {
238 int length;
239 int type;
240 unsigned char *data;
241 /* The value of the following field depends on the type being
242 * held. It is mostly being used for BIT_STRING so if the
243 * input data has a non-zero 'unused bits' value, it will be
244 * handled correctly */
245 long flags;
246 };
247
248/* ASN1_ENCODING structure: this is used to save the received
249 * encoding of an ASN1 type. This is useful to get round
250 * problems with invalid encodings which can break signatures.
251 */
252
253typedef struct ASN1_ENCODING_st
254 {
255 unsigned char *enc; /* DER encoding */
256 long len; /* Length of encoding */
Adam Langley48983312016-10-28 11:42:45 -0700257 int modified; /* set to 1 if 'enc' is invalid */
258 /* alias_only is zero if |enc| owns the buffer that it points to
259 * (although |enc| may still be NULL). If one, |enc| points into a
260 * buffer that is owned elsewhere. */
261 unsigned alias_only:1;
262 /* alias_only_on_next_parse is one iff the next parsing operation
263 * should avoid taking a copy of the input and rather set
264 * |alias_only|. */
265 unsigned alias_only_on_next_parse:1;
Adam Langley95c29f32014-06-20 12:00:00 -0700266 } ASN1_ENCODING;
267
Adam Langley95c29f32014-06-20 12:00:00 -0700268#define STABLE_FLAGS_MALLOC 0x01
269#define STABLE_NO_MASK 0x02
270#define DIRSTRING_TYPE \
271 (B_ASN1_PRINTABLESTRING|B_ASN1_T61STRING|B_ASN1_BMPSTRING|B_ASN1_UTF8STRING)
272#define PKCS9STRING_TYPE (DIRSTRING_TYPE|B_ASN1_IA5STRING)
273
274typedef struct asn1_string_table_st {
275 int nid;
276 long minsize;
277 long maxsize;
278 unsigned long mask;
279 unsigned long flags;
280} ASN1_STRING_TABLE;
281
282/* size limits: this stuff is taken straight from RFC2459 */
283
284#define ub_name 32768
285#define ub_common_name 64
286#define ub_locality_name 128
287#define ub_state_name 128
288#define ub_organization_name 64
289#define ub_organization_unit_name 64
290#define ub_title 64
291#define ub_email_address 128
292
293/* Declarations for template structures: for full definitions
294 * see asn1t.h
295 */
296typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE;
297typedef struct ASN1_TLC_st ASN1_TLC;
298/* This is just an opaque pointer */
299typedef struct ASN1_VALUE_st ASN1_VALUE;
300
301/* Declare ASN1 functions: the implement macro in in asn1t.h */
302
303#define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type)
304
305#define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \
306 DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, type)
307
308#define DECLARE_ASN1_FUNCTIONS_name(type, name) \
309 DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
310 DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name)
311
312#define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \
313 DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
314 DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)
315
316#define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700317 OPENSSL_EXPORT type *d2i_##name(type **a, const unsigned char **in, long len); \
318 OPENSSL_EXPORT int i2d_##name(type *a, unsigned char **out); \
Adam Langley95c29f32014-06-20 12:00:00 -0700319 DECLARE_ASN1_ITEM(itname)
320
321#define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700322 OPENSSL_EXPORT type *d2i_##name(type **a, const unsigned char **in, long len); \
323 OPENSSL_EXPORT int i2d_##name(const type *a, unsigned char **out); \
Adam Langley95c29f32014-06-20 12:00:00 -0700324 DECLARE_ASN1_ITEM(name)
325
326#define DECLARE_ASN1_NDEF_FUNCTION(name) \
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700327 OPENSSL_EXPORT int i2d_##name##_NDEF(name *a, unsigned char **out);
Adam Langley95c29f32014-06-20 12:00:00 -0700328
329#define DECLARE_ASN1_FUNCTIONS_const(name) \
330 DECLARE_ASN1_ALLOC_FUNCTIONS(name) \
331 DECLARE_ASN1_ENCODE_FUNCTIONS_const(name, name)
332
333#define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700334 OPENSSL_EXPORT type *name##_new(void); \
335 OPENSSL_EXPORT void name##_free(type *a);
Adam Langley95c29f32014-06-20 12:00:00 -0700336
337#define DECLARE_ASN1_PRINT_FUNCTION(stname) \
338 DECLARE_ASN1_PRINT_FUNCTION_fname(stname, stname)
339
340#define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700341 OPENSSL_EXPORT int fname##_print_ctx(BIO *out, stname *x, int indent, \
Adam Langley95c29f32014-06-20 12:00:00 -0700342 const ASN1_PCTX *pctx);
343
344#define D2I_OF(type) type *(*)(type **,const unsigned char **,long)
345#define I2D_OF(type) int (*)(type *,unsigned char **)
346#define I2D_OF_const(type) int (*)(const type *,unsigned char **)
347
348#define CHECKED_D2I_OF(type, d2i) \
349 ((d2i_of_void*) (1 ? d2i : ((D2I_OF(type))0)))
350#define CHECKED_I2D_OF(type, i2d) \
351 ((i2d_of_void*) (1 ? i2d : ((I2D_OF(type))0)))
352#define CHECKED_NEW_OF(type, xnew) \
353 ((void *(*)(void)) (1 ? xnew : ((type *(*)(void))0)))
354#define CHECKED_PPTR_OF(type, p) \
355 ((void**) (1 ? p : (type**)0))
356
357#define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long)
358#define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(const type *,unsigned char **)
359#define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type)
360
361TYPEDEF_D2I2D_OF(void);
362
363/* The following macros and typedefs allow an ASN1_ITEM
364 * to be embedded in a structure and referenced. Since
365 * the ASN1_ITEM pointers need to be globally accessible
366 * (possibly from shared libraries) they may exist in
367 * different forms. On platforms that support it the
368 * ASN1_ITEM structure itself will be globally exported.
369 * Other platforms will export a function that returns
370 * an ASN1_ITEM pointer.
371 *
372 * To handle both cases transparently the macros below
373 * should be used instead of hard coding an ASN1_ITEM
374 * pointer in a structure.
375 *
376 * The structure will look like this:
377 *
378 * typedef struct SOMETHING_st {
379 * ...
380 * ASN1_ITEM_EXP *iptr;
381 * ...
382 * } SOMETHING;
383 *
384 * It would be initialised as e.g.:
385 *
386 * SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...};
387 *
388 * and the actual pointer extracted with:
389 *
390 * const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr);
391 *
392 * Finally an ASN1_ITEM pointer can be extracted from an
393 * appropriate reference with: ASN1_ITEM_rptr(X509). This
394 * would be used when a function takes an ASN1_ITEM * argument.
395 *
396 */
397
Adam Langley95c29f32014-06-20 12:00:00 -0700398/* ASN1_ITEM pointer exported type */
399typedef const ASN1_ITEM ASN1_ITEM_EXP;
400
401/* Macro to obtain ASN1_ITEM pointer from exported type */
402#define ASN1_ITEM_ptr(iptr) (iptr)
403
404/* Macro to include ASN1_ITEM pointer from base type */
405#define ASN1_ITEM_ref(iptr) (&(iptr##_it))
406
407#define ASN1_ITEM_rptr(ref) (&(ref##_it))
408
409#define DECLARE_ASN1_ITEM(name) \
David Benjamin775b75f2014-09-30 19:51:34 -0400410 extern OPENSSL_EXPORT const ASN1_ITEM name##_it;
Adam Langley95c29f32014-06-20 12:00:00 -0700411
Adam Langley95c29f32014-06-20 12:00:00 -0700412/* Parameters used by ASN1_STRING_print_ex() */
413
414/* These determine which characters to escape:
415 * RFC2253 special characters, control characters and
416 * MSB set characters
417 */
418
419#define ASN1_STRFLGS_ESC_2253 1
420#define ASN1_STRFLGS_ESC_CTRL 2
421#define ASN1_STRFLGS_ESC_MSB 4
422
423
424/* This flag determines how we do escaping: normally
425 * RC2253 backslash only, set this to use backslash and
426 * quote.
427 */
428
429#define ASN1_STRFLGS_ESC_QUOTE 8
430
431
432/* These three flags are internal use only. */
433
434/* Character is a valid PrintableString character */
435#define CHARTYPE_PRINTABLESTRING 0x10
436/* Character needs escaping if it is the first character */
437#define CHARTYPE_FIRST_ESC_2253 0x20
438/* Character needs escaping if it is the last character */
439#define CHARTYPE_LAST_ESC_2253 0x40
440
441/* NB the internal flags are safely reused below by flags
442 * handled at the top level.
443 */
444
445/* If this is set we convert all character strings
446 * to UTF8 first
447 */
448
449#define ASN1_STRFLGS_UTF8_CONVERT 0x10
450
451/* If this is set we don't attempt to interpret content:
452 * just assume all strings are 1 byte per character. This
453 * will produce some pretty odd looking output!
454 */
455
456#define ASN1_STRFLGS_IGNORE_TYPE 0x20
457
458/* If this is set we include the string type in the output */
459#define ASN1_STRFLGS_SHOW_TYPE 0x40
460
461/* This determines which strings to display and which to
462 * 'dump' (hex dump of content octets or DER encoding). We can
463 * only dump non character strings or everything. If we
464 * don't dump 'unknown' they are interpreted as character
465 * strings with 1 octet per character and are subject to
466 * the usual escaping options.
467 */
468
469#define ASN1_STRFLGS_DUMP_ALL 0x80
470#define ASN1_STRFLGS_DUMP_UNKNOWN 0x100
471
472/* These determine what 'dumping' does, we can dump the
473 * content octets or the DER encoding: both use the
474 * RFC2253 #XXXXX notation.
475 */
476
477#define ASN1_STRFLGS_DUMP_DER 0x200
478
479/* All the string flags consistent with RFC2253,
480 * escaping control characters isn't essential in
481 * RFC2253 but it is advisable anyway.
482 */
483
484#define ASN1_STRFLGS_RFC2253 (ASN1_STRFLGS_ESC_2253 | \
485 ASN1_STRFLGS_ESC_CTRL | \
486 ASN1_STRFLGS_ESC_MSB | \
487 ASN1_STRFLGS_UTF8_CONVERT | \
488 ASN1_STRFLGS_DUMP_UNKNOWN | \
489 ASN1_STRFLGS_DUMP_DER)
490
David Benjamin01f8a8c2017-04-15 18:12:55 -0400491DEFINE_STACK_OF(ASN1_INTEGER)
Adam Langley95c29f32014-06-20 12:00:00 -0700492DECLARE_ASN1_SET_OF(ASN1_INTEGER)
493
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700494struct asn1_type_st
Adam Langley95c29f32014-06-20 12:00:00 -0700495 {
496 int type;
497 union {
498 char *ptr;
499 ASN1_BOOLEAN boolean;
500 ASN1_STRING * asn1_string;
501 ASN1_OBJECT * object;
502 ASN1_INTEGER * integer;
503 ASN1_ENUMERATED * enumerated;
504 ASN1_BIT_STRING * bit_string;
505 ASN1_OCTET_STRING * octet_string;
506 ASN1_PRINTABLESTRING * printablestring;
507 ASN1_T61STRING * t61string;
508 ASN1_IA5STRING * ia5string;
509 ASN1_GENERALSTRING * generalstring;
510 ASN1_BMPSTRING * bmpstring;
511 ASN1_UNIVERSALSTRING * universalstring;
512 ASN1_UTCTIME * utctime;
513 ASN1_GENERALIZEDTIME * generalizedtime;
514 ASN1_VISIBLESTRING * visiblestring;
515 ASN1_UTF8STRING * utf8string;
516 /* set and sequence are left complete and still
517 * contain the set or sequence bytes */
518 ASN1_STRING * set;
519 ASN1_STRING * sequence;
520 ASN1_VALUE * asn1_value;
521 } value;
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700522 };
Adam Langley95c29f32014-06-20 12:00:00 -0700523
David Benjamin01f8a8c2017-04-15 18:12:55 -0400524DEFINE_STACK_OF(ASN1_TYPE)
Adam Langley95c29f32014-06-20 12:00:00 -0700525DECLARE_ASN1_SET_OF(ASN1_TYPE)
526
527typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY;
528
529DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY)
530DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SET_ANY)
531
532struct X509_algor_st
533 {
534 ASN1_OBJECT *algorithm;
535 ASN1_TYPE *parameter;
536 } /* X509_ALGOR */;
Adam Langley95c29f32014-06-20 12:00:00 -0700537
Adam Langley1df63e92015-03-12 13:54:27 -0700538DECLARE_ASN1_FUNCTIONS(X509_ALGOR)
Adam Langley95c29f32014-06-20 12:00:00 -0700539
540typedef struct NETSCAPE_X509_st
541 {
542 ASN1_OCTET_STRING *header;
543 X509 *cert;
544 } NETSCAPE_X509;
545
546/* This is used to contain a list of bit names */
547typedef struct BIT_STRING_BITNAME_st {
548 int bitnum;
549 const char *lname;
550 const char *sname;
551} BIT_STRING_BITNAME;
552
553
554#define M_ASN1_STRING_length(x) ((x)->length)
555#define M_ASN1_STRING_length_set(x, n) ((x)->length = (n))
556#define M_ASN1_STRING_type(x) ((x)->type)
557#define M_ASN1_STRING_data(x) ((x)->data)
558
559/* Macros for string operations */
560#define M_ASN1_BIT_STRING_new() (ASN1_BIT_STRING *)\
561 ASN1_STRING_type_new(V_ASN1_BIT_STRING)
562#define M_ASN1_BIT_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
563#define M_ASN1_BIT_STRING_dup(a) (ASN1_BIT_STRING *)\
564 ASN1_STRING_dup((const ASN1_STRING *)a)
565#define M_ASN1_BIT_STRING_cmp(a,b) ASN1_STRING_cmp(\
566 (const ASN1_STRING *)a,(const ASN1_STRING *)b)
567#define M_ASN1_BIT_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
568
569#define M_ASN1_INTEGER_new() (ASN1_INTEGER *)\
570 ASN1_STRING_type_new(V_ASN1_INTEGER)
571#define M_ASN1_INTEGER_free(a) ASN1_STRING_free((ASN1_STRING *)a)
572#define M_ASN1_INTEGER_dup(a) (ASN1_INTEGER *)\
573 ASN1_STRING_dup((const ASN1_STRING *)a)
574#define M_ASN1_INTEGER_cmp(a,b) ASN1_STRING_cmp(\
575 (const ASN1_STRING *)a,(const ASN1_STRING *)b)
576
577#define M_ASN1_ENUMERATED_new() (ASN1_ENUMERATED *)\
578 ASN1_STRING_type_new(V_ASN1_ENUMERATED)
579#define M_ASN1_ENUMERATED_free(a) ASN1_STRING_free((ASN1_STRING *)a)
580#define M_ASN1_ENUMERATED_dup(a) (ASN1_ENUMERATED *)\
581 ASN1_STRING_dup((const ASN1_STRING *)a)
582#define M_ASN1_ENUMERATED_cmp(a,b) ASN1_STRING_cmp(\
583 (const ASN1_STRING *)a,(const ASN1_STRING *)b)
584
585#define M_ASN1_OCTET_STRING_new() (ASN1_OCTET_STRING *)\
586 ASN1_STRING_type_new(V_ASN1_OCTET_STRING)
587#define M_ASN1_OCTET_STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
588#define M_ASN1_OCTET_STRING_dup(a) (ASN1_OCTET_STRING *)\
589 ASN1_STRING_dup((const ASN1_STRING *)a)
590#define M_ASN1_OCTET_STRING_cmp(a,b) ASN1_STRING_cmp(\
591 (const ASN1_STRING *)a,(const ASN1_STRING *)b)
592#define M_ASN1_OCTET_STRING_set(a,b,c) ASN1_STRING_set((ASN1_STRING *)a,b,c)
593#define M_ASN1_OCTET_STRING_print(a,b) ASN1_STRING_print(a,(ASN1_STRING *)b)
Adam Langley95c29f32014-06-20 12:00:00 -0700594
595#define B_ASN1_TIME \
596 B_ASN1_UTCTIME | \
597 B_ASN1_GENERALIZEDTIME
598
599#define B_ASN1_PRINTABLE \
600 B_ASN1_NUMERICSTRING| \
601 B_ASN1_PRINTABLESTRING| \
602 B_ASN1_T61STRING| \
603 B_ASN1_IA5STRING| \
604 B_ASN1_BIT_STRING| \
605 B_ASN1_UNIVERSALSTRING|\
606 B_ASN1_BMPSTRING|\
607 B_ASN1_UTF8STRING|\
608 B_ASN1_SEQUENCE|\
609 B_ASN1_UNKNOWN
610
611#define B_ASN1_DIRECTORYSTRING \
612 B_ASN1_PRINTABLESTRING| \
613 B_ASN1_TELETEXSTRING|\
614 B_ASN1_BMPSTRING|\
615 B_ASN1_UNIVERSALSTRING|\
616 B_ASN1_UTF8STRING
617
618#define B_ASN1_DISPLAYTEXT \
619 B_ASN1_IA5STRING| \
620 B_ASN1_VISIBLESTRING| \
621 B_ASN1_BMPSTRING|\
622 B_ASN1_UTF8STRING
623
624#define M_ASN1_PRINTABLE_new() ASN1_STRING_type_new(V_ASN1_T61STRING)
625#define M_ASN1_PRINTABLE_free(a) ASN1_STRING_free((ASN1_STRING *)a)
Adam Langley95c29f32014-06-20 12:00:00 -0700626
627#define M_DIRECTORYSTRING_new() ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
628#define M_DIRECTORYSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
Adam Langley95c29f32014-06-20 12:00:00 -0700629
630#define M_DISPLAYTEXT_new() ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
631#define M_DISPLAYTEXT_free(a) ASN1_STRING_free((ASN1_STRING *)a)
Adam Langley95c29f32014-06-20 12:00:00 -0700632
633#define M_ASN1_PRINTABLESTRING_new() (ASN1_PRINTABLESTRING *)\
634 ASN1_STRING_type_new(V_ASN1_PRINTABLESTRING)
635#define M_ASN1_PRINTABLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
Adam Langley95c29f32014-06-20 12:00:00 -0700636
637#define M_ASN1_T61STRING_new() (ASN1_T61STRING *)\
638 ASN1_STRING_type_new(V_ASN1_T61STRING)
639#define M_ASN1_T61STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
Adam Langley95c29f32014-06-20 12:00:00 -0700640
641#define M_ASN1_IA5STRING_new() (ASN1_IA5STRING *)\
642 ASN1_STRING_type_new(V_ASN1_IA5STRING)
643#define M_ASN1_IA5STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
644#define M_ASN1_IA5STRING_dup(a) \
645 (ASN1_IA5STRING *)ASN1_STRING_dup((const ASN1_STRING *)a)
Adam Langley95c29f32014-06-20 12:00:00 -0700646
647#define M_ASN1_UTCTIME_new() (ASN1_UTCTIME *)\
648 ASN1_STRING_type_new(V_ASN1_UTCTIME)
649#define M_ASN1_UTCTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
650#define M_ASN1_UTCTIME_dup(a) (ASN1_UTCTIME *)\
651 ASN1_STRING_dup((const ASN1_STRING *)a)
652
653#define M_ASN1_GENERALIZEDTIME_new() (ASN1_GENERALIZEDTIME *)\
654 ASN1_STRING_type_new(V_ASN1_GENERALIZEDTIME)
655#define M_ASN1_GENERALIZEDTIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
656#define M_ASN1_GENERALIZEDTIME_dup(a) (ASN1_GENERALIZEDTIME *)ASN1_STRING_dup(\
657 (const ASN1_STRING *)a)
658
659#define M_ASN1_TIME_new() (ASN1_TIME *)\
660 ASN1_STRING_type_new(V_ASN1_UTCTIME)
661#define M_ASN1_TIME_free(a) ASN1_STRING_free((ASN1_STRING *)a)
662#define M_ASN1_TIME_dup(a) (ASN1_TIME *)\
663 ASN1_STRING_dup((const ASN1_STRING *)a)
664
665#define M_ASN1_GENERALSTRING_new() (ASN1_GENERALSTRING *)\
666 ASN1_STRING_type_new(V_ASN1_GENERALSTRING)
667#define M_ASN1_GENERALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
Adam Langley95c29f32014-06-20 12:00:00 -0700668
669#define M_ASN1_UNIVERSALSTRING_new() (ASN1_UNIVERSALSTRING *)\
670 ASN1_STRING_type_new(V_ASN1_UNIVERSALSTRING)
671#define M_ASN1_UNIVERSALSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
Adam Langley95c29f32014-06-20 12:00:00 -0700672
673#define M_ASN1_BMPSTRING_new() (ASN1_BMPSTRING *)\
674 ASN1_STRING_type_new(V_ASN1_BMPSTRING)
675#define M_ASN1_BMPSTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
Adam Langley95c29f32014-06-20 12:00:00 -0700676
677#define M_ASN1_VISIBLESTRING_new() (ASN1_VISIBLESTRING *)\
678 ASN1_STRING_type_new(V_ASN1_VISIBLESTRING)
679#define M_ASN1_VISIBLESTRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
Adam Langley95c29f32014-06-20 12:00:00 -0700680
681#define M_ASN1_UTF8STRING_new() (ASN1_UTF8STRING *)\
682 ASN1_STRING_type_new(V_ASN1_UTF8STRING)
683#define M_ASN1_UTF8STRING_free(a) ASN1_STRING_free((ASN1_STRING *)a)
Adam Langley95c29f32014-06-20 12:00:00 -0700684
Adam Langley95c29f32014-06-20 12:00:00 -0700685DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
686
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700687OPENSSL_EXPORT int ASN1_TYPE_get(ASN1_TYPE *a);
688OPENSSL_EXPORT void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
689OPENSSL_EXPORT int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
Adam Langleyca9a5382015-01-08 12:26:55 -0800690OPENSSL_EXPORT int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b);
Adam Langley95c29f32014-06-20 12:00:00 -0700691
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700692OPENSSL_EXPORT ASN1_OBJECT * ASN1_OBJECT_new(void );
693OPENSSL_EXPORT void ASN1_OBJECT_free(ASN1_OBJECT *a);
694OPENSSL_EXPORT int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
695OPENSSL_EXPORT ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a,const unsigned char **pp,
696 long length);
697OPENSSL_EXPORT ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,const unsigned char **pp,
698 long length);
Adam Langley95c29f32014-06-20 12:00:00 -0700699
700DECLARE_ASN1_ITEM(ASN1_OBJECT)
701
702DECLARE_ASN1_SET_OF(ASN1_OBJECT)
703
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700704OPENSSL_EXPORT ASN1_STRING * ASN1_STRING_new(void);
705OPENSSL_EXPORT void ASN1_STRING_free(ASN1_STRING *a);
706OPENSSL_EXPORT int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str);
707OPENSSL_EXPORT ASN1_STRING * ASN1_STRING_dup(const ASN1_STRING *a);
708OPENSSL_EXPORT ASN1_STRING * ASN1_STRING_type_new(int type );
709OPENSSL_EXPORT int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b);
Adam Langley95c29f32014-06-20 12:00:00 -0700710 /* Since this is used to store all sorts of things, via macros, for now, make
711 its data void * */
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700712OPENSSL_EXPORT int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
713OPENSSL_EXPORT void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len);
714OPENSSL_EXPORT int ASN1_STRING_length(const ASN1_STRING *x);
715OPENSSL_EXPORT void ASN1_STRING_length_set(ASN1_STRING *x, int n);
716OPENSSL_EXPORT int ASN1_STRING_type(ASN1_STRING *x);
717OPENSSL_EXPORT unsigned char * ASN1_STRING_data(ASN1_STRING *x);
Adam Langley95c29f32014-06-20 12:00:00 -0700718
719DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700720OPENSSL_EXPORT int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
721OPENSSL_EXPORT ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,const unsigned char **pp, long length);
722OPENSSL_EXPORT int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, int length );
723OPENSSL_EXPORT int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value);
724OPENSSL_EXPORT int ASN1_BIT_STRING_get_bit(ASN1_BIT_STRING *a, int n);
725OPENSSL_EXPORT int ASN1_BIT_STRING_check(ASN1_BIT_STRING *a, unsigned char *flags, int flags_len);
Adam Langley95c29f32014-06-20 12:00:00 -0700726
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700727OPENSSL_EXPORT int ASN1_BIT_STRING_name_print(BIO *out, ASN1_BIT_STRING *bs, BIT_STRING_BITNAME *tbl, int indent);
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700728OPENSSL_EXPORT int ASN1_BIT_STRING_num_asc(char *name, BIT_STRING_BITNAME *tbl);
729OPENSSL_EXPORT int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value, BIT_STRING_BITNAME *tbl);
Adam Langley95c29f32014-06-20 12:00:00 -0700730
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700731OPENSSL_EXPORT int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
732OPENSSL_EXPORT int d2i_ASN1_BOOLEAN(int *a,const unsigned char **pp,long length);
Adam Langley95c29f32014-06-20 12:00:00 -0700733
734DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700735OPENSSL_EXPORT int i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
736OPENSSL_EXPORT ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,const unsigned char **pp, long length);
737OPENSSL_EXPORT ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,const unsigned char **pp, long length);
738OPENSSL_EXPORT ASN1_INTEGER * ASN1_INTEGER_dup(const ASN1_INTEGER *x);
739OPENSSL_EXPORT int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y);
Adam Langley95c29f32014-06-20 12:00:00 -0700740
741DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)
742
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700743OPENSSL_EXPORT int ASN1_UTCTIME_check(const ASN1_UTCTIME *a);
744OPENSSL_EXPORT ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
745OPENSSL_EXPORT ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, int offset_day, long offset_sec);
746OPENSSL_EXPORT int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str);
747OPENSSL_EXPORT int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
Adam Langley95c29f32014-06-20 12:00:00 -0700748#if 0
749time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);
750#endif
751
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700752OPENSSL_EXPORT int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *a);
753OPENSSL_EXPORT ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
754OPENSSL_EXPORT ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, time_t t, int offset_day, long offset_sec);
755OPENSSL_EXPORT int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str);
756OPENSSL_EXPORT int ASN1_TIME_diff(int *pday, int *psec, const ASN1_TIME *from, const ASN1_TIME *to);
Adam Langley95c29f32014-06-20 12:00:00 -0700757
758DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700759OPENSSL_EXPORT ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(const ASN1_OCTET_STRING *a);
760OPENSSL_EXPORT int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, const ASN1_OCTET_STRING *b);
761OPENSSL_EXPORT int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data, int len);
Adam Langley95c29f32014-06-20 12:00:00 -0700762
763DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
764DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
765DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING)
766DECLARE_ASN1_FUNCTIONS(ASN1_NULL)
767DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING)
768
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700769OPENSSL_EXPORT int UTF8_getc(const unsigned char *str, int len, unsigned long *val);
770OPENSSL_EXPORT int UTF8_putc(unsigned char *str, int len, unsigned long value);
Adam Langley95c29f32014-06-20 12:00:00 -0700771
772DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE)
773
774DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
775DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT)
776DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING)
777DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING)
778DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING)
779DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING)
780DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
781DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
782DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
783
784DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)
785
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700786OPENSSL_EXPORT ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
787OPENSSL_EXPORT ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s,time_t t, int offset_day, long offset_sec);
788OPENSSL_EXPORT int ASN1_TIME_check(ASN1_TIME *t);
789OPENSSL_EXPORT ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
790OPENSSL_EXPORT int ASN1_TIME_set_string(ASN1_TIME *s, const char *str);
Adam Langley95c29f32014-06-20 12:00:00 -0700791
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700792OPENSSL_EXPORT int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700793OPENSSL_EXPORT int i2a_ASN1_ENUMERATED(BIO *bp, ASN1_ENUMERATED *a);
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700794OPENSSL_EXPORT int i2a_ASN1_OBJECT(BIO *bp,ASN1_OBJECT *a);
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700795OPENSSL_EXPORT int i2a_ASN1_STRING(BIO *bp, ASN1_STRING *a, int type);
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700796OPENSSL_EXPORT int i2t_ASN1_OBJECT(char *buf,int buf_len,ASN1_OBJECT *a);
Adam Langley95c29f32014-06-20 12:00:00 -0700797
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700798OPENSSL_EXPORT int a2d_ASN1_OBJECT(unsigned char *out,int olen, const char *buf, int num);
799OPENSSL_EXPORT ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data,int len, const char *sn, const char *ln);
Adam Langley95c29f32014-06-20 12:00:00 -0700800
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700801OPENSSL_EXPORT int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
802OPENSSL_EXPORT long ASN1_INTEGER_get(const ASN1_INTEGER *a);
803OPENSSL_EXPORT ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai);
804OPENSSL_EXPORT BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai,BIGNUM *bn);
Adam Langley95c29f32014-06-20 12:00:00 -0700805
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700806OPENSSL_EXPORT int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
807OPENSSL_EXPORT long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a);
808OPENSSL_EXPORT ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai);
809OPENSSL_EXPORT BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
Adam Langley95c29f32014-06-20 12:00:00 -0700810
811/* General */
812/* given a string, return the correct type, max is the maximum length */
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700813OPENSSL_EXPORT int ASN1_PRINTABLE_type(const unsigned char *s, int max);
Adam Langley95c29f32014-06-20 12:00:00 -0700814
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700815OPENSSL_EXPORT unsigned long ASN1_tag2bit(int tag);
Adam Langley95c29f32014-06-20 12:00:00 -0700816
817/* PARSING */
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700818OPENSSL_EXPORT int asn1_Finish(ASN1_CTX *c);
819OPENSSL_EXPORT int asn1_const_Finish(ASN1_const_CTX *c);
Adam Langley95c29f32014-06-20 12:00:00 -0700820
821/* SPECIALS */
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700822OPENSSL_EXPORT int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, int *pclass, long omax);
823OPENSSL_EXPORT int ASN1_check_infinite_end(unsigned char **p,long len);
824OPENSSL_EXPORT int ASN1_const_check_infinite_end(const unsigned char **p,long len);
825OPENSSL_EXPORT void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag, int xclass);
826OPENSSL_EXPORT int ASN1_put_eoc(unsigned char **pp);
827OPENSSL_EXPORT int ASN1_object_size(int constructed, int length, int tag);
Adam Langley95c29f32014-06-20 12:00:00 -0700828
829/* Used to implement other functions */
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700830OPENSSL_EXPORT void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, void *x);
Adam Langley95c29f32014-06-20 12:00:00 -0700831
832#define ASN1_dup_of(type,i2d,d2i,x) \
833 ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \
834 CHECKED_D2I_OF(type, d2i), \
835 CHECKED_PTR_OF(type, x)))
836
837#define ASN1_dup_of_const(type,i2d,d2i,x) \
838 ((type*)ASN1_dup(CHECKED_I2D_OF(const type, i2d), \
839 CHECKED_D2I_OF(type, d2i), \
840 CHECKED_PTR_OF(const type, x)))
841
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700842OPENSSL_EXPORT void *ASN1_item_dup(const ASN1_ITEM *it, void *x);
Adam Langley95c29f32014-06-20 12:00:00 -0700843
844/* ASN1 alloc/free macros for when a type is only used internally */
845
846#define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type))
847#define M_ASN1_free_of(x, type) \
848 ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type))
849
850#ifndef OPENSSL_NO_FP_API
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700851OPENSSL_EXPORT void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x);
Adam Langley95c29f32014-06-20 12:00:00 -0700852
853#define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \
854 ((type*)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \
855 CHECKED_D2I_OF(type, d2i), \
856 in, \
857 CHECKED_PPTR_OF(type, x)))
858
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700859OPENSSL_EXPORT void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);
860OPENSSL_EXPORT int ASN1_i2d_fp(i2d_of_void *i2d,FILE *out,void *x);
Adam Langley95c29f32014-06-20 12:00:00 -0700861
862#define ASN1_i2d_fp_of(type,i2d,out,x) \
863 (ASN1_i2d_fp(CHECKED_I2D_OF(type, i2d), \
864 out, \
865 CHECKED_PTR_OF(type, x)))
866
867#define ASN1_i2d_fp_of_const(type,i2d,out,x) \
868 (ASN1_i2d_fp(CHECKED_I2D_OF(const type, i2d), \
869 out, \
870 CHECKED_PTR_OF(const type, x)))
871
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700872OPENSSL_EXPORT int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x);
873OPENSSL_EXPORT int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
Adam Langley95c29f32014-06-20 12:00:00 -0700874#endif
875
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700876OPENSSL_EXPORT int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);
Adam Langley95c29f32014-06-20 12:00:00 -0700877
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700878OPENSSL_EXPORT void *ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x);
Adam Langley95c29f32014-06-20 12:00:00 -0700879
880#define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \
881 ((type*)ASN1_d2i_bio( CHECKED_NEW_OF(type, xnew), \
882 CHECKED_D2I_OF(type, d2i), \
883 in, \
884 CHECKED_PPTR_OF(type, x)))
885
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700886OPENSSL_EXPORT void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x);
David Benjaminba134022015-08-28 15:05:02 -0400887OPENSSL_EXPORT int ASN1_i2d_bio(i2d_of_void *i2d,BIO *out, void *x);
Adam Langley95c29f32014-06-20 12:00:00 -0700888
889#define ASN1_i2d_bio_of(type,i2d,out,x) \
890 (ASN1_i2d_bio(CHECKED_I2D_OF(type, i2d), \
891 out, \
892 CHECKED_PTR_OF(type, x)))
893
894#define ASN1_i2d_bio_of_const(type,i2d,out,x) \
895 (ASN1_i2d_bio(CHECKED_I2D_OF(const type, i2d), \
896 out, \
897 CHECKED_PTR_OF(const type, x)))
898
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700899OPENSSL_EXPORT int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x);
900OPENSSL_EXPORT int ASN1_UTCTIME_print(BIO *fp, const ASN1_UTCTIME *a);
901OPENSSL_EXPORT int ASN1_GENERALIZEDTIME_print(BIO *fp, const ASN1_GENERALIZEDTIME *a);
902OPENSSL_EXPORT int ASN1_TIME_print(BIO *fp, const ASN1_TIME *a);
903OPENSSL_EXPORT int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v);
904OPENSSL_EXPORT int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700905OPENSSL_EXPORT const char *ASN1_tag2str(int tag);
Adam Langley95c29f32014-06-20 12:00:00 -0700906
907/* Used to load and write netscape format cert */
908
909DECLARE_ASN1_FUNCTIONS(NETSCAPE_X509)
910
911int ASN1_UNIVERSALSTRING_to_string(ASN1_UNIVERSALSTRING *s);
912
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700913OPENSSL_EXPORT void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it);
Adam Langley95c29f32014-06-20 12:00:00 -0700914
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700915OPENSSL_EXPORT ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct);
Adam Langley95c29f32014-06-20 12:00:00 -0700916
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700917OPENSSL_EXPORT void ASN1_STRING_set_default_mask(unsigned long mask);
918OPENSSL_EXPORT int ASN1_STRING_set_default_mask_asc(const char *p);
919OPENSSL_EXPORT unsigned long ASN1_STRING_get_default_mask(void);
920OPENSSL_EXPORT int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len, int inform, unsigned long mask);
921OPENSSL_EXPORT int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len, int inform, unsigned long mask, long minsize, long maxsize);
Adam Langley95c29f32014-06-20 12:00:00 -0700922
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700923OPENSSL_EXPORT ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, int inlen, int inform, int nid);
924OPENSSL_EXPORT ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid);
925OPENSSL_EXPORT int ASN1_STRING_TABLE_add(int, long, long, unsigned long, unsigned long);
926OPENSSL_EXPORT void ASN1_STRING_TABLE_cleanup(void);
Adam Langley95c29f32014-06-20 12:00:00 -0700927
928/* ASN1 template functions */
929
930/* Old API compatible functions */
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700931OPENSSL_EXPORT ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
932OPENSSL_EXPORT void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
933OPENSSL_EXPORT ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it);
934OPENSSL_EXPORT int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
935OPENSSL_EXPORT int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
Adam Langley95c29f32014-06-20 12:00:00 -0700936
Adam Langleyeb7d2ed2014-07-30 16:02:14 -0700937OPENSSL_EXPORT ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf);
938OPENSSL_EXPORT ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf);
Adam Langley95c29f32014-06-20 12:00:00 -0700939
Adam Langley95c29f32014-06-20 12:00:00 -0700940
941#ifdef __cplusplus
942}
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700943
944extern "C++" {
945
946namespace bssl {
947
David Benjamindefe2a82016-09-13 18:10:38 -0400948BORINGSSL_MAKE_STACK_DELETER(ASN1_OBJECT, ASN1_OBJECT_free)
949
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700950BORINGSSL_MAKE_DELETER(ASN1_OBJECT, ASN1_OBJECT_free)
951BORINGSSL_MAKE_DELETER(ASN1_STRING, ASN1_STRING_free)
952BORINGSSL_MAKE_DELETER(ASN1_TYPE, ASN1_TYPE_free)
953
Matt Braithwaited17d74d2016-08-17 20:10:28 -0700954} // namespace bssl
955
956} /* extern C++ */
957
Adam Langley95c29f32014-06-20 12:00:00 -0700958#endif
959
David Benjamin689be0f2015-02-11 15:55:26 -0500960#define ASN1_R_ASN1_LENGTH_MISMATCH 100
961#define ASN1_R_AUX_ERROR 101
962#define ASN1_R_BAD_GET_ASN1_OBJECT_CALL 102
963#define ASN1_R_BAD_OBJECT_HEADER 103
964#define ASN1_R_BMPSTRING_IS_WRONG_LENGTH 104
965#define ASN1_R_BN_LIB 105
966#define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 106
967#define ASN1_R_BUFFER_TOO_SMALL 107
David Benjamina2f2bc32016-03-14 17:13:54 -0400968#define ASN1_R_CONTEXT_NOT_INITIALISED 108
969#define ASN1_R_DECODE_ERROR 109
970#define ASN1_R_DEPTH_EXCEEDED 110
971#define ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED 111
972#define ASN1_R_ENCODE_ERROR 112
973#define ASN1_R_ERROR_GETTING_TIME 113
974#define ASN1_R_EXPECTING_AN_ASN1_SEQUENCE 114
975#define ASN1_R_EXPECTING_AN_INTEGER 115
976#define ASN1_R_EXPECTING_AN_OBJECT 116
977#define ASN1_R_EXPECTING_A_BOOLEAN 117
978#define ASN1_R_EXPECTING_A_TIME 118
979#define ASN1_R_EXPLICIT_LENGTH_MISMATCH 119
980#define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED 120
981#define ASN1_R_FIELD_MISSING 121
982#define ASN1_R_FIRST_NUM_TOO_LARGE 122
983#define ASN1_R_HEADER_TOO_LONG 123
984#define ASN1_R_ILLEGAL_BITSTRING_FORMAT 124
985#define ASN1_R_ILLEGAL_BOOLEAN 125
986#define ASN1_R_ILLEGAL_CHARACTERS 126
987#define ASN1_R_ILLEGAL_FORMAT 127
988#define ASN1_R_ILLEGAL_HEX 128
989#define ASN1_R_ILLEGAL_IMPLICIT_TAG 129
990#define ASN1_R_ILLEGAL_INTEGER 130
991#define ASN1_R_ILLEGAL_NESTED_TAGGING 131
992#define ASN1_R_ILLEGAL_NULL 132
993#define ASN1_R_ILLEGAL_NULL_VALUE 133
994#define ASN1_R_ILLEGAL_OBJECT 134
995#define ASN1_R_ILLEGAL_OPTIONAL_ANY 135
996#define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 136
997#define ASN1_R_ILLEGAL_TAGGED_ANY 137
998#define ASN1_R_ILLEGAL_TIME_VALUE 138
999#define ASN1_R_INTEGER_NOT_ASCII_FORMAT 139
1000#define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 140
1001#define ASN1_R_INVALID_BIT_STRING_BITS_LEFT 141
1002#define ASN1_R_INVALID_BMPSTRING_LENGTH 142
1003#define ASN1_R_INVALID_DIGIT 143
1004#define ASN1_R_INVALID_MODIFIER 144
1005#define ASN1_R_INVALID_NUMBER 145
1006#define ASN1_R_INVALID_OBJECT_ENCODING 146
1007#define ASN1_R_INVALID_SEPARATOR 147
1008#define ASN1_R_INVALID_TIME_FORMAT 148
1009#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 149
1010#define ASN1_R_INVALID_UTF8STRING 150
1011#define ASN1_R_LIST_ERROR 151
1012#define ASN1_R_MISSING_ASN1_EOS 152
1013#define ASN1_R_MISSING_EOC 153
1014#define ASN1_R_MISSING_SECOND_NUMBER 154
1015#define ASN1_R_MISSING_VALUE 155
1016#define ASN1_R_MSTRING_NOT_UNIVERSAL 156
1017#define ASN1_R_MSTRING_WRONG_TAG 157
1018#define ASN1_R_NESTED_ASN1_ERROR 158
1019#define ASN1_R_NESTED_ASN1_STRING 159
1020#define ASN1_R_NON_HEX_CHARACTERS 160
1021#define ASN1_R_NOT_ASCII_FORMAT 161
1022#define ASN1_R_NOT_ENOUGH_DATA 162
1023#define ASN1_R_NO_MATCHING_CHOICE_TYPE 163
1024#define ASN1_R_NULL_IS_WRONG_LENGTH 164
1025#define ASN1_R_OBJECT_NOT_ASCII_FORMAT 165
1026#define ASN1_R_ODD_NUMBER_OF_CHARS 166
1027#define ASN1_R_SECOND_NUMBER_TOO_LARGE 167
1028#define ASN1_R_SEQUENCE_LENGTH_MISMATCH 168
1029#define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 169
1030#define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG 170
1031#define ASN1_R_SHORT_LINE 171
1032#define ASN1_R_STREAMING_NOT_SUPPORTED 172
1033#define ASN1_R_STRING_TOO_LONG 173
1034#define ASN1_R_STRING_TOO_SHORT 174
1035#define ASN1_R_TAG_VALUE_TOO_HIGH 175
1036#define ASN1_R_TIME_NOT_ASCII_FORMAT 176
1037#define ASN1_R_TOO_LONG 177
1038#define ASN1_R_TYPE_NOT_CONSTRUCTED 178
1039#define ASN1_R_TYPE_NOT_PRIMITIVE 179
1040#define ASN1_R_UNEXPECTED_EOC 180
1041#define ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH 181
1042#define ASN1_R_UNKNOWN_FORMAT 182
1043#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 183
1044#define ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM 184
1045#define ASN1_R_UNKNOWN_TAG 185
1046#define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 186
1047#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 187
1048#define ASN1_R_UNSUPPORTED_TYPE 188
David Benjaminfb8e6782016-03-11 14:39:46 -05001049#define ASN1_R_WRONG_PUBLIC_KEY_TYPE 189
David Benjamina2f2bc32016-03-14 17:13:54 -04001050#define ASN1_R_WRONG_TAG 190
1051#define ASN1_R_WRONG_TYPE 191
Adam Langley95c29f32014-06-20 12:00:00 -07001052
1053#endif