1/* 2 * {- join("\n * ", @autowarntext) -} 3 * 4 * Copyright 1999-2021 The OpenSSL Project Authors. All Rights Reserved. 5 * 6 * Licensed under the Apache License 2.0 (the "License"). You may not use 7 * this file except in compliance with the License. You can obtain a copy 8 * in the file LICENSE in the source distribution or at 9 * https://www.openssl.org/source/license.html 10 */ 11 12{- 13use OpenSSL::stackhash qw(generate_stack_macros); 14-} 15 16#ifndef OPENSSL_X509V3_H 17# define OPENSSL_X509V3_H 18# pragma once 19 20# include <openssl/macros.h> 21# ifndef OPENSSL_NO_DEPRECATED_3_0 22# define HEADER_X509V3_H 23# endif 24 25# include <openssl/bio.h> 26# include <openssl/x509.h> 27# include <openssl/conf.h> 28# include <openssl/x509v3err.h> 29 30#ifdef __cplusplus 31extern "C" { 32#endif 33 34/* Forward reference */ 35struct v3_ext_method; 36struct v3_ext_ctx; 37 38/* Useful typedefs */ 39 40typedef void *(*X509V3_EXT_NEW)(void); 41typedef void (*X509V3_EXT_FREE) (void *); 42typedef void *(*X509V3_EXT_D2I)(void *, const unsigned char **, long); 43typedef int (*X509V3_EXT_I2D) (const void *, unsigned char **); 44typedef STACK_OF(CONF_VALUE) * 45 (*X509V3_EXT_I2V) (const struct v3_ext_method *method, void *ext, 46 STACK_OF(CONF_VALUE) *extlist); 47typedef void *(*X509V3_EXT_V2I)(const struct v3_ext_method *method, 48 struct v3_ext_ctx *ctx, 49 STACK_OF(CONF_VALUE) *values); 50typedef char *(*X509V3_EXT_I2S)(const struct v3_ext_method *method, 51 void *ext); 52typedef void *(*X509V3_EXT_S2I)(const struct v3_ext_method *method, 53 struct v3_ext_ctx *ctx, const char *str); 54typedef int (*X509V3_EXT_I2R) (const struct v3_ext_method *method, void *ext, 55 BIO *out, int indent); 56typedef void *(*X509V3_EXT_R2I)(const struct v3_ext_method *method, 57 struct v3_ext_ctx *ctx, const char *str); 58 59/* V3 extension structure */ 60 61struct v3_ext_method { 62 int ext_nid; 63 int ext_flags; 64/* If this is set the following four fields are ignored */ 65 ASN1_ITEM_EXP *it; 66/* Old style ASN1 calls */ 67 X509V3_EXT_NEW ext_new; 68 X509V3_EXT_FREE ext_free; 69 X509V3_EXT_D2I d2i; 70 X509V3_EXT_I2D i2d; 71/* The following pair is used for string extensions */ 72 X509V3_EXT_I2S i2s; 73 X509V3_EXT_S2I s2i; 74/* The following pair is used for multi-valued extensions */ 75 X509V3_EXT_I2V i2v; 76 X509V3_EXT_V2I v2i; 77/* The following are used for raw extensions */ 78 X509V3_EXT_I2R i2r; 79 X509V3_EXT_R2I r2i; 80 void *usr_data; /* Any extension specific data */ 81}; 82 83typedef struct X509V3_CONF_METHOD_st { 84 char *(*get_string) (void *db, const char *section, const char *value); 85 STACK_OF(CONF_VALUE) *(*get_section) (void *db, const char *section); 86 void (*free_string) (void *db, char *string); 87 void (*free_section) (void *db, STACK_OF(CONF_VALUE) *section); 88} X509V3_CONF_METHOD; 89 90/* Context specific info for producing X509 v3 extensions*/ 91struct v3_ext_ctx { 92# define X509V3_CTX_TEST 0x1 93# ifndef OPENSSL_NO_DEPRECATED_3_0 94# define CTX_TEST X509V3_CTX_TEST 95# endif 96# define X509V3_CTX_REPLACE 0x2 97 int flags; 98 X509 *issuer_cert; 99 X509 *subject_cert; 100 X509_REQ *subject_req; 101 X509_CRL *crl; 102 X509V3_CONF_METHOD *db_meth; 103 void *db; 104 EVP_PKEY *issuer_pkey; 105/* Maybe more here */ 106}; 107 108typedef struct v3_ext_method X509V3_EXT_METHOD; 109 110{- 111 generate_stack_macros("X509V3_EXT_METHOD"); 112-} 113 114/* ext_flags values */ 115# define X509V3_EXT_DYNAMIC 0x1 116# define X509V3_EXT_CTX_DEP 0x2 117# define X509V3_EXT_MULTILINE 0x4 118 119typedef BIT_STRING_BITNAME ENUMERATED_NAMES; 120 121typedef struct BASIC_CONSTRAINTS_st { 122 int ca; 123 ASN1_INTEGER *pathlen; 124} BASIC_CONSTRAINTS; 125 126typedef struct PKEY_USAGE_PERIOD_st { 127 ASN1_GENERALIZEDTIME *notBefore; 128 ASN1_GENERALIZEDTIME *notAfter; 129} PKEY_USAGE_PERIOD; 130 131typedef struct otherName_st { 132 ASN1_OBJECT *type_id; 133 ASN1_TYPE *value; 134} OTHERNAME; 135 136typedef struct EDIPartyName_st { 137 ASN1_STRING *nameAssigner; 138 ASN1_STRING *partyName; 139} EDIPARTYNAME; 140 141typedef struct GENERAL_NAME_st { 142# define GEN_OTHERNAME 0 143# define GEN_EMAIL 1 144# define GEN_DNS 2 145# define GEN_X400 3 146# define GEN_DIRNAME 4 147# define GEN_EDIPARTY 5 148# define GEN_URI 6 149# define GEN_IPADD 7 150# define GEN_RID 8 151 int type; 152 union { 153 char *ptr; 154 OTHERNAME *otherName; /* otherName */ 155 ASN1_IA5STRING *rfc822Name; 156 ASN1_IA5STRING *dNSName; 157 ASN1_STRING *x400Address; 158 X509_NAME *directoryName; 159 EDIPARTYNAME *ediPartyName; 160 ASN1_IA5STRING *uniformResourceIdentifier; 161 ASN1_OCTET_STRING *iPAddress; 162 ASN1_OBJECT *registeredID; 163 /* Old names */ 164 ASN1_OCTET_STRING *ip; /* iPAddress */ 165 X509_NAME *dirn; /* dirn */ 166 ASN1_IA5STRING *ia5; /* rfc822Name, dNSName, 167 * uniformResourceIdentifier */ 168 ASN1_OBJECT *rid; /* registeredID */ 169 ASN1_TYPE *other; /* x400Address */ 170 } d; 171} GENERAL_NAME; 172 173typedef struct ACCESS_DESCRIPTION_st { 174 ASN1_OBJECT *method; 175 GENERAL_NAME *location; 176} ACCESS_DESCRIPTION; 177 178{- 179 generate_stack_macros("ACCESS_DESCRIPTION") 180 .generate_stack_macros("GENERAL_NAME"); 181-} 182 183typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS; 184typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE; 185typedef STACK_OF(ASN1_INTEGER) TLS_FEATURE; 186typedef STACK_OF(GENERAL_NAME) GENERAL_NAMES; 187 188{- 189 generate_stack_macros("GENERAL_NAMES"); 190-} 191 192typedef struct DIST_POINT_NAME_st { 193 int type; 194 union { 195 GENERAL_NAMES *fullname; 196 STACK_OF(X509_NAME_ENTRY) *relativename; 197 } name; 198/* If relativename then this contains the full distribution point name */ 199 X509_NAME *dpname; 200} DIST_POINT_NAME; 201/* All existing reasons */ 202# define CRLDP_ALL_REASONS 0x807f 203 204# define CRL_REASON_NONE -1 205# define CRL_REASON_UNSPECIFIED 0 206# define CRL_REASON_KEY_COMPROMISE 1 207# define CRL_REASON_CA_COMPROMISE 2 208# define CRL_REASON_AFFILIATION_CHANGED 3 209# define CRL_REASON_SUPERSEDED 4 210# define CRL_REASON_CESSATION_OF_OPERATION 5 211# define CRL_REASON_CERTIFICATE_HOLD 6 212# define CRL_REASON_REMOVE_FROM_CRL 8 213# define CRL_REASON_PRIVILEGE_WITHDRAWN 9 214# define CRL_REASON_AA_COMPROMISE 10 215 216struct DIST_POINT_st { 217 DIST_POINT_NAME *distpoint; 218 ASN1_BIT_STRING *reasons; 219 GENERAL_NAMES *CRLissuer; 220 int dp_reasons; 221}; 222 223{- 224 generate_stack_macros("DIST_POINT"); 225-} 226 227typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS; 228 229struct AUTHORITY_KEYID_st { 230 ASN1_OCTET_STRING *keyid; 231 GENERAL_NAMES *issuer; 232 ASN1_INTEGER *serial; 233}; 234 235/* Strong extranet structures */ 236 237typedef struct SXNET_ID_st { 238 ASN1_INTEGER *zone; 239 ASN1_OCTET_STRING *user; 240} SXNETID; 241 242{- 243 generate_stack_macros("SXNETID"); 244-} 245 246 247typedef struct SXNET_st { 248 ASN1_INTEGER *version; 249 STACK_OF(SXNETID) *ids; 250} SXNET; 251 252typedef struct ISSUER_SIGN_TOOL_st { 253 ASN1_UTF8STRING *signTool; 254 ASN1_UTF8STRING *cATool; 255 ASN1_UTF8STRING *signToolCert; 256 ASN1_UTF8STRING *cAToolCert; 257} ISSUER_SIGN_TOOL; 258 259typedef struct NOTICEREF_st { 260 ASN1_STRING *organization; 261 STACK_OF(ASN1_INTEGER) *noticenos; 262} NOTICEREF; 263 264typedef struct USERNOTICE_st { 265 NOTICEREF *noticeref; 266 ASN1_STRING *exptext; 267} USERNOTICE; 268 269typedef struct POLICYQUALINFO_st { 270 ASN1_OBJECT *pqualid; 271 union { 272 ASN1_IA5STRING *cpsuri; 273 USERNOTICE *usernotice; 274 ASN1_TYPE *other; 275 } d; 276} POLICYQUALINFO; 277 278{- 279 generate_stack_macros("POLICYQUALINFO"); 280-} 281 282 283typedef struct POLICYINFO_st { 284 ASN1_OBJECT *policyid; 285 STACK_OF(POLICYQUALINFO) *qualifiers; 286} POLICYINFO; 287 288{- 289 generate_stack_macros("POLICYINFO"); 290-} 291 292typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES; 293 294typedef struct POLICY_MAPPING_st { 295 ASN1_OBJECT *issuerDomainPolicy; 296 ASN1_OBJECT *subjectDomainPolicy; 297} POLICY_MAPPING; 298 299{- 300 generate_stack_macros("POLICY_MAPPING"); 301-} 302 303typedef STACK_OF(POLICY_MAPPING) POLICY_MAPPINGS; 304 305typedef struct GENERAL_SUBTREE_st { 306 GENERAL_NAME *base; 307 ASN1_INTEGER *minimum; 308 ASN1_INTEGER *maximum; 309} GENERAL_SUBTREE; 310 311{- 312 generate_stack_macros("GENERAL_SUBTREE"); 313-} 314 315struct NAME_CONSTRAINTS_st { 316 STACK_OF(GENERAL_SUBTREE) *permittedSubtrees; 317 STACK_OF(GENERAL_SUBTREE) *excludedSubtrees; 318}; 319 320typedef struct POLICY_CONSTRAINTS_st { 321 ASN1_INTEGER *requireExplicitPolicy; 322 ASN1_INTEGER *inhibitPolicyMapping; 323} POLICY_CONSTRAINTS; 324 325/* Proxy certificate structures, see RFC 3820 */ 326typedef struct PROXY_POLICY_st { 327 ASN1_OBJECT *policyLanguage; 328 ASN1_OCTET_STRING *policy; 329} PROXY_POLICY; 330 331typedef struct PROXY_CERT_INFO_EXTENSION_st { 332 ASN1_INTEGER *pcPathLengthConstraint; 333 PROXY_POLICY *proxyPolicy; 334} PROXY_CERT_INFO_EXTENSION; 335 336DECLARE_ASN1_FUNCTIONS(PROXY_POLICY) 337DECLARE_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION) 338 339struct ISSUING_DIST_POINT_st { 340 DIST_POINT_NAME *distpoint; 341 int onlyuser; 342 int onlyCA; 343 ASN1_BIT_STRING *onlysomereasons; 344 int indirectCRL; 345 int onlyattr; 346}; 347 348/* Values in idp_flags field */ 349/* IDP present */ 350# define IDP_PRESENT 0x1 351/* IDP values inconsistent */ 352# define IDP_INVALID 0x2 353/* onlyuser true */ 354# define IDP_ONLYUSER 0x4 355/* onlyCA true */ 356# define IDP_ONLYCA 0x8 357/* onlyattr true */ 358# define IDP_ONLYATTR 0x10 359/* indirectCRL true */ 360# define IDP_INDIRECT 0x20 361/* onlysomereasons present */ 362# define IDP_REASONS 0x40 363 364# define X509V3_conf_err(val) ERR_add_error_data(6, \ 365 "section:", (val)->section, \ 366 ",name:", (val)->name, ",value:", (val)->value) 367 368# define X509V3_set_ctx_test(ctx) \ 369 X509V3_set_ctx(ctx, NULL, NULL, NULL, NULL, X509V3_CTX_TEST) 370# define X509V3_set_ctx_nodb(ctx) (ctx)->db = NULL; 371 372# define EXT_BITSTRING(nid, table) { nid, 0, ASN1_ITEM_ref(ASN1_BIT_STRING), \ 373 0,0,0,0, \ 374 0,0, \ 375 (X509V3_EXT_I2V)i2v_ASN1_BIT_STRING, \ 376 (X509V3_EXT_V2I)v2i_ASN1_BIT_STRING, \ 377 NULL, NULL, \ 378 table} 379 380# define EXT_IA5STRING(nid) { nid, 0, ASN1_ITEM_ref(ASN1_IA5STRING), \ 381 0,0,0,0, \ 382 (X509V3_EXT_I2S)i2s_ASN1_IA5STRING, \ 383 (X509V3_EXT_S2I)s2i_ASN1_IA5STRING, \ 384 0,0,0,0, \ 385 NULL} 386 387#define EXT_UTF8STRING(nid) { nid, 0, ASN1_ITEM_ref(ASN1_UTF8STRING), \ 388 0,0,0,0, \ 389 (X509V3_EXT_I2S)i2s_ASN1_UTF8STRING, \ 390 (X509V3_EXT_S2I)s2i_ASN1_UTF8STRING, \ 391 0,0,0,0, \ 392 NULL} 393 394# define EXT_END { -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 395 396/* X509_PURPOSE stuff */ 397 398# define EXFLAG_BCONS 0x1 399# define EXFLAG_KUSAGE 0x2 400# define EXFLAG_XKUSAGE 0x4 401# define EXFLAG_NSCERT 0x8 402 403# define EXFLAG_CA 0x10 404# define EXFLAG_SI 0x20 /* self-issued, maybe not self-signed */ 405# define EXFLAG_V1 0x40 406# define EXFLAG_INVALID 0x80 407/* EXFLAG_SET is set to indicate that some values have been precomputed */ 408# define EXFLAG_SET 0x100 409# define EXFLAG_CRITICAL 0x200 410# define EXFLAG_PROXY 0x400 411 412# define EXFLAG_INVALID_POLICY 0x800 413# define EXFLAG_FRESHEST 0x1000 414# define EXFLAG_SS 0x2000 /* cert is apparently self-signed */ 415 416# define EXFLAG_BCONS_CRITICAL 0x10000 417# define EXFLAG_AKID_CRITICAL 0x20000 418# define EXFLAG_SKID_CRITICAL 0x40000 419# define EXFLAG_SAN_CRITICAL 0x80000 420# define EXFLAG_NO_FINGERPRINT 0x100000 421 422# define KU_DIGITAL_SIGNATURE 0x0080 423# define KU_NON_REPUDIATION 0x0040 424# define KU_KEY_ENCIPHERMENT 0x0020 425# define KU_DATA_ENCIPHERMENT 0x0010 426# define KU_KEY_AGREEMENT 0x0008 427# define KU_KEY_CERT_SIGN 0x0004 428# define KU_CRL_SIGN 0x0002 429# define KU_ENCIPHER_ONLY 0x0001 430# define KU_DECIPHER_ONLY 0x8000 431 432# define NS_SSL_CLIENT 0x80 433# define NS_SSL_SERVER 0x40 434# define NS_SMIME 0x20 435# define NS_OBJSIGN 0x10 436# define NS_SSL_CA 0x04 437# define NS_SMIME_CA 0x02 438# define NS_OBJSIGN_CA 0x01 439# define NS_ANY_CA (NS_SSL_CA|NS_SMIME_CA|NS_OBJSIGN_CA) 440 441# define XKU_SSL_SERVER 0x1 442# define XKU_SSL_CLIENT 0x2 443# define XKU_SMIME 0x4 444# define XKU_CODE_SIGN 0x8 445# define XKU_SGC 0x10 /* Netscape or MS Server-Gated Crypto */ 446# define XKU_OCSP_SIGN 0x20 447# define XKU_TIMESTAMP 0x40 448# define XKU_DVCS 0x80 449# define XKU_ANYEKU 0x100 450 451# define X509_PURPOSE_DYNAMIC 0x1 452# define X509_PURPOSE_DYNAMIC_NAME 0x2 453 454typedef struct x509_purpose_st { 455 int purpose; 456 int trust; /* Default trust ID */ 457 int flags; 458 int (*check_purpose) (const struct x509_purpose_st *, const X509 *, int); 459 char *name; 460 char *sname; 461 void *usr_data; 462} X509_PURPOSE; 463 464{- 465 generate_stack_macros("X509_PURPOSE"); 466-} 467 468 469# define X509_PURPOSE_SSL_CLIENT 1 470# define X509_PURPOSE_SSL_SERVER 2 471# define X509_PURPOSE_NS_SSL_SERVER 3 472# define X509_PURPOSE_SMIME_SIGN 4 473# define X509_PURPOSE_SMIME_ENCRYPT 5 474# define X509_PURPOSE_CRL_SIGN 6 475# define X509_PURPOSE_ANY 7 476# define X509_PURPOSE_OCSP_HELPER 8 477# define X509_PURPOSE_TIMESTAMP_SIGN 9 478 479# define X509_PURPOSE_MIN 1 480# define X509_PURPOSE_MAX 9 481 482/* Flags for X509V3_EXT_print() */ 483 484# define X509V3_EXT_UNKNOWN_MASK (0xfL << 16) 485/* Return error for unknown extensions */ 486# define X509V3_EXT_DEFAULT 0 487/* Print error for unknown extensions */ 488# define X509V3_EXT_ERROR_UNKNOWN (1L << 16) 489/* ASN1 parse unknown extensions */ 490# define X509V3_EXT_PARSE_UNKNOWN (2L << 16) 491/* BIO_dump unknown extensions */ 492# define X509V3_EXT_DUMP_UNKNOWN (3L << 16) 493 494/* Flags for X509V3_add1_i2d */ 495 496# define X509V3_ADD_OP_MASK 0xfL 497# define X509V3_ADD_DEFAULT 0L 498# define X509V3_ADD_APPEND 1L 499# define X509V3_ADD_REPLACE 2L 500# define X509V3_ADD_REPLACE_EXISTING 3L 501# define X509V3_ADD_KEEP_EXISTING 4L 502# define X509V3_ADD_DELETE 5L 503# define X509V3_ADD_SILENT 0x10 504 505DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS) 506 507DECLARE_ASN1_FUNCTIONS(SXNET) 508DECLARE_ASN1_FUNCTIONS(SXNETID) 509 510DECLARE_ASN1_FUNCTIONS(ISSUER_SIGN_TOOL) 511 512int SXNET_add_id_asc(SXNET **psx, const char *zone, const char *user, int userlen); 513int SXNET_add_id_ulong(SXNET **psx, unsigned long lzone, const char *user, 514 int userlen); 515int SXNET_add_id_INTEGER(SXNET **psx, ASN1_INTEGER *izone, const char *user, 516 int userlen); 517 518ASN1_OCTET_STRING *SXNET_get_id_asc(SXNET *sx, const char *zone); 519ASN1_OCTET_STRING *SXNET_get_id_ulong(SXNET *sx, unsigned long lzone); 520ASN1_OCTET_STRING *SXNET_get_id_INTEGER(SXNET *sx, ASN1_INTEGER *zone); 521 522DECLARE_ASN1_FUNCTIONS(AUTHORITY_KEYID) 523 524DECLARE_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD) 525 526DECLARE_ASN1_FUNCTIONS(GENERAL_NAME) 527DECLARE_ASN1_DUP_FUNCTION(GENERAL_NAME) 528int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b); 529 530ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, 531 X509V3_CTX *ctx, 532 STACK_OF(CONF_VALUE) *nval); 533STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, 534 ASN1_BIT_STRING *bits, 535 STACK_OF(CONF_VALUE) *extlist); 536char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5); 537ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, 538 X509V3_CTX *ctx, const char *str); 539char *i2s_ASN1_UTF8STRING(X509V3_EXT_METHOD *method, ASN1_UTF8STRING *utf8); 540ASN1_UTF8STRING *s2i_ASN1_UTF8STRING(X509V3_EXT_METHOD *method, 541 X509V3_CTX *ctx, const char *str); 542 543STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, 544 GENERAL_NAME *gen, 545 STACK_OF(CONF_VALUE) *ret); 546int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen); 547 548DECLARE_ASN1_FUNCTIONS(GENERAL_NAMES) 549 550STACK_OF(CONF_VALUE) *i2v_GENERAL_NAMES(X509V3_EXT_METHOD *method, 551 GENERAL_NAMES *gen, 552 STACK_OF(CONF_VALUE) *extlist); 553GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method, 554 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); 555 556DECLARE_ASN1_FUNCTIONS(OTHERNAME) 557DECLARE_ASN1_FUNCTIONS(EDIPARTYNAME) 558int OTHERNAME_cmp(OTHERNAME *a, OTHERNAME *b); 559void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value); 560void *GENERAL_NAME_get0_value(const GENERAL_NAME *a, int *ptype); 561int GENERAL_NAME_set0_othername(GENERAL_NAME *gen, 562 ASN1_OBJECT *oid, ASN1_TYPE *value); 563int GENERAL_NAME_get0_otherName(const GENERAL_NAME *gen, 564 ASN1_OBJECT **poid, ASN1_TYPE **pvalue); 565 566char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, 567 const ASN1_OCTET_STRING *ia5); 568ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, 569 X509V3_CTX *ctx, const char *str); 570 571DECLARE_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE) 572int i2a_ACCESS_DESCRIPTION(BIO *bp, const ACCESS_DESCRIPTION *a); 573 574DECLARE_ASN1_ALLOC_FUNCTIONS(TLS_FEATURE) 575 576DECLARE_ASN1_FUNCTIONS(CERTIFICATEPOLICIES) 577DECLARE_ASN1_FUNCTIONS(POLICYINFO) 578DECLARE_ASN1_FUNCTIONS(POLICYQUALINFO) 579DECLARE_ASN1_FUNCTIONS(USERNOTICE) 580DECLARE_ASN1_FUNCTIONS(NOTICEREF) 581 582DECLARE_ASN1_FUNCTIONS(CRL_DIST_POINTS) 583DECLARE_ASN1_FUNCTIONS(DIST_POINT) 584DECLARE_ASN1_FUNCTIONS(DIST_POINT_NAME) 585DECLARE_ASN1_FUNCTIONS(ISSUING_DIST_POINT) 586 587int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, const X509_NAME *iname); 588 589int NAME_CONSTRAINTS_check(X509 *x, NAME_CONSTRAINTS *nc); 590int NAME_CONSTRAINTS_check_CN(X509 *x, NAME_CONSTRAINTS *nc); 591 592DECLARE_ASN1_FUNCTIONS(ACCESS_DESCRIPTION) 593DECLARE_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS) 594 595DECLARE_ASN1_ITEM(POLICY_MAPPING) 596DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING) 597DECLARE_ASN1_ITEM(POLICY_MAPPINGS) 598 599DECLARE_ASN1_ITEM(GENERAL_SUBTREE) 600DECLARE_ASN1_ALLOC_FUNCTIONS(GENERAL_SUBTREE) 601 602DECLARE_ASN1_ITEM(NAME_CONSTRAINTS) 603DECLARE_ASN1_ALLOC_FUNCTIONS(NAME_CONSTRAINTS) 604 605DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS) 606DECLARE_ASN1_ITEM(POLICY_CONSTRAINTS) 607 608GENERAL_NAME *a2i_GENERAL_NAME(GENERAL_NAME *out, 609 const X509V3_EXT_METHOD *method, 610 X509V3_CTX *ctx, int gen_type, 611 const char *value, int is_nc); 612 613# ifdef OPENSSL_CONF_H 614GENERAL_NAME *v2i_GENERAL_NAME(const X509V3_EXT_METHOD *method, 615 X509V3_CTX *ctx, CONF_VALUE *cnf); 616GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out, 617 const X509V3_EXT_METHOD *method, 618 X509V3_CTX *ctx, CONF_VALUE *cnf, 619 int is_nc); 620 621void X509V3_conf_free(CONF_VALUE *val); 622 623X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid, 624 const char *value); 625X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, const char *name, 626 const char *value); 627int X509V3_EXT_add_nconf_sk(CONF *conf, X509V3_CTX *ctx, const char *section, 628 STACK_OF(X509_EXTENSION) **sk); 629int X509V3_EXT_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section, 630 X509 *cert); 631int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section, 632 X509_REQ *req); 633int X509V3_EXT_CRL_add_nconf(CONF *conf, X509V3_CTX *ctx, const char *section, 634 X509_CRL *crl); 635 636X509_EXTENSION *X509V3_EXT_conf_nid(LHASH_OF(CONF_VALUE) *conf, 637 X509V3_CTX *ctx, int ext_nid, 638 const char *value); 639X509_EXTENSION *X509V3_EXT_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, 640 const char *name, const char *value); 641int X509V3_EXT_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, 642 const char *section, X509 *cert); 643int X509V3_EXT_REQ_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, 644 const char *section, X509_REQ *req); 645int X509V3_EXT_CRL_add_conf(LHASH_OF(CONF_VALUE) *conf, X509V3_CTX *ctx, 646 const char *section, X509_CRL *crl); 647 648int X509V3_add_value_bool_nf(const char *name, int asn1_bool, 649 STACK_OF(CONF_VALUE) **extlist); 650int X509V3_get_value_bool(const CONF_VALUE *value, int *asn1_bool); 651int X509V3_get_value_int(const CONF_VALUE *value, ASN1_INTEGER **aint); 652void X509V3_set_nconf(X509V3_CTX *ctx, CONF *conf); 653void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH_OF(CONF_VALUE) *lhash); 654# endif 655 656char *X509V3_get_string(X509V3_CTX *ctx, const char *name, const char *section); 657STACK_OF(CONF_VALUE) *X509V3_get_section(X509V3_CTX *ctx, const char *section); 658void X509V3_string_free(X509V3_CTX *ctx, char *str); 659void X509V3_section_free(X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section); 660void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject, 661 X509_REQ *req, X509_CRL *crl, int flags); 662/* For API backward compatibility, this is separate from X509V3_set_ctx(): */ 663int X509V3_set_issuer_pkey(X509V3_CTX *ctx, EVP_PKEY *pkey); 664 665int X509V3_add_value(const char *name, const char *value, 666 STACK_OF(CONF_VALUE) **extlist); 667int X509V3_add_value_uchar(const char *name, const unsigned char *value, 668 STACK_OF(CONF_VALUE) **extlist); 669int X509V3_add_value_bool(const char *name, int asn1_bool, 670 STACK_OF(CONF_VALUE) **extlist); 671int X509V3_add_value_int(const char *name, const ASN1_INTEGER *aint, 672 STACK_OF(CONF_VALUE) **extlist); 673char *i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, const ASN1_INTEGER *aint); 674ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, const char *value); 675char *i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, const ASN1_ENUMERATED *aint); 676char *i2s_ASN1_ENUMERATED_TABLE(X509V3_EXT_METHOD *meth, 677 const ASN1_ENUMERATED *aint); 678int X509V3_EXT_add(X509V3_EXT_METHOD *ext); 679int X509V3_EXT_add_list(X509V3_EXT_METHOD *extlist); 680int X509V3_EXT_add_alias(int nid_to, int nid_from); 681void X509V3_EXT_cleanup(void); 682 683const X509V3_EXT_METHOD *X509V3_EXT_get(X509_EXTENSION *ext); 684const X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid); 685int X509V3_add_standard_extensions(void); 686STACK_OF(CONF_VALUE) *X509V3_parse_list(const char *line); 687void *X509V3_EXT_d2i(X509_EXTENSION *ext); 688void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *x, int nid, int *crit, 689 int *idx); 690 691X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc); 692int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, 693 int crit, unsigned long flags); 694 695#ifndef OPENSSL_NO_DEPRECATED_1_1_0 696/* The new declarations are in crypto.h, but the old ones were here. */ 697# define hex_to_string OPENSSL_buf2hexstr 698# define string_to_hex OPENSSL_hexstr2buf 699#endif 700 701void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, 702 int ml); 703int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, 704 int indent); 705#ifndef OPENSSL_NO_STDIO 706int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent); 707#endif 708int X509V3_extensions_print(BIO *out, const char *title, 709 const STACK_OF(X509_EXTENSION) *exts, 710 unsigned long flag, int indent); 711 712int X509_check_ca(X509 *x); 713int X509_check_purpose(X509 *x, int id, int ca); 714int X509_supported_extension(X509_EXTENSION *ex); 715int X509_PURPOSE_set(int *p, int purpose); 716int X509_check_issued(X509 *issuer, X509 *subject); 717int X509_check_akid(const X509 *issuer, const AUTHORITY_KEYID *akid); 718void X509_set_proxy_flag(X509 *x); 719void X509_set_proxy_pathlen(X509 *x, long l); 720long X509_get_proxy_pathlen(X509 *x); 721 722uint32_t X509_get_extension_flags(X509 *x); 723uint32_t X509_get_key_usage(X509 *x); 724uint32_t X509_get_extended_key_usage(X509 *x); 725const ASN1_OCTET_STRING *X509_get0_subject_key_id(X509 *x); 726const ASN1_OCTET_STRING *X509_get0_authority_key_id(X509 *x); 727const GENERAL_NAMES *X509_get0_authority_issuer(X509 *x); 728const ASN1_INTEGER *X509_get0_authority_serial(X509 *x); 729 730int X509_PURPOSE_get_count(void); 731X509_PURPOSE *X509_PURPOSE_get0(int idx); 732int X509_PURPOSE_get_by_sname(const char *sname); 733int X509_PURPOSE_get_by_id(int id); 734int X509_PURPOSE_add(int id, int trust, int flags, 735 int (*ck) (const X509_PURPOSE *, const X509 *, int), 736 const char *name, const char *sname, void *arg); 737char *X509_PURPOSE_get0_name(const X509_PURPOSE *xp); 738char *X509_PURPOSE_get0_sname(const X509_PURPOSE *xp); 739int X509_PURPOSE_get_trust(const X509_PURPOSE *xp); 740void X509_PURPOSE_cleanup(void); 741int X509_PURPOSE_get_id(const X509_PURPOSE *); 742 743STACK_OF(OPENSSL_STRING) *X509_get1_email(X509 *x); 744STACK_OF(OPENSSL_STRING) *X509_REQ_get1_email(X509_REQ *x); 745void X509_email_free(STACK_OF(OPENSSL_STRING) *sk); 746STACK_OF(OPENSSL_STRING) *X509_get1_ocsp(X509 *x); 747/* Flags for X509_check_* functions */ 748 749/* 750 * Always check subject name for host match even if subject alt names present 751 */ 752# define X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT 0x1 753/* Disable wildcard matching for dnsName fields and common name. */ 754# define X509_CHECK_FLAG_NO_WILDCARDS 0x2 755/* Wildcards must not match a partial label. */ 756# define X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS 0x4 757/* Allow (non-partial) wildcards to match multiple labels. */ 758# define X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS 0x8 759/* Constraint verifier subdomain patterns to match a single labels. */ 760# define X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS 0x10 761/* Never check the subject CN */ 762# define X509_CHECK_FLAG_NEVER_CHECK_SUBJECT 0x20 763/* 764 * Match reference identifiers starting with "." to any sub-domain. 765 * This is a non-public flag, turned on implicitly when the subject 766 * reference identity is a DNS name. 767 */ 768# define _X509_CHECK_FLAG_DOT_SUBDOMAINS 0x8000 769 770int X509_check_host(X509 *x, const char *chk, size_t chklen, 771 unsigned int flags, char **peername); 772int X509_check_email(X509 *x, const char *chk, size_t chklen, 773 unsigned int flags); 774int X509_check_ip(X509 *x, const unsigned char *chk, size_t chklen, 775 unsigned int flags); 776int X509_check_ip_asc(X509 *x, const char *ipasc, unsigned int flags); 777 778ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc); 779ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc); 780int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE) *dn_sk, 781 unsigned long chtype); 782 783void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent); 784{- 785 generate_stack_macros("X509_POLICY_NODE"); 786-} 787 788 789#ifndef OPENSSL_NO_RFC3779 790typedef struct ASRange_st { 791 ASN1_INTEGER *min, *max; 792} ASRange; 793 794# define ASIdOrRange_id 0 795# define ASIdOrRange_range 1 796 797typedef struct ASIdOrRange_st { 798 int type; 799 union { 800 ASN1_INTEGER *id; 801 ASRange *range; 802 } u; 803} ASIdOrRange; 804 805{- 806 generate_stack_macros("ASIdOrRange"); 807-} 808 809typedef STACK_OF(ASIdOrRange) ASIdOrRanges; 810 811# define ASIdentifierChoice_inherit 0 812# define ASIdentifierChoice_asIdsOrRanges 1 813 814typedef struct ASIdentifierChoice_st { 815 int type; 816 union { 817 ASN1_NULL *inherit; 818 ASIdOrRanges *asIdsOrRanges; 819 } u; 820} ASIdentifierChoice; 821 822typedef struct ASIdentifiers_st { 823 ASIdentifierChoice *asnum, *rdi; 824} ASIdentifiers; 825 826DECLARE_ASN1_FUNCTIONS(ASRange) 827DECLARE_ASN1_FUNCTIONS(ASIdOrRange) 828DECLARE_ASN1_FUNCTIONS(ASIdentifierChoice) 829DECLARE_ASN1_FUNCTIONS(ASIdentifiers) 830 831typedef struct IPAddressRange_st { 832 ASN1_BIT_STRING *min, *max; 833} IPAddressRange; 834 835# define IPAddressOrRange_addressPrefix 0 836# define IPAddressOrRange_addressRange 1 837 838typedef struct IPAddressOrRange_st { 839 int type; 840 union { 841 ASN1_BIT_STRING *addressPrefix; 842 IPAddressRange *addressRange; 843 } u; 844} IPAddressOrRange; 845 846{- 847 generate_stack_macros("IPAddressOrRange"); 848-} 849 850typedef STACK_OF(IPAddressOrRange) IPAddressOrRanges; 851 852# define IPAddressChoice_inherit 0 853# define IPAddressChoice_addressesOrRanges 1 854 855typedef struct IPAddressChoice_st { 856 int type; 857 union { 858 ASN1_NULL *inherit; 859 IPAddressOrRanges *addressesOrRanges; 860 } u; 861} IPAddressChoice; 862 863typedef struct IPAddressFamily_st { 864 ASN1_OCTET_STRING *addressFamily; 865 IPAddressChoice *ipAddressChoice; 866} IPAddressFamily; 867 868{- 869 generate_stack_macros("IPAddressFamily"); 870-} 871 872 873typedef STACK_OF(IPAddressFamily) IPAddrBlocks; 874 875DECLARE_ASN1_FUNCTIONS(IPAddressRange) 876DECLARE_ASN1_FUNCTIONS(IPAddressOrRange) 877DECLARE_ASN1_FUNCTIONS(IPAddressChoice) 878DECLARE_ASN1_FUNCTIONS(IPAddressFamily) 879 880/* 881 * API tag for elements of the ASIdentifer SEQUENCE. 882 */ 883# define V3_ASID_ASNUM 0 884# define V3_ASID_RDI 1 885 886/* 887 * AFI values, assigned by IANA. It'd be nice to make the AFI 888 * handling code totally generic, but there are too many little things 889 * that would need to be defined for other address families for it to 890 * be worth the trouble. 891 */ 892# define IANA_AFI_IPV4 1 893# define IANA_AFI_IPV6 2 894 895/* 896 * Utilities to construct and extract values from RFC3779 extensions, 897 * since some of the encodings (particularly for IP address prefixes 898 * and ranges) are a bit tedious to work with directly. 899 */ 900int X509v3_asid_add_inherit(ASIdentifiers *asid, int which); 901int X509v3_asid_add_id_or_range(ASIdentifiers *asid, int which, 902 ASN1_INTEGER *min, ASN1_INTEGER *max); 903int X509v3_addr_add_inherit(IPAddrBlocks *addr, 904 const unsigned afi, const unsigned *safi); 905int X509v3_addr_add_prefix(IPAddrBlocks *addr, 906 const unsigned afi, const unsigned *safi, 907 unsigned char *a, const int prefixlen); 908int X509v3_addr_add_range(IPAddrBlocks *addr, 909 const unsigned afi, const unsigned *safi, 910 unsigned char *min, unsigned char *max); 911unsigned X509v3_addr_get_afi(const IPAddressFamily *f); 912int X509v3_addr_get_range(IPAddressOrRange *aor, const unsigned afi, 913 unsigned char *min, unsigned char *max, 914 const int length); 915 916/* 917 * Canonical forms. 918 */ 919int X509v3_asid_is_canonical(ASIdentifiers *asid); 920int X509v3_addr_is_canonical(IPAddrBlocks *addr); 921int X509v3_asid_canonize(ASIdentifiers *asid); 922int X509v3_addr_canonize(IPAddrBlocks *addr); 923 924/* 925 * Tests for inheritance and containment. 926 */ 927int X509v3_asid_inherits(ASIdentifiers *asid); 928int X509v3_addr_inherits(IPAddrBlocks *addr); 929int X509v3_asid_subset(ASIdentifiers *a, ASIdentifiers *b); 930int X509v3_addr_subset(IPAddrBlocks *a, IPAddrBlocks *b); 931 932/* 933 * Check whether RFC 3779 extensions nest properly in chains. 934 */ 935int X509v3_asid_validate_path(X509_STORE_CTX *); 936int X509v3_addr_validate_path(X509_STORE_CTX *); 937int X509v3_asid_validate_resource_set(STACK_OF(X509) *chain, 938 ASIdentifiers *ext, 939 int allow_inheritance); 940int X509v3_addr_validate_resource_set(STACK_OF(X509) *chain, 941 IPAddrBlocks *ext, int allow_inheritance); 942 943#endif /* OPENSSL_NO_RFC3779 */ 944 945{- 946 generate_stack_macros("ASN1_STRING"); 947-} 948 949/* 950 * Admission Syntax 951 */ 952typedef struct NamingAuthority_st NAMING_AUTHORITY; 953typedef struct ProfessionInfo_st PROFESSION_INFO; 954typedef struct Admissions_st ADMISSIONS; 955typedef struct AdmissionSyntax_st ADMISSION_SYNTAX; 956DECLARE_ASN1_FUNCTIONS(NAMING_AUTHORITY) 957DECLARE_ASN1_FUNCTIONS(PROFESSION_INFO) 958DECLARE_ASN1_FUNCTIONS(ADMISSIONS) 959DECLARE_ASN1_FUNCTIONS(ADMISSION_SYNTAX) 960{- 961 generate_stack_macros("PROFESSION_INFO") 962 .generate_stack_macros("ADMISSIONS"); 963-} 964typedef STACK_OF(PROFESSION_INFO) PROFESSION_INFOS; 965 966const ASN1_OBJECT *NAMING_AUTHORITY_get0_authorityId( 967 const NAMING_AUTHORITY *n); 968const ASN1_IA5STRING *NAMING_AUTHORITY_get0_authorityURL( 969 const NAMING_AUTHORITY *n); 970const ASN1_STRING *NAMING_AUTHORITY_get0_authorityText( 971 const NAMING_AUTHORITY *n); 972void NAMING_AUTHORITY_set0_authorityId(NAMING_AUTHORITY *n, 973 ASN1_OBJECT* namingAuthorityId); 974void NAMING_AUTHORITY_set0_authorityURL(NAMING_AUTHORITY *n, 975 ASN1_IA5STRING* namingAuthorityUrl); 976void NAMING_AUTHORITY_set0_authorityText(NAMING_AUTHORITY *n, 977 ASN1_STRING* namingAuthorityText); 978 979const GENERAL_NAME *ADMISSION_SYNTAX_get0_admissionAuthority( 980 const ADMISSION_SYNTAX *as); 981void ADMISSION_SYNTAX_set0_admissionAuthority( 982 ADMISSION_SYNTAX *as, GENERAL_NAME *aa); 983const STACK_OF(ADMISSIONS) *ADMISSION_SYNTAX_get0_contentsOfAdmissions( 984 const ADMISSION_SYNTAX *as); 985void ADMISSION_SYNTAX_set0_contentsOfAdmissions( 986 ADMISSION_SYNTAX *as, STACK_OF(ADMISSIONS) *a); 987const GENERAL_NAME *ADMISSIONS_get0_admissionAuthority(const ADMISSIONS *a); 988void ADMISSIONS_set0_admissionAuthority(ADMISSIONS *a, GENERAL_NAME *aa); 989const NAMING_AUTHORITY *ADMISSIONS_get0_namingAuthority(const ADMISSIONS *a); 990void ADMISSIONS_set0_namingAuthority(ADMISSIONS *a, NAMING_AUTHORITY *na); 991const PROFESSION_INFOS *ADMISSIONS_get0_professionInfos(const ADMISSIONS *a); 992void ADMISSIONS_set0_professionInfos(ADMISSIONS *a, PROFESSION_INFOS *pi); 993const ASN1_OCTET_STRING *PROFESSION_INFO_get0_addProfessionInfo( 994 const PROFESSION_INFO *pi); 995void PROFESSION_INFO_set0_addProfessionInfo( 996 PROFESSION_INFO *pi, ASN1_OCTET_STRING *aos); 997const NAMING_AUTHORITY *PROFESSION_INFO_get0_namingAuthority( 998 const PROFESSION_INFO *pi); 999void PROFESSION_INFO_set0_namingAuthority( 1000 PROFESSION_INFO *pi, NAMING_AUTHORITY *na); 1001const STACK_OF(ASN1_STRING) *PROFESSION_INFO_get0_professionItems( 1002 const PROFESSION_INFO *pi); 1003void PROFESSION_INFO_set0_professionItems( 1004 PROFESSION_INFO *pi, STACK_OF(ASN1_STRING) *as); 1005const STACK_OF(ASN1_OBJECT) *PROFESSION_INFO_get0_professionOIDs( 1006 const PROFESSION_INFO *pi); 1007void PROFESSION_INFO_set0_professionOIDs( 1008 PROFESSION_INFO *pi, STACK_OF(ASN1_OBJECT) *po); 1009const ASN1_PRINTABLESTRING *PROFESSION_INFO_get0_registrationNumber( 1010 const PROFESSION_INFO *pi); 1011void PROFESSION_INFO_set0_registrationNumber( 1012 PROFESSION_INFO *pi, ASN1_PRINTABLESTRING *rn); 1013 1014# ifdef __cplusplus 1015} 1016# endif 1017#endif 1018