0007-S2S-TLS-OpenSSL-Fix-handling-of-certificate-informat.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. From 0bdc552ffe5c47be83c646b61e9a7d211d4568a6 Mon Sep 17 00:00:00 2001
  2. From: Alexander Barton <alex@barton.de>
  3. Date: Tue, 2 Jan 2024 21:10:17 +0100
  4. Subject: [PATCH 07/20] S2S-TLS/OpenSSL: Fix handling of certificate
  5. information for incoming connections
  6. Show proper certificate information for incoming connections, too, and
  7. not "peer did not present a certificate", regardless if the client sent
  8. a certificate or not.
  9. And free the client certificate structure "peer_cert" on incoming
  10. connections as well!
  11. (cherry picked from commit 679505aab9fea21b27a3d4bbf99cf2a16cf3d3d5)
  12. ---
  13. src/ngircd/conn-ssl.c | 46 ++++++++++++++++++++++++++++---------------
  14. 1 file changed, 30 insertions(+), 16 deletions(-)
  15. --- a/src/ngircd/conn-ssl.c
  16. +++ b/src/ngircd/conn-ssl.c
  17. @@ -935,22 +935,36 @@
  18. Log(LOG_INFO, "Connection %d: initialized %s using cipher %s, %s.",
  19. c->sock, SSL_get_version(ssl), SSL_get_cipher(ssl), comp_alg);
  20. peer_cert = SSL_get_peer_certificate(ssl);
  21. - if (peer_cert && connect) {
  22. + if (peer_cert) {
  23. cert_seen = true;
  24. - /* Client: Check server certificate */
  25. - int err = SSL_get_verify_result(ssl);
  26. - if (err == X509_V_OK) {
  27. - const char *peername = SSL_get0_peername(ssl);
  28. - if (peername != NULL)
  29. - cert_ok = true;
  30. - LogDebug("X509_V_OK, peername = '%s'", peername);
  31. - } else
  32. - Log(LOG_ERR, "Certificate validation failed: %s",
  33. - X509_verify_cert_error_string(err));
  34. - snprintf(msg, sizeof(msg), "%svalid peer certificate",
  35. - cert_ok ? "" : "in");
  36. - LogOpenSSL_CertInfo(cert_ok ? LOG_DEBUG : LOG_ERR, peer_cert,
  37. - msg);
  38. +
  39. + if (connect) {
  40. + /* Outgoing connection. Verify the remote server! */
  41. + int err = SSL_get_verify_result(ssl);
  42. + if (err == X509_V_OK) {
  43. + const char *peername = SSL_get0_peername(ssl);
  44. + if (peername != NULL)
  45. + cert_ok = true;
  46. + LogDebug("X509_V_OK, peername = '%s'", peername);
  47. + } else
  48. + Log(LOG_WARNING, "Certificate validation failed: %s!",
  49. + X509_verify_cert_error_string(err));
  50. +
  51. + snprintf(msg, sizeof(msg), "Got %svalid server certificate",
  52. + cert_ok ? "" : "in");
  53. + LogOpenSSL_CertInfo(LOG_INFO, peer_cert, msg);
  54. + } else {
  55. + /* Incoming connection.
  56. + * Accept all certificates, don't depend on their
  57. + * validity: for example, we don't know the hostname
  58. + * to check, because we not yet even know if this is a
  59. + * server connection at all and if so, which one, so we
  60. + * don't know a host name to look for. On the other
  61. + * hand we want client certificates, for example for
  62. + * "CertFP" authentication with services ... */
  63. + LogOpenSSL_CertInfo(LOG_INFO, peer_cert,
  64. + "Got unchecked client certificate");
  65. + }
  66. X509_free(peer_cert);
  67. }
  68. @@ -1038,7 +1052,7 @@
  69. if (cert_ok)
  70. Conn_OPTION_ADD(c, CONN_SSL_PEERCERT_OK);
  71. if (!cert_seen)
  72. - Log(LOG_INFO, "Peer did not present a certificate");
  73. + Log(LOG_INFO, "Peer did not present a certificate.");
  74. }