diff options
author | David Benjamin <davidben@google.com> | 2024-02-20 17:34:14 -0500 |
---|---|---|
committer | Boringssl LUCI CQ <boringssl-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2024-02-23 16:35:04 +0000 |
commit | 5d880140674cd36d84331de7df95c2dc00dc7686 (patch) | |
tree | 2ae3f65583cd7b379216559f3fe54368beff82cd /include | |
parent | bca5875eb3c25348ec07758cde66ebec27031ce4 (diff) | |
download | boringssl-5d880140674cd36d84331de7df95c2dc00dc7686.zip boringssl-5d880140674cd36d84331de7df95c2dc00dc7686.tar.gz boringssl-5d880140674cd36d84331de7df95c2dc00dc7686.tar.bz2 |
Deprecate and simplify SSL_CTX_check_private_key
It is not actually possible to configure an inconsistent certificate and
private key pair (short of mutating the objects after you've configured
them). The functions that configure certificates and private keys will
refuse to get CERT into an inconsistent state.
SSL_CTX_check_private_key is really just checking that you have a
certificate and private key at all. Some callers (notably pyOpenSSL's
tests) are written as if SSL_CTX_check_private_key does something more,
but that's only because they also configure certificate and private key
in the wrong order. If you configure the key first, configuring the
certificate silently drops the mismatched private key because OpenSSL
thinks you're overwriting an identity. SSL_CTX_check_private_key is
really just detecting this case.
Add tests for all this behavior, document that certificates should be
configured first, and then deprecate SSL_CTX_check_private_key because,
in the correct order, this function is superfluous.
This will get shuffled around with SSL_CREDENTIAL, so add some tests
first.
Bug: 249
Change-Id: I3fcc0f51add1826d581583b43ff003c0dea979dd
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/66447
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/openssl/ssl.h | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/include/openssl/ssl.h b/include/openssl/ssl.h index 97fe96e..04f1873 100644 --- a/include/openssl/ssl.h +++ b/include/openssl/ssl.h @@ -848,15 +848,22 @@ OPENSSL_EXPORT void SSL_CTX_set0_buffer_pool(SSL_CTX *ctx, // the wire) but does not include the leaf. Both client and server certificates // use these functions. // +// Prefer to configure the certificate before the private key. If configured in +// the other order, inconsistent private keys will be silently dropped, rather +// than return an error. Additionally, overwriting a previously-configured +// certificate and key pair only works if the certificate is configured first. +// // Certificates and keys may be configured before the handshake or dynamically // in the early callback and certificate callback. // SSL_CTX_use_certificate sets |ctx|'s leaf certificate to |x509|. It returns -// one on success and zero on failure. +// one on success and zero on failure. If |ctx| has a private key which is +// inconsistent with |x509|, the private key is silently dropped. OPENSSL_EXPORT int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x509); // SSL_use_certificate sets |ssl|'s leaf certificate to |x509|. It returns one -// on success and zero on failure. +// on success and zero on failure. If |ssl| has a private key which is +// inconsistent with |x509|, the private key is silently dropped. OPENSSL_EXPORT int SSL_use_certificate(SSL *ssl, X509 *x509); // SSL_CTX_use_PrivateKey sets |ctx|'s private key to |pkey|. It returns one on @@ -990,14 +997,6 @@ SSL_get0_peer_delegation_algorithms(const SSL *ssl, // chain of |ssl|. OPENSSL_EXPORT void SSL_certs_clear(SSL *ssl); -// SSL_CTX_check_private_key returns one if the certificate and private key -// configured in |ctx| are consistent and zero otherwise. -OPENSSL_EXPORT int SSL_CTX_check_private_key(const SSL_CTX *ctx); - -// SSL_check_private_key returns one if the certificate and private key -// configured in |ssl| are consistent and zero otherwise. -OPENSSL_EXPORT int SSL_check_private_key(const SSL *ssl); - // SSL_CTX_get0_certificate returns |ctx|'s leaf certificate. OPENSSL_EXPORT X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx); @@ -5317,6 +5316,25 @@ OPENSSL_EXPORT int SSL_set1_curves_list(SSL *ssl, const char *curves); // returns this value, but we define this constant for compatibility. #define TLSEXT_nid_unknown 0x1000000 +// SSL_CTX_check_private_key returns one if |ctx| has both a certificate and +// private key, and zero otherwise. +// +// This function does not check consistency because the library checks when the +// certificate and key are individually configured. However, if the private key +// is configured before the certificate, inconsistent private keys are silently +// dropped. Some callers are inadvertently relying on this function to detect +// when this happens. +// +// Instead, callers should configure the certificate first, then the private +// key, checking for errors in each. This function is then unnecessary. +OPENSSL_EXPORT int SSL_CTX_check_private_key(const SSL_CTX *ctx); + +// SSL_check_private_key returns one if |ssl| has both a certificate and private +// key, and zero otherwise. +// +// See discussion in |SSL_CTX_check_private_key|. +OPENSSL_EXPORT int SSL_check_private_key(const SSL *ssl); + // Compliance policy configurations // |