boringssl/crypto/x509
David Benjamin b965c63acb Reject calls to X509_verify_cert that have not been reinitialised
The function X509_verify_cert checks the value of |ctx->chain| at the
beginning, and if it is NULL then it initialises it, along with the value
of |ctx->untrusted|. The normal way to use X509_verify_cert() is to first
call X509_STORE_CTX_init(); then set up various parameters etc; then call
X509_verify_cert(); then check the results; and finally call
X509_STORE_CTX_cleanup(). The initial call to X509_STORE_CTX_init() sets
|ctx->chain| to NULL. The only place in the OpenSSL codebase  where
|ctx->chain| is set to anything other than a non NULL value is in
X509_verify_cert itself. Therefore the only ways that |ctx->chain| could be
non NULL on entry to X509_verify_cert is if one of the following occurs:
1) An application calls X509_verify_cert() twice without re-initialising
in between.
2) An application reaches inside the X509_STORE_CTX structure and changes
the value of |ctx->chain| directly.

With regards to the second of these, we should discount this - it should
not be supported to allow this.

With regards to the first of these, the documentation is not exactly
crystal clear, but the implication is that you must call
X509_STORE_CTX_init() before each call to X509_verify_cert(). If you fail
to do this then, at best, the results would be undefined.

Calling X509_verify_cert() with |ctx->chain| set to a non NULL value is
likely to have unexpected results, and could be dangerous. This commit
changes the behaviour of X509_verify_cert() so that it causes an error if
|ctx->chain| is anything other than NULL (because this indicates that we
have not been initialised properly). It also clarifies the associated
documentation.

(Imported from upstream's 692f07c3e0c04180b56febc2feb57cd94395a7a2.)

Change-Id: I971f1a305f12bbf9f4ae955313d5557368f0d374
Reviewed-on: https://boringssl-review.googlesource.com/6760
Reviewed-by: Adam Langley <agl@google.com>
2015-12-22 00:12:00 +00:00
..
a_digest.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
a_sign.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
a_strex.c Remove string.h from base.h. 2015-02-02 19:14:15 +00:00
a_verify.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
asn1_gen.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
by_dir.c Become partially -Wmissing-variable-declarations-clean. 2015-11-12 20:09:20 +00:00
by_file.c Become partially -Wmissing-variable-declarations-clean. 2015-11-12 20:09:20 +00:00
charmap.h Inital import. 2014-06-20 13:17:32 -07:00
CMakeLists.txt Add a run_tests target to run all tests. 2015-10-26 20:33:44 +00:00
i2d_pr.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
pkcs7_test.c Eliminate unnecessary includes from low-level crypto modules. 2015-04-13 20:49:18 +00:00
pkcs7.c Check for overflow when parsing a CBS with d2i_*. 2015-11-16 23:17:42 +00:00
t_crl.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
t_req.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
t_x509.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
t_x509a.c Inital import. 2014-06-20 13:17:32 -07:00
vpm_int.h Update API to use (char *) for email addresses and hostnames. 2015-02-13 11:00:48 -08:00
x509_att.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x509_cmp.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x509_d2.c Inital import. 2014-06-20 13:17:32 -07:00
x509_def.c Inital import. 2014-06-20 13:17:32 -07:00
x509_ext.c Inital import. 2014-06-20 13:17:32 -07:00
x509_lu.c Avoid sticking -1 into a size_t. 2015-10-26 19:50:53 +00:00
x509_obj.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x509_r2x.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x509_req.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x509_set.c Omit version for v1 certificates. 2014-11-10 13:45:32 -08:00
x509_trs.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x509_txt.c Inital import. 2014-06-20 13:17:32 -07:00
x509_v3.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x509_vfy.c Reject calls to X509_verify_cert that have not been reinitialised 2015-12-22 00:12:00 +00:00
x509_vpm.c Require that FOO_free functions do nothing on NULL. 2015-05-04 22:58:13 +00:00
x509.c Inital import. 2014-06-20 13:17:32 -07:00
x509cset.c Add X509_CRL_up_ref. 2015-09-01 19:12:56 +00:00
x509name.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x509rset.c Inital import. 2014-06-20 13:17:32 -07:00
x509spki.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x509type.c Inital import. 2014-06-20 13:17:32 -07:00
x_algor.c Fix various certificate fingerprint issues. 2015-01-09 19:41:59 +00:00
x_all.c Parse RSAPrivateKey with CBS. 2015-07-07 22:50:53 +00:00
x_attrib.c Inital import. 2014-06-20 13:17:32 -07:00
x_crl.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x_exten.c Inital import. 2014-06-20 13:17:32 -07:00
x_info.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x_name.c Become partially -Wmissing-variable-declarations-clean. 2015-11-12 20:09:20 +00:00
x_pkey.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x_pubkey.c Remove the func parameter to OPENSSL_PUT_ERROR. 2015-07-16 02:02:37 +00:00
x_req.c Remove last references to named locks. 2015-05-20 19:18:30 +00:00
x_sig.c Inital import. 2014-06-20 13:17:32 -07:00
x_spki.c Inital import. 2014-06-20 13:17:32 -07:00
x_val.c Inital import. 2014-06-20 13:17:32 -07:00
x_x509.c Remove the CRYPTO_EX_new callback. 2015-12-15 21:29:46 +00:00
x_x509a.c Fix memory leaks on error in x_x509a.c. 2015-08-31 18:54:17 +00:00