protocol-quic 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data/ext/ngtcp2/AUTHORS +44 -0
- data/ext/ngtcp2/CMakeLists.txt +431 -0
- data/ext/ngtcp2/CMakeOptions.txt +17 -0
- data/ext/ngtcp2/COPYING +22 -0
- data/ext/ngtcp2/ChangeLog +0 -0
- data/ext/ngtcp2/Makefile.am +60 -0
- data/ext/ngtcp2/NEWS +0 -0
- data/ext/ngtcp2/README +1 -0
- data/ext/ngtcp2/README.rst +258 -0
- data/ext/ngtcp2/ci/build_boringssl.sh +10 -0
- data/ext/ngtcp2/ci/build_nghttp3.sh +9 -0
- data/ext/ngtcp2/ci/build_openssl1.sh +8 -0
- data/ext/ngtcp2/ci/build_openssl1_cross.sh +9 -0
- data/ext/ngtcp2/ci/build_openssl3.sh +8 -0
- data/ext/ngtcp2/ci/build_picotls.sh +26 -0
- data/ext/ngtcp2/ci/build_wolfssl.sh +9 -0
- data/ext/ngtcp2/ci/gen-certificate.sh +8 -0
- data/ext/ngtcp2/cmake/ExtractValidFlags.cmake +31 -0
- data/ext/ngtcp2/cmake/FindCUnit.cmake +40 -0
- data/ext/ngtcp2/cmake/FindJemalloc.cmake +40 -0
- data/ext/ngtcp2/cmake/FindLibev.cmake +38 -0
- data/ext/ngtcp2/cmake/FindLibnghttp3.cmake +41 -0
- data/ext/ngtcp2/cmake/Findwolfssl.cmake +41 -0
- data/ext/ngtcp2/cmake/Version.cmake +11 -0
- data/ext/ngtcp2/cmakeconfig.h.in +36 -0
- data/ext/ngtcp2/configure.ac +755 -0
- data/ext/ngtcp2/crypto/CMakeLists.txt +56 -0
- data/ext/ngtcp2/crypto/Makefile.am +49 -0
- data/ext/ngtcp2/crypto/boringssl/CMakeLists.txt +64 -0
- data/ext/ngtcp2/crypto/boringssl/Makefile.am +39 -0
- data/ext/ngtcp2/crypto/boringssl/boringssl.c +630 -0
- data/ext/ngtcp2/crypto/boringssl/libngtcp2_crypto_boringssl.pc.in +33 -0
- data/ext/ngtcp2/crypto/gnutls/CMakeLists.txt +86 -0
- data/ext/ngtcp2/crypto/gnutls/Makefile.am +43 -0
- data/ext/ngtcp2/crypto/gnutls/gnutls.c +644 -0
- data/ext/ngtcp2/crypto/gnutls/libngtcp2_crypto_gnutls.pc.in +33 -0
- data/ext/ngtcp2/crypto/includes/CMakeLists.txt +56 -0
- data/ext/ngtcp2/crypto/includes/Makefile.am +45 -0
- data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto.h +893 -0
- data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_boringssl.h +104 -0
- data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_gnutls.h +107 -0
- data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h +132 -0
- data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_picotls.h +246 -0
- data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_wolfssl.h +106 -0
- data/ext/ngtcp2/crypto/openssl/CMakeLists.txt +86 -0
- data/ext/ngtcp2/crypto/openssl/Makefile.am +43 -0
- data/ext/ngtcp2/crypto/openssl/libngtcp2_crypto_openssl.pc.in +33 -0
- data/ext/ngtcp2/crypto/openssl/openssl.c +807 -0
- data/ext/ngtcp2/crypto/picotls/CMakeLists.txt +65 -0
- data/ext/ngtcp2/crypto/picotls/Makefile.am +39 -0
- data/ext/ngtcp2/crypto/picotls/libngtcp2_crypto_picotls.pc.in +33 -0
- data/ext/ngtcp2/crypto/picotls/picotls.c +707 -0
- data/ext/ngtcp2/crypto/shared.c +1431 -0
- data/ext/ngtcp2/crypto/shared.h +350 -0
- data/ext/ngtcp2/crypto/wolfssl/CMakeLists.txt +84 -0
- data/ext/ngtcp2/crypto/wolfssl/Makefile.am +43 -0
- data/ext/ngtcp2/crypto/wolfssl/libngtcp2_crypto_wolfssl.pc.in +33 -0
- data/ext/ngtcp2/crypto/wolfssl/wolfssl.c +534 -0
- data/ext/ngtcp2/doc/Makefile.am +65 -0
- data/ext/ngtcp2/doc/make.bat +35 -0
- data/ext/ngtcp2/doc/mkapiref.py +356 -0
- data/ext/ngtcp2/doc/source/conf.py.in +94 -0
- data/ext/ngtcp2/doc/source/index.rst +22 -0
- data/ext/ngtcp2/doc/source/programmers-guide.rst +476 -0
- data/ext/ngtcp2/docker/Dockerfile +39 -0
- data/ext/ngtcp2/examples/CMakeLists.txt +361 -0
- data/ext/ngtcp2/examples/Makefile.am +228 -0
- data/ext/ngtcp2/examples/client.cc +3049 -0
- data/ext/ngtcp2/examples/client.h +192 -0
- data/ext/ngtcp2/examples/client_base.cc +202 -0
- data/ext/ngtcp2/examples/client_base.h +213 -0
- data/ext/ngtcp2/examples/debug.cc +298 -0
- data/ext/ngtcp2/examples/debug.h +124 -0
- data/ext/ngtcp2/examples/examplestest.cc +84 -0
- data/ext/ngtcp2/examples/gtlssimpleclient.c +720 -0
- data/ext/ngtcp2/examples/h09client.cc +2601 -0
- data/ext/ngtcp2/examples/h09client.h +196 -0
- data/ext/ngtcp2/examples/h09server.cc +3024 -0
- data/ext/ngtcp2/examples/h09server.h +237 -0
- data/ext/ngtcp2/examples/http.cc +138 -0
- data/ext/ngtcp2/examples/http.h +44 -0
- data/ext/ngtcp2/examples/network.h +80 -0
- data/ext/ngtcp2/examples/server.cc +3731 -0
- data/ext/ngtcp2/examples/server.h +256 -0
- data/ext/ngtcp2/examples/server_base.cc +58 -0
- data/ext/ngtcp2/examples/server_base.h +195 -0
- data/ext/ngtcp2/examples/shared.cc +385 -0
- data/ext/ngtcp2/examples/shared.h +96 -0
- data/ext/ngtcp2/examples/simpleclient.c +683 -0
- data/ext/ngtcp2/examples/template.h +71 -0
- data/ext/ngtcp2/examples/tests/README.rst +60 -0
- data/ext/ngtcp2/examples/tests/__init__.py +0 -0
- data/ext/ngtcp2/examples/tests/config.ini.in +32 -0
- data/ext/ngtcp2/examples/tests/conftest.py +28 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/__init__.py +6 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/certs.py +476 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/client.py +187 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/env.py +191 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/log.py +101 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/server.py +137 -0
- data/ext/ngtcp2/examples/tests/ngtcp2test/tls.py +983 -0
- data/ext/ngtcp2/examples/tests/test_01_handshake.py +30 -0
- data/ext/ngtcp2/examples/tests/test_02_resume.py +46 -0
- data/ext/ngtcp2/examples/tests/test_03_earlydata.py +56 -0
- data/ext/ngtcp2/examples/tests/test_04_clientcert.py +57 -0
- data/ext/ngtcp2/examples/tests/test_05_ciphers.py +46 -0
- data/ext/ngtcp2/examples/tls_client_context.h +52 -0
- data/ext/ngtcp2/examples/tls_client_context_boringssl.cc +126 -0
- data/ext/ngtcp2/examples/tls_client_context_boringssl.h +49 -0
- data/ext/ngtcp2/examples/tls_client_context_gnutls.cc +74 -0
- data/ext/ngtcp2/examples/tls_client_context_gnutls.h +50 -0
- data/ext/ngtcp2/examples/tls_client_context_openssl.cc +137 -0
- data/ext/ngtcp2/examples/tls_client_context_openssl.h +49 -0
- data/ext/ngtcp2/examples/tls_client_context_picotls.cc +158 -0
- data/ext/ngtcp2/examples/tls_client_context_picotls.h +53 -0
- data/ext/ngtcp2/examples/tls_client_context_wolfssl.cc +177 -0
- data/ext/ngtcp2/examples/tls_client_context_wolfssl.h +51 -0
- data/ext/ngtcp2/examples/tls_client_session.h +52 -0
- data/ext/ngtcp2/examples/tls_client_session_boringssl.cc +110 -0
- data/ext/ngtcp2/examples/tls_client_session_boringssl.h +52 -0
- data/ext/ngtcp2/examples/tls_client_session_gnutls.cc +190 -0
- data/ext/ngtcp2/examples/tls_client_session_gnutls.h +52 -0
- data/ext/ngtcp2/examples/tls_client_session_openssl.cc +113 -0
- data/ext/ngtcp2/examples/tls_client_session_openssl.h +52 -0
- data/ext/ngtcp2/examples/tls_client_session_picotls.cc +147 -0
- data/ext/ngtcp2/examples/tls_client_session_picotls.h +52 -0
- data/ext/ngtcp2/examples/tls_client_session_wolfssl.cc +160 -0
- data/ext/ngtcp2/examples/tls_client_session_wolfssl.h +52 -0
- data/ext/ngtcp2/examples/tls_server_context.h +52 -0
- data/ext/ngtcp2/examples/tls_server_context_boringssl.cc +257 -0
- data/ext/ngtcp2/examples/tls_server_context_boringssl.h +54 -0
- data/ext/ngtcp2/examples/tls_server_context_gnutls.cc +99 -0
- data/ext/ngtcp2/examples/tls_server_context_gnutls.h +59 -0
- data/ext/ngtcp2/examples/tls_server_context_openssl.cc +338 -0
- data/ext/ngtcp2/examples/tls_server_context_openssl.h +54 -0
- data/ext/ngtcp2/examples/tls_server_context_picotls.cc +321 -0
- data/ext/ngtcp2/examples/tls_server_context_picotls.h +58 -0
- data/ext/ngtcp2/examples/tls_server_context_wolfssl.cc +284 -0
- data/ext/ngtcp2/examples/tls_server_context_wolfssl.h +55 -0
- data/ext/ngtcp2/examples/tls_server_session.h +52 -0
- data/ext/ngtcp2/examples/tls_server_session_boringssl.cc +84 -0
- data/ext/ngtcp2/examples/tls_server_session_boringssl.h +47 -0
- data/ext/ngtcp2/examples/tls_server_session_gnutls.cc +155 -0
- data/ext/ngtcp2/examples/tls_server_session_gnutls.h +46 -0
- data/ext/ngtcp2/examples/tls_server_session_openssl.cc +54 -0
- data/ext/ngtcp2/examples/tls_server_session_openssl.h +47 -0
- data/ext/ngtcp2/examples/tls_server_session_picotls.cc +70 -0
- data/ext/ngtcp2/examples/tls_server_session_picotls.h +47 -0
- data/ext/ngtcp2/examples/tls_server_session_wolfssl.cc +55 -0
- data/ext/ngtcp2/examples/tls_server_session_wolfssl.h +47 -0
- data/ext/ngtcp2/examples/tls_session_base_gnutls.cc +87 -0
- data/ext/ngtcp2/examples/tls_session_base_gnutls.h +51 -0
- data/ext/ngtcp2/examples/tls_session_base_openssl.cc +54 -0
- data/ext/ngtcp2/examples/tls_session_base_openssl.h +52 -0
- data/ext/ngtcp2/examples/tls_session_base_picotls.cc +56 -0
- data/ext/ngtcp2/examples/tls_session_base_picotls.h +54 -0
- data/ext/ngtcp2/examples/tls_session_base_wolfssl.cc +54 -0
- data/ext/ngtcp2/examples/tls_session_base_wolfssl.h +54 -0
- data/ext/ngtcp2/examples/tls_shared_picotls.cc +59 -0
- data/ext/ngtcp2/examples/tls_shared_picotls.h +36 -0
- data/ext/ngtcp2/examples/util.cc +646 -0
- data/ext/ngtcp2/examples/util.h +361 -0
- data/ext/ngtcp2/examples/util_gnutls.cc +136 -0
- data/ext/ngtcp2/examples/util_openssl.cc +131 -0
- data/ext/ngtcp2/examples/util_test.cc +237 -0
- data/ext/ngtcp2/examples/util_test.h +45 -0
- data/ext/ngtcp2/examples/util_wolfssl.cc +130 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/ack +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/ack_ecn +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/connection_close +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/crypto +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/data_blocked +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/datagram +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/datagram_len +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/max_data +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/max_stream_data +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/max_streams +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/new_connection_id +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/new_token +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/path_challenge +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/path_response +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/reset_stream +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/retire_connection_id +1 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/stop_sending +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/stream +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/stream_data_blocked +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/stream_len +0 -0
- data/ext/ngtcp2/fuzz/corpus/decode_frame/streams_blocked +0 -0
- data/ext/ngtcp2/fuzz/corpus/ksl/random +0 -0
- data/ext/ngtcp2/fuzz/decode_frame.cc +25 -0
- data/ext/ngtcp2/fuzz/ksl.cc +77 -0
- data/ext/ngtcp2/interop/Dockerfile +39 -0
- data/ext/ngtcp2/interop/run_endpoint.sh +93 -0
- data/ext/ngtcp2/lib/CMakeLists.txt +110 -0
- data/ext/ngtcp2/lib/Makefile.am +122 -0
- data/ext/ngtcp2/lib/includes/CMakeLists.txt +4 -0
- data/ext/ngtcp2/lib/includes/Makefile.am +25 -0
- data/ext/ngtcp2/lib/includes/ngtcp2/ngtcp2.h +5843 -0
- data/ext/ngtcp2/lib/includes/ngtcp2/version.h.in +51 -0
- data/ext/ngtcp2/lib/libngtcp2.pc.in +33 -0
- data/ext/ngtcp2/lib/ngtcp2_acktr.c +335 -0
- data/ext/ngtcp2/lib/ngtcp2_acktr.h +221 -0
- data/ext/ngtcp2/lib/ngtcp2_addr.c +117 -0
- data/ext/ngtcp2/lib/ngtcp2_addr.h +69 -0
- data/ext/ngtcp2/lib/ngtcp2_balloc.c +90 -0
- data/ext/ngtcp2/lib/ngtcp2_balloc.h +91 -0
- data/ext/ngtcp2/lib/ngtcp2_bbr.c +693 -0
- data/ext/ngtcp2/lib/ngtcp2_bbr.h +157 -0
- data/ext/ngtcp2/lib/ngtcp2_bbr2.c +1490 -0
- data/ext/ngtcp2/lib/ngtcp2_bbr2.h +149 -0
- data/ext/ngtcp2/lib/ngtcp2_buf.c +56 -0
- data/ext/ngtcp2/lib/ngtcp2_buf.h +108 -0
- data/ext/ngtcp2/lib/ngtcp2_cc.c +616 -0
- data/ext/ngtcp2/lib/ngtcp2_cc.h +422 -0
- data/ext/ngtcp2/lib/ngtcp2_cid.c +147 -0
- data/ext/ngtcp2/lib/ngtcp2_cid.h +175 -0
- data/ext/ngtcp2/lib/ngtcp2_conn.c +13731 -0
- data/ext/ngtcp2/lib/ngtcp2_conn.h +1119 -0
- data/ext/ngtcp2/lib/ngtcp2_conn_stat.h +131 -0
- data/ext/ngtcp2/lib/ngtcp2_conv.c +291 -0
- data/ext/ngtcp2/lib/ngtcp2_conv.h +208 -0
- data/ext/ngtcp2/lib/ngtcp2_crypto.c +895 -0
- data/ext/ngtcp2/lib/ngtcp2_crypto.h +148 -0
- data/ext/ngtcp2/lib/ngtcp2_err.c +154 -0
- data/ext/ngtcp2/lib/ngtcp2_err.h +34 -0
- data/ext/ngtcp2/lib/ngtcp2_gaptr.c +167 -0
- data/ext/ngtcp2/lib/ngtcp2_gaptr.h +98 -0
- data/ext/ngtcp2/lib/ngtcp2_idtr.c +79 -0
- data/ext/ngtcp2/lib/ngtcp2_idtr.h +89 -0
- data/ext/ngtcp2/lib/ngtcp2_ksl.c +819 -0
- data/ext/ngtcp2/lib/ngtcp2_ksl.h +345 -0
- data/ext/ngtcp2/lib/ngtcp2_log.c +822 -0
- data/ext/ngtcp2/lib/ngtcp2_log.h +123 -0
- data/ext/ngtcp2/lib/ngtcp2_macro.h +58 -0
- data/ext/ngtcp2/lib/ngtcp2_map.c +336 -0
- data/ext/ngtcp2/lib/ngtcp2_map.h +136 -0
- data/ext/ngtcp2/lib/ngtcp2_mem.c +113 -0
- data/ext/ngtcp2/lib/ngtcp2_mem.h +72 -0
- data/ext/ngtcp2/lib/ngtcp2_net.h +136 -0
- data/ext/ngtcp2/lib/ngtcp2_objalloc.c +40 -0
- data/ext/ngtcp2/lib/ngtcp2_objalloc.h +140 -0
- data/ext/ngtcp2/lib/ngtcp2_opl.c +46 -0
- data/ext/ngtcp2/lib/ngtcp2_opl.h +65 -0
- data/ext/ngtcp2/lib/ngtcp2_path.c +77 -0
- data/ext/ngtcp2/lib/ngtcp2_path.h +49 -0
- data/ext/ngtcp2/lib/ngtcp2_pkt.c +2527 -0
- data/ext/ngtcp2/lib/ngtcp2_pkt.h +1235 -0
- data/ext/ngtcp2/lib/ngtcp2_pmtud.c +160 -0
- data/ext/ngtcp2/lib/ngtcp2_pmtud.h +123 -0
- data/ext/ngtcp2/lib/ngtcp2_ppe.c +230 -0
- data/ext/ngtcp2/lib/ngtcp2_ppe.h +153 -0
- data/ext/ngtcp2/lib/ngtcp2_pq.c +164 -0
- data/ext/ngtcp2/lib/ngtcp2_pq.h +126 -0
- data/ext/ngtcp2/lib/ngtcp2_pv.c +172 -0
- data/ext/ngtcp2/lib/ngtcp2_pv.h +194 -0
- data/ext/ngtcp2/lib/ngtcp2_qlog.c +1219 -0
- data/ext/ngtcp2/lib/ngtcp2_qlog.h +161 -0
- data/ext/ngtcp2/lib/ngtcp2_range.c +61 -0
- data/ext/ngtcp2/lib/ngtcp2_range.h +80 -0
- data/ext/ngtcp2/lib/ngtcp2_rcvry.h +40 -0
- data/ext/ngtcp2/lib/ngtcp2_ringbuf.c +121 -0
- data/ext/ngtcp2/lib/ngtcp2_ringbuf.h +132 -0
- data/ext/ngtcp2/lib/ngtcp2_rob.c +319 -0
- data/ext/ngtcp2/lib/ngtcp2_rob.h +197 -0
- data/ext/ngtcp2/lib/ngtcp2_rst.c +138 -0
- data/ext/ngtcp2/lib/ngtcp2_rst.h +86 -0
- data/ext/ngtcp2/lib/ngtcp2_rtb.c +1676 -0
- data/ext/ngtcp2/lib/ngtcp2_rtb.h +468 -0
- data/ext/ngtcp2/lib/ngtcp2_str.c +233 -0
- data/ext/ngtcp2/lib/ngtcp2_str.h +94 -0
- data/ext/ngtcp2/lib/ngtcp2_strm.c +698 -0
- data/ext/ngtcp2/lib/ngtcp2_strm.h +310 -0
- data/ext/ngtcp2/lib/ngtcp2_unreachable.c +71 -0
- data/ext/ngtcp2/lib/ngtcp2_unreachable.h +46 -0
- data/ext/ngtcp2/lib/ngtcp2_vec.c +243 -0
- data/ext/ngtcp2/lib/ngtcp2_vec.h +120 -0
- data/ext/ngtcp2/lib/ngtcp2_version.c +39 -0
- data/ext/ngtcp2/lib/ngtcp2_window_filter.c +99 -0
- data/ext/ngtcp2/lib/ngtcp2_window_filter.h +65 -0
- data/ext/ngtcp2/m4/ax_check_compile_flag.m4 +74 -0
- data/ext/ngtcp2/m4/ax_cxx_compile_stdcxx.m4 +1009 -0
- data/ext/ngtcp2/tests/CMakeLists.txt +68 -0
- data/ext/ngtcp2/tests/Makefile.am +94 -0
- data/ext/ngtcp2/tests/main.c +358 -0
- data/ext/ngtcp2/tests/ngtcp2_acktr_test.c +367 -0
- data/ext/ngtcp2/tests/ngtcp2_acktr_test.h +37 -0
- data/ext/ngtcp2/tests/ngtcp2_conn_test.c +9821 -0
- data/ext/ngtcp2/tests/ngtcp2_conn_test.h +104 -0
- data/ext/ngtcp2/tests/ngtcp2_conv_test.c +430 -0
- data/ext/ngtcp2/tests/ngtcp2_conv_test.h +46 -0
- data/ext/ngtcp2/tests/ngtcp2_crypto_test.c +667 -0
- data/ext/ngtcp2/tests/ngtcp2_crypto_test.h +35 -0
- data/ext/ngtcp2/tests/ngtcp2_gaptr_test.c +127 -0
- data/ext/ngtcp2/tests/ngtcp2_gaptr_test.h +36 -0
- data/ext/ngtcp2/tests/ngtcp2_idtr_test.c +79 -0
- data/ext/ngtcp2/tests/ngtcp2_idtr_test.h +34 -0
- data/ext/ngtcp2/tests/ngtcp2_ksl_test.c +502 -0
- data/ext/ngtcp2/tests/ngtcp2_ksl_test.h +39 -0
- data/ext/ngtcp2/tests/ngtcp2_map_test.c +206 -0
- data/ext/ngtcp2/tests/ngtcp2_map_test.h +38 -0
- data/ext/ngtcp2/tests/ngtcp2_pkt_test.c +1645 -0
- data/ext/ngtcp2/tests/ngtcp2_pkt_test.h +68 -0
- data/ext/ngtcp2/tests/ngtcp2_pmtud_test.c +153 -0
- data/ext/ngtcp2/tests/ngtcp2_pmtud_test.h +34 -0
- data/ext/ngtcp2/tests/ngtcp2_pv_test.c +129 -0
- data/ext/ngtcp2/tests/ngtcp2_pv_test.h +35 -0
- data/ext/ngtcp2/tests/ngtcp2_range_test.c +105 -0
- data/ext/ngtcp2/tests/ngtcp2_range_test.h +36 -0
- data/ext/ngtcp2/tests/ngtcp2_ringbuf_test.c +91 -0
- data/ext/ngtcp2/tests/ngtcp2_ringbuf_test.h +35 -0
- data/ext/ngtcp2/tests/ngtcp2_rob_test.c +552 -0
- data/ext/ngtcp2/tests/ngtcp2_rob_test.h +37 -0
- data/ext/ngtcp2/tests/ngtcp2_rtb_test.c +470 -0
- data/ext/ngtcp2/tests/ngtcp2_rtb_test.h +38 -0
- data/ext/ngtcp2/tests/ngtcp2_str_test.c +96 -0
- data/ext/ngtcp2/tests/ngtcp2_str_test.h +36 -0
- data/ext/ngtcp2/tests/ngtcp2_strm_test.c +575 -0
- data/ext/ngtcp2/tests/ngtcp2_strm_test.h +36 -0
- data/ext/ngtcp2/tests/ngtcp2_test_helper.c +404 -0
- data/ext/ngtcp2/tests/ngtcp2_test_helper.h +191 -0
- data/ext/ngtcp2/tests/ngtcp2_vec_test.c +426 -0
- data/ext/ngtcp2/tests/ngtcp2_vec_test.h +36 -0
- data/ext/ngtcp2/third-party/CMakeLists.txt +34 -0
- data/ext/ngtcp2/third-party/Makefile.am +31 -0
- data/ext/ngtcp2/third-party/http-parser/AUTHORS +68 -0
- data/ext/ngtcp2/third-party/http-parser/LICENSE-MIT +23 -0
- data/ext/ngtcp2/third-party/http-parser/Makefile +157 -0
- data/ext/ngtcp2/third-party/http-parser/README.md +246 -0
- data/ext/ngtcp2/third-party/http-parser/bench.c +111 -0
- data/ext/ngtcp2/third-party/http-parser/contrib/parsertrace.c +160 -0
- data/ext/ngtcp2/third-party/http-parser/contrib/url_parser.c +47 -0
- data/ext/ngtcp2/third-party/http-parser/http_parser.c +2419 -0
- data/ext/ngtcp2/third-party/http-parser/http_parser.gyp +111 -0
- data/ext/ngtcp2/third-party/http-parser/http_parser.h +431 -0
- data/ext/ngtcp2/third-party/http-parser/test.c +4411 -0
- data/lib/protocol/quic/version.rb +10 -0
- data/lib/protocol/quic.rb +9 -0
- data/license.md +21 -0
- data.tar.gz.sig +1 -0
- metadata +424 -0
- metadata.gz.sig +1 -0
@@ -0,0 +1,361 @@
|
|
1
|
+
/*
|
2
|
+
* ngtcp2
|
3
|
+
*
|
4
|
+
* Copyright (c) 2017 ngtcp2 contributors
|
5
|
+
* Copyright (c) 2012 nghttp2 contributors
|
6
|
+
*
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
8
|
+
* a copy of this software and associated documentation files (the
|
9
|
+
* "Software"), to deal in the Software without restriction, including
|
10
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
11
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
12
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
13
|
+
* the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be
|
16
|
+
* included in all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
19
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
20
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
21
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
22
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
23
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
24
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
#ifndef UTIL_H
|
27
|
+
#define UTIL_H
|
28
|
+
|
29
|
+
#ifdef HAVE_CONFIG_H
|
30
|
+
# include <config.h>
|
31
|
+
#endif // HAVE_CONFIG_H
|
32
|
+
|
33
|
+
#include <sys/socket.h>
|
34
|
+
|
35
|
+
#include <optional>
|
36
|
+
#include <string>
|
37
|
+
#include <random>
|
38
|
+
#include <unordered_map>
|
39
|
+
#include <string_view>
|
40
|
+
|
41
|
+
#include <ngtcp2/ngtcp2.h>
|
42
|
+
#include <nghttp3/nghttp3.h>
|
43
|
+
|
44
|
+
#include <ev.h>
|
45
|
+
|
46
|
+
namespace ngtcp2 {
|
47
|
+
|
48
|
+
namespace util {
|
49
|
+
|
50
|
+
inline nghttp3_nv make_nv(const std::string_view &name,
|
51
|
+
const std::string_view &value, uint8_t flags) {
|
52
|
+
return nghttp3_nv{
|
53
|
+
reinterpret_cast<uint8_t *>(const_cast<char *>(std::data(name))),
|
54
|
+
reinterpret_cast<uint8_t *>(const_cast<char *>(std::data(value))),
|
55
|
+
name.size(),
|
56
|
+
value.size(),
|
57
|
+
flags,
|
58
|
+
};
|
59
|
+
}
|
60
|
+
|
61
|
+
inline nghttp3_nv make_nv_cc(const std::string_view &name,
|
62
|
+
const std::string_view &value) {
|
63
|
+
return make_nv(name, value, NGHTTP3_NV_FLAG_NONE);
|
64
|
+
}
|
65
|
+
|
66
|
+
inline nghttp3_nv make_nv_nc(const std::string_view &name,
|
67
|
+
const std::string_view &value) {
|
68
|
+
return make_nv(name, value, NGHTTP3_NV_FLAG_NO_COPY_NAME);
|
69
|
+
}
|
70
|
+
|
71
|
+
inline nghttp3_nv make_nv_nn(const std::string_view &name,
|
72
|
+
const std::string_view &value) {
|
73
|
+
return make_nv(name, value,
|
74
|
+
NGHTTP3_NV_FLAG_NO_COPY_NAME | NGHTTP3_NV_FLAG_NO_COPY_VALUE);
|
75
|
+
}
|
76
|
+
|
77
|
+
std::string format_hex(uint8_t c);
|
78
|
+
|
79
|
+
std::string format_hex(const uint8_t *s, size_t len);
|
80
|
+
|
81
|
+
std::string format_hex(const std::string_view &s);
|
82
|
+
|
83
|
+
template <size_t N> std::string format_hex(const uint8_t (&s)[N]) {
|
84
|
+
return format_hex(s, N);
|
85
|
+
}
|
86
|
+
|
87
|
+
std::string decode_hex(const std::string_view &s);
|
88
|
+
|
89
|
+
// format_durationf formats |ns| in human readable manner. |ns| must
|
90
|
+
// be nanoseconds resolution. This function uses the largest unit so
|
91
|
+
// that the integral part is strictly more than zero, and the
|
92
|
+
// precision is at most 2 digits. For example, 1234 is formatted as
|
93
|
+
// "1.23us". The largest unit is seconds.
|
94
|
+
std::string format_durationf(uint64_t ns);
|
95
|
+
|
96
|
+
std::mt19937 make_mt19937();
|
97
|
+
|
98
|
+
ngtcp2_tstamp timestamp(struct ev_loop *loop);
|
99
|
+
|
100
|
+
bool numeric_host(const char *hostname);
|
101
|
+
|
102
|
+
bool numeric_host(const char *hostname, int family);
|
103
|
+
|
104
|
+
// Dumps |src| of length |len| in the format similar to `hexdump -C`.
|
105
|
+
void hexdump(FILE *out, const uint8_t *src, size_t len);
|
106
|
+
|
107
|
+
inline char lowcase(char c) {
|
108
|
+
constexpr static unsigned char tbl[] = {
|
109
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
|
110
|
+
15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
|
111
|
+
30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
|
112
|
+
45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
|
113
|
+
60, 61, 62, 63, 64, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
|
114
|
+
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
|
115
|
+
'z', 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
|
116
|
+
105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
|
117
|
+
120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
|
118
|
+
135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
|
119
|
+
150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164,
|
120
|
+
165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
|
121
|
+
180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194,
|
122
|
+
195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
|
123
|
+
210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224,
|
124
|
+
225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
|
125
|
+
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254,
|
126
|
+
255,
|
127
|
+
};
|
128
|
+
return tbl[static_cast<unsigned char>(c)];
|
129
|
+
}
|
130
|
+
|
131
|
+
struct CaseCmp {
|
132
|
+
bool operator()(char lhs, char rhs) const {
|
133
|
+
return lowcase(lhs) == lowcase(rhs);
|
134
|
+
}
|
135
|
+
};
|
136
|
+
|
137
|
+
template <typename InputIterator1, typename InputIterator2>
|
138
|
+
bool istarts_with(InputIterator1 first1, InputIterator1 last1,
|
139
|
+
InputIterator2 first2, InputIterator2 last2) {
|
140
|
+
if (last1 - first1 < last2 - first2) {
|
141
|
+
return false;
|
142
|
+
}
|
143
|
+
return std::equal(first2, last2, first1, CaseCmp());
|
144
|
+
}
|
145
|
+
|
146
|
+
template <typename S, typename T> bool istarts_with(const S &a, const T &b) {
|
147
|
+
return istarts_with(a.begin(), a.end(), b.begin(), b.end());
|
148
|
+
}
|
149
|
+
|
150
|
+
// make_cid_key returns the key for |cid|.
|
151
|
+
std::string make_cid_key(const ngtcp2_cid *cid);
|
152
|
+
std::string make_cid_key(const uint8_t *cid, size_t cidlen);
|
153
|
+
|
154
|
+
// straddr stringifies |sa| of length |salen| in a format "[IP]:PORT".
|
155
|
+
std::string straddr(const sockaddr *sa, socklen_t salen);
|
156
|
+
|
157
|
+
// strccalgo stringifies |cc_algo|.
|
158
|
+
std::string_view strccalgo(ngtcp2_cc_algo cc_algo);
|
159
|
+
|
160
|
+
template <typename T, size_t N>
|
161
|
+
bool streq_l(const T (&a)[N], const nghttp3_vec &b) {
|
162
|
+
return N - 1 == b.len && memcmp(a, b.base, N - 1) == 0;
|
163
|
+
}
|
164
|
+
|
165
|
+
namespace {
|
166
|
+
constexpr char B64_CHARS[] = {
|
167
|
+
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
|
168
|
+
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
169
|
+
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
170
|
+
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
171
|
+
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/',
|
172
|
+
};
|
173
|
+
} // namespace
|
174
|
+
|
175
|
+
template <typename InputIt> std::string b64encode(InputIt first, InputIt last) {
|
176
|
+
std::string res;
|
177
|
+
size_t len = last - first;
|
178
|
+
if (len == 0) {
|
179
|
+
return res;
|
180
|
+
}
|
181
|
+
size_t r = len % 3;
|
182
|
+
res.resize((len + 2) / 3 * 4);
|
183
|
+
auto j = last - r;
|
184
|
+
auto p = std::begin(res);
|
185
|
+
while (first != j) {
|
186
|
+
uint32_t n = static_cast<uint8_t>(*first++) << 16;
|
187
|
+
n += static_cast<uint8_t>(*first++) << 8;
|
188
|
+
n += static_cast<uint8_t>(*first++);
|
189
|
+
*p++ = B64_CHARS[n >> 18];
|
190
|
+
*p++ = B64_CHARS[(n >> 12) & 0x3fu];
|
191
|
+
*p++ = B64_CHARS[(n >> 6) & 0x3fu];
|
192
|
+
*p++ = B64_CHARS[n & 0x3fu];
|
193
|
+
}
|
194
|
+
|
195
|
+
if (r == 2) {
|
196
|
+
uint32_t n = static_cast<uint8_t>(*first++) << 16;
|
197
|
+
n += static_cast<uint8_t>(*first++) << 8;
|
198
|
+
*p++ = B64_CHARS[n >> 18];
|
199
|
+
*p++ = B64_CHARS[(n >> 12) & 0x3fu];
|
200
|
+
*p++ = B64_CHARS[(n >> 6) & 0x3fu];
|
201
|
+
*p++ = '=';
|
202
|
+
} else if (r == 1) {
|
203
|
+
uint32_t n = static_cast<uint8_t>(*first++) << 16;
|
204
|
+
*p++ = B64_CHARS[n >> 18];
|
205
|
+
*p++ = B64_CHARS[(n >> 12) & 0x3fu];
|
206
|
+
*p++ = '=';
|
207
|
+
*p++ = '=';
|
208
|
+
}
|
209
|
+
return res;
|
210
|
+
}
|
211
|
+
|
212
|
+
// read_mime_types reads "MIME media types and the extensions" file
|
213
|
+
// denoted by |filename| and returns the mapping of extension to MIME
|
214
|
+
// media type.
|
215
|
+
std::optional<std::unordered_map<std::string, std::string>>
|
216
|
+
read_mime_types(const std::string_view &filename);
|
217
|
+
|
218
|
+
// format_uint converts |n| into string.
|
219
|
+
template <typename T> std::string format_uint(T n) {
|
220
|
+
std::string res;
|
221
|
+
if (n == 0) {
|
222
|
+
res = "0";
|
223
|
+
return res;
|
224
|
+
}
|
225
|
+
size_t nlen = 0;
|
226
|
+
for (auto t = n; t; t /= 10, ++nlen)
|
227
|
+
;
|
228
|
+
res.resize(nlen);
|
229
|
+
for (; n; n /= 10) {
|
230
|
+
res[--nlen] = (n % 10) + '0';
|
231
|
+
}
|
232
|
+
return res;
|
233
|
+
}
|
234
|
+
|
235
|
+
// format_uint_iec converts |n| into string with the IEC unit (either
|
236
|
+
// "G", "M", or "K"). It chooses the largest unit which does not drop
|
237
|
+
// precision.
|
238
|
+
template <typename T> std::string format_uint_iec(T n) {
|
239
|
+
if (n >= (1 << 30) && (n & ((1 << 30) - 1)) == 0) {
|
240
|
+
return format_uint(n / (1 << 30)) + 'G';
|
241
|
+
}
|
242
|
+
if (n >= (1 << 20) && (n & ((1 << 20) - 1)) == 0) {
|
243
|
+
return format_uint(n / (1 << 20)) + 'M';
|
244
|
+
}
|
245
|
+
if (n >= (1 << 10) && (n & ((1 << 10) - 1)) == 0) {
|
246
|
+
return format_uint(n / (1 << 10)) + 'K';
|
247
|
+
}
|
248
|
+
return format_uint(n);
|
249
|
+
}
|
250
|
+
|
251
|
+
// format_duration converts |n| into string with the unit in either
|
252
|
+
// "h" (hours), "m" (minutes), "s" (seconds), "ms" (milliseconds),
|
253
|
+
// "us" (microseconds) or "ns" (nanoseconds). It chooses the largest
|
254
|
+
// unit which does not drop precision. |n| is in nanosecond
|
255
|
+
// resolution.
|
256
|
+
std::string format_duration(ngtcp2_duration n);
|
257
|
+
|
258
|
+
// parse_uint parses |s| as 64-bit unsigned integer. If it cannot
|
259
|
+
// parse |s|, the return value does not contain a value.
|
260
|
+
std::optional<uint64_t> parse_uint(const std::string_view &s);
|
261
|
+
|
262
|
+
// parse_uint_iec parses |s| as 64-bit unsigned integer. It accepts
|
263
|
+
// IEC unit letter (either "G", "M", or "K") in |s|. If it cannot
|
264
|
+
// parse |s|, the return value does not contain a value.
|
265
|
+
std::optional<uint64_t> parse_uint_iec(const std::string_view &s);
|
266
|
+
|
267
|
+
// parse_duration parses |s| as 64-bit unsigned integer. It accepts a
|
268
|
+
// unit (either "h", "m", "s", "ms", "us", or "ns") in |s|. If no
|
269
|
+
// unit is present, the unit "s" is assumed. If it cannot parse |s|,
|
270
|
+
// the return value does not contain a value.
|
271
|
+
std::optional<uint64_t> parse_duration(const std::string_view &s);
|
272
|
+
|
273
|
+
// generate_secure_random generates a cryptographically secure pseudo
|
274
|
+
// random data of |datalen| bytes and stores to the buffer pointed by
|
275
|
+
// |data|.
|
276
|
+
int generate_secure_random(uint8_t *data, size_t datalen);
|
277
|
+
|
278
|
+
// generate_secret generates secret and writes it to the buffer
|
279
|
+
// pointed by |secret| of length |secretlen|. Currently, |secretlen|
|
280
|
+
// must be 32.
|
281
|
+
int generate_secret(uint8_t *secret, size_t secretlen);
|
282
|
+
|
283
|
+
// normalize_path removes ".." by consuming a previous path component.
|
284
|
+
// It also removes ".". It assumes that |path| starts with "/". If
|
285
|
+
// it cannot consume a previous path component, it just removes "..".
|
286
|
+
std::string normalize_path(const std::string_view &path);
|
287
|
+
|
288
|
+
constexpr bool is_digit(const char c) { return '0' <= c && c <= '9'; }
|
289
|
+
|
290
|
+
constexpr bool is_hex_digit(const char c) {
|
291
|
+
return is_digit(c) || ('A' <= c && c <= 'F') || ('a' <= c && c <= 'f');
|
292
|
+
}
|
293
|
+
|
294
|
+
// Returns integer corresponding to hex notation |c|. If
|
295
|
+
// is_hex_digit(c) is false, it returns 256.
|
296
|
+
constexpr uint32_t hex_to_uint(char c) {
|
297
|
+
if (c <= '9') {
|
298
|
+
return c - '0';
|
299
|
+
}
|
300
|
+
if (c <= 'Z') {
|
301
|
+
return c - 'A' + 10;
|
302
|
+
}
|
303
|
+
if (c <= 'z') {
|
304
|
+
return c - 'a' + 10;
|
305
|
+
}
|
306
|
+
return 256;
|
307
|
+
}
|
308
|
+
|
309
|
+
template <typename InputIt>
|
310
|
+
std::string percent_decode(InputIt first, InputIt last) {
|
311
|
+
std::string result;
|
312
|
+
result.resize(last - first);
|
313
|
+
auto p = std::begin(result);
|
314
|
+
for (; first != last; ++first) {
|
315
|
+
if (*first != '%') {
|
316
|
+
*p++ = *first;
|
317
|
+
continue;
|
318
|
+
}
|
319
|
+
|
320
|
+
if (first + 1 != last && first + 2 != last && is_hex_digit(*(first + 1)) &&
|
321
|
+
is_hex_digit(*(first + 2))) {
|
322
|
+
*p++ = (hex_to_uint(*(first + 1)) << 4) + hex_to_uint(*(first + 2));
|
323
|
+
first += 2;
|
324
|
+
continue;
|
325
|
+
}
|
326
|
+
|
327
|
+
*p++ = *first;
|
328
|
+
}
|
329
|
+
result.resize(p - std::begin(result));
|
330
|
+
return result;
|
331
|
+
}
|
332
|
+
|
333
|
+
int make_socket_nonblocking(int fd);
|
334
|
+
|
335
|
+
int create_nonblock_socket(int domain, int type, int protocol);
|
336
|
+
|
337
|
+
std::optional<std::string> read_token(const std::string_view &filename);
|
338
|
+
int write_token(const std::string_view &filename, const uint8_t *token,
|
339
|
+
size_t tokenlen);
|
340
|
+
|
341
|
+
const char *crypto_default_ciphers();
|
342
|
+
|
343
|
+
const char *crypto_default_groups();
|
344
|
+
|
345
|
+
// split_str parses delimited strings in |s| and returns substrings
|
346
|
+
// delimited by |delim|. The any white spaces around substring are
|
347
|
+
// treated as a part of substring.
|
348
|
+
std::vector<std::string_view> split_str(const std::string_view &s,
|
349
|
+
char delim = ',');
|
350
|
+
|
351
|
+
// parse_version parses |s| to get 4 byte QUIC version. |s| must be a
|
352
|
+
// hex string and must start with "0x" (.e.g, 0x00000001).
|
353
|
+
std::optional<uint32_t> parse_version(const std::string_view &s);
|
354
|
+
|
355
|
+
} // namespace util
|
356
|
+
|
357
|
+
std::ostream &operator<<(std::ostream &os, const ngtcp2_cid &cid);
|
358
|
+
|
359
|
+
} // namespace ngtcp2
|
360
|
+
|
361
|
+
#endif // UTIL_H
|
@@ -0,0 +1,136 @@
|
|
1
|
+
/*
|
2
|
+
* ngtcp2
|
3
|
+
*
|
4
|
+
* Copyright (c) 2020 ngtcp2 contributors
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
* a copy of this software and associated documentation files (the
|
8
|
+
* "Software"), to deal in the Software without restriction, including
|
9
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
* the following conditions:
|
13
|
+
*
|
14
|
+
* The above copyright notice and this permission notice shall be
|
15
|
+
* included in all copies or substantial portions of the Software.
|
16
|
+
*
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
*/
|
25
|
+
#include "util.h"
|
26
|
+
|
27
|
+
#include <cassert>
|
28
|
+
#include <iostream>
|
29
|
+
#include <fstream>
|
30
|
+
#include <array>
|
31
|
+
|
32
|
+
#include <ngtcp2/ngtcp2_crypto.h>
|
33
|
+
|
34
|
+
#include <gnutls/crypto.h>
|
35
|
+
|
36
|
+
#include "template.h"
|
37
|
+
|
38
|
+
// Based on https://github.com/ueno/ngtcp2-gnutls-examples
|
39
|
+
|
40
|
+
namespace ngtcp2 {
|
41
|
+
|
42
|
+
namespace util {
|
43
|
+
|
44
|
+
int generate_secure_random(uint8_t *data, size_t datalen) {
|
45
|
+
if (gnutls_rnd(GNUTLS_RND_RANDOM, data, datalen) != 0) {
|
46
|
+
return -1;
|
47
|
+
}
|
48
|
+
|
49
|
+
return 0;
|
50
|
+
}
|
51
|
+
|
52
|
+
int generate_secret(uint8_t *secret, size_t secretlen) {
|
53
|
+
std::array<uint8_t, 16> rand;
|
54
|
+
std::array<uint8_t, 32> md;
|
55
|
+
|
56
|
+
assert(md.size() == secretlen);
|
57
|
+
|
58
|
+
if (generate_secure_random(rand.data(), rand.size()) != 0) {
|
59
|
+
return -1;
|
60
|
+
}
|
61
|
+
|
62
|
+
if (gnutls_hash_fast(GNUTLS_DIG_SHA256, rand.data(), rand.size(),
|
63
|
+
md.data()) != 0) {
|
64
|
+
return -1;
|
65
|
+
}
|
66
|
+
|
67
|
+
std::copy_n(std::begin(md), secretlen, secret);
|
68
|
+
return 0;
|
69
|
+
}
|
70
|
+
|
71
|
+
std::optional<std::string> read_token(const std::string_view &filename) {
|
72
|
+
auto f = std::ifstream(filename.data());
|
73
|
+
if (!f) {
|
74
|
+
std::cerr << "Could not read token file " << filename << std::endl;
|
75
|
+
return {};
|
76
|
+
}
|
77
|
+
|
78
|
+
auto pos = f.tellg();
|
79
|
+
std::vector<char> content(pos);
|
80
|
+
f.seekg(0, std::ios::beg);
|
81
|
+
f.read(content.data(), pos);
|
82
|
+
|
83
|
+
gnutls_datum_t s;
|
84
|
+
s.data = reinterpret_cast<unsigned char *>(content.data());
|
85
|
+
s.size = content.size();
|
86
|
+
|
87
|
+
gnutls_datum_t d;
|
88
|
+
if (auto rv = gnutls_pem_base64_decode2("QUIC TOKEN", &s, &d); rv < 0) {
|
89
|
+
std::cerr << "Could not read token in " << filename << std::endl;
|
90
|
+
return {};
|
91
|
+
}
|
92
|
+
|
93
|
+
auto res = std::string{d.data, d.data + d.size};
|
94
|
+
|
95
|
+
gnutls_free(d.data);
|
96
|
+
|
97
|
+
return res;
|
98
|
+
}
|
99
|
+
|
100
|
+
int write_token(const std::string_view &filename, const uint8_t *token,
|
101
|
+
size_t tokenlen) {
|
102
|
+
auto f = std::ofstream(filename.data());
|
103
|
+
if (!f) {
|
104
|
+
std::cerr << "Could not write token in " << filename << std::endl;
|
105
|
+
return -1;
|
106
|
+
}
|
107
|
+
|
108
|
+
gnutls_datum_t s;
|
109
|
+
s.data = const_cast<uint8_t *>(token);
|
110
|
+
s.size = tokenlen;
|
111
|
+
|
112
|
+
gnutls_datum_t d;
|
113
|
+
if (auto rv = gnutls_pem_base64_encode2("QUIC TOKEN", &s, &d); rv < 0) {
|
114
|
+
std::cerr << "Could not encode token in " << filename << std::endl;
|
115
|
+
return -1;
|
116
|
+
}
|
117
|
+
|
118
|
+
f.write(reinterpret_cast<const char *>(d.data), d.size);
|
119
|
+
gnutls_free(d.data);
|
120
|
+
|
121
|
+
return 0;
|
122
|
+
}
|
123
|
+
|
124
|
+
const char *crypto_default_ciphers() {
|
125
|
+
return "NORMAL:-VERS-ALL:+VERS-TLS1.3:-CIPHER-ALL:+AES-128-GCM:+AES-256-GCM:"
|
126
|
+
"+CHACHA20-POLY1305:+AES-128-CCM";
|
127
|
+
}
|
128
|
+
|
129
|
+
const char *crypto_default_groups() {
|
130
|
+
return "-GROUP-ALL:+GROUP-X25519:+GROUP-SECP256R1:+GROUP-SECP384R1:"
|
131
|
+
"+GROUP-SECP521R1";
|
132
|
+
}
|
133
|
+
|
134
|
+
} // namespace util
|
135
|
+
|
136
|
+
} // namespace ngtcp2
|
@@ -0,0 +1,131 @@
|
|
1
|
+
/*
|
2
|
+
* ngtcp2
|
3
|
+
*
|
4
|
+
* Copyright (c) 2020 ngtcp2 contributors
|
5
|
+
*
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
7
|
+
* a copy of this software and associated documentation files (the
|
8
|
+
* "Software"), to deal in the Software without restriction, including
|
9
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
10
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
11
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
12
|
+
* the following conditions:
|
13
|
+
*
|
14
|
+
* The above copyright notice and this permission notice shall be
|
15
|
+
* included in all copies or substantial portions of the Software.
|
16
|
+
*
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
18
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
19
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
20
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
21
|
+
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
22
|
+
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
23
|
+
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
24
|
+
*/
|
25
|
+
#include "util.h"
|
26
|
+
|
27
|
+
#include <cassert>
|
28
|
+
#include <iostream>
|
29
|
+
#include <array>
|
30
|
+
|
31
|
+
#include <ngtcp2/ngtcp2_crypto.h>
|
32
|
+
|
33
|
+
#include <openssl/bio.h>
|
34
|
+
#include <openssl/ssl.h>
|
35
|
+
#include <openssl/evp.h>
|
36
|
+
#include <openssl/rand.h>
|
37
|
+
|
38
|
+
#include "template.h"
|
39
|
+
|
40
|
+
namespace ngtcp2 {
|
41
|
+
|
42
|
+
namespace util {
|
43
|
+
|
44
|
+
int generate_secure_random(uint8_t *data, size_t datalen) {
|
45
|
+
if (RAND_bytes(data, static_cast<int>(datalen)) != 1) {
|
46
|
+
return -1;
|
47
|
+
}
|
48
|
+
|
49
|
+
return 0;
|
50
|
+
}
|
51
|
+
|
52
|
+
int generate_secret(uint8_t *secret, size_t secretlen) {
|
53
|
+
std::array<uint8_t, 16> rand;
|
54
|
+
std::array<uint8_t, 32> md;
|
55
|
+
|
56
|
+
assert(md.size() == secretlen);
|
57
|
+
|
58
|
+
if (generate_secure_random(rand.data(), rand.size()) != 0) {
|
59
|
+
return -1;
|
60
|
+
}
|
61
|
+
|
62
|
+
auto ctx = EVP_MD_CTX_new();
|
63
|
+
if (ctx == nullptr) {
|
64
|
+
return -1;
|
65
|
+
}
|
66
|
+
|
67
|
+
auto ctx_deleter = defer(EVP_MD_CTX_free, ctx);
|
68
|
+
|
69
|
+
unsigned int mdlen = md.size();
|
70
|
+
if (!EVP_DigestInit_ex(ctx, EVP_sha256(), nullptr) ||
|
71
|
+
!EVP_DigestUpdate(ctx, rand.data(), rand.size()) ||
|
72
|
+
!EVP_DigestFinal_ex(ctx, md.data(), &mdlen)) {
|
73
|
+
return -1;
|
74
|
+
}
|
75
|
+
|
76
|
+
std::copy_n(std::begin(md), secretlen, secret);
|
77
|
+
return 0;
|
78
|
+
}
|
79
|
+
|
80
|
+
std::optional<std::string> read_token(const std::string_view &filename) {
|
81
|
+
auto f = BIO_new_file(filename.data(), "r");
|
82
|
+
if (f == nullptr) {
|
83
|
+
std::cerr << "Could not open token file " << filename << std::endl;
|
84
|
+
return {};
|
85
|
+
}
|
86
|
+
|
87
|
+
auto f_d = defer(BIO_free, f);
|
88
|
+
|
89
|
+
char *name, *header;
|
90
|
+
unsigned char *data;
|
91
|
+
long datalen;
|
92
|
+
std::string token;
|
93
|
+
if (PEM_read_bio(f, &name, &header, &data, &datalen) != 1) {
|
94
|
+
std::cerr << "Could not read token file " << filename << std::endl;
|
95
|
+
return {};
|
96
|
+
}
|
97
|
+
|
98
|
+
OPENSSL_free(name);
|
99
|
+
OPENSSL_free(header);
|
100
|
+
|
101
|
+
auto res = std::string{data, data + datalen};
|
102
|
+
|
103
|
+
OPENSSL_free(data);
|
104
|
+
|
105
|
+
return res;
|
106
|
+
}
|
107
|
+
|
108
|
+
int write_token(const std::string_view &filename, const uint8_t *token,
|
109
|
+
size_t tokenlen) {
|
110
|
+
auto f = BIO_new_file(filename.data(), "w");
|
111
|
+
if (f == nullptr) {
|
112
|
+
std::cerr << "Could not write token in " << filename << std::endl;
|
113
|
+
return -1;
|
114
|
+
}
|
115
|
+
|
116
|
+
PEM_write_bio(f, "QUIC TOKEN", "", token, tokenlen);
|
117
|
+
BIO_free(f);
|
118
|
+
|
119
|
+
return 0;
|
120
|
+
}
|
121
|
+
|
122
|
+
const char *crypto_default_ciphers() {
|
123
|
+
return "TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_"
|
124
|
+
"SHA256:TLS_AES_128_CCM_SHA256";
|
125
|
+
}
|
126
|
+
|
127
|
+
const char *crypto_default_groups() { return "X25519:P-256:P-384:P-521"; }
|
128
|
+
|
129
|
+
} // namespace util
|
130
|
+
|
131
|
+
} // namespace ngtcp2
|