grpc 0.13.1 → 0.14.1.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 (724) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +2098 -828
  3. data/include/grpc/byte_buffer.h +1 -1
  4. data/include/grpc/byte_buffer_reader.h +1 -20
  5. data/include/grpc/census.h +4 -4
  6. data/include/grpc/compression.h +6 -5
  7. data/include/grpc/grpc.h +31 -20
  8. data/include/grpc/grpc_security.h +17 -31
  9. data/include/grpc/grpc_security_constants.h +114 -0
  10. data/include/grpc/grpc_zookeeper.h +1 -1
  11. data/include/grpc/impl/codegen/alloc.h +1 -1
  12. data/include/grpc/impl/codegen/atm.h +1 -1
  13. data/include/grpc/impl/codegen/atm_gcc_atomic.h +1 -1
  14. data/include/grpc/impl/codegen/atm_gcc_sync.h +1 -1
  15. data/include/grpc/impl/codegen/atm_win32.h +1 -1
  16. data/include/grpc/impl/codegen/byte_buffer.h +1 -1
  17. data/{src/core/client_config/lb_policies/round_robin.h → include/grpc/impl/codegen/byte_buffer_reader.h} +19 -8
  18. data/include/grpc/impl/codegen/grpc_types.h +20 -3
  19. data/include/grpc/impl/codegen/log.h +9 -2
  20. data/include/grpc/impl/codegen/port_platform.h +102 -17
  21. data/include/grpc/impl/codegen/propagation_bits.h +3 -3
  22. data/include/grpc/impl/codegen/slice.h +3 -3
  23. data/include/grpc/impl/codegen/slice_buffer.h +3 -3
  24. data/include/grpc/impl/codegen/status.h +1 -1
  25. data/include/grpc/impl/codegen/sync_generic.h +1 -1
  26. data/include/grpc/impl/codegen/sync_posix.h +1 -1
  27. data/include/grpc/impl/codegen/sync_win32.h +1 -1
  28. data/include/grpc/impl/codegen/time.h +3 -3
  29. data/include/grpc/status.h +1 -1
  30. data/include/grpc/support/alloc.h +1 -1
  31. data/include/grpc/support/atm.h +1 -1
  32. data/include/grpc/support/atm_gcc_atomic.h +4 -4
  33. data/include/grpc/support/atm_gcc_sync.h +1 -1
  34. data/include/grpc/support/atm_win32.h +1 -1
  35. data/include/grpc/support/avl.h +1 -1
  36. data/include/grpc/support/cmdline.h +1 -1
  37. data/include/grpc/support/cpu.h +1 -1
  38. data/include/grpc/support/histogram.h +1 -1
  39. data/include/grpc/support/host_port.h +1 -1
  40. data/include/grpc/support/log.h +1 -1
  41. data/include/grpc/support/log_win32.h +1 -1
  42. data/include/grpc/support/port_platform.h +1 -1
  43. data/include/grpc/support/slice.h +1 -1
  44. data/include/grpc/support/slice_buffer.h +1 -1
  45. data/include/grpc/support/string_util.h +3 -1
  46. data/include/grpc/support/subprocess.h +2 -2
  47. data/include/grpc/support/sync.h +1 -1
  48. data/include/grpc/support/sync_generic.h +1 -1
  49. data/include/grpc/support/sync_posix.h +1 -1
  50. data/include/grpc/support/sync_win32.h +1 -1
  51. data/include/grpc/support/thd.h +1 -1
  52. data/include/grpc/support/time.h +1 -1
  53. data/include/grpc/support/tls.h +1 -1
  54. data/include/grpc/support/tls_gcc.h +45 -1
  55. data/include/grpc/support/tls_msvc.h +3 -3
  56. data/include/grpc/support/tls_pthread.h +1 -1
  57. data/include/grpc/support/useful.h +1 -1
  58. data/src/boringssl/err_data.c +258 -252
  59. data/src/core/{census → ext/census}/aggregation.h +3 -3
  60. data/src/core/{statistics → ext/census}/census_interface.h +3 -3
  61. data/src/core/{statistics → ext/census}/census_rpc_stats.h +4 -4
  62. data/src/core/{census → ext/census}/context.c +2 -2
  63. data/src/core/{census → ext/census}/grpc_context.c +2 -2
  64. data/src/core/{census → ext/census}/grpc_filter.c +30 -16
  65. data/src/core/{census → ext/census}/grpc_filter.h +4 -4
  66. data/src/core/ext/census/grpc_plugin.c +82 -0
  67. data/src/core/{census → ext/census}/initialize.c +1 -1
  68. data/src/core/{census → ext/census}/mlog.c +2 -2
  69. data/src/core/{census → ext/census}/mlog.h +4 -4
  70. data/src/core/{census → ext/census}/operation.c +0 -0
  71. data/src/core/{census → ext/census}/placeholders.c +0 -0
  72. data/src/core/{census → ext/census}/rpc_metric_id.h +3 -3
  73. data/src/core/{census → ext/census}/tracing.c +0 -0
  74. data/src/core/{surface → ext/client_config}/channel_connectivity.c +8 -21
  75. data/src/core/{channel → ext/client_config}/client_channel.c +80 -35
  76. data/src/core/{channel → ext/client_config}/client_channel.h +5 -5
  77. data/src/core/{client_config/subchannel_factory.c → ext/client_config/client_channel_factory.c} +14 -6
  78. data/src/core/ext/client_config/client_channel_factory.h +85 -0
  79. data/src/core/{client_config → ext/client_config}/client_config.c +4 -2
  80. data/src/core/{client_config → ext/client_config}/client_config.h +4 -4
  81. data/src/core/ext/client_config/client_config_plugin.c +95 -0
  82. data/src/core/{client_config → ext/client_config}/connector.c +2 -2
  83. data/src/core/{client_config → ext/client_config}/connector.h +7 -10
  84. data/src/core/{client_config → ext/client_config}/default_initial_connect_string.c +1 -1
  85. data/src/core/{client_config → ext/client_config}/initial_connect_string.c +1 -1
  86. data/src/core/{client_config → ext/client_config}/initial_connect_string.h +4 -4
  87. data/src/core/{client_config → ext/client_config}/lb_policy.c +12 -3
  88. data/src/core/{client_config → ext/client_config}/lb_policy.h +19 -6
  89. data/src/core/{client_config → ext/client_config}/lb_policy_factory.c +4 -3
  90. data/src/core/{client_config → ext/client_config}/lb_policy_factory.h +14 -9
  91. data/src/core/{client_config → ext/client_config}/lb_policy_registry.c +4 -9
  92. data/src/core/{client_config → ext/client_config}/lb_policy_registry.h +7 -6
  93. data/src/core/ext/client_config/parse_address.c +137 -0
  94. data/src/core/ext/client_config/parse_address.h +56 -0
  95. data/src/core/{client_config → ext/client_config}/resolver.c +1 -1
  96. data/src/core/{client_config → ext/client_config}/resolver.h +6 -6
  97. data/src/core/{client_config → ext/client_config}/resolver_factory.c +1 -1
  98. data/src/core/{client_config → ext/client_config}/resolver_factory.h +7 -7
  99. data/src/core/{client_config → ext/client_config}/resolver_registry.c +25 -11
  100. data/src/core/{client_config → ext/client_config}/resolver_registry.h +9 -5
  101. data/src/core/{client_config → ext/client_config}/subchannel.c +90 -126
  102. data/src/core/{client_config → ext/client_config}/subchannel.h +15 -15
  103. data/src/core/{channel → ext/client_config}/subchannel_call_holder.c +9 -8
  104. data/src/core/{channel → ext/client_config}/subchannel_call_holder.h +7 -7
  105. data/src/core/{client_config → ext/client_config}/subchannel_index.c +3 -2
  106. data/src/core/{client_config → ext/client_config}/subchannel_index.h +5 -5
  107. data/src/core/{client_config → ext/client_config}/uri_parser.c +69 -1
  108. data/src/core/{client_config → ext/client_config}/uri_parser.h +15 -3
  109. data/src/core/{client_config/lb_policies → ext/lb_policy/grpclb}/load_balancer_api.c +18 -9
  110. data/src/core/{client_config/lb_policies → ext/lb_policy/grpclb}/load_balancer_api.h +5 -5
  111. data/src/core/{proto → ext/lb_policy/grpclb/proto}/grpc/lb/v0/load_balancer.pb.c +1 -1
  112. data/src/core/{proto → ext/lb_policy/grpclb/proto}/grpc/lb/v0/load_balancer.pb.h +0 -0
  113. data/src/core/{client_config/lb_policies → ext/lb_policy/pick_first}/pick_first.c +95 -32
  114. data/src/core/{client_config/lb_policies → ext/lb_policy/round_robin}/round_robin.c +98 -34
  115. data/src/core/{client_config/resolvers → ext/resolver/dns/native}/dns_resolver.c +83 -39
  116. data/src/core/{client_config/resolvers → ext/resolver/sockaddr}/sockaddr_resolver.c +66 -169
  117. data/src/core/{transport/chttp2 → ext/transport/chttp2/alpn}/alpn.c +1 -1
  118. data/src/core/{transport/chttp2 → ext/transport/chttp2/alpn}/alpn.h +3 -3
  119. data/src/core/{surface → ext/transport/chttp2/client/insecure}/channel_create.c +65 -59
  120. data/src/core/{surface → ext/transport/chttp2/client/secure}/secure_channel_create.c +77 -69
  121. data/src/core/{surface → ext/transport/chttp2/server/insecure}/server_chttp2.c +8 -11
  122. data/src/core/{security → ext/transport/chttp2/server/secure}/server_secure_chttp2.c +14 -17
  123. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/bin_encoder.c +28 -74
  124. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/bin_encoder.h +5 -5
  125. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +46 -0
  126. data/src/core/{transport → ext/transport/chttp2/transport}/chttp2_transport.c +551 -310
  127. data/src/core/{transport → ext/transport/chttp2/transport}/chttp2_transport.h +5 -5
  128. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame.h +3 -3
  129. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame_data.c +30 -14
  130. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame_data.h +10 -7
  131. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame_goaway.c +2 -2
  132. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame_goaway.h +5 -5
  133. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame_ping.c +2 -2
  134. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame_ping.h +5 -5
  135. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame_rst_stream.c +9 -5
  136. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame_rst_stream.h +8 -6
  137. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame_settings.c +6 -6
  138. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame_settings.h +5 -5
  139. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame_window_update.c +11 -5
  140. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/frame_window_update.h +8 -6
  141. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/hpack_encoder.c +21 -12
  142. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/hpack_encoder.h +8 -6
  143. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/hpack_parser.c +42 -25
  144. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/hpack_parser.h +7 -7
  145. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/hpack_table.c +21 -11
  146. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/hpack_table.h +4 -4
  147. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/http2_errors.h +3 -3
  148. data/src/core/ext/transport/chttp2/transport/huffsyms.c +105 -0
  149. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/huffsyms.h +3 -3
  150. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/incoming_metadata.c +2 -2
  151. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/incoming_metadata.h +4 -4
  152. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/internal.h +81 -37
  153. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/parsing.c +54 -21
  154. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/status_conversion.c +1 -1
  155. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/status_conversion.h +4 -4
  156. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/stream_lists.c +10 -2
  157. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/stream_map.c +1 -1
  158. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/stream_map.h +3 -3
  159. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/timeout_encoding.c +4 -4
  160. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/timeout_encoding.h +4 -4
  161. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/varint.c +1 -1
  162. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/varint.h +3 -3
  163. data/src/core/{transport/chttp2 → ext/transport/chttp2/transport}/writing.c +30 -20
  164. data/src/core/{channel → lib/channel}/channel_args.c +3 -15
  165. data/src/core/{channel → lib/channel}/channel_args.h +11 -15
  166. data/src/core/{channel → lib/channel}/channel_stack.c +5 -3
  167. data/src/core/{channel → lib/channel}/channel_stack.h +13 -8
  168. data/src/core/lib/channel/channel_stack_builder.c +277 -0
  169. data/src/core/lib/channel/channel_stack_builder.h +161 -0
  170. data/src/core/{channel → lib/channel}/compress_filter.c +51 -16
  171. data/src/core/{channel → lib/channel}/compress_filter.h +6 -4
  172. data/src/core/{channel → lib/channel}/connected_channel.c +34 -24
  173. data/src/core/lib/channel/connected_channel.h +42 -0
  174. data/src/core/{channel → lib/channel}/context.h +3 -3
  175. data/src/core/{channel → lib/channel}/http_client_filter.c +24 -13
  176. data/src/core/{channel → lib/channel}/http_client_filter.h +4 -4
  177. data/src/core/{channel → lib/channel}/http_server_filter.c +39 -19
  178. data/src/core/{channel → lib/channel}/http_server_filter.h +4 -4
  179. data/src/core/{compression → lib/compression}/algorithm_metadata.h +4 -4
  180. data/src/core/{compression → lib/compression}/compression_algorithm.c +46 -9
  181. data/src/core/{compression → lib/compression}/message_compress.c +1 -1
  182. data/src/core/{compression → lib/compression}/message_compress.h +3 -3
  183. data/src/core/{debug → lib/debug}/trace.c +2 -2
  184. data/src/core/{debug → lib/debug}/trace.h +3 -3
  185. data/src/core/{httpcli → lib/http}/format_request.c +8 -8
  186. data/src/core/{httpcli → lib/http}/format_request.h +4 -4
  187. data/src/core/{httpcli → lib/http}/httpcli.c +24 -19
  188. data/src/core/{httpcli → lib/http}/httpcli.h +14 -33
  189. data/src/core/{httpcli → lib/http}/httpcli_security_connector.c +5 -5
  190. data/src/core/lib/http/parser.c +341 -0
  191. data/src/core/lib/http/parser.h +119 -0
  192. data/src/core/{iomgr → lib/iomgr}/closure.c +8 -2
  193. data/src/core/{iomgr → lib/iomgr}/closure.h +7 -4
  194. data/src/core/{iomgr → lib/iomgr}/endpoint.c +1 -1
  195. data/src/core/{iomgr → lib/iomgr}/endpoint.h +5 -5
  196. data/src/core/{iomgr → lib/iomgr}/endpoint_pair.h +4 -4
  197. data/src/core/{iomgr → lib/iomgr}/endpoint_pair_posix.c +8 -7
  198. data/src/core/{iomgr → lib/iomgr}/endpoint_pair_windows.c +4 -4
  199. data/src/core/lib/iomgr/ev_poll_and_epoll_posix.c +1936 -0
  200. data/src/core/lib/iomgr/ev_poll_and_epoll_posix.h +41 -0
  201. data/src/core/lib/iomgr/ev_posix.c +164 -0
  202. data/src/core/lib/iomgr/ev_posix.h +158 -0
  203. data/src/core/{iomgr → lib/iomgr}/exec_ctx.c +78 -3
  204. data/src/core/{iomgr → lib/iomgr}/exec_ctx.h +25 -10
  205. data/src/core/{iomgr → lib/iomgr}/executor.c +3 -3
  206. data/src/core/{iomgr → lib/iomgr}/executor.h +5 -5
  207. data/src/core/{iomgr → lib/iomgr}/iocp_windows.c +6 -6
  208. data/src/core/{iomgr → lib/iomgr}/iocp_windows.h +5 -5
  209. data/src/core/{iomgr → lib/iomgr}/iomgr.c +13 -10
  210. data/src/core/{iomgr → lib/iomgr}/iomgr.h +3 -3
  211. data/src/core/{iomgr → lib/iomgr}/iomgr_internal.h +5 -9
  212. data/src/core/{iomgr → lib/iomgr}/iomgr_posix.c +6 -6
  213. data/src/core/{iomgr → lib/iomgr}/iomgr_posix.h +4 -4
  214. data/src/core/{iomgr → lib/iomgr}/iomgr_windows.c +7 -4
  215. data/src/core/{iomgr → lib/iomgr}/pollset.h +11 -11
  216. data/src/core/{iomgr → lib/iomgr}/pollset_set.h +5 -5
  217. data/src/core/{iomgr → lib/iomgr}/pollset_set_windows.c +2 -2
  218. data/src/core/lib/iomgr/pollset_set_windows.h +39 -0
  219. data/src/core/{iomgr → lib/iomgr}/pollset_windows.c +7 -7
  220. data/src/core/{iomgr → lib/iomgr}/pollset_windows.h +8 -5
  221. data/src/core/{iomgr → lib/iomgr}/resolve_address.h +10 -9
  222. data/src/core/{iomgr → lib/iomgr}/resolve_address_posix.c +22 -22
  223. data/src/core/{iomgr → lib/iomgr}/resolve_address_windows.c +20 -12
  224. data/src/core/{iomgr → lib/iomgr}/sockaddr.h +5 -5
  225. data/src/core/{iomgr → lib/iomgr}/sockaddr_posix.h +5 -5
  226. data/src/core/{iomgr → lib/iomgr}/sockaddr_utils.c +9 -16
  227. data/src/core/{iomgr → lib/iomgr}/sockaddr_utils.h +4 -4
  228. data/src/core/{iomgr → lib/iomgr}/sockaddr_win32.h +6 -4
  229. data/src/core/{iomgr → lib/iomgr}/socket_utils_common_posix.c +29 -7
  230. data/src/core/{iomgr → lib/iomgr}/socket_utils_linux.c +2 -2
  231. data/src/core/{iomgr → lib/iomgr}/socket_utils_posix.c +1 -1
  232. data/src/core/{iomgr → lib/iomgr}/socket_utils_posix.h +14 -4
  233. data/src/core/{iomgr → lib/iomgr}/socket_windows.c +7 -5
  234. data/src/core/{iomgr → lib/iomgr}/socket_windows.h +6 -6
  235. data/src/core/{iomgr → lib/iomgr}/tcp_client.h +6 -6
  236. data/src/core/{iomgr → lib/iomgr}/tcp_client_posix.c +33 -18
  237. data/src/core/{iomgr → lib/iomgr}/tcp_client_windows.c +30 -20
  238. data/src/core/{iomgr → lib/iomgr}/tcp_posix.c +9 -10
  239. data/src/core/{iomgr → lib/iomgr}/tcp_posix.h +6 -6
  240. data/src/core/{iomgr → lib/iomgr}/tcp_server.h +6 -6
  241. data/src/core/{iomgr → lib/iomgr}/tcp_server_posix.c +24 -37
  242. data/src/core/{iomgr → lib/iomgr}/tcp_server_windows.c +8 -36
  243. data/src/core/{iomgr → lib/iomgr}/tcp_windows.c +27 -17
  244. data/src/core/{iomgr → lib/iomgr}/tcp_windows.h +5 -5
  245. data/src/core/{iomgr → lib/iomgr}/time_averaged_stats.c +1 -1
  246. data/src/core/{iomgr → lib/iomgr}/time_averaged_stats.h +3 -3
  247. data/src/core/{iomgr → lib/iomgr}/timer.c +31 -4
  248. data/src/core/{iomgr → lib/iomgr}/timer.h +6 -7
  249. data/src/core/{iomgr → lib/iomgr}/timer_heap.c +2 -2
  250. data/src/core/{iomgr → lib/iomgr}/timer_heap.h +4 -4
  251. data/src/core/{iomgr → lib/iomgr}/udp_server.c +13 -37
  252. data/src/core/{iomgr → lib/iomgr}/udp_server.h +11 -10
  253. data/src/core/lib/iomgr/unix_sockets_posix.c +89 -0
  254. data/src/core/{client_config/resolvers/sockaddr_resolver.h → lib/iomgr/unix_sockets_posix.h} +15 -11
  255. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +59 -0
  256. data/src/core/{iomgr → lib/iomgr}/wakeup_fd_eventfd.c +2 -2
  257. data/src/core/{iomgr → lib/iomgr}/wakeup_fd_nospecial.c +1 -1
  258. data/src/core/{iomgr → lib/iomgr}/wakeup_fd_pipe.c +8 -3
  259. data/src/core/{iomgr → lib/iomgr}/wakeup_fd_pipe.h +4 -4
  260. data/src/core/{iomgr → lib/iomgr}/wakeup_fd_posix.c +2 -2
  261. data/src/core/{iomgr → lib/iomgr}/wakeup_fd_posix.h +3 -3
  262. data/src/core/{iomgr → lib/iomgr}/workqueue.h +10 -10
  263. data/src/core/{iomgr → lib/iomgr}/workqueue_posix.c +5 -6
  264. data/src/core/{iomgr → lib/iomgr}/workqueue_posix.h +5 -5
  265. data/src/core/{iomgr → lib/iomgr}/workqueue_windows.c +1 -1
  266. data/src/core/{iomgr → lib/iomgr}/workqueue_windows.h +3 -3
  267. data/src/core/{json → lib/json}/json.c +1 -1
  268. data/src/core/{json → lib/json}/json.h +4 -4
  269. data/src/core/{json → lib/json}/json_common.h +3 -3
  270. data/src/core/{json → lib/json}/json_reader.c +16 -4
  271. data/src/core/{json → lib/json}/json_reader.h +4 -4
  272. data/src/core/{json → lib/json}/json_string.c +4 -4
  273. data/src/core/{json → lib/json}/json_writer.c +1 -1
  274. data/src/core/{json → lib/json}/json_writer.h +4 -4
  275. data/src/core/{profiling → lib/profiling}/basic_timers.c +3 -2
  276. data/src/core/{profiling → lib/profiling}/stap_timers.c +2 -2
  277. data/src/core/{profiling → lib/profiling}/timers.h +3 -3
  278. data/src/core/{security → lib/security}/auth_filters.h +4 -4
  279. data/src/core/{security → lib/security}/b64.c +2 -2
  280. data/src/core/{security → lib/security}/b64.h +4 -4
  281. data/src/core/{security → lib/security}/client_auth_filter.c +16 -16
  282. data/src/core/{security → lib/security}/credentials.c +42 -26
  283. data/src/core/{security → lib/security}/credentials.h +11 -10
  284. data/src/core/{security → lib/security}/credentials_metadata.c +1 -1
  285. data/src/core/{security → lib/security}/credentials_posix.c +3 -3
  286. data/src/core/{security → lib/security}/credentials_win32.c +3 -3
  287. data/src/core/{security → lib/security}/google_default_credentials.c +10 -9
  288. data/src/core/{security → lib/security}/handshake.c +4 -4
  289. data/src/core/{security → lib/security}/handshake.h +6 -6
  290. data/src/core/{security → lib/security}/json_token.c +4 -4
  291. data/src/core/{security → lib/security}/json_token.h +4 -4
  292. data/src/core/{security → lib/security}/jwt_verifier.c +14 -14
  293. data/src/core/{security → lib/security}/jwt_verifier.h +5 -5
  294. data/src/core/{security → lib/security}/secure_endpoint.c +9 -8
  295. data/src/core/{security → lib/security}/secure_endpoint.h +4 -4
  296. data/src/core/{security → lib/security}/security_connector.c +53 -21
  297. data/src/core/{security → lib/security}/security_connector.h +8 -8
  298. data/src/core/{security → lib/security}/security_context.c +5 -5
  299. data/src/core/{security → lib/security}/security_context.h +5 -5
  300. data/src/core/{security → lib/security}/server_auth_filter.c +9 -9
  301. data/src/core/{support → lib/support}/alloc.c +5 -3
  302. data/src/core/{support → lib/support}/avl.c +1 -1
  303. data/src/core/lib/support/backoff.c +76 -0
  304. data/src/core/lib/support/backoff.h +68 -0
  305. data/src/core/{support → lib/support}/block_annotate.h +3 -3
  306. data/src/core/{support → lib/support}/cmdline.c +1 -1
  307. data/src/core/{support → lib/support}/cpu_iphone.c +0 -0
  308. data/src/core/{support → lib/support}/cpu_linux.c +2 -2
  309. data/src/core/{support → lib/support}/cpu_posix.c +2 -2
  310. data/src/core/{support → lib/support}/cpu_windows.c +0 -0
  311. data/src/core/{support → lib/support}/env.h +3 -3
  312. data/src/core/{support → lib/support}/env_linux.c +3 -3
  313. data/src/core/{support → lib/support}/env_posix.c +2 -2
  314. data/src/core/{support → lib/support}/env_win32.c +27 -21
  315. data/src/core/{support → lib/support}/histogram.c +1 -1
  316. data/src/core/{support → lib/support}/host_port.c +1 -1
  317. data/src/core/{support → lib/support}/load_file.c +4 -4
  318. data/src/core/{support → lib/support}/load_file.h +4 -4
  319. data/src/core/{support → lib/support}/log.c +33 -0
  320. data/src/core/{support → lib/support}/log_android.c +2 -2
  321. data/src/core/{support → lib/support}/log_linux.c +6 -5
  322. data/src/core/{support → lib/support}/log_posix.c +3 -3
  323. data/src/core/{support → lib/support}/log_win32.c +8 -22
  324. data/src/core/{support → lib/support}/murmur_hash.c +1 -1
  325. data/src/core/{support → lib/support}/murmur_hash.h +3 -3
  326. data/src/core/{support → lib/support}/slice.c +0 -0
  327. data/src/core/{support → lib/support}/slice_buffer.c +0 -0
  328. data/src/core/{support → lib/support}/stack_lockfree.c +7 -7
  329. data/src/core/{support → lib/support}/stack_lockfree.h +3 -3
  330. data/src/core/{support → lib/support}/string.c +1 -1
  331. data/src/core/{support → lib/support}/string.h +4 -4
  332. data/src/core/{support → lib/support}/string_posix.c +1 -1
  333. data/src/core/{support/string_win32.c → lib/support/string_util_win32.c} +23 -38
  334. data/src/core/lib/support/string_win32.c +83 -0
  335. data/src/core/{support → lib/support}/string_win32.h +3 -3
  336. data/src/core/{support → lib/support}/subprocess_posix.c +3 -3
  337. data/src/core/{support → lib/support}/subprocess_windows.c +3 -3
  338. data/src/core/{support → lib/support}/sync.c +2 -2
  339. data/src/core/{support → lib/support}/sync_posix.c +3 -3
  340. data/src/core/{support → lib/support}/sync_win32.c +1 -1
  341. data/src/core/{support → lib/support}/thd.c +0 -0
  342. data/src/core/{support → lib/support}/thd_internal.h +3 -3
  343. data/src/core/{support → lib/support}/thd_posix.c +4 -3
  344. data/src/core/{support → lib/support}/thd_win32.c +1 -1
  345. data/src/core/{support → lib/support}/time.c +2 -2
  346. data/src/core/{support → lib/support}/time_posix.c +12 -6
  347. data/src/core/{support → lib/support}/time_precise.c +0 -0
  348. data/src/core/{support → lib/support}/time_precise.h +3 -3
  349. data/src/core/{support → lib/support}/time_win32.c +7 -7
  350. data/src/core/{support → lib/support}/tls_pthread.c +0 -0
  351. data/src/core/{support → lib/support}/tmpfile.h +4 -4
  352. data/src/core/lib/support/tmpfile_msys.c +73 -0
  353. data/src/core/{support → lib/support}/tmpfile_posix.c +5 -5
  354. data/src/core/{support → lib/support}/tmpfile_win32.c +5 -5
  355. data/src/core/{support → lib/support}/wrap_memcpy.c +0 -0
  356. data/src/core/{surface → lib/surface}/alarm.c +3 -3
  357. data/src/core/{surface → lib/surface}/api_trace.c +1 -1
  358. data/src/core/{surface → lib/surface}/api_trace.h +4 -4
  359. data/src/core/{surface → lib/surface}/byte_buffer.c +3 -3
  360. data/src/core/{surface → lib/surface}/byte_buffer_reader.c +3 -3
  361. data/src/core/{surface → lib/surface}/call.c +145 -73
  362. data/src/core/{surface → lib/surface}/call.h +14 -7
  363. data/src/core/{surface → lib/surface}/call_details.c +1 -1
  364. data/src/core/{surface → lib/surface}/call_log_batch.c +2 -2
  365. data/src/core/{surface → lib/surface}/call_test_only.h +3 -3
  366. data/src/core/{surface → lib/surface}/channel.c +33 -34
  367. data/src/core/{surface → lib/surface}/channel.h +9 -9
  368. data/src/core/lib/surface/channel_init.c +140 -0
  369. data/src/core/lib/surface/channel_init.h +87 -0
  370. data/src/core/{surface → lib/surface}/channel_ping.c +4 -4
  371. data/src/core/lib/surface/channel_stack_type.c +54 -0
  372. data/src/core/{httpcli/parser.h → lib/surface/channel_stack_type.h} +22 -28
  373. data/src/core/{surface → lib/surface}/completion_queue.c +15 -11
  374. data/src/core/{surface → lib/surface}/completion_queue.h +4 -4
  375. data/src/core/{surface → lib/surface}/event_string.c +2 -2
  376. data/src/core/{surface → lib/surface}/event_string.h +3 -3
  377. data/src/core/lib/surface/init.c +217 -0
  378. data/src/core/{surface → lib/surface}/init.h +4 -3
  379. data/src/core/lib/surface/init_secure.c +89 -0
  380. data/src/core/{surface → lib/surface}/lame_client.c +31 -19
  381. data/src/core/{iomgr/pollset_set_windows.h → lib/surface/lame_client.h} +7 -5
  382. data/src/core/{surface → lib/surface}/metadata_array.c +1 -1
  383. data/src/core/{surface → lib/surface}/server.c +208 -183
  384. data/src/core/{surface → lib/surface}/server.h +6 -11
  385. data/src/core/{surface → lib/surface}/surface_trace.h +5 -5
  386. data/src/core/{surface → lib/surface}/validate_metadata.c +1 -1
  387. data/src/core/{surface → lib/surface}/version.c +2 -2
  388. data/src/core/{transport → lib/transport}/byte_stream.c +1 -1
  389. data/src/core/{transport → lib/transport}/byte_stream.h +4 -4
  390. data/src/core/{transport → lib/transport}/connectivity_state.c +2 -2
  391. data/src/core/{transport → lib/transport}/connectivity_state.h +4 -4
  392. data/src/core/{transport → lib/transport}/metadata.c +71 -19
  393. data/src/core/{transport → lib/transport}/metadata.h +11 -4
  394. data/src/core/{transport → lib/transport}/metadata_batch.c +2 -2
  395. data/src/core/{transport → lib/transport}/metadata_batch.h +4 -4
  396. data/src/core/{transport → lib/transport}/static_metadata.c +100 -32
  397. data/src/core/{transport → lib/transport}/static_metadata.h +58 -58
  398. data/src/core/{transport → lib/transport}/transport.c +25 -5
  399. data/src/core/{transport → lib/transport}/transport.h +41 -16
  400. data/src/core/{transport → lib/transport}/transport_impl.h +8 -5
  401. data/src/core/{transport → lib/transport}/transport_op_string.c +2 -2
  402. data/src/core/{tsi → lib/tsi}/fake_transport_security.c +18 -14
  403. data/src/core/{tsi → lib/tsi}/fake_transport_security.h +4 -4
  404. data/src/core/{tsi → lib/tsi}/ssl_transport_security.c +173 -63
  405. data/src/core/{tsi → lib/tsi}/ssl_transport_security.h +24 -6
  406. data/src/core/{tsi → lib/tsi}/ssl_types.h +3 -3
  407. data/src/core/{tsi → lib/tsi}/transport_security.c +12 -28
  408. data/src/core/{tsi → lib/tsi}/transport_security.h +4 -4
  409. data/src/core/{tsi → lib/tsi}/transport_security_interface.h +12 -3
  410. data/src/core/plugin_registry/grpc_plugin_registry.c +66 -0
  411. data/src/ruby/ext/grpc/extconf.rb +14 -20
  412. data/src/ruby/ext/grpc/rb_byte_buffer.c +2 -3
  413. data/src/ruby/ext/grpc/rb_call.c +37 -4
  414. data/src/ruby/ext/grpc/rb_call_credentials.c +13 -3
  415. data/src/ruby/ext/grpc/rb_channel.c +2 -3
  416. data/src/ruby/ext/grpc/rb_channel_args.c +2 -3
  417. data/src/ruby/ext/grpc/rb_channel_credentials.c +31 -3
  418. data/src/ruby/ext/grpc/rb_completion_queue.c +2 -2
  419. data/src/ruby/ext/grpc/rb_event_thread.c +1 -1
  420. data/src/ruby/ext/grpc/rb_grpc.c +4 -2
  421. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +8 -0
  422. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +14 -2
  423. data/src/ruby/ext/grpc/rb_server.c +2 -3
  424. data/src/ruby/ext/grpc/rb_server_credentials.c +16 -13
  425. data/src/ruby/ext/grpc/rb_signal.c +70 -0
  426. data/src/ruby/ext/grpc/rb_signal.h +39 -0
  427. data/src/ruby/lib/grpc.rb +21 -13
  428. data/src/ruby/lib/grpc/core/time_consts.rb +2 -2
  429. data/src/ruby/lib/grpc/errors.rb +2 -2
  430. data/src/ruby/lib/grpc/generic/active_call.rb +10 -3
  431. data/src/ruby/lib/grpc/generic/bidi_call.rb +2 -2
  432. data/src/ruby/lib/grpc/generic/client_stub.rb +10 -7
  433. data/src/ruby/lib/grpc/generic/rpc_desc.rb +2 -2
  434. data/src/ruby/lib/grpc/generic/rpc_server.rb +21 -61
  435. data/src/ruby/lib/grpc/generic/service.rb +5 -15
  436. data/src/ruby/lib/grpc/grpc.rb +3 -3
  437. data/src/ruby/{bin/interop/interop_server.rb → lib/grpc/signals.rb} +39 -20
  438. data/src/ruby/lib/grpc/version.rb +2 -2
  439. data/src/ruby/pb/generate_proto_ruby.sh +9 -2
  440. data/src/ruby/pb/grpc/health/checker.rb +1 -1
  441. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services.rb +28 -0
  442. data/src/ruby/pb/grpc/testing/metrics.rb +28 -0
  443. data/src/ruby/pb/grpc/testing/metrics_services.rb +27 -0
  444. data/src/ruby/pb/test/client.rb +12 -23
  445. data/src/ruby/pb/test/server.rb +1 -1
  446. data/src/ruby/spec/client_server_spec.rb +1 -1
  447. data/src/ruby/spec/generic/client_stub_spec.rb +18 -17
  448. data/src/ruby/spec/generic/rpc_server_spec.rb +23 -7
  449. data/src/ruby/spec/generic/service_spec.rb +0 -69
  450. data/src/ruby/{bin/interop/interop_client.rb → spec/pb/duplicate/codegen_spec.rb} +41 -21
  451. data/src/ruby/spec/pb/health/checker_spec.rb +1 -1
  452. data/third_party/boringssl/crypto/asn1/a_bitstr.c +184 -176
  453. data/third_party/boringssl/crypto/asn1/a_bool.c +42 -44
  454. data/third_party/boringssl/crypto/asn1/a_bytes.c +236 -245
  455. data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +173 -192
  456. data/third_party/boringssl/crypto/asn1/a_dup.c +43 -35
  457. data/third_party/boringssl/crypto/asn1/a_enum.c +107 -109
  458. data/third_party/boringssl/crypto/asn1/a_gentm.c +180 -181
  459. data/third_party/boringssl/crypto/asn1/a_i2d_fp.c +73 -80
  460. data/third_party/boringssl/crypto/asn1/a_int.c +357 -353
  461. data/third_party/boringssl/crypto/asn1/a_mbstr.c +272 -253
  462. data/third_party/boringssl/crypto/asn1/a_object.c +293 -309
  463. data/third_party/boringssl/crypto/asn1/a_octet.c +13 -6
  464. data/third_party/boringssl/crypto/asn1/a_print.c +54 -52
  465. data/third_party/boringssl/crypto/asn1/a_strnid.c +179 -157
  466. data/third_party/boringssl/crypto/asn1/a_time.c +125 -129
  467. data/third_party/boringssl/crypto/asn1/a_type.c +79 -86
  468. data/third_party/boringssl/crypto/asn1/a_utctm.c +246 -255
  469. data/third_party/boringssl/crypto/asn1/a_utf8.c +159 -135
  470. data/third_party/boringssl/crypto/asn1/asn1_lib.c +361 -368
  471. data/third_party/boringssl/crypto/asn1/asn1_locl.h +11 -11
  472. data/third_party/boringssl/crypto/asn1/asn1_par.c +309 -351
  473. data/third_party/boringssl/crypto/asn1/asn_pack.c +30 -29
  474. data/third_party/boringssl/crypto/asn1/bio_asn1.c +375 -394
  475. data/third_party/boringssl/crypto/asn1/bio_ndef.c +146 -149
  476. data/third_party/boringssl/crypto/asn1/f_enum.c +128 -134
  477. data/third_party/boringssl/crypto/asn1/f_int.c +131 -139
  478. data/third_party/boringssl/crypto/asn1/f_string.c +125 -133
  479. data/third_party/boringssl/crypto/asn1/t_bitst.c +30 -29
  480. data/third_party/boringssl/crypto/asn1/t_pkey.c +45 -47
  481. data/third_party/boringssl/crypto/asn1/tasn_dec.c +1099 -1216
  482. data/third_party/boringssl/crypto/asn1/tasn_enc.c +556 -592
  483. data/third_party/boringssl/crypto/asn1/tasn_fre.c +175 -193
  484. data/third_party/boringssl/crypto/asn1/tasn_new.c +271 -288
  485. data/third_party/boringssl/crypto/asn1/tasn_prn.c +462 -508
  486. data/third_party/boringssl/crypto/asn1/tasn_typ.c +28 -21
  487. data/third_party/boringssl/crypto/asn1/x_bignum.c +62 -52
  488. data/third_party/boringssl/crypto/asn1/x_long.c +101 -86
  489. data/third_party/boringssl/crypto/bio/buffer.c +3 -3
  490. data/third_party/boringssl/crypto/bn/asm/x86_64-gcc.c +8 -68
  491. data/third_party/boringssl/crypto/bn/bn.c +1 -1
  492. data/third_party/boringssl/crypto/bn/bn_asn1.c +9 -22
  493. data/third_party/boringssl/crypto/bn/convert.c +9 -4
  494. data/third_party/boringssl/crypto/bn/div.c +0 -20
  495. data/third_party/boringssl/crypto/bn/exponentiation.c +22 -13
  496. data/third_party/boringssl/crypto/bn/generic.c +6 -242
  497. data/third_party/boringssl/crypto/bn/internal.h +9 -70
  498. data/third_party/boringssl/crypto/bn/montgomery.c +1 -2
  499. data/third_party/boringssl/crypto/bn/mul.c +6 -26
  500. data/third_party/boringssl/crypto/bn/rsaz_exp.c +21 -28
  501. data/third_party/boringssl/crypto/bytestring/asn1_compat.c +51 -0
  502. data/third_party/boringssl/crypto/bytestring/ber.c +128 -87
  503. data/third_party/boringssl/crypto/bytestring/cbb.c +37 -3
  504. data/third_party/boringssl/crypto/bytestring/internal.h +39 -10
  505. data/third_party/boringssl/crypto/chacha/chacha_vec.c +18 -13
  506. data/third_party/boringssl/crypto/cipher/e_aes.c +2 -2
  507. data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +4 -9
  508. data/third_party/boringssl/crypto/cipher/tls_cbc.c +39 -10
  509. data/third_party/boringssl/crypto/conf/conf.c +9 -0
  510. data/third_party/boringssl/crypto/cpu-intel.c +1 -1
  511. data/third_party/boringssl/crypto/crypto.c +2 -0
  512. data/third_party/boringssl/crypto/curve25519/curve25519.c +125 -120
  513. data/third_party/boringssl/crypto/curve25519/internal.h +45 -0
  514. data/third_party/boringssl/crypto/curve25519/x25519-x86_64.c +225 -0
  515. data/third_party/boringssl/crypto/dh/check.c +32 -10
  516. data/third_party/boringssl/crypto/dh/dh.c +1 -1
  517. data/third_party/boringssl/crypto/digest/md32_common.h +0 -60
  518. data/third_party/boringssl/crypto/dsa/dsa.c +47 -21
  519. data/third_party/boringssl/crypto/dsa/dsa_asn1.c +249 -64
  520. data/third_party/boringssl/crypto/ec/ec.c +45 -31
  521. data/third_party/boringssl/crypto/ec/ec_asn1.c +315 -382
  522. data/third_party/boringssl/crypto/ec/ec_key.c +1 -4
  523. data/third_party/boringssl/crypto/ec/ec_montgomery.c +0 -9
  524. data/third_party/boringssl/crypto/ec/internal.h +1 -19
  525. data/third_party/boringssl/crypto/ec/oct.c +12 -0
  526. data/third_party/boringssl/crypto/ec/p224-64.c +4 -65
  527. data/third_party/boringssl/crypto/ec/p256-64.c +9 -71
  528. data/third_party/boringssl/crypto/ec/p256-x86_64-table.h +1 -6
  529. data/third_party/boringssl/crypto/ec/p256-x86_64.c +3 -13
  530. data/third_party/boringssl/crypto/ec/simple.c +0 -76
  531. data/third_party/boringssl/crypto/ecdsa/ecdsa.c +1 -1
  532. data/third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c +10 -24
  533. data/third_party/boringssl/crypto/evp/evp.c +4 -3
  534. data/third_party/boringssl/crypto/evp/evp_asn1.c +101 -0
  535. data/third_party/boringssl/crypto/evp/evp_ctx.c +22 -51
  536. data/third_party/boringssl/crypto/evp/internal.h +28 -27
  537. data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +78 -249
  538. data/third_party/boringssl/crypto/evp/p_ec.c +19 -66
  539. data/third_party/boringssl/crypto/evp/p_ec_asn1.c +74 -231
  540. data/third_party/boringssl/crypto/evp/p_rsa.c +90 -13
  541. data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +49 -48
  542. data/third_party/boringssl/crypto/internal.h +16 -1
  543. data/third_party/boringssl/crypto/mem.c +2 -2
  544. data/third_party/boringssl/crypto/modes/ctr.c +2 -1
  545. data/third_party/boringssl/crypto/modes/gcm.c +5 -3
  546. data/third_party/boringssl/crypto/obj/obj_dat.h +6 -3
  547. data/third_party/boringssl/crypto/pem/pem_all.c +83 -102
  548. data/third_party/boringssl/crypto/pem/pem_info.c +286 -309
  549. data/third_party/boringssl/crypto/pem/pem_lib.c +690 -710
  550. data/third_party/boringssl/crypto/pem/pem_oth.c +15 -16
  551. data/third_party/boringssl/crypto/pem/pem_pk8.c +132 -119
  552. data/third_party/boringssl/crypto/pem/pem_pkey.c +144 -220
  553. data/third_party/boringssl/crypto/pem/pem_x509.c +3 -3
  554. data/third_party/boringssl/crypto/pem/pem_xaux.c +5 -4
  555. data/third_party/boringssl/crypto/pkcs8/pkcs8.c +54 -60
  556. data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +3 -1
  557. data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +48 -50
  558. data/third_party/boringssl/crypto/rand/rand.c +2 -0
  559. data/third_party/boringssl/crypto/rsa/blinding.c +8 -48
  560. data/third_party/boringssl/crypto/rsa/internal.h +1 -9
  561. data/third_party/boringssl/crypto/rsa/padding.c +73 -77
  562. data/third_party/boringssl/crypto/rsa/rsa.c +1 -1
  563. data/third_party/boringssl/crypto/rsa/rsa_asn1.c +27 -46
  564. data/third_party/boringssl/crypto/rsa/rsa_impl.c +23 -34
  565. data/third_party/boringssl/crypto/test/scoped_types.h +3 -0
  566. data/third_party/boringssl/crypto/thread_win.c +15 -13
  567. data/third_party/boringssl/crypto/time_support.c +0 -6
  568. data/third_party/boringssl/crypto/x509/a_digest.c +26 -27
  569. data/third_party/boringssl/crypto/x509/a_sign.c +63 -64
  570. data/third_party/boringssl/crypto/x509/a_strex.c +482 -413
  571. data/third_party/boringssl/crypto/x509/a_verify.c +45 -51
  572. data/third_party/boringssl/crypto/x509/asn1_gen.c +715 -769
  573. data/third_party/boringssl/crypto/x509/by_dir.c +355 -393
  574. data/third_party/boringssl/crypto/x509/by_file.c +186 -206
  575. data/third_party/boringssl/crypto/x509/charmap.h +11 -11
  576. data/third_party/boringssl/crypto/x509/i2d_pr.c +21 -22
  577. data/third_party/boringssl/crypto/x509/t_crl.c +50 -51
  578. data/third_party/boringssl/crypto/x509/t_x509.c +414 -406
  579. data/third_party/boringssl/crypto/x509/t_x509a.c +44 -42
  580. data/third_party/boringssl/crypto/x509/vpm_int.h +13 -13
  581. data/third_party/boringssl/crypto/x509/x509_att.c +241 -219
  582. data/third_party/boringssl/crypto/x509/x509_cmp.c +343 -359
  583. data/third_party/boringssl/crypto/x509/x509_d2.c +36 -35
  584. data/third_party/boringssl/crypto/x509/x509_def.c +23 -13
  585. data/third_party/boringssl/crypto/x509/x509_ext.c +75 -75
  586. data/third_party/boringssl/crypto/x509/x509_lu.c +574 -612
  587. data/third_party/boringssl/crypto/x509/x509_obj.c +104 -115
  588. data/third_party/boringssl/crypto/x509/x509_r2x.c +40 -40
  589. data/third_party/boringssl/crypto/x509/x509_req.c +181 -174
  590. data/third_party/boringssl/crypto/x509/x509_set.c +71 -76
  591. data/third_party/boringssl/crypto/x509/x509_trs.c +193 -171
  592. data/third_party/boringssl/crypto/x509/x509_txt.c +135 -138
  593. data/third_party/boringssl/crypto/x509/x509_v3.c +174 -167
  594. data/third_party/boringssl/crypto/x509/x509_vfy.c +2079 -2130
  595. data/third_party/boringssl/crypto/x509/x509_vpm.c +486 -522
  596. data/third_party/boringssl/crypto/x509/x509cset.c +96 -99
  597. data/third_party/boringssl/crypto/x509/x509name.c +280 -275
  598. data/third_party/boringssl/crypto/x509/x509rset.c +15 -14
  599. data/third_party/boringssl/crypto/x509/x509spki.c +62 -60
  600. data/third_party/boringssl/crypto/x509/x509type.c +58 -60
  601. data/third_party/boringssl/crypto/x509/x_algor.c +70 -73
  602. data/third_party/boringssl/crypto/x509/x_all.c +282 -328
  603. data/third_party/boringssl/crypto/x509/x_attrib.c +36 -42
  604. data/third_party/boringssl/crypto/x509/x_crl.c +397 -418
  605. data/third_party/boringssl/crypto/x509/x_exten.c +5 -5
  606. data/third_party/boringssl/crypto/x509/x_info.c +30 -27
  607. data/third_party/boringssl/crypto/x509/x_name.c +387 -388
  608. data/third_party/boringssl/crypto/x509/x_pkey.c +32 -29
  609. data/third_party/boringssl/crypto/x509/x_pubkey.c +261 -280
  610. data/third_party/boringssl/crypto/x509/x_req.c +30 -33
  611. data/third_party/boringssl/crypto/x509/x_sig.c +2 -2
  612. data/third_party/boringssl/crypto/x509/x_spki.c +9 -7
  613. data/third_party/boringssl/crypto/x509/x_val.c +2 -2
  614. data/third_party/boringssl/crypto/x509/x_x509.c +120 -119
  615. data/third_party/boringssl/crypto/x509/x_x509a.c +99 -91
  616. data/third_party/boringssl/crypto/x509v3/ext_dat.h +57 -51
  617. data/third_party/boringssl/crypto/x509v3/pcy_cache.c +199 -214
  618. data/third_party/boringssl/crypto/x509v3/pcy_data.c +57 -64
  619. data/third_party/boringssl/crypto/x509v3/pcy_int.h +95 -90
  620. data/third_party/boringssl/crypto/x509v3/pcy_lib.c +86 -87
  621. data/third_party/boringssl/crypto/x509v3/pcy_map.c +61 -64
  622. data/third_party/boringssl/crypto/x509v3/pcy_node.c +108 -117
  623. data/third_party/boringssl/crypto/x509v3/pcy_tree.c +676 -724
  624. data/third_party/boringssl/crypto/x509v3/v3_akey.c +128 -136
  625. data/third_party/boringssl/crypto/x509v3/v3_akeya.c +7 -6
  626. data/third_party/boringssl/crypto/x509v3/v3_alt.c +499 -507
  627. data/third_party/boringssl/crypto/x509v3/v3_bcons.c +54 -47
  628. data/third_party/boringssl/crypto/x509v3/v3_bitst.c +67 -67
  629. data/third_party/boringssl/crypto/x509v3/v3_conf.c +330 -328
  630. data/third_party/boringssl/crypto/x509v3/v3_cpols.c +354 -338
  631. data/third_party/boringssl/crypto/x509v3/v3_crld.c +441 -496
  632. data/third_party/boringssl/crypto/x509v3/v3_enum.c +35 -33
  633. data/third_party/boringssl/crypto/x509v3/v3_extku.c +66 -63
  634. data/third_party/boringssl/crypto/x509v3/v3_genn.c +157 -159
  635. data/third_party/boringssl/crypto/x509v3/v3_ia5.c +45 -43
  636. data/third_party/boringssl/crypto/x509v3/v3_info.c +124 -112
  637. data/third_party/boringssl/crypto/x509v3/v3_int.c +30 -26
  638. data/third_party/boringssl/crypto/x509v3/v3_lib.c +231 -204
  639. data/third_party/boringssl/crypto/x509v3/v3_ncons.c +353 -381
  640. data/third_party/boringssl/crypto/x509v3/v3_pci.c +252 -270
  641. data/third_party/boringssl/crypto/x509v3/v3_pcia.c +9 -8
  642. data/third_party/boringssl/crypto/x509v3/v3_pcons.c +58 -61
  643. data/third_party/boringssl/crypto/x509v3/v3_pku.c +35 -34
  644. data/third_party/boringssl/crypto/x509v3/v3_pmaps.c +72 -74
  645. data/third_party/boringssl/crypto/x509v3/v3_prn.c +146 -121
  646. data/third_party/boringssl/crypto/x509v3/v3_purp.c +651 -582
  647. data/third_party/boringssl/crypto/x509v3/v3_skey.c +76 -72
  648. data/third_party/boringssl/crypto/x509v3/v3_sxnet.c +139 -131
  649. data/third_party/boringssl/crypto/x509v3/v3_utl.c +1072 -1068
  650. data/third_party/boringssl/include/openssl/asn1.h +40 -38
  651. data/third_party/boringssl/include/openssl/base.h +10 -1
  652. data/third_party/boringssl/include/openssl/bio.h +10 -11
  653. data/third_party/boringssl/include/openssl/bn.h +12 -9
  654. data/third_party/boringssl/include/openssl/buf.h +1 -1
  655. data/third_party/boringssl/include/openssl/bytestring.h +29 -0
  656. data/third_party/boringssl/include/openssl/conf.h +25 -0
  657. data/third_party/boringssl/include/openssl/crypto.h +6 -1
  658. data/third_party/boringssl/include/openssl/curve25519.h +6 -3
  659. data/third_party/boringssl/include/openssl/dh.h +7 -3
  660. data/third_party/boringssl/include/openssl/dsa.h +108 -51
  661. data/third_party/boringssl/include/openssl/ec.h +46 -21
  662. data/third_party/boringssl/include/openssl/ec_key.h +78 -42
  663. data/third_party/boringssl/include/openssl/ecdsa.h +4 -4
  664. data/third_party/boringssl/include/openssl/err.h +3 -2
  665. data/third_party/boringssl/include/openssl/evp.h +120 -37
  666. data/third_party/boringssl/include/openssl/mem.h +4 -13
  667. data/third_party/boringssl/include/openssl/obj_mac.h +4 -0
  668. data/third_party/boringssl/include/openssl/pem.h +0 -9
  669. data/third_party/boringssl/include/openssl/pkcs8.h +6 -2
  670. data/third_party/boringssl/include/openssl/rand.h +3 -0
  671. data/third_party/boringssl/include/openssl/rsa.h +42 -42
  672. data/third_party/boringssl/include/openssl/ssl.h +115 -41
  673. data/third_party/boringssl/include/openssl/stack.h +0 -3
  674. data/third_party/boringssl/include/openssl/stack_macros.h +0 -256
  675. data/third_party/boringssl/include/openssl/tls1.h +1 -1
  676. data/third_party/boringssl/include/openssl/x509.h +0 -2
  677. data/third_party/boringssl/include/openssl/x509_vfy.h +5 -0
  678. data/third_party/boringssl/ssl/d1_both.c +102 -101
  679. data/third_party/boringssl/ssl/d1_clnt.c +145 -150
  680. data/third_party/boringssl/ssl/d1_lib.c +63 -62
  681. data/third_party/boringssl/ssl/d1_pkt.c +73 -71
  682. data/third_party/boringssl/ssl/d1_srvr.c +116 -125
  683. data/third_party/boringssl/ssl/dtls_record.c +3 -3
  684. data/third_party/boringssl/ssl/internal.h +210 -208
  685. data/third_party/boringssl/ssl/pqueue/pqueue.c +2 -2
  686. data/third_party/boringssl/ssl/s3_both.c +116 -130
  687. data/third_party/boringssl/ssl/s3_clnt.c +589 -740
  688. data/third_party/boringssl/ssl/s3_enc.c +52 -151
  689. data/third_party/boringssl/ssl/s3_lib.c +70 -76
  690. data/third_party/boringssl/ssl/s3_pkt.c +105 -144
  691. data/third_party/boringssl/ssl/s3_srvr.c +542 -806
  692. data/third_party/boringssl/ssl/ssl_aead_ctx.c +1 -1
  693. data/third_party/boringssl/ssl/ssl_cert.c +2 -2
  694. data/third_party/boringssl/ssl/ssl_cipher.c +7 -3
  695. data/third_party/boringssl/ssl/ssl_ecdh.c +374 -0
  696. data/third_party/boringssl/ssl/ssl_lib.c +260 -221
  697. data/third_party/boringssl/ssl/ssl_session.c +17 -17
  698. data/third_party/boringssl/ssl/t1_enc.c +128 -273
  699. data/third_party/boringssl/ssl/t1_lib.c +134 -258
  700. data/third_party/boringssl/ssl/test/test_config.h +2 -0
  701. data/third_party/boringssl/ssl/tls_record.c +52 -15
  702. metadata +385 -359
  703. data/src/core/channel/client_uchannel.c +0 -243
  704. data/src/core/channel/client_uchannel.h +0 -60
  705. data/src/core/channel/connected_channel.h +0 -51
  706. data/src/core/client_config/lb_policies/pick_first.h +0 -43
  707. data/src/core/client_config/resolvers/dns_resolver.h +0 -42
  708. data/src/core/client_config/subchannel_factory.h +0 -66
  709. data/src/core/httpcli/parser.c +0 -211
  710. data/src/core/iomgr/fd_posix.c +0 -451
  711. data/src/core/iomgr/fd_posix.h +0 -192
  712. data/src/core/iomgr/pollset_multipoller_with_epoll.c +0 -324
  713. data/src/core/iomgr/pollset_multipoller_with_poll_posix.c +0 -234
  714. data/src/core/iomgr/pollset_posix.c +0 -633
  715. data/src/core/iomgr/pollset_posix.h +0 -153
  716. data/src/core/iomgr/pollset_set_posix.c +0 -202
  717. data/src/core/iomgr/pollset_set_posix.h +0 -45
  718. data/src/core/surface/init.c +0 -174
  719. data/src/core/surface/init_secure.c +0 -42
  720. data/src/core/surface/server_create.c +0 -48
  721. data/src/core/transport/chttp2/huffsyms.c +0 -297
  722. data/src/ruby/bin/grpc_ruby_interop_client +0 -33
  723. data/src/ruby/bin/grpc_ruby_interop_server +0 -33
  724. data/third_party/boringssl/crypto/dsa/internal.h +0 -78
@@ -174,154 +174,154 @@
174
174
  #include "../crypto/dh/internal.h"
175
175
 
176
176
 
177
- int ssl3_accept(SSL *s) {
177
+ int ssl3_accept(SSL *ssl) {
178
178
  BUF_MEM *buf = NULL;
179
179
  uint32_t alg_a;
180
180
  void (*cb)(const SSL *ssl, int type, int value) = NULL;
181
181
  int ret = -1;
182
182
  int new_state, state, skip = 0;
183
183
 
184
- assert(s->handshake_func == ssl3_accept);
185
- assert(s->server);
186
- assert(!SSL_IS_DTLS(s));
184
+ assert(ssl->handshake_func == ssl3_accept);
185
+ assert(ssl->server);
186
+ assert(!SSL_IS_DTLS(ssl));
187
187
 
188
188
  ERR_clear_error();
189
189
  ERR_clear_system_error();
190
190
 
191
- if (s->info_callback != NULL) {
192
- cb = s->info_callback;
193
- } else if (s->ctx->info_callback != NULL) {
194
- cb = s->ctx->info_callback;
191
+ if (ssl->info_callback != NULL) {
192
+ cb = ssl->info_callback;
193
+ } else if (ssl->ctx->info_callback != NULL) {
194
+ cb = ssl->ctx->info_callback;
195
195
  }
196
196
 
197
- s->in_handshake++;
197
+ ssl->in_handshake++;
198
198
 
199
- if (s->cert == NULL) {
199
+ if (ssl->cert == NULL) {
200
200
  OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATE_SET);
201
201
  return -1;
202
202
  }
203
203
 
204
204
  for (;;) {
205
- state = s->state;
205
+ state = ssl->state;
206
206
 
207
- switch (s->state) {
207
+ switch (ssl->state) {
208
208
  case SSL_ST_ACCEPT:
209
209
  if (cb != NULL) {
210
- cb(s, SSL_CB_HANDSHAKE_START, 1);
210
+ cb(ssl, SSL_CB_HANDSHAKE_START, 1);
211
211
  }
212
212
 
213
- if (s->init_buf == NULL) {
213
+ if (ssl->init_buf == NULL) {
214
214
  buf = BUF_MEM_new();
215
215
  if (!buf || !BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {
216
216
  ret = -1;
217
217
  goto end;
218
218
  }
219
- s->init_buf = buf;
219
+ ssl->init_buf = buf;
220
220
  buf = NULL;
221
221
  }
222
- s->init_num = 0;
222
+ ssl->init_num = 0;
223
223
 
224
224
  /* Enable a write buffer. This groups handshake messages within a flight
225
225
  * into a single write. */
226
- if (!ssl_init_wbio_buffer(s, 1)) {
226
+ if (!ssl_init_wbio_buffer(ssl, 1)) {
227
227
  ret = -1;
228
228
  goto end;
229
229
  }
230
230
 
231
- if (!ssl3_init_handshake_buffer(s)) {
231
+ if (!ssl3_init_handshake_buffer(ssl)) {
232
232
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
233
233
  ret = -1;
234
234
  goto end;
235
235
  }
236
236
 
237
- if (!s->s3->have_version) {
238
- s->state = SSL3_ST_SR_INITIAL_BYTES;
237
+ if (!ssl->s3->have_version) {
238
+ ssl->state = SSL3_ST_SR_INITIAL_BYTES;
239
239
  } else {
240
- s->state = SSL3_ST_SR_CLNT_HELLO_A;
240
+ ssl->state = SSL3_ST_SR_CLNT_HELLO_A;
241
241
  }
242
242
  break;
243
243
 
244
244
  case SSL3_ST_SR_INITIAL_BYTES:
245
- ret = ssl3_get_initial_bytes(s);
245
+ ret = ssl3_get_initial_bytes(ssl);
246
246
  if (ret <= 0) {
247
247
  goto end;
248
248
  }
249
- /* ssl3_get_initial_bytes sets s->state to one of
249
+ /* ssl3_get_initial_bytes sets ssl->state to one of
250
250
  * SSL3_ST_SR_V2_CLIENT_HELLO or SSL3_ST_SR_CLNT_HELLO_A on success. */
251
251
  break;
252
252
 
253
253
  case SSL3_ST_SR_V2_CLIENT_HELLO:
254
- ret = ssl3_get_v2_client_hello(s);
254
+ ret = ssl3_get_v2_client_hello(ssl);
255
255
  if (ret <= 0) {
256
256
  goto end;
257
257
  }
258
- s->state = SSL3_ST_SR_CLNT_HELLO_A;
258
+ ssl->state = SSL3_ST_SR_CLNT_HELLO_A;
259
259
  break;
260
260
 
261
261
  case SSL3_ST_SR_CLNT_HELLO_A:
262
262
  case SSL3_ST_SR_CLNT_HELLO_B:
263
263
  case SSL3_ST_SR_CLNT_HELLO_C:
264
264
  case SSL3_ST_SR_CLNT_HELLO_D:
265
- s->shutdown = 0;
266
- ret = ssl3_get_client_hello(s);
265
+ ssl->shutdown = 0;
266
+ ret = ssl3_get_client_hello(ssl);
267
267
  if (ret <= 0) {
268
268
  goto end;
269
269
  }
270
- s->state = SSL3_ST_SW_SRVR_HELLO_A;
271
- s->init_num = 0;
270
+ ssl->state = SSL3_ST_SW_SRVR_HELLO_A;
271
+ ssl->init_num = 0;
272
272
  break;
273
273
 
274
274
  case SSL3_ST_SW_SRVR_HELLO_A:
275
275
  case SSL3_ST_SW_SRVR_HELLO_B:
276
- ret = ssl3_send_server_hello(s);
276
+ ret = ssl3_send_server_hello(ssl);
277
277
  if (ret <= 0) {
278
278
  goto end;
279
279
  }
280
- if (s->hit) {
281
- if (s->tlsext_ticket_expected) {
282
- s->state = SSL3_ST_SW_SESSION_TICKET_A;
280
+ if (ssl->hit) {
281
+ if (ssl->tlsext_ticket_expected) {
282
+ ssl->state = SSL3_ST_SW_SESSION_TICKET_A;
283
283
  } else {
284
- s->state = SSL3_ST_SW_CHANGE_A;
284
+ ssl->state = SSL3_ST_SW_CHANGE_A;
285
285
  }
286
286
  } else {
287
- s->state = SSL3_ST_SW_CERT_A;
287
+ ssl->state = SSL3_ST_SW_CERT_A;
288
288
  }
289
- s->init_num = 0;
289
+ ssl->init_num = 0;
290
290
  break;
291
291
 
292
292
  case SSL3_ST_SW_CERT_A:
293
293
  case SSL3_ST_SW_CERT_B:
294
- if (ssl_cipher_has_server_public_key(s->s3->tmp.new_cipher)) {
295
- ret = ssl3_send_server_certificate(s);
294
+ if (ssl_cipher_has_server_public_key(ssl->s3->tmp.new_cipher)) {
295
+ ret = ssl3_send_server_certificate(ssl);
296
296
  if (ret <= 0) {
297
297
  goto end;
298
298
  }
299
- if (s->s3->tmp.certificate_status_expected) {
300
- s->state = SSL3_ST_SW_CERT_STATUS_A;
299
+ if (ssl->s3->tmp.certificate_status_expected) {
300
+ ssl->state = SSL3_ST_SW_CERT_STATUS_A;
301
301
  } else {
302
- s->state = SSL3_ST_SW_KEY_EXCH_A;
302
+ ssl->state = SSL3_ST_SW_KEY_EXCH_A;
303
303
  }
304
304
  } else {
305
305
  skip = 1;
306
- s->state = SSL3_ST_SW_KEY_EXCH_A;
306
+ ssl->state = SSL3_ST_SW_KEY_EXCH_A;
307
307
  }
308
- s->init_num = 0;
308
+ ssl->init_num = 0;
309
309
  break;
310
310
 
311
311
  case SSL3_ST_SW_CERT_STATUS_A:
312
312
  case SSL3_ST_SW_CERT_STATUS_B:
313
- ret = ssl3_send_certificate_status(s);
313
+ ret = ssl3_send_certificate_status(ssl);
314
314
  if (ret <= 0) {
315
315
  goto end;
316
316
  }
317
- s->state = SSL3_ST_SW_KEY_EXCH_A;
318
- s->init_num = 0;
317
+ ssl->state = SSL3_ST_SW_KEY_EXCH_A;
318
+ ssl->init_num = 0;
319
319
  break;
320
320
 
321
321
  case SSL3_ST_SW_KEY_EXCH_A:
322
322
  case SSL3_ST_SW_KEY_EXCH_B:
323
323
  case SSL3_ST_SW_KEY_EXCH_C:
324
- alg_a = s->s3->tmp.new_cipher->algorithm_auth;
324
+ alg_a = ssl->s3->tmp.new_cipher->algorithm_auth;
325
325
 
326
326
  /* Send a ServerKeyExchange message if:
327
327
  * - The key exchange is ephemeral or anonymous
@@ -330,9 +330,9 @@ int ssl3_accept(SSL *s) {
330
330
  *
331
331
  * TODO(davidben): This logic is currently duplicated in d1_srvr.c. Fix
332
332
  * this. In the meantime, keep them in sync. */
333
- if (ssl_cipher_requires_server_key_exchange(s->s3->tmp.new_cipher) ||
334
- ((alg_a & SSL_aPSK) && s->psk_identity_hint)) {
335
- ret = ssl3_send_server_key_exchange(s);
333
+ if (ssl_cipher_requires_server_key_exchange(ssl->s3->tmp.new_cipher) ||
334
+ ((alg_a & SSL_aPSK) && ssl->psk_identity_hint)) {
335
+ ret = ssl3_send_server_key_exchange(ssl);
336
336
  if (ret <= 0) {
337
337
  goto end;
338
338
  }
@@ -340,33 +340,33 @@ int ssl3_accept(SSL *s) {
340
340
  skip = 1;
341
341
  }
342
342
 
343
- s->state = SSL3_ST_SW_CERT_REQ_A;
344
- s->init_num = 0;
343
+ ssl->state = SSL3_ST_SW_CERT_REQ_A;
344
+ ssl->init_num = 0;
345
345
  break;
346
346
 
347
347
  case SSL3_ST_SW_CERT_REQ_A:
348
348
  case SSL3_ST_SW_CERT_REQ_B:
349
- if (s->s3->tmp.cert_request) {
350
- ret = ssl3_send_certificate_request(s);
349
+ if (ssl->s3->tmp.cert_request) {
350
+ ret = ssl3_send_certificate_request(ssl);
351
351
  if (ret <= 0) {
352
352
  goto end;
353
353
  }
354
354
  } else {
355
355
  skip = 1;
356
356
  }
357
- s->state = SSL3_ST_SW_SRVR_DONE_A;
358
- s->init_num = 0;
357
+ ssl->state = SSL3_ST_SW_SRVR_DONE_A;
358
+ ssl->init_num = 0;
359
359
  break;
360
360
 
361
361
  case SSL3_ST_SW_SRVR_DONE_A:
362
362
  case SSL3_ST_SW_SRVR_DONE_B:
363
- ret = ssl3_send_server_done(s);
363
+ ret = ssl3_send_server_done(ssl);
364
364
  if (ret <= 0) {
365
365
  goto end;
366
366
  }
367
- s->s3->tmp.next_state = SSL3_ST_SR_CERT_A;
368
- s->state = SSL3_ST_SW_FLUSH;
369
- s->init_num = 0;
367
+ ssl->s3->tmp.next_state = SSL3_ST_SR_CERT_A;
368
+ ssl->state = SSL3_ST_SW_FLUSH;
369
+ ssl->init_num = 0;
370
370
  break;
371
371
 
372
372
  case SSL3_ST_SW_FLUSH:
@@ -375,149 +375,142 @@ int ssl3_accept(SSL *s) {
375
375
  * in PR#1939. The proposed fix doesn't completely resolve this issue
376
376
  * as buggy implementations of BIO_CTRL_PENDING still exist. So instead
377
377
  * we just flush unconditionally. */
378
- s->rwstate = SSL_WRITING;
379
- if (BIO_flush(s->wbio) <= 0) {
378
+ ssl->rwstate = SSL_WRITING;
379
+ if (BIO_flush(ssl->wbio) <= 0) {
380
380
  ret = -1;
381
381
  goto end;
382
382
  }
383
- s->rwstate = SSL_NOTHING;
383
+ ssl->rwstate = SSL_NOTHING;
384
384
 
385
- s->state = s->s3->tmp.next_state;
385
+ ssl->state = ssl->s3->tmp.next_state;
386
386
  break;
387
387
 
388
388
  case SSL3_ST_SR_CERT_A:
389
389
  case SSL3_ST_SR_CERT_B:
390
- if (s->s3->tmp.cert_request) {
391
- ret = ssl3_get_client_certificate(s);
390
+ if (ssl->s3->tmp.cert_request) {
391
+ ret = ssl3_get_client_certificate(ssl);
392
392
  if (ret <= 0) {
393
393
  goto end;
394
394
  }
395
395
  }
396
- s->init_num = 0;
397
- s->state = SSL3_ST_SR_KEY_EXCH_A;
396
+ ssl->init_num = 0;
397
+ ssl->state = SSL3_ST_SR_KEY_EXCH_A;
398
398
  break;
399
399
 
400
400
  case SSL3_ST_SR_KEY_EXCH_A:
401
401
  case SSL3_ST_SR_KEY_EXCH_B:
402
402
  case SSL3_ST_SR_KEY_EXCH_C:
403
- ret = ssl3_get_client_key_exchange(s);
403
+ ret = ssl3_get_client_key_exchange(ssl);
404
404
  if (ret <= 0) {
405
405
  goto end;
406
406
  }
407
- s->state = SSL3_ST_SR_CERT_VRFY_A;
408
- s->init_num = 0;
407
+ ssl->state = SSL3_ST_SR_CERT_VRFY_A;
408
+ ssl->init_num = 0;
409
409
  break;
410
410
 
411
411
  case SSL3_ST_SR_CERT_VRFY_A:
412
412
  case SSL3_ST_SR_CERT_VRFY_B:
413
- ret = ssl3_get_cert_verify(s);
413
+ ret = ssl3_get_cert_verify(ssl);
414
414
  if (ret <= 0) {
415
415
  goto end;
416
416
  }
417
417
 
418
- s->state = SSL3_ST_SR_CHANGE;
419
- s->init_num = 0;
418
+ ssl->state = SSL3_ST_SR_CHANGE;
419
+ ssl->init_num = 0;
420
420
  break;
421
421
 
422
422
  case SSL3_ST_SR_CHANGE:
423
- ret = s->method->ssl_read_change_cipher_spec(s);
423
+ ret = ssl->method->ssl_read_change_cipher_spec(ssl);
424
424
  if (ret <= 0) {
425
425
  goto end;
426
426
  }
427
427
 
428
- if (!ssl3_do_change_cipher_spec(s)) {
428
+ if (!tls1_change_cipher_state(ssl, SSL3_CHANGE_CIPHER_SERVER_READ)) {
429
429
  ret = -1;
430
430
  goto end;
431
431
  }
432
432
 
433
- if (s->s3->next_proto_neg_seen) {
434
- s->state = SSL3_ST_SR_NEXT_PROTO_A;
435
- } else if (s->s3->tlsext_channel_id_valid) {
436
- s->state = SSL3_ST_SR_CHANNEL_ID_A;
433
+ if (ssl->s3->next_proto_neg_seen) {
434
+ ssl->state = SSL3_ST_SR_NEXT_PROTO_A;
435
+ } else if (ssl->s3->tlsext_channel_id_valid) {
436
+ ssl->state = SSL3_ST_SR_CHANNEL_ID_A;
437
437
  } else {
438
- s->state = SSL3_ST_SR_FINISHED_A;
438
+ ssl->state = SSL3_ST_SR_FINISHED_A;
439
439
  }
440
440
  break;
441
441
 
442
442
  case SSL3_ST_SR_NEXT_PROTO_A:
443
443
  case SSL3_ST_SR_NEXT_PROTO_B:
444
- ret = ssl3_get_next_proto(s);
444
+ ret = ssl3_get_next_proto(ssl);
445
445
  if (ret <= 0) {
446
446
  goto end;
447
447
  }
448
- s->init_num = 0;
449
- if (s->s3->tlsext_channel_id_valid) {
450
- s->state = SSL3_ST_SR_CHANNEL_ID_A;
448
+ ssl->init_num = 0;
449
+ if (ssl->s3->tlsext_channel_id_valid) {
450
+ ssl->state = SSL3_ST_SR_CHANNEL_ID_A;
451
451
  } else {
452
- s->state = SSL3_ST_SR_FINISHED_A;
452
+ ssl->state = SSL3_ST_SR_FINISHED_A;
453
453
  }
454
454
  break;
455
455
 
456
456
  case SSL3_ST_SR_CHANNEL_ID_A:
457
457
  case SSL3_ST_SR_CHANNEL_ID_B:
458
- ret = ssl3_get_channel_id(s);
458
+ ret = ssl3_get_channel_id(ssl);
459
459
  if (ret <= 0) {
460
460
  goto end;
461
461
  }
462
- s->init_num = 0;
463
- s->state = SSL3_ST_SR_FINISHED_A;
462
+ ssl->init_num = 0;
463
+ ssl->state = SSL3_ST_SR_FINISHED_A;
464
464
  break;
465
465
 
466
466
  case SSL3_ST_SR_FINISHED_A:
467
467
  case SSL3_ST_SR_FINISHED_B:
468
- ret =
469
- ssl3_get_finished(s, SSL3_ST_SR_FINISHED_A, SSL3_ST_SR_FINISHED_B);
468
+ ret = ssl3_get_finished(ssl, SSL3_ST_SR_FINISHED_A,
469
+ SSL3_ST_SR_FINISHED_B);
470
470
  if (ret <= 0) {
471
471
  goto end;
472
472
  }
473
473
 
474
- if (s->hit) {
475
- s->state = SSL_ST_OK;
476
- } else if (s->tlsext_ticket_expected) {
477
- s->state = SSL3_ST_SW_SESSION_TICKET_A;
474
+ if (ssl->hit) {
475
+ ssl->state = SSL_ST_OK;
476
+ } else if (ssl->tlsext_ticket_expected) {
477
+ ssl->state = SSL3_ST_SW_SESSION_TICKET_A;
478
478
  } else {
479
- s->state = SSL3_ST_SW_CHANGE_A;
479
+ ssl->state = SSL3_ST_SW_CHANGE_A;
480
480
  }
481
481
  /* If this is a full handshake with ChannelID then record the hashshake
482
- * hashes in |s->session| in case we need them to verify a ChannelID
482
+ * hashes in |ssl->session| in case we need them to verify a ChannelID
483
483
  * signature on a resumption of this session in the future. */
484
- if (!s->hit && s->s3->tlsext_channel_id_valid) {
485
- ret = tls1_record_handshake_hashes_for_channel_id(s);
484
+ if (!ssl->hit && ssl->s3->tlsext_channel_id_valid) {
485
+ ret = tls1_record_handshake_hashes_for_channel_id(ssl);
486
486
  if (ret <= 0) {
487
487
  goto end;
488
488
  }
489
489
  }
490
- s->init_num = 0;
490
+ ssl->init_num = 0;
491
491
  break;
492
492
 
493
493
  case SSL3_ST_SW_SESSION_TICKET_A:
494
494
  case SSL3_ST_SW_SESSION_TICKET_B:
495
- ret = ssl3_send_new_session_ticket(s);
495
+ ret = ssl3_send_new_session_ticket(ssl);
496
496
  if (ret <= 0) {
497
497
  goto end;
498
498
  }
499
- s->state = SSL3_ST_SW_CHANGE_A;
500
- s->init_num = 0;
499
+ ssl->state = SSL3_ST_SW_CHANGE_A;
500
+ ssl->init_num = 0;
501
501
  break;
502
502
 
503
503
  case SSL3_ST_SW_CHANGE_A:
504
504
  case SSL3_ST_SW_CHANGE_B:
505
- s->session->cipher = s->s3->tmp.new_cipher;
506
- if (!s->enc_method->setup_key_block(s)) {
507
- ret = -1;
508
- goto end;
509
- }
510
-
511
- ret = ssl3_send_change_cipher_spec(s, SSL3_ST_SW_CHANGE_A,
505
+ ret = ssl3_send_change_cipher_spec(ssl, SSL3_ST_SW_CHANGE_A,
512
506
  SSL3_ST_SW_CHANGE_B);
513
507
  if (ret <= 0) {
514
508
  goto end;
515
509
  }
516
- s->state = SSL3_ST_SW_FINISHED_A;
517
- s->init_num = 0;
510
+ ssl->state = SSL3_ST_SW_FINISHED_A;
511
+ ssl->init_num = 0;
518
512
 
519
- if (!s->enc_method->change_cipher_state(
520
- s, SSL3_CHANGE_CIPHER_SERVER_WRITE)) {
513
+ if (!tls1_change_cipher_state(ssl, SSL3_CHANGE_CIPHER_SERVER_WRITE)) {
521
514
  ret = -1;
522
515
  goto end;
523
516
  }
@@ -525,49 +518,47 @@ int ssl3_accept(SSL *s) {
525
518
 
526
519
  case SSL3_ST_SW_FINISHED_A:
527
520
  case SSL3_ST_SW_FINISHED_B:
528
- ret =
529
- ssl3_send_finished(s, SSL3_ST_SW_FINISHED_A, SSL3_ST_SW_FINISHED_B,
530
- s->enc_method->server_finished_label,
531
- s->enc_method->server_finished_label_len);
521
+ ret = ssl3_send_finished(ssl, SSL3_ST_SW_FINISHED_A,
522
+ SSL3_ST_SW_FINISHED_B);
532
523
  if (ret <= 0) {
533
524
  goto end;
534
525
  }
535
- s->state = SSL3_ST_SW_FLUSH;
536
- if (s->hit) {
537
- s->s3->tmp.next_state = SSL3_ST_SR_CHANGE;
526
+ ssl->state = SSL3_ST_SW_FLUSH;
527
+ if (ssl->hit) {
528
+ ssl->s3->tmp.next_state = SSL3_ST_SR_CHANGE;
538
529
  } else {
539
- s->s3->tmp.next_state = SSL_ST_OK;
530
+ ssl->s3->tmp.next_state = SSL_ST_OK;
540
531
  }
541
- s->init_num = 0;
532
+ ssl->init_num = 0;
542
533
  break;
543
534
 
544
535
  case SSL_ST_OK:
545
536
  /* clean a few things up */
546
- ssl3_cleanup_key_block(s);
537
+ ssl3_cleanup_key_block(ssl);
547
538
 
548
- BUF_MEM_free(s->init_buf);
549
- s->init_buf = NULL;
539
+ BUF_MEM_free(ssl->init_buf);
540
+ ssl->init_buf = NULL;
550
541
 
551
542
  /* remove buffering on output */
552
- ssl_free_wbio_buffer(s);
543
+ ssl_free_wbio_buffer(ssl);
553
544
 
554
- s->init_num = 0;
545
+ ssl->init_num = 0;
555
546
 
556
547
  /* If we aren't retaining peer certificates then we can discard it
557
548
  * now. */
558
- if (s->ctx->retain_only_sha256_of_client_certs) {
559
- X509_free(s->session->peer);
560
- s->session->peer = NULL;
561
- sk_X509_pop_free(s->session->cert_chain, X509_free);
562
- s->session->cert_chain = NULL;
549
+ if (ssl->ctx->retain_only_sha256_of_client_certs) {
550
+ X509_free(ssl->session->peer);
551
+ ssl->session->peer = NULL;
552
+ sk_X509_pop_free(ssl->session->cert_chain, X509_free);
553
+ ssl->session->cert_chain = NULL;
563
554
  }
564
555
 
565
- s->s3->initial_handshake_complete = 1;
556
+ ssl->s3->initial_handshake_complete = 1;
566
557
 
567
- ssl_update_cache(s, SSL_SESS_CACHE_SERVER);
558
+ ssl_update_cache(ssl, SSL_SESS_CACHE_SERVER);
568
559
 
569
560
  if (cb != NULL) {
570
- cb(s, SSL_CB_HANDSHAKE_DONE, 1);
561
+ cb(ssl, SSL_CB_HANDSHAKE_DONE, 1);
571
562
  }
572
563
 
573
564
  ret = 1;
@@ -579,34 +570,35 @@ int ssl3_accept(SSL *s) {
579
570
  goto end;
580
571
  }
581
572
 
582
- if (!s->s3->tmp.reuse_message && !skip && cb != NULL && s->state != state) {
583
- new_state = s->state;
584
- s->state = state;
585
- cb(s, SSL_CB_ACCEPT_LOOP, 1);
586
- s->state = new_state;
573
+ if (!ssl->s3->tmp.reuse_message && !skip && cb != NULL &&
574
+ ssl->state != state) {
575
+ new_state = ssl->state;
576
+ ssl->state = state;
577
+ cb(ssl, SSL_CB_ACCEPT_LOOP, 1);
578
+ ssl->state = new_state;
587
579
  }
588
580
  skip = 0;
589
581
  }
590
582
 
591
583
  end:
592
- s->in_handshake--;
584
+ ssl->in_handshake--;
593
585
  BUF_MEM_free(buf);
594
586
  if (cb != NULL) {
595
- cb(s, SSL_CB_ACCEPT_EXIT, ret);
587
+ cb(ssl, SSL_CB_ACCEPT_EXIT, ret);
596
588
  }
597
589
  return ret;
598
590
  }
599
591
 
600
- int ssl3_get_initial_bytes(SSL *s) {
592
+ int ssl3_get_initial_bytes(SSL *ssl) {
601
593
  /* Read the first 5 bytes, the size of the TLS record header. This is
602
594
  * sufficient to detect a V2ClientHello and ensures that we never read beyond
603
595
  * the first record. */
604
- int ret = ssl_read_buffer_extend_to(s, SSL3_RT_HEADER_LENGTH);
596
+ int ret = ssl_read_buffer_extend_to(ssl, SSL3_RT_HEADER_LENGTH);
605
597
  if (ret <= 0) {
606
598
  return ret;
607
599
  }
608
- assert(ssl_read_buffer_len(s) == SSL3_RT_HEADER_LENGTH);
609
- const uint8_t *p = ssl_read_buffer(s);
600
+ assert(ssl_read_buffer_len(ssl) == SSL3_RT_HEADER_LENGTH);
601
+ const uint8_t *p = ssl_read_buffer(ssl);
610
602
 
611
603
  /* Some dedicated error codes for protocol mixups should the application wish
612
604
  * to interpret them differently. (These do not overlap with ClientHello or
@@ -627,16 +619,16 @@ int ssl3_get_initial_bytes(SSL *s) {
627
619
  if ((p[0] & 0x80) && p[2] == SSL2_MT_CLIENT_HELLO &&
628
620
  p[3] >= SSL3_VERSION_MAJOR) {
629
621
  /* This is a V2ClientHello. */
630
- s->state = SSL3_ST_SR_V2_CLIENT_HELLO;
622
+ ssl->state = SSL3_ST_SR_V2_CLIENT_HELLO;
631
623
  return 1;
632
624
  }
633
625
 
634
626
  /* Fall through to the standard logic. */
635
- s->state = SSL3_ST_SR_CLNT_HELLO_A;
627
+ ssl->state = SSL3_ST_SR_CLNT_HELLO_A;
636
628
  return 1;
637
629
  }
638
630
 
639
- int ssl3_get_v2_client_hello(SSL *s) {
631
+ int ssl3_get_v2_client_hello(SSL *ssl) {
640
632
  const uint8_t *p;
641
633
  int ret;
642
634
  CBS v2_client_hello, cipher_specs, session_id, challenge;
@@ -647,8 +639,8 @@ int ssl3_get_v2_client_hello(SSL *s) {
647
639
  uint8_t random[SSL3_RANDOM_SIZE];
648
640
 
649
641
  /* Determine the length of the V2ClientHello. */
650
- assert(ssl_read_buffer_len(s) >= SSL3_RT_HEADER_LENGTH);
651
- p = ssl_read_buffer(s);
642
+ assert(ssl_read_buffer_len(ssl) >= SSL3_RT_HEADER_LENGTH);
643
+ p = ssl_read_buffer(ssl);
652
644
  msg_length = ((p[0] & 0x7f) << 8) | p[1];
653
645
  if (msg_length > (1024 * 4)) {
654
646
  OPENSSL_PUT_ERROR(SSL, SSL_R_RECORD_TOO_LARGE);
@@ -663,22 +655,22 @@ int ssl3_get_v2_client_hello(SSL *s) {
663
655
  }
664
656
 
665
657
  /* Read the remainder of the V2ClientHello. */
666
- ret = ssl_read_buffer_extend_to(s, 2 + msg_length);
658
+ ret = ssl_read_buffer_extend_to(ssl, 2 + msg_length);
667
659
  if (ret <= 0) {
668
660
  return ret;
669
661
  }
670
- assert(ssl_read_buffer_len(s) == msg_length + 2);
671
- CBS_init(&v2_client_hello, ssl_read_buffer(s) + 2, msg_length);
662
+ assert(ssl_read_buffer_len(ssl) == msg_length + 2);
663
+ CBS_init(&v2_client_hello, ssl_read_buffer(ssl) + 2, msg_length);
672
664
 
673
665
  /* The V2ClientHello without the length is incorporated into the handshake
674
666
  * hash. */
675
- if (!ssl3_update_handshake_hash(s, CBS_data(&v2_client_hello),
667
+ if (!ssl3_update_handshake_hash(ssl, CBS_data(&v2_client_hello),
676
668
  CBS_len(&v2_client_hello))) {
677
669
  return -1;
678
670
  }
679
- if (s->msg_callback) {
680
- s->msg_callback(0, SSL2_VERSION, 0, CBS_data(&v2_client_hello),
681
- CBS_len(&v2_client_hello), s, s->msg_callback_arg);
671
+ if (ssl->msg_callback) {
672
+ ssl->msg_callback(0, SSL2_VERSION, 0, CBS_data(&v2_client_hello),
673
+ CBS_len(&v2_client_hello), ssl, ssl->msg_callback_arg);
682
674
  }
683
675
 
684
676
  if (!CBS_get_u8(&v2_client_hello, &msg_type) ||
@@ -709,8 +701,8 @@ int ssl3_get_v2_client_hello(SSL *s) {
709
701
 
710
702
  /* Write out an equivalent SSLv3 ClientHello. */
711
703
  CBB_zero(&client_hello);
712
- if (!CBB_init_fixed(&client_hello, (uint8_t *)s->init_buf->data,
713
- s->init_buf->max) ||
704
+ if (!CBB_init_fixed(&client_hello, (uint8_t *)ssl->init_buf->data,
705
+ ssl->init_buf->max) ||
714
706
  !CBB_add_u8(&client_hello, SSL3_MT_CLIENT_HELLO) ||
715
707
  !CBB_add_u24_length_prefixed(&client_hello, &hello_body) ||
716
708
  !CBB_add_u16(&hello_body, version) ||
@@ -752,19 +744,19 @@ int ssl3_get_v2_client_hello(SSL *s) {
752
744
  }
753
745
 
754
746
  /* Mark the message for "re"-use by the version-specific method. */
755
- s->s3->tmp.reuse_message = 1;
756
- s->s3->tmp.message_type = SSL3_MT_CLIENT_HELLO;
747
+ ssl->s3->tmp.reuse_message = 1;
748
+ ssl->s3->tmp.message_type = SSL3_MT_CLIENT_HELLO;
757
749
  /* The handshake message header is 4 bytes. */
758
- s->s3->tmp.message_size = len - 4;
750
+ ssl->s3->tmp.message_size = len - 4;
759
751
 
760
752
  /* Consume and discard the V2ClientHello. */
761
- ssl_read_buffer_consume(s, 2 + msg_length);
762
- ssl_read_buffer_discard(s);
753
+ ssl_read_buffer_consume(ssl, 2 + msg_length);
754
+ ssl_read_buffer_discard(ssl);
763
755
 
764
756
  return 1;
765
757
  }
766
758
 
767
- int ssl3_get_client_hello(SSL *s) {
759
+ int ssl3_get_client_hello(SSL *ssl) {
768
760
  int ok, al = SSL_AD_INTERNAL_ERROR, ret = -1;
769
761
  long n;
770
762
  const SSL_CIPHER *c;
@@ -779,11 +771,11 @@ int ssl3_get_client_hello(SSL *s) {
779
771
  * and we get SSLv3, we will respond with TLSv1, This down switching should
780
772
  * be handled by a different method. If we are SSLv3, we will respond with
781
773
  * SSLv3, even if prompted with TLSv1. */
782
- switch (s->state) {
774
+ switch (ssl->state) {
783
775
  case SSL3_ST_SR_CLNT_HELLO_A:
784
776
  case SSL3_ST_SR_CLNT_HELLO_B:
785
- n = s->method->ssl_get_message(
786
- s, SSL3_ST_SR_CLNT_HELLO_A, SSL3_ST_SR_CLNT_HELLO_B,
777
+ n = ssl->method->ssl_get_message(
778
+ ssl, SSL3_ST_SR_CLNT_HELLO_A, SSL3_ST_SR_CLNT_HELLO_B,
787
779
  SSL3_MT_CLIENT_HELLO, SSL3_RT_MAX_PLAIN_LENGTH,
788
780
  ssl_hash_message, &ok);
789
781
 
@@ -791,18 +783,18 @@ int ssl3_get_client_hello(SSL *s) {
791
783
  return n;
792
784
  }
793
785
 
794
- s->state = SSL3_ST_SR_CLNT_HELLO_C;
786
+ ssl->state = SSL3_ST_SR_CLNT_HELLO_C;
795
787
  /* fallthrough */
796
788
  case SSL3_ST_SR_CLNT_HELLO_C:
797
789
  case SSL3_ST_SR_CLNT_HELLO_D:
798
790
  /* We have previously parsed the ClientHello message, and can't call
799
791
  * ssl_get_message again without hashing the message into the Finished
800
792
  * digest again. */
801
- n = s->init_num;
793
+ n = ssl->init_num;
802
794
 
803
795
  memset(&early_ctx, 0, sizeof(early_ctx));
804
- early_ctx.ssl = s;
805
- early_ctx.client_hello = s->init_msg;
796
+ early_ctx.ssl = ssl;
797
+ early_ctx.client_hello = ssl->init_msg;
806
798
  early_ctx.client_hello_len = n;
807
799
  if (!ssl_early_callback_init(&early_ctx)) {
808
800
  al = SSL_AD_DECODE_ERROR;
@@ -810,12 +802,12 @@ int ssl3_get_client_hello(SSL *s) {
810
802
  goto f_err;
811
803
  }
812
804
 
813
- if (s->state == SSL3_ST_SR_CLNT_HELLO_C &&
814
- s->ctx->select_certificate_cb != NULL) {
815
- s->state = SSL3_ST_SR_CLNT_HELLO_D;
816
- switch (s->ctx->select_certificate_cb(&early_ctx)) {
805
+ if (ssl->state == SSL3_ST_SR_CLNT_HELLO_C &&
806
+ ssl->ctx->select_certificate_cb != NULL) {
807
+ ssl->state = SSL3_ST_SR_CLNT_HELLO_D;
808
+ switch (ssl->ctx->select_certificate_cb(&early_ctx)) {
817
809
  case 0:
818
- s->rwstate = SSL_CERTIFICATE_SELECTION_PENDING;
810
+ ssl->rwstate = SSL_CERTIFICATE_SELECTION_PENDING;
819
811
  goto err;
820
812
 
821
813
  case -1:
@@ -828,7 +820,7 @@ int ssl3_get_client_hello(SSL *s) {
828
820
  /* fallthrough */;
829
821
  }
830
822
  }
831
- s->state = SSL3_ST_SR_CLNT_HELLO_D;
823
+ ssl->state = SSL3_ST_SR_CLNT_HELLO_D;
832
824
  break;
833
825
 
834
826
  default:
@@ -836,7 +828,7 @@ int ssl3_get_client_hello(SSL *s) {
836
828
  return -1;
837
829
  }
838
830
 
839
- CBS_init(&client_hello, s->init_msg, n);
831
+ CBS_init(&client_hello, ssl->init_msg, n);
840
832
  if (!CBS_get_u16(&client_hello, &client_version) ||
841
833
  !CBS_get_bytes(&client_hello, &client_random, SSL3_RANDOM_SIZE) ||
842
834
  !CBS_get_u8_length_prefixed(&client_hello, &session_id) ||
@@ -848,12 +840,12 @@ int ssl3_get_client_hello(SSL *s) {
848
840
 
849
841
  /* use version from inside client hello, not from record header (may differ:
850
842
  * see RFC 2246, Appendix E, second paragraph) */
851
- s->client_version = client_version;
843
+ ssl->client_version = client_version;
852
844
 
853
845
  /* Load the client random. */
854
- memcpy(s->s3->client_random, CBS_data(&client_random), SSL3_RANDOM_SIZE);
846
+ memcpy(ssl->s3->client_random, CBS_data(&client_random), SSL3_RANDOM_SIZE);
855
847
 
856
- if (SSL_IS_DTLS(s)) {
848
+ if (SSL_IS_DTLS(ssl)) {
857
849
  CBS cookie;
858
850
 
859
851
  if (!CBS_get_u8_length_prefixed(&client_hello, &cookie) ||
@@ -869,40 +861,40 @@ int ssl3_get_client_hello(SSL *s) {
869
861
  *
870
862
  * TODO(davidben): Clean up the order of events around ClientHello
871
863
  * processing. */
872
- if (!s->s3->have_version) {
864
+ if (!ssl->s3->have_version) {
873
865
  /* Select version to use */
874
- uint16_t version = ssl3_get_mutual_version(s, client_version);
866
+ uint16_t version = ssl3_get_mutual_version(ssl, client_version);
875
867
  if (version == 0) {
876
868
  OPENSSL_PUT_ERROR(SSL, SSL_R_UNSUPPORTED_PROTOCOL);
877
- s->version = s->client_version;
869
+ ssl->version = ssl->client_version;
878
870
  al = SSL_AD_PROTOCOL_VERSION;
879
871
  goto f_err;
880
872
  }
881
- s->version = version;
882
- s->enc_method = ssl3_get_enc_method(version);
883
- assert(s->enc_method != NULL);
884
- /* At this point, the connection's version is known and |s->version| is
873
+ ssl->version = version;
874
+ ssl->s3->enc_method = ssl3_get_enc_method(version);
875
+ assert(ssl->s3->enc_method != NULL);
876
+ /* At this point, the connection's version is known and |ssl->version| is
885
877
  * fixed. Begin enforcing the record-layer version. */
886
- s->s3->have_version = 1;
887
- } else if (SSL_IS_DTLS(s) ? (s->client_version > s->version)
888
- : (s->client_version < s->version)) {
878
+ ssl->s3->have_version = 1;
879
+ } else if (SSL_IS_DTLS(ssl) ? (ssl->client_version > ssl->version)
880
+ : (ssl->client_version < ssl->version)) {
889
881
  OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_VERSION_NUMBER);
890
882
  al = SSL_AD_PROTOCOL_VERSION;
891
883
  goto f_err;
892
884
  }
893
885
 
894
- s->hit = 0;
886
+ ssl->hit = 0;
895
887
  int send_new_ticket = 0;
896
- switch (ssl_get_prev_session(s, &session, &send_new_ticket, &early_ctx)) {
888
+ switch (ssl_get_prev_session(ssl, &session, &send_new_ticket, &early_ctx)) {
897
889
  case ssl_session_success:
898
890
  break;
899
891
  case ssl_session_error:
900
892
  goto err;
901
893
  case ssl_session_retry:
902
- s->rwstate = SSL_PENDING_SESSION;
894
+ ssl->rwstate = SSL_PENDING_SESSION;
903
895
  goto err;
904
896
  }
905
- s->tlsext_ticket_expected = send_new_ticket;
897
+ ssl->tlsext_ticket_expected = send_new_ticket;
906
898
 
907
899
  /* The EMS state is needed when making the resumption decision, but
908
900
  * extensions are not normally parsed until later. This detects the EMS
@@ -911,7 +903,7 @@ int ssl3_get_client_hello(SSL *s) {
911
903
  const uint8_t *ems_data;
912
904
  size_t ems_len;
913
905
  int have_extended_master_secret =
914
- s->version != SSL3_VERSION &&
906
+ ssl->version != SSL3_VERSION &&
915
907
  SSL_early_callback_ctx_extension_get(&early_ctx,
916
908
  TLSEXT_TYPE_extended_master_secret,
917
909
  &ems_data, &ems_len) &&
@@ -927,34 +919,35 @@ int ssl3_get_client_hello(SSL *s) {
927
919
  goto f_err;
928
920
  }
929
921
 
930
- s->hit =
922
+ ssl->hit =
931
923
  /* Only resume if the session's version matches the negotiated version:
932
924
  * most clients do not accept a mismatch. */
933
- s->version == session->ssl_version &&
925
+ ssl->version == session->ssl_version &&
934
926
  /* If the client offers the EMS extension, but the previous session
935
927
  * didn't use it, then negotiate a new session. */
936
928
  have_extended_master_secret == session->extended_master_secret;
937
929
  }
938
930
 
939
- if (s->hit) {
931
+ if (ssl->hit) {
940
932
  /* Use the new session. */
941
- SSL_SESSION_free(s->session);
942
- s->session = session;
933
+ SSL_SESSION_free(ssl->session);
934
+ ssl->session = session;
943
935
  session = NULL;
944
936
 
945
- s->verify_result = s->session->verify_result;
937
+ ssl->verify_result = ssl->session->verify_result;
946
938
  } else {
947
- if (!ssl_get_new_session(s, 1 /* server */)) {
939
+ if (!ssl_get_new_session(ssl, 1 /* server */)) {
948
940
  goto err;
949
941
  }
950
942
 
951
943
  /* Clear the session ID if we want the session to be single-use. */
952
- if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) {
953
- s->session->session_id_length = 0;
944
+ if (!(ssl->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) {
945
+ ssl->session->session_id_length = 0;
954
946
  }
955
947
  }
956
948
 
957
- if (s->ctx->dos_protection_cb != NULL && s->ctx->dos_protection_cb(&early_ctx) == 0) {
949
+ if (ssl->ctx->dos_protection_cb != NULL &&
950
+ ssl->ctx->dos_protection_cb(&early_ctx) == 0) {
958
951
  /* Connection rejected for DOS reasons. */
959
952
  al = SSL_AD_ACCESS_DENIED;
960
953
  OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_REJECTED);
@@ -971,16 +964,16 @@ int ssl3_get_client_hello(SSL *s) {
971
964
  goto f_err;
972
965
  }
973
966
 
974
- ciphers = ssl_bytes_to_cipher_list(s, &cipher_suites);
967
+ ciphers = ssl_bytes_to_cipher_list(ssl, &cipher_suites);
975
968
  if (ciphers == NULL) {
976
969
  goto err;
977
970
  }
978
971
 
979
972
  /* If it is a hit, check that the cipher is in the list. */
980
- if (s->hit) {
973
+ if (ssl->hit) {
981
974
  size_t j;
982
975
  int found_cipher = 0;
983
- uint32_t id = s->session->cipher->id;
976
+ uint32_t id = ssl->session->cipher->id;
984
977
 
985
978
  for (j = 0; j < sk_SSL_CIPHER_num(ciphers); j++) {
986
979
  c = sk_SSL_CIPHER_value(ciphers, j);
@@ -1008,8 +1001,8 @@ int ssl3_get_client_hello(SSL *s) {
1008
1001
  }
1009
1002
 
1010
1003
  /* TLS extensions. */
1011
- if (s->version >= SSL3_VERSION &&
1012
- !ssl_parse_clienthello_tlsext(s, &client_hello)) {
1004
+ if (ssl->version >= SSL3_VERSION &&
1005
+ !ssl_parse_clienthello_tlsext(ssl, &client_hello)) {
1013
1006
  OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT);
1014
1007
  goto err;
1015
1008
  }
@@ -1022,14 +1015,14 @@ int ssl3_get_client_hello(SSL *s) {
1022
1015
  goto f_err;
1023
1016
  }
1024
1017
 
1025
- if (have_extended_master_secret != s->s3->tmp.extended_master_secret) {
1018
+ if (have_extended_master_secret != ssl->s3->tmp.extended_master_secret) {
1026
1019
  al = SSL_AD_INTERNAL_ERROR;
1027
1020
  OPENSSL_PUT_ERROR(SSL, SSL_R_EMS_STATE_INCONSISTENT);
1028
1021
  goto f_err;
1029
1022
  }
1030
1023
 
1031
1024
  /* Given ciphers and SSL_get_ciphers, we must pick a cipher */
1032
- if (!s->hit) {
1025
+ if (!ssl->hit) {
1033
1026
  if (ciphers == NULL) {
1034
1027
  al = SSL_AD_ILLEGAL_PARAMETER;
1035
1028
  OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHERS_PASSED);
@@ -1037,54 +1030,56 @@ int ssl3_get_client_hello(SSL *s) {
1037
1030
  }
1038
1031
 
1039
1032
  /* Let cert callback update server certificates if required */
1040
- if (s->cert->cert_cb) {
1041
- int rv = s->cert->cert_cb(s, s->cert->cert_cb_arg);
1033
+ if (ssl->cert->cert_cb) {
1034
+ int rv = ssl->cert->cert_cb(ssl, ssl->cert->cert_cb_arg);
1042
1035
  if (rv == 0) {
1043
1036
  al = SSL_AD_INTERNAL_ERROR;
1044
1037
  OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_CB_ERROR);
1045
1038
  goto f_err;
1046
1039
  }
1047
1040
  if (rv < 0) {
1048
- s->rwstate = SSL_X509_LOOKUP;
1041
+ ssl->rwstate = SSL_X509_LOOKUP;
1049
1042
  goto err;
1050
1043
  }
1051
- s->rwstate = SSL_NOTHING;
1044
+ ssl->rwstate = SSL_NOTHING;
1052
1045
  }
1053
- c = ssl3_choose_cipher(s, ciphers, ssl_get_cipher_preferences(s));
1046
+ c = ssl3_choose_cipher(ssl, ciphers, ssl_get_cipher_preferences(ssl));
1054
1047
 
1055
1048
  if (c == NULL) {
1056
1049
  al = SSL_AD_HANDSHAKE_FAILURE;
1057
1050
  OPENSSL_PUT_ERROR(SSL, SSL_R_NO_SHARED_CIPHER);
1058
1051
  goto f_err;
1059
1052
  }
1060
- s->s3->tmp.new_cipher = c;
1053
+ ssl->session->cipher = c;
1054
+ ssl->s3->tmp.new_cipher = c;
1061
1055
 
1062
1056
  /* Determine whether to request a client certificate. */
1063
- s->s3->tmp.cert_request = !!(s->verify_mode & SSL_VERIFY_PEER);
1057
+ ssl->s3->tmp.cert_request = !!(ssl->verify_mode & SSL_VERIFY_PEER);
1064
1058
  /* Only request a certificate if Channel ID isn't negotiated. */
1065
- if ((s->verify_mode & SSL_VERIFY_PEER_IF_NO_OBC) &&
1066
- s->s3->tlsext_channel_id_valid) {
1067
- s->s3->tmp.cert_request = 0;
1059
+ if ((ssl->verify_mode & SSL_VERIFY_PEER_IF_NO_OBC) &&
1060
+ ssl->s3->tlsext_channel_id_valid) {
1061
+ ssl->s3->tmp.cert_request = 0;
1068
1062
  }
1069
1063
  /* Plain PSK forbids Certificate and CertificateRequest. */
1070
- if (s->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK) {
1071
- s->s3->tmp.cert_request = 0;
1064
+ if (ssl->s3->tmp.new_cipher->algorithm_mkey & SSL_kPSK) {
1065
+ ssl->s3->tmp.cert_request = 0;
1072
1066
  }
1073
1067
  } else {
1074
1068
  /* Session-id reuse */
1075
- s->s3->tmp.new_cipher = s->session->cipher;
1076
- s->s3->tmp.cert_request = 0;
1069
+ ssl->s3->tmp.new_cipher = ssl->session->cipher;
1070
+ ssl->s3->tmp.cert_request = 0;
1077
1071
  }
1078
1072
 
1079
1073
  /* Now that the cipher is known, initialize the handshake hash. */
1080
- if (!ssl3_init_handshake_hash(s)) {
1074
+ if (!ssl3_init_handshake_hash(ssl)) {
1081
1075
  goto f_err;
1082
1076
  }
1083
1077
 
1084
1078
  /* In TLS 1.2, client authentication requires hashing the handshake transcript
1085
1079
  * under a different hash. Otherwise, release the handshake buffer. */
1086
- if (!SSL_USE_SIGALGS(s) || !s->s3->tmp.cert_request) {
1087
- ssl3_free_handshake_buffer(s);
1080
+ if (!ssl->s3->tmp.cert_request ||
1081
+ ssl3_protocol_version(ssl) < TLS1_2_VERSION) {
1082
+ ssl3_free_handshake_buffer(ssl);
1088
1083
  }
1089
1084
 
1090
1085
  /* we now have the following setup;
@@ -1093,15 +1088,15 @@ int ssl3_get_client_hello(SSL *s) {
1093
1088
  * ciphers - the clients prefered list of ciphers
1094
1089
  * compression - basically ignored right now
1095
1090
  * ssl version is set - sslv3
1096
- * s->session - The ssl session has been setup.
1097
- * s->hit - session reuse flag
1098
- * s->tmp.new_cipher - the new cipher to use. */
1091
+ * ssl->session - The ssl session has been setup.
1092
+ * ssl->hit - session reuse flag
1093
+ * ssl->tmp.new_cipher - the new cipher to use. */
1099
1094
 
1100
1095
  ret = 1;
1101
1096
 
1102
1097
  if (0) {
1103
1098
  f_err:
1104
- ssl3_send_alert(s, SSL3_AL_FATAL, al);
1099
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
1105
1100
  }
1106
1101
 
1107
1102
  err:
@@ -1187,323 +1182,203 @@ int ssl3_send_certificate_status(SSL *ssl) {
1187
1182
  return ssl_do_write(ssl);
1188
1183
  }
1189
1184
 
1190
- int ssl3_send_server_done(SSL *s) {
1191
- if (s->state == SSL3_ST_SW_SRVR_DONE_A) {
1192
- if (!ssl_set_handshake_header(s, SSL3_MT_SERVER_DONE, 0)) {
1185
+ int ssl3_send_server_done(SSL *ssl) {
1186
+ if (ssl->state == SSL3_ST_SW_SRVR_DONE_A) {
1187
+ if (!ssl_set_handshake_header(ssl, SSL3_MT_SERVER_DONE, 0)) {
1193
1188
  return -1;
1194
1189
  }
1195
- s->state = SSL3_ST_SW_SRVR_DONE_B;
1190
+ ssl->state = SSL3_ST_SW_SRVR_DONE_B;
1196
1191
  }
1197
1192
 
1198
1193
  /* SSL3_ST_SW_SRVR_DONE_B */
1199
- return ssl_do_write(s);
1194
+ return ssl_do_write(ssl);
1200
1195
  }
1201
1196
 
1202
- int ssl3_send_server_key_exchange(SSL *s) {
1203
- DH *dh = NULL, *dhp;
1204
- EC_KEY *ecdh = NULL;
1205
- uint8_t *encodedPoint = NULL;
1206
- int encodedlen = 0;
1207
- uint16_t curve_id = 0;
1208
- BN_CTX *bn_ctx = NULL;
1209
- const char *psk_identity_hint = NULL;
1210
- size_t psk_identity_hint_len = 0;
1211
- size_t sig_len;
1212
- size_t max_sig_len;
1213
- uint8_t *p, *d;
1214
- int al, i;
1215
- uint32_t alg_k;
1216
- uint32_t alg_a;
1217
- int n;
1218
- CERT *cert;
1219
- BIGNUM *r[4];
1220
- /* r_pad_bytes[i] contains the number of zero padding bytes that need to
1221
- * precede |r[i]| when serialising it. */
1222
- unsigned r_pad_bytes[4] = {0};
1223
- int nr[4];
1224
- BUF_MEM *buf;
1225
- EVP_MD_CTX md_ctx;
1226
-
1227
- if (s->state == SSL3_ST_SW_KEY_EXCH_C) {
1228
- return ssl_do_write(s);
1197
+ int ssl3_send_server_key_exchange(SSL *ssl) {
1198
+ if (ssl->state == SSL3_ST_SW_KEY_EXCH_C) {
1199
+ return ssl_do_write(ssl);
1229
1200
  }
1230
1201
 
1231
- EVP_MD_CTX_init(&md_ctx);
1232
-
1233
- if (ssl_cipher_has_server_public_key(s->s3->tmp.new_cipher)) {
1234
- if (!ssl_has_private_key(s)) {
1235
- al = SSL_AD_INTERNAL_ERROR;
1236
- goto f_err;
1237
- }
1238
- max_sig_len = ssl_private_key_max_signature_len(s);
1239
- } else {
1240
- max_sig_len = 0;
1202
+ CBB cbb, child;
1203
+ if (!CBB_init_fixed(&cbb, ssl_handshake_start(ssl),
1204
+ ssl->init_buf->max - SSL_HM_HEADER_LENGTH(ssl))) {
1205
+ goto err;
1241
1206
  }
1242
1207
 
1243
- enum ssl_private_key_result_t sign_result;
1244
- if (s->state == SSL3_ST_SW_KEY_EXCH_A) {
1245
- alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
1246
- alg_a = s->s3->tmp.new_cipher->algorithm_auth;
1247
- cert = s->cert;
1208
+ if (ssl->state == SSL3_ST_SW_KEY_EXCH_A) {
1209
+ /* This is the first iteration, so write parameters. */
1210
+ uint32_t alg_k = ssl->s3->tmp.new_cipher->algorithm_mkey;
1211
+ uint32_t alg_a = ssl->s3->tmp.new_cipher->algorithm_auth;
1248
1212
 
1249
- buf = s->init_buf;
1250
-
1251
- r[0] = r[1] = r[2] = r[3] = NULL;
1252
- n = 0;
1213
+ /* PSK ciphers begin with an identity hint. */
1253
1214
  if (alg_a & SSL_aPSK) {
1254
- /* size for PSK identity hint */
1255
- psk_identity_hint = s->psk_identity_hint;
1256
- if (psk_identity_hint) {
1257
- psk_identity_hint_len = strlen(psk_identity_hint);
1258
- } else {
1259
- psk_identity_hint_len = 0;
1215
+ size_t len =
1216
+ (ssl->psk_identity_hint == NULL) ? 0 : strlen(ssl->psk_identity_hint);
1217
+ if (!CBB_add_u16_length_prefixed(&cbb, &child) ||
1218
+ !CBB_add_bytes(&child, (const uint8_t *)ssl->psk_identity_hint,
1219
+ len)) {
1220
+ goto err;
1260
1221
  }
1261
- n += 2 + psk_identity_hint_len;
1262
1222
  }
1263
1223
 
1264
1224
  if (alg_k & SSL_kDHE) {
1265
- dhp = cert->dh_tmp;
1266
- if (dhp == NULL && s->cert->dh_tmp_cb != NULL) {
1267
- dhp = s->cert->dh_tmp_cb(s, 0, 1024);
1225
+ /* Determine the group to use. */
1226
+ DH *params = ssl->cert->dh_tmp;
1227
+ if (params == NULL && ssl->cert->dh_tmp_cb != NULL) {
1228
+ params = ssl->cert->dh_tmp_cb(ssl, 0, 1024);
1268
1229
  }
1269
- if (dhp == NULL) {
1270
- al = SSL_AD_HANDSHAKE_FAILURE;
1230
+ if (params == NULL) {
1271
1231
  OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_TMP_DH_KEY);
1272
- goto f_err;
1273
- }
1274
-
1275
- if (s->s3->tmp.dh != NULL) {
1276
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1232
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1277
1233
  goto err;
1278
1234
  }
1279
- dh = DHparams_dup(dhp);
1235
+ ssl->session->key_exchange_info = DH_num_bits(params);
1236
+
1237
+ /* Set up DH, generate a key, and emit the public half. */
1238
+ DH *dh = DHparams_dup(params);
1280
1239
  if (dh == NULL) {
1281
- OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1282
1240
  goto err;
1283
1241
  }
1284
- s->s3->tmp.dh = dh;
1285
1242
 
1286
- if (!DH_generate_key(dh)) {
1287
- OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1243
+ SSL_ECDH_CTX_init_for_dhe(&ssl->s3->tmp.ecdh_ctx, dh);
1244
+ if (!CBB_add_u16_length_prefixed(&cbb, &child) ||
1245
+ !BN_bn2cbb_padded(&child, BN_num_bytes(params->p), params->p) ||
1246
+ !CBB_add_u16_length_prefixed(&cbb, &child) ||
1247
+ !BN_bn2cbb_padded(&child, BN_num_bytes(params->g), params->g) ||
1248
+ !CBB_add_u16_length_prefixed(&cbb, &child) ||
1249
+ !SSL_ECDH_CTX_generate_keypair(&ssl->s3->tmp.ecdh_ctx, &child)) {
1288
1250
  goto err;
1289
1251
  }
1290
-
1291
- r[0] = dh->p;
1292
- r[1] = dh->g;
1293
- r[2] = dh->pub_key;
1294
- /* Due to a bug in yaSSL, the public key must be zero padded to the size
1295
- * of the prime. */
1296
- assert(BN_num_bytes(dh->pub_key) <= BN_num_bytes(dh->p));
1297
- r_pad_bytes[2] = BN_num_bytes(dh->p) - BN_num_bytes(dh->pub_key);
1298
1252
  } else if (alg_k & SSL_kECDHE) {
1299
1253
  /* Determine the curve to use. */
1300
- int nid = tls1_get_shared_curve(s);
1301
- if (nid == NID_undef) {
1302
- al = SSL_AD_HANDSHAKE_FAILURE;
1254
+ uint16_t curve_id;
1255
+ if (!tls1_get_shared_curve(ssl, &curve_id)) {
1303
1256
  OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_TMP_ECDH_KEY);
1304
- goto f_err;
1305
- }
1306
-
1307
- if (s->s3->tmp.ecdh != NULL) {
1308
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1257
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1309
1258
  goto err;
1310
1259
  }
1311
- ecdh = EC_KEY_new_by_curve_name(nid);
1312
- if (ecdh == NULL) {
1260
+ ssl->session->key_exchange_info = curve_id;
1261
+
1262
+ /* Set up ECDH, generate a key, and emit the public half. */
1263
+ if (!SSL_ECDH_CTX_init(&ssl->s3->tmp.ecdh_ctx, curve_id) ||
1264
+ !CBB_add_u8(&cbb, NAMED_CURVE_TYPE) ||
1265
+ !CBB_add_u16(&cbb, curve_id) ||
1266
+ !CBB_add_u8_length_prefixed(&cbb, &child) ||
1267
+ !SSL_ECDH_CTX_generate_keypair(&ssl->s3->tmp.ecdh_ctx, &child)) {
1313
1268
  goto err;
1314
1269
  }
1315
- s->s3->tmp.ecdh = ecdh;
1316
-
1317
- if (!EC_KEY_generate_key(ecdh)) {
1318
- OPENSSL_PUT_ERROR(SSL, ERR_R_ECDH_LIB);
1319
- goto err;
1320
- }
1321
-
1322
- /* We only support ephemeral ECDH keys over named (not generic) curves. */
1323
- const EC_GROUP *group = EC_KEY_get0_group(ecdh);
1324
- if (!tls1_ec_nid2curve_id(&curve_id, EC_GROUP_get_curve_name(group))) {
1325
- OPENSSL_PUT_ERROR(SSL, SSL_R_UNSUPPORTED_ELLIPTIC_CURVE);
1326
- goto err;
1327
- }
1328
-
1329
- /* Encode the public key. First check the size of encoding and allocate
1330
- * memory accordingly. */
1331
- encodedlen =
1332
- EC_POINT_point2oct(group, EC_KEY_get0_public_key(ecdh),
1333
- POINT_CONVERSION_UNCOMPRESSED, NULL, 0, NULL);
1334
-
1335
- encodedPoint = (uint8_t *)OPENSSL_malloc(encodedlen * sizeof(uint8_t));
1336
- bn_ctx = BN_CTX_new();
1337
- if (encodedPoint == NULL || bn_ctx == NULL) {
1338
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1339
- goto err;
1340
- }
1341
-
1342
- encodedlen = EC_POINT_point2oct(group, EC_KEY_get0_public_key(ecdh),
1343
- POINT_CONVERSION_UNCOMPRESSED,
1344
- encodedPoint, encodedlen, bn_ctx);
1345
-
1346
- if (encodedlen == 0) {
1347
- OPENSSL_PUT_ERROR(SSL, ERR_R_ECDH_LIB);
1348
- goto err;
1349
- }
1350
-
1351
- BN_CTX_free(bn_ctx);
1352
- bn_ctx = NULL;
1353
-
1354
- /* We only support named (not generic) curves in ECDH ephemeral key
1355
- * exchanges. In this situation, we need four additional bytes to encode
1356
- * the entire ServerECDHParams structure. */
1357
- n += 4 + encodedlen;
1358
-
1359
- /* We'll generate the serverKeyExchange message explicitly so we can set
1360
- * these to NULLs */
1361
- r[0] = NULL;
1362
- r[1] = NULL;
1363
- r[2] = NULL;
1364
- r[3] = NULL;
1365
- } else if (!(alg_k & SSL_kPSK)) {
1366
- al = SSL_AD_HANDSHAKE_FAILURE;
1367
- OPENSSL_PUT_ERROR(SSL, SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
1368
- goto f_err;
1270
+ } else {
1271
+ assert(alg_k & SSL_kPSK);
1369
1272
  }
1370
1273
 
1371
- for (i = 0; i < 4 && r[i] != NULL; i++) {
1372
- nr[i] = BN_num_bytes(r[i]) + r_pad_bytes[i];
1373
- n += 2 + nr[i];
1374
- }
1274
+ /* Otherwise, restore |cbb| from the previous iteration.
1275
+ * TODO(davidben): When |ssl->init_buf| is gone, come up with a simpler
1276
+ * pattern. Probably keep the |CBB| around in the handshake state. */
1277
+ } else if (!CBB_did_write(&cbb, ssl->init_num - SSL_HM_HEADER_LENGTH(ssl))) {
1278
+ goto err;
1279
+ }
1375
1280
 
1376
- if (!BUF_MEM_grow_clean(buf, n + SSL_HM_HEADER_LENGTH(s) + max_sig_len)) {
1377
- OPENSSL_PUT_ERROR(SSL, ERR_LIB_BUF);
1281
+ /* Add a signature. */
1282
+ if (ssl_cipher_has_server_public_key(ssl->s3->tmp.new_cipher)) {
1283
+ if (!ssl_has_private_key(ssl)) {
1284
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
1378
1285
  goto err;
1379
1286
  }
1380
- d = p = ssl_handshake_start(s);
1381
1287
 
1382
- for (i = 0; i < 4 && r[i] != NULL; i++) {
1383
- s2n(nr[i], p);
1384
- if (!BN_bn2bin_padded(p, nr[i], r[i])) {
1385
- OPENSSL_PUT_ERROR(SSL, ERR_LIB_BN);
1288
+ const size_t max_sig_len = ssl_private_key_max_signature_len(ssl);
1289
+ size_t sig_len;
1290
+ enum ssl_private_key_result_t sign_result;
1291
+ if (ssl->state == SSL3_ST_SW_KEY_EXCH_A) {
1292
+ /* This is the first iteration, so set up the signature. Sample the
1293
+ * parameter length before adding a signature algorithm. */
1294
+ if (!CBB_flush(&cbb)) {
1386
1295
  goto err;
1387
1296
  }
1388
- p += nr[i];
1389
- }
1390
-
1391
- /* Note: ECDHE PSK ciphersuites use SSL_kECDHE and SSL_aPSK. When one of
1392
- * them is used, the server key exchange record needs to have both the
1393
- * psk_identity_hint and the ServerECDHParams. */
1394
- if (alg_a & SSL_aPSK) {
1395
- /* copy PSK identity hint (if provided) */
1396
- s2n(psk_identity_hint_len, p);
1397
- if (psk_identity_hint_len > 0) {
1398
- memcpy(p, psk_identity_hint, psk_identity_hint_len);
1399
- p += psk_identity_hint_len;
1400
- }
1401
- }
1402
-
1403
- if (alg_k & SSL_kECDHE) {
1404
- /* We only support named (not generic) curves. In this situation, the
1405
- * serverKeyExchange message has:
1406
- * [1 byte CurveType], [2 byte CurveName]
1407
- * [1 byte length of encoded point], followed by
1408
- * the actual encoded point itself. */
1409
- *(p++) = NAMED_CURVE_TYPE;
1410
- *(p++) = (uint8_t)(curve_id >> 8);
1411
- *(p++) = (uint8_t)(curve_id & 0xff);
1412
- *(p++) = encodedlen;
1413
- memcpy(p, encodedPoint, encodedlen);
1414
- p += encodedlen;
1415
- OPENSSL_free(encodedPoint);
1416
- encodedPoint = NULL;
1417
- }
1418
-
1419
- if (ssl_cipher_has_server_public_key(s->s3->tmp.new_cipher)) {
1420
- /* n is the length of the params, they start at d and p points to
1421
- * the space at the end. */
1422
- const EVP_MD *md;
1423
- uint8_t digest[EVP_MAX_MD_SIZE];
1424
- unsigned int digest_length;
1425
-
1426
- const int pkey_type = ssl_private_key_type(s);
1297
+ size_t params_len = CBB_len(&cbb);
1427
1298
 
1428
1299
  /* Determine signature algorithm. */
1429
- if (SSL_USE_SIGALGS(s)) {
1430
- md = tls1_choose_signing_digest(s);
1431
- if (!tls12_get_sigandhash(s, p, md)) {
1432
- /* Should never happen */
1433
- al = SSL_AD_INTERNAL_ERROR;
1300
+ const EVP_MD *md;
1301
+ if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
1302
+ md = tls1_choose_signing_digest(ssl);
1303
+ if (!tls12_add_sigandhash(ssl, &cbb, md)) {
1434
1304
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1435
- goto f_err;
1305
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
1306
+ goto err;
1436
1307
  }
1437
- p += 2;
1438
- } else if (pkey_type == EVP_PKEY_RSA) {
1308
+ } else if (ssl_private_key_type(ssl) == EVP_PKEY_RSA) {
1439
1309
  md = EVP_md5_sha1();
1440
1310
  } else {
1441
1311
  md = EVP_sha1();
1442
1312
  }
1443
1313
 
1444
- if (!EVP_DigestInit_ex(&md_ctx, md, NULL) ||
1445
- !EVP_DigestUpdate(&md_ctx, s->s3->client_random, SSL3_RANDOM_SIZE) ||
1446
- !EVP_DigestUpdate(&md_ctx, s->s3->server_random, SSL3_RANDOM_SIZE) ||
1447
- !EVP_DigestUpdate(&md_ctx, d, n) ||
1448
- !EVP_DigestFinal_ex(&md_ctx, digest, &digest_length)) {
1449
- OPENSSL_PUT_ERROR(SSL, ERR_LIB_EVP);
1314
+ /* Compute the digest and sign it. */
1315
+ uint8_t digest[EVP_MAX_MD_SIZE];
1316
+ unsigned digest_len = 0;
1317
+ EVP_MD_CTX md_ctx;
1318
+ EVP_MD_CTX_init(&md_ctx);
1319
+ int digest_ret =
1320
+ EVP_DigestInit_ex(&md_ctx, md, NULL) &&
1321
+ EVP_DigestUpdate(&md_ctx, ssl->s3->client_random, SSL3_RANDOM_SIZE) &&
1322
+ EVP_DigestUpdate(&md_ctx, ssl->s3->server_random, SSL3_RANDOM_SIZE) &&
1323
+ EVP_DigestUpdate(&md_ctx, CBB_data(&cbb), params_len) &&
1324
+ EVP_DigestFinal_ex(&md_ctx, digest, &digest_len);
1325
+ EVP_MD_CTX_cleanup(&md_ctx);
1326
+ uint8_t *ptr;
1327
+ if (!digest_ret ||
1328
+ !CBB_add_u16_length_prefixed(&cbb, &child) ||
1329
+ !CBB_reserve(&child, &ptr, max_sig_len)) {
1450
1330
  goto err;
1451
1331
  }
1452
-
1453
- sign_result = ssl_private_key_sign(s, &p[2], &sig_len, max_sig_len,
1454
- EVP_MD_CTX_md(&md_ctx), digest,
1455
- digest_length);
1332
+ sign_result = ssl_private_key_sign(ssl, ptr, &sig_len, max_sig_len, md,
1333
+ digest, digest_len);
1456
1334
  } else {
1457
- /* This key exchange doesn't involve a signature. */
1458
- sign_result = ssl_private_key_success;
1459
- sig_len = 0;
1335
+ assert(ssl->state == SSL3_ST_SW_KEY_EXCH_B);
1336
+
1337
+ /* Retry the signature. */
1338
+ uint8_t *ptr;
1339
+ if (!CBB_add_u16_length_prefixed(&cbb, &child) ||
1340
+ !CBB_reserve(&child, &ptr, max_sig_len)) {
1341
+ goto err;
1342
+ }
1343
+ sign_result =
1344
+ ssl_private_key_sign_complete(ssl, ptr, &sig_len, max_sig_len);
1460
1345
  }
1461
- } else {
1462
- assert(s->state == SSL3_ST_SW_KEY_EXCH_B);
1463
- /* Restore |p|. */
1464
- p = ssl_handshake_start(s) + s->init_num - SSL_HM_HEADER_LENGTH(s);
1465
- sign_result = ssl_private_key_sign_complete(s, &p[2], &sig_len,
1466
- max_sig_len);
1467
- }
1468
1346
 
1469
- switch (sign_result) {
1470
- case ssl_private_key_success:
1471
- s->rwstate = SSL_NOTHING;
1472
- break;
1473
- case ssl_private_key_failure:
1474
- s->rwstate = SSL_NOTHING;
1475
- goto err;
1476
- case ssl_private_key_retry:
1477
- s->rwstate = SSL_PRIVATE_KEY_OPERATION;
1478
- /* Stash away |p|. */
1479
- s->init_num = p - ssl_handshake_start(s) + SSL_HM_HEADER_LENGTH(s);
1480
- s->state = SSL3_ST_SW_KEY_EXCH_B;
1481
- goto err;
1347
+ switch (sign_result) {
1348
+ case ssl_private_key_success:
1349
+ ssl->rwstate = SSL_NOTHING;
1350
+ if (!CBB_did_write(&child, sig_len)) {
1351
+ goto err;
1352
+ }
1353
+ break;
1354
+ case ssl_private_key_failure:
1355
+ ssl->rwstate = SSL_NOTHING;
1356
+ goto err;
1357
+ case ssl_private_key_retry:
1358
+ /* Discard the unfinished signature and save the state of |cbb| for the
1359
+ * next iteration. */
1360
+ CBB_discard_child(&cbb);
1361
+ ssl->init_num = SSL_HM_HEADER_LENGTH(ssl) + CBB_len(&cbb);
1362
+ ssl->rwstate = SSL_PRIVATE_KEY_OPERATION;
1363
+ ssl->state = SSL3_ST_SW_KEY_EXCH_B;
1364
+ goto err;
1365
+ }
1482
1366
  }
1483
1367
 
1484
- if (ssl_cipher_has_server_public_key(s->s3->tmp.new_cipher)) {
1485
- s2n(sig_len, p);
1486
- p += sig_len;
1487
- }
1488
- if (!ssl_set_handshake_header(s, SSL3_MT_SERVER_KEY_EXCHANGE,
1489
- p - ssl_handshake_start(s))) {
1368
+ size_t length;
1369
+ if (!CBB_finish(&cbb, NULL, &length) ||
1370
+ !ssl_set_handshake_header(ssl, SSL3_MT_SERVER_KEY_EXCHANGE, length)) {
1490
1371
  goto err;
1491
1372
  }
1492
- s->state = SSL3_ST_SW_KEY_EXCH_C;
1493
-
1494
- EVP_MD_CTX_cleanup(&md_ctx);
1495
- return ssl_do_write(s);
1373
+ ssl->state = SSL3_ST_SW_KEY_EXCH_C;
1374
+ return ssl_do_write(ssl);
1496
1375
 
1497
- f_err:
1498
- ssl3_send_alert(s, SSL3_AL_FATAL, al);
1499
1376
  err:
1500
- OPENSSL_free(encodedPoint);
1501
- BN_CTX_free(bn_ctx);
1502
- EVP_MD_CTX_cleanup(&md_ctx);
1377
+ CBB_cleanup(&cbb);
1503
1378
  return -1;
1504
1379
  }
1505
1380
 
1506
- int ssl3_send_certificate_request(SSL *s) {
1381
+ int ssl3_send_certificate_request(SSL *ssl) {
1507
1382
  uint8_t *p, *d;
1508
1383
  size_t i;
1509
1384
  int j, nl, off, n;
@@ -1511,21 +1386,21 @@ int ssl3_send_certificate_request(SSL *s) {
1511
1386
  X509_NAME *name;
1512
1387
  BUF_MEM *buf;
1513
1388
 
1514
- if (s->state == SSL3_ST_SW_CERT_REQ_A) {
1515
- buf = s->init_buf;
1389
+ if (ssl->state == SSL3_ST_SW_CERT_REQ_A) {
1390
+ buf = ssl->init_buf;
1516
1391
 
1517
- d = p = ssl_handshake_start(s);
1392
+ d = p = ssl_handshake_start(ssl);
1518
1393
 
1519
1394
  /* get the list of acceptable cert types */
1520
1395
  p++;
1521
- n = ssl3_get_req_cert_type(s, p);
1396
+ n = ssl3_get_req_cert_type(ssl, p);
1522
1397
  d[0] = n;
1523
1398
  p += n;
1524
1399
  n++;
1525
1400
 
1526
- if (SSL_USE_SIGALGS(s)) {
1401
+ if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
1527
1402
  const uint8_t *psigs;
1528
- nl = tls12_get_psigalgs(s, &psigs);
1403
+ nl = tls12_get_psigalgs(ssl, &psigs);
1529
1404
  s2n(nl, p);
1530
1405
  memcpy(p, psigs, nl);
1531
1406
  p += nl;
@@ -1536,17 +1411,17 @@ int ssl3_send_certificate_request(SSL *s) {
1536
1411
  p += 2;
1537
1412
  n += 2;
1538
1413
 
1539
- sk = SSL_get_client_CA_list(s);
1414
+ sk = SSL_get_client_CA_list(ssl);
1540
1415
  nl = 0;
1541
1416
  if (sk != NULL) {
1542
1417
  for (i = 0; i < sk_X509_NAME_num(sk); i++) {
1543
1418
  name = sk_X509_NAME_value(sk, i);
1544
1419
  j = i2d_X509_NAME(name, NULL);
1545
- if (!BUF_MEM_grow_clean(buf, SSL_HM_HEADER_LENGTH(s) + n + j + 2)) {
1420
+ if (!BUF_MEM_grow_clean(buf, SSL_HM_HEADER_LENGTH(ssl) + n + j + 2)) {
1546
1421
  OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
1547
1422
  goto err;
1548
1423
  }
1549
- p = ssl_handshake_start(s) + n;
1424
+ p = ssl_handshake_start(ssl) + n;
1550
1425
  s2n(j, p);
1551
1426
  i2d_X509_NAME(name, &p);
1552
1427
  n += 2 + j;
@@ -1555,23 +1430,23 @@ int ssl3_send_certificate_request(SSL *s) {
1555
1430
  }
1556
1431
 
1557
1432
  /* else no CA names */
1558
- p = ssl_handshake_start(s) + off;
1433
+ p = ssl_handshake_start(ssl) + off;
1559
1434
  s2n(nl, p);
1560
1435
 
1561
- if (!ssl_set_handshake_header(s, SSL3_MT_CERTIFICATE_REQUEST, n)) {
1436
+ if (!ssl_set_handshake_header(ssl, SSL3_MT_CERTIFICATE_REQUEST, n)) {
1562
1437
  goto err;
1563
1438
  }
1564
- s->state = SSL3_ST_SW_CERT_REQ_B;
1439
+ ssl->state = SSL3_ST_SW_CERT_REQ_B;
1565
1440
  }
1566
1441
 
1567
1442
  /* SSL3_ST_SW_CERT_REQ_B */
1568
- return ssl_do_write(s);
1443
+ return ssl_do_write(ssl);
1569
1444
 
1570
1445
  err:
1571
1446
  return -1;
1572
1447
  }
1573
1448
 
1574
- int ssl3_get_client_key_exchange(SSL *s) {
1449
+ int ssl3_get_client_key_exchange(SSL *ssl) {
1575
1450
  int al;
1576
1451
  CBS client_key_exchange;
1577
1452
  uint32_t alg_k;
@@ -1579,30 +1454,24 @@ int ssl3_get_client_key_exchange(SSL *s) {
1579
1454
  uint8_t *premaster_secret = NULL;
1580
1455
  size_t premaster_secret_len = 0;
1581
1456
  uint8_t *decrypt_buf = NULL;
1582
- BIGNUM *pub = NULL;
1583
- DH *dh_srvr;
1584
-
1585
- EC_KEY *srvr_ecdh = NULL;
1586
- EVP_PKEY *clnt_pub_pkey = NULL;
1587
- EC_POINT *clnt_ecpoint = NULL;
1588
- BN_CTX *bn_ctx = NULL;
1589
- unsigned int psk_len = 0;
1457
+
1458
+ unsigned psk_len = 0;
1590
1459
  uint8_t psk[PSK_MAX_PSK_LEN];
1591
1460
 
1592
- if (s->state == SSL3_ST_SR_KEY_EXCH_A ||
1593
- s->state == SSL3_ST_SR_KEY_EXCH_B) {
1461
+ if (ssl->state == SSL3_ST_SR_KEY_EXCH_A ||
1462
+ ssl->state == SSL3_ST_SR_KEY_EXCH_B) {
1594
1463
  int ok;
1595
- const long n = s->method->ssl_get_message(
1596
- s, SSL3_ST_SR_KEY_EXCH_A, SSL3_ST_SR_KEY_EXCH_B,
1464
+ const long n = ssl->method->ssl_get_message(
1465
+ ssl, SSL3_ST_SR_KEY_EXCH_A, SSL3_ST_SR_KEY_EXCH_B,
1597
1466
  SSL3_MT_CLIENT_KEY_EXCHANGE, 2048 /* ??? */, ssl_hash_message, &ok);
1598
1467
  if (!ok) {
1599
1468
  return n;
1600
1469
  }
1601
1470
  }
1602
1471
 
1603
- CBS_init(&client_key_exchange, s->init_msg, s->init_num);
1604
- alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
1605
- alg_a = s->s3->tmp.new_cipher->algorithm_auth;
1472
+ CBS_init(&client_key_exchange, ssl->init_msg, ssl->init_num);
1473
+ alg_k = ssl->s3->tmp.new_cipher->algorithm_mkey;
1474
+ alg_a = ssl->s3->tmp.new_cipher->algorithm_auth;
1606
1475
 
1607
1476
  /* If using a PSK key exchange, prepare the pre-shared key. */
1608
1477
  if (alg_a & SSL_aPSK) {
@@ -1617,7 +1486,7 @@ int ssl3_get_client_key_exchange(SSL *s) {
1617
1486
  goto f_err;
1618
1487
  }
1619
1488
 
1620
- if (s->psk_server_callback == NULL) {
1489
+ if (ssl->psk_server_callback == NULL) {
1621
1490
  OPENSSL_PUT_ERROR(SSL, SSL_R_PSK_NO_SERVER_CB);
1622
1491
  al = SSL_AD_INTERNAL_ERROR;
1623
1492
  goto f_err;
@@ -1630,15 +1499,15 @@ int ssl3_get_client_key_exchange(SSL *s) {
1630
1499
  goto f_err;
1631
1500
  }
1632
1501
 
1633
- if (!CBS_strdup(&psk_identity, &s->session->psk_identity)) {
1502
+ if (!CBS_strdup(&psk_identity, &ssl->session->psk_identity)) {
1634
1503
  al = SSL_AD_INTERNAL_ERROR;
1635
1504
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1636
1505
  goto f_err;
1637
1506
  }
1638
1507
 
1639
1508
  /* Look up the key for the identity. */
1640
- psk_len =
1641
- s->psk_server_callback(s, s->session->psk_identity, psk, sizeof(psk));
1509
+ psk_len = ssl->psk_server_callback(ssl, ssl->session->psk_identity, psk,
1510
+ sizeof(psk));
1642
1511
  if (psk_len > PSK_MAX_PSK_LEN) {
1643
1512
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1644
1513
  al = SSL_AD_INTERNAL_ERROR;
@@ -1654,13 +1523,8 @@ int ssl3_get_client_key_exchange(SSL *s) {
1654
1523
  /* Depending on the key exchange method, compute |premaster_secret| and
1655
1524
  * |premaster_secret_len|. */
1656
1525
  if (alg_k & SSL_kRSA) {
1657
- CBS encrypted_premaster_secret;
1658
- uint8_t rand_premaster_secret[SSL_MAX_MASTER_KEY_LENGTH];
1659
- uint8_t good;
1660
- size_t decrypt_len, premaster_index, j;
1661
- const size_t rsa_size = ssl_private_key_max_signature_len(s);
1662
-
1663
1526
  /* Allocate a buffer large enough for an RSA decryption. */
1527
+ const size_t rsa_size = ssl_private_key_max_signature_len(ssl);
1664
1528
  decrypt_buf = OPENSSL_malloc(rsa_size);
1665
1529
  if (decrypt_buf == NULL) {
1666
1530
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
@@ -1668,14 +1532,16 @@ int ssl3_get_client_key_exchange(SSL *s) {
1668
1532
  }
1669
1533
 
1670
1534
  enum ssl_private_key_result_t decrypt_result;
1671
- if (s->state == SSL3_ST_SR_KEY_EXCH_B) {
1672
- if (!ssl_has_private_key(s) || ssl_private_key_type(s) != EVP_PKEY_RSA) {
1535
+ size_t decrypt_len;
1536
+ if (ssl->state == SSL3_ST_SR_KEY_EXCH_B) {
1537
+ if (!ssl_has_private_key(ssl) ||
1538
+ ssl_private_key_type(ssl) != EVP_PKEY_RSA) {
1673
1539
  al = SSL_AD_HANDSHAKE_FAILURE;
1674
1540
  OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_RSA_CERTIFICATE);
1675
1541
  goto f_err;
1676
1542
  }
1677
- /* TLS and [incidentally] DTLS{0xFEFF} */
1678
- if (s->version > SSL3_VERSION) {
1543
+ CBS encrypted_premaster_secret;
1544
+ if (ssl->version > SSL3_VERSION) {
1679
1545
  if (!CBS_get_u16_length_prefixed(&client_key_exchange,
1680
1546
  &encrypted_premaster_secret) ||
1681
1547
  CBS_len(&client_key_exchange) != 0) {
@@ -1688,236 +1554,109 @@ int ssl3_get_client_key_exchange(SSL *s) {
1688
1554
  encrypted_premaster_secret = client_key_exchange;
1689
1555
  }
1690
1556
 
1691
- /* Reject overly short RSA keys because we want to be sure that the buffer
1692
- * size makes it safe to iterate over the entire size of a premaster
1693
- * secret (SSL_MAX_MASTER_KEY_LENGTH). The actual expected size is larger
1694
- * due to RSA padding, but the bound is sufficient to be safe. */
1695
- if (rsa_size < SSL_MAX_MASTER_KEY_LENGTH) {
1696
- al = SSL_AD_DECRYPT_ERROR;
1697
- OPENSSL_PUT_ERROR(SSL, SSL_R_DECRYPTION_FAILED);
1698
- goto f_err;
1699
- }
1700
-
1701
1557
  /* Decrypt with no padding. PKCS#1 padding will be removed as part of the
1702
1558
  * timing-sensitive code below. */
1703
1559
  decrypt_result = ssl_private_key_decrypt(
1704
- s, decrypt_buf, &decrypt_len, rsa_size,
1560
+ ssl, decrypt_buf, &decrypt_len, rsa_size,
1705
1561
  CBS_data(&encrypted_premaster_secret),
1706
1562
  CBS_len(&encrypted_premaster_secret));
1707
1563
  } else {
1708
- assert(s->state == SSL3_ST_SR_KEY_EXCH_C);
1564
+ assert(ssl->state == SSL3_ST_SR_KEY_EXCH_C);
1709
1565
  /* Complete async decrypt. */
1710
1566
  decrypt_result = ssl_private_key_decrypt_complete(
1711
- s, decrypt_buf, &decrypt_len, rsa_size);
1567
+ ssl, decrypt_buf, &decrypt_len, rsa_size);
1712
1568
  }
1713
1569
 
1714
1570
  switch (decrypt_result) {
1715
1571
  case ssl_private_key_success:
1716
- s->rwstate = SSL_NOTHING;
1572
+ ssl->rwstate = SSL_NOTHING;
1717
1573
  break;
1718
1574
  case ssl_private_key_failure:
1719
- s->rwstate = SSL_NOTHING;
1575
+ ssl->rwstate = SSL_NOTHING;
1720
1576
  goto err;
1721
1577
  case ssl_private_key_retry:
1722
- s->rwstate = SSL_PRIVATE_KEY_OPERATION;
1723
- s->state = SSL3_ST_SR_KEY_EXCH_C;
1578
+ ssl->rwstate = SSL_PRIVATE_KEY_OPERATION;
1579
+ ssl->state = SSL3_ST_SR_KEY_EXCH_C;
1724
1580
  goto err;
1725
1581
  }
1726
1582
 
1727
- if (decrypt_len != rsa_size) {
1728
- /* This should never happen, but do a check so we do not read
1729
- * uninitialized memory. */
1730
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1731
- goto err;
1732
- }
1583
+ assert(decrypt_len == rsa_size);
1733
1584
 
1734
- /* Remove the PKCS#1 padding and adjust |decrypt_len| as appropriate.
1735
- * |good| will be 0xff if the premaster is acceptable and zero otherwise.
1736
- * */
1737
- good =
1738
- constant_time_eq_int_8(RSA_message_index_PKCS1_type_2(
1739
- decrypt_buf, decrypt_len, &premaster_index),
1740
- 1);
1741
- decrypt_len = decrypt_len - premaster_index;
1742
-
1743
- /* decrypt_len should be SSL_MAX_MASTER_KEY_LENGTH. */
1744
- good &= constant_time_eq_8(decrypt_len, SSL_MAX_MASTER_KEY_LENGTH);
1745
-
1746
- /* Copy over the unpadded premaster. Whatever the value of
1747
- * |decrypt_good_mask|, copy as if the premaster were the right length. It
1748
- * is important the memory access pattern be constant. */
1749
- premaster_secret =
1750
- BUF_memdup(decrypt_buf + (rsa_size - SSL_MAX_MASTER_KEY_LENGTH),
1751
- SSL_MAX_MASTER_KEY_LENGTH);
1585
+ /* Prepare a random premaster, to be used on invalid padding. See RFC 5246,
1586
+ * section 7.4.7.1. */
1587
+ premaster_secret_len = SSL_MAX_MASTER_KEY_LENGTH;
1588
+ premaster_secret = OPENSSL_malloc(premaster_secret_len);
1752
1589
  if (premaster_secret == NULL) {
1753
1590
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1754
1591
  goto err;
1755
1592
  }
1756
- OPENSSL_free(decrypt_buf);
1757
- decrypt_buf = NULL;
1758
-
1759
- /* If the version in the decrypted pre-master secret is correct then
1760
- * version_good will be 0xff, otherwise it'll be zero. The
1761
- * Klima-Pokorny-Rosa extension of Bleichenbacher's attack
1762
- * (http://eprint.iacr.org/2003/052/) exploits the version number check as
1763
- * a "bad version oracle". Thus version checks are done in constant time
1764
- * and are treated like any other decryption error. */
1765
- good &= constant_time_eq_8(premaster_secret[0],
1766
- (unsigned)(s->client_version >> 8));
1767
- good &= constant_time_eq_8(premaster_secret[1],
1768
- (unsigned)(s->client_version & 0xff));
1769
-
1770
- /* We must not leak whether a decryption failure occurs because of
1771
- * Bleichenbacher's attack on PKCS #1 v1.5 RSA padding (see RFC 2246,
1772
- * section 7.4.7.1). The code follows that advice of the TLS RFC and
1773
- * generates a random premaster secret for the case that the decrypt
1774
- * fails. See https://tools.ietf.org/html/rfc5246#section-7.4.7.1 */
1775
- if (!RAND_bytes(rand_premaster_secret, sizeof(rand_premaster_secret))) {
1593
+ if (!RAND_bytes(premaster_secret, premaster_secret_len)) {
1776
1594
  goto err;
1777
1595
  }
1778
1596
 
1779
- /* Now copy rand_premaster_secret over premaster_secret using
1780
- * decrypt_good_mask. */
1781
- for (j = 0; j < sizeof(rand_premaster_secret); j++) {
1782
- premaster_secret[j] = constant_time_select_8(good, premaster_secret[j],
1783
- rand_premaster_secret[j]);
1784
- }
1785
-
1786
- premaster_secret_len = sizeof(rand_premaster_secret);
1787
- } else if (alg_k & SSL_kDHE) {
1788
- CBS dh_Yc;
1789
- int dh_len;
1790
-
1791
- if (!CBS_get_u16_length_prefixed(&client_key_exchange, &dh_Yc) ||
1792
- CBS_len(&dh_Yc) == 0 || CBS_len(&client_key_exchange) != 0) {
1793
- OPENSSL_PUT_ERROR(SSL, SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG);
1794
- al = SSL_R_DECODE_ERROR;
1597
+ /* The smallest padded premaster is 11 bytes of overhead. Small keys are
1598
+ * publicly invalid. */
1599
+ if (decrypt_len < 11 + premaster_secret_len) {
1600
+ al = SSL_AD_DECRYPT_ERROR;
1601
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECRYPTION_FAILED);
1795
1602
  goto f_err;
1796
1603
  }
1797
1604
 
1798
- if (s->s3->tmp.dh == NULL) {
1799
- al = SSL_AD_HANDSHAKE_FAILURE;
1800
- OPENSSL_PUT_ERROR(SSL, SSL_R_MISSING_TMP_DH_KEY);
1801
- goto f_err;
1605
+ /* Check the padding. See RFC 3447, section 7.2.2. */
1606
+ size_t padding_len = decrypt_len - premaster_secret_len;
1607
+ uint8_t good = constant_time_eq_int_8(decrypt_buf[0], 0) &
1608
+ constant_time_eq_int_8(decrypt_buf[1], 2);
1609
+ size_t i;
1610
+ for (i = 2; i < padding_len - 1; i++) {
1611
+ good &= ~constant_time_is_zero_8(decrypt_buf[i]);
1802
1612
  }
1803
- dh_srvr = s->s3->tmp.dh;
1613
+ good &= constant_time_is_zero_8(decrypt_buf[padding_len - 1]);
1804
1614
 
1805
- pub = BN_bin2bn(CBS_data(&dh_Yc), CBS_len(&dh_Yc), NULL);
1806
- if (pub == NULL) {
1807
- OPENSSL_PUT_ERROR(SSL, SSL_R_BN_LIB);
1808
- goto err;
1809
- }
1615
+ /* The premaster secret must begin with |client_version|. This too must be
1616
+ * checked in constant time (http://eprint.iacr.org/2003/052/). */
1617
+ good &= constant_time_eq_8(decrypt_buf[padding_len],
1618
+ (unsigned)(ssl->client_version >> 8));
1619
+ good &= constant_time_eq_8(decrypt_buf[padding_len + 1],
1620
+ (unsigned)(ssl->client_version & 0xff));
1810
1621
 
1811
- /* Allocate a buffer for the premaster secret. */
1812
- premaster_secret = OPENSSL_malloc(DH_size(dh_srvr));
1813
- if (premaster_secret == NULL) {
1814
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1815
- BN_clear_free(pub);
1816
- goto err;
1622
+ /* Select, in constant time, either the decrypted premaster or the random
1623
+ * premaster based on |good|. */
1624
+ for (i = 0; i < premaster_secret_len; i++) {
1625
+ premaster_secret[i] = constant_time_select_8(
1626
+ good, decrypt_buf[padding_len + i], premaster_secret[i]);
1817
1627
  }
1818
1628
 
1819
- dh_len = DH_compute_key(premaster_secret, pub, dh_srvr);
1820
- if (dh_len <= 0) {
1821
- OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1822
- BN_clear_free(pub);
1823
- goto err;
1824
- }
1825
-
1826
- DH_free(s->s3->tmp.dh);
1827
- s->s3->tmp.dh = NULL;
1828
- BN_clear_free(pub);
1829
- pub = NULL;
1830
-
1831
- premaster_secret_len = dh_len;
1832
- } else if (alg_k & SSL_kECDHE) {
1833
- int ecdh_len;
1834
- const EC_KEY *tkey;
1835
- const EC_GROUP *group;
1836
- const BIGNUM *priv_key;
1837
- CBS ecdh_Yc;
1838
-
1839
- /* initialize structures for server's ECDH key pair */
1840
- srvr_ecdh = EC_KEY_new();
1841
- if (srvr_ecdh == NULL) {
1842
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1843
- goto err;
1844
- }
1845
-
1846
- /* Use the ephermeral values we saved when generating the ServerKeyExchange
1847
- * msg. */
1848
- tkey = s->s3->tmp.ecdh;
1849
-
1850
- group = EC_KEY_get0_group(tkey);
1851
- priv_key = EC_KEY_get0_private_key(tkey);
1852
-
1853
- if (!EC_KEY_set_group(srvr_ecdh, group) ||
1854
- !EC_KEY_set_private_key(srvr_ecdh, priv_key)) {
1855
- OPENSSL_PUT_ERROR(SSL, ERR_R_EC_LIB);
1856
- goto err;
1857
- }
1858
-
1859
- /* Let's get client's public key */
1860
- clnt_ecpoint = EC_POINT_new(group);
1861
- if (clnt_ecpoint == NULL) {
1862
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1863
- goto err;
1629
+ OPENSSL_free(decrypt_buf);
1630
+ decrypt_buf = NULL;
1631
+ } else if (alg_k & (SSL_kECDHE|SSL_kDHE)) {
1632
+ /* Parse the ClientKeyExchange. ECDHE uses a u8 length prefix while DHE uses
1633
+ * u16. */
1634
+ CBS peer_key;
1635
+ int peer_key_ok;
1636
+ if (alg_k & SSL_kECDHE) {
1637
+ peer_key_ok = CBS_get_u8_length_prefixed(&client_key_exchange, &peer_key);
1638
+ } else {
1639
+ peer_key_ok =
1640
+ CBS_get_u16_length_prefixed(&client_key_exchange, &peer_key);
1864
1641
  }
1865
1642
 
1866
- /* Get client's public key from encoded point in the ClientKeyExchange
1867
- * message. */
1868
- if (!CBS_get_u8_length_prefixed(&client_key_exchange, &ecdh_Yc) ||
1869
- CBS_len(&client_key_exchange) != 0) {
1643
+ if (!peer_key_ok || CBS_len(&client_key_exchange) != 0) {
1870
1644
  al = SSL_AD_DECODE_ERROR;
1871
1645
  OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1872
1646
  goto f_err;
1873
1647
  }
1874
1648
 
1875
- bn_ctx = BN_CTX_new();
1876
- if (bn_ctx == NULL) {
1877
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1878
- goto err;
1879
- }
1880
-
1881
- if (!EC_POINT_oct2point(group, clnt_ecpoint, CBS_data(&ecdh_Yc),
1882
- CBS_len(&ecdh_Yc), bn_ctx)) {
1883
- OPENSSL_PUT_ERROR(SSL, ERR_R_EC_LIB);
1884
- goto err;
1885
- }
1886
-
1887
- /* Allocate a buffer for both the secret and the PSK. */
1888
- unsigned field_size = EC_GROUP_get_degree(group);
1889
- if (field_size == 0) {
1890
- OPENSSL_PUT_ERROR(SSL, ERR_R_ECDH_LIB);
1891
- goto err;
1892
- }
1893
-
1894
- ecdh_len = (field_size + 7) / 8;
1895
- premaster_secret = OPENSSL_malloc(ecdh_len);
1896
- if (premaster_secret == NULL) {
1897
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1898
- goto err;
1899
- }
1900
-
1901
- /* Compute the shared pre-master secret */
1902
- ecdh_len = ECDH_compute_key(premaster_secret, ecdh_len, clnt_ecpoint,
1903
- srvr_ecdh, NULL);
1904
- if (ecdh_len <= 0) {
1905
- OPENSSL_PUT_ERROR(SSL, ERR_R_ECDH_LIB);
1906
- goto err;
1649
+ /* Compute the premaster. */
1650
+ uint8_t alert;
1651
+ if (!SSL_ECDH_CTX_compute_secret(&ssl->s3->tmp.ecdh_ctx, &premaster_secret,
1652
+ &premaster_secret_len, &alert,
1653
+ CBS_data(&peer_key), CBS_len(&peer_key))) {
1654
+ al = alert;
1655
+ goto f_err;
1907
1656
  }
1908
1657
 
1909
- EVP_PKEY_free(clnt_pub_pkey);
1910
- clnt_pub_pkey = NULL;
1911
- EC_POINT_free(clnt_ecpoint);
1912
- clnt_ecpoint = NULL;
1913
- EC_KEY_free(srvr_ecdh);
1914
- srvr_ecdh = NULL;
1915
- BN_CTX_free(bn_ctx);
1916
- bn_ctx = NULL;
1917
- EC_KEY_free(s->s3->tmp.ecdh);
1918
- s->s3->tmp.ecdh = NULL;
1919
-
1920
- premaster_secret_len = ecdh_len;
1658
+ /* The key exchange state may now be discarded. */
1659
+ SSL_ECDH_CTX_cleanup(&ssl->s3->tmp.ecdh_ctx);
1921
1660
  } else if (alg_k & SSL_kPSK) {
1922
1661
  /* For plain PSK, other_secret is a block of 0s with the same length as the
1923
1662
  * pre-shared key. */
@@ -1960,40 +1699,34 @@ int ssl3_get_client_key_exchange(SSL *s) {
1960
1699
  }
1961
1700
 
1962
1701
  /* Compute the master secret */
1963
- s->session->master_key_length = s->enc_method->generate_master_secret(
1964
- s, s->session->master_key, premaster_secret, premaster_secret_len);
1965
- if (s->session->master_key_length == 0) {
1702
+ ssl->session->master_key_length = tls1_generate_master_secret(
1703
+ ssl, ssl->session->master_key, premaster_secret, premaster_secret_len);
1704
+ if (ssl->session->master_key_length == 0) {
1966
1705
  goto err;
1967
1706
  }
1968
- s->session->extended_master_secret = s->s3->tmp.extended_master_secret;
1707
+ ssl->session->extended_master_secret = ssl->s3->tmp.extended_master_secret;
1969
1708
 
1970
1709
  OPENSSL_cleanse(premaster_secret, premaster_secret_len);
1971
1710
  OPENSSL_free(premaster_secret);
1972
1711
  return 1;
1973
1712
 
1974
1713
  f_err:
1975
- ssl3_send_alert(s, SSL3_AL_FATAL, al);
1714
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
1976
1715
  err:
1977
- if (premaster_secret) {
1978
- if (premaster_secret_len) {
1979
- OPENSSL_cleanse(premaster_secret, premaster_secret_len);
1980
- }
1716
+ if (premaster_secret != NULL) {
1717
+ OPENSSL_cleanse(premaster_secret, premaster_secret_len);
1981
1718
  OPENSSL_free(premaster_secret);
1982
1719
  }
1983
1720
  OPENSSL_free(decrypt_buf);
1984
- EVP_PKEY_free(clnt_pub_pkey);
1985
- EC_POINT_free(clnt_ecpoint);
1986
- EC_KEY_free(srvr_ecdh);
1987
- BN_CTX_free(bn_ctx);
1988
1721
 
1989
1722
  return -1;
1990
1723
  }
1991
1724
 
1992
- int ssl3_get_cert_verify(SSL *s) {
1725
+ int ssl3_get_cert_verify(SSL *ssl) {
1993
1726
  int al, ok, ret = 0;
1994
1727
  long n;
1995
1728
  CBS certificate_verify, signature;
1996
- X509 *peer = s->session->peer;
1729
+ X509 *peer = ssl->session->peer;
1997
1730
  EVP_PKEY *pkey = NULL;
1998
1731
  const EVP_MD *md = NULL;
1999
1732
  uint8_t digest[EVP_MAX_MD_SIZE];
@@ -2004,12 +1737,12 @@ int ssl3_get_cert_verify(SSL *s) {
2004
1737
  * CertificateVerify is required if and only if there's a client certificate.
2005
1738
  * */
2006
1739
  if (peer == NULL) {
2007
- ssl3_free_handshake_buffer(s);
1740
+ ssl3_free_handshake_buffer(ssl);
2008
1741
  return 1;
2009
1742
  }
2010
1743
 
2011
- n = s->method->ssl_get_message(
2012
- s, SSL3_ST_SR_CERT_VRFY_A, SSL3_ST_SR_CERT_VRFY_B,
1744
+ n = ssl->method->ssl_get_message(
1745
+ ssl, SSL3_ST_SR_CERT_VRFY_A, SSL3_ST_SR_CERT_VRFY_B,
2013
1746
  SSL3_MT_CERTIFICATE_VERIFY, SSL3_RT_MAX_PLAIN_LENGTH,
2014
1747
  ssl_dont_hash_message, &ok);
2015
1748
 
@@ -2029,10 +1762,10 @@ int ssl3_get_cert_verify(SSL *s) {
2029
1762
  goto f_err;
2030
1763
  }
2031
1764
 
2032
- CBS_init(&certificate_verify, s->init_msg, n);
1765
+ CBS_init(&certificate_verify, ssl->init_msg, n);
2033
1766
 
2034
1767
  /* Determine the digest type if needbe. */
2035
- if (SSL_USE_SIGALGS(s)) {
1768
+ if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
2036
1769
  uint8_t hash, signature_type;
2037
1770
  if (!CBS_get_u8(&certificate_verify, &hash) ||
2038
1771
  !CBS_get_u8(&certificate_verify, &signature_type)) {
@@ -2040,20 +1773,20 @@ int ssl3_get_cert_verify(SSL *s) {
2040
1773
  OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
2041
1774
  goto f_err;
2042
1775
  }
2043
- if (!tls12_check_peer_sigalg(s, &md, &al, hash, signature_type, pkey)) {
1776
+ if (!tls12_check_peer_sigalg(ssl, &md, &al, hash, signature_type, pkey)) {
2044
1777
  goto f_err;
2045
1778
  }
2046
1779
  }
2047
1780
 
2048
1781
  /* Compute the digest. */
2049
- if (!ssl3_cert_verify_hash(s, digest, &digest_length, &md, pkey->type)) {
1782
+ if (!ssl3_cert_verify_hash(ssl, digest, &digest_length, &md, pkey->type)) {
2050
1783
  goto err;
2051
1784
  }
2052
1785
 
2053
1786
  /* The handshake buffer is no longer necessary, and we may hash the current
2054
1787
  * message.*/
2055
- ssl3_free_handshake_buffer(s);
2056
- if (!ssl3_hash_current_message(s)) {
1788
+ ssl3_free_handshake_buffer(ssl);
1789
+ if (!ssl3_hash_current_message(ssl)) {
2057
1790
  goto err;
2058
1791
  }
2059
1792
 
@@ -2082,7 +1815,7 @@ int ssl3_get_cert_verify(SSL *s) {
2082
1815
 
2083
1816
  if (0) {
2084
1817
  f_err:
2085
- ssl3_send_alert(s, SSL3_AL_FATAL, al);
1818
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
2086
1819
  }
2087
1820
 
2088
1821
  err:
@@ -2092,7 +1825,7 @@ err:
2092
1825
  return ret;
2093
1826
  }
2094
1827
 
2095
- int ssl3_get_client_certificate(SSL *s) {
1828
+ int ssl3_get_client_certificate(SSL *ssl) {
2096
1829
  int i, ok, al, ret = -1;
2097
1830
  X509 *x = NULL;
2098
1831
  unsigned long n;
@@ -2101,40 +1834,41 @@ int ssl3_get_client_certificate(SSL *s) {
2101
1834
  CBS certificate_msg, certificate_list;
2102
1835
  int is_first_certificate = 1;
2103
1836
 
2104
- n = s->method->ssl_get_message(s, SSL3_ST_SR_CERT_A, SSL3_ST_SR_CERT_B, -1,
2105
- (long)s->max_cert_list, ssl_hash_message, &ok);
1837
+ n = ssl->method->ssl_get_message(ssl, SSL3_ST_SR_CERT_A, SSL3_ST_SR_CERT_B,
1838
+ -1, (long)ssl->max_cert_list,
1839
+ ssl_hash_message, &ok);
2106
1840
 
2107
1841
  if (!ok) {
2108
1842
  return n;
2109
1843
  }
2110
1844
 
2111
- if (s->s3->tmp.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE) {
2112
- if ((s->verify_mode & SSL_VERIFY_PEER) &&
2113
- (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) {
1845
+ if (ssl->s3->tmp.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE) {
1846
+ if ((ssl->verify_mode & SSL_VERIFY_PEER) &&
1847
+ (ssl->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) {
2114
1848
  OPENSSL_PUT_ERROR(SSL, SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
2115
1849
  al = SSL_AD_HANDSHAKE_FAILURE;
2116
1850
  goto f_err;
2117
1851
  }
2118
1852
 
2119
1853
  /* If tls asked for a client cert, the client must return a 0 list */
2120
- if (s->version > SSL3_VERSION && s->s3->tmp.cert_request) {
1854
+ if (ssl->version > SSL3_VERSION && ssl->s3->tmp.cert_request) {
2121
1855
  OPENSSL_PUT_ERROR(SSL,
2122
1856
  SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST);
2123
1857
  al = SSL_AD_UNEXPECTED_MESSAGE;
2124
1858
  goto f_err;
2125
1859
  }
2126
- s->s3->tmp.reuse_message = 1;
1860
+ ssl->s3->tmp.reuse_message = 1;
2127
1861
 
2128
1862
  return 1;
2129
1863
  }
2130
1864
 
2131
- if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE) {
1865
+ if (ssl->s3->tmp.message_type != SSL3_MT_CERTIFICATE) {
2132
1866
  al = SSL_AD_UNEXPECTED_MESSAGE;
2133
1867
  OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_MESSAGE_TYPE);
2134
1868
  goto f_err;
2135
1869
  }
2136
1870
 
2137
- CBS_init(&certificate_msg, s->init_msg, n);
1871
+ CBS_init(&certificate_msg, ssl->init_msg, n);
2138
1872
 
2139
1873
  sk = sk_X509_new_null();
2140
1874
  if (sk == NULL) {
@@ -2159,13 +1893,13 @@ int ssl3_get_client_certificate(SSL *s) {
2159
1893
  goto f_err;
2160
1894
  }
2161
1895
 
2162
- if (is_first_certificate && s->ctx->retain_only_sha256_of_client_certs) {
1896
+ if (is_first_certificate && ssl->ctx->retain_only_sha256_of_client_certs) {
2163
1897
  /* If this is the first certificate, and we don't want to keep peer
2164
1898
  * certificates in memory, then we hash it right away. */
2165
1899
  SHA256_Init(&sha256);
2166
1900
  SHA256_Update(&sha256, CBS_data(&certificate), CBS_len(&certificate));
2167
- SHA256_Final(s->session->peer_sha256, &sha256);
2168
- s->session->peer_sha256_valid = 1;
1901
+ SHA256_Final(ssl->session->peer_sha256, &sha256);
1902
+ ssl->session->peer_sha256_valid = 1;
2169
1903
  }
2170
1904
  is_first_certificate = 0;
2171
1905
 
@@ -2191,35 +1925,35 @@ int ssl3_get_client_certificate(SSL *s) {
2191
1925
 
2192
1926
  if (sk_X509_num(sk) <= 0) {
2193
1927
  /* No client certificate so the handshake buffer may be discarded. */
2194
- ssl3_free_handshake_buffer(s);
1928
+ ssl3_free_handshake_buffer(ssl);
2195
1929
 
2196
1930
  /* TLS does not mind 0 certs returned */
2197
- if (s->version == SSL3_VERSION) {
1931
+ if (ssl->version == SSL3_VERSION) {
2198
1932
  al = SSL_AD_HANDSHAKE_FAILURE;
2199
1933
  OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CERTIFICATES_RETURNED);
2200
1934
  goto f_err;
2201
- } else if ((s->verify_mode & SSL_VERIFY_PEER) &&
2202
- (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) {
1935
+ } else if ((ssl->verify_mode & SSL_VERIFY_PEER) &&
1936
+ (ssl->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) {
2203
1937
  /* Fail for TLS only if we required a certificate */
2204
1938
  OPENSSL_PUT_ERROR(SSL, SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
2205
1939
  al = SSL_AD_HANDSHAKE_FAILURE;
2206
1940
  goto f_err;
2207
1941
  }
2208
1942
  } else {
2209
- i = ssl_verify_cert_chain(s, sk);
1943
+ i = ssl_verify_cert_chain(ssl, sk);
2210
1944
  if (i <= 0) {
2211
- al = ssl_verify_alarm_type(s->verify_result);
1945
+ al = ssl_verify_alarm_type(ssl->verify_result);
2212
1946
  OPENSSL_PUT_ERROR(SSL, SSL_R_CERTIFICATE_VERIFY_FAILED);
2213
1947
  goto f_err;
2214
1948
  }
2215
1949
  }
2216
1950
 
2217
- X509_free(s->session->peer);
2218
- s->session->peer = sk_X509_shift(sk);
2219
- s->session->verify_result = s->verify_result;
1951
+ X509_free(ssl->session->peer);
1952
+ ssl->session->peer = sk_X509_shift(sk);
1953
+ ssl->session->verify_result = ssl->verify_result;
2220
1954
 
2221
- sk_X509_pop_free(s->session->cert_chain, X509_free);
2222
- s->session->cert_chain = sk;
1955
+ sk_X509_pop_free(ssl->session->cert_chain, X509_free);
1956
+ ssl->session->cert_chain = sk;
2223
1957
  /* Inconsistency alert: cert_chain does *not* include the peer's own
2224
1958
  * certificate, while we do include it in s3_clnt.c */
2225
1959
 
@@ -2229,7 +1963,7 @@ int ssl3_get_client_certificate(SSL *s) {
2229
1963
 
2230
1964
  if (0) {
2231
1965
  f_err:
2232
- ssl3_send_alert(s, SSL3_AL_FATAL, al);
1966
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
2233
1967
  }
2234
1968
 
2235
1969
  err:
@@ -2238,20 +1972,20 @@ err:
2238
1972
  return ret;
2239
1973
  }
2240
1974
 
2241
- int ssl3_send_server_certificate(SSL *s) {
2242
- if (s->state == SSL3_ST_SW_CERT_A) {
2243
- if (!ssl3_output_cert_chain(s)) {
1975
+ int ssl3_send_server_certificate(SSL *ssl) {
1976
+ if (ssl->state == SSL3_ST_SW_CERT_A) {
1977
+ if (!ssl3_output_cert_chain(ssl)) {
2244
1978
  return 0;
2245
1979
  }
2246
- s->state = SSL3_ST_SW_CERT_B;
1980
+ ssl->state = SSL3_ST_SW_CERT_B;
2247
1981
  }
2248
1982
 
2249
1983
  /* SSL3_ST_SW_CERT_B */
2250
- return ssl_do_write(s);
1984
+ return ssl_do_write(ssl);
2251
1985
  }
2252
1986
 
2253
1987
  /* send a new session ticket (not necessarily for a new session) */
2254
- int ssl3_send_new_session_ticket(SSL *s) {
1988
+ int ssl3_send_new_session_ticket(SSL *ssl) {
2255
1989
  int ret = -1;
2256
1990
  uint8_t *session = NULL;
2257
1991
  size_t session_len;
@@ -2261,11 +1995,11 @@ int ssl3_send_new_session_ticket(SSL *s) {
2261
1995
  EVP_CIPHER_CTX_init(&ctx);
2262
1996
  HMAC_CTX_init(&hctx);
2263
1997
 
2264
- if (s->state == SSL3_ST_SW_SESSION_TICKET_A) {
1998
+ if (ssl->state == SSL3_ST_SW_SESSION_TICKET_A) {
2265
1999
  uint8_t *p, *macstart;
2266
2000
  int len;
2267
2001
  unsigned int hlen;
2268
- SSL_CTX *tctx = s->initial_ctx;
2002
+ SSL_CTX *tctx = ssl->initial_ctx;
2269
2003
  uint8_t iv[EVP_MAX_IV_LENGTH];
2270
2004
  uint8_t key_name[16];
2271
2005
  /* The maximum overhead of encrypting the session is 16 (key name) + IV +
@@ -2274,7 +2008,8 @@ int ssl3_send_new_session_ticket(SSL *s) {
2274
2008
  16 + EVP_MAX_IV_LENGTH + EVP_MAX_BLOCK_LENGTH + EVP_MAX_MD_SIZE;
2275
2009
 
2276
2010
  /* Serialize the SSL_SESSION to be encoded into the ticket. */
2277
- if (!SSL_SESSION_to_bytes_for_ticket(s->session, &session, &session_len)) {
2011
+ if (!SSL_SESSION_to_bytes_for_ticket(ssl->session, &session,
2012
+ &session_len)) {
2278
2013
  goto err;
2279
2014
  }
2280
2015
 
@@ -2287,7 +2022,7 @@ int ssl3_send_new_session_ticket(SSL *s) {
2287
2022
  OPENSSL_free(session);
2288
2023
  session = NULL;
2289
2024
 
2290
- p = ssl_handshake_start(s);
2025
+ p = ssl_handshake_start(ssl);
2291
2026
  /* Emit ticket_lifetime_hint. */
2292
2027
  l2n(0, p);
2293
2028
  /* Emit ticket. */
@@ -2295,26 +2030,26 @@ int ssl3_send_new_session_ticket(SSL *s) {
2295
2030
  memcpy(p, kTicketPlaceholder, placeholder_len);
2296
2031
  p += placeholder_len;
2297
2032
 
2298
- len = p - ssl_handshake_start(s);
2299
- if (!ssl_set_handshake_header(s, SSL3_MT_NEWSESSION_TICKET, len)) {
2033
+ len = p - ssl_handshake_start(ssl);
2034
+ if (!ssl_set_handshake_header(ssl, SSL3_MT_NEWSESSION_TICKET, len)) {
2300
2035
  goto err;
2301
2036
  }
2302
- s->state = SSL3_ST_SW_SESSION_TICKET_B;
2303
- return ssl_do_write(s);
2037
+ ssl->state = SSL3_ST_SW_SESSION_TICKET_B;
2038
+ return ssl_do_write(ssl);
2304
2039
  }
2305
2040
 
2306
2041
  /* Grow buffer if need be: the length calculation is as follows:
2307
2042
  * handshake_header_length + 4 (ticket lifetime hint) + 2 (ticket length) +
2308
2043
  * max_ticket_overhead + * session_length */
2309
- if (!BUF_MEM_grow(s->init_buf, SSL_HM_HEADER_LENGTH(s) + 6 +
2044
+ if (!BUF_MEM_grow(ssl->init_buf, SSL_HM_HEADER_LENGTH(ssl) + 6 +
2310
2045
  max_ticket_overhead + session_len)) {
2311
2046
  goto err;
2312
2047
  }
2313
- p = ssl_handshake_start(s);
2048
+ p = ssl_handshake_start(ssl);
2314
2049
  /* Initialize HMAC and cipher contexts. If callback present it does all the
2315
2050
  * work otherwise use generated values from parent ctx. */
2316
2051
  if (tctx->tlsext_ticket_key_cb) {
2317
- if (tctx->tlsext_ticket_key_cb(s, key_name, iv, &ctx, &hctx,
2052
+ if (tctx->tlsext_ticket_key_cb(ssl, key_name, iv, &ctx, &hctx,
2318
2053
  1 /* encrypt */) < 0) {
2319
2054
  goto err;
2320
2055
  }
@@ -2332,7 +2067,7 @@ int ssl3_send_new_session_ticket(SSL *s) {
2332
2067
  /* Ticket lifetime hint (advisory only): We leave this unspecified for
2333
2068
  * resumed session (for simplicity), and guess that tickets for new
2334
2069
  * sessions will live as long as their sessions. */
2335
- l2n(s->hit ? 0 : s->session->timeout, p);
2070
+ l2n(ssl->hit ? 0 : ssl->session->timeout, p);
2336
2071
 
2337
2072
  /* Skip ticket length for now */
2338
2073
  p += 2;
@@ -2361,18 +2096,18 @@ int ssl3_send_new_session_ticket(SSL *s) {
2361
2096
  p += hlen;
2362
2097
  /* Now write out lengths: p points to end of data written */
2363
2098
  /* Total length */
2364
- len = p - ssl_handshake_start(s);
2099
+ len = p - ssl_handshake_start(ssl);
2365
2100
  /* Skip ticket lifetime hint */
2366
- p = ssl_handshake_start(s) + 4;
2101
+ p = ssl_handshake_start(ssl) + 4;
2367
2102
  s2n(len - 6, p);
2368
- if (!ssl_set_handshake_header(s, SSL3_MT_NEWSESSION_TICKET, len)) {
2103
+ if (!ssl_set_handshake_header(ssl, SSL3_MT_NEWSESSION_TICKET, len)) {
2369
2104
  goto err;
2370
2105
  }
2371
- s->state = SSL3_ST_SW_SESSION_TICKET_B;
2106
+ ssl->state = SSL3_ST_SW_SESSION_TICKET_B;
2372
2107
  }
2373
2108
 
2374
2109
  /* SSL3_ST_SW_SESSION_TICKET_B */
2375
- ret = ssl_do_write(s);
2110
+ ret = ssl_do_write(ssl);
2376
2111
 
2377
2112
  err:
2378
2113
  OPENSSL_free(session);
@@ -2383,19 +2118,19 @@ err:
2383
2118
 
2384
2119
  /* ssl3_get_next_proto reads a Next Protocol Negotiation handshake message. It
2385
2120
  * sets the next_proto member in s if found */
2386
- int ssl3_get_next_proto(SSL *s) {
2121
+ int ssl3_get_next_proto(SSL *ssl) {
2387
2122
  int ok;
2388
2123
  long n;
2389
2124
  CBS next_protocol, selected_protocol, padding;
2390
2125
 
2391
2126
  /* Clients cannot send a NextProtocol message if we didn't see the extension
2392
2127
  * in their ClientHello */
2393
- if (!s->s3->next_proto_neg_seen) {
2128
+ if (!ssl->s3->next_proto_neg_seen) {
2394
2129
  OPENSSL_PUT_ERROR(SSL, SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION);
2395
2130
  return -1;
2396
2131
  }
2397
2132
 
2398
- n = s->method->ssl_get_message(s, SSL3_ST_SR_NEXT_PROTO_A,
2133
+ n = ssl->method->ssl_get_message(ssl, SSL3_ST_SR_NEXT_PROTO_A,
2399
2134
  SSL3_ST_SR_NEXT_PROTO_B, SSL3_MT_NEXT_PROTO,
2400
2135
  514, /* See the payload format below */
2401
2136
  ssl_hash_message, &ok);
@@ -2404,7 +2139,7 @@ int ssl3_get_next_proto(SSL *s) {
2404
2139
  return n;
2405
2140
  }
2406
2141
 
2407
- CBS_init(&next_protocol, s->init_msg, n);
2142
+ CBS_init(&next_protocol, ssl->init_msg, n);
2408
2143
 
2409
2144
  /* The payload looks like:
2410
2145
  * uint8 proto_len;
@@ -2414,8 +2149,8 @@ int ssl3_get_next_proto(SSL *s) {
2414
2149
  if (!CBS_get_u8_length_prefixed(&next_protocol, &selected_protocol) ||
2415
2150
  !CBS_get_u8_length_prefixed(&next_protocol, &padding) ||
2416
2151
  CBS_len(&next_protocol) != 0 ||
2417
- !CBS_stow(&selected_protocol, &s->next_proto_negotiated,
2418
- &s->next_proto_negotiated_len)) {
2152
+ !CBS_stow(&selected_protocol, &ssl->s3->next_proto_negotiated,
2153
+ &ssl->s3->next_proto_negotiated_len)) {
2419
2154
  return 0;
2420
2155
  }
2421
2156
 
@@ -2423,7 +2158,7 @@ int ssl3_get_next_proto(SSL *s) {
2423
2158
  }
2424
2159
 
2425
2160
  /* ssl3_get_channel_id reads and verifies a ClientID handshake message. */
2426
- int ssl3_get_channel_id(SSL *s) {
2161
+ int ssl3_get_channel_id(SSL *ssl) {
2427
2162
  int ret = -1, ok;
2428
2163
  long n;
2429
2164
  uint8_t channel_id_hash[EVP_MAX_MD_SIZE];
@@ -2437,8 +2172,8 @@ int ssl3_get_channel_id(SSL *s) {
2437
2172
  BIGNUM x, y;
2438
2173
  CBS encrypted_extensions, extension;
2439
2174
 
2440
- n = s->method->ssl_get_message(
2441
- s, SSL3_ST_SR_CHANNEL_ID_A, SSL3_ST_SR_CHANNEL_ID_B,
2175
+ n = ssl->method->ssl_get_message(
2176
+ ssl, SSL3_ST_SR_CHANNEL_ID_A, SSL3_ST_SR_CHANNEL_ID_B,
2442
2177
  SSL3_MT_ENCRYPTED_EXTENSIONS, 2 + 2 + TLSEXT_CHANNEL_ID_SIZE,
2443
2178
  ssl_dont_hash_message, &ok);
2444
2179
 
@@ -2448,16 +2183,16 @@ int ssl3_get_channel_id(SSL *s) {
2448
2183
 
2449
2184
  /* Before incorporating the EncryptedExtensions message to the handshake
2450
2185
  * hash, compute the hash that should have been signed. */
2451
- if (!tls1_channel_id_hash(s, channel_id_hash, &channel_id_hash_len)) {
2186
+ if (!tls1_channel_id_hash(ssl, channel_id_hash, &channel_id_hash_len)) {
2452
2187
  return -1;
2453
2188
  }
2454
2189
  assert(channel_id_hash_len == SHA256_DIGEST_LENGTH);
2455
2190
 
2456
- if (!ssl3_hash_current_message(s)) {
2191
+ if (!ssl3_hash_current_message(ssl)) {
2457
2192
  return -1;
2458
2193
  }
2459
2194
 
2460
- CBS_init(&encrypted_extensions, s->init_msg, n);
2195
+ CBS_init(&encrypted_extensions, ssl->init_msg, n);
2461
2196
 
2462
2197
  /* EncryptedExtensions could include multiple extensions, but the only
2463
2198
  * extension that could be negotiated is ChannelID, so there can only be one
@@ -2503,7 +2238,8 @@ int ssl3_get_channel_id(SSL *s) {
2503
2238
  }
2504
2239
 
2505
2240
  point = EC_POINT_new(p256);
2506
- if (!point || !EC_POINT_set_affine_coordinates_GFp(p256, point, &x, &y, NULL)) {
2241
+ if (!point ||
2242
+ !EC_POINT_set_affine_coordinates_GFp(p256, point, &x, &y, NULL)) {
2507
2243
  goto err;
2508
2244
  }
2509
2245
 
@@ -2517,11 +2253,11 @@ int ssl3_get_channel_id(SSL *s) {
2517
2253
  * were called. */
2518
2254
  if (!ECDSA_do_verify(channel_id_hash, channel_id_hash_len, &sig, key)) {
2519
2255
  OPENSSL_PUT_ERROR(SSL, SSL_R_CHANNEL_ID_SIGNATURE_INVALID);
2520
- s->s3->tlsext_channel_id_valid = 0;
2256
+ ssl->s3->tlsext_channel_id_valid = 0;
2521
2257
  goto err;
2522
2258
  }
2523
2259
 
2524
- memcpy(s->s3->tlsext_channel_id, p, 64);
2260
+ memcpy(ssl->s3->tlsext_channel_id, p, 64);
2525
2261
  ret = 1;
2526
2262
 
2527
2263
  err: