grpc 1.61.3 → 1.62.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (723) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +218 -196
  3. data/include/grpc/event_engine/event_engine.h +5 -43
  4. data/include/grpc/event_engine/extensible.h +68 -0
  5. data/include/grpc/impl/slice_type.h +1 -1
  6. data/include/grpc/support/port_platform.h +12 -20
  7. data/src/core/{ext/filters/client_channel → client_channel}/backend_metric.cc +1 -1
  8. data/src/core/{ext/filters/client_channel → client_channel}/backend_metric.h +4 -4
  9. data/src/core/{ext/filters/client_channel → client_channel}/backup_poller.cc +1 -1
  10. data/src/core/{ext/filters/client_channel → client_channel}/backup_poller.h +3 -3
  11. data/src/core/{ext/filters/client_channel → client_channel}/channel_connectivity.cc +11 -11
  12. data/src/core/{ext/filters/client_channel → client_channel}/client_channel_channelz.cc +1 -1
  13. data/src/core/{ext/filters/client_channel → client_channel}/client_channel_channelz.h +3 -3
  14. data/src/core/{ext/filters/client_channel → client_channel}/client_channel_factory.cc +1 -1
  15. data/src/core/{ext/filters/client_channel → client_channel}/client_channel_factory.h +4 -4
  16. data/src/core/{ext/filters/client_channel/client_channel.cc → client_channel/client_channel_filter.cc} +247 -231
  17. data/src/core/{ext/filters/client_channel/client_channel.h → client_channel/client_channel_filter.h} +42 -42
  18. data/src/core/{ext/filters/client_channel → client_channel}/client_channel_internal.h +6 -6
  19. data/src/core/{ext/filters/client_channel → client_channel}/client_channel_plugin.cc +5 -5
  20. data/src/core/{ext/filters/client_channel → client_channel}/client_channel_service_config.cc +2 -2
  21. data/src/core/{ext/filters/client_channel → client_channel}/client_channel_service_config.h +5 -5
  22. data/src/core/{ext/filters/client_channel → client_channel}/config_selector.cc +1 -1
  23. data/src/core/{ext/filters/client_channel → client_channel}/config_selector.h +5 -5
  24. data/src/core/{ext/filters/client_channel → client_channel}/connector.h +3 -3
  25. data/src/core/{ext/filters/client_channel → client_channel}/dynamic_filters.cc +1 -1
  26. data/src/core/{ext/filters/client_channel → client_channel}/dynamic_filters.h +3 -3
  27. data/src/core/{ext/filters/client_channel → client_channel}/global_subchannel_pool.cc +2 -2
  28. data/src/core/{ext/filters/client_channel → client_channel}/global_subchannel_pool.h +4 -4
  29. data/src/core/{ext/filters/client_channel → client_channel}/http_proxy_mapper.cc +1 -1
  30. data/src/core/{ext/filters/client_channel → client_channel}/http_proxy_mapper.h +3 -3
  31. data/src/core/{ext/filters/client_channel → client_channel}/local_subchannel_pool.cc +2 -2
  32. data/src/core/{ext/filters/client_channel → client_channel}/local_subchannel_pool.h +4 -4
  33. data/src/core/{ext/filters/client_channel → client_channel}/retry_filter.cc +8 -8
  34. data/src/core/{ext/filters/client_channel → client_channel}/retry_filter.h +8 -8
  35. data/src/core/{ext/filters/client_channel → client_channel}/retry_filter_legacy_call_data.cc +12 -9
  36. data/src/core/{ext/filters/client_channel → client_channel}/retry_filter_legacy_call_data.h +11 -10
  37. data/src/core/{ext/filters/client_channel → client_channel}/retry_service_config.cc +1 -1
  38. data/src/core/{ext/filters/client_channel → client_channel}/retry_service_config.h +4 -4
  39. data/src/core/{ext/filters/client_channel → client_channel}/retry_throttle.cc +1 -1
  40. data/src/core/{ext/filters/client_channel → client_channel}/retry_throttle.h +3 -3
  41. data/src/core/{ext/filters/client_channel → client_channel}/service_config_channel_arg_filter.cc +4 -4
  42. data/src/core/{ext/filters/client_channel → client_channel}/subchannel.cc +2 -2
  43. data/src/core/{ext/filters/client_channel → client_channel}/subchannel.h +6 -6
  44. data/src/core/{ext/filters/client_channel → client_channel}/subchannel_interface_internal.h +5 -5
  45. data/src/core/{ext/filters/client_channel → client_channel}/subchannel_pool_interface.cc +1 -1
  46. data/src/core/{ext/filters/client_channel → client_channel}/subchannel_pool_interface.h +3 -3
  47. data/src/core/{ext/filters/client_channel → client_channel}/subchannel_stream_client.cc +1 -1
  48. data/src/core/{ext/filters/client_channel → client_channel}/subchannel_stream_client.h +4 -4
  49. data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +1 -1
  50. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +1 -1
  51. data/src/core/ext/filters/fault_injection/fault_injection_service_config_parser.h +1 -1
  52. data/src/core/ext/filters/http/message_compress/legacy_compression_filter.cc +2 -2
  53. data/src/core/ext/filters/http/server/http_server_filter.cc +1 -1
  54. data/src/core/ext/filters/message_size/message_size_filter.cc +3 -3
  55. data/src/core/ext/filters/message_size/message_size_filter.h +1 -1
  56. data/src/core/ext/filters/rbac/rbac_filter.cc +1 -1
  57. data/src/core/ext/filters/rbac/rbac_service_config_parser.h +1 -1
  58. data/src/core/ext/filters/server_config_selector/server_config_selector.h +2 -2
  59. data/src/core/ext/filters/server_config_selector/server_config_selector_filter.cc +2 -2
  60. data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +2 -2
  61. data/src/core/ext/filters/stateful_session/stateful_session_filter.h +1 -1
  62. data/src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h +1 -1
  63. data/src/core/ext/transport/chttp2/alpn/alpn.cc +4 -1
  64. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +5 -5
  65. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
  66. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +1 -0
  67. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +5 -0
  68. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +27 -36
  69. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +3 -3
  70. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +3 -1
  71. data/src/core/ext/transport/inproc/inproc_transport.cc +20 -13
  72. data/src/core/ext/transport/inproc/inproc_transport.h +8 -0
  73. data/src/core/ext/upb-gen/envoy/config/bootstrap/v3/bootstrap.upb.h +351 -164
  74. data/src/core/ext/upb-gen/envoy/config/bootstrap/v3/bootstrap.upb_minitable.c +89 -50
  75. data/src/core/ext/upb-gen/envoy/config/bootstrap/v3/bootstrap.upb_minitable.h +2 -0
  76. data/src/core/ext/upb-gen/envoy/config/cluster/v3/cluster.upb.h +47 -3
  77. data/src/core/ext/upb-gen/envoy/config/cluster/v3/cluster.upb_minitable.c +15 -7
  78. data/src/core/ext/upb-gen/envoy/config/cluster/v3/filter.upb.h +32 -3
  79. data/src/core/ext/upb-gen/envoy/config/cluster/v3/filter.upb_minitable.c +8 -5
  80. data/src/core/ext/upb-gen/envoy/config/cluster/v3/outlier_detection.upb.h +28 -0
  81. data/src/core/ext/upb-gen/envoy/config/cluster/v3/outlier_detection.upb_minitable.c +6 -4
  82. data/src/core/ext/upb-gen/envoy/config/common/matcher/v3/matcher.upb.h +0 -1
  83. data/src/core/ext/upb-gen/envoy/config/common/matcher/v3/matcher.upb_minitable.c +0 -1
  84. data/src/core/ext/upb-gen/envoy/config/core/v3/address.upb.h +29 -0
  85. data/src/core/ext/upb-gen/envoy/config/core/v3/address.upb_minitable.c +7 -4
  86. data/src/core/ext/upb-gen/envoy/config/core/v3/base.upb.h +17 -1
  87. data/src/core/ext/upb-gen/envoy/config/core/v3/base.upb_minitable.c +4 -3
  88. data/src/core/ext/upb-gen/envoy/config/core/v3/http_service.upb.h +166 -0
  89. data/src/core/ext/upb-gen/envoy/config/core/v3/http_service.upb_minitable.c +55 -0
  90. data/src/core/ext/upb-gen/envoy/config/core/v3/http_service.upb_minitable.h +30 -0
  91. data/src/core/ext/upb-gen/envoy/config/core/v3/protocol.upb.h +30 -0
  92. data/src/core/ext/upb-gen/envoy/config/core/v3/protocol.upb_minitable.c +7 -5
  93. data/src/core/ext/upb-gen/envoy/config/core/v3/substitution_format_string.upb.h +99 -19
  94. data/src/core/ext/upb-gen/envoy/config/core/v3/substitution_format_string.upb_minitable.c +29 -12
  95. data/src/core/ext/upb-gen/envoy/config/core/v3/substitution_format_string.upb_minitable.h +1 -0
  96. data/src/core/ext/upb-gen/envoy/config/endpoint/v3/endpoint.upb.h +15 -0
  97. data/src/core/ext/upb-gen/envoy/config/endpoint/v3/endpoint.upb_minitable.c +4 -3
  98. data/src/core/ext/upb-gen/envoy/config/route/v3/route.upb.h +31 -3
  99. data/src/core/ext/upb-gen/envoy/config/route/v3/route.upb_minitable.c +22 -4
  100. data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb.h +91 -3
  101. data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb_minitable.c +11 -8
  102. data/src/core/ext/upb-gen/envoy/config/tap/v3/common.upb.h +30 -0
  103. data/src/core/ext/upb-gen/envoy/config/tap/v3/common.upb_minitable.c +7 -4
  104. data/src/core/ext/upb-gen/envoy/config/trace/v3/dynamic_ot.upb.h +1 -0
  105. data/src/core/ext/upb-gen/envoy/config/trace/v3/dynamic_ot.upb_minitable.c +1 -0
  106. data/src/core/ext/upb-gen/envoy/config/trace/v3/opentelemetry.upb.h +125 -3
  107. data/src/core/ext/upb-gen/envoy/config/trace/v3/opentelemetry.upb_minitable.c +17 -4
  108. data/src/core/ext/upb-gen/envoy/data/accesslog/v3/accesslog.upb.h +19 -1
  109. data/src/core/ext/upb-gen/envoy/data/accesslog/v3/accesslog.upb_minitable.c +4 -3
  110. data/src/core/ext/upb-gen/envoy/extensions/filters/http/router/v3/router.upb.h +1 -0
  111. data/src/core/ext/upb-gen/envoy/extensions/filters/http/router/v3/router.upb_minitable.c +1 -0
  112. data/src/core/ext/upb-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upb.h +15 -0
  113. data/src/core/ext/upb-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upb_minitable.c +5 -2
  114. data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +42 -0
  115. data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb_minitable.c +11 -8
  116. data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/common.upb.h +23 -8
  117. data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/common.upb_minitable.c +9 -4
  118. data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +58 -16
  119. data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/tls.upb_minitable.c +14 -11
  120. data/src/core/ext/upb-gen/envoy/service/status/v3/csds.upb.h +15 -0
  121. data/src/core/ext/upb-gen/envoy/service/status/v3/csds.upb_minitable.c +7 -2
  122. data/src/core/ext/upb-gen/envoy/type/matcher/v3/value.upb.h +129 -0
  123. data/src/core/ext/upb-gen/envoy/type/matcher/v3/value.upb_minitable.c +27 -6
  124. data/src/core/ext/upb-gen/envoy/type/matcher/v3/value.upb_minitable.h +1 -0
  125. data/src/core/ext/upb-gen/xds/type/matcher/v3/cel.upb.h +15 -0
  126. data/src/core/ext/upb-gen/xds/type/matcher/v3/cel.upb_minitable.c +5 -2
  127. data/src/core/ext/upbdefs-gen/envoy/config/accesslog/v3/accesslog.upbdefs.c +60 -60
  128. data/src/core/ext/upbdefs-gen/envoy/config/bootstrap/v3/bootstrap.upbdefs.c +278 -256
  129. data/src/core/ext/upbdefs-gen/envoy/config/bootstrap/v3/bootstrap.upbdefs.h +10 -0
  130. data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/cluster.upbdefs.c +483 -475
  131. data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/filter.upbdefs.c +27 -20
  132. data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/outlier_detection.upbdefs.c +17 -12
  133. data/src/core/ext/upbdefs-gen/envoy/config/common/matcher/v3/matcher.upbdefs.c +157 -161
  134. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/address.upbdefs.c +105 -97
  135. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/base.upbdefs.c +106 -102
  136. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/http_service.upbdefs.c +52 -0
  137. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/http_service.upbdefs.h +35 -0
  138. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/http_uri.upbdefs.c +14 -13
  139. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/protocol.upbdefs.c +228 -224
  140. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/substitution_format_string.upbdefs.c +32 -26
  141. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/substitution_format_string.upbdefs.h +5 -0
  142. data/src/core/ext/upbdefs-gen/envoy/config/endpoint/v3/endpoint.upbdefs.c +31 -28
  143. data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route.upbdefs.c +22 -19
  144. data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route_components.upbdefs.c +818 -813
  145. data/src/core/ext/upbdefs-gen/envoy/config/tap/v3/common.upbdefs.c +158 -151
  146. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/dynamic_ot.upbdefs.c +27 -23
  147. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/opencensus.upbdefs.c +59 -53
  148. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/opentelemetry.upbdefs.c +40 -18
  149. data/src/core/ext/upbdefs-gen/envoy/data/accesslog/v3/accesslog.upbdefs.c +106 -103
  150. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/router/v3/router.upbdefs.c +16 -12
  151. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upbdefs.c +22 -21
  152. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +265 -261
  153. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +127 -125
  154. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +188 -182
  155. data/src/core/ext/upbdefs-gen/envoy/service/status/v3/csds.upbdefs.c +57 -56
  156. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/value.upbdefs.c +27 -20
  157. data/src/core/ext/upbdefs-gen/envoy/type/matcher/v3/value.upbdefs.h +5 -0
  158. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/cel.upbdefs.c +10 -8
  159. data/src/core/ext/xds/xds_api.cc +63 -150
  160. data/src/core/ext/xds/xds_api.h +2 -7
  161. data/src/core/ext/xds/xds_bootstrap.h +3 -4
  162. data/src/core/ext/xds/xds_bootstrap_grpc.cc +4 -15
  163. data/src/core/ext/xds/xds_bootstrap_grpc.h +2 -1
  164. data/src/core/ext/xds/xds_client.cc +111 -59
  165. data/src/core/ext/xds/xds_client.h +20 -15
  166. data/src/core/ext/xds/xds_client_grpc.cc +53 -15
  167. data/src/core/ext/xds/xds_client_grpc.h +4 -1
  168. data/src/core/ext/xds/xds_client_stats.cc +11 -11
  169. data/src/core/ext/xds/xds_client_stats.h +8 -13
  170. data/src/core/ext/xds/xds_cluster.cc +1 -1
  171. data/src/core/ext/xds/xds_cluster.h +1 -1
  172. data/src/core/ext/xds/xds_endpoint.h +1 -1
  173. data/src/core/ext/xds/xds_health_status.h +1 -1
  174. data/src/core/ext/xds/xds_lb_policy_registry.cc +1 -1
  175. data/src/core/ext/xds/xds_route_config.cc +1 -1
  176. data/src/core/ext/xds/xds_server_config_fetcher.cc +2 -2
  177. data/src/core/ext/xds/xds_transport_grpc.cc +5 -5
  178. data/src/core/lib/channel/channel_args.h +15 -1
  179. data/src/core/lib/channel/connected_channel.cc +13 -12
  180. data/src/core/lib/channel/promise_based_filter.cc +4 -4
  181. data/src/core/lib/channel/promise_based_filter.h +1 -2
  182. data/src/core/lib/config/core_configuration.h +3 -3
  183. data/src/core/lib/event_engine/ares_resolver.cc +106 -59
  184. data/src/core/lib/event_engine/extensions/can_track_errors.h +40 -0
  185. data/src/core/lib/event_engine/extensions/supports_fd.h +160 -0
  186. data/src/core/lib/event_engine/forkable.cc +7 -5
  187. data/src/core/lib/event_engine/posix.h +11 -122
  188. data/src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.h +1 -5
  189. data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +31 -7
  190. data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +1 -0
  191. data/src/core/lib/event_engine/posix_engine/posix_engine.cc +3 -4
  192. data/src/core/lib/event_engine/posix_engine/posix_engine.h +2 -3
  193. data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +14 -6
  194. data/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +10 -0
  195. data/src/core/lib/event_engine/query_extensions.h +85 -0
  196. data/src/core/lib/event_engine/shim.cc +3 -17
  197. data/src/core/lib/event_engine/shim.h +0 -2
  198. data/src/core/lib/event_engine/thread_pool/thread_count.cc +28 -7
  199. data/src/core/lib/event_engine/thread_pool/thread_count.h +6 -1
  200. data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +109 -5
  201. data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.h +9 -0
  202. data/src/core/lib/event_engine/utils.cc +2 -1
  203. data/src/core/lib/event_engine/windows/grpc_polled_fd_windows.cc +1 -0
  204. data/src/core/lib/experiments/config.cc +10 -2
  205. data/src/core/lib/experiments/config.h +6 -0
  206. data/src/core/lib/experiments/experiments.cc +57 -18
  207. data/src/core/lib/experiments/experiments.h +16 -8
  208. data/src/core/lib/gpr/posix/sync.cc +2 -2
  209. data/src/core/lib/gpr/posix/time.cc +0 -5
  210. data/src/core/lib/gpr/windows/sync.cc +2 -2
  211. data/src/core/lib/gprpp/debug_location.h +2 -0
  212. data/src/core/lib/gprpp/down_cast.h +49 -0
  213. data/src/core/lib/gprpp/linux/env.cc +1 -19
  214. data/src/core/lib/gprpp/load_file.cc +2 -1
  215. data/src/core/lib/gprpp/load_file.h +2 -1
  216. data/src/core/lib/gprpp/posix/thd.cc +27 -2
  217. data/src/core/lib/gprpp/thd.h +8 -0
  218. data/src/core/lib/gprpp/time.h +4 -3
  219. data/src/core/lib/gprpp/windows/thd.cc +10 -1
  220. data/src/core/lib/iomgr/combiner.cc +1 -1
  221. data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +20 -14
  222. data/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc +2 -2
  223. data/src/core/lib/iomgr/grpc_if_nametoindex_unsupported.cc +2 -2
  224. data/src/core/lib/iomgr/tcp_server_posix.cc +65 -50
  225. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +12 -0
  226. data/src/core/lib/json/json_writer.cc +1 -1
  227. data/src/core/lib/promise/activity.h +8 -2
  228. data/src/core/lib/promise/context.h +45 -7
  229. data/src/core/lib/promise/for_each.h +6 -9
  230. data/src/core/lib/promise/interceptor_list.h +13 -5
  231. data/src/core/lib/promise/latch.h +3 -3
  232. data/src/core/lib/promise/party.cc +12 -0
  233. data/src/core/lib/promise/party.h +37 -6
  234. data/src/core/lib/promise/pipe.h +2 -7
  235. data/src/core/lib/promise/sleep.cc +1 -1
  236. data/src/core/lib/promise/status_flag.h +32 -2
  237. data/src/core/lib/resource_quota/memory_quota.cc +4 -4
  238. data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +5 -11
  239. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +11 -10
  240. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +9 -7
  241. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +1 -1
  242. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +16 -24
  243. data/src/core/lib/security/credentials/xds/xds_credentials.cc +1 -1
  244. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +1 -1
  245. data/src/core/lib/security/security_connector/load_system_roots_supported.cc +3 -7
  246. data/src/core/lib/security/security_connector/local/local_security_connector.cc +1 -1
  247. data/src/core/lib/security/security_connector/ssl_utils.cc +26 -17
  248. data/src/core/lib/security/transport/legacy_server_auth_filter.cc +2 -2
  249. data/src/core/lib/security/transport/security_handshaker.cc +0 -8
  250. data/src/core/lib/security/transport/security_handshaker.h +0 -6
  251. data/src/core/lib/security/transport/server_auth_filter.cc +2 -2
  252. data/src/core/lib/slice/slice_buffer.h +3 -1
  253. data/src/core/lib/surface/call.cc +162 -76
  254. data/src/core/lib/surface/call_trace.cc +9 -9
  255. data/src/core/lib/surface/channel.cc +15 -24
  256. data/src/core/lib/surface/channel.h +4 -20
  257. data/src/core/lib/surface/channel_init.cc +81 -7
  258. data/src/core/lib/surface/channel_init.h +104 -6
  259. data/src/core/lib/surface/init.cc +1 -1
  260. data/src/core/lib/surface/server.cc +4 -7
  261. data/src/core/lib/surface/version.cc +2 -2
  262. data/src/core/lib/surface/wait_for_cq_end_op.cc +75 -0
  263. data/src/core/lib/surface/wait_for_cq_end_op.h +4 -26
  264. data/src/core/lib/transport/batch_builder.cc +2 -3
  265. data/src/core/lib/transport/batch_builder.h +1 -1
  266. data/src/core/lib/transport/call_factory.cc +41 -0
  267. data/src/core/lib/transport/call_factory.h +56 -0
  268. data/src/core/lib/transport/call_filters.cc +371 -0
  269. data/src/core/lib/transport/call_filters.h +1500 -0
  270. data/src/core/lib/transport/call_size_estimator.cc +41 -0
  271. data/src/core/lib/transport/call_size_estimator.h +52 -0
  272. data/src/core/lib/transport/call_spine.cc +107 -0
  273. data/src/core/lib/transport/call_spine.h +429 -0
  274. data/src/core/lib/transport/handshaker.cc +0 -8
  275. data/src/core/lib/transport/handshaker.h +0 -7
  276. data/src/core/lib/transport/message.cc +45 -0
  277. data/src/core/lib/transport/message.h +61 -0
  278. data/src/core/lib/transport/metadata.cc +37 -0
  279. data/src/core/lib/transport/metadata.h +78 -0
  280. data/src/core/lib/transport/metadata_batch.cc +4 -2
  281. data/src/core/lib/transport/metadata_batch.h +2 -2
  282. data/src/core/lib/transport/transport.cc +0 -105
  283. data/src/core/lib/transport/transport.h +3 -452
  284. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/address_filtering.cc +1 -1
  285. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/address_filtering.h +4 -4
  286. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/backend_metric_data.h +3 -3
  287. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/child_policy_handler.cc +4 -4
  288. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/child_policy_handler.h +4 -4
  289. data/src/core/{lib/load_balancing → load_balancing}/delegating_helper.h +5 -5
  290. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/endpoint_list.cc +6 -6
  291. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/endpoint_list.h +6 -6
  292. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/grpclb/client_load_reporting_filter.cc +2 -2
  293. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/grpclb/client_load_reporting_filter.h +3 -3
  294. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/grpclb/grpclb.cc +19 -19
  295. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/grpclb/grpclb.h +3 -3
  296. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/grpclb/grpclb_balancer_addresses.cc +1 -1
  297. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/grpclb/grpclb_balancer_addresses.h +4 -4
  298. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/grpclb/grpclb_client_stats.cc +1 -1
  299. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/grpclb/grpclb_client_stats.h +3 -3
  300. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/grpclb/load_balancer_api.cc +1 -1
  301. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/grpclb/load_balancer_api.h +4 -4
  302. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/health_check_client.cc +6 -6
  303. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/health_check_client.h +4 -4
  304. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/health_check_client_internal.h +7 -7
  305. data/src/core/{lib/load_balancing → load_balancing}/lb_policy.cc +1 -1
  306. data/src/core/{lib/load_balancing → load_balancing}/lb_policy.h +6 -6
  307. data/src/core/{lib/load_balancing → load_balancing}/lb_policy_factory.h +4 -4
  308. data/src/core/{lib/load_balancing → load_balancing}/lb_policy_registry.cc +2 -2
  309. data/src/core/{lib/load_balancing → load_balancing}/lb_policy_registry.h +5 -5
  310. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/oob_backend_metric.cc +6 -6
  311. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/oob_backend_metric.h +5 -5
  312. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/oob_backend_metric_internal.h +8 -8
  313. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/outlier_detection/outlier_detection.cc +10 -10
  314. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/outlier_detection/outlier_detection.h +3 -3
  315. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/pick_first/pick_first.cc +6 -6
  316. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/pick_first/pick_first.h +4 -4
  317. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/priority/priority.cc +8 -8
  318. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/ring_hash/ring_hash.cc +8 -8
  319. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/ring_hash/ring_hash.h +4 -4
  320. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/rls/rls.cc +13 -13
  321. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/round_robin/round_robin.cc +7 -7
  322. data/src/core/{lib/load_balancing → load_balancing}/subchannel_interface.h +3 -3
  323. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/subchannel_list.h +8 -8
  324. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/weighted_round_robin/static_stride_scheduler.cc +1 -1
  325. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/weighted_round_robin/static_stride_scheduler.h +3 -3
  326. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/weighted_round_robin/weighted_round_robin.cc +10 -10
  327. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/weighted_target/weighted_target.cc +7 -7
  328. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/xds/cds.cc +26 -23
  329. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/xds/xds_channel_args.h +4 -4
  330. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/xds/xds_cluster_impl.cc +11 -11
  331. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/xds/xds_cluster_manager.cc +8 -8
  332. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/xds/xds_override_host.cc +10 -10
  333. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/xds/xds_override_host.h +4 -4
  334. data/src/core/{ext/filters/client_channel/lb_policy → load_balancing}/xds/xds_wrr_locality.cc +6 -6
  335. data/src/core/{ext/filters/client_channel/resolver → resolver}/binder/binder_resolver.cc +3 -3
  336. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/c_ares/dns_resolver_ares.cc +9 -9
  337. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/c_ares/dns_resolver_ares.h +3 -3
  338. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/c_ares/grpc_ares_ev_driver.h +4 -4
  339. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/c_ares/grpc_ares_ev_driver_posix.cc +2 -2
  340. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/c_ares/grpc_ares_ev_driver_windows.cc +2 -2
  341. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/c_ares/grpc_ares_wrapper.cc +2 -2
  342. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/c_ares/grpc_ares_wrapper.h +4 -4
  343. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/c_ares/grpc_ares_wrapper_posix.cc +1 -1
  344. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -2
  345. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/dns_resolver_plugin.cc +7 -5
  346. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/dns_resolver_plugin.h +3 -3
  347. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/event_engine/event_engine_client_channel_resolver.cc +9 -9
  348. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/event_engine/event_engine_client_channel_resolver.h +5 -5
  349. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/event_engine/service_config_helper.cc +1 -1
  350. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/event_engine/service_config_helper.h +3 -3
  351. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/native/dns_resolver.cc +4 -4
  352. data/src/core/{ext/filters/client_channel/resolver → resolver}/dns/native/dns_resolver.h +3 -3
  353. data/src/core/{lib/resolver → resolver}/endpoint_addresses.cc +1 -1
  354. data/src/core/{lib/resolver → resolver}/endpoint_addresses.h +3 -3
  355. data/src/core/{ext/filters/client_channel/resolver → resolver}/fake/fake_resolver.cc +2 -2
  356. data/src/core/{ext/filters/client_channel/resolver → resolver}/fake/fake_resolver.h +4 -4
  357. data/src/core/{ext/filters/client_channel/resolver → resolver}/google_c2p/google_c2p_resolver.cc +3 -3
  358. data/src/core/{ext/filters/client_channel/resolver → resolver}/polling_resolver.cc +3 -3
  359. data/src/core/{ext/filters/client_channel/resolver → resolver}/polling_resolver.h +5 -5
  360. data/src/core/{lib/resolver → resolver}/resolver.cc +1 -1
  361. data/src/core/{lib/resolver → resolver}/resolver.h +6 -6
  362. data/src/core/{lib/resolver → resolver}/resolver_factory.h +4 -4
  363. data/src/core/{lib/resolver → resolver}/resolver_registry.cc +1 -1
  364. data/src/core/{lib/resolver → resolver}/resolver_registry.h +5 -5
  365. data/src/core/{lib/resolver → resolver}/server_address.h +4 -4
  366. data/src/core/{ext/filters/client_channel/resolver → resolver}/sockaddr/sockaddr_resolver.cc +3 -3
  367. data/src/core/{ext/filters/client_channel/resolver → resolver}/xds/xds_dependency_manager.cc +4 -4
  368. data/src/core/{ext/filters/client_channel/resolver → resolver}/xds/xds_dependency_manager.h +4 -4
  369. data/src/core/{ext/filters/client_channel/resolver → resolver}/xds/xds_resolver.cc +11 -11
  370. data/src/core/{ext/filters/client_channel/resolver → resolver}/xds/xds_resolver_attributes.h +4 -4
  371. data/src/core/{ext/filters/client_channel/resolver → resolver}/xds/xds_resolver_trace.cc +1 -1
  372. data/src/core/{ext/filters/client_channel/resolver → resolver}/xds/xds_resolver_trace.h +3 -3
  373. data/src/core/{lib/service_config → service_config}/service_config.h +4 -4
  374. data/src/core/{lib/service_config → service_config}/service_config_call_data.h +5 -5
  375. data/src/core/{lib/service_config → service_config}/service_config_impl.cc +2 -2
  376. data/src/core/{lib/service_config → service_config}/service_config_impl.h +5 -5
  377. data/src/core/{lib/service_config → service_config}/service_config_parser.cc +1 -1
  378. data/src/core/{lib/service_config → service_config}/service_config_parser.h +3 -3
  379. data/src/core/tsi/fake_transport_security.cc +1 -1
  380. data/src/ruby/ext/grpc/extconf.rb +0 -1
  381. data/src/ruby/ext/grpc/rb_channel.c +11 -5
  382. data/src/ruby/ext/grpc/rb_event_thread.c +9 -3
  383. data/src/ruby/lib/grpc/version.rb +1 -1
  384. data/third_party/abseil-cpp/absl/algorithm/algorithm.h +8 -103
  385. data/third_party/abseil-cpp/absl/algorithm/container.h +57 -71
  386. data/third_party/abseil-cpp/absl/base/attributes.h +51 -12
  387. data/third_party/abseil-cpp/absl/base/call_once.h +15 -9
  388. data/third_party/abseil-cpp/absl/base/casts.h +1 -1
  389. data/third_party/abseil-cpp/absl/base/config.h +91 -24
  390. data/third_party/abseil-cpp/absl/base/internal/endian.h +13 -12
  391. data/third_party/abseil-cpp/absl/base/internal/identity.h +4 -2
  392. data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +19 -18
  393. data/third_party/abseil-cpp/absl/base/internal/low_level_alloc.cc +1 -1
  394. data/third_party/abseil-cpp/absl/base/internal/nullability_impl.h +106 -0
  395. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +9 -11
  396. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +2 -0
  397. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +17 -4
  398. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +20 -0
  399. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +10 -4
  400. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +13 -6
  401. data/third_party/abseil-cpp/absl/base/log_severity.cc +1 -0
  402. data/third_party/abseil-cpp/absl/base/log_severity.h +23 -10
  403. data/third_party/abseil-cpp/absl/base/no_destructor.h +217 -0
  404. data/third_party/abseil-cpp/absl/base/nullability.h +224 -0
  405. data/third_party/abseil-cpp/absl/base/optimization.h +1 -0
  406. data/third_party/abseil-cpp/absl/base/options.h +27 -1
  407. data/third_party/abseil-cpp/absl/base/prefetch.h +25 -14
  408. data/third_party/abseil-cpp/absl/base/thread_annotations.h +0 -2
  409. data/third_party/abseil-cpp/absl/container/flat_hash_map.h +3 -3
  410. data/third_party/abseil-cpp/absl/container/flat_hash_set.h +1 -1
  411. data/third_party/abseil-cpp/absl/container/internal/common_policy_traits.h +4 -2
  412. data/third_party/abseil-cpp/absl/container/internal/container_memory.h +13 -9
  413. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +2 -12
  414. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +12 -1
  415. data/third_party/abseil-cpp/absl/container/internal/layout.h +6 -21
  416. data/third_party/abseil-cpp/absl/container/internal/raw_hash_map.h +11 -2
  417. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +148 -31
  418. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +717 -278
  419. data/third_party/abseil-cpp/absl/crc/internal/cpu_detect.cc +26 -2
  420. data/third_party/abseil-cpp/absl/crc/internal/cpu_detect.h +6 -0
  421. data/third_party/abseil-cpp/absl/crc/internal/crc32_x86_arm_combined_simd.h +34 -5
  422. data/third_party/abseil-cpp/absl/crc/internal/crc_memcpy.h +6 -3
  423. data/third_party/abseil-cpp/absl/crc/internal/crc_memcpy_fallback.cc +4 -2
  424. data/third_party/abseil-cpp/absl/crc/internal/{crc_memcpy_x86_64.cc → crc_memcpy_x86_arm_combined.cc} +65 -47
  425. data/third_party/abseil-cpp/absl/crc/internal/crc_x86_arm_combined.cc +10 -2
  426. data/third_party/abseil-cpp/absl/debugging/internal/address_is_readable.cc +4 -2
  427. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +24 -0
  428. data/third_party/abseil-cpp/absl/debugging/internal/demangle.h +35 -33
  429. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +41 -17
  430. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +108 -44
  431. data/third_party/abseil-cpp/absl/flags/declare.h +0 -5
  432. data/third_party/abseil-cpp/absl/flags/flag.h +1 -10
  433. data/third_party/abseil-cpp/absl/flags/internal/flag.h +0 -5
  434. data/third_party/abseil-cpp/absl/flags/marshalling.cc +10 -1
  435. data/third_party/abseil-cpp/absl/flags/reflection.cc +2 -1
  436. data/third_party/abseil-cpp/absl/functional/function_ref.h +8 -0
  437. data/third_party/abseil-cpp/absl/functional/internal/any_invocable.h +2 -2
  438. data/third_party/abseil-cpp/absl/hash/internal/hash.h +49 -2
  439. data/third_party/abseil-cpp/absl/numeric/bits.h +37 -18
  440. data/third_party/abseil-cpp/absl/random/distributions.h +1 -1
  441. data/third_party/abseil-cpp/absl/status/internal/status_internal.cc +248 -0
  442. data/third_party/abseil-cpp/absl/status/internal/status_internal.h +55 -14
  443. data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +53 -2
  444. data/third_party/abseil-cpp/absl/status/status.cc +36 -238
  445. data/third_party/abseil-cpp/absl/status/status.h +95 -53
  446. data/third_party/abseil-cpp/absl/status/status_payload_printer.cc +1 -3
  447. data/third_party/abseil-cpp/absl/status/status_payload_printer.h +3 -2
  448. data/third_party/abseil-cpp/absl/status/statusor.cc +5 -2
  449. data/third_party/abseil-cpp/absl/status/statusor.h +43 -3
  450. data/third_party/abseil-cpp/absl/strings/ascii.cc +84 -12
  451. data/third_party/abseil-cpp/absl/strings/ascii.h +8 -6
  452. data/third_party/abseil-cpp/absl/strings/charconv.cc +19 -12
  453. data/third_party/abseil-cpp/absl/strings/charconv.h +6 -3
  454. data/third_party/abseil-cpp/absl/strings/charset.h +164 -0
  455. data/third_party/abseil-cpp/absl/strings/cord.cc +266 -69
  456. data/third_party/abseil-cpp/absl/strings/cord.h +138 -92
  457. data/third_party/abseil-cpp/absl/strings/cord_analysis.cc +19 -33
  458. data/third_party/abseil-cpp/absl/strings/cord_analysis.h +4 -3
  459. data/third_party/abseil-cpp/absl/strings/escaping.cc +5 -4
  460. data/third_party/abseil-cpp/absl/strings/has_absl_stringify.h +63 -0
  461. data/third_party/abseil-cpp/absl/strings/has_ostream_operator.h +42 -0
  462. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.cc +0 -6
  463. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +19 -45
  464. data/third_party/abseil-cpp/absl/strings/internal/cordz_info.cc +23 -28
  465. data/third_party/abseil-cpp/absl/strings/internal/has_absl_stringify.h +15 -26
  466. data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +12 -4
  467. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +145 -8
  468. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +72 -24
  469. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.cc +17 -1
  470. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +7 -4
  471. data/third_party/abseil-cpp/absl/strings/internal/str_format/constexpr_parser.h +8 -3
  472. data/third_party/abseil-cpp/absl/strings/internal/str_format/extension.h +10 -4
  473. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.h +5 -4
  474. data/third_party/abseil-cpp/absl/strings/match.cc +3 -0
  475. data/third_party/abseil-cpp/absl/strings/numbers.cc +396 -153
  476. data/third_party/abseil-cpp/absl/strings/numbers.h +193 -35
  477. data/third_party/abseil-cpp/absl/strings/str_cat.cc +151 -21
  478. data/third_party/abseil-cpp/absl/strings/str_cat.h +127 -25
  479. data/third_party/abseil-cpp/absl/strings/str_format.h +30 -20
  480. data/third_party/abseil-cpp/absl/strings/str_join.h +16 -16
  481. data/third_party/abseil-cpp/absl/strings/str_replace.cc +12 -3
  482. data/third_party/abseil-cpp/absl/strings/str_replace.h +8 -5
  483. data/third_party/abseil-cpp/absl/strings/str_split.cc +8 -6
  484. data/third_party/abseil-cpp/absl/strings/str_split.h +18 -0
  485. data/third_party/abseil-cpp/absl/strings/string_view.cc +26 -5
  486. data/third_party/abseil-cpp/absl/strings/string_view.h +91 -26
  487. data/third_party/abseil-cpp/absl/strings/strip.h +5 -2
  488. data/third_party/abseil-cpp/absl/strings/substitute.cc +12 -4
  489. data/third_party/abseil-cpp/absl/strings/substitute.h +103 -91
  490. data/third_party/abseil-cpp/absl/synchronization/internal/pthread_waiter.h +2 -2
  491. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +2 -0
  492. data/third_party/abseil-cpp/absl/synchronization/internal/win32_waiter.h +4 -2
  493. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +296 -332
  494. data/third_party/abseil-cpp/absl/synchronization/mutex.h +89 -34
  495. data/third_party/abseil-cpp/absl/time/civil_time.h +26 -0
  496. data/third_party/abseil-cpp/absl/time/clock.h +5 -1
  497. data/third_party/abseil-cpp/absl/time/duration.cc +3 -3
  498. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +2 -2
  499. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_format.cc +1 -1
  500. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_info.cc +9 -14
  501. data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +0 -8
  502. data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +18 -0
  503. data/third_party/abseil-cpp/absl/types/bad_variant_access.cc +18 -0
  504. data/third_party/abseil-cpp/absl/types/internal/variant.h +3 -3
  505. data/third_party/abseil-cpp/absl/types/optional.h +3 -2
  506. data/third_party/abseil-cpp/absl/types/span.h +9 -4
  507. data/third_party/abseil-cpp/absl/utility/utility.h +11 -93
  508. data/third_party/boringssl-with-bazel/err_data.c +278 -276
  509. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_gentm.c +1 -1
  510. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_mbstr.c +9 -9
  511. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_strex.c +8 -21
  512. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_time.c +1 -1
  513. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_type.c +19 -1
  514. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_utctm.c +1 -1
  515. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +11 -3
  516. data/third_party/boringssl-with-bazel/src/crypto/asn1/internal.h +4 -1
  517. data/third_party/boringssl-with-bazel/src/crypto/asn1/posix_time.c +1 -1
  518. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_dec.c +3 -3
  519. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +1 -6
  520. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_new.c +4 -13
  521. data/third_party/boringssl-with-bazel/src/crypto/base64/base64.c +1 -6
  522. data/third_party/boringssl-with-bazel/src/crypto/bio/bio.c +27 -4
  523. data/third_party/boringssl-with-bazel/src/crypto/bio/connect.c +1 -4
  524. data/third_party/boringssl-with-bazel/src/crypto/bio/pair.c +1 -4
  525. data/third_party/boringssl-with-bazel/src/crypto/bn_extra/convert.c +8 -0
  526. data/third_party/boringssl-with-bazel/src/crypto/buf/buf.c +1 -11
  527. data/third_party/boringssl-with-bazel/src/crypto/bytestring/ber.c +7 -8
  528. data/third_party/boringssl-with-bazel/src/crypto/bytestring/cbb.c +42 -12
  529. data/third_party/boringssl-with-bazel/src/crypto/bytestring/internal.h +0 -22
  530. data/third_party/boringssl-with-bazel/src/crypto/bytestring/unicode.c +9 -9
  531. data/third_party/boringssl-with-bazel/src/crypto/chacha/chacha.c +34 -1
  532. data/third_party/boringssl-with-bazel/src/crypto/chacha/internal.h +49 -3
  533. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/e_aesgcmsiv.c +30 -42
  534. data/third_party/boringssl-with-bazel/src/crypto/conf/conf.c +87 -96
  535. data/third_party/boringssl-with-bazel/src/crypto/conf/internal.h +5 -1
  536. data/third_party/boringssl-with-bazel/src/crypto/cpu_intel.c +4 -2
  537. data/third_party/boringssl-with-bazel/src/crypto/crypto.c +11 -0
  538. data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519.c +4 -0
  539. data/third_party/boringssl-with-bazel/src/crypto/curve25519/spake25519.c +1 -2
  540. data/third_party/boringssl-with-bazel/src/crypto/des/des.c +105 -31
  541. data/third_party/boringssl-with-bazel/src/crypto/des/internal.h +10 -81
  542. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +2 -15
  543. data/third_party/boringssl-with-bazel/src/crypto/engine/engine.c +1 -9
  544. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +1 -5
  545. data/third_party/boringssl-with-bazel/src/crypto/evp/evp_ctx.c +2 -5
  546. data/third_party/boringssl-with-bazel/src/crypto/evp/p_ec.c +1 -4
  547. data/third_party/boringssl-with-bazel/src/crypto/evp/p_hkdf.c +1 -2
  548. data/third_party/boringssl-with-bazel/src/crypto/evp/p_rsa.c +1 -3
  549. data/third_party/boringssl-with-bazel/src/crypto/evp/scrypt.c +2 -2
  550. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/add.c +2 -8
  551. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/bn.c +1 -1
  552. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/bytes.c +26 -17
  553. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/ctx.c +1 -1
  554. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/exponentiation.c +4 -2
  555. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/gcd.c +26 -5
  556. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/generic.c +10 -41
  557. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +49 -2
  558. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/montgomery.c +26 -0
  559. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/montgomery_inv.c +27 -26
  560. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/mul.c +2 -6
  561. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/prime.c +1 -8
  562. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/random.c +8 -2
  563. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/cipher.c +11 -2
  564. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/e_aes.c +11 -24
  565. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/e_aesccm.c +43 -50
  566. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/dh.c +2 -6
  567. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +4 -0
  568. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.c +1 -2
  569. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.c +16 -9
  570. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p224-64.c +7 -6
  571. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/wnaf.c +2 -7
  572. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/fork_detect.c +51 -13
  573. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/fork_detect.h +17 -0
  574. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +5 -2
  575. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/blinding.c +1 -2
  576. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +1 -3
  577. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +6 -5
  578. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/fips.c +1 -2
  579. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/internal.h +153 -6
  580. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha1.c +87 -7
  581. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha256.c +39 -5
  582. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha512.c +32 -5
  583. data/third_party/boringssl-with-bazel/src/crypto/internal.h +254 -54
  584. data/third_party/boringssl-with-bazel/src/crypto/keccak/internal.h +70 -0
  585. data/third_party/boringssl-with-bazel/src/crypto/{kyber → keccak}/keccak.c +124 -49
  586. data/third_party/boringssl-with-bazel/src/crypto/kyber/internal.h +8 -39
  587. data/third_party/boringssl-with-bazel/src/crypto/kyber/kyber.c +39 -29
  588. data/third_party/boringssl-with-bazel/src/crypto/lhash/lhash.c +3 -6
  589. data/third_party/boringssl-with-bazel/src/crypto/mem.c +17 -33
  590. data/third_party/boringssl-with-bazel/src/crypto/obj/obj.c +36 -16
  591. data/third_party/boringssl-with-bazel/src/crypto/obj/obj_dat.h +0 -3
  592. data/third_party/boringssl-with-bazel/src/crypto/pem/pem_info.c +31 -0
  593. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7_x509.c +2 -4
  594. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8.c +3 -3
  595. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +9 -13
  596. data/third_party/boringssl-with-bazel/src/crypto/pool/pool.c +3 -6
  597. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/forkunsafe.c +4 -0
  598. data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/rsa_crypt.c +3 -1
  599. data/third_party/boringssl-with-bazel/src/crypto/spx/address.c +101 -0
  600. data/third_party/boringssl-with-bazel/src/crypto/spx/address.h +50 -0
  601. data/third_party/boringssl-with-bazel/src/crypto/spx/fors.c +133 -0
  602. data/third_party/boringssl-with-bazel/src/crypto/spx/fors.h +54 -0
  603. data/third_party/boringssl-with-bazel/src/crypto/spx/internal.h +79 -0
  604. data/third_party/boringssl-with-bazel/src/crypto/spx/merkle.c +150 -0
  605. data/third_party/boringssl-with-bazel/src/crypto/spx/merkle.h +61 -0
  606. data/third_party/boringssl-with-bazel/src/crypto/spx/params.h +71 -0
  607. data/third_party/boringssl-with-bazel/src/crypto/spx/spx.c +139 -0
  608. data/third_party/boringssl-with-bazel/src/crypto/spx/spx_util.c +53 -0
  609. data/third_party/boringssl-with-bazel/src/crypto/spx/spx_util.h +44 -0
  610. data/third_party/boringssl-with-bazel/src/crypto/spx/thash.c +136 -0
  611. data/third_party/boringssl-with-bazel/src/crypto/spx/thash.h +70 -0
  612. data/third_party/boringssl-with-bazel/src/crypto/spx/wots.c +135 -0
  613. data/third_party/boringssl-with-bazel/src/crypto/spx/wots.h +45 -0
  614. data/third_party/boringssl-with-bazel/src/crypto/stack/stack.c +4 -9
  615. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +10 -22
  616. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +3 -6
  617. data/third_party/boringssl-with-bazel/src/crypto/trust_token/voprf.c +12 -36
  618. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +1 -2
  619. data/third_party/boringssl-with-bazel/src/crypto/x509/asn1_gen.c +0 -2
  620. data/third_party/boringssl-with-bazel/src/crypto/x509/by_dir.c +14 -9
  621. data/third_party/boringssl-with-bazel/src/crypto/x509/by_file.c +23 -33
  622. data/third_party/boringssl-with-bazel/src/crypto/x509/internal.h +225 -51
  623. data/third_party/boringssl-with-bazel/src/crypto/x509/policy.c +2 -6
  624. data/third_party/boringssl-with-bazel/src/crypto/x509/rsa_pss.c +6 -2
  625. data/third_party/boringssl-with-bazel/src/crypto/x509/t_crl.c +1 -1
  626. data/third_party/boringssl-with-bazel/src/crypto/x509/t_req.c +1 -4
  627. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509.c +1 -3
  628. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_akey.c +1 -1
  629. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_akeya.c +3 -1
  630. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_alt.c +5 -6
  631. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_bcons.c +1 -1
  632. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_bitst.c +1 -1
  633. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_conf.c +0 -2
  634. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_cpols.c +1 -1
  635. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_crld.c +1 -2
  636. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_enum.c +1 -0
  637. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_extku.c +1 -1
  638. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_genn.c +12 -12
  639. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_ia5.c +1 -1
  640. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_info.c +4 -6
  641. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_int.c +1 -1
  642. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_lib.c +3 -2
  643. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_ncons.c +2 -2
  644. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_ocsp.c +1 -1
  645. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_pcons.c +1 -1
  646. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_pmaps.c +1 -1
  647. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_prn.c +3 -4
  648. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_purp.c +92 -335
  649. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_skey.c +1 -2
  650. data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/v3_utl.c +20 -18
  651. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_att.c +35 -32
  652. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +44 -59
  653. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_ext.c +0 -1
  654. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_lu.c +107 -255
  655. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +32 -20
  656. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +25 -152
  657. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_v3.c +0 -1
  658. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +330 -944
  659. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vpm.c +93 -215
  660. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +28 -6
  661. data/third_party/boringssl-with-bazel/src/crypto/x509/x509spki.c +1 -1
  662. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +35 -129
  663. data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.c +7 -8
  664. data/third_party/boringssl-with-bazel/src/crypto/x509/x_pubkey.c +46 -50
  665. data/third_party/boringssl-with-bazel/src/crypto/x509/x_spki.c +2 -0
  666. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +1 -4
  667. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509a.c +6 -6
  668. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +0 -21
  669. data/third_party/boringssl-with-bazel/src/include/openssl/asm_base.h +5 -6
  670. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +3 -1
  671. data/third_party/boringssl-with-bazel/src/include/openssl/bio.h +24 -0
  672. data/third_party/boringssl-with-bazel/src/include/openssl/bn.h +14 -5
  673. data/third_party/boringssl-with-bazel/src/include/openssl/bytestring.h +22 -0
  674. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +1 -0
  675. data/third_party/boringssl-with-bazel/src/include/openssl/conf.h +4 -1
  676. data/third_party/boringssl-with-bazel/src/include/openssl/curve25519.h +2 -2
  677. data/third_party/boringssl-with-bazel/src/include/openssl/des.h +0 -13
  678. data/third_party/boringssl-with-bazel/src/include/openssl/ec.h +33 -11
  679. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +1 -1
  680. data/third_party/boringssl-with-bazel/src/include/openssl/ex_data.h +5 -4
  681. data/third_party/boringssl-with-bazel/src/include/openssl/kyber.h +26 -18
  682. data/third_party/boringssl-with-bazel/src/include/openssl/mem.h +13 -6
  683. data/third_party/boringssl-with-bazel/src/include/openssl/obj.h +5 -1
  684. data/third_party/boringssl-with-bazel/src/include/openssl/opensslconf.h +1 -0
  685. data/third_party/boringssl-with-bazel/src/include/openssl/pem.h +19 -5
  686. data/third_party/boringssl-with-bazel/src/include/openssl/posix_time.h +45 -0
  687. data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +5 -0
  688. data/third_party/boringssl-with-bazel/src/include/openssl/sha.h +20 -3
  689. data/third_party/boringssl-with-bazel/src/include/openssl/span.h +18 -20
  690. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +76 -60
  691. data/third_party/boringssl-with-bazel/src/include/openssl/target.h +31 -6
  692. data/third_party/boringssl-with-bazel/src/include/openssl/time.h +3 -22
  693. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +2 -1
  694. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +2806 -941
  695. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +38 -1025
  696. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3_errors.h +124 -0
  697. data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +1 -2
  698. data/third_party/boringssl-with-bazel/src/ssl/extensions.cc +82 -9
  699. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +42 -4
  700. data/third_party/boringssl-with-bazel/src/ssl/internal.h +4 -0
  701. data/third_party/boringssl-with-bazel/src/ssl/ssl_key_share.cc +4 -5
  702. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +9 -1
  703. data/third_party/boringssl-with-bazel/src/ssl/ssl_x509.cc +0 -1
  704. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +5 -1
  705. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +5 -1
  706. data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_64_adx.h +4 -2
  707. data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_64.h +21 -0
  708. data/third_party/cares/config_linux/ares_config.h +2 -38
  709. metadata +214 -179
  710. data/src/core/lib/iomgr/load_file.cc +0 -78
  711. data/src/core/lib/iomgr/load_file.h +0 -35
  712. data/third_party/abseil-cpp/absl/base/internal/prefetch.h +0 -137
  713. data/third_party/abseil-cpp/absl/base/internal/thread_annotations.h +0 -280
  714. data/third_party/abseil-cpp/absl/flags/flag.cc +0 -38
  715. data/third_party/abseil-cpp/absl/flags/internal/flag_msvc.inc +0 -116
  716. data/third_party/abseil-cpp/absl/strings/internal/char_map.h +0 -158
  717. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring.cc +0 -773
  718. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring.h +0 -607
  719. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring_reader.h +0 -118
  720. data/third_party/boringssl-with-bazel/src/crypto/x509/x_info.c +0 -100
  721. data/third_party/boringssl-with-bazel/src/crypto/x509/x_pkey.c +0 -111
  722. data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +0 -197
  723. /data/third_party/boringssl-with-bazel/src/crypto/{x509v3 → x509}/ext_dat.h +0 -0
@@ -55,6 +55,7 @@
55
55
  * [including the GNU Public Licence.] */
56
56
 
57
57
  #include <ctype.h>
58
+ #include <limits.h>
58
59
  #include <string.h>
59
60
  #include <time.h>
60
61
 
@@ -65,10 +66,8 @@
65
66
  #include <openssl/obj.h>
66
67
  #include <openssl/thread.h>
67
68
  #include <openssl/x509.h>
68
- #include <openssl/x509v3.h>
69
69
 
70
70
  #include "../internal.h"
71
- #include "../x509v3/internal.h"
72
71
  #include "internal.h"
73
72
 
74
73
  static CRYPTO_EX_DATA_CLASS g_ex_data_class =
@@ -77,44 +76,31 @@ static CRYPTO_EX_DATA_CLASS g_ex_data_class =
77
76
  // CRL score values
78
77
 
79
78
  // No unhandled critical extensions
80
-
81
79
  #define CRL_SCORE_NOCRITICAL 0x100
82
80
 
83
81
  // certificate is within CRL scope
84
-
85
82
  #define CRL_SCORE_SCOPE 0x080
86
83
 
87
84
  // CRL times valid
88
-
89
85
  #define CRL_SCORE_TIME 0x040
90
86
 
91
87
  // Issuer name matches certificate
92
-
93
88
  #define CRL_SCORE_ISSUER_NAME 0x020
94
89
 
95
90
  // If this score or above CRL is probably valid
96
-
97
91
  #define CRL_SCORE_VALID \
98
92
  (CRL_SCORE_NOCRITICAL | CRL_SCORE_TIME | CRL_SCORE_SCOPE)
99
93
 
100
94
  // CRL issuer is certificate issuer
101
-
102
95
  #define CRL_SCORE_ISSUER_CERT 0x018
103
96
 
104
97
  // CRL issuer is on certificate path
105
-
106
98
  #define CRL_SCORE_SAME_PATH 0x008
107
99
 
108
100
  // CRL issuer matches CRL AKID
109
-
110
101
  #define CRL_SCORE_AKID 0x004
111
102
 
112
- // Have a delta CRL with valid times
113
-
114
- #define CRL_SCORE_TIME_DELTA 0x002
115
-
116
103
  static int null_callback(int ok, X509_STORE_CTX *e);
117
- static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer);
118
104
  static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x);
119
105
  static int check_chain_extensions(X509_STORE_CTX *ctx);
120
106
  static int check_name_constraints(X509_STORE_CTX *ctx);
@@ -124,19 +110,14 @@ static int check_revocation(X509_STORE_CTX *ctx);
124
110
  static int check_cert(X509_STORE_CTX *ctx);
125
111
  static int check_policy(X509_STORE_CTX *ctx);
126
112
 
127
- static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer,
128
- unsigned int *preasons, X509_CRL *crl, X509 *x);
129
- static int get_crl_delta(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl,
113
+ static X509 *get_trusted_issuer(X509_STORE_CTX *ctx, X509 *x);
114
+ static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer, X509_CRL *crl,
130
115
  X509 *x);
131
- static void get_delta_sk(X509_STORE_CTX *ctx, X509_CRL **dcrl, int *pcrl_score,
132
- X509_CRL *base, STACK_OF(X509_CRL) *crls);
133
- static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer,
134
- int *pcrl_score);
135
- static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score,
136
- unsigned int *preasons);
137
- static int check_crl_path(X509_STORE_CTX *ctx, X509 *x);
138
- static int check_crl_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *cert_path,
139
- STACK_OF(X509) *crl_path);
116
+ static int get_crl(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 *x);
117
+ static int crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer,
118
+ int *pcrl_score);
119
+ static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score);
120
+ static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x);
140
121
 
141
122
  static int internal_verify(X509_STORE_CTX *ctx);
142
123
 
@@ -153,14 +134,24 @@ static int cert_self_signed(X509 *x, int *out_is_self_signed) {
153
134
  return 1;
154
135
  }
155
136
 
156
- // Given a certificate try and find an exact match in the store
137
+ static int call_verify_cb(int ok, X509_STORE_CTX *ctx) {
138
+ ok = ctx->verify_cb(ok, ctx);
139
+ // Historically, callbacks returning values like -1 would be treated as a mix
140
+ // of success or failure. Insert that callers check correctly.
141
+ //
142
+ // TODO(davidben): Also use this wrapper to constrain which errors may be
143
+ // suppressed, and ensure all |verify_cb| calls remember to fill in an error.
144
+ BSSL_CHECK(ok == 0 || ok == 1);
145
+ return ok;
146
+ }
157
147
 
148
+ // Given a certificate try and find an exact match in the store
158
149
  static X509 *lookup_cert_match(X509_STORE_CTX *ctx, X509 *x) {
159
150
  STACK_OF(X509) *certs;
160
151
  X509 *xtmp = NULL;
161
152
  size_t i;
162
153
  // Lookup all certs with matching subject name
163
- certs = ctx->lookup_certs(ctx, X509_get_subject_name(x));
154
+ certs = X509_STORE_CTX_get1_certs(ctx, X509_get_subject_name(x));
164
155
  if (certs == NULL) {
165
156
  return NULL;
166
157
  }
@@ -181,24 +172,35 @@ static X509 *lookup_cert_match(X509_STORE_CTX *ctx, X509 *x) {
181
172
  }
182
173
 
183
174
  int X509_verify_cert(X509_STORE_CTX *ctx) {
184
- X509 *x, *xtmp, *xtmp2, *chain_ss = NULL;
175
+ X509 *chain_ss = NULL;
185
176
  int bad_chain = 0;
186
177
  X509_VERIFY_PARAM *param = ctx->param;
187
- int depth, i, ok = 0;
188
- int num, j, retry, trust;
178
+ int i, ok = 0;
179
+ int j, retry, trust;
189
180
  STACK_OF(X509) *sktmp = NULL;
190
181
 
191
182
  if (ctx->cert == NULL) {
192
183
  OPENSSL_PUT_ERROR(X509, X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
193
184
  ctx->error = X509_V_ERR_INVALID_CALL;
194
- return -1;
185
+ return 0;
195
186
  }
187
+
196
188
  if (ctx->chain != NULL) {
197
189
  // This X509_STORE_CTX has already been used to verify a cert. We
198
190
  // cannot do another one.
199
191
  OPENSSL_PUT_ERROR(X509, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
200
192
  ctx->error = X509_V_ERR_INVALID_CALL;
201
- return -1;
193
+ return 0;
194
+ }
195
+
196
+ if (ctx->param->flags &
197
+ (X509_V_FLAG_EXTENDED_CRL_SUPPORT | X509_V_FLAG_USE_DELTAS)) {
198
+ // We do not support indirect or delta CRLs. The flags still exist for
199
+ // compatibility with bindings libraries, but to ensure we do not
200
+ // inadvertently skip a CRL check that the caller expects, fail closed.
201
+ OPENSSL_PUT_ERROR(X509, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
202
+ ctx->error = X509_V_ERR_INVALID_CALL;
203
+ return 0;
202
204
  }
203
205
 
204
206
  // first we make sure the chain we are going to build is present and that
@@ -217,17 +219,17 @@ int X509_verify_cert(X509_STORE_CTX *ctx) {
217
219
  goto end;
218
220
  }
219
221
 
220
- num = (int)sk_X509_num(ctx->chain);
221
- x = sk_X509_value(ctx->chain, num - 1);
222
- depth = param->depth;
222
+ int num = (int)sk_X509_num(ctx->chain);
223
+ X509 *x = sk_X509_value(ctx->chain, num - 1);
224
+ // |param->depth| does not include the leaf certificate or the trust anchor,
225
+ // so the maximum size is 2 more.
226
+ int max_chain = param->depth >= INT_MAX - 2 ? INT_MAX : param->depth + 2;
223
227
 
224
228
  for (;;) {
225
- // If we have enough, we break
226
- if (depth < num) {
227
- break; // FIXME: If this happens, we should take
228
- // note of it and, if appropriate, use the
229
- // X509_V_ERR_CERT_CHAIN_TOO_LONG error code
230
- // later.
229
+ if (num >= max_chain) {
230
+ // FIXME: If this happens, we should take note of it and, if appropriate,
231
+ // use the X509_V_ERR_CERT_CHAIN_TOO_LONG error code later.
232
+ break;
231
233
  }
232
234
 
233
235
  int is_self_signed;
@@ -242,32 +244,26 @@ int X509_verify_cert(X509_STORE_CTX *ctx) {
242
244
  }
243
245
  // If asked see if we can find issuer in trusted store first
244
246
  if (ctx->param->flags & X509_V_FLAG_TRUSTED_FIRST) {
245
- ok = ctx->get_issuer(&xtmp, ctx, x);
246
- if (ok < 0) {
247
- ctx->error = X509_V_ERR_STORE_LOOKUP;
248
- goto end;
249
- }
250
- // If successful for now free up cert so it will be picked up
251
- // again later.
252
- if (ok > 0) {
253
- X509_free(xtmp);
247
+ X509 *issuer = get_trusted_issuer(ctx, x);
248
+ if (issuer != NULL) {
249
+ // Free the certificate. It will be picked up again later.
250
+ X509_free(issuer);
254
251
  break;
255
252
  }
256
253
  }
257
254
 
258
255
  // If we were passed a cert chain, use it first
259
256
  if (sktmp != NULL) {
260
- xtmp = find_issuer(ctx, sktmp, x);
261
- if (xtmp != NULL) {
262
- if (!sk_X509_push(ctx->chain, xtmp)) {
257
+ X509 *issuer = find_issuer(ctx, sktmp, x);
258
+ if (issuer != NULL) {
259
+ if (!sk_X509_push(ctx->chain, issuer)) {
263
260
  ctx->error = X509_V_ERR_OUT_OF_MEM;
264
- ok = 0;
265
261
  goto end;
266
262
  }
267
- X509_up_ref(xtmp);
268
- (void)sk_X509_delete_ptr(sktmp, xtmp);
263
+ X509_up_ref(issuer);
264
+ (void)sk_X509_delete_ptr(sktmp, issuer);
269
265
  ctx->last_untrusted++;
270
- x = xtmp;
266
+ x = issuer;
271
267
  num++;
272
268
  // reparse the full chain for the next one
273
269
  continue;
@@ -299,24 +295,21 @@ int X509_verify_cert(X509_STORE_CTX *ctx) {
299
295
  // We have a single self signed certificate: see if we can
300
296
  // find it in the store. We must have an exact match to avoid
301
297
  // possible impersonation.
302
- ok = ctx->get_issuer(&xtmp, ctx, x);
303
- if ((ok <= 0) || X509_cmp(x, xtmp)) {
298
+ X509 *issuer = get_trusted_issuer(ctx, x);
299
+ if (issuer == NULL || X509_cmp(x, issuer) != 0) {
300
+ X509_free(issuer);
304
301
  ctx->error = X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT;
305
302
  ctx->current_cert = x;
306
303
  ctx->error_depth = i - 1;
307
- if (ok == 1) {
308
- X509_free(xtmp);
309
- }
310
304
  bad_chain = 1;
311
- ok = ctx->verify_cb(0, ctx);
312
- if (!ok) {
305
+ if (!call_verify_cb(0, ctx)) {
313
306
  goto end;
314
307
  }
315
308
  } else {
316
309
  // We have a match: replace certificate with store
317
310
  // version so we get any trust settings.
318
311
  X509_free(x);
319
- x = xtmp;
312
+ x = issuer;
320
313
  (void)sk_X509_set(ctx->chain, i - 1, x);
321
314
  ctx->last_untrusted = 0;
322
315
  }
@@ -331,8 +324,9 @@ int X509_verify_cert(X509_STORE_CTX *ctx) {
331
324
  }
332
325
  // We now lookup certs from the certificate store
333
326
  for (;;) {
334
- // If we have enough, we break
335
- if (depth < num) {
327
+ if (num >= max_chain) {
328
+ // FIXME: If this happens, we should take note of it and, if
329
+ // appropriate, use the X509_V_ERR_CERT_CHAIN_TOO_LONG error code later.
336
330
  break;
337
331
  }
338
332
  if (!cert_self_signed(x, &is_self_signed)) {
@@ -343,20 +337,14 @@ int X509_verify_cert(X509_STORE_CTX *ctx) {
343
337
  if (is_self_signed) {
344
338
  break;
345
339
  }
346
- ok = ctx->get_issuer(&xtmp, ctx, x);
347
-
348
- if (ok < 0) {
349
- ctx->error = X509_V_ERR_STORE_LOOKUP;
350
- goto end;
351
- }
352
- if (ok == 0) {
340
+ X509 *issuer = get_trusted_issuer(ctx, x);
341
+ if (issuer == NULL) {
353
342
  break;
354
343
  }
355
- x = xtmp;
344
+ x = issuer;
356
345
  if (!sk_X509_push(ctx->chain, x)) {
357
- X509_free(xtmp);
346
+ X509_free(issuer);
358
347
  ctx->error = X509_V_ERR_OUT_OF_MEM;
359
- ok = 0;
360
348
  goto end;
361
349
  }
362
350
  num++;
@@ -367,7 +355,6 @@ int X509_verify_cert(X509_STORE_CTX *ctx) {
367
355
 
368
356
  // If explicitly rejected error
369
357
  if (trust == X509_TRUST_REJECTED) {
370
- ok = 0;
371
358
  goto end;
372
359
  }
373
360
  // If it's not explicitly trusted then check if there is an alternative
@@ -379,21 +366,17 @@ int X509_verify_cert(X509_STORE_CTX *ctx) {
379
366
  !(ctx->param->flags & X509_V_FLAG_TRUSTED_FIRST) &&
380
367
  !(ctx->param->flags & X509_V_FLAG_NO_ALT_CHAINS)) {
381
368
  while (j-- > 1) {
382
- xtmp2 = sk_X509_value(ctx->chain, j - 1);
383
- ok = ctx->get_issuer(&xtmp, ctx, xtmp2);
384
- if (ok < 0) {
385
- goto end;
386
- }
369
+ X509 *issuer =
370
+ get_trusted_issuer(ctx, sk_X509_value(ctx->chain, j - 1));
387
371
  // Check if we found an alternate chain
388
- if (ok > 0) {
372
+ if (issuer != NULL) {
389
373
  // Free up the found cert we'll add it again later
390
- X509_free(xtmp);
374
+ X509_free(issuer);
391
375
 
392
376
  // Dump all the certs above this point - we've found an
393
377
  // alternate chain
394
378
  while (num > j) {
395
- xtmp = sk_X509_pop(ctx->chain);
396
- X509_free(xtmp);
379
+ X509_free(sk_X509_pop(ctx->chain));
397
380
  num--;
398
381
  }
399
382
  ctx->last_untrusted = (int)sk_X509_num(ctx->chain);
@@ -408,7 +391,8 @@ int X509_verify_cert(X509_STORE_CTX *ctx) {
408
391
  // self signed certificate in which case we've indicated an error already
409
392
  // and set bad_chain == 1
410
393
  if (trust != X509_TRUST_TRUSTED && !bad_chain) {
411
- if ((chain_ss == NULL) || !ctx->check_issued(ctx, x, chain_ss)) {
394
+ if (chain_ss == NULL ||
395
+ !x509_check_issued_with_callback(ctx, x, chain_ss)) {
412
396
  if (ctx->last_untrusted >= num) {
413
397
  ctx->error = X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY;
414
398
  } else {
@@ -416,7 +400,10 @@ int X509_verify_cert(X509_STORE_CTX *ctx) {
416
400
  }
417
401
  ctx->current_cert = x;
418
402
  } else {
419
- sk_X509_push(ctx->chain, chain_ss);
403
+ if (!sk_X509_push(ctx->chain, chain_ss)) {
404
+ ctx->error = X509_V_ERR_OUT_OF_MEM;
405
+ goto end;
406
+ }
420
407
  num++;
421
408
  ctx->last_untrusted = num;
422
409
  ctx->current_cert = chain_ss;
@@ -426,63 +413,33 @@ int X509_verify_cert(X509_STORE_CTX *ctx) {
426
413
 
427
414
  ctx->error_depth = num - 1;
428
415
  bad_chain = 1;
429
- ok = ctx->verify_cb(0, ctx);
430
- if (!ok) {
416
+ if (!call_verify_cb(0, ctx)) {
431
417
  goto end;
432
418
  }
433
419
  }
434
420
 
435
421
  // We have the chain complete: now we need to check its purpose
436
- ok = check_chain_extensions(ctx);
437
-
438
- if (!ok) {
422
+ if (!check_chain_extensions(ctx) || //
423
+ !check_id(ctx) ||
424
+ // We check revocation status after copying parameters because they may be
425
+ // needed for CRL signature verification.
426
+ !check_revocation(ctx) || //
427
+ !internal_verify(ctx) || //
428
+ !check_name_constraints(ctx) ||
429
+ // TODO(davidben): Does |check_policy| still need to be conditioned on
430
+ // |!bad_chain|? DoS concerns have been resolved.
431
+ (!bad_chain && !check_policy(ctx))) {
439
432
  goto end;
440
433
  }
441
434
 
442
- ok = check_id(ctx);
443
-
444
- if (!ok) {
445
- goto end;
446
- }
447
-
448
- // Check revocation status: we do this after copying parameters because
449
- // they may be needed for CRL signature verification.
450
- ok = ctx->check_revocation(ctx);
451
- if (!ok) {
452
- goto end;
453
- }
454
-
455
- // At this point, we have a chain and need to verify it
456
- if (ctx->verify != NULL) {
457
- ok = ctx->verify(ctx);
458
- } else {
459
- ok = internal_verify(ctx);
460
- }
461
- if (!ok) {
462
- goto end;
463
- }
464
-
465
- // Check name constraints
466
- ok = check_name_constraints(ctx);
467
- if (!ok) {
468
- goto end;
469
- }
470
-
471
- // If we get this far, evaluate policies.
472
- if (!bad_chain) {
473
- ok = ctx->check_policy(ctx);
474
- }
435
+ ok = 1;
475
436
 
476
437
  end:
477
- if (sktmp != NULL) {
478
- sk_X509_free(sktmp);
479
- }
480
- if (chain_ss != NULL) {
481
- X509_free(chain_ss);
482
- }
438
+ sk_X509_free(sktmp);
439
+ X509_free(chain_ss);
483
440
 
484
441
  // Safety net, error returns must set ctx->error
485
- if (ok <= 0 && ctx->error == X509_V_OK) {
442
+ if (!ok && ctx->error == X509_V_OK) {
486
443
  ctx->error = X509_V_ERR_UNSPECIFIED;
487
444
  }
488
445
  return ok;
@@ -495,7 +452,7 @@ static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x) {
495
452
  X509 *issuer;
496
453
  for (i = 0; i < sk_X509_num(sk); i++) {
497
454
  issuer = sk_X509_value(sk, i);
498
- if (ctx->check_issued(ctx, x, issuer)) {
455
+ if (x509_check_issued_with_callback(ctx, x, issuer)) {
499
456
  return issuer;
500
457
  }
501
458
  }
@@ -504,7 +461,8 @@ static X509 *find_issuer(X509_STORE_CTX *ctx, STACK_OF(X509) *sk, X509 *x) {
504
461
 
505
462
  // Given a possible certificate and issuer check them
506
463
 
507
- static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer) {
464
+ int x509_check_issued_with_callback(X509_STORE_CTX *ctx, X509 *x,
465
+ X509 *issuer) {
508
466
  int ret;
509
467
  ret = X509_check_issued(issuer, x);
510
468
  if (ret == X509_V_OK) {
@@ -517,31 +475,32 @@ static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer) {
517
475
 
518
476
  ctx->error = ret;
519
477
  ctx->current_cert = x;
520
- ctx->current_issuer = issuer;
521
- return ctx->verify_cb(0, ctx);
478
+ return call_verify_cb(0, ctx);
522
479
  }
523
480
 
524
- // Alternative lookup method: look from a STACK stored in other_ctx
481
+ static X509 *get_trusted_issuer(X509_STORE_CTX *ctx, X509 *x) {
482
+ X509 *issuer;
483
+ if (ctx->trusted_stack != NULL) {
484
+ // Ignore the store and use the configured stack instead.
485
+ issuer = find_issuer(ctx, ctx->trusted_stack, x);
486
+ if (issuer != NULL) {
487
+ X509_up_ref(issuer);
488
+ }
489
+ return issuer;
490
+ }
525
491
 
526
- static int get_issuer_sk(X509 **issuer, X509_STORE_CTX *ctx, X509 *x) {
527
- *issuer = find_issuer(ctx, ctx->other_ctx, x);
528
- if (*issuer) {
529
- X509_up_ref(*issuer);
530
- return 1;
531
- } else {
532
- return 0;
492
+ if (!X509_STORE_CTX_get1_issuer(&issuer, ctx, x)) {
493
+ return NULL;
533
494
  }
495
+ return issuer;
534
496
  }
535
497
 
536
498
  // Check a certificate chains extensions for consistency with the supplied
537
499
  // purpose
538
500
 
539
501
  static int check_chain_extensions(X509_STORE_CTX *ctx) {
540
- int ok = 0, plen = 0;
541
-
542
- // If |ctx->parent| is set, this is CRL path validation.
543
- int purpose =
544
- ctx->parent == NULL ? ctx->param->purpose : X509_PURPOSE_CRL_SIGN;
502
+ int plen = 0;
503
+ int purpose = ctx->param->purpose;
545
504
 
546
505
  // Check all untrusted certificates
547
506
  for (int i = 0; i < ctx->last_untrusted; i++) {
@@ -551,9 +510,8 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) {
551
510
  ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;
552
511
  ctx->error_depth = i;
553
512
  ctx->current_cert = x;
554
- ok = ctx->verify_cb(0, ctx);
555
- if (!ok) {
556
- goto end;
513
+ if (!call_verify_cb(0, ctx)) {
514
+ return 0;
557
515
  }
558
516
  }
559
517
 
@@ -562,9 +520,8 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) {
562
520
  ctx->error = X509_V_ERR_INVALID_CA;
563
521
  ctx->error_depth = i;
564
522
  ctx->current_cert = x;
565
- ok = ctx->verify_cb(0, ctx);
566
- if (!ok) {
567
- goto end;
523
+ if (!call_verify_cb(0, ctx)) {
524
+ return 0;
568
525
  }
569
526
  }
570
527
  if (ctx->param->purpose > 0 &&
@@ -572,9 +529,8 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) {
572
529
  ctx->error = X509_V_ERR_INVALID_PURPOSE;
573
530
  ctx->error_depth = i;
574
531
  ctx->current_cert = x;
575
- ok = ctx->verify_cb(0, ctx);
576
- if (!ok) {
577
- goto end;
532
+ if (!call_verify_cb(0, ctx)) {
533
+ return 0;
578
534
  }
579
535
  }
580
536
  // Check pathlen if not self issued
@@ -583,9 +539,8 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) {
583
539
  ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED;
584
540
  ctx->error_depth = i;
585
541
  ctx->current_cert = x;
586
- ok = ctx->verify_cb(0, ctx);
587
- if (!ok) {
588
- goto end;
542
+ if (!call_verify_cb(0, ctx)) {
543
+ return 0;
589
544
  }
590
545
  }
591
546
  // Increment path length if not self issued
@@ -593,9 +548,8 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) {
593
548
  plen++;
594
549
  }
595
550
  }
596
- ok = 1;
597
- end:
598
- return ok;
551
+
552
+ return 1;
599
553
  }
600
554
 
601
555
  static int reject_dns_name_in_common_name(X509 *x509) {
@@ -653,7 +607,7 @@ static int check_name_constraints(X509_STORE_CTX *ctx) {
653
607
  ctx->error = rv;
654
608
  ctx->error_depth = i;
655
609
  ctx->current_cert = x;
656
- if (!ctx->verify_cb(0, ctx)) {
610
+ if (!call_verify_cb(0, ctx)) {
657
611
  return 0;
658
612
  }
659
613
  break;
@@ -685,7 +639,7 @@ static int check_name_constraints(X509_STORE_CTX *ctx) {
685
639
  ctx->error = rv;
686
640
  ctx->error_depth = i;
687
641
  ctx->current_cert = leaf;
688
- if (!ctx->verify_cb(0, ctx)) {
642
+ if (!call_verify_cb(0, ctx)) {
689
643
  return 0;
690
644
  }
691
645
  break;
@@ -699,7 +653,7 @@ static int check_id_error(X509_STORE_CTX *ctx, int errcode) {
699
653
  ctx->error = errcode;
700
654
  ctx->current_cert = ctx->cert;
701
655
  ctx->error_depth = 0;
702
- return ctx->verify_cb(0, ctx);
656
+ return call_verify_cb(0, ctx);
703
657
  }
704
658
 
705
659
  static int check_hosts(X509 *x, X509_VERIFY_PARAM *param) {
@@ -707,14 +661,9 @@ static int check_hosts(X509 *x, X509_VERIFY_PARAM *param) {
707
661
  size_t n = sk_OPENSSL_STRING_num(param->hosts);
708
662
  char *name;
709
663
 
710
- if (param->peername != NULL) {
711
- OPENSSL_free(param->peername);
712
- param->peername = NULL;
713
- }
714
664
  for (i = 0; i < n; ++i) {
715
665
  name = sk_OPENSSL_STRING_value(param->hosts, i);
716
- if (X509_check_host(x, name, strlen(name), param->hostflags,
717
- &param->peername) > 0) {
666
+ if (X509_check_host(x, name, strlen(name), param->hostflags, NULL) > 0) {
718
667
  return 1;
719
668
  }
720
669
  }
@@ -748,24 +697,22 @@ static int check_id(X509_STORE_CTX *ctx) {
748
697
  }
749
698
 
750
699
  static int check_trust(X509_STORE_CTX *ctx) {
751
- int ok;
752
700
  X509 *x = NULL;
753
701
  // Check all trusted certificates in chain
754
702
  for (size_t i = ctx->last_untrusted; i < sk_X509_num(ctx->chain); i++) {
755
703
  x = sk_X509_value(ctx->chain, i);
756
- ok = X509_check_trust(x, ctx->param->trust, 0);
704
+ int trust = X509_check_trust(x, ctx->param->trust, 0);
757
705
  // If explicitly trusted return trusted
758
- if (ok == X509_TRUST_TRUSTED) {
706
+ if (trust == X509_TRUST_TRUSTED) {
759
707
  return X509_TRUST_TRUSTED;
760
708
  }
761
709
  // If explicitly rejected notify callback and reject if not
762
710
  // overridden.
763
- if (ok == X509_TRUST_REJECTED) {
711
+ if (trust == X509_TRUST_REJECTED) {
764
712
  ctx->error_depth = (int)i;
765
713
  ctx->current_cert = x;
766
714
  ctx->error = X509_V_ERR_CERT_REJECTED;
767
- ok = ctx->verify_cb(0, ctx);
768
- if (!ok) {
715
+ if (!call_verify_cb(0, ctx)) {
769
716
  return X509_TRUST_REJECTED;
770
717
  }
771
718
  }
@@ -800,96 +747,52 @@ static int check_revocation(X509_STORE_CTX *ctx) {
800
747
  if (ctx->param->flags & X509_V_FLAG_CRL_CHECK_ALL) {
801
748
  last = (int)sk_X509_num(ctx->chain) - 1;
802
749
  } else {
803
- // If checking CRL paths this isn't the EE certificate
804
- if (ctx->parent) {
805
- return 1;
806
- }
807
750
  last = 0;
808
751
  }
809
752
  for (int i = 0; i <= last; i++) {
810
753
  ctx->error_depth = i;
811
- int ok = check_cert(ctx);
812
- if (!ok) {
813
- return ok;
754
+ if (!check_cert(ctx)) {
755
+ return 0;
814
756
  }
815
757
  }
816
758
  return 1;
817
759
  }
818
760
 
819
761
  static int check_cert(X509_STORE_CTX *ctx) {
820
- X509_CRL *crl = NULL, *dcrl = NULL;
821
- X509 *x;
822
- int ok = 0, cnum;
823
- unsigned int last_reasons;
824
- cnum = ctx->error_depth;
825
- x = sk_X509_value(ctx->chain, cnum);
762
+ X509_CRL *crl = NULL;
763
+ int ok = 0, cnum = ctx->error_depth;
764
+ X509 *x = sk_X509_value(ctx->chain, cnum);
826
765
  ctx->current_cert = x;
827
- ctx->current_issuer = NULL;
766
+ ctx->current_crl_issuer = NULL;
828
767
  ctx->current_crl_score = 0;
829
- ctx->current_reasons = 0;
830
- while (ctx->current_reasons != CRLDP_ALL_REASONS) {
831
- last_reasons = ctx->current_reasons;
832
- // Try to retrieve relevant CRL
833
- if (ctx->get_crl) {
834
- ok = ctx->get_crl(ctx, &crl, x);
835
- } else {
836
- ok = get_crl_delta(ctx, &crl, &dcrl, x);
837
- }
838
- // If error looking up CRL, nothing we can do except notify callback
839
- if (!ok) {
840
- ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL;
841
- ok = ctx->verify_cb(0, ctx);
842
- goto err;
843
- }
844
- ctx->current_crl = crl;
845
- ok = ctx->check_crl(ctx, crl);
846
- if (!ok) {
847
- goto err;
848
- }
849
768
 
850
- if (dcrl) {
851
- ok = ctx->check_crl(ctx, dcrl);
852
- if (!ok) {
853
- goto err;
854
- }
855
- ok = ctx->cert_crl(ctx, dcrl, x);
856
- if (!ok) {
857
- goto err;
858
- }
859
- } else {
860
- ok = 1;
861
- }
862
-
863
- // Don't look in full CRL if delta reason is removefromCRL
864
- if (ok != 2) {
865
- ok = ctx->cert_crl(ctx, crl, x);
866
- if (!ok) {
867
- goto err;
868
- }
869
- }
769
+ // Try to retrieve the relevant CRL. Note that |get_crl| sets
770
+ // |current_crl_issuer| and |current_crl_score|, which |check_crl| then reads.
771
+ //
772
+ // TODO(davidben): Remove these callbacks. gRPC currently sets them, but
773
+ // implements them incorrectly. It is not actually possible to implement
774
+ // |get_crl| from outside the library.
775
+ if (!ctx->get_crl(ctx, &crl, x)) {
776
+ ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL;
777
+ ok = call_verify_cb(0, ctx);
778
+ goto err;
779
+ }
870
780
 
871
- X509_CRL_free(crl);
872
- X509_CRL_free(dcrl);
873
- crl = NULL;
874
- dcrl = NULL;
875
- // If reasons not updated we wont get anywhere by another iteration,
876
- // so exit loop.
877
- if (last_reasons == ctx->current_reasons) {
878
- ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL;
879
- ok = ctx->verify_cb(0, ctx);
880
- goto err;
881
- }
781
+ ctx->current_crl = crl;
782
+ if (!ctx->check_crl(ctx, crl) || //
783
+ !cert_crl(ctx, crl, x)) {
784
+ goto err;
882
785
  }
786
+
787
+ ok = 1;
788
+
883
789
  err:
884
790
  X509_CRL_free(crl);
885
- X509_CRL_free(dcrl);
886
-
887
791
  ctx->current_crl = NULL;
888
792
  return ok;
889
793
  }
890
794
 
891
795
  // Check CRL times against values in X509_STORE_CTX
892
-
893
796
  static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify) {
894
797
  if (ctx->param->flags & X509_V_FLAG_NO_CHECK_TIME) {
895
798
  return 1;
@@ -911,7 +814,7 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify) {
911
814
  return 0;
912
815
  }
913
816
  ctx->error = X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD;
914
- if (!ctx->verify_cb(0, ctx)) {
817
+ if (!call_verify_cb(0, ctx)) {
915
818
  return 0;
916
819
  }
917
820
  }
@@ -921,7 +824,7 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify) {
921
824
  return 0;
922
825
  }
923
826
  ctx->error = X509_V_ERR_CRL_NOT_YET_VALID;
924
- if (!ctx->verify_cb(0, ctx)) {
827
+ if (!call_verify_cb(0, ctx)) {
925
828
  return 0;
926
829
  }
927
830
  }
@@ -934,17 +837,16 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify) {
934
837
  return 0;
935
838
  }
936
839
  ctx->error = X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD;
937
- if (!ctx->verify_cb(0, ctx)) {
840
+ if (!call_verify_cb(0, ctx)) {
938
841
  return 0;
939
842
  }
940
843
  }
941
- // Ignore expiry of base CRL is delta is valid
942
- if ((i < 0) && !(ctx->current_crl_score & CRL_SCORE_TIME_DELTA)) {
844
+ if (i < 0) {
943
845
  if (!notify) {
944
846
  return 0;
945
847
  }
946
848
  ctx->error = X509_V_ERR_CRL_HAS_EXPIRED;
947
- if (!ctx->verify_cb(0, ctx)) {
849
+ if (!call_verify_cb(0, ctx)) {
948
850
  return 0;
949
851
  }
950
852
  }
@@ -957,20 +859,16 @@ static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify) {
957
859
  return 1;
958
860
  }
959
861
 
960
- static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl,
961
- X509 **pissuer, int *pscore, unsigned int *preasons,
962
- STACK_OF(X509_CRL) *crls) {
862
+ static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 **pissuer,
863
+ int *pscore, STACK_OF(X509_CRL) *crls) {
963
864
  int crl_score, best_score = *pscore;
964
- size_t i;
965
- unsigned int reasons, best_reasons = 0;
966
865
  X509 *x = ctx->current_cert;
967
- X509_CRL *crl, *best_crl = NULL;
866
+ X509_CRL *best_crl = NULL;
968
867
  X509 *crl_issuer = NULL, *best_crl_issuer = NULL;
969
868
 
970
- for (i = 0; i < sk_X509_CRL_num(crls); i++) {
971
- crl = sk_X509_CRL_value(crls, i);
972
- reasons = *preasons;
973
- crl_score = get_crl_score(ctx, &crl_issuer, &reasons, crl, x);
869
+ for (size_t i = 0; i < sk_X509_CRL_num(crls); i++) {
870
+ X509_CRL *crl = sk_X509_CRL_value(crls, i);
871
+ crl_score = get_crl_score(ctx, &crl_issuer, crl, x);
974
872
  if (crl_score < best_score || crl_score == 0) {
975
873
  continue;
976
874
  }
@@ -990,7 +888,6 @@ static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl,
990
888
  best_crl = crl;
991
889
  best_crl_issuer = crl_issuer;
992
890
  best_score = crl_score;
993
- best_reasons = reasons;
994
891
  }
995
892
 
996
893
  if (best_crl) {
@@ -1000,13 +897,7 @@ static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl,
1000
897
  *pcrl = best_crl;
1001
898
  *pissuer = best_crl_issuer;
1002
899
  *pscore = best_score;
1003
- *preasons = best_reasons;
1004
900
  X509_CRL_up_ref(best_crl);
1005
- if (*pdcrl) {
1006
- X509_CRL_free(*pdcrl);
1007
- *pdcrl = NULL;
1008
- }
1009
- get_delta_sk(ctx, pdcrl, pscore, best_crl, crls);
1010
901
  }
1011
902
 
1012
903
  if (best_score >= CRL_SCORE_VALID) {
@@ -1016,119 +907,12 @@ static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl,
1016
907
  return 0;
1017
908
  }
1018
909
 
1019
- // Compare two CRL extensions for delta checking purposes. They should be
1020
- // both present or both absent. If both present all fields must be identical.
1021
-
1022
- static int crl_extension_match(X509_CRL *a, X509_CRL *b, int nid) {
1023
- const ASN1_OCTET_STRING *exta, *extb;
1024
- int i;
1025
- i = X509_CRL_get_ext_by_NID(a, nid, -1);
1026
- if (i >= 0) {
1027
- // Can't have multiple occurrences
1028
- if (X509_CRL_get_ext_by_NID(a, nid, i) != -1) {
1029
- return 0;
1030
- }
1031
- exta = X509_EXTENSION_get_data(X509_CRL_get_ext(a, i));
1032
- } else {
1033
- exta = NULL;
1034
- }
1035
-
1036
- i = X509_CRL_get_ext_by_NID(b, nid, -1);
1037
-
1038
- if (i >= 0) {
1039
- if (X509_CRL_get_ext_by_NID(b, nid, i) != -1) {
1040
- return 0;
1041
- }
1042
- extb = X509_EXTENSION_get_data(X509_CRL_get_ext(b, i));
1043
- } else {
1044
- extb = NULL;
1045
- }
1046
-
1047
- if (!exta && !extb) {
1048
- return 1;
1049
- }
1050
-
1051
- if (!exta || !extb) {
1052
- return 0;
1053
- }
1054
-
1055
- if (ASN1_OCTET_STRING_cmp(exta, extb)) {
1056
- return 0;
1057
- }
1058
-
1059
- return 1;
1060
- }
1061
-
1062
- // See if a base and delta are compatible
1063
-
1064
- static int check_delta_base(X509_CRL *delta, X509_CRL *base) {
1065
- // Delta CRL must be a delta
1066
- if (!delta->base_crl_number) {
1067
- return 0;
1068
- }
1069
- // Base must have a CRL number
1070
- if (!base->crl_number) {
1071
- return 0;
1072
- }
1073
- // Issuer names must match
1074
- if (X509_NAME_cmp(X509_CRL_get_issuer(base), X509_CRL_get_issuer(delta))) {
1075
- return 0;
1076
- }
1077
- // AKID and IDP must match
1078
- if (!crl_extension_match(delta, base, NID_authority_key_identifier)) {
1079
- return 0;
1080
- }
1081
- if (!crl_extension_match(delta, base, NID_issuing_distribution_point)) {
1082
- return 0;
1083
- }
1084
- // Delta CRL base number must not exceed Full CRL number.
1085
- if (ASN1_INTEGER_cmp(delta->base_crl_number, base->crl_number) > 0) {
1086
- return 0;
1087
- }
1088
- // Delta CRL number must exceed full CRL number
1089
- if (ASN1_INTEGER_cmp(delta->crl_number, base->crl_number) > 0) {
1090
- return 1;
1091
- }
1092
- return 0;
1093
- }
1094
-
1095
- // For a given base CRL find a delta... maybe extend to delta scoring or
1096
- // retrieve a chain of deltas...
1097
-
1098
- static void get_delta_sk(X509_STORE_CTX *ctx, X509_CRL **dcrl, int *pscore,
1099
- X509_CRL *base, STACK_OF(X509_CRL) *crls) {
1100
- X509_CRL *delta;
1101
- size_t i;
1102
- if (!(ctx->param->flags & X509_V_FLAG_USE_DELTAS)) {
1103
- return;
1104
- }
1105
- if (!((ctx->current_cert->ex_flags | base->flags) & EXFLAG_FRESHEST)) {
1106
- return;
1107
- }
1108
- for (i = 0; i < sk_X509_CRL_num(crls); i++) {
1109
- delta = sk_X509_CRL_value(crls, i);
1110
- if (check_delta_base(delta, base)) {
1111
- if (check_crl_time(ctx, delta, 0)) {
1112
- *pscore |= CRL_SCORE_TIME_DELTA;
1113
- }
1114
- X509_CRL_up_ref(delta);
1115
- *dcrl = delta;
1116
- return;
1117
- }
1118
- }
1119
- *dcrl = NULL;
1120
- }
1121
-
1122
910
  // For a given CRL return how suitable it is for the supplied certificate
1123
911
  // 'x'. The return value is a mask of several criteria. If the issuer is not
1124
- // the certificate issuer this is returned in *pissuer. The reasons mask is
1125
- // also used to determine if the CRL is suitable: if no new reasons the CRL
1126
- // is rejected, otherwise reasons is updated.
1127
-
1128
- static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer,
1129
- unsigned int *preasons, X509_CRL *crl, X509 *x) {
912
+ // the certificate issuer this is returned in *pissuer.
913
+ static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer, X509_CRL *crl,
914
+ X509 *x) {
1130
915
  int crl_score = 0;
1131
- unsigned int tmp_reasons = *preasons, crl_reasons;
1132
916
 
1133
917
  // First see if we can reject CRL straight away
1134
918
 
@@ -1136,29 +920,15 @@ static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer,
1136
920
  if (crl->idp_flags & IDP_INVALID) {
1137
921
  return 0;
1138
922
  }
1139
- // Reason codes or indirect CRLs need extended CRL support
1140
- if (!(ctx->param->flags & X509_V_FLAG_EXTENDED_CRL_SUPPORT)) {
1141
- if (crl->idp_flags & (IDP_INDIRECT | IDP_REASONS)) {
1142
- return 0;
1143
- }
1144
- } else if (crl->idp_flags & IDP_REASONS) {
1145
- // If no new reasons reject
1146
- if (!(crl->idp_reasons & ~tmp_reasons)) {
1147
- return 0;
1148
- }
1149
- }
1150
- // Don't process deltas at this stage
1151
- else if (crl->base_crl_number) {
923
+ // Reason codes and indirect CRLs are not supported.
924
+ if (crl->idp_flags & (IDP_INDIRECT | IDP_REASONS)) {
1152
925
  return 0;
1153
926
  }
1154
- // If issuer name doesn't match certificate need indirect CRL
927
+ // We do not support indirect CRLs, so the issuer names must match.
1155
928
  if (X509_NAME_cmp(X509_get_issuer_name(x), X509_CRL_get_issuer(crl))) {
1156
- if (!(crl->idp_flags & IDP_INDIRECT)) {
1157
- return 0;
1158
- }
1159
- } else {
1160
- crl_score |= CRL_SCORE_ISSUER_NAME;
929
+ return 0;
1161
930
  }
931
+ crl_score |= CRL_SCORE_ISSUER_NAME;
1162
932
 
1163
933
  if (!(crl->flags & EXFLAG_CRITICAL)) {
1164
934
  crl_score |= CRL_SCORE_NOCRITICAL;
@@ -1170,36 +940,24 @@ static int get_crl_score(X509_STORE_CTX *ctx, X509 **pissuer,
1170
940
  }
1171
941
 
1172
942
  // Check authority key ID and locate certificate issuer
1173
- crl_akid_check(ctx, crl, pissuer, &crl_score);
1174
-
1175
- // If we can't locate certificate issuer at this point forget it
1176
-
1177
- if (!(crl_score & CRL_SCORE_AKID)) {
943
+ if (!crl_akid_check(ctx, crl, pissuer, &crl_score)) {
944
+ // If we can't locate certificate issuer at this point forget it
1178
945
  return 0;
1179
946
  }
1180
947
 
1181
948
  // Check cert for matching CRL distribution points
1182
-
1183
- if (crl_crldp_check(x, crl, crl_score, &crl_reasons)) {
1184
- // If no new reasons reject
1185
- if (!(crl_reasons & ~tmp_reasons)) {
1186
- return 0;
1187
- }
1188
- tmp_reasons |= crl_reasons;
949
+ if (crl_crldp_check(x, crl, crl_score)) {
1189
950
  crl_score |= CRL_SCORE_SCOPE;
1190
951
  }
1191
952
 
1192
- *preasons = tmp_reasons;
1193
-
1194
953
  return crl_score;
1195
954
  }
1196
955
 
1197
- static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer,
1198
- int *pcrl_score) {
956
+ static int crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer,
957
+ int *pcrl_score) {
1199
958
  X509 *crl_issuer = NULL;
1200
959
  X509_NAME *cnm = X509_CRL_get_issuer(crl);
1201
960
  int cidx = ctx->error_depth;
1202
- size_t i;
1203
961
 
1204
962
  if ((size_t)cidx != sk_X509_num(ctx->chain) - 1) {
1205
963
  cidx++;
@@ -1208,11 +966,9 @@ static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer,
1208
966
  crl_issuer = sk_X509_value(ctx->chain, cidx);
1209
967
 
1210
968
  if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {
1211
- if (*pcrl_score & CRL_SCORE_ISSUER_NAME) {
1212
- *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_ISSUER_CERT;
1213
- *pissuer = crl_issuer;
1214
- return;
1215
- }
969
+ *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_ISSUER_CERT;
970
+ *pissuer = crl_issuer;
971
+ return 1;
1216
972
  }
1217
973
 
1218
974
  for (cidx++; cidx < (int)sk_X509_num(ctx->chain); cidx++) {
@@ -1223,84 +979,10 @@ static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, X509 **pissuer,
1223
979
  if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {
1224
980
  *pcrl_score |= CRL_SCORE_AKID | CRL_SCORE_SAME_PATH;
1225
981
  *pissuer = crl_issuer;
1226
- return;
1227
- }
1228
- }
1229
-
1230
- // Anything else needs extended CRL support
1231
-
1232
- if (!(ctx->param->flags & X509_V_FLAG_EXTENDED_CRL_SUPPORT)) {
1233
- return;
1234
- }
1235
-
1236
- // Otherwise the CRL issuer is not on the path. Look for it in the set of
1237
- // untrusted certificates.
1238
- for (i = 0; i < sk_X509_num(ctx->untrusted); i++) {
1239
- crl_issuer = sk_X509_value(ctx->untrusted, i);
1240
- if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm)) {
1241
- continue;
1242
- }
1243
- if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) {
1244
- *pissuer = crl_issuer;
1245
- *pcrl_score |= CRL_SCORE_AKID;
1246
- return;
982
+ return 1;
1247
983
  }
1248
984
  }
1249
- }
1250
-
1251
- // Check the path of a CRL issuer certificate. This creates a new
1252
- // X509_STORE_CTX and populates it with most of the parameters from the
1253
- // parent. This could be optimised somewhat since a lot of path checking will
1254
- // be duplicated by the parent, but this will rarely be used in practice.
1255
-
1256
- static int check_crl_path(X509_STORE_CTX *ctx, X509 *x) {
1257
- X509_STORE_CTX crl_ctx;
1258
- int ret;
1259
- // Don't allow recursive CRL path validation
1260
- if (ctx->parent) {
1261
- return 0;
1262
- }
1263
- if (!X509_STORE_CTX_init(&crl_ctx, ctx->ctx, x, ctx->untrusted)) {
1264
- return -1;
1265
- }
1266
-
1267
- crl_ctx.crls = ctx->crls;
1268
- // Copy verify params across
1269
- X509_STORE_CTX_set0_param(&crl_ctx, ctx->param);
1270
-
1271
- crl_ctx.parent = ctx;
1272
- crl_ctx.verify_cb = ctx->verify_cb;
1273
-
1274
- // Verify CRL issuer
1275
- ret = X509_verify_cert(&crl_ctx);
1276
-
1277
- if (ret <= 0) {
1278
- goto err;
1279
- }
1280
985
 
1281
- // Check chain is acceptable
1282
-
1283
- ret = check_crl_chain(ctx, ctx->chain, crl_ctx.chain);
1284
- err:
1285
- X509_STORE_CTX_cleanup(&crl_ctx);
1286
- return ret;
1287
- }
1288
-
1289
- // RFC 3280 says nothing about the relationship between CRL path and
1290
- // certificate path, which could lead to situations where a certificate could
1291
- // be revoked or validated by a CA not authorised to do so. RFC 5280 is more
1292
- // strict and states that the two paths must end in the same trust anchor,
1293
- // though some discussions remain... until this is resolved we use the
1294
- // RFC 5280 version
1295
-
1296
- static int check_crl_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *cert_path,
1297
- STACK_OF(X509) *crl_path) {
1298
- X509 *cert_ta, *crl_ta;
1299
- cert_ta = sk_X509_value(cert_path, sk_X509_num(cert_path) - 1);
1300
- crl_ta = sk_X509_value(crl_path, sk_X509_num(crl_path) - 1);
1301
- if (!X509_cmp(cert_ta, crl_ta)) {
1302
- return 1;
1303
- }
1304
986
  return 0;
1305
987
  }
1306
988
 
@@ -1308,7 +990,6 @@ static int check_crl_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *cert_path,
1308
990
  // Both are relative names and compare X509_NAME types. 2. One full, one
1309
991
  // relative. Compare X509_NAME to GENERAL_NAMES. 3. Both are full names and
1310
992
  // compare two GENERAL_NAMES. 4. One is NULL: automatic match.
1311
-
1312
993
  static int idp_check_dp(DIST_POINT_NAME *a, DIST_POINT_NAME *b) {
1313
994
  X509_NAME *nm = NULL;
1314
995
  GENERAL_NAMES *gens = NULL;
@@ -1373,30 +1054,8 @@ static int idp_check_dp(DIST_POINT_NAME *a, DIST_POINT_NAME *b) {
1373
1054
  return 0;
1374
1055
  }
1375
1056
 
1376
- static int crldp_check_crlissuer(DIST_POINT *dp, X509_CRL *crl, int crl_score) {
1377
- size_t i;
1378
- X509_NAME *nm = X509_CRL_get_issuer(crl);
1379
- // If no CRLissuer return is successful iff don't need a match
1380
- if (!dp->CRLissuer) {
1381
- return !!(crl_score & CRL_SCORE_ISSUER_NAME);
1382
- }
1383
- for (i = 0; i < sk_GENERAL_NAME_num(dp->CRLissuer); i++) {
1384
- GENERAL_NAME *gen = sk_GENERAL_NAME_value(dp->CRLissuer, i);
1385
- if (gen->type != GEN_DIRNAME) {
1386
- continue;
1387
- }
1388
- if (!X509_NAME_cmp(gen->d.directoryName, nm)) {
1389
- return 1;
1390
- }
1391
- }
1392
- return 0;
1393
- }
1394
-
1395
1057
  // Check CRLDP and IDP
1396
-
1397
- static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score,
1398
- unsigned int *preasons) {
1399
- size_t i;
1058
+ static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score) {
1400
1059
  if (crl->idp_flags & IDP_ONLYATTR) {
1401
1060
  return 0;
1402
1061
  }
@@ -1409,52 +1068,49 @@ static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score,
1409
1068
  return 0;
1410
1069
  }
1411
1070
  }
1412
- *preasons = crl->idp_reasons;
1413
- for (i = 0; i < sk_DIST_POINT_num(x->crldp); i++) {
1071
+ for (size_t i = 0; i < sk_DIST_POINT_num(x->crldp); i++) {
1414
1072
  DIST_POINT *dp = sk_DIST_POINT_value(x->crldp, i);
1415
- if (crldp_check_crlissuer(dp, crl, crl_score)) {
1416
- if (!crl->idp || idp_check_dp(dp->distpoint, crl->idp->distpoint)) {
1417
- *preasons &= dp->dp_reasons;
1418
- return 1;
1419
- }
1073
+ // Skip distribution points with a reasons field or a CRL issuer:
1074
+ //
1075
+ // We do not support CRLs partitioned by reason code. RFC 5280 requires CAs
1076
+ // include at least one DistributionPoint that covers all reasons.
1077
+ //
1078
+ // We also do not support indirect CRLs, and a CRL issuer can only match
1079
+ // indirect CRLs (RFC 5280, section 6.3.3, step b.1).
1080
+ // support.
1081
+ if (dp->reasons != NULL && dp->CRLissuer != NULL &&
1082
+ (!crl->idp || idp_check_dp(dp->distpoint, crl->idp->distpoint))) {
1083
+ return 1;
1420
1084
  }
1421
1085
  }
1422
- if ((!crl->idp || !crl->idp->distpoint) &&
1423
- (crl_score & CRL_SCORE_ISSUER_NAME)) {
1424
- return 1;
1425
- }
1426
- return 0;
1427
- }
1428
1086
 
1429
- // Retrieve CRL corresponding to current certificate. If deltas enabled try
1430
- // to find a delta CRL too
1087
+ // If the CRL does not specify an issuing distribution point, allow it to
1088
+ // match anything.
1089
+ //
1090
+ // TODO(davidben): Does this match RFC 5280? It's hard to follow because RFC
1091
+ // 5280 starts from distribution points, while this starts from CRLs.
1092
+ return !crl->idp || !crl->idp->distpoint;
1093
+ }
1431
1094
 
1432
- static int get_crl_delta(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl,
1433
- X509 *x) {
1434
- int ok;
1095
+ // Retrieve CRL corresponding to current certificate.
1096
+ static int get_crl(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 *x) {
1435
1097
  X509 *issuer = NULL;
1436
1098
  int crl_score = 0;
1437
- unsigned int reasons;
1438
- X509_CRL *crl = NULL, *dcrl = NULL;
1439
- STACK_OF(X509_CRL) *skcrl;
1440
- X509_NAME *nm = X509_get_issuer_name(x);
1441
- reasons = ctx->current_reasons;
1442
- ok = get_crl_sk(ctx, &crl, &dcrl, &issuer, &crl_score, &reasons, ctx->crls);
1443
-
1444
- if (ok) {
1099
+ X509_CRL *crl = NULL;
1100
+ if (get_crl_sk(ctx, &crl, &issuer, &crl_score, ctx->crls)) {
1445
1101
  goto done;
1446
1102
  }
1447
1103
 
1448
1104
  // Lookup CRLs from store
1449
-
1450
- skcrl = ctx->lookup_crls(ctx, nm);
1105
+ STACK_OF(X509_CRL) *skcrl =
1106
+ X509_STORE_CTX_get1_crls(ctx, X509_get_issuer_name(x));
1451
1107
 
1452
1108
  // If no CRLs found and a near match from get_crl_sk use that
1453
1109
  if (!skcrl && crl) {
1454
1110
  goto done;
1455
1111
  }
1456
1112
 
1457
- get_crl_sk(ctx, &crl, &dcrl, &issuer, &crl_score, &reasons, skcrl);
1113
+ get_crl_sk(ctx, &crl, &issuer, &crl_score, skcrl);
1458
1114
 
1459
1115
  sk_X509_CRL_pop_free(skcrl, X509_CRL_free);
1460
1116
 
@@ -1462,11 +1118,9 @@ done:
1462
1118
 
1463
1119
  // If we got any kind of CRL use it and return success
1464
1120
  if (crl) {
1465
- ctx->current_issuer = issuer;
1121
+ ctx->current_crl_issuer = issuer;
1466
1122
  ctx->current_crl_score = crl_score;
1467
- ctx->current_reasons = reasons;
1468
1123
  *pcrl = crl;
1469
- *pdcrl = dcrl;
1470
1124
  return 1;
1471
1125
  }
1472
1126
 
@@ -1476,110 +1130,78 @@ done:
1476
1130
  // Check CRL validity
1477
1131
  static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) {
1478
1132
  X509 *issuer = NULL;
1479
- EVP_PKEY *ikey = NULL;
1480
- int ok = 0;
1481
1133
  int cnum = ctx->error_depth;
1482
1134
  int chnum = (int)sk_X509_num(ctx->chain) - 1;
1483
- // if we have an alternative CRL issuer cert use that
1484
- if (ctx->current_issuer) {
1485
- issuer = ctx->current_issuer;
1486
- }
1487
-
1488
- // Else find CRL issuer: if not last certificate then issuer is next
1489
- // certificate in chain.
1490
- else if (cnum < chnum) {
1135
+ // If we have an alternative CRL issuer cert use that. Otherwise, it is the
1136
+ // issuer of the current certificate.
1137
+ if (ctx->current_crl_issuer) {
1138
+ issuer = ctx->current_crl_issuer;
1139
+ } else if (cnum < chnum) {
1491
1140
  issuer = sk_X509_value(ctx->chain, cnum + 1);
1492
1141
  } else {
1493
1142
  issuer = sk_X509_value(ctx->chain, chnum);
1494
1143
  // If not self signed, can't check signature
1495
- if (!ctx->check_issued(ctx, issuer, issuer)) {
1144
+ if (!x509_check_issued_with_callback(ctx, issuer, issuer)) {
1496
1145
  ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER;
1497
- ok = ctx->verify_cb(0, ctx);
1498
- if (!ok) {
1499
- goto err;
1146
+ if (!call_verify_cb(0, ctx)) {
1147
+ return 0;
1500
1148
  }
1501
1149
  }
1502
1150
  }
1503
1151
 
1504
1152
  if (issuer) {
1505
- // Skip most tests for deltas because they have already been done
1506
- if (!crl->base_crl_number) {
1507
- // Check for cRLSign bit if keyUsage present
1508
- if ((issuer->ex_flags & EXFLAG_KUSAGE) &&
1509
- !(issuer->ex_kusage & KU_CRL_SIGN)) {
1510
- ctx->error = X509_V_ERR_KEYUSAGE_NO_CRL_SIGN;
1511
- ok = ctx->verify_cb(0, ctx);
1512
- if (!ok) {
1513
- goto err;
1514
- }
1515
- }
1516
-
1517
- if (!(ctx->current_crl_score & CRL_SCORE_SCOPE)) {
1518
- ctx->error = X509_V_ERR_DIFFERENT_CRL_SCOPE;
1519
- ok = ctx->verify_cb(0, ctx);
1520
- if (!ok) {
1521
- goto err;
1522
- }
1153
+ // Check for cRLSign bit if keyUsage present
1154
+ if ((issuer->ex_flags & EXFLAG_KUSAGE) &&
1155
+ !(issuer->ex_kusage & X509v3_KU_CRL_SIGN)) {
1156
+ ctx->error = X509_V_ERR_KEYUSAGE_NO_CRL_SIGN;
1157
+ if (!call_verify_cb(0, ctx)) {
1158
+ return 0;
1523
1159
  }
1160
+ }
1524
1161
 
1525
- if (!(ctx->current_crl_score & CRL_SCORE_SAME_PATH)) {
1526
- if (check_crl_path(ctx, ctx->current_issuer) <= 0) {
1527
- ctx->error = X509_V_ERR_CRL_PATH_VALIDATION_ERROR;
1528
- ok = ctx->verify_cb(0, ctx);
1529
- if (!ok) {
1530
- goto err;
1531
- }
1532
- }
1162
+ if (!(ctx->current_crl_score & CRL_SCORE_SCOPE)) {
1163
+ ctx->error = X509_V_ERR_DIFFERENT_CRL_SCOPE;
1164
+ if (!call_verify_cb(0, ctx)) {
1165
+ return 0;
1533
1166
  }
1167
+ }
1534
1168
 
1535
- if (crl->idp_flags & IDP_INVALID) {
1536
- ctx->error = X509_V_ERR_INVALID_EXTENSION;
1537
- ok = ctx->verify_cb(0, ctx);
1538
- if (!ok) {
1539
- goto err;
1540
- }
1169
+ if (crl->idp_flags & IDP_INVALID) {
1170
+ ctx->error = X509_V_ERR_INVALID_EXTENSION;
1171
+ if (!call_verify_cb(0, ctx)) {
1172
+ return 0;
1541
1173
  }
1542
1174
  }
1543
1175
 
1544
1176
  if (!(ctx->current_crl_score & CRL_SCORE_TIME)) {
1545
- ok = check_crl_time(ctx, crl, 1);
1546
- if (!ok) {
1547
- goto err;
1177
+ if (!check_crl_time(ctx, crl, 1)) {
1178
+ return 0;
1548
1179
  }
1549
1180
  }
1550
1181
 
1551
1182
  // Attempt to get issuer certificate public key
1552
- ikey = X509_get_pubkey(issuer);
1553
-
1183
+ EVP_PKEY *ikey = X509_get0_pubkey(issuer);
1554
1184
  if (!ikey) {
1555
1185
  ctx->error = X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
1556
- ok = ctx->verify_cb(0, ctx);
1557
- if (!ok) {
1558
- goto err;
1186
+ if (!call_verify_cb(0, ctx)) {
1187
+ return 0;
1559
1188
  }
1560
1189
  } else {
1561
1190
  // Verify CRL signature
1562
1191
  if (X509_CRL_verify(crl, ikey) <= 0) {
1563
1192
  ctx->error = X509_V_ERR_CRL_SIGNATURE_FAILURE;
1564
- ok = ctx->verify_cb(0, ctx);
1565
- if (!ok) {
1566
- goto err;
1193
+ if (!call_verify_cb(0, ctx)) {
1194
+ return 0;
1567
1195
  }
1568
1196
  }
1569
1197
  }
1570
1198
  }
1571
1199
 
1572
- ok = 1;
1573
-
1574
- err:
1575
- EVP_PKEY_free(ikey);
1576
- return ok;
1200
+ return 1;
1577
1201
  }
1578
1202
 
1579
1203
  // Check certificate against CRL
1580
1204
  static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x) {
1581
- int ok;
1582
- X509_REVOKED *rev;
1583
1205
  // The rules changed for this... previously if a CRL contained unhandled
1584
1206
  // critical extensions it could still be used to indicate a certificate
1585
1207
  // was revoked. This has since been changed since critical extension can
@@ -1587,20 +1209,15 @@ static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x) {
1587
1209
  if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL) &&
1588
1210
  (crl->flags & EXFLAG_CRITICAL)) {
1589
1211
  ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION;
1590
- ok = ctx->verify_cb(0, ctx);
1591
- if (!ok) {
1212
+ if (!call_verify_cb(0, ctx)) {
1592
1213
  return 0;
1593
1214
  }
1594
1215
  }
1595
- // Look for serial number of certificate in CRL If found make sure reason
1596
- // is not removeFromCRL.
1216
+ // Look for serial number of certificate in CRL.
1217
+ X509_REVOKED *rev;
1597
1218
  if (X509_CRL_get0_by_cert(crl, &rev, x)) {
1598
- if (rev->reason == CRL_REASON_REMOVE_FROM_CRL) {
1599
- return 2;
1600
- }
1601
1219
  ctx->error = X509_V_ERR_CERT_REVOKED;
1602
- ok = ctx->verify_cb(0, ctx);
1603
- if (!ok) {
1220
+ if (!call_verify_cb(0, ctx)) {
1604
1221
  return 0;
1605
1222
  }
1606
1223
  }
@@ -1609,11 +1226,6 @@ static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x) {
1609
1226
  }
1610
1227
 
1611
1228
  static int check_policy(X509_STORE_CTX *ctx) {
1612
- // TODO(davidben): Why do we disable policy validation for CRL paths?
1613
- if (ctx->parent) {
1614
- return 1;
1615
- }
1616
-
1617
1229
  X509 *current_cert = NULL;
1618
1230
  int ret = X509_policy_check(ctx->chain, ctx->param->policies,
1619
1231
  ctx->param->flags, &current_cert);
@@ -1623,18 +1235,7 @@ static int check_policy(X509_STORE_CTX *ctx) {
1623
1235
  if (ret == X509_V_ERR_OUT_OF_MEM) {
1624
1236
  return 0;
1625
1237
  }
1626
- return ctx->verify_cb(0, ctx);
1627
- }
1628
-
1629
- if (ctx->param->flags & X509_V_FLAG_NOTIFY_POLICY) {
1630
- ctx->current_cert = NULL;
1631
- // Verification errors need to be "sticky", a callback may have allowed
1632
- // an SSL handshake to continue despite an error, and we must then
1633
- // remain in an error state. Therefore, we MUST NOT clear earlier
1634
- // verification errors by setting the error to X509_V_OK.
1635
- if (!ctx->verify_cb(2, ctx)) {
1636
- return 0;
1637
- }
1238
+ return call_verify_cb(0, ctx);
1638
1239
  }
1639
1240
 
1640
1241
  return 1;
@@ -1656,7 +1257,7 @@ static int check_cert_time(X509_STORE_CTX *ctx, X509 *x) {
1656
1257
  if (i == 0) {
1657
1258
  ctx->error = X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;
1658
1259
  ctx->current_cert = x;
1659
- if (!ctx->verify_cb(0, ctx)) {
1260
+ if (!call_verify_cb(0, ctx)) {
1660
1261
  return 0;
1661
1262
  }
1662
1263
  }
@@ -1664,7 +1265,7 @@ static int check_cert_time(X509_STORE_CTX *ctx, X509 *x) {
1664
1265
  if (i > 0) {
1665
1266
  ctx->error = X509_V_ERR_CERT_NOT_YET_VALID;
1666
1267
  ctx->current_cert = x;
1667
- if (!ctx->verify_cb(0, ctx)) {
1268
+ if (!call_verify_cb(0, ctx)) {
1668
1269
  return 0;
1669
1270
  }
1670
1271
  }
@@ -1673,7 +1274,7 @@ static int check_cert_time(X509_STORE_CTX *ctx, X509 *x) {
1673
1274
  if (i == 0) {
1674
1275
  ctx->error = X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;
1675
1276
  ctx->current_cert = x;
1676
- if (!ctx->verify_cb(0, ctx)) {
1277
+ if (!call_verify_cb(0, ctx)) {
1677
1278
  return 0;
1678
1279
  }
1679
1280
  }
@@ -1681,7 +1282,7 @@ static int check_cert_time(X509_STORE_CTX *ctx, X509 *x) {
1681
1282
  if (i < 0) {
1682
1283
  ctx->error = X509_V_ERR_CERT_HAS_EXPIRED;
1683
1284
  ctx->current_cert = x;
1684
- if (!ctx->verify_cb(0, ctx)) {
1285
+ if (!call_verify_cb(0, ctx)) {
1685
1286
  return 0;
1686
1287
  }
1687
1288
  }
@@ -1690,16 +1291,20 @@ static int check_cert_time(X509_STORE_CTX *ctx, X509 *x) {
1690
1291
  }
1691
1292
 
1692
1293
  static int internal_verify(X509_STORE_CTX *ctx) {
1693
- int ok = 0;
1694
- X509 *xs, *xi;
1695
- EVP_PKEY *pkey = NULL;
1696
-
1294
+ // TODO(davidben): This logic is incredibly confusing. Rewrite this:
1295
+ //
1296
+ // First, don't allow the verify callback to suppress
1297
+ // X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY, which will simplify the
1298
+ // signature check. Then replace jumping into the middle of the loop. It's
1299
+ // trying to ensure that all certificates see |check_cert_time|, then checking
1300
+ // the root's self signature when requested, but not breaking partial chains
1301
+ // in the process.
1697
1302
  int n = (int)sk_X509_num(ctx->chain);
1698
1303
  ctx->error_depth = n - 1;
1699
1304
  n--;
1700
- xi = sk_X509_value(ctx->chain, n);
1701
-
1702
- if (ctx->check_issued(ctx, xi, xi)) {
1305
+ X509 *xi = sk_X509_value(ctx->chain, n);
1306
+ X509 *xs;
1307
+ if (x509_check_issued_with_callback(ctx, xi, xi)) {
1703
1308
  xs = xi;
1704
1309
  } else {
1705
1310
  if (ctx->param->flags & X509_V_FLAG_PARTIAL_CHAIN) {
@@ -1709,13 +1314,11 @@ static int internal_verify(X509_STORE_CTX *ctx) {
1709
1314
  if (n <= 0) {
1710
1315
  ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE;
1711
1316
  ctx->current_cert = xi;
1712
- ok = ctx->verify_cb(0, ctx);
1713
- goto end;
1714
- } else {
1715
- n--;
1716
- ctx->error_depth = n;
1717
- xs = sk_X509_value(ctx->chain, n);
1317
+ return call_verify_cb(0, ctx);
1718
1318
  }
1319
+ n--;
1320
+ ctx->error_depth = n;
1321
+ xs = sk_X509_value(ctx->chain, n);
1719
1322
  }
1720
1323
 
1721
1324
  // ctx->error=0; not needed
@@ -1726,38 +1329,31 @@ static int internal_verify(X509_STORE_CTX *ctx) {
1726
1329
  // explicitly asked for. It doesn't add any security and just wastes
1727
1330
  // time.
1728
1331
  if (xs != xi || (ctx->param->flags & X509_V_FLAG_CHECK_SS_SIGNATURE)) {
1729
- if ((pkey = X509_get_pubkey(xi)) == NULL) {
1332
+ EVP_PKEY *pkey = X509_get0_pubkey(xi);
1333
+ if (pkey == NULL) {
1730
1334
  ctx->error = X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY;
1731
1335
  ctx->current_cert = xi;
1732
- ok = ctx->verify_cb(0, ctx);
1733
- if (!ok) {
1734
- goto end;
1336
+ if (!call_verify_cb(0, ctx)) {
1337
+ return 0;
1735
1338
  }
1736
1339
  } else if (X509_verify(xs, pkey) <= 0) {
1737
1340
  ctx->error = X509_V_ERR_CERT_SIGNATURE_FAILURE;
1738
1341
  ctx->current_cert = xs;
1739
- ok = ctx->verify_cb(0, ctx);
1740
- if (!ok) {
1741
- EVP_PKEY_free(pkey);
1742
- goto end;
1342
+ if (!call_verify_cb(0, ctx)) {
1343
+ return 0;
1743
1344
  }
1744
1345
  }
1745
- EVP_PKEY_free(pkey);
1746
- pkey = NULL;
1747
1346
  }
1748
1347
 
1749
1348
  check_cert:
1750
- ok = check_cert_time(ctx, xs);
1751
- if (!ok) {
1752
- goto end;
1349
+ if (!check_cert_time(ctx, xs)) {
1350
+ return 0;
1753
1351
  }
1754
1352
 
1755
1353
  // The last error (if any) is still in the error value
1756
- ctx->current_issuer = xi;
1757
1354
  ctx->current_cert = xs;
1758
- ok = ctx->verify_cb(1, ctx);
1759
- if (!ok) {
1760
- goto end;
1355
+ if (!call_verify_cb(1, ctx)) {
1356
+ return 0;
1761
1357
  }
1762
1358
 
1763
1359
  n--;
@@ -1766,9 +1362,8 @@ static int internal_verify(X509_STORE_CTX *ctx) {
1766
1362
  xs = sk_X509_value(ctx->chain, n);
1767
1363
  }
1768
1364
  }
1769
- ok = 1;
1770
- end:
1771
- return ok;
1365
+
1366
+ return 1;
1772
1367
  }
1773
1368
 
1774
1369
  int X509_cmp_current_time(const ASN1_TIME *ctm) {
@@ -1810,117 +1405,6 @@ ASN1_TIME *X509_time_adj_ex(ASN1_TIME *s, int offset_day, long offset_sec,
1810
1405
  return ASN1_TIME_adj(s, t, offset_day, offset_sec);
1811
1406
  }
1812
1407
 
1813
- // Make a delta CRL as the diff between two full CRLs
1814
-
1815
- X509_CRL *X509_CRL_diff(X509_CRL *base, X509_CRL *newer, EVP_PKEY *skey,
1816
- const EVP_MD *md, unsigned int flags) {
1817
- X509_CRL *crl = NULL;
1818
- int i;
1819
- size_t j;
1820
- STACK_OF(X509_REVOKED) *revs = NULL;
1821
- // CRLs can't be delta already
1822
- if (base->base_crl_number || newer->base_crl_number) {
1823
- OPENSSL_PUT_ERROR(X509, X509_R_CRL_ALREADY_DELTA);
1824
- return NULL;
1825
- }
1826
- // Base and new CRL must have a CRL number
1827
- if (!base->crl_number || !newer->crl_number) {
1828
- OPENSSL_PUT_ERROR(X509, X509_R_NO_CRL_NUMBER);
1829
- return NULL;
1830
- }
1831
- // Issuer names must match
1832
- if (X509_NAME_cmp(X509_CRL_get_issuer(base), X509_CRL_get_issuer(newer))) {
1833
- OPENSSL_PUT_ERROR(X509, X509_R_ISSUER_MISMATCH);
1834
- return NULL;
1835
- }
1836
- // AKID and IDP must match
1837
- if (!crl_extension_match(base, newer, NID_authority_key_identifier)) {
1838
- OPENSSL_PUT_ERROR(X509, X509_R_AKID_MISMATCH);
1839
- return NULL;
1840
- }
1841
- if (!crl_extension_match(base, newer, NID_issuing_distribution_point)) {
1842
- OPENSSL_PUT_ERROR(X509, X509_R_IDP_MISMATCH);
1843
- return NULL;
1844
- }
1845
- // Newer CRL number must exceed full CRL number
1846
- if (ASN1_INTEGER_cmp(newer->crl_number, base->crl_number) <= 0) {
1847
- OPENSSL_PUT_ERROR(X509, X509_R_NEWER_CRL_NOT_NEWER);
1848
- return NULL;
1849
- }
1850
- // CRLs must verify
1851
- if (skey &&
1852
- (X509_CRL_verify(base, skey) <= 0 || X509_CRL_verify(newer, skey) <= 0)) {
1853
- OPENSSL_PUT_ERROR(X509, X509_R_CRL_VERIFY_FAILURE);
1854
- return NULL;
1855
- }
1856
- // Create new CRL
1857
- crl = X509_CRL_new();
1858
- if (!crl || !X509_CRL_set_version(crl, X509_CRL_VERSION_2)) {
1859
- goto memerr;
1860
- }
1861
- // Set issuer name
1862
- if (!X509_CRL_set_issuer_name(crl, X509_CRL_get_issuer(newer))) {
1863
- goto memerr;
1864
- }
1865
-
1866
- if (!X509_CRL_set1_lastUpdate(crl, X509_CRL_get0_lastUpdate(newer))) {
1867
- goto memerr;
1868
- }
1869
- if (!X509_CRL_set1_nextUpdate(crl, X509_CRL_get0_nextUpdate(newer))) {
1870
- goto memerr;
1871
- }
1872
-
1873
- // Set base CRL number: must be critical
1874
-
1875
- if (!X509_CRL_add1_ext_i2d(crl, NID_delta_crl, base->crl_number, 1, 0)) {
1876
- goto memerr;
1877
- }
1878
-
1879
- // Copy extensions across from newest CRL to delta: this will set CRL
1880
- // number to correct value too.
1881
-
1882
- for (i = 0; i < X509_CRL_get_ext_count(newer); i++) {
1883
- const X509_EXTENSION *ext = X509_CRL_get_ext(newer, i);
1884
- if (!X509_CRL_add_ext(crl, ext, -1)) {
1885
- goto memerr;
1886
- }
1887
- }
1888
-
1889
- // Go through revoked entries, copying as needed
1890
-
1891
- revs = X509_CRL_get_REVOKED(newer);
1892
-
1893
- for (j = 0; j < sk_X509_REVOKED_num(revs); j++) {
1894
- X509_REVOKED *rvn, *rvtmp;
1895
- rvn = sk_X509_REVOKED_value(revs, j);
1896
- // Add only if not also in base. TODO: need something cleverer here
1897
- // for some more complex CRLs covering multiple CAs.
1898
- if (!X509_CRL_get0_by_serial(base, &rvtmp, rvn->serialNumber)) {
1899
- rvtmp = X509_REVOKED_dup(rvn);
1900
- if (!rvtmp) {
1901
- goto memerr;
1902
- }
1903
- if (!X509_CRL_add0_revoked(crl, rvtmp)) {
1904
- X509_REVOKED_free(rvtmp);
1905
- goto memerr;
1906
- }
1907
- }
1908
- }
1909
- // TODO: optionally prune deleted entries
1910
-
1911
- if (skey && md && !X509_CRL_sign(crl, skey, md)) {
1912
- goto memerr;
1913
- }
1914
-
1915
- return crl;
1916
-
1917
- memerr:
1918
- if (crl) {
1919
- X509_CRL_free(crl);
1920
- }
1921
- return NULL;
1922
- }
1923
-
1924
1408
  int X509_STORE_CTX_get_ex_new_index(long argl, void *argp,
1925
1409
  CRYPTO_EX_unused *unused,
1926
1410
  CRYPTO_EX_dup *dup_unused,
@@ -1943,54 +1427,51 @@ void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx) {
1943
1427
  return CRYPTO_get_ex_data(&ctx->ex_data, idx);
1944
1428
  }
1945
1429
 
1946
- int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx) { return ctx->error; }
1430
+ int X509_STORE_CTX_get_error(const X509_STORE_CTX *ctx) { return ctx->error; }
1947
1431
 
1948
1432
  void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int err) {
1949
1433
  ctx->error = err;
1950
1434
  }
1951
1435
 
1952
- int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx) {
1436
+ int X509_STORE_CTX_get_error_depth(const X509_STORE_CTX *ctx) {
1953
1437
  return ctx->error_depth;
1954
1438
  }
1955
1439
 
1956
- X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx) {
1440
+ X509 *X509_STORE_CTX_get_current_cert(const X509_STORE_CTX *ctx) {
1957
1441
  return ctx->current_cert;
1958
1442
  }
1959
1443
 
1960
- STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx) {
1444
+ STACK_OF(X509) *X509_STORE_CTX_get_chain(const X509_STORE_CTX *ctx) {
1961
1445
  return ctx->chain;
1962
1446
  }
1963
1447
 
1964
- STACK_OF(X509) *X509_STORE_CTX_get0_chain(X509_STORE_CTX *ctx) {
1448
+ STACK_OF(X509) *X509_STORE_CTX_get0_chain(const X509_STORE_CTX *ctx) {
1965
1449
  return ctx->chain;
1966
1450
  }
1967
1451
 
1968
- STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx) {
1452
+ STACK_OF(X509) *X509_STORE_CTX_get1_chain(const X509_STORE_CTX *ctx) {
1969
1453
  if (!ctx->chain) {
1970
1454
  return NULL;
1971
1455
  }
1972
1456
  return X509_chain_up_ref(ctx->chain);
1973
1457
  }
1974
1458
 
1975
- X509 *X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx) {
1976
- return ctx->current_issuer;
1977
- }
1978
-
1979
- X509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx) {
1459
+ X509_CRL *X509_STORE_CTX_get0_current_crl(const X509_STORE_CTX *ctx) {
1980
1460
  return ctx->current_crl;
1981
1461
  }
1982
1462
 
1983
- X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(X509_STORE_CTX *ctx) {
1984
- return ctx->parent;
1463
+ X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(const X509_STORE_CTX *ctx) {
1464
+ // In OpenSSL, an |X509_STORE_CTX| sometimes has a parent context during CRL
1465
+ // path validation for indirect CRLs. We require the CRL to be issued
1466
+ // somewhere along the certificate path, so this is always NULL.
1467
+ return NULL;
1985
1468
  }
1986
1469
 
1987
- void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x) { ctx->cert = x; }
1988
-
1989
1470
  void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk) {
1990
1471
  ctx->untrusted = sk;
1991
1472
  }
1992
1473
 
1993
- STACK_OF(X509) *X509_STORE_CTX_get0_untrusted(X509_STORE_CTX *ctx) {
1474
+ STACK_OF(X509) *X509_STORE_CTX_get0_untrusted(const X509_STORE_CTX *ctx) {
1994
1475
  return ctx->untrusted;
1995
1476
  }
1996
1477
 
@@ -1999,80 +1480,47 @@ void X509_STORE_CTX_set0_crls(X509_STORE_CTX *ctx, STACK_OF(X509_CRL) *sk) {
1999
1480
  }
2000
1481
 
2001
1482
  int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose) {
2002
- return X509_STORE_CTX_purpose_inherit(ctx, 0, purpose, 0);
2003
- }
1483
+ // If |purpose| is zero, this function historically silently did nothing.
1484
+ if (purpose == 0) {
1485
+ return 1;
1486
+ }
2004
1487
 
2005
- int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust) {
2006
- return X509_STORE_CTX_purpose_inherit(ctx, 0, 0, trust);
2007
- }
2008
-
2009
- // This function is used to set the X509_STORE_CTX purpose and trust values.
2010
- // This is intended to be used when another structure has its own trust and
2011
- // purpose values which (if set) will be inherited by the ctx. If they aren't
2012
- // set then we will usually have a default purpose in mind which should then
2013
- // be used to set the trust value. An example of this is SSL use: an SSL
2014
- // structure will have its own purpose and trust settings which the
2015
- // application can set: if they aren't set then we use the default of SSL
2016
- // client/server.
2017
-
2018
- int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
2019
- int purpose, int trust) {
2020
- int idx;
2021
- // If purpose not set use default
2022
- if (!purpose) {
2023
- purpose = def_purpose;
2024
- }
2025
- // If we have a purpose then check it is valid
2026
- if (purpose) {
2027
- X509_PURPOSE *ptmp;
2028
- idx = X509_PURPOSE_get_by_id(purpose);
2029
- if (idx == -1) {
2030
- OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_PURPOSE_ID);
2031
- return 0;
2032
- }
2033
- ptmp = X509_PURPOSE_get0(idx);
2034
- if (ptmp->trust == X509_TRUST_DEFAULT) {
2035
- idx = X509_PURPOSE_get_by_id(def_purpose);
2036
- if (idx == -1) {
2037
- OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_PURPOSE_ID);
2038
- return 0;
2039
- }
2040
- ptmp = X509_PURPOSE_get0(idx);
2041
- }
2042
- // If trust not set then get from purpose default
2043
- if (!trust) {
2044
- trust = ptmp->trust;
2045
- }
1488
+ int idx = X509_PURPOSE_get_by_id(purpose);
1489
+ if (idx == -1) {
1490
+ OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_PURPOSE_ID);
1491
+ return 0;
2046
1492
  }
2047
- if (trust) {
2048
- idx = X509_TRUST_get_by_id(trust);
2049
- if (idx == -1) {
2050
- OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_TRUST_ID);
2051
- return 0;
2052
- }
1493
+
1494
+ int trust = X509_PURPOSE_get_trust(X509_PURPOSE_get0(idx));
1495
+ if (!X509_STORE_CTX_set_trust(ctx, trust)) {
1496
+ return 0;
2053
1497
  }
2054
1498
 
2055
- if (purpose && !ctx->param->purpose) {
1499
+ if (ctx->param->purpose == 0) {
2056
1500
  ctx->param->purpose = purpose;
2057
1501
  }
2058
- if (trust && !ctx->param->trust) {
2059
- ctx->param->trust = trust;
2060
- }
2061
1502
  return 1;
2062
1503
  }
2063
1504
 
2064
- X509_STORE_CTX *X509_STORE_CTX_new(void) {
2065
- X509_STORE_CTX *ctx;
2066
- ctx = (X509_STORE_CTX *)OPENSSL_malloc(sizeof(X509_STORE_CTX));
2067
- if (!ctx) {
2068
- return NULL;
1505
+ int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust) {
1506
+ // If |trust| is zero, this function historically silently did nothing.
1507
+ if (trust == 0) {
1508
+ return 1;
1509
+ }
1510
+
1511
+ if (X509_TRUST_get_by_id(trust) == -1) {
1512
+ OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_TRUST_ID);
1513
+ return 0;
2069
1514
  }
2070
- X509_STORE_CTX_zero(ctx);
2071
- return ctx;
1515
+
1516
+ if (ctx->param->trust == 0) {
1517
+ ctx->param->trust = trust;
1518
+ }
1519
+ return 1;
2072
1520
  }
2073
1521
 
2074
- void X509_STORE_CTX_zero(X509_STORE_CTX *ctx) {
2075
- OPENSSL_memset(ctx, 0, sizeof(X509_STORE_CTX));
1522
+ X509_STORE_CTX *X509_STORE_CTX_new(void) {
1523
+ return OPENSSL_zalloc(sizeof(X509_STORE_CTX));
2076
1524
  }
2077
1525
 
2078
1526
  void X509_STORE_CTX_free(X509_STORE_CTX *ctx) {
@@ -2085,7 +1533,8 @@ void X509_STORE_CTX_free(X509_STORE_CTX *ctx) {
2085
1533
 
2086
1534
  int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
2087
1535
  STACK_OF(X509) *chain) {
2088
- X509_STORE_CTX_zero(ctx);
1536
+ X509_STORE_CTX_cleanup(ctx);
1537
+
2089
1538
  ctx->ctx = store;
2090
1539
  ctx->cert = x509;
2091
1540
  ctx->untrusted = chain;
@@ -2105,7 +1554,6 @@ int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
2105
1554
  // Inherit callbacks and flags from X509_STORE.
2106
1555
 
2107
1556
  ctx->verify_cb = store->verify_cb;
2108
- ctx->cleanup = store->cleanup;
2109
1557
 
2110
1558
  if (!X509_VERIFY_PARAM_inherit(ctx->param, store->param) ||
2111
1559
  !X509_VERIFY_PARAM_inherit(ctx->param,
@@ -2113,40 +1561,16 @@ int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
2113
1561
  goto err;
2114
1562
  }
2115
1563
 
2116
- if (store->check_issued) {
2117
- ctx->check_issued = store->check_issued;
2118
- } else {
2119
- ctx->check_issued = check_issued;
2120
- }
2121
-
2122
- if (store->get_issuer) {
2123
- ctx->get_issuer = store->get_issuer;
2124
- } else {
2125
- ctx->get_issuer = X509_STORE_CTX_get1_issuer;
2126
- }
2127
-
2128
1564
  if (store->verify_cb) {
2129
1565
  ctx->verify_cb = store->verify_cb;
2130
1566
  } else {
2131
1567
  ctx->verify_cb = null_callback;
2132
1568
  }
2133
1569
 
2134
- if (store->verify) {
2135
- ctx->verify = store->verify;
2136
- } else {
2137
- ctx->verify = internal_verify;
2138
- }
2139
-
2140
- if (store->check_revocation) {
2141
- ctx->check_revocation = store->check_revocation;
2142
- } else {
2143
- ctx->check_revocation = check_revocation;
2144
- }
2145
-
2146
1570
  if (store->get_crl) {
2147
1571
  ctx->get_crl = store->get_crl;
2148
1572
  } else {
2149
- ctx->get_crl = NULL;
1573
+ ctx->get_crl = get_crl;
2150
1574
  }
2151
1575
 
2152
1576
  if (store->check_crl) {
@@ -2155,26 +1579,6 @@ int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
2155
1579
  ctx->check_crl = check_crl;
2156
1580
  }
2157
1581
 
2158
- if (store->cert_crl) {
2159
- ctx->cert_crl = store->cert_crl;
2160
- } else {
2161
- ctx->cert_crl = cert_crl;
2162
- }
2163
-
2164
- if (store->lookup_certs) {
2165
- ctx->lookup_certs = store->lookup_certs;
2166
- } else {
2167
- ctx->lookup_certs = X509_STORE_get1_certs;
2168
- }
2169
-
2170
- if (store->lookup_crls) {
2171
- ctx->lookup_crls = store->lookup_crls;
2172
- } else {
2173
- ctx->lookup_crls = X509_STORE_get1_crls;
2174
- }
2175
-
2176
- ctx->check_policy = check_policy;
2177
-
2178
1582
  return 1;
2179
1583
 
2180
1584
  err:
@@ -2192,8 +1596,7 @@ err:
2192
1596
 
2193
1597
  void X509_STORE_CTX_set0_trusted_stack(X509_STORE_CTX *ctx,
2194
1598
  STACK_OF(X509) *sk) {
2195
- ctx->other_ctx = sk;
2196
- ctx->get_issuer = get_issuer_sk;
1599
+ ctx->trusted_stack = sk;
2197
1600
  }
2198
1601
 
2199
1602
  void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk) {
@@ -2201,24 +1604,10 @@ void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk) {
2201
1604
  }
2202
1605
 
2203
1606
  void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx) {
2204
- // We need to be idempotent because, unfortunately, |X509_STORE_CTX_free|
2205
- // also calls this function.
2206
- if (ctx->cleanup != NULL) {
2207
- ctx->cleanup(ctx);
2208
- ctx->cleanup = NULL;
2209
- }
2210
- if (ctx->param != NULL) {
2211
- if (ctx->parent == NULL) {
2212
- X509_VERIFY_PARAM_free(ctx->param);
2213
- }
2214
- ctx->param = NULL;
2215
- }
2216
- if (ctx->chain != NULL) {
2217
- sk_X509_pop_free(ctx->chain, X509_free);
2218
- ctx->chain = NULL;
2219
- }
2220
1607
  CRYPTO_free_ex_data(&g_ex_data_class, ctx, &(ctx->ex_data));
2221
- OPENSSL_memset(&ctx->ex_data, 0, sizeof(CRYPTO_EX_DATA));
1608
+ X509_VERIFY_PARAM_free(ctx->param);
1609
+ sk_X509_pop_free(ctx->chain, X509_free);
1610
+ OPENSSL_memset(ctx, 0, sizeof(X509_STORE_CTX));
2222
1611
  }
2223
1612
 
2224
1613
  void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth) {
@@ -2230,7 +1619,7 @@ void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags) {
2230
1619
  }
2231
1620
 
2232
1621
  void X509_STORE_CTX_set_time_posix(X509_STORE_CTX *ctx, unsigned long flags,
2233
- int64_t t) {
1622
+ int64_t t) {
2234
1623
  X509_VERIFY_PARAM_set_time_posix(ctx->param, t);
2235
1624
  }
2236
1625
 
@@ -2239,9 +1628,7 @@ void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags,
2239
1628
  X509_STORE_CTX_set_time_posix(ctx, flags, t);
2240
1629
  }
2241
1630
 
2242
- X509 *X509_STORE_CTX_get0_cert(X509_STORE_CTX *ctx) {
2243
- return ctx->cert;
2244
- }
1631
+ X509 *X509_STORE_CTX_get0_cert(const X509_STORE_CTX *ctx) { return ctx->cert; }
2245
1632
 
2246
1633
  void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
2247
1634
  int (*verify_cb)(int, X509_STORE_CTX *)) {
@@ -2249,8 +1636,7 @@ void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
2249
1636
  }
2250
1637
 
2251
1638
  int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name) {
2252
- const X509_VERIFY_PARAM *param;
2253
- param = X509_VERIFY_PARAM_lookup(name);
1639
+ const X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_lookup(name);
2254
1640
  if (!param) {
2255
1641
  return 0;
2256
1642
  }