grpc 1.55.0 → 1.56.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (395) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +102 -68
  3. data/include/grpc/event_engine/event_engine.h +4 -3
  4. data/include/grpc/grpc_audit_logging.h +96 -0
  5. data/include/grpc/grpc_security.h +19 -0
  6. data/include/grpc/module.modulemap +2 -0
  7. data/include/grpc/support/json.h +218 -0
  8. data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +5 -0
  9. data/src/core/ext/filters/client_channel/backend_metric.cc +2 -0
  10. data/src/core/ext/filters/client_channel/channel_connectivity.cc +4 -4
  11. data/src/core/ext/filters/client_channel/client_channel.cc +86 -104
  12. data/src/core/ext/filters/client_channel/client_channel.h +6 -0
  13. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +19 -18
  14. data/src/core/ext/filters/client_channel/client_channel_internal.h +16 -21
  15. data/src/core/ext/filters/client_channel/config_selector.h +9 -24
  16. data/src/core/ext/filters/client_channel/lb_policy/backend_metric_data.h +3 -0
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +5 -4
  18. data/src/core/ext/filters/client_channel/lb_policy/health_check_client.cc +455 -0
  19. data/src/core/ext/filters/client_channel/lb_policy/health_check_client.h +54 -0
  20. data/src/core/ext/filters/client_channel/lb_policy/health_check_client_internal.h +186 -0
  21. data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.cc +2 -7
  22. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +53 -21
  23. data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.h +23 -2
  24. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +19 -6
  25. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +1 -9
  26. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +16 -7
  27. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +18 -1
  28. data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +12 -9
  29. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +6 -4
  30. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +36 -13
  31. data/src/core/ext/filters/client_channel/lb_policy/weighted_round_robin/static_stride_scheduler.cc +76 -6
  32. data/src/core/ext/filters/client_channel/lb_policy/weighted_round_robin/weighted_round_robin.cc +42 -40
  33. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +4 -10
  34. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +52 -47
  35. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +1 -9
  36. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +14 -16
  37. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +40 -43
  38. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_override_host.cc +7 -12
  39. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc +12 -19
  40. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +35 -33
  41. data/src/core/ext/filters/client_channel/resolver/dns/event_engine/event_engine_client_channel_resolver.cc +29 -4
  42. data/src/core/ext/filters/client_channel/resolver/dns/event_engine/service_config_helper.cc +1 -1
  43. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +28 -27
  44. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +163 -46
  45. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.h +16 -1
  46. data/src/core/ext/filters/client_channel/retry_service_config.cc +1 -0
  47. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +10 -40
  48. data/src/core/ext/filters/client_channel/subchannel.cc +10 -196
  49. data/src/core/ext/filters/client_channel/subchannel.h +3 -43
  50. data/src/core/ext/filters/http/message_compress/compression_filter.cc +5 -5
  51. data/src/core/ext/filters/rbac/rbac_service_config_parser.cc +100 -6
  52. data/src/core/ext/filters/server_config_selector/server_config_selector_filter.cc +6 -8
  53. data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +3 -3
  54. data/src/core/ext/filters/stateful_session/stateful_session_filter.h +16 -1
  55. data/src/core/ext/transport/chttp2/transport/flow_control.cc +46 -95
  56. data/src/core/ext/transport/chttp2/transport/hpack_parse_result.cc +176 -0
  57. data/src/core/ext/transport/chttp2/transport/hpack_parse_result.h +325 -0
  58. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +567 -543
  59. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +150 -9
  60. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +46 -32
  61. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +18 -5
  62. data/src/core/ext/transport/chttp2/transport/internal.h +1 -15
  63. data/src/core/ext/transport/chttp2/transport/parsing.cc +12 -12
  64. data/src/core/ext/upb-generated/xds/data/orca/v3/orca_load_report.upb.c +11 -2
  65. data/src/core/ext/upb-generated/xds/data/orca/v3/orca_load_report.upb.h +15 -0
  66. data/src/core/ext/xds/certificate_provider_store.cc +4 -9
  67. data/src/core/ext/xds/certificate_provider_store.h +1 -1
  68. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +30 -42
  69. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +14 -9
  70. data/src/core/ext/xds/xds_api.cc +9 -6
  71. data/src/core/ext/xds/xds_api.h +3 -2
  72. data/src/core/ext/xds/xds_audit_logger_registry.cc +122 -0
  73. data/src/core/ext/xds/xds_audit_logger_registry.h +68 -0
  74. data/src/core/ext/xds/xds_bootstrap_grpc.cc +21 -9
  75. data/src/core/ext/xds/xds_bootstrap_grpc.h +5 -0
  76. data/src/core/ext/xds/xds_client.cc +5 -4
  77. data/src/core/ext/xds/xds_client_stats.h +1 -1
  78. data/src/core/ext/xds/xds_cluster.cc +20 -19
  79. data/src/core/ext/xds/xds_cluster_specifier_plugin.cc +11 -8
  80. data/src/core/ext/xds/xds_common_types.cc +3 -1
  81. data/src/core/ext/xds/xds_http_fault_filter.cc +16 -13
  82. data/src/core/ext/xds/xds_http_fault_filter.h +2 -1
  83. data/src/core/ext/xds/xds_http_filters.h +4 -2
  84. data/src/core/ext/xds/xds_http_rbac_filter.cc +154 -67
  85. data/src/core/ext/xds/xds_http_rbac_filter.h +2 -1
  86. data/src/core/ext/xds/xds_http_stateful_session_filter.cc +15 -11
  87. data/src/core/ext/xds/xds_http_stateful_session_filter.h +2 -1
  88. data/src/core/ext/xds/xds_lb_policy_registry.cc +22 -16
  89. data/src/core/ext/xds/xds_listener.cc +1 -0
  90. data/src/core/ext/xds/xds_route_config.cc +40 -3
  91. data/src/core/ext/xds/xds_routing.cc +2 -2
  92. data/src/core/ext/xds/xds_transport_grpc.cc +3 -1
  93. data/src/core/lib/avl/avl.h +5 -0
  94. data/src/core/lib/backoff/random_early_detection.h +5 -0
  95. data/src/core/lib/channel/channel_args.cc +80 -22
  96. data/src/core/lib/channel/channel_args.h +34 -1
  97. data/src/core/lib/channel/channel_trace.cc +16 -12
  98. data/src/core/lib/channel/channelz.cc +159 -132
  99. data/src/core/lib/channel/channelz.h +42 -35
  100. data/src/core/lib/channel/channelz_registry.cc +23 -20
  101. data/src/core/lib/channel/connected_channel.cc +17 -6
  102. data/src/core/lib/channel/promise_based_filter.cc +0 -4
  103. data/src/core/lib/channel/promise_based_filter.h +2 -0
  104. data/src/core/lib/compression/compression_internal.cc +2 -5
  105. data/src/core/lib/config/config_vars.cc +20 -18
  106. data/src/core/lib/config/config_vars.h +4 -4
  107. data/src/core/lib/config/load_config.cc +13 -0
  108. data/src/core/lib/config/load_config.h +6 -0
  109. data/src/core/lib/debug/event_log.h +1 -1
  110. data/src/core/lib/debug/stats_data.h +1 -1
  111. data/src/core/lib/debug/trace.cc +24 -55
  112. data/src/core/lib/debug/trace.h +3 -1
  113. data/src/core/lib/event_engine/cf_engine/cf_engine.cc +211 -0
  114. data/src/core/lib/event_engine/cf_engine/cf_engine.h +86 -0
  115. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +354 -0
  116. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.h +146 -0
  117. data/src/core/lib/event_engine/cf_engine/cftype_unique_ref.h +79 -0
  118. data/src/core/lib/event_engine/default_event_engine.cc +13 -1
  119. data/src/core/lib/event_engine/default_event_engine_factory.cc +14 -2
  120. data/src/core/lib/event_engine/poller.h +2 -2
  121. data/src/core/lib/event_engine/posix.h +4 -0
  122. data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +1 -1
  123. data/src/core/lib/event_engine/posix_engine/lockfree_event.cc +7 -18
  124. data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +9 -0
  125. data/src/core/lib/event_engine/posix_engine/posix_engine.cc +33 -19
  126. data/src/core/lib/event_engine/posix_engine/posix_engine.h +2 -1
  127. data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +33 -4
  128. data/src/core/lib/event_engine/posix_engine/posix_engine_listener.h +10 -8
  129. data/src/core/lib/event_engine/posix_engine/timer_manager.h +1 -1
  130. data/src/core/lib/event_engine/shim.cc +7 -1
  131. data/src/core/lib/event_engine/{thread_pool.cc → thread_pool/original_thread_pool.cc} +28 -25
  132. data/src/core/lib/event_engine/{thread_pool.h → thread_pool/original_thread_pool.h} +11 -15
  133. data/src/core/lib/event_engine/thread_pool/thread_pool.h +50 -0
  134. data/src/core/lib/event_engine/{executor/executor.h → thread_pool/thread_pool_factory.cc} +17 -15
  135. data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.cc +489 -0
  136. data/src/core/lib/event_engine/thread_pool/work_stealing_thread_pool.h +249 -0
  137. data/src/core/lib/event_engine/thready_event_engine/thready_event_engine.cc +166 -0
  138. data/src/core/lib/event_engine/thready_event_engine/thready_event_engine.h +108 -0
  139. data/src/core/lib/event_engine/windows/iocp.cc +4 -3
  140. data/src/core/lib/event_engine/windows/iocp.h +3 -3
  141. data/src/core/lib/event_engine/windows/win_socket.cc +6 -6
  142. data/src/core/lib/event_engine/windows/win_socket.h +4 -4
  143. data/src/core/lib/event_engine/windows/windows_endpoint.cc +11 -10
  144. data/src/core/lib/event_engine/windows/windows_endpoint.h +3 -2
  145. data/src/core/lib/event_engine/windows/windows_engine.cc +19 -17
  146. data/src/core/lib/event_engine/windows/windows_engine.h +6 -6
  147. data/src/core/lib/event_engine/windows/windows_listener.cc +3 -3
  148. data/src/core/lib/event_engine/windows/windows_listener.h +3 -2
  149. data/src/core/lib/event_engine/work_queue/basic_work_queue.cc +63 -0
  150. data/src/core/lib/event_engine/work_queue/basic_work_queue.h +71 -0
  151. data/src/core/lib/event_engine/work_queue/work_queue.h +62 -0
  152. data/src/core/lib/experiments/config.cc +38 -7
  153. data/src/core/lib/experiments/config.h +16 -0
  154. data/src/core/lib/experiments/experiments.cc +67 -20
  155. data/src/core/lib/experiments/experiments.h +27 -21
  156. data/src/core/lib/gpr/log_internal.h +55 -0
  157. data/src/core/lib/gprpp/crash.cc +10 -0
  158. data/src/core/lib/gprpp/crash.h +3 -0
  159. data/src/core/lib/gprpp/per_cpu.cc +33 -0
  160. data/src/core/lib/gprpp/per_cpu.h +29 -6
  161. data/src/core/lib/gprpp/time.cc +1 -0
  162. data/src/core/lib/iomgr/cfstream_handle.cc +1 -1
  163. data/src/core/lib/iomgr/endpoint_cfstream.cc +10 -8
  164. data/src/core/lib/iomgr/ev_apple.cc +12 -12
  165. data/src/core/lib/iomgr/ev_epoll1_linux.cc +10 -3
  166. data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +15 -1
  167. data/src/core/lib/iomgr/iocp_windows.cc +24 -3
  168. data/src/core/lib/iomgr/iocp_windows.h +11 -0
  169. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +1 -1
  170. data/src/core/lib/iomgr/socket_utils_common_posix.cc +4 -2
  171. data/src/core/lib/iomgr/socket_windows.cc +61 -7
  172. data/src/core/lib/iomgr/socket_windows.h +9 -2
  173. data/src/core/lib/iomgr/tcp_client_cfstream.cc +14 -3
  174. data/src/core/lib/iomgr/tcp_server_posix.cc +182 -119
  175. data/src/core/lib/iomgr/tcp_server_utils_posix.h +13 -1
  176. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +21 -0
  177. data/src/core/lib/iomgr/tcp_server_windows.cc +1 -1
  178. data/src/core/lib/json/json.h +2 -166
  179. data/src/core/lib/json/json_object_loader.cc +8 -9
  180. data/src/core/lib/json/json_object_loader.h +25 -18
  181. data/src/core/lib/json/json_reader.cc +13 -6
  182. data/src/core/lib/json/json_util.cc +6 -11
  183. data/src/core/lib/json/json_writer.cc +7 -8
  184. data/src/core/lib/load_balancing/lb_policy.h +13 -0
  185. data/src/core/lib/load_balancing/lb_policy_registry.cc +2 -1
  186. data/src/core/lib/matchers/matchers.cc +3 -4
  187. data/src/core/lib/matchers/matchers.h +2 -1
  188. data/src/core/lib/promise/activity.cc +5 -0
  189. data/src/core/lib/promise/activity.h +10 -0
  190. data/src/core/lib/promise/detail/promise_factory.h +1 -1
  191. data/src/core/lib/promise/party.cc +31 -13
  192. data/src/core/lib/promise/party.h +11 -2
  193. data/src/core/lib/promise/pipe.h +9 -2
  194. data/src/core/lib/promise/prioritized_race.h +95 -0
  195. data/src/core/lib/promise/sleep.cc +2 -1
  196. data/src/core/lib/resolver/server_address.cc +0 -8
  197. data/src/core/lib/resolver/server_address.h +0 -6
  198. data/src/core/lib/resource_quota/memory_quota.cc +7 -7
  199. data/src/core/lib/resource_quota/memory_quota.h +1 -2
  200. data/src/core/lib/security/authorization/audit_logging.cc +98 -0
  201. data/src/core/lib/security/authorization/audit_logging.h +73 -0
  202. data/src/core/lib/security/authorization/grpc_authorization_engine.cc +47 -2
  203. data/src/core/lib/security/authorization/grpc_authorization_engine.h +18 -1
  204. data/src/core/lib/security/authorization/rbac_policy.cc +36 -4
  205. data/src/core/lib/security/authorization/rbac_policy.h +19 -2
  206. data/src/core/lib/security/authorization/stdout_logger.cc +75 -0
  207. data/src/core/lib/security/authorization/stdout_logger.h +61 -0
  208. data/src/core/lib/security/certificate_provider/certificate_provider_factory.h +8 -4
  209. data/src/core/lib/security/certificate_provider/certificate_provider_registry.cc +8 -18
  210. data/src/core/lib/security/certificate_provider/certificate_provider_registry.h +14 -8
  211. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +19 -12
  212. data/src/core/lib/security/credentials/external/external_account_credentials.cc +4 -2
  213. data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +1 -0
  214. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +1 -0
  215. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +1 -0
  216. data/src/core/lib/security/credentials/jwt/json_token.cc +15 -14
  217. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +4 -2
  218. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +1 -0
  219. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -0
  220. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +8 -0
  221. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +5 -1
  222. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +1 -5
  223. data/src/core/lib/security/security_connector/ssl_utils.cc +2 -1
  224. data/src/core/lib/security/security_connector/ssl_utils.h +1 -1
  225. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +1 -1
  226. data/src/core/lib/security/util/json_util.cc +1 -0
  227. data/src/core/lib/service_config/service_config_call_data.h +49 -20
  228. data/src/core/lib/service_config/service_config_impl.cc +2 -1
  229. data/src/core/lib/surface/call.cc +38 -23
  230. data/src/core/lib/surface/completion_queue.cc +6 -2
  231. data/src/core/lib/surface/validate_metadata.cc +37 -22
  232. data/src/core/lib/surface/validate_metadata.h +13 -3
  233. data/src/core/lib/surface/version.cc +2 -2
  234. data/src/core/lib/transport/batch_builder.cc +15 -12
  235. data/src/core/lib/transport/batch_builder.h +39 -35
  236. data/src/core/plugin_registry/grpc_plugin_registry.cc +0 -2
  237. data/src/core/plugin_registry/grpc_plugin_registry_extra.cc +2 -0
  238. data/src/core/tsi/ssl_transport_security.cc +5 -2
  239. data/src/core/tsi/ssl_transport_security.h +13 -1
  240. data/src/ruby/ext/grpc/extconf.rb +8 -9
  241. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
  242. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
  243. data/src/ruby/lib/grpc/version.rb +1 -1
  244. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_mbstr.c +9 -8
  245. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_strnid.c +1 -1
  246. data/third_party/boringssl-with-bazel/src/crypto/asn1/internal.h +3 -3
  247. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_dec.c +10 -6
  248. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +7 -4
  249. data/third_party/boringssl-with-bazel/src/crypto/bio/bio.c +6 -4
  250. data/third_party/boringssl-with-bazel/src/crypto/bio/fd.c +2 -1
  251. data/third_party/boringssl-with-bazel/src/crypto/bio/file.c +5 -9
  252. data/third_party/boringssl-with-bazel/src/crypto/bio/pair.c +4 -2
  253. data/third_party/boringssl-with-bazel/src/crypto/blake2/blake2.c +31 -22
  254. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/e_tls.c +29 -26
  255. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/internal.h +8 -0
  256. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/tls_cbc.c +189 -13
  257. data/third_party/boringssl-with-bazel/src/crypto/cpu_aarch64_openbsd.c +62 -0
  258. data/third_party/boringssl-with-bazel/src/crypto/cpu_arm_openbsd.c +31 -0
  259. data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519.c +6 -4
  260. data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519_tables.h +795 -795
  261. data/third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h +1 -5
  262. data/third_party/boringssl-with-bazel/src/crypto/dsa/dsa.c +4 -0
  263. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/hash_to_curve.c +18 -6
  264. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/internal.h +15 -7
  265. data/third_party/boringssl-with-bazel/src/crypto/ecdh_extra/ecdh_extra.c +1 -1
  266. data/third_party/boringssl-with-bazel/src/crypto/evp/p_rsa.c +1 -1
  267. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm.c +1 -0
  268. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/dh/dh.c +3 -0
  269. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.c +24 -24
  270. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.c +1 -1
  271. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_montgomery.c +7 -7
  272. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +74 -74
  273. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/oct.c +1 -2
  274. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p224-64.c +11 -11
  275. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256-nistz.c +12 -12
  276. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256.c +14 -15
  277. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/p256_table.h +1 -1
  278. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple.c +10 -10
  279. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/simple_mul.c +23 -23
  280. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/wnaf.c +13 -13
  281. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdh/ecdh.c +1 -1
  282. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +2 -2
  283. data/third_party/boringssl-with-bazel/src/crypto/{hkdf → fipsmodule/hkdf}/hkdf.c +1 -1
  284. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/cbc.c +2 -10
  285. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/ctr.c +1 -4
  286. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/gcm.c +115 -133
  287. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/gcm_nohw.c +12 -14
  288. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/internal.h +57 -47
  289. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/ofb.c +1 -8
  290. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/polyval.c +27 -28
  291. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/urandom.c +11 -23
  292. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/internal.h +21 -16
  293. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/padding.c +5 -288
  294. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +143 -83
  295. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +95 -183
  296. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +71 -0
  297. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/tls/internal.h +8 -0
  298. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/tls/kdf.c +33 -0
  299. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +162 -6
  300. data/third_party/boringssl-with-bazel/src/crypto/internal.h +18 -0
  301. data/third_party/boringssl-with-bazel/src/crypto/kyber/kyber.c +18 -11
  302. data/third_party/boringssl-with-bazel/src/crypto/obj/obj_dat.h +6 -13
  303. data/third_party/boringssl-with-bazel/src/crypto/pem/pem_lib.c +18 -14
  304. data/third_party/boringssl-with-bazel/src/crypto/{refcount_lock.c → refcount_no_threads.c} +3 -13
  305. data/third_party/boringssl-with-bazel/src/crypto/refcount_win.c +89 -0
  306. data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/internal.h +77 -0
  307. data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/rsa_crypt.c +568 -0
  308. data/third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h +62 -0
  309. data/third_party/boringssl-with-bazel/src/crypto/trust_token/pmbtoken.c +218 -44
  310. data/third_party/boringssl-with-bazel/src/crypto/trust_token/trust_token.c +35 -0
  311. data/third_party/boringssl-with-bazel/src/crypto/trust_token/voprf.c +588 -39
  312. data/third_party/boringssl-with-bazel/src/crypto/x509/a_sign.c +27 -18
  313. data/third_party/boringssl-with-bazel/src/crypto/x509/asn1_gen.c +1 -1
  314. data/third_party/boringssl-with-bazel/src/crypto/x509/name_print.c +17 -39
  315. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509.c +39 -48
  316. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_att.c +0 -140
  317. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +72 -23
  318. data/third_party/boringssl-with-bazel/src/crypto/x509/x509name.c +11 -14
  319. data/third_party/boringssl-with-bazel/src/crypto/x509/x509spki.c +1 -1
  320. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509a.c +2 -2
  321. data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +1 -1
  322. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_conf.c +33 -46
  323. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_cpols.c +1 -0
  324. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_info.c +3 -5
  325. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_lib.c +14 -46
  326. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_prn.c +14 -26
  327. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +17 -10
  328. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_utl.c +1 -1
  329. data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +5 -7
  330. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +6 -4
  331. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +32 -1
  332. data/third_party/boringssl-with-bazel/src/include/openssl/bio.h +0 -4
  333. data/third_party/boringssl-with-bazel/src/include/openssl/blake2.h +1 -4
  334. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +3 -3
  335. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +28 -0
  336. data/third_party/boringssl-with-bazel/src/include/openssl/nid.h +2 -11
  337. data/third_party/boringssl-with-bazel/src/include/openssl/pem.h +0 -3
  338. data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +91 -1
  339. data/third_party/boringssl-with-bazel/src/include/openssl/span.h +5 -0
  340. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +149 -20
  341. data/third_party/boringssl-with-bazel/src/include/openssl/thread.h +4 -0
  342. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +4 -0
  343. data/third_party/boringssl-with-bazel/src/include/openssl/trust_token.h +8 -0
  344. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +774 -615
  345. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +42 -10
  346. data/third_party/boringssl-with-bazel/src/ssl/encrypted_client_hello.cc +11 -6
  347. data/third_party/boringssl-with-bazel/src/ssl/extensions.cc +2 -4
  348. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +24 -16
  349. data/third_party/boringssl-with-bazel/src/ssl/internal.h +65 -18
  350. data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +37 -18
  351. data/third_party/boringssl-with-bazel/src/ssl/ssl_cipher.cc +187 -193
  352. data/third_party/boringssl-with-bazel/src/ssl/ssl_key_share.cc +13 -129
  353. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +85 -10
  354. data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +17 -4
  355. data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +27 -19
  356. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +1 -1
  357. data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +5 -21
  358. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +5 -2
  359. data/third_party/boringssl-with-bazel/src/third_party/fiat/curve25519_64_msvc.h +1281 -0
  360. data/third_party/boringssl-with-bazel/src/third_party/fiat/p256_64_msvc.h +2002 -0
  361. data/third_party/cares/cares/include/ares.h +23 -1
  362. data/third_party/cares/cares/{src/lib → include}/ares_nameser.h +9 -7
  363. data/third_party/cares/cares/include/ares_rules.h +2 -2
  364. data/third_party/cares/cares/include/ares_version.h +3 -3
  365. data/third_party/cares/cares/src/lib/ares__addrinfo2hostent.c +266 -0
  366. data/third_party/cares/cares/src/lib/ares__addrinfo_localhost.c +240 -0
  367. data/third_party/cares/cares/src/lib/ares__parse_into_addrinfo.c +49 -80
  368. data/third_party/cares/cares/src/lib/ares__readaddrinfo.c +37 -43
  369. data/third_party/cares/cares/src/lib/ares__sortaddrinfo.c +12 -4
  370. data/third_party/cares/cares/src/lib/ares_data.c +16 -0
  371. data/third_party/cares/cares/src/lib/ares_data.h +7 -0
  372. data/third_party/cares/cares/src/lib/ares_destroy.c +8 -0
  373. data/third_party/cares/cares/src/lib/ares_expand_name.c +17 -6
  374. data/third_party/cares/cares/src/lib/ares_freeaddrinfo.c +1 -0
  375. data/third_party/cares/cares/src/lib/ares_getaddrinfo.c +156 -78
  376. data/third_party/cares/cares/src/lib/ares_gethostbyname.c +130 -326
  377. data/third_party/cares/cares/src/lib/ares_init.c +97 -485
  378. data/third_party/cares/cares/src/lib/ares_library_init.c +2 -89
  379. data/third_party/cares/cares/src/lib/ares_parse_a_reply.c +23 -142
  380. data/third_party/cares/cares/src/lib/ares_parse_aaaa_reply.c +22 -142
  381. data/third_party/cares/cares/src/lib/ares_parse_uri_reply.c +184 -0
  382. data/third_party/cares/cares/src/lib/ares_private.h +30 -16
  383. data/third_party/cares/cares/src/lib/ares_process.c +55 -16
  384. data/third_party/cares/cares/src/lib/ares_query.c +1 -35
  385. data/third_party/cares/cares/src/lib/ares_rand.c +279 -0
  386. data/third_party/cares/cares/src/lib/ares_send.c +5 -7
  387. data/third_party/cares/cares/src/lib/ares_strdup.c +12 -19
  388. data/third_party/cares/cares/src/lib/ares_strsplit.c +44 -128
  389. data/third_party/cares/cares/src/lib/ares_strsplit.h +9 -10
  390. data/third_party/cares/cares/src/lib/inet_net_pton.c +78 -116
  391. data/third_party/cares/cares/src/tools/ares_getopt.h +53 -0
  392. metadata +50 -12
  393. data/src/core/ext/filters/client_channel/health/health_check_client.cc +0 -175
  394. data/src/core/ext/filters/client_channel/health/health_check_client.h +0 -43
  395. data/third_party/cares/cares/src/lib/ares_library_init.h +0 -43
@@ -85,6 +85,11 @@ W32_FUNC const char *_w32_GetHostsFile (void);
85
85
 
86
86
  #define PATH_HOSTS "InetDBase:Hosts"
87
87
 
88
+ #elif defined(__HAIKU__)
89
+
90
+ #define PATH_RESOLV_CONF "/system/settings/network/resolv.conf"
91
+ #define PATH_HOSTS "/system/settings/network/hosts"
92
+
88
93
  #else
89
94
 
90
95
  #define PATH_RESOLV_CONF "/etc/resolv.conf"
@@ -96,8 +101,6 @@ W32_FUNC const char *_w32_GetHostsFile (void);
96
101
 
97
102
  #endif
98
103
 
99
- #define ARES_ID_KEY_LEN 31
100
-
101
104
  #include "ares_ipv6.h"
102
105
  #include "ares_llist.h"
103
106
 
@@ -257,12 +260,8 @@ struct apattern {
257
260
  unsigned short type;
258
261
  };
259
262
 
260
- typedef struct rc4_key
261
- {
262
- unsigned char state[256];
263
- unsigned char x;
264
- unsigned char y;
265
- } rc4_key;
263
+ struct ares_rand_state;
264
+ typedef struct ares_rand_state ares_rand_state;
266
265
 
267
266
  struct ares_channeldata {
268
267
  /* Configuration data */
@@ -297,8 +296,8 @@ struct ares_channeldata {
297
296
 
298
297
  /* ID to use for next query */
299
298
  unsigned short next_id;
300
- /* key to use when generating new ids */
301
- rc4_key id_key;
299
+ /* random state to use when generating new ids */
300
+ ares_rand_state *rand_state;
302
301
 
303
302
  /* Generation number to use for the next TCP socket open/close */
304
303
  int tcp_connection_generation;
@@ -334,6 +333,9 @@ struct ares_channeldata {
334
333
 
335
334
  /* Path for resolv.conf file, configurable via ares_options */
336
335
  char *resolvconf_path;
336
+
337
+ /* Path for hosts file, configurable via ares_options */
338
+ char *hosts_path;
337
339
  };
338
340
 
339
341
  /* Does the domain end in ".onion" or ".onion."? Case-insensitive. */
@@ -354,7 +356,10 @@ void ares__close_sockets(ares_channel channel, struct server_state *server);
354
356
  int ares__get_hostent(FILE *fp, int family, struct hostent **host);
355
357
  int ares__read_line(FILE *fp, char **buf, size_t *bufsize);
356
358
  void ares__free_query(struct query *query);
357
- unsigned short ares__generate_new_id(rc4_key* key);
359
+
360
+ ares_rand_state *ares__init_rand_state(void);
361
+ void ares__destroy_rand_state(ares_rand_state *state);
362
+ unsigned short ares__generate_new_id(ares_rand_state *state);
358
363
  struct timeval ares__tvnow(void);
359
364
  int ares__expand_name_validated(const unsigned char *encoded,
360
365
  const unsigned char *abuf,
@@ -387,17 +392,26 @@ void ares__freeaddrinfo_cnames(struct ares_addrinfo_cname *ai_cname);
387
392
 
388
393
  struct ares_addrinfo_cname *ares__append_addrinfo_cname(struct ares_addrinfo_cname **ai_cname);
389
394
 
395
+ int ares_append_ai_node(int aftype, unsigned short port, int ttl,
396
+ const void *adata,
397
+ struct ares_addrinfo_node **nodes);
398
+
390
399
  void ares__addrinfo_cat_cnames(struct ares_addrinfo_cname **head,
391
400
  struct ares_addrinfo_cname *tail);
392
401
 
393
402
  int ares__parse_into_addrinfo(const unsigned char *abuf,
394
- int alen,
403
+ int alen, int cname_only_is_enodata,
404
+ unsigned short port,
395
405
  struct ares_addrinfo *ai);
396
406
 
397
- int ares__parse_into_addrinfo2(const unsigned char *abuf,
398
- int alen,
399
- char **question_hostname,
400
- struct ares_addrinfo *ai);
407
+ int ares__addrinfo2hostent(const struct ares_addrinfo *ai, int family,
408
+ struct hostent **host);
409
+ int ares__addrinfo2addrttl(const struct ares_addrinfo *ai, int family,
410
+ int req_naddrttls, struct ares_addrttl *addrttls,
411
+ struct ares_addr6ttl *addr6ttls, int *naddrttls);
412
+ int ares__addrinfo_localhost(const char *name, unsigned short port,
413
+ const struct ares_addrinfo_hints *hints,
414
+ struct ares_addrinfo *ai);
401
415
 
402
416
  #if 0 /* Not used */
403
417
  long ares__tvdiff(struct timeval t1, struct timeval t2);
@@ -209,6 +209,17 @@ static void write_tcp_data(ares_channel channel,
209
209
  ares_ssize_t scount;
210
210
  ares_ssize_t wcount;
211
211
  size_t n;
212
+ /* From writev manpage: An implementation can advertise its limit by defining
213
+ IOV_MAX in <limits.h> or at run time via the return value from
214
+ sysconf(_SC_IOV_MAX). On modern Linux systems, the limit is 1024. Back in
215
+ Linux 2.0 days, this limit was 16. */
216
+ #if defined(IOV_MAX)
217
+ const size_t maxn = IOV_MAX; /* FreeBSD */
218
+ #elif defined(_SC_IOV_MAX)
219
+ const size_t maxn = sysconf(_SC_IOV_MAX); /* Linux */
220
+ #else
221
+ const size_t maxn = 16; /* Safe default */
222
+ #endif
212
223
 
213
224
  if(!write_fds && (write_fd == ARES_SOCKET_BAD))
214
225
  /* no possible action */
@@ -256,6 +267,8 @@ static void write_tcp_data(ares_channel channel,
256
267
  vec[n].iov_base = (char *) sendreq->data;
257
268
  vec[n].iov_len = sendreq->len;
258
269
  n++;
270
+ if(n >= maxn)
271
+ break;
259
272
  }
260
273
  wcount = socket_writev(channel, server->tcp_socket, vec, (int)n);
261
274
  ares_free(vec);
@@ -457,7 +470,7 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
457
470
  {
458
471
  struct server_state *server;
459
472
  int i;
460
- ares_ssize_t count;
473
+ ares_ssize_t read_len;
461
474
  unsigned char buf[MAXENDSSZ + 1];
462
475
  #ifdef HAVE_RECVFROM
463
476
  ares_socklen_t fromlen;
@@ -500,32 +513,41 @@ static void read_udp_packets(ares_channel channel, fd_set *read_fds,
500
513
  /* To reduce event loop overhead, read and process as many
501
514
  * packets as we can. */
502
515
  do {
503
- if (server->udp_socket == ARES_SOCKET_BAD)
504
- count = 0;
505
-
506
- else {
507
- if (server->addr.family == AF_INET)
516
+ if (server->udp_socket == ARES_SOCKET_BAD) {
517
+ read_len = -1;
518
+ } else {
519
+ if (server->addr.family == AF_INET) {
508
520
  fromlen = sizeof(from.sa4);
509
- else
521
+ } else {
510
522
  fromlen = sizeof(from.sa6);
511
- count = socket_recvfrom(channel, server->udp_socket, (void *)buf,
512
- sizeof(buf), 0, &from.sa, &fromlen);
523
+ }
524
+ read_len = socket_recvfrom(channel, server->udp_socket, (void *)buf,
525
+ sizeof(buf), 0, &from.sa, &fromlen);
513
526
  }
514
527
 
515
- if (count == -1 && try_again(SOCKERRNO))
528
+ if (read_len == 0) {
529
+ /* UDP is connectionless, so result code of 0 is a 0-length UDP
530
+ * packet, and not an indication the connection is closed like on
531
+ * tcp */
516
532
  continue;
517
- else if (count <= 0)
533
+ } else if (read_len < 0) {
534
+ if (try_again(SOCKERRNO))
535
+ continue;
536
+
518
537
  handle_error(channel, i, now);
538
+
519
539
  #ifdef HAVE_RECVFROM
520
- else if (!same_address(&from.sa, &server->addr))
540
+ } else if (!same_address(&from.sa, &server->addr)) {
521
541
  /* The address the response comes from does not match the address we
522
542
  * sent the request to. Someone may be attempting to perform a cache
523
543
  * poisoning attack. */
524
- break;
544
+ continue;
525
545
  #endif
526
- else
527
- process_answer(channel, buf, (int)count, i, 0, now);
528
- } while (count > 0);
546
+
547
+ } else {
548
+ process_answer(channel, buf, (int)read_len, i, 0, now);
549
+ }
550
+ } while (read_len >= 0);
529
551
  }
530
552
  }
531
553
 
@@ -966,6 +988,22 @@ static int setsocknonblock(ares_socket_t sockfd, /* operate on this */
966
988
  #endif
967
989
  }
968
990
 
991
+ #if defined(IPV6_V6ONLY) && defined(WIN32)
992
+ /* It makes support for IPv4-mapped IPv6 addresses.
993
+ * Linux kernel, NetBSD, FreeBSD and Darwin: default is off;
994
+ * Windows Vista and later: default is on;
995
+ * DragonFly BSD: acts like off, and dummy setting;
996
+ * OpenBSD and earlier Windows: unsupported.
997
+ * Linux: controlled by /proc/sys/net/ipv6/bindv6only.
998
+ */
999
+ static void set_ipv6_v6only(ares_socket_t sockfd, int on)
1000
+ {
1001
+ (void)setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(on));
1002
+ }
1003
+ #else
1004
+ #define set_ipv6_v6only(s,v)
1005
+ #endif
1006
+
969
1007
  static int configure_socket(ares_socket_t s, int family, ares_channel channel)
970
1008
  {
971
1009
  union {
@@ -1028,6 +1066,7 @@ static int configure_socket(ares_socket_t s, int family, ares_channel channel)
1028
1066
  if (bind(s, &local.sa, sizeof(local.sa6)) < 0)
1029
1067
  return -1;
1030
1068
  }
1069
+ set_ipv6_v6only(s, 0);
1031
1070
  }
1032
1071
 
1033
1072
  return 0;
@@ -33,32 +33,6 @@ struct qquery {
33
33
 
34
34
  static void qcallback(void *arg, int status, int timeouts, unsigned char *abuf, int alen);
35
35
 
36
- static void rc4(rc4_key* key, unsigned char *buffer_ptr, int buffer_len)
37
- {
38
- unsigned char x;
39
- unsigned char y;
40
- unsigned char* state;
41
- unsigned char xorIndex;
42
- int counter;
43
-
44
- x = key->x;
45
- y = key->y;
46
-
47
- state = &key->state[0];
48
- for(counter = 0; counter < buffer_len; counter ++)
49
- {
50
- x = (unsigned char)((x + 1) % 256);
51
- y = (unsigned char)((state[x] + y) % 256);
52
- ARES_SWAP_BYTE(&state[x], &state[y]);
53
-
54
- xorIndex = (unsigned char)((state[x] + state[y]) % 256);
55
-
56
- buffer_ptr[counter] = (unsigned char)(buffer_ptr[counter]^state[xorIndex]);
57
- }
58
- key->x = x;
59
- key->y = y;
60
- }
61
-
62
36
  static struct query* find_query_by_id(ares_channel channel, unsigned short id)
63
37
  {
64
38
  unsigned short qid;
@@ -78,7 +52,6 @@ static struct query* find_query_by_id(ares_channel channel, unsigned short id)
78
52
  return NULL;
79
53
  }
80
54
 
81
-
82
55
  /* a unique query id is generated using an rc4 key. Since the id may already
83
56
  be used by a running query (as infrequent as it may be), a lookup is
84
57
  performed per id generation. In practice this search should happen only
@@ -89,19 +62,12 @@ static unsigned short generate_unique_id(ares_channel channel)
89
62
  unsigned short id;
90
63
 
91
64
  do {
92
- id = ares__generate_new_id(&channel->id_key);
65
+ id = ares__generate_new_id(channel->rand_state);
93
66
  } while (find_query_by_id(channel, id));
94
67
 
95
68
  return (unsigned short)id;
96
69
  }
97
70
 
98
- unsigned short ares__generate_new_id(rc4_key* key)
99
- {
100
- unsigned short r=0;
101
- rc4(key, (unsigned char *)&r, sizeof(r));
102
- return r;
103
- }
104
-
105
71
  void ares_query(ares_channel channel, const char *name, int dnsclass,
106
72
  int type, ares_callback callback, void *arg)
107
73
  {
@@ -0,0 +1,279 @@
1
+ /* Copyright 1998 by the Massachusetts Institute of Technology.
2
+ * Copyright (C) 2007-2013 by Daniel Stenberg
3
+ *
4
+ * Permission to use, copy, modify, and distribute this
5
+ * software and its documentation for any purpose and without
6
+ * fee is hereby granted, provided that the above copyright
7
+ * notice appear in all copies and that both that copyright
8
+ * notice and this permission notice appear in supporting
9
+ * documentation, and that the name of M.I.T. not be used in
10
+ * advertising or publicity pertaining to distribution of the
11
+ * software without specific, written prior permission.
12
+ * M.I.T. makes no representations about the suitability of
13
+ * this software for any purpose. It is provided "as is"
14
+ * without express or implied warranty.
15
+ */
16
+
17
+ #include "ares_setup.h"
18
+ #include "ares.h"
19
+ #include "ares_private.h"
20
+ #include "ares_nowarn.h"
21
+ #include <stdlib.h>
22
+
23
+ typedef enum {
24
+ ARES_RAND_OS = 1, /* OS-provided such as RtlGenRandom or arc4random */
25
+ ARES_RAND_FILE = 2, /* OS file-backed random number generator */
26
+ ARES_RAND_RC4 = 3 /* Internal RC4 based PRNG */
27
+ } ares_rand_backend;
28
+
29
+ typedef struct ares_rand_rc4
30
+ {
31
+ unsigned char S[256];
32
+ size_t i;
33
+ size_t j;
34
+ } ares_rand_rc4;
35
+
36
+ struct ares_rand_state
37
+ {
38
+ ares_rand_backend type;
39
+ union {
40
+ FILE *rand_file;
41
+ ares_rand_rc4 rc4;
42
+ } state;
43
+ };
44
+
45
+
46
+ /* Define RtlGenRandom = SystemFunction036. This is in advapi32.dll. There is
47
+ * no need to dynamically load this, other software used widely does not.
48
+ * http://blogs.msdn.com/michael_howard/archive/2005/01/14/353379.aspx
49
+ * https://docs.microsoft.com/en-us/windows/win32/api/ntsecapi/nf-ntsecapi-rtlgenrandom
50
+ */
51
+ #ifdef _WIN32
52
+ BOOLEAN WINAPI SystemFunction036(PVOID RandomBuffer, ULONG RandomBufferLength);
53
+ # ifndef RtlGenRandom
54
+ # define RtlGenRandom(a,b) SystemFunction036(a,b)
55
+ # endif
56
+ #endif
57
+
58
+
59
+ #define ARES_RC4_KEY_LEN 32 /* 256 bits */
60
+
61
+ #ifdef _MSC_VER
62
+ typedef unsigned __int64 cares_u64;
63
+ #else
64
+ typedef unsigned long long cares_u64;
65
+ #endif
66
+
67
+ static unsigned int ares_u32_from_ptr(void *addr)
68
+ {
69
+ if (sizeof(void *) == 8) {
70
+ return (unsigned int)((((cares_u64)addr >> 32) & 0xFFFFFFFF) | ((cares_u64)addr & 0xFFFFFFFF));
71
+ }
72
+ return (unsigned int)((size_t)addr & 0xFFFFFFFF);
73
+ }
74
+
75
+
76
+ /* initialize an rc4 key as the last possible fallback. */
77
+ static void ares_rc4_generate_key(ares_rand_rc4 *rc4_state, unsigned char *key, size_t key_len)
78
+ {
79
+ size_t i;
80
+ size_t len = 0;
81
+ unsigned int data;
82
+ struct timeval tv;
83
+
84
+ if (key_len != ARES_RC4_KEY_LEN)
85
+ return;
86
+
87
+ /* Randomness is hard to come by. Maybe the system randomizes heap and stack addresses.
88
+ * Maybe the current timestamp give us some randomness.
89
+ * Use rc4_state (heap), &i (stack), and ares__tvnow()
90
+ */
91
+ data = ares_u32_from_ptr(rc4_state);
92
+ memcpy(key + len, &data, sizeof(data));
93
+ len += sizeof(data);
94
+
95
+ data = ares_u32_from_ptr(&i);
96
+ memcpy(key + len, &data, sizeof(data));
97
+ len += sizeof(data);
98
+
99
+ tv = ares__tvnow();
100
+ data = (unsigned int)((tv.tv_sec | tv.tv_usec) & 0xFFFFFFFF);
101
+ memcpy(key + len, &data, sizeof(data));
102
+ len += sizeof(data);
103
+
104
+ srand(ares_u32_from_ptr(rc4_state) | ares_u32_from_ptr(&i) | (unsigned int)((tv.tv_sec | tv.tv_usec) & 0xFFFFFFFF));
105
+
106
+ for (i=len; i<key_len; i++) {
107
+ key[i]=(unsigned char)(rand() % 256); /* LCOV_EXCL_LINE */
108
+ }
109
+ }
110
+
111
+
112
+ static void ares_rc4_init(ares_rand_rc4 *rc4_state)
113
+ {
114
+ unsigned char key[ARES_RC4_KEY_LEN];
115
+ size_t i;
116
+ size_t j;
117
+
118
+ ares_rc4_generate_key(rc4_state, key, sizeof(key));
119
+
120
+ for (i = 0; i < sizeof(rc4_state->S); i++) {
121
+ rc4_state->S[i] = i & 0xFF;
122
+ }
123
+
124
+ for(i = 0, j = 0; i < 256; i++) {
125
+ j = (j + rc4_state->S[i] + key[i % sizeof(key)]) % 256;
126
+ ARES_SWAP_BYTE(&rc4_state->S[i], &rc4_state->S[j]);
127
+ }
128
+
129
+ rc4_state->i = 0;
130
+ rc4_state->j = 0;
131
+ }
132
+
133
+ /* Just outputs the key schedule, no need to XOR with any data since we have none */
134
+ static void ares_rc4_prng(ares_rand_rc4 *rc4_state, unsigned char *buf, size_t len)
135
+ {
136
+ unsigned char *S = rc4_state->S;
137
+ size_t i = rc4_state->i;
138
+ size_t j = rc4_state->j;
139
+ size_t cnt;
140
+
141
+ for (cnt=0; cnt<len; cnt++) {
142
+ i = (i + 1) % 256;
143
+ j = (j + S[i]) % 256;
144
+
145
+ ARES_SWAP_BYTE(&S[i], &S[j]);
146
+ buf[cnt] = S[(S[i] + S[j]) % 256];
147
+ }
148
+
149
+ rc4_state->i = i;
150
+ rc4_state->j = j;
151
+ }
152
+
153
+
154
+ static int ares__init_rand_engine(ares_rand_state *state)
155
+ {
156
+ memset(state, 0, sizeof(*state));
157
+
158
+ #if defined(HAVE_ARC4RANDOM_BUF) || defined(_WIN32)
159
+ state->type = ARES_RAND_OS;
160
+ return 1;
161
+ #elif defined(CARES_RANDOM_FILE)
162
+ state->type = ARES_RAND_FILE;
163
+ state->state.rand_file = fopen(CARES_RANDOM_FILE, "rb");
164
+ if (state->state.rand_file) {
165
+ setvbuf(state->state.rand_file, NULL, _IONBF, 0);
166
+ return 1;
167
+ }
168
+ /* Fall-Thru on failure to RC4 */
169
+ #endif
170
+
171
+ state->type = ARES_RAND_RC4;
172
+ ares_rc4_init(&state->state.rc4);
173
+
174
+ /* Currently cannot fail */
175
+ return 1;
176
+ }
177
+
178
+
179
+ ares_rand_state *ares__init_rand_state()
180
+ {
181
+ ares_rand_state *state = NULL;
182
+
183
+ state = ares_malloc(sizeof(*state));
184
+ if (!state)
185
+ return NULL;
186
+
187
+ if (!ares__init_rand_engine(state)) {
188
+ ares_free(state);
189
+ return NULL;
190
+ }
191
+
192
+ return state;
193
+ }
194
+
195
+
196
+ static void ares__clear_rand_state(ares_rand_state *state)
197
+ {
198
+ if (!state)
199
+ return;
200
+
201
+ switch (state->type) {
202
+ case ARES_RAND_OS:
203
+ break;
204
+ case ARES_RAND_FILE:
205
+ fclose(state->state.rand_file);
206
+ break;
207
+ case ARES_RAND_RC4:
208
+ break;
209
+ }
210
+ }
211
+
212
+
213
+ static void ares__reinit_rand(ares_rand_state *state)
214
+ {
215
+ ares__clear_rand_state(state);
216
+ ares__init_rand_engine(state);
217
+ }
218
+
219
+
220
+ void ares__destroy_rand_state(ares_rand_state *state)
221
+ {
222
+ if (!state)
223
+ return;
224
+
225
+ ares__clear_rand_state(state);
226
+ ares_free(state);
227
+ }
228
+
229
+
230
+ static void ares__rand_bytes(ares_rand_state *state, unsigned char *buf, size_t len)
231
+ {
232
+
233
+ while (1) {
234
+ size_t bytes_read = 0;
235
+
236
+ switch (state->type) {
237
+ case ARES_RAND_OS:
238
+ #ifdef _WIN32
239
+ RtlGenRandom(buf, len);
240
+ return;
241
+ #elif defined(HAVE_ARC4RANDOM_BUF)
242
+ arc4random_buf(buf, len);
243
+ return;
244
+ #else
245
+ /* Shouldn't be possible to be here */
246
+ break;
247
+ #endif
248
+
249
+ case ARES_RAND_FILE:
250
+ while (1) {
251
+ size_t rv = fread(buf + bytes_read, 1, len - bytes_read, state->state.rand_file);
252
+ if (rv == 0)
253
+ break; /* critical error, will reinit rand state */
254
+
255
+ bytes_read += rv;
256
+ if (bytes_read == len)
257
+ return;
258
+ }
259
+ break;
260
+
261
+ case ARES_RAND_RC4:
262
+ ares_rc4_prng(&state->state.rc4, buf, len);
263
+ return;
264
+ }
265
+
266
+ /* If we didn't return before we got here, that means we had a critical rand
267
+ * failure and need to reinitialized */
268
+ ares__reinit_rand(state);
269
+ }
270
+ }
271
+
272
+ unsigned short ares__generate_new_id(ares_rand_state *state)
273
+ {
274
+ unsigned short r=0;
275
+
276
+ ares__rand_bytes(state, (unsigned char *)&r, sizeof(r));
277
+ return r;
278
+ }
279
+
@@ -39,7 +39,11 @@ void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
39
39
  callback(arg, ARES_EBADQUERY, 0, NULL, 0);
40
40
  return;
41
41
  }
42
-
42
+ if (channel->nservers < 1)
43
+ {
44
+ callback(arg, ARES_ESERVFAIL, 0, NULL, 0);
45
+ return;
46
+ }
43
47
  /* Allocate space for query and allocated fields. */
44
48
  query = ares_malloc(sizeof(struct query));
45
49
  if (!query)
@@ -54,12 +58,6 @@ void ares_send(ares_channel channel, const unsigned char *qbuf, int qlen,
54
58
  callback(arg, ARES_ENOMEM, 0, NULL, 0);
55
59
  return;
56
60
  }
57
- if (channel->nservers < 1)
58
- {
59
- ares_free(query);
60
- callback(arg, ARES_ESERVFAIL, 0, NULL, 0);
61
- return;
62
- }
63
61
  query->server_info = ares_malloc(channel->nservers *
64
62
  sizeof(query->server_info[0]));
65
63
  if (!query->server_info)
@@ -22,28 +22,21 @@
22
22
 
23
23
  char *ares_strdup(const char *s1)
24
24
  {
25
- #ifdef HAVE_STRDUP
26
- if (ares_malloc == malloc)
27
- return strdup(s1);
28
- else
29
- #endif
30
- {
31
- size_t sz;
32
- char * s2;
25
+ size_t sz;
26
+ char * s2;
33
27
 
34
- if(s1) {
35
- sz = strlen(s1);
36
- if(sz < (size_t)-1) {
37
- sz++;
38
- if(sz < ((size_t)-1) / sizeof(char)) {
39
- s2 = ares_malloc(sz * sizeof(char));
40
- if(s2) {
41
- memcpy(s2, s1, sz * sizeof(char));
42
- return s2;
43
- }
28
+ if(s1) {
29
+ sz = strlen(s1);
30
+ if(sz < (size_t)-1) {
31
+ sz++;
32
+ if(sz < ((size_t)-1)) {
33
+ s2 = ares_malloc(sz);
34
+ if(s2) {
35
+ memcpy(s2, s1, sz);
36
+ return s2;
44
37
  }
45
38
  }
46
39
  }
47
- return (char *)NULL;
48
40
  }
41
+ return (char *)NULL;
49
42
  }