]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
QUIC DISPATCH/APL: Implement SSL_get_stream_type
authorHugo Landau <hlandau@openssl.org>
Tue, 18 Apr 2023 18:30:55 +0000 (19:30 +0100)
committerHugo Landau <hlandau@openssl.org>
Fri, 12 May 2023 13:47:11 +0000 (14:47 +0100)
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20765)

include/internal/quic_ssl.h
include/openssl/ssl.h.in
ssl/quic/quic_impl.c
ssl/ssl_lib.c
util/libssl.num

index 86dca6bb30bedf3f315cc3f9ac7669983902750e..35873cd51ddc2342a87201aa0acfce8ed4a027cc 100644 (file)
@@ -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
index 1c94f053fd4207db7ff1eb0ec7fbf0980012a834..25208ca29443a25e5223acec417f6d396b016f02 100644 (file)
@@ -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);
 
index 3ed03b1c866d2d68b7a6702624a98eee2a279f86..2f97f7c6b58811eb510973d9bdbb5e1225afb3eb 100644 (file)
@@ -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
  * ==========================================
index 29d16107aecf16e265f2b150903bf6eb4c2fad9e..5a226312da8bc5664de56c9ed811d9de708505ae 100644 (file)
@@ -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;
index 78a2676b4de4e2686dd945776963f8867b25c5e0..a52a034e20177da44bfeaf06399468a0cc0f3d9b 100644 (file)
@@ -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: