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 58 #ifndef HEADER_ASN1_H 59 #define HEADER_ASN1_H 60 61 #include <openssl/base.h> 62 63 #include <time.h> 64 65 #include <openssl/bio.h> 66 #include <openssl/stack.h> 67 68 #include <openssl/bn.h> 69 70 #ifdef __cplusplus 71 extern "C" { 72 #endif 73 74 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 82 // Tag constants. 83 // 84 // These constants are used in various APIs to specify ASN.1 types and tag 85 // components. See the specific API's documentation for details on which values 86 // are used and how. 87 88 // The following constants are tag classes. 89 #define V_ASN1_UNIVERSAL 0x00 90 #define V_ASN1_APPLICATION 0x40 91 #define V_ASN1_CONTEXT_SPECIFIC 0x80 92 #define V_ASN1_PRIVATE 0xc0 93 94 // V_ASN1_CONSTRUCTED indicates an element is constructed, rather than 95 // primitive. 96 #define V_ASN1_CONSTRUCTED 0x20 97 98 // V_ASN1_PRIMITIVE_TAG is the highest tag number which can be encoded in a 99 // single byte. Note this is unrelated to whether an element is constructed or 100 // primitive. 101 // 102 // TODO(davidben): Make this private. 103 #define V_ASN1_PRIMITIVE_TAG 0x1f 104 105 // V_ASN1_MAX_UNIVERSAL is the highest supported universal tag number. It is 106 // necessary to avoid ambiguity with |V_ASN1_NEG|. 107 // 108 // TODO(davidben): Make this private. 109 #define V_ASN1_MAX_UNIVERSAL 0xff 110 111 // V_ASN1_UNDEF is used in some APIs to indicate an ASN.1 element is omitted. 112 #define V_ASN1_UNDEF (-1) 113 114 // V_ASN1_APP_CHOOSE is used in some APIs to specify a default ASN.1 type based 115 // on the context. 116 #define V_ASN1_APP_CHOOSE (-2) 117 118 // V_ASN1_OTHER is used in |ASN1_TYPE| to indicate a non-universal ASN.1 type. 119 #define V_ASN1_OTHER (-3) 120 121 // V_ASN1_ANY is used by the ASN.1 templates to indicate an ANY type. 122 #define V_ASN1_ANY (-4) 123 124 // The following constants are tag numbers for universal types. 125 #define V_ASN1_EOC 0 126 #define V_ASN1_BOOLEAN 1 127 #define V_ASN1_INTEGER 2 128 #define V_ASN1_BIT_STRING 3 129 #define V_ASN1_OCTET_STRING 4 130 #define V_ASN1_NULL 5 131 #define V_ASN1_OBJECT 6 132 #define V_ASN1_OBJECT_DESCRIPTOR 7 133 #define V_ASN1_EXTERNAL 8 134 #define V_ASN1_REAL 9 135 #define V_ASN1_ENUMERATED 10 136 #define V_ASN1_UTF8STRING 12 137 #define V_ASN1_SEQUENCE 16 138 #define V_ASN1_SET 17 139 #define V_ASN1_NUMERICSTRING 18 140 #define V_ASN1_PRINTABLESTRING 19 141 #define V_ASN1_T61STRING 20 142 #define V_ASN1_TELETEXSTRING 20 143 #define V_ASN1_VIDEOTEXSTRING 21 144 #define V_ASN1_IA5STRING 22 145 #define V_ASN1_UTCTIME 23 146 #define V_ASN1_GENERALIZEDTIME 24 147 #define V_ASN1_GRAPHICSTRING 25 148 #define V_ASN1_ISO64STRING 26 149 #define V_ASN1_VISIBLESTRING 26 150 #define V_ASN1_GENERALSTRING 27 151 #define V_ASN1_UNIVERSALSTRING 28 152 #define V_ASN1_BMPSTRING 30 153 154 // The following constants are used for |ASN1_STRING| values that represent 155 // negative INTEGER and ENUMERATED values. See |ASN1_STRING| for more details. 156 #define V_ASN1_NEG 0x100 157 #define V_ASN1_NEG_INTEGER (V_ASN1_INTEGER | V_ASN1_NEG) 158 #define V_ASN1_NEG_ENUMERATED (V_ASN1_ENUMERATED | V_ASN1_NEG) 159 160 161 // Strings. 162 // 163 // ASN.1 contains a myriad of string types, as well as types that contain data 164 // that may be encoded into a string. This library uses a single type, 165 // |ASN1_STRING|, to represent most values. 166 167 // An asn1_string_st (aka |ASN1_STRING|) represents a value of a string-like 168 // ASN.1 type. It contains a type field, and a byte string data field with a 169 // type-specific representation. 170 // 171 // When representing a string value, the type field is one of 172 // |V_ASN1_OCTET_STRING|, |V_ASN1_UTF8STRING|, |V_ASN1_NUMERICSTRING|, 173 // |V_ASN1_PRINTABLESTRING|, |V_ASN1_T61STRING|, |V_ASN1_VIDEOTEXSTRING|, 174 // |V_ASN1_IA5STRING|, |V_ASN1_GRAPHICSTRING|, |V_ASN1_ISO64STRING|, 175 // |V_ASN1_VISIBLESTRING|, |V_ASN1_GENERALSTRING|, |V_ASN1_UNIVERSALSTRING|, or 176 // |V_ASN1_BMPSTRING|. The data contains the byte representation of of the 177 // string. 178 // 179 // When representing a BIT STRING value, the type field is |V_ASN1_BIT_STRING|. 180 // The data contains the encoded form of the BIT STRING, including any padding 181 // bits added to round to a whole number of bytes, but excluding the leading 182 // byte containing the number of padding bits. The number of padding bits is 183 // encoded in the flags field. See |ASN1_STRING_FLAG_BITS_LEFT| for details. For 184 // example, DER encodes the BIT STRING {1, 0} as {0x06, 0x80 = 0b10_000000}. The 185 // |ASN1_STRING| representation has data of {0x80} and flags of 186 // ASN1_STRING_FLAG_BITS_LEFT | 6. 187 // 188 // When representing an INTEGER or ENUMERATED value, the data contains the 189 // big-endian encoding of the absolute value of the integer. The sign bit is 190 // encoded in the type: non-negative values have a type of |V_ASN1_INTEGER| or 191 // |V_ASN1_ENUMERATED|, while negative values have a type of 192 // |V_ASN1_NEG_INTEGER| or |V_ASN1_NEG_ENUMERATED|. Note this differs from DER's 193 // two's complement representation. 194 // 195 // When representing a GeneralizedTime or UTCTime value, the type field is 196 // |V_ASN1_GENERALIZEDTIME| or |V_ASN1_UTCTIME|, respectively. The data contains 197 // the DER encoding of the value. For example, the UNIX epoch would be 198 // "19700101000000Z" for a GeneralizedTime and "700101000000Z" for a UTCTime. 199 // 200 // TODO(davidben): |ASN1_TYPE| additionally uses |ASN1_STRING| to represent 201 // various other odd cases. It also likes to assume unknown universal tags are 202 // string types. Make a note here when documenting |ASN1_TYPE|. 203 // 204 // |ASN1_STRING| additionally has the following typedefs: |ASN1_BIT_STRING|, 205 // |ASN1_BMPSTRING|, |ASN1_ENUMERATED|, |ASN1_GENERALIZEDTIME|, 206 // |ASN1_GENERALSTRING|, |ASN1_IA5STRING|, |ASN1_INTEGER|, |ASN1_OCTET_STRING|, 207 // |ASN1_PRINTABLESTRING|, |ASN1_T61STRING|, |ASN1_TIME|, 208 // |ASN1_UNIVERSALSTRING|, |ASN1_UTCTIME|, |ASN1_UTF8STRING|, and 209 // |ASN1_VISIBLESTRING|. Other than |ASN1_TIME|, these correspond to universal 210 // ASN.1 types. |ASN1_TIME| represents a CHOICE of UTCTime and GeneralizedTime, 211 // with a cutoff of 2049, as used in Section 4.1.2.5 of RFC 5280. 212 // 213 // For clarity, callers are encouraged to use the appropriate typedef when 214 // available. They are the same type as |ASN1_STRING|, so a caller may freely 215 // pass them into functions expecting |ASN1_STRING|, such as 216 // |ASN1_STRING_length|. 217 // 218 // If a function returns an |ASN1_STRING| where the typedef or ASN.1 structure 219 // implies constraints on the type field, callers may assume that the type field 220 // is correct. However, if a function takes an |ASN1_STRING| as input, callers 221 // must ensure the type field matches. These invariants are not captured by the 222 // C type system and may not be checked at runtime. For example, callers may 223 // assume the output of |X509_get0_serialNumber| has type |V_ASN1_INTEGER| or 224 // |V_ASN1_NEG_INTEGER|. Callers must not pass a string of type 225 // |V_ASN1_OCTET_STRING| to |X509_set_serialNumber|. Doing so may break 226 // invariants on the |X509| object and break the |X509_get0_serialNumber| 227 // invariant. 228 // 229 // TODO(davidben): This is very unfriendly. Getting the type field wrong should 230 // not cause memory errors, but it may do strange things. We should add runtime 231 // checks to anything that consumes |ASN1_STRING|s from the caller. 232 struct asn1_string_st { 233 int length; 234 int type; 235 unsigned char *data; 236 long flags; 237 }; 238 239 // ASN1_STRING_FLAG_BITS_LEFT indicates, in a BIT STRING |ASN1_STRING|, that 240 // flags & 0x7 contains the number of padding bits added to the BIT STRING 241 // value. When not set, all trailing zero bits in the last byte are implicitly 242 // treated as padding. This behavior is deprecated and should not be used. 243 #define ASN1_STRING_FLAG_BITS_LEFT 0x08 244 245 // ASN1_STRING_FLAG_MSTRING indicates that the |ASN1_STRING| is an MSTRING type, 246 // which is how this library refers to a CHOICE type of several string types. 247 // For example, DirectoryString as defined in RFC5280. 248 // 249 // TODO(davidben): This is only used in one place within the library and is easy 250 // to accidentally drop. Can it be removed? 251 #define ASN1_STRING_FLAG_MSTRING 0x040 252 253 // ASN1_STRING_type_new returns a newly-allocated empty |ASN1_STRING| object of 254 // type |type|, or NULL on error. 255 OPENSSL_EXPORT ASN1_STRING *ASN1_STRING_type_new(int type); 256 257 // ASN1_STRING_new returns a newly-allocated empty |ASN1_STRING| object with an 258 // arbitrary type. Prefer one of the type-specific constructors, such as 259 // |ASN1_OCTET_STRING_new|, or |ASN1_STRING_type_new|. 260 OPENSSL_EXPORT ASN1_STRING *ASN1_STRING_new(void); 261 262 // ASN1_STRING_free releases memory associated with |str|. 263 OPENSSL_EXPORT void ASN1_STRING_free(ASN1_STRING *str); 264 265 // ASN1_STRING_copy sets |dst| to a copy of |str|. It returns one on success and 266 // zero on error. 267 OPENSSL_EXPORT int ASN1_STRING_copy(ASN1_STRING *dst, const ASN1_STRING *str); 268 269 // ASN1_STRING_dup returns a newly-allocated copy of |str|, or NULL on error. 270 OPENSSL_EXPORT ASN1_STRING *ASN1_STRING_dup(const ASN1_STRING *str); 271 272 // ASN1_STRING_type returns the type of |str|. This value will be one of the 273 // |V_ASN1_*| constants. 274 OPENSSL_EXPORT int ASN1_STRING_type(const ASN1_STRING *str); 275 276 // ASN1_STRING_get0_data returns a pointer to |str|'s contents. Callers should 277 // use |ASN1_STRING_length| to determine the length of the string. The string 278 // may have embedded NUL bytes and may not be NUL-terminated. 279 OPENSSL_EXPORT const unsigned char *ASN1_STRING_get0_data( 280 const ASN1_STRING *str); 281 282 // ASN1_STRING_data returns a mutable pointer to |str|'s contents. Callers 283 // should use |ASN1_STRING_length| to determine the length of the string. The 284 // string may have embedded NUL bytes and may not be NUL-terminated. 285 // 286 // Prefer |ASN1_STRING_get0_data|. 287 OPENSSL_EXPORT unsigned char *ASN1_STRING_data(ASN1_STRING *str); 288 289 // ASN1_STRING_length returns the length of |str|, in bytes. 290 OPENSSL_EXPORT int ASN1_STRING_length(const ASN1_STRING *str); 291 292 // ASN1_STRING_cmp compares |a| and |b|'s type and contents. It returns an 293 // integer equal to, less than, or greater than zero if |a| is equal to, less 294 // than, or greater than |b|, respectively. The comparison is suitable for 295 // sorting, but callers should not rely on the particular comparison. 296 // 297 // Note if |a| or |b| are BIT STRINGs, this function does not compare the 298 // |ASN1_STRING_FLAG_BITS_LEFT| flags. 299 // 300 // TODO(davidben): The BIT STRING comparison seems like a bug. Fix it? 301 OPENSSL_EXPORT int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b); 302 303 // ASN1_STRING_set sets the contents of |str| to a copy of |len| bytes from 304 // |data|. It returns one on success and zero on error. 305 OPENSSL_EXPORT int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len); 306 307 // ASN1_STRING_set0 sets the contents of |str| to |len| bytes from |data|. It 308 // takes ownership of |data|, which must have been allocated with 309 // |OPENSSL_malloc|. 310 OPENSSL_EXPORT void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len); 311 312 // TODO(davidben): Pull up and document functions specific to individual string 313 // types. 314 315 316 // Underdocumented functions. 317 // 318 // The following functions are not yet documented and organized. 319 320 // For use with d2i_ASN1_type_bytes() 321 #define B_ASN1_NUMERICSTRING 0x0001 322 #define B_ASN1_PRINTABLESTRING 0x0002 323 #define B_ASN1_T61STRING 0x0004 324 #define B_ASN1_TELETEXSTRING 0x0004 325 #define B_ASN1_VIDEOTEXSTRING 0x0008 326 #define B_ASN1_IA5STRING 0x0010 327 #define B_ASN1_GRAPHICSTRING 0x0020 328 #define B_ASN1_ISO64STRING 0x0040 329 #define B_ASN1_VISIBLESTRING 0x0040 330 #define B_ASN1_GENERALSTRING 0x0080 331 #define B_ASN1_UNIVERSALSTRING 0x0100 332 #define B_ASN1_OCTET_STRING 0x0200 333 #define B_ASN1_BIT_STRING 0x0400 334 #define B_ASN1_BMPSTRING 0x0800 335 #define B_ASN1_UNKNOWN 0x1000 336 #define B_ASN1_UTF8STRING 0x2000 337 #define B_ASN1_UTCTIME 0x4000 338 #define B_ASN1_GENERALIZEDTIME 0x8000 339 #define B_ASN1_SEQUENCE 0x10000 340 341 // For use with ASN1_mbstring_copy() 342 #define MBSTRING_FLAG 0x1000 343 #define MBSTRING_UTF8 (MBSTRING_FLAG) 344 // |MBSTRING_ASC| refers to Latin-1, not ASCII. It is used with TeletexString 345 // which, in turn, is treated as Latin-1 rather than T.61 by OpenSSL and most 346 // other software. 347 #define MBSTRING_ASC (MBSTRING_FLAG | 1) 348 #define MBSTRING_BMP (MBSTRING_FLAG | 2) 349 #define MBSTRING_UNIV (MBSTRING_FLAG | 4) 350 351 #define DECLARE_ASN1_SET_OF(type) // filled in by mkstack.pl 352 #define IMPLEMENT_ASN1_SET_OF(type) // nothing, no longer needed 353 354 // These are used internally in the ASN1_OBJECT to keep track of 355 // whether the names and data need to be free()ed 356 #define ASN1_OBJECT_FLAG_DYNAMIC 0x01 // internal use 357 #define ASN1_OBJECT_FLAG_DYNAMIC_STRINGS 0x04 // internal use 358 #define ASN1_OBJECT_FLAG_DYNAMIC_DATA 0x08 // internal use 359 struct asn1_object_st { 360 const char *sn, *ln; 361 int nid; 362 int length; 363 const unsigned char *data; // data remains const after init 364 int flags; // Should we free this one 365 }; 366 367 DEFINE_STACK_OF(ASN1_OBJECT) 368 369 // ASN1_ENCODING structure: this is used to save the received 370 // encoding of an ASN1 type. This is useful to get round 371 // problems with invalid encodings which can break signatures. 372 373 typedef struct ASN1_ENCODING_st { 374 unsigned char *enc; // DER encoding 375 long len; // Length of encoding 376 int modified; // set to 1 if 'enc' is invalid 377 // alias_only is zero if |enc| owns the buffer that it points to 378 // (although |enc| may still be NULL). If one, |enc| points into a 379 // buffer that is owned elsewhere. 380 unsigned alias_only : 1; 381 // alias_only_on_next_parse is one iff the next parsing operation 382 // should avoid taking a copy of the input and rather set 383 // |alias_only|. 384 unsigned alias_only_on_next_parse : 1; 385 } ASN1_ENCODING; 386 387 #define STABLE_FLAGS_MALLOC 0x01 388 #define STABLE_NO_MASK 0x02 389 #define DIRSTRING_TYPE \ 390 (B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | B_ASN1_BMPSTRING | \ 391 B_ASN1_UTF8STRING) 392 #define PKCS9STRING_TYPE (DIRSTRING_TYPE | B_ASN1_IA5STRING) 393 394 typedef struct asn1_string_table_st { 395 int nid; 396 long minsize; 397 long maxsize; 398 unsigned long mask; 399 unsigned long flags; 400 } ASN1_STRING_TABLE; 401 402 // size limits: this stuff is taken straight from RFC2459 403 404 #define ub_name 32768 405 #define ub_common_name 64 406 #define ub_locality_name 128 407 #define ub_state_name 128 408 #define ub_organization_name 64 409 #define ub_organization_unit_name 64 410 #define ub_title 64 411 #define ub_email_address 128 412 413 // Declarations for template structures: for full definitions 414 // see asn1t.h 415 typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE; 416 typedef struct ASN1_TLC_st ASN1_TLC; 417 // This is just an opaque pointer 418 typedef struct ASN1_VALUE_st ASN1_VALUE; 419 420 // Declare ASN1 functions: the implement macro in in asn1t.h 421 422 #define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type) 423 424 #define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \ 425 DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, type) 426 427 #define DECLARE_ASN1_FUNCTIONS_name(type, name) \ 428 DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ 429 DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) 430 431 #define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \ 432 DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ 433 DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) 434 435 #define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \ 436 OPENSSL_EXPORT type *d2i_##name(type **a, const unsigned char **in, \ 437 long len); \ 438 OPENSSL_EXPORT int i2d_##name(type *a, unsigned char **out); \ 439 DECLARE_ASN1_ITEM(itname) 440 441 #define DECLARE_ASN1_ENCODE_FUNCTIONS_const(type, name) \ 442 OPENSSL_EXPORT type *d2i_##name(type **a, const unsigned char **in, \ 443 long len); \ 444 OPENSSL_EXPORT int i2d_##name(const type *a, unsigned char **out); \ 445 DECLARE_ASN1_ITEM(name) 446 447 #define DECLARE_ASN1_FUNCTIONS_const(name) \ 448 DECLARE_ASN1_ALLOC_FUNCTIONS(name) \ 449 DECLARE_ASN1_ENCODE_FUNCTIONS_const(name, name) 450 451 #define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ 452 OPENSSL_EXPORT type *name##_new(void); \ 453 OPENSSL_EXPORT void name##_free(type *a); 454 455 #define DECLARE_ASN1_PRINT_FUNCTION(stname) \ 456 DECLARE_ASN1_PRINT_FUNCTION_fname(stname, stname) 457 458 #define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \ 459 OPENSSL_EXPORT int fname##_print_ctx(BIO *out, stname *x, int indent, \ 460 const ASN1_PCTX *pctx); 461 462 typedef void *d2i_of_void(void **, const unsigned char **, long); 463 typedef int i2d_of_void(const void *, unsigned char **); 464 465 // The following macros and typedefs allow an ASN1_ITEM 466 // to be embedded in a structure and referenced. Since 467 // the ASN1_ITEM pointers need to be globally accessible 468 // (possibly from shared libraries) they may exist in 469 // different forms. On platforms that support it the 470 // ASN1_ITEM structure itself will be globally exported. 471 // Other platforms will export a function that returns 472 // an ASN1_ITEM pointer. 473 // 474 // To handle both cases transparently the macros below 475 // should be used instead of hard coding an ASN1_ITEM 476 // pointer in a structure. 477 // 478 // The structure will look like this: 479 // 480 // typedef struct SOMETHING_st { 481 // ... 482 // ASN1_ITEM_EXP *iptr; 483 // ... 484 // } SOMETHING; 485 // 486 // It would be initialised as e.g.: 487 // 488 // SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...}; 489 // 490 // and the actual pointer extracted with: 491 // 492 // const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr); 493 // 494 // Finally an ASN1_ITEM pointer can be extracted from an 495 // appropriate reference with: ASN1_ITEM_rptr(X509). This 496 // would be used when a function takes an ASN1_ITEM * argument. 497 // 498 499 // ASN1_ITEM pointer exported type 500 typedef const ASN1_ITEM ASN1_ITEM_EXP; 501 502 // Macro to obtain ASN1_ITEM pointer from exported type 503 #define ASN1_ITEM_ptr(iptr) (iptr) 504 505 // Macro to include ASN1_ITEM pointer from base type 506 #define ASN1_ITEM_ref(iptr) (&(iptr##_it)) 507 508 #define ASN1_ITEM_rptr(ref) (&(ref##_it)) 509 510 #define DECLARE_ASN1_ITEM(name) extern OPENSSL_EXPORT const ASN1_ITEM name##_it; 511 512 // Parameters used by ASN1_STRING_print_ex() 513 514 // These determine which characters to escape: 515 // RFC2253 special characters, control characters and 516 // MSB set characters 517 518 #define ASN1_STRFLGS_ESC_2253 1 519 #define ASN1_STRFLGS_ESC_CTRL 2 520 #define ASN1_STRFLGS_ESC_MSB 4 521 522 523 // This flag determines how we do escaping: normally 524 // RC2253 backslash only, set this to use backslash and 525 // quote. 526 527 #define ASN1_STRFLGS_ESC_QUOTE 8 528 529 530 // These three flags are internal use only. 531 532 // Character is a valid PrintableString character 533 #define CHARTYPE_PRINTABLESTRING 0x10 534 // Character needs escaping if it is the first character 535 #define CHARTYPE_FIRST_ESC_2253 0x20 536 // Character needs escaping if it is the last character 537 #define CHARTYPE_LAST_ESC_2253 0x40 538 539 // NB the internal flags are safely reused below by flags 540 // handled at the top level. 541 542 // If this is set we convert all character strings 543 // to UTF8 first 544 545 #define ASN1_STRFLGS_UTF8_CONVERT 0x10 546 547 // If this is set we don't attempt to interpret content: 548 // just assume all strings are 1 byte per character. This 549 // will produce some pretty odd looking output! 550 551 #define ASN1_STRFLGS_IGNORE_TYPE 0x20 552 553 // If this is set we include the string type in the output 554 #define ASN1_STRFLGS_SHOW_TYPE 0x40 555 556 // This determines which strings to display and which to 557 // 'dump' (hex dump of content octets or DER encoding). We can 558 // only dump non character strings or everything. If we 559 // don't dump 'unknown' they are interpreted as character 560 // strings with 1 octet per character and are subject to 561 // the usual escaping options. 562 563 #define ASN1_STRFLGS_DUMP_ALL 0x80 564 #define ASN1_STRFLGS_DUMP_UNKNOWN 0x100 565 566 // These determine what 'dumping' does, we can dump the 567 // content octets or the DER encoding: both use the 568 // RFC2253 #XXXXX notation. 569 570 #define ASN1_STRFLGS_DUMP_DER 0x200 571 572 // All the string flags consistent with RFC2253, 573 // escaping control characters isn't essential in 574 // RFC2253 but it is advisable anyway. 575 576 #define ASN1_STRFLGS_RFC2253 \ 577 (ASN1_STRFLGS_ESC_2253 | ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB | \ 578 ASN1_STRFLGS_UTF8_CONVERT | ASN1_STRFLGS_DUMP_UNKNOWN | \ 579 ASN1_STRFLGS_DUMP_DER) 580 581 DEFINE_STACK_OF(ASN1_INTEGER) 582 DECLARE_ASN1_SET_OF(ASN1_INTEGER) 583 584 struct asn1_type_st { 585 int type; 586 union { 587 char *ptr; 588 ASN1_BOOLEAN boolean; 589 ASN1_STRING *asn1_string; 590 ASN1_OBJECT *object; 591 ASN1_INTEGER *integer; 592 ASN1_ENUMERATED *enumerated; 593 ASN1_BIT_STRING *bit_string; 594 ASN1_OCTET_STRING *octet_string; 595 ASN1_PRINTABLESTRING *printablestring; 596 ASN1_T61STRING *t61string; 597 ASN1_IA5STRING *ia5string; 598 ASN1_GENERALSTRING *generalstring; 599 ASN1_BMPSTRING *bmpstring; 600 ASN1_UNIVERSALSTRING *universalstring; 601 ASN1_UTCTIME *utctime; 602 ASN1_GENERALIZEDTIME *generalizedtime; 603 ASN1_VISIBLESTRING *visiblestring; 604 ASN1_UTF8STRING *utf8string; 605 // set and sequence are left complete and still 606 // contain the set or sequence bytes 607 ASN1_STRING *set; 608 ASN1_STRING *sequence; 609 ASN1_VALUE *asn1_value; 610 } value; 611 }; 612 613 DEFINE_STACK_OF(ASN1_TYPE) 614 DECLARE_ASN1_SET_OF(ASN1_TYPE) 615 616 typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY; 617 618 DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY) 619 DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SET_ANY) 620 621 struct X509_algor_st { 622 ASN1_OBJECT *algorithm; 623 ASN1_TYPE *parameter; 624 } /* X509_ALGOR */; 625 626 DECLARE_ASN1_FUNCTIONS(X509_ALGOR) 627 628 // This is used to contain a list of bit names 629 typedef struct BIT_STRING_BITNAME_st { 630 int bitnum; 631 const char *lname; 632 const char *sname; 633 } BIT_STRING_BITNAME; 634 635 // M_ASN1_* are legacy aliases for various |ASN1_STRING| functions. Use the 636 // functions themselves. 637 #define M_ASN1_STRING_length(x) ASN1_STRING_length(x) 638 #define M_ASN1_STRING_type(x) ASN1_STRING_type(x) 639 #define M_ASN1_STRING_data(x) ASN1_STRING_data(x) 640 #define M_ASN1_BIT_STRING_new() ASN1_BIT_STRING_new() 641 #define M_ASN1_BIT_STRING_free(a) ASN1_BIT_STRING_free(a) 642 #define M_ASN1_BIT_STRING_dup(a) ASN1_STRING_dup(a) 643 #define M_ASN1_BIT_STRING_cmp(a, b) ASN1_STRING_cmp(a, b) 644 #define M_ASN1_BIT_STRING_set(a, b, c) ASN1_BIT_STRING_set(a, b, c) 645 #define M_ASN1_INTEGER_new() ASN1_INTEGER_new() 646 #define M_ASN1_INTEGER_free(a) ASN1_INTEGER_free(a) 647 #define M_ASN1_INTEGER_dup(a) ASN1_INTEGER_dup(a) 648 #define M_ASN1_INTEGER_cmp(a, b) ASN1_INTEGER_cmp(a, b) 649 #define M_ASN1_ENUMERATED_new() ASN1_ENUMERATED_new() 650 #define M_ASN1_ENUMERATED_free(a) ASN1_ENUMERATED_free(a) 651 #define M_ASN1_ENUMERATED_dup(a) ASN1_STRING_dup(a) 652 #define M_ASN1_ENUMERATED_cmp(a, b) ASN1_STRING_cmp(a, b) 653 #define M_ASN1_OCTET_STRING_new() ASN1_OCTET_STRING_new() 654 #define M_ASN1_OCTET_STRING_free(a) ASN1_OCTET_STRING_free() 655 #define M_ASN1_OCTET_STRING_dup(a) ASN1_OCTET_STRING_dup(a) 656 #define M_ASN1_OCTET_STRING_cmp(a, b) ASN1_OCTET_STRING_cmp(a, b) 657 #define M_ASN1_OCTET_STRING_set(a, b, c) ASN1_OCTET_STRING_set(a, b, c) 658 #define M_ASN1_OCTET_STRING_print(a, b) ASN1_STRING_print(a, b) 659 #define M_ASN1_PRINTABLESTRING_new() ASN1_PRINTABLESTRING_new() 660 #define M_ASN1_PRINTABLESTRING_free(a) ASN1_PRINTABLESTRING_free(a) 661 #define M_ASN1_IA5STRING_new() ASN1_IA5STRING_new() 662 #define M_ASN1_IA5STRING_free(a) ASN1_IA5STRING_free(a) 663 #define M_ASN1_IA5STRING_dup(a) ASN1_STRING_dup(a) 664 #define M_ASN1_UTCTIME_new() ASN1_UTCTIME_new() 665 #define M_ASN1_UTCTIME_free(a) ASN1_UTCTIME_free(a) 666 #define M_ASN1_UTCTIME_dup(a) ASN1_STRING_dup(a) 667 #define M_ASN1_T61STRING_new() ASN1_T61STRING_new() 668 #define M_ASN1_T61STRING_free(a) ASN1_T61STRING_free(a) 669 #define M_ASN1_GENERALIZEDTIME_new() ASN1_GENERALIZEDTIME_new() 670 #define M_ASN1_GENERALIZEDTIME_free(a) ASN1_GENERALIZEDTIME_free(a) 671 #define M_ASN1_GENERALIZEDTIME_dup(a) ASN1_STRING_dup(a) 672 #define M_ASN1_GENERALSTRING_new() ASN1_GENERALSTRING_new() 673 #define M_ASN1_GENERALSTRING_free(a) ASN1_GENERALSTRING_free(a) 674 #define M_ASN1_UNIVERSALSTRING_new() ASN1_UNIVERSALSTRING_new() 675 #define M_ASN1_UNIVERSALSTRING_free(a) ASN1_UNIVERSALSTRING_free(a) 676 #define M_ASN1_BMPSTRING_new() ASN1_BMPSTRING_new() 677 #define M_ASN1_BMPSTRING_free(a) ASN1_BMPSTRING_free(a) 678 #define M_ASN1_VISIBLESTRING_new() ASN1_VISIBLESTRING_new() 679 #define M_ASN1_VISIBLESTRING_free(a) ASN1_VISIBLESTRING_free(a) 680 #define M_ASN1_UTF8STRING_new() ASN1_UTF8STRING_new() 681 #define M_ASN1_UTF8STRING_free(a) ASN1_UTF8STRING_free(a) 682 683 #define B_ASN1_TIME B_ASN1_UTCTIME | B_ASN1_GENERALIZEDTIME 684 685 #define B_ASN1_PRINTABLE \ 686 B_ASN1_NUMERICSTRING | B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | \ 687 B_ASN1_IA5STRING | B_ASN1_BIT_STRING | B_ASN1_UNIVERSALSTRING | \ 688 B_ASN1_BMPSTRING | B_ASN1_UTF8STRING | B_ASN1_SEQUENCE | B_ASN1_UNKNOWN 689 690 #define B_ASN1_DIRECTORYSTRING \ 691 B_ASN1_PRINTABLESTRING | B_ASN1_TELETEXSTRING | B_ASN1_BMPSTRING | \ 692 B_ASN1_UNIVERSALSTRING | B_ASN1_UTF8STRING 693 694 #define B_ASN1_DISPLAYTEXT \ 695 B_ASN1_IA5STRING | B_ASN1_VISIBLESTRING | B_ASN1_BMPSTRING | B_ASN1_UTF8STRING 696 697 DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) 698 699 OPENSSL_EXPORT int ASN1_TYPE_get(const ASN1_TYPE *a); 700 OPENSSL_EXPORT void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value); 701 OPENSSL_EXPORT int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value); 702 OPENSSL_EXPORT int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b); 703 704 OPENSSL_EXPORT ASN1_OBJECT *ASN1_OBJECT_new(void); 705 OPENSSL_EXPORT void ASN1_OBJECT_free(ASN1_OBJECT *a); 706 OPENSSL_EXPORT int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp); 707 OPENSSL_EXPORT ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, 708 const unsigned char **pp, 709 long length); 710 OPENSSL_EXPORT ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, 711 const unsigned char **pp, 712 long length); 713 714 DECLARE_ASN1_ITEM(ASN1_OBJECT) 715 716 DECLARE_ASN1_SET_OF(ASN1_OBJECT) 717 718 DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING) 719 OPENSSL_EXPORT int i2c_ASN1_BIT_STRING(const ASN1_BIT_STRING *a, 720 unsigned char **pp); 721 OPENSSL_EXPORT ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, 722 const unsigned char **pp, 723 long length); 724 OPENSSL_EXPORT int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, 725 int length); 726 OPENSSL_EXPORT int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, 727 int value); 728 OPENSSL_EXPORT int ASN1_BIT_STRING_get_bit(const ASN1_BIT_STRING *a, int n); 729 OPENSSL_EXPORT int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *a, 730 unsigned char *flags, int flags_len); 731 732 OPENSSL_EXPORT int i2d_ASN1_BOOLEAN(int a, unsigned char **pp); 733 OPENSSL_EXPORT int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, 734 long length); 735 736 DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER) 737 OPENSSL_EXPORT int i2c_ASN1_INTEGER(const ASN1_INTEGER *a, unsigned char **pp); 738 OPENSSL_EXPORT ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, 739 const unsigned char **pp, 740 long length); 741 OPENSSL_EXPORT ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x); 742 OPENSSL_EXPORT int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, 743 const ASN1_INTEGER *y); 744 745 DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED) 746 747 OPENSSL_EXPORT int ASN1_UTCTIME_check(const ASN1_UTCTIME *a); 748 OPENSSL_EXPORT ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t); 749 OPENSSL_EXPORT ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, 750 int offset_day, long offset_sec); 751 OPENSSL_EXPORT int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str); 752 OPENSSL_EXPORT int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t); 753 #if 0 754 time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s); 755 #endif 756 757 OPENSSL_EXPORT int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *a); 758 OPENSSL_EXPORT ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set( 759 ASN1_GENERALIZEDTIME *s, time_t t); 760 OPENSSL_EXPORT ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj( 761 ASN1_GENERALIZEDTIME *s, time_t t, int offset_day, long offset_sec); 762 OPENSSL_EXPORT int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, 763 const char *str); 764 OPENSSL_EXPORT int ASN1_TIME_diff(int *pday, int *psec, const ASN1_TIME *from, 765 const ASN1_TIME *to); 766 767 DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING) 768 OPENSSL_EXPORT ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup( 769 const ASN1_OCTET_STRING *a); 770 OPENSSL_EXPORT int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, 771 const ASN1_OCTET_STRING *b); 772 OPENSSL_EXPORT int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, 773 const unsigned char *data, int len); 774 775 DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) 776 DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) 777 DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING) 778 DECLARE_ASN1_FUNCTIONS(ASN1_NULL) 779 DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING) 780 781 DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE) 782 783 DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING) 784 DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT) 785 DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING) 786 DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING) 787 DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING) 788 DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING) 789 DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME) 790 DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME) 791 DECLARE_ASN1_FUNCTIONS(ASN1_TIME) 792 793 OPENSSL_EXPORT ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t); 794 OPENSSL_EXPORT ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, time_t t, int offset_day, 795 long offset_sec); 796 OPENSSL_EXPORT int ASN1_TIME_check(const ASN1_TIME *t); 797 OPENSSL_EXPORT ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime( 798 const ASN1_TIME *t, ASN1_GENERALIZEDTIME **out); 799 OPENSSL_EXPORT int ASN1_TIME_set_string(ASN1_TIME *s, const char *str); 800 801 OPENSSL_EXPORT int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a); 802 OPENSSL_EXPORT int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a); 803 OPENSSL_EXPORT int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a); 804 OPENSSL_EXPORT int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type); 805 OPENSSL_EXPORT int i2t_ASN1_OBJECT(char *buf, int buf_len, 806 const ASN1_OBJECT *a); 807 808 OPENSSL_EXPORT ASN1_OBJECT *ASN1_OBJECT_create(int nid, unsigned char *data, 809 int len, const char *sn, 810 const char *ln); 811 812 OPENSSL_EXPORT int ASN1_INTEGER_set(ASN1_INTEGER *a, long v); 813 OPENSSL_EXPORT int ASN1_INTEGER_set_uint64(ASN1_INTEGER *out, uint64_t v); 814 OPENSSL_EXPORT long ASN1_INTEGER_get(const ASN1_INTEGER *a); 815 OPENSSL_EXPORT ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, 816 ASN1_INTEGER *ai); 817 OPENSSL_EXPORT BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn); 818 819 OPENSSL_EXPORT int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v); 820 OPENSSL_EXPORT long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a); 821 OPENSSL_EXPORT ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, 822 ASN1_ENUMERATED *ai); 823 OPENSSL_EXPORT BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, 824 BIGNUM *bn); 825 826 // General 827 // given a string, return the correct type, max is the maximum length 828 OPENSSL_EXPORT int ASN1_PRINTABLE_type(const unsigned char *s, int max); 829 830 OPENSSL_EXPORT unsigned long ASN1_tag2bit(int tag); 831 832 // SPECIALS 833 OPENSSL_EXPORT int ASN1_get_object(const unsigned char **pp, long *plength, 834 int *ptag, int *pclass, long omax); 835 OPENSSL_EXPORT void ASN1_put_object(unsigned char **pp, int constructed, 836 int length, int tag, int xclass); 837 OPENSSL_EXPORT int ASN1_put_eoc(unsigned char **pp); 838 OPENSSL_EXPORT int ASN1_object_size(int constructed, int length, int tag); 839 840 OPENSSL_EXPORT void *ASN1_item_dup(const ASN1_ITEM *it, void *x); 841 842 #ifndef OPENSSL_NO_FP_API 843 OPENSSL_EXPORT void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x); 844 OPENSSL_EXPORT int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x); 845 OPENSSL_EXPORT int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, 846 unsigned long flags); 847 #endif 848 849 OPENSSL_EXPORT int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in); 850 851 OPENSSL_EXPORT void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x); 852 OPENSSL_EXPORT int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x); 853 OPENSSL_EXPORT int ASN1_UTCTIME_print(BIO *fp, const ASN1_UTCTIME *a); 854 OPENSSL_EXPORT int ASN1_GENERALIZEDTIME_print(BIO *fp, 855 const ASN1_GENERALIZEDTIME *a); 856 OPENSSL_EXPORT int ASN1_TIME_print(BIO *fp, const ASN1_TIME *a); 857 OPENSSL_EXPORT int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v); 858 OPENSSL_EXPORT int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, 859 unsigned long flags); 860 OPENSSL_EXPORT const char *ASN1_tag2str(int tag); 861 862 // Used to load and write netscape format cert 863 864 OPENSSL_EXPORT void *ASN1_item_unpack(const ASN1_STRING *oct, 865 const ASN1_ITEM *it); 866 867 OPENSSL_EXPORT ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, 868 ASN1_OCTET_STRING **oct); 869 870 OPENSSL_EXPORT void ASN1_STRING_set_default_mask(unsigned long mask); 871 OPENSSL_EXPORT int ASN1_STRING_set_default_mask_asc(const char *p); 872 OPENSSL_EXPORT unsigned long ASN1_STRING_get_default_mask(void); 873 OPENSSL_EXPORT int ASN1_mbstring_copy(ASN1_STRING **out, 874 const unsigned char *in, int len, 875 int inform, unsigned long mask); 876 OPENSSL_EXPORT int ASN1_mbstring_ncopy(ASN1_STRING **out, 877 const unsigned char *in, int len, 878 int inform, unsigned long mask, 879 long minsize, long maxsize); 880 881 OPENSSL_EXPORT ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, 882 const unsigned char *in, 883 int inlen, int inform, 884 int nid); 885 OPENSSL_EXPORT ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid); 886 OPENSSL_EXPORT int ASN1_STRING_TABLE_add(int, long, long, unsigned long, 887 unsigned long); 888 OPENSSL_EXPORT void ASN1_STRING_TABLE_cleanup(void); 889 890 // ASN1 template functions 891 892 // Old API compatible functions 893 OPENSSL_EXPORT ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it); 894 OPENSSL_EXPORT void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it); 895 OPENSSL_EXPORT ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **val, 896 const unsigned char **in, long len, 897 const ASN1_ITEM *it); 898 OPENSSL_EXPORT int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, 899 const ASN1_ITEM *it); 900 901 OPENSSL_EXPORT ASN1_TYPE *ASN1_generate_nconf(const char *str, CONF *nconf); 902 OPENSSL_EXPORT ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf); 903 904 905 #ifdef __cplusplus 906 } 907 908 extern "C++" { 909 910 BSSL_NAMESPACE_BEGIN 911 912 BORINGSSL_MAKE_DELETER(ASN1_OBJECT, ASN1_OBJECT_free) 913 BORINGSSL_MAKE_DELETER(ASN1_STRING, ASN1_STRING_free) 914 BORINGSSL_MAKE_DELETER(ASN1_TYPE, ASN1_TYPE_free) 915 916 BSSL_NAMESPACE_END 917 918 } // extern C++ 919 920 #endif 921 922 #define ASN1_R_ASN1_LENGTH_MISMATCH 100 923 #define ASN1_R_AUX_ERROR 101 924 #define ASN1_R_BAD_GET_ASN1_OBJECT_CALL 102 925 #define ASN1_R_BAD_OBJECT_HEADER 103 926 #define ASN1_R_BMPSTRING_IS_WRONG_LENGTH 104 927 #define ASN1_R_BN_LIB 105 928 #define ASN1_R_BOOLEAN_IS_WRONG_LENGTH 106 929 #define ASN1_R_BUFFER_TOO_SMALL 107 930 #define ASN1_R_CONTEXT_NOT_INITIALISED 108 931 #define ASN1_R_DECODE_ERROR 109 932 #define ASN1_R_DEPTH_EXCEEDED 110 933 #define ASN1_R_DIGEST_AND_KEY_TYPE_NOT_SUPPORTED 111 934 #define ASN1_R_ENCODE_ERROR 112 935 #define ASN1_R_ERROR_GETTING_TIME 113 936 #define ASN1_R_EXPECTING_AN_ASN1_SEQUENCE 114 937 #define ASN1_R_EXPECTING_AN_INTEGER 115 938 #define ASN1_R_EXPECTING_AN_OBJECT 116 939 #define ASN1_R_EXPECTING_A_BOOLEAN 117 940 #define ASN1_R_EXPECTING_A_TIME 118 941 #define ASN1_R_EXPLICIT_LENGTH_MISMATCH 119 942 #define ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED 120 943 #define ASN1_R_FIELD_MISSING 121 944 #define ASN1_R_FIRST_NUM_TOO_LARGE 122 945 #define ASN1_R_HEADER_TOO_LONG 123 946 #define ASN1_R_ILLEGAL_BITSTRING_FORMAT 124 947 #define ASN1_R_ILLEGAL_BOOLEAN 125 948 #define ASN1_R_ILLEGAL_CHARACTERS 126 949 #define ASN1_R_ILLEGAL_FORMAT 127 950 #define ASN1_R_ILLEGAL_HEX 128 951 #define ASN1_R_ILLEGAL_IMPLICIT_TAG 129 952 #define ASN1_R_ILLEGAL_INTEGER 130 953 #define ASN1_R_ILLEGAL_NESTED_TAGGING 131 954 #define ASN1_R_ILLEGAL_NULL 132 955 #define ASN1_R_ILLEGAL_NULL_VALUE 133 956 #define ASN1_R_ILLEGAL_OBJECT 134 957 #define ASN1_R_ILLEGAL_OPTIONAL_ANY 135 958 #define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 136 959 #define ASN1_R_ILLEGAL_TAGGED_ANY 137 960 #define ASN1_R_ILLEGAL_TIME_VALUE 138 961 #define ASN1_R_INTEGER_NOT_ASCII_FORMAT 139 962 #define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 140 963 #define ASN1_R_INVALID_BIT_STRING_BITS_LEFT 141 964 #define ASN1_R_INVALID_BMPSTRING 142 965 #define ASN1_R_INVALID_DIGIT 143 966 #define ASN1_R_INVALID_MODIFIER 144 967 #define ASN1_R_INVALID_NUMBER 145 968 #define ASN1_R_INVALID_OBJECT_ENCODING 146 969 #define ASN1_R_INVALID_SEPARATOR 147 970 #define ASN1_R_INVALID_TIME_FORMAT 148 971 #define ASN1_R_INVALID_UNIVERSALSTRING 149 972 #define ASN1_R_INVALID_UTF8STRING 150 973 #define ASN1_R_LIST_ERROR 151 974 #define ASN1_R_MISSING_ASN1_EOS 152 975 #define ASN1_R_MISSING_EOC 153 976 #define ASN1_R_MISSING_SECOND_NUMBER 154 977 #define ASN1_R_MISSING_VALUE 155 978 #define ASN1_R_MSTRING_NOT_UNIVERSAL 156 979 #define ASN1_R_MSTRING_WRONG_TAG 157 980 #define ASN1_R_NESTED_ASN1_ERROR 158 981 #define ASN1_R_NESTED_ASN1_STRING 159 982 #define ASN1_R_NON_HEX_CHARACTERS 160 983 #define ASN1_R_NOT_ASCII_FORMAT 161 984 #define ASN1_R_NOT_ENOUGH_DATA 162 985 #define ASN1_R_NO_MATCHING_CHOICE_TYPE 163 986 #define ASN1_R_NULL_IS_WRONG_LENGTH 164 987 #define ASN1_R_OBJECT_NOT_ASCII_FORMAT 165 988 #define ASN1_R_ODD_NUMBER_OF_CHARS 166 989 #define ASN1_R_SECOND_NUMBER_TOO_LARGE 167 990 #define ASN1_R_SEQUENCE_LENGTH_MISMATCH 168 991 #define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 169 992 #define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG 170 993 #define ASN1_R_SHORT_LINE 171 994 #define ASN1_R_STREAMING_NOT_SUPPORTED 172 995 #define ASN1_R_STRING_TOO_LONG 173 996 #define ASN1_R_STRING_TOO_SHORT 174 997 #define ASN1_R_TAG_VALUE_TOO_HIGH 175 998 #define ASN1_R_TIME_NOT_ASCII_FORMAT 176 999 #define ASN1_R_TOO_LONG 177 1000 #define ASN1_R_TYPE_NOT_CONSTRUCTED 178 1001 #define ASN1_R_TYPE_NOT_PRIMITIVE 179 1002 #define ASN1_R_UNEXPECTED_EOC 180 1003 #define ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH 181 1004 #define ASN1_R_UNKNOWN_FORMAT 182 1005 #define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 183 1006 #define ASN1_R_UNKNOWN_SIGNATURE_ALGORITHM 184 1007 #define ASN1_R_UNKNOWN_TAG 185 1008 #define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 186 1009 #define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 187 1010 #define ASN1_R_UNSUPPORTED_TYPE 188 1011 #define ASN1_R_WRONG_PUBLIC_KEY_TYPE 189 1012 #define ASN1_R_WRONG_TAG 190 1013 #define ASN1_R_WRONG_TYPE 191 1014 #define ASN1_R_NESTED_TOO_DEEP 192 1015 #define ASN1_R_BAD_TEMPLATE 193 1016 1017 #endif 1018