diff options
author | Michael Kaufmann <mail@michael-kaufmann.ch> | 2021-05-18 11:34:02 +0200 |
---|---|---|
committer | Michael Kaufmann <mail@michael-kaufmann.ch> | 2021-06-01 09:40:40 +0200 |
commit | b249592d29ae0a2b3e8e07fdbc01f33b5a5b8420 (patch) | |
tree | 082fed52affee4d1ee63cb2d649187422743cc1d /lib/vtls/nss.c | |
parent | 8cc1fee5b96244f3468d300eaa02edaca55d9942 (diff) | |
download | curl-b249592d29ae0a2b3e8e07fdbc01f33b5a5b8420.tar.gz |
ssl: read pending close notify alert before closing the connection
This avoids a TCP reset (RST) if the server initiates a connection
shutdown by sending an SSL close notify alert and then closes the TCP
connection.
For SSL connections, usually the server announces that it will close the
connection with an SSL close notify alert. curl should read this alert.
If curl does not read this alert and just closes the connection, some
operating systems close the TCP connection with an RST flag.
See RFC 1122, section 4.2.2.13
If curl reads the close notify alert, the TCP connection is closed
normally with a FIN flag.
The new code is similar to existing code in the "SSL shutdown" function:
try to read an alert (non-blocking), and ignore any read errors.
Closes #7095
Diffstat (limited to 'lib/vtls/nss.c')
-rw-r--r-- | lib/vtls/nss.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/vtls/nss.c b/lib/vtls/nss.c index 1582b1e58..f7583d504 100644 --- a/lib/vtls/nss.c +++ b/lib/vtls/nss.c @@ -1546,6 +1546,14 @@ static void close_one(struct ssl_connect_data *connssl) const bool client_cert = (backend->client_nickname != NULL) || (backend->obj_clicert != NULL); + if(backend->handle) { + char buf[32]; + /* Maybe the server has already sent a close notify alert. + Read it to avoid an RST on the TCP connection. */ + (void)PR_Recv(backend->handle, buf, (int)sizeof(buf), 0, + PR_INTERVAL_NO_WAIT); + } + free(backend->client_nickname); backend->client_nickname = NULL; |