protocol-quic 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (343) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/ext/ngtcp2/AUTHORS +44 -0
  4. data/ext/ngtcp2/CMakeLists.txt +431 -0
  5. data/ext/ngtcp2/CMakeOptions.txt +17 -0
  6. data/ext/ngtcp2/COPYING +22 -0
  7. data/ext/ngtcp2/ChangeLog +0 -0
  8. data/ext/ngtcp2/Makefile.am +60 -0
  9. data/ext/ngtcp2/NEWS +0 -0
  10. data/ext/ngtcp2/README +1 -0
  11. data/ext/ngtcp2/README.rst +258 -0
  12. data/ext/ngtcp2/ci/build_boringssl.sh +10 -0
  13. data/ext/ngtcp2/ci/build_nghttp3.sh +9 -0
  14. data/ext/ngtcp2/ci/build_openssl1.sh +8 -0
  15. data/ext/ngtcp2/ci/build_openssl1_cross.sh +9 -0
  16. data/ext/ngtcp2/ci/build_openssl3.sh +8 -0
  17. data/ext/ngtcp2/ci/build_picotls.sh +26 -0
  18. data/ext/ngtcp2/ci/build_wolfssl.sh +9 -0
  19. data/ext/ngtcp2/ci/gen-certificate.sh +8 -0
  20. data/ext/ngtcp2/cmake/ExtractValidFlags.cmake +31 -0
  21. data/ext/ngtcp2/cmake/FindCUnit.cmake +40 -0
  22. data/ext/ngtcp2/cmake/FindJemalloc.cmake +40 -0
  23. data/ext/ngtcp2/cmake/FindLibev.cmake +38 -0
  24. data/ext/ngtcp2/cmake/FindLibnghttp3.cmake +41 -0
  25. data/ext/ngtcp2/cmake/Findwolfssl.cmake +41 -0
  26. data/ext/ngtcp2/cmake/Version.cmake +11 -0
  27. data/ext/ngtcp2/cmakeconfig.h.in +36 -0
  28. data/ext/ngtcp2/configure.ac +755 -0
  29. data/ext/ngtcp2/crypto/CMakeLists.txt +56 -0
  30. data/ext/ngtcp2/crypto/Makefile.am +49 -0
  31. data/ext/ngtcp2/crypto/boringssl/CMakeLists.txt +64 -0
  32. data/ext/ngtcp2/crypto/boringssl/Makefile.am +39 -0
  33. data/ext/ngtcp2/crypto/boringssl/boringssl.c +630 -0
  34. data/ext/ngtcp2/crypto/boringssl/libngtcp2_crypto_boringssl.pc.in +33 -0
  35. data/ext/ngtcp2/crypto/gnutls/CMakeLists.txt +86 -0
  36. data/ext/ngtcp2/crypto/gnutls/Makefile.am +43 -0
  37. data/ext/ngtcp2/crypto/gnutls/gnutls.c +644 -0
  38. data/ext/ngtcp2/crypto/gnutls/libngtcp2_crypto_gnutls.pc.in +33 -0
  39. data/ext/ngtcp2/crypto/includes/CMakeLists.txt +56 -0
  40. data/ext/ngtcp2/crypto/includes/Makefile.am +45 -0
  41. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto.h +893 -0
  42. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_boringssl.h +104 -0
  43. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_gnutls.h +107 -0
  44. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_openssl.h +132 -0
  45. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_picotls.h +246 -0
  46. data/ext/ngtcp2/crypto/includes/ngtcp2/ngtcp2_crypto_wolfssl.h +106 -0
  47. data/ext/ngtcp2/crypto/openssl/CMakeLists.txt +86 -0
  48. data/ext/ngtcp2/crypto/openssl/Makefile.am +43 -0
  49. data/ext/ngtcp2/crypto/openssl/libngtcp2_crypto_openssl.pc.in +33 -0
  50. data/ext/ngtcp2/crypto/openssl/openssl.c +807 -0
  51. data/ext/ngtcp2/crypto/picotls/CMakeLists.txt +65 -0
  52. data/ext/ngtcp2/crypto/picotls/Makefile.am +39 -0
  53. data/ext/ngtcp2/crypto/picotls/libngtcp2_crypto_picotls.pc.in +33 -0
  54. data/ext/ngtcp2/crypto/picotls/picotls.c +707 -0
  55. data/ext/ngtcp2/crypto/shared.c +1431 -0
  56. data/ext/ngtcp2/crypto/shared.h +350 -0
  57. data/ext/ngtcp2/crypto/wolfssl/CMakeLists.txt +84 -0
  58. data/ext/ngtcp2/crypto/wolfssl/Makefile.am +43 -0
  59. data/ext/ngtcp2/crypto/wolfssl/libngtcp2_crypto_wolfssl.pc.in +33 -0
  60. data/ext/ngtcp2/crypto/wolfssl/wolfssl.c +534 -0
  61. data/ext/ngtcp2/doc/Makefile.am +65 -0
  62. data/ext/ngtcp2/doc/make.bat +35 -0
  63. data/ext/ngtcp2/doc/mkapiref.py +356 -0
  64. data/ext/ngtcp2/doc/source/conf.py.in +94 -0
  65. data/ext/ngtcp2/doc/source/index.rst +22 -0
  66. data/ext/ngtcp2/doc/source/programmers-guide.rst +476 -0
  67. data/ext/ngtcp2/docker/Dockerfile +39 -0
  68. data/ext/ngtcp2/examples/CMakeLists.txt +361 -0
  69. data/ext/ngtcp2/examples/Makefile.am +228 -0
  70. data/ext/ngtcp2/examples/client.cc +3049 -0
  71. data/ext/ngtcp2/examples/client.h +192 -0
  72. data/ext/ngtcp2/examples/client_base.cc +202 -0
  73. data/ext/ngtcp2/examples/client_base.h +213 -0
  74. data/ext/ngtcp2/examples/debug.cc +298 -0
  75. data/ext/ngtcp2/examples/debug.h +124 -0
  76. data/ext/ngtcp2/examples/examplestest.cc +84 -0
  77. data/ext/ngtcp2/examples/gtlssimpleclient.c +720 -0
  78. data/ext/ngtcp2/examples/h09client.cc +2601 -0
  79. data/ext/ngtcp2/examples/h09client.h +196 -0
  80. data/ext/ngtcp2/examples/h09server.cc +3024 -0
  81. data/ext/ngtcp2/examples/h09server.h +237 -0
  82. data/ext/ngtcp2/examples/http.cc +138 -0
  83. data/ext/ngtcp2/examples/http.h +44 -0
  84. data/ext/ngtcp2/examples/network.h +80 -0
  85. data/ext/ngtcp2/examples/server.cc +3731 -0
  86. data/ext/ngtcp2/examples/server.h +256 -0
  87. data/ext/ngtcp2/examples/server_base.cc +58 -0
  88. data/ext/ngtcp2/examples/server_base.h +195 -0
  89. data/ext/ngtcp2/examples/shared.cc +385 -0
  90. data/ext/ngtcp2/examples/shared.h +96 -0
  91. data/ext/ngtcp2/examples/simpleclient.c +683 -0
  92. data/ext/ngtcp2/examples/template.h +71 -0
  93. data/ext/ngtcp2/examples/tests/README.rst +60 -0
  94. data/ext/ngtcp2/examples/tests/__init__.py +0 -0
  95. data/ext/ngtcp2/examples/tests/config.ini.in +32 -0
  96. data/ext/ngtcp2/examples/tests/conftest.py +28 -0
  97. data/ext/ngtcp2/examples/tests/ngtcp2test/__init__.py +6 -0
  98. data/ext/ngtcp2/examples/tests/ngtcp2test/certs.py +476 -0
  99. data/ext/ngtcp2/examples/tests/ngtcp2test/client.py +187 -0
  100. data/ext/ngtcp2/examples/tests/ngtcp2test/env.py +191 -0
  101. data/ext/ngtcp2/examples/tests/ngtcp2test/log.py +101 -0
  102. data/ext/ngtcp2/examples/tests/ngtcp2test/server.py +137 -0
  103. data/ext/ngtcp2/examples/tests/ngtcp2test/tls.py +983 -0
  104. data/ext/ngtcp2/examples/tests/test_01_handshake.py +30 -0
  105. data/ext/ngtcp2/examples/tests/test_02_resume.py +46 -0
  106. data/ext/ngtcp2/examples/tests/test_03_earlydata.py +56 -0
  107. data/ext/ngtcp2/examples/tests/test_04_clientcert.py +57 -0
  108. data/ext/ngtcp2/examples/tests/test_05_ciphers.py +46 -0
  109. data/ext/ngtcp2/examples/tls_client_context.h +52 -0
  110. data/ext/ngtcp2/examples/tls_client_context_boringssl.cc +126 -0
  111. data/ext/ngtcp2/examples/tls_client_context_boringssl.h +49 -0
  112. data/ext/ngtcp2/examples/tls_client_context_gnutls.cc +74 -0
  113. data/ext/ngtcp2/examples/tls_client_context_gnutls.h +50 -0
  114. data/ext/ngtcp2/examples/tls_client_context_openssl.cc +137 -0
  115. data/ext/ngtcp2/examples/tls_client_context_openssl.h +49 -0
  116. data/ext/ngtcp2/examples/tls_client_context_picotls.cc +158 -0
  117. data/ext/ngtcp2/examples/tls_client_context_picotls.h +53 -0
  118. data/ext/ngtcp2/examples/tls_client_context_wolfssl.cc +177 -0
  119. data/ext/ngtcp2/examples/tls_client_context_wolfssl.h +51 -0
  120. data/ext/ngtcp2/examples/tls_client_session.h +52 -0
  121. data/ext/ngtcp2/examples/tls_client_session_boringssl.cc +110 -0
  122. data/ext/ngtcp2/examples/tls_client_session_boringssl.h +52 -0
  123. data/ext/ngtcp2/examples/tls_client_session_gnutls.cc +190 -0
  124. data/ext/ngtcp2/examples/tls_client_session_gnutls.h +52 -0
  125. data/ext/ngtcp2/examples/tls_client_session_openssl.cc +113 -0
  126. data/ext/ngtcp2/examples/tls_client_session_openssl.h +52 -0
  127. data/ext/ngtcp2/examples/tls_client_session_picotls.cc +147 -0
  128. data/ext/ngtcp2/examples/tls_client_session_picotls.h +52 -0
  129. data/ext/ngtcp2/examples/tls_client_session_wolfssl.cc +160 -0
  130. data/ext/ngtcp2/examples/tls_client_session_wolfssl.h +52 -0
  131. data/ext/ngtcp2/examples/tls_server_context.h +52 -0
  132. data/ext/ngtcp2/examples/tls_server_context_boringssl.cc +257 -0
  133. data/ext/ngtcp2/examples/tls_server_context_boringssl.h +54 -0
  134. data/ext/ngtcp2/examples/tls_server_context_gnutls.cc +99 -0
  135. data/ext/ngtcp2/examples/tls_server_context_gnutls.h +59 -0
  136. data/ext/ngtcp2/examples/tls_server_context_openssl.cc +338 -0
  137. data/ext/ngtcp2/examples/tls_server_context_openssl.h +54 -0
  138. data/ext/ngtcp2/examples/tls_server_context_picotls.cc +321 -0
  139. data/ext/ngtcp2/examples/tls_server_context_picotls.h +58 -0
  140. data/ext/ngtcp2/examples/tls_server_context_wolfssl.cc +284 -0
  141. data/ext/ngtcp2/examples/tls_server_context_wolfssl.h +55 -0
  142. data/ext/ngtcp2/examples/tls_server_session.h +52 -0
  143. data/ext/ngtcp2/examples/tls_server_session_boringssl.cc +84 -0
  144. data/ext/ngtcp2/examples/tls_server_session_boringssl.h +47 -0
  145. data/ext/ngtcp2/examples/tls_server_session_gnutls.cc +155 -0
  146. data/ext/ngtcp2/examples/tls_server_session_gnutls.h +46 -0
  147. data/ext/ngtcp2/examples/tls_server_session_openssl.cc +54 -0
  148. data/ext/ngtcp2/examples/tls_server_session_openssl.h +47 -0
  149. data/ext/ngtcp2/examples/tls_server_session_picotls.cc +70 -0
  150. data/ext/ngtcp2/examples/tls_server_session_picotls.h +47 -0
  151. data/ext/ngtcp2/examples/tls_server_session_wolfssl.cc +55 -0
  152. data/ext/ngtcp2/examples/tls_server_session_wolfssl.h +47 -0
  153. data/ext/ngtcp2/examples/tls_session_base_gnutls.cc +87 -0
  154. data/ext/ngtcp2/examples/tls_session_base_gnutls.h +51 -0
  155. data/ext/ngtcp2/examples/tls_session_base_openssl.cc +54 -0
  156. data/ext/ngtcp2/examples/tls_session_base_openssl.h +52 -0
  157. data/ext/ngtcp2/examples/tls_session_base_picotls.cc +56 -0
  158. data/ext/ngtcp2/examples/tls_session_base_picotls.h +54 -0
  159. data/ext/ngtcp2/examples/tls_session_base_wolfssl.cc +54 -0
  160. data/ext/ngtcp2/examples/tls_session_base_wolfssl.h +54 -0
  161. data/ext/ngtcp2/examples/tls_shared_picotls.cc +59 -0
  162. data/ext/ngtcp2/examples/tls_shared_picotls.h +36 -0
  163. data/ext/ngtcp2/examples/util.cc +646 -0
  164. data/ext/ngtcp2/examples/util.h +361 -0
  165. data/ext/ngtcp2/examples/util_gnutls.cc +136 -0
  166. data/ext/ngtcp2/examples/util_openssl.cc +131 -0
  167. data/ext/ngtcp2/examples/util_test.cc +237 -0
  168. data/ext/ngtcp2/examples/util_test.h +45 -0
  169. data/ext/ngtcp2/examples/util_wolfssl.cc +130 -0
  170. data/ext/ngtcp2/fuzz/corpus/decode_frame/ack +0 -0
  171. data/ext/ngtcp2/fuzz/corpus/decode_frame/ack_ecn +0 -0
  172. data/ext/ngtcp2/fuzz/corpus/decode_frame/connection_close +0 -0
  173. data/ext/ngtcp2/fuzz/corpus/decode_frame/crypto +1 -0
  174. data/ext/ngtcp2/fuzz/corpus/decode_frame/data_blocked +1 -0
  175. data/ext/ngtcp2/fuzz/corpus/decode_frame/datagram +1 -0
  176. data/ext/ngtcp2/fuzz/corpus/decode_frame/datagram_len +1 -0
  177. data/ext/ngtcp2/fuzz/corpus/decode_frame/max_data +1 -0
  178. data/ext/ngtcp2/fuzz/corpus/decode_frame/max_stream_data +0 -0
  179. data/ext/ngtcp2/fuzz/corpus/decode_frame/max_streams +0 -0
  180. data/ext/ngtcp2/fuzz/corpus/decode_frame/new_connection_id +1 -0
  181. data/ext/ngtcp2/fuzz/corpus/decode_frame/new_token +1 -0
  182. data/ext/ngtcp2/fuzz/corpus/decode_frame/path_challenge +1 -0
  183. data/ext/ngtcp2/fuzz/corpus/decode_frame/path_response +1 -0
  184. data/ext/ngtcp2/fuzz/corpus/decode_frame/reset_stream +0 -0
  185. data/ext/ngtcp2/fuzz/corpus/decode_frame/retire_connection_id +1 -0
  186. data/ext/ngtcp2/fuzz/corpus/decode_frame/stop_sending +0 -0
  187. data/ext/ngtcp2/fuzz/corpus/decode_frame/stream +0 -0
  188. data/ext/ngtcp2/fuzz/corpus/decode_frame/stream_data_blocked +0 -0
  189. data/ext/ngtcp2/fuzz/corpus/decode_frame/stream_len +0 -0
  190. data/ext/ngtcp2/fuzz/corpus/decode_frame/streams_blocked +0 -0
  191. data/ext/ngtcp2/fuzz/corpus/ksl/random +0 -0
  192. data/ext/ngtcp2/fuzz/decode_frame.cc +25 -0
  193. data/ext/ngtcp2/fuzz/ksl.cc +77 -0
  194. data/ext/ngtcp2/interop/Dockerfile +39 -0
  195. data/ext/ngtcp2/interop/run_endpoint.sh +93 -0
  196. data/ext/ngtcp2/lib/CMakeLists.txt +110 -0
  197. data/ext/ngtcp2/lib/Makefile.am +122 -0
  198. data/ext/ngtcp2/lib/includes/CMakeLists.txt +4 -0
  199. data/ext/ngtcp2/lib/includes/Makefile.am +25 -0
  200. data/ext/ngtcp2/lib/includes/ngtcp2/ngtcp2.h +5843 -0
  201. data/ext/ngtcp2/lib/includes/ngtcp2/version.h.in +51 -0
  202. data/ext/ngtcp2/lib/libngtcp2.pc.in +33 -0
  203. data/ext/ngtcp2/lib/ngtcp2_acktr.c +335 -0
  204. data/ext/ngtcp2/lib/ngtcp2_acktr.h +221 -0
  205. data/ext/ngtcp2/lib/ngtcp2_addr.c +117 -0
  206. data/ext/ngtcp2/lib/ngtcp2_addr.h +69 -0
  207. data/ext/ngtcp2/lib/ngtcp2_balloc.c +90 -0
  208. data/ext/ngtcp2/lib/ngtcp2_balloc.h +91 -0
  209. data/ext/ngtcp2/lib/ngtcp2_bbr.c +693 -0
  210. data/ext/ngtcp2/lib/ngtcp2_bbr.h +157 -0
  211. data/ext/ngtcp2/lib/ngtcp2_bbr2.c +1490 -0
  212. data/ext/ngtcp2/lib/ngtcp2_bbr2.h +149 -0
  213. data/ext/ngtcp2/lib/ngtcp2_buf.c +56 -0
  214. data/ext/ngtcp2/lib/ngtcp2_buf.h +108 -0
  215. data/ext/ngtcp2/lib/ngtcp2_cc.c +616 -0
  216. data/ext/ngtcp2/lib/ngtcp2_cc.h +422 -0
  217. data/ext/ngtcp2/lib/ngtcp2_cid.c +147 -0
  218. data/ext/ngtcp2/lib/ngtcp2_cid.h +175 -0
  219. data/ext/ngtcp2/lib/ngtcp2_conn.c +13731 -0
  220. data/ext/ngtcp2/lib/ngtcp2_conn.h +1119 -0
  221. data/ext/ngtcp2/lib/ngtcp2_conn_stat.h +131 -0
  222. data/ext/ngtcp2/lib/ngtcp2_conv.c +291 -0
  223. data/ext/ngtcp2/lib/ngtcp2_conv.h +208 -0
  224. data/ext/ngtcp2/lib/ngtcp2_crypto.c +895 -0
  225. data/ext/ngtcp2/lib/ngtcp2_crypto.h +148 -0
  226. data/ext/ngtcp2/lib/ngtcp2_err.c +154 -0
  227. data/ext/ngtcp2/lib/ngtcp2_err.h +34 -0
  228. data/ext/ngtcp2/lib/ngtcp2_gaptr.c +167 -0
  229. data/ext/ngtcp2/lib/ngtcp2_gaptr.h +98 -0
  230. data/ext/ngtcp2/lib/ngtcp2_idtr.c +79 -0
  231. data/ext/ngtcp2/lib/ngtcp2_idtr.h +89 -0
  232. data/ext/ngtcp2/lib/ngtcp2_ksl.c +819 -0
  233. data/ext/ngtcp2/lib/ngtcp2_ksl.h +345 -0
  234. data/ext/ngtcp2/lib/ngtcp2_log.c +822 -0
  235. data/ext/ngtcp2/lib/ngtcp2_log.h +123 -0
  236. data/ext/ngtcp2/lib/ngtcp2_macro.h +58 -0
  237. data/ext/ngtcp2/lib/ngtcp2_map.c +336 -0
  238. data/ext/ngtcp2/lib/ngtcp2_map.h +136 -0
  239. data/ext/ngtcp2/lib/ngtcp2_mem.c +113 -0
  240. data/ext/ngtcp2/lib/ngtcp2_mem.h +72 -0
  241. data/ext/ngtcp2/lib/ngtcp2_net.h +136 -0
  242. data/ext/ngtcp2/lib/ngtcp2_objalloc.c +40 -0
  243. data/ext/ngtcp2/lib/ngtcp2_objalloc.h +140 -0
  244. data/ext/ngtcp2/lib/ngtcp2_opl.c +46 -0
  245. data/ext/ngtcp2/lib/ngtcp2_opl.h +65 -0
  246. data/ext/ngtcp2/lib/ngtcp2_path.c +77 -0
  247. data/ext/ngtcp2/lib/ngtcp2_path.h +49 -0
  248. data/ext/ngtcp2/lib/ngtcp2_pkt.c +2527 -0
  249. data/ext/ngtcp2/lib/ngtcp2_pkt.h +1235 -0
  250. data/ext/ngtcp2/lib/ngtcp2_pmtud.c +160 -0
  251. data/ext/ngtcp2/lib/ngtcp2_pmtud.h +123 -0
  252. data/ext/ngtcp2/lib/ngtcp2_ppe.c +230 -0
  253. data/ext/ngtcp2/lib/ngtcp2_ppe.h +153 -0
  254. data/ext/ngtcp2/lib/ngtcp2_pq.c +164 -0
  255. data/ext/ngtcp2/lib/ngtcp2_pq.h +126 -0
  256. data/ext/ngtcp2/lib/ngtcp2_pv.c +172 -0
  257. data/ext/ngtcp2/lib/ngtcp2_pv.h +194 -0
  258. data/ext/ngtcp2/lib/ngtcp2_qlog.c +1219 -0
  259. data/ext/ngtcp2/lib/ngtcp2_qlog.h +161 -0
  260. data/ext/ngtcp2/lib/ngtcp2_range.c +61 -0
  261. data/ext/ngtcp2/lib/ngtcp2_range.h +80 -0
  262. data/ext/ngtcp2/lib/ngtcp2_rcvry.h +40 -0
  263. data/ext/ngtcp2/lib/ngtcp2_ringbuf.c +121 -0
  264. data/ext/ngtcp2/lib/ngtcp2_ringbuf.h +132 -0
  265. data/ext/ngtcp2/lib/ngtcp2_rob.c +319 -0
  266. data/ext/ngtcp2/lib/ngtcp2_rob.h +197 -0
  267. data/ext/ngtcp2/lib/ngtcp2_rst.c +138 -0
  268. data/ext/ngtcp2/lib/ngtcp2_rst.h +86 -0
  269. data/ext/ngtcp2/lib/ngtcp2_rtb.c +1676 -0
  270. data/ext/ngtcp2/lib/ngtcp2_rtb.h +468 -0
  271. data/ext/ngtcp2/lib/ngtcp2_str.c +233 -0
  272. data/ext/ngtcp2/lib/ngtcp2_str.h +94 -0
  273. data/ext/ngtcp2/lib/ngtcp2_strm.c +698 -0
  274. data/ext/ngtcp2/lib/ngtcp2_strm.h +310 -0
  275. data/ext/ngtcp2/lib/ngtcp2_unreachable.c +71 -0
  276. data/ext/ngtcp2/lib/ngtcp2_unreachable.h +46 -0
  277. data/ext/ngtcp2/lib/ngtcp2_vec.c +243 -0
  278. data/ext/ngtcp2/lib/ngtcp2_vec.h +120 -0
  279. data/ext/ngtcp2/lib/ngtcp2_version.c +39 -0
  280. data/ext/ngtcp2/lib/ngtcp2_window_filter.c +99 -0
  281. data/ext/ngtcp2/lib/ngtcp2_window_filter.h +65 -0
  282. data/ext/ngtcp2/m4/ax_check_compile_flag.m4 +74 -0
  283. data/ext/ngtcp2/m4/ax_cxx_compile_stdcxx.m4 +1009 -0
  284. data/ext/ngtcp2/tests/CMakeLists.txt +68 -0
  285. data/ext/ngtcp2/tests/Makefile.am +94 -0
  286. data/ext/ngtcp2/tests/main.c +358 -0
  287. data/ext/ngtcp2/tests/ngtcp2_acktr_test.c +367 -0
  288. data/ext/ngtcp2/tests/ngtcp2_acktr_test.h +37 -0
  289. data/ext/ngtcp2/tests/ngtcp2_conn_test.c +9821 -0
  290. data/ext/ngtcp2/tests/ngtcp2_conn_test.h +104 -0
  291. data/ext/ngtcp2/tests/ngtcp2_conv_test.c +430 -0
  292. data/ext/ngtcp2/tests/ngtcp2_conv_test.h +46 -0
  293. data/ext/ngtcp2/tests/ngtcp2_crypto_test.c +667 -0
  294. data/ext/ngtcp2/tests/ngtcp2_crypto_test.h +35 -0
  295. data/ext/ngtcp2/tests/ngtcp2_gaptr_test.c +127 -0
  296. data/ext/ngtcp2/tests/ngtcp2_gaptr_test.h +36 -0
  297. data/ext/ngtcp2/tests/ngtcp2_idtr_test.c +79 -0
  298. data/ext/ngtcp2/tests/ngtcp2_idtr_test.h +34 -0
  299. data/ext/ngtcp2/tests/ngtcp2_ksl_test.c +502 -0
  300. data/ext/ngtcp2/tests/ngtcp2_ksl_test.h +39 -0
  301. data/ext/ngtcp2/tests/ngtcp2_map_test.c +206 -0
  302. data/ext/ngtcp2/tests/ngtcp2_map_test.h +38 -0
  303. data/ext/ngtcp2/tests/ngtcp2_pkt_test.c +1645 -0
  304. data/ext/ngtcp2/tests/ngtcp2_pkt_test.h +68 -0
  305. data/ext/ngtcp2/tests/ngtcp2_pmtud_test.c +153 -0
  306. data/ext/ngtcp2/tests/ngtcp2_pmtud_test.h +34 -0
  307. data/ext/ngtcp2/tests/ngtcp2_pv_test.c +129 -0
  308. data/ext/ngtcp2/tests/ngtcp2_pv_test.h +35 -0
  309. data/ext/ngtcp2/tests/ngtcp2_range_test.c +105 -0
  310. data/ext/ngtcp2/tests/ngtcp2_range_test.h +36 -0
  311. data/ext/ngtcp2/tests/ngtcp2_ringbuf_test.c +91 -0
  312. data/ext/ngtcp2/tests/ngtcp2_ringbuf_test.h +35 -0
  313. data/ext/ngtcp2/tests/ngtcp2_rob_test.c +552 -0
  314. data/ext/ngtcp2/tests/ngtcp2_rob_test.h +37 -0
  315. data/ext/ngtcp2/tests/ngtcp2_rtb_test.c +470 -0
  316. data/ext/ngtcp2/tests/ngtcp2_rtb_test.h +38 -0
  317. data/ext/ngtcp2/tests/ngtcp2_str_test.c +96 -0
  318. data/ext/ngtcp2/tests/ngtcp2_str_test.h +36 -0
  319. data/ext/ngtcp2/tests/ngtcp2_strm_test.c +575 -0
  320. data/ext/ngtcp2/tests/ngtcp2_strm_test.h +36 -0
  321. data/ext/ngtcp2/tests/ngtcp2_test_helper.c +404 -0
  322. data/ext/ngtcp2/tests/ngtcp2_test_helper.h +191 -0
  323. data/ext/ngtcp2/tests/ngtcp2_vec_test.c +426 -0
  324. data/ext/ngtcp2/tests/ngtcp2_vec_test.h +36 -0
  325. data/ext/ngtcp2/third-party/CMakeLists.txt +34 -0
  326. data/ext/ngtcp2/third-party/Makefile.am +31 -0
  327. data/ext/ngtcp2/third-party/http-parser/AUTHORS +68 -0
  328. data/ext/ngtcp2/third-party/http-parser/LICENSE-MIT +23 -0
  329. data/ext/ngtcp2/third-party/http-parser/Makefile +157 -0
  330. data/ext/ngtcp2/third-party/http-parser/README.md +246 -0
  331. data/ext/ngtcp2/third-party/http-parser/bench.c +111 -0
  332. data/ext/ngtcp2/third-party/http-parser/contrib/parsertrace.c +160 -0
  333. data/ext/ngtcp2/third-party/http-parser/contrib/url_parser.c +47 -0
  334. data/ext/ngtcp2/third-party/http-parser/http_parser.c +2419 -0
  335. data/ext/ngtcp2/third-party/http-parser/http_parser.gyp +111 -0
  336. data/ext/ngtcp2/third-party/http-parser/http_parser.h +431 -0
  337. data/ext/ngtcp2/third-party/http-parser/test.c +4411 -0
  338. data/lib/protocol/quic/version.rb +10 -0
  339. data/lib/protocol/quic.rb +9 -0
  340. data/license.md +21 -0
  341. data.tar.gz.sig +1 -0
  342. metadata +424 -0
  343. metadata.gz.sig +1 -0
@@ -0,0 +1,983 @@
1
+ import binascii
2
+ import logging
3
+ import sys
4
+ from collections.abc import Iterator
5
+ from typing import Dict, Any, Iterable
6
+
7
+
8
+ log = logging.getLogger(__name__)
9
+
10
+
11
+ class ParseError(Exception):
12
+ pass
13
+
14
+ def _get_int(d, n):
15
+ if len(d) < n:
16
+ raise ParseError(f'get_int: {n} bytes needed, but data is {d}')
17
+ if n == 1:
18
+ dlen = d[0]
19
+ else:
20
+ dlen = int.from_bytes(d[0:n], byteorder='big')
21
+ return d[n:], dlen
22
+
23
+
24
+ def _get_field(d, dlen):
25
+ if dlen > 0:
26
+ if len(d) < dlen:
27
+ raise ParseError(f'field len={dlen}, but data len={len(d)}')
28
+ field = d[0:dlen]
29
+ return d[dlen:], field
30
+ return d, b''
31
+
32
+
33
+ def _get_len_field(d, n):
34
+ d, dlen = _get_int(d, n)
35
+ return _get_field(d, dlen)
36
+
37
+
38
+ # d are bytes that start with a quic variable length integer
39
+ def _get_qint(d):
40
+ i = d[0] & 0xc0
41
+ if i == 0:
42
+ return d[1:], int(d[0])
43
+ elif i == 0x40:
44
+ ndata = bytearray(d[0:2])
45
+ d = d[2:]
46
+ ndata[0] = ndata[0] & ~0xc0
47
+ return d, int.from_bytes(ndata, byteorder='big')
48
+ elif i == 0x80:
49
+ ndata = bytearray(d[0:4])
50
+ d = d[4:]
51
+ ndata[0] = ndata[0] & ~0xc0
52
+ return d, int.from_bytes(ndata, byteorder='big')
53
+ else:
54
+ ndata = bytearray(d[0:8])
55
+ d = d[8:]
56
+ ndata[0] = ndata[0] & ~0xc0
57
+ return d, int.from_bytes(ndata, byteorder='big')
58
+
59
+
60
+ class TlsSupportedGroups:
61
+ NAME_BY_ID = {
62
+ 0: 'Reserved',
63
+ 1: 'sect163k1',
64
+ 2: 'sect163r1',
65
+ 3: 'sect163r2',
66
+ 4: 'sect193r1',
67
+ 5: 'sect193r2',
68
+ 6: 'sect233k1',
69
+ 7: 'sect233r1',
70
+ 8: 'sect239k1',
71
+ 9: 'sect283k1',
72
+ 10: 'sect283r1',
73
+ 11: 'sect409k1',
74
+ 12: 'sect409r1',
75
+ 13: 'sect571k1',
76
+ 14: 'sect571r1',
77
+ 15: 'secp160k1',
78
+ 16: 'secp160r1',
79
+ 17: 'secp160r2',
80
+ 18: 'secp192k1',
81
+ 19: 'secp192r1',
82
+ 20: 'secp224k1',
83
+ 21: 'secp224r1',
84
+ 22: 'secp256k1',
85
+ 23: 'secp256r1',
86
+ 24: 'secp384r1',
87
+ 25: 'secp521r1',
88
+ 26: 'brainpoolP256r1',
89
+ 27: 'brainpoolP384r1',
90
+ 28: 'brainpoolP512r1',
91
+ 29: 'x25519',
92
+ 30: 'x448',
93
+ 31: 'brainpoolP256r1tls13',
94
+ 32: 'brainpoolP384r1tls13',
95
+ 33: 'brainpoolP512r1tls13',
96
+ 34: 'GC256A',
97
+ 35: 'GC256B',
98
+ 36: 'GC256C',
99
+ 37: 'GC256D',
100
+ 38: 'GC512A',
101
+ 39: 'GC512B',
102
+ 40: 'GC512C',
103
+ 41: 'curveSM2',
104
+ }
105
+
106
+ @classmethod
107
+ def name(cls, gid):
108
+ if gid in cls.NAME_BY_ID:
109
+ return f'{cls.NAME_BY_ID[gid]}(0x{gid:0x})'
110
+ return f'0x{gid:0x}'
111
+
112
+
113
+ class TlsSignatureScheme:
114
+ NAME_BY_ID = {
115
+ 0x0201: 'rsa_pkcs1_sha1',
116
+ 0x0202: 'Reserved',
117
+ 0x0203: 'ecdsa_sha1',
118
+ 0x0401: 'rsa_pkcs1_sha256',
119
+ 0x0403: 'ecdsa_secp256r1_sha256',
120
+ 0x0420: 'rsa_pkcs1_sha256_legacy',
121
+ 0x0501: 'rsa_pkcs1_sha384',
122
+ 0x0503: 'ecdsa_secp384r1_sha384',
123
+ 0x0520: 'rsa_pkcs1_sha384_legacy',
124
+ 0x0601: 'rsa_pkcs1_sha512',
125
+ 0x0603: 'ecdsa_secp521r1_sha512',
126
+ 0x0620: 'rsa_pkcs1_sha512_legacy',
127
+ 0x0704: 'eccsi_sha256',
128
+ 0x0705: 'iso_ibs1',
129
+ 0x0706: 'iso_ibs2',
130
+ 0x0707: 'iso_chinese_ibs',
131
+ 0x0708: 'sm2sig_sm3',
132
+ 0x0709: 'gostr34102012_256a',
133
+ 0x070A: 'gostr34102012_256b',
134
+ 0x070B: 'gostr34102012_256c',
135
+ 0x070C: 'gostr34102012_256d',
136
+ 0x070D: 'gostr34102012_512a',
137
+ 0x070E: 'gostr34102012_512b',
138
+ 0x070F: 'gostr34102012_512c',
139
+ 0x0804: 'rsa_pss_rsae_sha256',
140
+ 0x0805: 'rsa_pss_rsae_sha384',
141
+ 0x0806: 'rsa_pss_rsae_sha512',
142
+ 0x0807: 'ed25519',
143
+ 0x0808: 'ed448',
144
+ 0x0809: 'rsa_pss_pss_sha256',
145
+ 0x080A: 'rsa_pss_pss_sha384',
146
+ 0x080B: 'rsa_pss_pss_sha512',
147
+ 0x081A: 'ecdsa_brainpoolP256r1tls13_sha256',
148
+ 0x081B: 'ecdsa_brainpoolP384r1tls13_sha384',
149
+ 0x081C: 'ecdsa_brainpoolP512r1tls13_sha512',
150
+ }
151
+
152
+ @classmethod
153
+ def name(cls, gid):
154
+ if gid in cls.NAME_BY_ID:
155
+ return f'{cls.NAME_BY_ID[gid]}(0x{gid:0x})'
156
+ return f'0x{gid:0x}'
157
+
158
+
159
+ class TlsCipherSuites:
160
+ NAME_BY_ID = {
161
+ 0x1301: 'TLS_AES_128_GCM_SHA256',
162
+ 0x1302: 'TLS_AES_256_GCM_SHA384',
163
+ 0x1303: 'TLS_CHACHA20_POLY1305_SHA256',
164
+ 0x1304: 'TLS_AES_128_CCM_SHA256',
165
+ 0x1305: 'TLS_AES_128_CCM_8_SHA256',
166
+ 0x00ff: 'TLS_EMPTY_RENEGOTIATION_INFO_SCSV',
167
+ }
168
+
169
+ @classmethod
170
+ def name(cls, cid):
171
+ if cid in cls.NAME_BY_ID:
172
+ return f'{cls.NAME_BY_ID[cid]}(0x{cid:0x})'
173
+ return f'Cipher(0x{cid:0x})'
174
+
175
+
176
+ class PskKeyExchangeMode:
177
+ NAME_BY_ID = {
178
+ 0x00: 'psk_ke',
179
+ 0x01: 'psk_dhe_ke',
180
+ }
181
+
182
+ @classmethod
183
+ def name(cls, gid):
184
+ if gid in cls.NAME_BY_ID:
185
+ return f'{cls.NAME_BY_ID[gid]}(0x{gid:0x})'
186
+ return f'0x{gid:0x}'
187
+
188
+
189
+ class QuicTransportParam:
190
+ NAME_BY_ID = {
191
+ 0x00: 'original_destination_connection_id',
192
+ 0x01: 'max_idle_timeout',
193
+ 0x02: 'stateless_reset_token',
194
+ 0x03: 'max_udp_payload_size',
195
+ 0x04: 'initial_max_data',
196
+ 0x05: 'initial_max_stream_data_bidi_local',
197
+ 0x06: 'initial_max_stream_data_bidi_remote',
198
+ 0x07: 'initial_max_stream_data_uni',
199
+ 0x08: 'initial_max_streams_bidi',
200
+ 0x09: 'initial_max_streams_uni',
201
+ 0x0a: 'ack_delay_exponent',
202
+ 0x0b: 'max_ack_delay',
203
+ 0x0c: 'disable_active_migration',
204
+ 0x0d: 'preferred_address',
205
+ 0x0e: 'active_connection_id_limit',
206
+ 0x0f: 'initial_source_connection_id',
207
+ 0x10: 'retry_source_connection_id',
208
+ }
209
+ TYPE_BY_ID = {
210
+ 0x00: bytes,
211
+ 0x01: int,
212
+ 0x02: bytes,
213
+ 0x03: int,
214
+ 0x04: int,
215
+ 0x05: int,
216
+ 0x06: int,
217
+ 0x07: int,
218
+ 0x08: int,
219
+ 0x09: int,
220
+ 0x0a: int,
221
+ 0x0b: int,
222
+ 0x0c: int,
223
+ 0x0d: bytes,
224
+ 0x0e: int,
225
+ 0x0f: bytes,
226
+ 0x10: bytes,
227
+ }
228
+
229
+ @classmethod
230
+ def name(cls, cid):
231
+ if cid in cls.NAME_BY_ID:
232
+ return f'{cls.NAME_BY_ID[cid]}(0x{cid:0x})'
233
+ return f'QuicTP(0x{cid:0x})'
234
+
235
+ @classmethod
236
+ def is_qint(cls, cid):
237
+ if cid in cls.TYPE_BY_ID:
238
+ return cls.TYPE_BY_ID[cid] == int
239
+ return False
240
+
241
+
242
+ class Extension:
243
+
244
+ def __init__(self, eid, name, edata, hsid):
245
+ self._eid = eid
246
+ self._name = name
247
+ self._edata = edata
248
+ self._hsid = hsid
249
+
250
+ @property
251
+ def data(self):
252
+ return self._edata
253
+
254
+ @property
255
+ def hsid(self):
256
+ return self._hsid
257
+
258
+ def to_json(self):
259
+ jdata = {
260
+ 'id': self._eid,
261
+ 'name': self._name,
262
+ }
263
+ if len(self.data) > 0:
264
+ jdata['data'] = binascii.hexlify(self.data).decode()
265
+ return jdata
266
+
267
+ def to_text(self, indent: int = 0):
268
+ ind = ' ' * (indent + 2)
269
+ s = f'{ind}{self._name}(0x{self._eid:0x})'
270
+ if len(self._edata):
271
+ s += f'\n{ind} data({len(self._edata)}): ' \
272
+ f'{binascii.hexlify(self._edata).decode()}'
273
+ return s
274
+
275
+
276
+ class ExtSupportedGroups(Extension):
277
+
278
+ def __init__(self, eid, name, edata, hsid):
279
+ super().__init__(eid=eid, name=name, edata=edata, hsid=hsid)
280
+ d = edata
281
+ self._groups = []
282
+ while len(d) > 0:
283
+ d, gid = _get_int(d, 2)
284
+ self._groups.append(gid)
285
+
286
+ def to_json(self):
287
+ jdata = {
288
+ 'id': self._eid,
289
+ 'name': self._name,
290
+ }
291
+ if len(self._groups):
292
+ jdata['groups'] = [TlsSupportedGroups.name(gid)
293
+ for gid in self._groups]
294
+ return jdata
295
+
296
+ def to_text(self, indent: int = 0):
297
+ ind = ' ' * (indent + 2)
298
+ gnames = [TlsSupportedGroups.name(gid) for gid in self._groups]
299
+ s = f'{ind}{self._name}(0x{self._eid:0x}): {", ".join(gnames)}'
300
+ return s
301
+
302
+
303
+ class ExtKeyShare(Extension):
304
+
305
+ def __init__(self, eid, name, edata, hsid):
306
+ super().__init__(eid=eid, name=name, edata=edata, hsid=hsid)
307
+ d = self.data
308
+ self._keys = []
309
+ self._group = None
310
+ self._pubkey = None
311
+ if self.hsid == 2: # ServerHello
312
+ # single key share (group, pubkey)
313
+ d, self._group = _get_int(d, 2)
314
+ d, self._pubkey = _get_len_field(d, 2)
315
+ elif self.hsid == 6: # HelloRetryRequest
316
+ assert len(d) == 2
317
+ d, self._group = _get_int(d, 2)
318
+ else:
319
+ # list if key shares (group, pubkey)
320
+ d, shares = _get_len_field(d, 2)
321
+ while len(shares) > 0:
322
+ shares, group = _get_int(shares, 2)
323
+ shares, pubkey = _get_len_field(shares, 2)
324
+ self._keys.append({
325
+ 'group': TlsSupportedGroups.name(group),
326
+ 'pubkey': binascii.hexlify(pubkey).decode()
327
+ })
328
+
329
+ def to_json(self):
330
+ jdata = super().to_json()
331
+ if self._group is not None:
332
+ jdata['group'] = TlsSupportedGroups.name(self._group)
333
+ if self._pubkey is not None:
334
+ jdata['pubkey'] = binascii.hexlify(self._pubkey).decode()
335
+ if len(self._keys) > 0:
336
+ jdata['keys'] = self._keys
337
+ return jdata
338
+
339
+ def to_text(self, indent: int = 0):
340
+ ind = ' ' * (indent + 2)
341
+ s = f'{ind}{self._name}(0x{self._eid:0x})'
342
+ if self._group is not None:
343
+ s += f'\n{ind} group: {TlsSupportedGroups.name(self._group)}'
344
+ if self._pubkey is not None:
345
+ s += f'\n{ind} pubkey: {binascii.hexlify(self._pubkey).decode()}'
346
+ if len(self._keys) > 0:
347
+ for idx, key in enumerate(self._keys):
348
+ s += f'\n{ind} {idx}: {key["group"]}, {key["pubkey"]}'
349
+ return s
350
+
351
+
352
+ class ExtSNI(Extension):
353
+
354
+ def __init__(self, eid, name, edata, hsid):
355
+ super().__init__(eid=eid, name=name, edata=edata, hsid=hsid)
356
+ d = self.data
357
+ self._indicators = []
358
+ while len(d) > 0:
359
+ d, entry = _get_len_field(d, 2)
360
+ entry, stype = _get_int(entry, 1)
361
+ entry, sname = _get_len_field(entry, 2)
362
+ self._indicators.append({
363
+ 'type': stype,
364
+ 'name': sname.decode()
365
+ })
366
+
367
+ def to_json(self):
368
+ jdata = super().to_json()
369
+ for i in self._indicators:
370
+ if i['type'] == 0:
371
+ jdata['host_name'] = i['name']
372
+ else:
373
+ jdata[f'0x{i["type"]}'] = i['name']
374
+ return jdata
375
+
376
+ def to_text(self, indent: int = 0):
377
+ ind = ' ' * (indent + 2)
378
+ s = f'{ind}{self._name}(0x{self._eid:0x})'
379
+ if len(self._indicators) == 1 and self._indicators[0]['type'] == 0:
380
+ s += f': {self._indicators[0]["name"]}'
381
+ else:
382
+ for i in self._indicators:
383
+ ikey = 'host_name' if i["type"] == 0 else f'type(0x{i["type"]:0x}'
384
+ s += f'\n{ind} {ikey}: {i["name"]}'
385
+ return s
386
+
387
+
388
+ class ExtALPN(Extension):
389
+
390
+ def __init__(self, eid, name, edata, hsid):
391
+ super().__init__(eid=eid, name=name, edata=edata, hsid=hsid)
392
+ d = self.data
393
+ d, list_len = _get_int(d, 2)
394
+ self._protocols = []
395
+ while len(d) > 0:
396
+ d, proto = _get_len_field(d, 1)
397
+ self._protocols.append(proto.decode())
398
+
399
+ def to_json(self):
400
+ jdata = super().to_json()
401
+ if len(self._protocols) == 1:
402
+ jdata['alpn'] = self._protocols[0]
403
+ else:
404
+ jdata['alpn'] = self._protocols
405
+ return jdata
406
+
407
+ def to_text(self, indent: int = 0):
408
+ ind = ' ' * (indent + 2)
409
+ return f'{ind}{self._name}(0x{self._eid:0x}): {", ".join(self._protocols)}'
410
+
411
+
412
+ class ExtEarlyData(Extension):
413
+
414
+ def __init__(self, eid, name, edata, hsid):
415
+ super().__init__(eid=eid, name=name, edata=edata, hsid=hsid)
416
+ self._max_size = None
417
+ d = self.data
418
+ if hsid == 4: # SessionTicket
419
+ assert len(d) == 4, f'expected 4, len is {len(d)} data={d}'
420
+ d, self._max_size = _get_int(d, 4)
421
+ else:
422
+ assert len(d) == 0
423
+
424
+ def to_json(self):
425
+ jdata = super().to_json()
426
+ if self._max_size is not None:
427
+ jdata['max_size'] = self._max_size
428
+ return jdata
429
+
430
+
431
+ class ExtSignatureAlgorithms(Extension):
432
+
433
+ def __init__(self, eid, name, edata, hsid):
434
+ super().__init__(eid=eid, name=name, edata=edata, hsid=hsid)
435
+ d = self.data
436
+ d, list_len = _get_int(d, 2)
437
+ self._algos = []
438
+ while len(d) > 0:
439
+ d, algo = _get_int(d, 2)
440
+ self._algos.append(TlsSignatureScheme.name(algo))
441
+
442
+ def to_json(self):
443
+ jdata = super().to_json()
444
+ if len(self._algos) > 0:
445
+ jdata['algorithms'] = self._algos
446
+ return jdata
447
+
448
+ def to_text(self, indent: int = 0):
449
+ ind = ' ' * (indent + 2)
450
+ return f'{ind}{self._name}(0x{self._eid:0x}): {", ".join(self._algos)}'
451
+
452
+
453
+ class ExtPSKExchangeModes(Extension):
454
+
455
+ def __init__(self, eid, name, edata, hsid):
456
+ super().__init__(eid=eid, name=name, edata=edata, hsid=hsid)
457
+ d = self.data
458
+ d, list_len = _get_int(d, 1)
459
+ self._modes = []
460
+ while len(d) > 0:
461
+ d, mode = _get_int(d, 1)
462
+ self._modes.append(PskKeyExchangeMode.name(mode))
463
+
464
+ def to_json(self):
465
+ jdata = super().to_json()
466
+ jdata['modes'] = self._modes
467
+ return jdata
468
+
469
+ def to_text(self, indent: int = 0):
470
+ ind = ' ' * (indent + 2)
471
+ return f'{ind}{self._name}(0x{self._eid:0x}): {", ".join(self._modes)}'
472
+
473
+
474
+ class ExtPreSharedKey(Extension):
475
+
476
+ def __init__(self, eid, name, edata, hsid):
477
+ super().__init__(eid=eid, name=name, edata=edata, hsid=hsid)
478
+ self._kid = None
479
+ self._identities = None
480
+ self._binders = None
481
+ d = self.data
482
+ if hsid == 1: # client hello
483
+ d, idata = _get_len_field(d, 2)
484
+ self._identities = []
485
+ while len(idata):
486
+ idata, identity = _get_len_field(idata, 2)
487
+ idata, obfs_age = _get_int(idata, 4)
488
+ self._identities.append({
489
+ 'id': binascii.hexlify(identity).decode(),
490
+ 'age': obfs_age,
491
+ })
492
+ d, binders = _get_len_field(d, 2)
493
+ self._binders = []
494
+ while len(binders) > 0:
495
+ binders, hmac = _get_len_field(binders, 1)
496
+ self._binders.append(binascii.hexlify(hmac).decode())
497
+ assert len(d) == 0
498
+ else:
499
+ d, self._kid = _get_int(d, 2)
500
+
501
+ def to_json(self):
502
+ jdata = super().to_json()
503
+ if self.hsid == 1:
504
+ jdata['identities'] = self._identities
505
+ jdata['binders'] = self._binders
506
+ else:
507
+ jdata['identity'] = self._kid
508
+ return jdata
509
+
510
+ def to_text(self, indent: int = 0):
511
+ ind = ' ' * (indent + 2)
512
+ s = f'{ind}{self._name}(0x{self._hsid:0x})'
513
+ if self.hsid == 1:
514
+ for idx, i in enumerate(self._identities):
515
+ s += f'\n{ind} {idx}: {i["id"]} ({i["age"]})'
516
+ s += f'\n{ind} binders: {self._binders}'
517
+ else:
518
+ s += f'\n{ind} identity: {self._kid}'
519
+ return s
520
+
521
+
522
+ class ExtSupportedVersions(Extension):
523
+
524
+ def __init__(self, eid, name, edata, hsid):
525
+ super().__init__(eid=eid, name=name, edata=edata, hsid=hsid)
526
+ d = self.data
527
+ self._versions = []
528
+ if hsid == 1: # client hello
529
+ d, list_len = _get_int(d, 1)
530
+ while len(d) > 0:
531
+ d, version = _get_int(d, 2)
532
+ self._versions.append(f'0x{version:0x}')
533
+ else:
534
+ d, version = _get_int(d, 2)
535
+ self._versions.append(f'0x{version:0x}')
536
+
537
+ def to_json(self):
538
+ jdata = super().to_json()
539
+ if len(self._versions) == 1:
540
+ jdata['version'] = self._versions[0]
541
+ else:
542
+ jdata['versions'] = self._versions
543
+ return jdata
544
+
545
+ def to_text(self, indent: int = 0):
546
+ ind = ' ' * (indent + 2)
547
+ return f'{ind}{self._name}(0x{self._eid:0x}): {", ".join(self._versions)}'
548
+
549
+
550
+ class ExtQuicTP(Extension):
551
+
552
+ def __init__(self, eid, name, edata, hsid):
553
+ super().__init__(eid=eid, name=name, edata=edata, hsid=hsid)
554
+ d = self.data
555
+ self._params = []
556
+ while len(d) > 0:
557
+ d, ptype = _get_qint(d)
558
+ d, plen = _get_qint(d)
559
+ d, pvalue = _get_field(d, plen)
560
+ if QuicTransportParam.is_qint(ptype):
561
+ _, pvalue = _get_qint(pvalue)
562
+ else:
563
+ pvalue = binascii.hexlify(pvalue).decode()
564
+ self._params.append({
565
+ 'key': QuicTransportParam.name(ptype),
566
+ 'value': pvalue,
567
+ })
568
+
569
+ def to_json(self):
570
+ jdata = super().to_json()
571
+ jdata['params'] = self._params
572
+ return jdata
573
+
574
+ def to_text(self, indent: int = 0):
575
+ ind = ' ' * (indent + 2)
576
+ s = f'{ind}{self._name}(0x{self._eid:0x})'
577
+ for p in self._params:
578
+ s += f'\n{ind} {p["key"]}: {p["value"]}'
579
+ return s
580
+
581
+
582
+ class TlsExtensions:
583
+
584
+ EXT_TYPES = [
585
+ (0x00, 'SNI', ExtSNI),
586
+ (0x01, 'MAX_FRAGMENT_LENGTH', Extension),
587
+ (0x03, 'TRUSTED_CA_KEYS', Extension),
588
+ (0x04, 'TRUNCATED_HMAC', Extension),
589
+ (0x05, 'OSCP_STATUS_REQUEST', Extension),
590
+ (0x0a, 'SUPPORTED_GROUPS', ExtSupportedGroups),
591
+ (0x0b, 'EC_POINT_FORMATS', Extension),
592
+ (0x0d, 'SIGNATURE_ALGORITHMS', ExtSignatureAlgorithms),
593
+ (0x0e, 'USE_SRTP', Extension),
594
+ (0x10, 'ALPN', ExtALPN),
595
+ (0x11, 'STATUS_REQUEST_V2', Extension),
596
+ (0x16, 'ENCRYPT_THEN_MAC', Extension),
597
+ (0x17, 'EXTENDED_MASTER_SECRET', Extension),
598
+ (0x23, 'SESSION_TICKET', Extension),
599
+ (0x29, 'PRE_SHARED_KEY', ExtPreSharedKey),
600
+ (0x2a, 'EARLY_DATA', ExtEarlyData),
601
+ (0x2b, 'SUPPORTED_VERSIONS', ExtSupportedVersions),
602
+ (0x2c, 'COOKIE', Extension),
603
+ (0x2d, 'PSK_KEY_EXCHANGE_MODES', ExtPSKExchangeModes),
604
+ (0x31, 'POST_HANDSHAKE_AUTH', Extension),
605
+ (0x32, 'SIGNATURE_ALGORITHMS_CERT', Extension),
606
+ (0x33, 'KEY_SHARE', ExtKeyShare),
607
+ (0x39, 'QUIC_TP_PARAMS', ExtQuicTP),
608
+ (0xff01, 'RENEGOTIATION_INFO', Extension),
609
+ (0xffa5, 'QUIC_TP_PARAMS_DRAFT', ExtQuicTP),
610
+ ]
611
+ NAME_BY_ID = {}
612
+ CLASS_BY_ID = {}
613
+
614
+ @classmethod
615
+ def init(cls):
616
+ for (eid, name, ecls) in cls.EXT_TYPES:
617
+ cls.NAME_BY_ID[eid] = name
618
+ cls.CLASS_BY_ID[eid] = ecls
619
+
620
+ @classmethod
621
+ def from_data(cls, hsid, data):
622
+ exts = []
623
+ d = data
624
+ while len(d):
625
+ d, eid = _get_int(d, 2)
626
+ d, elen = _get_int(d, 2)
627
+ d, edata = _get_field(d, elen)
628
+ if eid in cls.NAME_BY_ID:
629
+ ename = cls.NAME_BY_ID[eid]
630
+ ecls = cls.CLASS_BY_ID[eid]
631
+ exts.append(ecls(eid=eid, name=ename, edata=edata, hsid=hsid))
632
+ else:
633
+ exts.append(Extension(eid=eid, name=f'(0x{eid:0x})',
634
+ edata=edata, hsid=hsid))
635
+ return exts
636
+
637
+
638
+ TlsExtensions.init()
639
+
640
+
641
+ class HSRecord:
642
+
643
+ def __init__(self, hsid: int, name: str, data):
644
+ self._hsid = hsid
645
+ self._name = name
646
+ self._data = data
647
+
648
+ @property
649
+ def hsid(self):
650
+ return self._hsid
651
+
652
+ @property
653
+ def name(self):
654
+ return self._name
655
+
656
+ @name.setter
657
+ def name(self, value):
658
+ self._name = value
659
+
660
+ @property
661
+ def data(self):
662
+ return self._data
663
+
664
+ def __repr__(self):
665
+ return f'{self.name}[{binascii.hexlify(self._data).decode()}]'
666
+
667
+ def to_json(self) -> Dict[str, Any]:
668
+ return {
669
+ 'name': self.name,
670
+ 'data': binascii.hexlify(self._data).decode(),
671
+ }
672
+
673
+ def to_text(self, indent: int = 0):
674
+ ind = ' ' * (indent + 2)
675
+ return f'{ind}{self._name}\n'\
676
+ f'{ind} id: 0x{self._hsid:0x}\n'\
677
+ f'{ind} data({len(self._data)}): '\
678
+ f'{binascii.hexlify(self._data).decode()}'
679
+
680
+
681
+ class ClientHello(HSRecord):
682
+
683
+ def __init__(self, hsid: int, name: str, data):
684
+ super().__init__(hsid=hsid, name=name, data=data)
685
+ d = data
686
+ d, self._version = _get_int(d, 2)
687
+ d, self._random = _get_field(d, 32)
688
+ d, self._session_id = _get_len_field(d, 1)
689
+ self._ciphers = []
690
+ d, ciphers = _get_len_field(d, 2)
691
+ while len(ciphers):
692
+ ciphers, cipher = _get_int(ciphers, 2)
693
+ self._ciphers.append(TlsCipherSuites.name(cipher))
694
+ d, comps = _get_len_field(d, 1)
695
+ self._compressions = [int(c) for c in comps]
696
+ d, edata = _get_len_field(d, 2)
697
+ self._extensions = TlsExtensions.from_data(hsid, edata)
698
+
699
+ def to_json(self):
700
+ jdata = super().to_json()
701
+ jdata['version'] = f'0x{self._version:0x}'
702
+ jdata['random'] = f'{binascii.hexlify(self._random).decode()}'
703
+ jdata['session_id'] = binascii.hexlify(self._session_id).decode()
704
+ jdata['ciphers'] = self._ciphers
705
+ jdata['compressions'] = self._compressions
706
+ jdata['extensions'] = [ext.to_json() for ext in self._extensions]
707
+ return jdata
708
+
709
+ def to_text(self, indent: int = 0):
710
+ ind = ' ' * (indent + 2)
711
+ return super().to_text(indent=indent) + '\n'\
712
+ f'{ind} version: 0x{self._version:0x}\n'\
713
+ f'{ind} random: {binascii.hexlify(self._random).decode()}\n' \
714
+ f'{ind} session_id: {binascii.hexlify(self._session_id).decode()}\n' \
715
+ f'{ind} ciphers: {", ".join(self._ciphers)}\n'\
716
+ f'{ind} compressions: {self._compressions}\n'\
717
+ f'{ind} extensions: \n' + '\n'.join(
718
+ [ext.to_text(indent=indent+4) for ext in self._extensions])
719
+
720
+
721
+ class ServerHello(HSRecord):
722
+
723
+ HELLO_RETRY_RANDOM = binascii.unhexlify(
724
+ 'CF21AD74E59A6111BE1D8C021E65B891C2A211167ABB8C5E079E09E2C8A8339C'
725
+ )
726
+
727
+ def __init__(self, hsid: int, name: str, data):
728
+ super().__init__(hsid=hsid, name=name, data=data)
729
+ d = data
730
+ d, self._version = _get_int(d, 2)
731
+ d, self._random = _get_field(d, 32)
732
+ if self._random == self.HELLO_RETRY_RANDOM:
733
+ self.name = 'HelloRetryRequest'
734
+ hsid = 6
735
+ d, self._session_id = _get_len_field(d, 1)
736
+ d, cipher = _get_int(d, 2)
737
+ self._cipher = TlsCipherSuites.name(cipher)
738
+ d, self._compression = _get_int(d, 1)
739
+ d, edata = _get_len_field(d, 2)
740
+ self._extensions = TlsExtensions.from_data(hsid, edata)
741
+
742
+ def to_json(self):
743
+ jdata = super().to_json()
744
+ jdata['version'] = f'0x{self._version:0x}'
745
+ jdata['random'] = f'{binascii.hexlify(self._random).decode()}'
746
+ jdata['session_id'] = binascii.hexlify(self._session_id).decode()
747
+ jdata['cipher'] = self._cipher
748
+ jdata['compression'] = int(self._compression)
749
+ jdata['extensions'] = [ext.to_json() for ext in self._extensions]
750
+ return jdata
751
+
752
+ def to_text(self, indent: int = 0):
753
+ ind = ' ' * (indent + 2)
754
+ return super().to_text(indent=indent) + '\n'\
755
+ f'{ind} version: 0x{self._version:0x}\n'\
756
+ f'{ind} random: {binascii.hexlify(self._random).decode()}\n' \
757
+ f'{ind} session_id: {binascii.hexlify(self._session_id).decode()}\n' \
758
+ f'{ind} cipher: {self._cipher}\n'\
759
+ f'{ind} compression: {int(self._compression)}\n'\
760
+ f'{ind} extensions: \n' + '\n'.join(
761
+ [ext.to_text(indent=indent+4) for ext in self._extensions])
762
+
763
+
764
+ class EncryptedExtensions(HSRecord):
765
+
766
+ def __init__(self, hsid: int, name: str, data):
767
+ super().__init__(hsid=hsid, name=name, data=data)
768
+ d = data
769
+ d, edata = _get_len_field(d, 2)
770
+ self._extensions = TlsExtensions.from_data(hsid, edata)
771
+
772
+ def to_json(self):
773
+ jdata = super().to_json()
774
+ jdata['extensions'] = [ext.to_json() for ext in self._extensions]
775
+ return jdata
776
+
777
+ def to_text(self, indent: int = 0):
778
+ ind = ' ' * (indent + 2)
779
+ return super().to_text(indent=indent) + '\n'\
780
+ f'{ind} extensions: \n' + '\n'.join(
781
+ [ext.to_text(indent=indent+4) for ext in self._extensions])
782
+
783
+
784
+ class CertificateRequest(HSRecord):
785
+
786
+ def __init__(self, hsid: int, name: str, data):
787
+ super().__init__(hsid=hsid, name=name, data=data)
788
+ d = data
789
+ d, self._context = _get_int(d, 1)
790
+ d, edata = _get_len_field(d, 2)
791
+ self._extensions = TlsExtensions.from_data(hsid, edata)
792
+
793
+ def to_json(self):
794
+ jdata = super().to_json()
795
+ jdata['context'] = self._context
796
+ jdata['extensions'] = [ext.to_json() for ext in self._extensions]
797
+ return jdata
798
+
799
+ def to_text(self, indent: int = 0):
800
+ ind = ' ' * (indent + 2)
801
+ return super().to_text(indent=indent) + '\n'\
802
+ f'{ind} context: {self._context}\n'\
803
+ f'{ind} extensions: \n' + '\n'.join(
804
+ [ext.to_text(indent=indent+4) for ext in self._extensions])
805
+
806
+
807
+ class Certificate(HSRecord):
808
+
809
+ def __init__(self, hsid: int, name: str, data):
810
+ super().__init__(hsid=hsid, name=name, data=data)
811
+ d = data
812
+ d, self._context = _get_int(d, 1)
813
+ d, clist = _get_len_field(d, 3)
814
+ self._cert_entries = []
815
+ while len(clist) > 0:
816
+ clist, cert_data = _get_len_field(clist, 3)
817
+ clist, cert_exts = _get_len_field(clist, 2)
818
+ exts = TlsExtensions.from_data(hsid, cert_exts)
819
+ self._cert_entries.append({
820
+ 'cert': binascii.hexlify(cert_data).decode(),
821
+ 'extensions': exts,
822
+ })
823
+
824
+ def to_json(self):
825
+ jdata = super().to_json()
826
+ jdata['context'] = self._context
827
+ jdata['certificate_list'] = [{
828
+ 'cert': e['cert'],
829
+ 'extensions': [x.to_json() for x in e['extensions']],
830
+ } for e in self._cert_entries]
831
+ return jdata
832
+
833
+ def _enxtry_text(self, e, indent: int = 0):
834
+ ind = ' ' * (indent + 2)
835
+ return f'{ind} cert: {e["cert"]}\n'\
836
+ f'{ind} extensions: \n' + '\n'.join(
837
+ [x.to_text(indent=indent + 4) for x in e['extensions']])
838
+
839
+ def to_text(self, indent: int = 0):
840
+ ind = ' ' * (indent + 2)
841
+ return super().to_text(indent=indent) + '\n'\
842
+ f'{ind} context: {self._context}\n'\
843
+ f'{ind} certificate_list: \n' + '\n'.join(
844
+ [self._enxtry_text(e, indent+4) for e in self._cert_entries])
845
+
846
+
847
+ class SessionTicket(HSRecord):
848
+
849
+ def __init__(self, hsid: int, name: str, data):
850
+ super().__init__(hsid=hsid, name=name, data=data)
851
+ d = data
852
+ d, self._lifetime = _get_int(d, 4)
853
+ d, self._age = _get_int(d, 4)
854
+ d, self._nonce = _get_len_field(d, 1)
855
+ d, self._ticket = _get_len_field(d, 2)
856
+ d, edata = _get_len_field(d, 2)
857
+ self._extensions = TlsExtensions.from_data(hsid, edata)
858
+
859
+ def to_json(self):
860
+ jdata = super().to_json()
861
+ jdata['lifetime'] = self._lifetime
862
+ jdata['age'] = self._age
863
+ jdata['nonce'] = binascii.hexlify(self._nonce).decode()
864
+ jdata['ticket'] = binascii.hexlify(self._ticket).decode()
865
+ jdata['extensions'] = [ext.to_json() for ext in self._extensions]
866
+ return jdata
867
+
868
+
869
+ class HSIterator(Iterator):
870
+
871
+ def __init__(self, recs):
872
+ self._recs = recs
873
+ self._index = 0
874
+
875
+ def __iter__(self):
876
+ return self
877
+
878
+ def __next__(self):
879
+ try:
880
+ result = self._recs[self._index]
881
+ except IndexError:
882
+ raise StopIteration
883
+ self._index += 1
884
+ return result
885
+
886
+
887
+ class HandShake:
888
+ REC_TYPES = [
889
+ (1, 'ClientHello', ClientHello),
890
+ (2, 'ServerHello', ServerHello),
891
+ (3, 'HelloVerifyRequest', HSRecord),
892
+ (4, 'SessionTicket', SessionTicket),
893
+ (5, 'EndOfEarlyData', HSRecord),
894
+ (6, 'HelloRetryRequest', ServerHello),
895
+ (8, 'EncryptedExtensions', EncryptedExtensions),
896
+ (11, 'Certificate', Certificate),
897
+ (12, 'ServerKeyExchange ', HSRecord),
898
+ (13, 'CertificateRequest', CertificateRequest),
899
+ (14, 'ServerHelloDone', HSRecord),
900
+ (15, 'CertificateVerify', HSRecord),
901
+ (16, 'ClientKeyExchange', HSRecord),
902
+ (20, 'Finished', HSRecord),
903
+ (22, 'CertificateStatus', HSRecord),
904
+ (24, 'KeyUpdate', HSRecord),
905
+ ]
906
+ RT_NAME_BY_ID = {}
907
+ RT_CLS_BY_ID = {}
908
+
909
+ @classmethod
910
+ def _parse_rec(cls, data):
911
+ d, hsid = _get_int(data, 1)
912
+ if hsid not in cls.RT_CLS_BY_ID:
913
+ raise ParseError(f'unknown type {hsid}')
914
+ d, rec_len = _get_int(d, 3)
915
+ if rec_len > len(d):
916
+ # incomplete, need more data
917
+ return data, None
918
+ d, rec_data = _get_field(d, rec_len)
919
+ if hsid in cls.RT_CLS_BY_ID:
920
+ name = cls.RT_NAME_BY_ID[hsid]
921
+ rcls = cls.RT_CLS_BY_ID[hsid]
922
+ else:
923
+ name = f'CryptoRecord(0x{hsid:0x})'
924
+ rcls = HSRecord
925
+ return d, rcls(hsid=hsid, name=name, data=rec_data)
926
+
927
+ @classmethod
928
+ def _parse(cls, source, strict=False, verbose: int = 0):
929
+ d = b''
930
+ hsid = 0
931
+ hsrecs = []
932
+ if verbose > 0:
933
+ log.debug(f'scanning for handshake records')
934
+ blocks = [d for d in source]
935
+ while len(blocks) > 0:
936
+ try:
937
+ total_data = b''.join(blocks)
938
+ remain, r = cls._parse_rec(total_data)
939
+ if r is None:
940
+ # if we could not recognize a record, skip the first
941
+ # data block and try again
942
+ blocks = blocks[1:]
943
+ continue
944
+ hsrecs.append(r)
945
+ cons_len = len(total_data) - len(remain)
946
+ while cons_len > 0 and len(blocks) > 0:
947
+ if cons_len >= len(blocks[0]):
948
+ cons_len -= len(blocks[0])
949
+ blocks = blocks[1:]
950
+ else:
951
+ blocks[0] = blocks[0][cons_len:]
952
+ cons_len = 0
953
+ if verbose > 2:
954
+ log.debug(f'added record: {r.to_text()}')
955
+ except ParseError as err:
956
+ # if we could not recognize a record, skip the first
957
+ # data block and try again
958
+ blocks = blocks[1:]
959
+ if len(blocks) > 0 and strict:
960
+ raise Exception(f'possibly incomplete handshake record '
961
+ f'id={hsid}, from raw={blocks}\n')
962
+ return hsrecs
963
+
964
+
965
+
966
+ @classmethod
967
+ def init(cls):
968
+ for (hsid, name, rcls) in cls.REC_TYPES:
969
+ cls.RT_NAME_BY_ID[hsid] = name
970
+ cls.RT_CLS_BY_ID[hsid] = rcls
971
+
972
+ def __init__(self, source: Iterable[bytes], strict: bool = False,
973
+ verbose: int = 0):
974
+ self._source = source
975
+ self._strict = strict
976
+ self._verbose = verbose
977
+
978
+ def __iter__(self):
979
+ return HSIterator(recs=self._parse(self._source, strict=self._strict,
980
+ verbose=self._verbose))
981
+
982
+
983
+ HandShake.init()