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