From: Hugo Landau Date: Tue, 18 Apr 2023 18:30:55 +0000 (+0100) Subject: QUIC DISPATCH/APL: Implement SSL_get_stream_type X-Git-Tag: openssl-3.2.0-alpha1~863 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1bca3f1b2d139c2306fd65d23583e4d16bdc11f9;p=thirdparty%2Fopenssl.git QUIC DISPATCH/APL: Implement SSL_get_stream_type Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/20765) --- diff --git a/include/internal/quic_ssl.h b/include/internal/quic_ssl.h index 86dca6bb30b..35873cd51dd 100644 --- a/include/internal/quic_ssl.h +++ b/include/internal/quic_ssl.h @@ -67,6 +67,7 @@ __owur int ossl_quic_conn_set_initial_peer_addr(SSL *s, const BIO_ADDR *peer_addr); __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); /* * 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 1c94f053fd4..25208ca2944 100644 --- a/include/openssl/ssl.h.in +++ b/include/openssl/ssl.h.in @@ -2269,6 +2269,12 @@ __owur int SSL_set_initial_peer_addr(SSL *s, const BIO_ADDR *peer_addr); __owur SSL *SSL_get0_connection(SSL *s); __owur int SSL_is_connection(SSL *s); +#define SSL_STREAM_TYPE_NONE 0 +#define SSL_STREAM_TYPE_READ 1 +#define SSL_STREAM_TYPE_WRITE 2 +#define SSL_STREAM_TYPE_BIDI (SSL_STREAM_TYPE_READ | SSL_STREAM_TYPE_WRITE) +__owur int SSL_get_stream_type(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 3ed03b1c866..2f97f7c6b58 100644 --- a/ssl/quic/quic_impl.c +++ b/ssl/quic/quic_impl.c @@ -1835,6 +1835,38 @@ SSL *ossl_quic_get0_connection(SSL *s) return &ctx.qc->ssl; } +/* + * SSL_get_stream_type + * ------------------- + */ +int ossl_quic_get_stream_type(SSL *s) +{ + QCTX ctx; + + if (!expect_quic(s, &ctx)) + return SSL_STREAM_TYPE_NONE; + + if (ctx.xso == NULL) { + /* + * If we are deferring XSO creation, assume single stream mode and + * default to BIDI, as the deferred XSO which will be created will be + * bidirectional. + */ + if (!ctx.qc->default_xso_created) + return SSL_STREAM_TYPE_BIDI; + else + return SSL_STREAM_TYPE_NONE; + } + + if (ossl_quic_stream_is_bidi(ctx.xso->stream)) + return SSL_STREAM_TYPE_BIDI; + + if (ossl_quic_stream_is_server_init(ctx.xso->stream) != ctx.qc->as_server) + return SSL_STREAM_TYPE_READ; + else + return SSL_STREAM_TYPE_WRITE; +} + /* * QUIC Front-End I/O API: SSL_CTX Management * ========================================== diff --git a/ssl/ssl_lib.c b/ssl/ssl_lib.c index 29d16107aec..5a226312da8 100644 --- a/ssl/ssl_lib.c +++ b/ssl/ssl_lib.c @@ -7328,6 +7328,18 @@ int SSL_is_connection(SSL *s) return SSL_get0_connection(s) == s; } +int SSL_get_stream_type(SSL *s) +{ +#ifndef OPENSSL_NO_QUIC + if (!IS_QUIC(s)) + return SSL_STREAM_TYPE_BIDI; + + return ossl_quic_get_stream_type(s); +#else + return SSL_STREAM_TYPE_BIDI; +#endif +} + int SSL_add_expected_rpk(SSL *s, EVP_PKEY *rpk) { unsigned char *data = NULL; diff --git a/util/libssl.num b/util/libssl.num index 78a2676b4de..a52a034e201 100644 --- a/util/libssl.num +++ b/util/libssl.num @@ -562,3 +562,5 @@ SSL_is_tls ? 3_2_0 EXIST::FUNCTION: SSL_is_quic ? 3_2_0 EXIST::FUNCTION: SSL_new_stream ? 3_2_0 EXIST::FUNCTION: SSL_get0_connection ? 3_2_0 EXIST::FUNCTION: +SSL_is_connection ? 3_2_0 EXIST::FUNCTION: +SSL_get_stream_type ? 3_2_0 EXIST::FUNCTION: