| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- From dc75413ffbb588e9caf25f9978fbaf624491e2ba Mon Sep 17 00:00:00 2001
- From: Alexander Barton <alex@barton.de>
- Date: Tue, 2 Jan 2024 22:02:46 +0100
- Subject: [PATCH 08/20] S2S-TLS/OpenSSL: Postpone verification of TLS session
- right before server handshake
- The verify callback in OpenSSL is called pretty early, and at that time
- it is not possible yet to check which connection it belongs to, and some
- connections may have relaxed requirements.
- So always return success in the Verify_openssl() callback, and postpone
- validation of the TLS session until starting the server handshake in
- cb_connserver_login_ssl(), when we know which server this connection
- belongs to and which options (like "SSLVerify") are in effect.
- The code doing this was already present in cb_connserver_login_ssl(),
- but this patch adds a more prominent comment to the function.
- (cherry picked from commit 3db3b47fc7172a69b7d99d66eddb07a323dc6e74)
- ---
- src/ngircd/conn-ssl.c | 21 +++++++++++++++------
- src/ngircd/conn.c | 7 +++++++
- 2 files changed, 22 insertions(+), 6 deletions(-)
- --- a/src/ngircd/conn-ssl.c
- +++ b/src/ngircd/conn-ssl.c
- @@ -203,14 +203,23 @@
- static int
- Verify_openssl(int preverify_ok, X509_STORE_CTX * ctx)
- {
- - int err;
- -
- +#ifdef DEBUG
- if (!preverify_ok) {
- - err = X509_STORE_CTX_get_error(ctx);
- - Log(LOG_ERR, "Certificate validation failed: %s",
- - X509_verify_cert_error_string(err));
- + int err = X509_STORE_CTX_get_error(ctx);
- + LogDebug("Certificate validation failed: %s",
- + X509_verify_cert_error_string(err));
- }
- - return preverify_ok;
- +#else
- + (void)preverify_ok;
- + (void)ctx;
- +#endif
- +
- + /* Always(!) return success as we have to deal with invalid
- + * (self-signed, expired, ...) client certificates and with invalid
- + * server certificates when "SSLVerify" is disabled, which we don't
- + * know at this stage. Therefore we postpone this check, it will be
- + * (and has to be!) handled in cb_connserver_login_ssl(). */
- + return 1;
- }
- #endif
-
- --- a/src/ngircd/conn.c
- +++ b/src/ngircd/conn.c
- @@ -2499,6 +2499,13 @@
- /**
- * IO callback for new outgoing SSL-enabled server connections.
- *
- + * IMPORTANT: The SSL session has been validated before, but all errors have
- + * been ignored so far! The reason for this is that the generic SSL code has no
- + * idea if the new session actually belongs to a server, as this only becomes
- + * clear when the remote peer sends its PASS command (and we have to handle
- + * invalid client certificates!). Therefore, it is important to check the
- + * status of the SSL session first before continuing the server handshake here!
- + *
- * @param sock Socket descriptor.
- * @param unused (ignored IO specification)
- */
|