]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add a test for receiving a post-handshake CertificateRequest
authorMatt Caswell <matt@openssl.org>
Mon, 7 Aug 2023 15:53:24 +0000 (16:53 +0100)
committerMatt Caswell <matt@openssl.org>
Tue, 15 Aug 2023 13:41:31 +0000 (14:41 +0100)
This should result in a QUIC PROTOCOL_VIOLATION

We also add tests for a post-handshake KeyUpdate, and a NewSessionTicket
with an invalid max_early_data value.

Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/21686)

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

index 90834b211c7f0a15cb08063964a776c1f15d5b02..45aea0abace93576c97335c03fceb8524f8e6d15 100644 (file)
@@ -204,6 +204,13 @@ QUIC_CHANNEL *ossl_quic_tserver_get_channel(QUIC_TSERVER *srv);
 /* Send a TLS new session ticket */
 int ossl_quic_tserver_new_ticket(QUIC_TSERVER *srv);
 
+/*
+ * Set the max_early_data value to be sent in NewSessionTickets. Only the
+ * values 0 and 0xffffffff are valid for use in QUIC.
+ */
+int ossl_quic_tserver_set_max_early_data(QUIC_TSERVER *srv,
+                                         uint32_t max_early_data);
+
 # endif
 
 #endif
index ae792c5e7af181ac7d63f574f4290399d8f1b17c..5401453dc59052dc60cdc273a1c3f3966529432e 100644 (file)
@@ -534,3 +534,9 @@ int ossl_quic_tserver_new_ticket(QUIC_TSERVER *srv)
 {
     return SSL_new_session_ticket(srv->tls);
 }
+
+int ossl_quic_tserver_set_max_early_data(QUIC_TSERVER *srv,
+                                         uint32_t max_early_data)
+{
+    return SSL_set_max_early_data(srv->tls, max_early_data);
+}
index a9de46230fc1bff88263255692c4e4d2a287da56..b37f7af00692ff45cafd22e4d7303369f894e799 100644 (file)
@@ -4181,6 +4181,150 @@ static const struct script_op script_67[] = {
     OP_END
 };
 
+/* 68. Fault injection - Unexpected TLS messages */
+static int script_68_inject_handshake(struct helper *h, unsigned char *msg,
+                                      size_t msglen)
+{
+    const unsigned char *data;
+    size_t datalen;
+    const unsigned char certreq[] = {
+        SSL3_MT_CERTIFICATE_REQUEST,         /* CertificateRequest message */
+        0, 0, 12,                            /* Length of message */
+        1, 1,                                /* certificate_request_context */
+        0, 8,                                /* Extensions block length */
+        0, TLSEXT_TYPE_signature_algorithms, /* sig_algs extension*/
+        0, 4,                                /* 4 bytes of sig algs extension*/
+        0, 2,                                /* sigalgs list is 2 bytes long */
+        8, 4                                 /* rsa_pss_rsae_sha256 */
+    };
+    const unsigned char keyupdate[] = {
+        SSL3_MT_KEY_UPDATE,                  /* KeyUpdate message */
+        0, 0, 1,                             /* Length of message */
+        SSL_KEY_UPDATE_NOT_REQUESTED         /* update_not_requested */
+    };
+
+    /* We transform the NewSessionTicket message into something else */
+    switch(h->inject_word0) {
+    case 0:
+        return 1;
+
+    case 1:
+        /* CertificateRequest message */
+        data = certreq;
+        datalen = sizeof(certreq);
+        break;
+
+    case 2:
+        /* KeyUpdate message */
+        data = keyupdate;
+        datalen = sizeof(keyupdate);
+        break;
+
+    default:
+        return 0;
+    }
+
+    if (!TEST_true(qtest_fault_resize_message(h->qtf,
+                                              datalen - SSL3_HM_HEADER_LENGTH)))
+        return 0;
+
+    memcpy(msg, data, datalen);
+
+    return 1;
+}
+
+/* Send a CerticateRequest message post-handshake */
+static const struct script_op script_68[] = {
+    OP_S_SET_INJECT_HANDSHAKE(script_68_inject_handshake)
+    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)
+
+    OP_SET_INJECT_WORD       (1, 0)
+    OP_S_NEW_TICKET          ()
+    OP_S_WRITE               (a, "orange", 6)
+
+    OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_PROTOCOL_VIOLATION, 0, 0)
+
+    OP_END
+};
+
+/* 69. Send a TLS KeyUpdate message post-handshake */
+static const struct script_op script_69[] = {
+    OP_S_SET_INJECT_HANDSHAKE(script_68_inject_handshake)
+    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)
+
+    OP_SET_INJECT_WORD       (2, 0)
+    OP_S_NEW_TICKET          ()
+    OP_S_WRITE               (a, "orange", 6)
+
+    OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_CRYPTO_ERR_BEGIN
+                                + SSL_AD_UNEXPECTED_MESSAGE, 0, 0)
+
+    OP_END
+};
+
+static int set_max_early_data(struct helper *h, const struct script_op *op)
+{
+
+    if (!TEST_true(ossl_quic_tserver_set_max_early_data(h->s,
+                                                        (uint32_t)op->arg2)))
+        return 0;
+
+    return 1;
+}
+
+/* 70. Send a TLS NewSessionTicket message with invalid max_early_data */
+static const struct script_op script_70[] = {
+    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)
+
+    OP_CHECK                 (set_max_early_data, 0xfffffffe)
+    OP_S_NEW_TICKET          ()
+    OP_S_WRITE               (a, "orange", 6)
+
+    OP_C_EXPECT_CONN_CLOSE_INFO(QUIC_ERR_PROTOCOL_VIOLATION, 0, 0)
+
+    OP_END
+};
+
+/* 71. Send a TLS NewSessionTicket message with valid max_early_data */
+static const struct script_op script_71[] = {
+    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)
+
+    OP_CHECK                 (set_max_early_data, 0xffffffff)
+    OP_S_NEW_TICKET          ()
+    OP_S_WRITE               (a, "orange", 6)
+    OP_C_READ_EXPECT         (a, "orange", 6)
+
+    OP_END
+};
+
 static const struct script_op *const scripts[] = {
     script_1,
     script_2,
@@ -4249,6 +4393,10 @@ static const struct script_op *const scripts[] = {
     script_65,
     script_66,
     script_67,
+    script_68,
+    script_69,
+    script_70,
+    script_71
 };
 
 static int test_script(int idx)