grpc 1.74.1 → 1.75.0.pre1

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 (368) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +83 -41
  3. data/include/grpc/credentials.h +7 -1
  4. data/src/core/call/client_call.cc +4 -4
  5. data/src/core/call/filter_fusion.h +1230 -0
  6. data/src/core/call/metadata.cc +22 -0
  7. data/src/core/call/metadata.h +24 -2
  8. data/src/core/channelz/channelz.cc +10 -17
  9. data/src/core/channelz/channelz.h +58 -19
  10. data/src/core/channelz/channelz_registry.cc +0 -162
  11. data/src/core/channelz/channelz_registry.h +14 -7
  12. data/src/core/channelz/property_list.cc +19 -23
  13. data/src/core/channelz/property_list.h +3 -1
  14. data/src/core/channelz/v2tov1/convert.cc +683 -0
  15. data/src/core/channelz/v2tov1/convert.h +58 -0
  16. data/src/core/channelz/v2tov1/legacy_api.cc +425 -0
  17. data/src/core/channelz/v2tov1/legacy_api.h +32 -0
  18. data/src/core/channelz/v2tov1/property_list.cc +118 -0
  19. data/src/core/channelz/v2tov1/property_list.h +52 -0
  20. data/src/core/client_channel/client_channel_filter.cc +5 -4
  21. data/src/core/client_channel/client_channel_filter.h +2 -2
  22. data/src/core/client_channel/client_channel_internal.h +2 -1
  23. data/src/core/client_channel/load_balanced_call_destination.cc +6 -5
  24. data/src/core/client_channel/subchannel.cc +14 -6
  25. data/src/core/client_channel/subchannel.h +2 -0
  26. data/src/core/config/core_configuration.cc +3 -1
  27. data/src/core/config/core_configuration.h +12 -0
  28. data/src/core/credentials/transport/alts/alts_credentials.cc +5 -0
  29. data/src/core/credentials/transport/alts/check_gcp_environment_windows.cc +2 -0
  30. data/src/core/credentials/transport/channel_creds_registry_init.cc +3 -1
  31. data/src/core/credentials/transport/ssl/ssl_credentials.cc +1 -1
  32. data/src/core/credentials/transport/ssl/ssl_security_connector.cc +8 -3
  33. data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +29 -24
  34. data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +19 -8
  35. data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +96 -54
  36. data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +15 -2
  37. data/src/core/credentials/transport/tls/spiffe_utils.cc +371 -0
  38. data/src/core/credentials/transport/tls/spiffe_utils.h +171 -0
  39. data/src/core/credentials/transport/tls/ssl_utils.cc +11 -10
  40. data/src/core/credentials/transport/tls/ssl_utils.h +4 -2
  41. data/src/core/credentials/transport/tls/tls_credentials.cc +2 -0
  42. data/src/core/credentials/transport/tls/tls_security_connector.cc +11 -26
  43. data/src/core/credentials/transport/tls/tls_security_connector.h +12 -12
  44. data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +1 -2
  45. data/src/core/ext/filters/http/client/http_client_filter.cc +3 -6
  46. data/src/core/ext/filters/http/client_authority_filter.cc +1 -2
  47. data/src/core/ext/filters/http/message_compress/compression_filter.cc +8 -8
  48. data/src/core/ext/filters/http/server/http_server_filter.cc +3 -6
  49. data/src/core/ext/filters/message_size/message_size_filter.cc +4 -4
  50. data/src/core/ext/filters/rbac/rbac_filter.cc +1 -1
  51. data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +3 -5
  52. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +3 -2
  53. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -0
  54. data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -0
  55. data/src/core/ext/transport/chttp2/transport/frame.cc +89 -6
  56. data/src/core/ext/transport/chttp2/transport/frame.h +38 -0
  57. data/src/core/ext/transport/chttp2/transport/header_assembler.h +5 -14
  58. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +4 -1
  59. data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +294 -78
  60. data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +128 -9
  61. data/src/core/ext/transport/chttp2/transport/http2_settings.cc +11 -38
  62. data/src/core/ext/transport/chttp2/transport/http2_settings.h +52 -35
  63. data/src/core/ext/transport/chttp2/transport/http2_settings_manager.cc +61 -0
  64. data/src/core/ext/transport/chttp2/transport/http2_settings_manager.h +142 -0
  65. data/src/core/ext/transport/chttp2/transport/http2_transport.cc +81 -3
  66. data/src/core/ext/transport/chttp2/transport/http2_transport.h +12 -1
  67. data/src/core/ext/transport/chttp2/transport/message_assembler.h +2 -2
  68. data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -1
  69. data/src/core/ext/transport/chttp2/transport/ping_promise.cc +2 -1
  70. data/src/core/ext/transport/chttp2/transport/ping_promise.h +22 -5
  71. data/src/core/ext/transport/chttp2/transport/stream_data_queue.h +607 -0
  72. data/src/core/ext/transport/chttp2/transport/writable_streams.h +254 -0
  73. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -4
  74. data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb.h +4959 -0
  75. data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.c +1111 -0
  76. data/src/core/ext/upb-gen/src/proto/grpc/channelz/channelz.upb_minitable.h +108 -0
  77. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb.h +142 -54
  78. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.c +18 -14
  79. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/property_list.upb_minitable.h +2 -2
  80. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.c +716 -0
  81. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.h +227 -0
  82. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.c +86 -88
  83. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/property_list.upbdefs.h +2 -2
  84. data/src/core/filter/auth/auth_filters.h +2 -2
  85. data/src/core/filter/fused_filters.cc +154 -0
  86. data/src/core/handshaker/security/legacy_secure_endpoint.cc +1 -1
  87. data/src/core/handshaker/security/pipelined_secure_endpoint.cc +965 -0
  88. data/src/core/handshaker/security/secure_endpoint.cc +28 -13
  89. data/src/core/handshaker/security/secure_endpoint.h +8 -0
  90. data/src/core/lib/channel/promise_based_filter.cc +15 -25
  91. data/src/core/lib/channel/promise_based_filter.h +6 -5
  92. data/src/core/lib/event_engine/ares_resolver.h +3 -1
  93. data/src/core/lib/event_engine/cf_engine/cf_engine.cc +9 -5
  94. data/src/core/lib/event_engine/cf_engine/cf_engine.h +2 -1
  95. data/src/core/lib/event_engine/cf_engine/cfsocket_listener.cc +263 -0
  96. data/src/core/lib/event_engine/cf_engine/cfsocket_listener.h +107 -0
  97. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +31 -3
  98. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.h +12 -0
  99. data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +12 -10
  100. data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.h +6 -4
  101. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +15 -14
  102. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.h +7 -5
  103. data/src/core/lib/event_engine/posix_engine/event_poller.h +0 -8
  104. data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.cc +11 -5
  105. data/src/core/lib/event_engine/posix_engine/event_poller_posix_default.h +3 -2
  106. data/src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h +1 -0
  107. data/src/core/lib/event_engine/posix_engine/lockfree_event.cc +4 -4
  108. data/src/core/lib/event_engine/posix_engine/lockfree_event.h +3 -4
  109. data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +2 -2
  110. data/src/core/lib/event_engine/posix_engine/posix_engine.cc +188 -199
  111. data/src/core/lib/event_engine/posix_engine/posix_engine.h +30 -45
  112. data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +1 -1
  113. data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +1 -1
  114. data/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc +2 -1
  115. data/src/core/lib/experiments/experiments.cc +120 -6
  116. data/src/core/lib/experiments/experiments.h +46 -3
  117. data/src/core/lib/iomgr/combiner.cc +1 -1
  118. data/src/core/lib/iomgr/exec_ctx.h +3 -9
  119. data/src/core/lib/iomgr/socket_mutator.cc +1 -1
  120. data/src/core/lib/iomgr/socket_utils_posix.cc +1 -1
  121. data/src/core/lib/iomgr/socket_utils_posix.h +1 -1
  122. data/src/core/lib/iomgr/tcp_client_posix.cc +1 -1
  123. data/src/core/lib/iomgr/tcp_posix.cc +3 -3
  124. data/src/core/lib/promise/activity.h +2 -2
  125. data/src/core/lib/promise/mpsc.cc +8 -8
  126. data/src/core/lib/promise/party.cc +7 -7
  127. data/src/core/lib/promise/party.h +4 -4
  128. data/src/core/lib/promise/poll.h +10 -0
  129. data/src/core/lib/resource_quota/memory_quota.cc +90 -3
  130. data/src/core/lib/resource_quota/memory_quota.h +20 -9
  131. data/src/core/lib/resource_quota/periodic_update.cc +14 -0
  132. data/src/core/lib/resource_quota/periodic_update.h +8 -0
  133. data/src/core/lib/resource_quota/resource_quota.cc +15 -4
  134. data/src/core/lib/resource_quota/resource_quota.h +3 -0
  135. data/src/core/lib/security/authorization/grpc_server_authz_filter.cc +1 -2
  136. data/src/core/lib/surface/call.cc +5 -5
  137. data/src/core/lib/surface/call.h +6 -5
  138. data/src/core/lib/surface/completion_queue.cc +2 -4
  139. data/src/core/lib/surface/filter_stack_call.cc +1 -1
  140. data/src/core/lib/surface/version.cc +2 -2
  141. data/src/core/lib/transport/promise_endpoint.cc +2 -2
  142. data/src/core/lib/transport/promise_endpoint.h +3 -3
  143. data/src/core/load_balancing/endpoint_list.cc +29 -2
  144. data/src/core/load_balancing/grpclb/client_load_reporting_filter.cc +3 -3
  145. data/src/core/load_balancing/grpclb/client_load_reporting_filter.h +1 -1
  146. data/src/core/load_balancing/pick_first/pick_first.cc +12 -5
  147. data/src/core/load_balancing/xds/xds_cluster_impl.cc +5 -3
  148. data/src/core/net/socket_mutator.cc +19 -0
  149. data/src/core/net/socket_mutator.h +25 -0
  150. data/src/core/plugin_registry/grpc_plugin_registry.cc +6 -0
  151. data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h +6 -1
  152. data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +2 -1
  153. data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +8 -5
  154. data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
  155. data/src/core/resolver/xds/xds_dependency_manager.cc +1 -1
  156. data/src/core/server/server.cc +1 -1
  157. data/src/core/server/server_call_tracer_filter.cc +0 -66
  158. data/src/core/server/server_call_tracer_filter.h +64 -0
  159. data/src/core/server/server_config_selector_filter.cc +1 -1
  160. data/src/core/service_config/service_config_channel_arg_filter.cc +3 -60
  161. data/src/core/service_config/service_config_channel_arg_filter.h +82 -0
  162. data/src/core/telemetry/call_tracer.cc +20 -14
  163. data/src/core/telemetry/call_tracer.h +22 -17
  164. data/src/core/telemetry/metrics.h +8 -8
  165. data/src/core/telemetry/stats_data.cc +151 -151
  166. data/src/core/telemetry/stats_data.h +87 -87
  167. data/src/core/transport/auth_context.cc +20 -0
  168. data/src/core/transport/auth_context.h +4 -0
  169. data/src/core/transport/auth_context_comparator_registry.h +69 -0
  170. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +2 -3
  171. data/src/core/tsi/ssl_transport_security.cc +202 -32
  172. data/src/core/tsi/ssl_transport_security.h +19 -10
  173. data/src/core/tsi/ssl_transport_security_utils.cc +21 -0
  174. data/src/core/tsi/ssl_transport_security_utils.h +4 -0
  175. data/src/core/util/http_client/httpcli_security_connector.cc +3 -1
  176. data/src/core/util/latent_see.cc +178 -146
  177. data/src/core/util/latent_see.h +245 -188
  178. data/src/core/util/single_set_ptr.h +5 -2
  179. data/src/core/util/useful.h +91 -0
  180. data/src/core/util/windows/directory_reader.cc +1 -0
  181. data/src/core/util/windows/thd.cc +1 -3
  182. data/src/core/util/work_serializer.cc +1 -1
  183. data/src/core/xds/grpc/file_watcher_certificate_provider_factory.cc +32 -5
  184. data/src/core/xds/grpc/file_watcher_certificate_provider_factory.h +5 -0
  185. data/src/core/xds/grpc/xds_certificate_provider.cc +5 -6
  186. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
  187. data/src/ruby/lib/grpc/version.rb +1 -1
  188. data/third_party/cares/cares/include/ares.h +925 -460
  189. data/third_party/cares/cares/include/ares_dns.h +86 -71
  190. data/third_party/cares/cares/include/ares_dns_record.h +1118 -0
  191. data/third_party/cares/cares/include/ares_nameser.h +215 -189
  192. data/third_party/cares/cares/include/ares_version.h +37 -14
  193. data/third_party/cares/cares/src/lib/ares_addrinfo2hostent.c +305 -0
  194. data/third_party/cares/cares/src/lib/ares_addrinfo_localhost.c +245 -0
  195. data/third_party/cares/cares/src/lib/ares_android.c +216 -164
  196. data/third_party/cares/cares/src/lib/ares_android.h +25 -14
  197. data/third_party/cares/cares/src/lib/ares_cancel.c +68 -44
  198. data/third_party/cares/cares/src/lib/ares_close_sockets.c +137 -0
  199. data/third_party/cares/cares/src/lib/ares_conn.c +511 -0
  200. data/third_party/cares/cares/src/lib/ares_conn.h +196 -0
  201. data/third_party/cares/cares/src/lib/ares_cookie.c +461 -0
  202. data/third_party/cares/cares/src/lib/ares_data.c +93 -181
  203. data/third_party/cares/cares/src/lib/ares_data.h +50 -39
  204. data/third_party/cares/cares/src/lib/ares_destroy.c +127 -89
  205. data/third_party/cares/cares/src/lib/ares_free_hostent.c +35 -24
  206. data/third_party/cares/cares/src/lib/ares_free_string.c +24 -16
  207. data/third_party/cares/cares/src/lib/ares_freeaddrinfo.c +45 -38
  208. data/third_party/cares/cares/src/lib/ares_getaddrinfo.c +549 -663
  209. data/third_party/cares/cares/src/lib/ares_getenv.c +25 -15
  210. data/third_party/cares/cares/src/lib/ares_getenv.h +26 -18
  211. data/third_party/cares/cares/src/lib/ares_gethostbyaddr.c +163 -221
  212. data/third_party/cares/cares/src/lib/ares_gethostbyname.c +222 -223
  213. data/third_party/cares/cares/src/lib/ares_getnameinfo.c +328 -338
  214. data/third_party/cares/cares/src/lib/ares_hosts_file.c +952 -0
  215. data/third_party/cares/cares/src/lib/ares_inet_net_pton.h +25 -19
  216. data/third_party/cares/cares/src/lib/ares_init.c +425 -2091
  217. data/third_party/cares/cares/src/lib/ares_ipv6.h +63 -33
  218. data/third_party/cares/cares/src/lib/ares_library_init.c +110 -54
  219. data/third_party/cares/cares/src/lib/ares_metrics.c +261 -0
  220. data/third_party/cares/cares/src/lib/ares_options.c +418 -332
  221. data/third_party/cares/cares/src/lib/ares_parse_into_addrinfo.c +179 -0
  222. data/third_party/cares/cares/src/lib/ares_private.h +558 -356
  223. data/third_party/cares/cares/src/lib/ares_process.c +1224 -1369
  224. data/third_party/cares/cares/src/lib/ares_qcache.c +430 -0
  225. data/third_party/cares/cares/src/lib/ares_query.c +126 -121
  226. data/third_party/cares/cares/src/lib/ares_search.c +564 -262
  227. data/third_party/cares/cares/src/lib/ares_send.c +264 -93
  228. data/third_party/cares/cares/src/lib/ares_set_socket_functions.c +588 -0
  229. data/third_party/cares/cares/src/lib/ares_setup.h +115 -111
  230. data/third_party/cares/cares/src/lib/ares_socket.c +425 -0
  231. data/third_party/cares/cares/src/lib/ares_socket.h +163 -0
  232. data/third_party/cares/cares/src/lib/ares_sortaddrinfo.c +447 -0
  233. data/third_party/cares/cares/src/lib/ares_strerror.c +83 -48
  234. data/third_party/cares/cares/src/lib/ares_sysconfig.c +639 -0
  235. data/third_party/cares/cares/src/lib/ares_sysconfig_files.c +839 -0
  236. data/third_party/cares/cares/src/lib/ares_sysconfig_mac.c +373 -0
  237. data/third_party/cares/cares/src/lib/ares_sysconfig_win.c +621 -0
  238. data/third_party/cares/cares/src/lib/ares_timeout.c +136 -73
  239. data/third_party/cares/cares/src/lib/ares_update_servers.c +1362 -0
  240. data/third_party/cares/cares/src/lib/ares_version.c +29 -4
  241. data/third_party/cares/cares/src/lib/config-dos.h +88 -89
  242. data/third_party/cares/cares/src/lib/config-win32.h +122 -77
  243. data/third_party/cares/cares/src/lib/dsa/ares_array.c +394 -0
  244. data/third_party/cares/cares/src/lib/dsa/ares_htable.c +447 -0
  245. data/third_party/cares/cares/src/lib/dsa/ares_htable.h +174 -0
  246. data/third_party/cares/cares/src/lib/dsa/ares_htable_asvp.c +224 -0
  247. data/third_party/cares/cares/src/lib/dsa/ares_htable_dict.c +228 -0
  248. data/third_party/cares/cares/src/lib/dsa/ares_htable_strvp.c +210 -0
  249. data/third_party/cares/cares/src/lib/dsa/ares_htable_szvp.c +188 -0
  250. data/third_party/cares/cares/src/lib/dsa/ares_htable_vpstr.c +186 -0
  251. data/third_party/cares/cares/src/lib/dsa/ares_htable_vpvp.c +194 -0
  252. data/third_party/cares/cares/src/lib/dsa/ares_llist.c +382 -0
  253. data/third_party/cares/cares/src/lib/dsa/ares_slist.c +479 -0
  254. data/third_party/cares/cares/src/lib/dsa/ares_slist.h +207 -0
  255. data/third_party/cares/cares/src/lib/event/ares_event.h +191 -0
  256. data/third_party/cares/cares/src/lib/event/ares_event_configchg.c +743 -0
  257. data/third_party/cares/cares/src/lib/event/ares_event_epoll.c +192 -0
  258. data/third_party/cares/cares/src/lib/event/ares_event_kqueue.c +248 -0
  259. data/third_party/cares/cares/src/lib/event/ares_event_poll.c +140 -0
  260. data/third_party/cares/cares/src/lib/event/ares_event_select.c +159 -0
  261. data/third_party/cares/cares/src/lib/event/ares_event_thread.c +567 -0
  262. data/third_party/cares/cares/src/lib/event/ares_event_wake_pipe.c +166 -0
  263. data/third_party/cares/cares/src/lib/event/ares_event_win32.c +978 -0
  264. data/third_party/cares/cares/src/lib/event/ares_event_win32.h +161 -0
  265. data/third_party/cares/cares/src/lib/include/ares_array.h +276 -0
  266. data/third_party/cares/cares/src/lib/include/ares_buf.h +732 -0
  267. data/third_party/cares/cares/src/lib/include/ares_htable_asvp.h +130 -0
  268. data/third_party/cares/cares/src/lib/include/ares_htable_dict.h +123 -0
  269. data/third_party/cares/cares/src/lib/include/ares_htable_strvp.h +130 -0
  270. data/third_party/cares/cares/src/lib/include/ares_htable_szvp.h +118 -0
  271. data/third_party/cares/cares/src/lib/include/ares_htable_vpstr.h +111 -0
  272. data/third_party/cares/cares/src/lib/include/ares_htable_vpvp.h +128 -0
  273. data/third_party/cares/cares/src/lib/include/ares_llist.h +239 -0
  274. data/third_party/cares/cares/src/lib/include/ares_mem.h +38 -0
  275. data/third_party/cares/cares/src/lib/include/ares_str.h +244 -0
  276. data/third_party/cares/cares/src/lib/inet_net_pton.c +202 -157
  277. data/third_party/cares/cares/src/lib/inet_ntop.c +87 -69
  278. data/third_party/cares/cares/src/lib/legacy/ares_create_query.c +78 -0
  279. data/third_party/cares/cares/src/lib/legacy/ares_expand_name.c +99 -0
  280. data/third_party/cares/cares/src/lib/legacy/ares_expand_string.c +107 -0
  281. data/third_party/cares/cares/src/lib/legacy/ares_fds.c +80 -0
  282. data/third_party/cares/cares/src/lib/legacy/ares_getsock.c +85 -0
  283. data/third_party/cares/cares/src/lib/legacy/ares_parse_a_reply.c +107 -0
  284. data/third_party/cares/cares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
  285. data/third_party/cares/cares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
  286. data/third_party/cares/cares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
  287. data/third_party/cares/cares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
  288. data/third_party/cares/cares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
  289. data/third_party/cares/cares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
  290. data/third_party/cares/cares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
  291. data/third_party/cares/cares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
  292. data/third_party/cares/cares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
  293. data/third_party/cares/cares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
  294. data/third_party/cares/cares/src/lib/record/ares_dns_mapping.c +982 -0
  295. data/third_party/cares/cares/src/lib/record/ares_dns_multistring.c +307 -0
  296. data/third_party/cares/cares/src/lib/record/ares_dns_multistring.h +72 -0
  297. data/third_party/cares/cares/src/lib/record/ares_dns_name.c +673 -0
  298. data/third_party/cares/cares/src/lib/record/ares_dns_parse.c +1329 -0
  299. data/third_party/cares/cares/src/lib/record/ares_dns_private.h +273 -0
  300. data/third_party/cares/cares/src/lib/record/ares_dns_record.c +1661 -0
  301. data/third_party/cares/cares/src/lib/record/ares_dns_write.c +1229 -0
  302. data/third_party/cares/cares/src/lib/str/ares_buf.c +1498 -0
  303. data/third_party/cares/cares/src/lib/str/ares_str.c +508 -0
  304. data/third_party/cares/cares/src/lib/str/ares_strsplit.c +90 -0
  305. data/third_party/cares/cares/src/lib/str/ares_strsplit.h +51 -0
  306. data/third_party/cares/cares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
  307. data/third_party/cares/cares/src/lib/util/ares_iface_ips.c +628 -0
  308. data/third_party/cares/cares/src/lib/util/ares_iface_ips.h +139 -0
  309. data/third_party/cares/cares/src/lib/util/ares_math.c +158 -0
  310. data/third_party/cares/cares/src/lib/util/ares_math.h +45 -0
  311. data/third_party/cares/cares/src/lib/util/ares_rand.c +389 -0
  312. data/third_party/cares/cares/src/lib/util/ares_rand.h +36 -0
  313. data/third_party/cares/cares/src/lib/util/ares_threads.c +614 -0
  314. data/third_party/cares/cares/src/lib/util/ares_threads.h +60 -0
  315. data/third_party/cares/cares/src/lib/util/ares_time.h +48 -0
  316. data/third_party/cares/cares/src/lib/util/ares_timeval.c +95 -0
  317. data/third_party/cares/cares/src/lib/util/ares_uri.c +1626 -0
  318. data/third_party/cares/cares/src/lib/util/ares_uri.h +252 -0
  319. data/third_party/cares/cares/src/lib/windows_port.c +16 -9
  320. metadata +121 -49
  321. data/src/core/util/ring_buffer.h +0 -122
  322. data/third_party/cares/cares/include/ares_rules.h +0 -125
  323. data/third_party/cares/cares/src/lib/ares__addrinfo2hostent.c +0 -266
  324. data/third_party/cares/cares/src/lib/ares__addrinfo_localhost.c +0 -240
  325. data/third_party/cares/cares/src/lib/ares__close_sockets.c +0 -61
  326. data/third_party/cares/cares/src/lib/ares__get_hostent.c +0 -260
  327. data/third_party/cares/cares/src/lib/ares__parse_into_addrinfo.c +0 -229
  328. data/third_party/cares/cares/src/lib/ares__read_line.c +0 -73
  329. data/third_party/cares/cares/src/lib/ares__readaddrinfo.c +0 -258
  330. data/third_party/cares/cares/src/lib/ares__sortaddrinfo.c +0 -507
  331. data/third_party/cares/cares/src/lib/ares__timeval.c +0 -111
  332. data/third_party/cares/cares/src/lib/ares_create_query.c +0 -197
  333. data/third_party/cares/cares/src/lib/ares_expand_name.c +0 -311
  334. data/third_party/cares/cares/src/lib/ares_expand_string.c +0 -67
  335. data/third_party/cares/cares/src/lib/ares_fds.c +0 -59
  336. data/third_party/cares/cares/src/lib/ares_getsock.c +0 -66
  337. data/third_party/cares/cares/src/lib/ares_iphlpapi.h +0 -221
  338. data/third_party/cares/cares/src/lib/ares_llist.c +0 -63
  339. data/third_party/cares/cares/src/lib/ares_llist.h +0 -39
  340. data/third_party/cares/cares/src/lib/ares_mkquery.c +0 -24
  341. data/third_party/cares/cares/src/lib/ares_nowarn.c +0 -260
  342. data/third_party/cares/cares/src/lib/ares_nowarn.h +0 -61
  343. data/third_party/cares/cares/src/lib/ares_parse_a_reply.c +0 -90
  344. data/third_party/cares/cares/src/lib/ares_parse_aaaa_reply.c +0 -92
  345. data/third_party/cares/cares/src/lib/ares_parse_caa_reply.c +0 -199
  346. data/third_party/cares/cares/src/lib/ares_parse_mx_reply.c +0 -164
  347. data/third_party/cares/cares/src/lib/ares_parse_naptr_reply.c +0 -183
  348. data/third_party/cares/cares/src/lib/ares_parse_ns_reply.c +0 -177
  349. data/third_party/cares/cares/src/lib/ares_parse_ptr_reply.c +0 -228
  350. data/third_party/cares/cares/src/lib/ares_parse_soa_reply.c +0 -179
  351. data/third_party/cares/cares/src/lib/ares_parse_srv_reply.c +0 -168
  352. data/third_party/cares/cares/src/lib/ares_parse_txt_reply.c +0 -214
  353. data/third_party/cares/cares/src/lib/ares_parse_uri_reply.c +0 -184
  354. data/third_party/cares/cares/src/lib/ares_platform.c +0 -11042
  355. data/third_party/cares/cares/src/lib/ares_platform.h +0 -43
  356. data/third_party/cares/cares/src/lib/ares_rand.c +0 -279
  357. data/third_party/cares/cares/src/lib/ares_strcasecmp.c +0 -66
  358. data/third_party/cares/cares/src/lib/ares_strcasecmp.h +0 -30
  359. data/third_party/cares/cares/src/lib/ares_strdup.c +0 -42
  360. data/third_party/cares/cares/src/lib/ares_strdup.h +0 -24
  361. data/third_party/cares/cares/src/lib/ares_strsplit.c +0 -94
  362. data/third_party/cares/cares/src/lib/ares_strsplit.h +0 -42
  363. data/third_party/cares/cares/src/lib/ares_writev.c +0 -79
  364. data/third_party/cares/cares/src/lib/ares_writev.h +0 -36
  365. data/third_party/cares/cares/src/lib/bitncmp.c +0 -59
  366. data/third_party/cares/cares/src/lib/bitncmp.h +0 -26
  367. data/third_party/cares/cares/src/lib/setup_once.h +0 -554
  368. data/third_party/cares/cares/src/tools/ares_getopt.h +0 -53
@@ -71,6 +71,7 @@
71
71
  #include "src/core/tsi/transport_security_interface.h"
72
72
  #include "src/core/util/crash.h"
73
73
  #include "src/core/util/env.h"
74
+ #include "src/core/util/match.h"
74
75
  #include "src/core/util/sync.h"
75
76
  #include "src/core/util/useful.h"
76
77
 
@@ -118,6 +119,7 @@ struct tsi_ssl_client_handshaker_factory {
118
119
  size_t alpn_protocol_list_length;
119
120
  grpc_core::RefCountedPtr<tsi::SslSessionLRUCache> session_cache;
120
121
  grpc_core::RefCountedPtr<TlsSessionKeyLogger> key_logger;
122
+ std::shared_ptr<RootCertInfo> root_cert_info;
121
123
  };
122
124
 
123
125
  struct tsi_ssl_server_handshaker_factory {
@@ -131,6 +133,7 @@ struct tsi_ssl_server_handshaker_factory {
131
133
  unsigned char* alpn_protocol_list;
132
134
  size_t alpn_protocol_list_length;
133
135
  grpc_core::RefCountedPtr<TlsSessionKeyLogger> key_logger;
136
+ std::shared_ptr<RootCertInfo> root_cert_info;
134
137
  };
135
138
 
136
139
  struct tsi_ssl_handshaker {
@@ -250,6 +253,7 @@ int ServerHandshakerFactoryAlpnCallback(SSL* /*ssl*/, const unsigned char** out,
250
253
  static gpr_once g_init_openssl_once = GPR_ONCE_INIT;
251
254
  static int g_ssl_ctx_ex_factory_index = -1;
252
255
  static int g_ssl_ctx_ex_crl_provider_index = -1;
256
+ static int g_ssl_ctx_ex_spiffe_bundle_map_index = -1;
253
257
  static const unsigned char kSslSessionIdContext[] = {'g', 'r', 'p', 'c'};
254
258
  static int g_ssl_ex_verified_root_cert_index = -1;
255
259
  #if !defined(OPENSSL_IS_BORINGSSL) && !defined(OPENSSL_NO_ENGINE)
@@ -340,6 +344,10 @@ static void init_openssl(void) {
340
344
  SSL_CTX_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr);
341
345
  CHECK_NE(g_ssl_ctx_ex_crl_provider_index, -1);
342
346
 
347
+ g_ssl_ctx_ex_spiffe_bundle_map_index =
348
+ SSL_CTX_get_ex_new_index(0, nullptr, nullptr, nullptr, nullptr);
349
+ CHECK_NE(g_ssl_ctx_ex_spiffe_bundle_map_index, -1);
350
+
343
351
  g_ssl_ex_verified_root_cert_index = SSL_get_ex_new_index(
344
352
  0, nullptr, nullptr, nullptr, verified_root_cert_free);
345
353
  CHECK_NE(g_ssl_ex_verified_root_cert_index, -1);
@@ -1231,6 +1239,113 @@ static int CheckChainRevocation(
1231
1239
  return 1;
1232
1240
  }
1233
1241
 
1242
+ static grpc_core::SpiffeBundleMap* GetSpiffeBundleMap(X509_STORE_CTX* ctx) {
1243
+ CHECK(ctx != nullptr);
1244
+ ERR_clear_error();
1245
+ int ssl_index = SSL_get_ex_data_X509_STORE_CTX_idx();
1246
+ if (ssl_index < 0) {
1247
+ char err_str[256];
1248
+ ERR_error_string_n(ERR_get_error(), err_str, sizeof(err_str));
1249
+ GRPC_TRACE_LOG(tsi, INFO)
1250
+ << "error getting the SSL index from the X509_STORE_CTX while getting "
1251
+ "the SPIFFE Bundle Map: "
1252
+ << err_str;
1253
+ return nullptr;
1254
+ }
1255
+ SSL* ssl = static_cast<SSL*>(X509_STORE_CTX_get_ex_data(ctx, ssl_index));
1256
+ if (ssl == nullptr) {
1257
+ GRPC_TRACE_LOG(tsi, INFO)
1258
+ << "error while fetching SPIFFE Bundle Map. SSL object is null";
1259
+ return nullptr;
1260
+ }
1261
+ SSL_CTX* ssl_ctx = SSL_get_SSL_CTX(ssl);
1262
+ return static_cast<grpc_core::SpiffeBundleMap*>(
1263
+ SSL_CTX_get_ex_data(ssl_ctx, g_ssl_ctx_ex_spiffe_bundle_map_index));
1264
+ }
1265
+
1266
+ static absl::StatusOr<std::string> GetSpiffeUriFromCert(X509* cert) {
1267
+ CHECK(cert != nullptr);
1268
+ GENERAL_NAMES* subject_alt_names = static_cast<GENERAL_NAMES*>(
1269
+ X509_get_ext_d2i(cert, NID_subject_alt_name, nullptr, nullptr));
1270
+ int uri_count = 0;
1271
+ absl::StatusOr<std::string> spiffe_uri = absl::InvalidArgumentError(
1272
+ "spiffe: no SPIFFE ID found in leaf certificate.");
1273
+ if (subject_alt_names != nullptr) {
1274
+ size_t subject_alt_name_count = sk_GENERAL_NAME_num(subject_alt_names);
1275
+ for (size_t i = 0; i < subject_alt_name_count; i++) {
1276
+ GENERAL_NAME* subject_alt_name =
1277
+ sk_GENERAL_NAME_value(subject_alt_names, TSI_SIZE_AS_SIZE(i));
1278
+ if (subject_alt_name == nullptr) {
1279
+ continue;
1280
+ }
1281
+ if (subject_alt_name->type == GEN_URI) {
1282
+ uri_count++;
1283
+ if (uri_count > 1) {
1284
+ sk_GENERAL_NAME_pop_free(subject_alt_names, GENERAL_NAME_free);
1285
+ return absl::InvalidArgumentError(
1286
+ "spiffe: more than one SAN URI found while doing SPIFFE "
1287
+ "validation. Must "
1288
+ "have exactly one URI SAN that is the SPIFFE ID.");
1289
+ }
1290
+ spiffe_uri = grpc_core::ParseUriString(subject_alt_name);
1291
+ }
1292
+ }
1293
+ }
1294
+ sk_GENERAL_NAME_pop_free(subject_alt_names, GENERAL_NAME_free);
1295
+ GRPC_RETURN_IF_ERROR(spiffe_uri.status());
1296
+ if (spiffe_uri->empty()) {
1297
+ return absl::InvalidArgumentError(
1298
+ "spiffe: no URI SAN found in leaf certificate");
1299
+ }
1300
+ return spiffe_uri;
1301
+ }
1302
+
1303
+ static absl::StatusOr<std::string> SpiffeTrustDomainFromCert(X509* cert) {
1304
+ CHECK(cert != nullptr);
1305
+ auto subject_name = GetSpiffeUriFromCert(cert);
1306
+ GRPC_RETURN_IF_ERROR(subject_name.status());
1307
+ auto spiffe_id = grpc_core::SpiffeId::FromString(*subject_name);
1308
+ GRPC_RETURN_IF_ERROR(spiffe_id.status());
1309
+ return std::string(spiffe_id->trust_domain());
1310
+ }
1311
+
1312
+ // Fills ctx's trusted roots with the roots in the SPIFFE Bundle Map that
1313
+ // are associated with the to-be-verified leaf certificate's trust domain.
1314
+ // For more detail see
1315
+ // https://github.com/grpc/proposal/blob/master/A87-mtls-spiffe-support.md
1316
+ absl::Status ConfigureSpiffeRoots(
1317
+ X509_STORE_CTX* ctx, grpc_core::SpiffeBundleMap* spiffe_bundle_map) {
1318
+ CHECK(ctx != nullptr);
1319
+ if (spiffe_bundle_map == nullptr) {
1320
+ return absl::InvalidArgumentError(
1321
+ "cannot configure spiffe roots with a nullptr spiffe_bundle_map.");
1322
+ }
1323
+ #if OPENSSL_VERSION_NUMBER >= 0x10100000L
1324
+ X509* leaf_cert = X509_STORE_CTX_get0_cert(ctx);
1325
+ #else
1326
+ X509* leaf_cert = ctx->cert;
1327
+ #endif
1328
+ if (leaf_cert == nullptr) {
1329
+ return absl::InvalidArgumentError(
1330
+ "A SPIFFE bundle map was configured but the leaf cert is null");
1331
+ }
1332
+ absl::StatusOr<std::string> trust_domain =
1333
+ SpiffeTrustDomainFromCert(leaf_cert);
1334
+ GRPC_RETURN_IF_ERROR(trust_domain.status());
1335
+ auto root_stack = spiffe_bundle_map->GetRootStack(*trust_domain);
1336
+ GRPC_RETURN_IF_ERROR(root_stack.status());
1337
+ if (*root_stack == nullptr) {
1338
+ return absl::InvalidArgumentError(
1339
+ "spiffe: root stack in the SPIFFE Bundle Map is nullptr.");
1340
+ }
1341
+ #if OPENSSL_VERSION_NUMBER >= 0x10100000L
1342
+ X509_STORE_CTX_set0_trusted_stack(ctx, *root_stack);
1343
+ #else
1344
+ X509_STORE_CTX_trusted_stack(ctx, *root_stack);
1345
+ #endif
1346
+ return absl::OkStatus();
1347
+ }
1348
+
1234
1349
  // The custom verification function to set in OpenSSL using
1235
1350
  // X509_set_cert_verify_callback. This calls the standard OpenSSL procedure
1236
1351
  // (X509_verify_cert), then also extracts the root certificate in the built
@@ -1238,12 +1353,24 @@ static int CheckChainRevocation(
1238
1353
  // returns 1 on success, indicating a trusted chain to a root of trust was
1239
1354
  // found, 0 if a trusted chain could not be built.
1240
1355
  static int CustomVerificationFunction(X509_STORE_CTX* ctx, void* arg) {
1356
+ CHECK(ctx != nullptr);
1357
+ grpc_core::SpiffeBundleMap* spiffe_bundle_map = GetSpiffeBundleMap(ctx);
1358
+ if (spiffe_bundle_map != nullptr) {
1359
+ // If a SPIFFE Bundle Map is configured, we'll use
1360
+ // X509_STORE_CTX_set0_trusted_stack to then configure these as the roots
1361
+ // for verification.
1362
+ absl::Status status = ConfigureSpiffeRoots(ctx, spiffe_bundle_map);
1363
+ if (!status.ok()) {
1364
+ VLOG(2) << "Failed to configure SPIFFE roots: " << status;
1365
+ return -1;
1366
+ }
1367
+ }
1241
1368
  int ret = X509_verify_cert(ctx);
1242
1369
  if (ret <= 0) {
1243
1370
  VLOG(2) << "Failed to verify cert chain.";
1244
1371
  // Verification failed. We shouldn't expect to have a verified chain, so
1245
- // there is no need to attempt to extract the root cert from it, check for
1246
- // revocation, or check anything else.
1372
+ // there is no need to attempt to extract the root cert from it, check
1373
+ // for revocation, or check anything else.
1247
1374
  return ret;
1248
1375
  }
1249
1376
  grpc_core::experimental::CrlProvider* provider = GetCrlProvider(ctx);
@@ -1257,9 +1384,9 @@ static int CustomVerificationFunction(X509_STORE_CTX* ctx, void* arg) {
1257
1384
  return RootCertExtractCallback(ctx, arg);
1258
1385
  }
1259
1386
 
1260
- // Sets the min and max TLS version of |ssl_context| to |min_tls_version| and
1261
- // |max_tls_version|, respectively. Calling this method is a no-op when using
1262
- // OpenSSL versions < 1.1.
1387
+ // Sets the min and max TLS version of |ssl_context| to |min_tls_version|
1388
+ // and |max_tls_version|, respectively. Calling this method is a no-op when
1389
+ // using OpenSSL versions < 1.1.
1263
1390
  static tsi_result tsi_set_min_and_max_tls_versions(
1264
1391
  SSL_CTX* ssl_context, tsi_tls_version min_tls_version,
1265
1392
  tsi_tls_version max_tls_version) {
@@ -2155,9 +2282,7 @@ static void tsi_ssl_client_handshaker_factory_destroy(
2155
2282
  reinterpret_cast<tsi_ssl_client_handshaker_factory*>(factory);
2156
2283
  if (self->ssl_context != nullptr) SSL_CTX_free(self->ssl_context);
2157
2284
  if (self->alpn_protocol_list != nullptr) gpr_free(self->alpn_protocol_list);
2158
- self->session_cache.reset();
2159
- self->key_logger.reset();
2160
- gpr_free(self);
2285
+ delete self;
2161
2286
  }
2162
2287
 
2163
2288
  static int client_handshaker_factory_npn_callback(
@@ -2206,8 +2331,7 @@ static void tsi_ssl_server_handshaker_factory_destroy(
2206
2331
  gpr_free(self->ssl_context_x509_subject_names);
2207
2332
  }
2208
2333
  if (self->alpn_protocol_list != nullptr) gpr_free(self->alpn_protocol_list);
2209
- self->key_logger.reset();
2210
- gpr_free(self);
2334
+ delete self;
2211
2335
  }
2212
2336
 
2213
2337
  static int does_entry_match_name(absl::string_view entry,
@@ -2330,7 +2454,9 @@ tsi_result tsi_create_ssl_client_handshaker_factory(
2330
2454
  tsi_ssl_client_handshaker_factory** factory) {
2331
2455
  tsi_ssl_client_handshaker_options options;
2332
2456
  options.pem_key_cert_pair = pem_key_cert_pair;
2333
- options.pem_root_certs = pem_root_certs;
2457
+ if (pem_root_certs != nullptr) {
2458
+ options.root_cert_info = std::make_shared<RootCertInfo>(pem_root_certs);
2459
+ }
2334
2460
  options.cipher_suites = cipher_suites;
2335
2461
  options.alpn_protocols = alpn_protocols;
2336
2462
  options.num_alpn_protocols = num_alpn_protocols;
@@ -2349,7 +2475,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options(
2349
2475
 
2350
2476
  if (factory == nullptr) return TSI_INVALID_ARGUMENT;
2351
2477
  *factory = nullptr;
2352
- if (options->pem_root_certs == nullptr && options->root_store == nullptr &&
2478
+ if (options->root_store == nullptr && options->root_cert_info == nullptr &&
2353
2479
  !options->skip_server_certificate_verification) {
2354
2480
  return TSI_INVALID_ARGUMENT;
2355
2481
  }
@@ -2372,8 +2498,7 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options(
2372
2498
  ssl_context, options->min_tls_version, options->max_tls_version);
2373
2499
  if (result != TSI_OK) return result;
2374
2500
 
2375
- impl = static_cast<tsi_ssl_client_handshaker_factory*>(
2376
- gpr_zalloc(sizeof(*impl)));
2501
+ impl = new tsi_ssl_client_handshaker_factory();
2377
2502
  tsi_ssl_handshaker_factory_init(&impl->base);
2378
2503
  impl->base.vtable = &client_handshaker_factory_vtable;
2379
2504
  impl->ssl_context = ssl_context;
@@ -2386,6 +2511,9 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options(
2386
2511
  server_handshaker_factory_new_session_callback);
2387
2512
  SSL_CTX_set_session_cache_mode(ssl_context, SSL_SESS_CACHE_CLIENT);
2388
2513
  }
2514
+ if (options->root_cert_info != nullptr) {
2515
+ impl->root_cert_info = options->root_cert_info;
2516
+ }
2389
2517
 
2390
2518
  #if OPENSSL_VERSION_NUMBER >= 0x10101000 && !defined(LIBRESSL_VERSION_NUMBER)
2391
2519
  if (options->key_logger != nullptr) {
@@ -2417,10 +2545,23 @@ tsi_result tsi_create_ssl_client_handshaker_factory_with_options(
2417
2545
  #endif
2418
2546
  if (OPENSSL_VERSION_NUMBER < 0x10100000 ||
2419
2547
  (options->root_store == nullptr &&
2420
- options->pem_root_certs != nullptr)) {
2421
- result = ssl_ctx_load_verification_certs(
2422
- ssl_context, options->pem_root_certs, strlen(options->pem_root_certs),
2423
- nullptr);
2548
+ options->root_cert_info != nullptr)) {
2549
+ Match(
2550
+ *options->root_cert_info,
2551
+ [&](const std::string& pem_root_certs) {
2552
+ result = ssl_ctx_load_verification_certs(
2553
+ ssl_context, pem_root_certs.c_str(), pem_root_certs.size(),
2554
+ nullptr);
2555
+ },
2556
+ [&](const grpc_core::SpiffeBundleMap& spiffe_bundle_map) {
2557
+ X509_STORE* cert_store = SSL_CTX_get_cert_store(ssl_context);
2558
+ X509_STORE_set_flags(cert_store, X509_V_FLAG_PARTIAL_CHAIN |
2559
+ X509_V_FLAG_TRUSTED_FIRST);
2560
+ const void* p = &spiffe_bundle_map;
2561
+ void* map = const_cast<void*>(p);
2562
+ SSL_CTX_set_ex_data(ssl_context,
2563
+ g_ssl_ctx_ex_spiffe_bundle_map_index, map);
2564
+ });
2424
2565
  X509_STORE* cert_store = SSL_CTX_get_cert_store(ssl_context);
2425
2566
  #if OPENSSL_VERSION_NUMBER >= 0x10100000
2426
2567
  X509_VERIFY_PARAM* param = X509_STORE_get0_param(cert_store);
@@ -2518,7 +2659,10 @@ tsi_result tsi_create_ssl_server_handshaker_factory_ex(
2518
2659
  tsi_ssl_server_handshaker_options options;
2519
2660
  options.pem_key_cert_pairs = pem_key_cert_pairs;
2520
2661
  options.num_key_cert_pairs = num_key_cert_pairs;
2521
- options.pem_client_root_certs = pem_client_root_certs;
2662
+ if (pem_client_root_certs != nullptr) {
2663
+ options.root_cert_info =
2664
+ std::make_shared<RootCertInfo>(pem_client_root_certs);
2665
+ }
2522
2666
  options.client_certificate_request = client_certificate_request;
2523
2667
  options.cipher_suites = cipher_suites;
2524
2668
  options.alpn_protocols = alpn_protocols;
@@ -2543,8 +2687,7 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options(
2543
2687
  return TSI_INVALID_ARGUMENT;
2544
2688
  }
2545
2689
 
2546
- impl = static_cast<tsi_ssl_server_handshaker_factory*>(
2547
- gpr_zalloc(sizeof(*impl)));
2690
+ impl = new tsi_ssl_server_handshaker_factory();
2548
2691
  tsi_ssl_handshaker_factory_init(&impl->base);
2549
2692
  impl->base.vtable = &server_handshaker_factory_vtable;
2550
2693
 
@@ -2558,6 +2701,9 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options(
2558
2701
  return TSI_OUT_OF_RESOURCES;
2559
2702
  }
2560
2703
  impl->ssl_context_count = options->num_key_cert_pairs;
2704
+ if (options->root_cert_info != nullptr) {
2705
+ impl->root_cert_info = options->root_cert_info;
2706
+ }
2561
2707
 
2562
2708
  if (options->num_alpn_protocols > 0) {
2563
2709
  result = BuildAlpnProtocolNameList(
@@ -2622,20 +2768,34 @@ tsi_result tsi_create_ssl_server_handshaker_factory_with_options(
2622
2768
  break;
2623
2769
  }
2624
2770
  }
2625
-
2626
- if (options->pem_client_root_certs != nullptr) {
2627
- STACK_OF(X509_NAME)* root_names = nullptr;
2628
- result = ssl_ctx_load_verification_certs(
2629
- impl->ssl_contexts[i], options->pem_client_root_certs,
2630
- strlen(options->pem_client_root_certs),
2631
- options->send_client_ca_list ? &root_names : nullptr);
2771
+ if (options->root_cert_info != nullptr) {
2772
+ Match(
2773
+ *options->root_cert_info,
2774
+ [&](const std::string& pem_root_certs) {
2775
+ STACK_OF(X509_NAME)* root_names = nullptr;
2776
+ result = ssl_ctx_load_verification_certs(
2777
+ impl->ssl_contexts[i], pem_root_certs.c_str(),
2778
+ pem_root_certs.size(), nullptr);
2779
+ if (result != TSI_OK) {
2780
+ LOG(ERROR) << "Invalid verification certs.";
2781
+ }
2782
+ if (options->send_client_ca_list) {
2783
+ SSL_CTX_set_client_CA_list(impl->ssl_contexts[i], root_names);
2784
+ }
2785
+ },
2786
+ [&](const grpc_core::SpiffeBundleMap& spiffe_bundle_map) {
2787
+ X509_STORE* cert_store =
2788
+ SSL_CTX_get_cert_store(impl->ssl_contexts[i]);
2789
+ X509_STORE_set_flags(cert_store, X509_V_FLAG_PARTIAL_CHAIN |
2790
+ X509_V_FLAG_TRUSTED_FIRST);
2791
+ const void* p = &spiffe_bundle_map;
2792
+ void* map = const_cast<void*>(p);
2793
+ SSL_CTX_set_ex_data(impl->ssl_contexts[i],
2794
+ g_ssl_ctx_ex_spiffe_bundle_map_index, map);
2795
+ });
2632
2796
  if (result != TSI_OK) {
2633
- LOG(ERROR) << "Invalid verification certs.";
2634
2797
  break;
2635
2798
  }
2636
- if (options->send_client_ca_list) {
2637
- SSL_CTX_set_client_CA_list(impl->ssl_contexts[i], root_names);
2638
- }
2639
2799
  }
2640
2800
  switch (options->client_certificate_request) {
2641
2801
  case TSI_DONT_REQUEST_CLIENT_CERTIFICATE:
@@ -2770,6 +2930,16 @@ int tsi_ssl_peer_matches_name(const tsi_peer* peer, absl::string_view name) {
2770
2930
  return 0; // Not found.
2771
2931
  }
2772
2932
 
2933
+ bool IsRootCertInfoEmpty(const RootCertInfo* root_cert_info) {
2934
+ if (root_cert_info == nullptr) return true;
2935
+ return Match(
2936
+ *root_cert_info,
2937
+ [&](const std::string& pem_root_certs) { return pem_root_certs.empty(); },
2938
+ [&](const grpc_core::SpiffeBundleMap& spiffe_bundle_map) {
2939
+ return spiffe_bundle_map.size() == 0;
2940
+ });
2941
+ }
2942
+
2773
2943
  // --- Testing support. ---
2774
2944
  const tsi_ssl_handshaker_factory_vtable* tsi_ssl_handshaker_factory_swap_vtable(
2775
2945
  tsi_ssl_handshaker_factory* factory,
@@ -27,6 +27,7 @@
27
27
  #include <memory>
28
28
 
29
29
  #include "absl/strings/string_view.h"
30
+ #include "src/core/credentials/transport/tls/spiffe_utils.h"
30
31
  #include "src/core/tsi/ssl/key_logging/ssl_key_logging.h"
31
32
  #include "src/core/tsi/ssl_transport_security_utils.h"
32
33
  #include "src/core/tsi/transport_security_interface.h"
@@ -50,6 +51,8 @@
50
51
  #define TSI_X509_VERIFIED_ROOT_CERT_SUBECT_PEER_PROPERTY \
51
52
  "x509_verified_root_cert_subject"
52
53
 
54
+ using RootCertInfo = std::variant<std::string, grpc_core::SpiffeBundleMap>;
55
+
53
56
  // --- tsi_ssl_root_certs_store object ---
54
57
 
55
58
  // This object stores SSL root certificates. It can be shared by multiple SSL
@@ -142,9 +145,6 @@ struct tsi_ssl_client_handshaker_options {
142
145
  // key and certificate chain. This parameter can be NULL if the client does
143
146
  // not have such a key/cert pair.
144
147
  const tsi_ssl_pem_key_cert_pair* pem_key_cert_pair;
145
- // pem_roots_cert is the NULL-terminated string containing the PEM encoding of
146
- // the client root certificates.
147
- const char* pem_root_certs;
148
148
  // root_store is a pointer to the ssl_root_certs_store object. If root_store
149
149
  // is not nullptr and SSL implementation permits, root_store will be used as
150
150
  // root certificates. Otherwise, pem_roots_cert will be used to load server
@@ -190,9 +190,14 @@ struct tsi_ssl_client_handshaker_options {
190
190
  // options as a shared_ptr.
191
191
  std::shared_ptr<grpc_core::experimental::CrlProvider> crl_provider;
192
192
 
193
+ // root_cert_info is either the string containing the PEM encoding of the
194
+ // client root certificates or a SPIFFE bundle map.
195
+ std::shared_ptr<RootCertInfo> root_cert_info;
196
+
197
+ // TODO(gtcooke94) this ctor is not needed
198
+ // https://github.com/grpc/grpc/pull/39708/files#r2143735662
193
199
  tsi_ssl_client_handshaker_options()
194
200
  : pem_key_cert_pair(nullptr),
195
- pem_root_certs(nullptr),
196
201
  root_store(nullptr),
197
202
  cipher_suites(nullptr),
198
203
  alpn_protocols(nullptr),
@@ -303,13 +308,9 @@ struct tsi_ssl_server_handshaker_options {
303
308
  // num_key_cert_pairs is the number of items in the pem_key_cert_pairs
304
309
  // array.
305
310
  size_t num_key_cert_pairs;
306
- // pem_root_certs is the NULL-terminated string containing the PEM encoding
307
- // of the server root certificates. This parameter may be NULL if the server
308
- // does not want the client to be authenticated with SSL.
309
- const char* pem_client_root_certs;
310
311
  // client_certificate_request, if set to non-zero will force the client to
311
312
  // authenticate with an SSL cert. Note that this option is ignored if
312
- // pem_client_root_certs is NULL or pem_client_roots_certs_size is 0.
313
+ // root_cert_info is NULL
313
314
  tsi_client_certificate_request_type client_certificate_request;
314
315
  // cipher_suites contains an optional list of the ciphers that the server
315
316
  // supports. The format of this string is described in:
@@ -360,10 +361,16 @@ struct tsi_ssl_server_handshaker_options {
360
361
  // will be unusable.
361
362
  bool send_client_ca_list;
362
363
 
364
+ // root_cert_info is either the string containing the PEM encoding of the
365
+ // server root certificates or a SPIFFE bundle map. This parameter may be NULL
366
+ // if the server does not want the client to be authenticated with SSL.
367
+ std::shared_ptr<RootCertInfo> root_cert_info;
368
+
369
+ // TODO(gtcooke94) this ctor is not needed
370
+ // https://github.com/grpc/grpc/pull/39708/files#r2143735662
363
371
  tsi_ssl_server_handshaker_options()
364
372
  : pem_key_cert_pairs(nullptr),
365
373
  num_key_cert_pairs(0),
366
- pem_client_root_certs(nullptr),
367
374
  client_certificate_request(TSI_DONT_REQUEST_CLIENT_CERTIFICATE),
368
375
  cipher_suites(nullptr),
369
376
  alpn_protocols(nullptr),
@@ -441,4 +448,6 @@ tsi_result tsi_ssl_extract_x509_subject_names_from_pem_cert(
441
448
  tsi_result tsi_ssl_get_cert_chain_contents(STACK_OF(X509) * peer_chain,
442
449
  tsi_peer_property* property);
443
450
 
451
+ bool IsRootCertInfoEmpty(const RootCertInfo* root_cert_info);
452
+
444
453
  #endif // GRPC_SRC_CORE_TSI_SSL_TRANSPORT_SECURITY_H
@@ -428,4 +428,25 @@ absl::StatusOr<EVP_PKEY*> ParsePemPrivateKey(
428
428
  return pkey;
429
429
  }
430
430
 
431
+ absl::StatusOr<std::string> ParseUriString(GENERAL_NAME* subject_alt_name) {
432
+ if (subject_alt_name == nullptr || subject_alt_name->type != GEN_URI) {
433
+ return absl::InvalidArgumentError("Could not parse ASN1 string to UTF8");
434
+ }
435
+ // This shouldn't be a possible if statement to enter because if the type is
436
+ // GEN_URI it then by definition should have a d.uniformResourceIdentifier.
437
+ // But we can still keep it for safety.
438
+ if (subject_alt_name->d.uniformResourceIdentifier == nullptr) {
439
+ return absl::InvalidArgumentError("Could not parse ASN1 string to UTF8");
440
+ }
441
+ unsigned char* name = nullptr;
442
+ int name_size =
443
+ ASN1_STRING_to_UTF8(&name, subject_alt_name->d.uniformResourceIdentifier);
444
+ if (name_size < 0 || name == nullptr) {
445
+ OPENSSL_free(name);
446
+ return absl::InvalidArgumentError("Could not parse ASN1 string to UTF8");
447
+ }
448
+ std::string ret(reinterpret_cast<char const*>(name), name_size);
449
+ OPENSSL_free(name);
450
+ return ret;
451
+ }
431
452
  } // namespace grpc_core
@@ -23,6 +23,7 @@
23
23
  #include <grpc/support/port_platform.h>
24
24
  #include <openssl/evp.h>
25
25
  #include <openssl/x509.h>
26
+ #include <openssl/x509v3.h>
26
27
 
27
28
  #include "absl/status/status.h"
28
29
  #include "absl/status/statusor.h"
@@ -177,6 +178,9 @@ absl::StatusOr<std::vector<X509*>> ParsePemCertificateChain(
177
178
  // Returns an EVP_PKEY instance parsed from the non-empty PEM private key block
178
179
  // in private_key_pem. Caller takes ownership of the EVP_PKEY pointer.
179
180
  absl::StatusOr<EVP_PKEY*> ParsePemPrivateKey(absl::string_view private_key_pem);
181
+
182
+ // Safely parses a URI from OpenSSL's GENERAL_NAME to a string representation.
183
+ absl::StatusOr<std::string> ParseUriString(GENERAL_NAME* subject_alt_name);
180
184
  } // namespace grpc_core
181
185
 
182
186
  #endif // GRPC_SRC_CORE_TSI_SSL_TRANSPORT_SECURITY_UTILS_H
@@ -77,7 +77,9 @@ class grpc_httpcli_ssl_channel_security_connector final
77
77
  tsi_result InitHandshakerFactory(const char* pem_root_certs,
78
78
  const tsi_ssl_root_certs_store* root_store) {
79
79
  tsi_ssl_client_handshaker_options options;
80
- options.pem_root_certs = pem_root_certs;
80
+ if (pem_root_certs != nullptr) {
81
+ options.root_cert_info = std::make_shared<RootCertInfo>(pem_root_certs);
82
+ }
81
83
  options.root_store = root_store;
82
84
  return tsi_create_ssl_client_handshaker_factory_with_options(
83
85
  &options, &handshaker_factory_);