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
@@ -171,184 +171,178 @@
171
171
  #include "../crypto/internal.h"
172
172
 
173
173
 
174
- static int ssl3_get_client_hello(SSL *ssl);
175
- static int ssl3_send_server_hello(SSL *ssl);
176
- static int ssl3_send_server_certificate(SSL *ssl);
177
- static int ssl3_send_certificate_status(SSL *ssl);
178
- static int ssl3_send_server_key_exchange(SSL *ssl);
179
- static int ssl3_send_certificate_request(SSL *ssl);
180
- static int ssl3_send_server_hello_done(SSL *ssl);
181
- static int ssl3_get_client_certificate(SSL *ssl);
182
- static int ssl3_get_client_key_exchange(SSL *ssl);
183
- static int ssl3_get_cert_verify(SSL *ssl);
184
- static int ssl3_get_next_proto(SSL *ssl);
185
- static int ssl3_get_channel_id(SSL *ssl);
186
- static int ssl3_send_new_session_ticket(SSL *ssl);
187
-
188
- int ssl3_accept(SSL *ssl) {
174
+ static int ssl3_process_client_hello(SSL_HANDSHAKE *hs);
175
+ static int ssl3_select_certificate(SSL_HANDSHAKE *hs);
176
+ static int ssl3_select_parameters(SSL_HANDSHAKE *hs);
177
+ static int ssl3_send_server_hello(SSL_HANDSHAKE *hs);
178
+ static int ssl3_send_server_certificate(SSL_HANDSHAKE *hs);
179
+ static int ssl3_send_certificate_status(SSL_HANDSHAKE *hs);
180
+ static int ssl3_send_server_key_exchange(SSL_HANDSHAKE *hs);
181
+ static int ssl3_send_certificate_request(SSL_HANDSHAKE *hs);
182
+ static int ssl3_send_server_hello_done(SSL_HANDSHAKE *hs);
183
+ static int ssl3_get_client_certificate(SSL_HANDSHAKE *hs);
184
+ static int ssl3_get_client_key_exchange(SSL_HANDSHAKE *hs);
185
+ static int ssl3_get_cert_verify(SSL_HANDSHAKE *hs);
186
+ static int ssl3_get_next_proto(SSL_HANDSHAKE *hs);
187
+ static int ssl3_get_channel_id(SSL_HANDSHAKE *hs);
188
+ static int ssl3_send_new_session_ticket(SSL_HANDSHAKE *hs);
189
+
190
+ static struct CRYPTO_STATIC_MUTEX g_v2clienthello_lock =
191
+ CRYPTO_STATIC_MUTEX_INIT;
192
+ static uint64_t g_v2clienthello_count = 0;
193
+
194
+ uint64_t SSL_get_v2clienthello_count(void) {
195
+ CRYPTO_STATIC_MUTEX_lock_read(&g_v2clienthello_lock);
196
+ uint64_t ret = g_v2clienthello_count;
197
+ CRYPTO_STATIC_MUTEX_unlock_read(&g_v2clienthello_lock);
198
+ return ret;
199
+ }
200
+
201
+ int ssl3_accept(SSL_HANDSHAKE *hs) {
202
+ SSL *const ssl = hs->ssl;
189
203
  uint32_t alg_a;
190
204
  int ret = -1;
191
- int state, skip = 0;
192
205
 
193
206
  assert(ssl->handshake_func == ssl3_accept);
194
207
  assert(ssl->server);
195
208
 
196
209
  for (;;) {
197
- state = ssl->state;
210
+ int state = hs->state;
198
211
 
199
- switch (ssl->state) {
212
+ switch (hs->state) {
200
213
  case SSL_ST_INIT:
201
- ssl->state = SSL_ST_ACCEPT;
202
- skip = 1;
203
- break;
204
-
205
- case SSL_ST_ACCEPT:
206
214
  ssl_do_info_callback(ssl, SSL_CB_HANDSHAKE_START, 1);
215
+ hs->state = SSL3_ST_SR_CLNT_HELLO_A;
216
+ break;
207
217
 
208
- ssl->s3->hs = ssl_handshake_new(tls13_server_handshake);
209
- if (ssl->s3->hs == NULL) {
210
- ret = -1;
218
+ case SSL3_ST_SR_CLNT_HELLO_A:
219
+ ret = ssl->method->ssl_get_message(ssl);
220
+ if (ret <= 0) {
211
221
  goto end;
212
222
  }
223
+ hs->state = SSL3_ST_SR_CLNT_HELLO_B;
224
+ break;
213
225
 
214
- /* Enable a write buffer. This groups handshake messages within a flight
215
- * into a single write. */
216
- if (!ssl_init_wbio_buffer(ssl)) {
217
- ret = -1;
226
+ case SSL3_ST_SR_CLNT_HELLO_B:
227
+ ret = ssl3_process_client_hello(hs);
228
+ if (ret <= 0) {
218
229
  goto end;
219
230
  }
231
+ hs->state = SSL3_ST_SR_CLNT_HELLO_C;
232
+ break;
220
233
 
221
- if (!ssl3_init_handshake_buffer(ssl)) {
222
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
223
- ret = -1;
234
+ case SSL3_ST_SR_CLNT_HELLO_C:
235
+ ret = ssl3_select_certificate(hs);
236
+ if (ret <= 0) {
224
237
  goto end;
225
238
  }
226
-
227
- ssl->state = SSL3_ST_SR_CLNT_HELLO_A;
239
+ if (hs->state != SSL_ST_TLS13) {
240
+ hs->state = SSL3_ST_SR_CLNT_HELLO_D;
241
+ }
228
242
  break;
229
243
 
230
- case SSL3_ST_SR_CLNT_HELLO_A:
231
- case SSL3_ST_SR_CLNT_HELLO_B:
232
- case SSL3_ST_SR_CLNT_HELLO_C:
233
244
  case SSL3_ST_SR_CLNT_HELLO_D:
234
- ret = ssl3_get_client_hello(ssl);
235
- if (ssl->state == SSL_ST_TLS13) {
236
- break;
237
- }
245
+ ret = ssl3_select_parameters(hs);
238
246
  if (ret <= 0) {
239
247
  goto end;
240
248
  }
241
249
  ssl->method->received_flight(ssl);
242
- ssl->state = SSL3_ST_SW_SRVR_HELLO_A;
250
+ hs->state = SSL3_ST_SW_SRVR_HELLO_A;
243
251
  break;
244
252
 
245
253
  case SSL3_ST_SW_SRVR_HELLO_A:
246
- case SSL3_ST_SW_SRVR_HELLO_B:
247
- ret = ssl3_send_server_hello(ssl);
254
+ ret = ssl3_send_server_hello(hs);
248
255
  if (ret <= 0) {
249
256
  goto end;
250
257
  }
251
258
  if (ssl->session != NULL) {
252
- ssl->state = SSL3_ST_SW_SESSION_TICKET_A;
259
+ hs->state = SSL3_ST_SW_SESSION_TICKET_A;
253
260
  } else {
254
- ssl->state = SSL3_ST_SW_CERT_A;
261
+ hs->state = SSL3_ST_SW_CERT_A;
255
262
  }
256
263
  break;
257
264
 
258
265
  case SSL3_ST_SW_CERT_A:
259
- case SSL3_ST_SW_CERT_B:
260
- if (ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
261
- ret = ssl3_send_server_certificate(ssl);
266
+ if (ssl_cipher_uses_certificate_auth(hs->new_cipher)) {
267
+ ret = ssl3_send_server_certificate(hs);
262
268
  if (ret <= 0) {
263
269
  goto end;
264
270
  }
265
- } else {
266
- skip = 1;
267
271
  }
268
- ssl->state = SSL3_ST_SW_CERT_STATUS_A;
272
+ hs->state = SSL3_ST_SW_CERT_STATUS_A;
269
273
  break;
270
274
 
271
275
  case SSL3_ST_SW_CERT_STATUS_A:
272
- case SSL3_ST_SW_CERT_STATUS_B:
273
- if (ssl->s3->tmp.certificate_status_expected) {
274
- ret = ssl3_send_certificate_status(ssl);
276
+ if (hs->certificate_status_expected) {
277
+ ret = ssl3_send_certificate_status(hs);
275
278
  if (ret <= 0) {
276
279
  goto end;
277
280
  }
278
- } else {
279
- skip = 1;
280
281
  }
281
- ssl->state = SSL3_ST_SW_KEY_EXCH_A;
282
+ hs->state = SSL3_ST_SW_KEY_EXCH_A;
282
283
  break;
283
284
 
284
285
  case SSL3_ST_SW_KEY_EXCH_A:
285
286
  case SSL3_ST_SW_KEY_EXCH_B:
286
- case SSL3_ST_SW_KEY_EXCH_C:
287
- alg_a = ssl->s3->tmp.new_cipher->algorithm_auth;
287
+ alg_a = hs->new_cipher->algorithm_auth;
288
288
 
289
289
  /* PSK ciphers send ServerKeyExchange if there is an identity hint. */
290
- if (ssl_cipher_requires_server_key_exchange(ssl->s3->tmp.new_cipher) ||
290
+ if (ssl_cipher_requires_server_key_exchange(hs->new_cipher) ||
291
291
  ((alg_a & SSL_aPSK) && ssl->psk_identity_hint)) {
292
- ret = ssl3_send_server_key_exchange(ssl);
292
+ ret = ssl3_send_server_key_exchange(hs);
293
293
  if (ret <= 0) {
294
294
  goto end;
295
295
  }
296
- } else {
297
- skip = 1;
298
296
  }
299
297
 
300
- ssl->state = SSL3_ST_SW_CERT_REQ_A;
298
+ hs->state = SSL3_ST_SW_CERT_REQ_A;
301
299
  break;
302
300
 
303
301
  case SSL3_ST_SW_CERT_REQ_A:
304
- case SSL3_ST_SW_CERT_REQ_B:
305
- if (ssl->s3->tmp.cert_request) {
306
- ret = ssl3_send_certificate_request(ssl);
302
+ if (hs->cert_request) {
303
+ ret = ssl3_send_certificate_request(hs);
307
304
  if (ret <= 0) {
308
305
  goto end;
309
306
  }
310
- } else {
311
- skip = 1;
312
307
  }
313
- ssl->state = SSL3_ST_SW_SRVR_DONE_A;
308
+ hs->state = SSL3_ST_SW_SRVR_DONE_A;
314
309
  break;
315
310
 
316
311
  case SSL3_ST_SW_SRVR_DONE_A:
317
- case SSL3_ST_SW_SRVR_DONE_B:
318
- ret = ssl3_send_server_hello_done(ssl);
312
+ ret = ssl3_send_server_hello_done(hs);
319
313
  if (ret <= 0) {
320
314
  goto end;
321
315
  }
322
- ssl->s3->tmp.next_state = SSL3_ST_SR_CERT_A;
323
- ssl->state = SSL3_ST_SW_FLUSH;
316
+ hs->next_state = SSL3_ST_SR_CERT_A;
317
+ hs->state = SSL3_ST_SW_FLUSH;
324
318
  break;
325
319
 
326
320
  case SSL3_ST_SR_CERT_A:
327
- if (ssl->s3->tmp.cert_request) {
328
- ret = ssl3_get_client_certificate(ssl);
321
+ if (hs->cert_request) {
322
+ ret = ssl3_get_client_certificate(hs);
329
323
  if (ret <= 0) {
330
324
  goto end;
331
325
  }
332
326
  }
333
- ssl->state = SSL3_ST_SR_KEY_EXCH_A;
327
+ hs->state = SSL3_ST_SR_KEY_EXCH_A;
334
328
  break;
335
329
 
336
330
  case SSL3_ST_SR_KEY_EXCH_A:
337
331
  case SSL3_ST_SR_KEY_EXCH_B:
338
- ret = ssl3_get_client_key_exchange(ssl);
332
+ ret = ssl3_get_client_key_exchange(hs);
339
333
  if (ret <= 0) {
340
334
  goto end;
341
335
  }
342
- ssl->state = SSL3_ST_SR_CERT_VRFY_A;
336
+ hs->state = SSL3_ST_SR_CERT_VRFY_A;
343
337
  break;
344
338
 
345
339
  case SSL3_ST_SR_CERT_VRFY_A:
346
- ret = ssl3_get_cert_verify(ssl);
340
+ ret = ssl3_get_cert_verify(hs);
347
341
  if (ret <= 0) {
348
342
  goto end;
349
343
  }
350
344
 
351
- ssl->state = SSL3_ST_SR_CHANGE;
345
+ hs->state = SSL3_ST_SR_CHANGE;
352
346
  break;
353
347
 
354
348
  case SSL3_ST_SR_CHANGE:
@@ -357,56 +351,52 @@ int ssl3_accept(SSL *ssl) {
357
351
  goto end;
358
352
  }
359
353
 
360
- if (!tls1_change_cipher_state(ssl, SSL3_CHANGE_CIPHER_SERVER_READ)) {
354
+ if (!tls1_change_cipher_state(hs, SSL3_CHANGE_CIPHER_SERVER_READ)) {
361
355
  ret = -1;
362
356
  goto end;
363
357
  }
364
358
 
365
- ssl->state = SSL3_ST_SR_NEXT_PROTO_A;
359
+ hs->state = SSL3_ST_SR_NEXT_PROTO_A;
366
360
  break;
367
361
 
368
362
  case SSL3_ST_SR_NEXT_PROTO_A:
369
- if (ssl->s3->next_proto_neg_seen) {
370
- ret = ssl3_get_next_proto(ssl);
363
+ if (hs->next_proto_neg_seen) {
364
+ ret = ssl3_get_next_proto(hs);
371
365
  if (ret <= 0) {
372
366
  goto end;
373
367
  }
374
- } else {
375
- skip = 1;
376
368
  }
377
- ssl->state = SSL3_ST_SR_CHANNEL_ID_A;
369
+ hs->state = SSL3_ST_SR_CHANNEL_ID_A;
378
370
  break;
379
371
 
380
372
  case SSL3_ST_SR_CHANNEL_ID_A:
381
373
  if (ssl->s3->tlsext_channel_id_valid) {
382
- ret = ssl3_get_channel_id(ssl);
374
+ ret = ssl3_get_channel_id(hs);
383
375
  if (ret <= 0) {
384
376
  goto end;
385
377
  }
386
- } else {
387
- skip = 1;
388
378
  }
389
- ssl->state = SSL3_ST_SR_FINISHED_A;
379
+ hs->state = SSL3_ST_SR_FINISHED_A;
390
380
  break;
391
381
 
392
382
  case SSL3_ST_SR_FINISHED_A:
393
- ret = ssl3_get_finished(ssl);
383
+ ret = ssl3_get_finished(hs);
394
384
  if (ret <= 0) {
395
385
  goto end;
396
386
  }
397
387
 
398
388
  ssl->method->received_flight(ssl);
399
389
  if (ssl->session != NULL) {
400
- ssl->state = SSL_ST_OK;
390
+ hs->state = SSL_ST_OK;
401
391
  } else {
402
- ssl->state = SSL3_ST_SW_SESSION_TICKET_A;
392
+ hs->state = SSL3_ST_SW_SESSION_TICKET_A;
403
393
  }
404
394
 
405
395
  /* If this is a full handshake with ChannelID then record the handshake
406
- * hashes in |ssl->s3->new_session| in case we need them to verify a
396
+ * hashes in |hs->new_session| in case we need them to verify a
407
397
  * ChannelID signature on a resumption of this session in the future. */
408
398
  if (ssl->session == NULL && ssl->s3->tlsext_channel_id_valid) {
409
- ret = tls1_record_handshake_hashes_for_channel_id(ssl);
399
+ ret = tls1_record_handshake_hashes_for_channel_id(hs);
410
400
  if (ret <= 0) {
411
401
  goto end;
412
402
  }
@@ -414,80 +404,68 @@ int ssl3_accept(SSL *ssl) {
414
404
  break;
415
405
 
416
406
  case SSL3_ST_SW_SESSION_TICKET_A:
417
- case SSL3_ST_SW_SESSION_TICKET_B:
418
- if (ssl->tlsext_ticket_expected) {
419
- ret = ssl3_send_new_session_ticket(ssl);
407
+ if (hs->ticket_expected) {
408
+ ret = ssl3_send_new_session_ticket(hs);
420
409
  if (ret <= 0) {
421
410
  goto end;
422
411
  }
423
- } else {
424
- skip = 1;
425
412
  }
426
- ssl->state = SSL3_ST_SW_CHANGE;
413
+ hs->state = SSL3_ST_SW_CHANGE;
427
414
  break;
428
415
 
429
416
  case SSL3_ST_SW_CHANGE:
430
- ret = ssl->method->send_change_cipher_spec(ssl);
431
- if (ret <= 0) {
432
- goto end;
433
- }
434
- ssl->state = SSL3_ST_SW_FINISHED_A;
435
-
436
- if (!tls1_change_cipher_state(ssl, SSL3_CHANGE_CIPHER_SERVER_WRITE)) {
417
+ if (!ssl->method->add_change_cipher_spec(ssl) ||
418
+ !tls1_change_cipher_state(hs, SSL3_CHANGE_CIPHER_SERVER_WRITE)) {
437
419
  ret = -1;
438
420
  goto end;
439
421
  }
422
+
423
+ hs->state = SSL3_ST_SW_FINISHED_A;
440
424
  break;
441
425
 
442
426
  case SSL3_ST_SW_FINISHED_A:
443
- case SSL3_ST_SW_FINISHED_B:
444
- ret = ssl3_send_finished(ssl, SSL3_ST_SW_FINISHED_A,
445
- SSL3_ST_SW_FINISHED_B);
427
+ ret = ssl3_send_finished(hs);
446
428
  if (ret <= 0) {
447
429
  goto end;
448
430
  }
449
- ssl->state = SSL3_ST_SW_FLUSH;
431
+ hs->state = SSL3_ST_SW_FLUSH;
450
432
  if (ssl->session != NULL) {
451
- ssl->s3->tmp.next_state = SSL3_ST_SR_CHANGE;
433
+ hs->next_state = SSL3_ST_SR_CHANGE;
452
434
  } else {
453
- ssl->s3->tmp.next_state = SSL_ST_OK;
435
+ hs->next_state = SSL_ST_OK;
454
436
  }
455
437
  break;
456
438
 
457
439
  case SSL3_ST_SW_FLUSH:
458
- if (BIO_flush(ssl->wbio) <= 0) {
459
- ssl->rwstate = SSL_WRITING;
460
- ret = -1;
440
+ ret = ssl->method->flush_flight(ssl);
441
+ if (ret <= 0) {
461
442
  goto end;
462
443
  }
463
444
 
464
- ssl->state = ssl->s3->tmp.next_state;
465
- if (ssl->state != SSL_ST_OK) {
445
+ hs->state = hs->next_state;
446
+ if (hs->state != SSL_ST_OK) {
466
447
  ssl->method->expect_flight(ssl);
467
448
  }
468
449
  break;
469
450
 
470
451
  case SSL_ST_TLS13:
471
- ret = tls13_handshake(ssl);
452
+ ret = tls13_handshake(hs);
472
453
  if (ret <= 0) {
473
454
  goto end;
474
455
  }
475
- ssl->state = SSL_ST_OK;
456
+ hs->state = SSL_ST_OK;
476
457
  break;
477
458
 
478
459
  case SSL_ST_OK:
479
- /* Clean a few things up. */
480
- ssl3_cleanup_key_block(ssl);
481
460
  ssl->method->release_current_message(ssl, 1 /* free_buffer */);
482
461
 
483
462
  /* If we aren't retaining peer certificates then we can discard it
484
463
  * now. */
485
- if (ssl->s3->new_session != NULL &&
486
- ssl->ctx->retain_only_sha256_of_client_certs) {
487
- X509_free(ssl->s3->new_session->peer);
488
- ssl->s3->new_session->peer = NULL;
489
- sk_X509_pop_free(ssl->s3->new_session->cert_chain, X509_free);
490
- ssl->s3->new_session->cert_chain = NULL;
464
+ if (hs->new_session != NULL &&
465
+ ssl->retain_only_sha256_of_client_certs) {
466
+ sk_CRYPTO_BUFFER_pop_free(hs->new_session->certs, CRYPTO_BUFFER_free);
467
+ hs->new_session->certs = NULL;
468
+ ssl->ctx->x509_method->session_clear(hs->new_session);
491
469
  }
492
470
 
493
471
  SSL_SESSION_free(ssl->s3->established_session);
@@ -495,23 +473,21 @@ int ssl3_accept(SSL *ssl) {
495
473
  SSL_SESSION_up_ref(ssl->session);
496
474
  ssl->s3->established_session = ssl->session;
497
475
  } else {
498
- ssl->s3->established_session = ssl->s3->new_session;
476
+ ssl->s3->established_session = hs->new_session;
499
477
  ssl->s3->established_session->not_resumable = 0;
500
- ssl->s3->new_session = NULL;
478
+ hs->new_session = NULL;
501
479
  }
502
480
 
503
- /* remove buffering on output */
504
- ssl_free_wbio_buffer(ssl);
505
-
506
- ssl_handshake_free(ssl->s3->hs);
507
- ssl->s3->hs = NULL;
481
+ if (hs->v2_clienthello) {
482
+ CRYPTO_STATIC_MUTEX_lock_write(&g_v2clienthello_lock);
483
+ g_v2clienthello_count++;
484
+ CRYPTO_STATIC_MUTEX_unlock_write(&g_v2clienthello_lock);
485
+ }
508
486
 
509
487
  ssl->s3->initial_handshake_complete = 1;
510
-
511
- ssl_update_cache(ssl, SSL_SESS_CACHE_SERVER);
488
+ ssl_update_cache(hs, SSL_SESS_CACHE_SERVER);
512
489
 
513
490
  ssl_do_info_callback(ssl, SSL_CB_HANDSHAKE_DONE, 1);
514
-
515
491
  ret = 1;
516
492
  goto end;
517
493
 
@@ -521,13 +497,9 @@ int ssl3_accept(SSL *ssl) {
521
497
  goto end;
522
498
  }
523
499
 
524
- if (!ssl->s3->tmp.reuse_message && !skip && ssl->state != state) {
525
- int new_state = ssl->state;
526
- ssl->state = state;
500
+ if (hs->state != state) {
527
501
  ssl_do_info_callback(ssl, SSL_CB_ACCEPT_LOOP, 1);
528
- ssl->state = new_state;
529
502
  }
530
- skip = 0;
531
503
  }
532
504
 
533
505
  end:
@@ -535,8 +507,8 @@ end:
535
507
  return ret;
536
508
  }
537
509
 
538
- int ssl_client_cipher_list_contains_cipher(
539
- const struct ssl_early_callback_ctx *client_hello, uint16_t id) {
510
+ int ssl_client_cipher_list_contains_cipher(const SSL_CLIENT_HELLO *client_hello,
511
+ uint16_t id) {
540
512
  CBS cipher_suites;
541
513
  CBS_init(&cipher_suites, client_hello->cipher_suites,
542
514
  client_hello->cipher_suites_len);
@@ -555,9 +527,10 @@ int ssl_client_cipher_list_contains_cipher(
555
527
  return 0;
556
528
  }
557
529
 
558
- static int negotiate_version(
559
- SSL *ssl, int *out_alert,
560
- const struct ssl_early_callback_ctx *client_hello) {
530
+ static int negotiate_version(SSL_HANDSHAKE *hs, uint8_t *out_alert,
531
+ const SSL_CLIENT_HELLO *client_hello) {
532
+ SSL *const ssl = hs->ssl;
533
+ assert(!ssl->s3->have_version);
561
534
  uint16_t min_version, max_version;
562
535
  if (!ssl_get_version_range(ssl, &min_version, &max_version)) {
563
536
  *out_alert = SSL_AD_PROTOCOL_VERSION;
@@ -567,8 +540,8 @@ static int negotiate_version(
567
540
  uint16_t version = 0;
568
541
  /* Check supported_versions extension if it is present. */
569
542
  CBS supported_versions;
570
- if (ssl_early_callback_get_extension(client_hello, &supported_versions,
571
- TLSEXT_TYPE_supported_versions)) {
543
+ if (ssl_client_hello_get_extension(client_hello, &supported_versions,
544
+ TLSEXT_TYPE_supported_versions)) {
572
545
  CBS versions;
573
546
  if (!CBS_get_u8_length_prefixed(&supported_versions, &versions) ||
574
547
  CBS_len(&supported_versions) != 0 ||
@@ -578,6 +551,9 @@ static int negotiate_version(
578
551
  return 0;
579
552
  }
580
553
 
554
+ /* Choose the newest commonly-supported version advertised by the client.
555
+ * The client orders the versions according to its preferences, but we're
556
+ * not required to honor the client's preferences. */
581
557
  int found_version = 0;
582
558
  while (CBS_len(&versions) != 0) {
583
559
  uint16_t ext_version;
@@ -590,10 +566,10 @@ static int negotiate_version(
590
566
  continue;
591
567
  }
592
568
  if (min_version <= ext_version &&
593
- ext_version <= max_version) {
569
+ ext_version <= max_version &&
570
+ (!found_version || version < ext_version)) {
594
571
  version = ext_version;
595
572
  found_version = 1;
596
- break;
597
573
  }
598
574
  }
599
575
 
@@ -644,10 +620,8 @@ static int negotiate_version(
644
620
  return 0;
645
621
  }
646
622
 
647
- ssl->client_version = client_hello->version;
623
+ hs->client_version = client_hello->version;
648
624
  ssl->version = ssl->method->version_to_wire(version);
649
- ssl->s3->enc_method = ssl3_get_enc_method(version);
650
- assert(ssl->s3->enc_method != NULL);
651
625
 
652
626
  /* At this point, the connection's version is known and |ssl->version| is
653
627
  * fixed. Begin enforcing the record-layer version. */
@@ -661,235 +635,397 @@ unsupported_protocol:
661
635
  return 0;
662
636
  }
663
637
 
664
- static int ssl3_get_client_hello(SSL *ssl) {
665
- int al = SSL_AD_INTERNAL_ERROR, ret = -1;
666
- SSL_SESSION *session = NULL;
638
+ static STACK_OF(SSL_CIPHER) *
639
+ ssl_parse_client_cipher_list(const SSL_CLIENT_HELLO *client_hello) {
640
+ CBS cipher_suites;
641
+ CBS_init(&cipher_suites, client_hello->cipher_suites,
642
+ client_hello->cipher_suites_len);
643
+
644
+ STACK_OF(SSL_CIPHER) *sk = sk_SSL_CIPHER_new_null();
645
+ if (sk == NULL) {
646
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
647
+ goto err;
648
+ }
667
649
 
668
- if (ssl->state == SSL3_ST_SR_CLNT_HELLO_A) {
669
- /* The first time around, read the ClientHello. */
670
- int msg_ret = ssl->method->ssl_get_message(ssl, SSL3_MT_CLIENT_HELLO,
671
- ssl_hash_message);
672
- if (msg_ret <= 0) {
673
- return msg_ret;
650
+ while (CBS_len(&cipher_suites) > 0) {
651
+ uint16_t cipher_suite;
652
+
653
+ if (!CBS_get_u16(&cipher_suites, &cipher_suite)) {
654
+ OPENSSL_PUT_ERROR(SSL, SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
655
+ goto err;
674
656
  }
675
657
 
676
- ssl->state = SSL3_ST_SR_CLNT_HELLO_B;
658
+ const SSL_CIPHER *c = SSL_get_cipher_by_value(cipher_suite);
659
+ if (c != NULL && !sk_SSL_CIPHER_push(sk, c)) {
660
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
661
+ goto err;
662
+ }
677
663
  }
678
664
 
679
- struct ssl_early_callback_ctx client_hello;
680
- if (!ssl_early_callback_init(ssl, &client_hello, ssl->init_msg,
681
- ssl->init_num)) {
682
- al = SSL_AD_DECODE_ERROR;
683
- OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
684
- goto f_err;
685
- }
665
+ return sk;
686
666
 
687
- if (ssl->state == SSL3_ST_SR_CLNT_HELLO_B) {
688
- /* Unlike other callbacks, the early callback is not run a second time if
689
- * paused. */
690
- ssl->state = SSL3_ST_SR_CLNT_HELLO_C;
667
+ err:
668
+ sk_SSL_CIPHER_free(sk);
669
+ return NULL;
670
+ }
691
671
 
692
- /* Run the early callback. */
693
- if (ssl->ctx->select_certificate_cb != NULL) {
694
- switch (ssl->ctx->select_certificate_cb(&client_hello)) {
695
- case 0:
696
- ssl->rwstate = SSL_CERTIFICATE_SELECTION_PENDING;
697
- goto err;
672
+ /* ssl_get_compatible_server_ciphers determines the key exchange and
673
+ * authentication cipher suite masks compatible with the server configuration
674
+ * and current ClientHello parameters of |hs|. It sets |*out_mask_k| to the key
675
+ * exchange mask and |*out_mask_a| to the authentication mask. */
676
+ static void ssl_get_compatible_server_ciphers(SSL_HANDSHAKE *hs,
677
+ uint32_t *out_mask_k,
678
+ uint32_t *out_mask_a) {
679
+ SSL *const ssl = hs->ssl;
680
+ if (ssl3_protocol_version(ssl) >= TLS1_3_VERSION) {
681
+ *out_mask_k = SSL_kGENERIC;
682
+ *out_mask_a = SSL_aGENERIC;
683
+ return;
684
+ }
698
685
 
699
- case -1:
700
- /* Connection rejected. */
701
- al = SSL_AD_HANDSHAKE_FAILURE;
702
- OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED);
703
- goto f_err;
686
+ uint32_t mask_k = 0;
687
+ uint32_t mask_a = 0;
704
688
 
705
- default:
706
- /* fallthrough */;
707
- }
689
+ if (ssl_has_certificate(ssl)) {
690
+ int type = ssl_private_key_type(ssl);
691
+ if (type == NID_rsaEncryption) {
692
+ mask_k |= SSL_kRSA;
693
+ mask_a |= SSL_aRSA;
694
+ } else if (ssl_is_ecdsa_key_type(type)) {
695
+ mask_a |= SSL_aECDSA;
708
696
  }
709
697
  }
710
698
 
711
- /* Negotiate the protocol version if we have not done so yet. */
712
- if (!ssl->s3->have_version) {
713
- if (!negotiate_version(ssl, &al, &client_hello)) {
714
- goto f_err;
715
- }
699
+ if (ssl->cert->dh_tmp != NULL || ssl->cert->dh_tmp_cb != NULL) {
700
+ mask_k |= SSL_kDHE;
701
+ }
716
702
 
717
- if (ssl3_protocol_version(ssl) >= TLS1_3_VERSION) {
718
- ssl->state = SSL_ST_TLS13;
719
- return 1;
720
- }
703
+ /* Check for a shared group to consider ECDHE ciphers. */
704
+ uint16_t unused;
705
+ if (tls1_get_shared_group(hs, &unused)) {
706
+ mask_k |= SSL_kECDHE;
721
707
  }
722
708
 
723
- if (ssl->state == SSL3_ST_SR_CLNT_HELLO_C) {
724
- /* Load the client random. */
725
- if (client_hello.random_len != SSL3_RANDOM_SIZE) {
726
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
727
- return -1;
709
+ /* PSK requires a server callback. */
710
+ if (ssl->psk_server_callback != NULL) {
711
+ mask_k |= SSL_kPSK;
712
+ mask_a |= SSL_aPSK;
713
+ }
714
+
715
+ *out_mask_k = mask_k;
716
+ *out_mask_a = mask_a;
717
+ }
718
+
719
+ static const SSL_CIPHER *ssl3_choose_cipher(
720
+ SSL_HANDSHAKE *hs, const SSL_CLIENT_HELLO *client_hello,
721
+ const struct ssl_cipher_preference_list_st *server_pref) {
722
+ SSL *const ssl = hs->ssl;
723
+ const SSL_CIPHER *c, *ret = NULL;
724
+ STACK_OF(SSL_CIPHER) *srvr = server_pref->ciphers, *prio, *allow;
725
+ int ok;
726
+ size_t cipher_index;
727
+ uint32_t alg_k, alg_a, mask_k, mask_a;
728
+ /* in_group_flags will either be NULL, or will point to an array of bytes
729
+ * which indicate equal-preference groups in the |prio| stack. See the
730
+ * comment about |in_group_flags| in the |ssl_cipher_preference_list_st|
731
+ * struct. */
732
+ const uint8_t *in_group_flags;
733
+ /* group_min contains the minimal index so far found in a group, or -1 if no
734
+ * such value exists yet. */
735
+ int group_min = -1;
736
+
737
+ STACK_OF(SSL_CIPHER) *clnt = ssl_parse_client_cipher_list(client_hello);
738
+ if (clnt == NULL) {
739
+ return NULL;
740
+ }
741
+
742
+ if (ssl->options & SSL_OP_CIPHER_SERVER_PREFERENCE) {
743
+ prio = srvr;
744
+ in_group_flags = server_pref->in_group_flags;
745
+ allow = clnt;
746
+ } else {
747
+ prio = clnt;
748
+ in_group_flags = NULL;
749
+ allow = srvr;
750
+ }
751
+
752
+ ssl_get_compatible_server_ciphers(hs, &mask_k, &mask_a);
753
+
754
+ for (size_t i = 0; i < sk_SSL_CIPHER_num(prio); i++) {
755
+ c = sk_SSL_CIPHER_value(prio, i);
756
+
757
+ ok = 1;
758
+
759
+ /* Check the TLS version. */
760
+ if (SSL_CIPHER_get_min_version(c) > ssl3_protocol_version(ssl) ||
761
+ SSL_CIPHER_get_max_version(c) < ssl3_protocol_version(ssl)) {
762
+ ok = 0;
728
763
  }
729
- memcpy(ssl->s3->client_random, client_hello.random,
730
- client_hello.random_len);
731
764
 
732
- /* Determine whether we are doing session resumption. */
733
- int send_new_ticket = 0;
734
- switch (
735
- ssl_get_prev_session(ssl, &session, &send_new_ticket, &client_hello)) {
736
- case ssl_session_success:
765
+ alg_k = c->algorithm_mkey;
766
+ alg_a = c->algorithm_auth;
767
+
768
+ ok = ok && (alg_k & mask_k) && (alg_a & mask_a);
769
+
770
+ if (ok && sk_SSL_CIPHER_find(allow, &cipher_index, c)) {
771
+ if (in_group_flags != NULL && in_group_flags[i] == 1) {
772
+ /* This element of |prio| is in a group. Update the minimum index found
773
+ * so far and continue looking. */
774
+ if (group_min == -1 || (size_t)group_min > cipher_index) {
775
+ group_min = cipher_index;
776
+ }
777
+ } else {
778
+ if (group_min != -1 && (size_t)group_min < cipher_index) {
779
+ cipher_index = group_min;
780
+ }
781
+ ret = sk_SSL_CIPHER_value(allow, cipher_index);
737
782
  break;
738
- case ssl_session_error:
739
- goto err;
740
- case ssl_session_retry:
741
- ssl->rwstate = SSL_PENDING_SESSION;
742
- goto err;
743
- }
744
- ssl->tlsext_ticket_expected = send_new_ticket;
745
-
746
- /* The EMS state is needed when making the resumption decision, but
747
- * extensions are not normally parsed until later. This detects the EMS
748
- * extension for the resumption decision and it's checked against the result
749
- * of the normal parse later in this function. */
750
- CBS ems;
751
- int have_extended_master_secret =
752
- ssl->version != SSL3_VERSION &&
753
- ssl_early_callback_get_extension(&client_hello, &ems,
754
- TLSEXT_TYPE_extended_master_secret) &&
755
- CBS_len(&ems) == 0;
756
-
757
- int has_session = 0;
758
- if (session != NULL) {
759
- if (session->extended_master_secret &&
760
- !have_extended_master_secret) {
761
- /* A ClientHello without EMS that attempts to resume a session with EMS
762
- * is fatal to the connection. */
763
- al = SSL_AD_HANDSHAKE_FAILURE;
764
- OPENSSL_PUT_ERROR(SSL, SSL_R_RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION);
765
- goto f_err;
766
783
  }
784
+ }
767
785
 
768
- has_session =
769
- /* Only resume if the session's version matches the negotiated
770
- * version: most clients do not accept a mismatch. */
771
- ssl->version == session->ssl_version &&
772
- /* If the client offers the EMS extension, but the previous session
773
- * didn't use it, then negotiate a new session. */
774
- have_extended_master_secret == session->extended_master_secret;
786
+ if (in_group_flags != NULL && in_group_flags[i] == 0 && group_min != -1) {
787
+ /* We are about to leave a group, but we found a match in it, so that's
788
+ * our answer. */
789
+ ret = sk_SSL_CIPHER_value(allow, group_min);
790
+ break;
775
791
  }
792
+ }
776
793
 
777
- if (has_session) {
778
- /* Use the old session. */
779
- ssl->session = session;
780
- session = NULL;
781
- ssl->s3->session_reused = 1;
782
- } else {
783
- ssl_set_session(ssl, NULL);
784
- if (!ssl_get_new_session(ssl, 1 /* server */)) {
785
- goto err;
786
- }
794
+ sk_SSL_CIPHER_free(clnt);
795
+ return ret;
796
+ }
787
797
 
788
- /* Clear the session ID if we want the session to be single-use. */
789
- if (!(ssl->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) {
790
- ssl->s3->new_session->session_id_length = 0;
791
- }
792
- }
798
+ static int ssl3_process_client_hello(SSL_HANDSHAKE *hs) {
799
+ SSL *const ssl = hs->ssl;
800
+ if (!ssl_check_message_type(ssl, SSL3_MT_CLIENT_HELLO)) {
801
+ return -1;
802
+ }
793
803
 
794
- if (ssl->ctx->dos_protection_cb != NULL &&
795
- ssl->ctx->dos_protection_cb(&client_hello) == 0) {
796
- /* Connection rejected for DOS reasons. */
797
- al = SSL_AD_INTERNAL_ERROR;
798
- OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED);
799
- goto f_err;
804
+ SSL_CLIENT_HELLO client_hello;
805
+ if (!ssl_client_hello_init(ssl, &client_hello, ssl->init_msg,
806
+ ssl->init_num)) {
807
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
808
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
809
+ return -1;
810
+ }
811
+
812
+ /* Run the early callback. */
813
+ if (ssl->ctx->select_certificate_cb != NULL) {
814
+ switch (ssl->ctx->select_certificate_cb(&client_hello)) {
815
+ case 0:
816
+ ssl->rwstate = SSL_CERTIFICATE_SELECTION_PENDING;
817
+ return -1;
818
+
819
+ case -1:
820
+ /* Connection rejected. */
821
+ OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED);
822
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
823
+ return -1;
824
+
825
+ default:
826
+ /* fallthrough */;
800
827
  }
828
+ }
801
829
 
802
- /* Only null compression is supported. */
803
- if (memchr(client_hello.compression_methods, 0,
804
- client_hello.compression_methods_len) == NULL) {
805
- al = SSL_AD_ILLEGAL_PARAMETER;
806
- OPENSSL_PUT_ERROR(SSL, SSL_R_NO_COMPRESSION_SPECIFIED);
807
- goto f_err;
830
+ uint8_t alert = SSL_AD_DECODE_ERROR;
831
+ if (!negotiate_version(hs, &alert, &client_hello)) {
832
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
833
+ return -1;
834
+ }
835
+
836
+ /* Load the client random. */
837
+ if (client_hello.random_len != SSL3_RANDOM_SIZE) {
838
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
839
+ return -1;
840
+ }
841
+ OPENSSL_memcpy(ssl->s3->client_random, client_hello.random,
842
+ client_hello.random_len);
843
+
844
+ /* Only null compression is supported. TLS 1.3 further requires the peer
845
+ * advertise no other compression. */
846
+ if (OPENSSL_memchr(client_hello.compression_methods, 0,
847
+ client_hello.compression_methods_len) == NULL ||
848
+ (ssl3_protocol_version(ssl) >= TLS1_3_VERSION &&
849
+ client_hello.compression_methods_len != 1)) {
850
+ OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_COMPRESSION_LIST);
851
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
852
+ return -1;
853
+ }
854
+
855
+ /* TLS extensions. */
856
+ if (!ssl_parse_clienthello_tlsext(hs, &client_hello)) {
857
+ OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT);
858
+ return -1;
859
+ }
860
+
861
+ return 1;
862
+ }
863
+
864
+ static int ssl3_select_certificate(SSL_HANDSHAKE *hs) {
865
+ SSL *const ssl = hs->ssl;
866
+ /* Call |cert_cb| to update server certificates if required. */
867
+ if (ssl->cert->cert_cb != NULL) {
868
+ int rv = ssl->cert->cert_cb(ssl, ssl->cert->cert_cb_arg);
869
+ if (rv == 0) {
870
+ OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_CB_ERROR);
871
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
872
+ return -1;
873
+ }
874
+ if (rv < 0) {
875
+ ssl->rwstate = SSL_X509_LOOKUP;
876
+ return -1;
808
877
  }
878
+ }
879
+
880
+ if (!ssl_auto_chain_if_needed(ssl)) {
881
+ return -1;
882
+ }
883
+
884
+ if (ssl3_protocol_version(ssl) >= TLS1_3_VERSION) {
885
+ /* Jump to the TLS 1.3 state machine. */
886
+ hs->state = SSL_ST_TLS13;
887
+ hs->do_tls13_handshake = tls13_server_handshake;
888
+ return 1;
889
+ }
890
+
891
+ SSL_CLIENT_HELLO client_hello;
892
+ if (!ssl_client_hello_init(ssl, &client_hello, ssl->init_msg,
893
+ ssl->init_num)) {
894
+ return -1;
895
+ }
896
+
897
+ /* Negotiate the cipher suite. This must be done after |cert_cb| so the
898
+ * certificate is finalized. */
899
+ hs->new_cipher =
900
+ ssl3_choose_cipher(hs, &client_hello, ssl_get_cipher_preferences(ssl));
901
+ if (hs->new_cipher == NULL) {
902
+ OPENSSL_PUT_ERROR(SSL, SSL_R_NO_SHARED_CIPHER);
903
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
904
+ return -1;
905
+ }
906
+
907
+ return 1;
908
+ }
809
909
 
810
- /* TLS extensions. */
811
- if (!ssl_parse_clienthello_tlsext(ssl, &client_hello)) {
812
- OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT);
910
+ static int ssl3_select_parameters(SSL_HANDSHAKE *hs) {
911
+ SSL *const ssl = hs->ssl;
912
+ uint8_t al = SSL_AD_INTERNAL_ERROR;
913
+ int ret = -1;
914
+ SSL_SESSION *session = NULL;
915
+
916
+ SSL_CLIENT_HELLO client_hello;
917
+ if (!ssl_client_hello_init(ssl, &client_hello, ssl->init_msg,
918
+ ssl->init_num)) {
919
+ return -1;
920
+ }
921
+
922
+ /* Determine whether we are doing session resumption. */
923
+ int tickets_supported = 0, renew_ticket = 0;
924
+ switch (ssl_get_prev_session(ssl, &session, &tickets_supported, &renew_ticket,
925
+ &client_hello)) {
926
+ case ssl_session_success:
927
+ break;
928
+ case ssl_session_error:
813
929
  goto err;
814
- }
930
+ case ssl_session_retry:
931
+ ssl->rwstate = SSL_PENDING_SESSION;
932
+ goto err;
933
+ }
815
934
 
816
- if (have_extended_master_secret != ssl->s3->tmp.extended_master_secret) {
817
- al = SSL_AD_INTERNAL_ERROR;
818
- OPENSSL_PUT_ERROR(SSL, SSL_R_EMS_STATE_INCONSISTENT);
935
+ if (session != NULL) {
936
+ if (session->extended_master_secret && !hs->extended_master_secret) {
937
+ /* A ClientHello without EMS that attempts to resume a session with EMS
938
+ * is fatal to the connection. */
939
+ al = SSL_AD_HANDSHAKE_FAILURE;
940
+ OPENSSL_PUT_ERROR(SSL, SSL_R_RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION);
819
941
  goto f_err;
820
942
  }
821
943
 
822
- ssl->state = SSL3_ST_SR_CLNT_HELLO_D;
944
+ if (!ssl_session_is_resumable(hs, session) ||
945
+ /* If the client offers the EMS extension, but the previous session
946
+ * didn't use it, then negotiate a new session. */
947
+ hs->extended_master_secret != session->extended_master_secret) {
948
+ SSL_SESSION_free(session);
949
+ session = NULL;
950
+ }
823
951
  }
824
952
 
825
- /* Determine the remaining connection parameters. This is a separate state so
826
- * |cert_cb| does not cause earlier logic to run multiple times. */
827
- assert(ssl->state == SSL3_ST_SR_CLNT_HELLO_D);
953
+ if (session != NULL) {
954
+ /* Use the old session. */
955
+ hs->ticket_expected = renew_ticket;
956
+ ssl->session = session;
957
+ session = NULL;
958
+ ssl->s3->session_reused = 1;
959
+ } else {
960
+ hs->ticket_expected = tickets_supported;
961
+ ssl_set_session(ssl, NULL);
962
+ if (!ssl_get_new_session(hs, 1 /* server */)) {
963
+ goto err;
964
+ }
828
965
 
829
- if (ssl->session != NULL) {
830
- /* Check that the cipher is in the list. */
831
- if (!ssl_client_cipher_list_contains_cipher(
832
- &client_hello, (uint16_t)ssl->session->cipher->id)) {
833
- al = SSL_AD_ILLEGAL_PARAMETER;
834
- OPENSSL_PUT_ERROR(SSL, SSL_R_REQUIRED_CIPHER_MISSING);
835
- goto f_err;
966
+ /* Clear the session ID if we want the session to be single-use. */
967
+ if (!(ssl->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) {
968
+ hs->new_session->session_id_length = 0;
836
969
  }
970
+ }
837
971
 
838
- ssl->s3->tmp.new_cipher = ssl->session->cipher;
839
- ssl->s3->tmp.cert_request = 0;
840
- } else {
841
- /* Call |cert_cb| to update server certificates if required. */
842
- if (ssl->cert->cert_cb != NULL) {
843
- int rv = ssl->cert->cert_cb(ssl, ssl->cert->cert_cb_arg);
844
- if (rv == 0) {
972
+ if (ssl->ctx->dos_protection_cb != NULL &&
973
+ ssl->ctx->dos_protection_cb(&client_hello) == 0) {
974
+ /* Connection rejected for DOS reasons. */
975
+ al = SSL_AD_INTERNAL_ERROR;
976
+ OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED);
977
+ goto f_err;
978
+ }
979
+
980
+ if (ssl->session == NULL) {
981
+ hs->new_session->cipher = hs->new_cipher;
982
+
983
+ /* On new sessions, stash the SNI value in the session. */
984
+ if (hs->hostname != NULL) {
985
+ OPENSSL_free(hs->new_session->tlsext_hostname);
986
+ hs->new_session->tlsext_hostname = BUF_strdup(hs->hostname);
987
+ if (hs->new_session->tlsext_hostname == NULL) {
845
988
  al = SSL_AD_INTERNAL_ERROR;
846
- OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_CB_ERROR);
847
989
  goto f_err;
848
990
  }
849
- if (rv < 0) {
850
- ssl->rwstate = SSL_X509_LOOKUP;
851
- goto err;
852
- }
853
991
  }
854
992
 
855
- const SSL_CIPHER *c =
856
- ssl3_choose_cipher(ssl, &client_hello, ssl_get_cipher_preferences(ssl));
857
- if (c == NULL) {
858
- al = SSL_AD_HANDSHAKE_FAILURE;
859
- OPENSSL_PUT_ERROR(SSL, SSL_R_NO_SHARED_CIPHER);
860
- goto f_err;
861
- }
862
-
863
- ssl->s3->new_session->cipher = c;
864
- ssl->s3->tmp.new_cipher = c;
865
-
866
993
  /* Determine whether to request a client certificate. */
867
- ssl->s3->tmp.cert_request = !!(ssl->verify_mode & SSL_VERIFY_PEER);
994
+ hs->cert_request = !!(ssl->verify_mode & SSL_VERIFY_PEER);
868
995
  /* Only request a certificate if Channel ID isn't negotiated. */
869
996
  if ((ssl->verify_mode & SSL_VERIFY_PEER_IF_NO_OBC) &&
870
997
  ssl->s3->tlsext_channel_id_valid) {
871
- ssl->s3->tmp.cert_request = 0;
998
+ hs->cert_request = 0;
872
999
  }
873
1000
  /* CertificateRequest may only be sent in certificate-based ciphers. */
874
- if (!ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
875
- ssl->s3->tmp.cert_request = 0;
1001
+ if (!ssl_cipher_uses_certificate_auth(hs->new_cipher)) {
1002
+ hs->cert_request = 0;
876
1003
  }
877
1004
 
878
- if (!ssl->s3->tmp.cert_request) {
1005
+ if (!hs->cert_request) {
879
1006
  /* OpenSSL returns X509_V_OK when no certificates are requested. This is
880
1007
  * classed by them as a bug, but it's assumed by at least NGINX. */
881
- ssl->s3->new_session->verify_result = X509_V_OK;
1008
+ hs->new_session->verify_result = X509_V_OK;
882
1009
  }
883
1010
  }
884
1011
 
885
- /* Now that the cipher is known, initialize the handshake hash. */
886
- if (!ssl3_init_handshake_hash(ssl)) {
1012
+ /* HTTP/2 negotiation depends on the cipher suite, so ALPN negotiation was
1013
+ * deferred. Complete it now. */
1014
+ if (!ssl_negotiate_alpn(hs, &al, &client_hello)) {
1015
+ goto f_err;
1016
+ }
1017
+
1018
+ /* Now that all parameters are known, initialize the handshake hash and hash
1019
+ * the ClientHello. */
1020
+ if (!SSL_TRANSCRIPT_init_hash(&hs->transcript, ssl3_protocol_version(ssl),
1021
+ hs->new_cipher->algorithm_prf) ||
1022
+ !ssl_hash_current_message(hs)) {
887
1023
  goto f_err;
888
1024
  }
889
1025
 
890
1026
  /* Release the handshake buffer if client authentication isn't required. */
891
- if (!ssl->s3->tmp.cert_request) {
892
- ssl3_free_handshake_buffer(ssl);
1027
+ if (!hs->cert_request) {
1028
+ SSL_TRANSCRIPT_free_buffer(&hs->transcript);
893
1029
  }
894
1030
 
895
1031
  ret = 1;
@@ -904,17 +1040,13 @@ err:
904
1040
  return ret;
905
1041
  }
906
1042
 
907
- static int ssl3_send_server_hello(SSL *ssl) {
908
- if (ssl->state == SSL3_ST_SW_SRVR_HELLO_B) {
909
- return ssl->method->write_message(ssl);
910
- }
911
-
912
- assert(ssl->state == SSL3_ST_SW_SRVR_HELLO_A);
1043
+ static int ssl3_send_server_hello(SSL_HANDSHAKE *hs) {
1044
+ SSL *const ssl = hs->ssl;
913
1045
 
914
1046
  /* We only accept ChannelIDs on connections with ECDHE in order to avoid a
915
1047
  * known attack while we fix ChannelID itself. */
916
1048
  if (ssl->s3->tlsext_channel_id_valid &&
917
- (ssl->s3->tmp.new_cipher->algorithm_mkey & SSL_kECDHE) == 0) {
1049
+ (hs->new_cipher->algorithm_mkey & SSL_kECDHE) == 0) {
918
1050
  ssl->s3->tlsext_channel_id_valid = 0;
919
1051
  }
920
1052
 
@@ -939,7 +1071,7 @@ static int ssl3_send_server_hello(SSL *ssl) {
939
1071
  /* TODO(davidben): Implement the TLS 1.1 and 1.2 downgrade sentinels once TLS
940
1072
  * 1.3 is finalized and we are not implementing a draft version. */
941
1073
 
942
- const SSL_SESSION *session = ssl->s3->new_session;
1074
+ const SSL_SESSION *session = hs->new_session;
943
1075
  if (ssl->session != NULL) {
944
1076
  session = ssl->session;
945
1077
  }
@@ -951,70 +1083,59 @@ static int ssl3_send_server_hello(SSL *ssl) {
951
1083
  !CBB_add_u8_length_prefixed(&body, &session_id) ||
952
1084
  !CBB_add_bytes(&session_id, session->session_id,
953
1085
  session->session_id_length) ||
954
- !CBB_add_u16(&body, ssl_cipher_get_value(ssl->s3->tmp.new_cipher)) ||
1086
+ !CBB_add_u16(&body, ssl_cipher_get_value(hs->new_cipher)) ||
955
1087
  !CBB_add_u8(&body, 0 /* no compression */) ||
956
- !ssl_add_serverhello_tlsext(ssl, &body) ||
957
- !ssl->method->finish_message(ssl, &cbb)) {
1088
+ !ssl_add_serverhello_tlsext(hs, &body) ||
1089
+ !ssl_add_message_cbb(ssl, &cbb)) {
958
1090
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
959
1091
  CBB_cleanup(&cbb);
960
1092
  return -1;
961
1093
  }
962
1094
 
963
- ssl->state = SSL3_ST_SW_SRVR_HELLO_B;
964
- return ssl->method->write_message(ssl);
1095
+ return 1;
965
1096
  }
966
1097
 
967
- static int ssl3_send_server_certificate(SSL *ssl) {
968
- if (ssl->state == SSL3_ST_SW_CERT_B) {
969
- return ssl->method->write_message(ssl);
970
- }
971
-
1098
+ static int ssl3_send_server_certificate(SSL_HANDSHAKE *hs) {
1099
+ SSL *const ssl = hs->ssl;
972
1100
  if (!ssl_has_certificate(ssl)) {
973
1101
  OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATE_SET);
974
- return 0;
1102
+ return -1;
975
1103
  }
976
1104
 
977
1105
  if (!ssl3_output_cert_chain(ssl)) {
978
- return 0;
1106
+ return -1;
979
1107
  }
980
- ssl->state = SSL3_ST_SW_CERT_B;
981
- return ssl->method->write_message(ssl);
1108
+ return 1;
982
1109
  }
983
1110
 
984
- static int ssl3_send_certificate_status(SSL *ssl) {
985
- if (ssl->state == SSL3_ST_SW_CERT_STATUS_B) {
986
- return ssl->method->write_message(ssl);
987
- }
988
-
1111
+ static int ssl3_send_certificate_status(SSL_HANDSHAKE *hs) {
1112
+ SSL *const ssl = hs->ssl;
989
1113
  CBB cbb, body, ocsp_response;
990
1114
  if (!ssl->method->init_message(ssl, &cbb, &body,
991
1115
  SSL3_MT_CERTIFICATE_STATUS) ||
992
1116
  !CBB_add_u8(&body, TLSEXT_STATUSTYPE_ocsp) ||
993
1117
  !CBB_add_u24_length_prefixed(&body, &ocsp_response) ||
994
- !CBB_add_bytes(&ocsp_response, ssl->ctx->ocsp_response,
995
- ssl->ctx->ocsp_response_length) ||
996
- !ssl->method->finish_message(ssl, &cbb)) {
1118
+ !CBB_add_bytes(&ocsp_response,
1119
+ CRYPTO_BUFFER_data(ssl->cert->ocsp_response),
1120
+ CRYPTO_BUFFER_len(ssl->cert->ocsp_response)) ||
1121
+ !ssl_add_message_cbb(ssl, &cbb)) {
997
1122
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
998
1123
  CBB_cleanup(&cbb);
999
1124
  return -1;
1000
1125
  }
1001
1126
 
1002
- ssl->state = SSL3_ST_SW_CERT_STATUS_B;
1003
- return ssl->method->write_message(ssl);
1127
+ return 1;
1004
1128
  }
1005
1129
 
1006
- static int ssl3_send_server_key_exchange(SSL *ssl) {
1007
- if (ssl->state == SSL3_ST_SW_KEY_EXCH_C) {
1008
- return ssl->method->write_message(ssl);
1009
- }
1010
-
1130
+ static int ssl3_send_server_key_exchange(SSL_HANDSHAKE *hs) {
1131
+ SSL *const ssl = hs->ssl;
1011
1132
  CBB cbb, child;
1012
1133
  CBB_zero(&cbb);
1013
1134
 
1014
1135
  /* Put together the parameters. */
1015
- if (ssl->state == SSL3_ST_SW_KEY_EXCH_A) {
1016
- uint32_t alg_k = ssl->s3->tmp.new_cipher->algorithm_mkey;
1017
- uint32_t alg_a = ssl->s3->tmp.new_cipher->algorithm_auth;
1136
+ if (hs->state == SSL3_ST_SW_KEY_EXCH_A) {
1137
+ uint32_t alg_k = hs->new_cipher->algorithm_mkey;
1138
+ uint32_t alg_a = hs->new_cipher->algorithm_auth;
1018
1139
 
1019
1140
  /* Pre-allocate enough room to comfortably fit an ECDHE public key. */
1020
1141
  if (!CBB_init(&cbb, 128)) {
@@ -1043,7 +1164,6 @@ static int ssl3_send_server_key_exchange(SSL *ssl) {
1043
1164
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1044
1165
  goto err;
1045
1166
  }
1046
- ssl->s3->new_session->key_exchange_info = DH_num_bits(params);
1047
1167
 
1048
1168
  /* Set up DH, generate a key, and emit the public half. */
1049
1169
  DH *dh = DHparams_dup(params);
@@ -1051,64 +1171,52 @@ static int ssl3_send_server_key_exchange(SSL *ssl) {
1051
1171
  goto err;
1052
1172
  }
1053
1173
 
1054
- SSL_ECDH_CTX_init_for_dhe(&ssl->s3->tmp.ecdh_ctx, dh);
1174
+ SSL_ECDH_CTX_init_for_dhe(&hs->ecdh_ctx, dh);
1055
1175
  if (!CBB_add_u16_length_prefixed(&cbb, &child) ||
1056
1176
  !BN_bn2cbb_padded(&child, BN_num_bytes(params->p), params->p) ||
1057
1177
  !CBB_add_u16_length_prefixed(&cbb, &child) ||
1058
1178
  !BN_bn2cbb_padded(&child, BN_num_bytes(params->g), params->g) ||
1059
1179
  !CBB_add_u16_length_prefixed(&cbb, &child) ||
1060
- !SSL_ECDH_CTX_offer(&ssl->s3->tmp.ecdh_ctx, &child)) {
1180
+ !SSL_ECDH_CTX_offer(&hs->ecdh_ctx, &child)) {
1061
1181
  goto err;
1062
1182
  }
1063
1183
  } else if (alg_k & SSL_kECDHE) {
1064
1184
  /* Determine the group to use. */
1065
1185
  uint16_t group_id;
1066
- if (!tls1_get_shared_group(ssl, &group_id)) {
1186
+ if (!tls1_get_shared_group(hs, &group_id)) {
1067
1187
  OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_TMP_ECDH_KEY);
1068
1188
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1069
1189
  goto err;
1070
1190
  }
1071
- ssl->s3->new_session->key_exchange_info = group_id;
1191
+ hs->new_session->group_id = group_id;
1072
1192
 
1073
1193
  /* Set up ECDH, generate a key, and emit the public half. */
1074
- if (!SSL_ECDH_CTX_init(&ssl->s3->tmp.ecdh_ctx, group_id) ||
1194
+ if (!SSL_ECDH_CTX_init(&hs->ecdh_ctx, group_id) ||
1075
1195
  !CBB_add_u8(&cbb, NAMED_CURVE_TYPE) ||
1076
1196
  !CBB_add_u16(&cbb, group_id) ||
1077
1197
  !CBB_add_u8_length_prefixed(&cbb, &child) ||
1078
- !SSL_ECDH_CTX_offer(&ssl->s3->tmp.ecdh_ctx, &child)) {
1079
- goto err;
1080
- }
1081
- } else if (alg_k & SSL_kCECPQ1) {
1082
- SSL_ECDH_CTX_init_for_cecpq1(&ssl->s3->tmp.ecdh_ctx);
1083
- if (!CBB_add_u16_length_prefixed(&cbb, &child) ||
1084
- !SSL_ECDH_CTX_offer(&ssl->s3->tmp.ecdh_ctx, &child)) {
1198
+ !SSL_ECDH_CTX_offer(&hs->ecdh_ctx, &child)) {
1085
1199
  goto err;
1086
1200
  }
1087
1201
  } else {
1088
1202
  assert(alg_k & SSL_kPSK);
1089
1203
  }
1090
1204
 
1091
- size_t len;
1092
- if (!CBB_finish(&cbb, &ssl->s3->tmp.server_params, &len) ||
1093
- len > 0xffffffffu) {
1094
- OPENSSL_free(ssl->s3->tmp.server_params);
1095
- ssl->s3->tmp.server_params = NULL;
1205
+ if (!CBB_finish(&cbb, &hs->server_params, &hs->server_params_len)) {
1096
1206
  goto err;
1097
1207
  }
1098
- ssl->s3->tmp.server_params_len = (uint32_t)len;
1099
1208
  }
1100
1209
 
1101
1210
  /* Assemble the message. */
1102
1211
  CBB body;
1103
1212
  if (!ssl->method->init_message(ssl, &cbb, &body,
1104
1213
  SSL3_MT_SERVER_KEY_EXCHANGE) ||
1105
- !CBB_add_bytes(&body, ssl->s3->tmp.server_params,
1106
- ssl->s3->tmp.server_params_len)) {
1214
+ !CBB_add_bytes(&body, hs->server_params, hs->server_params_len)) {
1107
1215
  goto err;
1108
1216
  }
1109
1217
 
1110
1218
  /* Add a signature. */
1111
- if (ssl_cipher_uses_certificate_auth(ssl->s3->tmp.new_cipher)) {
1219
+ if (ssl_cipher_uses_certificate_auth(hs->new_cipher)) {
1112
1220
  if (!ssl_has_private_key(ssl)) {
1113
1221
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
1114
1222
  goto err;
@@ -1116,7 +1224,7 @@ static int ssl3_send_server_key_exchange(SSL *ssl) {
1116
1224
 
1117
1225
  /* Determine the signature algorithm. */
1118
1226
  uint16_t signature_algorithm;
1119
- if (!tls1_choose_signature_algorithm(ssl, &signature_algorithm)) {
1227
+ if (!tls1_choose_signature_algorithm(hs, &signature_algorithm)) {
1120
1228
  goto err;
1121
1229
  }
1122
1230
  if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
@@ -1137,16 +1245,18 @@ static int ssl3_send_server_key_exchange(SSL *ssl) {
1137
1245
 
1138
1246
  size_t sig_len;
1139
1247
  enum ssl_private_key_result_t sign_result;
1140
- if (ssl->state == SSL3_ST_SW_KEY_EXCH_A) {
1248
+ if (hs->state == SSL3_ST_SW_KEY_EXCH_A) {
1141
1249
  CBB transcript;
1142
1250
  uint8_t *transcript_data;
1143
1251
  size_t transcript_len;
1144
1252
  if (!CBB_init(&transcript,
1145
- 2*SSL3_RANDOM_SIZE + ssl->s3->tmp.server_params_len) ||
1146
- !CBB_add_bytes(&transcript, ssl->s3->client_random, SSL3_RANDOM_SIZE) ||
1147
- !CBB_add_bytes(&transcript, ssl->s3->server_random, SSL3_RANDOM_SIZE) ||
1148
- !CBB_add_bytes(&transcript, ssl->s3->tmp.server_params,
1149
- ssl->s3->tmp.server_params_len) ||
1253
+ 2 * SSL3_RANDOM_SIZE + hs->server_params_len) ||
1254
+ !CBB_add_bytes(&transcript, ssl->s3->client_random,
1255
+ SSL3_RANDOM_SIZE) ||
1256
+ !CBB_add_bytes(&transcript, ssl->s3->server_random,
1257
+ SSL3_RANDOM_SIZE) ||
1258
+ !CBB_add_bytes(&transcript, hs->server_params,
1259
+ hs->server_params_len) ||
1150
1260
  !CBB_finish(&transcript, &transcript_data, &transcript_len)) {
1151
1261
  CBB_cleanup(&transcript);
1152
1262
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
@@ -1159,7 +1269,7 @@ static int ssl3_send_server_key_exchange(SSL *ssl) {
1159
1269
  transcript_len);
1160
1270
  OPENSSL_free(transcript_data);
1161
1271
  } else {
1162
- assert(ssl->state == SSL3_ST_SW_KEY_EXCH_B);
1272
+ assert(hs->state == SSL3_ST_SW_KEY_EXCH_B);
1163
1273
  sign_result = ssl_private_key_complete(ssl, ptr, &sig_len, max_sig_len);
1164
1274
  }
1165
1275
 
@@ -1173,21 +1283,20 @@ static int ssl3_send_server_key_exchange(SSL *ssl) {
1173
1283
  goto err;
1174
1284
  case ssl_private_key_retry:
1175
1285
  ssl->rwstate = SSL_PRIVATE_KEY_OPERATION;
1176
- ssl->state = SSL3_ST_SW_KEY_EXCH_B;
1286
+ hs->state = SSL3_ST_SW_KEY_EXCH_B;
1177
1287
  goto err;
1178
1288
  }
1179
1289
  }
1180
1290
 
1181
- if (!ssl->method->finish_message(ssl, &cbb)) {
1291
+ if (!ssl_add_message_cbb(ssl, &cbb)) {
1182
1292
  goto err;
1183
1293
  }
1184
1294
 
1185
- OPENSSL_free(ssl->s3->tmp.server_params);
1186
- ssl->s3->tmp.server_params = NULL;
1187
- ssl->s3->tmp.server_params_len = 0;
1295
+ OPENSSL_free(hs->server_params);
1296
+ hs->server_params = NULL;
1297
+ hs->server_params_len = 0;
1188
1298
 
1189
- ssl->state = SSL3_ST_SW_KEY_EXCH_C;
1190
- return ssl->method->write_message(ssl);
1299
+ return 1;
1191
1300
 
1192
1301
  err:
1193
1302
  CBB_cleanup(&cbb);
@@ -1199,8 +1308,8 @@ static int add_cert_types(SSL *ssl, CBB *cbb) {
1199
1308
  int have_rsa_sign = 0;
1200
1309
  int have_ecdsa_sign = 0;
1201
1310
  const uint16_t *sig_algs;
1202
- size_t sig_algs_len = tls12_get_psigalgs(ssl, &sig_algs);
1203
- for (size_t i = 0; i < sig_algs_len; i++) {
1311
+ size_t num_sig_algs = tls12_get_verify_sigalgs(ssl, &sig_algs);
1312
+ for (size_t i = 0; i < num_sig_algs; i++) {
1204
1313
  switch (sig_algs[i]) {
1205
1314
  case SSL_SIGN_RSA_PKCS1_SHA512:
1206
1315
  case SSL_SIGN_RSA_PKCS1_SHA384:
@@ -1232,11 +1341,8 @@ static int add_cert_types(SSL *ssl, CBB *cbb) {
1232
1341
  return 1;
1233
1342
  }
1234
1343
 
1235
- static int ssl3_send_certificate_request(SSL *ssl) {
1236
- if (ssl->state == SSL3_ST_SW_CERT_REQ_B) {
1237
- return ssl->method->write_message(ssl);
1238
- }
1239
-
1344
+ static int ssl3_send_certificate_request(SSL_HANDSHAKE *hs) {
1345
+ SSL *const ssl = hs->ssl;
1240
1346
  CBB cbb, body, cert_types, sigalgs_cbb;
1241
1347
  if (!ssl->method->init_message(ssl, &cbb, &body,
1242
1348
  SSL3_MT_CERTIFICATE_REQUEST) ||
@@ -1247,7 +1353,7 @@ static int ssl3_send_certificate_request(SSL *ssl) {
1247
1353
 
1248
1354
  if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
1249
1355
  const uint16_t *sigalgs;
1250
- size_t num_sigalgs = tls12_get_psigalgs(ssl, &sigalgs);
1356
+ size_t num_sigalgs = tls12_get_verify_sigalgs(ssl, &sigalgs);
1251
1357
  if (!CBB_add_u16_length_prefixed(&body, &sigalgs_cbb)) {
1252
1358
  goto err;
1253
1359
  }
@@ -1260,12 +1366,11 @@ static int ssl3_send_certificate_request(SSL *ssl) {
1260
1366
  }
1261
1367
 
1262
1368
  if (!ssl_add_client_CA_list(ssl, &body) ||
1263
- !ssl->method->finish_message(ssl, &cbb)) {
1369
+ !ssl_add_message_cbb(ssl, &cbb)) {
1264
1370
  goto err;
1265
1371
  }
1266
1372
 
1267
- ssl->state = SSL3_ST_SW_CERT_REQ_B;
1268
- return ssl->method->write_message(ssl);
1373
+ return 1;
1269
1374
 
1270
1375
  err:
1271
1376
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
@@ -1273,27 +1378,24 @@ err:
1273
1378
  return -1;
1274
1379
  }
1275
1380
 
1276
- static int ssl3_send_server_hello_done(SSL *ssl) {
1277
- if (ssl->state == SSL3_ST_SW_SRVR_DONE_B) {
1278
- return ssl->method->write_message(ssl);
1279
- }
1280
-
1381
+ static int ssl3_send_server_hello_done(SSL_HANDSHAKE *hs) {
1382
+ SSL *const ssl = hs->ssl;
1281
1383
  CBB cbb, body;
1282
1384
  if (!ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_SERVER_HELLO_DONE) ||
1283
- !ssl->method->finish_message(ssl, &cbb)) {
1385
+ !ssl_add_message_cbb(ssl, &cbb)) {
1284
1386
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1285
1387
  CBB_cleanup(&cbb);
1286
1388
  return -1;
1287
1389
  }
1288
1390
 
1289
- ssl->state = SSL3_ST_SW_SRVR_DONE_B;
1290
- return ssl->method->write_message(ssl);
1391
+ return 1;
1291
1392
  }
1292
1393
 
1293
- static int ssl3_get_client_certificate(SSL *ssl) {
1294
- assert(ssl->s3->tmp.cert_request);
1394
+ static int ssl3_get_client_certificate(SSL_HANDSHAKE *hs) {
1395
+ SSL *const ssl = hs->ssl;
1396
+ assert(hs->cert_request);
1295
1397
 
1296
- int msg_ret = ssl->method->ssl_get_message(ssl, -1, ssl_hash_message);
1398
+ int msg_ret = ssl->method->ssl_get_message(ssl);
1297
1399
  if (msg_ret <= 0) {
1298
1400
  return msg_ret;
1299
1401
  }
@@ -1311,7 +1413,7 @@ static int ssl3_get_client_certificate(SSL *ssl) {
1311
1413
 
1312
1414
  /* OpenSSL returns X509_V_OK when no certificates are received. This is
1313
1415
  * classed by them as a bug, but it's assumed by at least NGINX. */
1314
- ssl->s3->new_session->verify_result = X509_V_OK;
1416
+ hs->new_session->verify_result = X509_V_OK;
1315
1417
  ssl->s3->tmp.reuse_message = 1;
1316
1418
  return 1;
1317
1419
  }
@@ -1321,75 +1423,73 @@ static int ssl3_get_client_certificate(SSL *ssl) {
1321
1423
  return -1;
1322
1424
  }
1323
1425
 
1426
+ if (!ssl_hash_current_message(hs)) {
1427
+ return -1;
1428
+ }
1429
+
1324
1430
  CBS certificate_msg;
1325
1431
  CBS_init(&certificate_msg, ssl->init_msg, ssl->init_num);
1326
- uint8_t alert;
1327
- STACK_OF(X509) *chain = ssl_parse_cert_chain(
1328
- ssl, &alert, ssl->ctx->retain_only_sha256_of_client_certs
1329
- ? ssl->s3->new_session->peer_sha256
1330
- : NULL,
1331
- &certificate_msg);
1332
- if (chain == NULL) {
1432
+
1433
+ sk_CRYPTO_BUFFER_pop_free(hs->new_session->certs, CRYPTO_BUFFER_free);
1434
+ EVP_PKEY_free(hs->peer_pubkey);
1435
+ hs->peer_pubkey = NULL;
1436
+ uint8_t alert = SSL_AD_DECODE_ERROR;
1437
+ hs->new_session->certs = ssl_parse_cert_chain(
1438
+ &alert, &hs->peer_pubkey,
1439
+ ssl->retain_only_sha256_of_client_certs ? hs->new_session->peer_sha256
1440
+ : NULL,
1441
+ &certificate_msg, ssl->ctx->pool);
1442
+ if (hs->new_session->certs == NULL) {
1333
1443
  ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
1334
- goto err;
1444
+ return -1;
1335
1445
  }
1336
1446
 
1337
- if (CBS_len(&certificate_msg) != 0) {
1447
+ if (CBS_len(&certificate_msg) != 0 ||
1448
+ !ssl->ctx->x509_method->session_cache_objects(hs->new_session)) {
1338
1449
  OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1339
1450
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1340
- goto err;
1451
+ return -1;
1341
1452
  }
1342
1453
 
1343
- if (sk_X509_num(chain) == 0) {
1454
+ if (sk_CRYPTO_BUFFER_num(hs->new_session->certs) == 0) {
1344
1455
  /* No client certificate so the handshake buffer may be discarded. */
1345
- ssl3_free_handshake_buffer(ssl);
1456
+ SSL_TRANSCRIPT_free_buffer(&hs->transcript);
1346
1457
 
1347
1458
  /* In SSL 3.0, sending no certificate is signaled by omitting the
1348
1459
  * Certificate message. */
1349
1460
  if (ssl->version == SSL3_VERSION) {
1350
1461
  OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATES_RETURNED);
1351
1462
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1352
- goto err;
1463
+ return -1;
1353
1464
  }
1354
1465
 
1355
1466
  if (ssl->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT) {
1356
1467
  /* Fail for TLS only if we required a certificate */
1357
1468
  OPENSSL_PUT_ERROR(SSL, SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
1358
1469
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1359
- goto err;
1470
+ return -1;
1360
1471
  }
1361
1472
 
1362
1473
  /* OpenSSL returns X509_V_OK when no certificates are received. This is
1363
1474
  * classed by them as a bug, but it's assumed by at least NGINX. */
1364
- ssl->s3->new_session->verify_result = X509_V_OK;
1365
- } else {
1366
- /* The hash would have been filled in. */
1367
- if (ssl->ctx->retain_only_sha256_of_client_certs) {
1368
- ssl->s3->new_session->peer_sha256_valid = 1;
1369
- }
1370
-
1371
- if (!ssl_verify_cert_chain(ssl, &ssl->s3->new_session->verify_result,
1372
- chain)) {
1373
- goto err;
1374
- }
1475
+ hs->new_session->verify_result = X509_V_OK;
1476
+ return 1;
1375
1477
  }
1376
1478
 
1377
- X509_free(ssl->s3->new_session->peer);
1378
- ssl->s3->new_session->peer = sk_X509_shift(chain);
1379
-
1380
- sk_X509_pop_free(ssl->s3->new_session->cert_chain, X509_free);
1381
- ssl->s3->new_session->cert_chain = chain;
1382
- /* Inconsistency alert: cert_chain does *not* include the peer's own
1383
- * certificate, while we do include it in s3_clnt.c */
1479
+ /* The hash will have been filled in. */
1480
+ if (ssl->retain_only_sha256_of_client_certs) {
1481
+ hs->new_session->peer_sha256_valid = 1;
1482
+ }
1384
1483
 
1484
+ if (!ssl_verify_cert_chain(ssl, &hs->new_session->verify_result,
1485
+ hs->new_session->x509_chain)) {
1486
+ return -1;
1487
+ }
1385
1488
  return 1;
1386
-
1387
- err:
1388
- sk_X509_pop_free(chain, X509_free);
1389
- return -1;
1390
1489
  }
1391
1490
 
1392
- static int ssl3_get_client_key_exchange(SSL *ssl) {
1491
+ static int ssl3_get_client_key_exchange(SSL_HANDSHAKE *hs) {
1492
+ SSL *const ssl = hs->ssl;
1393
1493
  int al;
1394
1494
  CBS client_key_exchange;
1395
1495
  uint32_t alg_k;
@@ -1401,17 +1501,21 @@ static int ssl3_get_client_key_exchange(SSL *ssl) {
1401
1501
  unsigned psk_len = 0;
1402
1502
  uint8_t psk[PSK_MAX_PSK_LEN];
1403
1503
 
1404
- if (ssl->state == SSL3_ST_SR_KEY_EXCH_A) {
1405
- int ret = ssl->method->ssl_get_message(ssl, SSL3_MT_CLIENT_KEY_EXCHANGE,
1406
- ssl_hash_message);
1504
+ if (hs->state == SSL3_ST_SR_KEY_EXCH_A) {
1505
+ int ret = ssl->method->ssl_get_message(ssl);
1407
1506
  if (ret <= 0) {
1408
1507
  return ret;
1409
1508
  }
1509
+
1510
+ if (!ssl_check_message_type(ssl, SSL3_MT_CLIENT_KEY_EXCHANGE) ||
1511
+ !ssl_hash_current_message(hs)) {
1512
+ return -1;
1513
+ }
1410
1514
  }
1411
1515
 
1412
1516
  CBS_init(&client_key_exchange, ssl->init_msg, ssl->init_num);
1413
- alg_k = ssl->s3->tmp.new_cipher->algorithm_mkey;
1414
- alg_a = ssl->s3->tmp.new_cipher->algorithm_auth;
1517
+ alg_k = hs->new_cipher->algorithm_mkey;
1518
+ alg_a = hs->new_cipher->algorithm_auth;
1415
1519
 
1416
1520
  /* If using a PSK key exchange, prepare the pre-shared key. */
1417
1521
  if (alg_a & SSL_aPSK) {
@@ -1439,15 +1543,15 @@ static int ssl3_get_client_key_exchange(SSL *ssl) {
1439
1543
  goto f_err;
1440
1544
  }
1441
1545
 
1442
- if (!CBS_strdup(&psk_identity, &ssl->s3->new_session->psk_identity)) {
1546
+ if (!CBS_strdup(&psk_identity, &hs->new_session->psk_identity)) {
1443
1547
  al = SSL_AD_INTERNAL_ERROR;
1444
1548
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1445
1549
  goto f_err;
1446
1550
  }
1447
1551
 
1448
1552
  /* Look up the key for the identity. */
1449
- psk_len = ssl->psk_server_callback(ssl, ssl->s3->new_session->psk_identity,
1450
- psk, sizeof(psk));
1553
+ psk_len = ssl->psk_server_callback(ssl, hs->new_session->psk_identity, psk,
1554
+ sizeof(psk));
1451
1555
  if (psk_len > PSK_MAX_PSK_LEN) {
1452
1556
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1453
1557
  al = SSL_AD_INTERNAL_ERROR;
@@ -1473,7 +1577,7 @@ static int ssl3_get_client_key_exchange(SSL *ssl) {
1473
1577
 
1474
1578
  enum ssl_private_key_result_t decrypt_result;
1475
1579
  size_t decrypt_len;
1476
- if (ssl->state == SSL3_ST_SR_KEY_EXCH_A) {
1580
+ if (hs->state == SSL3_ST_SR_KEY_EXCH_A) {
1477
1581
  if (!ssl_has_private_key(ssl) ||
1478
1582
  ssl_private_key_type(ssl) != NID_rsaEncryption) {
1479
1583
  al = SSL_AD_HANDSHAKE_FAILURE;
@@ -1501,7 +1605,7 @@ static int ssl3_get_client_key_exchange(SSL *ssl) {
1501
1605
  CBS_data(&encrypted_premaster_secret),
1502
1606
  CBS_len(&encrypted_premaster_secret));
1503
1607
  } else {
1504
- assert(ssl->state == SSL3_ST_SR_KEY_EXCH_B);
1608
+ assert(hs->state == SSL3_ST_SR_KEY_EXCH_B);
1505
1609
  /* Complete async decrypt. */
1506
1610
  decrypt_result =
1507
1611
  ssl_private_key_complete(ssl, decrypt_buf, &decrypt_len, rsa_size);
@@ -1514,7 +1618,7 @@ static int ssl3_get_client_key_exchange(SSL *ssl) {
1514
1618
  goto err;
1515
1619
  case ssl_private_key_retry:
1516
1620
  ssl->rwstate = SSL_PRIVATE_KEY_OPERATION;
1517
- ssl->state = SSL3_ST_SR_KEY_EXCH_B;
1621
+ hs->state = SSL3_ST_SR_KEY_EXCH_B;
1518
1622
  goto err;
1519
1623
  }
1520
1624
 
@@ -1556,9 +1660,9 @@ static int ssl3_get_client_key_exchange(SSL *ssl) {
1556
1660
  /* The premaster secret must begin with |client_version|. This too must be
1557
1661
  * checked in constant time (http://eprint.iacr.org/2003/052/). */
1558
1662
  good &= constant_time_eq_8(decrypt_buf[padding_len],
1559
- (unsigned)(ssl->client_version >> 8));
1663
+ (unsigned)(hs->client_version >> 8));
1560
1664
  good &= constant_time_eq_8(decrypt_buf[padding_len + 1],
1561
- (unsigned)(ssl->client_version & 0xff));
1665
+ (unsigned)(hs->client_version & 0xff));
1562
1666
 
1563
1667
  /* Select, in constant time, either the decrypted premaster or the random
1564
1668
  * premaster based on |good|. */
@@ -1569,11 +1673,10 @@ static int ssl3_get_client_key_exchange(SSL *ssl) {
1569
1673
 
1570
1674
  OPENSSL_free(decrypt_buf);
1571
1675
  decrypt_buf = NULL;
1572
- } else if (alg_k & (SSL_kECDHE|SSL_kDHE|SSL_kCECPQ1)) {
1676
+ } else if (alg_k & (SSL_kECDHE|SSL_kDHE)) {
1573
1677
  /* Parse the ClientKeyExchange. */
1574
1678
  CBS peer_key;
1575
- if (!SSL_ECDH_CTX_get_key(&ssl->s3->tmp.ecdh_ctx, &client_key_exchange,
1576
- &peer_key) ||
1679
+ if (!SSL_ECDH_CTX_get_key(&hs->ecdh_ctx, &client_key_exchange, &peer_key) ||
1577
1680
  CBS_len(&client_key_exchange) != 0) {
1578
1681
  al = SSL_AD_DECODE_ERROR;
1579
1682
  OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
@@ -1581,8 +1684,8 @@ static int ssl3_get_client_key_exchange(SSL *ssl) {
1581
1684
  }
1582
1685
 
1583
1686
  /* Compute the premaster. */
1584
- uint8_t alert;
1585
- if (!SSL_ECDH_CTX_finish(&ssl->s3->tmp.ecdh_ctx, &premaster_secret,
1687
+ uint8_t alert = SSL_AD_DECODE_ERROR;
1688
+ if (!SSL_ECDH_CTX_finish(&hs->ecdh_ctx, &premaster_secret,
1586
1689
  &premaster_secret_len, &alert, CBS_data(&peer_key),
1587
1690
  CBS_len(&peer_key))) {
1588
1691
  al = alert;
@@ -1590,7 +1693,7 @@ static int ssl3_get_client_key_exchange(SSL *ssl) {
1590
1693
  }
1591
1694
 
1592
1695
  /* The key exchange state may now be discarded. */
1593
- SSL_ECDH_CTX_cleanup(&ssl->s3->tmp.ecdh_ctx);
1696
+ SSL_ECDH_CTX_cleanup(&hs->ecdh_ctx);
1594
1697
  } else if (alg_k & SSL_kPSK) {
1595
1698
  /* For plain PSK, other_secret is a block of 0s with the same length as the
1596
1699
  * pre-shared key. */
@@ -1600,7 +1703,7 @@ static int ssl3_get_client_key_exchange(SSL *ssl) {
1600
1703
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1601
1704
  goto err;
1602
1705
  }
1603
- memset(premaster_secret, 0, premaster_secret_len);
1706
+ OPENSSL_memset(premaster_secret, 0, premaster_secret_len);
1604
1707
  } else {
1605
1708
  al = SSL_AD_HANDSHAKE_FAILURE;
1606
1709
  OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_CIPHER_TYPE);
@@ -1633,14 +1736,12 @@ static int ssl3_get_client_key_exchange(SSL *ssl) {
1633
1736
  }
1634
1737
 
1635
1738
  /* Compute the master secret */
1636
- ssl->s3->new_session->master_key_length = tls1_generate_master_secret(
1637
- ssl, ssl->s3->new_session->master_key, premaster_secret,
1638
- premaster_secret_len);
1639
- if (ssl->s3->new_session->master_key_length == 0) {
1739
+ hs->new_session->master_key_length = tls1_generate_master_secret(
1740
+ hs, hs->new_session->master_key, premaster_secret, premaster_secret_len);
1741
+ if (hs->new_session->master_key_length == 0) {
1640
1742
  goto err;
1641
1743
  }
1642
- ssl->s3->new_session->extended_master_secret =
1643
- ssl->s3->tmp.extended_master_secret;
1744
+ hs->new_session->extended_master_secret = hs->extended_master_secret;
1644
1745
 
1645
1746
  OPENSSL_cleanse(premaster_secret, premaster_secret_len);
1646
1747
  OPENSSL_free(premaster_secret);
@@ -1658,30 +1759,26 @@ err:
1658
1759
  return -1;
1659
1760
  }
1660
1761
 
1661
- static int ssl3_get_cert_verify(SSL *ssl) {
1662
- int al, ret = 0;
1762
+ static int ssl3_get_cert_verify(SSL_HANDSHAKE *hs) {
1763
+ SSL *const ssl = hs->ssl;
1764
+ int al;
1663
1765
  CBS certificate_verify, signature;
1664
- X509 *peer = ssl->s3->new_session->peer;
1665
- EVP_PKEY *pkey = NULL;
1666
1766
 
1667
1767
  /* Only RSA and ECDSA client certificates are supported, so a
1668
1768
  * CertificateVerify is required if and only if there's a client certificate.
1669
1769
  * */
1670
- if (peer == NULL) {
1671
- ssl3_free_handshake_buffer(ssl);
1770
+ if (hs->peer_pubkey == NULL) {
1771
+ SSL_TRANSCRIPT_free_buffer(&hs->transcript);
1672
1772
  return 1;
1673
1773
  }
1674
1774
 
1675
- int msg_ret = ssl->method->ssl_get_message(ssl, SSL3_MT_CERTIFICATE_VERIFY,
1676
- ssl_dont_hash_message);
1775
+ int msg_ret = ssl->method->ssl_get_message(ssl);
1677
1776
  if (msg_ret <= 0) {
1678
1777
  return msg_ret;
1679
1778
  }
1680
1779
 
1681
- /* Filter out unsupported certificate types. */
1682
- pkey = X509_get_pubkey(peer);
1683
- if (pkey == NULL) {
1684
- goto err;
1780
+ if (!ssl_check_message_type(ssl, SSL3_MT_CERTIFICATE_VERIFY)) {
1781
+ return -1;
1685
1782
  }
1686
1783
 
1687
1784
  CBS_init(&certificate_verify, ssl->init_msg, ssl->init_num);
@@ -1697,10 +1794,10 @@ static int ssl3_get_cert_verify(SSL *ssl) {
1697
1794
  if (!tls12_check_peer_sigalg(ssl, &al, signature_algorithm)) {
1698
1795
  goto f_err;
1699
1796
  }
1700
- ssl->s3->tmp.peer_signature_algorithm = signature_algorithm;
1701
- } else if (pkey->type == EVP_PKEY_RSA) {
1797
+ hs->new_session->peer_signature_algorithm = signature_algorithm;
1798
+ } else if (hs->peer_pubkey->type == EVP_PKEY_RSA) {
1702
1799
  signature_algorithm = SSL_SIGN_RSA_PKCS1_MD5_SHA1;
1703
- } else if (pkey->type == EVP_PKEY_EC) {
1800
+ } else if (hs->peer_pubkey->type == EVP_PKEY_EC) {
1704
1801
  signature_algorithm = SSL_SIGN_ECDSA_SHA1;
1705
1802
  } else {
1706
1803
  al = SSL_AD_UNSUPPORTED_CERTIFICATE;
@@ -1720,26 +1817,25 @@ static int ssl3_get_cert_verify(SSL *ssl) {
1720
1817
  /* The SSL3 construction for CertificateVerify does not decompose into a
1721
1818
  * single final digest and signature, and must be special-cased. */
1722
1819
  if (ssl3_protocol_version(ssl) == SSL3_VERSION) {
1723
- const EVP_MD *md;
1724
1820
  uint8_t digest[EVP_MAX_MD_SIZE];
1725
1821
  size_t digest_len;
1726
- if (!ssl3_cert_verify_hash(ssl, &md, digest, &digest_len,
1727
- signature_algorithm)) {
1822
+ if (!SSL_TRANSCRIPT_ssl3_cert_verify_hash(&hs->transcript, digest,
1823
+ &digest_len, hs->new_session,
1824
+ signature_algorithm)) {
1728
1825
  goto err;
1729
1826
  }
1730
1827
 
1731
- EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new(pkey, NULL);
1828
+ EVP_PKEY_CTX *pctx = EVP_PKEY_CTX_new(hs->peer_pubkey, NULL);
1732
1829
  sig_ok = pctx != NULL &&
1733
1830
  EVP_PKEY_verify_init(pctx) &&
1734
- EVP_PKEY_CTX_set_signature_md(pctx, md) &&
1735
1831
  EVP_PKEY_verify(pctx, CBS_data(&signature), CBS_len(&signature),
1736
1832
  digest, digest_len);
1737
1833
  EVP_PKEY_CTX_free(pctx);
1738
1834
  } else {
1739
1835
  sig_ok = ssl_public_key_verify(
1740
1836
  ssl, CBS_data(&signature), CBS_len(&signature), signature_algorithm,
1741
- pkey, (const uint8_t *)ssl->s3->handshake_buffer->data,
1742
- ssl->s3->handshake_buffer->length);
1837
+ hs->peer_pubkey, (const uint8_t *)hs->transcript.buffer->data,
1838
+ hs->transcript.buffer->length);
1743
1839
  }
1744
1840
 
1745
1841
  #if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
@@ -1754,33 +1850,33 @@ static int ssl3_get_cert_verify(SSL *ssl) {
1754
1850
 
1755
1851
  /* The handshake buffer is no longer necessary, and we may hash the current
1756
1852
  * message.*/
1757
- ssl3_free_handshake_buffer(ssl);
1758
- if (!ssl->method->hash_current_message(ssl)) {
1853
+ SSL_TRANSCRIPT_free_buffer(&hs->transcript);
1854
+ if (!ssl_hash_current_message(hs)) {
1759
1855
  goto err;
1760
1856
  }
1761
1857
 
1762
- ret = 1;
1763
-
1764
- if (0) {
1765
- f_err:
1766
- ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
1767
- }
1858
+ return 1;
1768
1859
 
1860
+ f_err:
1861
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
1769
1862
  err:
1770
- EVP_PKEY_free(pkey);
1771
-
1772
- return ret;
1863
+ return 0;
1773
1864
  }
1774
1865
 
1775
1866
  /* ssl3_get_next_proto reads a Next Protocol Negotiation handshake message. It
1776
1867
  * sets the next_proto member in s if found */
1777
- static int ssl3_get_next_proto(SSL *ssl) {
1778
- int ret =
1779
- ssl->method->ssl_get_message(ssl, SSL3_MT_NEXT_PROTO, ssl_hash_message);
1868
+ static int ssl3_get_next_proto(SSL_HANDSHAKE *hs) {
1869
+ SSL *const ssl = hs->ssl;
1870
+ int ret = ssl->method->ssl_get_message(ssl);
1780
1871
  if (ret <= 0) {
1781
1872
  return ret;
1782
1873
  }
1783
1874
 
1875
+ if (!ssl_check_message_type(ssl, SSL3_MT_NEXT_PROTO) ||
1876
+ !ssl_hash_current_message(hs)) {
1877
+ return -1;
1878
+ }
1879
+
1784
1880
  CBS next_protocol, selected_protocol, padding;
1785
1881
  CBS_init(&next_protocol, ssl->init_msg, ssl->init_num);
1786
1882
  if (!CBS_get_u8_length_prefixed(&next_protocol, &selected_protocol) ||
@@ -1800,133 +1896,55 @@ static int ssl3_get_next_proto(SSL *ssl) {
1800
1896
  }
1801
1897
 
1802
1898
  /* ssl3_get_channel_id reads and verifies a ClientID handshake message. */
1803
- static int ssl3_get_channel_id(SSL *ssl) {
1804
- int ret = -1;
1805
- uint8_t channel_id_hash[EVP_MAX_MD_SIZE];
1806
- size_t channel_id_hash_len;
1807
- const uint8_t *p;
1808
- uint16_t extension_type;
1809
- EC_GROUP *p256 = NULL;
1810
- EC_KEY *key = NULL;
1811
- EC_POINT *point = NULL;
1812
- ECDSA_SIG sig;
1813
- BIGNUM x, y;
1814
- CBS encrypted_extensions, extension;
1815
-
1816
- int msg_ret = ssl->method->ssl_get_message(ssl, SSL3_MT_CHANNEL_ID,
1817
- ssl_dont_hash_message);
1899
+ static int ssl3_get_channel_id(SSL_HANDSHAKE *hs) {
1900
+ SSL *const ssl = hs->ssl;
1901
+ int msg_ret = ssl->method->ssl_get_message(ssl);
1818
1902
  if (msg_ret <= 0) {
1819
1903
  return msg_ret;
1820
1904
  }
1821
1905
 
1822
- /* Before incorporating the EncryptedExtensions message to the handshake
1823
- * hash, compute the hash that should have been signed. */
1824
- if (!tls1_channel_id_hash(ssl, channel_id_hash, &channel_id_hash_len)) {
1906
+ if (!ssl_check_message_type(ssl, SSL3_MT_CHANNEL_ID) ||
1907
+ !tls1_verify_channel_id(hs) ||
1908
+ !ssl_hash_current_message(hs)) {
1825
1909
  return -1;
1826
1910
  }
1827
- assert(channel_id_hash_len == SHA256_DIGEST_LENGTH);
1828
-
1829
- if (!ssl->method->hash_current_message(ssl)) {
1830
- return -1;
1831
- }
1832
-
1833
- CBS_init(&encrypted_extensions, ssl->init_msg, ssl->init_num);
1834
-
1835
- /* EncryptedExtensions could include multiple extensions, but the only
1836
- * extension that could be negotiated is Channel ID, so there can only be one
1837
- * entry. */
1838
- if (!CBS_get_u16(&encrypted_extensions, &extension_type) ||
1839
- !CBS_get_u16_length_prefixed(&encrypted_extensions, &extension) ||
1840
- CBS_len(&encrypted_extensions) != 0 ||
1841
- extension_type != TLSEXT_TYPE_channel_id ||
1842
- CBS_len(&extension) != TLSEXT_CHANNEL_ID_SIZE) {
1843
- OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1844
- ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1845
- return -1;
1846
- }
1847
-
1848
- p256 = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1);
1849
- if (!p256) {
1850
- OPENSSL_PUT_ERROR(SSL, SSL_R_NO_P256_SUPPORT);
1851
- return -1;
1852
- }
1853
-
1854
- BN_init(&x);
1855
- BN_init(&y);
1856
- sig.r = BN_new();
1857
- sig.s = BN_new();
1858
- if (sig.r == NULL || sig.s == NULL) {
1859
- goto err;
1860
- }
1861
-
1862
- p = CBS_data(&extension);
1863
- if (BN_bin2bn(p + 0, 32, &x) == NULL ||
1864
- BN_bin2bn(p + 32, 32, &y) == NULL ||
1865
- BN_bin2bn(p + 64, 32, sig.r) == NULL ||
1866
- BN_bin2bn(p + 96, 32, sig.s) == NULL) {
1867
- goto err;
1868
- }
1869
-
1870
- point = EC_POINT_new(p256);
1871
- if (!point ||
1872
- !EC_POINT_set_affine_coordinates_GFp(p256, point, &x, &y, NULL)) {
1873
- goto err;
1874
- }
1875
-
1876
- key = EC_KEY_new();
1877
- if (!key || !EC_KEY_set_group(key, p256) ||
1878
- !EC_KEY_set_public_key(key, point)) {
1879
- goto err;
1880
- }
1881
-
1882
- /* We stored the handshake hash in |tlsext_channel_id| the first time that we
1883
- * were called. */
1884
- int sig_ok = ECDSA_do_verify(channel_id_hash, channel_id_hash_len, &sig, key);
1885
- #if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
1886
- sig_ok = 1;
1887
- #endif
1888
- if (!sig_ok) {
1889
- OPENSSL_PUT_ERROR(SSL, SSL_R_CHANNEL_ID_SIGNATURE_INVALID);
1890
- ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR);
1891
- ssl->s3->tlsext_channel_id_valid = 0;
1892
- goto err;
1893
- }
1894
-
1895
- memcpy(ssl->s3->tlsext_channel_id, p, 64);
1896
- ret = 1;
1897
-
1898
- err:
1899
- BN_free(&x);
1900
- BN_free(&y);
1901
- BN_free(sig.r);
1902
- BN_free(sig.s);
1903
- EC_KEY_free(key);
1904
- EC_POINT_free(point);
1905
- EC_GROUP_free(p256);
1906
- return ret;
1911
+ return 1;
1907
1912
  }
1908
1913
 
1909
- static int ssl3_send_new_session_ticket(SSL *ssl) {
1910
- if (ssl->state == SSL3_ST_SW_SESSION_TICKET_B) {
1911
- return ssl->method->write_message(ssl);
1914
+ static int ssl3_send_new_session_ticket(SSL_HANDSHAKE *hs) {
1915
+ SSL *const ssl = hs->ssl;
1916
+ const SSL_SESSION *session;
1917
+ SSL_SESSION *session_copy = NULL;
1918
+ if (ssl->session == NULL) {
1919
+ /* Fix the timeout to measure from the ticket issuance time. */
1920
+ ssl_session_rebase_time(ssl, hs->new_session);
1921
+ session = hs->new_session;
1922
+ } else {
1923
+ /* We are renewing an existing session. Duplicate the session to adjust the
1924
+ * timeout. */
1925
+ session_copy = SSL_SESSION_dup(ssl->session, SSL_SESSION_INCLUDE_NONAUTH);
1926
+ if (session_copy == NULL) {
1927
+ return -1;
1928
+ }
1929
+
1930
+ ssl_session_rebase_time(ssl, session_copy);
1931
+ session = session_copy;
1912
1932
  }
1913
1933
 
1914
1934
  CBB cbb, body, ticket;
1915
- if (!ssl->method->init_message(ssl, &cbb, &body,
1916
- SSL3_MT_NEW_SESSION_TICKET) ||
1917
- /* Ticket lifetime hint (advisory only): We leave this unspecified for
1918
- * resumed session (for simplicity), and guess that tickets for new
1919
- * sessions will live as long as their sessions. */
1920
- !CBB_add_u32(&body,
1921
- ssl->session != NULL ? 0 : ssl->s3->new_session->timeout) ||
1922
- !CBB_add_u16_length_prefixed(&body, &ticket) ||
1923
- !ssl_encrypt_ticket(ssl, &ticket, ssl->session != NULL
1924
- ? ssl->session
1925
- : ssl->s3->new_session) ||
1926
- !ssl->method->finish_message(ssl, &cbb)) {
1927
- return 0;
1935
+ int ok =
1936
+ ssl->method->init_message(ssl, &cbb, &body, SSL3_MT_NEW_SESSION_TICKET) &&
1937
+ CBB_add_u32(&body, session->timeout) &&
1938
+ CBB_add_u16_length_prefixed(&body, &ticket) &&
1939
+ ssl_encrypt_ticket(ssl, &ticket, session) &&
1940
+ ssl_add_message_cbb(ssl, &cbb);
1941
+
1942
+ SSL_SESSION_free(session_copy);
1943
+ CBB_cleanup(&cbb);
1944
+
1945
+ if (!ok) {
1946
+ return -1;
1928
1947
  }
1929
1948
 
1930
- ssl->state = SSL3_ST_SW_SESSION_TICKET_B;
1931
- return ssl->method->write_message(ssl);
1949
+ return 1;
1932
1950
  }