From 19cb0887722b66e5db7ec0d339526608444a11ef Mon Sep 17 00:00:00 2001 From: Hugo Landau Date: Tue, 18 Apr 2023 19:30:55 +0100 Subject: [PATCH] QUIC DISPATCH/APL: Implement SSL_get_stream_id Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/20765) --- include/internal/quic_ssl.h | 1 + include/openssl/ssl.h.in | 2 ++ ssl/quic/quic_impl.c | 14 ++++++++++++++ ssl/ssl_lib.c | 12 ++++++++++++ 4 files changed, 29 insertions(+) diff --git a/include/internal/quic_ssl.h b/include/internal/quic_ssl.h index 35873cd51d..0ccb1c5526 100644 --- a/include/internal/quic_ssl.h +++ b/include/internal/quic_ssl.h @@ -68,6 +68,7 @@ __owur int ossl_quic_conn_set_initial_peer_addr(SSL *s, __owur SSL *ossl_quic_conn_stream_new(SSL *s, uint64_t flags); __owur SSL *ossl_quic_get0_connection(SSL *s); __owur int ossl_quic_get_stream_type(SSL *s); +__owur uint64_t ossl_quic_get_stream_id(SSL *s); /* * Used to override ossl_time_now() for debug purposes. Must be called before diff --git a/include/openssl/ssl.h.in b/include/openssl/ssl.h.in index 25208ca294..8d82bf6b5a 100644 --- a/include/openssl/ssl.h.in +++ b/include/openssl/ssl.h.in @@ -2275,6 +2275,8 @@ __owur int SSL_is_connection(SSL *s); #define SSL_STREAM_TYPE_BIDI (SSL_STREAM_TYPE_READ | SSL_STREAM_TYPE_WRITE) __owur int SSL_get_stream_type(SSL *s); +__owur uint64_t SSL_get_stream_id(SSL *s); + #define SSL_STREAM_FLAG_UNI (1U << 0) __owur SSL *SSL_new_stream(SSL *s, uint64_t flags); diff --git a/ssl/quic/quic_impl.c b/ssl/quic/quic_impl.c index 2f97f7c6b5..6a28c00c75 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -1867,6 +1867,20 @@ int ossl_quic_get_stream_type(SSL *s) return SSL_STREAM_TYPE_WRITE; } +/* + * SSL_get_stream_id + * ----------------- + */ +uint64_t ossl_quic_get_stream_id(SSL *s) +{ + QCTX ctx; + + if (!expect_quic_with_stream(s, /*remote_init=*/-1, &ctx)) + return UINT64_MAX; + + return ctx.xso->stream->id; +} + /* * QUIC Front-End I/O API: SSL_CTX Management * ========================================== diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 5a226312da..a7e3682291 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -7340,6 +7340,18 @@ int SSL_get_stream_type(SSL *s) #endif } +uint64_t SSL_get_stream_id(SSL *s) +{ +#ifndef OPENSSL_NO_QUIC + if (!IS_QUIC(s)) + return UINT64_MAX; + + return ossl_quic_get_stream_id(s); +#else + return UINT64_MAX; +#endif +} + int SSL_add_expected_rpk(SSL *s, EVP_PKEY *rpk) { unsigned char *data = NULL; -- 2.34.1