Commit af0e79c8 authored by Michael Paquier's avatar Michael Paquier

Move SSL information callback earlier to capture more information

The callback for retrieving state change information during connection
setup was only installed when the connection was mostly set up, and
thus didn't provide much information and missed all the details related
to the handshake.

This also extends the callback with SSL_state_string_long() to print
more information about the state change within the SSL object handled.

While there, fix some comments which were incorrectly referring to the
callback and its previous location in fe-secure.c.

Author: Daniel Gustafsson
Discussion: https://postgr.es/m/232CF476-94E1-42F1-9408-719E2AEC5491@yesql.se
parent 27a48e5a
...@@ -381,6 +381,9 @@ be_tls_open_server(Port *port) ...@@ -381,6 +381,9 @@ be_tls_open_server(Port *port)
return -1; return -1;
} }
/* set up debugging/info callback */
SSL_CTX_set_info_callback(SSL_context, info_cb);
if (!(port->ssl = SSL_new(SSL_context))) if (!(port->ssl = SSL_new(SSL_context)))
{ {
ereport(COMMERROR, ereport(COMMERROR,
...@@ -562,9 +565,6 @@ aloop: ...@@ -562,9 +565,6 @@ aloop:
port->peer_cert_valid = true; port->peer_cert_valid = true;
} }
/* set up debugging/info callback */
SSL_CTX_set_info_callback(SSL_context, info_cb);
return 0; return 0;
} }
...@@ -999,39 +999,43 @@ verify_cb(int ok, X509_STORE_CTX *ctx) ...@@ -999,39 +999,43 @@ verify_cb(int ok, X509_STORE_CTX *ctx)
static void static void
info_cb(const SSL *ssl, int type, int args) info_cb(const SSL *ssl, int type, int args)
{ {
const char *desc;
desc = SSL_state_string_long(ssl);
switch (type) switch (type)
{ {
case SSL_CB_HANDSHAKE_START: case SSL_CB_HANDSHAKE_START:
ereport(DEBUG4, ereport(DEBUG4,
(errmsg_internal("SSL: handshake start"))); (errmsg_internal("SSL: handshake start: \"%s\"", desc)));
break; break;
case SSL_CB_HANDSHAKE_DONE: case SSL_CB_HANDSHAKE_DONE:
ereport(DEBUG4, ereport(DEBUG4,
(errmsg_internal("SSL: handshake done"))); (errmsg_internal("SSL: handshake done: \"%s\"", desc)));
break; break;
case SSL_CB_ACCEPT_LOOP: case SSL_CB_ACCEPT_LOOP:
ereport(DEBUG4, ereport(DEBUG4,
(errmsg_internal("SSL: accept loop"))); (errmsg_internal("SSL: accept loop: \"%s\"", desc)));
break; break;
case SSL_CB_ACCEPT_EXIT: case SSL_CB_ACCEPT_EXIT:
ereport(DEBUG4, ereport(DEBUG4,
(errmsg_internal("SSL: accept exit (%d)", args))); (errmsg_internal("SSL: accept exit (%d): \"%s\"", args, desc)));
break; break;
case SSL_CB_CONNECT_LOOP: case SSL_CB_CONNECT_LOOP:
ereport(DEBUG4, ereport(DEBUG4,
(errmsg_internal("SSL: connect loop"))); (errmsg_internal("SSL: connect loop: \"%s\"", desc)));
break; break;
case SSL_CB_CONNECT_EXIT: case SSL_CB_CONNECT_EXIT:
ereport(DEBUG4, ereport(DEBUG4,
(errmsg_internal("SSL: connect exit (%d)", args))); (errmsg_internal("SSL: connect exit (%d): \"%s\"", args, desc)));
break; break;
case SSL_CB_READ_ALERT: case SSL_CB_READ_ALERT:
ereport(DEBUG4, ereport(DEBUG4,
(errmsg_internal("SSL: read alert (0x%04x)", args))); (errmsg_internal("SSL: read alert (0x%04x): \"%s\"", args, desc)));
break; break;
case SSL_CB_WRITE_ALERT: case SSL_CB_WRITE_ALERT:
ereport(DEBUG4, ereport(DEBUG4,
(errmsg_internal("SSL: write alert (0x%04x)", args))); (errmsg_internal("SSL: write alert (0x%04x): \"%s\"", args, desc)));
break; break;
} }
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* NOTES * NOTES
* *
* We don't provide informational callbacks here (like * We don't provide informational callbacks here (like
* info_cb() in be-secure.c), since there's no good mechanism to * info_cb() in be-secure-openssl.c), since there's no good mechanism to
* display such information to the user. * display such information to the user.
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
......
...@@ -13,12 +13,6 @@ ...@@ -13,12 +13,6 @@
* IDENTIFICATION * IDENTIFICATION
* src/interfaces/libpq/fe-secure.c * src/interfaces/libpq/fe-secure.c
* *
* NOTES
*
* We don't provide informational callbacks here (like
* info_cb() in be-secure.c), since there's no good mechanism to
* display such information to the user.
*
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment