From 5debf070103131cff97a2fc78c93cae391099842 Mon Sep 17 00:00:00 2001 From: Hugo Landau Date: Thu, 31 Aug 2023 11:53:32 +0100 Subject: [PATCH] QUIC APL: Implement SSL_want Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/21915) --- include/internal/quic_ssl.h | 1 + ssl/quic/quic_impl.c | 42 +++++++++++++++++++++++++++++++++++++ ssl/ssl_lib.c | 5 +++++ 3 files changed, 48 insertions(+) diff --git a/include/internal/quic_ssl.h b/include/internal/quic_ssl.h index f815ba5435..77ff85a022 100644 --- a/include/internal/quic_ssl.h +++ b/include/internal/quic_ssl.h @@ -57,6 +57,7 @@ __owur int ossl_quic_get_wpoll_descriptor(SSL *s, BIO_POLL_DESCRIPTOR *d); __owur int ossl_quic_get_net_read_desired(SSL *s); __owur int ossl_quic_get_net_write_desired(SSL *s); __owur int ossl_quic_get_error(const SSL *s, int i); +__owur int ossl_quic_want(const SSL *s); __owur int ossl_quic_conn_get_blocking_mode(const SSL *s); __owur int ossl_quic_conn_set_blocking_mode(SSL *s, int blocking); __owur int ossl_quic_conn_shutdown(SSL *s, uint64_t flags, diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index 2f60594efa..71c1536102 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -2025,6 +2025,7 @@ SSL *ossl_quic_conn_stream_new(SSL *s, uint64_t flags) * above, all QUIC I/O is implemented using non-blocking mode internally. * * SSL_get_error => partially implemented by ossl_quic_get_error + * SSL_want => ossl_quic_want * (BIO/)SSL_read => ossl_quic_read * (BIO/)SSL_write => ossl_quic_write * SSL_pending => ossl_quic_pending @@ -2052,6 +2053,47 @@ int ossl_quic_get_error(const SSL *s, int i) return last_error; } +/* Converts a code returned by SSL_get_error to a code returned by SSL_want. */ +static int error_to_want(int error) +{ + switch (error) { + case SSL_ERROR_WANT_CONNECT: /* never used - UDP is connectionless */ + case SSL_ERROR_WANT_ACCEPT: /* never used - UDP is connectionless */ + case SSL_ERROR_ZERO_RETURN: + default: + return SSL_NOTHING; + + case SSL_ERROR_WANT_READ: + return SSL_READING; + + case SSL_ERROR_WANT_WRITE: + return SSL_WRITING; + + case SSL_ERROR_WANT_CLIENT_HELLO_CB: + return SSL_CLIENT_HELLO_CB; + + case SSL_ERROR_WANT_X509_LOOKUP: + return SSL_X509_LOOKUP; + } +} + +/* SSL_want */ +int ossl_quic_want(const SSL *s) +{ + QCTX ctx; + int w; + + if (!expect_quic(s, &ctx)) + return SSL_NOTHING; + + quic_lock(ctx.qc); + + w = error_to_want(ctx.is_stream ? ctx.xso->last_error : ctx.qc->last_error); + + quic_unlock(ctx.qc); + return w; +} + /* * SSL_write * --------- diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index b83f11fa5b..5bfd8cc4ce 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -5501,6 +5501,11 @@ int SSL_want(const SSL *s) { const SSL_CONNECTION *sc = SSL_CONNECTION_FROM_CONST_SSL(s); +#ifndef OPENSSL_NO_QUIC + if (IS_QUIC(s)) + return ossl_quic_want(s); +#endif + if (sc == NULL) return SSL_NOTHING;