Skip to content

Commit 8826acb

Browse files
committed
netutils: introduce QUIC support through ngtcp2 library
This commit is adding support for ngtcp2, a QUIC implementation following the RFC9000. In order to benefit from the existing wolfssl crypto backend, the library build process was adapted to include QUIC support when the ngtcp2 flag is enabled. Signed-off-by: Andrei Gorneanu <andreigorneanu@gmail.com>
1 parent af7222e commit 8826acb

7 files changed

Lines changed: 325 additions & 4 deletions

File tree

‎crypto/wolfssl/Makefile‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,14 @@ CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/wc_port.c
108108
CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/wolfevent.c
109109
CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/wolfmath.c
110110

111+
# QUIC support
112+
ifeq ($(CONFIG_NETUTILS_QUIC),y)
113+
114+
CSRCS += $(WOLFSSL_UNPACKNAME)/src/quic.c
115+
CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/evp.c
116+
117+
endif
118+
111119
CFLAGS += -DWOLFSSL_USER_SETTINGS
112120

113121
ifneq ($(CONFIG_WOLFCRYPT_APPS),)
@@ -154,11 +162,14 @@ endif
154162

155163
ifeq ($(CONFIG_WOLFSSL_APP_CLIENT_SERVER),y)
156164
wolfssl:
157-
git clone git@github.com:wolfSSL/wolfssl.git $(WOLFSSL_UNPACKNAME)
165+
git clone --depth 1 -b v$(WOLFSSL_VERSION)-stable git@github.com:wolfSSL/wolfssl.git $(WOLFSSL_UNPACKNAME)
158166
git clone git@github.com:wolfSSL/wolfssl-examples.git $(WOLFSSL_EXAMPLESNAME)
159167
else
160168
wolfssl:
161-
git clone git@github.com:wolfSSL/wolfssl.git $(WOLFSSL_UNPACKNAME)
169+
git clone --depth 1 -b v$(WOLFSSL_VERSION)-stable git@github.com:wolfSSL/wolfssl.git $(WOLFSSL_UNPACKNAME)
170+
ifeq ($(CONFIG_NETUTILS_QUIC),y)
171+
touch $(WOLFSSL_UNPACKNAME)/wolfssl/options.h
172+
endif
162173
endif
163174

164175
context:: wolfssl
@@ -168,7 +179,7 @@ distclean::
168179
$(call DELDIR, $(WOLFSSL_UNPACKNAME))
169180
$(call DELDIR, $(WOLFSSL_EXAMPLESNAME))
170181
else
171-
distclean:
182+
distclean::
172183
$(call DELDIR, $(WOLFSSL_UNPACKNAME))
173184
endif
174185

‎crypto/wolfssl/user_settings.h‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
* under the License.
2020
****************************************************************************/
2121

22+
//***************************************************************************
23+
// Included Files
24+
//***************************************************************************
25+
2226
#include <nuttx/config.h>
2327

2428
/* Library */
@@ -50,7 +54,8 @@
5054
#define WOLFSSL_BENCHMARK_FIXED_UNITS_MB
5155

5256
/* Development */
53-
/*#define DEBUG_WOLFSSL*/
57+
58+
/* #define DEBUG_WOLFSSL */
5459

5560
#define HAVE_TLS_EXTENSIONS
5661
#define HAVE_SUPPORTED_CURVES
@@ -72,3 +77,24 @@
7277
#define HAVE_CHACHA
7378
#define HAVE_ENCRYPT_THEN_MAC
7479
#define NO_OLD_TLS
80+
81+
#ifdef NETUTILS_QUIC
82+
#define OPENSSL_ALL
83+
#define OPENSSL_EXTRA
84+
#define WOLFSSL_QUIC
85+
#define WOLFSSL_OPTIONS_H
86+
87+
#define HAVE_ALPN
88+
#define HAVE_CURVE25519
89+
#define HAVE_LIMITS_H
90+
#define HAVE_SESSION_TICKET
91+
#define HAVE_SNI
92+
#define WOLFSSL_AES_COUNTER
93+
#define WOLFSSL_AES_DIRECT
94+
#define WOLFSSL_AES_128
95+
#define WOLFSSL_AES_256
96+
#define WOLFSSL_EARLY_DATA
97+
98+
#define NO_INT128
99+
#undef HAVE___UINT128_T
100+
#endif

‎netutils/ngtcp2/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/ngtcp2*

‎netutils/ngtcp2/CMakeLists.txt‎

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# ##############################################################################
2+
# apps/netutils/ngtcp2/CMakeLists.txt
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
7+
# license agreements. See the NOTICE file distributed with this work for
8+
# additional information regarding copyright ownership. The ASF licenses this
9+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
10+
# use this file except in compliance with the License. You may obtain a copy of
11+
# the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations under
19+
# the License.
20+
#
21+
# ##############################################################################
22+
23+
if(CONFIG_NETUTILS_QUIC)
24+
set(NGTCP2_DIR ${CMAKE_CURRENT_LIST_DIR}/ngtcp2)
25+
set(NGTCP2_VERSION ${CONFIG_NETUTILS_QUIC_VERSION})
26+
27+
if(NOT EXISTS ${NGTCP2_DIR})
28+
set(NGTCP2_URL https://github.com/ngtcp2/ngtcp2/releases/download)
29+
FetchContent_Declare(
30+
ngtcp2_fetch
31+
URL ${NGTCP2_URL}/v${NGTCP2_VERSION}/ngtcp2-${NGTCP2_VERSION}.tar.bz2
32+
SOURCE_DIR ${NGTCP2_DIR} BINARY_DIR
33+
${CMAKE_BINARY_DIR}/apps/netutils/ngtcp2
34+
DOWNLOAD_NO_PROGRESS true
35+
TIMEOUT 30)
36+
37+
FetchContent_GetProperties(ngtcp2_fetch)
38+
39+
if(NOT ngtcp2_fetch_POPULATED)
40+
FetchContent_Populate(ngtcp2_fetch)
41+
endif()
42+
endif()
43+
44+
set(NGTCP2_INCDIR
45+
${CMAKE_CURRENT_LIST_DIR}
46+
${NGTCP2_DIR}/lib
47+
${NGTCP2_DIR}/lib/includes
48+
${NGTCP2_DIR}/crypto
49+
${NGTCP2_DIR}/crypto/includes
50+
${NUTTX_APPS_DIR}/../nuttx/include
51+
${NUTTX_APPS_DIR}/crypto/wolfssl
52+
${NUTTX_APPS_DIR}/crypto/wolfssl/wolfssl
53+
${NUTTX_APPS_DIR}/crypto/wolfssl/openssl
54+
${NUTTX_APPS_DIR}/include)
55+
56+
set(NGTCP2_FLAGS
57+
-Wno-undef
58+
-DNO_INT128
59+
-DHAVE_WOLFSSL
60+
-DBUILDING_NGTCP2
61+
-DWOLFSSL_QUIC
62+
-DOPENSSL_EXTRA
63+
-DHAVE_AESGCM
64+
-DHAVE_SESSION_TICKET)
65+
66+
target_include_directories(apps PUBLIC ${NGTCP2_INCDIR})
67+
target_compile_options(apps PRIVATE ${NGTCP2_FLAGS})
68+
target_sources(
69+
apps
70+
PRIVATE ${NGTCP2_DIR}/lib/ngtcp2_pkt.c
71+
${NGTCP2_DIR}/lib/ngtcp2_conv.c
72+
${NGTCP2_DIR}/lib/ngtcp2_str.c
73+
${NGTCP2_DIR}/lib/ngtcp2_vec.c
74+
${NGTCP2_DIR}/lib/ngtcp2_buf.c
75+
${NGTCP2_DIR}/lib/ngtcp2_conn.c
76+
${NGTCP2_DIR}/lib/ngtcp2_mem.c
77+
${NGTCP2_DIR}/lib/ngtcp2_pq.c
78+
${NGTCP2_DIR}/lib/ngtcp2_map.c
79+
${NGTCP2_DIR}/lib/ngtcp2_rob.c
80+
${NGTCP2_DIR}/lib/ngtcp2_ppe.c
81+
${NGTCP2_DIR}/lib/ngtcp2_crypto.c
82+
${NGTCP2_DIR}/lib/ngtcp2_err.c
83+
${NGTCP2_DIR}/lib/ngtcp2_range.c
84+
${NGTCP2_DIR}/lib/ngtcp2_acktr.c
85+
${NGTCP2_DIR}/lib/ngtcp2_rtb.c
86+
${NGTCP2_DIR}/lib/ngtcp2_frame_chain.c
87+
${NGTCP2_DIR}/lib/ngtcp2_strm.c
88+
${NGTCP2_DIR}/lib/ngtcp2_idtr.c
89+
${NGTCP2_DIR}/lib/ngtcp2_gaptr.c
90+
${NGTCP2_DIR}/lib/ngtcp2_ringbuf.c
91+
${NGTCP2_DIR}/lib/ngtcp2_log.c
92+
${NGTCP2_DIR}/lib/ngtcp2_qlog.c
93+
${NGTCP2_DIR}/lib/ngtcp2_cid.c
94+
${NGTCP2_DIR}/lib/ngtcp2_ksl.c
95+
${NGTCP2_DIR}/lib/ngtcp2_cc.c
96+
${NGTCP2_DIR}/lib/ngtcp2_bbr.c
97+
${NGTCP2_DIR}/lib/ngtcp2_addr.c
98+
${NGTCP2_DIR}/lib/ngtcp2_path.c
99+
${NGTCP2_DIR}/lib/ngtcp2_pv.c
100+
${NGTCP2_DIR}/lib/ngtcp2_pmtud.c
101+
${NGTCP2_DIR}/lib/ngtcp2_version.c
102+
${NGTCP2_DIR}/lib/ngtcp2_rst.c
103+
${NGTCP2_DIR}/lib/ngtcp2_window_filter.c
104+
${NGTCP2_DIR}/lib/ngtcp2_opl.c
105+
${NGTCP2_DIR}/lib/ngtcp2_balloc.c
106+
${NGTCP2_DIR}/lib/ngtcp2_objalloc.c
107+
${NGTCP2_DIR}/lib/ngtcp2_unreachable.c
108+
${NGTCP2_DIR}/lib/ngtcp2_transport_params.c
109+
${NGTCP2_DIR}/lib/ngtcp2_settings.c
110+
${NGTCP2_DIR}/lib/ngtcp2_callbacks.c
111+
${NGTCP2_DIR}/lib/ngtcp2_dcidtr.c
112+
${NGTCP2_DIR}/lib/ngtcp2_pcg.c
113+
${NGTCP2_DIR}/lib/ngtcp2_ratelim.c
114+
${NGTCP2_DIR}/lib/ngtcp2_conn_info.c
115+
${NGTCP2_DIR}/crypto/shared.c
116+
${NGTCP2_DIR}/crypto/wolfssl/wolfssl.c)
117+
endif()

‎netutils/ngtcp2/Kconfig‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# For a description of the syntax of this configuration file,
3+
# see the file kconfig-language.txt in the NuttX tools repository.
4+
#
5+
6+
config NETUTILS_QUIC
7+
bool "QUIC - ngtcp2 library"
8+
default n
9+
depends on CRYPTO_WOLFSSL
10+
depends on LIBUV
11+
---help---
12+
ngtcp2 is a C implementation of QUIC protocol based on RFC9000.
13+
14+
if NETUTILS_QUIC
15+
16+
config NETUTILS_QUIC_VERSION
17+
string "QUIC - ngtcp2 version"
18+
default "1.21.0"
19+
20+
endif # NETUTILS_QUIC

‎netutils/ngtcp2/Make.defs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
############################################################################
2+
# apps/netutils/ngtcp2/Make.defs
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more
7+
# contributor license agreements. See the NOTICE file distributed with
8+
# this work for additional information regarding copyright ownership. The
9+
# ASF licenses this file to you under the Apache License, Version 2.0 (the
10+
# "License"); you may not use this file except in compliance with the
11+
# License. You may obtain a copy of the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations
19+
# under the License.
20+
#
21+
############################################################################
22+
23+
ifneq ($(CONFIG_NETUTILS_QUIC),)
24+
CONFIGURED_APPS += $(APPDIR)/netutils/ngtcp2
25+
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)$(DELIM)netutils$(DELIM)ngtcp2$(DELIM)ngtcp2$(DELIM)include
26+
endif

‎netutils/ngtcp2/Makefile‎

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# ##############################################################################
2+
# apps/netutils/ngtcp2/Makefile
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
7+
# license agreements. See the NOTICE file distributed with this work for
8+
# additional information regarding copyright ownership. The ASF licenses this
9+
# file to you under the Apache License, Version 2.0 (the "License"); you may not
10+
# use this file except in compliance with the License. You may obtain a copy of
11+
# the License at
12+
#
13+
# http://www.apache.org/licenses/LICENSE-2.0
14+
#
15+
# Unless required by applicable law or agreed to in writing, software
16+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
17+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
18+
# License for the specific language governing permissions and limitations under
19+
# the License.
20+
#
21+
# ##############################################################################
22+
23+
include $(APPDIR)/Make.defs
24+
25+
NGTCP2_UNPACKNAME = ngtcp2
26+
NGTCP2_VERSION = $(patsubst "%",%,$(strip $(CONFIG_NETUTILS_QUIC_VERSION)))
27+
28+
# ngtcp2 library
29+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_pkt.c
30+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_conv.c
31+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_str.c
32+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_vec.c
33+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_buf.c
34+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_conn.c
35+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_mem.c
36+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_pq.c
37+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_map.c
38+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_rob.c
39+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_ppe.c
40+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_crypto.c
41+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_err.c
42+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_range.c
43+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_acktr.c
44+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_rtb.c
45+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_frame_chain.c
46+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_strm.c
47+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_idtr.c
48+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_gaptr.c
49+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_ringbuf.c
50+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_log.c
51+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_qlog.c
52+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_cid.c
53+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_ksl.c
54+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_cc.c
55+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_bbr.c
56+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_addr.c
57+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_path.c
58+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_pv.c
59+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_pmtud.c
60+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_version.c
61+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_rst.c
62+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_window_filter.c
63+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_opl.c
64+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_balloc.c
65+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_objalloc.c
66+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_unreachable.c
67+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_transport_params.c
68+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_settings.c
69+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_callbacks.c
70+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_dcidtr.c
71+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_pcg.c
72+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_ratelim.c
73+
CSRCS += $(NGTCP2_UNPACKNAME)/lib/ngtcp2_conn_info.c
74+
75+
# ngtcp2 crypto layer
76+
CSRCS += $(NGTCP2_UNPACKNAME)/crypto/shared.c
77+
CSRCS += $(NGTCP2_UNPACKNAME)/crypto/wolfssl/wolfssl.c
78+
79+
# Compilation flags
80+
CFLAGS = -Wno-undef
81+
82+
# ngtcp2 specific includes
83+
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/netutils/ngtcp2
84+
CFLAGS += ${INCDIR_PREFIX}$(NGTCP2_UNPACKNAME)/lib
85+
CFLAGS += ${INCDIR_PREFIX}$(NGTCP2_UNPACKNAME)/lib/includes
86+
CFLAGS += ${INCDIR_PREFIX}$(NGTCP2_UNPACKNAME)/crypto
87+
CFLAGS += ${INCDIR_PREFIX}$(NGTCP2_UNPACKNAME)/crypto/includes
88+
89+
# NuttX specific includes
90+
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/../nuttx/include
91+
92+
# wolfssl specific includes
93+
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/wolfssl
94+
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/wolfssl/wolfssl
95+
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/wolfssl/openssl
96+
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/include
97+
98+
CFLAGS += -DNO_INT128 -DHAVE_WOLFSSL -DBUILDING_NGTCP2 -DWOLFSSL_QUIC -DOPENSSL_EXTRA -DHAVE_AESGCM -DHAVE_SESSION_TICKET
99+
100+
NGTCP2_URL ?= "https://github.com/ngtcp2/ngtcp2/releases/download"
101+
NGTCP2_TAR = ngtcp2-$(NGTCP2_VERSION).tar.bz2
102+
103+
UNPACK ?= tar -xf
104+
105+
$(NGTCP2_TAR):
106+
@echo "Downloading: $(NGTCP2_URL)/v$(NGTCP2_VERSION)/$(NGTCP2_TAR)"
107+
$(Q) curl -o $(NGTCP2_TAR) -L $(NGTCP2_URL)/v$(NGTCP2_VERSION)/$(NGTCP2_TAR)
108+
109+
$(NGTCP2_UNPACKNAME): $(NGTCP2_TAR)
110+
@echo "Unpacking: $(NGTCP2_TAR) -> $(NGTCP2_UNPACKNAME)"
111+
$(Q) $(UNPACK) $(NGTCP2_TAR)
112+
$(Q) mv ngtcp2-$(NGTCP2_VERSION) $(NGTCP2_UNPACKNAME)
113+
114+
distclean::
115+
$(call DELDIR, $(NGTCP2_UNPACKNAME))
116+
$(call DELFILE, $(NGTCP2_TAR))
117+
118+
context:: $(NGTCP2_UNPACKNAME)
119+
120+
include $(APPDIR)/Application.mk

0 commit comments

Comments
 (0)