Skip to content

Commit 05cc63d

Browse files
author
jsing
committed
Handle zero byte reads/writes that trigger handshakes in the TLSv1.3 stack.
With the legaacy stack, it is possible to do a zero byte SSL_read() or SSL_write() that triggers the handshake, but then returns zero without SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE being flagged. This currently works in the TLSv1.3 stack by returning TLS_IO_WANT_POLLIN or TLS_IO_WANT_POLLOUT, which is then hidden by SSL_get_error(). However, due to upcoming changes to SSL_get_error() this will no longer be the case. In order to maintain the existing legacy behaviour, explicitly handle zero byte reads and writes in the TLSv1.3 stack, following completion of a handshake. ok inoguchi@ tb@
1 parent 403a203 commit 05cc63d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/lib/libssl/tls13_legacy.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: tls13_legacy.c,v 1.36 2022/02/05 14:54:10 jsing Exp $ */
1+
/* $OpenBSD: tls13_legacy.c,v 1.37 2022/02/06 16:08:14 jsing Exp $ */
22
/*
33
* Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
44
*
@@ -229,6 +229,8 @@ tls13_legacy_read_bytes(SSL *ssl, int type, unsigned char *buf, int len, int pee
229229
if (ctx == NULL || !ctx->handshake_completed) {
230230
if ((ret = ssl->internal->handshake_func(ssl)) <= 0)
231231
return ret;
232+
if (len == 0)
233+
return 0;
232234
return tls13_legacy_return_code(ssl, TLS13_IO_WANT_POLLIN);
233235
}
234236

@@ -263,6 +265,8 @@ tls13_legacy_write_bytes(SSL *ssl, int type, const void *vbuf, int len)
263265
if (ctx == NULL || !ctx->handshake_completed) {
264266
if ((ret = ssl->internal->handshake_func(ssl)) <= 0)
265267
return ret;
268+
if (len == 0)
269+
return 0;
266270
return tls13_legacy_return_code(ssl, TLS13_IO_WANT_POLLOUT);
267271
}
268272

0 commit comments

Comments
 (0)