Skip to content

Commit 45aac10

Browse files
committedMay 24, 2023
Support trace for QUIC datagrams
Extend SSL_trace so that it knows how to dump information about the receipt of a QUIC datagram. Reviewed-by: Tomas Mraz <[email protected]> Reviewed-by: Hugo Landau <[email protected]> (Merged from #20914)
1 parent 63dfde8 commit 45aac10

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed
 

‎ssl/quic/build.info

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ SOURCE[$LIBSSL]=quic_channel.c
1313
SOURCE[$LIBSSL]=quic_tserver.c
1414
SOURCE[$LIBSSL]=quic_tls.c
1515
SOURCE[$LIBSSL]=quic_thread_assist.c
16+
SOURCE[$LIBSSL]=quic_trace.c

‎ssl/quic/quic_local.h

+3
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ void ossl_quic_conn_raise_protocol_error(QUIC_CONNECTION *qc,
218218
void ossl_quic_conn_on_remote_conn_close(QUIC_CONNECTION *qc,
219219
OSSL_QUIC_FRAME_CONN_CLOSE *f);
220220

221+
int ossl_quic_trace(int write_p, int version, int content_type,
222+
const void *buf, size_t msglen, SSL *ssl, void *arg);
223+
221224
# define OSSL_QUIC_ANY_VERSION 0xFFFFF
222225

223226
# define QUIC_CONNECTION_FROM_SSL_int(ssl, c) \

‎ssl/quic/quic_record_rx.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* https://www.openssl.org/source/license.html
88
*/
99

10+
#include <openssl/ssl.h>
1011
#include "internal/quic_record_rx.h"
1112
#include "quic_record_shared.h"
1213
#include "internal/common.h"
@@ -233,6 +234,10 @@ void ossl_qrx_inject_urxe(OSSL_QRX *qrx, QUIC_URXE *urxe)
233234
urxe->hpr_removed = 0;
234235
urxe->deferred = 0;
235236
ossl_list_urxe_insert_tail(&qrx->urx_pending, urxe);
237+
238+
if (qrx->msg_callback != NULL)
239+
qrx->msg_callback(0, OSSL_QUIC1_VERSION, SSL3_RT_QUIC_DATAGRAM, urxe + 1,
240+
urxe->data_len, qrx->msg_callback_s, qrx->msg_callback_arg);
236241
}
237242

238243
static void qrx_on_rx(QUIC_URXE *urxe, void *arg)
@@ -988,10 +993,6 @@ static int qrx_process_datagram(OSSL_QRX *qrx, QUIC_URXE *e,
988993
if (!PACKET_buf_init(&pkt, data, data_len))
989994
return 0;
990995

991-
if (qrx->msg_callback != NULL)
992-
qrx->msg_callback(0, OSSL_QUIC1_VERSION, SSL3_RT_QUIC_DATAGRAM, data,
993-
data_len, qrx->msg_callback_s, qrx->msg_callback_arg);
994-
995996
for (; PACKET_remaining(&pkt) > 0; ++pkt_idx) {
996997
/*
997998
* A packet smallest than the minimum possible QUIC packet size is not

‎ssl/quic/quic_trace.c

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2023 The OpenSSL Project Authors. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License 2.0 (the "License"). You may not use
5+
* this file except in compliance with the License. You can obtain a copy
6+
* in the file LICENSE in the source distribution or at
7+
* https://www.openssl.org/source/license.html
8+
*/
9+
10+
#include <openssl/bio.h>
11+
#include "../ssl_local.h"
12+
13+
int ossl_quic_trace(int write_p, int version, int content_type,
14+
const void *buf, size_t msglen, SSL *ssl, void *arg)
15+
{
16+
BIO *bio = arg;
17+
18+
switch (content_type) {
19+
case SSL3_RT_QUIC_DATAGRAM:
20+
BIO_puts(bio, write_p ? "Sent" : "Received");
21+
/*
22+
* Unfortunately there is no way of receiving auxilliary information
23+
* about the datagram through the msg_callback API such as the peer
24+
* address
25+
*/
26+
BIO_printf(bio, " Datagram\n Length: %zu\n", msglen);
27+
break;
28+
29+
default:
30+
/* Unrecognised content_type. We defer to SSL_trace */
31+
return 0;
32+
}
33+
34+
return 1;
35+
}

‎ssl/t1_trce.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,19 @@ void SSL_trace(int write_p, int version, int content_type,
17021702
const unsigned char *msg = buf;
17031703
BIO *bio = arg;
17041704
SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(ssl);
1705+
#ifndef OPENSSL_NO_QUIC
1706+
QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(ssl);
1707+
1708+
if (qc != NULL) {
1709+
if (ossl_quic_trace(write_p, version, content_type, buf, msglen, ssl,
1710+
arg))
1711+
return;
1712+
/*
1713+
* Otherwise ossl_quic_trace didn't handle this content_type so we
1714+
* fallback to standard TLS handling
1715+
*/
1716+
}
1717+
#endif
17051718

17061719
if (sc == NULL)
17071720
return;
@@ -1720,7 +1733,7 @@ void SSL_trace(int write_p, int version, int content_type,
17201733
}
17211734
hvers = msg[1] << 8 | msg[2];
17221735
BIO_puts(bio, write_p ? "Sent" : "Received");
1723-
BIO_printf(bio, " Record\nHeader:\n Version = %s (0x%x)\n",
1736+
BIO_printf(bio, " TLS Record\nHeader:\n Version = %s (0x%x)\n",
17241737
ssl_trace_str(hvers, ssl_version_tbl), hvers);
17251738
if (SSL_CONNECTION_IS_DTLS(sc)) {
17261739
BIO_printf(bio,

0 commit comments

Comments
 (0)
Please sign in to comment.