grpc 1.83.1 → 1.84.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +21 -17
  3. data/include/grpc/credentials.h +10 -0
  4. data/include/grpc/grpc_security_constants.h +2 -0
  5. data/include/grpc/impl/channel_arg_names.h +9 -0
  6. data/src/core/call/call_filters.h +4 -2
  7. data/src/core/call/client_call.cc +20 -8
  8. data/src/core/call/client_call.h +4 -0
  9. data/src/core/call/interception_chain.cc +2 -0
  10. data/src/core/call/interception_chain.h +14 -1
  11. data/src/core/call/metadata.cc +1 -3
  12. data/src/core/call/metadata_batch.h +13 -5
  13. data/src/core/call/server_call.cc +31 -14
  14. data/src/core/call/server_call.h +4 -0
  15. data/src/core/channelz/text_encode.cc +9 -4
  16. data/src/core/channelz/v2tov1/convert.cc +2 -2
  17. data/src/core/client_channel/backup_poller.cc +1 -2
  18. data/src/core/client_channel/client_channel.cc +6 -33
  19. data/src/core/client_channel/client_channel_filter.cc +22 -55
  20. data/src/core/client_channel/client_channel_filter.h +2 -2
  21. data/src/core/client_channel/client_channel_service_config.cc +3 -19
  22. data/src/core/client_channel/direct_channel.cc +7 -1
  23. data/src/core/client_channel/direct_channel.h +2 -2
  24. data/src/core/client_channel/load_balanced_call_destination.cc +5 -3
  25. data/src/core/client_channel/retry_filter_legacy_call_data.cc +5 -12
  26. data/src/core/client_channel/subchannel.cc +310 -1058
  27. data/src/core/client_channel/subchannel.h +44 -329
  28. data/src/core/client_channel/subchannel_metrics.cc +48 -0
  29. data/src/core/client_channel/subchannel_metrics.h +60 -0
  30. data/src/core/credentials/call/external/file_external_account_credentials.cc +1 -1
  31. data/src/core/credentials/call/external/url_external_account_credentials.cc +2 -3
  32. data/src/core/credentials/call/gcp_service_account_identity/gcp_service_account_identity_credentials.cc +8 -24
  33. data/src/core/credentials/call/gcp_service_account_identity/gcp_service_account_identity_credentials.h +3 -6
  34. data/src/core/credentials/call/gdch_service_account/gdch_service_account_credentials.cc +525 -0
  35. data/src/core/credentials/call/gdch_service_account/gdch_service_account_credentials.h +138 -0
  36. data/src/core/credentials/call/json_util.h +1 -0
  37. data/src/core/credentials/call/jwt/json_token.cc +10 -2
  38. data/src/core/credentials/call/jwt/jwt_verifier.cc +15 -1
  39. data/src/core/credentials/call/jwt_token_file/jwt_token_file_call_credentials.cc +1 -1
  40. data/src/core/credentials/call/oauth2/oauth2_credentials.cc +42 -79
  41. data/src/core/credentials/call/oauth2/oauth2_credentials.h +2 -5
  42. data/src/core/credentials/call/token_fetcher/token_fetcher_credentials.cc +52 -31
  43. data/src/core/credentials/call/token_fetcher/token_fetcher_credentials.h +21 -8
  44. data/src/core/credentials/transport/google_default/google_default_credentials.cc +3 -4
  45. data/src/core/credentials/transport/ssl/ssl_credentials.cc +59 -72
  46. data/src/core/credentials/transport/ssl/ssl_credentials.h +9 -8
  47. data/src/core/credentials/transport/ssl/ssl_security_connector.cc +12 -6
  48. data/src/core/credentials/transport/ssl/ssl_security_connector.h +4 -4
  49. data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +29 -18
  50. data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +9 -6
  51. data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +45 -56
  52. data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +5 -4
  53. data/src/core/credentials/transport/tls/grpc_tls_certificate_selector.h +26 -0
  54. data/src/core/credentials/transport/tls/grpc_tls_crl_provider.cc +1 -1
  55. data/src/core/credentials/transport/tls/load_system_roots.h +2 -6
  56. data/src/core/credentials/transport/tls/load_system_roots_fallback.cc +2 -4
  57. data/src/core/credentials/transport/tls/load_system_roots_supported.cc +13 -15
  58. data/src/core/credentials/transport/tls/load_system_roots_supported.h +3 -2
  59. data/src/core/credentials/transport/tls/load_system_roots_windows.cc +5 -8
  60. data/src/core/credentials/transport/tls/spiffe_utils.cc +1 -1
  61. data/src/core/credentials/transport/tls/ssl_utils.cc +39 -28
  62. data/src/core/credentials/transport/tls/ssl_utils.h +12 -49
  63. data/src/core/credentials/transport/tls/tls_security_connector.cc +48 -33
  64. data/src/core/credentials/transport/tls/tls_security_connector.h +31 -10
  65. data/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.cc +15 -11
  66. data/src/core/ext/filters/http/http_filters_plugin.cc +20 -9
  67. data/src/core/ext/filters/rbac/rbac_filter.cc +43 -21
  68. data/src/core/ext/filters/rbac/rbac_filter.h +21 -3
  69. data/src/core/ext/filters/rbac/rbac_service_config_parser.cc +2 -2
  70. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +1 -1
  71. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +6 -20
  72. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +32 -67
  73. data/src/core/ext/transport/chttp2/transport/flow_control.cc +2 -0
  74. data/src/core/ext/transport/chttp2/transport/flow_control.h +78 -4
  75. data/src/core/ext/transport/chttp2/transport/frame.h +2 -0
  76. data/src/core/ext/transport/chttp2/transport/frame_data.cc +3 -4
  77. data/src/core/ext/transport/chttp2/transport/goaway.h +7 -0
  78. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +5 -3
  79. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +3 -1
  80. data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +141 -130
  81. data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +22 -22
  82. data/src/core/ext/transport/chttp2/transport/http2_server_transport.cc +402 -269
  83. data/src/core/ext/transport/chttp2/transport/http2_server_transport.h +80 -49
  84. data/src/core/ext/transport/chttp2/transport/http2_settings_promises.h +1 -2
  85. data/src/core/ext/transport/chttp2/transport/http2_status.h +38 -37
  86. data/src/core/ext/transport/chttp2/transport/http2_transport.cc +178 -5
  87. data/src/core/ext/transport/chttp2/transport/http2_transport.h +345 -5
  88. data/src/core/ext/transport/chttp2/transport/parsing.cc +5 -5
  89. data/src/core/ext/transport/chttp2/transport/ping_promise.cc +3 -2
  90. data/src/core/ext/transport/chttp2/transport/ping_promise.h +25 -5
  91. data/src/core/ext/transport/chttp2/transport/ping_rate_policy.cc +3 -4
  92. data/src/core/ext/transport/chttp2/transport/read_context.h +30 -3
  93. data/src/core/ext/transport/chttp2/transport/stream.h +65 -23
  94. data/src/core/ext/transport/chttp2/transport/writing.cc +0 -3
  95. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -5
  96. data/src/core/ext/transport/inproc/legacy_inproc_transport.cc +4 -17
  97. data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upb.h +1912 -0
  98. data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upb_minitable.c +300 -0
  99. data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upb_minitable.h +37 -0
  100. data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upb.h +187 -0
  101. data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upb_minitable.c +64 -0
  102. data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upb_minitable.h +31 -0
  103. data/src/core/ext/upb-gen/envoy/service/ext_proc/v3/external_processor.upb.h +2362 -0
  104. data/src/core/ext/upb-gen/envoy/service/ext_proc/v3/external_processor.upb_minitable.c +556 -0
  105. data/src/core/ext/upb-gen/envoy/service/ext_proc/v3/external_processor.upb_minitable.h +47 -0
  106. data/src/core/ext/upb-gen/{src/proto/grpc/channelz → grpc/channelz/v1}/channelz.upb.h +5 -5
  107. data/src/core/ext/upb-gen/{src/proto/grpc/channelz → grpc/channelz/v1}/channelz.upb_minitable.c +3 -3
  108. data/src/core/ext/upb-gen/{src/proto/grpc/channelz → grpc/channelz/v1}/channelz.upb_minitable.h +5 -5
  109. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upbdefs.c +453 -0
  110. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upbdefs.h +67 -0
  111. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upbdefs.c +142 -0
  112. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upbdefs.h +37 -0
  113. data/src/core/ext/upbdefs-gen/grpc/channelz/v1/channelz.upbdefs.c +715 -0
  114. data/src/core/ext/upbdefs-gen/{src/proto/grpc/channelz → grpc/channelz/v1}/channelz.upbdefs.h +44 -44
  115. data/src/core/filter/auth/server_auth_filter.cc +2 -3
  116. data/src/core/filter/composite/composite_filter.cc +45 -33
  117. data/src/core/filter/composite/composite_filter.h +5 -4
  118. data/src/core/filter/ext_proc/ext_proc_filter.cc +224 -0
  119. data/src/core/filter/ext_proc/ext_proc_filter.h +155 -0
  120. data/src/core/filter/ext_proc/ext_proc_messages.cc +701 -0
  121. data/src/core/filter/ext_proc/ext_proc_messages.h +297 -0
  122. data/src/core/filter/filter_args.h +13 -2
  123. data/src/core/handshaker/http_connect/http_proxy_mapper.cc +30 -3
  124. data/src/core/handshaker/security/security_handshaker.cc +9 -6
  125. data/src/core/lib/channel/channel_stack.cc +3 -0
  126. data/src/core/lib/channel/channel_stack.h +2 -0
  127. data/src/core/lib/channel/channel_stack_builder_impl.cc +1 -2
  128. data/src/core/lib/channel/promise_based_filter.cc +132 -20
  129. data/src/core/lib/channel/promise_based_filter.h +42 -12
  130. data/src/core/lib/compression/compression_internal.cc +4 -5
  131. data/src/core/lib/debug/trace_flags.cc +8 -0
  132. data/src/core/lib/debug/trace_flags.h +3 -0
  133. data/src/core/lib/event_engine/ares_resolver.cc +54 -50
  134. data/src/core/lib/event_engine/ares_resolver.h +3 -2
  135. data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +3 -3
  136. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +4 -10
  137. data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +74 -33
  138. data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +4 -4
  139. data/src/core/lib/event_engine/posix_engine/posix_engine.cc +6 -2
  140. data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +3 -0
  141. data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +3 -0
  142. data/src/core/lib/event_engine/windows/windows_endpoint.cc +1 -3
  143. data/src/core/lib/experiments/experiments.cc +60 -96
  144. data/src/core/lib/experiments/experiments.h +34 -50
  145. data/src/core/lib/iomgr/cfstream_handle.cc +2 -6
  146. data/src/core/lib/iomgr/endpoint_cfstream.cc +3 -10
  147. data/src/core/lib/iomgr/error.cc +2 -6
  148. data/src/core/lib/iomgr/error_cfstream.cc +1 -1
  149. data/src/core/lib/iomgr/ev_poll_posix.cc +5 -9
  150. data/src/core/lib/iomgr/event_engine_shims/closure.cc +1 -1
  151. data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +1 -2
  152. data/src/core/lib/iomgr/event_engine_shims/tcp_client.cc +1 -2
  153. data/src/core/lib/iomgr/iomgr_posix.cc +0 -4
  154. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +0 -4
  155. data/src/core/lib/iomgr/iomgr_windows.cc +0 -4
  156. data/src/core/lib/iomgr/socket_factory_posix.h +1 -1
  157. data/src/core/lib/iomgr/socket_utils_posix.cc +3 -0
  158. data/src/core/lib/iomgr/socket_utils_posix.h +3 -0
  159. data/src/core/lib/iomgr/systemd_utils.cc +0 -1
  160. data/src/core/lib/iomgr/tcp_client.h +1 -1
  161. data/src/core/lib/iomgr/tcp_posix.cc +23 -15
  162. data/src/core/lib/iomgr/tcp_server.h +1 -1
  163. data/src/core/lib/iomgr/tcp_server_posix.cc +2 -3
  164. data/src/core/lib/iomgr/tcp_server_utils_posix.h +0 -1
  165. data/src/core/lib/iomgr/tcp_server_windows.cc +0 -1
  166. data/src/core/lib/iomgr/tcp_windows.cc +5 -10
  167. data/src/core/lib/iomgr/unix_sockets_posix.cc +2 -4
  168. data/src/core/lib/iomgr/unix_sockets_posix.h +3 -1
  169. data/src/core/lib/iomgr/vsock.h +3 -1
  170. data/src/core/lib/resource_quota/memory_quota.cc +1 -1
  171. data/src/core/lib/security/authorization/rbac_policy.cc +139 -56
  172. data/src/core/lib/security/authorization/rbac_policy.h +21 -3
  173. data/src/core/lib/surface/call.cc +3 -9
  174. data/src/core/lib/surface/call_utils.h +113 -0
  175. data/src/core/lib/surface/channel_create.cc +1 -1
  176. data/src/core/lib/surface/channel_create.h +0 -2
  177. data/src/core/lib/surface/channel_init.cc +77 -38
  178. data/src/core/lib/surface/channel_init.h +30 -16
  179. data/src/core/lib/surface/filter_stack_call.cc +5 -10
  180. data/src/core/lib/surface/init.cc +13 -27
  181. data/src/core/lib/surface/version.cc +1 -1
  182. data/src/core/lib/transport/error_utils.cc +0 -27
  183. data/src/core/lib/transport/error_utils.h +0 -16
  184. data/src/core/lib/transport/transport.h +7 -5
  185. data/src/core/load_balancing/pick_first/pick_first.cc +2 -0
  186. data/src/core/load_balancing/rls/rls.cc +28 -11
  187. data/src/core/load_balancing/weighted_round_robin/weighted_round_robin.cc +33 -42
  188. data/src/core/load_balancing/weighted_round_robin/weighted_round_robin.h +0 -2
  189. data/src/core/load_balancing/xds/cds.cc +3 -1
  190. data/src/core/load_balancing/xds/xds_cluster_impl.cc +0 -1
  191. data/src/core/mitigation_engine/mitigation.h +14 -5
  192. data/src/core/mitigation_engine/mitigation_engine.h +7 -3
  193. data/src/core/mitigation_engine/mitigation_provider.h +2 -1
  194. data/src/core/plugin_registry/grpc_plugin_registry.cc +39 -8
  195. data/src/core/resolver/dns/{event_engine/event_engine_client_channel_resolver.cc → dns_resolver.cc} +42 -41
  196. data/src/core/resolver/dns/{event_engine/event_engine_client_channel_resolver.h → dns_resolver.h} +8 -5
  197. data/src/core/resolver/dns/{event_engine/service_config_helper.cc → service_config_helper.cc} +1 -1
  198. data/src/core/resolver/dns/{event_engine/service_config_helper.h → service_config_helper.h} +3 -3
  199. data/src/core/resolver/endpoint_addresses.h +3 -0
  200. data/src/core/resolver/google_c2p/google_c2p_resolver.cc +2 -1
  201. data/src/core/resolver/xds/xds_resolver.cc +35 -9
  202. data/src/core/server/server.cc +2 -6
  203. data/src/core/server/server_config_selector.h +18 -3
  204. data/src/core/server/server_config_selector_filter.cc +178 -91
  205. data/src/core/server/server_config_selector_filter.h +58 -3
  206. data/src/core/server/xds_server_config_fetcher.cc +196 -129
  207. data/src/core/server/xds_server_config_fetcher.h +49 -0
  208. data/src/core/server/xds_server_config_fetcher_legacy.cc +41 -37
  209. data/src/core/telemetry/histogram.h +94 -14
  210. data/src/core/telemetry/instrument.cc +179 -74
  211. data/src/core/telemetry/instrument.h +78 -30
  212. data/src/core/telemetry/metrics.h +5 -0
  213. data/src/core/{resolver/dns/dns_resolver_plugin.h → telemetry/telemetry_label.h} +12 -8
  214. data/src/core/tsi/alts/crypt/aes_gcm.cc +10 -13
  215. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +2 -2
  216. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +3 -1
  217. data/src/core/tsi/ssl_telemetry_utils.cc +216 -259
  218. data/src/core/tsi/ssl_telemetry_utils.h +12 -2
  219. data/src/core/tsi/ssl_transport_security.cc +238 -80
  220. data/src/core/tsi/ssl_transport_security.h +63 -33
  221. data/src/core/tsi/tls_telemetry.cc +31 -0
  222. data/src/core/tsi/tls_telemetry.h +47 -0
  223. data/src/core/tsi/transport_security.cc +2 -2
  224. data/src/core/tsi/transport_security.h +1 -1
  225. data/src/core/tsi/transport_security_interface.h +1 -1
  226. data/src/core/{resolver/dns/native/dns_resolver.h → util/address_sorting_init.cc} +21 -8
  227. data/src/core/{resolver/dns/c_ares/grpc_ares_wrapper_posix.cc → util/address_sorting_init.h} +7 -8
  228. data/src/core/util/http_client/httpcli.cc +16 -53
  229. data/src/core/util/http_client/httpcli.h +0 -7
  230. data/src/core/util/http_client/httpcli_security_connector.cc +13 -8
  231. data/src/core/util/linux/cpu.cc +1 -1
  232. data/src/core/util/load_file.cc +3 -9
  233. data/src/core/util/load_file.h +3 -4
  234. data/src/core/util/matchers.h +8 -0
  235. data/src/core/util/posix/cpu.cc +1 -1
  236. data/src/core/util/status_helper.cc +0 -20
  237. data/src/core/util/status_helper.h +3 -14
  238. data/src/core/xds/grpc/xds_audit_logger_registry.cc +51 -31
  239. data/src/core/xds/grpc/xds_audit_logger_registry.h +17 -3
  240. data/src/core/xds/grpc/xds_bootstrap_grpc.cc +2 -10
  241. data/src/core/xds/grpc/xds_bootstrap_grpc.h +8 -6
  242. data/src/core/xds/grpc/xds_bootstrap_grpc_builder.cc +488 -0
  243. data/src/core/xds/grpc/xds_bootstrap_grpc_builder.h +97 -0
  244. data/src/core/xds/grpc/xds_certificate_provider.cc +7 -7
  245. data/src/core/xds/grpc/xds_client_grpc.cc +4 -8
  246. data/src/core/xds/grpc/xds_client_grpc.h +0 -4
  247. data/src/core/xds/grpc/xds_cluster.h +1 -0
  248. data/src/core/xds/grpc/xds_cluster_parser.cc +1 -5
  249. data/src/core/xds/grpc/xds_cluster_parser.h +0 -2
  250. data/src/core/xds/grpc/xds_cluster_specifier_plugin.cc +0 -2
  251. data/src/core/xds/grpc/xds_cluster_specifier_plugin.h +0 -2
  252. data/src/core/xds/grpc/xds_common_types.cc +0 -91
  253. data/src/core/xds/grpc/xds_common_types.h +1 -47
  254. data/src/core/xds/grpc/xds_common_types_parser.cc +84 -378
  255. data/src/core/xds/grpc/xds_common_types_parser.h +9 -11
  256. data/src/core/xds/grpc/xds_endpoint_parser.cc +0 -2
  257. data/src/core/xds/grpc/xds_grpc_service_parser.cc +177 -0
  258. data/src/core/{resolver/dns/c_ares/dns_resolver_ares.h → xds/grpc/xds_grpc_service_parser.h} +14 -9
  259. data/src/core/xds/grpc/xds_http_composite_filter.cc +26 -21
  260. data/src/core/xds/grpc/xds_http_composite_filter.h +4 -3
  261. data/src/core/xds/grpc/xds_http_ext_proc_filter.cc +418 -0
  262. data/src/core/xds/grpc/xds_http_ext_proc_filter.h +89 -0
  263. data/src/core/xds/grpc/xds_http_fault_filter.cc +9 -12
  264. data/src/core/xds/grpc/xds_http_fault_filter.h +1 -4
  265. data/src/core/xds/grpc/xds_http_filter.cc +2 -1
  266. data/src/core/xds/grpc/xds_http_filter.h +6 -5
  267. data/src/core/xds/grpc/xds_http_filter_registry.cc +10 -127
  268. data/src/core/xds/grpc/xds_http_filter_registry.h +7 -59
  269. data/src/core/xds/grpc/xds_http_gcp_authn_filter.cc +13 -14
  270. data/src/core/xds/grpc/xds_http_gcp_authn_filter.h +3 -2
  271. data/src/core/xds/grpc/xds_http_rbac_filter.cc +403 -25
  272. data/src/core/xds/grpc/xds_http_rbac_filter.h +1 -3
  273. data/src/core/xds/grpc/xds_http_stateful_session_filter.cc +8 -13
  274. data/src/core/xds/grpc/xds_http_stateful_session_filter.h +1 -4
  275. data/src/core/xds/grpc/xds_lb_policy_registry.cc +0 -292
  276. data/src/core/xds/grpc/xds_lb_policy_registry.h +7 -3
  277. data/src/core/xds/grpc/xds_listener.cc +2 -0
  278. data/src/core/xds/grpc/xds_listener.h +5 -0
  279. data/src/core/xds/grpc/xds_listener_parser.cc +16 -11
  280. data/src/core/xds/grpc/xds_matcher_parse.h +3 -1
  281. data/src/core/xds/grpc/xds_metadata_parser.cc +6 -1
  282. data/src/core/xds/grpc/xds_metadata_parser.h +2 -0
  283. data/src/core/xds/grpc/xds_route_config.cc +2 -0
  284. data/src/core/xds/grpc/xds_route_config.h +3 -1
  285. data/src/core/xds/grpc/xds_route_config_parser.cc +13 -79
  286. data/src/core/xds/grpc/xds_route_config_parser.h +0 -3
  287. data/src/core/xds/grpc/xds_routing.cc +116 -69
  288. data/src/core/xds/grpc/xds_routing.h +19 -8
  289. data/src/core/xds/grpc/xds_tls_context.cc +117 -0
  290. data/src/core/xds/grpc/xds_tls_context.h +76 -0
  291. data/src/core/xds/grpc/xds_tls_context_parser.cc +275 -0
  292. data/src/core/xds/grpc/xds_tls_context_parser.h +35 -0
  293. data/src/core/xds/grpc/xds_transport_grpc.cc +41 -38
  294. data/src/core/xds/grpc/xds_transport_grpc.h +4 -2
  295. data/src/ruby/ext/grpc/rb_call.c +26 -15
  296. data/src/ruby/ext/grpc/rb_completion_queue.c +6 -5
  297. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  298. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
  299. data/src/ruby/lib/grpc/version.rb +1 -1
  300. data/src/ruby/pb/test/client.rb +5 -4
  301. data/src/ruby/spec/call_spec.rb +14 -0
  302. data/src/ruby/spec/generic/server_interceptors_spec.rb +3 -6
  303. metadata +50 -35
  304. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.c +0 -716
  305. data/src/core/lib/iomgr/resolve_address.cc +0 -59
  306. data/src/core/lib/iomgr/resolve_address.h +0 -125
  307. data/src/core/lib/iomgr/resolve_address_impl.h +0 -58
  308. data/src/core/lib/iomgr/resolve_address_posix.cc +0 -184
  309. data/src/core/lib/iomgr/resolve_address_posix.h +0 -78
  310. data/src/core/lib/iomgr/resolve_address_windows.cc +0 -169
  311. data/src/core/lib/iomgr/resolve_address_windows.h +0 -76
  312. data/src/core/resolver/dns/c_ares/dns_resolver_ares.cc +0 -781
  313. data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h +0 -93
  314. data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +0 -203
  315. data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +0 -838
  316. data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +0 -1237
  317. data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h +0 -130
  318. data/src/core/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +0 -35
  319. data/src/core/resolver/dns/dns_resolver_plugin.cc +0 -64
  320. data/src/core/resolver/dns/native/dns_resolver.cc +0 -173
  321. data/src/core/util/json/json_util.cc +0 -101
  322. data/src/core/util/json/json_util.h +0 -163
@@ -70,8 +70,10 @@
70
70
  #include "src/core/tsi/ssl/key_logging/ssl_key_logging.h"
71
71
  #include "src/core/tsi/ssl/session_cache/ssl_session.h"
72
72
  #include "src/core/tsi/ssl/session_cache/ssl_session_cache.h"
73
+ #include "src/core/tsi/ssl_telemetry_utils.h"
73
74
  #include "src/core/tsi/ssl_transport_security_utils.h"
74
75
  #include "src/core/tsi/ssl_types.h"
76
+ #include "src/core/tsi/tls_telemetry.h"
75
77
  #include "src/core/tsi/transport_security.h"
76
78
  #include "src/core/tsi/transport_security_interface.h"
77
79
  #include "src/core/util/grpc_check.h"
@@ -127,7 +129,7 @@ using SelectCertificateResult =
127
129
  using AsyncCertificateSelectionHandle =
128
130
  grpc_core::CertificateSelector::AsyncCertificateSelectionHandle;
129
131
  #endif
130
- using tsi::PrivateKey;
132
+ using grpc_core::PrivateKey;
131
133
  using tsi::RootCertInfo;
132
134
 
133
135
  // --- Structure definitions. ---
@@ -206,13 +208,28 @@ struct HandshakerNextArgs {
206
208
  tsi_handshaker_result* handshaker_result = nullptr;
207
209
  };
208
210
 
211
+ struct tsi_ssl_handshaker_result {
212
+ tsi_handshaker_result base;
213
+ SSL* ssl;
214
+ BIO* network_io;
215
+ unsigned char* unused_bytes;
216
+ size_t unused_bytes_size;
217
+ };
218
+
219
+ struct SslHandshakeResult {
220
+ tsi_result tsi_handshake_result;
221
+ int ssl_error = SSL_ERROR_NONE;
222
+ unsigned long err_code = 0;
223
+ };
224
+
209
225
  struct tsi_ssl_handshaker : public tsi_handshaker,
210
226
  public grpc_core::RefCounted<tsi_ssl_handshaker> {
211
227
  tsi_ssl_handshaker(
212
228
  const tsi_handshaker_vtable* handshaker_vtable, SSL* ssl, BIO* network_io,
213
229
  tsi_ssl_handshaker_factory* factory_ref,
214
230
  grpc_core::RefCountedPtr<grpc_core::CollectionScope> collection_scope,
215
- bool is_client, std::shared_ptr<grpc_core::PrivateKeySigner> signer)
231
+ bool is_client, std::shared_ptr<grpc_core::PrivateKeySigner> signer,
232
+ std::string target, std::string locality, std::string backend_service)
216
233
  : tsi_handshaker(handshaker_vtable),
217
234
  ssl(ssl),
218
235
  network_io(network_io),
@@ -223,7 +240,10 @@ struct tsi_ssl_handshaker : public tsi_handshaker,
223
240
  gpr_zalloc(outgoing_bytes_buffer_size))),
224
241
  factory_ref(factory_ref),
225
242
  collection_scope(std::move(collection_scope)),
226
- is_client(is_client) {
243
+ is_client(is_client),
244
+ target(std::move(target)),
245
+ locality(std::move(locality)),
246
+ backend_service(std::move(backend_service)) {
227
247
  #if defined(OPENSSL_IS_BORINGSSL)
228
248
  key_signer = std::move(signer);
229
249
  #endif
@@ -256,6 +276,14 @@ struct tsi_ssl_handshaker : public tsi_handshaker,
256
276
  *handshaker_next_args->error_ptr = std::move(error);
257
277
  }
258
278
  bool is_client = false;
279
+ std::string target;
280
+ std::string locality;
281
+ std::string backend_service;
282
+ bool metric_recorded ABSL_GUARDED_BY(mu) = false;
283
+
284
+ void MaybeRecordTelemetry(const SslHandshakeResult& handshake_result)
285
+ ABSL_EXCLUSIVE_LOCKS_REQUIRED(&mu);
286
+
259
287
  #if defined(OPENSSL_IS_BORINGSSL)
260
288
  std::shared_ptr<AsyncCertificateSelectionHandle> cert_selection_handle
261
289
  ABSL_GUARDED_BY(mu);
@@ -275,17 +303,62 @@ struct tsi_ssl_handshaker : public tsi_handshaker,
275
303
  #endif
276
304
  };
277
305
 
306
+ void tsi_ssl_handshaker::MaybeRecordTelemetry(
307
+ const SslHandshakeResult& handshake_result) {
308
+ // If there's no collection scope, don't do anything regarding telemetry
309
+ if (collection_scope == nullptr) return;
310
+ if (handshake_result.tsi_handshake_result == TSI_INCOMPLETE_DATA ||
311
+ handshake_result.tsi_handshake_result == TSI_DRAIN_BUFFER) {
312
+ return;
313
+ }
314
+ // The handshaker can return TSI_OK as an intermediate state, only keep going
315
+ // if a result has been created
316
+ if (handshake_result.tsi_handshake_result == TSI_OK &&
317
+ !handshaker_result_created) {
318
+ return;
319
+ }
320
+ if (metric_recorded) return;
321
+ metric_recorded = true;
322
+ SSL* active_ssl = ssl;
323
+ if (active_ssl == nullptr && handshaker_next_args.has_value() &&
324
+ handshaker_next_args->handshaker_result != nullptr) {
325
+ auto* res = reinterpret_cast<tsi_ssl_handshaker_result*>(
326
+ handshaker_next_args->handshaker_result);
327
+ active_ssl = res->ssl;
328
+ }
329
+ absl::string_view resumed = active_ssl == nullptr ? "unknown"
330
+ : SSL_session_reused(active_ssl) ? "true"
331
+ : "false";
332
+ grpc_core::TlsTelemetryHandshakeResult result =
333
+ grpc_core::TlsTelemetryHandshakeResult::kSuccess;
334
+ if (handshake_result.tsi_handshake_result != TSI_OK) {
335
+ // If TSI reports non-ok, get more details from the SSL stack
336
+ long verify_res =
337
+ active_ssl != nullptr ? SSL_get_verify_result(active_ssl) : X509_V_OK;
338
+ result = grpc_core::MapSslErrorToTlsTelemetryHandshakeResult(
339
+ handshake_result.tsi_handshake_result, handshake_result.ssl_error,
340
+ handshake_result.err_code, verify_res);
341
+ }
342
+ absl::string_view status_str =
343
+ grpc_core::TlsTelemetryHandshakeResultToString(result);
344
+ if (is_client) {
345
+ auto storage = grpc_core::TlsClientHandshakeTelemetryDomain::GetStorage(
346
+ collection_scope, status_str, target, resumed, locality,
347
+ backend_service);
348
+ storage->Increment(
349
+ grpc_core::TlsClientHandshakeTelemetryDomain::kHandshakes);
350
+ } else {
351
+ auto storage = grpc_core::TlsServerHandshakeTelemetryDomain::GetStorage(
352
+ collection_scope, status_str, resumed);
353
+ storage->Increment(
354
+ grpc_core::TlsServerHandshakeTelemetryDomain::kHandshakes);
355
+ }
356
+ }
357
+
278
358
  static std::pair<tsi_result, std::optional<HandshakerNextArgs>>
279
359
  ssl_handshaker_next_async(tsi_ssl_handshaker* self)
280
360
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu);
281
361
 
282
- struct tsi_ssl_handshaker_result {
283
- tsi_handshaker_result base;
284
- SSL* ssl;
285
- BIO* network_io;
286
- unsigned char* unused_bytes;
287
- size_t unused_bytes_size;
288
- };
289
362
  struct tsi_ssl_frame_protector {
290
363
  tsi_frame_protector base;
291
364
  SSL* ssl;
@@ -614,9 +687,64 @@ SelectCertificateInfo PrepareSelectCertificateInfo(
614
687
  } else {
615
688
  VLOG(2) << "Client did not provide SNI for cert selection.";
616
689
  }
690
+ size_t capabilities_len = 0;
691
+ uint8_t* buffer;
692
+ bssl::ScopedCBB cbb;
693
+ if (CBB_init(cbb.get(), 128) &&
694
+ SSL_serialize_capabilities(client_hello->ssl, cbb.get()) &&
695
+ CBB_finish(cbb.get(), &buffer, &capabilities_len)) {
696
+ select_cert_info.handshake_hints_info.ssl_capabilities =
697
+ std::string(reinterpret_cast<const char*>(buffer), capabilities_len);
698
+ OPENSSL_free(buffer);
699
+ } else {
700
+ VLOG(2) << "Failed to generate SSL capabilities";
701
+ }
702
+ select_cert_info.handshake_hints_info.client_hello =
703
+ std::string(reinterpret_cast<const char*>(client_hello->client_hello),
704
+ client_hello->client_hello_len);
617
705
  return select_cert_info;
618
706
  }
619
707
 
708
+ absl::Status ProcessSelectCertResultForHandshakeHints(
709
+ tsi_ssl_handshaker* handshaker, const SelectCertificateResult& result) {
710
+ // If no handshake hints are provided, return early. This doesn't mean the
711
+ // handshake will fail. The private key operation will happen later.
712
+ if (result.handshake_hints_result.handshake_hints.empty()) {
713
+ return absl::OkStatus();
714
+ }
715
+ if (!SSL_set_min_proto_version(
716
+ handshaker->ssl, result.handshake_hints_result.min_tls_version)) {
717
+ return absl::InvalidArgumentError("Failed to set min TLS version.");
718
+ }
719
+ if (!SSL_set_max_proto_version(
720
+ handshaker->ssl, result.handshake_hints_result.max_tls_version)) {
721
+ return absl::InvalidArgumentError("Failed to set max TLS version.");
722
+ }
723
+ if (!result.handshake_hints_result.cipher_list.empty() &&
724
+ !SSL_set_strict_cipher_list(
725
+ handshaker->ssl, result.handshake_hints_result.cipher_list.c_str())) {
726
+ return absl::InvalidArgumentError("Failed to set cipher list.");
727
+ }
728
+ if (!result.handshake_hints_result.key_exchange_groups.empty() &&
729
+ !SSL_set1_group_ids(
730
+ handshaker->ssl,
731
+ result.handshake_hints_result.key_exchange_groups.data(),
732
+ result.handshake_hints_result.key_exchange_groups.size())) {
733
+ return absl::InvalidArgumentError("Failed to set key exchange groups.");
734
+ }
735
+ // No session resumption.
736
+ SSL_set_options(handshaker->ssl,
737
+ SSL_OP_CIPHER_SERVER_PREFERENCE | SSL_OP_NO_TICKET);
738
+ if (!SSL_set_handshake_hints(
739
+ handshaker->ssl,
740
+ reinterpret_cast<const uint8_t*>(
741
+ result.handshake_hints_result.handshake_hints.data()),
742
+ result.handshake_hints_result.handshake_hints.size())) {
743
+ return absl::InternalError("Failed to set handshake hints.");
744
+ }
745
+ return absl::OkStatus();
746
+ }
747
+
620
748
  absl::Status ProcessSelectCertificateResult(tsi_ssl_handshaker* handshaker,
621
749
  SelectCertificateResult result)
622
750
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
@@ -628,7 +756,7 @@ absl::Status ProcessSelectCertificateResult(tsi_ssl_handshaker* handshaker,
628
756
  for (auto& raw_cert : result.certificate_chain) {
629
757
  cert_chain.push_back(raw_cert.get());
630
758
  }
631
- return grpc_core::MatchMutable(
759
+ absl::Status pkey_status = grpc_core::MatchMutable(
632
760
  &result.private_key,
633
761
  [&](bssl::UniquePtr<EVP_PKEY>* key) {
634
762
  VLOG(2) << "Select cert result returned a static private key.";
@@ -656,6 +784,8 @@ absl::Status ProcessSelectCertificateResult(tsi_ssl_handshaker* handshaker,
656
784
  }
657
785
  return absl::OkStatus();
658
786
  });
787
+ GRPC_RETURN_IF_ERROR(pkey_status);
788
+ return ProcessSelectCertResultForHandshakeHints(handshaker, result);
659
789
  }
660
790
 
661
791
  // Invoked by the cert selector when it runs asynchronously.
@@ -1401,22 +1531,22 @@ static tsi_result ssl_ctx_load_verification_certs(SSL_CTX* context,
1401
1531
  // Populates the SSL context with a private key and a cert chain, and sets the
1402
1532
  // cipher list and the ephemeral ECDH key.
1403
1533
  static tsi_result populate_ssl_context(
1404
- SSL_CTX* context, const tsi_ssl_pem_key_cert_pair* key_cert_pair,
1534
+ SSL_CTX* context, const grpc_core::PemKeyCertPair* key_cert_pair,
1405
1535
  const char* cipher_list,
1406
1536
  const std::vector<grpc_tls_key_exchange_group>& key_exchange_groups) {
1407
1537
  tsi_result result = TSI_OK;
1408
1538
  if (key_cert_pair != nullptr) {
1409
- if (!key_cert_pair->cert_chain.empty()) {
1539
+ if (!key_cert_pair->cert_chain().empty()) {
1410
1540
  result = ssl_ctx_use_certificate_chain(
1411
- context, key_cert_pair->cert_chain.c_str(),
1412
- key_cert_pair->cert_chain.length());
1541
+ context, key_cert_pair->cert_chain().c_str(),
1542
+ key_cert_pair->cert_chain().length());
1413
1543
  if (result != TSI_OK) {
1414
1544
  LOG(ERROR) << "Invalid cert chain file.";
1415
1545
  return result;
1416
1546
  }
1417
1547
  }
1418
1548
  result = grpc_core::Match(
1419
- key_cert_pair->private_key,
1549
+ key_cert_pair->private_key(),
1420
1550
  [&](const std::string& pem_root_certs) {
1421
1551
  tsi_result result = TSI_OK;
1422
1552
  result = ssl_ctx_use_private_key(context, pem_root_certs.data(),
@@ -1936,8 +2066,8 @@ static tsi_result tsi_set_min_and_max_tls_versions(
1936
2066
  // --- tsi_ssl_root_certs_store methods implementation. ---
1937
2067
 
1938
2068
  tsi_ssl_root_certs_store* tsi_ssl_root_certs_store_create(
1939
- const char* pem_roots) {
1940
- if (pem_roots == nullptr) {
2069
+ absl::string_view pem_roots) {
2070
+ if (pem_roots.empty()) {
1941
2071
  LOG(ERROR) << "The root certificates are empty.";
1942
2072
  return nullptr;
1943
2073
  }
@@ -1953,8 +2083,8 @@ tsi_ssl_root_certs_store* tsi_ssl_root_certs_store_create(
1953
2083
  gpr_free(root_store);
1954
2084
  return nullptr;
1955
2085
  }
1956
- tsi_result result = x509_store_load_certs(root_store->store, pem_roots,
1957
- strlen(pem_roots), nullptr);
2086
+ tsi_result result = x509_store_load_certs(root_store->store, pem_roots.data(),
2087
+ pem_roots.size(), nullptr);
1958
2088
  if (result != TSI_OK) {
1959
2089
  LOG(ERROR) << "Could not load root certificates.";
1960
2090
  X509_STORE_free(root_store->store);
@@ -2359,11 +2489,11 @@ static tsi_result ssl_handshaker_get_result(tsi_ssl_handshaker* impl) {
2359
2489
  return impl->result;
2360
2490
  }
2361
2491
 
2362
- static tsi_result ssl_handshaker_do_handshake(tsi_ssl_handshaker* impl)
2492
+ static SslHandshakeResult ssl_handshaker_do_handshake(tsi_ssl_handshaker* impl)
2363
2493
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
2364
2494
  if (ssl_handshaker_get_result(impl) != TSI_HANDSHAKE_IN_PROGRESS) {
2365
2495
  impl->result = TSI_OK;
2366
- return impl->result;
2496
+ return {impl->result, SSL_ERROR_NONE, 0};
2367
2497
  } else {
2368
2498
  ERR_clear_error();
2369
2499
  // Get ready to get some bytes from SSL.
@@ -2373,23 +2503,24 @@ static tsi_result ssl_handshaker_do_handshake(tsi_ssl_handshaker* impl)
2373
2503
  case SSL_ERROR_WANT_READ:
2374
2504
  if (BIO_pending(impl->network_io) == 0) {
2375
2505
  // We need more data.
2376
- return TSI_INCOMPLETE_DATA;
2506
+ return {TSI_INCOMPLETE_DATA, SSL_ERROR_NONE, 0};
2377
2507
  } else {
2378
- return TSI_OK;
2508
+ return {TSI_OK, SSL_ERROR_NONE, 0};
2379
2509
  }
2380
2510
  case SSL_ERROR_NONE:
2381
- return TSI_OK;
2511
+ return {TSI_OK, SSL_ERROR_NONE, 0};
2382
2512
  case SSL_ERROR_WANT_WRITE:
2383
- return TSI_DRAIN_BUFFER;
2513
+ return {TSI_DRAIN_BUFFER, SSL_ERROR_NONE, 0};
2384
2514
  #if defined(OPENSSL_IS_BORINGSSL)
2385
2515
  case SSL_ERROR_WANT_PRIVATE_KEY_OPERATION:
2386
- return TSI_ASYNC;
2516
+ return {TSI_ASYNC, SSL_ERROR_NONE, 0};
2387
2517
  case SSL_ERROR_PENDING_CERTIFICATE:
2388
- return TSI_ASYNC;
2518
+ return {TSI_ASYNC, SSL_ERROR_NONE, 0};
2389
2519
  #endif
2390
2520
  default: {
2391
2521
  char err_str[256];
2392
- ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str));
2522
+ unsigned long err_code = ERR_get_error();
2523
+ ERR_error_string_n(err_code, err_str, sizeof(err_str));
2393
2524
  long verify_result = SSL_get_verify_result(impl->ssl);
2394
2525
  std::string verify_result_str;
2395
2526
  if (verify_result != X509_V_OK) {
@@ -2408,19 +2539,19 @@ static tsi_result ssl_handshaker_do_handshake(tsi_ssl_handshaker* impl)
2408
2539
  err_str, verify_result_str,
2409
2540
  signer_error));
2410
2541
  impl->result = TSI_PROTOCOL_FAILURE;
2411
- return impl->result;
2542
+ return {impl->result, ssl_result, err_code};
2412
2543
  }
2413
2544
  }
2414
2545
  }
2415
2546
  }
2416
2547
 
2417
- static tsi_result ssl_handshaker_process_bytes_from_peer(
2548
+ static SslHandshakeResult ssl_handshaker_process_bytes_from_peer(
2418
2549
  tsi_ssl_handshaker* impl, const unsigned char* bytes, size_t* bytes_size)
2419
2550
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
2420
2551
  int bytes_written_into_ssl_size = 0;
2421
2552
  if (bytes == nullptr || bytes_size == nullptr || *bytes_size > INT_MAX) {
2422
2553
  impl->MaybeSetError("invalid argument");
2423
- return TSI_INVALID_ARGUMENT;
2554
+ return {TSI_INVALID_ARGUMENT, SSL_ERROR_NONE, 0};
2424
2555
  }
2425
2556
  GRPC_CHECK_LE(*bytes_size, static_cast<size_t>(INT_MAX));
2426
2557
  bytes_written_into_ssl_size =
@@ -2429,7 +2560,7 @@ static tsi_result ssl_handshaker_process_bytes_from_peer(
2429
2560
  LOG(ERROR) << "Could not write to memory BIO.";
2430
2561
  impl->MaybeSetError("could not write to memory BIO");
2431
2562
  impl->result = TSI_INTERNAL_ERROR;
2432
- return impl->result;
2563
+ return {impl->result, SSL_ERROR_NONE, 0};
2433
2564
  }
2434
2565
  *bytes_size = static_cast<size_t>(bytes_written_into_ssl_size);
2435
2566
  return ssl_handshaker_do_handshake(impl);
@@ -2498,10 +2629,10 @@ static tsi_result ssl_handshaker_write_output_buffer(tsi_ssl_handshaker* impl,
2498
2629
  return status;
2499
2630
  }
2500
2631
 
2501
- static tsi_result ssl_handshaker_next_impl(tsi_ssl_handshaker* self)
2632
+ static SslHandshakeResult ssl_handshaker_next_impl(tsi_ssl_handshaker* self)
2502
2633
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&tsi_ssl_handshaker::mu) {
2503
2634
  // If there are received bytes, process them first.
2504
- tsi_result status = TSI_OK;
2635
+ SslHandshakeResult handshake_result = {TSI_OK, SSL_ERROR_NONE, 0};
2505
2636
  size_t bytes_written = 0;
2506
2637
  if (!self->handshaker_next_args->received_bytes.empty()) {
2507
2638
  size_t received_bytes_size =
@@ -2512,23 +2643,25 @@ static tsi_result ssl_handshaker_next_impl(tsi_ssl_handshaker* self)
2512
2643
  size_t remaining_bytes_to_write_to_openssl_size = received_bytes_size;
2513
2644
  size_t number_bio_write_attempts = 0;
2514
2645
  while (remaining_bytes_to_write_to_openssl_size > 0 &&
2515
- (status == TSI_OK || status == TSI_INCOMPLETE_DATA) &&
2646
+ (handshake_result.tsi_handshake_result == TSI_OK ||
2647
+ handshake_result.tsi_handshake_result == TSI_INCOMPLETE_DATA) &&
2516
2648
  number_bio_write_attempts < TSI_SSL_MAX_BIO_WRITE_ATTEMPTS) {
2517
2649
  ++number_bio_write_attempts;
2518
2650
  // Try to write all of the remaining bytes to the BIO.
2519
2651
  size_t bytes_written_to_openssl =
2520
2652
  remaining_bytes_to_write_to_openssl_size;
2521
- status = ssl_handshaker_process_bytes_from_peer(
2653
+ handshake_result = ssl_handshaker_process_bytes_from_peer(
2522
2654
  self, remaining_bytes_to_write_to_openssl, &bytes_written_to_openssl);
2523
2655
  // As long as the BIO is full, drive the SSL handshake to consume bytes
2524
2656
  // from the BIO. If the SSL handshake returns any bytes, write them to
2525
2657
  // the peer.
2526
- while (status == TSI_DRAIN_BUFFER) {
2527
- status = ssl_handshaker_write_output_buffer(self, &bytes_written);
2658
+ while (handshake_result.tsi_handshake_result == TSI_DRAIN_BUFFER) {
2659
+ tsi_result status =
2660
+ ssl_handshaker_write_output_buffer(self, &bytes_written);
2528
2661
  if (status != TSI_OK) {
2529
- return status;
2662
+ return {status, SSL_ERROR_NONE, 0};
2530
2663
  }
2531
- status = ssl_handshaker_do_handshake(self);
2664
+ handshake_result = ssl_handshaker_do_handshake(self);
2532
2665
  }
2533
2666
  // Move the pointer to the first byte not yet successfully written to
2534
2667
  // the BIO.
@@ -2552,17 +2685,17 @@ static tsi_result ssl_handshaker_next_impl(tsi_ssl_handshaker* self)
2552
2685
  // After an asynchronous certificate selection offload or private key
2553
2686
  // offload, another call to ssl_handshaker_do_handshake needs to be
2554
2687
  // triggered to continue the SSL handshake.
2555
- status = ssl_handshaker_do_handshake(self);
2688
+ handshake_result = ssl_handshaker_do_handshake(self);
2556
2689
  #endif
2557
2690
  }
2558
2691
 
2559
- if (status != TSI_OK) {
2560
- return status;
2692
+ if (handshake_result.tsi_handshake_result != TSI_OK) {
2693
+ return handshake_result;
2561
2694
  }
2562
2695
  // Get bytes to send to the peer, if available.
2563
- status = ssl_handshaker_write_output_buffer(self, &bytes_written);
2696
+ tsi_result status = ssl_handshaker_write_output_buffer(self, &bytes_written);
2564
2697
  if (status != TSI_OK) {
2565
- return status;
2698
+ return {status, SSL_ERROR_NONE, 0};
2566
2699
  }
2567
2700
  self->handshaker_next_args->bytes_to_send = self->outgoing_bytes_buffer;
2568
2701
  self->handshaker_next_args->bytes_to_send_size = bytes_written;
@@ -2578,14 +2711,14 @@ static tsi_result ssl_handshaker_next_impl(tsi_ssl_handshaker* self)
2578
2711
  size_t unused_bytes_size = 0;
2579
2712
  status = ssl_bytes_remaining(self, &unused_bytes, &unused_bytes_size);
2580
2713
  if (status != TSI_OK) {
2581
- return status;
2714
+ return {status, SSL_ERROR_NONE, 0};
2582
2715
  }
2583
2716
  if (unused_bytes_size >
2584
2717
  self->handshaker_next_args->original_received_bytes_size) {
2585
2718
  LOG(ERROR) << "More unused bytes than received bytes.";
2586
2719
  gpr_free(unused_bytes);
2587
2720
  self->MaybeSetError("More unused bytes than received bytes.");
2588
- return TSI_INTERNAL_ERROR;
2721
+ return {TSI_INTERNAL_ERROR, SSL_ERROR_NONE, 0};
2589
2722
  }
2590
2723
  status =
2591
2724
  ssl_handshaker_result_create(self, unused_bytes, unused_bytes_size);
@@ -2606,8 +2739,9 @@ static tsi_result ssl_handshaker_next_impl(tsi_ssl_handshaker* self)
2606
2739
  }
2607
2740
  }
2608
2741
  }
2742
+ return {status, SSL_ERROR_NONE, 0};
2609
2743
  }
2610
- return status;
2744
+ return {status, SSL_ERROR_NONE, 0};
2611
2745
  }
2612
2746
 
2613
2747
  // Wrapper for ssl_handshaker_next_impl() when called from an async callback.
@@ -2618,13 +2752,14 @@ ssl_handshaker_next_async(tsi_ssl_handshaker* self)
2618
2752
  if (self->is_shutdown || !self->handshaker_next_args.has_value()) {
2619
2753
  return {TSI_HANDSHAKE_SHUTDOWN, std::nullopt};
2620
2754
  }
2621
- tsi_result result = ssl_handshaker_next_impl(self);
2622
- if (result != TSI_ASYNC) {
2755
+ SslHandshakeResult handshake_result = ssl_handshaker_next_impl(self);
2756
+ if (handshake_result.tsi_handshake_result != TSI_ASYNC) {
2757
+ self->MaybeRecordTelemetry(handshake_result);
2623
2758
  // We now have a result to return to the caller via the callback.
2624
2759
  std::optional<HandshakerNextArgs> args =
2625
2760
  std::move(self->handshaker_next_args);
2626
2761
  self->handshaker_next_args.reset();
2627
- return {result, std::move(args)};
2762
+ return {handshake_result.tsi_handshake_result, std::move(args)};
2628
2763
  }
2629
2764
  return {TSI_ASYNC, std::nullopt};
2630
2765
  }
@@ -2660,29 +2795,38 @@ static tsi_result ssl_handshaker_next(
2660
2795
  impl->handshaker_next_args->user_data = user_data;
2661
2796
  impl->handshaker_next_args->error_ptr = error;
2662
2797
  // Now do the actual work.
2663
- tsi_result result = ssl_handshaker_next_impl(impl);
2798
+ SslHandshakeResult handshake_result = ssl_handshaker_next_impl(impl);
2664
2799
  // If returning synchronously, propagate output and clear args.
2665
- if (result != TSI_ASYNC) {
2800
+ if (handshake_result.tsi_handshake_result != TSI_ASYNC) {
2666
2801
  *bytes_to_send = impl->handshaker_next_args->bytes_to_send;
2667
2802
  *bytes_to_send_size = impl->handshaker_next_args->bytes_to_send_size;
2668
2803
  *handshaker_result = impl->handshaker_next_args->handshaker_result;
2804
+ impl->MaybeRecordTelemetry(handshake_result);
2669
2805
  impl->handshaker_next_args.reset();
2670
2806
  }
2671
- return result;
2807
+ return handshake_result.tsi_handshake_result;
2672
2808
  }
2673
2809
 
2674
- static void ssl_handshaker_shutdown(tsi_handshaker* self) {
2675
- #if defined(OPENSSL_IS_BORINGSSL)
2810
+ static void ssl_handshaker_shutdown(tsi_handshaker* self, bool peer_closed) {
2676
2811
  tsi_ssl_handshaker* impl = static_cast<tsi_ssl_handshaker*>(self);
2812
+ #if defined(OPENSSL_IS_BORINGSSL)
2677
2813
  std::shared_ptr<grpc_core::PrivateKeySigner> key_signer;
2678
2814
  std::shared_ptr<grpc_core::PrivateKeySigner::AsyncSigningHandle>
2679
2815
  signing_handle;
2680
2816
  std::shared_ptr<AsyncCertificateSelectionHandle> cert_selection_handle;
2681
2817
  std::optional<HandshakerNextArgs> next_args;
2818
+ #endif // defined(OPENSSL_IS_BORINGSSL)
2682
2819
  {
2683
2820
  grpc_core::MutexLock lock(&impl->mu);
2821
+ // Should never happen, if so something is very wrong
2684
2822
  if (impl->ssl == nullptr) return;
2685
2823
  impl->is_shutdown = true;
2824
+ impl->MaybeRecordTelemetry({
2825
+ /*tsi_result=*/peer_closed ? TSI_CLOSE_NOTIFY : TSI_HANDSHAKE_SHUTDOWN,
2826
+ /*ssl_error=*/SSL_ERROR_NONE,
2827
+ /*err_code=*/0,
2828
+ });
2829
+ #if defined(OPENSSL_IS_BORINGSSL)
2686
2830
  if (impl->key_signer != nullptr && impl->signing_handle != nullptr) {
2687
2831
  key_signer = std::move(impl->key_signer);
2688
2832
  signing_handle = std::move(impl->signing_handle);
@@ -2721,8 +2865,8 @@ static void ssl_handshaker_shutdown(tsi_handshaker* self) {
2721
2865
  args.handshaker_result);
2722
2866
  }
2723
2867
  });
2724
- }
2725
2868
  #endif // defined(OPENSSL_IS_BORINGSSL)
2869
+ }
2726
2870
  }
2727
2871
 
2728
2872
  static const tsi_handshaker_vtable handshaker_vtable = {
@@ -2758,6 +2902,7 @@ static tsi_result create_tsi_ssl_handshaker(
2758
2902
  std::shared_ptr<grpc_core::PrivateKeySigner> key_signer,
2759
2903
  tsi_ssl_handshaker_factory* factory,
2760
2904
  grpc_core::RefCountedPtr<grpc_core::CollectionScope> collection_scope,
2905
+ std::string target, std::string locality, std::string backend_service,
2761
2906
  tsi_handshaker** handshaker) {
2762
2907
  SSL* ssl = SSL_new(ctx);
2763
2908
  BIO* network_io = nullptr;
@@ -2854,7 +2999,8 @@ static tsi_result create_tsi_ssl_handshaker(
2854
2999
  tsi_ssl_handshaker* impl = new tsi_ssl_handshaker(
2855
3000
  &handshaker_vtable, ssl, network_io,
2856
3001
  tsi_ssl_handshaker_factory_ref(factory), std::move(collection_scope),
2857
- is_client, std::move(key_signer));
3002
+ is_client, std::move(key_signer), std::move(target), std::move(locality),
3003
+ std::move(backend_service));
2858
3004
  *handshaker = impl;
2859
3005
 
2860
3006
  if (!SSL_set_ex_data(ssl, g_ssl_ex_handshaker_index, impl)) {
@@ -2900,6 +3046,7 @@ tsi_result tsi_ssl_client_handshaker_factory_create_handshaker(
2900
3046
  size_t ssl_bio_buf_size,
2901
3047
  std::optional<std::string> alpn_preferred_protocol_list,
2902
3048
  grpc_core::RefCountedPtr<grpc_core::CollectionScope> collection_scope,
3049
+ std::string target, std::string locality, std::string backend_service,
2903
3050
  tsi_handshaker** handshaker) {
2904
3051
  GRPC_TRACE_LOG(tsi, INFO)
2905
3052
  << "Creating SSL handshaker with SNI " << server_name_indication;
@@ -2911,6 +3058,7 @@ tsi_result tsi_ssl_client_handshaker_factory_create_handshaker(
2911
3058
  factory->ssl_context, /*is_client=*/true, server_name_indication,
2912
3059
  network_bio_buf_size, ssl_bio_buf_size, alpn_preferred_protocol_list,
2913
3060
  std::move(key_signer), &factory->base, std::move(collection_scope),
3061
+ std::move(target), std::move(locality), std::move(backend_service),
2914
3062
  handshaker);
2915
3063
  }
2916
3064
 
@@ -2964,10 +3112,11 @@ tsi_result tsi_ssl_server_handshaker_factory_create_handshaker(
2964
3112
  key_signer = factory->ssl_contexts[0].key_signer;
2965
3113
  #endif
2966
3114
  return create_tsi_ssl_handshaker(
2967
- factory->ssl_contexts[0].ssl_ctx, /*is_client=*/false, nullptr,
2968
- network_bio_buf_size, ssl_bio_buf_size, std::nullopt,
2969
- std::move(key_signer), &factory->base, std::move(collection_scope),
2970
- handshaker);
3115
+ factory->ssl_contexts[0].ssl_ctx, /*is_client=*/false,
3116
+ /*server_name_indication=*/nullptr, network_bio_buf_size,
3117
+ ssl_bio_buf_size, std::nullopt, std::move(key_signer), &factory->base,
3118
+ std::move(collection_scope), /*target=*/"",
3119
+ /*locality=*/"", /*backend_service=*/"", handshaker);
2971
3120
  }
2972
3121
 
2973
3122
  void tsi_ssl_server_handshaker_factory_unref(
@@ -3035,6 +3184,12 @@ static int ssl_server_handshaker_factory_servername_callback(SSL* ssl,
3035
3184
  if (servername == nullptr || strlen(servername) == 0) {
3036
3185
  return SSL_TLSEXT_ERR_NOACK;
3037
3186
  }
3187
+ #if defined(OPENSSL_IS_BORINGSSL)
3188
+ // The cert selector will handle SNI.
3189
+ if (impl->certificate_selector != nullptr) {
3190
+ return SSL_TLSEXT_ERR_OK;
3191
+ }
3192
+ #endif
3038
3193
 
3039
3194
  for (const auto& ssl_context : impl->ssl_contexts) {
3040
3195
  if (tsi_ssl_peer_matches_name(&ssl_context.x509_subject_name, servername)) {
@@ -3103,7 +3258,7 @@ static tsi_ssl_handshaker_factory_vtable client_handshaker_factory_vtable = {
3103
3258
  tsi_ssl_client_handshaker_factory_destroy};
3104
3259
 
3105
3260
  tsi_result tsi_create_ssl_client_handshaker_factory(
3106
- const tsi_ssl_pem_key_cert_pair* pem_key_cert_pair,
3261
+ const grpc_core::PemKeyCertPair* pem_key_cert_pair,
3107
3262
  const char* pem_root_certs, const char* cipher_suites,
3108
3263
  const char** alpn_protocols, uint16_t num_alpn_protocols,
3109
3264
  tsi_ssl_client_handshaker_factory** factory) {
@@ -3196,7 +3351,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options(
3196
3351
  #if defined(OPENSSL_IS_BORINGSSL)
3197
3352
  if (options->pem_key_cert_pair != nullptr) {
3198
3353
  grpc_core::Match(
3199
- options->pem_key_cert_pair->private_key, [](const std::string&) {},
3354
+ options->pem_key_cert_pair->private_key(), [](const std::string&) {},
3200
3355
  [&](const std::shared_ptr<grpc_core::PrivateKeySigner>& key_signer) {
3201
3356
  // The Handshaker Factory will own a shared copy of the reference
3202
3357
  // passed through the options.
@@ -3212,9 +3367,9 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options(
3212
3367
  SSL_CTX_set_cert_store(ssl_context, options->root_store->store);
3213
3368
  }
3214
3369
  #endif
3215
- if (OPENSSL_VERSION_NUMBER < 0x10100000 ||
3216
- (options->root_store == nullptr &&
3217
- options->root_cert_info != nullptr)) {
3370
+ if (options->root_cert_info != nullptr &&
3371
+ (OPENSSL_VERSION_NUMBER < 0x10100000 ||
3372
+ options->root_store == nullptr)) {
3218
3373
  Match(
3219
3374
  *options->root_cert_info,
3220
3375
  [&](const std::string& pem_root_certs) {
@@ -3307,25 +3462,25 @@ static tsi_ssl_handshaker_factory_vtable server_handshaker_factory_vtable = {
3307
3462
  tsi_ssl_server_handshaker_factory_destroy};
3308
3463
 
3309
3464
  tsi_result tsi_create_ssl_server_handshaker_factory(
3310
- tsi_ssl_key_cert_pairs pem_key_cert_pairs,
3465
+ grpc_core::KeyCertPairsOrSelector key_cert_pairs_or_selector,
3311
3466
  const char* pem_client_root_certs, int force_client_auth,
3312
3467
  const char* cipher_suites, const char** alpn_protocols,
3313
3468
  uint16_t num_alpn_protocols, tsi_ssl_server_handshaker_factory** factory) {
3314
3469
  return tsi_create_ssl_server_handshaker_factory_ex(
3315
- std::move(pem_key_cert_pairs), pem_client_root_certs,
3470
+ std::move(key_cert_pairs_or_selector), pem_client_root_certs,
3316
3471
  force_client_auth ? TSI_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY
3317
3472
  : TSI_DONT_REQUEST_CLIENT_CERTIFICATE,
3318
3473
  cipher_suites, alpn_protocols, num_alpn_protocols, factory);
3319
3474
  }
3320
3475
 
3321
3476
  tsi_result tsi_create_ssl_server_handshaker_factory_ex(
3322
- tsi_ssl_key_cert_pairs pem_key_cert_pairs,
3477
+ grpc_core::KeyCertPairsOrSelector key_cert_pairs_or_selector,
3323
3478
  const char* pem_client_root_certs,
3324
3479
  tsi_client_certificate_request_type client_certificate_request,
3325
3480
  const char* cipher_suites, const char** alpn_protocols,
3326
3481
  uint16_t num_alpn_protocols, tsi_ssl_server_handshaker_factory** factory) {
3327
3482
  tsi_ssl_server_handshaker_options options;
3328
- options.pem_key_cert_pairs = std::move(pem_key_cert_pairs);
3483
+ options.key_cert_pairs_or_selector = std::move(key_cert_pairs_or_selector);
3329
3484
  if (pem_client_root_certs != nullptr) {
3330
3485
  options.root_cert_info =
3331
3486
  std::make_shared<tsi::RootCertInfo>(pem_client_root_certs);
@@ -3340,7 +3495,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex(
3340
3495
 
3341
3496
  tsi_result tsi_configure_server_ssl_context(
3342
3497
  const tsi_ssl_server_handshaker_options* options,
3343
- const tsi_ssl_pem_key_cert_pair* pem_key_cert_pair,
3498
+ const grpc_core::PemKeyCertPair* pem_key_cert_pair,
3344
3499
  tsi_ssl_server_handshaker_factory* impl, SslContext& ssl_context) {
3345
3500
  #if OPENSSL_VERSION_NUMBER >= 0x10100000
3346
3501
  ssl_context.ssl_ctx = SSL_CTX_new(TLS_method());
@@ -3366,7 +3521,7 @@ tsi_result tsi_configure_server_ssl_context(
3366
3521
  #if defined(OPENSSL_IS_BORINGSSL)
3367
3522
  if (pem_key_cert_pair != nullptr) {
3368
3523
  grpc_core::Match(
3369
- pem_key_cert_pair->private_key, [](const std::string&) {},
3524
+ pem_key_cert_pair->private_key(), [](const std::string&) {},
3370
3525
  [&](const std::shared_ptr<grpc_core::PrivateKeySigner>& key_signer) {
3371
3526
  ssl_context.key_signer = key_signer;
3372
3527
  });
@@ -3472,12 +3627,15 @@ tsi_result tsi_configure_server_ssl_context(
3472
3627
 
3473
3628
  if (pem_key_cert_pair != nullptr) {
3474
3629
  result = tsi_ssl_extract_x509_subject_names_from_pem_cert(
3475
- pem_key_cert_pair->cert_chain.c_str(), &ssl_context.x509_subject_name);
3630
+ pem_key_cert_pair->cert_chain().c_str(),
3631
+ &ssl_context.x509_subject_name);
3476
3632
  if (result != TSI_OK) return result;
3477
- SSL_CTX_set_tlsext_servername_callback(
3478
- ssl_context.ssl_ctx, ssl_server_handshaker_factory_servername_callback);
3479
- SSL_CTX_set_tlsext_servername_arg(ssl_context.ssl_ctx, impl);
3480
3633
  }
3634
+ // Always configure the callback because responding to SNI is required for
3635
+ // ClientHello in TLS 1.3, and we need to respond to that.
3636
+ SSL_CTX_set_tlsext_servername_callback(
3637
+ ssl_context.ssl_ctx, ssl_server_handshaker_factory_servername_callback);
3638
+ SSL_CTX_set_tlsext_servername_arg(ssl_context.ssl_ctx, impl);
3481
3639
  #if TSI_OPENSSL_ALPN_SUPPORT
3482
3640
  SSL_CTX_set_alpn_select_cb(ssl_context.ssl_ctx,
3483
3641
  ServerHandshakerFactoryAlpnCallback, impl);
@@ -3517,8 +3675,8 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options(
3517
3675
  impl->base.vtable = &server_handshaker_factory_vtable;
3518
3676
 
3519
3677
  tsi_result result = grpc_core::Match(
3520
- options->pem_key_cert_pairs,
3521
- [&](const std::vector<tsi_ssl_pem_key_cert_pair>& pem_key_cert_pairs) {
3678
+ options->key_cert_pairs_or_selector,
3679
+ [&](const grpc_core::PemKeyCertPairList& pem_key_cert_pairs) {
3522
3680
  if (pem_key_cert_pairs.empty()) {
3523
3681
  return TSI_INVALID_ARGUMENT;
3524
3682
  }