QUIC: Enable building with QUIC support disabled

Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/19703)
This commit is contained in:
Hugo Landau 2022-11-17 16:03:00 +00:00
parent 44019a69c4
commit 6292519cd8
31 changed files with 289 additions and 143 deletions

View File

@ -223,6 +223,7 @@ static int put_value(unsigned char *data, uint64_t value, size_t len)
return 1;
}
#ifndef OPENSSL_NO_QUIC
static int put_quic_value(unsigned char *data, size_t value, size_t len)
{
if (data == NULL)
@ -235,6 +236,7 @@ static int put_quic_value(unsigned char *data, size_t value, size_t len)
ossl_quic_vlint_encode_n(data, value, len);
return 1;
}
#endif
/*
* Internal helper function used by WPACKET_close(), WPACKET_finish() and
@ -272,6 +274,7 @@ static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose)
unsigned char *buf = GETBUF(pkt);
if (buf != NULL) {
#ifndef OPENSSL_NO_QUIC
if ((sub->flags & WPACKET_FLAGS_QUIC_VLINT) == 0) {
if (!put_value(&buf[sub->packet_len], packlen, sub->lenbytes))
return 0;
@ -279,6 +282,10 @@ static int wpacket_intern_close(WPACKET *pkt, WPACKET_SUB *sub, int doclose)
if (!put_quic_value(&buf[sub->packet_len], packlen, sub->lenbytes))
return 0;
}
#else
if (!put_value(&buf[sub->packet_len], packlen, sub->lenbytes))
return 0;
#endif
}
} else if (pkt->endfirst && sub->parent != NULL
&& (packlen != 0
@ -524,6 +531,8 @@ void WPACKET_cleanup(WPACKET *pkt)
pkt->subs = NULL;
}
#ifndef OPENSSL_NO_QUIC
int WPACKET_start_quic_sub_packet_bound(WPACKET *pkt, size_t max_len)
{
size_t enclen = ossl_quic_vlint_encode_len(max_len);
@ -574,3 +583,5 @@ int WPACKET_quic_write_vlint(WPACKET *pkt, uint64_t v)
ossl_quic_vlint_encode(b, v);
return 1;
}
#endif

View File

@ -1,6 +1,8 @@
#include "internal/quic_vlint.h"
#include "internal/e_os.h"
#ifndef OPENSSL_NO_QUIC
void ossl_quic_vlint_encode_n(uint8_t *buf, uint64_t v, int n)
{
if (n == 1) {
@ -75,3 +77,5 @@ int ossl_quic_vlint_decode(const unsigned char *buf, size_t buf_len, uint64_t *v
*v = x;
return dec_len;
}
#endif

View File

@ -251,6 +251,8 @@ __owur static ossl_inline int PACKET_peek_net_8(const PACKET *pkt,
return 1;
}
# ifndef OPENSSL_NO_QUIC
/*
* Decodes a QUIC variable-length integer in |pkt| and stores the result in
* |data|.
@ -314,6 +316,8 @@ __owur static ossl_inline int PACKET_skip_quic_vlint(PACKET *pkt)
return 1;
}
# endif
/* Equivalent of n2l */
/* Get 4 bytes in network order from |pkt| and store the value in |*data| */
__owur static ossl_inline int PACKET_get_net_4(PACKET *pkt, unsigned long *data)
@ -691,6 +695,8 @@ __owur static ossl_inline int PACKET_get_length_prefixed_3(PACKET *pkt,
return 1;
}
# ifndef OPENSSL_NO_QUIC
/*
* Reads a variable-length vector prefixed with a QUIC variable-length integer
* denoting the length, and stores the contents in |subpkt|. |pkt| can equal
@ -718,6 +724,8 @@ __owur static ossl_inline int PACKET_get_quic_length_prefixed(PACKET *pkt,
return 1;
}
# endif
/* Writeable packets */
typedef struct wpacket_sub WPACKET_SUB;
@ -1027,6 +1035,8 @@ int WPACKET_is_null_buf(WPACKET *pkt);
/* Release resources in a WPACKET if a failure has occurred. */
void WPACKET_cleanup(WPACKET *pkt);
# ifndef OPENSSL_NO_QUIC
/*
* Starts a QUIC sub-packet headed by a QUIC variable-length integer. A 4-byte
* representation is used.
@ -1056,4 +1066,6 @@ __owur int WPACKET_quic_sub_allocate_bytes(WPACKET *pkt, size_t len,
*/
__owur int WPACKET_quic_write_vlint(WPACKET *pkt, uint64_t v);
# endif
#endif /* OSSL_INTERNAL_PACKET_H */

View File

@ -16,6 +16,8 @@
# include "internal/time.h"
# include "internal/list.h"
# ifndef OPENSSL_NO_QUIC
typedef struct ossl_ackm_st OSSL_ACKM;
OSSL_ACKM *ossl_ackm_new(OSSL_TIME (*now)(void *arg),
@ -232,3 +234,5 @@ int ossl_ackm_mark_packet_pseudo_lost(OSSL_ACKM *ackm,
OSSL_TIME ossl_ackm_get_pto_duration(OSSL_ACKM *ackm);
# endif
#endif

View File

@ -12,6 +12,8 @@
#include "openssl/params.h"
#include "internal/time.h"
# ifndef OPENSSL_NO_QUIC
typedef struct ossl_cc_data_st *OSSL_CC_DATA;
typedef struct ossl_cc_method_st {
@ -154,3 +156,5 @@ typedef struct ossl_cc_method_st {
extern const OSSL_CC_METHOD ossl_cc_dummy_method;
# endif
#endif

View File

@ -13,6 +13,8 @@
# include <openssl/ssl.h>
# include "internal/quic_types.h"
# ifndef OPENSSL_NO_QUIC
/*
* QUIC Control Frame Queue Item
* =============================
@ -139,3 +141,5 @@ QUIC_CFQ_ITEM *ossl_quic_cfq_item_get_priority_next(const QUIC_CFQ_ITEM *item,
uint32_t pn_space);
# endif
#endif

View File

@ -17,6 +17,8 @@
# include "internal/quic_statm.h"
# include "internal/time.h"
# ifndef OPENSSL_NO_QUIC
/*
* QUIC Channel
* ============
@ -157,3 +159,5 @@ int ossl_quic_channel_is_active(const QUIC_CHANNEL *ch);
int ossl_quic_channel_is_handshake_complete(const QUIC_CHANNEL *ch);
# endif
#endif

View File

@ -16,6 +16,8 @@
# include "internal/time.h"
# include "internal/list.h"
# ifndef OPENSSL_NO_QUIC
/*
* QUIC Demuxer
* ============
@ -274,3 +276,5 @@ int ossl_quic_demux_inject(QUIC_DEMUX *demux,
const BIO_ADDR *local);
# endif
#endif

View File

@ -13,6 +13,8 @@
# include <openssl/ssl.h>
# include "internal/quic_stream.h"
# ifndef OPENSSL_NO_QUIC
/*
* QUIC Dummy Handshake Module
* ===========================
@ -127,3 +129,5 @@ int ossl_quic_dhs_set_transport_params(QUIC_DHS *dhs,
size_t transport_params_len);
# endif
#endif

View File

@ -12,6 +12,8 @@
# include <openssl/ssl.h>
# ifndef OPENSSL_NO_QUIC
/* RFC 9000 Section 20.1 */
# define QUIC_ERR_NO_ERROR 0x00
# define QUIC_ERR_INTERNAL_ERROR 0x01
@ -36,3 +38,5 @@
# define QUUC_ERR_CRYPTO_ERR_END 0x01FF
# endif
#endif

View File

@ -13,6 +13,8 @@
# include <openssl/ssl.h>
# include "internal/time.h"
# ifndef OPENSSL_NO_QUIC
/*
* TX Flow Controller (TXFC)
* =========================
@ -252,3 +254,5 @@ int ossl_quic_rxfc_has_cwm_changed(QUIC_RXFC *rxfc, int clear);
int ossl_quic_rxfc_get_error(QUIC_RXFC *rxfc, int clear);
# endif
#endif

View File

@ -17,6 +17,8 @@
# include "internal/quic_txpim.h"
# include "internal/quic_stream.h"
# ifndef OPENSSL_NO_QUIC
/*
* QUIC Frame-in-Flight Dispatcher (FIFD)
* ======================================
@ -58,3 +60,5 @@ void ossl_quic_fifd_cleanup(QUIC_FIFD *fifd); /* (no-op) */
int ossl_quic_fifd_pkt_commit(QUIC_FIFD *fifd, QUIC_TXPIM_PKT *pkt);
# endif
#endif

View File

@ -13,6 +13,8 @@
# include "internal/sockets.h"
# include <openssl/bio.h>
# ifndef OPENSSL_NO_QUIC
/*
* Core I/O Reactor Framework
* ==========================
@ -65,8 +67,6 @@
* adaptation layer on top of our internal asynchronous I/O API as exposed by
* the reactor interface.
*/
# ifndef OPENSSL_NO_QUIC
typedef struct quic_tick_result_st {
char want_net_read;
char want_net_write;

View File

@ -16,6 +16,8 @@
# include "internal/quic_record_util.h"
# include "internal/quic_demux.h"
# ifndef OPENSSL_NO_QUIC
/*
* QUIC Record Layer - RX
* ======================
@ -533,3 +535,5 @@ uint64_t ossl_qrx_get_max_forged_pkt_count(OSSL_QRX *qrx,
uint32_t enc_level);
# endif
#endif

View File

@ -15,6 +15,8 @@
# include "internal/quic_types.h"
# include "internal/quic_record_util.h"
# ifndef OPENSSL_NO_QUIC
/*
* QUIC Record Layer - TX
* ======================
@ -323,3 +325,5 @@ uint64_t ossl_qtx_get_cur_epoch_pkt_count(OSSL_QTX *qtx, uint32_t enc_level);
uint64_t ossl_qtx_get_max_epoch_pkt_count(OSSL_QTX *qtx, uint32_t enc_level);
# endif
#endif

View File

@ -13,6 +13,8 @@
# include <openssl/ssl.h>
# include "internal/quic_types.h"
# ifndef OPENSSL_NO_QUIC
struct ossl_qrx_st;
struct ossl_qtx_st;
@ -110,3 +112,5 @@ uint64_t ossl_qrl_get_suite_max_pkt(uint32_t suite_id);
uint64_t ossl_qrl_get_suite_max_forged_pkt(uint32_t suite_id);
# endif
#endif

View File

@ -12,6 +12,10 @@
# include "internal/quic_channel.h"
# ifndef OPENSSL_NO_QUIC
int ossl_quic_handle_frames(QUIC_CHANNEL *qc, OSSL_QRX_PKT *qpacket);
# endif
#endif

View File

@ -35,6 +35,7 @@
* able to mark an empty frame.
* Invariant: The offset never points further than into the first frame.
*/
# ifndef OPENSSL_NO_QUIC
typedef struct stream_frame_st STREAM_FRAME;
@ -59,3 +60,5 @@ int ossl_sframe_list_peek(const SFRAME_LIST *fl, void **iter,
int ossl_sframe_list_drop_frames(SFRAME_LIST *fl, uint64_t limit);
# endif
#endif

View File

@ -15,6 +15,8 @@
# include "internal/quic_record_rx.h" /* OSSL_QRX */
# include "internal/quic_ackm.h" /* OSSL_ACKM */
# ifndef OPENSSL_NO_QUIC
__owur SSL *ossl_quic_new(SSL_CTX *ctx);
__owur int ossl_quic_init(SSL *s);
void ossl_quic_deinit(SSL *s);
@ -61,3 +63,5 @@ __owur int ossl_quic_conn_set_initial_peer_addr(QUIC_CONNECTION *qc,
const BIO_ADDR *peer_addr);
# endif
#endif

View File

@ -13,6 +13,8 @@
# include <openssl/ssl.h>
# include "internal/time.h"
# ifndef OPENSSL_NO_QUIC
typedef struct ossl_statm_st {
OSSL_TIME smoothed_rtt, latest_rtt, min_rtt, rtt_variance, max_ack_delay;
char have_first_sample;
@ -36,3 +38,5 @@ void ossl_statm_update_rtt(OSSL_STATM *statm,
void ossl_statm_set_max_ack_delay(OSSL_STATM *statm, OSSL_TIME max_ack_delay);
# endif
#endif

View File

@ -20,6 +20,8 @@
#include "internal/quic_fc.h"
#include "internal/quic_statm.h"
# ifndef OPENSSL_NO_QUIC
/*
* QUIC Send Stream
* ================
@ -344,3 +346,5 @@ int ossl_quic_rstream_peek(QUIC_RSTREAM *qrs, unsigned char *buf, size_t size,
int ossl_quic_rstream_available(QUIC_RSTREAM *qrs, size_t *avail, int *fin);
# endif
#endif

View File

@ -21,6 +21,8 @@
# include "internal/bio_addr.h"
# include "internal/time.h"
# ifndef OPENSSL_NO_QUIC
/*
* QUIC TX Packetiser
* ==================
@ -160,3 +162,5 @@ int ossl_quic_tx_packetiser_schedule_conn_close(OSSL_QUIC_TX_PACKETISER *txp,
const OSSL_QUIC_FRAME_CONN_CLOSE *f);
# endif
#endif

View File

@ -15,6 +15,8 @@
# include "internal/quic_cfq.h"
# include "internal/quic_ackm.h"
# ifndef OPENSSL_NO_QUIC
/*
* QUIC Transmitted Packet Information Manager
* ===========================================
@ -126,3 +128,5 @@ size_t ossl_quic_txpim_pkt_get_num_chunks(const QUIC_TXPIM_PKT *fpkt);
size_t ossl_quic_txpim_get_in_use(const QUIC_TXPIM *txpim);
# endif
#endif

View File

@ -14,6 +14,8 @@
# include <assert.h>
# include <string.h>
# ifndef OPENSSL_NO_QUIC
/* QUIC encryption levels. */
# define QUIC_ENC_LEVEL_INITIAL 0
# define QUIC_ENC_LEVEL_HANDSHAKE 1
@ -92,3 +94,5 @@ static ossl_unused ossl_inline int ossl_quic_conn_id_eq(const QUIC_CONN_ID *a,
# define QUIC_DEFAULT_IDLE_TIMEOUT 30000
# endif
#endif

View File

@ -13,6 +13,8 @@
# include "internal/e_os.h"
# ifndef OPENSSL_NO_QUIC
/* The smallest value requiring a 1, 2, 4, or 8-byte representation. */
#define OSSL_QUIC_VLINT_1B_MIN 0
#define OSSL_QUIC_VLINT_2B_MIN 64
@ -121,3 +123,5 @@ uint64_t ossl_quic_vlint_decode_unchecked(const unsigned char *buf);
int ossl_quic_vlint_decode(const unsigned char *buf, size_t buf_len, uint64_t *v);
# endif
#endif

View File

@ -16,6 +16,8 @@
# include "internal/quic_types.h"
# include "internal/packet.h"
# ifndef OPENSSL_NO_QUIC
# define OSSL_QUIC_FRAME_TYPE_PADDING 0x00
# define OSSL_QUIC_FRAME_TYPE_PING 0x01
# define OSSL_QUIC_FRAME_TYPE_ACK_WITHOUT_ECN 0x02
@ -753,3 +755,5 @@ int ossl_quic_wire_decode_transport_param_cid(PACKET *pkt,
QUIC_CONN_ID *cid);
# endif
#endif

View File

@ -14,6 +14,8 @@
# include "internal/packet.h"
# include "internal/quic_types.h"
# ifndef OPENSSL_NO_QUIC
# define QUIC_VERSION_NONE ((uint32_t)0) /* Used for version negotiation */
# define QUIC_VERSION_1 ((uint32_t)1) /* QUIC v1 */
@ -593,3 +595,5 @@ int ossl_quic_calculate_retry_integrity_tag(OSSL_LIB_CTX *libctx,
unsigned char *tag);
# endif
#endif

View File

@ -87,7 +87,7 @@ static int ch_init(QUIC_CHANNEL *ch)
QUIC_DHS_ARGS dhs_args = {0};
uint32_t pn_space;
// TODO CLIENT ONLY
/* TODO(QUIC): This is only applicable to clients. */
if (!gen_rand_conn_id(ch->libctx, INIT_DCID_LEN, &ch->init_dcid))
goto err;

View File

@ -2054,10 +2054,12 @@ int SSL_get_async_status(SSL *s, int *status)
int SSL_accept(SSL *s)
{
SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
#ifndef OPENSSL_NO_QUIC
QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(s);
if (qc != NULL)
return s->method->ssl_accept(s);
#endif
if (sc == NULL)
return 0;
@ -2073,10 +2075,12 @@ int SSL_accept(SSL *s)
int SSL_connect(SSL *s)
{
SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
#ifndef OPENSSL_NO_QUIC
QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(s);
if (qc != NULL)
return s->method->ssl_connect(s);
#endif
if (sc == NULL)
return 0;
@ -2177,10 +2181,12 @@ static int ssl_io_intern(void *vargs)
int ssl_read_internal(SSL *s, void *buf, size_t num, size_t *readbytes)
{
SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
#ifndef OPENSSL_NO_QUIC
QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(s);
if (qc != NULL)
return s->method->ssl_read(s, buf, num, readbytes);
#endif
if (sc == NULL)
return -1;
@ -2328,10 +2334,12 @@ int SSL_get_early_data_status(const SSL *s)
static int ssl_peek_internal(SSL *s, void *buf, size_t num, size_t *readbytes)
{
SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
#ifndef OPENSSL_NO_QUIC
QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(s);
if (qc != NULL)
return s->method->ssl_peek(s, buf, num, readbytes);
#endif
if (sc == NULL)
return 0;
@ -2397,10 +2405,12 @@ int SSL_peek_ex(SSL *s, void *buf, size_t num, size_t *readbytes)
int ssl_write_internal(SSL *s, const void *buf, size_t num, size_t *written)
{
SSL_CONNECTION *sc = SSL_CONNECTION_FROM_SSL(s);
#ifndef OPENSSL_NO_QUIC
QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_SSL(s);
if (qc != NULL)
return s->method->ssl_write(s, buf, num, written);
#endif
if (sc == NULL)
return 0;
@ -4642,10 +4652,12 @@ const char *ssl_protocol_to_string(int version)
const char *SSL_get_version(const SSL *s)
{
const SSL_CONNECTION *sc = SSL_CONNECTION_FROM_CONST_SSL(s);
#ifndef OPENSSL_NO_QUIC
const QUIC_CONNECTION *qc = QUIC_CONNECTION_FROM_CONST_SSL(s);
if (qc != NULL)
return "QUIC";
#endif
if (sc == NULL)
return NULL;

View File

@ -465,6 +465,8 @@ static int test_PACKET_as_length_prefixed_2(void)
return 1;
}
#ifndef OPENSSL_NO_QUIC
static int test_PACKET_get_quic_vlint(void)
{
struct quic_test_case {
@ -569,6 +571,8 @@ static int test_PACKET_get_quic_length_prefixed(void)
return 1;
}
#endif
int setup_tests(void)
{
unsigned int i;
@ -599,7 +603,9 @@ int setup_tests(void)
ADD_TEST(test_PACKET_get_length_prefixed_3);
ADD_TEST(test_PACKET_as_length_prefixed_1);
ADD_TEST(test_PACKET_as_length_prefixed_2);
#ifndef OPENSSL_NO_QUIC
ADD_TEST(test_PACKET_get_quic_vlint);
ADD_TEST(test_PACKET_get_quic_length_prefixed);
#endif
return 1;
}

View File

@ -26,6 +26,8 @@ static const unsigned char simpleder[] = {
0xfc, 0x04, 0x00, 0x01, 0x02, 0x03, 0xff, 0xfe, 0xfd
};
#ifndef OPENSSL_NO_QUIC
/* QUIC sub-packet with 4-byte length prefix, containing a 1-byte vlint */
static const unsigned char quic1[] = { 0x80, 0x00, 0x00, 0x01, 0x09 };
/* QUIC sub-packet with 1-byte length prefix, containing a 1-byte vlint */
@ -50,6 +52,8 @@ static const unsigned char quic7[] = {
0x40, 0x01, 0x11, 0x40, 0x01, 0x12, 0x40, 0x01, 0x13
};
#endif
static BUF_MEM *buf;
static int cleanup(WPACKET *pkt)
@ -448,6 +452,8 @@ static int test_WPACKET_init_der(void)
return 1;
}
#ifndef OPENSSL_NO_QUIC
static int test_WPACKET_quic(void)
{
WPACKET pkt;
@ -621,6 +627,8 @@ static int test_WPACKET_quic_vlint_random(void)
return 1;
}
#endif
int setup_tests(void)
{
if (!TEST_ptr(buf = BUF_MEM_new()))
@ -633,8 +641,10 @@ int setup_tests(void)
ADD_TEST(test_WPACKET_allocate_bytes);
ADD_TEST(test_WPACKET_memcpy);
ADD_TEST(test_WPACKET_init_der);
#ifndef OPENSSL_NO_QUIC
ADD_TEST(test_WPACKET_quic);
ADD_TEST(test_WPACKET_quic_vlint_random);
#endif
return 1;
}