README.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. ngtcp2
  2. ======
  3. "Call it TCP/2. One More Time."
  4. ngtcp2 project is an effort to implement `RFC9000
  5. <https://datatracker.ietf.org/doc/html/rfc9000>`_ QUIC protocol.
  6. Documentation
  7. -------------
  8. `Online documentation <https://nghttp2.org/ngtcp2/>`_ is available.
  9. Public test server
  10. ------------------
  11. The following endpoints are available to try out ngtcp2
  12. implementation:
  13. - https://nghttp2.org:4433
  14. - https://nghttp2.org:4434 (requires address validation token)
  15. - https://nghttp2.org (powered by `nghttpx
  16. <https://nghttp2.org/documentation/nghttpx.1.html>`_)
  17. This endpoints sends Alt-Svc header field to clients if it is
  18. accessed via HTTP/1.1 or HTTP/2 to tell them that HTTP/3 is
  19. available at UDP 443.
  20. Requirements
  21. ------------
  22. The libngtcp2 C library itself does not depend on any external
  23. libraries. The example client, and server are written in C++20, and
  24. should compile with the modern C++ compilers (e.g., clang >= 11.0, or
  25. gcc >= 11.0).
  26. The following packages are required to configure the build system:
  27. - pkg-config >= 0.20
  28. - autoconf
  29. - automake
  30. - autotools-dev
  31. - libtool
  32. To build sources under the examples directory, libev and nghttp3 are
  33. required:
  34. - libev
  35. - `nghttp3 <https://github.com/ngtcp2/nghttp3>`_ for HTTP/3
  36. To enable `TLS Certificate Compression
  37. <https://datatracker.ietf.org/doc/html/rfc8879>`_ in bsslclient and
  38. bsslserver (BoringSSL (aws-lc) examples client and server), the
  39. following library is required:
  40. - libbrotli-dev >= 1.0.9
  41. ngtcp2 crypto helper library, and client and server under examples
  42. directory require at least one of the following TLS backends:
  43. - `quictls
  44. <https://github.com/quictls/openssl/tree/OpenSSL_1_1_1w+quic>`_
  45. - GnuTLS >= 3.7.5
  46. - BoringSSL (commit c361e279402ec359834b7eaa7d737462d02675e1);
  47. or aws-lc >= 1.39.0
  48. - Picotls (commit 402544bb65b35c3231a8912f25919de7e7922659)
  49. - wolfSSL >= 5.5.0
  50. - LibreSSL >= v3.9.2
  51. Before building from git
  52. ------------------------
  53. When build from git, run the following command to pull submodules:
  54. .. code-block:: shell
  55. $ git submodule update --init
  56. Build with wolfSSL
  57. ------------------
  58. .. code-block:: shell
  59. $ git clone --depth 1 -b v5.7.4-stable https://github.com/wolfSSL/wolfssl
  60. $ cd wolfssl
  61. $ autoreconf -i
  62. $ # For wolfSSL < v5.6.6, append --enable-quic.
  63. $ ./configure --prefix=$PWD/build \
  64. --enable-all --enable-aesni --enable-harden --enable-keylog-export \
  65. --disable-ech
  66. $ make -j$(nproc)
  67. $ make install
  68. $ cd ..
  69. $ git clone --recursive https://github.com/ngtcp2/nghttp3
  70. $ cd nghttp3
  71. $ autoreconf -i
  72. $ ./configure --prefix=$PWD/build --enable-lib-only
  73. $ make -j$(nproc) check
  74. $ make install
  75. $ cd ..
  76. $ git clone --recursive https://github.com/ngtcp2/ngtcp2
  77. $ cd ngtcp2
  78. $ autoreconf -i
  79. $ # For Mac users who have installed libev with MacPorts, append
  80. $ # LIBEV_CFLAGS="-I/opt/local/include" LIBEV_LIBS="-L/opt/local/lib -lev"
  81. $ ./configure PKG_CONFIG_PATH=$PWD/../wolfssl/build/lib/pkgconfig:$PWD/../nghttp3/build/lib/pkgconfig \
  82. --with-wolfssl
  83. $ make -j$(nproc) check
  84. Build with BoringSSL
  85. --------------------
  86. .. code-block:: shell
  87. $ git clone https://boringssl.googlesource.com/boringssl
  88. $ cd boringssl
  89. $ git checkout c361e279402ec359834b7eaa7d737462d02675e1
  90. $ cmake -B build -DCMAKE_POSITION_INDEPENDENT_CODE=ON
  91. $ make -j$(nproc) -C build
  92. $ cd ..
  93. $ git clone --recursive https://github.com/ngtcp2/nghttp3
  94. $ cd nghttp3
  95. $ autoreconf -i
  96. $ ./configure --prefix=$PWD/build --enable-lib-only
  97. $ make -j$(nproc) check
  98. $ make install
  99. $ cd ..
  100. $ git clone --recursive https://github.com/ngtcp2/ngtcp2
  101. $ cd ngtcp2
  102. $ autoreconf -i
  103. $ # For Mac users who have installed libev with MacPorts, append
  104. $ # LIBEV_CFLAGS="-I/opt/local/include" LIBEV_LIBS="-L/opt/local/lib -lev"
  105. $ ./configure PKG_CONFIG_PATH=$PWD/../nghttp3/build/lib/pkgconfig \
  106. BORINGSSL_LIBS="-L$PWD/../boringssl/build/ssl -lssl -L$PWD/../boringssl/build/crypto -lcrypto" \
  107. BORINGSSL_CFLAGS="-I$PWD/../boringssl/include" \
  108. --with-boringssl
  109. $ make -j$(nproc) check
  110. Build with aws-lc
  111. -----------------
  112. .. code-block:: shell
  113. $ git clone --depth 1 -b v1.41.1 https://github.com/aws/aws-lc
  114. $ cd aws-lc
  115. $ cmake -B build -DDISABLE_GO=ON
  116. $ make -j$(nproc) -C build
  117. $ cd ..
  118. $ git clone --recursive https://github.com/ngtcp2/nghttp3
  119. $ cd nghttp3
  120. $ autoreconf -i
  121. $ ./configure --prefix=$PWD/build --enable-lib-only
  122. $ make -j$(nproc) check
  123. $ make install
  124. $ cd ..
  125. $ git clone --recursive https://github.com/ngtcp2/ngtcp2
  126. $ cd ngtcp2
  127. $ autoreconf -i
  128. $ # For Mac users who have installed libev with MacPorts, append
  129. $ # LIBEV_CFLAGS="-I/opt/local/include" LIBEV_LIBS="-L/opt/local/lib -lev"
  130. $ ./configure PKG_CONFIG_PATH=$PWD/../nghttp3/build/lib/pkgconfig \
  131. BORINGSSL_CFLAGS="-I$PWD/../aws-lc/include" \
  132. BORINGSSL_LIBS="-L$PWD/../aws-lc/build/ssl -lssl -L$PWD/../aws-lc/build/crypto -lcrypto" \
  133. --with-boringssl
  134. $ make -j$(nproc) check
  135. Build with libressl
  136. -----------------
  137. .. code-block:: shell
  138. $ git clone --depth 1 -b v4.0.0 https://github.com/libressl/portable.git libressl
  139. $ cd libressl
  140. $ # Workaround autogen.sh failure
  141. $ export LIBRESSL_GIT_OPTIONS="-b libressl-v4.0.0"
  142. $ ./autogen.sh
  143. $ ./configure --prefix=$PWD/build
  144. $ make -j$(nproc) install
  145. $ cd ..
  146. $ git clone --recursive https://github.com/ngtcp2/nghttp3
  147. $ cd nghttp3
  148. $ autoreconf -i
  149. $ ./configure --prefix=$PWD/build --enable-lib-only
  150. $ make -j$(nproc) check
  151. $ make install
  152. $ cd ..
  153. $ git clone --recursive https://github.com/ngtcp2/ngtcp2
  154. $ cd ngtcp2
  155. $ autoreconf -i
  156. $ # For Mac users who have installed libev with MacPorts, append
  157. $ # LIBEV_CFLAGS="-I/opt/homebrew/Cellar/libev/4.33/include" LIBEV_LIBS="-L/opt/homebrew/Cellar/libev/4.33/lib -lev"
  158. $ ./configure PKG_CONFIG_PATH=$PWD/../nghttp3/build/lib/pkgconfig:$PWD/../libressl/build/lib/pkgconfig
  159. $ make -j$(nproc) check
  160. Client/Server
  161. -------------
  162. After successful build, the client and server executable should be
  163. found under examples directory. They talk HTTP/3.
  164. Client
  165. ~~~~~~
  166. .. code-block:: shell
  167. $ examples/wsslclient [OPTIONS] <HOST> <PORT> [<URI>...]
  168. The notable options are:
  169. - ``-d``, ``--data=<PATH>``: Read data from <PATH> and send it to a
  170. peer.
  171. Server
  172. ~~~~~~
  173. .. code-block:: shell
  174. $ examples/wsslserver [OPTIONS] <ADDR> <PORT> <PRIVATE_KEY_FILE> <CERTIFICATE_FILE>
  175. The notable options are:
  176. - ``-V``, ``--validate-addr``: Enforce stateless address validation.
  177. H09wsslclient/H09wsslserver
  178. ---------------------------
  179. There are h09wsslclient and h09wsslserver which speak HTTP/0.9. They
  180. are written just for `quic-interop-runner
  181. <https://github.com/marten-seemann/quic-interop-runner>`_. They share
  182. the basic functionalities with HTTP/3 client and server but have less
  183. functions (e.g., h09wsslclient does not have a capability to send
  184. request body, and h09wsslserver does not understand numeric request
  185. path, like /1000).
  186. Resumption and 0-RTT
  187. --------------------
  188. In order to resume a session, a session ticket, and a transport
  189. parameters must be fetched from server. First, run
  190. examples/wsslclient with --session-file, and --tp-file options which
  191. specify a path to session ticket, and transport parameter files
  192. respectively to save them locally.
  193. Once these files are available, run examples/wsslclient with the same
  194. arguments again. You will see that session is resumed in your log if
  195. resumption succeeds. Resuming session makes server's first Handshake
  196. packet pretty small because it does not send its certificates.
  197. To send 0-RTT data, after making sure that resumption works, use -d
  198. option to specify a file which contains data to send.
  199. Token (Not something included in Retry packet)
  200. ----------------------------------------------
  201. QUIC server might send a token to client after connection has been
  202. established. Client can send this token in subsequent connection to
  203. the server. Server verifies the token and if it succeeds, the address
  204. validation completes and lifts some restrictions on server which might
  205. speed up transfer. In order to save and/or load a token,
  206. use --token-file option of examples/wsslclient. The given file is
  207. overwritten if it already exists when storing a token.
  208. Crypto helper library
  209. ---------------------
  210. In order to make TLS stack integration less painful, we provide a
  211. crypto helper library which offers the basic crypto operations.
  212. The header file exists under crypto/includes/ngtcp2 directory.
  213. Each library file is built for a particular TLS backend. The
  214. available crypto helper libraries are:
  215. - libngtcp2_crypto_quictls: Use quictls and libressl as TLS backend
  216. - libngtcp2_crypto_gnutls: Use GnuTLS as TLS backend
  217. - libngtcp2_crypto_boringssl: Use BoringSSL and aws-lc as TLS backend
  218. - libngtcp2_crypto_picotls: Use Picotls as TLS backend
  219. - libngtcp2_crypto_wolfssl: Use wolfSSL as TLS backend
  220. Because BoringSSL and Picotls are an unversioned product, we only
  221. tested their particular revision. See Requirements section above.
  222. We use Picotls with OpenSSL as crypto backend.
  223. The examples directory contains client and server that are linked to
  224. those crypto helper libraries and TLS backends. They are only built
  225. if their corresponding crypto helper library is built:
  226. - qtlsclient: quictls(libressl) client
  227. - qtlsserver: quictls(libressl) server
  228. - gtlsclient: GnuTLS client
  229. - gtlsserver: GnuTLS server
  230. - bsslclient: BoringSSL(aws-lc) client
  231. - bsslserver: BoringSSL(aws-lc) server
  232. - ptlsclient: Picotls client
  233. - ptlsserver: Picotls server
  234. - wsslclient: wolfSSL client
  235. - wsslserver: wolfSSL server
  236. QUIC protocol extensions
  237. -------------------------
  238. The library implements the following QUIC protocol extensions:
  239. - `An Unreliable Datagram Extension to QUIC
  240. <https://datatracker.ietf.org/doc/html/rfc9221>`_
  241. - `Greasing the QUIC Bit
  242. <https://datatracker.ietf.org/doc/html/rfc9287>`_
  243. - `Compatible Version Negotiation for QUIC
  244. <https://datatracker.ietf.org/doc/html/rfc9368>`_
  245. - `QUIC Version 2
  246. <https://datatracker.ietf.org/doc/html/rfc9369>`_
  247. Configuring Wireshark for QUIC
  248. ------------------------------
  249. `Wireshark <https://www.wireshark.org/download.html>`_ can be configured to
  250. analyze QUIC traffic using the following steps:
  251. 1. Set *SSLKEYLOGFILE* environment variable:
  252. .. code-block:: shell
  253. $ export SSLKEYLOGFILE=quic_keylog_file
  254. 2. Set the port that QUIC uses
  255. Go to *Preferences->Protocols->QUIC* and set the port the program
  256. listens to. In the case of the example application this would be
  257. the port specified on the command line.
  258. 3. Set Pre-Master-Secret logfile
  259. Go to *Preferences->Protocols->TLS* and set the *Pre-Master-Secret
  260. log file* to the same value that was specified for *SSLKEYLOGFILE*.
  261. 4. Choose the correct network interface for capturing
  262. Make sure you choose the correct network interface for
  263. capturing. For example, if using localhost choose the *loopback*
  264. network interface on macos.
  265. 5. Create a filter
  266. Create A filter for the udp.port and set the port to the port the
  267. application is listening to. For example:
  268. .. code-block:: text
  269. udp.port == 7777
  270. License
  271. -------
  272. The MIT License
  273. Copyright (c) 2016 ngtcp2 contributors