@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
@@ -69,406 +69,397 @@
69
69
  #include "../x509/internal.h"
70
70
  #include "internal.h"
71
71
 
72
- /*
73
- * Enable this to print out the complete policy tree at various point during
74
- * evaluation.
75
- */
72
+ // Enable this to print out the complete policy tree at various point during
73
+ // evaluation.
76
74
 
77
- /*
78
- * #define OPENSSL_POLICY_DEBUG
79
- */
75
+ // #define OPENSSL_POLICY_DEBUG
80
76
 
81
77
  #ifdef OPENSSL_POLICY_DEBUG
82
78
 
83
79
  static void expected_print(BIO *err, X509_POLICY_LEVEL *lev,
84
- X509_POLICY_NODE *node, int indent)
85
- {
86
- if ((lev->flags & X509_V_FLAG_INHIBIT_MAP)
87
- || !(node->data->flags & POLICY_DATA_FLAG_MAP_MASK))
88
- BIO_puts(err, " Not Mapped\n");
89
- else {
90
- int i;
91
- STACK_OF(ASN1_OBJECT) *pset = node->data->expected_policy_set;
92
- ASN1_OBJECT *oid;
93
- BIO_puts(err, " Expected: ");
94
- for (i = 0; i < sk_ASN1_OBJECT_num(pset); i++) {
95
- oid = sk_ASN1_OBJECT_value(pset, i);
96
- if (i)
97
- BIO_puts(err, ", ");
98
- i2a_ASN1_OBJECT(err, oid);
99
- }
100
- BIO_puts(err, "\n");
80
+ X509_POLICY_NODE *node, int indent) {
81
+ if ((lev->flags & X509_V_FLAG_INHIBIT_MAP) ||
82
+ !(node->data->flags & POLICY_DATA_FLAG_MAP_MASK)) {
83
+ BIO_puts(err, " Not Mapped\n");
84
+ } else {
85
+ int i;
86
+ STACK_OF(ASN1_OBJECT) *pset = node->data->expected_policy_set;
87
+ ASN1_OBJECT *oid;
88
+ BIO_puts(err, " Expected: ");
89
+ for (i = 0; i < sk_ASN1_OBJECT_num(pset); i++) {
90
+ oid = sk_ASN1_OBJECT_value(pset, i);
91
+ if (i) {
92
+ BIO_puts(err, ", ");
93
+ }
94
+ i2a_ASN1_OBJECT(err, oid);
101
95
  }
96
+ BIO_puts(err, "\n");
97
+ }
102
98
  }
103
99
 
104
100
  static void tree_print(char *str, X509_POLICY_TREE *tree,
105
- X509_POLICY_LEVEL *curr)
106
- {
107
- X509_POLICY_LEVEL *plev;
108
- X509_POLICY_NODE *node;
109
- int i;
110
- BIO *err;
111
- err = BIO_new_fp(stderr, BIO_NOCLOSE);
112
- if (!curr)
113
- curr = tree->levels + tree->nlevel;
114
- else
115
- curr++;
116
- BIO_printf(err, "Level print after %s\n", str);
117
- BIO_printf(err, "Printing Up to Level %ld\n", curr - tree->levels);
118
- for (plev = tree->levels; plev != curr; plev++) {
119
- BIO_printf(err, "Level %ld, flags = %x\n",
120
- plev - tree->levels, plev->flags);
121
- for (i = 0; i < sk_X509_POLICY_NODE_num(plev->nodes); i++) {
122
- node = sk_X509_POLICY_NODE_value(plev->nodes, i);
123
- X509_POLICY_NODE_print(err, node, 2);
124
- expected_print(err, plev, node, 2);
125
- BIO_printf(err, " Flags: %x\n", node->data->flags);
126
- }
127
- if (plev->anyPolicy)
128
- X509_POLICY_NODE_print(err, plev->anyPolicy, 2);
101
+ X509_POLICY_LEVEL *curr) {
102
+ X509_POLICY_LEVEL *plev;
103
+ X509_POLICY_NODE *node;
104
+ int i;
105
+ BIO *err;
106
+ err = BIO_new_fp(stderr, BIO_NOCLOSE);
107
+ if (!curr) {
108
+ curr = tree->levels + tree->nlevel;
109
+ } else {
110
+ curr++;
111
+ }
112
+ BIO_printf(err, "Level print after %s\n", str);
113
+ BIO_printf(err, "Printing Up to Level %ld\n", curr - tree->levels);
114
+ for (plev = tree->levels; plev != curr; plev++) {
115
+ BIO_printf(err, "Level %ld, flags = %x\n", plev - tree->levels,
116
+ plev->flags);
117
+ for (i = 0; i < sk_X509_POLICY_NODE_num(plev->nodes); i++) {
118
+ node = sk_X509_POLICY_NODE_value(plev->nodes, i);
119
+ X509_POLICY_NODE_print(err, node, 2);
120
+ expected_print(err, plev, node, 2);
121
+ BIO_printf(err, " Flags: %x\n", node->data->flags);
129
122
  }
123
+ if (plev->anyPolicy) {
124
+ X509_POLICY_NODE_print(err, plev->anyPolicy, 2);
125
+ }
126
+ }
130
127
 
131
- BIO_free(err);
132
-
128
+ BIO_free(err);
133
129
  }
134
130
  #else
135
131
 
136
- # define tree_print(a,b,c) /* */
132
+ #define tree_print(a, b, c) //
137
133
 
138
134
  #endif
139
135
 
140
- /*-
141
- * Initialize policy tree. Return values:
142
- * 0 Some internal error occurred.
143
- * -1 Inconsistent or invalid extensions in certificates.
144
- * 1 Tree initialized OK.
145
- * 2 Policy tree is empty.
146
- * 5 Tree OK and requireExplicitPolicy true.
147
- * 6 Tree empty and requireExplicitPolicy true.
148
- */
136
+ //-
137
+ // Initialize policy tree. Return values:
138
+ // 0 Some internal error occurred.
139
+ // -1 Inconsistent or invalid extensions in certificates.
140
+ // 1 Tree initialized OK.
141
+ // 2 Policy tree is empty.
142
+ // 5 Tree OK and requireExplicitPolicy true.
143
+ // 6 Tree empty and requireExplicitPolicy true.
149
144
 
150
145
  static int tree_init(X509_POLICY_TREE **ptree, STACK_OF(X509) *certs,
151
- unsigned int flags)
152
- {
153
- X509_POLICY_TREE *tree;
154
- X509_POLICY_LEVEL *level;
155
- const X509_POLICY_CACHE *cache;
156
- X509_POLICY_DATA *data = NULL;
157
- X509 *x;
158
- int ret = 1;
159
- int i, n;
160
- int explicit_policy;
161
- int any_skip;
162
- int map_skip;
163
- *ptree = NULL;
164
- n = sk_X509_num(certs);
146
+ unsigned int flags) {
147
+ X509_POLICY_TREE *tree;
148
+ X509_POLICY_LEVEL *level;
149
+ const X509_POLICY_CACHE *cache;
150
+ X509_POLICY_DATA *data = NULL;
151
+ X509 *x;
152
+ int ret = 1;
153
+ int i, n;
154
+ int explicit_policy;
155
+ int any_skip;
156
+ int map_skip;
157
+ *ptree = NULL;
158
+ n = sk_X509_num(certs);
165
159
 
166
160
  #if 0
167
- /* Disable policy mapping for now... */
161
+ // Disable policy mapping for now...
168
162
  flags |= X509_V_FLAG_INHIBIT_MAP;
169
163
  #endif
170
164
 
171
- if (flags & X509_V_FLAG_EXPLICIT_POLICY)
172
- explicit_policy = 0;
173
- else
174
- explicit_policy = n + 1;
175
-
176
- if (flags & X509_V_FLAG_INHIBIT_ANY)
177
- any_skip = 0;
178
- else
179
- any_skip = n + 1;
180
-
181
- if (flags & X509_V_FLAG_INHIBIT_MAP)
182
- map_skip = 0;
183
- else
184
- map_skip = n + 1;
185
-
186
- /* Can't do anything with just a trust anchor */
187
- if (n == 1)
188
- return 1;
189
- /*
190
- * First setup policy cache in all certificates apart from the trust
191
- * anchor. Note any bad cache results on the way. Also can calculate
192
- * explicit_policy value at this point.
193
- */
194
- for (i = n - 2; i >= 0; i--) {
195
- x = sk_X509_value(certs, i);
196
- X509_check_purpose(x, -1, -1);
197
- cache = policy_cache_set(x);
198
- /* If cache NULL something bad happened: return immediately */
199
- if (cache == NULL)
200
- return 0;
201
- /*
202
- * If inconsistent extensions keep a note of it but continue
203
- */
204
- if (x->ex_flags & EXFLAG_INVALID_POLICY)
205
- ret = -1;
206
- /*
207
- * Otherwise if we have no data (hence no CertificatePolicies) and
208
- * haven't already set an inconsistent code note it.
209
- */
210
- else if ((ret == 1) && !cache->data)
211
- ret = 2;
212
- if (explicit_policy > 0) {
213
- if (!(x->ex_flags & EXFLAG_SI))
214
- explicit_policy--;
215
- if ((cache->explicit_skip != -1)
216
- && (cache->explicit_skip < explicit_policy))
217
- explicit_policy = cache->explicit_skip;
218
- }
165
+ if (flags & X509_V_FLAG_EXPLICIT_POLICY) {
166
+ explicit_policy = 0;
167
+ } else {
168
+ explicit_policy = n + 1;
169
+ }
170
+
171
+ if (flags & X509_V_FLAG_INHIBIT_ANY) {
172
+ any_skip = 0;
173
+ } else {
174
+ any_skip = n + 1;
175
+ }
176
+
177
+ if (flags & X509_V_FLAG_INHIBIT_MAP) {
178
+ map_skip = 0;
179
+ } else {
180
+ map_skip = n + 1;
181
+ }
182
+
183
+ // Can't do anything with just a trust anchor
184
+ if (n == 1) {
185
+ return 1;
186
+ }
187
+ // First setup policy cache in all certificates apart from the trust
188
+ // anchor. Note any bad cache results on the way. Also can calculate
189
+ // explicit_policy value at this point.
190
+ for (i = n - 2; i >= 0; i--) {
191
+ x = sk_X509_value(certs, i);
192
+ X509_check_purpose(x, -1, -1);
193
+ cache = policy_cache_set(x);
194
+ // If cache NULL something bad happened: return immediately
195
+ if (cache == NULL) {
196
+ return 0;
219
197
  }
220
-
221
- if (ret != 1) {
222
- if (ret == 2 && !explicit_policy)
223
- return 6;
224
- return ret;
198
+ // If inconsistent extensions keep a note of it but continue
199
+ if (x->ex_flags & EXFLAG_INVALID_POLICY) {
200
+ ret = -1;
225
201
  }
202
+ // Otherwise if we have no data (hence no CertificatePolicies) and
203
+ // haven't already set an inconsistent code note it.
204
+ else if ((ret == 1) && !cache->data) {
205
+ ret = 2;
206
+ }
207
+ if (explicit_policy > 0) {
208
+ if (!(x->ex_flags & EXFLAG_SI)) {
209
+ explicit_policy--;
210
+ }
211
+ if ((cache->explicit_skip != -1) &&
212
+ (cache->explicit_skip < explicit_policy)) {
213
+ explicit_policy = cache->explicit_skip;
214
+ }
215
+ }
216
+ }
226
217
 
227
- /* If we get this far initialize the tree */
228
-
229
- tree = OPENSSL_malloc(sizeof(X509_POLICY_TREE));
218
+ if (ret != 1) {
219
+ if (ret == 2 && !explicit_policy) {
220
+ return 6;
221
+ }
222
+ return ret;
223
+ }
230
224
 
231
- if (!tree)
232
- return 0;
225
+ // If we get this far initialize the tree
233
226
 
234
- tree->flags = 0;
235
- tree->levels = OPENSSL_malloc(sizeof(X509_POLICY_LEVEL) * n);
236
- tree->nlevel = 0;
237
- tree->extra_data = NULL;
238
- tree->auth_policies = NULL;
239
- tree->user_policies = NULL;
227
+ tree = OPENSSL_malloc(sizeof(X509_POLICY_TREE));
240
228
 
241
- if (!tree->levels) {
242
- OPENSSL_free(tree);
243
- return 0;
244
- }
229
+ if (!tree) {
230
+ return 0;
231
+ }
245
232
 
246
- OPENSSL_memset(tree->levels, 0, n * sizeof(X509_POLICY_LEVEL));
233
+ tree->flags = 0;
234
+ tree->levels = OPENSSL_malloc(sizeof(X509_POLICY_LEVEL) * n);
235
+ tree->nlevel = 0;
236
+ tree->extra_data = NULL;
237
+ tree->auth_policies = NULL;
238
+ tree->user_policies = NULL;
247
239
 
248
- tree->nlevel = n;
240
+ if (!tree->levels) {
241
+ OPENSSL_free(tree);
242
+ return 0;
243
+ }
249
244
 
250
- level = tree->levels;
245
+ OPENSSL_memset(tree->levels, 0, n * sizeof(X509_POLICY_LEVEL));
251
246
 
252
- /* Root data: initialize to anyPolicy */
247
+ tree->nlevel = n;
253
248
 
254
- data = policy_data_new(NULL, OBJ_nid2obj(NID_any_policy), 0);
249
+ level = tree->levels;
255
250
 
256
- if (!data || !level_add_node(level, data, NULL, tree))
257
- goto bad_tree;
251
+ // Root data: initialize to anyPolicy
258
252
 
259
- for (i = n - 2; i >= 0; i--) {
260
- level++;
261
- x = sk_X509_value(certs, i);
262
- cache = policy_cache_set(x);
263
- X509_up_ref(x);
264
- level->cert = x;
253
+ data = policy_data_new(NULL, OBJ_nid2obj(NID_any_policy), 0);
265
254
 
266
- if (!cache->anyPolicy)
267
- level->flags |= X509_V_FLAG_INHIBIT_ANY;
255
+ if (!data || !level_add_node(level, data, NULL, tree)) {
256
+ goto bad_tree;
257
+ }
268
258
 
269
- /* Determine inhibit any and inhibit map flags */
270
- if (any_skip == 0) {
271
- /*
272
- * Any matching allowed if certificate is self issued and not the
273
- * last in the chain.
274
- */
275
- if (!(x->ex_flags & EXFLAG_SI) || (i == 0))
276
- level->flags |= X509_V_FLAG_INHIBIT_ANY;
277
- } else {
278
- if (!(x->ex_flags & EXFLAG_SI))
279
- any_skip--;
280
- if ((cache->any_skip >= 0)
281
- && (cache->any_skip < any_skip))
282
- any_skip = cache->any_skip;
283
- }
259
+ for (i = n - 2; i >= 0; i--) {
260
+ level++;
261
+ x = sk_X509_value(certs, i);
262
+ cache = policy_cache_set(x);
263
+ X509_up_ref(x);
264
+ level->cert = x;
284
265
 
285
- if (map_skip == 0)
286
- level->flags |= X509_V_FLAG_INHIBIT_MAP;
287
- else {
288
- if (!(x->ex_flags & EXFLAG_SI))
289
- map_skip--;
290
- if ((cache->map_skip >= 0)
291
- && (cache->map_skip < map_skip))
292
- map_skip = cache->map_skip;
293
- }
266
+ if (!cache->anyPolicy) {
267
+ level->flags |= X509_V_FLAG_INHIBIT_ANY;
268
+ }
294
269
 
270
+ // Determine inhibit any and inhibit map flags
271
+ if (any_skip == 0) {
272
+ // Any matching allowed if certificate is self issued and not the
273
+ // last in the chain.
274
+ if (!(x->ex_flags & EXFLAG_SI) || (i == 0)) {
275
+ level->flags |= X509_V_FLAG_INHIBIT_ANY;
276
+ }
277
+ } else {
278
+ if (!(x->ex_flags & EXFLAG_SI)) {
279
+ any_skip--;
280
+ }
281
+ if ((cache->any_skip >= 0) && (cache->any_skip < any_skip)) {
282
+ any_skip = cache->any_skip;
283
+ }
295
284
  }
296
285
 
297
- *ptree = tree;
286
+ if (map_skip == 0) {
287
+ level->flags |= X509_V_FLAG_INHIBIT_MAP;
288
+ } else {
289
+ if (!(x->ex_flags & EXFLAG_SI)) {
290
+ map_skip--;
291
+ }
292
+ if ((cache->map_skip >= 0) && (cache->map_skip < map_skip)) {
293
+ map_skip = cache->map_skip;
294
+ }
295
+ }
296
+ }
298
297
 
299
- if (explicit_policy)
300
- return 1;
301
- else
302
- return 5;
298
+ *ptree = tree;
303
299
 
304
- bad_tree:
300
+ if (explicit_policy) {
301
+ return 1;
302
+ } else {
303
+ return 5;
304
+ }
305
305
 
306
- X509_policy_tree_free(tree);
306
+ bad_tree:
307
307
 
308
- return 0;
308
+ X509_policy_tree_free(tree);
309
309
 
310
+ return 0;
310
311
  }
311
312
 
312
313
  static int tree_link_matching_nodes(X509_POLICY_LEVEL *curr,
313
- X509_POLICY_DATA *data)
314
- {
315
- X509_POLICY_LEVEL *last = curr - 1;
316
- X509_POLICY_NODE *node;
317
- int matched = 0;
318
- size_t i;
319
- /* Iterate through all in nodes linking matches */
320
- for (i = 0; i < sk_X509_POLICY_NODE_num(last->nodes); i++) {
321
- node = sk_X509_POLICY_NODE_value(last->nodes, i);
322
- if (policy_node_match(last, node, data->valid_policy)) {
323
- if (!level_add_node(curr, data, node, NULL))
324
- return 0;
325
- matched = 1;
326
- }
314
+ X509_POLICY_DATA *data) {
315
+ X509_POLICY_LEVEL *last = curr - 1;
316
+ X509_POLICY_NODE *node;
317
+ int matched = 0;
318
+ size_t i;
319
+ // Iterate through all in nodes linking matches
320
+ for (i = 0; i < sk_X509_POLICY_NODE_num(last->nodes); i++) {
321
+ node = sk_X509_POLICY_NODE_value(last->nodes, i);
322
+ if (policy_node_match(last, node, data->valid_policy)) {
323
+ if (!level_add_node(curr, data, node, NULL)) {
324
+ return 0;
325
+ }
326
+ matched = 1;
327
327
  }
328
- if (!matched && last->anyPolicy) {
329
- if (!level_add_node(curr, data, last->anyPolicy, NULL))
330
- return 0;
328
+ }
329
+ if (!matched && last->anyPolicy) {
330
+ if (!level_add_node(curr, data, last->anyPolicy, NULL)) {
331
+ return 0;
331
332
  }
332
- return 1;
333
+ }
334
+ return 1;
333
335
  }
334
336
 
335
- /*
336
- * This corresponds to RFC 3280 6.1.3(d)(1): link any data from
337
- * CertificatePolicies onto matching parent or anyPolicy if no match.
338
- */
337
+ // This corresponds to RFC 3280 6.1.3(d)(1): link any data from
338
+ // CertificatePolicies onto matching parent or anyPolicy if no match.
339
339
 
340
340
  static int tree_link_nodes(X509_POLICY_LEVEL *curr,
341
- const X509_POLICY_CACHE *cache)
342
- {
343
- size_t i;
344
- X509_POLICY_DATA *data;
345
-
346
- for (i = 0; i < sk_X509_POLICY_DATA_num(cache->data); i++) {
347
- data = sk_X509_POLICY_DATA_value(cache->data, i);
348
- /*
349
- * If a node is mapped any it doesn't have a corresponding
350
- * CertificatePolicies entry. However such an identical node would
351
- * be created if anyPolicy matching is enabled because there would be
352
- * no match with the parent valid_policy_set. So we create link
353
- * because then it will have the mapping flags right and we can prune
354
- * it later.
355
- */
341
+ const X509_POLICY_CACHE *cache) {
342
+ size_t i;
343
+ X509_POLICY_DATA *data;
344
+
345
+ for (i = 0; i < sk_X509_POLICY_DATA_num(cache->data); i++) {
346
+ data = sk_X509_POLICY_DATA_value(cache->data, i);
347
+ // If a node is mapped any it doesn't have a corresponding
348
+ // CertificatePolicies entry. However such an identical node would
349
+ // be created if anyPolicy matching is enabled because there would be
350
+ // no match with the parent valid_policy_set. So we create link
351
+ // because then it will have the mapping flags right and we can prune
352
+ // it later.
356
353
  #if 0
357
354
  if ((data->flags & POLICY_DATA_FLAG_MAPPED_ANY)
358
355
  && !(curr->flags & X509_V_FLAG_INHIBIT_ANY))
359
356
  continue;
360
357
  #endif
361
- /* Look for matching nodes in previous level */
362
- if (!tree_link_matching_nodes(curr, data))
363
- return 0;
358
+ // Look for matching nodes in previous level
359
+ if (!tree_link_matching_nodes(curr, data)) {
360
+ return 0;
364
361
  }
365
- return 1;
362
+ }
363
+ return 1;
366
364
  }
367
365
 
368
- /*
369
- * This corresponds to RFC 3280 6.1.3(d)(2): Create new data for any unmatched
370
- * policies in the parent and link to anyPolicy.
371
- */
366
+ // This corresponds to RFC 3280 6.1.3(d)(2): Create new data for any unmatched
367
+ // policies in the parent and link to anyPolicy.
372
368
 
373
369
  static int tree_add_unmatched(X509_POLICY_LEVEL *curr,
374
370
  const X509_POLICY_CACHE *cache,
375
- const ASN1_OBJECT *id,
376
- X509_POLICY_NODE *node, X509_POLICY_TREE *tree)
377
- {
378
- X509_POLICY_DATA *data;
379
- if (id == NULL)
380
- id = node->data->valid_policy;
381
- /*
382
- * Create a new node with qualifiers from anyPolicy and id from unmatched
383
- * node.
384
- */
385
- data = policy_data_new(NULL, id, node_critical(node));
386
-
387
- if (data == NULL)
388
- return 0;
389
- /* Curr may not have anyPolicy */
390
- data->qualifier_set = cache->anyPolicy->qualifier_set;
391
- data->flags |= POLICY_DATA_FLAG_SHARED_QUALIFIERS;
392
- if (!level_add_node(curr, data, node, tree)) {
393
- policy_data_free(data);
394
- return 0;
395
- }
371
+ const ASN1_OBJECT *id, X509_POLICY_NODE *node,
372
+ X509_POLICY_TREE *tree) {
373
+ X509_POLICY_DATA *data;
374
+ if (id == NULL) {
375
+ id = node->data->valid_policy;
376
+ }
377
+ // Create a new node with qualifiers from anyPolicy and id from unmatched
378
+ // node.
379
+ data = policy_data_new(NULL, id, node_critical(node));
380
+
381
+ if (data == NULL) {
382
+ return 0;
383
+ }
384
+ // Curr may not have anyPolicy
385
+ data->qualifier_set = cache->anyPolicy->qualifier_set;
386
+ data->flags |= POLICY_DATA_FLAG_SHARED_QUALIFIERS;
387
+ if (!level_add_node(curr, data, node, tree)) {
388
+ policy_data_free(data);
389
+ return 0;
390
+ }
396
391
 
397
- return 1;
392
+ return 1;
398
393
  }
399
394
 
400
395
  static int tree_link_unmatched(X509_POLICY_LEVEL *curr,
401
396
  const X509_POLICY_CACHE *cache,
402
- X509_POLICY_NODE *node, X509_POLICY_TREE *tree)
403
- {
404
- const X509_POLICY_LEVEL *last = curr - 1;
405
- size_t i;
406
-
407
- if ((last->flags & X509_V_FLAG_INHIBIT_MAP)
408
- || !(node->data->flags & POLICY_DATA_FLAG_MAPPED)) {
409
- /* If no policy mapping: matched if one child present */
410
- if (node->nchild)
411
- return 1;
412
- if (!tree_add_unmatched(curr, cache, NULL, node, tree))
413
- return 0;
414
- /* Add it */
415
- } else {
416
- /* If mapping: matched if one child per expected policy set */
417
- STACK_OF(ASN1_OBJECT) *expset = node->data->expected_policy_set;
418
- if ((size_t)node->nchild == sk_ASN1_OBJECT_num(expset))
419
- return 1;
420
- /* Locate unmatched nodes */
421
- for (i = 0; i < sk_ASN1_OBJECT_num(expset); i++) {
422
- ASN1_OBJECT *oid = sk_ASN1_OBJECT_value(expset, i);
423
- if (level_find_node(curr, node, oid))
424
- continue;
425
- if (!tree_add_unmatched(curr, cache, oid, node, tree))
426
- return 0;
427
- }
428
-
397
+ X509_POLICY_NODE *node, X509_POLICY_TREE *tree) {
398
+ const X509_POLICY_LEVEL *last = curr - 1;
399
+ size_t i;
400
+
401
+ if ((last->flags & X509_V_FLAG_INHIBIT_MAP) ||
402
+ !(node->data->flags & POLICY_DATA_FLAG_MAPPED)) {
403
+ // If no policy mapping: matched if one child present
404
+ if (node->nchild) {
405
+ return 1;
429
406
  }
407
+ if (!tree_add_unmatched(curr, cache, NULL, node, tree)) {
408
+ return 0;
409
+ }
410
+ // Add it
411
+ } else {
412
+ // If mapping: matched if one child per expected policy set
413
+ STACK_OF(ASN1_OBJECT) *expset = node->data->expected_policy_set;
414
+ if ((size_t)node->nchild == sk_ASN1_OBJECT_num(expset)) {
415
+ return 1;
416
+ }
417
+ // Locate unmatched nodes
418
+ for (i = 0; i < sk_ASN1_OBJECT_num(expset); i++) {
419
+ ASN1_OBJECT *oid = sk_ASN1_OBJECT_value(expset, i);
420
+ if (level_find_node(curr, node, oid)) {
421
+ continue;
422
+ }
423
+ if (!tree_add_unmatched(curr, cache, oid, node, tree)) {
424
+ return 0;
425
+ }
426
+ }
427
+ }
430
428
 
431
- return 1;
432
-
429
+ return 1;
433
430
  }
434
431
 
435
432
  static int tree_link_any(X509_POLICY_LEVEL *curr,
436
433
  const X509_POLICY_CACHE *cache,
437
- X509_POLICY_TREE *tree)
438
- {
439
- size_t i;
440
- /*
441
- * X509_POLICY_DATA *data;
442
- */
443
- X509_POLICY_NODE *node;
444
- X509_POLICY_LEVEL *last = curr - 1;
445
-
446
- for (i = 0; i < sk_X509_POLICY_NODE_num(last->nodes); i++) {
447
- node = sk_X509_POLICY_NODE_value(last->nodes, i);
448
-
449
- if (!tree_link_unmatched(curr, cache, node, tree))
450
- return 0;
434
+ X509_POLICY_TREE *tree) {
435
+ size_t i;
436
+ // X509_POLICY_DATA *data;
437
+ X509_POLICY_NODE *node;
438
+ X509_POLICY_LEVEL *last = curr - 1;
439
+
440
+ for (i = 0; i < sk_X509_POLICY_NODE_num(last->nodes); i++) {
441
+ node = sk_X509_POLICY_NODE_value(last->nodes, i);
442
+
443
+ if (!tree_link_unmatched(curr, cache, node, tree)) {
444
+ return 0;
445
+ }
451
446
 
452
447
  #if 0
453
448
 
454
- /*
455
- * Skip any node with any children: we only want unmathced nodes.
456
- * Note: need something better for policy mapping because each node
457
- * may have multiple children
458
- */
449
+ // Skip any node with any children: we only want unmathced nodes.
450
+ // Note: need something better for policy mapping because each node
451
+ // may have multiple children
459
452
  if (node->nchild)
460
453
  continue;
461
454
 
462
- /*
463
- * Create a new node with qualifiers from anyPolicy and id from
464
- * unmatched node.
465
- */
455
+ // Create a new node with qualifiers from anyPolicy and id from
456
+ // unmatched node.
466
457
  data = policy_data_new(NULL, node->data->valid_policy,
467
458
  node_critical(node));
468
459
 
469
460
  if (data == NULL)
470
461
  return 0;
471
- /* Curr may not have anyPolicy */
462
+ // Curr may not have anyPolicy
472
463
  data->qualifier_set = cache->anyPolicy->qualifier_set;
473
464
  data->flags |= POLICY_DATA_FLAG_SHARED_QUALIFIERS;
474
465
  if (!level_add_node(curr, data, node, tree)) {
@@ -476,368 +467,372 @@ static int tree_link_any(X509_POLICY_LEVEL *curr,
476
467
  return 0;
477
468
  }
478
469
  #endif
479
-
470
+ }
471
+ // Finally add link to anyPolicy
472
+ if (last->anyPolicy) {
473
+ if (!level_add_node(curr, cache->anyPolicy, last->anyPolicy, NULL)) {
474
+ return 0;
480
475
  }
481
- /* Finally add link to anyPolicy */
482
- if (last->anyPolicy) {
483
- if (!level_add_node(curr, cache->anyPolicy, last->anyPolicy, NULL))
484
- return 0;
485
- }
486
- return 1;
476
+ }
477
+ return 1;
487
478
  }
488
479
 
489
- /*
490
- * Prune the tree: delete any child mapped child data on the current level
491
- * then proceed up the tree deleting any data with no children. If we ever
492
- * have no data on a level we can halt because the tree will be empty.
493
- */
480
+ // Prune the tree: delete any child mapped child data on the current level
481
+ // then proceed up the tree deleting any data with no children. If we ever
482
+ // have no data on a level we can halt because the tree will be empty.
483
+
484
+ static int tree_prune(X509_POLICY_TREE *tree, X509_POLICY_LEVEL *curr) {
485
+ STACK_OF(X509_POLICY_NODE) *nodes;
486
+ X509_POLICY_NODE *node;
487
+ int i;
488
+ nodes = curr->nodes;
489
+ if (curr->flags & X509_V_FLAG_INHIBIT_MAP) {
490
+ for (i = sk_X509_POLICY_NODE_num(nodes) - 1; i >= 0; i--) {
491
+ node = sk_X509_POLICY_NODE_value(nodes, i);
492
+ // Delete any mapped data: see RFC 3280 XXXX
493
+ if (node->data->flags & POLICY_DATA_FLAG_MAP_MASK) {
494
+ node->parent->nchild--;
495
+ OPENSSL_free(node);
496
+ (void)sk_X509_POLICY_NODE_delete(nodes, i);
497
+ }
498
+ }
499
+ }
494
500
 
495
- static int tree_prune(X509_POLICY_TREE *tree, X509_POLICY_LEVEL *curr)
496
- {
497
- STACK_OF(X509_POLICY_NODE) *nodes;
498
- X509_POLICY_NODE *node;
499
- int i;
501
+ for (;;) {
502
+ --curr;
500
503
  nodes = curr->nodes;
501
- if (curr->flags & X509_V_FLAG_INHIBIT_MAP) {
502
- for (i = sk_X509_POLICY_NODE_num(nodes) - 1; i >= 0; i--) {
503
- node = sk_X509_POLICY_NODE_value(nodes, i);
504
- /* Delete any mapped data: see RFC 3280 XXXX */
505
- if (node->data->flags & POLICY_DATA_FLAG_MAP_MASK) {
506
- node->parent->nchild--;
507
- OPENSSL_free(node);
508
- (void)sk_X509_POLICY_NODE_delete(nodes, i);
509
- }
510
- }
504
+ for (i = sk_X509_POLICY_NODE_num(nodes) - 1; i >= 0; i--) {
505
+ node = sk_X509_POLICY_NODE_value(nodes, i);
506
+ if (node->nchild == 0) {
507
+ node->parent->nchild--;
508
+ OPENSSL_free(node);
509
+ (void)sk_X509_POLICY_NODE_delete(nodes, i);
510
+ }
511
511
  }
512
-
513
- for (;;) {
514
- --curr;
515
- nodes = curr->nodes;
516
- for (i = sk_X509_POLICY_NODE_num(nodes) - 1; i >= 0; i--) {
517
- node = sk_X509_POLICY_NODE_value(nodes, i);
518
- if (node->nchild == 0) {
519
- node->parent->nchild--;
520
- OPENSSL_free(node);
521
- (void)sk_X509_POLICY_NODE_delete(nodes, i);
522
- }
523
- }
524
- if (curr->anyPolicy && !curr->anyPolicy->nchild) {
525
- if (curr->anyPolicy->parent)
526
- curr->anyPolicy->parent->nchild--;
527
- OPENSSL_free(curr->anyPolicy);
528
- curr->anyPolicy = NULL;
529
- }
530
- if (curr == tree->levels) {
531
- /* If we zapped anyPolicy at top then tree is empty */
532
- if (!curr->anyPolicy)
533
- return 2;
534
- return 1;
535
- }
512
+ if (curr->anyPolicy && !curr->anyPolicy->nchild) {
513
+ if (curr->anyPolicy->parent) {
514
+ curr->anyPolicy->parent->nchild--;
515
+ }
516
+ OPENSSL_free(curr->anyPolicy);
517
+ curr->anyPolicy = NULL;
536
518
  }
537
-
519
+ if (curr == tree->levels) {
520
+ // If we zapped anyPolicy at top then tree is empty
521
+ if (!curr->anyPolicy) {
522
+ return 2;
523
+ }
524
+ return 1;
525
+ }
526
+ }
538
527
  }
539
528
 
540
529
  static int tree_add_auth_node(STACK_OF(X509_POLICY_NODE) **pnodes,
541
- X509_POLICY_NODE *pcy)
542
- {
530
+ X509_POLICY_NODE *pcy) {
531
+ if (!*pnodes) {
532
+ *pnodes = policy_node_cmp_new();
543
533
  if (!*pnodes) {
544
- *pnodes = policy_node_cmp_new();
545
- if (!*pnodes)
546
- return 0;
547
- } else {
548
- sk_X509_POLICY_NODE_sort(*pnodes);
549
- if (sk_X509_POLICY_NODE_find(*pnodes, NULL, pcy))
550
- return 1;
534
+ return 0;
551
535
  }
552
- if (!sk_X509_POLICY_NODE_push(*pnodes, pcy))
553
- return 0;
554
-
555
- return 1;
536
+ } else {
537
+ sk_X509_POLICY_NODE_sort(*pnodes);
538
+ if (sk_X509_POLICY_NODE_find(*pnodes, NULL, pcy)) {
539
+ return 1;
540
+ }
541
+ }
542
+ if (!sk_X509_POLICY_NODE_push(*pnodes, pcy)) {
543
+ return 0;
544
+ }
556
545
 
546
+ return 1;
557
547
  }
558
548
 
559
- /*
560
- * Calculate the authority set based on policy tree. The 'pnodes' parameter
561
- * is used as a store for the set of policy nodes used to calculate the user
562
- * set. If the authority set is not anyPolicy then pnodes will just point to
563
- * the authority set. If however the authority set is anyPolicy then the set
564
- * of valid policies (other than anyPolicy) is store in pnodes. The return
565
- * value of '2' is used in this case to indicate that pnodes should be freed.
566
- */
549
+ // Calculate the authority set based on policy tree. The 'pnodes' parameter
550
+ // is used as a store for the set of policy nodes used to calculate the user
551
+ // set. If the authority set is not anyPolicy then pnodes will just point to
552
+ // the authority set. If however the authority set is anyPolicy then the set
553
+ // of valid policies (other than anyPolicy) is store in pnodes. The return
554
+ // value of '2' is used in this case to indicate that pnodes should be freed.
567
555
 
568
556
  static int tree_calculate_authority_set(X509_POLICY_TREE *tree,
569
- STACK_OF(X509_POLICY_NODE) **pnodes)
570
- {
571
- X509_POLICY_LEVEL *curr;
572
- X509_POLICY_NODE *node, *anyptr;
573
- STACK_OF(X509_POLICY_NODE) **addnodes;
574
- int i;
575
- size_t j;
576
- curr = tree->levels + tree->nlevel - 1;
577
-
578
- /* If last level contains anyPolicy set is anyPolicy */
579
- if (curr->anyPolicy) {
580
- if (!tree_add_auth_node(&tree->auth_policies, curr->anyPolicy))
581
- return 0;
582
- addnodes = pnodes;
583
- } else
584
- /* Add policies to authority set */
585
- addnodes = &tree->auth_policies;
586
-
587
- curr = tree->levels;
588
- for (i = 1; i < tree->nlevel; i++) {
589
- /*
590
- * If no anyPolicy node on this this level it can't appear on lower
591
- * levels so end search.
592
- */
593
- if (!(anyptr = curr->anyPolicy))
594
- break;
595
- curr++;
596
- for (j = 0; j < sk_X509_POLICY_NODE_num(curr->nodes); j++) {
597
- node = sk_X509_POLICY_NODE_value(curr->nodes, j);
598
- if ((node->parent == anyptr)
599
- && !tree_add_auth_node(addnodes, node))
600
- return 0;
601
- }
557
+ STACK_OF(X509_POLICY_NODE) **pnodes) {
558
+ X509_POLICY_LEVEL *curr;
559
+ X509_POLICY_NODE *node, *anyptr;
560
+ STACK_OF(X509_POLICY_NODE) **addnodes;
561
+ int i;
562
+ size_t j;
563
+ curr = tree->levels + tree->nlevel - 1;
564
+
565
+ // If last level contains anyPolicy set is anyPolicy
566
+ if (curr->anyPolicy) {
567
+ if (!tree_add_auth_node(&tree->auth_policies, curr->anyPolicy)) {
568
+ return 0;
602
569
  }
570
+ addnodes = pnodes;
571
+ } else {
572
+ // Add policies to authority set
573
+ addnodes = &tree->auth_policies;
574
+ }
575
+
576
+ curr = tree->levels;
577
+ for (i = 1; i < tree->nlevel; i++) {
578
+ // If no anyPolicy node on this this level it can't appear on lower
579
+ // levels so end search.
580
+ if (!(anyptr = curr->anyPolicy)) {
581
+ break;
582
+ }
583
+ curr++;
584
+ for (j = 0; j < sk_X509_POLICY_NODE_num(curr->nodes); j++) {
585
+ node = sk_X509_POLICY_NODE_value(curr->nodes, j);
586
+ if ((node->parent == anyptr) && !tree_add_auth_node(addnodes, node)) {
587
+ return 0;
588
+ }
589
+ }
590
+ }
603
591
 
604
- if (addnodes == pnodes)
605
- return 2;
592
+ if (addnodes == pnodes) {
593
+ return 2;
594
+ }
606
595
 
607
- *pnodes = tree->auth_policies;
596
+ *pnodes = tree->auth_policies;
608
597
 
609
- return 1;
598
+ return 1;
610
599
  }
611
600
 
612
601
  static int tree_calculate_user_set(X509_POLICY_TREE *tree,
613
602
  STACK_OF(ASN1_OBJECT) *policy_oids,
614
- STACK_OF(X509_POLICY_NODE) *auth_nodes)
615
- {
616
- size_t i;
617
- X509_POLICY_NODE *node;
618
- ASN1_OBJECT *oid;
603
+ STACK_OF(X509_POLICY_NODE) *auth_nodes) {
604
+ size_t i;
605
+ X509_POLICY_NODE *node;
606
+ ASN1_OBJECT *oid;
619
607
 
620
- X509_POLICY_NODE *anyPolicy;
621
- X509_POLICY_DATA *extra;
608
+ X509_POLICY_NODE *anyPolicy;
609
+ X509_POLICY_DATA *extra;
622
610
 
623
- /*
624
- * Check if anyPolicy present in authority constrained policy set: this
625
- * will happen if it is a leaf node.
626
- */
611
+ // Check if anyPolicy present in authority constrained policy set: this
612
+ // will happen if it is a leaf node.
627
613
 
628
- if (sk_ASN1_OBJECT_num(policy_oids) <= 0)
629
- return 1;
614
+ if (sk_ASN1_OBJECT_num(policy_oids) <= 0) {
615
+ return 1;
616
+ }
630
617
 
631
- anyPolicy = tree->levels[tree->nlevel - 1].anyPolicy;
618
+ anyPolicy = tree->levels[tree->nlevel - 1].anyPolicy;
632
619
 
633
- for (i = 0; i < sk_ASN1_OBJECT_num(policy_oids); i++) {
634
- oid = sk_ASN1_OBJECT_value(policy_oids, i);
635
- if (OBJ_obj2nid(oid) == NID_any_policy) {
636
- tree->flags |= POLICY_FLAG_ANY_POLICY;
637
- return 1;
638
- }
620
+ for (i = 0; i < sk_ASN1_OBJECT_num(policy_oids); i++) {
621
+ oid = sk_ASN1_OBJECT_value(policy_oids, i);
622
+ if (OBJ_obj2nid(oid) == NID_any_policy) {
623
+ tree->flags |= POLICY_FLAG_ANY_POLICY;
624
+ return 1;
639
625
  }
640
-
641
- for (i = 0; i < sk_ASN1_OBJECT_num(policy_oids); i++) {
642
- oid = sk_ASN1_OBJECT_value(policy_oids, i);
643
- node = tree_find_sk(auth_nodes, oid);
644
- if (!node) {
645
- if (!anyPolicy)
646
- continue;
647
- /*
648
- * Create a new node with policy ID from user set and qualifiers
649
- * from anyPolicy.
650
- */
651
- extra = policy_data_new(NULL, oid, node_critical(anyPolicy));
652
- if (!extra)
653
- return 0;
654
- extra->qualifier_set = anyPolicy->data->qualifier_set;
655
- extra->flags = POLICY_DATA_FLAG_SHARED_QUALIFIERS
656
- | POLICY_DATA_FLAG_EXTRA_NODE;
657
- node = level_add_node(NULL, extra, anyPolicy->parent, tree);
658
- }
659
- if (!tree->user_policies) {
660
- tree->user_policies = sk_X509_POLICY_NODE_new_null();
661
- if (!tree->user_policies)
662
- return 1;
663
- }
664
- if (!sk_X509_POLICY_NODE_push(tree->user_policies, node))
665
- return 0;
626
+ }
627
+
628
+ for (i = 0; i < sk_ASN1_OBJECT_num(policy_oids); i++) {
629
+ oid = sk_ASN1_OBJECT_value(policy_oids, i);
630
+ node = tree_find_sk(auth_nodes, oid);
631
+ if (!node) {
632
+ if (!anyPolicy) {
633
+ continue;
634
+ }
635
+ // Create a new node with policy ID from user set and qualifiers
636
+ // from anyPolicy.
637
+ extra = policy_data_new(NULL, oid, node_critical(anyPolicy));
638
+ if (!extra) {
639
+ return 0;
640
+ }
641
+ extra->qualifier_set = anyPolicy->data->qualifier_set;
642
+ extra->flags =
643
+ POLICY_DATA_FLAG_SHARED_QUALIFIERS | POLICY_DATA_FLAG_EXTRA_NODE;
644
+ node = level_add_node(NULL, extra, anyPolicy->parent, tree);
666
645
  }
667
- return 1;
668
-
646
+ if (!tree->user_policies) {
647
+ tree->user_policies = sk_X509_POLICY_NODE_new_null();
648
+ if (!tree->user_policies) {
649
+ return 1;
650
+ }
651
+ }
652
+ if (!sk_X509_POLICY_NODE_push(tree->user_policies, node)) {
653
+ return 0;
654
+ }
655
+ }
656
+ return 1;
669
657
  }
670
658
 
671
- static int tree_evaluate(X509_POLICY_TREE *tree)
672
- {
673
- int ret, i;
674
- X509_POLICY_LEVEL *curr = tree->levels + 1;
675
- const X509_POLICY_CACHE *cache;
676
-
677
- for (i = 1; i < tree->nlevel; i++, curr++) {
678
- cache = policy_cache_set(curr->cert);
679
- if (!tree_link_nodes(curr, cache))
680
- return 0;
659
+ static int tree_evaluate(X509_POLICY_TREE *tree) {
660
+ int ret, i;
661
+ X509_POLICY_LEVEL *curr = tree->levels + 1;
662
+ const X509_POLICY_CACHE *cache;
681
663
 
682
- if (!(curr->flags & X509_V_FLAG_INHIBIT_ANY)
683
- && !tree_link_any(curr, cache, tree))
684
- return 0;
685
- tree_print("before tree_prune()", tree, curr);
686
- ret = tree_prune(tree, curr);
687
- if (ret != 1)
688
- return ret;
664
+ for (i = 1; i < tree->nlevel; i++, curr++) {
665
+ cache = policy_cache_set(curr->cert);
666
+ if (!tree_link_nodes(curr, cache)) {
667
+ return 0;
689
668
  }
690
669
 
691
- return 1;
670
+ if (!(curr->flags & X509_V_FLAG_INHIBIT_ANY) &&
671
+ !tree_link_any(curr, cache, tree)) {
672
+ return 0;
673
+ }
674
+ tree_print("before tree_prune()", tree, curr);
675
+ ret = tree_prune(tree, curr);
676
+ if (ret != 1) {
677
+ return ret;
678
+ }
679
+ }
692
680
 
681
+ return 1;
693
682
  }
694
683
 
695
- static void exnode_free(X509_POLICY_NODE *node)
696
- {
697
- if (node->data && (node->data->flags & POLICY_DATA_FLAG_EXTRA_NODE))
698
- OPENSSL_free(node);
684
+ static void exnode_free(X509_POLICY_NODE *node) {
685
+ if (node->data && (node->data->flags & POLICY_DATA_FLAG_EXTRA_NODE)) {
686
+ OPENSSL_free(node);
687
+ }
699
688
  }
700
689
 
701
- void X509_policy_tree_free(X509_POLICY_TREE *tree)
702
- {
703
- X509_POLICY_LEVEL *curr;
704
- int i;
690
+ void X509_policy_tree_free(X509_POLICY_TREE *tree) {
691
+ X509_POLICY_LEVEL *curr;
692
+ int i;
705
693
 
706
- if (!tree)
707
- return;
694
+ if (!tree) {
695
+ return;
696
+ }
708
697
 
709
- sk_X509_POLICY_NODE_free(tree->auth_policies);
710
- sk_X509_POLICY_NODE_pop_free(tree->user_policies, exnode_free);
698
+ sk_X509_POLICY_NODE_free(tree->auth_policies);
699
+ sk_X509_POLICY_NODE_pop_free(tree->user_policies, exnode_free);
711
700
 
712
- for (i = 0, curr = tree->levels; i < tree->nlevel; i++, curr++) {
713
- if (curr->cert)
714
- X509_free(curr->cert);
715
- if (curr->nodes)
716
- sk_X509_POLICY_NODE_pop_free(curr->nodes, policy_node_free);
717
- if (curr->anyPolicy)
718
- policy_node_free(curr->anyPolicy);
701
+ for (i = 0, curr = tree->levels; i < tree->nlevel; i++, curr++) {
702
+ if (curr->cert) {
703
+ X509_free(curr->cert);
719
704
  }
705
+ if (curr->nodes) {
706
+ sk_X509_POLICY_NODE_pop_free(curr->nodes, policy_node_free);
707
+ }
708
+ if (curr->anyPolicy) {
709
+ policy_node_free(curr->anyPolicy);
710
+ }
711
+ }
720
712
 
721
- if (tree->extra_data)
722
- sk_X509_POLICY_DATA_pop_free(tree->extra_data, policy_data_free);
723
-
724
- OPENSSL_free(tree->levels);
725
- OPENSSL_free(tree);
713
+ if (tree->extra_data) {
714
+ sk_X509_POLICY_DATA_pop_free(tree->extra_data, policy_data_free);
715
+ }
726
716
 
717
+ OPENSSL_free(tree->levels);
718
+ OPENSSL_free(tree);
727
719
  }
728
720
 
729
- /*-
730
- * Application policy checking function.
731
- * Return codes:
732
- * 0 Internal Error.
733
- * 1 Successful.
734
- * -1 One or more certificates contain invalid or inconsistent extensions
735
- * -2 User constrained policy set empty and requireExplicit true.
736
- */
721
+ //-
722
+ // Application policy checking function.
723
+ // Return codes:
724
+ // 0 Internal Error.
725
+ // 1 Successful.
726
+ // -1 One or more certificates contain invalid or inconsistent extensions
727
+ // -2 User constrained policy set empty and requireExplicit true.
737
728
 
738
729
  int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy,
739
- STACK_OF(X509) *certs,
740
- STACK_OF(ASN1_OBJECT) *policy_oids, unsigned int flags)
741
- {
742
- int ret;
743
- int calc_ret;
744
- X509_POLICY_TREE *tree = NULL;
745
- STACK_OF(X509_POLICY_NODE) *nodes, *auth_nodes = NULL;
746
- *ptree = NULL;
747
-
748
- *pexplicit_policy = 0;
749
- ret = tree_init(&tree, certs, flags);
750
-
751
- switch (ret) {
752
-
753
- /* Tree empty requireExplicit False: OK */
730
+ STACK_OF(X509) *certs, STACK_OF(ASN1_OBJECT) *policy_oids,
731
+ unsigned int flags) {
732
+ int ret;
733
+ int calc_ret;
734
+ X509_POLICY_TREE *tree = NULL;
735
+ STACK_OF(X509_POLICY_NODE) *nodes, *auth_nodes = NULL;
736
+ *ptree = NULL;
737
+
738
+ *pexplicit_policy = 0;
739
+ ret = tree_init(&tree, certs, flags);
740
+
741
+ switch (ret) {
742
+ // Tree empty requireExplicit False: OK
754
743
  case 2:
755
- return 1;
744
+ return 1;
756
745
 
757
- /* Some internal error */
746
+ // Some internal error
758
747
  case -1:
759
- return -1;
748
+ return -1;
760
749
 
761
- /* Some internal error */
750
+ // Some internal error
762
751
  case 0:
763
- return 0;
752
+ return 0;
764
753
 
765
- /* Tree empty requireExplicit True: Error */
754
+ // Tree empty requireExplicit True: Error
766
755
 
767
756
  case 6:
768
- *pexplicit_policy = 1;
769
- return -2;
757
+ *pexplicit_policy = 1;
758
+ return -2;
770
759
 
771
- /* Tree OK requireExplicit True: OK and continue */
760
+ // Tree OK requireExplicit True: OK and continue
772
761
  case 5:
773
- *pexplicit_policy = 1;
774
- break;
762
+ *pexplicit_policy = 1;
763
+ break;
775
764
 
776
- /* Tree OK: continue */
765
+ // Tree OK: continue
777
766
 
778
767
  case 1:
779
- if (!tree)
780
- /*
781
- * tree_init() returns success and a null tree
782
- * if it's just looking at a trust anchor.
783
- * I'm not sure that returning success here is
784
- * correct, but I'm sure that reporting this
785
- * as an internal error which our caller
786
- * interprets as a malloc failure is wrong.
787
- */
788
- return 1;
789
- break;
790
- }
768
+ if (!tree) {
769
+ // tree_init() returns success and a null tree
770
+ // if it's just looking at a trust anchor.
771
+ // I'm not sure that returning success here is
772
+ // correct, but I'm sure that reporting this
773
+ // as an internal error which our caller
774
+ // interprets as a malloc failure is wrong.
775
+ return 1;
776
+ }
777
+ break;
778
+ }
791
779
 
792
- if (!tree)
793
- goto error;
794
- ret = tree_evaluate(tree);
780
+ if (!tree) {
781
+ goto error;
782
+ }
783
+ ret = tree_evaluate(tree);
795
784
 
796
- tree_print("tree_evaluate()", tree, NULL);
785
+ tree_print("tree_evaluate()", tree, NULL);
797
786
 
798
- if (ret <= 0)
799
- goto error;
787
+ if (ret <= 0) {
788
+ goto error;
789
+ }
800
790
 
801
- /* Return value 2 means tree empty */
802
- if (ret == 2) {
803
- X509_policy_tree_free(tree);
804
- if (*pexplicit_policy)
805
- return -2;
806
- else
807
- return 1;
791
+ // Return value 2 means tree empty
792
+ if (ret == 2) {
793
+ X509_policy_tree_free(tree);
794
+ if (*pexplicit_policy) {
795
+ return -2;
796
+ } else {
797
+ return 1;
808
798
  }
799
+ }
809
800
 
810
- /* Tree is not empty: continue */
801
+ // Tree is not empty: continue
811
802
 
812
- calc_ret = tree_calculate_authority_set(tree, &auth_nodes);
803
+ calc_ret = tree_calculate_authority_set(tree, &auth_nodes);
813
804
 
814
- if (!calc_ret)
815
- goto error;
805
+ if (!calc_ret) {
806
+ goto error;
807
+ }
816
808
 
817
- ret = tree_calculate_user_set(tree, policy_oids, auth_nodes);
809
+ ret = tree_calculate_user_set(tree, policy_oids, auth_nodes);
818
810
 
819
- if (calc_ret == 2)
820
- sk_X509_POLICY_NODE_free(auth_nodes);
811
+ if (calc_ret == 2) {
812
+ sk_X509_POLICY_NODE_free(auth_nodes);
813
+ }
821
814
 
822
- if (!ret)
823
- goto error;
815
+ if (!ret) {
816
+ goto error;
817
+ }
824
818
 
825
819
 
826
- if (tree)
827
- *ptree = tree;
820
+ if (tree) {
821
+ *ptree = tree;
822
+ }
828
823
 
829
- if (*pexplicit_policy) {
830
- nodes = X509_policy_tree_get0_user_policies(tree);
831
- if (sk_X509_POLICY_NODE_num(nodes) <= 0)
832
- return -2;
824
+ if (*pexplicit_policy) {
825
+ nodes = X509_policy_tree_get0_user_policies(tree);
826
+ if (sk_X509_POLICY_NODE_num(nodes) <= 0) {
827
+ return -2;
833
828
  }
829
+ }
834
830
 
835
- return 1;
836
-
837
- error:
831
+ return 1;
838
832
 
839
- X509_policy_tree_free(tree);
833
+ error:
840
834
 
841
- return 0;
835
+ X509_policy_tree_free(tree);
842
836
 
837
+ return 0;
843
838
  }