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
@@ -29,6 +29,7 @@
29
29
  #include <variant>
30
30
  #include <vector>
31
31
 
32
+ #include "src/core/credentials/transport/tls/grpc_tls_certificate_selector.h"
32
33
  #include "src/core/credentials/transport/tls/spiffe_utils.h"
33
34
  #include "src/core/credentials/transport/tls/ssl_utils.h"
34
35
  #include "src/core/lib/debug/trace.h"
@@ -194,20 +195,6 @@ FileWatcherCertificateProvider::FileWatcherCertificateProvider(
194
195
  distributor_->SetKeyMaterials(cert_name, roots.ok() ? *roots : nullptr,
195
196
  pem_key_cert_pairs);
196
197
  }
197
- grpc_error_handle root_cert_error;
198
- grpc_error_handle identity_cert_error;
199
- if (root_being_watched && (!roots.ok() || *roots == nullptr)) {
200
- root_cert_error =
201
- GRPC_ERROR_CREATE("Unable to get latest root certificates.");
202
- }
203
- if (identity_being_watched && !pem_key_cert_pairs.has_value()) {
204
- identity_cert_error =
205
- GRPC_ERROR_CREATE("Unable to get latest identity certificates.");
206
- }
207
- if (!root_cert_error.ok() || !identity_cert_error.ok()) {
208
- distributor_->SetErrorForCert(cert_name, root_cert_error,
209
- identity_cert_error);
210
- }
211
198
  });
212
199
  }
213
200
 
@@ -326,8 +313,7 @@ std::optional<std::string>
326
313
  FileWatcherCertificateProvider::ReadRootCertificatesFromFile(
327
314
  const std::string& root_cert_full_path) {
328
315
  // Read the root file.
329
- auto root_slice =
330
- LoadFile(root_cert_full_path, /*add_null_terminator=*/false);
316
+ auto root_slice = LoadFile(root_cert_full_path);
331
317
  if (!root_slice.ok()) {
332
318
  LOG(ERROR) << "Reading file " << root_cert_full_path
333
319
  << " failed: " << root_slice.status();
@@ -371,14 +357,13 @@ FileWatcherCertificateProvider::ReadIdentityKeyCertPairFromFiles(
371
357
  continue;
372
358
  }
373
359
  // Read the identity files.
374
- auto key_slice = LoadFile(private_key_path, /*add_null_terminator=*/false);
360
+ auto key_slice = LoadFile(private_key_path);
375
361
  if (!key_slice.ok()) {
376
362
  LOG(ERROR) << "Reading file " << private_key_path
377
363
  << " failed: " << key_slice.status() << ". Start retrying...";
378
364
  continue;
379
365
  }
380
- auto cert_slice =
381
- LoadFile(identity_certificate_path, /*add_null_terminator=*/false);
366
+ auto cert_slice = LoadFile(identity_certificate_path);
382
367
  if (!cert_slice.ok()) {
383
368
  LOG(ERROR) << "Reading file " << identity_certificate_path
384
369
  << " failed: " << cert_slice.status() << ". Start retrying...";
@@ -423,7 +408,7 @@ InMemoryCertificateProvider::InMemoryCertificateProvider()
423
408
  bool identity_being_watched) {
424
409
  MutexLock lock(&mu_);
425
410
  std::shared_ptr<tsi::RootCertInfo> roots;
426
- std::optional<PemKeyCertPairList> pem_key_cert_pairs;
411
+ std::optional<KeyCertPairsOrSelector> key_cert_pairs_or_selector;
427
412
  WatcherInfo& info = watcher_info_[cert_name];
428
413
  if (!info.root_being_watched && root_being_watched &&
429
414
  root_certificates_.ok() && *root_certificates_ != nullptr) {
@@ -431,36 +416,23 @@ InMemoryCertificateProvider::InMemoryCertificateProvider()
431
416
  }
432
417
  info.root_being_watched = root_being_watched;
433
418
  if (!info.identity_being_watched && identity_being_watched &&
434
- !pem_key_cert_pairs_.empty()) {
435
- pem_key_cert_pairs = pem_key_cert_pairs_;
419
+ !IsKeyCertPairsOrSelectorEmpty(key_cert_pairs_or_selector_)) {
420
+ key_cert_pairs_or_selector = key_cert_pairs_or_selector_;
436
421
  }
437
422
  info.identity_being_watched = identity_being_watched;
438
423
  if (!info.root_being_watched && !info.identity_being_watched) {
439
424
  watcher_info_.erase(cert_name);
440
425
  }
441
- if (roots != nullptr || pem_key_cert_pairs.has_value()) {
442
- distributor_->SetKeyMaterials(cert_name, roots, pem_key_cert_pairs);
443
- }
444
- grpc_error_handle root_cert_error;
445
- grpc_error_handle identity_cert_error;
446
- if (root_being_watched && roots == nullptr) {
447
- root_cert_error =
448
- GRPC_ERROR_CREATE("Unable to get latest root certificates.");
449
- }
450
- if (identity_being_watched && !pem_key_cert_pairs.has_value()) {
451
- identity_cert_error =
452
- GRPC_ERROR_CREATE("Unable to get latest identity certificates.");
453
- }
454
- if (!root_cert_error.ok() || !identity_cert_error.ok()) {
455
- distributor_->SetErrorForCert(cert_name, root_cert_error,
456
- identity_cert_error);
426
+ if (roots != nullptr || key_cert_pairs_or_selector.has_value()) {
427
+ distributor_->SetKeyMaterials(cert_name, roots,
428
+ key_cert_pairs_or_selector);
457
429
  }
458
430
  });
459
431
  }
460
432
 
461
433
  absl::Status InMemoryCertificateProvider::Update(
462
434
  std::optional<std::shared_ptr<tsi::RootCertInfo>> root_cert_info,
463
- std::optional<const PemKeyCertPairList> pem_key_cert_pairs) {
435
+ std::optional<const KeyCertPairsOrSelector> key_cert_pairs_or_selector) {
464
436
  MutexLock lock(&mu_);
465
437
  const bool root_changed =
466
438
  root_cert_info.has_value() &&
@@ -468,10 +440,11 @@ absl::Status InMemoryCertificateProvider::Update(
468
440
  if (root_changed) {
469
441
  root_certificates_ = std::move(*root_cert_info);
470
442
  }
471
- const bool identity_cert_changed = pem_key_cert_pairs.has_value() &&
472
- pem_key_cert_pairs_ != pem_key_cert_pairs;
443
+ const bool identity_cert_changed =
444
+ key_cert_pairs_or_selector.has_value() &&
445
+ key_cert_pairs_or_selector_ != key_cert_pairs_or_selector;
473
446
  if (identity_cert_changed) {
474
- pem_key_cert_pairs_ = *pem_key_cert_pairs;
447
+ key_cert_pairs_or_selector_ = *key_cert_pairs_or_selector;
475
448
  }
476
449
  if (root_changed || identity_cert_changed) {
477
450
  grpc_error_handle root_cert_error =
@@ -482,15 +455,16 @@ absl::Status InMemoryCertificateProvider::Update(
482
455
  const std::string& cert_name = p.first;
483
456
  const WatcherInfo& info = p.second;
484
457
  std::shared_ptr<tsi::RootCertInfo> root_to_report;
485
- std::optional<PemKeyCertPairList> identity_to_report;
458
+ std::optional<KeyCertPairsOrSelector> identity_to_report;
486
459
  // Set key materials to the distributor if their contents changed.
487
460
  if (info.root_being_watched && root_changed) {
488
461
  root_to_report =
489
462
  root_certificates_.ok() ? *root_certificates_ : nullptr;
490
463
  }
491
- if (info.identity_being_watched && !pem_key_cert_pairs_.empty() &&
464
+ if (info.identity_being_watched &&
465
+ !IsKeyCertPairsOrSelectorEmpty(key_cert_pairs_or_selector_) &&
492
466
  identity_cert_changed) {
493
- identity_to_report = pem_key_cert_pairs_;
467
+ identity_to_report = key_cert_pairs_or_selector_;
494
468
  }
495
469
  if (root_to_report != nullptr || identity_to_report.has_value()) {
496
470
  distributor_->SetKeyMaterials(cert_name, std::move(root_to_report),
@@ -501,7 +475,8 @@ absl::Status InMemoryCertificateProvider::Update(
501
475
  info.root_being_watched &&
502
476
  (!root_certificates_.ok() || *root_certificates_ == nullptr);
503
477
  const bool report_identity_error =
504
- info.identity_being_watched && pem_key_cert_pairs_.empty();
478
+ info.identity_being_watched &&
479
+ IsKeyCertPairsOrSelectorEmpty(key_cert_pairs_or_selector_);
505
480
  if (report_root_error || report_identity_error) {
506
481
  distributor_->SetErrorForCert(
507
482
  cert_name, report_root_error ? root_cert_error : absl::OkStatus(),
@@ -521,14 +496,28 @@ absl::Status InMemoryCertificateProvider::ValidateCredentials() const {
521
496
  if (!status.ok()) {
522
497
  return status;
523
498
  }
524
- for (const PemKeyCertPair& pair : pem_key_cert_pairs_) {
525
- absl::Status status =
526
- ValidatePemKeyCertPair(pair.cert_chain(), pair.private_key());
527
- if (!status.ok()) {
528
- return status;
529
- }
530
- }
531
- return absl::OkStatus();
499
+ return Match(
500
+ key_cert_pairs_or_selector_,
501
+ [](const PemKeyCertPairList& pem_pairs) {
502
+ for (const PemKeyCertPair& pair : pem_pairs) {
503
+ absl::Status status =
504
+ ValidatePemKeyCertPair(pair.cert_chain(), pair.private_key());
505
+ if (!status.ok()) {
506
+ return status;
507
+ }
508
+ }
509
+ return absl::OkStatus();
510
+ },
511
+ [](const std::shared_ptr<CertificateSelector>& cert_selector) {
512
+ #if !defined(OPENSSL_IS_BORINGSSL)
513
+ return absl::InvalidArgumentError(
514
+ "Certificate selector is not supported");
515
+ #endif
516
+ if (cert_selector == nullptr) {
517
+ return absl::InvalidArgumentError("Certificiate selector is nullptr");
518
+ }
519
+ return absl::OkStatus();
520
+ });
532
521
  }
533
522
 
534
523
  absl::Status InMemoryCertificateProvider::UpdateRoot(
@@ -537,8 +526,8 @@ absl::Status InMemoryCertificateProvider::UpdateRoot(
537
526
  }
538
527
 
539
528
  absl::Status InMemoryCertificateProvider::UpdateIdentityKeyCertPair(
540
- const PemKeyCertPairList& pem_key_cert_pairs) {
541
- return Update(std::nullopt, pem_key_cert_pairs);
529
+ const KeyCertPairsOrSelector& key_cert_pairs_or_selector) {
530
+ return Update(std::nullopt, key_cert_pairs_or_selector);
542
531
  }
543
532
 
544
533
  UniqueTypeName InMemoryCertificateProvider::type() const {
@@ -27,6 +27,7 @@
27
27
  #include <string>
28
28
 
29
29
  #include "src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h"
30
+ #include "src/core/credentials/transport/tls/grpc_tls_certificate_selector.h"
30
31
  #include "src/core/credentials/transport/tls/ssl_utils.h"
31
32
  #include "src/core/util/grpc_check.h"
32
33
  #include "src/core/util/ref_counted.h"
@@ -191,7 +192,7 @@ class InMemoryCertificateProvider final : public grpc_tls_certificate_provider {
191
192
  // successful.
192
193
  absl::Status UpdateRoot(std::shared_ptr<tsi::RootCertInfo> root_certificates);
193
194
  absl::Status UpdateIdentityKeyCertPair(
194
- const PemKeyCertPairList& pem_key_cert_pairs);
195
+ const KeyCertPairsOrSelector& key_cert_pairs_or_selector);
195
196
 
196
197
  private:
197
198
  struct WatcherInfo {
@@ -205,15 +206,15 @@ class InMemoryCertificateProvider final : public grpc_tls_certificate_provider {
205
206
  }
206
207
  absl::Status Update(
207
208
  std::optional<std::shared_ptr<tsi::RootCertInfo>> root_cert_info,
208
- std::optional<const PemKeyCertPairList> pem_key_cert_pairs);
209
+ std::optional<const KeyCertPairsOrSelector> key_cert_pairs_or_selector);
209
210
 
210
211
  RefCountedPtr<grpc_tls_certificate_distributor> distributor_;
211
212
 
212
- // Guards pem_key_cert_pairs_, root_certificates_ and watcher_info_.
213
+ // Guards identities_, root_certificates_ and watcher_info_.
213
214
  mutable Mutex mu_;
214
215
  // The most-recent credential data. It will be empty if the most recent read
215
216
  // attempt failed.
216
- PemKeyCertPairList pem_key_cert_pairs_ ABSL_GUARDED_BY(mu_);
217
+ KeyCertPairsOrSelector key_cert_pairs_or_selector_ ABSL_GUARDED_BY(mu_);
217
218
  absl::StatusOr<std::shared_ptr<tsi::RootCertInfo>> root_certificates_
218
219
  ABSL_GUARDED_BY(mu_);
219
220
  // Stores each cert_name we get from the distributor callback and its watcher
@@ -41,6 +41,13 @@ class CertificateSelector {
41
41
  public:
42
42
  struct SelectCertificateInfo {
43
43
  std::string sni;
44
+ // TODO(lwge): Must be removed before this API can be public.
45
+ struct HandshakeHintsInfo {
46
+ // The raw ClientHello message.
47
+ std::string client_hello;
48
+ // The SSL capabilities string generated by BoringSSL.
49
+ std::string ssl_capabilities;
50
+ } handshake_hints_info;
44
51
  };
45
52
 
46
53
  // TODO(lwge): This should be an opaque struct when moved to a public header.
@@ -48,6 +55,25 @@ class CertificateSelector {
48
55
  std::vector<bssl::UniquePtr<CRYPTO_BUFFER>> certificate_chain;
49
56
  std::variant<bssl::UniquePtr<EVP_PKEY>, std::shared_ptr<PrivateKeySigner>>
50
57
  private_key;
58
+ // TODO(lwge): Must be removed before this API can be public.
59
+ struct HandshakeHintsResult {
60
+ // Opaque string generated by BoringSSL. See
61
+ // https://commondatastorage.googleapis.com/chromium-boringssl-docs/ssl.h.html#Handshake-hints.
62
+ std::string handshake_hints;
63
+ // The cipher list (in BoringSSL's mini-language format) to set on the
64
+ // server-side SSL object. See
65
+ // https://commondatastorage.googleapis.com/chromium-boringssl-docs/ssl.h.html#Cipher-suite-configuration.
66
+ std::string cipher_list;
67
+ // The key exchange groups to set on the server-side SSL object. See
68
+ // https://commondatastorage.googleapis.com/chromium-boringssl-docs/ssl.h.html#Diffie-Hellman-groups-and-ephemeral-key-exchanges.
69
+ std::vector<uint16_t> key_exchange_groups;
70
+ // The minimum TLS version to set on the server-side SSL object. See
71
+ // https://commondatastorage.googleapis.com/chromium-boringssl-docs/ssl.h.html#Protocol-versions.
72
+ uint16_t min_tls_version;
73
+ // The maximum TLS version to set on the server-side SSL object. See
74
+ // https://commondatastorage.googleapis.com/chromium-boringssl-docs/ssl.h.html#Protocol-versions.
75
+ uint16_t max_tls_version;
76
+ } handshake_hints_result;
51
77
  };
52
78
 
53
79
  // Returns a SelectCertificateResult given a DER-encoded certificate chain,
@@ -72,7 +72,7 @@ absl::StatusOr<std::string> IssuerFromCrl(X509_CRL* crl) {
72
72
 
73
73
  absl::StatusOr<std::shared_ptr<Crl>> ReadCrlFromFile(
74
74
  const std::string& crl_path) {
75
- absl::StatusOr<Slice> crl_slice = LoadFile(crl_path, false);
75
+ absl::StatusOr<Slice> crl_slice = LoadFile(crl_path);
76
76
  if (!crl_slice.ok()) {
77
77
  return crl_slice.status();
78
78
  }
@@ -19,16 +19,12 @@
19
19
  #ifndef GRPC_SRC_CORE_CREDENTIALS_TRANSPORT_TLS_LOAD_SYSTEM_ROOTS_H
20
20
  #define GRPC_SRC_CORE_CREDENTIALS_TRANSPORT_TLS_LOAD_SYSTEM_ROOTS_H
21
21
 
22
- #include <grpc/slice.h>
23
- #include <grpc/support/port_platform.h>
22
+ #include "src/core/lib/slice/slice.h"
24
23
 
25
24
  namespace grpc_core {
26
25
 
27
- // TODO(matthewstevenson88): Update LoadSystemRootCerts to use Slice
28
- // instead of grpc_slice.
29
-
30
26
  // Returns a slice containing roots from the OS trust store
31
- grpc_slice LoadSystemRootCerts();
27
+ Slice LoadSystemRootCerts();
32
28
 
33
29
  } // namespace grpc_core
34
30
 
@@ -22,14 +22,12 @@
22
22
  !defined(GPR_APPLE) && !defined(GPR_NETBSD) && !defined(GPR_OPENBSD) && \
23
23
  !defined(GPR_WINDOWS)
24
24
 
25
- #include <grpc/slice.h>
26
- #include <grpc/slice_buffer.h>
27
-
28
25
  #include "src/core/credentials/transport/tls/load_system_roots.h"
26
+ #include "src/core/lib/slice/slice.h"
29
27
 
30
28
  namespace grpc_core {
31
29
 
32
- grpc_slice LoadSystemRootCerts() { return grpc_empty_slice(); }
30
+ Slice LoadSystemRootCerts() { return Slice(); }
33
31
 
34
32
  } // namespace grpc_core
35
33
 
@@ -67,13 +67,13 @@ const char* kCertFiles[] = {"/etc/ssl/cert.pem"};
67
67
  const char* kCertDirectories[] = {""};
68
68
  #endif // GPR_OPENBSD
69
69
 
70
- grpc_slice GetSystemRootCerts() {
70
+ Slice GetSystemRootCerts() {
71
71
  size_t num_cert_files_ = GPR_ARRAY_SIZE(kCertFiles);
72
72
  for (size_t i = 0; i < num_cert_files_; i++) {
73
- auto slice = LoadFile(kCertFiles[i], /*add_null_terminator=*/true);
74
- if (slice.ok()) return slice->TakeCSlice();
73
+ auto slice = LoadFile(kCertFiles[i]);
74
+ if (slice.ok()) return std::move(*slice);
75
75
  }
76
- return grpc_empty_slice();
76
+ return Slice();
77
77
  }
78
78
 
79
79
  } // namespace
@@ -89,14 +89,13 @@ void GetAbsoluteFilePath(const char* valid_file_dir,
89
89
  }
90
90
  }
91
91
 
92
- grpc_slice CreateRootCertsBundle(const char* certs_directory) {
93
- grpc_slice bundle_slice = grpc_empty_slice();
92
+ Slice CreateRootCertsBundle(const char* certs_directory) {
94
93
  if (certs_directory == nullptr) {
95
- return bundle_slice;
94
+ return Slice();
96
95
  }
97
96
  DIR* ca_directory = opendir(certs_directory);
98
97
  if (ca_directory == nullptr) {
99
- return bundle_slice;
98
+ return Slice();
100
99
  }
101
100
  struct FileData {
102
101
  char path[MAXPATHLEN];
@@ -140,12 +139,11 @@ grpc_slice CreateRootCertsBundle(const char* certs_directory) {
140
139
  close(file_descriptor);
141
140
  }
142
141
  }
143
- bundle_slice = grpc_slice_new(bundle_string, bytes_read, gpr_free);
144
- return bundle_slice;
142
+ return Slice(grpc_slice_new(bundle_string, bytes_read, gpr_free));
145
143
  }
146
144
 
147
- grpc_slice LoadSystemRootCerts() {
148
- grpc_slice result = grpc_empty_slice();
145
+ Slice LoadSystemRootCerts() {
146
+ Slice result;
149
147
  // Prioritize user-specified custom directory if flag is set.
150
148
  auto custom_dir = ConfigVars::Get().SystemSslRootsDir();
151
149
  if (!custom_dir.empty()) {
@@ -153,13 +151,13 @@ grpc_slice LoadSystemRootCerts() {
153
151
  }
154
152
  // If the custom directory is empty/invalid/not specified, fallback to
155
153
  // distribution-specific directory.
156
- if (GRPC_SLICE_IS_EMPTY(result)) {
154
+ if (result.empty()) {
157
155
  result = GetSystemRootCerts();
158
156
  }
159
- if (GRPC_SLICE_IS_EMPTY(result)) {
157
+ if (result.empty()) {
160
158
  for (size_t i = 0; i < GPR_ARRAY_SIZE(kCertDirectories); i++) {
161
159
  result = CreateRootCertsBundle(kCertDirectories[i]);
162
- if (!GRPC_SLICE_IS_EMPTY(result)) {
160
+ if (!result.empty()) {
163
161
  break;
164
162
  }
165
163
  }
@@ -19,9 +19,10 @@
19
19
  #ifndef GRPC_SRC_CORE_CREDENTIALS_TRANSPORT_TLS_LOAD_SYSTEM_ROOTS_SUPPORTED_H
20
20
  #define GRPC_SRC_CORE_CREDENTIALS_TRANSPORT_TLS_LOAD_SYSTEM_ROOTS_SUPPORTED_H
21
21
 
22
- #include <grpc/slice.h>
23
22
  #include <grpc/support/port_platform.h>
24
23
 
24
+ #include "src/core/lib/slice/slice.h"
25
+
25
26
  #if defined(GPR_LINUX) || defined(GPR_FREEBSD) || defined(GPR_APPLE)
26
27
 
27
28
  namespace grpc_core {
@@ -30,7 +31,7 @@ namespace grpc_core {
30
31
  // a directory.
31
32
  // Returns such slice.
32
33
  // Exposed for testing purposes only.
33
- grpc_slice CreateRootCertsBundle(const char* certs_directory);
34
+ Slice CreateRootCertsBundle(const char* certs_directory);
34
35
 
35
36
  // Gets the absolute file path needed to load a certificate file.
36
37
  // Populates path_buffer, which must be of size MAXPATHLEN.
@@ -23,15 +23,12 @@
23
23
  #pragma comment(lib, "crypt32")
24
24
 
25
25
  #include <esent.h>
26
- #include <grpc/slice.h>
27
- #include <grpc/slice_buffer.h>
28
- #include <grpc/support/alloc.h>
29
26
  #include <wincrypt.h>
30
27
 
31
28
  #include <vector>
32
29
 
33
30
  #include "src/core/credentials/transport/tls/load_system_roots.h"
34
- #include "src/core/lib/slice/slice_internal.h"
31
+ #include "src/core/lib/slice/slice.h"
35
32
  #include "src/core/util/useful.h"
36
33
 
37
34
  namespace grpc_core {
@@ -50,13 +47,13 @@ std::string Utf8Encode(const std::wstring& wstr) {
50
47
 
51
48
  } // namespace
52
49
 
53
- grpc_slice LoadSystemRootCerts() {
50
+ Slice LoadSystemRootCerts() {
54
51
  std::string bundle_string;
55
52
 
56
53
  // Open root certificate store.
57
54
  HANDLE root_cert_store = CertOpenSystemStoreW(NULL, L"ROOT");
58
55
  if (!root_cert_store) {
59
- return grpc_empty_slice();
56
+ return Slice();
60
57
  }
61
58
 
62
59
  // Load all root certificates from certificate store.
@@ -74,10 +71,10 @@ grpc_slice LoadSystemRootCerts() {
74
71
 
75
72
  CertCloseStore(root_cert_store, 0);
76
73
  if (bundle_string.size() == 0) {
77
- return grpc_empty_slice();
74
+ return Slice();
78
75
  }
79
76
 
80
- return grpc_slice_from_cpp_string(std::move(bundle_string));
77
+ return Slice::FromCopiedString(std::move(bundle_string));
81
78
  }
82
79
 
83
80
  } // namespace grpc_core
@@ -345,7 +345,7 @@ void SpiffeBundleMap::JsonPostLoad(const Json&, const JsonArgs&,
345
345
 
346
346
  absl::StatusOr<SpiffeBundleMap> SpiffeBundleMap::FromFile(
347
347
  absl::string_view file_path) {
348
- auto slice = LoadFile(file_path.data(), /*add_null_terminator=*/false);
348
+ auto slice = LoadFile(file_path.data());
349
349
  GRPC_RETURN_IF_ERROR(slice.status());
350
350
  auto json = JsonParse(slice->as_string_view());
351
351
  GRPC_RETURN_IF_ERROR(json.status());
@@ -34,6 +34,7 @@
34
34
  #include <vector>
35
35
 
36
36
  #include "src/core/config/config_vars.h"
37
+ #include "src/core/credentials/transport/tls/grpc_tls_certificate_selector.h"
37
38
  #include "src/core/credentials/transport/tls/load_system_roots.h"
38
39
  #include "src/core/ext/transport/chttp2/alpn/alpn.h"
39
40
  #include "src/core/lib/channel/channel_args.h"
@@ -303,6 +304,10 @@ grpc_core::RefCountedPtr<grpc_auth_context> grpc_ssl_peer_to_auth_context(
303
304
  grpc_auth_context_add_property(ctx.get(),
304
305
  GRPC_SSL_SESSION_REUSED_PROPERTY,
305
306
  prop->value.data, prop->value.length);
307
+ } else if (strcmp(prop->name, TSI_SSL_NEGOTIATED_KEY_EXCHANGE_GROUP) == 0) {
308
+ grpc_auth_context_add_property(
309
+ ctx.get(), GRPC_SSL_NEGOTIATED_KEY_EXCHANGE_GROUP_PROPERTY_NAME,
310
+ prop->value.data, prop->value.length);
306
311
  } else if (strcmp(prop->name, TSI_SECURITY_LEVEL_PEER_PROPERTY) == 0) {
307
312
  grpc_auth_context_add_property(
308
313
  ctx.get(), GRPC_TRANSPORT_SECURITY_LEVEL_PROPERTY_NAME,
@@ -418,7 +423,7 @@ void grpc_shallow_peer_destruct(tsi_peer* peer) {
418
423
  }
419
424
 
420
425
  grpc_security_status grpc_ssl_tsi_client_handshaker_factory_init(
421
- tsi_ssl_pem_key_cert_pair* pem_key_cert_pair,
426
+ const grpc_core::PemKeyCertPair* pem_key_cert_pair,
422
427
  std::shared_ptr<tsi::RootCertInfo> root_cert_info,
423
428
  bool skip_server_certificate_verification, tsi_tls_version min_tls_version,
424
429
  tsi_tls_version max_tls_version, tsi_ssl_session_cache* ssl_session_cache,
@@ -427,7 +432,7 @@ grpc_security_status grpc_ssl_tsi_client_handshaker_factory_init(
427
432
  std::shared_ptr<grpc_core::experimental::CrlProvider> crl_provider,
428
433
  const std::vector<grpc_tls_key_exchange_group>& key_exchange_groups,
429
434
  tsi_ssl_client_handshaker_factory** handshaker_factory) {
430
- const char* root_certs = nullptr;
435
+ absl::string_view root_certs;
431
436
  const tsi_ssl_root_certs_store* root_store = nullptr;
432
437
  tsi_ssl_client_handshaker_options options;
433
438
  bool roots_are_configured = root_cert_info != nullptr;
@@ -437,19 +442,20 @@ grpc_security_status grpc_ssl_tsi_client_handshaker_factory_init(
437
442
  "default locations instead";
438
443
  // Use default root certificates.
439
444
  root_certs = grpc_core::DefaultSslRootStore::GetPemRootCerts();
440
- if (root_certs == nullptr) {
445
+ if (root_certs.empty()) {
441
446
  LOG(ERROR) << "Could not get default pem root certs.";
442
447
  return GRPC_SECURITY_ERROR;
443
448
  }
444
449
  root_store = grpc_core::DefaultSslRootStore::GetRootStore();
445
- options.root_cert_info = std::make_shared<tsi::RootCertInfo>(root_certs);
450
+ options.root_cert_info =
451
+ std::make_shared<tsi::RootCertInfo>(std::string(root_certs));
446
452
  } else {
447
453
  options.root_cert_info = std::move(root_cert_info);
448
454
  }
449
455
  bool has_key_cert_pair =
450
456
  pem_key_cert_pair != nullptr &&
451
- !grpc_core::IsPrivateKeyEmpty(pem_key_cert_pair->private_key) &&
452
- !pem_key_cert_pair->cert_chain.empty();
457
+ !grpc_core::IsPrivateKeyEmpty(pem_key_cert_pair->private_key()) &&
458
+ !pem_key_cert_pair->cert_chain().empty();
453
459
  options.root_store = root_store;
454
460
  options.alpn_protocols =
455
461
  grpc_fill_alpn_protocol_strings(&options.num_alpn_protocols);
@@ -479,7 +485,7 @@ grpc_security_status grpc_ssl_tsi_client_handshaker_factory_init(
479
485
  }
480
486
 
481
487
  grpc_security_status grpc_ssl_tsi_server_handshaker_factory_init(
482
- std::vector<tsi_ssl_pem_key_cert_pair> pem_key_cert_pairs,
488
+ grpc_core::KeyCertPairsOrSelector key_cert_pairs,
483
489
  std::shared_ptr<tsi::RootCertInfo> root_cert_info,
484
490
  grpc_ssl_client_certificate_request_type client_certificate_request,
485
491
  tsi_tls_version min_tls_version, tsi_tls_version max_tls_version,
@@ -492,7 +498,7 @@ grpc_security_status grpc_ssl_tsi_server_handshaker_factory_init(
492
498
  const char** alpn_protocol_strings =
493
499
  grpc_fill_alpn_protocol_strings(&num_alpn_protocols);
494
500
  tsi_ssl_server_handshaker_options options;
495
- options.pem_key_cert_pairs = pem_key_cert_pairs;
501
+ options.key_cert_pairs_or_selector = std::move(key_cert_pairs);
496
502
  options.client_certificate_request =
497
503
  grpc_get_tsi_client_certificate_request_type(client_certificate_request);
498
504
  options.cipher_suites = grpc_get_ssl_cipher_suites();
@@ -574,29 +580,25 @@ bool IsPrivateKeyEmpty(const PrivateKey& private_key) {
574
580
  }
575
581
 
576
582
  tsi_ssl_root_certs_store* DefaultSslRootStore::default_root_store_;
577
- grpc_slice DefaultSslRootStore::default_pem_root_certs_;
583
+ Slice DefaultSslRootStore::default_pem_root_certs_;
578
584
 
579
585
  const tsi_ssl_root_certs_store* DefaultSslRootStore::GetRootStore() {
580
586
  InitRootStore();
581
587
  return default_root_store_;
582
588
  }
583
589
 
584
- const char* DefaultSslRootStore::GetPemRootCerts() {
590
+ absl::string_view DefaultSslRootStore::GetPemRootCerts() {
585
591
  InitRootStore();
586
- return GRPC_SLICE_IS_EMPTY(default_pem_root_certs_)
587
- ? nullptr
588
- : reinterpret_cast<const char*>
589
- GRPC_SLICE_START_PTR(default_pem_root_certs_);
592
+ return default_pem_root_certs_.as_string_view();
590
593
  }
591
594
 
592
- grpc_slice DefaultSslRootStore::ComputePemRootCerts() {
595
+ Slice DefaultSslRootStore::ComputePemRootCerts() {
593
596
  Slice result;
594
597
  // First try to load the roots from the configuration.
595
598
  std::string default_root_certs_path =
596
599
  ConfigVars::Get().DefaultSslRootsFilePath();
597
600
  if (!default_root_certs_path.empty()) {
598
- auto slice =
599
- LoadFile(default_root_certs_path, /*add_null_terminator=*/true);
601
+ auto slice = LoadFile(default_root_certs_path);
600
602
  if (!slice.ok()) {
601
603
  LOG(ERROR) << "error loading file " << default_root_certs_path << ": "
602
604
  << slice.status();
@@ -607,7 +609,7 @@ grpc_slice DefaultSslRootStore::ComputePemRootCerts() {
607
609
  // Try loading roots from OS trust store if preferred over callback.
608
610
  if (result.empty() &&
609
611
  ConfigVars::Get().UseSystemRootsOverLanguageCallback()) {
610
- result = Slice(LoadSystemRootCerts());
612
+ result = LoadSystemRootCerts();
611
613
  }
612
614
  // Try overridden roots if needed.
613
615
  grpc_ssl_roots_override_result ovrd_res = GRPC_SSL_ROOTS_OVERRIDE_FAIL;
@@ -616,19 +618,17 @@ grpc_slice DefaultSslRootStore::ComputePemRootCerts() {
616
618
  ovrd_res = ssl_roots_override_cb(&pem_root_certs);
617
619
  if (ovrd_res == GRPC_SSL_ROOTS_OVERRIDE_OK) {
618
620
  GRPC_CHECK_NE(pem_root_certs, nullptr);
619
- result = Slice::FromCopiedBuffer(
620
- pem_root_certs,
621
- strlen(pem_root_certs) + 1); // nullptr terminator.
621
+ result = Slice::FromCopiedBuffer(pem_root_certs, strlen(pem_root_certs));
622
622
  }
623
623
  gpr_free(pem_root_certs);
624
624
  }
625
625
  // Try loading roots from OS trust store if flag is enabled.
626
626
  if (result.empty() && !ConfigVars::Get().NotUseSystemSslRoots()) {
627
- result = Slice(LoadSystemRootCerts());
627
+ result = LoadSystemRootCerts();
628
628
  }
629
629
  // Fallback to roots manually shipped with gRPC.
630
630
  if (result.empty() && ovrd_res != GRPC_SSL_ROOTS_OVERRIDE_FAIL_PERMANENTLY) {
631
- auto slice = LoadFile(installed_roots_path, /*add_null_terminator=*/true);
631
+ auto slice = LoadFile(installed_roots_path);
632
632
  if (!slice.ok()) {
633
633
  LOG(ERROR) << "error loading file " << installed_roots_path << ": "
634
634
  << slice.status();
@@ -636,7 +636,7 @@ grpc_slice DefaultSslRootStore::ComputePemRootCerts() {
636
636
  result = std::move(*slice);
637
637
  }
638
638
  }
639
- return result.TakeCSlice();
639
+ return result;
640
640
  }
641
641
 
642
642
  void DefaultSslRootStore::InitRootStore() {
@@ -646,11 +646,22 @@ void DefaultSslRootStore::InitRootStore() {
646
646
 
647
647
  void DefaultSslRootStore::InitRootStoreOnce() {
648
648
  default_pem_root_certs_ = ComputePemRootCerts();
649
- if (!GRPC_SLICE_IS_EMPTY(default_pem_root_certs_)) {
650
- default_root_store_ =
651
- tsi_ssl_root_certs_store_create(reinterpret_cast<const char*>(
652
- GRPC_SLICE_START_PTR(default_pem_root_certs_)));
649
+ if (!default_pem_root_certs_.empty()) {
650
+ default_root_store_ = tsi_ssl_root_certs_store_create(
651
+ default_pem_root_certs_.as_string_view());
653
652
  }
654
653
  }
655
654
 
655
+ bool IsKeyCertPairsOrSelectorEmpty(
656
+ const KeyCertPairsOrSelector& key_cert_pairs_or_selector) {
657
+ return Match(
658
+ key_cert_pairs_or_selector,
659
+ [](const PemKeyCertPairList& pem_key_cert_pairs) {
660
+ return pem_key_cert_pairs.empty();
661
+ },
662
+ [](const std::shared_ptr<CertificateSelector>& selector) {
663
+ return selector == nullptr;
664
+ });
665
+ }
666
+
656
667
  } // namespace grpc_core