diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-04-08 04:24:49 +0300 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2024-04-08 04:24:49 +0300 |
commit | d39a49c1e459804831302807c724fa6512e90cf0 (patch) | |
tree | 6c4c806f3e663ace026213bf719a89873fe7a7ab /src/interfaces/libpq/fe-secure-openssl.c | |
parent | 05fd30c0e730bd5238f62d2fdfdcfaf28b16b225 (diff) | |
download | postgresql-d39a49c1e459804831302807c724fa6512e90cf0.tar.gz postgresql-d39a49c1e459804831302807c724fa6512e90cf0.zip |
Support TLS handshake directly without SSLRequest negotiation
By skipping SSLRequest, you can eliminate one round-trip when
establishing a TLS connection. It is also more friendly to generic TLS
proxies that don't understand the PostgreSQL protocol.
This is disabled by default in libpq, because the direct TLS handshake
will fail with old server versions. It can be enabled with the
sslnegotation=direct option. It will still fall back to the negotiated
TLS handshake if the server rejects the direct attempt, either because
it is an older version or the server doesn't support TLS at all, but
the fallback can be disabled with the sslnegotiation=requiredirect
option.
Author: Greg Stark, Heikki Linnakangas
Reviewed-by: Matthias van de Meent, Jacob Champion
Diffstat (limited to 'src/interfaces/libpq/fe-secure-openssl.c')
-rw-r--r-- | src/interfaces/libpq/fe-secure-openssl.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c index 0c8c9f8dcba..a43e74284f2 100644 --- a/src/interfaces/libpq/fe-secure-openssl.c +++ b/src/interfaces/libpq/fe-secure-openssl.c @@ -1612,6 +1612,7 @@ pgtls_close(PGconn *conn) SSL_free(conn->ssl); conn->ssl = NULL; conn->ssl_in_use = false; + conn->ssl_handshake_started = false; destroy_needed = true; } @@ -1825,9 +1826,10 @@ static BIO_METHOD *my_bio_methods; static int my_sock_read(BIO *h, char *buf, int size) { + PGconn *conn = (PGconn *) BIO_get_app_data(h); int res; - res = pqsecure_raw_read((PGconn *) BIO_get_app_data(h), buf, size); + res = pqsecure_raw_read(conn, buf, size); BIO_clear_retry_flags(h); if (res < 0) { @@ -1849,6 +1851,9 @@ my_sock_read(BIO *h, char *buf, int size) } } + if (res > 0) + conn->ssl_handshake_started = true; + return res; } |