diff options
author | jsing <> | 2019-02-28 17:56:43 +0000 |
---|---|---|
committer | jsing <> | 2019-02-28 17:56:43 +0000 |
commit | c033d8dd5f1b51daaea294f6d345521ac6566588 (patch) | |
tree | 5afffe228b3a0a9a1724ae29407d33698377ad48 /src/lib | |
parent | fff434b2b23e8a074d741e819b9a91ddac0d4c9c (diff) | |
download | openbsd-c033d8dd5f1b51daaea294f6d345521ac6566588.tar.gz openbsd-c033d8dd5f1b51daaea294f6d345521ac6566588.tar.bz2 openbsd-c033d8dd5f1b51daaea294f6d345521ac6566588.zip |
Automatically complete the handshake from tls13_legacy_{read,write}_bytes()
If the TLS handshake has not been completed, automatically complete the
handshake as part of the read/write call, implementing the current
SSL_read()/SSL_write() behaviour.
Once the TLS handshake is completed we push a WANT_POLLIN or WANT_POLLOUT
back up to the caller, since some applications appear to incorrectly call
SSL_read() or SSL_write(), rather than repeating the previous call. This
can lead to attempts to read data that does not exist, since the
WANT_POLLIN was actually triggered as part of the handshake.
ok inoguchi@ tb@
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libssl/tls13_handshake.c | 3 | ||||
-rw-r--r-- | src/lib/libssl/tls13_internal.h | 3 | ||||
-rw-r--r-- | src/lib/libssl/tls13_lib.c | 14 |
3 files changed, 17 insertions, 3 deletions
diff --git a/src/lib/libssl/tls13_handshake.c b/src/lib/libssl/tls13_handshake.c index d4fc7cb6f7..536630ac33 100644 --- a/src/lib/libssl/tls13_handshake.c +++ b/src/lib/libssl/tls13_handshake.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_handshake.c,v 1.30 2019/02/28 17:39:36 jsing Exp $ */ | 1 | /* $OpenBSD: tls13_handshake.c,v 1.31 2019/02/28 17:56:43 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018-2019 Theo Buehler <tb@openbsd.org> | 3 | * Copyright (c) 2018-2019 Theo Buehler <tb@openbsd.org> |
4 | * Copyright (c) 2019 Joel Sing <jsing@openbsd.org> | 4 | * Copyright (c) 2019 Joel Sing <jsing@openbsd.org> |
@@ -282,6 +282,7 @@ tls13_handshake_perform(struct tls13_ctx *ctx) | |||
282 | return TLS13_IO_FAILURE; | 282 | return TLS13_IO_FAILURE; |
283 | 283 | ||
284 | if (action->handshake_complete) { | 284 | if (action->handshake_complete) { |
285 | ctx->handshake_completed = 1; | ||
285 | tls13_record_layer_handshake_completed(ctx->rl); | 286 | tls13_record_layer_handshake_completed(ctx->rl); |
286 | return TLS13_IO_SUCCESS; | 287 | return TLS13_IO_SUCCESS; |
287 | } | 288 | } |
diff --git a/src/lib/libssl/tls13_internal.h b/src/lib/libssl/tls13_internal.h index c3b698e987..f3cccc14a6 100644 --- a/src/lib/libssl/tls13_internal.h +++ b/src/lib/libssl/tls13_internal.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_internal.h,v 1.24 2019/02/25 19:44:04 tb Exp $ */ | 1 | /* $OpenBSD: tls13_internal.h,v 1.25 2019/02/28 17:56:43 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018 Bob Beck <beck@openbsd.org> | 3 | * Copyright (c) 2018 Bob Beck <beck@openbsd.org> |
4 | * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2018 Theo Buehler <tb@openbsd.org> |
@@ -156,6 +156,7 @@ struct tls13_ctx { | |||
156 | struct ssl_handshake_tls13_st *hs; | 156 | struct ssl_handshake_tls13_st *hs; |
157 | uint8_t mode; | 157 | uint8_t mode; |
158 | struct tls13_handshake_stage handshake_stage; | 158 | struct tls13_handshake_stage handshake_stage; |
159 | int handshake_completed; | ||
159 | 160 | ||
160 | const EVP_AEAD *aead; | 161 | const EVP_AEAD *aead; |
161 | const EVP_MD *hash; | 162 | const EVP_MD *hash; |
diff --git a/src/lib/libssl/tls13_lib.c b/src/lib/libssl/tls13_lib.c index e371d71750..c5e2faf3fc 100644 --- a/src/lib/libssl/tls13_lib.c +++ b/src/lib/libssl/tls13_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: tls13_lib.c,v 1.7 2019/02/28 17:44:56 jsing Exp $ */ | 1 | /* $OpenBSD: tls13_lib.c,v 1.8 2019/02/28 17:56:43 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -241,6 +241,12 @@ tls13_legacy_read_bytes(SSL *ssl, int type, unsigned char *buf, int len, int pee | |||
241 | struct tls13_ctx *ctx = ssl->internal->tls13; | 241 | struct tls13_ctx *ctx = ssl->internal->tls13; |
242 | ssize_t ret; | 242 | ssize_t ret; |
243 | 243 | ||
244 | if (ctx == NULL || !ctx->handshake_completed) { | ||
245 | if ((ret = ssl->internal->handshake_func(ssl)) <= 0) | ||
246 | return ret; | ||
247 | return tls13_legacy_return_code(ssl, TLS13_IO_WANT_POLLIN); | ||
248 | } | ||
249 | |||
244 | if (peek) { | 250 | if (peek) { |
245 | /* XXX - support peek... */ | 251 | /* XXX - support peek... */ |
246 | SSLerror(ssl, ERR_R_INTERNAL_ERROR); | 252 | SSLerror(ssl, ERR_R_INTERNAL_ERROR); |
@@ -266,6 +272,12 @@ tls13_legacy_write_bytes(SSL *ssl, int type, const void *buf, int len) | |||
266 | struct tls13_ctx *ctx = ssl->internal->tls13; | 272 | struct tls13_ctx *ctx = ssl->internal->tls13; |
267 | ssize_t ret; | 273 | ssize_t ret; |
268 | 274 | ||
275 | if (ctx == NULL || !ctx->handshake_completed) { | ||
276 | if ((ret = ssl->internal->handshake_func(ssl)) <= 0) | ||
277 | return ret; | ||
278 | return tls13_legacy_return_code(ssl, TLS13_IO_WANT_POLLOUT); | ||
279 | } | ||
280 | |||
269 | if (type != SSL3_RT_APPLICATION_DATA) { | 281 | if (type != SSL3_RT_APPLICATION_DATA) { |
270 | SSLerror(ssl, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); | 282 | SSLerror(ssl, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); |
271 | return -1; | 283 | return -1; |