grpc 1.4.5 → 1.6.0.pre1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (928) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1235 -1100
  3. data/etc/roots.pem +0 -412
  4. data/include/grpc/byte_buffer.h +10 -25
  5. data/include/grpc/byte_buffer_reader.h +10 -25
  6. data/include/grpc/census.h +10 -25
  7. data/include/grpc/compression.h +10 -25
  8. data/include/grpc/grpc.h +15 -26
  9. data/include/grpc/grpc_cronet.h +10 -25
  10. data/include/grpc/grpc_posix.h +10 -25
  11. data/include/grpc/grpc_security.h +10 -25
  12. data/include/grpc/grpc_security_constants.h +10 -25
  13. data/include/grpc/impl/codegen/atm.h +11 -25
  14. data/include/grpc/impl/codegen/atm_gcc_atomic.h +10 -25
  15. data/include/grpc/impl/codegen/atm_gcc_sync.h +10 -25
  16. data/include/grpc/impl/codegen/atm_windows.h +10 -25
  17. data/include/grpc/impl/codegen/byte_buffer_reader.h +11 -26
  18. data/include/grpc/impl/codegen/compression_types.h +12 -27
  19. data/include/grpc/impl/codegen/connectivity_state.h +10 -25
  20. data/include/grpc/impl/codegen/exec_ctx_fwd.h +10 -25
  21. data/include/grpc/impl/codegen/gpr_slice.h +10 -25
  22. data/include/grpc/impl/codegen/gpr_types.h +10 -25
  23. data/include/grpc/impl/codegen/grpc_types.h +42 -43
  24. data/include/grpc/impl/codegen/port_platform.h +10 -25
  25. data/include/grpc/impl/codegen/propagation_bits.h +10 -25
  26. data/include/grpc/impl/codegen/slice.h +13 -28
  27. data/include/grpc/impl/codegen/status.h +10 -25
  28. data/include/grpc/impl/codegen/sync.h +10 -25
  29. data/include/grpc/impl/codegen/sync_generic.h +10 -25
  30. data/include/grpc/impl/codegen/sync_posix.h +10 -25
  31. data/include/grpc/impl/codegen/sync_windows.h +10 -25
  32. data/include/grpc/load_reporting.h +10 -25
  33. data/include/grpc/slice.h +10 -25
  34. data/include/grpc/slice_buffer.h +10 -25
  35. data/include/grpc/status.h +10 -25
  36. data/include/grpc/support/alloc.h +10 -25
  37. data/include/grpc/support/atm.h +10 -25
  38. data/include/grpc/support/atm_gcc_atomic.h +10 -25
  39. data/include/grpc/support/atm_gcc_sync.h +10 -25
  40. data/include/grpc/support/atm_windows.h +10 -25
  41. data/include/grpc/support/avl.h +46 -49
  42. data/include/grpc/support/cmdline.h +10 -25
  43. data/include/grpc/support/cpu.h +10 -25
  44. data/include/grpc/support/histogram.h +10 -25
  45. data/include/grpc/support/host_port.h +10 -25
  46. data/include/grpc/support/log.h +10 -25
  47. data/include/grpc/support/log_windows.h +10 -25
  48. data/include/grpc/support/port_platform.h +10 -25
  49. data/include/grpc/support/string_util.h +10 -25
  50. data/include/grpc/support/subprocess.h +10 -25
  51. data/include/grpc/support/sync.h +10 -25
  52. data/include/grpc/support/sync_generic.h +10 -25
  53. data/include/grpc/support/sync_posix.h +10 -25
  54. data/include/grpc/support/sync_windows.h +10 -25
  55. data/include/grpc/support/thd.h +10 -25
  56. data/include/grpc/support/time.h +10 -25
  57. data/include/grpc/support/tls.h +10 -25
  58. data/include/grpc/support/tls_gcc.h +10 -25
  59. data/include/grpc/support/tls_msvc.h +10 -25
  60. data/include/grpc/support/tls_pthread.h +10 -25
  61. data/include/grpc/support/useful.h +10 -25
  62. data/include/grpc/support/workaround_list.h +11 -26
  63. data/src/boringssl/err_data.c +277 -259
  64. data/src/core/ext/census/aggregation.h +10 -25
  65. data/src/core/ext/census/base_resources.c +10 -25
  66. data/src/core/ext/census/base_resources.h +10 -25
  67. data/src/core/ext/census/census_interface.h +10 -25
  68. data/src/core/ext/census/census_rpc_stats.h +10 -25
  69. data/src/core/ext/census/context.c +10 -25
  70. data/src/core/ext/census/gen/census.pb.c +10 -25
  71. data/src/core/ext/census/gen/census.pb.h +10 -25
  72. data/src/core/ext/census/gen/trace_context.pb.c +10 -25
  73. data/src/core/ext/census/gen/trace_context.pb.h +10 -25
  74. data/src/core/ext/census/grpc_context.c +10 -25
  75. data/src/core/ext/census/grpc_filter.c +11 -26
  76. data/src/core/ext/census/grpc_filter.h +10 -25
  77. data/src/core/ext/census/grpc_plugin.c +10 -25
  78. data/src/core/ext/census/initialize.c +10 -25
  79. data/src/core/ext/census/intrusive_hash_map.c +10 -25
  80. data/src/core/ext/census/intrusive_hash_map.h +10 -25
  81. data/src/core/ext/census/intrusive_hash_map_internal.h +10 -25
  82. data/src/core/ext/census/mlog.c +10 -25
  83. data/src/core/ext/census/mlog.h +10 -25
  84. data/src/core/ext/census/operation.c +10 -25
  85. data/src/core/ext/census/placeholders.c +10 -25
  86. data/src/core/ext/census/resource.c +10 -25
  87. data/src/core/ext/census/resource.h +10 -25
  88. data/src/core/ext/census/rpc_metric_id.h +10 -25
  89. data/src/core/ext/census/trace_context.c +10 -25
  90. data/src/core/ext/census/trace_context.h +10 -25
  91. data/src/core/ext/census/trace_label.h +10 -25
  92. data/src/core/ext/census/trace_propagation.h +10 -25
  93. data/src/core/ext/census/trace_status.h +10 -25
  94. data/src/core/ext/census/trace_string.h +10 -25
  95. data/src/core/ext/census/tracing.c +10 -26
  96. data/src/core/ext/census/tracing.h +10 -25
  97. data/src/core/ext/filters/client_channel/channel_connectivity.c +20 -33
  98. data/src/core/ext/filters/client_channel/client_channel.c +617 -520
  99. data/src/core/ext/filters/client_channel/client_channel.h +15 -28
  100. data/src/core/ext/filters/client_channel/client_channel_factory.c +13 -31
  101. data/src/core/ext/filters/client_channel/client_channel_factory.h +10 -25
  102. data/src/core/ext/filters/client_channel/client_channel_plugin.c +16 -29
  103. data/src/core/ext/filters/client_channel/connector.c +10 -25
  104. data/src/core/ext/filters/client_channel/connector.h +10 -25
  105. data/src/core/ext/filters/client_channel/http_connect_handshaker.c +15 -30
  106. data/src/core/ext/filters/client_channel/http_connect_handshaker.h +10 -25
  107. data/src/core/ext/filters/client_channel/http_proxy.c +112 -38
  108. data/src/core/ext/filters/client_channel/http_proxy.h +10 -25
  109. data/src/core/ext/filters/client_channel/lb_policy.c +32 -36
  110. data/src/core/ext/filters/client_channel/lb_policy.h +24 -27
  111. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +14 -30
  112. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +10 -25
  113. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +464 -279
  114. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +10 -25
  115. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +15 -28
  116. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.c +40 -48
  117. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +65 -49
  118. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +31 -31
  119. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +47 -32
  120. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +11 -26
  121. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +13 -9
  122. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +27 -21
  123. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +373 -136
  124. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +504 -279
  125. data/src/core/ext/filters/client_channel/lb_policy_factory.c +12 -31
  126. data/src/core/ext/filters/client_channel/lb_policy_factory.h +12 -27
  127. data/src/core/ext/filters/client_channel/lb_policy_registry.c +10 -25
  128. data/src/core/ext/filters/client_channel/lb_policy_registry.h +10 -25
  129. data/src/core/ext/filters/client_channel/parse_address.c +10 -25
  130. data/src/core/ext/filters/client_channel/parse_address.h +10 -25
  131. data/src/core/ext/filters/client_channel/proxy_mapper.c +10 -25
  132. data/src/core/ext/filters/client_channel/proxy_mapper.h +10 -25
  133. data/src/core/ext/filters/client_channel/proxy_mapper_registry.c +10 -25
  134. data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +10 -25
  135. data/src/core/ext/filters/client_channel/resolver.c +33 -38
  136. data/src/core/ext/filters/client_channel/resolver.h +19 -30
  137. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +153 -50
  138. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +14 -27
  139. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +33 -30
  140. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +326 -116
  141. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +35 -36
  142. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.c +60 -0
  143. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.c +19 -34
  144. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.c +254 -0
  145. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +60 -0
  146. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +16 -28
  147. data/src/core/ext/filters/client_channel/resolver_factory.c +10 -25
  148. data/src/core/ext/filters/client_channel/resolver_factory.h +10 -25
  149. data/src/core/ext/filters/client_channel/resolver_registry.c +10 -25
  150. data/src/core/ext/filters/client_channel/resolver_registry.h +10 -25
  151. data/src/core/ext/filters/client_channel/retry_throttle.c +23 -34
  152. data/src/core/ext/filters/client_channel/retry_throttle.h +10 -25
  153. data/src/core/ext/filters/client_channel/subchannel.c +33 -55
  154. data/src/core/ext/filters/client_channel/subchannel.h +16 -26
  155. data/src/core/ext/filters/client_channel/subchannel_index.c +55 -92
  156. data/src/core/ext/filters/client_channel/subchannel_index.h +26 -29
  157. data/src/core/ext/filters/client_channel/uri_parser.c +10 -25
  158. data/src/core/ext/filters/client_channel/uri_parser.h +10 -25
  159. data/src/core/ext/filters/deadline/deadline_filter.c +30 -45
  160. data/src/core/ext/filters/deadline/deadline_filter.h +10 -25
  161. data/src/core/ext/filters/http/client/http_client_filter.c +255 -294
  162. data/src/core/ext/filters/http/client/http_client_filter.h +10 -25
  163. data/src/core/ext/filters/http/http_filters_plugin.c +11 -26
  164. data/src/core/ext/filters/http/message_compress/message_compress_filter.c +133 -105
  165. data/src/core/ext/filters/http/message_compress/message_compress_filter.h +10 -25
  166. data/src/core/ext/filters/http/server/http_server_filter.c +17 -32
  167. data/src/core/ext/filters/http/server/http_server_filter.h +10 -25
  168. data/src/core/ext/filters/load_reporting/load_reporting.c +11 -30
  169. data/src/core/ext/filters/load_reporting/load_reporting.h +10 -25
  170. data/src/core/ext/filters/load_reporting/load_reporting_filter.c +11 -26
  171. data/src/core/ext/filters/load_reporting/load_reporting_filter.h +10 -25
  172. data/src/core/ext/filters/max_age/max_age_filter.c +28 -43
  173. data/src/core/ext/filters/max_age/max_age_filter.h +10 -25
  174. data/src/core/ext/filters/message_size/message_size_filter.c +24 -37
  175. data/src/core/ext/filters/message_size/message_size_filter.h +10 -25
  176. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +16 -31
  177. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h +10 -25
  178. data/src/core/ext/filters/workarounds/workaround_utils.c +12 -26
  179. data/src/core/ext/filters/workarounds/workaround_utils.h +11 -26
  180. data/src/core/ext/transport/chttp2/alpn/alpn.c +10 -25
  181. data/src/core/ext/transport/chttp2/alpn/alpn.h +10 -25
  182. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +13 -28
  183. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +10 -25
  184. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +13 -30
  185. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +12 -29
  186. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +13 -30
  187. data/src/core/ext/transport/chttp2/server/chttp2_server.c +11 -26
  188. data/src/core/ext/transport/chttp2/server/chttp2_server.h +10 -25
  189. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +10 -25
  190. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +10 -25
  191. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +10 -25
  192. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +11 -25
  193. data/src/core/ext/transport/chttp2/transport/bin_decoder.h +10 -25
  194. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +10 -25
  195. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +10 -25
  196. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +15 -27
  197. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +421 -443
  198. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +14 -25
  199. data/src/core/ext/transport/chttp2/transport/flow_control.c +500 -0
  200. data/src/core/ext/transport/chttp2/transport/frame.h +10 -25
  201. data/src/core/ext/transport/chttp2/transport/frame_data.c +20 -28
  202. data/src/core/ext/transport/chttp2/transport/frame_data.h +10 -25
  203. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +10 -25
  204. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +10 -25
  205. data/src/core/ext/transport/chttp2/transport/frame_ping.c +11 -26
  206. data/src/core/ext/transport/chttp2/transport/frame_ping.h +10 -25
  207. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +11 -26
  208. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +10 -25
  209. data/src/core/ext/transport/chttp2/transport/frame_settings.c +16 -29
  210. data/src/core/ext/transport/chttp2/transport/frame_settings.h +10 -25
  211. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +17 -33
  212. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +10 -25
  213. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +18 -31
  214. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +12 -25
  215. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +15 -30
  216. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +10 -25
  217. data/src/core/ext/transport/chttp2/transport/hpack_table.c +10 -25
  218. data/src/core/ext/transport/chttp2/transport/hpack_table.h +10 -25
  219. data/src/core/ext/transport/chttp2/transport/http2_settings.c +10 -25
  220. data/src/core/ext/transport/chttp2/transport/http2_settings.h +10 -25
  221. data/src/core/ext/transport/chttp2/transport/huffsyms.c +10 -25
  222. data/src/core/ext/transport/chttp2/transport/huffsyms.h +10 -25
  223. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +10 -25
  224. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +10 -25
  225. data/src/core/ext/transport/chttp2/transport/internal.h +191 -179
  226. data/src/core/ext/transport/chttp2/transport/parsing.c +33 -102
  227. data/src/core/ext/transport/chttp2/transport/stream_lists.c +26 -28
  228. data/src/core/ext/transport/chttp2/transport/stream_map.c +10 -25
  229. data/src/core/ext/transport/chttp2/transport/stream_map.h +10 -25
  230. data/src/core/ext/transport/chttp2/transport/varint.c +14 -25
  231. data/src/core/ext/transport/chttp2/transport/varint.h +10 -25
  232. data/src/core/ext/transport/chttp2/transport/writing.c +164 -106
  233. data/src/core/ext/transport/inproc/inproc_plugin.c +29 -0
  234. data/src/core/ext/transport/inproc/inproc_transport.c +1303 -0
  235. data/src/core/ext/transport/inproc/inproc_transport.h +41 -0
  236. data/src/core/lib/channel/channel_args.c +52 -27
  237. data/src/core/lib/channel/channel_args.h +18 -27
  238. data/src/core/lib/channel/channel_stack.c +11 -26
  239. data/src/core/lib/channel/channel_stack.h +12 -27
  240. data/src/core/lib/channel/channel_stack_builder.c +11 -26
  241. data/src/core/lib/channel/channel_stack_builder.h +10 -25
  242. data/src/core/lib/channel/connected_channel.c +10 -25
  243. data/src/core/lib/channel/connected_channel.h +10 -25
  244. data/src/core/lib/channel/context.h +10 -25
  245. data/src/core/lib/channel/handshaker.c +14 -29
  246. data/src/core/lib/channel/handshaker.h +10 -25
  247. data/src/core/lib/channel/handshaker_factory.c +10 -25
  248. data/src/core/lib/channel/handshaker_factory.h +10 -25
  249. data/src/core/lib/channel/handshaker_registry.c +10 -25
  250. data/src/core/lib/channel/handshaker_registry.h +10 -25
  251. data/src/core/lib/compression/algorithm_metadata.h +10 -25
  252. data/src/core/lib/compression/compression.c +10 -25
  253. data/src/core/lib/compression/message_compress.c +10 -25
  254. data/src/core/lib/compression/message_compress.h +10 -25
  255. data/src/core/lib/compression/stream_compression.c +191 -0
  256. data/src/core/lib/compression/stream_compression.h +90 -0
  257. data/src/core/lib/debug/trace.c +28 -29
  258. data/src/core/lib/debug/trace.h +16 -30
  259. data/src/core/lib/http/format_request.c +10 -25
  260. data/src/core/lib/http/format_request.h +10 -25
  261. data/src/core/lib/http/httpcli.c +19 -35
  262. data/src/core/lib/http/httpcli.h +10 -25
  263. data/src/core/lib/http/httpcli_security_connector.c +17 -30
  264. data/src/core/lib/http/parser.c +11 -26
  265. data/src/core/lib/http/parser.h +10 -25
  266. data/src/core/lib/iomgr/closure.c +62 -25
  267. data/src/core/lib/iomgr/closure.h +81 -26
  268. data/src/core/lib/iomgr/combiner.c +103 -200
  269. data/src/core/lib/iomgr/combiner.h +14 -32
  270. data/src/core/lib/iomgr/endpoint.c +10 -29
  271. data/src/core/lib/iomgr/endpoint.h +10 -29
  272. data/src/core/lib/iomgr/endpoint_pair.h +10 -25
  273. data/src/core/lib/iomgr/endpoint_pair_posix.c +10 -25
  274. data/src/core/lib/iomgr/endpoint_pair_uv.c +10 -25
  275. data/src/core/lib/iomgr/endpoint_pair_windows.c +10 -25
  276. data/src/core/lib/iomgr/error.c +45 -46
  277. data/src/core/lib/iomgr/error.h +21 -34
  278. data/src/core/lib/iomgr/error_internal.h +10 -25
  279. data/src/core/lib/iomgr/ev_epoll1_linux.c +279 -179
  280. data/src/core/lib/iomgr/ev_epoll1_linux.h +10 -25
  281. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +75 -264
  282. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +10 -25
  283. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +44 -199
  284. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +10 -25
  285. data/src/core/lib/iomgr/ev_epollex_linux.c +184 -247
  286. data/src/core/lib/iomgr/ev_epollex_linux.h +10 -25
  287. data/src/core/lib/iomgr/ev_epollsig_linux.c +116 -323
  288. data/src/core/lib/iomgr/ev_epollsig_linux.h +10 -25
  289. data/src/core/lib/iomgr/ev_poll_posix.c +328 -184
  290. data/src/core/lib/iomgr/ev_poll_posix.h +10 -25
  291. data/src/core/lib/iomgr/ev_posix.c +25 -56
  292. data/src/core/lib/iomgr/ev_posix.h +15 -44
  293. data/src/core/lib/iomgr/ev_windows.c +11 -26
  294. data/src/core/lib/iomgr/exec_ctx.c +36 -45
  295. data/src/core/lib/iomgr/exec_ctx.h +10 -25
  296. data/src/core/lib/iomgr/executor.c +152 -127
  297. data/src/core/lib/iomgr/executor.h +18 -26
  298. data/src/core/lib/iomgr/gethostname.h +26 -0
  299. data/src/core/lib/iomgr/gethostname_fallback.c +27 -0
  300. data/src/core/lib/iomgr/gethostname_host_name_max.c +37 -0
  301. data/src/core/lib/iomgr/gethostname_sysconf.c +37 -0
  302. data/src/core/lib/iomgr/iocp_windows.c +10 -25
  303. data/src/core/lib/iomgr/iocp_windows.h +10 -25
  304. data/src/core/lib/iomgr/iomgr.c +17 -28
  305. data/src/core/lib/iomgr/iomgr.h +12 -27
  306. data/src/core/lib/iomgr/iomgr_internal.h +10 -25
  307. data/src/core/lib/iomgr/iomgr_posix.c +11 -26
  308. data/src/core/lib/iomgr/iomgr_posix.h +10 -25
  309. data/src/core/lib/iomgr/iomgr_uv.c +19 -26
  310. data/src/core/lib/iomgr/iomgr_uv.h +37 -0
  311. data/src/core/lib/iomgr/iomgr_windows.c +10 -25
  312. data/src/core/lib/iomgr/is_epollexclusive_available.c +10 -25
  313. data/src/core/lib/iomgr/is_epollexclusive_available.h +10 -25
  314. data/src/core/lib/iomgr/load_file.c +10 -25
  315. data/src/core/lib/iomgr/load_file.h +10 -25
  316. data/src/core/lib/iomgr/lockfree_event.c +22 -35
  317. data/src/core/lib/iomgr/lockfree_event.h +13 -27
  318. data/src/core/lib/iomgr/nameser.h +104 -0
  319. data/src/core/lib/iomgr/network_status_tracker.c +10 -25
  320. data/src/core/lib/iomgr/network_status_tracker.h +10 -25
  321. data/src/core/lib/iomgr/polling_entity.c +10 -25
  322. data/src/core/lib/iomgr/polling_entity.h +14 -34
  323. data/src/core/lib/iomgr/pollset.h +14 -25
  324. data/src/core/lib/iomgr/pollset_set.h +10 -25
  325. data/src/core/lib/iomgr/pollset_set_uv.c +10 -25
  326. data/src/core/lib/iomgr/pollset_set_windows.c +10 -25
  327. data/src/core/lib/iomgr/pollset_set_windows.h +10 -25
  328. data/src/core/lib/iomgr/pollset_uv.c +25 -26
  329. data/src/core/lib/iomgr/pollset_uv.h +10 -25
  330. data/src/core/lib/iomgr/pollset_windows.c +17 -27
  331. data/src/core/lib/iomgr/pollset_windows.h +10 -25
  332. data/src/core/lib/iomgr/port.h +24 -25
  333. data/src/core/lib/iomgr/resolve_address.h +10 -25
  334. data/src/core/lib/iomgr/resolve_address_posix.c +13 -28
  335. data/src/core/lib/iomgr/resolve_address_uv.c +31 -35
  336. data/src/core/lib/iomgr/resolve_address_windows.c +13 -28
  337. data/src/core/lib/iomgr/resource_quota.c +52 -67
  338. data/src/core/lib/iomgr/resource_quota.h +10 -25
  339. data/src/core/lib/iomgr/sockaddr.h +10 -25
  340. data/src/core/lib/iomgr/sockaddr_posix.h +10 -25
  341. data/src/core/lib/iomgr/sockaddr_utils.c +15 -25
  342. data/src/core/lib/iomgr/sockaddr_utils.h +12 -25
  343. data/src/core/lib/iomgr/sockaddr_windows.h +10 -25
  344. data/src/core/lib/iomgr/socket_factory_posix.c +13 -31
  345. data/src/core/lib/iomgr/socket_factory_posix.h +10 -25
  346. data/src/core/lib/iomgr/socket_mutator.c +14 -31
  347. data/src/core/lib/iomgr/socket_mutator.h +10 -25
  348. data/src/core/lib/iomgr/socket_utils.h +10 -25
  349. data/src/core/lib/iomgr/socket_utils_common_posix.c +10 -25
  350. data/src/core/lib/iomgr/socket_utils_linux.c +10 -25
  351. data/src/core/lib/iomgr/socket_utils_posix.c +10 -25
  352. data/src/core/lib/iomgr/socket_utils_posix.h +10 -25
  353. data/src/core/lib/iomgr/socket_utils_uv.c +10 -25
  354. data/src/core/lib/iomgr/socket_utils_windows.c +10 -25
  355. data/src/core/lib/iomgr/socket_windows.c +12 -27
  356. data/src/core/lib/iomgr/socket_windows.h +10 -25
  357. data/src/core/lib/iomgr/sys_epoll_wrapper.h +10 -25
  358. data/src/core/lib/iomgr/tcp_client.h +10 -25
  359. data/src/core/lib/iomgr/tcp_client_posix.c +21 -34
  360. data/src/core/lib/iomgr/tcp_client_posix.h +10 -25
  361. data/src/core/lib/iomgr/tcp_client_uv.c +18 -27
  362. data/src/core/lib/iomgr/tcp_client_windows.c +14 -29
  363. data/src/core/lib/iomgr/tcp_posix.c +36 -55
  364. data/src/core/lib/iomgr/tcp_posix.h +10 -25
  365. data/src/core/lib/iomgr/tcp_server.h +10 -25
  366. data/src/core/lib/iomgr/tcp_server_posix.c +16 -31
  367. data/src/core/lib/iomgr/tcp_server_utils_posix.h +10 -25
  368. data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +11 -26
  369. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +10 -25
  370. data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +10 -25
  371. data/src/core/lib/iomgr/tcp_server_uv.c +103 -64
  372. data/src/core/lib/iomgr/tcp_server_windows.c +14 -29
  373. data/src/core/lib/iomgr/tcp_uv.c +41 -45
  374. data/src/core/lib/iomgr/tcp_uv.h +10 -25
  375. data/src/core/lib/iomgr/tcp_windows.c +39 -53
  376. data/src/core/lib/iomgr/tcp_windows.h +10 -25
  377. data/src/core/lib/iomgr/time_averaged_stats.c +10 -25
  378. data/src/core/lib/iomgr/time_averaged_stats.h +10 -25
  379. data/src/core/lib/iomgr/timer.h +18 -27
  380. data/src/core/lib/iomgr/timer_generic.c +91 -87
  381. data/src/core/lib/iomgr/timer_generic.h +10 -25
  382. data/src/core/lib/iomgr/timer_heap.c +10 -25
  383. data/src/core/lib/iomgr/timer_heap.h +10 -25
  384. data/src/core/lib/iomgr/timer_manager.c +178 -100
  385. data/src/core/lib/iomgr/timer_manager.h +10 -25
  386. data/src/core/lib/iomgr/timer_uv.c +23 -33
  387. data/src/core/lib/iomgr/timer_uv.h +10 -25
  388. data/src/core/lib/iomgr/udp_server.c +17 -32
  389. data/src/core/lib/iomgr/udp_server.h +10 -25
  390. data/src/core/lib/iomgr/unix_sockets_posix.c +10 -25
  391. data/src/core/lib/iomgr/unix_sockets_posix.h +10 -25
  392. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +10 -25
  393. data/src/core/lib/iomgr/wakeup_fd_cv.c +10 -25
  394. data/src/core/lib/iomgr/wakeup_fd_cv.h +13 -28
  395. data/src/core/lib/iomgr/wakeup_fd_eventfd.c +10 -25
  396. data/src/core/lib/iomgr/wakeup_fd_nospecial.c +10 -25
  397. data/src/core/lib/iomgr/wakeup_fd_pipe.c +10 -25
  398. data/src/core/lib/iomgr/wakeup_fd_pipe.h +10 -25
  399. data/src/core/lib/iomgr/wakeup_fd_posix.c +10 -25
  400. data/src/core/lib/iomgr/wakeup_fd_posix.h +10 -25
  401. data/src/core/lib/json/json.c +10 -25
  402. data/src/core/lib/json/json.h +10 -25
  403. data/src/core/lib/json/json_common.h +10 -25
  404. data/src/core/lib/json/json_reader.c +11 -25
  405. data/src/core/lib/json/json_reader.h +10 -25
  406. data/src/core/lib/json/json_string.c +10 -25
  407. data/src/core/lib/json/json_writer.c +10 -25
  408. data/src/core/lib/json/json_writer.h +10 -25
  409. data/src/core/lib/profiling/basic_timers.c +10 -25
  410. data/src/core/lib/profiling/stap_timers.c +10 -25
  411. data/src/core/lib/profiling/timers.h +10 -25
  412. data/src/core/lib/security/context/security_context.c +32 -40
  413. data/src/core/lib/security/context/security_context.h +15 -26
  414. data/src/core/lib/security/credentials/composite/composite_credentials.c +76 -81
  415. data/src/core/lib/security/credentials/composite/composite_credentials.h +10 -25
  416. data/src/core/lib/security/credentials/credentials.c +29 -49
  417. data/src/core/lib/security/credentials/credentials.h +48 -61
  418. data/src/core/lib/security/credentials/credentials_metadata.c +34 -78
  419. data/src/core/lib/security/credentials/fake/fake_credentials.c +33 -56
  420. data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -27
  421. data/src/core/lib/security/credentials/google_default/credentials_generic.c +10 -25
  422. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +12 -27
  423. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +10 -25
  424. data/src/core/lib/security/credentials/iam/iam_credentials.c +40 -40
  425. data/src/core/lib/security/credentials/iam/iam_credentials.h +11 -26
  426. data/src/core/lib/security/credentials/jwt/json_token.c +10 -25
  427. data/src/core/lib/security/credentials/jwt/json_token.h +10 -25
  428. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +45 -48
  429. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +11 -26
  430. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +53 -33
  431. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +10 -25
  432. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +155 -87
  433. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +24 -28
  434. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +118 -82
  435. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +24 -27
  436. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +13 -32
  437. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +10 -25
  438. data/src/core/lib/security/transport/auth_filters.h +10 -25
  439. data/src/core/lib/security/transport/client_auth_filter.c +217 -112
  440. data/src/core/lib/security/transport/lb_targets_info.c +16 -32
  441. data/src/core/lib/security/transport/lb_targets_info.h +10 -25
  442. data/src/core/lib/security/transport/secure_endpoint.c +29 -43
  443. data/src/core/lib/security/transport/secure_endpoint.h +10 -25
  444. data/src/core/lib/security/transport/security_connector.c +80 -61
  445. data/src/core/lib/security/transport/security_connector.h +35 -35
  446. data/src/core/lib/security/transport/security_handshaker.c +18 -33
  447. data/src/core/lib/security/transport/security_handshaker.h +10 -25
  448. data/src/core/lib/security/transport/server_auth_filter.c +62 -116
  449. data/src/core/lib/security/transport/tsi_error.c +10 -25
  450. data/src/core/lib/security/transport/tsi_error.h +10 -25
  451. data/src/core/lib/security/util/json_util.c +10 -25
  452. data/src/core/lib/security/util/json_util.h +10 -25
  453. data/src/core/lib/slice/b64.c +10 -25
  454. data/src/core/lib/slice/b64.h +10 -25
  455. data/src/core/lib/slice/percent_encoding.c +10 -25
  456. data/src/core/lib/slice/percent_encoding.h +10 -25
  457. data/src/core/lib/slice/slice.c +10 -25
  458. data/src/core/lib/slice/slice_buffer.c +10 -25
  459. data/src/core/lib/slice/slice_hash_table.c +48 -26
  460. data/src/core/lib/slice/slice_hash_table.h +26 -28
  461. data/src/core/lib/slice/slice_intern.c +10 -25
  462. data/src/core/lib/slice/slice_internal.h +10 -25
  463. data/src/core/lib/slice/slice_string_helpers.c +10 -25
  464. data/src/core/lib/slice/slice_string_helpers.h +10 -25
  465. data/src/core/lib/support/alloc.c +10 -25
  466. data/src/core/lib/support/arena.c +12 -27
  467. data/src/core/lib/support/arena.h +10 -25
  468. data/src/core/lib/support/atm.c +17 -32
  469. data/src/core/lib/support/atomic.h +10 -25
  470. data/src/core/lib/support/atomic_with_atm.h +10 -25
  471. data/src/core/lib/support/atomic_with_std.h +10 -25
  472. data/src/core/lib/support/avl.c +101 -101
  473. data/src/core/lib/support/backoff.c +10 -25
  474. data/src/core/lib/support/backoff.h +10 -25
  475. data/src/core/lib/support/block_annotate.h +10 -25
  476. data/src/core/lib/support/cmdline.c +10 -25
  477. data/src/core/lib/support/cpu_iphone.c +10 -25
  478. data/src/core/lib/support/cpu_linux.c +10 -25
  479. data/src/core/lib/support/cpu_posix.c +10 -25
  480. data/src/core/lib/support/cpu_windows.c +10 -25
  481. data/src/core/lib/support/env.h +16 -25
  482. data/src/core/lib/support/env_linux.c +30 -37
  483. data/src/core/lib/support/env_posix.c +15 -25
  484. data/src/core/lib/support/env_windows.c +15 -25
  485. data/src/core/lib/support/histogram.c +10 -25
  486. data/src/core/lib/support/host_port.c +10 -25
  487. data/src/core/lib/support/log.c +20 -29
  488. data/src/core/lib/support/log_android.c +10 -25
  489. data/src/core/lib/support/log_linux.c +13 -26
  490. data/src/core/lib/support/log_posix.c +10 -25
  491. data/src/core/lib/support/log_windows.c +10 -25
  492. data/src/core/lib/support/memory.h +10 -25
  493. data/src/core/lib/support/mpscq.c +11 -49
  494. data/src/core/lib/support/mpscq.h +11 -50
  495. data/src/core/lib/support/murmur_hash.c +12 -25
  496. data/src/core/lib/support/murmur_hash.h +10 -25
  497. data/src/core/lib/support/spinlock.h +10 -25
  498. data/src/core/lib/support/stack_lockfree.c +10 -25
  499. data/src/core/lib/support/stack_lockfree.h +10 -25
  500. data/src/core/lib/support/string.c +10 -25
  501. data/src/core/lib/support/string.h +10 -25
  502. data/src/core/lib/support/string_posix.c +10 -25
  503. data/src/core/lib/support/string_util_windows.c +10 -25
  504. data/src/core/lib/support/string_windows.c +10 -25
  505. data/src/core/lib/support/string_windows.h +10 -25
  506. data/src/core/lib/support/subprocess_posix.c +10 -25
  507. data/src/core/lib/support/subprocess_windows.c +10 -25
  508. data/src/core/lib/support/sync.c +10 -25
  509. data/src/core/lib/support/sync_posix.c +10 -25
  510. data/src/core/lib/support/sync_windows.c +10 -25
  511. data/src/core/lib/support/thd.c +10 -25
  512. data/src/core/lib/support/thd_internal.h +10 -25
  513. data/src/core/lib/support/thd_posix.c +10 -25
  514. data/src/core/lib/support/thd_windows.c +10 -25
  515. data/src/core/lib/support/time.c +10 -25
  516. data/src/core/lib/support/time_posix.c +10 -25
  517. data/src/core/lib/support/time_precise.c +18 -33
  518. data/src/core/lib/support/time_precise.h +10 -25
  519. data/src/core/lib/support/time_windows.c +10 -25
  520. data/src/core/lib/support/tls_pthread.c +10 -25
  521. data/src/core/lib/support/tmpfile.h +10 -25
  522. data/src/core/lib/support/tmpfile_msys.c +10 -25
  523. data/src/core/lib/support/tmpfile_posix.c +10 -25
  524. data/src/core/lib/support/tmpfile_windows.c +10 -25
  525. data/src/core/lib/support/wrap_memcpy.c +10 -25
  526. data/src/core/lib/surface/alarm.c +78 -35
  527. data/src/core/lib/surface/alarm_internal.h +40 -0
  528. data/src/core/lib/surface/api_trace.c +11 -26
  529. data/src/core/lib/surface/api_trace.h +10 -25
  530. data/src/core/lib/surface/byte_buffer.c +10 -25
  531. data/src/core/lib/surface/byte_buffer_reader.c +10 -25
  532. data/src/core/lib/surface/call.c +64 -84
  533. data/src/core/lib/surface/call.h +11 -26
  534. data/src/core/lib/surface/call_details.c +10 -25
  535. data/src/core/lib/surface/call_log_batch.c +10 -25
  536. data/src/core/lib/surface/call_test_only.h +10 -25
  537. data/src/core/lib/surface/channel.c +11 -26
  538. data/src/core/lib/surface/channel.h +11 -26
  539. data/src/core/lib/surface/channel_init.c +10 -25
  540. data/src/core/lib/surface/channel_init.h +10 -25
  541. data/src/core/lib/surface/channel_ping.c +12 -27
  542. data/src/core/lib/surface/channel_stack_type.c +10 -25
  543. data/src/core/lib/surface/channel_stack_type.h +10 -25
  544. data/src/core/lib/surface/completion_queue.c +442 -331
  545. data/src/core/lib/surface/completion_queue.h +16 -33
  546. data/src/core/lib/surface/completion_queue_factory.c +10 -25
  547. data/src/core/lib/surface/completion_queue_factory.h +10 -25
  548. data/src/core/lib/surface/event_string.c +10 -25
  549. data/src/core/lib/surface/event_string.h +10 -25
  550. data/src/core/lib/surface/init.c +38 -47
  551. data/src/core/lib/surface/init.h +10 -25
  552. data/src/core/lib/surface/init_secure.c +20 -27
  553. data/src/core/lib/surface/lame_client.cc +14 -29
  554. data/src/core/lib/surface/lame_client.h +10 -25
  555. data/src/core/lib/surface/metadata_array.c +10 -25
  556. data/src/core/lib/surface/server.c +128 -81
  557. data/src/core/lib/surface/server.h +10 -25
  558. data/src/core/lib/surface/validate_metadata.c +10 -25
  559. data/src/core/lib/surface/validate_metadata.h +10 -25
  560. data/src/core/lib/surface/version.c +11 -26
  561. data/src/core/lib/transport/bdp_estimator.c +19 -29
  562. data/src/core/lib/transport/bdp_estimator.h +16 -29
  563. data/src/core/lib/transport/byte_stream.c +127 -36
  564. data/src/core/lib/transport/byte_stream.h +88 -46
  565. data/src/core/lib/transport/connectivity_state.c +17 -31
  566. data/src/core/lib/transport/connectivity_state.h +10 -25
  567. data/src/core/lib/transport/error_utils.c +10 -25
  568. data/src/core/lib/transport/error_utils.h +10 -25
  569. data/src/core/lib/transport/http2_errors.h +10 -25
  570. data/src/core/lib/transport/metadata.c +87 -85
  571. data/src/core/lib/transport/metadata.h +15 -28
  572. data/src/core/lib/transport/metadata_batch.c +10 -25
  573. data/src/core/lib/transport/metadata_batch.h +10 -25
  574. data/src/core/lib/transport/pid_controller.c +10 -25
  575. data/src/core/lib/transport/pid_controller.h +10 -25
  576. data/src/core/lib/transport/service_config.c +11 -26
  577. data/src/core/lib/transport/service_config.h +10 -25
  578. data/src/core/lib/transport/static_metadata.c +12 -26
  579. data/src/core/lib/transport/static_metadata.h +10 -25
  580. data/src/core/lib/transport/status_conversion.c +10 -25
  581. data/src/core/lib/transport/status_conversion.h +10 -25
  582. data/src/core/lib/transport/timeout_encoding.c +10 -25
  583. data/src/core/lib/transport/timeout_encoding.h +10 -25
  584. data/src/core/lib/transport/transport.c +60 -53
  585. data/src/core/lib/transport/transport.h +36 -34
  586. data/src/core/lib/transport/transport_impl.h +10 -25
  587. data/src/core/lib/transport/transport_op_string.c +10 -28
  588. data/src/core/plugin_registry/grpc_plugin_registry.c +22 -25
  589. data/src/core/tsi/fake_transport_security.c +199 -94
  590. data/src/core/tsi/fake_transport_security.h +11 -26
  591. data/src/core/tsi/gts_transport_security.c +40 -0
  592. data/src/core/tsi/gts_transport_security.h +37 -0
  593. data/src/core/tsi/ssl_transport_security.c +13 -32
  594. data/src/core/tsi/ssl_transport_security.h +10 -25
  595. data/src/core/tsi/ssl_types.h +10 -25
  596. data/src/core/tsi/transport_security.c +48 -78
  597. data/src/core/tsi/transport_security.h +18 -27
  598. data/src/core/tsi/transport_security_adapter.c +17 -29
  599. data/src/core/tsi/transport_security_adapter.h +10 -25
  600. data/src/core/tsi/transport_security_grpc.c +64 -0
  601. data/src/core/tsi/transport_security_grpc.h +80 -0
  602. data/src/core/tsi/transport_security_interface.h +21 -27
  603. data/src/ruby/bin/apis/google/protobuf/empty.rb +10 -25
  604. data/src/ruby/bin/apis/pubsub_demo.rb +10 -25
  605. data/src/ruby/bin/apis/tech/pubsub/proto/pubsub.rb +10 -25
  606. data/src/ruby/bin/apis/tech/pubsub/proto/pubsub_services.rb +10 -25
  607. data/src/ruby/bin/math_client.rb +10 -25
  608. data/src/ruby/bin/math_server.rb +10 -25
  609. data/src/ruby/bin/math_services_pb.rb +10 -25
  610. data/src/ruby/bin/noproto_client.rb +10 -25
  611. data/src/ruby/bin/noproto_server.rb +10 -25
  612. data/src/ruby/ext/grpc/extconf.rb +10 -25
  613. data/src/ruby/ext/grpc/rb_byte_buffer.c +10 -25
  614. data/src/ruby/ext/grpc/rb_byte_buffer.h +10 -25
  615. data/src/ruby/ext/grpc/rb_call.c +44 -25
  616. data/src/ruby/ext/grpc/rb_call.h +10 -25
  617. data/src/ruby/ext/grpc/rb_call_credentials.c +10 -25
  618. data/src/ruby/ext/grpc/rb_call_credentials.h +10 -25
  619. data/src/ruby/ext/grpc/rb_channel.c +10 -25
  620. data/src/ruby/ext/grpc/rb_channel.h +10 -25
  621. data/src/ruby/ext/grpc/rb_channel_args.c +10 -25
  622. data/src/ruby/ext/grpc/rb_channel_args.h +10 -25
  623. data/src/ruby/ext/grpc/rb_channel_credentials.c +10 -25
  624. data/src/ruby/ext/grpc/rb_channel_credentials.h +10 -25
  625. data/src/ruby/ext/grpc/rb_completion_queue.c +10 -25
  626. data/src/ruby/ext/grpc/rb_completion_queue.h +10 -25
  627. data/src/ruby/ext/grpc/rb_compression_options.c +10 -25
  628. data/src/ruby/ext/grpc/rb_compression_options.h +10 -25
  629. data/src/ruby/ext/grpc/rb_event_thread.c +10 -25
  630. data/src/ruby/ext/grpc/rb_event_thread.h +10 -25
  631. data/src/ruby/ext/grpc/rb_grpc.c +10 -25
  632. data/src/ruby/ext/grpc/rb_grpc.h +10 -25
  633. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +10 -25
  634. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +16 -31
  635. data/src/ruby/ext/grpc/rb_loader.c +10 -25
  636. data/src/ruby/ext/grpc/rb_loader.h +10 -25
  637. data/src/ruby/ext/grpc/rb_server.c +10 -25
  638. data/src/ruby/ext/grpc/rb_server.h +10 -25
  639. data/src/ruby/ext/grpc/rb_server_credentials.c +10 -25
  640. data/src/ruby/ext/grpc/rb_server_credentials.h +10 -25
  641. data/src/ruby/lib/grpc.rb +10 -25
  642. data/src/ruby/lib/grpc/core/time_consts.rb +10 -25
  643. data/src/ruby/lib/grpc/errors.rb +16 -30
  644. data/src/ruby/lib/grpc/generic/active_call.rb +25 -27
  645. data/src/ruby/lib/grpc/generic/bidi_call.rb +17 -27
  646. data/src/ruby/lib/grpc/generic/client_stub.rb +10 -25
  647. data/src/ruby/lib/grpc/generic/rpc_desc.rb +10 -25
  648. data/src/ruby/lib/grpc/generic/rpc_server.rb +10 -25
  649. data/src/ruby/lib/grpc/generic/service.rb +10 -25
  650. data/src/ruby/lib/grpc/grpc.rb +10 -25
  651. data/src/ruby/lib/grpc/logconfig.rb +10 -25
  652. data/src/ruby/lib/grpc/notifier.rb +10 -25
  653. data/src/ruby/lib/grpc/version.rb +11 -26
  654. data/src/ruby/pb/generate_proto_ruby.sh +10 -25
  655. data/src/ruby/pb/grpc/health/checker.rb +10 -25
  656. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +10 -25
  657. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +10 -25
  658. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +10 -25
  659. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +10 -25
  660. data/src/ruby/pb/test/client.rb +10 -25
  661. data/src/ruby/pb/test/server.rb +10 -25
  662. data/src/ruby/spec/call_credentials_spec.rb +10 -25
  663. data/src/ruby/spec/call_spec.rb +43 -25
  664. data/src/ruby/spec/channel_connection_spec.rb +10 -25
  665. data/src/ruby/spec/channel_credentials_spec.rb +11 -26
  666. data/src/ruby/spec/channel_spec.rb +10 -25
  667. data/src/ruby/spec/client_auth_spec.rb +10 -25
  668. data/src/ruby/spec/client_server_spec.rb +66 -25
  669. data/src/ruby/spec/compression_options_spec.rb +10 -25
  670. data/src/ruby/spec/error_sanity_spec.rb +10 -25
  671. data/src/ruby/spec/generic/active_call_spec.rb +10 -25
  672. data/src/ruby/spec/generic/client_stub_spec.rb +146 -35
  673. data/src/ruby/spec/generic/rpc_desc_spec.rb +10 -25
  674. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +10 -25
  675. data/src/ruby/spec/generic/rpc_server_spec.rb +124 -34
  676. data/src/ruby/spec/generic/service_spec.rb +10 -25
  677. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +10 -25
  678. data/src/ruby/spec/pb/health/checker_spec.rb +10 -25
  679. data/src/ruby/spec/server_credentials_spec.rb +10 -25
  680. data/src/ruby/spec/server_spec.rb +10 -25
  681. data/src/ruby/spec/spec_helper.rb +10 -25
  682. data/src/ruby/spec/time_consts_spec.rb +10 -25
  683. data/third_party/boringssl/crypto/aes/key_wrap.c +138 -0
  684. data/third_party/boringssl/crypto/asn1/a_bitstr.c +6 -3
  685. data/third_party/boringssl/crypto/asn1/a_enum.c +4 -1
  686. data/third_party/boringssl/crypto/asn1/a_gentm.c +20 -15
  687. data/third_party/boringssl/crypto/asn1/a_int.c +7 -4
  688. data/third_party/boringssl/crypto/asn1/a_object.c +5 -2
  689. data/third_party/boringssl/crypto/asn1/a_time.c +0 -1
  690. data/third_party/boringssl/crypto/asn1/a_utctm.c +1 -2
  691. data/third_party/boringssl/crypto/asn1/asn1_lib.c +5 -2
  692. data/third_party/boringssl/crypto/asn1/asn1_locl.h +35 -0
  693. data/third_party/boringssl/crypto/asn1/tasn_dec.c +3 -1
  694. data/third_party/boringssl/crypto/asn1/tasn_enc.c +6 -3
  695. data/third_party/boringssl/crypto/asn1/tasn_new.c +12 -7
  696. data/third_party/boringssl/crypto/asn1/tasn_utl.c +22 -8
  697. data/third_party/boringssl/crypto/{time_support.c → asn1/time_support.c} +1 -1
  698. data/third_party/boringssl/crypto/asn1/x_long.c +5 -2
  699. data/third_party/boringssl/crypto/base64/base64.c +7 -5
  700. data/third_party/boringssl/crypto/bio/bio.c +24 -10
  701. data/third_party/boringssl/crypto/bio/bio_mem.c +12 -10
  702. data/third_party/boringssl/crypto/bio/connect.c +7 -18
  703. data/third_party/boringssl/crypto/bio/fd.c +3 -6
  704. data/third_party/boringssl/crypto/bio/file.c +6 -6
  705. data/third_party/boringssl/crypto/bio/hexdump.c +4 -2
  706. data/third_party/boringssl/crypto/bio/pair.c +30 -344
  707. data/third_party/boringssl/crypto/bio/socket.c +6 -7
  708. data/third_party/boringssl/crypto/bio/socket_helper.c +4 -3
  709. data/third_party/boringssl/crypto/bn/add.c +1 -1
  710. data/third_party/boringssl/crypto/bn/asm/x86_64-gcc.c +11 -10
  711. data/third_party/boringssl/crypto/bn/bn.c +6 -20
  712. data/third_party/boringssl/crypto/bn/cmp.c +14 -0
  713. data/third_party/boringssl/crypto/bn/convert.c +73 -2
  714. data/third_party/boringssl/crypto/bn/ctx.c +3 -1
  715. data/third_party/boringssl/crypto/bn/div.c +108 -51
  716. data/third_party/boringssl/crypto/bn/exponentiation.c +15 -33
  717. data/third_party/boringssl/crypto/bn/gcd.c +29 -22
  718. data/third_party/boringssl/crypto/bn/generic.c +71 -67
  719. data/third_party/boringssl/crypto/bn/internal.h +19 -6
  720. data/third_party/boringssl/crypto/bn/kronecker.c +1 -0
  721. data/third_party/boringssl/crypto/bn/montgomery.c +9 -10
  722. data/third_party/boringssl/crypto/bn/montgomery_inv.c +47 -0
  723. data/third_party/boringssl/crypto/bn/mul.c +11 -9
  724. data/third_party/boringssl/crypto/bn/random.c +6 -3
  725. data/third_party/boringssl/crypto/bn/rsaz_exp.c +0 -65
  726. data/third_party/boringssl/crypto/bn/rsaz_exp.h +0 -3
  727. data/third_party/boringssl/crypto/bn/shift.c +9 -1
  728. data/third_party/boringssl/crypto/bn/sqrt.c +3 -1
  729. data/third_party/boringssl/crypto/buf/buf.c +6 -4
  730. data/third_party/boringssl/crypto/bytestring/asn1_compat.c +2 -1
  731. data/third_party/boringssl/crypto/bytestring/ber.c +2 -1
  732. data/third_party/boringssl/crypto/bytestring/cbb.c +9 -7
  733. data/third_party/boringssl/crypto/bytestring/cbs.c +54 -2
  734. data/third_party/boringssl/crypto/chacha/chacha.c +1 -1
  735. data/third_party/boringssl/crypto/cipher/aead.c +3 -3
  736. data/third_party/boringssl/crypto/cipher/cipher.c +18 -13
  737. data/third_party/boringssl/crypto/cipher/e_aes.c +335 -281
  738. data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +113 -137
  739. data/third_party/boringssl/crypto/cipher/e_null.c +2 -1
  740. data/third_party/boringssl/crypto/cipher/e_rc2.c +54 -49
  741. data/third_party/boringssl/crypto/cipher/e_ssl3.c +4 -3
  742. data/third_party/boringssl/crypto/cipher/e_tls.c +5 -5
  743. data/third_party/boringssl/crypto/cipher/tls_cbc.c +41 -112
  744. data/third_party/boringssl/crypto/cmac/cmac.c +6 -4
  745. data/third_party/boringssl/crypto/conf/conf.c +6 -3
  746. data/third_party/boringssl/crypto/cpu-arm-linux.c +2 -2
  747. data/third_party/boringssl/crypto/curve25519/curve25519.c +28 -34
  748. data/third_party/boringssl/crypto/curve25519/spake25519.c +7 -6
  749. data/third_party/boringssl/crypto/curve25519/x25519-x86_64.c +2 -1
  750. data/third_party/boringssl/crypto/des/des.c +1 -1
  751. data/third_party/boringssl/crypto/des/internal.h +58 -46
  752. data/third_party/boringssl/crypto/dh/dh.c +4 -8
  753. data/third_party/boringssl/crypto/digest/digest.c +5 -2
  754. data/third_party/boringssl/crypto/digest/digests.c +70 -33
  755. data/third_party/boringssl/crypto/digest/md32_common.h +39 -27
  756. data/third_party/boringssl/crypto/dsa/dsa.c +11 -19
  757. data/third_party/boringssl/crypto/ec/ec.c +1 -1
  758. data/third_party/boringssl/crypto/ec/ec_asn1.c +3 -2
  759. data/third_party/boringssl/crypto/ec/ec_key.c +1 -1
  760. data/third_party/boringssl/crypto/ec/ec_montgomery.c +6 -11
  761. data/third_party/boringssl/crypto/ec/oct.c +2 -14
  762. data/third_party/boringssl/crypto/ec/p224-64.c +78 -122
  763. data/third_party/boringssl/crypto/ec/p256-64.c +93 -133
  764. data/third_party/boringssl/crypto/ec/p256-x86_64.c +48 -61
  765. data/third_party/boringssl/crypto/ec/p256-x86_64.h +113 -0
  766. data/third_party/boringssl/crypto/ec/simple.c +2 -1
  767. data/third_party/boringssl/crypto/ec/wnaf.c +52 -43
  768. data/third_party/boringssl/crypto/ecdh/ecdh.c +4 -2
  769. data/third_party/boringssl/crypto/ecdsa/ecdsa.c +17 -16
  770. data/third_party/boringssl/crypto/engine/engine.c +3 -1
  771. data/third_party/boringssl/crypto/err/err.c +5 -5
  772. data/third_party/boringssl/crypto/evp/evp.c +1 -1
  773. data/third_party/boringssl/crypto/evp/evp_asn1.c +1 -1
  774. data/third_party/boringssl/crypto/evp/evp_ctx.c +23 -29
  775. data/third_party/boringssl/crypto/evp/p_ec.c +2 -1
  776. data/third_party/boringssl/crypto/evp/p_rsa.c +9 -3
  777. data/third_party/boringssl/crypto/evp/pbkdf.c +3 -1
  778. data/third_party/boringssl/crypto/hkdf/hkdf.c +3 -1
  779. data/third_party/boringssl/crypto/hmac/hmac.c +4 -2
  780. data/third_party/boringssl/crypto/internal.h +81 -0
  781. data/third_party/boringssl/crypto/lhash/lhash.c +7 -13
  782. data/third_party/boringssl/crypto/md4/md4.c +20 -18
  783. data/third_party/boringssl/crypto/md5/md5.c +31 -21
  784. data/third_party/boringssl/crypto/mem.c +4 -10
  785. data/third_party/boringssl/crypto/modes/cbc.c +2 -6
  786. data/third_party/boringssl/crypto/modes/cfb.c +2 -2
  787. data/third_party/boringssl/crypto/modes/ctr.c +1 -1
  788. data/third_party/boringssl/crypto/modes/gcm.c +117 -334
  789. data/third_party/boringssl/crypto/modes/internal.h +107 -84
  790. data/third_party/boringssl/crypto/modes/ofb.c +3 -3
  791. data/third_party/boringssl/crypto/modes/polyval.c +94 -0
  792. data/third_party/boringssl/crypto/obj/obj.c +13 -8
  793. data/third_party/boringssl/crypto/obj/obj_dat.h +6109 -5187
  794. data/third_party/boringssl/crypto/obj/obj_xref.c +55 -57
  795. data/third_party/boringssl/crypto/pem/pem_lib.c +6 -3
  796. data/third_party/boringssl/crypto/pkcs8/internal.h +27 -8
  797. data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +137 -352
  798. data/third_party/boringssl/crypto/pkcs8/pkcs8.c +371 -364
  799. data/third_party/boringssl/crypto/poly1305/poly1305.c +12 -18
  800. data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +2 -2
  801. data/third_party/boringssl/crypto/{newhope/reduce.c → pool/internal.h} +24 -21
  802. data/third_party/boringssl/crypto/pool/pool.c +200 -0
  803. data/third_party/boringssl/crypto/rand/deterministic.c +6 -5
  804. data/third_party/boringssl/crypto/rand/fuchsia.c +43 -0
  805. data/third_party/boringssl/crypto/rand/rand.c +7 -7
  806. data/third_party/boringssl/crypto/rand/urandom.c +136 -22
  807. data/third_party/boringssl/crypto/rand/windows.c +2 -2
  808. data/third_party/boringssl/crypto/rsa/blinding.c +2 -1
  809. data/third_party/boringssl/crypto/rsa/padding.c +11 -11
  810. data/third_party/boringssl/crypto/rsa/rsa.c +4 -4
  811. data/third_party/boringssl/crypto/rsa/rsa_asn1.c +7 -1
  812. data/third_party/boringssl/crypto/rsa/rsa_impl.c +41 -80
  813. data/third_party/boringssl/crypto/sha/sha1-altivec.c +346 -0
  814. data/third_party/boringssl/crypto/sha/sha1.c +60 -42
  815. data/third_party/boringssl/crypto/sha/sha256.c +4 -2
  816. data/third_party/boringssl/crypto/sha/sha512.c +9 -7
  817. data/third_party/boringssl/crypto/stack/stack.c +10 -7
  818. data/third_party/boringssl/crypto/thread_pthread.c +2 -2
  819. data/third_party/boringssl/crypto/thread_win.c +2 -2
  820. data/third_party/boringssl/crypto/x509/a_verify.c +1 -1
  821. data/third_party/boringssl/crypto/x509/asn1_gen.c +1 -1
  822. data/third_party/boringssl/crypto/x509/by_dir.c +1 -1
  823. data/third_party/boringssl/crypto/x509/t_x509.c +78 -38
  824. data/third_party/boringssl/crypto/x509/x509_cmp.c +8 -5
  825. data/third_party/boringssl/crypto/x509/x509_lu.c +6 -1
  826. data/third_party/boringssl/crypto/x509/x509_obj.c +4 -1
  827. data/third_party/boringssl/crypto/x509/x509_vfy.c +42 -8
  828. data/third_party/boringssl/crypto/x509/x509_vpm.c +8 -6
  829. data/third_party/boringssl/crypto/x509/x509name.c +4 -1
  830. data/third_party/boringssl/crypto/x509/x_crl.c +4 -2
  831. data/third_party/boringssl/crypto/x509/x_name.c +23 -13
  832. data/third_party/boringssl/crypto/x509/x_pkey.c +4 -1
  833. data/third_party/boringssl/crypto/x509/x_x509.c +42 -3
  834. data/third_party/boringssl/crypto/x509v3/pcy_int.h +2 -2
  835. data/third_party/boringssl/crypto/x509v3/pcy_tree.c +2 -1
  836. data/third_party/boringssl/crypto/x509v3/v3_cpols.c +1 -1
  837. data/third_party/boringssl/crypto/x509v3/v3_ia5.c +4 -1
  838. data/third_party/boringssl/crypto/x509v3/v3_ncons.c +4 -1
  839. data/third_party/boringssl/crypto/x509v3/v3_pci.c +6 -3
  840. data/third_party/boringssl/crypto/x509v3/v3_purp.c +13 -21
  841. data/third_party/boringssl/crypto/x509v3/v3_utl.c +19 -33
  842. data/third_party/boringssl/include/openssl/aead.h +9 -20
  843. data/third_party/boringssl/include/openssl/aes.h +21 -9
  844. data/third_party/boringssl/include/openssl/asn1.h +9 -1
  845. data/third_party/boringssl/include/openssl/base.h +33 -6
  846. data/third_party/boringssl/include/openssl/bio.h +10 -103
  847. data/third_party/boringssl/include/openssl/bn.h +58 -42
  848. data/third_party/boringssl/include/openssl/bytestring.h +17 -0
  849. data/third_party/boringssl/include/openssl/cipher.h +4 -3
  850. data/third_party/boringssl/include/openssl/conf.h +4 -1
  851. data/third_party/boringssl/include/openssl/curve25519.h +13 -0
  852. data/third_party/boringssl/include/openssl/digest.h +5 -3
  853. data/third_party/boringssl/include/openssl/dsa.h +5 -5
  854. data/third_party/boringssl/include/openssl/ec.h +2 -2
  855. data/third_party/boringssl/include/openssl/ecdh.h +3 -4
  856. data/third_party/boringssl/include/openssl/ecdsa.h +10 -10
  857. data/third_party/boringssl/include/openssl/err.h +5 -5
  858. data/third_party/boringssl/include/openssl/evp.h +11 -7
  859. data/third_party/boringssl/include/openssl/lhash.h +2 -3
  860. data/third_party/boringssl/include/openssl/lhash_macros.h +56 -14
  861. data/third_party/boringssl/include/openssl/nid.h +2949 -2916
  862. data/third_party/boringssl/include/openssl/obj.h +1 -1
  863. data/third_party/boringssl/include/openssl/pkcs8.h +21 -42
  864. data/third_party/boringssl/include/openssl/pool.h +87 -0
  865. data/third_party/boringssl/include/openssl/rand.h +1 -1
  866. data/third_party/boringssl/include/openssl/rsa.h +4 -2
  867. data/third_party/boringssl/include/openssl/sha.h +0 -4
  868. data/third_party/boringssl/include/openssl/ssl.h +327 -662
  869. data/third_party/boringssl/include/openssl/ssl3.h +1 -21
  870. data/third_party/boringssl/include/openssl/stack.h +1 -0
  871. data/third_party/boringssl/include/openssl/stack_macros.h +85 -0
  872. data/third_party/boringssl/include/openssl/tls1.h +23 -52
  873. data/third_party/boringssl/include/openssl/type_check.h +4 -0
  874. data/third_party/boringssl/include/openssl/x509.h +10 -59
  875. data/third_party/boringssl/include/openssl/x509_vfy.h +7 -1
  876. data/third_party/boringssl/include/openssl/x509v3.h +4 -4
  877. data/third_party/boringssl/ssl/bio_ssl.c +175 -0
  878. data/third_party/boringssl/ssl/custom_extensions.c +24 -21
  879. data/third_party/boringssl/ssl/d1_both.c +259 -289
  880. data/third_party/boringssl/ssl/d1_lib.c +8 -20
  881. data/third_party/boringssl/ssl/d1_pkt.c +6 -15
  882. data/third_party/boringssl/ssl/dtls_method.c +22 -8
  883. data/third_party/boringssl/ssl/dtls_record.c +27 -2
  884. data/third_party/boringssl/ssl/handshake_client.c +460 -579
  885. data/third_party/boringssl/ssl/handshake_server.c +662 -644
  886. data/third_party/boringssl/ssl/internal.h +1009 -375
  887. data/third_party/boringssl/ssl/s3_both.c +312 -162
  888. data/third_party/boringssl/ssl/s3_lib.c +12 -128
  889. data/third_party/boringssl/ssl/s3_pkt.c +22 -30
  890. data/third_party/boringssl/ssl/ssl_aead_ctx.c +28 -22
  891. data/third_party/boringssl/ssl/ssl_asn1.c +210 -114
  892. data/third_party/boringssl/ssl/ssl_buffer.c +2 -1
  893. data/third_party/boringssl/ssl/ssl_cert.c +417 -219
  894. data/third_party/boringssl/ssl/ssl_cipher.c +191 -393
  895. data/third_party/boringssl/ssl/ssl_ecdh.c +19 -164
  896. data/third_party/boringssl/ssl/ssl_file.c +0 -11
  897. data/third_party/boringssl/ssl/ssl_lib.c +325 -652
  898. data/third_party/boringssl/ssl/{ssl_rsa.c → ssl_privkey.c} +21 -131
  899. data/third_party/boringssl/ssl/ssl_privkey_cc.cc +76 -0
  900. data/third_party/boringssl/ssl/ssl_session.c +206 -95
  901. data/third_party/boringssl/ssl/ssl_stat.c +18 -84
  902. data/third_party/boringssl/ssl/{s3_enc.c → ssl_transcript.c} +150 -157
  903. data/third_party/boringssl/ssl/ssl_x509.c +815 -0
  904. data/third_party/boringssl/ssl/t1_enc.c +188 -174
  905. data/third_party/boringssl/ssl/t1_lib.c +1064 -764
  906. data/third_party/boringssl/ssl/tls13_both.c +290 -96
  907. data/third_party/boringssl/ssl/tls13_client.c +344 -314
  908. data/third_party/boringssl/ssl/tls13_enc.c +239 -200
  909. data/third_party/boringssl/ssl/tls13_server.c +374 -366
  910. data/third_party/boringssl/ssl/tls_method.c +40 -5
  911. data/third_party/boringssl/ssl/tls_record.c +166 -71
  912. metadata +39 -25
  913. data/src/core/lib/iomgr/workqueue.h +0 -87
  914. data/src/core/lib/iomgr/workqueue_uv.c +0 -65
  915. data/src/core/lib/iomgr/workqueue_uv.h +0 -37
  916. data/src/core/lib/iomgr/workqueue_windows.c +0 -63
  917. data/src/core/lib/iomgr/workqueue_windows.h +0 -37
  918. data/third_party/boringssl/crypto/bio/buffer.c +0 -496
  919. data/third_party/boringssl/crypto/newhope/error_correction.c +0 -131
  920. data/third_party/boringssl/crypto/newhope/internal.h +0 -71
  921. data/third_party/boringssl/crypto/newhope/newhope.c +0 -174
  922. data/third_party/boringssl/crypto/newhope/ntt.c +0 -148
  923. data/third_party/boringssl/crypto/newhope/poly.c +0 -183
  924. data/third_party/boringssl/crypto/newhope/precomp.c +0 -306
  925. data/third_party/boringssl/crypto/obj/obj_xref.h +0 -96
  926. data/third_party/boringssl/crypto/pkcs8/p5_pbe.c +0 -151
  927. data/third_party/boringssl/include/openssl/newhope.h +0 -158
  928. data/third_party/boringssl/include/openssl/time_support.h +0 -91
@@ -64,9 +64,11 @@
64
64
  #include <openssl/mem.h>
65
65
  #include <openssl/nid.h>
66
66
 
67
+ #include "../crypto/internal.h"
67
68
  #include "internal.h"
68
69
 
69
70
 
71
+
70
72
  /* DTLS1_MTU_TIMEOUTS is the maximum number of timeouts to expire
71
73
  * before starting to decrease the MTU. */
72
74
  #define DTLS1_MTU_TIMEOUTS 2
@@ -86,7 +88,7 @@ int dtls1_new(SSL *ssl) {
86
88
  ssl3_free(ssl);
87
89
  return 0;
88
90
  }
89
- memset(d1, 0, sizeof *d1);
91
+ OPENSSL_memset(d1, 0, sizeof *d1);
90
92
 
91
93
  ssl->d1 = d1;
92
94
 
@@ -113,10 +115,6 @@ void dtls1_free(SSL *ssl) {
113
115
  ssl->d1 = NULL;
114
116
  }
115
117
 
116
- int dtls1_supports_cipher(const SSL_CIPHER *cipher) {
117
- return cipher->algorithm_enc != SSL_eNULL;
118
- }
119
-
120
118
  void DTLSv1_set_initial_timeout_duration(SSL *ssl, unsigned int duration_ms) {
121
119
  ssl->initial_timeout_duration_ms = duration_ms;
122
120
  }
@@ -158,12 +156,12 @@ int DTLSv1_get_timeout(const SSL *ssl, struct timeval *out) {
158
156
  if (ssl->d1->next_timeout.tv_sec < timenow.tv_sec ||
159
157
  (ssl->d1->next_timeout.tv_sec == timenow.tv_sec &&
160
158
  ssl->d1->next_timeout.tv_usec <= timenow.tv_usec)) {
161
- memset(out, 0, sizeof(struct timeval));
159
+ OPENSSL_memset(out, 0, sizeof(struct timeval));
162
160
  return 1;
163
161
  }
164
162
 
165
163
  /* Calculate time left until timer expires */
166
- memcpy(out, &ssl->d1->next_timeout, sizeof(struct timeval));
164
+ OPENSSL_memcpy(out, &ssl->d1->next_timeout, sizeof(struct timeval));
167
165
  out->tv_sec -= timenow.tv_sec;
168
166
  out->tv_usec -= timenow.tv_usec;
169
167
  if (out->tv_usec < 0) {
@@ -174,7 +172,7 @@ int DTLSv1_get_timeout(const SSL *ssl, struct timeval *out) {
174
172
  /* If remaining time is less than 15 ms, set it to 0 to prevent issues
175
173
  * because of small devergences with socket timeouts. */
176
174
  if (out->tv_sec == 0 && out->tv_usec < 15000) {
177
- memset(out, 0, sizeof(struct timeval));
175
+ OPENSSL_memset(out, 0, sizeof(struct timeval));
178
176
  }
179
177
 
180
178
  return 1;
@@ -208,7 +206,7 @@ void dtls1_double_timeout(SSL *ssl) {
208
206
  void dtls1_stop_timer(SSL *ssl) {
209
207
  /* Reset everything */
210
208
  ssl->d1->num_timeouts = 0;
211
- memset(&ssl->d1->next_timeout, 0, sizeof(struct timeval));
209
+ OPENSSL_memset(&ssl->d1->next_timeout, 0, sizeof(struct timeval));
212
210
  ssl->d1->timeout_duration_ms = ssl->initial_timeout_duration_ms;
213
211
  BIO_ctrl(ssl->rbio, BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0,
214
212
  &ssl->d1->next_timeout);
@@ -238,9 +236,7 @@ int dtls1_check_timeout_num(SSL *ssl) {
238
236
  }
239
237
 
240
238
  int DTLSv1_handle_timeout(SSL *ssl) {
241
- ssl->rwstate = SSL_NOTHING;
242
- /* Functions which use SSL_get_error must clear the error queue on entry. */
243
- ERR_clear_error();
239
+ ssl_reset_error_state(ssl);
244
240
 
245
241
  if (!SSL_is_dtls(ssl)) {
246
242
  return -1;
@@ -260,11 +256,3 @@ int DTLSv1_handle_timeout(SSL *ssl) {
260
256
  dtls1_start_timer(ssl);
261
257
  return dtls1_retransmit_outgoing_messages(ssl);
262
258
  }
263
-
264
- void dtls1_expect_flight(SSL *ssl) {
265
- dtls1_start_timer(ssl);
266
- }
267
-
268
- void dtls1_received_flight(SSL *ssl) {
269
- dtls1_stop_timer(ssl);
270
- }
@@ -122,6 +122,7 @@
122
122
  #include <openssl/err.h>
123
123
  #include <openssl/rand.h>
124
124
 
125
+ #include "../crypto/internal.h"
125
126
  #include "internal.h"
126
127
 
127
128
 
@@ -265,7 +266,7 @@ again:
265
266
  len = rr->length;
266
267
  }
267
268
 
268
- memcpy(buf, rr->data, len);
269
+ OPENSSL_memcpy(buf, rr->data, len);
269
270
  if (!peek) {
270
271
  /* TODO(davidben): Should the record be truncated instead? This is a
271
272
  * datagram transport. See https://crbug.com/boringssl/65. */
@@ -330,7 +331,7 @@ void dtls1_read_close_notify(SSL *ssl) {
330
331
  }
331
332
  }
332
333
 
333
- int dtls1_write_app_data(SSL *ssl, const void *buf_, int len) {
334
+ int dtls1_write_app_data(SSL *ssl, const uint8_t *buf, int len) {
334
335
  assert(!SSL_in_init(ssl));
335
336
 
336
337
  if (len > SSL3_RT_MAX_PLAIN_LENGTH) {
@@ -347,7 +348,7 @@ int dtls1_write_app_data(SSL *ssl, const void *buf_, int len) {
347
348
  return 0;
348
349
  }
349
350
 
350
- int ret = dtls1_write_record(ssl, SSL3_RT_APPLICATION_DATA, buf_, (size_t)len,
351
+ int ret = dtls1_write_record(ssl, SSL3_RT_APPLICATION_DATA, buf, (size_t)len,
351
352
  dtls1_use_current_epoch);
352
353
  if (ret <= 0) {
353
354
  return ret;
@@ -363,21 +364,12 @@ int dtls1_write_record(SSL *ssl, int type, const uint8_t *buf, size_t len,
363
364
  * |ssl_write_buffer_flush|. */
364
365
  assert(!ssl_write_buffer_is_pending(ssl));
365
366
 
366
- /* If we have an alert to send, lets send it */
367
- if (ssl->s3->alert_dispatch) {
368
- int ret = ssl->method->dispatch_alert(ssl);
369
- if (ret <= 0) {
370
- return ret;
371
- }
372
- /* if it went, fall through and send more stuff */
373
- }
374
-
375
367
  if (len > SSL3_RT_MAX_PLAIN_LENGTH) {
376
368
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
377
369
  return -1;
378
370
  }
379
371
 
380
- size_t max_out = len + ssl_max_seal_overhead(ssl);
372
+ size_t max_out = len + SSL_max_seal_overhead(ssl);
381
373
  uint8_t *out;
382
374
  size_t ciphertext_len;
383
375
  if (!ssl_write_buffer_init(ssl, &out, max_out) ||
@@ -396,13 +388,12 @@ int dtls1_write_record(SSL *ssl, int type, const uint8_t *buf, size_t len,
396
388
  }
397
389
 
398
390
  int dtls1_dispatch_alert(SSL *ssl) {
399
- ssl->s3->alert_dispatch = 0;
400
391
  int ret = dtls1_write_record(ssl, SSL3_RT_ALERT, &ssl->s3->send_alert[0], 2,
401
392
  dtls1_use_current_epoch);
402
393
  if (ret <= 0) {
403
- ssl->s3->alert_dispatch = 1;
404
394
  return ret;
405
395
  }
396
+ ssl->s3->alert_dispatch = 0;
406
397
 
407
398
  /* If the alert is fatal, flush the BIO now. */
408
399
  if (ssl->s3->send_alert[0] == SSL3_AL_FATAL) {
@@ -62,6 +62,7 @@
62
62
  #include <openssl/buf.h>
63
63
  #include <openssl/err.h>
64
64
 
65
+ #include "../crypto/internal.h"
65
66
  #include "internal.h"
66
67
 
67
68
 
@@ -94,6 +95,14 @@ static uint16_t dtls1_version_to_wire(uint16_t version) {
94
95
  return 0;
95
96
  }
96
97
 
98
+ static int dtls1_supports_cipher(const SSL_CIPHER *cipher) {
99
+ return cipher->algorithm_enc != SSL_eNULL;
100
+ }
101
+
102
+ static void dtls1_expect_flight(SSL *ssl) { dtls1_start_timer(ssl); }
103
+
104
+ static void dtls1_received_flight(SSL *ssl) { dtls1_stop_timer(ssl); }
105
+
97
106
  static int dtls1_set_read_state(SSL *ssl, SSL_AEAD_CTX *aead_ctx) {
98
107
  /* Cipher changes are illegal when there are buffered incoming messages. */
99
108
  if (dtls_has_incoming_messages(ssl)) {
@@ -104,8 +113,8 @@ static int dtls1_set_read_state(SSL *ssl, SSL_AEAD_CTX *aead_ctx) {
104
113
  }
105
114
 
106
115
  ssl->d1->r_epoch++;
107
- memset(&ssl->d1->bitmap, 0, sizeof(ssl->d1->bitmap));
108
- memset(ssl->s3->read_sequence, 0, sizeof(ssl->s3->read_sequence));
116
+ OPENSSL_memset(&ssl->d1->bitmap, 0, sizeof(ssl->d1->bitmap));
117
+ OPENSSL_memset(ssl->s3->read_sequence, 0, sizeof(ssl->s3->read_sequence));
109
118
 
110
119
  SSL_AEAD_CTX_free(ssl->s3->aead_read_ctx);
111
120
  ssl->s3->aead_read_ctx = aead_ctx;
@@ -114,9 +123,9 @@ static int dtls1_set_read_state(SSL *ssl, SSL_AEAD_CTX *aead_ctx) {
114
123
 
115
124
  static int dtls1_set_write_state(SSL *ssl, SSL_AEAD_CTX *aead_ctx) {
116
125
  ssl->d1->w_epoch++;
117
- memcpy(ssl->d1->last_write_sequence, ssl->s3->write_sequence,
118
- sizeof(ssl->s3->write_sequence));
119
- memset(ssl->s3->write_sequence, 0, sizeof(ssl->s3->write_sequence));
126
+ OPENSSL_memcpy(ssl->d1->last_write_sequence, ssl->s3->write_sequence,
127
+ sizeof(ssl->s3->write_sequence));
128
+ OPENSSL_memset(ssl->s3->write_sequence, 0, sizeof(ssl->s3->write_sequence));
120
129
 
121
130
  SSL_AEAD_CTX_free(ssl->s3->aead_write_ctx);
122
131
  ssl->s3->aead_write_ctx = aead_ctx;
@@ -132,7 +141,7 @@ static const SSL_PROTOCOL_METHOD kDTLSProtocolMethod = {
132
141
  dtls1_new,
133
142
  dtls1_free,
134
143
  dtls1_get_message,
135
- dtls1_hash_current_message,
144
+ dtls1_get_current_message,
136
145
  dtls1_release_current_message,
137
146
  dtls1_read_app_data,
138
147
  dtls1_read_change_cipher_spec,
@@ -142,8 +151,10 @@ static const SSL_PROTOCOL_METHOD kDTLSProtocolMethod = {
142
151
  dtls1_supports_cipher,
143
152
  dtls1_init_message,
144
153
  dtls1_finish_message,
145
- dtls1_write_message,
146
- dtls1_send_change_cipher_spec,
154
+ dtls1_add_message,
155
+ dtls1_add_change_cipher_spec,
156
+ dtls1_add_alert,
157
+ dtls1_flush_flight,
147
158
  dtls1_expect_flight,
148
159
  dtls1_received_flight,
149
160
  dtls1_set_read_state,
@@ -154,6 +165,7 @@ const SSL_METHOD *DTLS_method(void) {
154
165
  static const SSL_METHOD kMethod = {
155
166
  0,
156
167
  &kDTLSProtocolMethod,
168
+ &ssl_crypto_x509_method,
157
169
  };
158
170
  return &kMethod;
159
171
  }
@@ -164,6 +176,7 @@ const SSL_METHOD *DTLSv1_2_method(void) {
164
176
  static const SSL_METHOD kMethod = {
165
177
  DTLS1_2_VERSION,
166
178
  &kDTLSProtocolMethod,
179
+ &ssl_crypto_x509_method,
167
180
  };
168
181
  return &kMethod;
169
182
  }
@@ -172,6 +185,7 @@ const SSL_METHOD *DTLSv1_method(void) {
172
185
  static const SSL_METHOD kMethod = {
173
186
  DTLS1_VERSION,
174
187
  &kDTLSProtocolMethod,
188
+ &ssl_crypto_x509_method,
175
189
  };
176
190
  return &kMethod;
177
191
  }
@@ -249,10 +249,35 @@ enum ssl_open_record_t dtls_open_record(SSL *ssl, uint8_t *out_type, CBS *out,
249
249
  return ssl_open_record_success;
250
250
  }
251
251
 
252
+ static const SSL_AEAD_CTX *get_write_aead(const SSL *ssl,
253
+ enum dtls1_use_epoch_t use_epoch) {
254
+ if (use_epoch == dtls1_use_previous_epoch) {
255
+ /* DTLS renegotiation is unsupported, so only epochs 0 (NULL cipher) and 1
256
+ * (negotiated cipher) exist. */
257
+ assert(ssl->d1->w_epoch == 1);
258
+ return NULL;
259
+ }
260
+
261
+ return ssl->s3->aead_write_ctx;
262
+ }
263
+
264
+ size_t dtls_max_seal_overhead(const SSL *ssl,
265
+ enum dtls1_use_epoch_t use_epoch) {
266
+ return DTLS1_RT_HEADER_LENGTH +
267
+ SSL_AEAD_CTX_max_overhead(get_write_aead(ssl, use_epoch));
268
+ }
269
+
270
+ size_t dtls_seal_prefix_len(const SSL *ssl, enum dtls1_use_epoch_t use_epoch) {
271
+ return DTLS1_RT_HEADER_LENGTH +
272
+ SSL_AEAD_CTX_explicit_nonce_len(get_write_aead(ssl, use_epoch));
273
+ }
274
+
252
275
  int dtls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
253
276
  uint8_t type, const uint8_t *in, size_t in_len,
254
277
  enum dtls1_use_epoch_t use_epoch) {
255
- if (buffers_alias(in, in_len, out, max_out)) {
278
+ const size_t prefix = dtls_seal_prefix_len(ssl, use_epoch);
279
+ if (buffers_alias(in, in_len, out, max_out) &&
280
+ (max_out < prefix || out + prefix != in)) {
256
281
  OPENSSL_PUT_ERROR(SSL, SSL_R_OUTPUT_ALIASES_INPUT);
257
282
  return 0;
258
283
  }
@@ -283,7 +308,7 @@ int dtls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
283
308
 
284
309
  out[3] = epoch >> 8;
285
310
  out[4] = epoch & 0xff;
286
- memcpy(&out[5], &seq[2], 6);
311
+ OPENSSL_memcpy(&out[5], &seq[2], 6);
287
312
 
288
313
  size_t ciphertext_len;
289
314
  if (!SSL_AEAD_CTX_seal(aead, out + DTLS1_RT_HEADER_LENGTH, &ciphertext_len,
@@ -152,6 +152,7 @@
152
152
  #include <assert.h>
153
153
  #include <string.h>
154
154
 
155
+ #include <openssl/aead.h>
155
156
  #include <openssl/bn.h>
156
157
  #include <openssl/buf.h>
157
158
  #include <openssl/bytestring.h>
@@ -166,90 +167,73 @@
166
167
  #include <openssl/x509.h>
167
168
  #include <openssl/x509v3.h>
168
169
 
170
+ #include "../crypto/internal.h"
169
171
  #include "internal.h"
170
172
 
171
173
 
172
- static int ssl3_send_client_hello(SSL *ssl);
173
- static int dtls1_get_hello_verify(SSL *ssl);
174
- static int ssl3_get_server_hello(SSL *ssl);
175
- static int ssl3_get_server_certificate(SSL *ssl);
176
- static int ssl3_get_cert_status(SSL *ssl);
177
- static int ssl3_verify_server_cert(SSL *ssl);
178
- static int ssl3_get_server_key_exchange(SSL *ssl);
179
- static int ssl3_get_certificate_request(SSL *ssl);
180
- static int ssl3_get_server_hello_done(SSL *ssl);
181
- static int ssl3_send_client_certificate(SSL *ssl);
182
- static int ssl3_send_client_key_exchange(SSL *ssl);
183
- static int ssl3_send_cert_verify(SSL *ssl);
184
- static int ssl3_send_next_proto(SSL *ssl);
185
- static int ssl3_send_channel_id(SSL *ssl);
186
- static int ssl3_get_new_session_ticket(SSL *ssl);
187
-
188
- int ssl3_connect(SSL *ssl) {
174
+ static int ssl3_send_client_hello(SSL_HANDSHAKE *hs);
175
+ static int dtls1_get_hello_verify(SSL_HANDSHAKE *hs);
176
+ static int ssl3_get_server_hello(SSL_HANDSHAKE *hs);
177
+ static int ssl3_get_server_certificate(SSL_HANDSHAKE *hs);
178
+ static int ssl3_get_cert_status(SSL_HANDSHAKE *hs);
179
+ static int ssl3_verify_server_cert(SSL_HANDSHAKE *hs);
180
+ static int ssl3_get_server_key_exchange(SSL_HANDSHAKE *hs);
181
+ static int ssl3_get_certificate_request(SSL_HANDSHAKE *hs);
182
+ static int ssl3_get_server_hello_done(SSL_HANDSHAKE *hs);
183
+ static int ssl3_send_client_certificate(SSL_HANDSHAKE *hs);
184
+ static int ssl3_send_client_key_exchange(SSL_HANDSHAKE *hs);
185
+ static int ssl3_send_cert_verify(SSL_HANDSHAKE *hs);
186
+ static int ssl3_send_next_proto(SSL_HANDSHAKE *hs);
187
+ static int ssl3_send_channel_id(SSL_HANDSHAKE *hs);
188
+ static int ssl3_get_new_session_ticket(SSL_HANDSHAKE *hs);
189
+
190
+ int ssl3_connect(SSL_HANDSHAKE *hs) {
191
+ SSL *const ssl = hs->ssl;
189
192
  int ret = -1;
190
- int state, skip = 0;
191
193
 
192
194
  assert(ssl->handshake_func == ssl3_connect);
193
195
  assert(!ssl->server);
194
196
 
195
197
  for (;;) {
196
- state = ssl->state;
198
+ int state = hs->state;
197
199
 
198
- switch (ssl->state) {
200
+ switch (hs->state) {
199
201
  case SSL_ST_INIT:
200
- ssl->state = SSL_ST_CONNECT;
201
- skip = 1;
202
- break;
203
-
204
- case SSL_ST_CONNECT:
205
202
  ssl_do_info_callback(ssl, SSL_CB_HANDSHAKE_START, 1);
206
-
207
- ssl->s3->hs = ssl_handshake_new(tls13_client_handshake);
208
- if (ssl->s3->hs == NULL) {
209
- ret = -1;
210
- goto end;
211
- }
212
-
213
- if (!ssl_init_wbio_buffer(ssl)) {
214
- ret = -1;
215
- goto end;
216
- }
217
-
218
- ssl->state = SSL3_ST_CW_CLNT_HELLO_A;
203
+ hs->state = SSL3_ST_CW_CLNT_HELLO_A;
219
204
  break;
220
205
 
221
206
  case SSL3_ST_CW_CLNT_HELLO_A:
222
- case SSL3_ST_CW_CLNT_HELLO_B:
223
- ret = ssl3_send_client_hello(ssl);
207
+ ret = ssl3_send_client_hello(hs);
224
208
  if (ret <= 0) {
225
209
  goto end;
226
210
  }
227
211
 
228
212
  if (!SSL_is_dtls(ssl) || ssl->d1->send_cookie) {
229
- ssl->s3->tmp.next_state = SSL3_ST_CR_SRVR_HELLO_A;
213
+ hs->next_state = SSL3_ST_CR_SRVR_HELLO_A;
230
214
  } else {
231
- ssl->s3->tmp.next_state = DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A;
215
+ hs->next_state = DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A;
232
216
  }
233
- ssl->state = SSL3_ST_CW_FLUSH;
217
+ hs->state = SSL3_ST_CW_FLUSH;
234
218
  break;
235
219
 
236
220
  case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
237
221
  assert(SSL_is_dtls(ssl));
238
- ret = dtls1_get_hello_verify(ssl);
222
+ ret = dtls1_get_hello_verify(hs);
239
223
  if (ret <= 0) {
240
224
  goto end;
241
225
  }
242
226
  if (ssl->d1->send_cookie) {
243
227
  ssl->method->received_flight(ssl);
244
- ssl->state = SSL3_ST_CW_CLNT_HELLO_A;
228
+ hs->state = SSL3_ST_CW_CLNT_HELLO_A;
245
229
  } else {
246
- ssl->state = SSL3_ST_CR_SRVR_HELLO_A;
230
+ hs->state = SSL3_ST_CR_SRVR_HELLO_A;
247
231
  }
248
232
  break;
249
233
 
250
234
  case SSL3_ST_CR_SRVR_HELLO_A:
251
- ret = ssl3_get_server_hello(ssl);
252
- if (ssl->state == SSL_ST_TLS13) {
235
+ ret = ssl3_get_server_hello(hs);
236
+ if (hs->state == SSL_ST_TLS13) {
253
237
  break;
254
238
  }
255
239
  if (ret <= 0) {
@@ -257,172 +241,143 @@ int ssl3_connect(SSL *ssl) {
257
241
  }
258
242
 
259
243
  if (ssl->session != NULL) {
260
- ssl->state = SSL3_ST_CR_SESSION_TICKET_A;
244
+ hs->state = SSL3_ST_CR_SESSION_TICKET_A;
261
245
  } else {
262
- ssl->state = SSL3_ST_CR_CERT_A;
246
+ hs->state = SSL3_ST_CR_CERT_A;
263
247
  }
264
248
  break;
265
249
 
266
250
  case SSL3_ST_CR_CERT_A:
267
- if (ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
268
- ret = ssl3_get_server_certificate(ssl);
251
+ if (ssl_cipher_uses_certificate_auth(hs->new_cipher)) {
252
+ ret = ssl3_get_server_certificate(hs);
269
253
  if (ret <= 0) {
270
254
  goto end;
271
255
  }
272
- } else {
273
- skip = 1;
274
256
  }
275
- ssl->state = SSL3_ST_CR_CERT_STATUS_A;
257
+ hs->state = SSL3_ST_CR_CERT_STATUS_A;
276
258
  break;
277
259
 
278
260
  case SSL3_ST_CR_CERT_STATUS_A:
279
- if (ssl->s3->tmp.certificate_status_expected) {
280
- ret = ssl3_get_cert_status(ssl);
261
+ if (hs->certificate_status_expected) {
262
+ ret = ssl3_get_cert_status(hs);
281
263
  if (ret <= 0) {
282
264
  goto end;
283
265
  }
284
- } else {
285
- skip = 1;
286
266
  }
287
- ssl->state = SSL3_ST_VERIFY_SERVER_CERT;
267
+ hs->state = SSL3_ST_VERIFY_SERVER_CERT;
288
268
  break;
289
269
 
290
270
  case SSL3_ST_VERIFY_SERVER_CERT:
291
- if (ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
292
- ret = ssl3_verify_server_cert(ssl);
271
+ if (ssl_cipher_uses_certificate_auth(hs->new_cipher)) {
272
+ ret = ssl3_verify_server_cert(hs);
293
273
  if (ret <= 0) {
294
274
  goto end;
295
275
  }
296
- } else {
297
- skip = 1;
298
276
  }
299
- ssl->state = SSL3_ST_CR_KEY_EXCH_A;
277
+ hs->state = SSL3_ST_CR_KEY_EXCH_A;
300
278
  break;
301
279
 
302
280
  case SSL3_ST_CR_KEY_EXCH_A:
303
- ret = ssl3_get_server_key_exchange(ssl);
281
+ ret = ssl3_get_server_key_exchange(hs);
304
282
  if (ret <= 0) {
305
283
  goto end;
306
284
  }
307
- ssl->state = SSL3_ST_CR_CERT_REQ_A;
285
+ hs->state = SSL3_ST_CR_CERT_REQ_A;
308
286
  break;
309
287
 
310
288
  case SSL3_ST_CR_CERT_REQ_A:
311
- if (ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
312
- ret = ssl3_get_certificate_request(ssl);
289
+ if (ssl_cipher_uses_certificate_auth(hs->new_cipher)) {
290
+ ret = ssl3_get_certificate_request(hs);
313
291
  if (ret <= 0) {
314
292
  goto end;
315
293
  }
316
- } else {
317
- skip = 1;
318
294
  }
319
- ssl->state = SSL3_ST_CR_SRVR_DONE_A;
295
+ hs->state = SSL3_ST_CR_SRVR_DONE_A;
320
296
  break;
321
297
 
322
298
  case SSL3_ST_CR_SRVR_DONE_A:
323
- ret = ssl3_get_server_hello_done(ssl);
299
+ ret = ssl3_get_server_hello_done(hs);
324
300
  if (ret <= 0) {
325
301
  goto end;
326
302
  }
327
303
  ssl->method->received_flight(ssl);
328
- ssl->state = SSL3_ST_CW_CERT_A;
304
+ hs->state = SSL3_ST_CW_CERT_A;
329
305
  break;
330
306
 
331
307
  case SSL3_ST_CW_CERT_A:
332
- case SSL3_ST_CW_CERT_B:
333
- case SSL3_ST_CW_CERT_C:
334
- if (ssl->s3->tmp.cert_request) {
335
- ret = ssl3_send_client_certificate(ssl);
308
+ if (hs->cert_request) {
309
+ ret = ssl3_send_client_certificate(hs);
336
310
  if (ret <= 0) {
337
311
  goto end;
338
312
  }
339
- } else {
340
- skip = 1;
341
313
  }
342
- ssl->state = SSL3_ST_CW_KEY_EXCH_A;
314
+ hs->state = SSL3_ST_CW_KEY_EXCH_A;
343
315
  break;
344
316
 
345
317
  case SSL3_ST_CW_KEY_EXCH_A:
346
- case SSL3_ST_CW_KEY_EXCH_B:
347
- ret = ssl3_send_client_key_exchange(ssl);
318
+ ret = ssl3_send_client_key_exchange(hs);
348
319
  if (ret <= 0) {
349
320
  goto end;
350
321
  }
351
- ssl->state = SSL3_ST_CW_CERT_VRFY_A;
322
+ hs->state = SSL3_ST_CW_CERT_VRFY_A;
352
323
  break;
353
324
 
354
325
  case SSL3_ST_CW_CERT_VRFY_A:
355
326
  case SSL3_ST_CW_CERT_VRFY_B:
356
- case SSL3_ST_CW_CERT_VRFY_C:
357
- if (ssl->s3->tmp.cert_request) {
358
- ret = ssl3_send_cert_verify(ssl);
327
+ if (hs->cert_request && ssl_has_certificate(ssl)) {
328
+ ret = ssl3_send_cert_verify(hs);
359
329
  if (ret <= 0) {
360
330
  goto end;
361
331
  }
362
- } else {
363
- skip = 1;
364
332
  }
365
- ssl->state = SSL3_ST_CW_CHANGE;
333
+ hs->state = SSL3_ST_CW_CHANGE;
366
334
  break;
367
335
 
368
336
  case SSL3_ST_CW_CHANGE:
369
- ret = ssl->method->send_change_cipher_spec(ssl);
370
- if (ret <= 0) {
371
- goto end;
372
- }
373
-
374
- ssl->state = SSL3_ST_CW_NEXT_PROTO_A;
375
-
376
- if (!tls1_change_cipher_state(ssl, SSL3_CHANGE_CIPHER_CLIENT_WRITE)) {
337
+ if (!ssl->method->add_change_cipher_spec(ssl) ||
338
+ !tls1_change_cipher_state(hs, SSL3_CHANGE_CIPHER_CLIENT_WRITE)) {
377
339
  ret = -1;
378
340
  goto end;
379
341
  }
380
342
 
343
+ hs->state = SSL3_ST_CW_NEXT_PROTO_A;
381
344
  break;
382
345
 
383
346
  case SSL3_ST_CW_NEXT_PROTO_A:
384
- case SSL3_ST_CW_NEXT_PROTO_B:
385
- if (ssl->s3->next_proto_neg_seen) {
386
- ret = ssl3_send_next_proto(ssl);
347
+ if (hs->next_proto_neg_seen) {
348
+ ret = ssl3_send_next_proto(hs);
387
349
  if (ret <= 0) {
388
350
  goto end;
389
351
  }
390
- } else {
391
- skip = 1;
392
352
  }
393
- ssl->state = SSL3_ST_CW_CHANNEL_ID_A;
353
+ hs->state = SSL3_ST_CW_CHANNEL_ID_A;
394
354
  break;
395
355
 
396
356
  case SSL3_ST_CW_CHANNEL_ID_A:
397
- case SSL3_ST_CW_CHANNEL_ID_B:
398
357
  if (ssl->s3->tlsext_channel_id_valid) {
399
- ret = ssl3_send_channel_id(ssl);
358
+ ret = ssl3_send_channel_id(hs);
400
359
  if (ret <= 0) {
401
360
  goto end;
402
361
  }
403
- } else {
404
- skip = 1;
405
362
  }
406
- ssl->state = SSL3_ST_CW_FINISHED_A;
363
+ hs->state = SSL3_ST_CW_FINISHED_A;
407
364
  break;
408
365
 
409
366
  case SSL3_ST_CW_FINISHED_A:
410
- case SSL3_ST_CW_FINISHED_B:
411
- ret = ssl3_send_finished(ssl, SSL3_ST_CW_FINISHED_A,
412
- SSL3_ST_CW_FINISHED_B);
367
+ ret = ssl3_send_finished(hs);
413
368
  if (ret <= 0) {
414
369
  goto end;
415
370
  }
416
- ssl->state = SSL3_ST_CW_FLUSH;
371
+ hs->state = SSL3_ST_CW_FLUSH;
417
372
 
418
373
  if (ssl->session != NULL) {
419
- ssl->s3->tmp.next_state = SSL_ST_OK;
374
+ hs->next_state = SSL3_ST_FINISH_CLIENT_HANDSHAKE;
420
375
  } else {
421
376
  /* This is a non-resumption handshake. If it involves ChannelID, then
422
377
  * record the handshake hashes at this point in the session so that
423
378
  * any resumption of this session with ChannelID can sign those
424
379
  * hashes. */
425
- ret = tls1_record_handshake_hashes_for_channel_id(ssl);
380
+ ret = tls1_record_handshake_hashes_for_channel_id(hs);
426
381
  if (ret <= 0) {
427
382
  goto end;
428
383
  }
@@ -431,31 +386,27 @@ int ssl3_connect(SSL *ssl) {
431
386
  /* No False Start on renegotiation (would complicate the state
432
387
  * machine). */
433
388
  !ssl->s3->initial_handshake_complete) {
434
- ssl->s3->tmp.next_state = SSL3_ST_FALSE_START;
389
+ hs->next_state = SSL3_ST_FALSE_START;
435
390
  } else {
436
- ssl->s3->tmp.next_state = SSL3_ST_CR_SESSION_TICKET_A;
391
+ hs->next_state = SSL3_ST_CR_SESSION_TICKET_A;
437
392
  }
438
393
  }
439
394
  break;
440
395
 
441
396
  case SSL3_ST_FALSE_START:
442
- ssl->state = SSL3_ST_CR_SESSION_TICKET_A;
443
- ssl->s3->tmp.in_false_start = 1;
444
-
445
- ssl_free_wbio_buffer(ssl);
397
+ hs->state = SSL3_ST_CR_SESSION_TICKET_A;
398
+ hs->in_false_start = 1;
446
399
  ret = 1;
447
400
  goto end;
448
401
 
449
402
  case SSL3_ST_CR_SESSION_TICKET_A:
450
- if (ssl->tlsext_ticket_expected) {
451
- ret = ssl3_get_new_session_ticket(ssl);
403
+ if (hs->ticket_expected) {
404
+ ret = ssl3_get_new_session_ticket(hs);
452
405
  if (ret <= 0) {
453
406
  goto end;
454
407
  }
455
- } else {
456
- skip = 1;
457
408
  }
458
- ssl->state = SSL3_ST_CR_CHANGE;
409
+ hs->state = SSL3_ST_CR_CHANGE;
459
410
  break;
460
411
 
461
412
  case SSL3_ST_CR_CHANGE:
@@ -464,50 +415,47 @@ int ssl3_connect(SSL *ssl) {
464
415
  goto end;
465
416
  }
466
417
 
467
- if (!tls1_change_cipher_state(ssl, SSL3_CHANGE_CIPHER_CLIENT_READ)) {
418
+ if (!tls1_change_cipher_state(hs, SSL3_CHANGE_CIPHER_CLIENT_READ)) {
468
419
  ret = -1;
469
420
  goto end;
470
421
  }
471
- ssl->state = SSL3_ST_CR_FINISHED_A;
422
+ hs->state = SSL3_ST_CR_FINISHED_A;
472
423
  break;
473
424
 
474
425
  case SSL3_ST_CR_FINISHED_A:
475
- ret = ssl3_get_finished(ssl);
426
+ ret = ssl3_get_finished(hs);
476
427
  if (ret <= 0) {
477
428
  goto end;
478
429
  }
479
430
  ssl->method->received_flight(ssl);
480
431
 
481
432
  if (ssl->session != NULL) {
482
- ssl->state = SSL3_ST_CW_CHANGE;
433
+ hs->state = SSL3_ST_CW_CHANGE;
483
434
  } else {
484
- ssl->state = SSL_ST_OK;
435
+ hs->state = SSL3_ST_FINISH_CLIENT_HANDSHAKE;
485
436
  }
486
437
  break;
487
438
 
488
439
  case SSL3_ST_CW_FLUSH:
489
- if (BIO_flush(ssl->wbio) <= 0) {
490
- ssl->rwstate = SSL_WRITING;
491
- ret = -1;
440
+ ret = ssl->method->flush_flight(ssl);
441
+ if (ret <= 0) {
492
442
  goto end;
493
443
  }
494
- ssl->state = ssl->s3->tmp.next_state;
495
- if (ssl->state != SSL_ST_OK) {
444
+ hs->state = hs->next_state;
445
+ if (hs->state != SSL3_ST_FINISH_CLIENT_HANDSHAKE) {
496
446
  ssl->method->expect_flight(ssl);
497
447
  }
498
448
  break;
499
449
 
500
450
  case SSL_ST_TLS13:
501
- ret = tls13_handshake(ssl);
451
+ ret = tls13_handshake(hs);
502
452
  if (ret <= 0) {
503
453
  goto end;
504
454
  }
505
- ssl->state = SSL_ST_OK;
455
+ hs->state = SSL3_ST_FINISH_CLIENT_HANDSHAKE;
506
456
  break;
507
457
 
508
- case SSL_ST_OK:
509
- /* Clean a few things up. */
510
- ssl3_cleanup_key_block(ssl);
458
+ case SSL3_ST_FINISH_CLIENT_HANDSHAKE:
511
459
  ssl->method->release_current_message(ssl, 1 /* free_buffer */);
512
460
 
513
461
  SSL_SESSION_free(ssl->s3->established_session);
@@ -519,45 +467,32 @@ int ssl3_connect(SSL *ssl) {
519
467
  * of the new established_session due to False Start. The caller may
520
468
  * have taken a reference to the temporary session. */
521
469
  ssl->s3->established_session =
522
- SSL_SESSION_dup(ssl->s3->new_session, SSL_SESSION_DUP_ALL);
470
+ SSL_SESSION_dup(hs->new_session, SSL_SESSION_DUP_ALL);
523
471
  if (ssl->s3->established_session == NULL) {
524
- /* Do not stay in SSL_ST_OK, to avoid confusing |SSL_in_init|
525
- * callers. */
526
- ssl->state = SSL_ST_ERROR;
527
- skip = 1;
528
472
  ret = -1;
529
473
  goto end;
530
474
  }
531
475
  ssl->s3->established_session->not_resumable = 0;
532
476
 
533
- SSL_SESSION_free(ssl->s3->new_session);
534
- ssl->s3->new_session = NULL;
477
+ SSL_SESSION_free(hs->new_session);
478
+ hs->new_session = NULL;
535
479
  }
536
480
 
537
- /* Remove write buffering now. */
538
- ssl_free_wbio_buffer(ssl);
539
-
540
- ssl_handshake_free(ssl->s3->hs);
541
- ssl->s3->hs = NULL;
481
+ hs->state = SSL_ST_OK;
482
+ break;
542
483
 
484
+ case SSL_ST_OK: {
543
485
  const int is_initial_handshake = !ssl->s3->initial_handshake_complete;
544
-
545
- ssl->s3->tmp.in_false_start = 0;
546
486
  ssl->s3->initial_handshake_complete = 1;
547
-
548
487
  if (is_initial_handshake) {
549
488
  /* Renegotiations do not participate in session resumption. */
550
- ssl_update_cache(ssl, SSL_SESS_CACHE_CLIENT);
489
+ ssl_update_cache(hs, SSL_SESS_CACHE_CLIENT);
551
490
  }
552
491
 
553
492
  ret = 1;
554
493
  ssl_do_info_callback(ssl, SSL_CB_HANDSHAKE_DONE, 1);
555
494
  goto end;
556
-
557
- case SSL_ST_ERROR:
558
- OPENSSL_PUT_ERROR(SSL, SSL_R_SSL_HANDSHAKE_FAILURE);
559
- ret = -1;
560
- goto end;
495
+ }
561
496
 
562
497
  default:
563
498
  OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_STATE);
@@ -565,13 +500,9 @@ int ssl3_connect(SSL *ssl) {
565
500
  goto end;
566
501
  }
567
502
 
568
- if (!ssl->s3->tmp.reuse_message && !skip && ssl->state != state) {
569
- int new_state = ssl->state;
570
- ssl->state = state;
503
+ if (hs->state != state) {
571
504
  ssl_do_info_callback(ssl, SSL_CB_CONNECT_LOOP, 1);
572
- ssl->state = new_state;
573
505
  }
574
- skip = 0;
575
506
  }
576
507
 
577
508
  end:
@@ -591,11 +522,59 @@ uint16_t ssl_get_grease_value(const SSL *ssl, enum ssl_grease_index_t index) {
591
522
  return ret;
592
523
  }
593
524
 
525
+ /* ssl_get_client_disabled sets |*out_mask_a| and |*out_mask_k| to masks of
526
+ * disabled algorithms. */
527
+ static void ssl_get_client_disabled(SSL *ssl, uint32_t *out_mask_a,
528
+ uint32_t *out_mask_k) {
529
+ int have_rsa = 0, have_ecdsa = 0;
530
+ *out_mask_a = 0;
531
+ *out_mask_k = 0;
532
+
533
+ /* Now go through all signature algorithms seeing if we support any for RSA or
534
+ * ECDSA. Do this for all versions not just TLS 1.2. */
535
+ const uint16_t *sigalgs;
536
+ size_t num_sigalgs = tls12_get_verify_sigalgs(ssl, &sigalgs);
537
+ for (size_t i = 0; i < num_sigalgs; i++) {
538
+ switch (sigalgs[i]) {
539
+ case SSL_SIGN_RSA_PSS_SHA512:
540
+ case SSL_SIGN_RSA_PSS_SHA384:
541
+ case SSL_SIGN_RSA_PSS_SHA256:
542
+ case SSL_SIGN_RSA_PKCS1_SHA512:
543
+ case SSL_SIGN_RSA_PKCS1_SHA384:
544
+ case SSL_SIGN_RSA_PKCS1_SHA256:
545
+ case SSL_SIGN_RSA_PKCS1_SHA1:
546
+ have_rsa = 1;
547
+ break;
548
+
549
+ case SSL_SIGN_ECDSA_SECP521R1_SHA512:
550
+ case SSL_SIGN_ECDSA_SECP384R1_SHA384:
551
+ case SSL_SIGN_ECDSA_SECP256R1_SHA256:
552
+ case SSL_SIGN_ECDSA_SHA1:
553
+ have_ecdsa = 1;
554
+ break;
555
+ }
556
+ }
557
+
558
+ /* Disable auth if we don't include any appropriate signature algorithms. */
559
+ if (!have_rsa) {
560
+ *out_mask_a |= SSL_aRSA;
561
+ }
562
+ if (!have_ecdsa) {
563
+ *out_mask_a |= SSL_aECDSA;
564
+ }
565
+
566
+ /* PSK requires a client callback. */
567
+ if (ssl->psk_client_callback == NULL) {
568
+ *out_mask_a |= SSL_aPSK;
569
+ *out_mask_k |= SSL_kPSK;
570
+ }
571
+ }
572
+
594
573
  static int ssl_write_client_cipher_list(SSL *ssl, CBB *out,
595
574
  uint16_t min_version,
596
575
  uint16_t max_version) {
597
- /* Prepare disabled cipher masks. */
598
- ssl_set_client_disabled(ssl);
576
+ uint32_t mask_a, mask_k;
577
+ ssl_get_client_disabled(ssl, &mask_a, &mask_k);
599
578
 
600
579
  CBB child;
601
580
  if (!CBB_add_u16_length_prefixed(out, &child)) {
@@ -608,47 +587,53 @@ static int ssl_write_client_cipher_list(SSL *ssl, CBB *out,
608
587
  return 0;
609
588
  }
610
589
 
611
- STACK_OF(SSL_CIPHER) *ciphers = SSL_get_ciphers(ssl);
612
-
613
- int any_enabled = 0;
614
- for (size_t i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
615
- const SSL_CIPHER *cipher = sk_SSL_CIPHER_value(ciphers, i);
616
- /* Skip disabled ciphers */
617
- if ((cipher->algorithm_mkey & ssl->cert->mask_k) ||
618
- (cipher->algorithm_auth & ssl->cert->mask_a)) {
619
- continue;
590
+ /* Add TLS 1.3 ciphers. Order ChaCha20-Poly1305 relative to AES-GCM based on
591
+ * hardware support. */
592
+ if (max_version >= TLS1_3_VERSION) {
593
+ if (!EVP_has_aes_hardware() &&
594
+ !CBB_add_u16(&child, TLS1_CK_CHACHA20_POLY1305_SHA256 & 0xffff)) {
595
+ return 0;
620
596
  }
621
- if (SSL_CIPHER_get_min_version(cipher) > max_version ||
622
- SSL_CIPHER_get_max_version(cipher) < min_version) {
623
- continue;
597
+ if (!CBB_add_u16(&child, TLS1_CK_AES_128_GCM_SHA256 & 0xffff) ||
598
+ !CBB_add_u16(&child, TLS1_CK_AES_256_GCM_SHA384 & 0xffff)) {
599
+ return 0;
624
600
  }
625
- any_enabled = 1;
626
- if (!CBB_add_u16(&child, ssl_cipher_get_value(cipher))) {
601
+ if (EVP_has_aes_hardware() &&
602
+ !CBB_add_u16(&child, TLS1_CK_CHACHA20_POLY1305_SHA256 & 0xffff)) {
627
603
  return 0;
628
604
  }
629
- /* Add PSK ciphers for TLS 1.3 resumption. */
630
- uint16_t session_version;
631
- if (ssl->session != NULL &&
632
- ssl->method->version_from_wire(&session_version,
633
- ssl->session->ssl_version) &&
634
- session_version >= TLS1_3_VERSION) {
635
- uint16_t resumption_cipher;
636
- if (ssl_cipher_get_ecdhe_psk_cipher(cipher, &resumption_cipher) &&
637
- !CBB_add_u16(&child, resumption_cipher)) {
605
+ }
606
+
607
+ if (min_version < TLS1_3_VERSION) {
608
+ STACK_OF(SSL_CIPHER) *ciphers = SSL_get_ciphers(ssl);
609
+ int any_enabled = 0;
610
+ for (size_t i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
611
+ const SSL_CIPHER *cipher = sk_SSL_CIPHER_value(ciphers, i);
612
+ /* Skip disabled ciphers */
613
+ if ((cipher->algorithm_mkey & mask_k) ||
614
+ (cipher->algorithm_auth & mask_a)) {
615
+ continue;
616
+ }
617
+ if (SSL_CIPHER_get_min_version(cipher) > max_version ||
618
+ SSL_CIPHER_get_max_version(cipher) < min_version) {
619
+ continue;
620
+ }
621
+ any_enabled = 1;
622
+ if (!CBB_add_u16(&child, ssl_cipher_get_value(cipher))) {
638
623
  return 0;
639
624
  }
640
625
  }
641
- }
642
626
 
643
- /* If all ciphers were disabled, return the error to the caller. */
644
- if (!any_enabled) {
645
- OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHERS_AVAILABLE);
646
- return 0;
627
+ /* If all ciphers were disabled, return the error to the caller. */
628
+ if (!any_enabled && max_version < TLS1_3_VERSION) {
629
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHERS_AVAILABLE);
630
+ return 0;
631
+ }
647
632
  }
648
633
 
649
634
  /* For SSLv3, the SCSV is added. Otherwise the renegotiation extension is
650
635
  * added. */
651
- if (ssl->client_version == SSL3_VERSION &&
636
+ if (max_version == SSL3_VERSION &&
652
637
  !ssl->s3->initial_handshake_complete) {
653
638
  if (!CBB_add_u16(&child, SSL3_CK_SCSV & 0xffff)) {
654
639
  return 0;
@@ -664,84 +649,103 @@ static int ssl_write_client_cipher_list(SSL *ssl, CBB *out,
664
649
  return CBB_flush(out);
665
650
  }
666
651
 
667
- int ssl_add_client_hello_body(SSL *ssl, CBB *body) {
652
+ int ssl_write_client_hello(SSL_HANDSHAKE *hs) {
653
+ SSL *const ssl = hs->ssl;
668
654
  uint16_t min_version, max_version;
669
655
  if (!ssl_get_version_range(ssl, &min_version, &max_version)) {
670
656
  return 0;
671
657
  }
672
658
 
659
+ CBB cbb, body;
660
+ if (!ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_CLIENT_HELLO)) {
661
+ goto err;
662
+ }
663
+
673
664
  /* Renegotiations do not participate in session resumption. */
674
665
  int has_session = ssl->session != NULL &&
675
666
  !ssl->s3->initial_handshake_complete;
676
667
 
677
668
  CBB child;
678
- if (!CBB_add_u16(body, ssl->client_version) ||
679
- !CBB_add_bytes(body, ssl->s3->client_random, SSL3_RANDOM_SIZE) ||
680
- !CBB_add_u8_length_prefixed(body, &child) ||
669
+ if (!CBB_add_u16(&body, hs->client_version) ||
670
+ !CBB_add_bytes(&body, ssl->s3->client_random, SSL3_RANDOM_SIZE) ||
671
+ !CBB_add_u8_length_prefixed(&body, &child) ||
681
672
  (has_session &&
682
673
  !CBB_add_bytes(&child, ssl->session->session_id,
683
674
  ssl->session->session_id_length))) {
684
- return 0;
675
+ goto err;
685
676
  }
686
677
 
687
678
  if (SSL_is_dtls(ssl)) {
688
- if (!CBB_add_u8_length_prefixed(body, &child) ||
679
+ if (!CBB_add_u8_length_prefixed(&body, &child) ||
689
680
  !CBB_add_bytes(&child, ssl->d1->cookie, ssl->d1->cookie_len)) {
690
- return 0;
681
+ goto err;
691
682
  }
692
683
  }
693
684
 
694
685
  size_t header_len =
695
686
  SSL_is_dtls(ssl) ? DTLS1_HM_HEADER_LENGTH : SSL3_HM_HEADER_LENGTH;
696
- if (!ssl_write_client_cipher_list(ssl, body, min_version, max_version) ||
697
- !CBB_add_u8(body, 1 /* one compression method */) ||
698
- !CBB_add_u8(body, 0 /* null compression */) ||
699
- !ssl_add_clienthello_tlsext(ssl, body, header_len + CBB_len(body))) {
700
- return 0;
687
+ if (!ssl_write_client_cipher_list(ssl, &body, min_version, max_version) ||
688
+ !CBB_add_u8(&body, 1 /* one compression method */) ||
689
+ !CBB_add_u8(&body, 0 /* null compression */) ||
690
+ !ssl_add_clienthello_tlsext(hs, &body, header_len + CBB_len(&body))) {
691
+ goto err;
701
692
  }
702
693
 
703
- return 1;
704
- }
694
+ uint8_t *msg = NULL;
695
+ size_t len;
696
+ if (!ssl->method->finish_message(ssl, &cbb, &msg, &len)) {
697
+ goto err;
698
+ }
705
699
 
706
- static int ssl3_send_client_hello(SSL *ssl) {
707
- if (ssl->state == SSL3_ST_CW_CLNT_HELLO_B) {
708
- return ssl->method->write_message(ssl);
700
+ /* Now that the length prefixes have been computed, fill in the placeholder
701
+ * PSK binder. */
702
+ if (hs->needs_psk_binder &&
703
+ !tls13_write_psk_binder(hs, msg, len)) {
704
+ OPENSSL_free(msg);
705
+ goto err;
709
706
  }
710
707
 
708
+ return ssl->method->add_message(ssl, msg, len);
709
+
710
+ err:
711
+ CBB_cleanup(&cbb);
712
+ return 0;
713
+ }
714
+
715
+ static int ssl3_send_client_hello(SSL_HANDSHAKE *hs) {
716
+ SSL *const ssl = hs->ssl;
711
717
  /* The handshake buffer is reset on every ClientHello. Notably, in DTLS, we
712
718
  * may send multiple ClientHellos if we receive HelloVerifyRequest. */
713
- if (!ssl3_init_handshake_buffer(ssl)) {
719
+ if (!SSL_TRANSCRIPT_init(&hs->transcript)) {
714
720
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
715
721
  return -1;
716
722
  }
717
723
 
718
- CBB cbb;
719
- CBB_zero(&cbb);
720
-
721
724
  uint16_t min_version, max_version;
722
725
  if (!ssl_get_version_range(ssl, &min_version, &max_version)) {
723
- goto err;
726
+ return -1;
724
727
  }
725
728
 
726
- assert(ssl->state == SSL3_ST_CW_CLNT_HELLO_A);
729
+ uint16_t max_wire_version = ssl->method->version_to_wire(max_version);
730
+ assert(hs->state == SSL3_ST_CW_CLNT_HELLO_A);
727
731
  if (!ssl->s3->have_version) {
728
- ssl->version = ssl->method->version_to_wire(max_version);
729
- /* Only set |ssl->client_version| on the initial handshake. Renegotiations,
730
- * although locked to a version, reuse the value. When using the plain RSA
731
- * key exchange, the ClientHello version is checked in the premaster secret.
732
- * Some servers fail when this value changes. */
733
- ssl->client_version = ssl->version;
734
-
735
- if (max_version >= TLS1_3_VERSION) {
736
- ssl->client_version = ssl->method->version_to_wire(TLS1_2_VERSION);
737
- }
732
+ ssl->version = max_wire_version;
733
+ }
734
+
735
+ /* Always advertise the ClientHello version from the original maximum version,
736
+ * even on renegotiation. The static RSA key exchange uses this field, and
737
+ * some servers fail when it changes across handshakes. */
738
+ hs->client_version = max_wire_version;
739
+ if (max_version >= TLS1_3_VERSION) {
740
+ hs->client_version = ssl->method->version_to_wire(TLS1_2_VERSION);
738
741
  }
739
742
 
740
743
  /* If the configured session has expired or was created at a disabled
741
744
  * version, drop it. */
742
745
  if (ssl->session != NULL) {
743
746
  uint16_t session_version;
744
- if (!ssl->method->version_from_wire(&session_version,
747
+ if (ssl->session->is_server ||
748
+ !ssl->method->version_from_wire(&session_version,
745
749
  ssl->session->ssl_version) ||
746
750
  (session_version < TLS1_3_VERSION &&
747
751
  ssl->session->session_id_length == 0) ||
@@ -756,30 +760,23 @@ static int ssl3_send_client_hello(SSL *ssl) {
756
760
  * renegerate the client_random. The random must be reused. */
757
761
  if ((!SSL_is_dtls(ssl) || !ssl->d1->send_cookie) &&
758
762
  !RAND_bytes(ssl->s3->client_random, sizeof(ssl->s3->client_random))) {
759
- goto err;
763
+ return -1;
760
764
  }
761
765
 
762
- CBB body;
763
- if (!ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_CLIENT_HELLO) ||
764
- !ssl_add_client_hello_body(ssl, &body) ||
765
- !ssl->method->finish_message(ssl, &cbb)) {
766
- goto err;
766
+ if (!ssl_write_client_hello(hs)) {
767
+ return -1;
767
768
  }
768
769
 
769
- ssl->state = SSL3_ST_CW_CLNT_HELLO_B;
770
- return ssl->method->write_message(ssl);
771
-
772
- err:
773
- CBB_cleanup(&cbb);
774
- return -1;
770
+ return 1;
775
771
  }
776
772
 
777
- static int dtls1_get_hello_verify(SSL *ssl) {
773
+ static int dtls1_get_hello_verify(SSL_HANDSHAKE *hs) {
774
+ SSL *const ssl = hs->ssl;
778
775
  int al;
779
776
  CBS hello_verify_request, cookie;
780
777
  uint16_t server_version;
781
778
 
782
- int ret = ssl->method->ssl_get_message(ssl, -1, ssl_hash_message);
779
+ int ret = ssl->method->ssl_get_message(ssl);
783
780
  if (ret <= 0) {
784
781
  return ret;
785
782
  }
@@ -791,7 +788,6 @@ static int dtls1_get_hello_verify(SSL *ssl) {
791
788
  }
792
789
 
793
790
  CBS_init(&hello_verify_request, ssl->init_msg, ssl->init_num);
794
-
795
791
  if (!CBS_get_u16(&hello_verify_request, &server_version) ||
796
792
  !CBS_get_u8_length_prefixed(&hello_verify_request, &cookie) ||
797
793
  CBS_len(&hello_verify_request) != 0) {
@@ -805,7 +801,7 @@ static int dtls1_get_hello_verify(SSL *ssl) {
805
801
  goto f_err;
806
802
  }
807
803
 
808
- memcpy(ssl->d1->cookie, CBS_data(&cookie), CBS_len(&cookie));
804
+ OPENSSL_memcpy(ssl->d1->cookie, CBS_data(&cookie), CBS_len(&cookie));
809
805
  ssl->d1->cookie_len = CBS_len(&cookie);
810
806
 
811
807
  ssl->d1->send_cookie = 1;
@@ -816,16 +812,14 @@ f_err:
816
812
  return -1;
817
813
  }
818
814
 
819
- static int ssl3_get_server_hello(SSL *ssl) {
820
- STACK_OF(SSL_CIPHER) *sk;
821
- const SSL_CIPHER *c;
822
- CERT *ct = ssl->cert;
815
+ static int ssl3_get_server_hello(SSL_HANDSHAKE *hs) {
816
+ SSL *const ssl = hs->ssl;
823
817
  int al = SSL_AD_INTERNAL_ERROR;
824
818
  CBS server_hello, server_random, session_id;
825
819
  uint16_t server_wire_version, cipher_suite;
826
820
  uint8_t compression_method;
827
821
 
828
- int ret = ssl->method->ssl_get_message(ssl, -1, ssl_hash_message);
822
+ int ret = ssl->method->ssl_get_message(ssl);
829
823
  if (ret <= 0) {
830
824
  uint32_t err = ERR_peek_error();
831
825
  if (ERR_GET_LIB(err) == ERR_LIB_SSL &&
@@ -868,8 +862,6 @@ static int ssl3_get_server_hello(SSL *ssl) {
868
862
  assert(ssl->s3->have_version == ssl->s3->initial_handshake_complete);
869
863
  if (!ssl->s3->have_version) {
870
864
  ssl->version = server_wire_version;
871
- ssl->s3->enc_method = ssl3_get_enc_method(server_version);
872
- assert(ssl->s3->enc_method != NULL);
873
865
  /* At this point, the connection's version is known and ssl->version is
874
866
  * fixed. Begin enforcing the record-layer version. */
875
867
  ssl->s3->have_version = 1;
@@ -880,15 +872,14 @@ static int ssl3_get_server_hello(SSL *ssl) {
880
872
  }
881
873
 
882
874
  if (ssl3_protocol_version(ssl) >= TLS1_3_VERSION) {
883
- ssl->state = SSL_ST_TLS13;
875
+ hs->state = SSL_ST_TLS13;
876
+ hs->do_tls13_handshake = tls13_client_handshake;
884
877
  return 1;
885
878
  }
886
879
 
887
- ssl_clear_tls13_state(ssl);
880
+ ssl_clear_tls13_state(hs);
888
881
 
889
- if (ssl->s3->tmp.message_type != SSL3_MT_SERVER_HELLO) {
890
- ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
891
- OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
882
+ if (!ssl_check_message_type(ssl, SSL3_MT_SERVER_HELLO)) {
892
883
  return -1;
893
884
  }
894
885
 
@@ -903,7 +894,7 @@ static int ssl3_get_server_hello(SSL *ssl) {
903
894
  }
904
895
 
905
896
  /* Copy over the server random. */
906
- memcpy(ssl->s3->server_random, CBS_data(&server_random), SSL3_RANDOM_SIZE);
897
+ OPENSSL_memcpy(ssl->s3->server_random, CBS_data(&server_random), SSL3_RANDOM_SIZE);
907
898
 
908
899
  /* TODO(davidben): Implement the TLS 1.1 and 1.2 downgrade sentinels once TLS
909
900
  * 1.3 is finalized and we are not implementing a draft version. */
@@ -917,49 +908,44 @@ static int ssl3_get_server_hello(SSL *ssl) {
917
908
  /* The session wasn't resumed. Create a fresh SSL_SESSION to
918
909
  * fill out. */
919
910
  ssl_set_session(ssl, NULL);
920
- if (!ssl_get_new_session(ssl, 0 /* client */)) {
911
+ if (!ssl_get_new_session(hs, 0 /* client */)) {
921
912
  goto f_err;
922
913
  }
923
914
  /* Note: session_id could be empty. */
924
- ssl->s3->new_session->session_id_length = CBS_len(&session_id);
925
- memcpy(ssl->s3->new_session->session_id, CBS_data(&session_id),
926
- CBS_len(&session_id));
915
+ hs->new_session->session_id_length = CBS_len(&session_id);
916
+ OPENSSL_memcpy(hs->new_session->session_id, CBS_data(&session_id),
917
+ CBS_len(&session_id));
927
918
  }
928
919
 
929
- c = SSL_get_cipher_by_value(cipher_suite);
920
+ const SSL_CIPHER *c = SSL_get_cipher_by_value(cipher_suite);
930
921
  if (c == NULL) {
931
922
  /* unknown cipher */
932
923
  al = SSL_AD_ILLEGAL_PARAMETER;
933
924
  OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_CIPHER_RETURNED);
934
925
  goto f_err;
935
926
  }
936
- /* If the cipher is disabled then we didn't sent it in the ClientHello, so if
937
- * the server selected it, it's an error. */
938
- if ((c->algorithm_mkey & ct->mask_k) || (c->algorithm_auth & ct->mask_a) ||
939
- SSL_CIPHER_get_min_version(c) > ssl3_protocol_version(ssl) ||
940
- SSL_CIPHER_get_max_version(c) < ssl3_protocol_version(ssl)) {
941
- al = SSL_AD_ILLEGAL_PARAMETER;
942
- OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
943
- goto f_err;
944
- }
945
927
 
946
- sk = ssl_get_ciphers_by_id(ssl);
947
- if (!sk_SSL_CIPHER_find(sk, NULL, c)) {
948
- /* we did not say we would use this cipher */
928
+ /* The cipher must be allowed in the selected version and enabled. */
929
+ uint32_t mask_a, mask_k;
930
+ ssl_get_client_disabled(ssl, &mask_a, &mask_k);
931
+ if ((c->algorithm_mkey & mask_k) || (c->algorithm_auth & mask_a) ||
932
+ SSL_CIPHER_get_min_version(c) > ssl3_protocol_version(ssl) ||
933
+ SSL_CIPHER_get_max_version(c) < ssl3_protocol_version(ssl) ||
934
+ !sk_SSL_CIPHER_find(SSL_get_ciphers(ssl), NULL, c)) {
949
935
  al = SSL_AD_ILLEGAL_PARAMETER;
950
936
  OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
951
937
  goto f_err;
952
938
  }
953
939
 
954
940
  if (ssl->session != NULL) {
955
- if (ssl->session->cipher != c) {
941
+ if (ssl->session->ssl_version != ssl->version) {
956
942
  al = SSL_AD_ILLEGAL_PARAMETER;
957
- OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED);
943
+ OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_VERSION_NOT_RETURNED);
958
944
  goto f_err;
959
945
  }
960
- if (ssl->session->ssl_version != ssl->version) {
946
+ if (ssl->session->cipher != c) {
961
947
  al = SSL_AD_ILLEGAL_PARAMETER;
962
- OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_VERSION_NOT_RETURNED);
948
+ OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED);
963
949
  goto f_err;
964
950
  }
965
951
  if (!ssl_session_is_context_valid(ssl, ssl->session)) {
@@ -970,12 +956,15 @@ static int ssl3_get_server_hello(SSL *ssl) {
970
956
  goto f_err;
971
957
  }
972
958
  } else {
973
- ssl->s3->new_session->cipher = c;
959
+ hs->new_session->cipher = c;
974
960
  }
975
- ssl->s3->tmp.new_cipher = c;
961
+ hs->new_cipher = c;
976
962
 
977
- /* Now that the cipher is known, initialize the handshake hash. */
978
- if (!ssl3_init_handshake_hash(ssl)) {
963
+ /* Now that the cipher is known, initialize the handshake hash and hash the
964
+ * ServerHello. */
965
+ if (!SSL_TRANSCRIPT_init_hash(&hs->transcript, ssl3_protocol_version(ssl),
966
+ c->algorithm_prf) ||
967
+ !ssl_hash_current_message(hs)) {
979
968
  goto f_err;
980
969
  }
981
970
 
@@ -983,8 +972,8 @@ static int ssl3_get_server_hello(SSL *ssl) {
983
972
  * which requires hashing the handshake transcript. Otherwise, the handshake
984
973
  * buffer may be released. */
985
974
  if (ssl->session != NULL ||
986
- !ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
987
- ssl3_free_handshake_buffer(ssl);
975
+ !ssl_cipher_uses_certificate_auth(hs->new_cipher)) {
976
+ SSL_TRANSCRIPT_free_buffer(&hs->transcript);
988
977
  }
989
978
 
990
979
  /* Only the NULL compression algorithm is supported. */
@@ -995,7 +984,7 @@ static int ssl3_get_server_hello(SSL *ssl) {
995
984
  }
996
985
 
997
986
  /* TLS extensions */
998
- if (!ssl_parse_serverhello_tlsext(ssl, &server_hello)) {
987
+ if (!ssl_parse_serverhello_tlsext(hs, &server_hello)) {
999
988
  OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT);
1000
989
  goto err;
1001
990
  }
@@ -1009,8 +998,7 @@ static int ssl3_get_server_hello(SSL *ssl) {
1009
998
  }
1010
999
 
1011
1000
  if (ssl->session != NULL &&
1012
- ssl->s3->tmp.extended_master_secret !=
1013
- ssl->session->extended_master_secret) {
1001
+ hs->extended_master_secret != ssl->session->extended_master_secret) {
1014
1002
  al = SSL_AD_HANDSHAKE_FAILURE;
1015
1003
  if (ssl->session->extended_master_secret) {
1016
1004
  OPENSSL_PUT_ERROR(SSL, SSL_R_RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION);
@@ -1028,56 +1016,57 @@ err:
1028
1016
  return -1;
1029
1017
  }
1030
1018
 
1031
- static int ssl3_get_server_certificate(SSL *ssl) {
1032
- int ret =
1033
- ssl->method->ssl_get_message(ssl, SSL3_MT_CERTIFICATE, ssl_hash_message);
1019
+ static int ssl3_get_server_certificate(SSL_HANDSHAKE *hs) {
1020
+ SSL *const ssl = hs->ssl;
1021
+ int ret = ssl->method->ssl_get_message(ssl);
1034
1022
  if (ret <= 0) {
1035
1023
  return ret;
1036
1024
  }
1037
1025
 
1026
+ if (!ssl_check_message_type(ssl, SSL3_MT_CERTIFICATE) ||
1027
+ !ssl_hash_current_message(hs)) {
1028
+ return -1;
1029
+ }
1030
+
1038
1031
  CBS cbs;
1039
1032
  CBS_init(&cbs, ssl->init_msg, ssl->init_num);
1040
- uint8_t alert;
1041
- STACK_OF(X509) *chain = ssl_parse_cert_chain(ssl, &alert, NULL, &cbs);
1042
- if (chain == NULL) {
1033
+
1034
+ uint8_t alert = SSL_AD_DECODE_ERROR;
1035
+ sk_CRYPTO_BUFFER_pop_free(hs->new_session->certs, CRYPTO_BUFFER_free);
1036
+ EVP_PKEY_free(hs->peer_pubkey);
1037
+ hs->peer_pubkey = NULL;
1038
+ hs->new_session->certs = ssl_parse_cert_chain(&alert, &hs->peer_pubkey, NULL,
1039
+ &cbs, ssl->ctx->pool);
1040
+ if (hs->new_session->certs == NULL) {
1043
1041
  ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
1044
- goto err;
1042
+ return -1;
1045
1043
  }
1046
1044
 
1047
- if (sk_X509_num(chain) == 0 || CBS_len(&cbs) != 0) {
1045
+ if (sk_CRYPTO_BUFFER_num(hs->new_session->certs) == 0 ||
1046
+ CBS_len(&cbs) != 0 ||
1047
+ !ssl->ctx->x509_method->session_cache_objects(hs->new_session)) {
1048
1048
  OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1049
1049
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1050
- goto err;
1050
+ return -1;
1051
1051
  }
1052
1052
 
1053
- X509 *leaf = sk_X509_value(chain, 0);
1054
- if (!ssl_check_leaf_certificate(ssl, leaf)) {
1053
+ if (!ssl_check_leaf_certificate(
1054
+ hs, hs->peer_pubkey,
1055
+ sk_CRYPTO_BUFFER_value(hs->new_session->certs, 0))) {
1055
1056
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
1056
- goto err;
1057
+ return -1;
1057
1058
  }
1058
1059
 
1059
- /* NOTE: Unlike the server half, the client's copy of |cert_chain| includes
1060
- * the leaf. */
1061
- sk_X509_pop_free(ssl->s3->new_session->cert_chain, X509_free);
1062
- ssl->s3->new_session->cert_chain = chain;
1063
-
1064
- X509_free(ssl->s3->new_session->peer);
1065
- X509_up_ref(leaf);
1066
- ssl->s3->new_session->peer = leaf;
1067
-
1068
1060
  return 1;
1069
-
1070
- err:
1071
- sk_X509_pop_free(chain, X509_free);
1072
- return -1;
1073
1061
  }
1074
1062
 
1075
- static int ssl3_get_cert_status(SSL *ssl) {
1063
+ static int ssl3_get_cert_status(SSL_HANDSHAKE *hs) {
1064
+ SSL *const ssl = hs->ssl;
1076
1065
  int al;
1077
1066
  CBS certificate_status, ocsp_response;
1078
1067
  uint8_t status_type;
1079
1068
 
1080
- int ret = ssl->method->ssl_get_message(ssl, -1, ssl_hash_message);
1069
+ int ret = ssl->method->ssl_get_message(ssl);
1081
1070
  if (ret <= 0) {
1082
1071
  return ret;
1083
1072
  }
@@ -1089,6 +1078,10 @@ static int ssl3_get_cert_status(SSL *ssl) {
1089
1078
  return 1;
1090
1079
  }
1091
1080
 
1081
+ if (!ssl_hash_current_message(hs)) {
1082
+ return -1;
1083
+ }
1084
+
1092
1085
  CBS_init(&certificate_status, ssl->init_msg, ssl->init_num);
1093
1086
  if (!CBS_get_u8(&certificate_status, &status_type) ||
1094
1087
  status_type != TLSEXT_STATUSTYPE_ocsp ||
@@ -1100,8 +1093,8 @@ static int ssl3_get_cert_status(SSL *ssl) {
1100
1093
  goto f_err;
1101
1094
  }
1102
1095
 
1103
- if (!CBS_stow(&ocsp_response, &ssl->s3->new_session->ocsp_response,
1104
- &ssl->s3->new_session->ocsp_response_length)) {
1096
+ if (!CBS_stow(&ocsp_response, &hs->new_session->ocsp_response,
1097
+ &hs->new_session->ocsp_response_length)) {
1105
1098
  al = SSL_AD_INTERNAL_ERROR;
1106
1099
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1107
1100
  goto f_err;
@@ -1113,30 +1106,31 @@ f_err:
1113
1106
  return -1;
1114
1107
  }
1115
1108
 
1116
- static int ssl3_verify_server_cert(SSL *ssl) {
1117
- if (!ssl_verify_cert_chain(ssl, &ssl->s3->new_session->verify_result,
1118
- ssl->s3->new_session->cert_chain)) {
1109
+ static int ssl3_verify_server_cert(SSL_HANDSHAKE *hs) {
1110
+ SSL *const ssl = hs->ssl;
1111
+ if (!ssl_verify_cert_chain(ssl, &hs->new_session->verify_result,
1112
+ hs->new_session->x509_chain)) {
1119
1113
  return -1;
1120
1114
  }
1121
1115
 
1122
1116
  return 1;
1123
1117
  }
1124
1118
 
1125
- static int ssl3_get_server_key_exchange(SSL *ssl) {
1119
+ static int ssl3_get_server_key_exchange(SSL_HANDSHAKE *hs) {
1120
+ SSL *const ssl = hs->ssl;
1126
1121
  int al;
1127
- EVP_PKEY *pkey = NULL;
1128
1122
  DH *dh = NULL;
1129
1123
  EC_KEY *ecdh = NULL;
1130
1124
  EC_POINT *srvr_ecpoint = NULL;
1131
1125
 
1132
- int ret = ssl->method->ssl_get_message(ssl, -1, ssl_hash_message);
1126
+ int ret = ssl->method->ssl_get_message(ssl);
1133
1127
  if (ret <= 0) {
1134
1128
  return ret;
1135
1129
  }
1136
1130
 
1137
1131
  if (ssl->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE) {
1138
1132
  /* Some ciphers (pure PSK) have an optional ServerKeyExchange message. */
1139
- if (ssl_cipher_requires_server_key_exchange(ssl->s3->tmp.new_cipher)) {
1133
+ if (ssl_cipher_requires_server_key_exchange(hs->new_cipher)) {
1140
1134
  OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
1141
1135
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
1142
1136
  return -1;
@@ -1146,13 +1140,17 @@ static int ssl3_get_server_key_exchange(SSL *ssl) {
1146
1140
  return 1;
1147
1141
  }
1148
1142
 
1143
+ if (!ssl_hash_current_message(hs)) {
1144
+ return -1;
1145
+ }
1146
+
1149
1147
  /* Retain a copy of the original CBS to compute the signature over. */
1150
1148
  CBS server_key_exchange;
1151
1149
  CBS_init(&server_key_exchange, ssl->init_msg, ssl->init_num);
1152
1150
  CBS server_key_exchange_orig = server_key_exchange;
1153
1151
 
1154
- uint32_t alg_k = ssl->s3->tmp.new_cipher->algorithm_mkey;
1155
- uint32_t alg_a = ssl->s3->tmp.new_cipher->algorithm_auth;
1152
+ uint32_t alg_k = hs->new_cipher->algorithm_mkey;
1153
+ uint32_t alg_a = hs->new_cipher->algorithm_auth;
1156
1154
 
1157
1155
  if (alg_a & SSL_aPSK) {
1158
1156
  CBS psk_identity_hint;
@@ -1185,7 +1183,7 @@ static int ssl3_get_server_key_exchange(SSL *ssl) {
1185
1183
  * empty hint. Having different capabilities is odd, so we interpret empty
1186
1184
  * and missing as identical. */
1187
1185
  if (CBS_len(&psk_identity_hint) != 0 &&
1188
- !CBS_strdup(&psk_identity_hint, &ssl->s3->hs->peer_psk_identity_hint)) {
1186
+ !CBS_strdup(&psk_identity_hint, &hs->peer_psk_identity_hint)) {
1189
1187
  al = SSL_AD_INTERNAL_ERROR;
1190
1188
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1191
1189
  goto f_err;
@@ -1216,11 +1214,11 @@ static int ssl3_get_server_key_exchange(SSL *ssl) {
1216
1214
  goto err;
1217
1215
  }
1218
1216
 
1219
- ssl->s3->new_session->key_exchange_info = DH_num_bits(dh);
1220
- if (ssl->s3->new_session->key_exchange_info < 1024) {
1217
+ unsigned bits = DH_num_bits(dh);
1218
+ if (bits < 1024) {
1221
1219
  OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_DH_P_LENGTH);
1222
1220
  goto err;
1223
- } else if (ssl->s3->new_session->key_exchange_info > 4096) {
1221
+ } else if (bits > 4096) {
1224
1222
  /* Overly large DHE groups are prohibitively expensive, so enforce a limit
1225
1223
  * to prevent a server from causing us to perform too expensive of a
1226
1224
  * computation. */
@@ -1228,18 +1226,13 @@ static int ssl3_get_server_key_exchange(SSL *ssl) {
1228
1226
  goto err;
1229
1227
  }
1230
1228
 
1231
- SSL_ECDH_CTX_init_for_dhe(&ssl->s3->tmp.ecdh_ctx, dh);
1229
+ SSL_ECDH_CTX_init_for_dhe(&hs->ecdh_ctx, dh);
1232
1230
  dh = NULL;
1233
1231
 
1234
1232
  /* Save the peer public key for later. */
1235
- size_t peer_key_len;
1236
- if (!CBS_stow(&dh_Ys, &ssl->s3->tmp.peer_key, &peer_key_len)) {
1233
+ if (!CBS_stow(&dh_Ys, &hs->peer_key, &hs->peer_key_len)) {
1237
1234
  goto err;
1238
1235
  }
1239
- /* |dh_Ys| was initialized with CBS_get_u16_length_prefixed, so peer_key_len
1240
- * fits in a uint16_t. */
1241
- assert(sizeof(ssl->s3->tmp.peer_key_len) == 2 && peer_key_len <= 0xffff);
1242
- ssl->s3->tmp.peer_key_len = (uint16_t)peer_key_len;
1243
1236
  } else if (alg_k & SSL_kECDHE) {
1244
1237
  /* Parse the server parameters. */
1245
1238
  uint8_t group_type;
@@ -1253,7 +1246,7 @@ static int ssl3_get_server_key_exchange(SSL *ssl) {
1253
1246
  OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1254
1247
  goto f_err;
1255
1248
  }
1256
- ssl->s3->new_session->key_exchange_info = group_id;
1249
+ hs->new_session->group_id = group_id;
1257
1250
 
1258
1251
  /* Ensure the group is consistent with preferences. */
1259
1252
  if (!tls1_check_group_id(ssl, group_id)) {
@@ -1263,32 +1256,10 @@ static int ssl3_get_server_key_exchange(SSL *ssl) {
1263
1256
  }
1264
1257
 
1265
1258
  /* Initialize ECDH and save the peer public key for later. */
1266
- size_t peer_key_len;
1267
- if (!SSL_ECDH_CTX_init(&ssl->s3->tmp.ecdh_ctx, group_id) ||
1268
- !CBS_stow(&point, &ssl->s3->tmp.peer_key, &peer_key_len)) {
1259
+ if (!SSL_ECDH_CTX_init(&hs->ecdh_ctx, group_id) ||
1260
+ !CBS_stow(&point, &hs->peer_key, &hs->peer_key_len)) {
1269
1261
  goto err;
1270
1262
  }
1271
- /* |point| was initialized with CBS_get_u8_length_prefixed, so peer_key_len
1272
- * fits in a uint16_t. */
1273
- assert(sizeof(ssl->s3->tmp.peer_key_len) == 2 && peer_key_len <= 0xffff);
1274
- ssl->s3->tmp.peer_key_len = (uint16_t)peer_key_len;
1275
- } else if (alg_k & SSL_kCECPQ1) {
1276
- SSL_ECDH_CTX_init_for_cecpq1(&ssl->s3->tmp.ecdh_ctx);
1277
- CBS key;
1278
- if (!CBS_get_u16_length_prefixed(&server_key_exchange, &key)) {
1279
- al = SSL_AD_DECODE_ERROR;
1280
- OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1281
- goto f_err;
1282
- }
1283
-
1284
- size_t peer_key_len;
1285
- if (!CBS_stow(&key, &ssl->s3->tmp.peer_key, &peer_key_len)) {
1286
- goto err;
1287
- }
1288
- /* |key| was initialized with CBS_get_u16_length_prefixed, so peer_key_len
1289
- * fits in a uint16_t. */
1290
- assert(sizeof(ssl->s3->tmp.peer_key_len) == 2 && peer_key_len <= 0xffff);
1291
- ssl->s3->tmp.peer_key_len = (uint16_t)peer_key_len;
1292
1263
  } else if (!(alg_k & SSL_kPSK)) {
1293
1264
  al = SSL_AD_UNEXPECTED_MESSAGE;
1294
1265
  OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
@@ -1303,12 +1274,7 @@ static int ssl3_get_server_key_exchange(SSL *ssl) {
1303
1274
  CBS_len(&server_key_exchange_orig) - CBS_len(&server_key_exchange));
1304
1275
 
1305
1276
  /* ServerKeyExchange should be signed by the server's public key. */
1306
- if (ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
1307
- pkey = X509_get_pubkey(ssl->s3->new_session->peer);
1308
- if (pkey == NULL) {
1309
- goto err;
1310
- }
1311
-
1277
+ if (ssl_cipher_uses_certificate_auth(hs->new_cipher)) {
1312
1278
  uint16_t signature_algorithm = 0;
1313
1279
  if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
1314
1280
  if (!CBS_get_u16(&server_key_exchange, &signature_algorithm)) {
@@ -1319,10 +1285,10 @@ static int ssl3_get_server_key_exchange(SSL *ssl) {
1319
1285
  if (!tls12_check_peer_sigalg(ssl, &al, signature_algorithm)) {
1320
1286
  goto f_err;
1321
1287
  }
1322
- ssl->s3->tmp.peer_signature_algorithm = signature_algorithm;
1323
- } else if (pkey->type == EVP_PKEY_RSA) {
1288
+ hs->new_session->peer_signature_algorithm = signature_algorithm;
1289
+ } else if (hs->peer_pubkey->type == EVP_PKEY_RSA) {
1324
1290
  signature_algorithm = SSL_SIGN_RSA_PKCS1_MD5_SHA1;
1325
- } else if (pkey->type == EVP_PKEY_EC) {
1291
+ } else if (hs->peer_pubkey->type == EVP_PKEY_EC) {
1326
1292
  signature_algorithm = SSL_SIGN_ECDSA_SHA1;
1327
1293
  } else {
1328
1294
  al = SSL_AD_UNSUPPORTED_CERTIFICATE;
@@ -1355,7 +1321,7 @@ static int ssl3_get_server_key_exchange(SSL *ssl) {
1355
1321
 
1356
1322
  int sig_ok = ssl_public_key_verify(
1357
1323
  ssl, CBS_data(&signature), CBS_len(&signature), signature_algorithm,
1358
- pkey, transcript_data, transcript_len);
1324
+ hs->peer_pubkey, transcript_data, transcript_len);
1359
1325
  OPENSSL_free(transcript_data);
1360
1326
 
1361
1327
  #if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
@@ -1378,38 +1344,34 @@ static int ssl3_get_server_key_exchange(SSL *ssl) {
1378
1344
  goto f_err;
1379
1345
  }
1380
1346
  }
1381
- EVP_PKEY_free(pkey);
1382
1347
  return 1;
1383
1348
 
1384
1349
  f_err:
1385
1350
  ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
1386
1351
  err:
1387
- EVP_PKEY_free(pkey);
1388
1352
  DH_free(dh);
1389
1353
  EC_POINT_free(srvr_ecpoint);
1390
1354
  EC_KEY_free(ecdh);
1391
1355
  return -1;
1392
1356
  }
1393
1357
 
1394
- static int ssl3_get_certificate_request(SSL *ssl) {
1395
- int msg_ret = ssl->method->ssl_get_message(ssl, -1, ssl_hash_message);
1358
+ static int ssl3_get_certificate_request(SSL_HANDSHAKE *hs) {
1359
+ SSL *const ssl = hs->ssl;
1360
+ int msg_ret = ssl->method->ssl_get_message(ssl);
1396
1361
  if (msg_ret <= 0) {
1397
1362
  return msg_ret;
1398
1363
  }
1399
1364
 
1400
- ssl->s3->tmp.cert_request = 0;
1401
-
1402
1365
  if (ssl->s3->tmp.message_type == SSL3_MT_SERVER_HELLO_DONE) {
1403
1366
  ssl->s3->tmp.reuse_message = 1;
1404
1367
  /* If we get here we don't need the handshake buffer as we won't be doing
1405
1368
  * client auth. */
1406
- ssl3_free_handshake_buffer(ssl);
1369
+ SSL_TRANSCRIPT_free_buffer(&hs->transcript);
1407
1370
  return 1;
1408
1371
  }
1409
1372
 
1410
- if (ssl->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST) {
1411
- ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
1412
- OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
1373
+ if (!ssl_check_message_type(ssl, SSL3_MT_CERTIFICATE_REQUEST) ||
1374
+ !ssl_hash_current_message(hs)) {
1413
1375
  return -1;
1414
1376
  }
1415
1377
 
@@ -1424,8 +1386,8 @@ static int ssl3_get_certificate_request(SSL *ssl) {
1424
1386
  return -1;
1425
1387
  }
1426
1388
 
1427
- if (!CBS_stow(&certificate_types, &ssl->s3->tmp.certificate_types,
1428
- &ssl->s3->tmp.num_certificate_types)) {
1389
+ if (!CBS_stow(&certificate_types, &hs->certificate_types,
1390
+ &hs->num_certificate_types)) {
1429
1391
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
1430
1392
  return -1;
1431
1393
  }
@@ -1433,14 +1395,14 @@ static int ssl3_get_certificate_request(SSL *ssl) {
1433
1395
  if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
1434
1396
  CBS supported_signature_algorithms;
1435
1397
  if (!CBS_get_u16_length_prefixed(&cbs, &supported_signature_algorithms) ||
1436
- !tls1_parse_peer_sigalgs(ssl, &supported_signature_algorithms)) {
1398
+ !tls1_parse_peer_sigalgs(hs, &supported_signature_algorithms)) {
1437
1399
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1438
1400
  OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1439
1401
  return -1;
1440
1402
  }
1441
1403
  }
1442
1404
 
1443
- uint8_t alert;
1405
+ uint8_t alert = SSL_AD_DECODE_ERROR;
1444
1406
  STACK_OF(X509_NAME) *ca_sk = ssl_parse_client_CA_list(ssl, &alert, &cbs);
1445
1407
  if (ca_sk == NULL) {
1446
1408
  ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
@@ -1454,19 +1416,24 @@ static int ssl3_get_certificate_request(SSL *ssl) {
1454
1416
  return -1;
1455
1417
  }
1456
1418
 
1457
- ssl->s3->tmp.cert_request = 1;
1458
- sk_X509_NAME_pop_free(ssl->s3->tmp.ca_names, X509_NAME_free);
1459
- ssl->s3->tmp.ca_names = ca_sk;
1419
+ hs->cert_request = 1;
1420
+ sk_X509_NAME_pop_free(hs->ca_names, X509_NAME_free);
1421
+ hs->ca_names = ca_sk;
1460
1422
  return 1;
1461
1423
  }
1462
1424
 
1463
- static int ssl3_get_server_hello_done(SSL *ssl) {
1464
- int ret = ssl->method->ssl_get_message(ssl, SSL3_MT_SERVER_HELLO_DONE,
1465
- ssl_hash_message);
1425
+ static int ssl3_get_server_hello_done(SSL_HANDSHAKE *hs) {
1426
+ SSL *const ssl = hs->ssl;
1427
+ int ret = ssl->method->ssl_get_message(ssl);
1466
1428
  if (ret <= 0) {
1467
1429
  return ret;
1468
1430
  }
1469
1431
 
1432
+ if (!ssl_check_message_type(ssl, SSL3_MT_SERVER_HELLO_DONE) ||
1433
+ !ssl_hash_current_message(hs)) {
1434
+ return -1;
1435
+ }
1436
+
1470
1437
  /* ServerHelloDone is empty. */
1471
1438
  if (ssl->init_num > 0) {
1472
1439
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
@@ -1477,65 +1444,48 @@ static int ssl3_get_server_hello_done(SSL *ssl) {
1477
1444
  return 1;
1478
1445
  }
1479
1446
 
1480
- static int ssl3_send_client_certificate(SSL *ssl) {
1481
- if (ssl->state == SSL3_ST_CW_CERT_A) {
1482
- /* Call cert_cb to update the certificate. */
1483
- if (ssl->cert->cert_cb) {
1484
- int ret = ssl->cert->cert_cb(ssl, ssl->cert->cert_cb_arg);
1485
- if (ret < 0) {
1486
- ssl->rwstate = SSL_X509_LOOKUP;
1487
- return -1;
1488
- }
1489
- if (ret == 0) {
1490
- ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
1491
- return -1;
1492
- }
1447
+ static int ssl3_send_client_certificate(SSL_HANDSHAKE *hs) {
1448
+ SSL *const ssl = hs->ssl;
1449
+ /* Call cert_cb to update the certificate. */
1450
+ if (ssl->cert->cert_cb) {
1451
+ int ret = ssl->cert->cert_cb(ssl, ssl->cert->cert_cb_arg);
1452
+ if (ret < 0) {
1453
+ ssl->rwstate = SSL_X509_LOOKUP;
1454
+ return -1;
1493
1455
  }
1494
-
1495
- ssl->state = SSL3_ST_CW_CERT_B;
1496
- }
1497
-
1498
- if (ssl->state == SSL3_ST_CW_CERT_B) {
1499
- /* Call client_cert_cb to update the certificate. */
1500
- int should_retry;
1501
- if (!ssl_do_client_cert_cb(ssl, &should_retry)) {
1502
- if (should_retry) {
1503
- ssl->rwstate = SSL_X509_LOOKUP;
1504
- }
1456
+ if (ret == 0) {
1457
+ OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_CB_ERROR);
1458
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
1505
1459
  return -1;
1506
1460
  }
1461
+ }
1507
1462
 
1508
- if (!ssl_has_certificate(ssl)) {
1509
- ssl->s3->tmp.cert_request = 0;
1510
- /* Without a client certificate, the handshake buffer may be released. */
1511
- ssl3_free_handshake_buffer(ssl);
1463
+ if (!ssl_has_certificate(ssl)) {
1464
+ /* Without a client certificate, the handshake buffer may be released. */
1465
+ SSL_TRANSCRIPT_free_buffer(&hs->transcript);
1512
1466
 
1513
- if (ssl->version == SSL3_VERSION) {
1514
- /* In SSL 3.0, send no certificate by skipping both messages. */
1515
- ssl3_send_alert(ssl, SSL3_AL_WARNING, SSL_AD_NO_CERTIFICATE);
1516
- return 1;
1467
+ /* In SSL 3.0, the Certificate message is replaced with a warning alert. */
1468
+ if (ssl->version == SSL3_VERSION) {
1469
+ if (!ssl->method->add_alert(ssl, SSL3_AL_WARNING,
1470
+ SSL_AD_NO_CERTIFICATE)) {
1471
+ return -1;
1517
1472
  }
1473
+ return 1;
1518
1474
  }
1519
-
1520
- if (!ssl3_output_cert_chain(ssl)) {
1521
- return -1;
1522
- }
1523
- ssl->state = SSL3_ST_CW_CERT_C;
1524
1475
  }
1525
1476
 
1526
- assert(ssl->state == SSL3_ST_CW_CERT_C);
1527
- return ssl->method->write_message(ssl);
1477
+ if (!ssl_auto_chain_if_needed(ssl) ||
1478
+ !ssl3_output_cert_chain(ssl)) {
1479
+ return -1;
1480
+ }
1481
+ return 1;
1528
1482
  }
1529
1483
 
1530
1484
  OPENSSL_COMPILE_ASSERT(sizeof(size_t) >= sizeof(unsigned),
1531
1485
  SIZE_T_IS_SMALLER_THAN_UNSIGNED);
1532
1486
 
1533
- static int ssl3_send_client_key_exchange(SSL *ssl) {
1534
- if (ssl->state == SSL3_ST_CW_KEY_EXCH_B) {
1535
- return ssl->method->write_message(ssl);
1536
- }
1537
- assert(ssl->state == SSL3_ST_CW_KEY_EXCH_A);
1538
-
1487
+ static int ssl3_send_client_key_exchange(SSL_HANDSHAKE *hs) {
1488
+ SSL *const ssl = hs->ssl;
1539
1489
  uint8_t *pms = NULL;
1540
1490
  size_t pms_len = 0;
1541
1491
  CBB cbb, body;
@@ -1544,8 +1494,8 @@ static int ssl3_send_client_key_exchange(SSL *ssl) {
1544
1494
  goto err;
1545
1495
  }
1546
1496
 
1547
- uint32_t alg_k = ssl->s3->tmp.new_cipher->algorithm_mkey;
1548
- uint32_t alg_a = ssl->s3->tmp.new_cipher->algorithm_auth;
1497
+ uint32_t alg_k = hs->new_cipher->algorithm_mkey;
1498
+ uint32_t alg_a = hs->new_cipher->algorithm_auth;
1549
1499
 
1550
1500
  /* If using a PSK key exchange, prepare the pre-shared key. */
1551
1501
  unsigned psk_len = 0;
@@ -1557,10 +1507,10 @@ static int ssl3_send_client_key_exchange(SSL *ssl) {
1557
1507
  }
1558
1508
 
1559
1509
  char identity[PSK_MAX_IDENTITY_LEN + 1];
1560
- memset(identity, 0, sizeof(identity));
1561
- psk_len = ssl->psk_client_callback(
1562
- ssl, ssl->s3->hs->peer_psk_identity_hint, identity, sizeof(identity),
1563
- psk, sizeof(psk));
1510
+ OPENSSL_memset(identity, 0, sizeof(identity));
1511
+ psk_len =
1512
+ ssl->psk_client_callback(ssl, hs->peer_psk_identity_hint, identity,
1513
+ sizeof(identity), psk, sizeof(psk));
1564
1514
  if (psk_len == 0) {
1565
1515
  OPENSSL_PUT_ERROR(SSL, SSL_R_PSK_IDENTITY_NOT_FOUND);
1566
1516
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
@@ -1568,9 +1518,9 @@ static int ssl3_send_client_key_exchange(SSL *ssl) {
1568
1518
  }
1569
1519
  assert(psk_len <= PSK_MAX_PSK_LEN);
1570
1520
 
1571
- OPENSSL_free(ssl->s3->new_session->psk_identity);
1572
- ssl->s3->new_session->psk_identity = BUF_strdup(identity);
1573
- if (ssl->s3->new_session->psk_identity == NULL) {
1521
+ OPENSSL_free(hs->new_session->psk_identity);
1522
+ hs->new_session->psk_identity = BUF_strdup(identity);
1523
+ if (hs->new_session->psk_identity == NULL) {
1574
1524
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1575
1525
  goto err;
1576
1526
  }
@@ -1594,22 +1544,14 @@ static int ssl3_send_client_key_exchange(SSL *ssl) {
1594
1544
  goto err;
1595
1545
  }
1596
1546
 
1597
- EVP_PKEY *pkey = X509_get_pubkey(ssl->s3->new_session->peer);
1598
- if (pkey == NULL) {
1599
- goto err;
1600
- }
1601
-
1602
- RSA *rsa = EVP_PKEY_get0_RSA(pkey);
1547
+ RSA *rsa = EVP_PKEY_get0_RSA(hs->peer_pubkey);
1603
1548
  if (rsa == NULL) {
1604
1549
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1605
- EVP_PKEY_free(pkey);
1606
1550
  goto err;
1607
1551
  }
1608
1552
 
1609
- EVP_PKEY_free(pkey);
1610
-
1611
- pms[0] = ssl->client_version >> 8;
1612
- pms[1] = ssl->client_version & 0xff;
1553
+ pms[0] = hs->client_version >> 8;
1554
+ pms[1] = hs->client_version & 0xff;
1613
1555
  if (!RAND_bytes(&pms[2], SSL_MAX_MASTER_KEY_LENGTH - 2)) {
1614
1556
  goto err;
1615
1557
  }
@@ -1628,24 +1570,21 @@ static int ssl3_send_client_key_exchange(SSL *ssl) {
1628
1570
  if (!CBB_reserve(enc_pms, &ptr, RSA_size(rsa)) ||
1629
1571
  !RSA_encrypt(rsa, &enc_pms_len, ptr, RSA_size(rsa), pms, pms_len,
1630
1572
  RSA_PKCS1_PADDING) ||
1631
- /* Log the premaster secret, if logging is enabled. */
1632
- !ssl_log_rsa_client_key_exchange(ssl, ptr, enc_pms_len, pms, pms_len) ||
1633
1573
  !CBB_did_write(enc_pms, enc_pms_len) ||
1634
1574
  !CBB_flush(&body)) {
1635
1575
  goto err;
1636
1576
  }
1637
- } else if (alg_k & (SSL_kECDHE|SSL_kDHE|SSL_kCECPQ1)) {
1577
+ } else if (alg_k & (SSL_kECDHE|SSL_kDHE)) {
1638
1578
  /* Generate a keypair and serialize the public half. */
1639
1579
  CBB child;
1640
- if (!SSL_ECDH_CTX_add_key(&ssl->s3->tmp.ecdh_ctx, &body, &child)) {
1580
+ if (!SSL_ECDH_CTX_add_key(&hs->ecdh_ctx, &body, &child)) {
1641
1581
  goto err;
1642
1582
  }
1643
1583
 
1644
1584
  /* Compute the premaster. */
1645
- uint8_t alert;
1646
- if (!SSL_ECDH_CTX_accept(&ssl->s3->tmp.ecdh_ctx, &child, &pms, &pms_len,
1647
- &alert, ssl->s3->tmp.peer_key,
1648
- ssl->s3->tmp.peer_key_len)) {
1585
+ uint8_t alert = SSL_AD_DECODE_ERROR;
1586
+ if (!SSL_ECDH_CTX_accept(&hs->ecdh_ctx, &child, &pms, &pms_len, &alert,
1587
+ hs->peer_key, hs->peer_key_len)) {
1649
1588
  ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
1650
1589
  goto err;
1651
1590
  }
@@ -1654,9 +1593,10 @@ static int ssl3_send_client_key_exchange(SSL *ssl) {
1654
1593
  }
1655
1594
 
1656
1595
  /* The key exchange state may now be discarded. */
1657
- SSL_ECDH_CTX_cleanup(&ssl->s3->tmp.ecdh_ctx);
1658
- OPENSSL_free(ssl->s3->tmp.peer_key);
1659
- ssl->s3->tmp.peer_key = NULL;
1596
+ SSL_ECDH_CTX_cleanup(&hs->ecdh_ctx);
1597
+ OPENSSL_free(hs->peer_key);
1598
+ hs->peer_key = NULL;
1599
+ hs->peer_key_len = 0;
1660
1600
  } else if (alg_k & SSL_kPSK) {
1661
1601
  /* For plain PSK, other_secret is a block of 0s with the same length as
1662
1602
  * the pre-shared key. */
@@ -1666,7 +1606,7 @@ static int ssl3_send_client_key_exchange(SSL *ssl) {
1666
1606
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1667
1607
  goto err;
1668
1608
  }
1669
- memset(pms, 0, pms_len);
1609
+ OPENSSL_memset(pms, 0, pms_len);
1670
1610
  } else {
1671
1611
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1672
1612
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
@@ -1699,23 +1639,20 @@ static int ssl3_send_client_key_exchange(SSL *ssl) {
1699
1639
 
1700
1640
  /* The message must be added to the finished hash before calculating the
1701
1641
  * master secret. */
1702
- if (!ssl->method->finish_message(ssl, &cbb)) {
1642
+ if (!ssl_add_message_cbb(ssl, &cbb)) {
1703
1643
  goto err;
1704
1644
  }
1705
- ssl->state = SSL3_ST_CW_KEY_EXCH_B;
1706
1645
 
1707
- ssl->s3->new_session->master_key_length =
1708
- tls1_generate_master_secret(ssl, ssl->s3->new_session->master_key, pms,
1709
- pms_len);
1710
- if (ssl->s3->new_session->master_key_length == 0) {
1646
+ hs->new_session->master_key_length = tls1_generate_master_secret(
1647
+ hs, hs->new_session->master_key, pms, pms_len);
1648
+ if (hs->new_session->master_key_length == 0) {
1711
1649
  goto err;
1712
1650
  }
1713
- ssl->s3->new_session->extended_master_secret =
1714
- ssl->s3->tmp.extended_master_secret;
1651
+ hs->new_session->extended_master_secret = hs->extended_master_secret;
1715
1652
  OPENSSL_cleanse(pms, pms_len);
1716
1653
  OPENSSL_free(pms);
1717
1654
 
1718
- return ssl->method->write_message(ssl);
1655
+ return 1;
1719
1656
 
1720
1657
  err:
1721
1658
  CBB_cleanup(&cbb);
@@ -1726,11 +1663,8 @@ err:
1726
1663
  return -1;
1727
1664
  }
1728
1665
 
1729
- static int ssl3_send_cert_verify(SSL *ssl) {
1730
- if (ssl->state == SSL3_ST_CW_CERT_VRFY_C) {
1731
- return ssl->method->write_message(ssl);
1732
- }
1733
-
1666
+ static int ssl3_send_cert_verify(SSL_HANDSHAKE *hs) {
1667
+ SSL *const ssl = hs->ssl;
1734
1668
  assert(ssl_has_private_key(ssl));
1735
1669
 
1736
1670
  CBB cbb, body, child;
@@ -1740,7 +1674,7 @@ static int ssl3_send_cert_verify(SSL *ssl) {
1740
1674
  }
1741
1675
 
1742
1676
  uint16_t signature_algorithm;
1743
- if (!tls1_choose_signature_algorithm(ssl, &signature_algorithm)) {
1677
+ if (!tls1_choose_signature_algorithm(hs, &signature_algorithm)) {
1744
1678
  goto err;
1745
1679
  }
1746
1680
  if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
@@ -1761,7 +1695,7 @@ static int ssl3_send_cert_verify(SSL *ssl) {
1761
1695
 
1762
1696
  size_t sig_len = max_sig_len;
1763
1697
  enum ssl_private_key_result_t sign_result;
1764
- if (ssl->state == SSL3_ST_CW_CERT_VRFY_A) {
1698
+ if (hs->state == SSL3_ST_CW_CERT_VRFY_A) {
1765
1699
  /* The SSL3 construction for CertificateVerify does not decompose into a
1766
1700
  * single final digest and signature, and must be special-cased. */
1767
1701
  if (ssl3_protocol_version(ssl) == SSL3_VERSION) {
@@ -1770,11 +1704,11 @@ static int ssl3_send_cert_verify(SSL *ssl) {
1770
1704
  goto err;
1771
1705
  }
1772
1706
 
1773
- const EVP_MD *md;
1774
1707
  uint8_t digest[EVP_MAX_MD_SIZE];
1775
1708
  size_t digest_len;
1776
- if (!ssl3_cert_verify_hash(ssl, &md, digest, &digest_len,
1777
- signature_algorithm)) {
1709
+ if (!SSL_TRANSCRIPT_ssl3_cert_verify_hash(&hs->transcript, digest,
1710
+ &digest_len, hs->new_session,
1711
+ signature_algorithm)) {
1778
1712
  goto err;
1779
1713
  }
1780
1714
 
@@ -1783,7 +1717,6 @@ static int ssl3_send_cert_verify(SSL *ssl) {
1783
1717
  EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new(ssl->cert->privatekey, NULL);
1784
1718
  if (pctx == NULL ||
1785
1719
  !EVP_PKEY_sign_init(pctx) ||
1786
- !EVP_PKEY_CTX_set_signature_md(pctx, md) ||
1787
1720
  !EVP_PKEY_sign(pctx, ptr, &sig_len, digest, digest_len)) {
1788
1721
  EVP_PKEY_CTX_free(pctx);
1789
1722
  sign_result = ssl_private_key_failure;
@@ -1793,14 +1726,14 @@ static int ssl3_send_cert_verify(SSL *ssl) {
1793
1726
  } else {
1794
1727
  sign_result = ssl_private_key_sign(
1795
1728
  ssl, ptr, &sig_len, max_sig_len, signature_algorithm,
1796
- (const uint8_t *)ssl->s3->handshake_buffer->data,
1797
- ssl->s3->handshake_buffer->length);
1729
+ (const uint8_t *)hs->transcript.buffer->data,
1730
+ hs->transcript.buffer->length);
1798
1731
  }
1799
1732
 
1800
1733
  /* The handshake buffer is no longer necessary. */
1801
- ssl3_free_handshake_buffer(ssl);
1734
+ SSL_TRANSCRIPT_free_buffer(&hs->transcript);
1802
1735
  } else {
1803
- assert(ssl->state == SSL3_ST_CW_CERT_VRFY_B);
1736
+ assert(hs->state == SSL3_ST_CW_CERT_VRFY_B);
1804
1737
  sign_result = ssl_private_key_complete(ssl, ptr, &sig_len, max_sig_len);
1805
1738
  }
1806
1739
 
@@ -1811,30 +1744,24 @@ static int ssl3_send_cert_verify(SSL *ssl) {
1811
1744
  goto err;
1812
1745
  case ssl_private_key_retry:
1813
1746
  ssl->rwstate = SSL_PRIVATE_KEY_OPERATION;
1814
- ssl->state = SSL3_ST_CW_CERT_VRFY_B;
1747
+ hs->state = SSL3_ST_CW_CERT_VRFY_B;
1815
1748
  goto err;
1816
1749
  }
1817
1750
 
1818
1751
  if (!CBB_did_write(&child, sig_len) ||
1819
- !ssl->method->finish_message(ssl, &cbb)) {
1752
+ !ssl_add_message_cbb(ssl, &cbb)) {
1820
1753
  goto err;
1821
1754
  }
1822
1755
 
1823
- ssl->state = SSL3_ST_CW_CERT_VRFY_C;
1824
- return ssl->method->write_message(ssl);
1756
+ return 1;
1825
1757
 
1826
1758
  err:
1827
1759
  CBB_cleanup(&cbb);
1828
1760
  return -1;
1829
1761
  }
1830
1762
 
1831
- static int ssl3_send_next_proto(SSL *ssl) {
1832
- if (ssl->state == SSL3_ST_CW_NEXT_PROTO_B) {
1833
- return ssl->method->write_message(ssl);
1834
- }
1835
-
1836
- assert(ssl->state == SSL3_ST_CW_NEXT_PROTO_A);
1837
-
1763
+ static int ssl3_send_next_proto(SSL_HANDSHAKE *hs) {
1764
+ SSL *const ssl = hs->ssl;
1838
1765
  static const uint8_t kZero[32] = {0};
1839
1766
  size_t padding_len = 32 - ((ssl->s3->next_proto_negotiated_len + 2) % 32);
1840
1767
 
@@ -1845,33 +1772,19 @@ static int ssl3_send_next_proto(SSL *ssl) {
1845
1772
  ssl->s3->next_proto_negotiated_len) ||
1846
1773
  !CBB_add_u8_length_prefixed(&body, &child) ||
1847
1774
  !CBB_add_bytes(&child, kZero, padding_len) ||
1848
- !ssl->method->finish_message(ssl, &cbb)) {
1775
+ !ssl_add_message_cbb(ssl, &cbb)) {
1849
1776
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1850
1777
  CBB_cleanup(&cbb);
1851
1778
  return -1;
1852
1779
  }
1853
1780
 
1854
- ssl->state = SSL3_ST_CW_NEXT_PROTO_B;
1855
- return ssl->method->write_message(ssl);
1781
+ return 1;
1856
1782
  }
1857
1783
 
1858
- static int ssl3_send_channel_id(SSL *ssl) {
1859
- if (ssl->state == SSL3_ST_CW_CHANNEL_ID_B) {
1860
- return ssl->method->write_message(ssl);
1861
- }
1862
-
1863
- assert(ssl->state == SSL3_ST_CW_CHANNEL_ID_A);
1864
-
1865
- if (ssl->tlsext_channel_id_private == NULL &&
1866
- ssl->ctx->channel_id_cb != NULL) {
1867
- EVP_PKEY *key = NULL;
1868
- ssl->ctx->channel_id_cb(ssl, &key);
1869
- if (key != NULL &&
1870
- !SSL_set1_tls_channel_id(ssl, key)) {
1871
- EVP_PKEY_free(key);
1872
- return -1;
1873
- }
1874
- EVP_PKEY_free(key);
1784
+ static int ssl3_send_channel_id(SSL_HANDSHAKE *hs) {
1785
+ SSL *const ssl = hs->ssl;
1786
+ if (!ssl_do_channel_id_callback(ssl)) {
1787
+ return -1;
1875
1788
  }
1876
1789
 
1877
1790
  if (ssl->tlsext_channel_id_private == NULL) {
@@ -1879,64 +1792,30 @@ static int ssl3_send_channel_id(SSL *ssl) {
1879
1792
  return -1;
1880
1793
  }
1881
1794
 
1882
- EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(ssl->tlsext_channel_id_private);
1883
- if (ec_key == NULL) {
1884
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1885
- return -1;
1886
- }
1887
-
1888
- int ret = -1;
1889
- BIGNUM *x = BN_new();
1890
- BIGNUM *y = BN_new();
1891
- ECDSA_SIG *sig = NULL;
1892
- if (x == NULL || y == NULL ||
1893
- !EC_POINT_get_affine_coordinates_GFp(EC_KEY_get0_group(ec_key),
1894
- EC_KEY_get0_public_key(ec_key),
1895
- x, y, NULL)) {
1896
- goto err;
1897
- }
1898
-
1899
- uint8_t digest[EVP_MAX_MD_SIZE];
1900
- size_t digest_len;
1901
- if (!tls1_channel_id_hash(ssl, digest, &digest_len)) {
1902
- goto err;
1903
- }
1904
-
1905
- sig = ECDSA_do_sign(digest, digest_len, ec_key);
1906
- if (sig == NULL) {
1907
- goto err;
1908
- }
1909
-
1910
- CBB cbb, body, child;
1795
+ CBB cbb, body;
1911
1796
  if (!ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_CHANNEL_ID) ||
1912
- !CBB_add_u16(&body, TLSEXT_TYPE_channel_id) ||
1913
- !CBB_add_u16_length_prefixed(&body, &child) ||
1914
- !BN_bn2cbb_padded(&child, 32, x) || !BN_bn2cbb_padded(&child, 32, y) ||
1915
- !BN_bn2cbb_padded(&child, 32, sig->r) ||
1916
- !BN_bn2cbb_padded(&child, 32, sig->s) ||
1917
- !ssl->method->finish_message(ssl, &cbb)) {
1797
+ !tls1_write_channel_id(hs, &body) ||
1798
+ !ssl_add_message_cbb(ssl, &cbb)) {
1918
1799
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1919
1800
  CBB_cleanup(&cbb);
1920
- goto err;
1801
+ return -1;
1921
1802
  }
1922
1803
 
1923
- ssl->state = SSL3_ST_CW_CHANNEL_ID_B;
1924
- ret = ssl->method->write_message(ssl);
1925
-
1926
- err:
1927
- BN_free(x);
1928
- BN_free(y);
1929
- ECDSA_SIG_free(sig);
1930
- return ret;
1804
+ return 1;
1931
1805
  }
1932
1806
 
1933
- static int ssl3_get_new_session_ticket(SSL *ssl) {
1934
- int ret = ssl->method->ssl_get_message(ssl, SSL3_MT_NEW_SESSION_TICKET,
1935
- ssl_hash_message);
1807
+ static int ssl3_get_new_session_ticket(SSL_HANDSHAKE *hs) {
1808
+ SSL *const ssl = hs->ssl;
1809
+ int ret = ssl->method->ssl_get_message(ssl);
1936
1810
  if (ret <= 0) {
1937
1811
  return ret;
1938
1812
  }
1939
1813
 
1814
+ if (!ssl_check_message_type(ssl, SSL3_MT_NEW_SESSION_TICKET) ||
1815
+ !ssl_hash_current_message(hs)) {
1816
+ return -1;
1817
+ }
1818
+
1940
1819
  CBS new_session_ticket, ticket;
1941
1820
  uint32_t tlsext_tick_lifetime_hint;
1942
1821
  CBS_init(&new_session_ticket, ssl->init_msg, ssl->init_num);
@@ -1950,15 +1829,14 @@ static int ssl3_get_new_session_ticket(SSL *ssl) {
1950
1829
 
1951
1830
  if (CBS_len(&ticket) == 0) {
1952
1831
  /* RFC 5077 allows a server to change its mind and send no ticket after
1953
- * negotiating the extension. The value of |tlsext_ticket_expected| is
1954
- * checked in |ssl_update_cache| so is cleared here to avoid an unnecessary
1955
- * update. */
1956
- ssl->tlsext_ticket_expected = 0;
1832
+ * negotiating the extension. The value of |ticket_expected| is checked in
1833
+ * |ssl_update_cache| so is cleared here to avoid an unnecessary update. */
1834
+ hs->ticket_expected = 0;
1957
1835
  return 1;
1958
1836
  }
1959
1837
 
1960
1838
  int session_renewed = ssl->session != NULL;
1961
- SSL_SESSION *session = ssl->s3->new_session;
1839
+ SSL_SESSION *session = hs->new_session;
1962
1840
  if (session_renewed) {
1963
1841
  /* The server is sending a new ticket for an existing session. Sessions are
1964
1842
  * immutable once established, so duplicate all but the ticket of the
@@ -1971,6 +1849,9 @@ static int ssl3_get_new_session_ticket(SSL *ssl) {
1971
1849
  }
1972
1850
  }
1973
1851
 
1852
+ /* |tlsext_tick_lifetime_hint| is measured from when the ticket was issued. */
1853
+ ssl_session_rebase_time(ssl, session);
1854
+
1974
1855
  if (!CBS_stow(&ticket, &session->tlsext_tick, &session->tlsext_ticklen)) {
1975
1856
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1976
1857
  goto err;