diff options
author | Hugo Landau <hlandau@openssl.org> | 2022-12-13 12:27:05 +0000 |
---|---|---|
committer | Hugo Landau <hlandau@openssl.org> | 2023-01-27 14:19:14 +0000 |
commit | e8043229ead9b44e2883a80ce256c219a1171cbb (patch) | |
tree | 72a689685efbdb2fdd811c586e30558188d9f3a0 /ssl | |
parent | d4c5d8ff483d99f94d649fb67f1f26fce9694c92 (diff) |
QUIC: Refine SSL_shutdown and begin to implement SSL_shutdown_ex
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19897)
Diffstat (limited to 'ssl')
-rw-r--r-- | ssl/quic/quic_channel.c | 5 | ||||
-rw-r--r-- | ssl/quic/quic_impl.c | 52 | ||||
-rw-r--r-- | ssl/quic/quic_local.h | 2 | ||||
-rw-r--r-- | ssl/ssl_lib.c | 26 |
4 files changed, 67 insertions, 18 deletions
diff --git a/ssl/quic/quic_channel.c b/ssl/quic/quic_channel.c index 3701d93e1c..bffd0d3244 100644 --- a/ssl/quic/quic_channel.c +++ b/ssl/quic/quic_channel.c @@ -1712,14 +1712,15 @@ int ossl_quic_channel_start(QUIC_CHANNEL *ch) } /* Start a locally initiated connection shutdown. */ -void ossl_quic_channel_local_close(QUIC_CHANNEL *ch) +void ossl_quic_channel_local_close(QUIC_CHANNEL *ch, uint64_t app_error_code) { QUIC_TERMINATE_CAUSE tcause = {0}; if (ossl_quic_channel_is_term_any(ch)) return; - tcause.app = 1; + tcause.app = 1; + tcause.error_code = app_error_code; ch_start_terminating(ch, &tcause, 0); } diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index 6fb868a004..e869e97ef5 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -18,6 +18,7 @@ #include "internal/time.h" static void aon_write_finish(QUIC_CONNECTION *qc); +static int ensure_channel(QUIC_CONNECTION *qc); /* * QUIC Front-End I/O API: Common Utilities @@ -486,17 +487,34 @@ int ossl_quic_get_net_write_desired(QUIC_CONNECTION *qc) */ /* SSL_shutdown */ -int ossl_quic_shutdown(SSL *s) +static int quic_shutdown_wait(void *arg) { - QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(s); + QUIC_CONNECTION *qc = arg; - if (!expect_quic_conn(qc)) - return 0; + return qc->ch == NULL || ossl_quic_channel_is_terminated(qc->ch); +} - if (qc->ch != NULL) - ossl_quic_channel_local_close(qc->ch); +int ossl_quic_conn_shutdown(QUIC_CONNECTION *qc, uint64_t flags, + const SSL_SHUTDOWN_EX_ARGS *args, + size_t args_len) +{ + if (!ensure_channel(qc)) + return -1; - return 1; + ossl_quic_channel_local_close(qc->ch, + args != NULL ? args->quic_error_code : 0); + + /* TODO(QUIC): !SSL_SHUTDOWN_FLAG_IMMEDIATE */ + + if (ossl_quic_channel_is_terminated(qc->ch)) + return 1; + + if (blocking_mode(qc) && (flags & SSL_SHUTDOWN_FLAG_RAPID) == 0) + block_until_pred(qc, quic_shutdown_wait, NULL, 0); + else + ossl_quic_reactor_tick(ossl_quic_channel_get_reactor(qc->ch)); + + return ossl_quic_channel_is_terminated(qc->ch); } /* SSL_ctrl */ @@ -573,12 +591,7 @@ static int configure_channel(QUIC_CONNECTION *qc) return 1; } -/* - * Creates a channel and configures it with the information we have accumulated - * via calls made to us from the application prior to starting a handshake - * attempt. - */ -static int ensure_channel_and_start(QUIC_CONNECTION *qc) +static int ensure_channel(QUIC_CONNECTION *qc) { QUIC_CHANNEL_ARGS args = {0}; @@ -594,6 +607,19 @@ static int ensure_channel_and_start(QUIC_CONNECTION *qc) if (qc->ch == NULL) return 0; + return 1; +} + +/* + * Creates a channel and configures it with the information we have accumulated + * via calls made to us from the application prior to starting a handshake + * attempt. + */ +static int ensure_channel_and_start(QUIC_CONNECTION *qc) +{ + if (!ensure_channel(qc)) + return 0; + if (!configure_channel(qc) || !ossl_quic_channel_start(qc->ch)) { ossl_quic_channel_free(qc->ch); diff --git a/ssl/quic/quic_local.h b/ssl/quic/quic_local.h index 83cce376fb..f4397447dd 100644 --- a/ssl/quic/quic_local.h +++ b/ssl/quic/quic_local.h @@ -198,7 +198,7 @@ const SSL_METHOD *func_name(void) \ ossl_quic_read, \ ossl_quic_peek, \ ossl_quic_write, \ - ossl_quic_shutdown, \ + NULL /* shutdown */, \ NULL /* renegotiate */, \ ossl_quic_renegotiate_check, \ NULL /* read_bytes */, \ diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 1e23ec55e5..b927e283fe 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -2638,6 +2638,12 @@ int SSL_shutdown(SSL *s) * (see ssl3_shutdown). */ SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s); +#ifndef OPENSSL_NO_QUIC + QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(s); + + if (qc != NULL) + return ossl_quic_conn_shutdown(qc, 0, NULL, 0); +#endif if (sc == NULL) return -1; @@ -7168,10 +7174,26 @@ int SSL_set_initial_peer_addr(SSL *s, const BIO_ADDR *peer_addr) QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(s); if (qc == NULL) - return -1; + return 0; return ossl_quic_conn_set_initial_peer_addr(qc, peer_addr); #else - return -1; + return 0; +#endif +} + +int SSL_shutdown_ex(SSL *ssl, uint64_t flags, + const SSL_SHUTDOWN_EX_ARGS *args, + size_t args_len) +{ +#ifndef OPENSSL_NO_QUIC + QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(ssl); + + if (qc == NULL) + return SSL_shutdown(ssl); + + return ossl_quic_conn_shutdown(qc, flags, args, args_len); +#else + return SSL_shutdown(ssl); #endif } |