| 1 |
// Written by Dr Stephen N Henson ([email protected]) for the OpenSSL project 2013. |
| 2 |
// Copyright (c) 2013 The OpenSSL Project. All rights reserved. |
| 3 |
// SPDX-License-Identifier: Apache-2.0 |
| 4 |
|
| 5 |
#ifndef OPENSSL_HEADER_X509_INTERNAL_H |
| 6 |
#define OPENSSL_HEADER_X509_INTERNAL_H |
| 7 |
|
| 8 |
#include <openssl/base.h> |
| 9 |
#include <openssl/evp.h> |
| 10 |
#include <openssl/x509.h> |
| 11 |
|
| 12 |
#include "../asn1/internal.h" |
| 13 |
|
| 14 |
#if defined(__cplusplus) |
| 15 |
extern "C" { |
| 16 |
#endif |
| 17 |
|
| 18 |
|
| 19 |
// Internal structures. |
| 20 |
|
| 21 |
typedef struct X509_val_st { |
| 22 |
ASN1_TIME *notBefore; |
| 23 |
ASN1_TIME *notAfter; |
| 24 |
} X509_VAL; |
| 25 |
|
| 26 |
DECLARE_ASN1_FUNCTIONS_const(X509_VAL) |
| 27 |
|
| 28 |
struct X509_pubkey_st { |
| 29 |
X509_ALGOR *algor; |
| 30 |
ASN1_BIT_STRING *public_key; |
| 31 |
EVP_PKEY *pkey; |
| 32 |
} /* X509_PUBKEY */; |
| 33 |
|
| 34 |
struct X509_name_entry_st { |
| 35 |
ASN1_OBJECT *object; |
| 36 |
ASN1_STRING *value; |
| 37 |
int set; |
| 38 |
} /* X509_NAME_ENTRY */; |
| 39 |
|
| 40 |
// we always keep X509_NAMEs in 2 forms. |
| 41 |
struct X509_name_st { |
| 42 |
STACK_OF(X509_NAME_ENTRY) *entries; |
| 43 |
int modified; // true if 'bytes' needs to be built |
| 44 |
BUF_MEM *bytes; |
| 45 |
unsigned char *canon_enc; |
| 46 |
int canon_enclen; |
| 47 |
} /* X509_NAME */; |
| 48 |
|
| 49 |
struct x509_attributes_st { |
| 50 |
ASN1_OBJECT *object; |
| 51 |
STACK_OF(ASN1_TYPE) *set; |
| 52 |
} /* X509_ATTRIBUTE */; |
| 53 |
|
| 54 |
typedef struct x509_cert_aux_st { |
| 55 |
STACK_OF(ASN1_OBJECT) *trust; // trusted uses |
| 56 |
STACK_OF(ASN1_OBJECT) *reject; // rejected uses |
| 57 |
ASN1_UTF8STRING *alias; // "friendly name" |
| 58 |
ASN1_OCTET_STRING *keyid; // key id of private key |
| 59 |
} X509_CERT_AUX; |
| 60 |
|
| 61 |
DECLARE_ASN1_FUNCTIONS_const(X509_CERT_AUX) |
| 62 |
|
| 63 |
struct X509_extension_st { |
| 64 |
ASN1_OBJECT *object; |
| 65 |
ASN1_BOOLEAN critical; |
| 66 |
ASN1_OCTET_STRING *value; |
| 67 |
} /* X509_EXTENSION */; |
| 68 |
|
| 69 |
typedef struct { |
| 70 |
ASN1_INTEGER *version; // [ 0 ] default of v1 |
| 71 |
ASN1_INTEGER *serialNumber; |
| 72 |
X509_ALGOR *signature; |
| 73 |
X509_NAME *issuer; |
| 74 |
X509_VAL *validity; |
| 75 |
X509_NAME *subject; |
| 76 |
X509_PUBKEY *key; |
| 77 |
ASN1_BIT_STRING *issuerUID; // [ 1 ] optional in v2 |
| 78 |
ASN1_BIT_STRING *subjectUID; // [ 2 ] optional in v2 |
| 79 |
STACK_OF(X509_EXTENSION) *extensions; // [ 3 ] optional in v3 |
| 80 |
ASN1_ENCODING enc; |
| 81 |
} X509_CINF; |
| 82 |
|
| 83 |
// TODO(https://crbug.com/boringssl/407): This is not const because it contains |
| 84 |
// an |X509_NAME|. |
| 85 |
DECLARE_ASN1_FUNCTIONS(X509_CINF) |
| 86 |
|
| 87 |
struct x509_sig_info_st { |
| 88 |
// NID of message digest. |
| 89 |
int digest_nid; |
| 90 |
// NID of public key algorithm. |
| 91 |
int pubkey_nid; |
| 92 |
// Security bits. |
| 93 |
int sec_bits; |
| 94 |
uint32_t flags; |
| 95 |
} /* X509_SIG_INFO */; |
| 96 |
|
| 97 |
struct x509_st { |
| 98 |
X509_CINF *cert_info; |
| 99 |
X509_ALGOR *sig_alg; |
| 100 |
ASN1_BIT_STRING *signature; |
| 101 |
X509_SIG_INFO sig_info; |
| 102 |
CRYPTO_refcount_t references; |
| 103 |
CRYPTO_EX_DATA ex_data; |
| 104 |
// These contain copies of various extension values |
| 105 |
long ex_pathlen; |
| 106 |
uint32_t ex_flags; |
| 107 |
uint32_t ex_kusage; |
| 108 |
uint32_t ex_xkusage; |
| 109 |
uint32_t ex_nscert; |
| 110 |
ASN1_OCTET_STRING *skid; |
| 111 |
AUTHORITY_KEYID *akid; |
| 112 |
STACK_OF(DIST_POINT) *crldp; |
| 113 |
STACK_OF(GENERAL_NAME) *altname; |
| 114 |
NAME_CONSTRAINTS *nc; |
| 115 |
unsigned char cert_hash[SHA256_DIGEST_LENGTH]; |
| 116 |
X509_CERT_AUX *aux; |
| 117 |
CRYPTO_BUFFER *buf; |
| 118 |
CRYPTO_MUTEX lock; |
| 119 |
} /* X509 */; |
| 120 |
|
| 121 |
typedef struct { |
| 122 |
ASN1_ENCODING enc; |
| 123 |
ASN1_INTEGER *version; |
| 124 |
X509_NAME *subject; |
| 125 |
X509_PUBKEY *pubkey; |
| 126 |
// d=2 hl=2 l= 0 cons: cont: 00 |
| 127 |
STACK_OF(X509_ATTRIBUTE) *attributes; // [ 0 ] |
| 128 |
} X509_REQ_INFO; |
| 129 |
|
| 130 |
// TODO(https://crbug.com/boringssl/407): This is not const because it contains |
| 131 |
// an |X509_NAME|. |
| 132 |
DECLARE_ASN1_FUNCTIONS(X509_REQ_INFO) |
| 133 |
|
| 134 |
struct X509_req_st { |
| 135 |
X509_REQ_INFO *req_info; |
| 136 |
X509_ALGOR *sig_alg; |
| 137 |
ASN1_BIT_STRING *signature; |
| 138 |
} /* X509_REQ */; |
| 139 |
|
| 140 |
struct x509_revoked_st { |
| 141 |
ASN1_INTEGER *serialNumber; |
| 142 |
ASN1_TIME *revocationDate; |
| 143 |
STACK_OF(X509_EXTENSION) /* optional */ *extensions; |
| 144 |
// Revocation reason |
| 145 |
int reason; |
| 146 |
} /* X509_REVOKED */; |
| 147 |
|
| 148 |
typedef struct { |
| 149 |
ASN1_INTEGER *version; |
| 150 |
X509_ALGOR *sig_alg; |
| 151 |
X509_NAME *issuer; |
| 152 |
ASN1_TIME *lastUpdate; |
| 153 |
ASN1_TIME *nextUpdate; |
| 154 |
STACK_OF(X509_REVOKED) *revoked; |
| 155 |
STACK_OF(X509_EXTENSION) /* [0] */ *extensions; |
| 156 |
ASN1_ENCODING enc; |
| 157 |
} X509_CRL_INFO; |
| 158 |
|
| 159 |
// TODO(https://crbug.com/boringssl/407): This is not const because it contains |
| 160 |
// an |X509_NAME|. |
| 161 |
DECLARE_ASN1_FUNCTIONS(X509_CRL_INFO) |
| 162 |
|
| 163 |
// Values in idp_flags field |
| 164 |
// IDP present |
| 165 |
#define IDP_PRESENT 0x1 |
| 166 |
// IDP values inconsistent |
| 167 |
#define IDP_INVALID 0x2 |
| 168 |
// onlyuser true |
| 169 |
#define IDP_ONLYUSER 0x4 |
| 170 |
// onlyCA true |
| 171 |
#define IDP_ONLYCA 0x8 |
| 172 |
// onlyattr true |
| 173 |
#define IDP_ONLYATTR 0x10 |
| 174 |
// indirectCRL true |
| 175 |
#define IDP_INDIRECT 0x20 |
| 176 |
// onlysomereasons present |
| 177 |
#define IDP_REASONS 0x40 |
| 178 |
|
| 179 |
struct X509_crl_st { |
| 180 |
// actual signature |
| 181 |
X509_CRL_INFO *crl; |
| 182 |
X509_ALGOR *sig_alg; |
| 183 |
ASN1_BIT_STRING *signature; |
| 184 |
CRYPTO_refcount_t references; |
| 185 |
int flags; |
| 186 |
// Copies of various extensions |
| 187 |
AUTHORITY_KEYID *akid; |
| 188 |
ISSUING_DIST_POINT *idp; |
| 189 |
// Convenient breakdown of IDP |
| 190 |
int idp_flags; |
| 191 |
unsigned char crl_hash[SHA256_DIGEST_LENGTH]; |
| 192 |
} /* X509_CRL */; |
| 193 |
|
| 194 |
// GENERAL_NAME is an |ASN1_ITEM| whose ASN.1 type is GeneralName and C type is |
| 195 |
// |GENERAL_NAME*|. |
| 196 |
DECLARE_ASN1_ITEM(GENERAL_NAME) |
| 197 |
|
| 198 |
// GENERAL_NAMES is an |ASN1_ITEM| whose ASN.1 type is SEQUENCE OF GeneralName |
| 199 |
// and C type is |GENERAL_NAMES*|, aka |STACK_OF(GENERAL_NAME)*|. |
| 200 |
DECLARE_ASN1_ITEM(GENERAL_NAMES) |
| 201 |
|
| 202 |
struct X509_VERIFY_PARAM_st { |
| 203 |
int64_t check_time; // POSIX time to use |
| 204 |
unsigned long flags; // Various verify flags |
| 205 |
int purpose; // purpose to check untrusted certificates |
| 206 |
int trust; // trust setting to check |
| 207 |
int depth; // Verify depth |
| 208 |
STACK_OF(ASN1_OBJECT) *policies; // Permissible policies |
| 209 |
// The following fields specify acceptable peer identities. |
| 210 |
STACK_OF(OPENSSL_STRING) *hosts; // Set of acceptable names |
| 211 |
unsigned int hostflags; // Flags to control matching features |
| 212 |
char *email; // If not NULL email address to match |
| 213 |
size_t emaillen; |
| 214 |
unsigned char *ip; // If not NULL IP address to match |
| 215 |
size_t iplen; // Length of IP address |
| 216 |
unsigned char poison; // Fail all verifications at name checking |
| 217 |
uint64_t awslc_flags; |
| 218 |
} /* X509_VERIFY_PARAM */; |
| 219 |
|
| 220 |
struct x509_object_st { |
| 221 |
// one of the above types |
| 222 |
int type; |
| 223 |
union { |
| 224 |
char *ptr; |
| 225 |
X509 *x509; |
| 226 |
X509_CRL *crl; |
| 227 |
EVP_PKEY *pkey; |
| 228 |
} data; |
| 229 |
} /* X509_OBJECT */; |
| 230 |
|
| 231 |
// This is a static that defines the function interface |
| 232 |
struct x509_lookup_method_st { |
| 233 |
int (*new_item)(X509_LOOKUP *ctx); |
| 234 |
void (*free)(X509_LOOKUP *ctx); |
| 235 |
int (*ctrl)(X509_LOOKUP *ctx, int cmd, const char *argc, long argl, |
| 236 |
char **ret); |
| 237 |
int (*get_by_subject)(X509_LOOKUP *ctx, int type, X509_NAME *name, |
| 238 |
X509_OBJECT *ret); |
| 239 |
} /* X509_LOOKUP_METHOD */; |
| 240 |
|
| 241 |
DEFINE_STACK_OF(X509_LOOKUP) |
| 242 |
|
| 243 |
// This is used to hold everything. It is used for all certificate |
| 244 |
// validation. Once we have a certificate chain, the 'verify' |
| 245 |
// function is then called to actually check the cert chain. |
| 246 |
struct x509_store_st { |
| 247 |
// The following is a cache of trusted certs |
| 248 |
STACK_OF(X509_OBJECT) *objs; // Cache of all objects |
| 249 |
CRYPTO_MUTEX objs_lock; |
| 250 |
|
| 251 |
// These are external lookup methods |
| 252 |
STACK_OF(X509_LOOKUP) *get_cert_methods; |
| 253 |
|
| 254 |
X509_VERIFY_PARAM *param; |
| 255 |
|
| 256 |
// Callbacks for various operations |
| 257 |
X509_STORE_CTX_verify_cb verify_cb; // error callback |
| 258 |
X509_STORE_CTX_lookup_crls_fn lookup_crls; |
| 259 |
X509_STORE_CTX_get_crl_fn get_crl; // retrieve CRL |
| 260 |
X509_STORE_CTX_check_crl_fn check_crl; // Check CRL validity |
| 261 |
|
| 262 |
CRYPTO_refcount_t references; |
| 263 |
CRYPTO_EX_DATA ex_data; |
| 264 |
} /* X509_STORE */; |
| 265 |
|
| 266 |
// This is the functions plus an instance of the local variables. |
| 267 |
struct x509_lookup_st { |
| 268 |
const X509_LOOKUP_METHOD *method; // the functions |
| 269 |
void *method_data; // method data |
| 270 |
|
| 271 |
X509_STORE *store_ctx; // who owns us |
| 272 |
} /* X509_LOOKUP */; |
| 273 |
|
| 274 |
// This is a used when verifying cert chains. Since the |
| 275 |
// gathering of the cert chain can take some time (and have to be |
| 276 |
// 'retried', this needs to be kept and passed around. |
| 277 |
struct x509_store_ctx_st { |
| 278 |
X509_STORE *ctx; |
| 279 |
|
| 280 |
// The following are set by the caller |
| 281 |
X509 *cert; // The cert to check |
| 282 |
STACK_OF(X509) *untrusted; // chain of X509s - untrusted - passed in |
| 283 |
STACK_OF(X509_CRL) *crls; // set of CRLs passed in |
| 284 |
|
| 285 |
X509_VERIFY_PARAM *param; |
| 286 |
|
| 287 |
// trusted_stack, if non-NULL, is a set of trusted certificates to consider |
| 288 |
// instead of those from |X509_STORE|. |
| 289 |
STACK_OF(X509) *trusted_stack; |
| 290 |
|
| 291 |
// Callbacks for various operations |
| 292 |
X509_STORE_CTX_verify_cb verify_cb; // error callback |
| 293 |
X509_STORE_CTX_lookup_crls_fn lookup_crls; |
| 294 |
X509_STORE_CTX_get_crl_fn get_crl; // retrieve CRL |
| 295 |
X509_STORE_CTX_check_crl_fn check_crl; // Check CRL validity |
| 296 |
X509_STORE_CTX_verify_crit_oids_cb |
| 297 |
verify_custom_crit_oids; // Check custom critical oids |
| 298 |
|
| 299 |
// The following is built up |
| 300 |
|
| 301 |
int last_untrusted; // index of last untrusted cert |
| 302 |
STACK_OF(X509) *chain; // chain of X509s - built up and trusted |
| 303 |
|
| 304 |
// When something goes wrong, this is why |
| 305 |
int error_depth; |
| 306 |
int error; |
| 307 |
X509 *current_cert; |
| 308 |
X509 *current_issuer; // cert currently being tested as valid issuer |
| 309 |
X509_CRL *current_crl; // current CRL |
| 310 |
|
| 311 |
int current_crl_score; // score of current CRL |
| 312 |
|
| 313 |
// Stack of allowed custom critical extension oids. |
| 314 |
STACK_OF(ASN1_OBJECT) *custom_crit_oids; |
| 315 |
|
| 316 |
CRYPTO_EX_DATA ex_data; |
| 317 |
} /* X509_STORE_CTX */; |
| 318 |
|
| 319 |
#define FLAG_BIT(n) ((uint64_t)1 << (uint64_t)n) |
| 320 |
|
| 321 |
#define AWSLC_V_ENABLE_EC_KEY_EXPLICIT_PARAMS FLAG_BIT(0) |
| 322 |
|
| 323 |
void X509_OBJECT_free_contents(X509_OBJECT *a); |
| 324 |
|
| 325 |
ASN1_TYPE *ASN1_generate_v3(const char *str, const X509V3_CTX *cnf); |
| 326 |
|
| 327 |
int X509_CERT_AUX_print(BIO *bp, X509_CERT_AUX *x, int indent); |
| 328 |
|
| 329 |
int x509_check_cert_time(X509_STORE_CTX *ctx, X509 *x, int suppress_error); |
| 330 |
|
| 331 |
// RSA-PSS functions. |
| 332 |
|
| 333 |
// x509_rsa_pss_to_ctx configures |ctx| for an RSA-PSS operation based on |
| 334 |
// signature algorithm parameters in |sigalg| (which must have type |
| 335 |
// |NID_rsassaPss|) and key |pkey|. It returns one on success and zero on |
| 336 |
// error. |
| 337 |
int x509_rsa_pss_to_ctx(EVP_MD_CTX *ctx, const X509_ALGOR *sigalg, |
| 338 |
EVP_PKEY *pkey); |
| 339 |
|
| 340 |
// x509_rsa_pss_to_ctx sets |algor| to the signature algorithm parameters for |
| 341 |
// |ctx|, which must have been configured for an RSA-PSS signing operation. It |
| 342 |
// returns one on success and zero on error. |
| 343 |
int x509_rsa_ctx_to_pss(EVP_MD_CTX *ctx, X509_ALGOR *algor); |
| 344 |
|
| 345 |
// x509_print_rsa_pss_params prints a human-readable representation of RSA-PSS |
| 346 |
// parameters in |sigalg| to |bp|. It returns one on success and zero on |
| 347 |
// error. |
| 348 |
int x509_print_rsa_pss_params(BIO *bp, const X509_ALGOR *sigalg, int indent, |
| 349 |
ASN1_PCTX *pctx); |
| 350 |
|
| 351 |
|
| 352 |
// Signature algorithm functions. |
| 353 |
|
| 354 |
// x509_digest_sign_algorithm encodes the signing parameters of |ctx| as an |
| 355 |
// AlgorithmIdentifier and saves the result in |algor|. It returns one on |
| 356 |
// success, or zero on error. |
| 357 |
int x509_digest_sign_algorithm(EVP_MD_CTX *ctx, X509_ALGOR *algor); |
| 358 |
|
| 359 |
// x509_digest_verify_init sets up |ctx| for a signature verification operation |
| 360 |
// with public key |pkey| and parameters from |algor|. The |ctx| argument must |
| 361 |
// have been initialised with |EVP_MD_CTX_init|. It returns one on success, or |
| 362 |
// zero on error. |
| 363 |
int x509_digest_verify_init(EVP_MD_CTX *ctx, const X509_ALGOR *sigalg, |
| 364 |
EVP_PKEY *pkey); |
| 365 |
|
| 366 |
// x509_init_signature_info initializes the signature info for |x509|. |
| 367 |
int x509_init_signature_info(X509 *x509); |
| 368 |
|
| 369 |
|
| 370 |
// Path-building functions. |
| 371 |
|
| 372 |
// X509_policy_check checks certificate policies in |certs|. |user_policies| is |
| 373 |
// the user-initial-policy-set. |flags| is a set of |X509_V_FLAG_*| values to |
| 374 |
// apply. It returns |X509_V_OK| on success and |X509_V_ERR_*| on error. It |
| 375 |
// additionally sets |*out_current_cert| to the certificate where the error |
| 376 |
// occurred. If the function succeeded, or the error applies to the entire |
| 377 |
// chain, it sets |*out_current_cert| to NULL. |
| 378 |
int X509_policy_check(const STACK_OF(X509) *certs, |
| 379 |
const STACK_OF(ASN1_OBJECT) *user_policies, |
| 380 |
unsigned long flags, X509 **out_current_cert); |
| 381 |
|
| 382 |
// x509_check_issued_with_callback calls |X509_check_issued|, but allows the |
| 383 |
// verify callback to override the result. It returns one on success and zero on |
| 384 |
// error. |
| 385 |
// |
| 386 |
// TODO(davidben): Reduce the scope of the verify callback and remove this. The |
| 387 |
// callback only runs with |X509_V_FLAG_CB_ISSUER_CHECK|, which is only used by |
| 388 |
// one internal project and rust-openssl, who use it by mistake. |
| 389 |
int x509_check_issued_with_callback(X509_STORE_CTX *ctx, X509 *x, X509 *issuer); |
| 390 |
|
| 391 |
// x509v3_bytes_to_hex encodes |len| bytes from |in| to hex and returns a |
| 392 |
// newly-allocated NUL-terminated string containing the result, or NULL on |
| 393 |
// allocation error. |
| 394 |
// |
| 395 |
// This function was historically named |hex_to_string| in OpenSSL. Despite the |
| 396 |
// name, |hex_to_string| converted to hex. |
| 397 |
OPENSSL_EXPORT char *x509v3_bytes_to_hex(const uint8_t *in, size_t len); |
| 398 |
|
| 399 |
// x509v3_hex_string_to_bytes decodes |str| in hex and returns a newly-allocated |
| 400 |
// array containing the result, or NULL on error. On success, it sets |*len| to |
| 401 |
// the length of the result. Colon separators between bytes in the input are |
| 402 |
// allowed and ignored. |
| 403 |
// |
| 404 |
// This function was historically named |string_to_hex| in OpenSSL. Despite the |
| 405 |
// name, |string_to_hex| converted from hex. |
| 406 |
unsigned char *x509v3_hex_to_bytes(const char *str, size_t *len); |
| 407 |
|
| 408 |
// x509v3_conf_name_matches returns one if |name| is equal to |cmp| or begins |
| 409 |
// with |cmp| followed by '.', and zero otherwise. |
| 410 |
int x509v3_conf_name_matches(const char *name, const char *cmp); |
| 411 |
|
| 412 |
// x509v3_cache_extensions fills in a number of fields relating to X.509 |
| 413 |
// extensions in |x|. It returns one on success and zero if some extensions were |
| 414 |
// invalid. |
| 415 |
OPENSSL_EXPORT int x509v3_cache_extensions(X509 *x); |
| 416 |
|
| 417 |
// x509v3_a2i_ipadd decodes |ipasc| as an IPv4 or IPv6 address. IPv6 addresses |
| 418 |
// use colon-separated syntax while IPv4 addresses use dotted decimal syntax. If |
| 419 |
// it decodes an IPv4 address, it writes the result to the first four bytes of |
| 420 |
// |ipout| and returns four. If it decodes an IPv6 address, it writes the result |
| 421 |
// to all 16 bytes of |ipout| and returns 16. Otherwise, it returns zero. |
| 422 |
int x509v3_a2i_ipadd(unsigned char ipout[16], const char *ipasc); |
| 423 |
|
| 424 |
// A |BIT_STRING_BITNAME| is used to contain a list of bit names. |
| 425 |
typedef struct { |
| 426 |
int bitnum; |
| 427 |
const char *lname; |
| 428 |
const char *sname; |
| 429 |
} BIT_STRING_BITNAME; |
| 430 |
|
| 431 |
// x509V3_add_value_asn1_string appends a |CONF_VALUE| with the specified name |
| 432 |
// and value to |*extlist|. if |*extlist| is NULL, it sets |*extlist| to a |
| 433 |
// newly-allocated |STACK_OF(CONF_VALUE)| first. It returns one on success and |
| 434 |
// zero on error. |
| 435 |
int x509V3_add_value_asn1_string(const char *name, const ASN1_STRING *value, |
| 436 |
STACK_OF(CONF_VALUE) **extlist); |
| 437 |
|
| 438 |
// x509v3_ext_free_with_method frees |ext_data| with |ext_method|. |
| 439 |
int x509v3_ext_free_with_method(const X509V3_EXT_METHOD *ext_method, |
| 440 |
void *ext_data); |
| 441 |
|
| 442 |
// X509V3_NAME_from_section adds attributes to |nm| by interpreting the |
| 443 |
// key/value pairs in |dn_sk|. It returns one on success and zero on error. |
| 444 |
// |chtype|, which should be one of |MBSTRING_*| constants, determines the |
| 445 |
// character encoding used to interpret values. |
| 446 |
int X509V3_NAME_from_section(X509_NAME *nm, const STACK_OF(CONF_VALUE) *dn_sk, |
| 447 |
int chtype); |
| 448 |
|
| 449 |
// X509V3_bool_from_string decodes |str| as a boolean. On success, it returns |
| 450 |
// one and sets |*out_bool| to resulting value. Otherwise, it returns zero. |
| 451 |
int X509V3_bool_from_string(const char *str, ASN1_BOOLEAN *out_bool); |
| 452 |
|
| 453 |
// X509V3_get_value_bool decodes |value| as a boolean. On success, it returns |
| 454 |
// one and sets |*out_bool| to the resulting value. Otherwise, it returns zero. |
| 455 |
int X509V3_get_value_bool(const CONF_VALUE *value, ASN1_BOOLEAN *out_bool); |
| 456 |
|
| 457 |
// X509V3_get_value_int decodes |value| as an integer. On success, it returns |
| 458 |
// one and sets |*aint| to the resulting value. Otherwise, it returns zero. If |
| 459 |
// |*aint| was non-NULL at the start of the function, it frees the previous |
| 460 |
// value before writing a new one. |
| 461 |
int X509V3_get_value_int(const CONF_VALUE *value, ASN1_INTEGER **aint); |
| 462 |
|
| 463 |
// X509V3_get_section behaves like |NCONF_get_section| but queries |ctx|'s |
| 464 |
// config database. |
| 465 |
const STACK_OF(CONF_VALUE) *X509V3_get_section(const X509V3_CTX *ctx, |
| 466 |
const char *section); |
| 467 |
|
| 468 |
// X509V3_add_value appends a |CONF_VALUE| containing |name| and |value| to |
| 469 |
// |*extlist|. It returns one on success and zero on error. If |*extlist| is |
| 470 |
// NULL, it sets |*extlist| to a newly-allocated |STACK_OF(CONF_VALUE)| |
| 471 |
// containing the result. Either |name| or |value| may be NULL to omit the |
| 472 |
// field. |
| 473 |
// |
| 474 |
// On failure, if |*extlist| was NULL, |*extlist| will remain NULL when the |
| 475 |
// function returns. |
| 476 |
int X509V3_add_value(const char *name, const char *value, |
| 477 |
STACK_OF(CONF_VALUE) **extlist); |
| 478 |
|
| 479 |
// X509V3_add_value_bool behaves like |X509V3_add_value| but stores the value |
| 480 |
// "TRUE" if |asn1_bool| is non-zero and "FALSE" otherwise. |
| 481 |
int X509V3_add_value_bool(const char *name, int asn1_bool, |
| 482 |
STACK_OF(CONF_VALUE) **extlist); |
| 483 |
|
| 484 |
// X509V3_add_value_bool behaves like |X509V3_add_value| but stores a string |
| 485 |
// representation of |aint|. Note this string representation may be decimal or |
| 486 |
// hexadecimal, depending on the size of |aint|. |
| 487 |
int X509V3_add_value_int(const char *name, const ASN1_INTEGER *aint, |
| 488 |
STACK_OF(CONF_VALUE) **extlist); |
| 489 |
|
| 490 |
#define X509V3_conf_err(val) \ |
| 491 |
ERR_add_error_data(6, "section:", (val)->section, ",name:", (val)->name, \ |
| 492 |
",value:", (val)->value); |
| 493 |
|
| 494 |
int NAME_CONSTRAINTS_check_CN(X509 *x, NAME_CONSTRAINTS *nc); |
| 495 |
|
| 496 |
// GENERAL_NAME_cmp returns zero if |a| and |b| are equal and a non-zero |
| 497 |
// value otherwise. Note this function does not provide a comparison suitable |
| 498 |
// for sorting. |
| 499 |
// |
| 500 |
// This function is exported for testing. |
| 501 |
OPENSSL_EXPORT int GENERAL_NAME_cmp(const GENERAL_NAME *a, |
| 502 |
const GENERAL_NAME *b); |
| 503 |
|
| 504 |
// X509_VERIFY_PARAM_lookup returns a pre-defined |X509_VERIFY_PARAM| named by |
| 505 |
// |name|, or NULL if no such name is defined. |
| 506 |
const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name); |
| 507 |
|
| 508 |
GENERAL_NAME *v2i_GENERAL_NAME(const X509V3_EXT_METHOD *method, |
| 509 |
const X509V3_CTX *ctx, const CONF_VALUE *cnf); |
| 510 |
GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out, |
| 511 |
const X509V3_EXT_METHOD *method, |
| 512 |
const X509V3_CTX *ctx, const CONF_VALUE *cnf, |
| 513 |
int is_nc); |
| 514 |
GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method, |
| 515 |
const X509V3_CTX *ctx, |
| 516 |
const STACK_OF(CONF_VALUE) *nval); |
| 517 |
|
| 518 |
// TODO(https://crbug.com/boringssl/407): Make |issuer| const once the |
| 519 |
// |X509_NAME| issue is resolved. |
| 520 |
int X509_check_akid(X509 *issuer, const AUTHORITY_KEYID *akid); |
| 521 |
|
| 522 |
// TODO(https://crbug.com/boringssl/695): Remove this. |
| 523 |
int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname); |
| 524 |
|
| 525 |
// Exported for testing purposes only. Used for validating that the CIDR mask bytes |
| 526 |
// from a IP Name Constraint is a valid CIDR prefix. |
| 527 |
// |
| 528 |
// It accepts either IPv4 (4 bytes) or IPv6 (16 bytes) masks, returns 0 for any other lengths, |
| 529 |
// and otherwise returns 1 if the provided netmask is a valid CIDR prefix. |
| 530 |
// |
| 531 |
// For example the IPv4 mask `255.255.255.0` would return valid, but `255.0.255.0` would be invalid. |
| 532 |
OPENSSL_EXPORT int validate_cidr_mask(CBS *cidr_mask); |
| 533 |
|
| 534 |
OPENSSL_EXPORT int cn2dnsid(ASN1_STRING *cn, unsigned char **dnsid, size_t *idlen); |
| 535 |
|
| 536 |
int x509_digest_nid_ok(const int digest_nid); |
| 537 |
|
| 538 |
// Match reference identifiers starting with "." to any sub-domain. |
| 539 |
// This is a non-public flag, turned on implicitly when the subject |
| 540 |
// reference identity is a DNS name. |
| 541 |
#define _X509_CHECK_FLAG_DOT_SUBDOMAINS 0x8000 |
| 542 |
|
| 543 |
#if defined(__cplusplus) |
| 544 |
} // extern C |
| 545 |
#endif |
| 546 |
|
| 547 |
#endif // OPENSSL_HEADER_X509_INTERNAL_H |