@fails-components/webtransport 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (300) hide show
  1. package/package.json +1 -1
  2. package/readme.md +1 -3
  3. package/src/http3eventloop.cc +83 -9
  4. package/src/http3eventloop.h +13 -3
  5. package/src/http3server.cc +22 -22
  6. package/src/http3server.h +7 -20
  7. package/src/http3wtstreamvisitor.cc +31 -10
  8. package/src/http3wtstreamvisitor.h +38 -11
  9. package/src/webtransport.js +91 -23
  10. package/test/echoserver.js +29 -5
  11. package/test/testsuite.js +242 -220
  12. package/third_party/boringssl/src/CMakeLists.txt +2 -0
  13. package/third_party/boringssl/src/crypto/CMakeLists.txt +1 -0
  14. package/third_party/boringssl/src/crypto/asn1/a_bitstr.c +174 -177
  15. package/third_party/boringssl/src/crypto/asn1/a_bool.c +46 -48
  16. package/third_party/boringssl/src/crypto/asn1/a_d2i_fp.c +21 -23
  17. package/third_party/boringssl/src/crypto/asn1/a_dup.c +21 -23
  18. package/third_party/boringssl/src/crypto/asn1/a_gentm.c +84 -187
  19. package/third_party/boringssl/src/crypto/asn1/a_i2d_fp.c +19 -21
  20. package/third_party/boringssl/src/crypto/asn1/a_int.c +305 -329
  21. package/third_party/boringssl/src/crypto/asn1/a_mbstr.c +190 -195
  22. package/third_party/boringssl/src/crypto/asn1/a_object.c +182 -189
  23. package/third_party/boringssl/src/crypto/asn1/a_octet.c +6 -9
  24. package/third_party/boringssl/src/crypto/asn1/a_print.c +15 -16
  25. package/third_party/boringssl/src/crypto/asn1/a_strex.c +386 -399
  26. package/third_party/boringssl/src/crypto/asn1/a_strnid.c +110 -131
  27. package/third_party/boringssl/src/crypto/asn1/a_time.c +118 -111
  28. package/third_party/boringssl/src/crypto/asn1/a_type.c +59 -60
  29. package/third_party/boringssl/src/crypto/asn1/a_utctm.c +114 -186
  30. package/third_party/boringssl/src/crypto/asn1/a_utf8.c +171 -159
  31. package/third_party/boringssl/src/crypto/asn1/asn1_lib.c +245 -260
  32. package/third_party/boringssl/src/crypto/asn1/asn1_par.c +41 -40
  33. package/third_party/boringssl/src/crypto/asn1/asn1_test.cc +31 -0
  34. package/third_party/boringssl/src/crypto/asn1/asn_pack.c +31 -33
  35. package/third_party/boringssl/src/crypto/asn1/f_int.c +36 -33
  36. package/third_party/boringssl/src/crypto/asn1/f_string.c +29 -26
  37. package/third_party/boringssl/src/crypto/asn1/internal.h +62 -61
  38. package/third_party/boringssl/src/crypto/asn1/tasn_dec.c +706 -702
  39. package/third_party/boringssl/src/crypto/asn1/tasn_enc.c +507 -524
  40. package/third_party/boringssl/src/crypto/asn1/tasn_fre.c +141 -133
  41. package/third_party/boringssl/src/crypto/asn1/tasn_new.c +207 -199
  42. package/third_party/boringssl/src/crypto/asn1/tasn_typ.c +19 -22
  43. package/third_party/boringssl/src/crypto/asn1/tasn_utl.c +24 -24
  44. package/third_party/boringssl/src/crypto/asn1/time_support.c +13 -13
  45. package/third_party/boringssl/src/crypto/bio/connect.c +9 -3
  46. package/third_party/boringssl/src/crypto/bytestring/bytestring_test.cc +125 -1
  47. package/third_party/boringssl/src/crypto/bytestring/cbb.c +4 -7
  48. package/third_party/boringssl/src/crypto/bytestring/cbs.c +167 -9
  49. package/third_party/boringssl/src/crypto/cipher_extra/e_aesctrhmac.c +0 -2
  50. package/third_party/boringssl/src/crypto/cipher_extra/e_aesgcmsiv.c +23 -54
  51. package/third_party/boringssl/src/crypto/cipher_extra/e_chacha20poly1305.c +0 -2
  52. package/third_party/boringssl/src/crypto/cipher_extra/e_tls.c +0 -2
  53. package/third_party/boringssl/src/crypto/curve25519/curve25519.c +6 -8
  54. package/third_party/boringssl/src/crypto/evp/evp_ctx.c +25 -22
  55. package/third_party/boringssl/src/crypto/evp/internal.h +15 -9
  56. package/third_party/boringssl/src/crypto/evp/p_dsa_asn1.c +2 -0
  57. package/third_party/boringssl/src/crypto/evp/p_ec_asn1.c +2 -0
  58. package/third_party/boringssl/src/crypto/evp/p_ed25519.c +3 -3
  59. package/third_party/boringssl/src/crypto/evp/p_ed25519_asn1.c +10 -7
  60. package/third_party/boringssl/src/crypto/evp/p_hkdf.c +241 -0
  61. package/third_party/boringssl/src/crypto/evp/p_rsa_asn1.c +2 -0
  62. package/third_party/boringssl/src/crypto/evp/p_x25519_asn1.c +1 -0
  63. package/third_party/boringssl/src/crypto/fipsmodule/aes/aes_nohw.c +9 -10
  64. package/third_party/boringssl/src/crypto/fipsmodule/aes/key_wrap.c +2 -6
  65. package/third_party/boringssl/src/crypto/fipsmodule/bn/exponentiation.c +5 -11
  66. package/third_party/boringssl/src/crypto/fipsmodule/bn/internal.h +1 -1
  67. package/third_party/boringssl/src/crypto/fipsmodule/bn/prime.c +2 -0
  68. package/third_party/boringssl/src/crypto/fipsmodule/cipher/e_aes.c +10 -26
  69. package/third_party/boringssl/src/crypto/fipsmodule/cipher/e_aesccm.c +2 -3
  70. package/third_party/boringssl/src/crypto/fipsmodule/digestsign/digestsign.c +1 -0
  71. package/third_party/boringssl/src/crypto/fipsmodule/ec/p256-nistz.c +44 -43
  72. package/third_party/boringssl/src/crypto/fipsmodule/modes/cbc.c +5 -9
  73. package/third_party/boringssl/src/crypto/fipsmodule/modes/gcm.c +14 -21
  74. package/third_party/boringssl/src/crypto/fipsmodule/rand/ctrdrbg.c +8 -8
  75. package/third_party/boringssl/src/crypto/fipsmodule/rand/internal.h +1 -4
  76. package/third_party/boringssl/src/crypto/hkdf/hkdf_test.cc +104 -0
  77. package/third_party/boringssl/src/crypto/internal.h +18 -4
  78. package/third_party/boringssl/src/crypto/lhash/internal.h +13 -1
  79. package/third_party/boringssl/src/crypto/obj/obj_dat.h +4 -1
  80. package/third_party/boringssl/src/crypto/obj/obj_mac.num +1 -0
  81. package/third_party/boringssl/src/crypto/obj/objects.txt +2 -0
  82. package/third_party/boringssl/src/crypto/pem/pem_all.c +77 -86
  83. package/third_party/boringssl/src/crypto/pem/pem_info.c +221 -233
  84. package/third_party/boringssl/src/crypto/pem/pem_lib.c +639 -608
  85. package/third_party/boringssl/src/crypto/pem/pem_oth.c +17 -16
  86. package/third_party/boringssl/src/crypto/pem/pem_pk8.c +133 -142
  87. package/third_party/boringssl/src/crypto/pem/pem_pkey.c +96 -92
  88. package/third_party/boringssl/src/crypto/poly1305/poly1305_vec.c +12 -28
  89. package/third_party/boringssl/src/crypto/siphash/siphash.c +8 -11
  90. package/third_party/boringssl/src/crypto/siphash/siphash_test.cc +5 -7
  91. package/third_party/boringssl/src/crypto/stack/stack.c +33 -16
  92. package/third_party/boringssl/src/crypto/thread_pthread.c +0 -2
  93. package/third_party/boringssl/src/crypto/thread_win.c +0 -2
  94. package/third_party/boringssl/src/crypto/trust_token/internal.h +14 -0
  95. package/third_party/boringssl/src/crypto/trust_token/pmbtoken.c +127 -30
  96. package/third_party/boringssl/src/crypto/trust_token/trust_token.c +40 -0
  97. package/third_party/boringssl/src/crypto/trust_token/trust_token_test.cc +165 -0
  98. package/third_party/boringssl/src/crypto/trust_token/voprf.c +55 -6
  99. package/third_party/boringssl/src/crypto/x509/a_digest.c +23 -24
  100. package/third_party/boringssl/src/crypto/x509/a_sign.c +52 -55
  101. package/third_party/boringssl/src/crypto/x509/a_verify.c +33 -34
  102. package/third_party/boringssl/src/crypto/x509/algorithm.c +17 -18
  103. package/third_party/boringssl/src/crypto/x509/asn1_gen.c +618 -612
  104. package/third_party/boringssl/src/crypto/x509/by_dir.c +320 -337
  105. package/third_party/boringssl/src/crypto/x509/by_file.c +186 -186
  106. package/third_party/boringssl/src/crypto/x509/i2d_pr.c +11 -14
  107. package/third_party/boringssl/src/crypto/x509/internal.h +22 -22
  108. package/third_party/boringssl/src/crypto/x509/name_print.c +155 -150
  109. package/third_party/boringssl/src/crypto/x509/rsa_pss.c +27 -29
  110. package/third_party/boringssl/src/crypto/x509/t_crl.c +67 -70
  111. package/third_party/boringssl/src/crypto/x509/t_req.c +3 -5
  112. package/third_party/boringssl/src/crypto/x509/t_x509.c +280 -251
  113. package/third_party/boringssl/src/crypto/x509/t_x509a.c +52 -47
  114. package/third_party/boringssl/src/crypto/x509/x509.c +3 -4
  115. package/third_party/boringssl/src/crypto/x509/x509_att.c +234 -223
  116. package/third_party/boringssl/src/crypto/x509/x509_cmp.c +286 -296
  117. package/third_party/boringssl/src/crypto/x509/x509_d2.c +37 -32
  118. package/third_party/boringssl/src/crypto/x509/x509_def.c +14 -30
  119. package/third_party/boringssl/src/crypto/x509/x509_ext.c +55 -84
  120. package/third_party/boringssl/src/crypto/x509/x509_lu.c +545 -581
  121. package/third_party/boringssl/src/crypto/x509/x509_obj.c +131 -121
  122. package/third_party/boringssl/src/crypto/x509/x509_req.c +120 -139
  123. package/third_party/boringssl/src/crypto/x509/x509_set.c +128 -142
  124. package/third_party/boringssl/src/crypto/x509/x509_trs.c +185 -193
  125. package/third_party/boringssl/src/crypto/x509/x509_txt.c +70 -72
  126. package/third_party/boringssl/src/crypto/x509/x509_v3.c +172 -161
  127. package/third_party/boringssl/src/crypto/x509/x509_vfy.c +2041 -2053
  128. package/third_party/boringssl/src/crypto/x509/x509_vpm.c +441 -461
  129. package/third_party/boringssl/src/crypto/x509/x509cset.c +152 -170
  130. package/third_party/boringssl/src/crypto/x509/x509name.c +274 -260
  131. package/third_party/boringssl/src/crypto/x509/x509rset.c +43 -20
  132. package/third_party/boringssl/src/crypto/x509/x509spki.c +62 -63
  133. package/third_party/boringssl/src/crypto/x509/x_algor.c +64 -62
  134. package/third_party/boringssl/src/crypto/x509/x_all.c +103 -133
  135. package/third_party/boringssl/src/crypto/x509/x_attrib.c +23 -24
  136. package/third_party/boringssl/src/crypto/x509/x_crl.c +310 -321
  137. package/third_party/boringssl/src/crypto/x509/x_exten.c +6 -5
  138. package/third_party/boringssl/src/crypto/x509/x_info.c +31 -28
  139. package/third_party/boringssl/src/crypto/x509/x_name.c +361 -365
  140. package/third_party/boringssl/src/crypto/x509/x_pkey.c +38 -32
  141. package/third_party/boringssl/src/crypto/x509/x_pubkey.c +114 -117
  142. package/third_party/boringssl/src/crypto/x509/x_req.c +27 -29
  143. package/third_party/boringssl/src/crypto/x509/x_sig.c +2 -2
  144. package/third_party/boringssl/src/crypto/x509/x_spki.c +8 -10
  145. package/third_party/boringssl/src/crypto/x509/x_val.c +2 -2
  146. package/third_party/boringssl/src/crypto/x509/x_x509.c +212 -226
  147. package/third_party/boringssl/src/crypto/x509/x_x509a.c +112 -109
  148. package/third_party/boringssl/src/crypto/x509v3/ext_dat.h +10 -13
  149. package/third_party/boringssl/src/crypto/x509v3/internal.h +72 -87
  150. package/third_party/boringssl/src/crypto/x509v3/pcy_cache.c +184 -176
  151. package/third_party/boringssl/src/crypto/x509v3/pcy_data.c +58 -56
  152. package/third_party/boringssl/src/crypto/x509v3/pcy_lib.c +71 -70
  153. package/third_party/boringssl/src/crypto/x509v3/pcy_map.c +56 -58
  154. package/third_party/boringssl/src/crypto/x509v3/pcy_node.c +89 -91
  155. package/third_party/boringssl/src/crypto/x509v3/pcy_tree.c +585 -590
  156. package/third_party/boringssl/src/crypto/x509v3/v3_akey.c +118 -112
  157. package/third_party/boringssl/src/crypto/x509v3/v3_akeya.c +3 -3
  158. package/third_party/boringssl/src/crypto/x509v3/v3_alt.c +447 -451
  159. package/third_party/boringssl/src/crypto/x509v3/v3_bcons.c +44 -38
  160. package/third_party/boringssl/src/crypto/x509v3/v3_bitst.c +39 -43
  161. package/third_party/boringssl/src/crypto/x509v3/v3_conf.c +321 -320
  162. package/third_party/boringssl/src/crypto/x509v3/v3_cpols.c +352 -327
  163. package/third_party/boringssl/src/crypto/x509v3/v3_crld.c +437 -383
  164. package/third_party/boringssl/src/crypto/x509v3/v3_enum.c +23 -16
  165. package/third_party/boringssl/src/crypto/x509v3/v3_extku.c +62 -53
  166. package/third_party/boringssl/src/crypto/x509v3/v3_genn.c +118 -115
  167. package/third_party/boringssl/src/crypto/x509v3/v3_ia5.c +30 -31
  168. package/third_party/boringssl/src/crypto/x509v3/v3_info.c +112 -98
  169. package/third_party/boringssl/src/crypto/x509v3/v3_int.c +40 -15
  170. package/third_party/boringssl/src/crypto/x509v3/v3_lib.c +248 -252
  171. package/third_party/boringssl/src/crypto/x509v3/v3_ncons.c +390 -386
  172. package/third_party/boringssl/src/crypto/x509v3/v3_ocsp.c +45 -32
  173. package/third_party/boringssl/src/crypto/x509v3/v3_pci.c +206 -209
  174. package/third_party/boringssl/src/crypto/x509v3/v3_pcia.c +6 -8
  175. package/third_party/boringssl/src/crypto/x509v3/v3_pcons.c +54 -50
  176. package/third_party/boringssl/src/crypto/x509v3/v3_pmaps.c +66 -65
  177. package/third_party/boringssl/src/crypto/x509v3/v3_prn.c +144 -133
  178. package/third_party/boringssl/src/crypto/x509v3/v3_purp.c +695 -709
  179. package/third_party/boringssl/src/crypto/x509v3/v3_skey.c +75 -69
  180. package/third_party/boringssl/src/crypto/x509v3/v3_utl.c +1102 -1082
  181. package/third_party/boringssl/src/include/openssl/base.h +3 -1
  182. package/third_party/boringssl/src/include/openssl/bn.h +3 -0
  183. package/third_party/boringssl/src/include/openssl/bytestring.h +20 -0
  184. package/third_party/boringssl/src/include/openssl/evp.h +6 -5
  185. package/third_party/boringssl/src/include/openssl/kdf.h +91 -0
  186. package/third_party/boringssl/src/include/openssl/nid.h +4 -0
  187. package/third_party/boringssl/src/include/openssl/ssl.h +6 -1
  188. package/third_party/boringssl/src/include/openssl/stack.h +47 -32
  189. package/third_party/boringssl/src/include/openssl/trust_token.h +18 -3
  190. package/third_party/boringssl/src/include/openssl/x509.h +18 -0
  191. package/third_party/boringssl/src/ssl/ssl_file.cc +61 -99
  192. package/third_party/boringssl/src/ssl/ssl_test.cc +101 -0
  193. package/third_party/boringssl/src/util/doc.config +2 -1
  194. package/third_party/boringssl/src/util/fipstools/acvp/acvptool/subprocess/subprocess.go +8 -0
  195. package/third_party/googleurl/AUTHORS +16 -2
  196. package/third_party/googleurl/base/BUILD +1 -0
  197. package/third_party/googleurl/base/compiler_specific.h +16 -17
  198. package/third_party/googleurl/base/containers/contiguous_iterator.h +13 -9
  199. package/third_party/googleurl/base/containers/span.h +23 -8
  200. package/third_party/googleurl/base/memory/raw_ptr.h +17 -25
  201. package/third_party/googleurl/base/memory/raw_ptr_exclusion.h +21 -0
  202. package/third_party/googleurl/base/strings/escape.cc +14 -2
  203. package/third_party/googleurl/base/strings/safe_sprintf.h +1 -1
  204. package/third_party/googleurl/base/strings/string_number_conversions.cc +5 -3
  205. package/third_party/googleurl/base/strings/string_number_conversions_internal.h +5 -5
  206. package/third_party/googleurl/base/strings/string_piece.h +3 -3
  207. package/third_party/googleurl/base/strings/string_util.cc +4 -27
  208. package/third_party/googleurl/base/strings/string_util.h +43 -8
  209. package/third_party/googleurl/base/strings/string_util_internal.h +11 -12
  210. package/third_party/googleurl/base/strings/string_util_unittest.cc +33 -0
  211. package/third_party/googleurl/base/strings/string_util_win.cc +0 -5
  212. package/third_party/googleurl/base/strings/string_util_win.h +9 -1
  213. package/third_party/googleurl/base/strings/utf_offset_string_conversions.cc +1 -1
  214. package/third_party/googleurl/base/strings/utf_string_conversion_utils.cc +5 -8
  215. package/third_party/googleurl/base/strings/utf_string_conversion_utils.h +13 -10
  216. package/third_party/googleurl/base/strings/utf_string_conversions.cc +32 -25
  217. package/third_party/googleurl/base/template_util.h +23 -35
  218. package/third_party/googleurl/build/build_config.h +14 -3
  219. package/third_party/googleurl/copy.bara.sky +1 -1
  220. package/third_party/googleurl/url/gurl.cc +8 -4
  221. package/third_party/googleurl/url/gurl.h +1 -0
  222. package/third_party/googleurl/url/gurl_unittest.cc +1 -0
  223. package/third_party/googleurl/url/origin.h +36 -26
  224. package/third_party/googleurl/url/scheme_host_port.h +4 -1
  225. package/third_party/googleurl/url/url_canon.h +2 -1
  226. package/third_party/googleurl/url/url_canon_internal.cc +9 -7
  227. package/third_party/googleurl/url/url_canon_internal.h +16 -16
  228. package/third_party/googleurl/url/url_canon_stdstring.h +2 -1
  229. package/third_party/googleurl/url/url_util.cc +9 -8
  230. package/third_party/quiche/build/source_list.bzl +7 -0
  231. package/third_party/quiche/build/source_list.gni +7 -0
  232. package/third_party/quiche/build/source_list.json +7 -0
  233. package/third_party/quiche/quiche/common/platform/api/quiche_mem_slice.h +7 -3
  234. package/third_party/quiche/quiche/http2/adapter/nghttp2_adapter_test.cc +86 -2
  235. package/third_party/quiche/quiche/http2/adapter/oghttp2_adapter_test.cc +104 -2
  236. package/third_party/quiche/quiche/http2/adapter/oghttp2_session.cc +23 -0
  237. package/third_party/quiche/quiche/http2/adapter/oghttp2_session.h +6 -1
  238. package/third_party/quiche/quiche/quic/core/congestion_control/send_algorithm_test.cc +0 -16
  239. package/third_party/quiche/quiche/quic/core/crypto/crypto_protocol.h +1 -1
  240. package/third_party/quiche/quiche/quic/core/http/end_to_end_test.cc +56 -2
  241. package/third_party/quiche/quiche/quic/core/http/http_constants.cc +1 -0
  242. package/third_party/quiche/quiche/quic/core/http/http_constants.h +1 -0
  243. package/third_party/quiche/quiche/quic/core/http/http_encoder.cc +28 -17
  244. package/third_party/quiche/quiche/quic/core/http/http_encoder.h +5 -0
  245. package/third_party/quiche/quiche/quic/core/http/http_encoder_test.cc +26 -30
  246. package/third_party/quiche/quiche/quic/core/http/http_frames.h +1 -0
  247. package/third_party/quiche/quiche/quic/core/http/quic_server_session_base.cc +4 -4
  248. package/third_party/quiche/quiche/quic/core/http/quic_server_session_base_test.cc +1 -1
  249. package/third_party/quiche/quiche/quic/core/http/quic_spdy_client_session.cc +5 -1
  250. package/third_party/quiche/quiche/quic/core/http/quic_spdy_stream.cc +6 -33
  251. package/third_party/quiche/quiche/quic/core/http/quic_spdy_stream.h +0 -17
  252. package/third_party/quiche/quiche/quic/core/http/quic_spdy_stream_test.cc +5 -20
  253. package/third_party/quiche/quiche/quic/core/io/quic_event_loop.h +81 -0
  254. package/third_party/quiche/quiche/quic/core/io/quic_poll_event_loop.cc +265 -0
  255. package/third_party/quiche/quiche/quic/core/io/quic_poll_event_loop.h +152 -0
  256. package/third_party/quiche/quiche/quic/core/io/quic_poll_event_loop_test.cc +341 -0
  257. package/third_party/quiche/quiche/quic/core/quic_buffered_packet_store.cc +3 -1
  258. package/third_party/quiche/quiche/quic/core/quic_buffered_packet_store.h +7 -7
  259. package/third_party/quiche/quiche/quic/core/quic_buffered_packet_store_test.cc +4 -3
  260. package/third_party/quiche/quiche/quic/core/quic_connection.cc +69 -19
  261. package/third_party/quiche/quiche/quic/core/quic_connection.h +9 -3
  262. package/third_party/quiche/quiche/quic/core/quic_connection_id_manager.cc +29 -10
  263. package/third_party/quiche/quiche/quic/core/quic_connection_id_manager.h +5 -3
  264. package/third_party/quiche/quiche/quic/core/quic_connection_id_manager_test.cc +85 -22
  265. package/third_party/quiche/quiche/quic/core/quic_connection_test.cc +186 -30
  266. package/third_party/quiche/quiche/quic/core/quic_crypto_stream.cc +2 -1
  267. package/third_party/quiche/quiche/quic/core/quic_default_clock.cc +31 -0
  268. package/third_party/quiche/quiche/quic/core/quic_default_clock.h +34 -0
  269. package/third_party/quiche/quiche/quic/core/quic_default_connection_helper.h +49 -0
  270. package/third_party/quiche/quiche/quic/core/quic_dispatcher.cc +53 -37
  271. package/third_party/quiche/quiche/quic/core/quic_dispatcher.h +19 -11
  272. package/third_party/quiche/quiche/quic/core/quic_dispatcher_test.cc +15 -2
  273. package/third_party/quiche/quiche/quic/core/quic_flags_list.h +10 -4
  274. package/third_party/quiche/quiche/quic/core/quic_idle_network_detector.cc +2 -2
  275. package/third_party/quiche/quiche/quic/core/quic_idle_network_detector_test.cc +4 -4
  276. package/third_party/quiche/quiche/quic/core/quic_packet_creator.cc +14 -3
  277. package/third_party/quiche/quiche/quic/core/quic_packet_creator_test.cc +145 -2
  278. package/third_party/quiche/quiche/quic/core/quic_packets.cc +3 -1
  279. package/third_party/quiche/quiche/quic/core/quic_packets.h +4 -0
  280. package/third_party/quiche/quiche/quic/core/quic_sent_packet_manager.cc +13 -11
  281. package/third_party/quiche/quiche/quic/core/quic_sent_packet_manager.h +9 -0
  282. package/third_party/quiche/quiche/quic/core/quic_sent_packet_manager_test.cc +6 -0
  283. package/third_party/quiche/quiche/quic/core/quic_session.cc +3 -2
  284. package/third_party/quiche/quiche/quic/core/quic_session.h +8 -3
  285. package/third_party/quiche/quiche/quic/core/quic_types.cc +18 -0
  286. package/third_party/quiche/quiche/quic/core/quic_types.h +3 -0
  287. package/third_party/quiche/quiche/quic/core/tls_chlo_extractor.cc +3 -0
  288. package/third_party/quiche/quiche/quic/core/tls_chlo_extractor.h +10 -0
  289. package/third_party/quiche/quiche/quic/test_tools/mock_quic_session_visitor.h +1 -1
  290. package/third_party/quiche/quiche/quic/test_tools/quic_test_utils.h +1 -1
  291. package/third_party/quiche/quiche/quic/test_tools/server_thread.cc +3 -2
  292. package/third_party/quiche/quiche/quic/test_tools/simple_session_notifier.cc +7 -1
  293. package/third_party/quiche/quiche/quic/test_tools/simple_session_notifier.h +3 -0
  294. package/third_party/quiche/quiche/quic/test_tools/simulator/quic_endpoint.h +4 -2
  295. package/certs/ca.cnf +0 -69
  296. package/certs/generate_certs.sh +0 -53
  297. package/certs/generate_certs_leaf.sh +0 -53
  298. package/certs/leaf.cnf +0 -24
  299. package/certs/readme.txt +0 -2
  300. package/third_party/quiche/build/BUILD.bazel +0 -7
@@ -55,67 +55,62 @@
55
55
  * [including the GNU Public Licence.] */
56
56
 
57
57
  #include <openssl/asn1.h>
58
-
59
- #include <limits.h>
60
- #include <string.h>
61
-
62
58
  #include <openssl/asn1t.h>
59
+ #include <openssl/bytestring.h>
63
60
  #include <openssl/err.h>
64
61
  #include <openssl/mem.h>
65
62
 
63
+ #include <limits.h>
64
+ #include <string.h>
65
+
66
66
  #include "../internal.h"
67
67
  #include "internal.h"
68
68
 
69
- /*
70
- * Constructed types with a recursive definition (such as can be found in PKCS7)
71
- * could eventually exceed the stack given malicious input with excessive
72
- * recursion. Therefore we limit the stack depth. This is the maximum number of
73
- * recursive invocations of asn1_item_embed_d2i().
74
- */
69
+ // Constructed types with a recursive definition (such as can be found in PKCS7)
70
+ // could eventually exceed the stack given malicious input with excessive
71
+ // recursion. Therefore we limit the stack depth. This is the maximum number of
72
+ // recursive invocations of asn1_item_embed_d2i().
75
73
  #define ASN1_MAX_CONSTRUCTED_NEST 30
76
74
 
77
75
  static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
78
76
  char *cst, const unsigned char **in, long len,
79
77
  int exptag, int expclass, char opt);
80
78
 
81
- static int asn1_template_ex_d2i(ASN1_VALUE **pval,
82
- const unsigned char **in, long len,
83
- const ASN1_TEMPLATE *tt, char opt,
79
+ static int asn1_template_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
80
+ long len, const ASN1_TEMPLATE *tt, char opt,
84
81
  int depth);
85
- static int asn1_template_noexp_d2i(ASN1_VALUE **val,
86
- const unsigned char **in, long len,
87
- const ASN1_TEMPLATE *tt, char opt,
82
+ static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
83
+ long len, const ASN1_TEMPLATE *tt, char opt,
88
84
  int depth);
89
85
  static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
90
86
  int utype, const ASN1_ITEM *it);
91
- static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
92
- const unsigned char **in, long len,
93
- const ASN1_ITEM *it,
94
- int tag, int aclass, char opt);
87
+ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
88
+ long len, const ASN1_ITEM *it, int tag,
89
+ int aclass, char opt);
95
90
  static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
96
91
  long len, const ASN1_ITEM *it, int tag, int aclass,
97
92
  char opt, int depth);
98
93
 
99
- /* Table to convert tags to bit values, used for MSTRING type */
94
+ // Table to convert tags to bit values, used for MSTRING type
100
95
  static const unsigned long tag2bit[31] = {
101
- 0, /* (reserved) */
102
- 0, /* BOOLEAN */
103
- 0, /* INTEGER */
96
+ 0, // (reserved)
97
+ 0, // BOOLEAN
98
+ 0, // INTEGER
104
99
  B_ASN1_BIT_STRING,
105
100
  B_ASN1_OCTET_STRING,
106
- 0, /* NULL */
107
- 0, /* OBJECT IDENTIFIER */
108
- B_ASN1_UNKNOWN, /* ObjectDescriptor */
109
- B_ASN1_UNKNOWN, /* EXTERNAL */
110
- B_ASN1_UNKNOWN, /* REAL */
111
- B_ASN1_UNKNOWN, /* ENUMERATED */
112
- B_ASN1_UNKNOWN, /* EMBEDDED PDV */
101
+ 0, // NULL
102
+ 0, // OBJECT IDENTIFIER
103
+ B_ASN1_UNKNOWN, // ObjectDescriptor
104
+ B_ASN1_UNKNOWN, // EXTERNAL
105
+ B_ASN1_UNKNOWN, // REAL
106
+ B_ASN1_UNKNOWN, // ENUMERATED
107
+ B_ASN1_UNKNOWN, // EMBEDDED PDV
113
108
  B_ASN1_UTF8STRING,
114
- B_ASN1_UNKNOWN, /* RELATIVE-OID */
115
- B_ASN1_UNKNOWN, /* TIME */
116
- B_ASN1_UNKNOWN, /* (reserved) */
109
+ B_ASN1_UNKNOWN, // RELATIVE-OID
110
+ B_ASN1_UNKNOWN, // TIME
111
+ B_ASN1_UNKNOWN, // (reserved)
117
112
  B_ASN1_SEQUENCE,
118
- 0, /* SET */
113
+ 0, // SET
119
114
  B_ASN1_NUMERICSTRING,
120
115
  B_ASN1_PRINTABLESTRING,
121
116
  B_ASN1_T61STRING,
@@ -127,673 +122,663 @@ static const unsigned long tag2bit[31] = {
127
122
  B_ASN1_ISO64STRING,
128
123
  B_ASN1_GENERALSTRING,
129
124
  B_ASN1_UNIVERSALSTRING,
130
- B_ASN1_UNKNOWN, /* CHARACTER STRING */
125
+ B_ASN1_UNKNOWN, // CHARACTER STRING
131
126
  B_ASN1_BMPSTRING,
132
127
  };
133
128
 
134
- unsigned long ASN1_tag2bit(int tag)
135
- {
136
- if (tag < 0 || tag > 30)
137
- return 0;
138
- return tag2bit[tag];
129
+ unsigned long ASN1_tag2bit(int tag) {
130
+ if (tag < 0 || tag > 30) {
131
+ return 0;
132
+ }
133
+ return tag2bit[tag];
139
134
  }
140
135
 
141
- /* Macro to initialize and invalidate the cache */
142
-
143
- /*
144
- * Decode an ASN1 item, this currently behaves just like a standard 'd2i'
145
- * function. 'in' points to a buffer to read the data from, in future we
146
- * will have more advanced versions that can input data a piece at a time and
147
- * this will simply be a special case.
148
- */
149
-
150
- ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval,
151
- const unsigned char **in, long len,
152
- const ASN1_ITEM *it)
153
- {
154
- ASN1_VALUE *ptmpval = NULL;
155
- if (!pval)
156
- pval = &ptmpval;
157
-
158
- if (asn1_item_ex_d2i(pval, in, len, it, -1, 0, 0, 0) > 0)
159
- return *pval;
160
- return NULL;
136
+ // Macro to initialize and invalidate the cache
137
+
138
+ // Decode an ASN1 item, this currently behaves just like a standard 'd2i'
139
+ // function. 'in' points to a buffer to read the data from, in future we
140
+ // will have more advanced versions that can input data a piece at a time and
141
+ // this will simply be a special case.
142
+
143
+ ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
144
+ const ASN1_ITEM *it) {
145
+ ASN1_VALUE *ptmpval = NULL;
146
+ if (!pval) {
147
+ pval = &ptmpval;
148
+ }
149
+
150
+ if (asn1_item_ex_d2i(pval, in, len, it, -1, 0, 0, 0) > 0) {
151
+ return *pval;
152
+ }
153
+ return NULL;
161
154
  }
162
155
 
163
- /*
164
- * Decode an item, taking care of IMPLICIT tagging, if any. If 'opt' set and
165
- * tag mismatch return -1 to handle OPTIONAL
166
- */
156
+ // Decode an item, taking care of IMPLICIT tagging, if any. If 'opt' set and
157
+ // tag mismatch return -1 to handle OPTIONAL
167
158
 
168
159
  static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
169
160
  long len, const ASN1_ITEM *it, int tag, int aclass,
170
- char opt, int depth)
171
- {
172
- const ASN1_TEMPLATE *tt, *errtt = NULL;
173
- const ASN1_EXTERN_FUNCS *ef;
174
- const unsigned char *p = NULL, *q;
175
- unsigned char oclass;
176
- char cst, isopt;
177
- int i;
178
- int otag;
179
- int ret = 0;
180
- ASN1_VALUE **pchptr;
181
- int combine = aclass & ASN1_TFLG_COMBINE;
182
- aclass &= ~ASN1_TFLG_COMBINE;
183
- if (!pval)
184
- return 0;
185
-
186
- /*
187
- * Bound |len| to comfortably fit in an int. Lengths in this module often
188
- * switch between int and long without overflow checks.
189
- */
190
- if (len > INT_MAX/2) {
191
- len = INT_MAX/2;
192
- }
161
+ char opt, int depth) {
162
+ const ASN1_TEMPLATE *tt, *errtt = NULL;
163
+ const ASN1_EXTERN_FUNCS *ef;
164
+ const unsigned char *p = NULL, *q;
165
+ unsigned char oclass;
166
+ char cst, isopt;
167
+ int i;
168
+ int otag;
169
+ int ret = 0;
170
+ ASN1_VALUE **pchptr;
171
+ int combine = aclass & ASN1_TFLG_COMBINE;
172
+ aclass &= ~ASN1_TFLG_COMBINE;
173
+ if (!pval) {
174
+ return 0;
175
+ }
193
176
 
194
- if (++depth > ASN1_MAX_CONSTRUCTED_NEST) {
195
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_TOO_DEEP);
196
- goto err;
197
- }
177
+ // Bound |len| to comfortably fit in an int. Lengths in this module often
178
+ // switch between int and long without overflow checks.
179
+ if (len > INT_MAX / 2) {
180
+ len = INT_MAX / 2;
181
+ }
182
+
183
+ if (++depth > ASN1_MAX_CONSTRUCTED_NEST) {
184
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_TOO_DEEP);
185
+ goto err;
186
+ }
198
187
 
199
- switch (it->itype) {
188
+ switch (it->itype) {
200
189
  case ASN1_ITYPE_PRIMITIVE:
201
- if (it->templates) {
202
- /*
203
- * tagging or OPTIONAL is currently illegal on an item template
204
- * because the flags can't get passed down. In practice this
205
- * isn't a problem: we include the relevant flags from the item
206
- * template in the template itself.
207
- */
208
- if ((tag != -1) || opt) {
209
- OPENSSL_PUT_ERROR(ASN1,
210
- ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
211
- goto err;
212
- }
213
- return asn1_template_ex_d2i(pval, in, len,
214
- it->templates, opt, depth);
215
- }
216
- return asn1_d2i_ex_primitive(pval, in, len, it,
217
- tag, aclass, opt);
218
- break;
190
+ if (it->templates) {
191
+ // tagging or OPTIONAL is currently illegal on an item template
192
+ // because the flags can't get passed down. In practice this
193
+ // isn't a problem: we include the relevant flags from the item
194
+ // template in the template itself.
195
+ if ((tag != -1) || opt) {
196
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
197
+ goto err;
198
+ }
199
+ return asn1_template_ex_d2i(pval, in, len, it->templates, opt, depth);
200
+ }
201
+ return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt);
202
+ break;
219
203
 
220
204
  case ASN1_ITYPE_MSTRING:
221
- /*
222
- * It never makes sense for multi-strings to have implicit tagging, so
223
- * if tag != -1, then this looks like an error in the template.
224
- */
225
- if (tag != -1) {
226
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
227
- goto err;
228
- }
205
+ // It never makes sense for multi-strings to have implicit tagging, so
206
+ // if tag != -1, then this looks like an error in the template.
207
+ if (tag != -1) {
208
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
209
+ goto err;
210
+ }
229
211
 
230
- p = *in;
231
- /* Just read in tag and class */
232
- ret = asn1_check_tlen(NULL, &otag, &oclass, NULL,
233
- &p, len, -1, 0, 1);
234
- if (!ret) {
235
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
236
- goto err;
237
- }
212
+ p = *in;
213
+ // Just read in tag and class
214
+ ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, &p, len, -1, 0, 1);
215
+ if (!ret) {
216
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
217
+ goto err;
218
+ }
238
219
 
239
- /* Must be UNIVERSAL class */
240
- if (oclass != V_ASN1_UNIVERSAL) {
241
- /* If OPTIONAL, assume this is OK */
242
- if (opt)
243
- return -1;
244
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_NOT_UNIVERSAL);
245
- goto err;
220
+ // Must be UNIVERSAL class
221
+ if (oclass != V_ASN1_UNIVERSAL) {
222
+ // If OPTIONAL, assume this is OK
223
+ if (opt) {
224
+ return -1;
246
225
  }
247
- /* Check tag matches bit map */
248
- if (!(ASN1_tag2bit(otag) & it->utype)) {
249
- /* If OPTIONAL, assume this is OK */
250
- if (opt)
251
- return -1;
252
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_WRONG_TAG);
253
- goto err;
226
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_NOT_UNIVERSAL);
227
+ goto err;
228
+ }
229
+ // Check tag matches bit map
230
+ if (!(ASN1_tag2bit(otag) & it->utype)) {
231
+ // If OPTIONAL, assume this is OK
232
+ if (opt) {
233
+ return -1;
254
234
  }
255
- return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0);
235
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_MSTRING_WRONG_TAG);
236
+ goto err;
237
+ }
238
+ return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0);
256
239
 
257
240
  case ASN1_ITYPE_EXTERN:
258
- /* Use new style d2i */
259
- ef = it->funcs;
260
- return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, NULL);
241
+ // Use new style d2i
242
+ ef = it->funcs;
243
+ return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, NULL);
261
244
 
262
245
  case ASN1_ITYPE_CHOICE: {
263
- /*
264
- * It never makes sense for CHOICE types to have implicit tagging, so if
265
- * tag != -1, then this looks like an error in the template.
266
- */
267
- if (tag != -1) {
268
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
269
- goto err;
270
- }
271
-
272
- const ASN1_AUX *aux = it->funcs;
273
- ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
274
- if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
275
- goto auxerr;
276
-
277
- if (*pval) {
278
- /* Free up and zero CHOICE value if initialised */
279
- i = asn1_get_choice_selector(pval, it);
280
- if ((i >= 0) && (i < it->tcount)) {
281
- tt = it->templates + i;
282
- pchptr = asn1_get_field_ptr(pval, tt);
283
- ASN1_template_free(pchptr, tt);
284
- asn1_set_choice_selector(pval, -1, it);
285
- }
286
- } else if (!ASN1_item_ex_new(pval, it)) {
287
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
288
- goto err;
289
- }
290
- /* CHOICE type, try each possibility in turn */
291
- p = *in;
292
- for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
293
- pchptr = asn1_get_field_ptr(pval, tt);
294
- /*
295
- * We mark field as OPTIONAL so its absence can be recognised.
296
- */
297
- ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, depth);
298
- /* If field not present, try the next one */
299
- if (ret == -1)
300
- continue;
301
- /* If positive return, read OK, break loop */
302
- if (ret > 0)
303
- break;
304
- /* Otherwise must be an ASN1 parsing error */
305
- errtt = tt;
306
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
307
- goto err;
308
- }
246
+ // It never makes sense for CHOICE types to have implicit tagging, so if
247
+ // tag != -1, then this looks like an error in the template.
248
+ if (tag != -1) {
249
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
250
+ goto err;
251
+ }
252
+
253
+ const ASN1_AUX *aux = it->funcs;
254
+ ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
255
+ if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) {
256
+ goto auxerr;
257
+ }
258
+
259
+ if (*pval) {
260
+ // Free up and zero CHOICE value if initialised
261
+ i = asn1_get_choice_selector(pval, it);
262
+ if ((i >= 0) && (i < it->tcount)) {
263
+ tt = it->templates + i;
264
+ pchptr = asn1_get_field_ptr(pval, tt);
265
+ ASN1_template_free(pchptr, tt);
266
+ asn1_set_choice_selector(pval, -1, it);
267
+ }
268
+ } else if (!ASN1_item_ex_new(pval, it)) {
269
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
270
+ goto err;
271
+ }
272
+ // CHOICE type, try each possibility in turn
273
+ p = *in;
274
+ for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
275
+ pchptr = asn1_get_field_ptr(pval, tt);
276
+ // We mark field as OPTIONAL so its absence can be recognised.
277
+ ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, depth);
278
+ // If field not present, try the next one
279
+ if (ret == -1) {
280
+ continue;
281
+ }
282
+ // If positive return, read OK, break loop
283
+ if (ret > 0) {
284
+ break;
285
+ }
286
+ // Otherwise must be an ASN1 parsing error
287
+ errtt = tt;
288
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
289
+ goto err;
290
+ }
309
291
 
310
- /* Did we fall off the end without reading anything? */
311
- if (i == it->tcount) {
312
- /* If OPTIONAL, this is OK */
313
- if (opt) {
314
- /* Free and zero it */
315
- ASN1_item_ex_free(pval, it);
316
- return -1;
317
- }
318
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NO_MATCHING_CHOICE_TYPE);
319
- goto err;
292
+ // Did we fall off the end without reading anything?
293
+ if (i == it->tcount) {
294
+ // If OPTIONAL, this is OK
295
+ if (opt) {
296
+ // Free and zero it
297
+ ASN1_item_ex_free(pval, it);
298
+ return -1;
320
299
  }
321
-
322
- asn1_set_choice_selector(pval, i, it);
323
- if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
324
- goto auxerr;
325
- *in = p;
326
- return 1;
300
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NO_MATCHING_CHOICE_TYPE);
301
+ goto err;
302
+ }
303
+
304
+ asn1_set_choice_selector(pval, i, it);
305
+ if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL)) {
306
+ goto auxerr;
307
+ }
308
+ *in = p;
309
+ return 1;
327
310
  }
328
311
 
329
312
  case ASN1_ITYPE_SEQUENCE: {
330
- p = *in;
313
+ p = *in;
331
314
 
332
- /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
333
- if (tag == -1) {
334
- tag = V_ASN1_SEQUENCE;
335
- aclass = V_ASN1_UNIVERSAL;
336
- }
337
- /* Get SEQUENCE length and update len, p */
338
- ret = asn1_check_tlen(&len, NULL, NULL, &cst,
339
- &p, len, tag, aclass, opt);
340
- if (!ret) {
341
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
342
- goto err;
343
- } else if (ret == -1)
344
- return -1;
345
- if (!cst) {
346
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
347
- goto err;
348
- }
349
-
350
- if (!*pval && !ASN1_item_ex_new(pval, it)) {
351
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
352
- goto err;
353
- }
315
+ // If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL
316
+ if (tag == -1) {
317
+ tag = V_ASN1_SEQUENCE;
318
+ aclass = V_ASN1_UNIVERSAL;
319
+ }
320
+ // Get SEQUENCE length and update len, p
321
+ ret = asn1_check_tlen(&len, NULL, NULL, &cst, &p, len, tag, aclass, opt);
322
+ if (!ret) {
323
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
324
+ goto err;
325
+ } else if (ret == -1) {
326
+ return -1;
327
+ }
328
+ if (!cst) {
329
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
330
+ goto err;
331
+ }
354
332
 
355
- const ASN1_AUX *aux = it->funcs;
356
- ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
357
- if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
358
- goto auxerr;
359
-
360
- /* Free up and zero any ADB found */
361
- for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
362
- if (tt->flags & ASN1_TFLG_ADB_MASK) {
363
- const ASN1_TEMPLATE *seqtt;
364
- ASN1_VALUE **pseqval;
365
- seqtt = asn1_do_adb(pval, tt, 0);
366
- if (seqtt == NULL)
367
- continue;
368
- pseqval = asn1_get_field_ptr(pval, seqtt);
369
- ASN1_template_free(pseqval, seqtt);
370
- }
333
+ if (!*pval && !ASN1_item_ex_new(pval, it)) {
334
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
335
+ goto err;
336
+ }
337
+
338
+ const ASN1_AUX *aux = it->funcs;
339
+ ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL;
340
+ if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) {
341
+ goto auxerr;
342
+ }
343
+
344
+ // Free up and zero any ADB found
345
+ for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
346
+ if (tt->flags & ASN1_TFLG_ADB_MASK) {
347
+ const ASN1_TEMPLATE *seqtt;
348
+ ASN1_VALUE **pseqval;
349
+ seqtt = asn1_do_adb(pval, tt, 0);
350
+ if (seqtt == NULL) {
351
+ continue;
352
+ }
353
+ pseqval = asn1_get_field_ptr(pval, seqtt);
354
+ ASN1_template_free(pseqval, seqtt);
355
+ }
356
+ }
357
+
358
+ // Get each field entry
359
+ for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
360
+ const ASN1_TEMPLATE *seqtt;
361
+ ASN1_VALUE **pseqval;
362
+ seqtt = asn1_do_adb(pval, tt, 1);
363
+ if (seqtt == NULL) {
364
+ goto err;
365
+ }
366
+ pseqval = asn1_get_field_ptr(pval, seqtt);
367
+ // Have we ran out of data?
368
+ if (!len) {
369
+ break;
371
370
  }
372
-
373
- /* Get each field entry */
374
- for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
375
- const ASN1_TEMPLATE *seqtt;
376
- ASN1_VALUE **pseqval;
377
- seqtt = asn1_do_adb(pval, tt, 1);
378
- if (seqtt == NULL)
379
- goto err;
380
- pseqval = asn1_get_field_ptr(pval, seqtt);
381
- /* Have we ran out of data? */
382
- if (!len)
383
- break;
384
- q = p;
385
- /*
386
- * This determines the OPTIONAL flag value. The field cannot be
387
- * omitted if it is the last of a SEQUENCE and there is still
388
- * data to be read. This isn't strictly necessary but it
389
- * increases efficiency in some cases.
390
- */
391
- if (i == (it->tcount - 1))
392
- isopt = 0;
393
- else
394
- isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
395
- /*
396
- * attempt to read in field, allowing each to be OPTIONAL
397
- */
398
-
399
- ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, depth);
400
- if (!ret) {
401
- errtt = seqtt;
402
- goto err;
403
- } else if (ret == -1) {
404
- /*
405
- * OPTIONAL component absent. Free and zero the field.
406
- */
407
- ASN1_template_free(pseqval, seqtt);
408
- continue;
409
- }
410
- /* Update length */
411
- len -= p - q;
371
+ q = p;
372
+ // This determines the OPTIONAL flag value. The field cannot be
373
+ // omitted if it is the last of a SEQUENCE and there is still
374
+ // data to be read. This isn't strictly necessary but it
375
+ // increases efficiency in some cases.
376
+ if (i == (it->tcount - 1)) {
377
+ isopt = 0;
378
+ } else {
379
+ isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
412
380
  }
381
+ // attempt to read in field, allowing each to be OPTIONAL
413
382
 
414
- /* Check all data read */
415
- if (len) {
416
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
417
- goto err;
418
- }
383
+ ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, depth);
384
+ if (!ret) {
385
+ errtt = seqtt;
386
+ goto err;
387
+ } else if (ret == -1) {
388
+ // OPTIONAL component absent. Free and zero the field.
389
+ ASN1_template_free(pseqval, seqtt);
390
+ continue;
391
+ }
392
+ // Update length
393
+ len -= p - q;
394
+ }
419
395
 
420
- /*
421
- * If we get here we've got no more data in the SEQUENCE, however we
422
- * may not have read all fields so check all remaining are OPTIONAL
423
- * and clear any that are.
424
- */
425
- for (; i < it->tcount; tt++, i++) {
426
- const ASN1_TEMPLATE *seqtt;
427
- seqtt = asn1_do_adb(pval, tt, 1);
428
- if (seqtt == NULL)
429
- goto err;
430
- if (seqtt->flags & ASN1_TFLG_OPTIONAL) {
431
- ASN1_VALUE **pseqval;
432
- pseqval = asn1_get_field_ptr(pval, seqtt);
433
- ASN1_template_free(pseqval, seqtt);
434
- } else {
435
- errtt = seqtt;
436
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_FIELD_MISSING);
437
- goto err;
438
- }
439
- }
440
- /* Save encoding */
441
- if (!asn1_enc_save(pval, *in, p - *in, it))
442
- goto auxerr;
443
- if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL))
444
- goto auxerr;
445
- *in = p;
446
- return 1;
396
+ // Check all data read
397
+ if (len) {
398
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
399
+ goto err;
400
+ }
401
+
402
+ // If we get here we've got no more data in the SEQUENCE, however we
403
+ // may not have read all fields so check all remaining are OPTIONAL
404
+ // and clear any that are.
405
+ for (; i < it->tcount; tt++, i++) {
406
+ const ASN1_TEMPLATE *seqtt;
407
+ seqtt = asn1_do_adb(pval, tt, 1);
408
+ if (seqtt == NULL) {
409
+ goto err;
410
+ }
411
+ if (seqtt->flags & ASN1_TFLG_OPTIONAL) {
412
+ ASN1_VALUE **pseqval;
413
+ pseqval = asn1_get_field_ptr(pval, seqtt);
414
+ ASN1_template_free(pseqval, seqtt);
415
+ } else {
416
+ errtt = seqtt;
417
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_FIELD_MISSING);
418
+ goto err;
419
+ }
420
+ }
421
+ // Save encoding
422
+ if (!asn1_enc_save(pval, *in, p - *in, it)) {
423
+ goto auxerr;
424
+ }
425
+ if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it, NULL)) {
426
+ goto auxerr;
427
+ }
428
+ *in = p;
429
+ return 1;
447
430
  }
448
431
 
449
432
  default:
450
- return 0;
451
- }
452
- auxerr:
453
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_AUX_ERROR);
454
- err:
455
- if (combine == 0)
456
- ASN1_item_ex_free(pval, it);
457
- if (errtt)
458
- ERR_add_error_data(4, "Field=", errtt->field_name,
459
- ", Type=", it->sname);
460
- else
461
- ERR_add_error_data(2, "Type=", it->sname);
462
- return 0;
433
+ return 0;
434
+ }
435
+ auxerr:
436
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_AUX_ERROR);
437
+ err:
438
+ if (combine == 0) {
439
+ ASN1_item_ex_free(pval, it);
440
+ }
441
+ if (errtt) {
442
+ ERR_add_error_data(4, "Field=", errtt->field_name, ", Type=", it->sname);
443
+ } else {
444
+ ERR_add_error_data(2, "Type=", it->sname);
445
+ }
446
+ return 0;
463
447
  }
464
448
 
465
449
  int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
466
- const ASN1_ITEM *it,
467
- int tag, int aclass, char opt, ASN1_TLC *ctx)
468
- {
469
- return asn1_item_ex_d2i(pval, in, len, it, tag, aclass, opt, 0);
450
+ const ASN1_ITEM *it, int tag, int aclass, char opt,
451
+ ASN1_TLC *ctx) {
452
+ return asn1_item_ex_d2i(pval, in, len, it, tag, aclass, opt, 0);
470
453
  }
471
454
 
472
- /*
473
- * Templates are handled with two separate functions. One handles any
474
- * EXPLICIT tag and the other handles the rest.
475
- */
476
-
477
- static int asn1_template_ex_d2i(ASN1_VALUE **val,
478
- const unsigned char **in, long inlen,
479
- const ASN1_TEMPLATE *tt, char opt,
480
- int depth)
481
- {
482
- int flags, aclass;
483
- int ret;
484
- long len;
485
- const unsigned char *p, *q;
486
- if (!val)
487
- return 0;
488
- flags = tt->flags;
489
- aclass = flags & ASN1_TFLG_TAG_CLASS;
455
+ // Templates are handled with two separate functions. One handles any
456
+ // EXPLICIT tag and the other handles the rest.
457
+
458
+ static int asn1_template_ex_d2i(ASN1_VALUE **val, const unsigned char **in,
459
+ long inlen, const ASN1_TEMPLATE *tt, char opt,
460
+ int depth) {
461
+ int flags, aclass;
462
+ int ret;
463
+ long len;
464
+ const unsigned char *p, *q;
465
+ if (!val) {
466
+ return 0;
467
+ }
468
+ flags = tt->flags;
469
+ aclass = flags & ASN1_TFLG_TAG_CLASS;
490
470
 
491
- p = *in;
471
+ p = *in;
492
472
 
493
- /* Check if EXPLICIT tag expected */
494
- if (flags & ASN1_TFLG_EXPTAG) {
495
- char cst;
496
- /*
497
- * Need to work out amount of data available to the inner content and
498
- * where it starts: so read in EXPLICIT header to get the info.
499
- */
500
- ret = asn1_check_tlen(&len, NULL, NULL, &cst,
501
- &p, inlen, tt->tag, aclass, opt);
502
- q = p;
503
- if (!ret) {
504
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
505
- return 0;
506
- } else if (ret == -1)
507
- return -1;
508
- if (!cst) {
509
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
510
- return 0;
511
- }
512
- /* We've found the field so it can't be OPTIONAL now */
513
- ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, depth);
514
- if (!ret) {
515
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
516
- return 0;
517
- }
518
- /* We read the field in OK so update length */
519
- len -= p - q;
520
- /* Check for trailing data. */
521
- if (len) {
522
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_LENGTH_MISMATCH);
523
- goto err;
524
- }
525
- } else
526
- return asn1_template_noexp_d2i(val, in, inlen, tt, opt, depth);
473
+ // Check if EXPLICIT tag expected
474
+ if (flags & ASN1_TFLG_EXPTAG) {
475
+ char cst;
476
+ // Need to work out amount of data available to the inner content and
477
+ // where it starts: so read in EXPLICIT header to get the info.
478
+ ret = asn1_check_tlen(&len, NULL, NULL, &cst, &p, inlen, tt->tag, aclass,
479
+ opt);
480
+ q = p;
481
+ if (!ret) {
482
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
483
+ return 0;
484
+ } else if (ret == -1) {
485
+ return -1;
486
+ }
487
+ if (!cst) {
488
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
489
+ return 0;
490
+ }
491
+ // We've found the field so it can't be OPTIONAL now
492
+ ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, depth);
493
+ if (!ret) {
494
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
495
+ return 0;
496
+ }
497
+ // We read the field in OK so update length
498
+ len -= p - q;
499
+ // Check for trailing data.
500
+ if (len) {
501
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_LENGTH_MISMATCH);
502
+ goto err;
503
+ }
504
+ } else {
505
+ return asn1_template_noexp_d2i(val, in, inlen, tt, opt, depth);
506
+ }
527
507
 
528
- *in = p;
529
- return 1;
508
+ *in = p;
509
+ return 1;
530
510
 
531
- err:
532
- ASN1_template_free(val, tt);
533
- return 0;
511
+ err:
512
+ ASN1_template_free(val, tt);
513
+ return 0;
534
514
  }
535
515
 
536
- static int asn1_template_noexp_d2i(ASN1_VALUE **val,
537
- const unsigned char **in, long len,
538
- const ASN1_TEMPLATE *tt, char opt,
539
- int depth)
540
- {
541
- int flags, aclass;
542
- int ret;
543
- const unsigned char *p;
544
- if (!val)
545
- return 0;
546
- flags = tt->flags;
547
- aclass = flags & ASN1_TFLG_TAG_CLASS;
548
-
549
- p = *in;
550
-
551
- if (flags & ASN1_TFLG_SK_MASK) {
552
- /* SET OF, SEQUENCE OF */
553
- int sktag, skaclass;
554
- /* First work out expected inner tag value */
555
- if (flags & ASN1_TFLG_IMPTAG) {
556
- sktag = tt->tag;
557
- skaclass = aclass;
558
- } else {
559
- skaclass = V_ASN1_UNIVERSAL;
560
- if (flags & ASN1_TFLG_SET_OF)
561
- sktag = V_ASN1_SET;
562
- else
563
- sktag = V_ASN1_SEQUENCE;
564
- }
565
- /* Get the tag */
566
- ret = asn1_check_tlen(&len, NULL, NULL, NULL,
567
- &p, len, sktag, skaclass, opt);
568
- if (!ret) {
569
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
570
- return 0;
571
- } else if (ret == -1)
572
- return -1;
573
- if (!*val)
574
- *val = (ASN1_VALUE *)sk_ASN1_VALUE_new_null();
575
- else {
576
- /*
577
- * We've got a valid STACK: free up any items present
578
- */
579
- STACK_OF(ASN1_VALUE) *sktmp = (STACK_OF(ASN1_VALUE) *)*val;
580
- ASN1_VALUE *vtmp;
581
- while (sk_ASN1_VALUE_num(sktmp) > 0) {
582
- vtmp = sk_ASN1_VALUE_pop(sktmp);
583
- ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
584
- }
585
- }
516
+ static int asn1_template_noexp_d2i(ASN1_VALUE **val, const unsigned char **in,
517
+ long len, const ASN1_TEMPLATE *tt, char opt,
518
+ int depth) {
519
+ int flags, aclass;
520
+ int ret;
521
+ const unsigned char *p;
522
+ if (!val) {
523
+ return 0;
524
+ }
525
+ flags = tt->flags;
526
+ aclass = flags & ASN1_TFLG_TAG_CLASS;
527
+
528
+ p = *in;
529
+
530
+ if (flags & ASN1_TFLG_SK_MASK) {
531
+ // SET OF, SEQUENCE OF
532
+ int sktag, skaclass;
533
+ // First work out expected inner tag value
534
+ if (flags & ASN1_TFLG_IMPTAG) {
535
+ sktag = tt->tag;
536
+ skaclass = aclass;
537
+ } else {
538
+ skaclass = V_ASN1_UNIVERSAL;
539
+ if (flags & ASN1_TFLG_SET_OF) {
540
+ sktag = V_ASN1_SET;
541
+ } else {
542
+ sktag = V_ASN1_SEQUENCE;
543
+ }
544
+ }
545
+ // Get the tag
546
+ ret =
547
+ asn1_check_tlen(&len, NULL, NULL, NULL, &p, len, sktag, skaclass, opt);
548
+ if (!ret) {
549
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
550
+ return 0;
551
+ } else if (ret == -1) {
552
+ return -1;
553
+ }
554
+ if (!*val) {
555
+ *val = (ASN1_VALUE *)sk_ASN1_VALUE_new_null();
556
+ } else {
557
+ // We've got a valid STACK: free up any items present
558
+ STACK_OF(ASN1_VALUE) *sktmp = (STACK_OF(ASN1_VALUE) *)*val;
559
+ ASN1_VALUE *vtmp;
560
+ while (sk_ASN1_VALUE_num(sktmp) > 0) {
561
+ vtmp = sk_ASN1_VALUE_pop(sktmp);
562
+ ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
563
+ }
564
+ }
586
565
 
587
- if (!*val) {
588
- OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
589
- goto err;
590
- }
566
+ if (!*val) {
567
+ OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
568
+ goto err;
569
+ }
591
570
 
592
- /* Read as many items as we can */
593
- while (len > 0) {
594
- ASN1_VALUE *skfield;
595
- const unsigned char *q = p;
596
- skfield = NULL;
597
- if (!asn1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item),
598
- -1, 0, 0, depth)) {
599
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
600
- goto err;
601
- }
602
- len -= p - q;
603
- if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, skfield)) {
604
- ASN1_item_ex_free(&skfield, ASN1_ITEM_ptr(tt->item));
605
- OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
606
- goto err;
607
- }
608
- }
609
- } else if (flags & ASN1_TFLG_IMPTAG) {
610
- /* IMPLICIT tagging */
611
- ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag,
612
- aclass, opt, depth);
613
- if (!ret) {
614
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
615
- goto err;
616
- } else if (ret == -1)
617
- return -1;
618
- } else {
619
- /* Nothing special */
620
- ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item),
621
- -1, tt->flags & ASN1_TFLG_COMBINE, opt,
622
- depth);
623
- if (!ret) {
624
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
625
- goto err;
626
- } else if (ret == -1)
627
- return -1;
571
+ // Read as many items as we can
572
+ while (len > 0) {
573
+ ASN1_VALUE *skfield;
574
+ const unsigned char *q = p;
575
+ skfield = NULL;
576
+ if (!asn1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0,
577
+ 0, depth)) {
578
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
579
+ goto err;
580
+ }
581
+ len -= p - q;
582
+ if (!sk_ASN1_VALUE_push((STACK_OF(ASN1_VALUE) *)*val, skfield)) {
583
+ ASN1_item_ex_free(&skfield, ASN1_ITEM_ptr(tt->item));
584
+ OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
585
+ goto err;
586
+ }
587
+ }
588
+ } else if (flags & ASN1_TFLG_IMPTAG) {
589
+ // IMPLICIT tagging
590
+ ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag,
591
+ aclass, opt, depth);
592
+ if (!ret) {
593
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
594
+ goto err;
595
+ } else if (ret == -1) {
596
+ return -1;
597
+ }
598
+ } else {
599
+ // Nothing special
600
+ ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1,
601
+ tt->flags & ASN1_TFLG_COMBINE, opt, depth);
602
+ if (!ret) {
603
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
604
+ goto err;
605
+ } else if (ret == -1) {
606
+ return -1;
628
607
  }
608
+ }
629
609
 
630
- *in = p;
631
- return 1;
610
+ *in = p;
611
+ return 1;
632
612
 
633
- err:
634
- ASN1_template_free(val, tt);
635
- return 0;
613
+ err:
614
+ ASN1_template_free(val, tt);
615
+ return 0;
636
616
  }
637
617
 
638
- static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
639
- const unsigned char **in, long inlen,
640
- const ASN1_ITEM *it,
641
- int tag, int aclass, char opt)
642
- {
643
- int ret = 0, utype;
644
- long plen;
645
- char cst;
646
- const unsigned char *p;
647
- const unsigned char *cont = NULL;
648
- long len;
649
- if (!pval) {
650
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_NULL);
651
- return 0; /* Should never happen */
652
- }
653
-
654
- if (it->itype == ASN1_ITYPE_MSTRING) {
655
- utype = tag;
656
- tag = -1;
657
- } else
658
- utype = it->utype;
659
-
660
- if (utype == V_ASN1_ANY) {
661
- /* If type is ANY need to figure out type from tag */
662
- unsigned char oclass;
663
- if (tag >= 0) {
664
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_TAGGED_ANY);
665
- return 0;
666
- }
667
- if (opt) {
668
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONAL_ANY);
669
- return 0;
670
- }
671
- p = *in;
672
- ret = asn1_check_tlen(NULL, &utype, &oclass, NULL,
673
- &p, inlen, -1, 0, 0);
674
- if (!ret) {
675
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
676
- return 0;
677
- }
678
- if (oclass != V_ASN1_UNIVERSAL)
679
- utype = V_ASN1_OTHER;
618
+ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in,
619
+ long inlen, const ASN1_ITEM *it, int tag,
620
+ int aclass, char opt) {
621
+ int ret = 0, utype;
622
+ long plen;
623
+ char cst;
624
+ const unsigned char *p;
625
+ const unsigned char *cont = NULL;
626
+ long len;
627
+ if (!pval) {
628
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_NULL);
629
+ return 0; // Should never happen
630
+ }
631
+
632
+ if (it->itype == ASN1_ITYPE_MSTRING) {
633
+ utype = tag;
634
+ tag = -1;
635
+ } else {
636
+ utype = it->utype;
637
+ }
638
+
639
+ if (utype == V_ASN1_ANY) {
640
+ // If type is ANY need to figure out type from tag
641
+ unsigned char oclass;
642
+ if (tag >= 0) {
643
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_TAGGED_ANY);
644
+ return 0;
680
645
  }
681
- if (tag == -1) {
682
- tag = utype;
683
- aclass = V_ASN1_UNIVERSAL;
646
+ if (opt) {
647
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OPTIONAL_ANY);
648
+ return 0;
684
649
  }
685
650
  p = *in;
686
- /* Check header */
687
- ret = asn1_check_tlen(&plen, NULL, NULL, &cst,
688
- &p, inlen, tag, aclass, opt);
651
+ ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, &p, inlen, -1, 0, 0);
689
652
  if (!ret) {
690
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
691
- return 0;
692
- } else if (ret == -1)
693
- return -1;
694
- ret = 0;
695
- /* SEQUENCE, SET and "OTHER" are left in encoded form */
696
- if ((utype == V_ASN1_SEQUENCE)
697
- || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
698
- /* SEQUENCE and SET must be constructed */
699
- if (utype != V_ASN1_OTHER && !cst) {
700
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_CONSTRUCTED);
701
- return 0;
702
- }
703
-
704
- cont = *in;
705
- len = p - cont + plen;
706
- p += plen;
707
- } else if (cst) {
708
- /* This parser historically supported BER constructed strings. We no
709
- * longer do and will gradually tighten this parser into a DER
710
- * parser. BER types should use |CBS_asn1_ber_to_der|. */
711
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
712
- return 0;
713
- } else {
714
- cont = p;
715
- len = plen;
716
- p += plen;
653
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
654
+ return 0;
655
+ }
656
+ if (oclass != V_ASN1_UNIVERSAL) {
657
+ utype = V_ASN1_OTHER;
658
+ }
659
+ }
660
+ if (tag == -1) {
661
+ tag = utype;
662
+ aclass = V_ASN1_UNIVERSAL;
663
+ }
664
+ p = *in;
665
+ // Check header
666
+ ret = asn1_check_tlen(&plen, NULL, NULL, &cst, &p, inlen, tag, aclass, opt);
667
+ if (!ret) {
668
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
669
+ return 0;
670
+ } else if (ret == -1) {
671
+ return -1;
672
+ }
673
+ ret = 0;
674
+ // SEQUENCE, SET and "OTHER" are left in encoded form
675
+ if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
676
+ (utype == V_ASN1_OTHER)) {
677
+ // SEQUENCE and SET must be constructed
678
+ if (utype != V_ASN1_OTHER && !cst) {
679
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_CONSTRUCTED);
680
+ return 0;
717
681
  }
718
682
 
719
- /* We now have content length and type: translate into a structure */
720
- if (!asn1_ex_c2i(pval, cont, len, utype, it))
721
- goto err;
722
-
723
- *in = p;
724
- ret = 1;
725
- err:
726
- return ret;
683
+ cont = *in;
684
+ len = p - cont + plen;
685
+ p += plen;
686
+ } else if (cst) {
687
+ // This parser historically supported BER constructed strings. We no
688
+ // longer do and will gradually tighten this parser into a DER
689
+ // parser. BER types should use |CBS_asn1_ber_to_der|.
690
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
691
+ return 0;
692
+ } else {
693
+ cont = p;
694
+ len = plen;
695
+ p += plen;
696
+ }
697
+
698
+ // We now have content length and type: translate into a structure
699
+ if (!asn1_ex_c2i(pval, cont, len, utype, it)) {
700
+ goto err;
701
+ }
702
+
703
+ *in = p;
704
+ ret = 1;
705
+ err:
706
+ return ret;
727
707
  }
728
708
 
729
- /* Translate ASN1 content octets into a structure */
709
+ // Translate ASN1 content octets into a structure
730
710
 
731
711
  static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
732
- int utype, const ASN1_ITEM *it)
733
- {
734
- ASN1_VALUE **opval = NULL;
735
- ASN1_STRING *stmp;
736
- ASN1_TYPE *typ = NULL;
737
- int ret = 0;
738
- ASN1_INTEGER **tint;
739
-
740
- /* Historically, |it->funcs| for primitive types contained an
741
- * |ASN1_PRIMITIVE_FUNCS| table of callbacks. */
742
- assert(it->funcs == NULL);
743
-
744
- /* If ANY type clear type and set pointer to internal value */
745
- if (it->utype == V_ASN1_ANY) {
746
- if (!*pval) {
747
- typ = ASN1_TYPE_new();
748
- if (typ == NULL)
749
- goto err;
750
- *pval = (ASN1_VALUE *)typ;
751
- } else
752
- typ = (ASN1_TYPE *)*pval;
753
-
754
- if (utype != typ->type)
755
- ASN1_TYPE_set(typ, utype, NULL);
756
- opval = pval;
757
- pval = &typ->value.asn1_value;
712
+ int utype, const ASN1_ITEM *it) {
713
+ ASN1_VALUE **opval = NULL;
714
+ ASN1_STRING *stmp;
715
+ ASN1_TYPE *typ = NULL;
716
+ int ret = 0;
717
+ ASN1_INTEGER **tint;
718
+
719
+ // Historically, |it->funcs| for primitive types contained an
720
+ // |ASN1_PRIMITIVE_FUNCS| table of callbacks.
721
+ assert(it->funcs == NULL);
722
+
723
+ // If ANY type clear type and set pointer to internal value
724
+ if (it->utype == V_ASN1_ANY) {
725
+ if (!*pval) {
726
+ typ = ASN1_TYPE_new();
727
+ if (typ == NULL) {
728
+ goto err;
729
+ }
730
+ *pval = (ASN1_VALUE *)typ;
731
+ } else {
732
+ typ = (ASN1_TYPE *)*pval;
758
733
  }
759
- switch (utype) {
734
+
735
+ if (utype != typ->type) {
736
+ ASN1_TYPE_set(typ, utype, NULL);
737
+ }
738
+ opval = pval;
739
+ pval = &typ->value.asn1_value;
740
+ }
741
+ switch (utype) {
760
742
  case V_ASN1_OBJECT:
761
- if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len))
762
- goto err;
763
- break;
743
+ if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) {
744
+ goto err;
745
+ }
746
+ break;
764
747
 
765
748
  case V_ASN1_NULL:
766
- if (len) {
767
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_NULL_IS_WRONG_LENGTH);
768
- goto err;
769
- }
770
- *pval = (ASN1_VALUE *)1;
771
- break;
749
+ if (len) {
750
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_NULL_IS_WRONG_LENGTH);
751
+ goto err;
752
+ }
753
+ *pval = (ASN1_VALUE *)1;
754
+ break;
772
755
 
773
756
  case V_ASN1_BOOLEAN:
774
- if (len != 1) {
775
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
776
- goto err;
777
- } else {
778
- ASN1_BOOLEAN *tbool;
779
- tbool = (ASN1_BOOLEAN *)pval;
780
- *tbool = *cont;
781
- }
782
- break;
757
+ if (len != 1) {
758
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
759
+ goto err;
760
+ } else {
761
+ ASN1_BOOLEAN *tbool;
762
+ tbool = (ASN1_BOOLEAN *)pval;
763
+ *tbool = *cont;
764
+ }
765
+ break;
783
766
 
784
767
  case V_ASN1_BIT_STRING:
785
- if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len))
786
- goto err;
787
- break;
768
+ if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) {
769
+ goto err;
770
+ }
771
+ break;
788
772
 
789
773
  case V_ASN1_INTEGER:
790
774
  case V_ASN1_ENUMERATED:
791
- tint = (ASN1_INTEGER **)pval;
792
- if (!c2i_ASN1_INTEGER(tint, &cont, len))
793
- goto err;
794
- /* Fixup type to match the expected form */
795
- (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
796
- break;
775
+ tint = (ASN1_INTEGER **)pval;
776
+ if (!c2i_ASN1_INTEGER(tint, &cont, len)) {
777
+ goto err;
778
+ }
779
+ // Fixup type to match the expected form
780
+ (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
781
+ break;
797
782
 
798
783
  case V_ASN1_OCTET_STRING:
799
784
  case V_ASN1_NUMERICSTRING:
@@ -813,92 +798,111 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
813
798
  case V_ASN1_SET:
814
799
  case V_ASN1_SEQUENCE:
815
800
  default:
816
- if (utype == V_ASN1_BMPSTRING && (len & 1)) {
817
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
818
- goto err;
819
- }
820
- if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) {
821
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
822
- goto err;
823
- }
824
- /* All based on ASN1_STRING and handled the same */
825
- if (!*pval) {
826
- stmp = ASN1_STRING_type_new(utype);
827
- if (!stmp) {
828
- OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
829
- goto err;
830
- }
831
- *pval = (ASN1_VALUE *)stmp;
832
- } else {
833
- stmp = (ASN1_STRING *)*pval;
834
- stmp->type = utype;
835
- }
836
- if (!ASN1_STRING_set(stmp, cont, len)) {
837
- OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
838
- ASN1_STRING_free(stmp);
839
- *pval = NULL;
840
- goto err;
841
- }
842
- break;
843
- }
844
- /* If ASN1_ANY and NULL type fix up value */
845
- if (typ && (utype == V_ASN1_NULL))
846
- typ->value.ptr = NULL;
847
-
848
- ret = 1;
849
- err:
850
- if (!ret) {
851
- ASN1_TYPE_free(typ);
852
- if (opval)
853
- *opval = NULL;
801
+ if (utype == V_ASN1_BMPSTRING && (len & 1)) {
802
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_BMPSTRING_IS_WRONG_LENGTH);
803
+ goto err;
804
+ }
805
+ if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) {
806
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH);
807
+ goto err;
808
+ }
809
+ if (utype == V_ASN1_UTCTIME) {
810
+ CBS cbs;
811
+ CBS_init(&cbs, cont, (size_t)len);
812
+ if (!CBS_parse_utc_time(&cbs, NULL, /*allow_timezone_offset=*/1)) {
813
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_TIME_FORMAT);
814
+ goto err;
815
+ }
816
+ }
817
+ if (utype == V_ASN1_GENERALIZEDTIME) {
818
+ CBS cbs;
819
+ CBS_init(&cbs, cont, (size_t)len);
820
+ if (!CBS_parse_generalized_time(&cbs, NULL,
821
+ /*allow_timezone_offset=*/0)) {
822
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_TIME_FORMAT);
823
+ goto err;
824
+ }
825
+ }
826
+ // All based on ASN1_STRING and handled the same
827
+ if (!*pval) {
828
+ stmp = ASN1_STRING_type_new(utype);
829
+ if (!stmp) {
830
+ OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
831
+ goto err;
832
+ }
833
+ *pval = (ASN1_VALUE *)stmp;
834
+ } else {
835
+ stmp = (ASN1_STRING *)*pval;
836
+ stmp->type = utype;
837
+ }
838
+ if (!ASN1_STRING_set(stmp, cont, len)) {
839
+ OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
840
+ ASN1_STRING_free(stmp);
841
+ *pval = NULL;
842
+ goto err;
843
+ }
844
+ break;
845
+ }
846
+ // If ASN1_ANY and NULL type fix up value
847
+ if (typ && (utype == V_ASN1_NULL)) {
848
+ typ->value.ptr = NULL;
849
+ }
850
+
851
+ ret = 1;
852
+ err:
853
+ if (!ret) {
854
+ ASN1_TYPE_free(typ);
855
+ if (opval) {
856
+ *opval = NULL;
854
857
  }
855
- return ret;
858
+ }
859
+ return ret;
856
860
  }
857
861
 
858
- /*
859
- * Check an ASN1 tag and length: a bit like ASN1_get_object but it
860
- * checks the expected tag.
861
- */
862
+ // Check an ASN1 tag and length: a bit like ASN1_get_object but it
863
+ // checks the expected tag.
862
864
 
863
865
  static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
864
866
  char *cst, const unsigned char **in, long len,
865
- int exptag, int expclass, char opt)
866
- {
867
- int i;
868
- int ptag, pclass;
869
- long plen;
870
- const unsigned char *p;
871
- p = *in;
872
-
873
- i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
874
- if (i & 0x80) {
875
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_OBJECT_HEADER);
876
- return 0;
877
- }
878
- if (exptag >= 0) {
879
- if ((exptag != ptag) || (expclass != pclass)) {
880
- /*
881
- * If type is OPTIONAL, not an error: indicate missing type.
882
- */
883
- if (opt)
884
- return -1;
885
- OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TAG);
886
- return 0;
887
- }
867
+ int exptag, int expclass, char opt) {
868
+ int i;
869
+ int ptag, pclass;
870
+ long plen;
871
+ const unsigned char *p;
872
+ p = *in;
873
+
874
+ i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
875
+ if (i & 0x80) {
876
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_OBJECT_HEADER);
877
+ return 0;
878
+ }
879
+ if (exptag >= 0) {
880
+ if ((exptag != ptag) || (expclass != pclass)) {
881
+ // If type is OPTIONAL, not an error: indicate missing type.
882
+ if (opt) {
883
+ return -1;
884
+ }
885
+ OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TAG);
886
+ return 0;
888
887
  }
888
+ }
889
889
 
890
- if (cst)
891
- *cst = i & V_ASN1_CONSTRUCTED;
890
+ if (cst) {
891
+ *cst = i & V_ASN1_CONSTRUCTED;
892
+ }
892
893
 
893
- if (olen)
894
- *olen = plen;
894
+ if (olen) {
895
+ *olen = plen;
896
+ }
895
897
 
896
- if (oclass)
897
- *oclass = pclass;
898
+ if (oclass) {
899
+ *oclass = pclass;
900
+ }
898
901
 
899
- if (otag)
900
- *otag = ptag;
902
+ if (otag) {
903
+ *otag = ptag;
904
+ }
901
905
 
902
- *in = p;
903
- return 1;
906
+ *in = p;
907
+ return 1;
904
908
  }