Ensure QUIC-TLS errors raised during channel start are available to caller
authorMatt Caswell <matt@openssl.org>
Mon, 11 Sep 2023 12:55:41 +0000 (13:55 +0100)
committerMatt Caswell <matt@openssl.org>
Wed, 13 Sep 2023 08:45:17 +0000 (09:45 +0100)
TLS misconfiguration errors should be shown to the application to enable
diagnosis of the problem. Otherwise you just get a generical "internal
error" message.

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

ssl/quic/quic_channel.c
ssl/quic/quic_impl.c

index ce938b70f06a647359032efee913ffa32eb4c632..7504f06dfc0c821cbf2d87875457e7380ba63f5b 100644 (file)
@@ -44,6 +44,7 @@
  */
 #define DEFAULT_MAX_ACK_DELAY   QUIC_DEFAULT_MAX_ACK_DELAY
 
+static void ch_save_err_state(QUIC_CHANNEL *ch);
 static void ch_rx_pre(QUIC_CHANNEL *ch);
 static int ch_rx(QUIC_CHANNEL *ch);
 static int ch_tx(QUIC_CHANNEL *ch);
@@ -2702,6 +2703,10 @@ int ossl_quic_channel_set_net_wbio(QUIC_CHANNEL *ch, BIO *net_wbio)
  */
 int ossl_quic_channel_start(QUIC_CHANNEL *ch)
 {
+    uint64_t error_code;
+    const char *error_msg;
+    ERR_STATE *error_state = NULL;
+
     if (ch->is_server)
         /*
          * This is not used by the server. The server moves to active
@@ -2730,8 +2735,14 @@ int ossl_quic_channel_start(QUIC_CHANNEL *ch)
     ch->doing_proactive_ver_neg = 0; /* not currently supported */
 
     /* Handshake layer: start (e.g. send CH). */
-    if (!ossl_quic_tls_tick(ch->qtls))
+    ossl_quic_tls_tick(ch->qtls);
+
+    if (ossl_quic_tls_get_error(ch->qtls, &error_code, &error_msg,
+                                &error_state)) {
+        ossl_quic_channel_raise_protocol_error_state(ch, error_code, 0,
+                                                     error_msg, error_state);
         return 0;
+    }
 
     ossl_quic_reactor_tick(&ch->rtor, 0); /* best effort */
     return 1;
index b632ad22db2f86e329415382c64b965285a459ce..beec26c019c1de475e8827bb37ac034adabac96d 100644 (file)
@@ -1524,6 +1524,7 @@ static int ensure_channel_started(QCTX *ctx)
         }
 
         if (!ossl_quic_channel_start(qc->ch)) {
+            ossl_quic_channel_restore_err_state(qc->ch);
             QUIC_RAISE_NON_NORMAL_ERROR(ctx, ERR_R_INTERNAL_ERROR,
                                         "failed to start channel");
             return 0;