grpc 1.37.1 → 1.40.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (738) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +112 -59
  3. data/include/grpc/event_engine/README.md +38 -0
  4. data/include/grpc/event_engine/endpoint_config.h +48 -0
  5. data/include/grpc/event_engine/event_engine.h +330 -0
  6. data/include/grpc/event_engine/port.h +41 -0
  7. data/include/grpc/event_engine/slice_allocator.h +66 -0
  8. data/include/grpc/grpc.h +11 -4
  9. data/include/grpc/grpc_security.h +32 -0
  10. data/include/grpc/grpc_security_constants.h +15 -0
  11. data/include/grpc/impl/codegen/grpc_types.h +44 -19
  12. data/include/grpc/impl/codegen/port_platform.h +46 -0
  13. data/include/grpc/module.modulemap +14 -14
  14. data/src/core/ext/filters/client_channel/backup_poller.cc +3 -3
  15. data/src/core/ext/filters/client_channel/channel_connectivity.cc +177 -202
  16. data/src/core/ext/filters/client_channel/client_channel.cc +975 -3282
  17. data/src/core/ext/filters/client_channel/client_channel.h +513 -55
  18. data/src/core/ext/filters/client_channel/client_channel_channelz.h +1 -1
  19. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +4 -1
  20. data/src/core/ext/filters/client_channel/config_selector.h +20 -7
  21. data/src/core/ext/filters/client_channel/connector.h +1 -1
  22. data/src/core/ext/filters/client_channel/dynamic_filters.cc +9 -10
  23. data/src/core/ext/filters/client_channel/dynamic_filters.h +3 -3
  24. data/src/core/ext/filters/client_channel/health/health_check_client.cc +28 -27
  25. data/src/core/ext/filters/client_channel/health/health_check_client.h +30 -29
  26. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +24 -21
  27. data/src/core/ext/filters/client_channel/http_proxy.cc +16 -1
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +6 -6
  29. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +53 -51
  30. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -1
  31. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +2 -1
  32. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +14 -23
  33. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +16 -16
  34. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +734 -0
  35. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +10 -0
  36. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +10 -17
  37. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +1 -1
  38. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +17 -20
  39. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +53 -65
  40. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +36 -44
  41. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +33 -55
  42. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +151 -163
  43. data/src/core/ext/filters/client_channel/lb_policy.cc +2 -16
  44. data/src/core/ext/filters/client_channel/lb_policy.h +70 -46
  45. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
  46. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +4 -4
  47. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  48. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +24 -18
  49. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +1 -1
  50. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc +31 -0
  51. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +3 -3
  52. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +2 -2
  53. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +14 -14
  54. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +33 -24
  55. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +1 -1
  56. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc +28 -0
  57. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +1 -1
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
  59. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +18 -12
  60. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +20 -28
  61. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +7 -5
  62. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +20 -13
  63. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -1
  64. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +158 -102
  65. data/src/core/ext/filters/client_channel/resolver.h +2 -2
  66. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +32 -239
  67. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +20 -49
  68. data/src/core/ext/filters/client_channel/retry_filter.cc +2598 -0
  69. data/src/core/ext/filters/client_channel/retry_filter.h +30 -0
  70. data/src/core/ext/filters/client_channel/retry_service_config.cc +316 -0
  71. data/src/core/ext/filters/client_channel/retry_service_config.h +96 -0
  72. data/src/core/ext/filters/client_channel/server_address.cc +1 -1
  73. data/src/core/ext/filters/client_channel/service_config.cc +15 -14
  74. data/src/core/ext/filters/client_channel/service_config.h +7 -6
  75. data/src/core/ext/filters/client_channel/service_config_call_data.h +45 -5
  76. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +5 -4
  77. data/src/core/ext/filters/client_channel/service_config_parser.cc +6 -6
  78. data/src/core/ext/filters/client_channel/service_config_parser.h +7 -4
  79. data/src/core/ext/filters/client_channel/subchannel.cc +17 -16
  80. data/src/core/ext/filters/client_channel/subchannel.h +7 -6
  81. data/src/core/ext/filters/client_idle/client_idle_filter.cc +17 -16
  82. data/src/core/ext/filters/deadline/deadline_filter.cc +10 -10
  83. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +19 -18
  84. data/src/core/ext/filters/fault_injection/service_config_parser.cc +5 -5
  85. data/src/core/ext/filters/fault_injection/service_config_parser.h +1 -1
  86. data/src/core/ext/filters/http/client/http_client_filter.cc +33 -23
  87. data/src/core/ext/filters/http/client_authority_filter.cc +3 -3
  88. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +23 -22
  89. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +21 -21
  90. data/src/core/ext/filters/http/server/http_server_filter.cc +27 -23
  91. data/src/core/ext/filters/max_age/max_age_filter.cc +12 -10
  92. data/src/core/ext/filters/message_size/message_size_filter.cc +14 -11
  93. data/src/core/ext/filters/message_size/message_size_filter.h +1 -1
  94. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +4 -3
  95. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +7 -7
  96. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +7 -7
  97. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +2 -2
  98. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +3 -2
  99. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +3 -3
  100. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +49 -46
  101. data/src/core/ext/transport/chttp2/server/chttp2_server.h +2 -2
  102. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +3 -4
  103. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +5 -4
  104. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +3 -4
  105. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +1 -1
  106. data/src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.cc +66 -0
  107. data/src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.h +74 -0
  108. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +141 -126
  109. data/src/core/ext/transport/chttp2/transport/context_list.cc +4 -5
  110. data/src/core/ext/transport/chttp2/transport/context_list.h +4 -4
  111. data/src/core/ext/transport/chttp2/transport/flow_control.cc +3 -3
  112. data/src/core/ext/transport/chttp2/transport/flow_control.h +9 -9
  113. data/src/core/ext/transport/chttp2/transport/frame_data.cc +12 -12
  114. data/src/core/ext/transport/chttp2/transport/frame_data.h +10 -10
  115. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +15 -16
  116. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +6 -6
  117. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +7 -8
  118. data/src/core/ext/transport/chttp2/transport/frame_ping.h +7 -6
  119. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +7 -7
  120. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +6 -6
  121. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +11 -10
  122. data/src/core/ext/transport/chttp2/transport/frame_settings.h +6 -6
  123. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +4 -6
  124. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +4 -6
  125. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +652 -736
  126. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +195 -74
  127. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +4 -3
  128. data/src/core/ext/transport/chttp2/transport/hpack_table.h +4 -4
  129. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +2 -2
  130. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +2 -2
  131. data/src/core/ext/transport/chttp2/transport/internal.h +33 -28
  132. data/src/core/ext/transport/chttp2/transport/parsing.cc +129 -106
  133. data/src/core/ext/transport/chttp2/transport/varint.cc +6 -4
  134. data/src/core/ext/transport/chttp2/transport/writing.cc +7 -3
  135. data/src/core/ext/transport/inproc/inproc_transport.cc +72 -60
  136. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.c +56 -35
  137. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.h +180 -76
  138. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +35 -27
  139. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +97 -48
  140. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +45 -9
  141. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +67 -7
  142. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +66 -9
  143. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +227 -0
  144. data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.c +46 -0
  145. data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.h +121 -0
  146. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +1 -0
  147. data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.c +35 -0
  148. data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.h +90 -0
  149. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +32 -24
  150. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +120 -73
  151. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +4 -2
  152. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +15 -0
  153. data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.c +48 -0
  154. data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.h +171 -0
  155. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +8 -6
  156. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +27 -19
  157. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +1 -0
  158. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +24 -7
  159. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +57 -0
  160. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +29 -17
  161. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +72 -0
  162. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.c +3 -2
  163. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.h +4 -0
  164. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.c +6 -5
  165. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.h +15 -11
  166. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +85 -43
  167. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +274 -91
  168. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +11 -8
  169. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +30 -13
  170. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.c +33 -5
  171. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.h +115 -0
  172. data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.c +60 -0
  173. data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.h +181 -0
  174. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +1 -0
  175. data/src/core/ext/upb-generated/validate/validate.upb.c +82 -66
  176. data/src/core/ext/upb-generated/validate/validate.upb.h +220 -124
  177. data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.c +15 -7
  178. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +53 -52
  179. data/src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.c +318 -277
  180. data/src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.h +5 -0
  181. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +437 -410
  182. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c +198 -170
  183. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.h +10 -0
  184. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +9 -8
  185. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +219 -163
  186. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.h +15 -0
  187. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/resolver.upbdefs.c +59 -0
  188. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/resolver.upbdefs.h +40 -0
  189. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.c +29 -25
  190. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/udp_socket_config.upbdefs.c +52 -0
  191. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/udp_socket_config.upbdefs.h +35 -0
  192. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.c +135 -125
  193. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.h +5 -0
  194. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c +131 -123
  195. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/quic_config.upbdefs.c +90 -0
  196. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/quic_config.upbdefs.h +35 -0
  197. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.c +32 -24
  198. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c +69 -55
  199. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.h +5 -0
  200. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +684 -664
  201. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.h +5 -0
  202. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/fault/v3/fault.upbdefs.c +13 -10
  203. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/router/v3/router.upbdefs.c +13 -10
  204. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +441 -375
  205. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +10 -0
  206. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +122 -114
  207. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +1 -1
  208. data/src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.c +112 -79
  209. data/src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.h +5 -0
  210. data/src/core/ext/upbdefs-generated/envoy/type/http/v3/path_transformation.upbdefs.c +64 -0
  211. data/src/core/ext/upbdefs-generated/envoy/type/http/v3/path_transformation.upbdefs.h +50 -0
  212. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c +35 -32
  213. data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.c +4 -4
  214. data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.c +182 -160
  215. data/src/core/ext/xds/certificate_provider_factory.h +1 -1
  216. data/src/core/ext/xds/certificate_provider_store.h +3 -3
  217. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +3 -3
  218. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +2 -2
  219. data/src/core/ext/xds/xds_api.cc +665 -317
  220. data/src/core/ext/xds/xds_api.h +52 -14
  221. data/src/core/ext/xds/xds_bootstrap.cc +101 -160
  222. data/src/core/ext/xds/xds_bootstrap.h +19 -24
  223. data/src/core/ext/xds/xds_certificate_provider.cc +4 -4
  224. data/src/core/ext/xds/xds_certificate_provider.h +4 -4
  225. data/src/core/ext/xds/xds_channel_args.h +5 -2
  226. data/src/core/ext/xds/xds_client.cc +370 -215
  227. data/src/core/ext/xds/xds_client.h +38 -28
  228. data/src/core/ext/xds/xds_client_stats.h +3 -2
  229. data/src/core/ext/xds/xds_http_filters.cc +3 -2
  230. data/src/core/ext/xds/xds_http_filters.h +3 -0
  231. data/src/core/ext/xds/xds_server_config_fetcher.cc +34 -20
  232. data/src/core/lib/{iomgr → address_utils}/parse_address.cc +17 -17
  233. data/src/core/lib/{iomgr → address_utils}/parse_address.h +7 -7
  234. data/src/core/lib/{iomgr → address_utils}/sockaddr_utils.cc +16 -20
  235. data/src/core/lib/{iomgr → address_utils}/sockaddr_utils.h +16 -11
  236. data/src/core/lib/channel/call_tracer.h +85 -0
  237. data/src/core/lib/channel/channel_stack.cc +10 -9
  238. data/src/core/lib/channel/channel_stack.h +11 -10
  239. data/src/core/lib/channel/channel_stack_builder.cc +2 -2
  240. data/src/core/lib/channel/channel_stack_builder.h +1 -1
  241. data/src/core/lib/channel/channelz.cc +21 -13
  242. data/src/core/lib/channel/channelz.h +3 -0
  243. data/src/core/lib/channel/connected_channel.cc +4 -4
  244. data/src/core/lib/channel/context.h +3 -0
  245. data/src/core/lib/channel/handshaker.cc +7 -6
  246. data/src/core/lib/channel/handshaker.h +5 -5
  247. data/src/core/lib/channel/status_util.h +4 -0
  248. data/src/core/lib/compression/stream_compression.h +1 -1
  249. data/src/core/lib/compression/stream_compression_gzip.h +1 -1
  250. data/src/core/lib/compression/stream_compression_identity.h +1 -1
  251. data/src/core/lib/debug/stats.h +1 -1
  252. data/src/core/lib/event_engine/endpoint_config.cc +46 -0
  253. data/src/core/lib/event_engine/endpoint_config_internal.h +42 -0
  254. data/src/core/lib/event_engine/event_engine.cc +50 -0
  255. data/src/core/lib/event_engine/sockaddr.cc +40 -0
  256. data/src/core/lib/event_engine/sockaddr.h +44 -0
  257. data/src/core/lib/gpr/murmur_hash.cc +4 -2
  258. data/src/core/lib/gpr/wrap_memcpy.cc +2 -1
  259. data/src/core/lib/gprpp/manual_constructor.h +1 -1
  260. data/src/core/lib/gprpp/orphanable.h +3 -3
  261. data/src/core/lib/gprpp/ref_counted.h +28 -14
  262. data/src/core/lib/gprpp/status_helper.cc +407 -0
  263. data/src/core/lib/gprpp/status_helper.h +183 -0
  264. data/src/core/lib/gprpp/sync.h +2 -30
  265. data/src/core/lib/http/httpcli.cc +11 -11
  266. data/src/core/lib/http/httpcli_security_connector.cc +11 -7
  267. data/src/core/lib/http/parser.cc +16 -16
  268. data/src/core/lib/http/parser.h +4 -4
  269. data/src/core/lib/iomgr/buffer_list.cc +8 -10
  270. data/src/core/lib/iomgr/buffer_list.h +4 -5
  271. data/src/core/lib/iomgr/call_combiner.cc +15 -12
  272. data/src/core/lib/iomgr/call_combiner.h +12 -14
  273. data/src/core/lib/iomgr/cfstream_handle.cc +3 -3
  274. data/src/core/lib/iomgr/cfstream_handle.h +1 -1
  275. data/src/core/lib/iomgr/closure.h +7 -6
  276. data/src/core/lib/iomgr/combiner.cc +14 -12
  277. data/src/core/lib/iomgr/combiner.h +2 -2
  278. data/src/core/lib/iomgr/endpoint.cc +1 -1
  279. data/src/core/lib/iomgr/endpoint.h +2 -2
  280. data/src/core/lib/iomgr/endpoint_cfstream.cc +11 -13
  281. data/src/core/lib/iomgr/endpoint_pair_event_engine.cc +33 -0
  282. data/src/core/lib/iomgr/endpoint_pair_windows.cc +1 -1
  283. data/src/core/lib/iomgr/error.cc +168 -61
  284. data/src/core/lib/iomgr/error.h +217 -106
  285. data/src/core/lib/iomgr/error_cfstream.cc +3 -2
  286. data/src/core/lib/iomgr/error_cfstream.h +2 -2
  287. data/src/core/lib/iomgr/error_internal.h +5 -1
  288. data/src/core/lib/iomgr/ev_apple.cc +5 -5
  289. data/src/core/lib/iomgr/ev_apple.h +1 -1
  290. data/src/core/lib/iomgr/ev_epoll1_linux.cc +19 -19
  291. data/src/core/lib/iomgr/ev_epollex_linux.cc +48 -45
  292. data/src/core/lib/iomgr/ev_poll_posix.cc +26 -23
  293. data/src/core/lib/iomgr/ev_posix.cc +9 -8
  294. data/src/core/lib/iomgr/ev_posix.h +9 -9
  295. data/src/core/lib/iomgr/event_engine/closure.cc +54 -0
  296. data/src/core/lib/iomgr/event_engine/closure.h +33 -0
  297. data/src/core/lib/iomgr/event_engine/endpoint.cc +192 -0
  298. data/src/core/lib/iomgr/event_engine/endpoint.h +53 -0
  299. data/src/core/lib/iomgr/event_engine/iomgr.cc +105 -0
  300. data/src/core/lib/iomgr/event_engine/iomgr.h +24 -0
  301. data/src/core/lib/iomgr/event_engine/pollset.cc +87 -0
  302. data/src/core/lib/iomgr/event_engine/pollset.h +25 -0
  303. data/src/core/lib/iomgr/event_engine/promise.h +51 -0
  304. data/src/core/lib/iomgr/event_engine/resolved_address_internal.cc +41 -0
  305. data/src/core/lib/iomgr/event_engine/resolved_address_internal.h +35 -0
  306. data/src/core/lib/iomgr/event_engine/resolver.cc +110 -0
  307. data/src/core/lib/iomgr/event_engine/tcp.cc +263 -0
  308. data/src/core/lib/iomgr/event_engine/timer.cc +57 -0
  309. data/src/core/lib/iomgr/exec_ctx.cc +12 -4
  310. data/src/core/lib/iomgr/exec_ctx.h +4 -5
  311. data/src/core/lib/iomgr/executor/threadpool.cc +2 -3
  312. data/src/core/lib/iomgr/executor/threadpool.h +2 -2
  313. data/src/core/lib/iomgr/executor.cc +8 -8
  314. data/src/core/lib/iomgr/executor.h +2 -2
  315. data/src/core/lib/iomgr/iomgr.cc +2 -2
  316. data/src/core/lib/iomgr/iomgr.h +1 -1
  317. data/src/core/lib/iomgr/iomgr_custom.cc +1 -1
  318. data/src/core/lib/iomgr/iomgr_internal.cc +2 -2
  319. data/src/core/lib/iomgr/iomgr_internal.h +3 -3
  320. data/src/core/lib/iomgr/iomgr_posix.cc +3 -1
  321. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +42 -12
  322. data/src/core/lib/iomgr/iomgr_windows.cc +1 -1
  323. data/src/core/lib/iomgr/load_file.cc +4 -4
  324. data/src/core/lib/iomgr/load_file.h +2 -2
  325. data/src/core/lib/iomgr/lockfree_event.cc +5 -5
  326. data/src/core/lib/iomgr/lockfree_event.h +1 -1
  327. data/src/core/lib/iomgr/pollset.cc +5 -5
  328. data/src/core/lib/iomgr/pollset.h +9 -9
  329. data/src/core/lib/iomgr/pollset_custom.cc +7 -7
  330. data/src/core/lib/iomgr/pollset_custom.h +3 -1
  331. data/src/core/lib/iomgr/pollset_uv.cc +3 -1
  332. data/src/core/lib/iomgr/pollset_uv.h +5 -1
  333. data/src/core/lib/iomgr/pollset_windows.cc +5 -5
  334. data/src/core/lib/iomgr/port.h +7 -5
  335. data/src/core/lib/iomgr/python_util.h +2 -2
  336. data/src/core/lib/iomgr/resolve_address.cc +8 -4
  337. data/src/core/lib/iomgr/resolve_address.h +12 -6
  338. data/src/core/lib/iomgr/resolve_address_custom.cc +10 -9
  339. data/src/core/lib/iomgr/resolve_address_custom.h +3 -3
  340. data/src/core/lib/iomgr/resolve_address_posix.cc +3 -3
  341. data/src/core/lib/iomgr/resolve_address_windows.cc +4 -4
  342. data/src/core/lib/iomgr/resource_quota.cc +13 -10
  343. data/src/core/lib/iomgr/sockaddr.h +1 -0
  344. data/src/core/lib/iomgr/socket_mutator.cc +15 -2
  345. data/src/core/lib/iomgr/socket_mutator.h +26 -2
  346. data/src/core/lib/iomgr/socket_utils_common_posix.cc +24 -22
  347. data/src/core/lib/iomgr/socket_utils_posix.h +20 -20
  348. data/src/core/lib/iomgr/tcp_client_cfstream.cc +4 -4
  349. data/src/core/lib/iomgr/tcp_client_custom.cc +5 -6
  350. data/src/core/lib/iomgr/tcp_client_posix.cc +22 -19
  351. data/src/core/lib/iomgr/tcp_client_posix.h +3 -4
  352. data/src/core/lib/iomgr/tcp_client_windows.cc +7 -5
  353. data/src/core/lib/iomgr/tcp_custom.cc +14 -16
  354. data/src/core/lib/iomgr/tcp_custom.h +13 -12
  355. data/src/core/lib/iomgr/tcp_posix.cc +78 -73
  356. data/src/core/lib/iomgr/tcp_posix.h +8 -0
  357. data/src/core/lib/iomgr/tcp_server.cc +6 -6
  358. data/src/core/lib/iomgr/tcp_server.h +12 -11
  359. data/src/core/lib/iomgr/tcp_server_custom.cc +26 -25
  360. data/src/core/lib/iomgr/tcp_server_posix.cc +29 -21
  361. data/src/core/lib/iomgr/tcp_server_utils_posix.h +13 -12
  362. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +21 -18
  363. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +9 -9
  364. data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc +4 -4
  365. data/src/core/lib/iomgr/tcp_server_windows.cc +26 -25
  366. data/src/core/lib/iomgr/tcp_uv.cc +25 -23
  367. data/src/core/lib/iomgr/tcp_windows.cc +13 -13
  368. data/src/core/lib/iomgr/tcp_windows.h +2 -2
  369. data/src/core/lib/iomgr/timer.h +6 -1
  370. data/src/core/lib/iomgr/timer_custom.cc +2 -1
  371. data/src/core/lib/iomgr/timer_custom.h +1 -1
  372. data/src/core/lib/iomgr/timer_generic.cc +6 -6
  373. data/src/core/lib/iomgr/timer_manager.cc +1 -1
  374. data/src/core/lib/iomgr/udp_server.cc +21 -20
  375. data/src/core/lib/iomgr/unix_sockets_posix.cc +3 -3
  376. data/src/core/lib/iomgr/unix_sockets_posix.h +2 -2
  377. data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +10 -7
  378. data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +3 -3
  379. data/src/core/lib/iomgr/wakeup_fd_pipe.cc +4 -4
  380. data/src/core/lib/iomgr/wakeup_fd_posix.cc +3 -3
  381. data/src/core/lib/iomgr/wakeup_fd_posix.h +8 -6
  382. data/src/core/lib/iomgr/work_serializer.h +17 -1
  383. data/src/core/lib/json/json.h +1 -1
  384. data/src/core/lib/json/json_reader.cc +5 -6
  385. data/src/core/lib/matchers/matchers.cc +46 -58
  386. data/src/core/lib/matchers/matchers.h +30 -29
  387. data/src/core/lib/security/authorization/authorization_engine.h +44 -0
  388. data/src/core/lib/security/authorization/authorization_policy_provider.h +32 -0
  389. data/src/core/lib/security/authorization/authorization_policy_provider_vtable.cc +46 -0
  390. data/src/core/lib/security/authorization/evaluate_args.cc +209 -0
  391. data/src/core/lib/security/authorization/evaluate_args.h +91 -0
  392. data/src/core/lib/security/credentials/composite/composite_credentials.cc +4 -4
  393. data/src/core/lib/security/credentials/composite/composite_credentials.h +2 -2
  394. data/src/core/lib/security/credentials/credentials.h +2 -2
  395. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +17 -13
  396. data/src/core/lib/security/credentials/external/aws_external_account_credentials.h +13 -11
  397. data/src/core/lib/security/credentials/external/aws_request_signer.cc +2 -1
  398. data/src/core/lib/security/credentials/external/aws_request_signer.h +1 -1
  399. data/src/core/lib/security/credentials/external/external_account_credentials.cc +15 -12
  400. data/src/core/lib/security/credentials/external/external_account_credentials.h +9 -8
  401. data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +5 -4
  402. data/src/core/lib/security/credentials/external/file_external_account_credentials.h +4 -3
  403. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +8 -8
  404. data/src/core/lib/security/credentials/external/url_external_account_credentials.h +9 -7
  405. data/src/core/lib/security/credentials/fake/fake_credentials.cc +2 -2
  406. data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -2
  407. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +12 -10
  408. data/src/core/lib/security/credentials/iam/iam_credentials.cc +2 -2
  409. data/src/core/lib/security/credentials/iam/iam_credentials.h +2 -2
  410. data/src/core/lib/security/credentials/jwt/json_token.cc +2 -2
  411. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +3 -3
  412. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +2 -2
  413. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +7 -5
  414. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +21 -19
  415. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +5 -5
  416. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +5 -5
  417. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -2
  418. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +8 -7
  419. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +9 -9
  420. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +68 -13
  421. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +7 -0
  422. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +4 -0
  423. data/src/core/lib/security/credentials/tls/tls_utils.cc +32 -0
  424. data/src/core/lib/security/credentials/tls/tls_utils.h +13 -0
  425. data/src/core/lib/security/credentials/xds/xds_credentials.cc +3 -3
  426. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -3
  427. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +13 -3
  428. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc +2 -2
  429. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.h +12 -2
  430. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +1 -1
  431. data/src/core/lib/security/security_connector/local/local_security_connector.cc +22 -9
  432. data/src/core/lib/security/security_connector/security_connector.h +9 -4
  433. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +16 -6
  434. data/src/core/lib/security/security_connector/ssl_utils.cc +27 -4
  435. data/src/core/lib/security/security_connector/ssl_utils.h +4 -4
  436. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +60 -76
  437. data/src/core/lib/security/security_connector/tls/tls_security_connector.h +66 -48
  438. data/src/core/lib/security/transport/client_auth_filter.cc +18 -10
  439. data/src/core/lib/security/transport/secure_endpoint.cc +4 -4
  440. data/src/core/lib/security/transport/security_handshaker.cc +45 -36
  441. data/src/core/lib/security/transport/server_auth_filter.cc +17 -18
  442. data/src/core/lib/security/transport/tsi_error.cc +2 -1
  443. data/src/core/lib/security/transport/tsi_error.h +2 -1
  444. data/src/core/lib/security/util/json_util.cc +2 -2
  445. data/src/core/lib/security/util/json_util.h +1 -1
  446. data/src/core/lib/slice/slice_internal.h +1 -0
  447. data/src/core/lib/surface/call.cc +72 -52
  448. data/src/core/lib/surface/call.h +13 -2
  449. data/src/core/lib/surface/channel.cc +6 -6
  450. data/src/core/lib/surface/channel.h +3 -2
  451. data/src/core/lib/surface/channel_ping.cc +1 -1
  452. data/src/core/lib/surface/completion_queue.cc +68 -69
  453. data/src/core/lib/surface/completion_queue.h +3 -2
  454. data/src/core/lib/surface/completion_queue_factory.cc +1 -2
  455. data/src/core/lib/surface/init.cc +1 -3
  456. data/src/core/lib/surface/init.h +10 -1
  457. data/src/core/lib/surface/lame_client.cc +11 -11
  458. data/src/core/lib/surface/lame_client.h +1 -1
  459. data/src/core/lib/surface/server.cc +31 -23
  460. data/src/core/lib/surface/server.h +19 -18
  461. data/src/core/lib/surface/validate_metadata.cc +7 -7
  462. data/src/core/lib/surface/validate_metadata.h +3 -2
  463. data/src/core/lib/surface/version.cc +2 -2
  464. data/src/core/lib/transport/byte_stream.cc +5 -5
  465. data/src/core/lib/transport/byte_stream.h +8 -8
  466. data/src/core/lib/transport/connectivity_state.cc +1 -1
  467. data/src/core/lib/transport/error_utils.cc +21 -10
  468. data/src/core/lib/transport/error_utils.h +11 -5
  469. data/src/core/lib/transport/metadata_batch.cc +37 -37
  470. data/src/core/lib/transport/metadata_batch.h +19 -18
  471. data/src/core/lib/transport/transport.cc +4 -3
  472. data/src/core/lib/transport/transport.h +6 -4
  473. data/src/core/lib/transport/transport_op_string.cc +6 -6
  474. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  475. data/src/core/tsi/alts/crypt/gsec.h +6 -0
  476. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +5 -4
  477. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +7 -6
  478. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h +2 -1
  479. data/src/core/tsi/ssl_transport_security.cc +32 -14
  480. data/src/core/tsi/ssl_transport_security.h +3 -4
  481. data/src/ruby/bin/math_services_pb.rb +1 -1
  482. data/src/ruby/ext/grpc/extconf.rb +2 -0
  483. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +6 -0
  484. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +11 -2
  485. data/src/ruby/lib/grpc/version.rb +1 -1
  486. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +1 -1
  487. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +6 -6
  488. data/third_party/abseil-cpp/absl/algorithm/container.h +3 -3
  489. data/third_party/abseil-cpp/absl/base/attributes.h +24 -4
  490. data/third_party/abseil-cpp/absl/base/call_once.h +2 -9
  491. data/third_party/abseil-cpp/absl/base/config.h +37 -9
  492. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +24 -10
  493. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +4 -1
  494. data/third_party/abseil-cpp/absl/base/internal/endian.h +61 -0
  495. data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +2 -3
  496. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +34 -32
  497. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +16 -6
  498. data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +11 -2
  499. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +14 -5
  500. data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +2 -2
  501. data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +3 -3
  502. data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +2 -2
  503. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +11 -11
  504. data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +5 -5
  505. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +1 -1
  506. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +5 -2
  507. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +43 -42
  508. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +111 -7
  509. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +0 -76
  510. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +1 -3
  511. data/third_party/abseil-cpp/absl/base/log_severity.h +4 -4
  512. data/third_party/abseil-cpp/absl/base/macros.h +11 -0
  513. data/third_party/abseil-cpp/absl/base/optimization.h +10 -7
  514. data/third_party/abseil-cpp/absl/base/options.h +1 -1
  515. data/third_party/abseil-cpp/absl/base/port.h +0 -1
  516. data/third_party/abseil-cpp/absl/base/thread_annotations.h +1 -1
  517. data/third_party/abseil-cpp/absl/container/fixed_array.h +2 -2
  518. data/third_party/abseil-cpp/absl/container/inlined_vector.h +5 -3
  519. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +1 -1
  520. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +5 -1
  521. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +2 -1
  522. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler_force_weak_definition.cc +2 -1
  523. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +141 -66
  524. data/third_party/abseil-cpp/absl/container/internal/layout.h +4 -4
  525. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +14 -1
  526. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +136 -136
  527. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +16 -12
  528. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +5 -2
  529. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +3 -12
  530. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +6 -1
  531. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +3 -5
  532. data/third_party/abseil-cpp/absl/debugging/symbolize_darwin.inc +2 -2
  533. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +2 -2
  534. data/third_party/abseil-cpp/absl/hash/internal/city.cc +15 -12
  535. data/third_party/abseil-cpp/absl/hash/internal/city.h +1 -19
  536. data/third_party/abseil-cpp/absl/hash/internal/hash.cc +25 -10
  537. data/third_party/abseil-cpp/absl/hash/internal/hash.h +86 -37
  538. data/third_party/abseil-cpp/absl/hash/internal/wyhash.cc +111 -0
  539. data/third_party/abseil-cpp/absl/hash/internal/wyhash.h +48 -0
  540. data/third_party/abseil-cpp/absl/meta/type_traits.h +16 -2
  541. data/third_party/abseil-cpp/absl/numeric/bits.h +177 -0
  542. data/third_party/abseil-cpp/absl/numeric/int128.cc +3 -3
  543. data/third_party/abseil-cpp/absl/numeric/internal/bits.h +358 -0
  544. data/third_party/abseil-cpp/absl/numeric/internal/representation.h +55 -0
  545. data/third_party/abseil-cpp/absl/status/internal/status_internal.h +18 -0
  546. data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +4 -7
  547. data/third_party/abseil-cpp/absl/status/status.cc +29 -22
  548. data/third_party/abseil-cpp/absl/status/status.h +81 -20
  549. data/third_party/abseil-cpp/absl/status/statusor.h +3 -3
  550. data/third_party/abseil-cpp/absl/strings/charconv.cc +5 -5
  551. data/third_party/abseil-cpp/absl/strings/cord.cc +326 -371
  552. data/third_party/abseil-cpp/absl/strings/cord.h +182 -64
  553. data/third_party/abseil-cpp/absl/strings/escaping.cc +4 -4
  554. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +6 -6
  555. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.cc +83 -0
  556. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +387 -17
  557. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_flat.h +146 -0
  558. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring.cc +897 -0
  559. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring.h +589 -0
  560. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring_reader.h +114 -0
  561. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +14 -0
  562. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +14 -0
  563. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.cc +15 -1
  564. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +19 -4
  565. data/third_party/abseil-cpp/absl/strings/internal/str_format/checker.h +14 -0
  566. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +36 -18
  567. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.h +14 -0
  568. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.cc +14 -0
  569. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.h +14 -0
  570. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +15 -40
  571. data/third_party/abseil-cpp/absl/strings/internal/string_constant.h +64 -0
  572. data/third_party/abseil-cpp/absl/strings/match.cc +6 -3
  573. data/third_party/abseil-cpp/absl/strings/match.h +16 -6
  574. data/third_party/abseil-cpp/absl/strings/numbers.cc +132 -4
  575. data/third_party/abseil-cpp/absl/strings/numbers.h +10 -10
  576. data/third_party/abseil-cpp/absl/strings/str_join.h +1 -1
  577. data/third_party/abseil-cpp/absl/strings/str_split.h +38 -4
  578. data/third_party/abseil-cpp/absl/synchronization/internal/futex.h +154 -0
  579. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +2 -1
  580. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +2 -2
  581. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +4 -4
  582. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +1 -65
  583. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +2 -6
  584. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +71 -59
  585. data/third_party/abseil-cpp/absl/synchronization/mutex.h +79 -62
  586. data/third_party/abseil-cpp/absl/time/clock.cc +146 -130
  587. data/third_party/abseil-cpp/absl/time/clock.h +2 -2
  588. data/third_party/abseil-cpp/absl/time/duration.cc +3 -2
  589. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +7 -11
  590. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +7 -1
  591. data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +4 -4
  592. data/third_party/abseil-cpp/absl/time/time.cc +4 -3
  593. data/third_party/abseil-cpp/absl/time/time.h +26 -24
  594. data/third_party/abseil-cpp/absl/types/internal/variant.h +1 -1
  595. data/third_party/abseil-cpp/absl/types/variant.h +9 -4
  596. data/third_party/boringssl-with-bazel/err_data.c +483 -461
  597. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_bool.c +1 -1
  598. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +9 -7
  599. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_type.c +18 -8
  600. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +1 -2
  601. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_locl.h +5 -0
  602. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +1 -1
  603. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_fre.c +1 -1
  604. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/cipher_extra.c +4 -0
  605. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/e_tls.c +1 -88
  606. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/internal.h +14 -3
  607. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/tls_cbc.c +119 -273
  608. data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519.c +1 -1
  609. data/third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h +1 -1
  610. data/third_party/boringssl-with-bazel/src/crypto/err/err.c +87 -80
  611. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +9 -0
  612. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm.c +1 -0
  613. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +1 -1
  614. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/prime.c +0 -4
  615. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/cipher.c +11 -3
  616. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/e_aes.c +25 -2
  617. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +7 -0
  618. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digests.c +10 -2
  619. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/md32_common.h +87 -160
  620. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.c +4 -0
  621. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.c +0 -1
  622. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +0 -4
  623. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +104 -93
  624. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/internal.h +39 -0
  625. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md4/md4.c +52 -65
  626. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md5/md5.c +52 -66
  627. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/cbc.c +33 -22
  628. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/cfb.c +9 -8
  629. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/ctr.c +9 -8
  630. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/gcm.c +17 -13
  631. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/internal.h +1 -22
  632. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/ofb.c +2 -1
  633. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +1 -4
  634. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +0 -13
  635. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/urandom.c +26 -7
  636. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +26 -24
  637. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +10 -7
  638. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/fips.c +79 -0
  639. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +14 -9
  640. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha1.c +61 -75
  641. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha256.c +80 -103
  642. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha512.c +40 -49
  643. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +367 -315
  644. data/third_party/boringssl-with-bazel/src/crypto/internal.h +65 -0
  645. data/third_party/boringssl-with-bazel/src/crypto/mem.c +14 -0
  646. data/third_party/boringssl-with-bazel/src/crypto/obj/obj.c +3 -3
  647. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7_x509.c +5 -3
  648. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +95 -48
  649. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/passive.c +2 -2
  650. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/rand_extra.c +1 -1
  651. data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/rsa_asn1.c +1 -2
  652. data/third_party/boringssl-with-bazel/src/crypto/thread_pthread.c +0 -28
  653. data/third_party/boringssl-with-bazel/src/crypto/x509/internal.h +120 -11
  654. data/third_party/boringssl-with-bazel/src/crypto/x509/t_req.c +2 -0
  655. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509a.c +3 -0
  656. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_att.c +19 -25
  657. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +3 -2
  658. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +42 -89
  659. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +9 -16
  660. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +2 -0
  661. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +14 -15
  662. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vpm.c +53 -73
  663. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +31 -0
  664. data/third_party/boringssl-with-bazel/src/crypto/x509/x509rset.c +3 -0
  665. data/third_party/boringssl-with-bazel/src/crypto/x509/x_algor.c +21 -17
  666. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +3 -0
  667. data/third_party/boringssl-with-bazel/src/crypto/x509/x_attrib.c +7 -25
  668. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +5 -0
  669. data/third_party/boringssl-with-bazel/src/crypto/x509/x_pubkey.c +25 -22
  670. data/third_party/boringssl-with-bazel/src/crypto/x509/x_req.c +5 -8
  671. data/third_party/boringssl-with-bazel/src/crypto/x509/x_sig.c +5 -0
  672. data/third_party/boringssl-with-bazel/src/crypto/x509/x_val.c +2 -0
  673. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509a.c +3 -0
  674. data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +7 -0
  675. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_cpols.c +2 -4
  676. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +1 -1
  677. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +1 -0
  678. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_utl.c +5 -8
  679. data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +1 -4
  680. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +66 -1
  681. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +120 -41
  682. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +47 -7
  683. data/third_party/boringssl-with-bazel/src/include/openssl/bytestring.h +1 -0
  684. data/third_party/boringssl-with-bazel/src/include/openssl/chacha.h +1 -1
  685. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +0 -8
  686. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +24 -4
  687. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +6 -2
  688. data/third_party/boringssl-with-bazel/src/include/openssl/ec.h +5 -2
  689. data/third_party/boringssl-with-bazel/src/include/openssl/ecdsa.h +33 -0
  690. data/third_party/boringssl-with-bazel/src/include/openssl/err.h +3 -2
  691. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +20 -49
  692. data/third_party/boringssl-with-bazel/src/{crypto/x509/x509_r2x.c → include/openssl/evp_errors.h} +41 -58
  693. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +325 -0
  694. data/third_party/boringssl-with-bazel/src/include/openssl/obj.h +24 -5
  695. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +25 -7
  696. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs8.h +9 -1
  697. data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +2 -2
  698. data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +99 -63
  699. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +283 -85
  700. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +13 -19
  701. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +445 -152
  702. data/third_party/boringssl-with-bazel/src/include/openssl/x509_vfy.h +451 -435
  703. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +2 -1
  704. data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +7 -2
  705. data/third_party/boringssl-with-bazel/src/ssl/d1_srtp.cc +1 -1
  706. data/third_party/boringssl-with-bazel/src/ssl/encrypted_client_hello.cc +1133 -0
  707. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +298 -22
  708. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +66 -30
  709. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +189 -86
  710. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +154 -24
  711. data/third_party/boringssl-with-bazel/src/ssl/internal.h +414 -135
  712. data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +9 -3
  713. data/third_party/boringssl-with-bazel/src/ssl/s3_lib.cc +2 -2
  714. data/third_party/boringssl-with-bazel/src/ssl/s3_pkt.cc +14 -19
  715. data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +4 -6
  716. data/third_party/boringssl-with-bazel/src/ssl/ssl_key_share.cc +23 -26
  717. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +51 -60
  718. data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +2 -0
  719. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +8 -31
  720. data/third_party/boringssl-with-bazel/src/ssl/ssl_stat.cc +3 -0
  721. data/third_party/boringssl-with-bazel/src/ssl/ssl_transcript.cc +4 -3
  722. data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +7 -3
  723. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +664 -702
  724. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +65 -7
  725. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +98 -39
  726. data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +141 -94
  727. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +213 -118
  728. data/third_party/boringssl-with-bazel/src/ssl/tls_method.cc +4 -2
  729. data/third_party/xxhash/xxhash.h +77 -195
  730. metadata +116 -51
  731. data/src/core/lib/gpr/arena.h +0 -47
  732. data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +0 -88
  733. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +0 -88
  734. data/third_party/abseil-cpp/absl/base/internal/bits.h +0 -219
  735. data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +0 -249
  736. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/is_fips.c +0 -29
  737. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +0 -246
  738. data/third_party/boringssl-with-bazel/src/crypto/x509/vpm_int.h +0 -71
@@ -154,6 +154,8 @@
154
154
  #include <openssl/bn.h>
155
155
  #include <openssl/bytestring.h>
156
156
  #include <openssl/cipher.h>
157
+ #include <openssl/curve25519.h>
158
+ #include <openssl/digest.h>
157
159
  #include <openssl/ec.h>
158
160
  #include <openssl/ecdsa.h>
159
161
  #include <openssl/err.h>
@@ -563,7 +565,7 @@ static enum ssl_hs_wait_t do_read_client_hello(SSL_HANDSHAKE *hs) {
563
565
  }
564
566
 
565
567
  SSL_CLIENT_HELLO client_hello;
566
- if (!ssl_client_hello_init(ssl, &client_hello, msg)) {
568
+ if (!ssl_client_hello_init(ssl, &client_hello, msg.body)) {
567
569
  OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
568
570
  ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
569
571
  return ssl_hs_error;
@@ -581,12 +583,113 @@ static enum ssl_hs_wait_t do_read_client_hello(SSL_HANDSHAKE *hs) {
581
583
  return ssl_hs_handoff;
582
584
  }
583
585
 
586
+ // If the ClientHello contains an encrypted_client_hello extension (and no
587
+ // ech_is_inner extension), act as a client-facing server and attempt to
588
+ // decrypt the ClientHelloInner.
589
+ CBS ech_body;
590
+ if (ssl_client_hello_get_extension(&client_hello, &ech_body,
591
+ TLSEXT_TYPE_encrypted_client_hello)) {
592
+ CBS unused;
593
+ if (ssl_client_hello_get_extension(&client_hello, &unused,
594
+ TLSEXT_TYPE_ech_is_inner)) {
595
+ OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_EXTENSION);
596
+ ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
597
+ return ssl_hs_error;
598
+ }
599
+
600
+ // Parse a ClientECH out of the extension body.
601
+ uint8_t config_id;
602
+ uint16_t kdf_id, aead_id;
603
+ CBS enc, payload;
604
+ if (!CBS_get_u16(&ech_body, &kdf_id) || //
605
+ !CBS_get_u16(&ech_body, &aead_id) ||
606
+ !CBS_get_u8(&ech_body, &config_id) ||
607
+ !CBS_get_u16_length_prefixed(&ech_body, &enc) ||
608
+ !CBS_get_u16_length_prefixed(&ech_body, &payload) ||
609
+ CBS_len(&ech_body) != 0) {
610
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
611
+ ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
612
+ return ssl_hs_error;
613
+ }
614
+
615
+ {
616
+ MutexReadLock lock(&ssl->ctx->lock);
617
+ hs->ech_keys = UpRef(ssl->ctx->ech_keys);
618
+ }
619
+
620
+ if (hs->ech_keys) {
621
+ for (const auto &config : hs->ech_keys->configs) {
622
+ hs->ech_hpke_ctx.Reset();
623
+ if (config_id != config->ech_config().config_id ||
624
+ !config->SetupContext(hs->ech_hpke_ctx.get(), kdf_id, aead_id,
625
+ enc)) {
626
+ // Ignore the error and try another ECHConfig.
627
+ ERR_clear_error();
628
+ continue;
629
+ }
630
+ Array<uint8_t> encoded_client_hello_inner;
631
+ bool is_decrypt_error;
632
+ if (!ssl_client_hello_decrypt(hs->ech_hpke_ctx.get(),
633
+ &encoded_client_hello_inner,
634
+ &is_decrypt_error, &client_hello, kdf_id,
635
+ aead_id, config_id, enc, payload)) {
636
+ if (is_decrypt_error) {
637
+ // Ignore the error and try another ECHConfig.
638
+ ERR_clear_error();
639
+ continue;
640
+ }
641
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECRYPTION_FAILED);
642
+ return ssl_hs_error;
643
+ }
644
+
645
+ // Recover the ClientHelloInner from the EncodedClientHelloInner.
646
+ uint8_t alert = SSL_AD_DECODE_ERROR;
647
+ bssl::Array<uint8_t> client_hello_inner;
648
+ if (!ssl_decode_client_hello_inner(ssl, &alert, &client_hello_inner,
649
+ encoded_client_hello_inner,
650
+ &client_hello)) {
651
+ ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
652
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
653
+ return ssl_hs_error;
654
+ }
655
+ hs->ech_client_hello_buf = std::move(client_hello_inner);
656
+
657
+ // Load the ClientHelloInner into |client_hello|.
658
+ if (!hs->GetClientHello(&msg, &client_hello)) {
659
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
660
+ return ssl_hs_error;
661
+ }
662
+
663
+ hs->ech_config_id = config_id;
664
+ ssl->s3->ech_accept = true;
665
+ break;
666
+ }
667
+ }
668
+
669
+ // If we did not accept ECH, we will send the current ECHConfigs as
670
+ // retry_configs in the ServerHello's encrypted extensions. Proceed with the
671
+ // ClientHelloOuter.
672
+ }
673
+
584
674
  uint8_t alert = SSL_AD_DECODE_ERROR;
585
675
  if (!extract_sni(hs, &alert, &client_hello)) {
586
676
  ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
587
677
  return ssl_hs_error;
588
678
  }
589
679
 
680
+ hs->state = state12_read_client_hello_after_ech;
681
+ return ssl_hs_ok;
682
+ }
683
+
684
+ static enum ssl_hs_wait_t do_read_client_hello_after_ech(SSL_HANDSHAKE *hs) {
685
+ SSL *const ssl = hs->ssl;
686
+
687
+ SSLMessage msg_unused;
688
+ SSL_CLIENT_HELLO client_hello;
689
+ if (!hs->GetClientHello(&msg_unused, &client_hello)) {
690
+ return ssl_hs_error;
691
+ }
692
+
590
693
  // Run the early callback.
591
694
  if (ssl->ctx->select_certificate_cb != NULL) {
592
695
  switch (ssl->ctx->select_certificate_cb(&client_hello)) {
@@ -614,6 +717,7 @@ static enum ssl_hs_wait_t do_read_client_hello(SSL_HANDSHAKE *hs) {
614
717
  hs->apply_jdk11_workaround = true;
615
718
  }
616
719
 
720
+ uint8_t alert = SSL_AD_DECODE_ERROR;
617
721
  if (!negotiate_version(hs, &alert, &client_hello)) {
618
722
  ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
619
723
  return ssl_hs_error;
@@ -657,11 +761,6 @@ static enum ssl_hs_wait_t do_read_client_hello(SSL_HANDSHAKE *hs) {
657
761
  static enum ssl_hs_wait_t do_select_certificate(SSL_HANDSHAKE *hs) {
658
762
  SSL *const ssl = hs->ssl;
659
763
 
660
- SSLMessage msg;
661
- if (!ssl->method->get_message(ssl, &msg)) {
662
- return ssl_hs_read_message;
663
- }
664
-
665
764
  // Call |cert_cb| to update server certificates if required.
666
765
  if (hs->config->cert->cert_cb != NULL) {
667
766
  int rv = hs->config->cert->cert_cb(ssl, hs->config->cert->cert_cb_arg);
@@ -701,10 +800,22 @@ static enum ssl_hs_wait_t do_select_certificate(SSL_HANDSHAKE *hs) {
701
800
  return ssl_hs_ok;
702
801
  }
703
802
 
803
+ // It should not be possible to negotiate TLS 1.2 with ECH. The
804
+ // ClientHelloInner decoding function rejects ClientHellos which offer TLS 1.2
805
+ // or below.
806
+ assert(!ssl->s3->ech_accept);
807
+
808
+ // TODO(davidben): Also compute hints for TLS 1.2. When doing so, update the
809
+ // check in bssl_shim.cc to test this.
810
+ if (hs->hints_requested) {
811
+ return ssl_hs_hints_ready;
812
+ }
813
+
704
814
  ssl->s3->early_data_reason = ssl_early_data_protocol_version;
705
815
 
816
+ SSLMessage msg_unused;
706
817
  SSL_CLIENT_HELLO client_hello;
707
- if (!ssl_client_hello_init(ssl, &client_hello, msg)) {
818
+ if (!hs->GetClientHello(&msg_unused, &client_hello)) {
708
819
  return ssl_hs_error;
709
820
  }
710
821
 
@@ -743,10 +854,15 @@ static enum ssl_hs_wait_t do_select_parameters(SSL_HANDSHAKE *hs) {
743
854
  }
744
855
 
745
856
  SSL_CLIENT_HELLO client_hello;
746
- if (!ssl_client_hello_init(ssl, &client_hello, msg)) {
857
+ if (!ssl_client_hello_init(ssl, &client_hello, msg.body)) {
747
858
  return ssl_hs_error;
748
859
  }
749
860
 
861
+ hs->session_id_len = client_hello.session_id_len;
862
+ // This is checked in |ssl_client_hello_init|.
863
+ assert(hs->session_id_len <= sizeof(hs->session_id));
864
+ OPENSSL_memcpy(hs->session_id, client_hello.session_id, hs->session_id_len);
865
+
750
866
  // Determine whether we are doing session resumption.
751
867
  UniquePtr<SSL_SESSION> session;
752
868
  bool tickets_supported = false, renew_ticket = false;
@@ -778,16 +894,20 @@ static enum ssl_hs_wait_t do_select_parameters(SSL_HANDSHAKE *hs) {
778
894
  hs->ticket_expected = renew_ticket;
779
895
  ssl->session = std::move(session);
780
896
  ssl->s3->session_reused = true;
897
+ hs->can_release_private_key = true;
781
898
  } else {
782
899
  hs->ticket_expected = tickets_supported;
783
- ssl_set_session(ssl, NULL);
784
- if (!ssl_get_new_session(hs, 1 /* server */)) {
900
+ ssl_set_session(ssl, nullptr);
901
+ if (!ssl_get_new_session(hs)) {
785
902
  return ssl_hs_error;
786
903
  }
787
904
 
788
- // Clear the session ID if we want the session to be single-use.
789
- if (!(ssl->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) {
790
- hs->new_session->session_id_length = 0;
905
+ // Assign a session ID if not using session tickets.
906
+ if (!hs->ticket_expected &&
907
+ (ssl->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) {
908
+ hs->new_session->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
909
+ RAND_bytes(hs->new_session->session_id,
910
+ hs->new_session->session_id_length);
791
911
  }
792
912
  }
793
913
 
@@ -806,7 +926,7 @@ static enum ssl_hs_wait_t do_select_parameters(SSL_HANDSHAKE *hs) {
806
926
  hs->cert_request = !!(hs->config->verify_mode & SSL_VERIFY_PEER);
807
927
  // Only request a certificate if Channel ID isn't negotiated.
808
928
  if ((hs->config->verify_mode & SSL_VERIFY_PEER_IF_NO_OBC) &&
809
- ssl->s3->channel_id_valid) {
929
+ hs->channel_id_negotiated) {
810
930
  hs->cert_request = false;
811
931
  }
812
932
  // CertificateRequest may only be sent in certificate-based ciphers.
@@ -860,9 +980,9 @@ static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) {
860
980
 
861
981
  // We only accept ChannelIDs on connections with ECDHE in order to avoid a
862
982
  // known attack while we fix ChannelID itself.
863
- if (ssl->s3->channel_id_valid &&
983
+ if (hs->channel_id_negotiated &&
864
984
  (hs->new_cipher->algorithm_mkey & SSL_kECDHE) == 0) {
865
- ssl->s3->channel_id_valid = false;
985
+ hs->channel_id_negotiated = false;
866
986
  }
867
987
 
868
988
  // If this is a resumption and the original handshake didn't support
@@ -870,7 +990,7 @@ static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) {
870
990
  // session and so cannot resume with ChannelIDs.
871
991
  if (ssl->session != NULL &&
872
992
  ssl->session->original_handshake_hash_len == 0) {
873
- ssl->s3->channel_id_valid = false;
993
+ hs->channel_id_negotiated = false;
874
994
  }
875
995
 
876
996
  struct OPENSSL_timeval now;
@@ -901,19 +1021,22 @@ static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) {
901
1021
  }
902
1022
  }
903
1023
 
904
- const SSL_SESSION *session = hs->new_session.get();
1024
+ Span<const uint8_t> session_id;
905
1025
  if (ssl->session != nullptr) {
906
- session = ssl->session.get();
1026
+ // Echo the session ID from the ClientHello to indicate resumption.
1027
+ session_id = MakeConstSpan(hs->session_id, hs->session_id_len);
1028
+ } else {
1029
+ session_id = MakeConstSpan(hs->new_session->session_id,
1030
+ hs->new_session->session_id_length);
907
1031
  }
908
1032
 
909
1033
  ScopedCBB cbb;
910
- CBB body, session_id;
1034
+ CBB body, session_id_bytes;
911
1035
  if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_SERVER_HELLO) ||
912
1036
  !CBB_add_u16(&body, ssl->version) ||
913
1037
  !CBB_add_bytes(&body, ssl->s3->server_random, SSL3_RANDOM_SIZE) ||
914
- !CBB_add_u8_length_prefixed(&body, &session_id) ||
915
- !CBB_add_bytes(&session_id, session->session_id,
916
- session->session_id_length) ||
1038
+ !CBB_add_u8_length_prefixed(&body, &session_id_bytes) ||
1039
+ !CBB_add_bytes(&session_id_bytes, session_id.data(), session_id.size()) ||
917
1040
  !CBB_add_u16(&body, SSL_CIPHER_get_protocol_id(hs->new_cipher)) ||
918
1041
  !CBB_add_u8(&body, 0 /* no compression */) ||
919
1042
  !ssl_add_serverhello_tlsext(hs, &body) ||
@@ -1083,6 +1206,7 @@ static enum ssl_hs_wait_t do_send_server_key_exchange(SSL_HANDSHAKE *hs) {
1083
1206
  }
1084
1207
  }
1085
1208
 
1209
+ hs->can_release_private_key = true;
1086
1210
  if (!ssl_add_message_cbb(ssl, cbb.get())) {
1087
1211
  return ssl_hs_error;
1088
1212
  }
@@ -1415,6 +1539,7 @@ static enum ssl_hs_wait_t do_read_client_key_exchange(SSL_HANDSHAKE *hs) {
1415
1539
  }
1416
1540
  hs->new_session->extended_master_secret = hs->extended_master_secret;
1417
1541
  CONSTTIME_DECLASSIFY(hs->new_session->secret, hs->new_session->secret_length);
1542
+ hs->can_release_private_key = true;
1418
1543
 
1419
1544
  ssl->method->next_message(ssl);
1420
1545
  hs->state = state12_read_client_certificate_verify;
@@ -1556,7 +1681,7 @@ static enum ssl_hs_wait_t do_read_next_proto(SSL_HANDSHAKE *hs) {
1556
1681
  static enum ssl_hs_wait_t do_read_channel_id(SSL_HANDSHAKE *hs) {
1557
1682
  SSL *const ssl = hs->ssl;
1558
1683
 
1559
- if (!ssl->s3->channel_id_valid) {
1684
+ if (!hs->channel_id_negotiated) {
1560
1685
  hs->state = state12_read_client_finished;
1561
1686
  return ssl_hs_ok;
1562
1687
  }
@@ -1693,6 +1818,9 @@ enum ssl_hs_wait_t ssl_server_handshake(SSL_HANDSHAKE *hs) {
1693
1818
  case state12_read_client_hello:
1694
1819
  ret = do_read_client_hello(hs);
1695
1820
  break;
1821
+ case state12_read_client_hello_after_ech:
1822
+ ret = do_read_client_hello_after_ech(hs);
1823
+ break;
1696
1824
  case state12_select_certificate:
1697
1825
  ret = do_select_certificate(hs);
1698
1826
  break;
@@ -1773,6 +1901,8 @@ const char *ssl_server_handshake_state(SSL_HANDSHAKE *hs) {
1773
1901
  return "TLS server start_accept";
1774
1902
  case state12_read_client_hello:
1775
1903
  return "TLS server read_client_hello";
1904
+ case state12_read_client_hello_after_ech:
1905
+ return "TLS server read_client_hello_after_ech";
1776
1906
  case state12_select_certificate:
1777
1907
  return "TLS server select_certificate";
1778
1908
  case state12_tls13:
@@ -152,7 +152,9 @@
152
152
  #include <utility>
153
153
 
154
154
  #include <openssl/aead.h>
155
+ #include <openssl/curve25519.h>
155
156
  #include <openssl/err.h>
157
+ #include <openssl/hpke.h>
156
158
  #include <openssl/lhash.h>
157
159
  #include <openssl/mem.h>
158
160
  #include <openssl/span.h>
@@ -276,9 +278,9 @@ class Array {
276
278
  T &operator[](size_t i) { return data_[i]; }
277
279
 
278
280
  T *begin() { return data_; }
279
- const T *cbegin() const { return data_; }
281
+ const T *begin() const { return data_; }
280
282
  T *end() { return data_ + size_; }
281
- const T *cend() const { return data_ + size_; }
283
+ const T *end() const { return data_ + size_; }
282
284
 
283
285
  void Reset() { Reset(nullptr, 0); }
284
286
 
@@ -378,6 +380,8 @@ class GrowableArray {
378
380
  return *this;
379
381
  }
380
382
 
383
+ const T *data() const { return array_.data(); }
384
+ T *data() { return array_.data(); }
381
385
  size_t size() const { return size_; }
382
386
  bool empty() const { return size_ == 0; }
383
387
 
@@ -385,9 +389,9 @@ class GrowableArray {
385
389
  T &operator[](size_t i) { return array_[i]; }
386
390
 
387
391
  T *begin() { return array_.data(); }
388
- const T *cbegin() const { return array_.data(); }
392
+ const T *begin() const { return array_.data(); }
389
393
  T *end() { return array_.data() + size_; }
390
- const T *cend() const { return array_.data() + size_; }
394
+ const T *end() const { return array_.data() + size_; }
391
395
 
392
396
  void clear() {
393
397
  size_ = 0;
@@ -484,15 +488,17 @@ bool ssl_get_version_range(const SSL_HANDSHAKE *hs, uint16_t *out_min_version,
484
488
  uint16_t *out_max_version);
485
489
 
486
490
  // ssl_supports_version returns whether |hs| supports |version|.
487
- bool ssl_supports_version(SSL_HANDSHAKE *hs, uint16_t version);
491
+ bool ssl_supports_version(const SSL_HANDSHAKE *hs, uint16_t version);
488
492
 
489
493
  // ssl_method_supports_version returns whether |method| supports |version|.
490
494
  bool ssl_method_supports_version(const SSL_PROTOCOL_METHOD *method,
491
495
  uint16_t version);
492
496
 
493
497
  // ssl_add_supported_versions writes the supported versions of |hs| to |cbb|, in
494
- // decreasing preference order.
495
- bool ssl_add_supported_versions(SSL_HANDSHAKE *hs, CBB *cbb);
498
+ // decreasing preference order. The version list is filtered to those whose
499
+ // protocol version is at least |extra_min_version|.
500
+ bool ssl_add_supported_versions(const SSL_HANDSHAKE *hs, CBB *cbb,
501
+ uint16_t extra_min_version);
496
502
 
497
503
  // ssl_negotiate_version negotiates a common version based on |hs|'s preferences
498
504
  // and the peer preference list in |peer_versions|. On success, it returns true
@@ -675,6 +681,9 @@ class SSLTranscript {
675
681
  SSLTranscript();
676
682
  ~SSLTranscript();
677
683
 
684
+ SSLTranscript(SSLTranscript &&other) = default;
685
+ SSLTranscript &operator=(SSLTranscript &&other) = default;
686
+
678
687
  // Init initializes the handshake transcript. If called on an existing
679
688
  // transcript, it resets the transcript and hash. It returns true on success
680
689
  // and false on failure.
@@ -696,9 +705,9 @@ class SSLTranscript {
696
705
  // the transcript. It returns true on success and false on failure. If the
697
706
  // handshake buffer is still present, |digest| may be any supported digest.
698
707
  // Otherwise, |digest| must match the transcript hash.
699
- bool CopyToHashContext(EVP_MD_CTX *ctx, const EVP_MD *digest);
708
+ bool CopyToHashContext(EVP_MD_CTX *ctx, const EVP_MD *digest) const;
700
709
 
701
- Span<const uint8_t> buffer() {
710
+ Span<const uint8_t> buffer() const {
702
711
  return MakeConstSpan(reinterpret_cast<const uint8_t *>(buffer_->data),
703
712
  buffer_->length);
704
713
  }
@@ -721,14 +730,14 @@ class SSLTranscript {
721
730
  // GetHash writes the handshake hash to |out| which must have room for at
722
731
  // least |DigestLen| bytes. On success, it returns true and sets |*out_len| to
723
732
  // the number of bytes written. Otherwise, it returns false.
724
- bool GetHash(uint8_t *out, size_t *out_len);
733
+ bool GetHash(uint8_t *out, size_t *out_len) const;
725
734
 
726
735
  // GetFinishedMAC computes the MAC for the Finished message into the bytes
727
736
  // pointed by |out| and writes the number of bytes to |*out_len|. |out| must
728
737
  // have room for |EVP_MAX_MD_SIZE| bytes. It returns true on success and false
729
738
  // on failure.
730
739
  bool GetFinishedMAC(uint8_t *out, size_t *out_len, const SSL_SESSION *session,
731
- bool from_server);
740
+ bool from_server) const;
732
741
 
733
742
  private:
734
743
  // buffer_, if non-null, contains the handshake transcript.
@@ -1066,6 +1075,10 @@ class SSLKeyShare {
1066
1075
  // |Serialize|.
1067
1076
  static UniquePtr<SSLKeyShare> Create(CBS *in);
1068
1077
 
1078
+ // Serializes writes the group ID and private key, in a format that can be
1079
+ // read by |Create|.
1080
+ bool Serialize(CBB *out);
1081
+
1069
1082
  // GroupID returns the group ID.
1070
1083
  virtual uint16_t GroupID() const PURE_VIRTUAL;
1071
1084
 
@@ -1090,13 +1103,13 @@ class SSLKeyShare {
1090
1103
  virtual bool Finish(Array<uint8_t> *out_secret, uint8_t *out_alert,
1091
1104
  Span<const uint8_t> peer_key) PURE_VIRTUAL;
1092
1105
 
1093
- // Serialize writes the state of the key exchange to |out|, returning true if
1094
- // successful and false otherwise.
1095
- virtual bool Serialize(CBB *out) { return false; }
1106
+ // SerializePrivateKey writes the private key to |out|, returning true if
1107
+ // successful and false otherwise. It should be called after |Offer|.
1108
+ virtual bool SerializePrivateKey(CBB *out) { return false; }
1096
1109
 
1097
- // Deserialize initializes the state of the key exchange from |in|, returning
1098
- // true if successful and false otherwise. It is called by |Create|.
1099
- virtual bool Deserialize(CBS *in) { return false; }
1110
+ // DeserializePrivateKey initializes the state of the key exchange from |in|,
1111
+ // returning true if successful and false otherwise.
1112
+ virtual bool DeserializePrivateKey(CBS *in) { return false; }
1100
1113
  };
1101
1114
 
1102
1115
  struct NamedGroup {
@@ -1352,9 +1365,10 @@ bool ssl_on_certificate_selected(SSL_HANDSHAKE *hs);
1352
1365
  bool tls13_init_key_schedule(SSL_HANDSHAKE *hs, Span<const uint8_t> psk);
1353
1366
 
1354
1367
  // tls13_init_early_key_schedule initializes the handshake hash and key
1355
- // derivation state from the resumption secret and incorporates the PSK to
1356
- // derive the early secrets. It returns one on success and zero on error.
1357
- bool tls13_init_early_key_schedule(SSL_HANDSHAKE *hs, Span<const uint8_t> psk);
1368
+ // derivation state from |session| for use with 0-RTT. It returns one on success
1369
+ // and zero on error.
1370
+ bool tls13_init_early_key_schedule(SSL_HANDSHAKE *hs,
1371
+ const SSL_SESSION *session);
1358
1372
 
1359
1373
  // tls13_advance_key_schedule incorporates |in| into the key schedule with
1360
1374
  // HKDF-Extract. It returns true on success and false on error.
@@ -1407,25 +1421,184 @@ bool tls13_finished_mac(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len,
1407
1421
  // on failure.
1408
1422
  bool tls13_derive_session_psk(SSL_SESSION *session, Span<const uint8_t> nonce);
1409
1423
 
1410
- // tls13_write_psk_binder calculates the PSK binder value and replaces the last
1411
- // bytes of |msg| with the resulting value. It returns true on success, and
1412
- // false on failure.
1413
- bool tls13_write_psk_binder(SSL_HANDSHAKE *hs, Span<uint8_t> msg);
1424
+ // tls13_write_psk_binder calculates the PSK binder value over |transcript| and
1425
+ // |msg|, and replaces the last bytes of |msg| with the resulting value. It
1426
+ // returns true on success, and false on failure. If |out_binder_len| is
1427
+ // non-NULL, it sets |*out_binder_len| to the length of the value computed.
1428
+ bool tls13_write_psk_binder(const SSL_HANDSHAKE *hs,
1429
+ const SSLTranscript &transcript, Span<uint8_t> msg,
1430
+ size_t *out_binder_len);
1414
1431
 
1415
1432
  // tls13_verify_psk_binder verifies that the handshake transcript, truncated up
1416
1433
  // to the binders has a valid signature using the value of |session|'s
1417
1434
  // resumption secret. It returns true on success, and false on failure.
1418
- bool tls13_verify_psk_binder(SSL_HANDSHAKE *hs, SSL_SESSION *session,
1419
- const SSLMessage &msg, CBS *binders);
1435
+ bool tls13_verify_psk_binder(const SSL_HANDSHAKE *hs,
1436
+ const SSL_SESSION *session, const SSLMessage &msg,
1437
+ CBS *binders);
1438
+
1439
+
1440
+ // Encrypted ClientHello.
1441
+
1442
+ struct ECHConfig {
1443
+ static constexpr bool kAllowUniquePtr = true;
1444
+ // raw contains the serialized ECHConfig.
1445
+ Array<uint8_t> raw;
1446
+ // The following fields alias into |raw|.
1447
+ Span<const uint8_t> public_key;
1448
+ Span<const uint8_t> public_name;
1449
+ Span<const uint8_t> cipher_suites;
1450
+ uint16_t kem_id = 0;
1451
+ uint16_t maximum_name_length = 0;
1452
+ uint8_t config_id = 0;
1453
+ };
1454
+
1455
+ class ECHServerConfig {
1456
+ public:
1457
+ static constexpr bool kAllowUniquePtr = true;
1458
+ ECHServerConfig() = default;
1459
+ ECHServerConfig(const ECHServerConfig &other) = delete;
1460
+ ECHServerConfig &operator=(ECHServerConfig &&) = delete;
1461
+
1462
+ // Init parses |ech_config| as an ECHConfig and saves a copy of |key|.
1463
+ // It returns true on success and false on error.
1464
+ bool Init(Span<const uint8_t> ech_config, const EVP_HPKE_KEY *key,
1465
+ bool is_retry_config);
1466
+
1467
+ // SetupContext sets up |ctx| for a new connection, given the specified
1468
+ // HPKE ciphersuite and encapsulated KEM key. It returns true on success and
1469
+ // false on error. This function may only be called on an initialized object.
1470
+ bool SetupContext(EVP_HPKE_CTX *ctx, uint16_t kdf_id, uint16_t aead_id,
1471
+ Span<const uint8_t> enc) const;
1472
+
1473
+ const ECHConfig &ech_config() const { return ech_config_; }
1474
+ bool is_retry_config() const { return is_retry_config_; }
1475
+
1476
+ private:
1477
+ ECHConfig ech_config_;
1478
+ ScopedEVP_HPKE_KEY key_;
1479
+ bool is_retry_config_ = false;
1480
+ };
1481
+
1482
+ enum ssl_client_hello_type_t {
1483
+ ssl_client_hello_unencrypted,
1484
+ ssl_client_hello_inner,
1485
+ ssl_client_hello_outer,
1486
+ };
1487
+
1488
+ // ssl_decode_client_hello_inner recovers the full ClientHelloInner from the
1489
+ // EncodedClientHelloInner |encoded_client_hello_inner| by replacing its
1490
+ // outer_extensions extension with the referenced extensions from the
1491
+ // ClientHelloOuter |client_hello_outer|. If successful, it writes the recovered
1492
+ // ClientHelloInner to |out_client_hello_inner|. It returns true on success and
1493
+ // false on failure.
1494
+ OPENSSL_EXPORT bool ssl_decode_client_hello_inner(
1495
+ SSL *ssl, uint8_t *out_alert, Array<uint8_t> *out_client_hello_inner,
1496
+ Span<const uint8_t> encoded_client_hello_inner,
1497
+ const SSL_CLIENT_HELLO *client_hello_outer);
1498
+
1499
+ // ssl_client_hello_decrypt attempts to decrypt the given |payload| into
1500
+ // |out_encoded_client_hello_inner|. The decrypted value should be an
1501
+ // EncodedClientHelloInner. It returns false if any fatal errors occur and true
1502
+ // otherwise, regardless of whether the decrypt was successful. It sets
1503
+ // |out_encoded_client_hello_inner| to true if the decryption fails, and false
1504
+ // otherwise.
1505
+ bool ssl_client_hello_decrypt(EVP_HPKE_CTX *hpke_ctx,
1506
+ Array<uint8_t> *out_encoded_client_hello_inner,
1507
+ bool *out_is_decrypt_error,
1508
+ const SSL_CLIENT_HELLO *client_hello_outer,
1509
+ uint16_t kdf_id, uint16_t aead_id,
1510
+ uint8_t config_id, Span<const uint8_t> enc,
1511
+ Span<const uint8_t> payload);
1512
+
1513
+ #define ECH_CONFIRMATION_SIGNAL_LEN 8
1514
+
1515
+ // ssl_ech_confirmation_signal_hello_offset returns the offset of the ECH
1516
+ // confirmation signal in a ServerHello message, including the handshake header.
1517
+ size_t ssl_ech_confirmation_signal_hello_offset(const SSL *ssl);
1518
+
1519
+ // ssl_ech_accept_confirmation computes the server's ECH acceptance signal,
1520
+ // writing it to |out|. The signal is computed by concatenating |transcript|
1521
+ // with |server_hello|. This function handles the fact that eight bytes of
1522
+ // |server_hello| need to be replaced with zeros before hashing. It returns true
1523
+ // on success, and false on failure.
1524
+ bool ssl_ech_accept_confirmation(const SSL_HANDSHAKE *hs, Span<uint8_t> out,
1525
+ const SSLTranscript &transcript,
1526
+ Span<const uint8_t> server_hello);
1527
+
1528
+ // ssl_is_valid_ech_public_name returns true if |public_name| is a valid ECH
1529
+ // public name and false otherwise. It is exported for testing.
1530
+ OPENSSL_EXPORT bool ssl_is_valid_ech_public_name(
1531
+ Span<const uint8_t> public_name);
1532
+
1533
+ // ssl_is_valid_ech_config_list returns true if |ech_config_list| is a valid
1534
+ // ECHConfigList structure and false otherwise.
1535
+ bool ssl_is_valid_ech_config_list(Span<const uint8_t> ech_config_list);
1536
+
1537
+ // ssl_select_ech_config selects an ECHConfig and associated parameters to offer
1538
+ // on the client and updates |hs|. It returns true on success, whether an
1539
+ // ECHConfig was found or not, and false on internal error. On success, the
1540
+ // encapsulated key is written to |out_enc| and |*out_enc_len| is set to the
1541
+ // number of bytes written. If the function did not select an ECHConfig, the
1542
+ // encapsulated key is the empty string.
1543
+ bool ssl_select_ech_config(SSL_HANDSHAKE *hs, Span<uint8_t> out_enc,
1544
+ size_t *out_enc_len);
1545
+
1546
+ // ssl_ech_extension_body_length returns the length of the body of a ClientHello
1547
+ // ECH extension that encrypts |in_len| bytes with |aead| and an 'enc' value of
1548
+ // length |enc_len|. The result does not include the four-byte extension header.
1549
+ size_t ssl_ech_extension_body_length(const EVP_HPKE_AEAD *aead, size_t enc_len,
1550
+ size_t in_len);
1551
+
1552
+ // ssl_encrypt_client_hello constructs a new ClientHelloInner, adds it to the
1553
+ // inner transcript, and encrypts for inclusion in the ClientHelloOuter. |enc|
1554
+ // is the encapsulated key to include in the extension. It returns true on
1555
+ // success and false on error. If not offering ECH, |enc| is ignored and the
1556
+ // function will compute a GREASE ECH extension if necessary, and otherwise
1557
+ // return success while doing nothing.
1558
+ //
1559
+ // Encrypting the ClientHelloInner incorporates all extensions in the
1560
+ // ClientHelloOuter, so all other state necessary for |ssl_add_client_hello|
1561
+ // must already be computed.
1562
+ bool ssl_encrypt_client_hello(SSL_HANDSHAKE *hs, Span<const uint8_t> enc);
1563
+
1564
+
1565
+ // Delegated credentials.
1566
+
1567
+ // This structure stores a delegated credential (DC) as defined by
1568
+ // draft-ietf-tls-subcerts-03.
1569
+ struct DC {
1570
+ static constexpr bool kAllowUniquePtr = true;
1571
+ ~DC();
1572
+
1573
+ // Dup returns a copy of this DC and takes references to |raw| and |pkey|.
1574
+ UniquePtr<DC> Dup();
1420
1575
 
1576
+ // Parse parses the delegated credential stored in |in|. If successful it
1577
+ // returns the parsed structure, otherwise it returns |nullptr| and sets
1578
+ // |*out_alert|.
1579
+ static UniquePtr<DC> Parse(CRYPTO_BUFFER *in, uint8_t *out_alert);
1421
1580
 
1422
- // Encrypted Client Hello.
1581
+ // raw is the delegated credential encoded as specified in draft-ietf-tls-
1582
+ // subcerts-03.
1583
+ UniquePtr<CRYPTO_BUFFER> raw;
1584
+
1585
+ // expected_cert_verify_algorithm is the signature scheme of the DC public
1586
+ // key.
1587
+ uint16_t expected_cert_verify_algorithm = 0;
1588
+
1589
+ // pkey is the public key parsed from |public_key|.
1590
+ UniquePtr<EVP_PKEY> pkey;
1591
+
1592
+ private:
1593
+ friend DC* New<DC>();
1594
+ DC();
1595
+ };
1423
1596
 
1424
- // tls13_ech_accept_confirmation computes the server's ECH acceptance signal,
1425
- // writing it to |out|. It returns true on success, and false on failure.
1426
- bool tls13_ech_accept_confirmation(
1427
- SSL_HANDSHAKE *hs, bssl::Span<uint8_t> out,
1428
- bssl::Span<const uint8_t> server_hello_ech_conf);
1597
+ // ssl_signing_with_dc returns true if the peer has indicated support for
1598
+ // delegated credentials and this host has sent a delegated credential in
1599
+ // response. If this is true then we've committed to using the DC in the
1600
+ // handshake.
1601
+ bool ssl_signing_with_dc(const SSL_HANDSHAKE *hs);
1429
1602
 
1430
1603
 
1431
1604
  // Handshake functions.
@@ -1440,7 +1613,6 @@ enum ssl_hs_wait_t {
1440
1613
  ssl_hs_handoff,
1441
1614
  ssl_hs_handback,
1442
1615
  ssl_hs_x509_lookup,
1443
- ssl_hs_channel_id_lookup,
1444
1616
  ssl_hs_private_key_operation,
1445
1617
  ssl_hs_pending_session,
1446
1618
  ssl_hs_pending_ticket,
@@ -1449,6 +1621,7 @@ enum ssl_hs_wait_t {
1449
1621
  ssl_hs_read_end_of_early_data,
1450
1622
  ssl_hs_read_change_cipher_spec,
1451
1623
  ssl_hs_certificate_verify,
1624
+ ssl_hs_hints_ready,
1452
1625
  };
1453
1626
 
1454
1627
  enum ssl_grease_index_t {
@@ -1458,12 +1631,14 @@ enum ssl_grease_index_t {
1458
1631
  ssl_grease_extension2,
1459
1632
  ssl_grease_version,
1460
1633
  ssl_grease_ticket_extension,
1461
- ssl_grease_last_index = ssl_grease_ticket_extension,
1634
+ ssl_grease_ech_config_id,
1635
+ ssl_grease_last_index = ssl_grease_ech_config_id,
1462
1636
  };
1463
1637
 
1464
1638
  enum tls12_server_hs_state_t {
1465
1639
  state12_start_accept = 0,
1466
1640
  state12_read_client_hello,
1641
+ state12_read_client_hello_after_ech,
1467
1642
  state12_select_certificate,
1468
1643
  state12_tls13,
1469
1644
  state12_select_parameters,
@@ -1515,46 +1690,30 @@ enum handback_t {
1515
1690
  handback_max_value = handback_tls13,
1516
1691
  };
1517
1692
 
1518
-
1519
- // Delegated credentials.
1520
-
1521
- // This structure stores a delegated credential (DC) as defined by
1522
- // draft-ietf-tls-subcerts-03.
1523
- struct DC {
1693
+ // SSL_HANDSHAKE_HINTS contains handshake hints for a connection. See
1694
+ // |SSL_request_handshake_hints| and related functions.
1695
+ struct SSL_HANDSHAKE_HINTS {
1524
1696
  static constexpr bool kAllowUniquePtr = true;
1525
- ~DC();
1526
1697
 
1527
- // Dup returns a copy of this DC and takes references to |raw| and |pkey|.
1528
- UniquePtr<DC> Dup();
1698
+ Array<uint8_t> server_random;
1529
1699
 
1530
- // Parse parses the delegated credential stored in |in|. If successful it
1531
- // returns the parsed structure, otherwise it returns |nullptr| and sets
1532
- // |*out_alert|.
1533
- static UniquePtr<DC> Parse(CRYPTO_BUFFER *in, uint8_t *out_alert);
1700
+ uint16_t key_share_group_id = 0;
1701
+ Array<uint8_t> key_share_public_key;
1702
+ Array<uint8_t> key_share_secret;
1534
1703
 
1535
- // raw is the delegated credential encoded as specified in draft-ietf-tls-
1536
- // subcerts-03.
1537
- UniquePtr<CRYPTO_BUFFER> raw;
1704
+ uint16_t signature_algorithm = 0;
1705
+ Array<uint8_t> signature_input;
1706
+ Array<uint8_t> signature_spki;
1707
+ Array<uint8_t> signature;
1538
1708
 
1539
- // expected_cert_verify_algorithm is the signature scheme of the DC public
1540
- // key.
1541
- uint16_t expected_cert_verify_algorithm = 0;
1709
+ Array<uint8_t> decrypted_psk;
1710
+ bool ignore_psk = false;
1542
1711
 
1543
- // pkey is the public key parsed from |public_key|.
1544
- UniquePtr<EVP_PKEY> pkey;
1545
-
1546
- private:
1547
- friend DC* New<DC>();
1548
- DC();
1712
+ uint16_t cert_compression_alg_id = 0;
1713
+ Array<uint8_t> cert_compression_input;
1714
+ Array<uint8_t> cert_compression_output;
1549
1715
  };
1550
1716
 
1551
- // ssl_signing_with_dc returns true if the peer has indicated support for
1552
- // delegated credentials and this host has sent a delegated credential in
1553
- // response. If this is true then we've committed to using the DC in the
1554
- // handshake.
1555
- bool ssl_signing_with_dc(const SSL_HANDSHAKE *hs);
1556
-
1557
-
1558
1717
  struct SSL_HANDSHAKE {
1559
1718
  explicit SSL_HANDSHAKE(SSL *ssl);
1560
1719
  ~SSL_HANDSHAKE();
@@ -1599,7 +1758,21 @@ struct SSL_HANDSHAKE {
1599
1758
  public:
1600
1759
  void ResizeSecrets(size_t hash_len);
1601
1760
 
1761
+ // GetClientHello, on the server, returns either the normal ClientHello
1762
+ // message or the ClientHelloInner if it has been serialized to
1763
+ // |ech_client_hello_buf|. This function should only be called when the
1764
+ // current message is a ClientHello. It returns true on success and false on
1765
+ // error.
1766
+ //
1767
+ // Note that fields of the returned |out_msg| and |out_client_hello| point
1768
+ // into a handshake-owned buffer, so their lifetimes should not exceed this
1769
+ // SSL_HANDSHAKE.
1770
+ bool GetClientHello(SSLMessage *out_msg, SSL_CLIENT_HELLO *out_client_hello);
1771
+
1602
1772
  Span<uint8_t> secret() { return MakeSpan(secret_, hash_len_); }
1773
+ Span<const uint8_t> secret() const {
1774
+ return MakeConstSpan(secret_, hash_len_);
1775
+ }
1603
1776
  Span<uint8_t> early_traffic_secret() {
1604
1777
  return MakeSpan(early_traffic_secret_, hash_len_);
1605
1778
  }
@@ -1629,9 +1802,9 @@ struct SSL_HANDSHAKE {
1629
1802
  uint32_t received;
1630
1803
  } extensions;
1631
1804
 
1632
- // retry_group is the group ID selected by the server in HelloRetryRequest in
1633
- // TLS 1.3.
1634
- uint16_t retry_group = 0;
1805
+ // inner_extensions_sent, on clients that offer ECH, is |extensions.sent| for
1806
+ // the ClientHelloInner.
1807
+ uint32_t inner_extensions_sent = 0;
1635
1808
 
1636
1809
  // error, if |wait| is |ssl_hs_error|, is the error the handshake failed on.
1637
1810
  UniquePtr<ERR_SAVE_STATE> error;
@@ -1644,15 +1817,26 @@ struct SSL_HANDSHAKE {
1644
1817
  // transcript is the current handshake transcript.
1645
1818
  SSLTranscript transcript;
1646
1819
 
1820
+ // inner_transcript, on the client, is the handshake transcript for the
1821
+ // ClientHelloInner handshake. It is moved to |transcript| if the server
1822
+ // accepts ECH.
1823
+ SSLTranscript inner_transcript;
1824
+
1825
+ // inner_client_random is the ClientHello random value used with
1826
+ // ClientHelloInner.
1827
+ uint8_t inner_client_random[SSL3_RANDOM_SIZE] = {0};
1828
+
1647
1829
  // cookie is the value of the cookie received from the server, if any.
1648
1830
  Array<uint8_t> cookie;
1649
1831
 
1650
- // ech_grease contains the bytes of the GREASE ECH extension that was sent in
1651
- // the first ClientHello.
1652
- Array<uint8_t> ech_grease;
1832
+ // ech_client_bytes contains the ECH extension to send in the ClientHello.
1833
+ Array<uint8_t> ech_client_bytes;
1834
+
1835
+ // ech_client_hello_buf, on the server, contains the bytes of the
1836
+ // reconstructed ClientHelloInner message.
1837
+ Array<uint8_t> ech_client_hello_buf;
1653
1838
 
1654
- // key_share_bytes is the value of the previously sent KeyShare extension by
1655
- // the client in TLS 1.3.
1839
+ // key_share_bytes is the key_share extension that the client should send.
1656
1840
  Array<uint8_t> key_share_bytes;
1657
1841
 
1658
1842
  // ecdh_public_key, for servers, is the key share to be sent to the client in
@@ -1676,17 +1860,21 @@ struct SSL_HANDSHAKE {
1676
1860
  // peer_key is the peer's ECDH key for a TLS 1.2 client.
1677
1861
  Array<uint8_t> peer_key;
1678
1862
 
1679
- // negotiated_token_binding_version is used by a server to store the
1680
- // on-the-wire encoding of the Token Binding protocol version to advertise in
1681
- // the ServerHello/EncryptedExtensions if the Token Binding extension is to be
1682
- // sent.
1683
- uint16_t negotiated_token_binding_version;
1863
+ // extension_permutation is the permutation to apply to ClientHello
1864
+ // extensions. It maps indices into the |kExtensions| table into other
1865
+ // indices.
1866
+ Array<uint8_t> extension_permutation;
1684
1867
 
1685
1868
  // cert_compression_alg_id, for a server, contains the negotiated certificate
1686
1869
  // compression algorithm for this client. It is only valid if
1687
1870
  // |cert_compression_negotiated| is true.
1688
1871
  uint16_t cert_compression_alg_id;
1689
1872
 
1873
+ // ech_hpke_ctx is the HPKE context used in ECH. On the server, it is
1874
+ // initialized if |ech_accept| is true. On the client, it is initialized if
1875
+ // |selected_ech_config| is not nullptr.
1876
+ ScopedEVP_HPKE_CTX ech_hpke_ctx;
1877
+
1690
1878
  // server_params, in a TLS 1.2 server, stores the ServerKeyExchange
1691
1879
  // parameters. It has client and server randoms prepended for signing
1692
1880
  // convenience.
@@ -1723,12 +1911,29 @@ struct SSL_HANDSHAKE {
1723
1911
  // the client if |in_early_data| is true.
1724
1912
  UniquePtr<SSL_SESSION> early_session;
1725
1913
 
1914
+ // ssl_ech_keys, for servers, is the set of ECH keys to use with this
1915
+ // handshake. This is copied from |SSL_CTX| to ensure consistent behavior as
1916
+ // |SSL_CTX| rotates keys.
1917
+ UniquePtr<SSL_ECH_KEYS> ech_keys;
1918
+
1919
+ // selected_ech_config, for clients, is the ECHConfig the client uses to offer
1920
+ // ECH, or nullptr if ECH is not being offered. If non-NULL, |ech_hpke_ctx|
1921
+ // will be initialized.
1922
+ UniquePtr<ECHConfig> selected_ech_config;
1923
+
1726
1924
  // new_cipher is the cipher being negotiated in this handshake.
1727
1925
  const SSL_CIPHER *new_cipher = nullptr;
1728
1926
 
1729
1927
  // key_block is the record-layer key block for TLS 1.2 and earlier.
1730
1928
  Array<uint8_t> key_block;
1731
1929
 
1930
+ // hints contains the handshake hints for this connection. If
1931
+ // |hints_requested| is true, this field is non-null and contains the pending
1932
+ // hints to filled as the predicted handshake progresses. Otherwise, this
1933
+ // field, if non-null, contains hints configured by the caller and will
1934
+ // influence the handshake on match.
1935
+ UniquePtr<SSL_HANDSHAKE_HINTS> hints;
1936
+
1732
1937
  // ech_present, on the server, indicates whether the ClientHello contained an
1733
1938
  // encrypted_client_hello extension.
1734
1939
  bool ech_present : 1;
@@ -1740,10 +1945,6 @@ struct SSL_HANDSHAKE {
1740
1945
  // scts_requested is true if the SCT extension is in the ClientHello.
1741
1946
  bool scts_requested : 1;
1742
1947
 
1743
- // needs_psk_binder is true if the ClientHello has a placeholder PSK binder to
1744
- // be filled in.
1745
- bool needs_psk_binder : 1;
1746
-
1747
1948
  // handshake_finalized is true once the handshake has completed, at which
1748
1949
  // point accessors should use the established state.
1749
1950
  bool handshake_finalized : 1;
@@ -1805,15 +2006,17 @@ struct SSL_HANDSHAKE {
1805
2006
  // in progress.
1806
2007
  bool pending_private_key_op : 1;
1807
2008
 
1808
- // grease_seeded is true if |grease_seed| has been initialized.
1809
- bool grease_seeded : 1;
1810
-
1811
2009
  // handback indicates that a server should pause the handshake after
1812
2010
  // finishing operations that require private key material, in such a way that
1813
2011
  // |SSL_get_error| returns |SSL_ERROR_HANDBACK|. It is set by
1814
2012
  // |SSL_apply_handoff|.
1815
2013
  bool handback : 1;
1816
2014
 
2015
+ // hints_requested indicates the caller has requested handshake hints. Only
2016
+ // the first round-trip of the handshake will complete, after which the
2017
+ // |hints| structure can be serialized.
2018
+ bool hints_requested : 1;
2019
+
1817
2020
  // cert_compression_negotiated is true iff |cert_compression_alg_id| is valid.
1818
2021
  bool cert_compression_negotiated : 1;
1819
2022
 
@@ -1821,6 +2024,14 @@ struct SSL_HANDSHAKE {
1821
2024
  // which implemented TLS 1.3 incorrectly.
1822
2025
  bool apply_jdk11_workaround : 1;
1823
2026
 
2027
+ // can_release_private_key is true if the private key will no longer be used
2028
+ // in this handshake.
2029
+ bool can_release_private_key : 1;
2030
+
2031
+ // channel_id_negotiated is true if Channel ID should be used in this
2032
+ // handshake.
2033
+ bool channel_id_negotiated : 1;
2034
+
1824
2035
  // client_version is the value sent or received in the ClientHello version.
1825
2036
  uint16_t client_version = 0;
1826
2037
 
@@ -1832,12 +2043,14 @@ struct SSL_HANDSHAKE {
1832
2043
  // record layer.
1833
2044
  uint16_t early_data_written = 0;
1834
2045
 
2046
+ // ech_config_id is the ECH config sent by the client.
2047
+ uint8_t ech_config_id = 0;
2048
+
1835
2049
  // session_id is the session ID in the ClientHello.
1836
2050
  uint8_t session_id[SSL_MAX_SSL_SESSION_ID_LENGTH] = {0};
1837
2051
  uint8_t session_id_len = 0;
1838
2052
 
1839
- // grease_seed is the entropy for GREASE values. It is valid if
1840
- // |grease_seeded| is true.
2053
+ // grease_seed is the entropy for GREASE values.
1841
2054
  uint8_t grease_seed[ssl_grease_last_index + 1] = {0};
1842
2055
  };
1843
2056
 
@@ -1897,14 +2110,24 @@ bool tls13_process_new_session_ticket(SSL *ssl, const SSLMessage &msg);
1897
2110
  bssl::UniquePtr<SSL_SESSION> tls13_create_session_with_ticket(SSL *ssl,
1898
2111
  CBS *body);
1899
2112
 
2113
+ // ssl_setup_extension_permutation computes a ClientHello extension permutation
2114
+ // for |hs|, if applicable. It returns true on success and false on error.
2115
+ bool ssl_setup_extension_permutation(SSL_HANDSHAKE *hs);
2116
+
2117
+ // ssl_setup_key_shares computes client key shares and saves them in |hs|. It
2118
+ // returns true on success and false on failure. If |override_group_id| is zero,
2119
+ // it offers the default groups, including GREASE. If it is non-zero, it offers
2120
+ // a single key share of the specified group.
2121
+ bool ssl_setup_key_shares(SSL_HANDSHAKE *hs, uint16_t override_group_id);
2122
+
1900
2123
  bool ssl_ext_key_share_parse_serverhello(SSL_HANDSHAKE *hs,
1901
2124
  Array<uint8_t> *out_secret,
1902
2125
  uint8_t *out_alert, CBS *contents);
1903
2126
  bool ssl_ext_key_share_parse_clienthello(SSL_HANDSHAKE *hs, bool *out_found,
1904
- Array<uint8_t> *out_secret,
1905
- uint8_t *out_alert, CBS *contents);
1906
- bool ssl_ext_key_share_add_serverhello(SSL_HANDSHAKE *hs, CBB *out,
1907
- bool dry_run);
2127
+ Span<const uint8_t> *out_peer_key,
2128
+ uint8_t *out_alert,
2129
+ const SSL_CLIENT_HELLO *client_hello);
2130
+ bool ssl_ext_key_share_add_serverhello(SSL_HANDSHAKE *hs, CBB *out);
1908
2131
 
1909
2132
  bool ssl_ext_pre_shared_key_parse_serverhello(SSL_HANDSHAKE *hs,
1910
2133
  uint8_t *out_alert,
@@ -1919,7 +2142,17 @@ bool ssl_ext_pre_shared_key_add_serverhello(SSL_HANDSHAKE *hs, CBB *out);
1919
2142
  // returns whether it's valid.
1920
2143
  bool ssl_is_sct_list_valid(const CBS *contents);
1921
2144
 
1922
- bool ssl_write_client_hello(SSL_HANDSHAKE *hs);
2145
+ // ssl_write_client_hello_without_extensions writes a ClientHello to |out|,
2146
+ // up to the extensions field. |type| determines the type of ClientHello to
2147
+ // write. If |omit_session_id| is true, the session ID is empty.
2148
+ bool ssl_write_client_hello_without_extensions(const SSL_HANDSHAKE *hs,
2149
+ CBB *cbb,
2150
+ ssl_client_hello_type_t type,
2151
+ bool empty_session_id);
2152
+
2153
+ // ssl_add_client_hello constructs a ClientHello and adds it to the outgoing
2154
+ // flight. It returns true on success and false on error.
2155
+ bool ssl_add_client_hello(SSL_HANDSHAKE *hs);
1923
2156
 
1924
2157
  enum ssl_cert_verify_context_t {
1925
2158
  ssl_cert_verify_server,
@@ -1935,6 +2168,9 @@ bool tls13_get_cert_verify_signature_input(
1935
2168
  SSL_HANDSHAKE *hs, Array<uint8_t> *out,
1936
2169
  enum ssl_cert_verify_context_t cert_verify_context);
1937
2170
 
2171
+ // ssl_is_valid_alpn_list returns whether |in| is a valid ALPN protocol list.
2172
+ bool ssl_is_valid_alpn_list(Span<const uint8_t> in);
2173
+
1938
2174
  // ssl_is_alpn_protocol_allowed returns whether |protocol| is a valid server
1939
2175
  // selection for |hs->ssl|'s client preferences.
1940
2176
  bool ssl_is_alpn_protocol_allowed(const SSL_HANDSHAKE *hs,
@@ -1946,6 +2182,13 @@ bool ssl_is_alpn_protocol_allowed(const SSL_HANDSHAKE *hs,
1946
2182
  bool ssl_negotiate_alpn(SSL_HANDSHAKE *hs, uint8_t *out_alert,
1947
2183
  const SSL_CLIENT_HELLO *client_hello);
1948
2184
 
2185
+ // ssl_get_local_application_settings looks up the configured ALPS value for
2186
+ // |protocol|. If found, it sets |*out_settings| to the value and returns true.
2187
+ // Otherwise, it returns false.
2188
+ bool ssl_get_local_application_settings(const SSL_HANDSHAKE *hs,
2189
+ Span<const uint8_t> *out_settings,
2190
+ Span<const uint8_t> protocol);
2191
+
1949
2192
  // ssl_negotiate_alps negotiates the ALPS extension, if applicable. It returns
1950
2193
  // true on successful negotiation or if nothing was negotiated. It returns false
1951
2194
  // and sets |*out_alert| to an alert on error.
@@ -1982,6 +2225,10 @@ bool ssl_output_cert_chain(SSL_HANDSHAKE *hs);
1982
2225
  // handshake. Note, in TLS 1.2 resumptions, this session is immutable.
1983
2226
  const SSL_SESSION *ssl_handshake_session(const SSL_HANDSHAKE *hs);
1984
2227
 
2228
+ // ssl_done_writing_client_hello is called after the last ClientHello is written
2229
+ // by |hs|. It releases some memory that is no longer needed.
2230
+ void ssl_done_writing_client_hello(SSL_HANDSHAKE *hs);
2231
+
1985
2232
 
1986
2233
  // SSLKEYLOGFILE functions.
1987
2234
 
@@ -1993,8 +2240,11 @@ bool ssl_log_secret(const SSL *ssl, const char *label,
1993
2240
 
1994
2241
  // ClientHello functions.
1995
2242
 
1996
- bool ssl_client_hello_init(const SSL *ssl, SSL_CLIENT_HELLO *out,
1997
- const SSLMessage &msg);
2243
+ // ssl_client_hello_init parses |body| as a ClientHello message, excluding the
2244
+ // message header, and writes the result to |*out|. It returns true on success
2245
+ // and false on error. This function is exported for testing.
2246
+ OPENSSL_EXPORT bool ssl_client_hello_init(const SSL *ssl, SSL_CLIENT_HELLO *out,
2247
+ Span<const uint8_t> body);
1998
2248
 
1999
2249
  bool ssl_client_hello_get_extension(const SSL_CLIENT_HELLO *client_hello,
2000
2250
  CBS *out, uint16_t extension_type);
@@ -2009,7 +2259,8 @@ bool ssl_client_cipher_list_contains_cipher(
2009
2259
  // connection, the values for each index will be deterministic. This allows the
2010
2260
  // same ClientHello be sent twice for a HelloRetryRequest or the same group be
2011
2261
  // advertised in both supported_groups and key_shares.
2012
- uint16_t ssl_get_grease_value(SSL_HANDSHAKE *hs, enum ssl_grease_index_t index);
2262
+ uint16_t ssl_get_grease_value(const SSL_HANDSHAKE *hs,
2263
+ enum ssl_grease_index_t index);
2013
2264
 
2014
2265
 
2015
2266
  // Signature algorithms.
@@ -2169,10 +2420,11 @@ struct SSL_PROTOCOL_METHOD {
2169
2420
  // init_message begins a new handshake message of type |type|. |cbb| is the
2170
2421
  // root CBB to be passed into |finish_message|. |*body| is set to a child CBB
2171
2422
  // the caller should write to. It returns true on success and false on error.
2172
- bool (*init_message)(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
2423
+ bool (*init_message)(const SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
2173
2424
  // finish_message finishes a handshake message. It sets |*out_msg| to the
2174
2425
  // serialized message. It returns true on success and false on error.
2175
- bool (*finish_message)(SSL *ssl, CBB *cbb, bssl::Array<uint8_t> *out_msg);
2426
+ bool (*finish_message)(const SSL *ssl, CBB *cbb,
2427
+ bssl::Array<uint8_t> *out_msg);
2176
2428
  // add_message adds a handshake message to the pending flight. It returns
2177
2429
  // true on success and false on error.
2178
2430
  bool (*add_message)(SSL *ssl, bssl::Array<uint8_t> msg);
@@ -2383,9 +2635,8 @@ struct SSL3_STATE {
2383
2635
  // key_update_count is the number of consecutive KeyUpdates received.
2384
2636
  uint8_t key_update_count = 0;
2385
2637
 
2386
- // The negotiated Token Binding key parameter. Only valid if
2387
- // |token_binding_negotiated| is set.
2388
- uint8_t negotiated_token_binding_param = 0;
2638
+ // ech_accept indicates whether ECH was accepted by the server.
2639
+ bool ech_accept : 1;
2389
2640
 
2390
2641
  // skip_early_data instructs the record layer to skip unexpected early data
2391
2642
  // messages when 0RTT is rejected.
@@ -2420,9 +2671,8 @@ struct SSL3_STATE {
2420
2671
 
2421
2672
  bool send_connection_binding : 1;
2422
2673
 
2423
- // In a client, this means that the server supported Channel ID and that a
2424
- // Channel ID was sent. In a server it means that we echoed support for
2425
- // Channel IDs and that |channel_id| will be valid after the handshake.
2674
+ // channel_id_valid is true if, on the server, the client has negotiated a
2675
+ // Channel ID and the |channel_id| field is filled in.
2426
2676
  bool channel_id_valid : 1;
2427
2677
 
2428
2678
  // key_update_pending is true if we have a KeyUpdate acknowledgment
@@ -2435,9 +2685,6 @@ struct SSL3_STATE {
2435
2685
  // early_data_accepted is true if early data was accepted by the server.
2436
2686
  bool early_data_accepted : 1;
2437
2687
 
2438
- // token_binding_negotiated is set if Token Binding was negotiated.
2439
- bool token_binding_negotiated : 1;
2440
-
2441
2688
  // alert_dispatch is true there is an alert in |send_alert| to be sent.
2442
2689
  bool alert_dispatch : 1;
2443
2690
 
@@ -2720,7 +2967,8 @@ struct SSL_CONFIG {
2720
2967
 
2721
2968
  Array<uint16_t> supported_group_list; // our list
2722
2969
 
2723
- // The client's Channel ID private key.
2970
+ // channel_id_private is the client's Channel ID private key, or null if
2971
+ // Channel ID should not be offered on this connection.
2724
2972
  UniquePtr<EVP_PKEY> channel_id_private;
2725
2973
 
2726
2974
  // For a client, this contains the list of supported protocols in wire
@@ -2731,9 +2979,6 @@ struct SSL_CONFIG {
2731
2979
  // along with their corresponding ALPS values.
2732
2980
  GrowableArray<ALPSConfig> alps_configs;
2733
2981
 
2734
- // Contains a list of supported Token Binding key parameters.
2735
- Array<uint8_t> token_binding_params;
2736
-
2737
2982
  // Contains the QUIC transport params that this endpoint will send.
2738
2983
  Array<uint8_t> quic_transport_params;
2739
2984
 
@@ -2748,6 +2993,10 @@ struct SSL_CONFIG {
2748
2993
  // DTLS-SRTP.
2749
2994
  UniquePtr<STACK_OF(SRTP_PROTECTION_PROFILE)> srtp_profiles;
2750
2995
 
2996
+ // client_ech_config_list, if not empty, is a serialized ECHConfigList
2997
+ // structure for the client to use when negotiating ECH.
2998
+ Array<uint8_t> client_ech_config_list;
2999
+
2751
3000
  // verify_mode is a bitmask of |SSL_VERIFY_*| values.
2752
3001
  uint8_t verify_mode = SSL_VERIFY_NONE;
2753
3002
 
@@ -2762,9 +3011,8 @@ struct SSL_CONFIG {
2762
3011
  // whether OCSP stapling will be requested.
2763
3012
  bool ocsp_stapling_enabled : 1;
2764
3013
 
2765
- // channel_id_enabled is copied from the |SSL_CTX|. For a server, means that
2766
- // we'll accept Channel IDs from clients. For a client, means that we'll
2767
- // advertise support.
3014
+ // channel_id_enabled is copied from the |SSL_CTX|. For a server, it means
3015
+ // that we'll accept Channel IDs from clients. It is ignored on the client.
2768
3016
  bool channel_id_enabled : 1;
2769
3017
 
2770
3018
  // If enforce_rsa_key_usage is true, the handshake will fail if the
@@ -2794,6 +3042,9 @@ struct SSL_CONFIG {
2794
3042
  // QUIC drafts up to and including 32 used a different TLS extension
2795
3043
  // codepoint to convey QUIC's transport parameters.
2796
3044
  bool quic_use_legacy_codepoint : 1;
3045
+
3046
+ // permute_extensions is whether to permute extensions when sending messages.
3047
+ bool permute_extensions : 1;
2797
3048
  };
2798
3049
 
2799
3050
  // From RFC 8446, used in determining PSK modes.
@@ -2814,7 +3065,7 @@ bool ssl_is_key_type_supported(int key_type);
2814
3065
  bool ssl_compare_public_and_private_key(const EVP_PKEY *pubkey,
2815
3066
  const EVP_PKEY *privkey);
2816
3067
  bool ssl_cert_check_private_key(const CERT *cert, const EVP_PKEY *privkey);
2817
- int ssl_get_new_session(SSL_HANDSHAKE *hs, int is_server);
3068
+ bool ssl_get_new_session(SSL_HANDSHAKE *hs);
2818
3069
  int ssl_encrypt_ticket(SSL_HANDSHAKE *hs, CBB *out, const SSL_SESSION *session);
2819
3070
  int ssl_ctx_rotate_ticket_encryption_key(SSL_CTX *ctx);
2820
3071
 
@@ -2917,14 +3168,14 @@ int tls_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *buf,
2917
3168
  bool tls_new(SSL *ssl);
2918
3169
  void tls_free(SSL *ssl);
2919
3170
 
2920
- bool tls_init_message(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
2921
- bool tls_finish_message(SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
3171
+ bool tls_init_message(const SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
3172
+ bool tls_finish_message(const SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
2922
3173
  bool tls_add_message(SSL *ssl, Array<uint8_t> msg);
2923
3174
  bool tls_add_change_cipher_spec(SSL *ssl);
2924
3175
  int tls_flush_flight(SSL *ssl);
2925
3176
 
2926
- bool dtls1_init_message(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
2927
- bool dtls1_finish_message(SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
3177
+ bool dtls1_init_message(const SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
3178
+ bool dtls1_finish_message(const SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
2928
3179
  bool dtls1_add_message(SSL *ssl, Array<uint8_t> msg);
2929
3180
  bool dtls1_add_change_cipher_spec(SSL *ssl);
2930
3181
  int dtls1_flush_flight(SSL *ssl);
@@ -3009,11 +3260,27 @@ bool tls1_set_curves(Array<uint16_t> *out_group_ids, Span<const int> curves);
3009
3260
  // false.
3010
3261
  bool tls1_set_curves_list(Array<uint16_t> *out_group_ids, const char *curves);
3011
3262
 
3012
- // ssl_add_clienthello_tlsext writes ClientHello extensions to |out|. It returns
3013
- // true on success and false on failure. The |header_len| argument is the length
3014
- // of the ClientHello written so far and is used to compute the padding length.
3015
- // (It does not include the record header.)
3016
- bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, size_t header_len);
3263
+ // ssl_add_clienthello_tlsext writes ClientHello extensions to |out| for |type|.
3264
+ // It returns true on success and false on failure. The |header_len| argument is
3265
+ // the length of the ClientHello written so far and is used to compute the
3266
+ // padding length. (It does not include the record header or handshake headers.)
3267
+ //
3268
+ // If |type| is |ssl_client_hello_inner|, this function also writes the
3269
+ // compressed extensions to |out_encoded|. Otherwise, |out_encoded| should be
3270
+ // nullptr.
3271
+ //
3272
+ // On success, the function sets |*out_needs_psk_binder| to whether the last
3273
+ // ClientHello extension was the pre_shared_key extension and needs a PSK binder
3274
+ // filled in. The caller should then update |out| and, if applicable,
3275
+ // |out_encoded| with the binder after completing the whole message.
3276
+ //
3277
+ // If |omit_ech_len| is non-zero, the ECH extension is omitted, but padding is
3278
+ // computed as if there were an extension of length |omit_ech_len|. This is used
3279
+ // to compute ClientHelloOuterAAD.
3280
+ bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, CBB *out_encoded,
3281
+ bool *out_needs_psk_binder,
3282
+ ssl_client_hello_type_t type, size_t header_len,
3283
+ size_t omit_ech_len);
3017
3284
 
3018
3285
  bool ssl_add_serverhello_tlsext(SSL_HANDSHAKE *hs, CBB *out);
3019
3286
  bool ssl_parse_clienthello_tlsext(SSL_HANDSHAKE *hs,
@@ -3056,12 +3323,6 @@ bool tls1_channel_id_hash(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len);
3056
3323
  // data.
3057
3324
  bool tls1_record_handshake_hashes_for_channel_id(SSL_HANDSHAKE *hs);
3058
3325
 
3059
- // ssl_do_channel_id_callback checks runs |hs->ssl->ctx->channel_id_cb| if
3060
- // necessary. It returns true on success and false on fatal error. Note that, on
3061
- // success, |hs->ssl->channel_id_private| may be unset, in which case the
3062
- // operation should be retried later.
3063
- bool ssl_do_channel_id_callback(SSL_HANDSHAKE *hs);
3064
-
3065
3326
  // ssl_can_write returns whether |ssl| is allowed to write.
3066
3327
  bool ssl_can_write(const SSL *ssl);
3067
3328
 
@@ -3185,9 +3446,6 @@ struct ssl_ctx_st {
3185
3446
  int (*client_cert_cb)(SSL *ssl, X509 **out_x509,
3186
3447
  EVP_PKEY **out_pkey) = nullptr;
3187
3448
 
3188
- // get channel id callback
3189
- void (*channel_id_cb)(SSL *ssl, EVP_PKEY **out_pkey) = nullptr;
3190
-
3191
3449
  CRYPTO_EX_DATA ex_data;
3192
3450
 
3193
3451
  // Default values used when no per-SSL value is defined follow
@@ -3315,9 +3573,15 @@ struct ssl_ctx_st {
3315
3573
  // Supported group values inherited by SSL structure
3316
3574
  bssl::Array<uint16_t> supported_group_list;
3317
3575
 
3318
- // The client's Channel ID private key.
3576
+ // channel_id_private is the client's Channel ID private key, or null if
3577
+ // Channel ID should not be offered on this connection.
3319
3578
  bssl::UniquePtr<EVP_PKEY> channel_id_private;
3320
3579
 
3580
+ // ech_keys contains the server's list of ECHConfig values and associated
3581
+ // private keys. This list may be swapped out at any time, so all access must
3582
+ // be synchronized through |lock|.
3583
+ bssl::UniquePtr<SSL_ECH_KEYS> ech_keys;
3584
+
3321
3585
  // keylog_callback, if not NULL, is the key logging callback. See
3322
3586
  // |SSL_CTX_set_keylog_callback|.
3323
3587
  void (*keylog_callback)(const SSL *ssl, const char *line) = nullptr;
@@ -3365,9 +3629,12 @@ struct ssl_ctx_st {
3365
3629
  // advertise support.
3366
3630
  bool channel_id_enabled : 1;
3367
3631
 
3368
- // grease_enabled is whether draft-davidben-tls-grease-01 is enabled.
3632
+ // grease_enabled is whether GREASE (RFC 8701) is enabled.
3369
3633
  bool grease_enabled : 1;
3370
3634
 
3635
+ // permute_extensions is whether to permute extensions when sending messages.
3636
+ bool permute_extensions : 1;
3637
+
3371
3638
  // allow_unknown_alpn_protos is whether the client allows unsolicited ALPN
3372
3639
  // protocols from the peer.
3373
3640
  bool allow_unknown_alpn_protos : 1;
@@ -3631,5 +3898,17 @@ struct ssl_session_st {
3631
3898
  friend void SSL_SESSION_free(SSL_SESSION *);
3632
3899
  };
3633
3900
 
3901
+ struct ssl_ech_keys_st {
3902
+ ssl_ech_keys_st() = default;
3903
+ ssl_ech_keys_st(const ssl_ech_keys_st &) = delete;
3904
+ ssl_ech_keys_st &operator=(const ssl_ech_keys_st &) = delete;
3905
+
3906
+ bssl::GrowableArray<bssl::UniquePtr<bssl::ECHServerConfig>> configs;
3907
+ CRYPTO_refcount_t references = 1;
3908
+
3909
+ private:
3910
+ ~ssl_ech_keys_st() = default;
3911
+ friend void SSL_ECH_KEYS_free(SSL_ECH_KEYS *);
3912
+ };
3634
3913
 
3635
3914
  #endif // OPENSSL_HEADER_SSL_INTERNAL_H