Skip to content

Commit ac81beb

Browse files
goandreixiaoxiang781216
authored andcommitted
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. [skip-cmake-parity] - no CMake file implemented for wolfssl Signed-off-by: Andrei Gorneanu <andreigorneanu@gmail.com>
1 parent 5e0f069 commit ac81beb

7 files changed

Lines changed: 317 additions & 3 deletions

File tree

‎crypto/wolfssl/Makefile‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ 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_NGTCP2),y)
113+
114+
CFLAGS += -DNETUTILS_NGTCP2
115+
CSRCS += $(WOLFSSL_UNPACKNAME)/src/quic.c
116+
CSRCS += $(WOLFSSL_UNPACKNAME)/wolfcrypt/src/evp.c
117+
118+
endif
119+
111120
CFLAGS += -DWOLFSSL_USER_SETTINGS
112121

113122
ifneq ($(CONFIG_WOLFCRYPT_APPS),)
@@ -154,11 +163,14 @@ endif
154163

155164
ifeq ($(CONFIG_WOLFSSL_APP_CLIENT_SERVER),y)
156165
wolfssl:
157-
git clone git@github.com:wolfSSL/wolfssl.git $(WOLFSSL_UNPACKNAME)
166+
git clone --depth 1 -b v$(WOLFSSL_VERSION)-stable git@github.com:wolfSSL/wolfssl.git $(WOLFSSL_UNPACKNAME)
158167
git clone git@github.com:wolfSSL/wolfssl-examples.git $(WOLFSSL_EXAMPLESNAME)
159168
else
160169
wolfssl:
161-
git clone git@github.com:wolfSSL/wolfssl.git $(WOLFSSL_UNPACKNAME)
170+
git clone --depth 1 -b v$(WOLFSSL_VERSION)-stable git@github.com:wolfSSL/wolfssl.git $(WOLFSSL_UNPACKNAME)
171+
ifeq ($(CONFIG_NETUTILS_NGTCP2),y)
172+
touch $(WOLFSSL_UNPACKNAME)/wolfssl/options.h
173+
endif
162174
endif
163175

164176
context:: wolfssl

‎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_NGTCP2
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: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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_NGTCP2)
24+
set(NGTCP2_DIR ${CMAKE_CURRENT_LIST_DIR}/ngtcp2)
25+
set(NGTCP2_VERSION ${CONFIG_NETUTILS_NGTCP2_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}/crypto/wolfssl
51+
${NUTTX_APPS_DIR}/crypto/wolfssl/wolfssl
52+
${NUTTX_APPS_DIR}/crypto/wolfssl/openssl)
53+
54+
set(NGTCP2_FLAGS
55+
-Wno-undef
56+
-DNO_INT128
57+
-DHAVE_WOLFSSL
58+
-DBUILDING_NGTCP2
59+
-DWOLFSSL_QUIC
60+
-DOPENSSL_EXTRA
61+
-DHAVE_AESGCM
62+
-DHAVE_SESSION_TICKET)
63+
64+
target_include_directories(apps PUBLIC ${NGTCP2_INCDIR})
65+
target_compile_options(apps PRIVATE ${NGTCP2_FLAGS})
66+
target_sources(
67+
apps
68+
PRIVATE ${NGTCP2_DIR}/lib/ngtcp2_pkt.c
69+
${NGTCP2_DIR}/lib/ngtcp2_conv.c
70+
${NGTCP2_DIR}/lib/ngtcp2_str.c
71+
${NGTCP2_DIR}/lib/ngtcp2_vec.c
72+
${NGTCP2_DIR}/lib/ngtcp2_buf.c
73+
${NGTCP2_DIR}/lib/ngtcp2_conn.c
74+
${NGTCP2_DIR}/lib/ngtcp2_mem.c
75+
${NGTCP2_DIR}/lib/ngtcp2_pq.c
76+
${NGTCP2_DIR}/lib/ngtcp2_map.c
77+
${NGTCP2_DIR}/lib/ngtcp2_rob.c
78+
${NGTCP2_DIR}/lib/ngtcp2_ppe.c
79+
${NGTCP2_DIR}/lib/ngtcp2_crypto.c
80+
${NGTCP2_DIR}/lib/ngtcp2_err.c
81+
${NGTCP2_DIR}/lib/ngtcp2_range.c
82+
${NGTCP2_DIR}/lib/ngtcp2_acktr.c
83+
${NGTCP2_DIR}/lib/ngtcp2_rtb.c
84+
${NGTCP2_DIR}/lib/ngtcp2_frame_chain.c
85+
${NGTCP2_DIR}/lib/ngtcp2_strm.c
86+
${NGTCP2_DIR}/lib/ngtcp2_idtr.c
87+
${NGTCP2_DIR}/lib/ngtcp2_gaptr.c
88+
${NGTCP2_DIR}/lib/ngtcp2_ringbuf.c
89+
${NGTCP2_DIR}/lib/ngtcp2_log.c
90+
${NGTCP2_DIR}/lib/ngtcp2_qlog.c
91+
${NGTCP2_DIR}/lib/ngtcp2_cid.c
92+
${NGTCP2_DIR}/lib/ngtcp2_ksl.c
93+
${NGTCP2_DIR}/lib/ngtcp2_cc.c
94+
${NGTCP2_DIR}/lib/ngtcp2_bbr.c
95+
${NGTCP2_DIR}/lib/ngtcp2_addr.c
96+
${NGTCP2_DIR}/lib/ngtcp2_path.c
97+
${NGTCP2_DIR}/lib/ngtcp2_pv.c
98+
${NGTCP2_DIR}/lib/ngtcp2_pmtud.c
99+
${NGTCP2_DIR}/lib/ngtcp2_version.c
100+
${NGTCP2_DIR}/lib/ngtcp2_rst.c
101+
${NGTCP2_DIR}/lib/ngtcp2_window_filter.c
102+
${NGTCP2_DIR}/lib/ngtcp2_opl.c
103+
${NGTCP2_DIR}/lib/ngtcp2_balloc.c
104+
${NGTCP2_DIR}/lib/ngtcp2_objalloc.c
105+
${NGTCP2_DIR}/lib/ngtcp2_unreachable.c
106+
${NGTCP2_DIR}/lib/ngtcp2_transport_params.c
107+
${NGTCP2_DIR}/lib/ngtcp2_settings.c
108+
${NGTCP2_DIR}/lib/ngtcp2_callbacks.c
109+
${NGTCP2_DIR}/lib/ngtcp2_dcidtr.c
110+
${NGTCP2_DIR}/lib/ngtcp2_pcg.c
111+
${NGTCP2_DIR}/lib/ngtcp2_ratelim.c
112+
${NGTCP2_DIR}/lib/ngtcp2_conn_info.c
113+
${NGTCP2_DIR}/crypto/shared.c
114+
${NGTCP2_DIR}/crypto/wolfssl/wolfssl.c)
115+
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_NGTCP2
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_NGTCP2
15+
16+
config NETUTILS_NGTCP2_VERSION
17+
string "QUIC - ngtcp2 version"
18+
default "1.21.0"
19+
20+
endif # NETUTILS_NGTCP2

‎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_NGTCP2),)
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: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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_NGTCP2_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+
# ngtcp2 specific includes
80+
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/netutils/ngtcp2
81+
CFLAGS += ${INCDIR_PREFIX}$(NGTCP2_UNPACKNAME)/lib
82+
CFLAGS += ${INCDIR_PREFIX}$(NGTCP2_UNPACKNAME)/lib/includes
83+
CFLAGS += ${INCDIR_PREFIX}$(NGTCP2_UNPACKNAME)/crypto
84+
CFLAGS += ${INCDIR_PREFIX}$(NGTCP2_UNPACKNAME)/crypto/includes
85+
86+
# wolfssl specific includes
87+
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/wolfssl
88+
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/wolfssl/wolfssl
89+
CFLAGS += ${INCDIR_PREFIX}$(APPDIR)/crypto/wolfssl/openssl
90+
91+
CFLAGS += -Wno-undef
92+
CFLAGS += -DNO_INT128 -DHAVE_WOLFSSL -DBUILDING_NGTCP2 -DWOLFSSL_QUIC -DOPENSSL_EXTRA -DHAVE_AESGCM -DHAVE_SESSION_TICKET
93+
94+
NGTCP2_URL ?= "https://github.com/ngtcp2/ngtcp2/releases/download"
95+
NGTCP2_TAR = ngtcp2-$(NGTCP2_VERSION).tar.bz2
96+
97+
UNPACK ?= tar -xf
98+
99+
$(NGTCP2_TAR):
100+
@echo "Downloading: $(NGTCP2_URL)/v$(NGTCP2_VERSION)/$(NGTCP2_TAR)"
101+
$(Q) curl -o $(NGTCP2_TAR) -L $(NGTCP2_URL)/v$(NGTCP2_VERSION)/$(NGTCP2_TAR)
102+
103+
$(NGTCP2_UNPACKNAME): $(NGTCP2_TAR)
104+
@echo "Unpacking: $(NGTCP2_TAR) -> $(NGTCP2_UNPACKNAME)"
105+
$(Q) $(UNPACK) $(NGTCP2_TAR)
106+
$(Q) mv ngtcp2-$(NGTCP2_VERSION) $(NGTCP2_UNPACKNAME)
107+
108+
distclean::
109+
$(call DELDIR, $(NGTCP2_UNPACKNAME))
110+
$(call DELFILE, $(NGTCP2_TAR))
111+
112+
context:: $(NGTCP2_UNPACKNAME)
113+
114+
include $(APPDIR)/Application.mk

0 commit comments

Comments
 (0)