]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
QUIC MULTISTREAM TEST: Test WAIT_PEER
authorHugo Landau <hlandau@openssl.org>
Wed, 23 Aug 2023 07:39:38 +0000 (08:39 +0100)
committerHugo Landau <hlandau@openssl.org>
Wed, 30 Aug 2023 07:28:22 +0000 (08:28 +0100)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21815)

include/internal/quic_tserver.h
ssl/quic/quic_tserver.c
test/quic_multistream_test.c
util/quicserver.c

index 45aea0abace93576c97335c03fceb8524f8e6d15..b1415d5edf78eb54bcca7ac87af1275f052db708 100644 (file)
@@ -182,7 +182,7 @@ OSSL_TIME ossl_quic_tserver_get_deadline(QUIC_TSERVER *srv);
  * Shutdown the QUIC connection. Returns 1 if the connection is terminated and
  * 0 otherwise.
  */
-int ossl_quic_tserver_shutdown(QUIC_TSERVER *srv);
+int ossl_quic_tserver_shutdown(QUIC_TSERVER *srv, uint64_t app_error_code);
 
 /* Force generation of an ACK-eliciting packet. */
 int ossl_quic_tserver_ping(QUIC_TSERVER *srv);
index 366673f5cb423bb9e9b93504e1763cf95f6bfb81..a3359c21c022fd72857a9ad59544ef70418d9822 100644 (file)
@@ -502,9 +502,9 @@ OSSL_TIME ossl_quic_tserver_get_deadline(QUIC_TSERVER *srv)
                 ossl_quic_channel_get_reactor(srv->ch));
 }
 
-int ossl_quic_tserver_shutdown(QUIC_TSERVER *srv)
+int ossl_quic_tserver_shutdown(QUIC_TSERVER *srv, uint64_t app_error_code)
 {
-    ossl_quic_channel_local_close(srv->ch, 0, NULL);
+    ossl_quic_channel_local_close(srv->ch, app_error_code, NULL);
 
     /* TODO(QUIC): !SSL_SHUTDOWN_FLAG_NO_STREAM_FLUSH */
 
index ba97bfd7d43c8fbed7a9d7c883ca492695580fd6..81e05dbf2eec28d055e81bf4cc94653245b0d33c 100644 (file)
@@ -157,6 +157,7 @@ struct script_op {
 #define OPK_S_NEW_TICKET                            47
 #define OPK_C_SKIP_IF_UNBOUND                       48
 #define OPK_S_SET_INJECT_DATAGRAM                   49
+#define OPK_S_SHUTDOWN                              50
 
 #define EXPECT_CONN_CLOSE_APP       (1U << 0)
 #define EXPECT_CONN_CLOSE_REMOTE    (1U << 1)
@@ -229,8 +230,8 @@ struct script_op {
     {OPK_C_SET_DEFAULT_STREAM_MODE, NULL, (mode), NULL, NULL},
 #define OP_C_SET_INCOMING_STREAM_POLICY(policy) \
     {OPK_C_SET_INCOMING_STREAM_POLICY, NULL, (policy), NULL, NULL},
-#define OP_C_SHUTDOWN_WAIT(reason) \
-    {OPK_C_SHUTDOWN_WAIT, (reason), 0, NULL, NULL},
+#define OP_C_SHUTDOWN_WAIT(reason, flags) \
+    {OPK_C_SHUTDOWN_WAIT, (reason), (flags), NULL, NULL},
 #define OP_C_EXPECT_CONN_CLOSE_INFO(ec, app, remote)                \
     {OPK_C_EXPECT_CONN_CLOSE_INFO, NULL,                            \
         ((app) ? EXPECT_CONN_CLOSE_APP : 0) |                       \
@@ -293,6 +294,8 @@ struct script_op {
     {OPK_C_SKIP_IF_UNBOUND, NULL, (n), NULL, #stream_name},
 #define OP_S_SET_INJECT_DATAGRAM(f) \
     {OPK_S_SET_INJECT_DATAGRAM, NULL, 0, NULL, NULL, 0, NULL, NULL, (f)},
+#define OP_S_SHUTDOWN(error_code) \
+    {OPK_S_SHUTDOWN, NULL, (error_code)},
 
 static OSSL_TIME get_time(void *arg)
 {
@@ -1354,7 +1357,7 @@ static int run_script_worker(struct helper *h, const struct script_op *script,
 
                 args.quic_reason = (const char *)op->arg0;
 
-                ret = SSL_shutdown_ex(c_tgt, 0, &args, sizeof(args));
+                ret = SSL_shutdown_ex(c_tgt, op->arg1, &args, sizeof(args));
                 if (!TEST_int_ge(ret, 0))
                     goto out;
 
@@ -1363,6 +1366,12 @@ static int run_script_worker(struct helper *h, const struct script_op *script,
             }
             break;
 
+        case OPK_S_SHUTDOWN:
+            {
+                ossl_quic_tserver_shutdown(h->s, op->arg1);
+            }
+            break;
+
         case OPK_C_EXPECT_CONN_CLOSE_INFO:
             {
                 SSL_CONN_CLOSE_INFO cc_info = {0};
@@ -1970,7 +1979,7 @@ static const struct script_op script_10[] = {
     OP_S_BIND_STREAM_ID     (a, C_BIDI_ID(0))
     OP_S_READ_EXPECT        (a, "apple", 5)
 
-    OP_C_SHUTDOWN_WAIT      (NULL)
+    OP_C_SHUTDOWN_WAIT      (NULL, 0)
     OP_C_EXPECT_CONN_CLOSE_INFO(0, 1, 0)
     OP_S_EXPECT_CONN_CLOSE_INFO(0, 1, 1)
 
@@ -3062,7 +3071,7 @@ static const struct script_op script_40[] = {
     OP_END_REPEAT           ()
 
     OP_C_CONCLUDE           (a)
-    OP_C_SHUTDOWN_WAIT      (NULL) /* disengages tick inhibition */
+    OP_C_SHUTDOWN_WAIT      (NULL, 0) /* disengages tick inhibition */
 
     OP_S_BIND_STREAM_ID     (a, C_BIDI_ID(0))
     OP_S_READ_EXPECT        (a, "apple", 5)
@@ -3967,7 +3976,7 @@ static const struct script_op script_60[] = {
     OP_S_READ_EXPECT        (a, "apple", 5)
 
     OP_CHECK                (init_reason, 0)
-    OP_C_SHUTDOWN_WAIT      (long_reason)
+    OP_C_SHUTDOWN_WAIT      (long_reason, 0)
     OP_CHECK                (check_shutdown_reason, 0)
 
     OP_END
@@ -4535,6 +4544,37 @@ static const struct script_op script_75[] = {
     OP_END
 };
 
+/* 74. Test peer-initiated shutdown wait */
+static int script_76_check(struct helper *h, const struct script_op *op)
+{
+    if (!TEST_false(SSL_shutdown_ex(h->c_conn, SSL_SHUTDOWN_FLAG_WAIT_PEER,
+                                    NULL, 0)))
+        return 0;
+
+    return 1;
+}
+
+static const struct script_op script_76[] = {
+    OP_C_SET_ALPN           ("ossltest")
+    OP_C_CONNECT_WAIT       ()
+    OP_C_SET_DEFAULT_STREAM_MODE(SSL_DEFAULT_STREAM_MODE_NONE)
+
+    OP_C_NEW_STREAM_BIDI    (a, C_BIDI_ID(0))
+    OP_C_WRITE              (a, "apple", 5)
+
+    OP_S_BIND_STREAM_ID     (a, C_BIDI_ID(0))
+    OP_S_READ_EXPECT        (a, "apple", 5)
+
+    /* Check a WAIT_PEER call doesn't succeed yet. */
+    OP_CHECK                (script_76_check, 0)
+    OP_S_SHUTDOWN           (42)
+
+    OP_C_SHUTDOWN_WAIT      (NULL, SSL_SHUTDOWN_FLAG_WAIT_PEER)
+    OP_C_EXPECT_CONN_CLOSE_INFO(42, 1, 1)
+
+    OP_END
+};
+
 static const struct script_op *const scripts[] = {
     script_1,
     script_2,
@@ -4610,7 +4650,8 @@ static const struct script_op *const scripts[] = {
     script_72,
     script_73,
     script_74,
-    script_75
+    script_75,
+    script_76
 };
 
 static int test_script(int idx)
index c25128eaf6c3d12a3e1a6dc51dd4951b0becb09f..44d301313eb7c2eea98732e227be3aa4ebd22db9 100644 (file)
@@ -242,6 +242,9 @@ int main(int argc, char *argv[])
             }
         } while(streamid == UINT64_MAX);
 
+    while (!ossl_quic_tserver_shutdown(qtserv, 0))
+        wait_for_activity(qtserv);
+
         /* Read the request */
         do {
             if (first)