1
0

0009-S2S-TLS-OpenSSL-Streamline-logging.patch 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. From 36ba9c20f4962b207531238ea2a0935ee9122547 Mon Sep 17 00:00:00 2001
  2. From: Alexander Barton <alex@barton.de>
  3. Date: Tue, 2 Jan 2024 22:13:42 +0100
  4. Subject: [PATCH 09/20] S2S-TLS/OpenSSL: Streamline logging
  5. This includes simplifying cb_connserver_login_ssl() a bit, we do not
  6. have to code for invalid state which was ruled out by an assert() and
  7. therefore can get rid of the goto altogether (and don't log the same
  8. error twice with different messages).
  9. (cherry picked from commit 02bb99b0242ade8af78f957aa1657561374ef1d6)
  10. ---
  11. src/ngircd/conn-ssl.c | 15 +++++++++------
  12. src/ngircd/conn.c | 25 +++++++++++--------------
  13. 2 files changed, 20 insertions(+), 20 deletions(-)
  14. --- a/src/ngircd/conn-ssl.c
  15. +++ b/src/ngircd/conn-ssl.c
  16. @@ -147,13 +147,13 @@
  17. mem = BIO_new(BIO_s_mem());
  18. if (!mem)
  19. return;
  20. - X509_NAME_print_ex(mem, X509_get_subject_name(cert), 4,
  21. + X509_NAME_print_ex(mem, X509_get_subject_name(cert), 0,
  22. XN_FLAG_ONELINE);
  23. - X509_NAME_print_ex(mem, X509_get_issuer_name(cert), 4, XN_FLAG_ONELINE);
  24. + X509_NAME_print_ex(mem, X509_get_issuer_name(cert), 2, XN_FLAG_ONELINE);
  25. if (BIO_write(mem, "", 1) == 1) {
  26. len = BIO_get_mem_data(mem, &memptr);
  27. if (memptr && len > 0)
  28. - Log(level, "%s: \"%s\"", msg, memptr);
  29. + Log(level, "%s: \"%s\".", msg, memptr);
  30. }
  31. (void)BIO_set_close(mem, BIO_CLOSE);
  32. BIO_free(mem);
  33. @@ -755,9 +755,12 @@
  34. "SSL error, client disconnected [in %s()]!",
  35. fname);
  36. break;
  37. - case -1: /* low level socket I/O error, check errno */
  38. - Log(LOG_ERR, "SSL error: %s [in %s()]!",
  39. - strerror(real_errno), fname);
  40. + case -1:
  41. + /* Low level socket I/O error, check errno. But
  42. + * we don't need to log this here, the generic
  43. + * connection layer will take care of it. */
  44. + LogDebug("SSL error: %s [in %s()]!",
  45. + strerror(real_errno), fname);
  46. }
  47. }
  48. break;
  49. --- a/src/ngircd/conn.c
  50. +++ b/src/ngircd/conn.c
  51. @@ -2534,28 +2534,25 @@
  52. serveridx = Conf_GetServer(idx);
  53. assert(serveridx >= 0);
  54. - if (serveridx < 0)
  55. - goto err;
  56. -
  57. - Log( LOG_INFO, "SSL connection %d with \"%s:%d\" established.", idx,
  58. - My_Connections[idx].host, Conf_Server[Conf_GetServer( idx )].port );
  59. + /* The SSL handshake is done, but validation results were ignored so
  60. + * far, so let's see where we are: */
  61. + LogDebug("SSL handshake on socket %d done.", idx);
  62. if (!Conn_OPTION_ISSET(&My_Connections[idx], CONN_SSL_PEERCERT_OK)) {
  63. if (Conf_Server[serveridx].SSLVerify) {
  64. Log(LOG_ERR,
  65. - "SSLVerify enabled for %d, but peer certificate check failed",
  66. - idx);
  67. - goto err;
  68. + "Peer certificate check failed for \"%s\" on connection %d!",
  69. + My_Connections[idx].host, idx);
  70. + Conn_Close(idx, "Valid certificate required",
  71. + NULL, false);
  72. + return;
  73. }
  74. Log(LOG_WARNING,
  75. - "Peer certificate check failed for %d, but SSLVerify is disabled, continuing",
  76. - idx);
  77. + "Peer certificate check failed for \"%s\" on connection %d, but \"SSLVerify\" is disabled. Continuing ...",
  78. + My_Connections[idx].host, idx);
  79. }
  80. + LogDebug("Server certificate accepted, continuing server login ...");
  81. server_login(idx);
  82. - return;
  83. - err:
  84. - Log(LOG_ERR, "SSL connection on socket %d failed!", sock);
  85. - Conn_Close(idx, "Can't connect!", NULL, false);
  86. }