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
@@ -172,37 +172,37 @@
172
172
  #include "../crypto/dh/internal.h"
173
173
 
174
174
 
175
- int ssl3_connect(SSL *s) {
175
+ int ssl3_connect(SSL *ssl) {
176
176
  BUF_MEM *buf = NULL;
177
177
  void (*cb)(const SSL *ssl, int type, int value) = NULL;
178
178
  int ret = -1;
179
179
  int new_state, state, skip = 0;
180
180
 
181
- assert(s->handshake_func == ssl3_connect);
182
- assert(!s->server);
183
- assert(!SSL_IS_DTLS(s));
181
+ assert(ssl->handshake_func == ssl3_connect);
182
+ assert(!ssl->server);
183
+ assert(!SSL_IS_DTLS(ssl));
184
184
 
185
185
  ERR_clear_error();
186
186
  ERR_clear_system_error();
187
187
 
188
- if (s->info_callback != NULL) {
189
- cb = s->info_callback;
190
- } else if (s->ctx->info_callback != NULL) {
191
- cb = s->ctx->info_callback;
188
+ if (ssl->info_callback != NULL) {
189
+ cb = ssl->info_callback;
190
+ } else if (ssl->ctx->info_callback != NULL) {
191
+ cb = ssl->ctx->info_callback;
192
192
  }
193
193
 
194
- s->in_handshake++;
194
+ ssl->in_handshake++;
195
195
 
196
196
  for (;;) {
197
- state = s->state;
197
+ state = ssl->state;
198
198
 
199
- switch (s->state) {
199
+ switch (ssl->state) {
200
200
  case SSL_ST_CONNECT:
201
201
  if (cb != NULL) {
202
- cb(s, SSL_CB_HANDSHAKE_START, 1);
202
+ cb(ssl, SSL_CB_HANDSHAKE_START, 1);
203
203
  }
204
204
 
205
- if (s->init_buf == NULL) {
205
+ if (ssl->init_buf == NULL) {
206
206
  buf = BUF_MEM_new();
207
207
  if (buf == NULL ||
208
208
  !BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH)) {
@@ -210,124 +210,124 @@ int ssl3_connect(SSL *s) {
210
210
  goto end;
211
211
  }
212
212
 
213
- s->init_buf = buf;
213
+ ssl->init_buf = buf;
214
214
  buf = NULL;
215
215
  }
216
216
 
217
- if (!ssl_init_wbio_buffer(s, 0)) {
217
+ if (!ssl_init_wbio_buffer(ssl, 0)) {
218
218
  ret = -1;
219
219
  goto end;
220
220
  }
221
221
 
222
222
  /* don't push the buffering BIO quite yet */
223
223
 
224
- if (!ssl3_init_handshake_buffer(s)) {
224
+ if (!ssl3_init_handshake_buffer(ssl)) {
225
225
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
226
226
  ret = -1;
227
227
  goto end;
228
228
  }
229
229
 
230
- s->state = SSL3_ST_CW_CLNT_HELLO_A;
231
- s->init_num = 0;
230
+ ssl->state = SSL3_ST_CW_CLNT_HELLO_A;
231
+ ssl->init_num = 0;
232
232
  break;
233
233
 
234
234
  case SSL3_ST_CW_CLNT_HELLO_A:
235
235
  case SSL3_ST_CW_CLNT_HELLO_B:
236
- s->shutdown = 0;
237
- ret = ssl3_send_client_hello(s);
236
+ ssl->shutdown = 0;
237
+ ret = ssl3_send_client_hello(ssl);
238
238
  if (ret <= 0) {
239
239
  goto end;
240
240
  }
241
- s->state = SSL3_ST_CR_SRVR_HELLO_A;
242
- s->init_num = 0;
241
+ ssl->state = SSL3_ST_CR_SRVR_HELLO_A;
242
+ ssl->init_num = 0;
243
243
 
244
244
  /* turn on buffering for the next lot of output */
245
- if (s->bbio != s->wbio) {
246
- s->wbio = BIO_push(s->bbio, s->wbio);
245
+ if (ssl->bbio != ssl->wbio) {
246
+ ssl->wbio = BIO_push(ssl->bbio, ssl->wbio);
247
247
  }
248
248
 
249
249
  break;
250
250
 
251
251
  case SSL3_ST_CR_SRVR_HELLO_A:
252
252
  case SSL3_ST_CR_SRVR_HELLO_B:
253
- ret = ssl3_get_server_hello(s);
253
+ ret = ssl3_get_server_hello(ssl);
254
254
  if (ret <= 0) {
255
255
  goto end;
256
256
  }
257
257
 
258
- if (s->hit) {
259
- s->state = SSL3_ST_CR_CHANGE;
260
- if (s->tlsext_ticket_expected) {
258
+ if (ssl->hit) {
259
+ ssl->state = SSL3_ST_CR_CHANGE;
260
+ if (ssl->tlsext_ticket_expected) {
261
261
  /* receive renewed session ticket */
262
- s->state = SSL3_ST_CR_SESSION_TICKET_A;
262
+ ssl->state = SSL3_ST_CR_SESSION_TICKET_A;
263
263
  }
264
264
  } else {
265
- s->state = SSL3_ST_CR_CERT_A;
265
+ ssl->state = SSL3_ST_CR_CERT_A;
266
266
  }
267
- s->init_num = 0;
267
+ ssl->init_num = 0;
268
268
  break;
269
269
 
270
270
  case SSL3_ST_CR_CERT_A:
271
271
  case SSL3_ST_CR_CERT_B:
272
- if (ssl_cipher_has_server_public_key(s->s3->tmp.new_cipher)) {
273
- ret = ssl3_get_server_certificate(s);
272
+ if (ssl_cipher_has_server_public_key(ssl->s3->tmp.new_cipher)) {
273
+ ret = ssl3_get_server_certificate(ssl);
274
274
  if (ret <= 0) {
275
275
  goto end;
276
276
  }
277
- if (s->s3->tmp.certificate_status_expected) {
278
- s->state = SSL3_ST_CR_CERT_STATUS_A;
277
+ if (ssl->s3->tmp.certificate_status_expected) {
278
+ ssl->state = SSL3_ST_CR_CERT_STATUS_A;
279
279
  } else {
280
- s->state = SSL3_ST_VERIFY_SERVER_CERT;
280
+ ssl->state = SSL3_ST_VERIFY_SERVER_CERT;
281
281
  }
282
282
  } else {
283
283
  skip = 1;
284
- s->state = SSL3_ST_CR_KEY_EXCH_A;
284
+ ssl->state = SSL3_ST_CR_KEY_EXCH_A;
285
285
  }
286
- s->init_num = 0;
286
+ ssl->init_num = 0;
287
287
  break;
288
288
 
289
289
  case SSL3_ST_VERIFY_SERVER_CERT:
290
- ret = ssl3_verify_server_cert(s);
290
+ ret = ssl3_verify_server_cert(ssl);
291
291
  if (ret <= 0) {
292
292
  goto end;
293
293
  }
294
294
 
295
- s->state = SSL3_ST_CR_KEY_EXCH_A;
296
- s->init_num = 0;
295
+ ssl->state = SSL3_ST_CR_KEY_EXCH_A;
296
+ ssl->init_num = 0;
297
297
  break;
298
298
 
299
299
  case SSL3_ST_CR_KEY_EXCH_A:
300
300
  case SSL3_ST_CR_KEY_EXCH_B:
301
- ret = ssl3_get_server_key_exchange(s);
301
+ ret = ssl3_get_server_key_exchange(ssl);
302
302
  if (ret <= 0) {
303
303
  goto end;
304
304
  }
305
- s->state = SSL3_ST_CR_CERT_REQ_A;
306
- s->init_num = 0;
305
+ ssl->state = SSL3_ST_CR_CERT_REQ_A;
306
+ ssl->init_num = 0;
307
307
  break;
308
308
 
309
309
  case SSL3_ST_CR_CERT_REQ_A:
310
310
  case SSL3_ST_CR_CERT_REQ_B:
311
- ret = ssl3_get_certificate_request(s);
311
+ ret = ssl3_get_certificate_request(ssl);
312
312
  if (ret <= 0) {
313
313
  goto end;
314
314
  }
315
- s->state = SSL3_ST_CR_SRVR_DONE_A;
316
- s->init_num = 0;
315
+ ssl->state = SSL3_ST_CR_SRVR_DONE_A;
316
+ ssl->init_num = 0;
317
317
  break;
318
318
 
319
319
  case SSL3_ST_CR_SRVR_DONE_A:
320
320
  case SSL3_ST_CR_SRVR_DONE_B:
321
- ret = ssl3_get_server_done(s);
321
+ ret = ssl3_get_server_done(ssl);
322
322
  if (ret <= 0) {
323
323
  goto end;
324
324
  }
325
- if (s->s3->tmp.cert_req) {
326
- s->state = SSL3_ST_CW_CERT_A;
325
+ if (ssl->s3->tmp.cert_req) {
326
+ ssl->state = SSL3_ST_CW_CERT_A;
327
327
  } else {
328
- s->state = SSL3_ST_CW_KEY_EXCH_A;
328
+ ssl->state = SSL3_ST_CW_KEY_EXCH_A;
329
329
  }
330
- s->init_num = 0;
330
+ ssl->init_num = 0;
331
331
 
332
332
  break;
333
333
 
@@ -335,63 +335,60 @@ int ssl3_connect(SSL *s) {
335
335
  case SSL3_ST_CW_CERT_B:
336
336
  case SSL3_ST_CW_CERT_C:
337
337
  case SSL3_ST_CW_CERT_D:
338
- ret = ssl3_send_client_certificate(s);
338
+ ret = ssl3_send_client_certificate(ssl);
339
339
  if (ret <= 0) {
340
340
  goto end;
341
341
  }
342
- s->state = SSL3_ST_CW_KEY_EXCH_A;
343
- s->init_num = 0;
342
+ ssl->state = SSL3_ST_CW_KEY_EXCH_A;
343
+ ssl->init_num = 0;
344
344
  break;
345
345
 
346
346
  case SSL3_ST_CW_KEY_EXCH_A:
347
347
  case SSL3_ST_CW_KEY_EXCH_B:
348
- ret = ssl3_send_client_key_exchange(s);
348
+ ret = ssl3_send_client_key_exchange(ssl);
349
349
  if (ret <= 0) {
350
350
  goto end;
351
351
  }
352
352
  /* For TLS, cert_req is set to 2, so a cert chain
353
353
  * of nothing is sent, but no verify packet is sent */
354
- if (s->s3->tmp.cert_req == 1) {
355
- s->state = SSL3_ST_CW_CERT_VRFY_A;
354
+ if (ssl->s3->tmp.cert_req == 1) {
355
+ ssl->state = SSL3_ST_CW_CERT_VRFY_A;
356
356
  } else {
357
- s->state = SSL3_ST_CW_CHANGE_A;
357
+ ssl->state = SSL3_ST_CW_CHANGE_A;
358
358
  }
359
359
 
360
- s->init_num = 0;
360
+ ssl->init_num = 0;
361
361
  break;
362
362
 
363
363
  case SSL3_ST_CW_CERT_VRFY_A:
364
364
  case SSL3_ST_CW_CERT_VRFY_B:
365
365
  case SSL3_ST_CW_CERT_VRFY_C:
366
- ret = ssl3_send_cert_verify(s);
366
+ ret = ssl3_send_cert_verify(ssl);
367
367
  if (ret <= 0) {
368
368
  goto end;
369
369
  }
370
- s->state = SSL3_ST_CW_CHANGE_A;
371
- s->init_num = 0;
370
+ ssl->state = SSL3_ST_CW_CHANGE_A;
371
+ ssl->init_num = 0;
372
372
  break;
373
373
 
374
374
  case SSL3_ST_CW_CHANGE_A:
375
375
  case SSL3_ST_CW_CHANGE_B:
376
- ret = ssl3_send_change_cipher_spec(s, SSL3_ST_CW_CHANGE_A,
376
+ ret = ssl3_send_change_cipher_spec(ssl, SSL3_ST_CW_CHANGE_A,
377
377
  SSL3_ST_CW_CHANGE_B);
378
378
  if (ret <= 0) {
379
379
  goto end;
380
380
  }
381
381
 
382
- s->state = SSL3_ST_CW_FINISHED_A;
383
- if (s->s3->tlsext_channel_id_valid) {
384
- s->state = SSL3_ST_CW_CHANNEL_ID_A;
382
+ ssl->state = SSL3_ST_CW_FINISHED_A;
383
+ if (ssl->s3->tlsext_channel_id_valid) {
384
+ ssl->state = SSL3_ST_CW_CHANNEL_ID_A;
385
385
  }
386
- if (s->s3->next_proto_neg_seen) {
387
- s->state = SSL3_ST_CW_NEXT_PROTO_A;
386
+ if (ssl->s3->next_proto_neg_seen) {
387
+ ssl->state = SSL3_ST_CW_NEXT_PROTO_A;
388
388
  }
389
- s->init_num = 0;
389
+ ssl->init_num = 0;
390
390
 
391
- s->session->cipher = s->s3->tmp.new_cipher;
392
- if (!s->enc_method->setup_key_block(s) ||
393
- !s->enc_method->change_cipher_state(
394
- s, SSL3_CHANGE_CIPHER_CLIENT_WRITE)) {
391
+ if (!tls1_change_cipher_state(ssl, SSL3_CHANGE_CIPHER_CLIENT_WRITE)) {
395
392
  ret = -1;
396
393
  goto end;
397
394
  }
@@ -400,165 +397,163 @@ int ssl3_connect(SSL *s) {
400
397
 
401
398
  case SSL3_ST_CW_NEXT_PROTO_A:
402
399
  case SSL3_ST_CW_NEXT_PROTO_B:
403
- ret = ssl3_send_next_proto(s);
400
+ ret = ssl3_send_next_proto(ssl);
404
401
  if (ret <= 0) {
405
402
  goto end;
406
403
  }
407
404
 
408
- if (s->s3->tlsext_channel_id_valid) {
409
- s->state = SSL3_ST_CW_CHANNEL_ID_A;
405
+ if (ssl->s3->tlsext_channel_id_valid) {
406
+ ssl->state = SSL3_ST_CW_CHANNEL_ID_A;
410
407
  } else {
411
- s->state = SSL3_ST_CW_FINISHED_A;
408
+ ssl->state = SSL3_ST_CW_FINISHED_A;
412
409
  }
413
410
  break;
414
411
 
415
412
  case SSL3_ST_CW_CHANNEL_ID_A:
416
413
  case SSL3_ST_CW_CHANNEL_ID_B:
417
- ret = ssl3_send_channel_id(s);
414
+ ret = ssl3_send_channel_id(ssl);
418
415
  if (ret <= 0) {
419
416
  goto end;
420
417
  }
421
- s->state = SSL3_ST_CW_FINISHED_A;
418
+ ssl->state = SSL3_ST_CW_FINISHED_A;
422
419
  break;
423
420
 
424
421
  case SSL3_ST_CW_FINISHED_A:
425
422
  case SSL3_ST_CW_FINISHED_B:
426
- ret =
427
- ssl3_send_finished(s, SSL3_ST_CW_FINISHED_A, SSL3_ST_CW_FINISHED_B,
428
- s->enc_method->client_finished_label,
429
- s->enc_method->client_finished_label_len);
423
+ ret = ssl3_send_finished(ssl, SSL3_ST_CW_FINISHED_A,
424
+ SSL3_ST_CW_FINISHED_B);
430
425
  if (ret <= 0) {
431
426
  goto end;
432
427
  }
433
- s->state = SSL3_ST_CW_FLUSH;
428
+ ssl->state = SSL3_ST_CW_FLUSH;
434
429
 
435
- if (s->hit) {
436
- s->s3->tmp.next_state = SSL_ST_OK;
430
+ if (ssl->hit) {
431
+ ssl->s3->tmp.next_state = SSL_ST_OK;
437
432
  } else {
438
433
  /* This is a non-resumption handshake. If it involves ChannelID, then
439
434
  * record the handshake hashes at this point in the session so that
440
435
  * any resumption of this session with ChannelID can sign those
441
436
  * hashes. */
442
- ret = tls1_record_handshake_hashes_for_channel_id(s);
437
+ ret = tls1_record_handshake_hashes_for_channel_id(ssl);
443
438
  if (ret <= 0) {
444
439
  goto end;
445
440
  }
446
- if ((SSL_get_mode(s) & SSL_MODE_ENABLE_FALSE_START) &&
447
- ssl3_can_false_start(s) &&
441
+ if ((SSL_get_mode(ssl) & SSL_MODE_ENABLE_FALSE_START) &&
442
+ ssl3_can_false_start(ssl) &&
448
443
  /* No False Start on renegotiation (would complicate the state
449
444
  * machine). */
450
- !s->s3->initial_handshake_complete) {
451
- s->s3->tmp.next_state = SSL3_ST_FALSE_START;
445
+ !ssl->s3->initial_handshake_complete) {
446
+ ssl->s3->tmp.next_state = SSL3_ST_FALSE_START;
452
447
  } else {
453
448
  /* Allow NewSessionTicket if ticket expected */
454
- if (s->tlsext_ticket_expected) {
455
- s->s3->tmp.next_state = SSL3_ST_CR_SESSION_TICKET_A;
449
+ if (ssl->tlsext_ticket_expected) {
450
+ ssl->s3->tmp.next_state = SSL3_ST_CR_SESSION_TICKET_A;
456
451
  } else {
457
- s->s3->tmp.next_state = SSL3_ST_CR_CHANGE;
452
+ ssl->s3->tmp.next_state = SSL3_ST_CR_CHANGE;
458
453
  }
459
454
  }
460
455
  }
461
- s->init_num = 0;
456
+ ssl->init_num = 0;
462
457
  break;
463
458
 
464
459
  case SSL3_ST_CR_SESSION_TICKET_A:
465
460
  case SSL3_ST_CR_SESSION_TICKET_B:
466
- ret = ssl3_get_new_session_ticket(s);
461
+ ret = ssl3_get_new_session_ticket(ssl);
467
462
  if (ret <= 0) {
468
463
  goto end;
469
464
  }
470
- s->state = SSL3_ST_CR_CHANGE;
471
- s->init_num = 0;
465
+ ssl->state = SSL3_ST_CR_CHANGE;
466
+ ssl->init_num = 0;
472
467
  break;
473
468
 
474
469
  case SSL3_ST_CR_CERT_STATUS_A:
475
470
  case SSL3_ST_CR_CERT_STATUS_B:
476
- ret = ssl3_get_cert_status(s);
471
+ ret = ssl3_get_cert_status(ssl);
477
472
  if (ret <= 0) {
478
473
  goto end;
479
474
  }
480
- s->state = SSL3_ST_VERIFY_SERVER_CERT;
481
- s->init_num = 0;
475
+ ssl->state = SSL3_ST_VERIFY_SERVER_CERT;
476
+ ssl->init_num = 0;
482
477
  break;
483
478
 
484
479
  case SSL3_ST_CR_CHANGE:
485
- ret = s->method->ssl_read_change_cipher_spec(s);
480
+ ret = ssl->method->ssl_read_change_cipher_spec(ssl);
486
481
  if (ret <= 0) {
487
482
  goto end;
488
483
  }
489
484
 
490
- if (!ssl3_do_change_cipher_spec(s)) {
485
+ if (!tls1_change_cipher_state(ssl, SSL3_CHANGE_CIPHER_CLIENT_READ)) {
491
486
  ret = -1;
492
487
  goto end;
493
488
  }
494
- s->state = SSL3_ST_CR_FINISHED_A;
489
+ ssl->state = SSL3_ST_CR_FINISHED_A;
495
490
  break;
496
491
 
497
492
  case SSL3_ST_CR_FINISHED_A:
498
493
  case SSL3_ST_CR_FINISHED_B:
499
- ret =
500
- ssl3_get_finished(s, SSL3_ST_CR_FINISHED_A, SSL3_ST_CR_FINISHED_B);
494
+ ret = ssl3_get_finished(ssl, SSL3_ST_CR_FINISHED_A,
495
+ SSL3_ST_CR_FINISHED_B);
501
496
  if (ret <= 0) {
502
497
  goto end;
503
498
  }
504
499
 
505
- if (s->hit) {
506
- s->state = SSL3_ST_CW_CHANGE_A;
500
+ if (ssl->hit) {
501
+ ssl->state = SSL3_ST_CW_CHANGE_A;
507
502
  } else {
508
- s->state = SSL_ST_OK;
503
+ ssl->state = SSL_ST_OK;
509
504
  }
510
- s->init_num = 0;
505
+ ssl->init_num = 0;
511
506
  break;
512
507
 
513
508
  case SSL3_ST_CW_FLUSH:
514
- s->rwstate = SSL_WRITING;
515
- if (BIO_flush(s->wbio) <= 0) {
509
+ ssl->rwstate = SSL_WRITING;
510
+ if (BIO_flush(ssl->wbio) <= 0) {
516
511
  ret = -1;
517
512
  goto end;
518
513
  }
519
- s->rwstate = SSL_NOTHING;
520
- s->state = s->s3->tmp.next_state;
514
+ ssl->rwstate = SSL_NOTHING;
515
+ ssl->state = ssl->s3->tmp.next_state;
521
516
  break;
522
517
 
523
518
  case SSL3_ST_FALSE_START:
524
519
  /* Allow NewSessionTicket if ticket expected */
525
- if (s->tlsext_ticket_expected) {
526
- s->state = SSL3_ST_CR_SESSION_TICKET_A;
520
+ if (ssl->tlsext_ticket_expected) {
521
+ ssl->state = SSL3_ST_CR_SESSION_TICKET_A;
527
522
  } else {
528
- s->state = SSL3_ST_CR_CHANGE;
523
+ ssl->state = SSL3_ST_CR_CHANGE;
529
524
  }
530
- s->s3->tmp.in_false_start = 1;
525
+ ssl->s3->tmp.in_false_start = 1;
531
526
 
532
- ssl_free_wbio_buffer(s);
527
+ ssl_free_wbio_buffer(ssl);
533
528
  ret = 1;
534
529
  goto end;
535
530
 
536
531
  case SSL_ST_OK:
537
532
  /* clean a few things up */
538
- ssl3_cleanup_key_block(s);
533
+ ssl3_cleanup_key_block(ssl);
539
534
 
540
- BUF_MEM_free(s->init_buf);
541
- s->init_buf = NULL;
535
+ BUF_MEM_free(ssl->init_buf);
536
+ ssl->init_buf = NULL;
542
537
 
543
538
  /* Remove write buffering now. */
544
- ssl_free_wbio_buffer(s);
539
+ ssl_free_wbio_buffer(ssl);
545
540
 
546
- const int is_initial_handshake = !s->s3->initial_handshake_complete;
541
+ const int is_initial_handshake = !ssl->s3->initial_handshake_complete;
547
542
 
548
- s->init_num = 0;
549
- s->s3->tmp.in_false_start = 0;
550
- s->s3->initial_handshake_complete = 1;
543
+ ssl->init_num = 0;
544
+ ssl->s3->tmp.in_false_start = 0;
545
+ ssl->s3->initial_handshake_complete = 1;
551
546
 
552
547
  if (is_initial_handshake) {
553
548
  /* Renegotiations do not participate in session resumption. */
554
- ssl_update_cache(s, SSL_SESS_CACHE_CLIENT);
549
+ ssl_update_cache(ssl, SSL_SESS_CACHE_CLIENT);
555
550
  }
556
551
 
557
552
  ret = 1;
558
- /* s->server=0; */
553
+ /* ssl->server=0; */
559
554
 
560
555
  if (cb != NULL) {
561
- cb(s, SSL_CB_HANDSHAKE_DONE, 1);
556
+ cb(ssl, SSL_CB_HANDSHAKE_DONE, 1);
562
557
  }
563
558
 
564
559
  goto end;
@@ -569,22 +564,22 @@ int ssl3_connect(SSL *s) {
569
564
  goto end;
570
565
  }
571
566
 
572
- if (!s->s3->tmp.reuse_message && !skip) {
573
- if (cb != NULL && s->state != state) {
574
- new_state = s->state;
575
- s->state = state;
576
- cb(s, SSL_CB_CONNECT_LOOP, 1);
577
- s->state = new_state;
567
+ if (!ssl->s3->tmp.reuse_message && !skip) {
568
+ if (cb != NULL && ssl->state != state) {
569
+ new_state = ssl->state;
570
+ ssl->state = state;
571
+ cb(ssl, SSL_CB_CONNECT_LOOP, 1);
572
+ ssl->state = new_state;
578
573
  }
579
574
  }
580
575
  skip = 0;
581
576
  }
582
577
 
583
578
  end:
584
- s->in_handshake--;
579
+ ssl->in_handshake--;
585
580
  BUF_MEM_free(buf);
586
581
  if (cb != NULL) {
587
- cb(s, SSL_CB_CONNECT_EXIT, ret);
582
+ cb(ssl, SSL_CB_CONNECT_EXIT, ret);
588
583
  }
589
584
  return ret;
590
585
  }
@@ -736,17 +731,17 @@ err:
736
731
  return -1;
737
732
  }
738
733
 
739
- int ssl3_get_server_hello(SSL *s) {
734
+ int ssl3_get_server_hello(SSL *ssl) {
740
735
  STACK_OF(SSL_CIPHER) *sk;
741
736
  const SSL_CIPHER *c;
742
- CERT *ct = s->cert;
737
+ CERT *ct = ssl->cert;
743
738
  int al = SSL_AD_INTERNAL_ERROR, ok;
744
739
  long n;
745
740
  CBS server_hello, server_random, session_id;
746
741
  uint16_t server_version, cipher_suite;
747
742
  uint8_t compression_method;
748
743
 
749
- n = s->method->ssl_get_message(s, SSL3_ST_CR_SRVR_HELLO_A,
744
+ n = ssl->method->ssl_get_message(ssl, SSL3_ST_CR_SRVR_HELLO_A,
750
745
  SSL3_ST_CR_SRVR_HELLO_B, SSL3_MT_SERVER_HELLO,
751
746
  20000, /* ?? */
752
747
  ssl_hash_message, &ok);
@@ -766,7 +761,7 @@ int ssl3_get_server_hello(SSL *s) {
766
761
  return n;
767
762
  }
768
763
 
769
- CBS_init(&server_hello, s->init_msg, n);
764
+ CBS_init(&server_hello, ssl->init_msg, n);
770
765
 
771
766
  if (!CBS_get_u16(&server_hello, &server_version) ||
772
767
  !CBS_get_bytes(&server_hello, &server_random, SSL3_RANDOM_SIZE) ||
@@ -779,55 +774,56 @@ int ssl3_get_server_hello(SSL *s) {
779
774
  goto f_err;
780
775
  }
781
776
 
782
- assert(s->s3->have_version == s->s3->initial_handshake_complete);
783
- if (!s->s3->have_version) {
784
- if (!ssl3_is_version_enabled(s, server_version)) {
777
+ assert(ssl->s3->have_version == ssl->s3->initial_handshake_complete);
778
+ if (!ssl->s3->have_version) {
779
+ if (!ssl3_is_version_enabled(ssl, server_version)) {
785
780
  OPENSSL_PUT_ERROR(SSL, SSL_R_UNSUPPORTED_PROTOCOL);
786
- s->version = server_version;
781
+ ssl->version = server_version;
787
782
  /* Mark the version as fixed so the record-layer version is not clamped
788
783
  * to TLS 1.0. */
789
- s->s3->have_version = 1;
784
+ ssl->s3->have_version = 1;
790
785
  al = SSL_AD_PROTOCOL_VERSION;
791
786
  goto f_err;
792
787
  }
793
- s->version = server_version;
794
- s->enc_method = ssl3_get_enc_method(server_version);
795
- assert(s->enc_method != NULL);
796
- /* At this point, the connection's version is known and s->version is
788
+ ssl->version = server_version;
789
+ ssl->s3->enc_method = ssl3_get_enc_method(server_version);
790
+ assert(ssl->s3->enc_method != NULL);
791
+ /* At this point, the connection's version is known and ssl->version is
797
792
  * fixed. Begin enforcing the record-layer version. */
798
- s->s3->have_version = 1;
799
- } else if (server_version != s->version) {
793
+ ssl->s3->have_version = 1;
794
+ } else if (server_version != ssl->version) {
800
795
  OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_SSL_VERSION);
801
796
  al = SSL_AD_PROTOCOL_VERSION;
802
797
  goto f_err;
803
798
  }
804
799
 
805
800
  /* Copy over the server random. */
806
- memcpy(s->s3->server_random, CBS_data(&server_random), SSL3_RANDOM_SIZE);
807
-
808
- assert(s->session == NULL || s->session->session_id_length > 0);
809
- if (!s->s3->initial_handshake_complete && s->session != NULL &&
810
- CBS_mem_equal(&session_id, s->session->session_id,
811
- s->session->session_id_length)) {
812
- if (s->sid_ctx_length != s->session->sid_ctx_length ||
813
- memcmp(s->session->sid_ctx, s->sid_ctx, s->sid_ctx_length)) {
801
+ memcpy(ssl->s3->server_random, CBS_data(&server_random), SSL3_RANDOM_SIZE);
802
+
803
+ assert(ssl->session == NULL || ssl->session->session_id_length > 0);
804
+ if (!ssl->s3->initial_handshake_complete && ssl->session != NULL &&
805
+ CBS_mem_equal(&session_id, ssl->session->session_id,
806
+ ssl->session->session_id_length)) {
807
+ if (ssl->sid_ctx_length != ssl->session->sid_ctx_length ||
808
+ memcmp(ssl->session->sid_ctx, ssl->sid_ctx, ssl->sid_ctx_length)) {
814
809
  /* actually a client application bug */
815
810
  al = SSL_AD_ILLEGAL_PARAMETER;
816
811
  OPENSSL_PUT_ERROR(SSL,
817
812
  SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
818
813
  goto f_err;
819
814
  }
820
- s->hit = 1;
815
+ ssl->hit = 1;
821
816
  } else {
822
817
  /* The session wasn't resumed. Create a fresh SSL_SESSION to
823
818
  * fill out. */
824
- s->hit = 0;
825
- if (!ssl_get_new_session(s, 0 /* client */)) {
819
+ ssl->hit = 0;
820
+ if (!ssl_get_new_session(ssl, 0 /* client */)) {
826
821
  goto f_err;
827
822
  }
828
823
  /* Note: session_id could be empty. */
829
- s->session->session_id_length = CBS_len(&session_id);
830
- memcpy(s->session->session_id, CBS_data(&session_id), CBS_len(&session_id));
824
+ ssl->session->session_id_length = CBS_len(&session_id);
825
+ memcpy(ssl->session->session_id, CBS_data(&session_id),
826
+ CBS_len(&session_id));
831
827
  }
832
828
 
833
829
  c = SSL_get_cipher_by_value(cipher_suite);
@@ -839,15 +835,14 @@ int ssl3_get_server_hello(SSL *s) {
839
835
  }
840
836
  /* If the cipher is disabled then we didn't sent it in the ClientHello, so if
841
837
  * the server selected it, it's an error. */
842
- if ((c->algorithm_mkey & ct->mask_k) ||
843
- (c->algorithm_auth & ct->mask_a) ||
844
- SSL_CIPHER_get_min_version(c) > ssl3_version_from_wire(s, s->version)) {
838
+ if ((c->algorithm_mkey & ct->mask_k) || (c->algorithm_auth & ct->mask_a) ||
839
+ SSL_CIPHER_get_min_version(c) > ssl3_protocol_version(ssl)) {
845
840
  al = SSL_AD_ILLEGAL_PARAMETER;
846
841
  OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CIPHER_RETURNED);
847
842
  goto f_err;
848
843
  }
849
844
 
850
- sk = ssl_get_ciphers_by_id(s);
845
+ sk = ssl_get_ciphers_by_id(ssl);
851
846
  if (!sk_SSL_CIPHER_find(sk, NULL, c)) {
852
847
  /* we did not say we would use this cipher */
853
848
  al = SSL_AD_ILLEGAL_PARAMETER;
@@ -855,30 +850,32 @@ int ssl3_get_server_hello(SSL *s) {
855
850
  goto f_err;
856
851
  }
857
852
 
858
- if (s->hit) {
859
- if (s->session->cipher != c) {
853
+ if (ssl->hit) {
854
+ if (ssl->session->cipher != c) {
860
855
  al = SSL_AD_ILLEGAL_PARAMETER;
861
856
  OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED);
862
857
  goto f_err;
863
858
  }
864
- if (s->session->ssl_version != s->version) {
859
+ if (ssl->session->ssl_version != ssl->version) {
865
860
  al = SSL_AD_ILLEGAL_PARAMETER;
866
861
  OPENSSL_PUT_ERROR(SSL, SSL_R_OLD_SESSION_VERSION_NOT_RETURNED);
867
862
  goto f_err;
868
863
  }
864
+ } else {
865
+ ssl->session->cipher = c;
869
866
  }
870
- s->s3->tmp.new_cipher = c;
867
+ ssl->s3->tmp.new_cipher = c;
871
868
 
872
869
  /* Now that the cipher is known, initialize the handshake hash. */
873
- if (!ssl3_init_handshake_hash(s)) {
870
+ if (!ssl3_init_handshake_hash(ssl)) {
874
871
  goto f_err;
875
872
  }
876
873
 
877
874
  /* If doing a full handshake with TLS 1.2, the server may request a client
878
875
  * certificate which requires hashing the handshake transcript under a
879
876
  * different hash. Otherwise, the handshake buffer may be released. */
880
- if (!SSL_USE_SIGALGS(s) || s->hit) {
881
- ssl3_free_handshake_buffer(s);
877
+ if (ssl->hit || ssl3_protocol_version(ssl) < TLS1_2_VERSION) {
878
+ ssl3_free_handshake_buffer(ssl);
882
879
  }
883
880
 
884
881
  /* Only the NULL compression algorithm is supported. */
@@ -889,7 +886,7 @@ int ssl3_get_server_hello(SSL *s) {
889
886
  }
890
887
 
891
888
  /* TLS extensions */
892
- if (!ssl_parse_serverhello_tlsext(s, &server_hello)) {
889
+ if (!ssl_parse_serverhello_tlsext(ssl, &server_hello)) {
893
890
  OPENSSL_PUT_ERROR(SSL, SSL_R_PARSE_TLSEXT);
894
891
  goto err;
895
892
  }
@@ -902,10 +899,11 @@ int ssl3_get_server_hello(SSL *s) {
902
899
  goto f_err;
903
900
  }
904
901
 
905
- if (s->hit &&
906
- s->s3->tmp.extended_master_secret != s->session->extended_master_secret) {
902
+ if (ssl->hit &&
903
+ ssl->s3->tmp.extended_master_secret !=
904
+ ssl->session->extended_master_secret) {
907
905
  al = SSL_AD_HANDSHAKE_FAILURE;
908
- if (s->session->extended_master_secret) {
906
+ if (ssl->session->extended_master_secret) {
909
907
  OPENSSL_PUT_ERROR(SSL, SSL_R_RESUMED_EMS_SESSION_WITHOUT_EMS_EXTENSION);
910
908
  } else {
911
909
  OPENSSL_PUT_ERROR(SSL, SSL_R_RESUMED_NON_EMS_SESSION_WITH_EMS_EXTENSION);
@@ -916,7 +914,7 @@ int ssl3_get_server_hello(SSL *s) {
916
914
  return 1;
917
915
 
918
916
  f_err:
919
- ssl3_send_alert(s, SSL3_AL_FATAL, al);
917
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
920
918
  err:
921
919
  return -1;
922
920
  }
@@ -964,7 +962,7 @@ err:
964
962
  return ret;
965
963
  }
966
964
 
967
- int ssl3_get_server_certificate(SSL *s) {
965
+ int ssl3_get_server_certificate(SSL *ssl) {
968
966
  int al, ok, ret = -1;
969
967
  unsigned long n;
970
968
  X509 *x = NULL;
@@ -973,15 +971,15 @@ int ssl3_get_server_certificate(SSL *s) {
973
971
  CBS cbs, certificate_list;
974
972
  const uint8_t *data;
975
973
 
976
- n = s->method->ssl_get_message(s, SSL3_ST_CR_CERT_A, SSL3_ST_CR_CERT_B,
977
- SSL3_MT_CERTIFICATE, (long)s->max_cert_list,
974
+ n = ssl->method->ssl_get_message(ssl, SSL3_ST_CR_CERT_A, SSL3_ST_CR_CERT_B,
975
+ SSL3_MT_CERTIFICATE, (long)ssl->max_cert_list,
978
976
  ssl_hash_message, &ok);
979
977
 
980
978
  if (!ok) {
981
979
  return n;
982
980
  }
983
981
 
984
- CBS_init(&cbs, s->init_msg, n);
982
+ CBS_init(&cbs, ssl->init_msg, n);
985
983
 
986
984
  sk = sk_X509_new_null();
987
985
  if (sk == NULL) {
@@ -1025,27 +1023,27 @@ int ssl3_get_server_certificate(SSL *s) {
1025
1023
  }
1026
1024
 
1027
1025
  X509 *leaf = sk_X509_value(sk, 0);
1028
- if (!ssl3_check_leaf_certificate(s, leaf)) {
1026
+ if (!ssl3_check_leaf_certificate(ssl, leaf)) {
1029
1027
  al = SSL_AD_ILLEGAL_PARAMETER;
1030
1028
  goto f_err;
1031
1029
  }
1032
1030
 
1033
1031
  /* NOTE: Unlike the server half, the client's copy of |cert_chain| includes
1034
1032
  * the leaf. */
1035
- sk_X509_pop_free(s->session->cert_chain, X509_free);
1036
- s->session->cert_chain = sk;
1033
+ sk_X509_pop_free(ssl->session->cert_chain, X509_free);
1034
+ ssl->session->cert_chain = sk;
1037
1035
  sk = NULL;
1038
1036
 
1039
- X509_free(s->session->peer);
1040
- s->session->peer = X509_up_ref(leaf);
1037
+ X509_free(ssl->session->peer);
1038
+ ssl->session->peer = X509_up_ref(leaf);
1041
1039
 
1042
- s->session->verify_result = s->verify_result;
1040
+ ssl->session->verify_result = ssl->verify_result;
1043
1041
 
1044
1042
  ret = 1;
1045
1043
 
1046
1044
  if (0) {
1047
1045
  f_err:
1048
- ssl3_send_alert(s, SSL3_AL_FATAL, al);
1046
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
1049
1047
  }
1050
1048
 
1051
1049
  err:
@@ -1055,53 +1053,49 @@ err:
1055
1053
  return ret;
1056
1054
  }
1057
1055
 
1058
- int ssl3_get_server_key_exchange(SSL *s) {
1056
+ int ssl3_get_server_key_exchange(SSL *ssl) {
1059
1057
  EVP_MD_CTX md_ctx;
1060
1058
  int al, ok;
1061
- long n, alg_k, alg_a;
1062
1059
  EVP_PKEY *pkey = NULL;
1063
- const EVP_MD *md = NULL;
1064
- RSA *rsa = NULL;
1065
1060
  DH *dh = NULL;
1066
1061
  EC_KEY *ecdh = NULL;
1067
- BN_CTX *bn_ctx = NULL;
1068
1062
  EC_POINT *srvr_ecpoint = NULL;
1069
- CBS server_key_exchange, server_key_exchange_orig, parameter;
1070
1063
 
1071
1064
  /* use same message size as in ssl3_get_certificate_request() as
1072
1065
  * ServerKeyExchange message may be skipped */
1073
- n = s->method->ssl_get_message(s, SSL3_ST_CR_KEY_EXCH_A,
1074
- SSL3_ST_CR_KEY_EXCH_B, -1, s->max_cert_list,
1075
- ssl_hash_message, &ok);
1066
+ long n = ssl->method->ssl_get_message(
1067
+ ssl, SSL3_ST_CR_KEY_EXCH_A, SSL3_ST_CR_KEY_EXCH_B, -1, ssl->max_cert_list,
1068
+ ssl_hash_message, &ok);
1076
1069
  if (!ok) {
1077
1070
  return n;
1078
1071
  }
1079
1072
 
1080
- if (s->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE) {
1081
- if (ssl_cipher_requires_server_key_exchange(s->s3->tmp.new_cipher)) {
1073
+ if (ssl->s3->tmp.message_type != SSL3_MT_SERVER_KEY_EXCHANGE) {
1074
+ if (ssl_cipher_requires_server_key_exchange(ssl->s3->tmp.new_cipher)) {
1082
1075
  OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
1083
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
1076
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
1084
1077
  return -1;
1085
1078
  }
1086
1079
 
1087
1080
  /* In plain PSK ciphersuite, ServerKeyExchange may be omitted to send no
1088
1081
  * identity hint. */
1089
- if (s->s3->tmp.new_cipher->algorithm_auth & SSL_aPSK) {
1082
+ if (ssl->s3->tmp.new_cipher->algorithm_auth & SSL_aPSK) {
1090
1083
  /* TODO(davidben): This should be reset in one place with the rest of the
1091
1084
  * handshake state. */
1092
- OPENSSL_free(s->s3->tmp.peer_psk_identity_hint);
1093
- s->s3->tmp.peer_psk_identity_hint = NULL;
1085
+ OPENSSL_free(ssl->s3->tmp.peer_psk_identity_hint);
1086
+ ssl->s3->tmp.peer_psk_identity_hint = NULL;
1094
1087
  }
1095
- s->s3->tmp.reuse_message = 1;
1088
+ ssl->s3->tmp.reuse_message = 1;
1096
1089
  return 1;
1097
1090
  }
1098
1091
 
1099
1092
  /* Retain a copy of the original CBS to compute the signature over. */
1100
- CBS_init(&server_key_exchange, s->init_msg, n);
1101
- server_key_exchange_orig = server_key_exchange;
1093
+ CBS server_key_exchange;
1094
+ CBS_init(&server_key_exchange, ssl->init_msg, n);
1095
+ CBS server_key_exchange_orig = server_key_exchange;
1102
1096
 
1103
- alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
1104
- alg_a = s->s3->tmp.new_cipher->algorithm_auth;
1097
+ uint32_t alg_k = ssl->s3->tmp.new_cipher->algorithm_mkey;
1098
+ uint32_t alg_a = ssl->s3->tmp.new_cipher->algorithm_auth;
1105
1099
  EVP_MD_CTX_init(&md_ctx);
1106
1100
 
1107
1101
  if (alg_a & SSL_aPSK) {
@@ -1130,7 +1124,7 @@ int ssl3_get_server_key_exchange(SSL *s) {
1130
1124
  }
1131
1125
 
1132
1126
  /* Save the identity hint as a C string. */
1133
- if (!CBS_strdup(&psk_identity_hint, &s->s3->tmp.peer_psk_identity_hint)) {
1127
+ if (!CBS_strdup(&psk_identity_hint, &ssl->s3->tmp.peer_psk_identity_hint)) {
1134
1128
  al = SSL_AD_INTERNAL_ERROR;
1135
1129
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1136
1130
  goto f_err;
@@ -1139,7 +1133,6 @@ int ssl3_get_server_key_exchange(SSL *s) {
1139
1133
 
1140
1134
  if (alg_k & SSL_kDHE) {
1141
1135
  CBS dh_p, dh_g, dh_Ys;
1142
-
1143
1136
  if (!CBS_get_u16_length_prefixed(&server_key_exchange, &dh_p) ||
1144
1137
  CBS_len(&dh_p) == 0 ||
1145
1138
  !CBS_get_u16_length_prefixed(&server_key_exchange, &dh_g) ||
@@ -1153,91 +1146,69 @@ int ssl3_get_server_key_exchange(SSL *s) {
1153
1146
 
1154
1147
  dh = DH_new();
1155
1148
  if (dh == NULL) {
1156
- OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1157
1149
  goto err;
1158
1150
  }
1159
1151
 
1160
- if ((dh->p = BN_bin2bn(CBS_data(&dh_p), CBS_len(&dh_p), NULL)) == NULL ||
1161
- (dh->g = BN_bin2bn(CBS_data(&dh_g), CBS_len(&dh_g), NULL)) == NULL ||
1162
- (dh->pub_key = BN_bin2bn(CBS_data(&dh_Ys), CBS_len(&dh_Ys), NULL)) ==
1163
- NULL) {
1164
- OPENSSL_PUT_ERROR(SSL, ERR_R_BN_LIB);
1152
+ dh->p = BN_bin2bn(CBS_data(&dh_p), CBS_len(&dh_p), NULL);
1153
+ dh->g = BN_bin2bn(CBS_data(&dh_g), CBS_len(&dh_g), NULL);
1154
+ if (dh->p == NULL || dh->g == NULL) {
1165
1155
  goto err;
1166
1156
  }
1167
1157
 
1168
- s->session->key_exchange_info = DH_num_bits(dh);
1169
- if (s->session->key_exchange_info < 1024) {
1158
+ ssl->session->key_exchange_info = DH_num_bits(dh);
1159
+ if (ssl->session->key_exchange_info < 1024) {
1170
1160
  OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_DH_P_LENGTH);
1171
1161
  goto err;
1172
- }
1173
- if (s->session->key_exchange_info > 4096) {
1162
+ } else if (ssl->session->key_exchange_info > 4096) {
1174
1163
  /* Overly large DHE groups are prohibitively expensive, so enforce a limit
1175
1164
  * to prevent a server from causing us to perform too expensive of a
1176
1165
  * computation. */
1177
1166
  OPENSSL_PUT_ERROR(SSL, SSL_R_DH_P_TOO_LONG);
1178
1167
  goto err;
1179
1168
  }
1180
- DH_free(s->s3->tmp.peer_dh_tmp);
1181
- s->s3->tmp.peer_dh_tmp = dh;
1169
+
1170
+ SSL_ECDH_CTX_init_for_dhe(&ssl->s3->tmp.ecdh_ctx, dh);
1182
1171
  dh = NULL;
1172
+
1173
+ /* Save the peer public key for later. */
1174
+ size_t peer_key_len;
1175
+ if (!CBS_stow(&dh_Ys, &ssl->s3->tmp.peer_key, &peer_key_len)) {
1176
+ goto err;
1177
+ }
1178
+ /* |dh_Ys| has a u16 length prefix, so this fits in a |uint16_t|. */
1179
+ assert(sizeof(ssl->s3->tmp.peer_key_len) == 2 && peer_key_len <= 0xffff);
1180
+ ssl->s3->tmp.peer_key_len = (uint16_t)peer_key_len;
1183
1181
  } else if (alg_k & SSL_kECDHE) {
1182
+ /* Parse the server parameters. */
1183
+ uint8_t curve_type;
1184
1184
  uint16_t curve_id;
1185
- int curve_nid = 0;
1186
- const EC_GROUP *group;
1187
1185
  CBS point;
1188
-
1189
- /* Extract elliptic curve parameters and the server's ephemeral ECDH public
1190
- * key. Check curve is one of our preferences, if not server has sent an
1191
- * invalid curve. */
1192
- if (!tls1_check_curve(s, &server_key_exchange, &curve_id)) {
1186
+ if (!CBS_get_u8(&server_key_exchange, &curve_type) ||
1187
+ curve_type != NAMED_CURVE_TYPE ||
1188
+ !CBS_get_u16(&server_key_exchange, &curve_id) ||
1189
+ !CBS_get_u8_length_prefixed(&server_key_exchange, &point)) {
1193
1190
  al = SSL_AD_DECODE_ERROR;
1194
- OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
1195
- goto f_err;
1196
- }
1197
-
1198
- curve_nid = tls1_ec_curve_id2nid(curve_id);
1199
- if (curve_nid == 0) {
1200
- al = SSL_AD_INTERNAL_ERROR;
1201
- OPENSSL_PUT_ERROR(SSL, SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS);
1191
+ OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1202
1192
  goto f_err;
1203
1193
  }
1194
+ ssl->session->key_exchange_info = curve_id;
1204
1195
 
1205
- ecdh = EC_KEY_new_by_curve_name(curve_nid);
1206
- s->session->key_exchange_info = curve_id;
1207
- if (ecdh == NULL) {
1208
- OPENSSL_PUT_ERROR(SSL, ERR_R_EC_LIB);
1209
- goto err;
1210
- }
1211
-
1212
- group = EC_KEY_get0_group(ecdh);
1213
-
1214
- /* Next, get the encoded ECPoint */
1215
- if (!CBS_get_u8_length_prefixed(&server_key_exchange, &point)) {
1216
- al = SSL_AD_DECODE_ERROR;
1217
- OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1196
+ /* Ensure the curve is consistent with preferences. */
1197
+ if (!tls1_check_curve_id(ssl, curve_id)) {
1198
+ al = SSL_AD_ILLEGAL_PARAMETER;
1199
+ OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
1218
1200
  goto f_err;
1219
1201
  }
1220
1202
 
1221
- if (((srvr_ecpoint = EC_POINT_new(group)) == NULL) ||
1222
- ((bn_ctx = BN_CTX_new()) == NULL)) {
1223
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1203
+ /* Initialize ECDH and save the peer public key for later. */
1204
+ size_t peer_key_len;
1205
+ if (!SSL_ECDH_CTX_init(&ssl->s3->tmp.ecdh_ctx, curve_id) ||
1206
+ !CBS_stow(&point, &ssl->s3->tmp.peer_key, &peer_key_len)) {
1224
1207
  goto err;
1225
1208
  }
1226
-
1227
- if (!EC_POINT_oct2point(group, srvr_ecpoint, CBS_data(&point),
1228
- CBS_len(&point), bn_ctx)) {
1229
- al = SSL_AD_DECODE_ERROR;
1230
- OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_ECPOINT);
1231
- goto f_err;
1232
- }
1233
- EC_KEY_set_public_key(ecdh, srvr_ecpoint);
1234
- EC_KEY_free(s->s3->tmp.peer_ecdh_tmp);
1235
- s->s3->tmp.peer_ecdh_tmp = ecdh;
1236
- ecdh = NULL;
1237
- BN_CTX_free(bn_ctx);
1238
- bn_ctx = NULL;
1239
- EC_POINT_free(srvr_ecpoint);
1240
- srvr_ecpoint = NULL;
1209
+ /* |point| has a u8 length prefix, so this fits in a |uint16_t|. */
1210
+ assert(sizeof(ssl->s3->tmp.peer_key_len) == 2 && peer_key_len <= 0xffff);
1211
+ ssl->s3->tmp.peer_key_len = (uint16_t)peer_key_len;
1241
1212
  } else if (!(alg_k & SSL_kPSK)) {
1242
1213
  al = SSL_AD_UNEXPECTED_MESSAGE;
1243
1214
  OPENSSL_PUT_ERROR(SSL, SSL_R_UNEXPECTED_MESSAGE);
@@ -1247,17 +1218,19 @@ int ssl3_get_server_key_exchange(SSL *s) {
1247
1218
  /* At this point, |server_key_exchange| contains the signature, if any, while
1248
1219
  * |server_key_exchange_orig| contains the entire message. From that, derive
1249
1220
  * a CBS containing just the parameter. */
1221
+ CBS parameter;
1250
1222
  CBS_init(&parameter, CBS_data(&server_key_exchange_orig),
1251
1223
  CBS_len(&server_key_exchange_orig) - CBS_len(&server_key_exchange));
1252
1224
 
1253
1225
  /* ServerKeyExchange should be signed by the server's public key. */
1254
- if (ssl_cipher_has_server_public_key(s->s3->tmp.new_cipher)) {
1255
- pkey = X509_get_pubkey(s->session->peer);
1226
+ if (ssl_cipher_has_server_public_key(ssl->s3->tmp.new_cipher)) {
1227
+ pkey = X509_get_pubkey(ssl->session->peer);
1256
1228
  if (pkey == NULL) {
1257
1229
  goto err;
1258
1230
  }
1259
1231
 
1260
- if (SSL_USE_SIGALGS(s)) {
1232
+ const EVP_MD *md = NULL;
1233
+ if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
1261
1234
  uint8_t hash, signature;
1262
1235
  if (!CBS_get_u8(&server_key_exchange, &hash) ||
1263
1236
  !CBS_get_u8(&server_key_exchange, &signature)) {
@@ -1265,10 +1238,10 @@ int ssl3_get_server_key_exchange(SSL *s) {
1265
1238
  OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1266
1239
  goto f_err;
1267
1240
  }
1268
- if (!tls12_check_peer_sigalg(s, &md, &al, hash, signature, pkey)) {
1241
+ if (!tls12_check_peer_sigalg(ssl, &md, &al, hash, signature, pkey)) {
1269
1242
  goto f_err;
1270
1243
  }
1271
- s->s3->tmp.server_key_exchange_hash = hash;
1244
+ ssl->s3->tmp.server_key_exchange_hash = hash;
1272
1245
  } else if (pkey->type == EVP_PKEY_RSA) {
1273
1246
  md = EVP_md5_sha1();
1274
1247
  } else {
@@ -1285,9 +1258,9 @@ int ssl3_get_server_key_exchange(SSL *s) {
1285
1258
  }
1286
1259
 
1287
1260
  if (!EVP_DigestVerifyInit(&md_ctx, NULL, md, NULL, pkey) ||
1288
- !EVP_DigestVerifyUpdate(&md_ctx, s->s3->client_random,
1261
+ !EVP_DigestVerifyUpdate(&md_ctx, ssl->s3->client_random,
1289
1262
  SSL3_RANDOM_SIZE) ||
1290
- !EVP_DigestVerifyUpdate(&md_ctx, s->s3->server_random,
1263
+ !EVP_DigestVerifyUpdate(&md_ctx, ssl->s3->server_random,
1291
1264
  SSL3_RANDOM_SIZE) ||
1292
1265
  !EVP_DigestVerifyUpdate(&md_ctx, CBS_data(&parameter),
1293
1266
  CBS_len(&parameter)) ||
@@ -1313,12 +1286,10 @@ int ssl3_get_server_key_exchange(SSL *s) {
1313
1286
  return 1;
1314
1287
 
1315
1288
  f_err:
1316
- ssl3_send_alert(s, SSL3_AL_FATAL, al);
1289
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
1317
1290
  err:
1318
1291
  EVP_PKEY_free(pkey);
1319
- RSA_free(rsa);
1320
1292
  DH_free(dh);
1321
- BN_CTX_free(bn_ctx);
1322
1293
  EC_POINT_free(srvr_ecpoint);
1323
1294
  EC_KEY_free(ecdh);
1324
1295
  EVP_MD_CTX_cleanup(&md_ctx);
@@ -1329,7 +1300,7 @@ static int ca_dn_cmp(const X509_NAME **a, const X509_NAME **b) {
1329
1300
  return X509_NAME_cmp(*a, *b);
1330
1301
  }
1331
1302
 
1332
- int ssl3_get_certificate_request(SSL *s) {
1303
+ int ssl3_get_certificate_request(SSL *ssl) {
1333
1304
  int ok, ret = 0;
1334
1305
  unsigned long n;
1335
1306
  X509_NAME *xn = NULL;
@@ -1339,31 +1310,31 @@ int ssl3_get_certificate_request(SSL *s) {
1339
1310
  CBS certificate_authorities;
1340
1311
  const uint8_t *data;
1341
1312
 
1342
- n = s->method->ssl_get_message(s, SSL3_ST_CR_CERT_REQ_A,
1343
- SSL3_ST_CR_CERT_REQ_B, -1, s->max_cert_list,
1313
+ n = ssl->method->ssl_get_message(ssl, SSL3_ST_CR_CERT_REQ_A,
1314
+ SSL3_ST_CR_CERT_REQ_B, -1, ssl->max_cert_list,
1344
1315
  ssl_hash_message, &ok);
1345
1316
 
1346
1317
  if (!ok) {
1347
1318
  return n;
1348
1319
  }
1349
1320
 
1350
- s->s3->tmp.cert_req = 0;
1321
+ ssl->s3->tmp.cert_req = 0;
1351
1322
 
1352
- if (s->s3->tmp.message_type == SSL3_MT_SERVER_DONE) {
1353
- s->s3->tmp.reuse_message = 1;
1323
+ if (ssl->s3->tmp.message_type == SSL3_MT_SERVER_DONE) {
1324
+ ssl->s3->tmp.reuse_message = 1;
1354
1325
  /* If we get here we don't need the handshake buffer as we won't be doing
1355
1326
  * client auth. */
1356
- ssl3_free_handshake_buffer(s);
1327
+ ssl3_free_handshake_buffer(ssl);
1357
1328
  return 1;
1358
1329
  }
1359
1330
 
1360
- if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST) {
1361
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
1331
+ if (ssl->s3->tmp.message_type != SSL3_MT_CERTIFICATE_REQUEST) {
1332
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
1362
1333
  OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_MESSAGE_TYPE);
1363
1334
  goto err;
1364
1335
  }
1365
1336
 
1366
- CBS_init(&cbs, s->init_msg, n);
1337
+ CBS_init(&cbs, ssl->init_msg, n);
1367
1338
 
1368
1339
  ca_sk = sk_X509_NAME_new(ca_dn_cmp);
1369
1340
  if (ca_sk == NULL) {
@@ -1373,22 +1344,22 @@ int ssl3_get_certificate_request(SSL *s) {
1373
1344
 
1374
1345
  /* get the certificate types */
1375
1346
  if (!CBS_get_u8_length_prefixed(&cbs, &certificate_types)) {
1376
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1347
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1377
1348
  OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1378
1349
  goto err;
1379
1350
  }
1380
1351
 
1381
- if (!CBS_stow(&certificate_types, &s->s3->tmp.certificate_types,
1382
- &s->s3->tmp.num_certificate_types)) {
1383
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
1352
+ if (!CBS_stow(&certificate_types, &ssl->s3->tmp.certificate_types,
1353
+ &ssl->s3->tmp.num_certificate_types)) {
1354
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
1384
1355
  goto err;
1385
1356
  }
1386
1357
 
1387
- if (SSL_USE_SIGALGS(s)) {
1358
+ if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
1388
1359
  CBS supported_signature_algorithms;
1389
1360
  if (!CBS_get_u16_length_prefixed(&cbs, &supported_signature_algorithms) ||
1390
- !tls1_parse_peer_sigalgs(s, &supported_signature_algorithms)) {
1391
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1361
+ !tls1_parse_peer_sigalgs(ssl, &supported_signature_algorithms)) {
1362
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1392
1363
  OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
1393
1364
  goto err;
1394
1365
  }
@@ -1396,7 +1367,7 @@ int ssl3_get_certificate_request(SSL *s) {
1396
1367
 
1397
1368
  /* get the CA RDNs */
1398
1369
  if (!CBS_get_u16_length_prefixed(&cbs, &certificate_authorities)) {
1399
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1370
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1400
1371
  OPENSSL_PUT_ERROR(SSL, SSL_R_LENGTH_MISMATCH);
1401
1372
  goto err;
1402
1373
  }
@@ -1405,7 +1376,7 @@ int ssl3_get_certificate_request(SSL *s) {
1405
1376
  CBS distinguished_name;
1406
1377
  if (!CBS_get_u16_length_prefixed(&certificate_authorities,
1407
1378
  &distinguished_name)) {
1408
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1379
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1409
1380
  OPENSSL_PUT_ERROR(SSL, SSL_R_CA_DN_TOO_LONG);
1410
1381
  goto err;
1411
1382
  }
@@ -1415,19 +1386,19 @@ int ssl3_get_certificate_request(SSL *s) {
1415
1386
  /* A u16 length cannot overflow a long. */
1416
1387
  xn = d2i_X509_NAME(NULL, &data, (long)CBS_len(&distinguished_name));
1417
1388
  if (xn == NULL) {
1418
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1389
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1419
1390
  OPENSSL_PUT_ERROR(SSL, ERR_R_ASN1_LIB);
1420
1391
  goto err;
1421
1392
  }
1422
1393
 
1423
1394
  if (!CBS_skip(&distinguished_name, data - CBS_data(&distinguished_name))) {
1424
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1395
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1425
1396
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1426
1397
  goto err;
1427
1398
  }
1428
1399
 
1429
1400
  if (CBS_len(&distinguished_name) != 0) {
1430
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1401
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1431
1402
  OPENSSL_PUT_ERROR(SSL, SSL_R_CA_DN_LENGTH_MISMATCH);
1432
1403
  goto err;
1433
1404
  }
@@ -1439,9 +1410,9 @@ int ssl3_get_certificate_request(SSL *s) {
1439
1410
  }
1440
1411
 
1441
1412
  /* we should setup a certificate to return.... */
1442
- s->s3->tmp.cert_req = 1;
1443
- sk_X509_NAME_pop_free(s->s3->tmp.ca_names, X509_NAME_free);
1444
- s->s3->tmp.ca_names = ca_sk;
1413
+ ssl->s3->tmp.cert_req = 1;
1414
+ sk_X509_NAME_pop_free(ssl->s3->tmp.ca_names, X509_NAME_free);
1415
+ ssl->s3->tmp.ca_names = ca_sk;
1445
1416
  ca_sk = NULL;
1446
1417
 
1447
1418
  ret = 1;
@@ -1451,10 +1422,10 @@ err:
1451
1422
  return ret;
1452
1423
  }
1453
1424
 
1454
- int ssl3_get_new_session_ticket(SSL *s) {
1425
+ int ssl3_get_new_session_ticket(SSL *ssl) {
1455
1426
  int ok, al;
1456
- long n = s->method->ssl_get_message(
1457
- s, SSL3_ST_CR_SESSION_TICKET_A, SSL3_ST_CR_SESSION_TICKET_B,
1427
+ long n = ssl->method->ssl_get_message(
1428
+ ssl, SSL3_ST_CR_SESSION_TICKET_A, SSL3_ST_CR_SESSION_TICKET_B,
1458
1429
  SSL3_MT_NEWSESSION_TICKET, 16384, ssl_hash_message, &ok);
1459
1430
 
1460
1431
  if (!ok) {
@@ -1463,7 +1434,7 @@ int ssl3_get_new_session_ticket(SSL *s) {
1463
1434
 
1464
1435
  CBS new_session_ticket, ticket;
1465
1436
  uint32_t ticket_lifetime_hint;
1466
- CBS_init(&new_session_ticket, s->init_msg, n);
1437
+ CBS_init(&new_session_ticket, ssl->init_msg, n);
1467
1438
  if (!CBS_get_u32(&new_session_ticket, &ticket_lifetime_hint) ||
1468
1439
  !CBS_get_u16_length_prefixed(&new_session_ticket, &ticket) ||
1469
1440
  CBS_len(&new_session_ticket) != 0) {
@@ -1477,17 +1448,17 @@ int ssl3_get_new_session_ticket(SSL *s) {
1477
1448
  * negotiating the extension. The value of |tlsext_ticket_expected| is
1478
1449
  * checked in |ssl_update_cache| so is cleared here to avoid an unnecessary
1479
1450
  * update. */
1480
- s->tlsext_ticket_expected = 0;
1451
+ ssl->tlsext_ticket_expected = 0;
1481
1452
  return 1;
1482
1453
  }
1483
1454
 
1484
- if (s->hit) {
1455
+ if (ssl->hit) {
1485
1456
  /* The server is sending a new ticket for an existing session. Sessions are
1486
1457
  * immutable once established, so duplicate all but the ticket of the
1487
1458
  * existing session. */
1488
1459
  uint8_t *bytes;
1489
1460
  size_t bytes_len;
1490
- if (!SSL_SESSION_to_bytes_for_ticket(s->session, &bytes, &bytes_len)) {
1461
+ if (!SSL_SESSION_to_bytes_for_ticket(ssl->session, &bytes, &bytes_len)) {
1491
1462
  goto err;
1492
1463
  }
1493
1464
  SSL_SESSION *new_session = SSL_SESSION_from_bytes(bytes, bytes_len);
@@ -1498,55 +1469,55 @@ int ssl3_get_new_session_ticket(SSL *s) {
1498
1469
  goto err;
1499
1470
  }
1500
1471
 
1501
- SSL_SESSION_free(s->session);
1502
- s->session = new_session;
1472
+ SSL_SESSION_free(ssl->session);
1473
+ ssl->session = new_session;
1503
1474
  }
1504
1475
 
1505
- if (!CBS_stow(&ticket, &s->session->tlsext_tick,
1506
- &s->session->tlsext_ticklen)) {
1476
+ if (!CBS_stow(&ticket, &ssl->session->tlsext_tick,
1477
+ &ssl->session->tlsext_ticklen)) {
1507
1478
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1508
1479
  goto err;
1509
1480
  }
1510
- s->session->tlsext_tick_lifetime_hint = ticket_lifetime_hint;
1481
+ ssl->session->tlsext_tick_lifetime_hint = ticket_lifetime_hint;
1511
1482
 
1512
1483
  /* Generate a session ID for this session based on the session ticket. We use
1513
1484
  * the session ID mechanism for detecting ticket resumption. This also fits in
1514
1485
  * with assumptions elsewhere in OpenSSL.*/
1515
- if (!EVP_Digest(CBS_data(&ticket), CBS_len(&ticket), s->session->session_id,
1516
- &s->session->session_id_length, EVP_sha256(), NULL)) {
1486
+ if (!EVP_Digest(CBS_data(&ticket), CBS_len(&ticket), ssl->session->session_id,
1487
+ &ssl->session->session_id_length, EVP_sha256(), NULL)) {
1517
1488
  goto err;
1518
1489
  }
1519
1490
 
1520
1491
  return 1;
1521
1492
 
1522
1493
  f_err:
1523
- ssl3_send_alert(s, SSL3_AL_FATAL, al);
1494
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
1524
1495
  err:
1525
1496
  return -1;
1526
1497
  }
1527
1498
 
1528
- int ssl3_get_cert_status(SSL *s) {
1499
+ int ssl3_get_cert_status(SSL *ssl) {
1529
1500
  int ok, al;
1530
1501
  long n;
1531
1502
  CBS certificate_status, ocsp_response;
1532
1503
  uint8_t status_type;
1533
1504
 
1534
- n = s->method->ssl_get_message(
1535
- s, SSL3_ST_CR_CERT_STATUS_A, SSL3_ST_CR_CERT_STATUS_B,
1505
+ n = ssl->method->ssl_get_message(
1506
+ ssl, SSL3_ST_CR_CERT_STATUS_A, SSL3_ST_CR_CERT_STATUS_B,
1536
1507
  -1, 16384, ssl_hash_message, &ok);
1537
1508
 
1538
1509
  if (!ok) {
1539
1510
  return n;
1540
1511
  }
1541
1512
 
1542
- if (s->s3->tmp.message_type != SSL3_MT_CERTIFICATE_STATUS) {
1513
+ if (ssl->s3->tmp.message_type != SSL3_MT_CERTIFICATE_STATUS) {
1543
1514
  /* A server may send status_request in ServerHello and then change
1544
1515
  * its mind about sending CertificateStatus. */
1545
- s->s3->tmp.reuse_message = 1;
1516
+ ssl->s3->tmp.reuse_message = 1;
1546
1517
  return 1;
1547
1518
  }
1548
1519
 
1549
- CBS_init(&certificate_status, s->init_msg, n);
1520
+ CBS_init(&certificate_status, ssl->init_msg, n);
1550
1521
  if (!CBS_get_u8(&certificate_status, &status_type) ||
1551
1522
  status_type != TLSEXT_STATUSTYPE_ocsp ||
1552
1523
  !CBS_get_u24_length_prefixed(&certificate_status, &ocsp_response) ||
@@ -1557,8 +1528,8 @@ int ssl3_get_cert_status(SSL *s) {
1557
1528
  goto f_err;
1558
1529
  }
1559
1530
 
1560
- if (!CBS_stow(&ocsp_response, &s->session->ocsp_response,
1561
- &s->session->ocsp_response_length)) {
1531
+ if (!CBS_stow(&ocsp_response, &ssl->session->ocsp_response,
1532
+ &ssl->session->ocsp_response_length)) {
1562
1533
  al = SSL_AD_INTERNAL_ERROR;
1563
1534
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1564
1535
  goto f_err;
@@ -1566,15 +1537,15 @@ int ssl3_get_cert_status(SSL *s) {
1566
1537
  return 1;
1567
1538
 
1568
1539
  f_err:
1569
- ssl3_send_alert(s, SSL3_AL_FATAL, al);
1540
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
1570
1541
  return -1;
1571
1542
  }
1572
1543
 
1573
- int ssl3_get_server_done(SSL *s) {
1544
+ int ssl3_get_server_done(SSL *ssl) {
1574
1545
  int ok;
1575
1546
  long n;
1576
1547
 
1577
- n = s->method->ssl_get_message(s, SSL3_ST_CR_SRVR_DONE_A,
1548
+ n = ssl->method->ssl_get_message(ssl, SSL3_ST_CR_SRVR_DONE_A,
1578
1549
  SSL3_ST_CR_SRVR_DONE_B, SSL3_MT_SERVER_DONE,
1579
1550
  30, /* should be very small, like 0 :-) */
1580
1551
  ssl_hash_message, &ok);
@@ -1585,7 +1556,7 @@ int ssl3_get_server_done(SSL *s) {
1585
1556
 
1586
1557
  if (n > 0) {
1587
1558
  /* should contain no data */
1588
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1559
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1589
1560
  OPENSSL_PUT_ERROR(SSL, SSL_R_LENGTH_MISMATCH);
1590
1561
  return -1;
1591
1562
  }
@@ -1596,415 +1567,299 @@ int ssl3_get_server_done(SSL *s) {
1596
1567
  OPENSSL_COMPILE_ASSERT(sizeof(size_t) >= sizeof(unsigned),
1597
1568
  SIZE_T_IS_SMALLER_THAN_UNSIGNED);
1598
1569
 
1599
- int ssl3_send_client_key_exchange(SSL *s) {
1600
- uint8_t *p;
1601
- int n = 0;
1602
- uint32_t alg_k;
1603
- uint32_t alg_a;
1604
- uint8_t *q;
1605
- EVP_PKEY *pkey = NULL;
1606
- EC_KEY *clnt_ecdh = NULL;
1607
- const EC_POINT *srvr_ecpoint = NULL;
1608
- EVP_PKEY *srvr_pub_pkey = NULL;
1609
- uint8_t *encodedPoint = NULL;
1610
- int encoded_pt_len = 0;
1611
- BN_CTX *bn_ctx = NULL;
1612
- unsigned int psk_len = 0;
1613
- uint8_t psk[PSK_MAX_PSK_LEN];
1570
+ int ssl3_send_client_key_exchange(SSL *ssl) {
1571
+ if (ssl->state == SSL3_ST_CW_KEY_EXCH_B) {
1572
+ return ssl_do_write(ssl);
1573
+ }
1574
+ assert(ssl->state == SSL3_ST_CW_KEY_EXCH_A);
1575
+
1614
1576
  uint8_t *pms = NULL;
1615
1577
  size_t pms_len = 0;
1578
+ CBB cbb;
1579
+ if (!CBB_init_fixed(&cbb, ssl_handshake_start(ssl),
1580
+ ssl->init_buf->max - SSL_HM_HEADER_LENGTH(ssl))) {
1581
+ goto err;
1582
+ }
1616
1583
 
1617
- if (s->state == SSL3_ST_CW_KEY_EXCH_A) {
1618
- p = ssl_handshake_start(s);
1619
-
1620
- alg_k = s->s3->tmp.new_cipher->algorithm_mkey;
1621
- alg_a = s->s3->tmp.new_cipher->algorithm_auth;
1622
-
1623
- /* If using a PSK key exchange, prepare the pre-shared key. */
1624
- if (alg_a & SSL_aPSK) {
1625
- char identity[PSK_MAX_IDENTITY_LEN + 1];
1626
- size_t identity_len;
1627
-
1628
- if (s->psk_client_callback == NULL) {
1629
- OPENSSL_PUT_ERROR(SSL, SSL_R_PSK_NO_CLIENT_CB);
1630
- goto err;
1631
- }
1632
-
1633
- memset(identity, 0, sizeof(identity));
1634
- psk_len =
1635
- s->psk_client_callback(s, s->s3->tmp.peer_psk_identity_hint, identity,
1636
- sizeof(identity), psk, sizeof(psk));
1637
- if (psk_len > PSK_MAX_PSK_LEN) {
1638
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1639
- goto err;
1640
- } else if (psk_len == 0) {
1641
- OPENSSL_PUT_ERROR(SSL, SSL_R_PSK_IDENTITY_NOT_FOUND);
1642
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1643
- goto err;
1644
- }
1645
-
1646
- identity_len = OPENSSL_strnlen(identity, sizeof(identity));
1647
- if (identity_len > PSK_MAX_IDENTITY_LEN) {
1648
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1649
- goto err;
1650
- }
1584
+ uint32_t alg_k = ssl->s3->tmp.new_cipher->algorithm_mkey;
1585
+ uint32_t alg_a = ssl->s3->tmp.new_cipher->algorithm_auth;
1651
1586
 
1652
- OPENSSL_free(s->session->psk_identity);
1653
- s->session->psk_identity = BUF_strdup(identity);
1654
- if (s->session->psk_identity == NULL) {
1655
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1656
- goto err;
1657
- }
1587
+ /* If using a PSK key exchange, prepare the pre-shared key. */
1588
+ unsigned psk_len = 0;
1589
+ uint8_t psk[PSK_MAX_PSK_LEN];
1590
+ if (alg_a & SSL_aPSK) {
1591
+ if (ssl->psk_client_callback == NULL) {
1592
+ OPENSSL_PUT_ERROR(SSL, SSL_R_PSK_NO_CLIENT_CB);
1593
+ goto err;
1594
+ }
1658
1595
 
1659
- /* Write out psk_identity. */
1660
- s2n(identity_len, p);
1661
- memcpy(p, identity, identity_len);
1662
- p += identity_len;
1663
- n = 2 + identity_len;
1596
+ char identity[PSK_MAX_IDENTITY_LEN + 1];
1597
+ memset(identity, 0, sizeof(identity));
1598
+ psk_len = ssl->psk_client_callback(
1599
+ ssl, ssl->s3->tmp.peer_psk_identity_hint, identity, sizeof(identity),
1600
+ psk, sizeof(psk));
1601
+ if (psk_len == 0) {
1602
+ OPENSSL_PUT_ERROR(SSL, SSL_R_PSK_IDENTITY_NOT_FOUND);
1603
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1604
+ goto err;
1664
1605
  }
1606
+ assert(psk_len <= PSK_MAX_PSK_LEN);
1665
1607
 
1666
- /* Depending on the key exchange method, compute |pms| and |pms_len|. */
1667
- if (alg_k & SSL_kRSA) {
1668
- size_t enc_pms_len;
1608
+ OPENSSL_free(ssl->session->psk_identity);
1609
+ ssl->session->psk_identity = BUF_strdup(identity);
1610
+ if (ssl->session->psk_identity == NULL) {
1611
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1612
+ goto err;
1613
+ }
1669
1614
 
1670
- pms_len = SSL_MAX_MASTER_KEY_LENGTH;
1671
- pms = OPENSSL_malloc(pms_len);
1672
- if (pms == NULL) {
1673
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1674
- goto err;
1675
- }
1615
+ /* Write out psk_identity. */
1616
+ CBB child;
1617
+ if (!CBB_add_u16_length_prefixed(&cbb, &child) ||
1618
+ !CBB_add_bytes(&child, (const uint8_t *)identity,
1619
+ OPENSSL_strnlen(identity, sizeof(identity))) ||
1620
+ !CBB_flush(&cbb)) {
1621
+ goto err;
1622
+ }
1623
+ }
1676
1624
 
1677
- pkey = X509_get_pubkey(s->session->peer);
1678
- if (pkey == NULL) {
1679
- goto err;
1680
- }
1625
+ /* Depending on the key exchange method, compute |pms| and |pms_len|. */
1626
+ if (alg_k & SSL_kRSA) {
1627
+ pms_len = SSL_MAX_MASTER_KEY_LENGTH;
1628
+ pms = OPENSSL_malloc(pms_len);
1629
+ if (pms == NULL) {
1630
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1631
+ goto err;
1632
+ }
1681
1633
 
1682
- RSA *rsa = EVP_PKEY_get0_RSA(pkey);
1683
- if (rsa == NULL) {
1684
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1685
- EVP_PKEY_free(pkey);
1686
- goto err;
1687
- }
1634
+ EVP_PKEY *pkey = X509_get_pubkey(ssl->session->peer);
1635
+ if (pkey == NULL) {
1636
+ goto err;
1637
+ }
1688
1638
 
1689
- s->session->key_exchange_info = EVP_PKEY_bits(pkey);
1639
+ RSA *rsa = EVP_PKEY_get0_RSA(pkey);
1640
+ if (rsa == NULL) {
1641
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1690
1642
  EVP_PKEY_free(pkey);
1643
+ goto err;
1644
+ }
1691
1645
 
1692
- pms[0] = s->client_version >> 8;
1693
- pms[1] = s->client_version & 0xff;
1694
- if (!RAND_bytes(&pms[2], SSL_MAX_MASTER_KEY_LENGTH - 2)) {
1695
- goto err;
1696
- }
1697
-
1698
- s->session->master_key_length = SSL_MAX_MASTER_KEY_LENGTH;
1699
-
1700
- q = p;
1701
- /* In TLS and beyond, reserve space for the length prefix. */
1702
- if (s->version > SSL3_VERSION) {
1703
- p += 2;
1704
- n += 2;
1705
- }
1706
- if (!RSA_encrypt(rsa, &enc_pms_len, p, RSA_size(rsa), pms, pms_len,
1707
- RSA_PKCS1_PADDING)) {
1708
- OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_RSA_ENCRYPT);
1709
- goto err;
1710
- }
1711
- n += enc_pms_len;
1712
-
1713
- /* Log the premaster secret, if logging is enabled. */
1714
- if (!ssl_log_rsa_client_key_exchange(s, p, enc_pms_len, pms, pms_len)) {
1715
- goto err;
1716
- }
1717
-
1718
- /* Fill in the length prefix. */
1719
- if (s->version > SSL3_VERSION) {
1720
- s2n(enc_pms_len, q);
1721
- }
1722
- } else if (alg_k & SSL_kDHE) {
1723
- DH *dh_srvr, *dh_clnt;
1724
- int dh_len;
1725
- size_t pub_len;
1726
-
1727
- if (s->s3->tmp.peer_dh_tmp == NULL) {
1728
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1729
- goto err;
1730
- }
1731
- dh_srvr = s->s3->tmp.peer_dh_tmp;
1732
-
1733
- /* generate a new random key */
1734
- dh_clnt = DHparams_dup(dh_srvr);
1735
- if (dh_clnt == NULL) {
1736
- OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1737
- goto err;
1738
- }
1739
- if (!DH_generate_key(dh_clnt)) {
1740
- OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1741
- DH_free(dh_clnt);
1742
- goto err;
1743
- }
1744
-
1745
- pms_len = DH_size(dh_clnt);
1746
- pms = OPENSSL_malloc(pms_len);
1747
- if (pms == NULL) {
1748
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1749
- DH_free(dh_clnt);
1750
- goto err;
1751
- }
1752
-
1753
- dh_len = DH_compute_key(pms, dh_srvr->pub_key, dh_clnt);
1754
- if (dh_len <= 0) {
1755
- OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1756
- DH_free(dh_clnt);
1757
- goto err;
1758
- }
1759
- pms_len = dh_len;
1760
-
1761
- /* send off the data */
1762
- pub_len = BN_num_bytes(dh_clnt->pub_key);
1763
- s2n(pub_len, p);
1764
- BN_bn2bin(dh_clnt->pub_key, p);
1765
- n += 2 + pub_len;
1766
-
1767
- DH_free(dh_clnt);
1768
- } else if (alg_k & SSL_kECDHE) {
1769
- const EC_GROUP *srvr_group = NULL;
1770
- EC_KEY *tkey;
1771
- int ecdh_len;
1772
-
1773
- if (s->s3->tmp.peer_ecdh_tmp == NULL) {
1774
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1775
- goto err;
1776
- }
1777
-
1778
- tkey = s->s3->tmp.peer_ecdh_tmp;
1779
-
1780
- srvr_group = EC_KEY_get0_group(tkey);
1781
- srvr_ecpoint = EC_KEY_get0_public_key(tkey);
1782
- if (srvr_group == NULL || srvr_ecpoint == NULL) {
1783
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1784
- goto err;
1785
- }
1786
-
1787
- clnt_ecdh = EC_KEY_new();
1788
- if (clnt_ecdh == NULL) {
1789
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1790
- goto err;
1791
- }
1792
-
1793
- if (!EC_KEY_set_group(clnt_ecdh, srvr_group)) {
1794
- OPENSSL_PUT_ERROR(SSL, ERR_R_EC_LIB);
1795
- goto err;
1796
- }
1797
-
1798
- /* Generate a new ECDH key pair */
1799
- if (!EC_KEY_generate_key(clnt_ecdh)) {
1800
- OPENSSL_PUT_ERROR(SSL, ERR_R_ECDH_LIB);
1801
- goto err;
1802
- }
1803
-
1804
- unsigned field_size = EC_GROUP_get_degree(srvr_group);
1805
- if (field_size == 0) {
1806
- OPENSSL_PUT_ERROR(SSL, ERR_R_ECDH_LIB);
1807
- goto err;
1808
- }
1646
+ ssl->session->key_exchange_info = EVP_PKEY_bits(pkey);
1647
+ EVP_PKEY_free(pkey);
1809
1648
 
1810
- pms_len = (field_size + 7) / 8;
1811
- pms = OPENSSL_malloc(pms_len);
1812
- if (pms == NULL) {
1813
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1814
- goto err;
1815
- }
1649
+ pms[0] = ssl->client_version >> 8;
1650
+ pms[1] = ssl->client_version & 0xff;
1651
+ if (!RAND_bytes(&pms[2], SSL_MAX_MASTER_KEY_LENGTH - 2)) {
1652
+ goto err;
1653
+ }
1816
1654
 
1817
- ecdh_len = ECDH_compute_key(pms, pms_len, srvr_ecpoint, clnt_ecdh, NULL);
1818
- if (ecdh_len <= 0) {
1819
- OPENSSL_PUT_ERROR(SSL, ERR_R_ECDH_LIB);
1820
- goto err;
1821
- }
1822
- pms_len = ecdh_len;
1823
-
1824
- /* First check the size of encoding and allocate memory accordingly. */
1825
- encoded_pt_len =
1826
- EC_POINT_point2oct(srvr_group, EC_KEY_get0_public_key(clnt_ecdh),
1827
- POINT_CONVERSION_UNCOMPRESSED, NULL, 0, NULL);
1828
-
1829
- encodedPoint =
1830
- (uint8_t *)OPENSSL_malloc(encoded_pt_len * sizeof(uint8_t));
1831
- bn_ctx = BN_CTX_new();
1832
- if (encodedPoint == NULL || bn_ctx == NULL) {
1833
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1655
+ CBB child, *enc_pms = &cbb;
1656
+ size_t enc_pms_len;
1657
+ /* In TLS, there is a length prefix. */
1658
+ if (ssl->version > SSL3_VERSION) {
1659
+ if (!CBB_add_u16_length_prefixed(&cbb, &child)) {
1834
1660
  goto err;
1835
1661
  }
1662
+ enc_pms = &child;
1663
+ }
1836
1664
 
1837
- /* Encode the public key */
1838
- encoded_pt_len = EC_POINT_point2oct(
1839
- srvr_group, EC_KEY_get0_public_key(clnt_ecdh),
1840
- POINT_CONVERSION_UNCOMPRESSED, encodedPoint, encoded_pt_len, bn_ctx);
1841
-
1842
- *p = encoded_pt_len; /* length of encoded point */
1843
- /* Encoded point will be copied here */
1844
- p += 1;
1845
- n += 1;
1846
- /* copy the point */
1847
- memcpy(p, encodedPoint, encoded_pt_len);
1848
- /* increment n to account for length field */
1849
- n += encoded_pt_len;
1850
-
1851
- /* Free allocated memory */
1852
- BN_CTX_free(bn_ctx);
1853
- bn_ctx = NULL;
1854
- OPENSSL_free(encodedPoint);
1855
- encodedPoint = NULL;
1856
- EC_KEY_free(clnt_ecdh);
1857
- clnt_ecdh = NULL;
1858
- EVP_PKEY_free(srvr_pub_pkey);
1859
- srvr_pub_pkey = NULL;
1860
- } else if (alg_k & SSL_kPSK) {
1861
- /* For plain PSK, other_secret is a block of 0s with the same length as
1862
- * the pre-shared key. */
1863
- pms_len = psk_len;
1864
- pms = OPENSSL_malloc(pms_len);
1865
- if (pms == NULL) {
1866
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1867
- goto err;
1868
- }
1869
- memset(pms, 0, pms_len);
1665
+ uint8_t *ptr;
1666
+ if (!CBB_reserve(enc_pms, &ptr, RSA_size(rsa)) ||
1667
+ !RSA_encrypt(rsa, &enc_pms_len, ptr, RSA_size(rsa), pms, pms_len,
1668
+ RSA_PKCS1_PADDING) ||
1669
+ /* Log the premaster secret, if logging is enabled. */
1670
+ !ssl_log_rsa_client_key_exchange(ssl, ptr, enc_pms_len, pms, pms_len) ||
1671
+ !CBB_did_write(enc_pms, enc_pms_len) ||
1672
+ !CBB_flush(&cbb)) {
1673
+ goto err;
1674
+ }
1675
+ } else if (alg_k & (SSL_kECDHE|SSL_kDHE)) {
1676
+ /* Generate a keypair and serialize the public half. ECDHE uses a u8 length
1677
+ * prefix while DHE uses u16. */
1678
+ CBB child;
1679
+ int child_ok;
1680
+ if (alg_k & SSL_kECDHE) {
1681
+ child_ok = CBB_add_u8_length_prefixed(&cbb, &child);
1870
1682
  } else {
1871
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1872
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1683
+ child_ok = CBB_add_u16_length_prefixed(&cbb, &child);
1684
+ }
1685
+
1686
+ if (!child_ok ||
1687
+ !SSL_ECDH_CTX_generate_keypair(&ssl->s3->tmp.ecdh_ctx, &child) ||
1688
+ !CBB_flush(&cbb)) {
1873
1689
  goto err;
1874
1690
  }
1875
1691
 
1876
- /* For a PSK cipher suite, other_secret is combined with the pre-shared
1877
- * key. */
1878
- if (alg_a & SSL_aPSK) {
1879
- CBB cbb, child;
1880
- uint8_t *new_pms;
1881
- size_t new_pms_len;
1882
-
1883
- CBB_zero(&cbb);
1884
- if (!CBB_init(&cbb, 2 + psk_len + 2 + pms_len) ||
1885
- !CBB_add_u16_length_prefixed(&cbb, &child) ||
1886
- !CBB_add_bytes(&child, pms, pms_len) ||
1887
- !CBB_add_u16_length_prefixed(&cbb, &child) ||
1888
- !CBB_add_bytes(&child, psk, psk_len) ||
1889
- !CBB_finish(&cbb, &new_pms, &new_pms_len)) {
1890
- CBB_cleanup(&cbb);
1891
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1892
- goto err;
1893
- }
1894
- OPENSSL_cleanse(pms, pms_len);
1895
- OPENSSL_free(pms);
1896
- pms = new_pms;
1897
- pms_len = new_pms_len;
1692
+ /* Compute the premaster. */
1693
+ uint8_t alert;
1694
+ if (!SSL_ECDH_CTX_compute_secret(&ssl->s3->tmp.ecdh_ctx, &pms, &pms_len,
1695
+ &alert, ssl->s3->tmp.peer_key,
1696
+ ssl->s3->tmp.peer_key_len)) {
1697
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, alert);
1698
+ goto err;
1898
1699
  }
1899
1700
 
1900
- /* The message must be added to the finished hash before calculating the
1901
- * master secret. */
1902
- if (!ssl_set_handshake_header(s, SSL3_MT_CLIENT_KEY_EXCHANGE, n)) {
1701
+ /* The key exchange state may now be discarded. */
1702
+ SSL_ECDH_CTX_cleanup(&ssl->s3->tmp.ecdh_ctx);
1703
+ OPENSSL_free(ssl->s3->tmp.peer_key);
1704
+ ssl->s3->tmp.peer_key = NULL;
1705
+ } else if (alg_k & SSL_kPSK) {
1706
+ /* For plain PSK, other_secret is a block of 0s with the same length as
1707
+ * the pre-shared key. */
1708
+ pms_len = psk_len;
1709
+ pms = OPENSSL_malloc(pms_len);
1710
+ if (pms == NULL) {
1711
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1903
1712
  goto err;
1904
1713
  }
1905
- s->state = SSL3_ST_CW_KEY_EXCH_B;
1714
+ memset(pms, 0, pms_len);
1715
+ } else {
1716
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1717
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1718
+ goto err;
1719
+ }
1906
1720
 
1907
- s->session->master_key_length = s->enc_method->generate_master_secret(
1908
- s, s->session->master_key, pms, pms_len);
1909
- if (s->session->master_key_length == 0) {
1721
+ /* For a PSK cipher suite, other_secret is combined with the pre-shared
1722
+ * key. */
1723
+ if (alg_a & SSL_aPSK) {
1724
+ CBB pms_cbb, child;
1725
+ uint8_t *new_pms;
1726
+ size_t new_pms_len;
1727
+
1728
+ CBB_zero(&pms_cbb);
1729
+ if (!CBB_init(&pms_cbb, 2 + psk_len + 2 + pms_len) ||
1730
+ !CBB_add_u16_length_prefixed(&pms_cbb, &child) ||
1731
+ !CBB_add_bytes(&child, pms, pms_len) ||
1732
+ !CBB_add_u16_length_prefixed(&pms_cbb, &child) ||
1733
+ !CBB_add_bytes(&child, psk, psk_len) ||
1734
+ !CBB_finish(&pms_cbb, &new_pms, &new_pms_len)) {
1735
+ CBB_cleanup(&pms_cbb);
1736
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1910
1737
  goto err;
1911
1738
  }
1912
- s->session->extended_master_secret = s->s3->tmp.extended_master_secret;
1913
1739
  OPENSSL_cleanse(pms, pms_len);
1914
1740
  OPENSSL_free(pms);
1741
+ pms = new_pms;
1742
+ pms_len = new_pms_len;
1915
1743
  }
1916
1744
 
1745
+ /* The message must be added to the finished hash before calculating the
1746
+ * master secret. */
1747
+ size_t length;
1748
+ if (!CBB_finish(&cbb, NULL, &length) ||
1749
+ !ssl_set_handshake_header(ssl, SSL3_MT_CLIENT_KEY_EXCHANGE, length)) {
1750
+ goto err;
1751
+ }
1752
+ ssl->state = SSL3_ST_CW_KEY_EXCH_B;
1753
+
1754
+ ssl->session->master_key_length =
1755
+ tls1_generate_master_secret(ssl, ssl->session->master_key, pms, pms_len);
1756
+ if (ssl->session->master_key_length == 0) {
1757
+ goto err;
1758
+ }
1759
+ ssl->session->extended_master_secret = ssl->s3->tmp.extended_master_secret;
1760
+ OPENSSL_cleanse(pms, pms_len);
1761
+ OPENSSL_free(pms);
1762
+
1917
1763
  /* SSL3_ST_CW_KEY_EXCH_B */
1918
- return s->method->do_write(s);
1764
+ return ssl_do_write(ssl);
1919
1765
 
1920
1766
  err:
1921
- BN_CTX_free(bn_ctx);
1922
- OPENSSL_free(encodedPoint);
1923
- EC_KEY_free(clnt_ecdh);
1924
- EVP_PKEY_free(srvr_pub_pkey);
1925
- if (pms) {
1767
+ if (pms != NULL) {
1926
1768
  OPENSSL_cleanse(pms, pms_len);
1927
1769
  OPENSSL_free(pms);
1928
1770
  }
1929
1771
  return -1;
1930
1772
  }
1931
1773
 
1932
- int ssl3_send_cert_verify(SSL *s) {
1933
- if (s->state == SSL3_ST_CW_CERT_VRFY_A ||
1934
- s->state == SSL3_ST_CW_CERT_VRFY_B) {
1935
- enum ssl_private_key_result_t sign_result;
1936
- uint8_t *p = ssl_handshake_start(s);
1937
- size_t signature_length = 0;
1938
- unsigned long n = 0;
1939
- assert(ssl_has_private_key(s));
1940
-
1941
- if (s->state == SSL3_ST_CW_CERT_VRFY_A) {
1942
- uint8_t *buf = (uint8_t *)s->init_buf->data;
1943
- const EVP_MD *md = NULL;
1944
- uint8_t digest[EVP_MAX_MD_SIZE];
1945
- size_t digest_length;
1946
-
1947
- /* Write out the digest type if need be. */
1948
- if (SSL_USE_SIGALGS(s)) {
1949
- md = tls1_choose_signing_digest(s);
1950
- if (!tls12_get_sigandhash(s, p, md)) {
1951
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1952
- return -1;
1953
- }
1954
- p += 2;
1955
- n += 2;
1956
- }
1774
+ int ssl3_send_cert_verify(SSL *ssl) {
1775
+ if (ssl->state == SSL3_ST_CW_CERT_VRFY_C) {
1776
+ return ssl_do_write(ssl);
1777
+ }
1957
1778
 
1958
- /* Compute the digest. */
1959
- const int pkey_type = ssl_private_key_type(s);
1960
- if (!ssl3_cert_verify_hash(s, digest, &digest_length, &md, pkey_type)) {
1961
- return -1;
1962
- }
1779
+ CBB cbb, child;
1780
+ if (!CBB_init_fixed(&cbb, ssl_handshake_start(ssl),
1781
+ ssl->init_buf->max - SSL_HM_HEADER_LENGTH(ssl))) {
1782
+ goto err;
1783
+ }
1963
1784
 
1964
- /* The handshake buffer is no longer necessary. */
1965
- ssl3_free_handshake_buffer(s);
1785
+ assert(ssl_has_private_key(ssl));
1966
1786
 
1967
- /* Sign the digest. */
1968
- signature_length = ssl_private_key_max_signature_len(s);
1969
- if (p + 2 + signature_length > buf + SSL3_RT_MAX_PLAIN_LENGTH) {
1970
- OPENSSL_PUT_ERROR(SSL, SSL_R_DATA_LENGTH_TOO_LONG);
1971
- return -1;
1787
+ const size_t max_sig_len = ssl_private_key_max_signature_len(ssl);
1788
+ size_t sig_len;
1789
+ enum ssl_private_key_result_t sign_result;
1790
+ if (ssl->state == SSL3_ST_CW_CERT_VRFY_A) {
1791
+ /* Select and write out the digest type in TLS 1.2. */
1792
+ const EVP_MD *md = NULL;
1793
+ if (ssl3_protocol_version(ssl) >= TLS1_2_VERSION) {
1794
+ md = tls1_choose_signing_digest(ssl);
1795
+ if (!tls12_add_sigandhash(ssl, &cbb, md)) {
1796
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
1797
+ goto err;
1972
1798
  }
1799
+ }
1973
1800
 
1974
- s->rwstate = SSL_PRIVATE_KEY_OPERATION;
1975
- sign_result = ssl_private_key_sign(s, &p[2], &signature_length,
1976
- signature_length, md, digest,
1977
- digest_length);
1978
- } else {
1979
- if (SSL_USE_SIGALGS(s)) {
1980
- /* The digest has already been selected and written. */
1981
- p += 2;
1982
- n += 2;
1983
- }
1984
- signature_length = ssl_private_key_max_signature_len(s);
1985
- s->rwstate = SSL_PRIVATE_KEY_OPERATION;
1986
- sign_result = ssl_private_key_sign_complete(s, &p[2], &signature_length,
1987
- signature_length);
1801
+ /* Compute the digest. In TLS 1.1 and below, the digest type is also
1802
+ * selected here. */
1803
+ uint8_t digest[EVP_MAX_MD_SIZE];
1804
+ size_t digest_len;
1805
+ if (!ssl3_cert_verify_hash(ssl, digest, &digest_len, &md,
1806
+ ssl_private_key_type(ssl))) {
1807
+ goto err;
1988
1808
  }
1989
1809
 
1990
- if (sign_result == ssl_private_key_retry) {
1991
- s->state = SSL3_ST_CW_CERT_VRFY_B;
1992
- return -1;
1810
+ /* The handshake buffer is no longer necessary. */
1811
+ ssl3_free_handshake_buffer(ssl);
1812
+
1813
+ /* Sign the digest. */
1814
+ uint8_t *ptr;
1815
+ if (!CBB_add_u16_length_prefixed(&cbb, &child) ||
1816
+ !CBB_reserve(&child, &ptr, max_sig_len)) {
1817
+ goto err;
1993
1818
  }
1994
- s->rwstate = SSL_NOTHING;
1995
- if (sign_result != ssl_private_key_success) {
1996
- return -1;
1819
+ sign_result = ssl_private_key_sign(ssl, ptr, &sig_len, max_sig_len, md,
1820
+ digest, digest_len);
1821
+ } else {
1822
+ assert(ssl->state == SSL3_ST_CW_CERT_VRFY_B);
1823
+
1824
+ /* Skip over the already written signature algorithm and retry the
1825
+ * signature. */
1826
+ uint8_t *ptr;
1827
+ if ((ssl3_protocol_version(ssl) >= TLS1_2_VERSION &&
1828
+ !CBB_did_write(&cbb, 2)) ||
1829
+ !CBB_add_u16_length_prefixed(&cbb, &child) ||
1830
+ !CBB_reserve(&child, &ptr, max_sig_len)) {
1831
+ goto err;
1997
1832
  }
1833
+ sign_result =
1834
+ ssl_private_key_sign_complete(ssl, ptr, &sig_len, max_sig_len);
1835
+ }
1998
1836
 
1999
- s2n(signature_length, p);
2000
- n += signature_length + 2;
2001
- if (!ssl_set_handshake_header(s, SSL3_MT_CERTIFICATE_VERIFY, n)) {
2002
- return -1;
2003
- }
2004
- s->state = SSL3_ST_CW_CERT_VRFY_C;
1837
+ switch (sign_result) {
1838
+ case ssl_private_key_success:
1839
+ ssl->rwstate = SSL_NOTHING;
1840
+ break;
1841
+ case ssl_private_key_failure:
1842
+ ssl->rwstate = SSL_NOTHING;
1843
+ goto err;
1844
+ case ssl_private_key_retry:
1845
+ ssl->rwstate = SSL_PRIVATE_KEY_OPERATION;
1846
+ ssl->state = SSL3_ST_CW_CERT_VRFY_B;
1847
+ goto err;
2005
1848
  }
2006
1849
 
2007
- return ssl_do_write(s);
1850
+ size_t length;
1851
+ if (!CBB_did_write(&child, sig_len) ||
1852
+ !CBB_finish(&cbb, NULL, &length) ||
1853
+ !ssl_set_handshake_header(ssl, SSL3_MT_CERTIFICATE_VERIFY, length)) {
1854
+ goto err;
1855
+ }
1856
+
1857
+ ssl->state = SSL3_ST_CW_CERT_VRFY_C;
1858
+ return ssl_do_write(ssl);
1859
+
1860
+ err:
1861
+ CBB_cleanup(&cbb);
1862
+ return -1;
2008
1863
  }
2009
1864
 
2010
1865
  /* ssl3_has_client_certificate returns true if a client certificate is
@@ -2013,47 +1868,47 @@ static int ssl3_has_client_certificate(SSL *ssl) {
2013
1868
  return ssl->cert && ssl->cert->x509 && ssl_has_private_key(ssl);
2014
1869
  }
2015
1870
 
2016
- int ssl3_send_client_certificate(SSL *s) {
1871
+ int ssl3_send_client_certificate(SSL *ssl) {
2017
1872
  X509 *x509 = NULL;
2018
1873
  EVP_PKEY *pkey = NULL;
2019
1874
  int i;
2020
1875
 
2021
- if (s->state == SSL3_ST_CW_CERT_A) {
1876
+ if (ssl->state == SSL3_ST_CW_CERT_A) {
2022
1877
  /* Let cert callback update client certificates if required */
2023
- if (s->cert->cert_cb) {
2024
- i = s->cert->cert_cb(s, s->cert->cert_cb_arg);
1878
+ if (ssl->cert->cert_cb) {
1879
+ i = ssl->cert->cert_cb(ssl, ssl->cert->cert_cb_arg);
2025
1880
  if (i < 0) {
2026
- s->rwstate = SSL_X509_LOOKUP;
1881
+ ssl->rwstate = SSL_X509_LOOKUP;
2027
1882
  return -1;
2028
1883
  }
2029
1884
  if (i == 0) {
2030
- ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
1885
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
2031
1886
  return 0;
2032
1887
  }
2033
- s->rwstate = SSL_NOTHING;
1888
+ ssl->rwstate = SSL_NOTHING;
2034
1889
  }
2035
1890
 
2036
- if (ssl3_has_client_certificate(s)) {
2037
- s->state = SSL3_ST_CW_CERT_C;
1891
+ if (ssl3_has_client_certificate(ssl)) {
1892
+ ssl->state = SSL3_ST_CW_CERT_C;
2038
1893
  } else {
2039
- s->state = SSL3_ST_CW_CERT_B;
1894
+ ssl->state = SSL3_ST_CW_CERT_B;
2040
1895
  }
2041
1896
  }
2042
1897
 
2043
1898
  /* We need to get a client cert */
2044
- if (s->state == SSL3_ST_CW_CERT_B) {
1899
+ if (ssl->state == SSL3_ST_CW_CERT_B) {
2045
1900
  /* If we get an error, we need to:
2046
1901
  * ssl->rwstate=SSL_X509_LOOKUP; return(-1);
2047
1902
  * We then get retried later */
2048
- i = ssl_do_client_cert_cb(s, &x509, &pkey);
1903
+ i = ssl_do_client_cert_cb(ssl, &x509, &pkey);
2049
1904
  if (i < 0) {
2050
- s->rwstate = SSL_X509_LOOKUP;
1905
+ ssl->rwstate = SSL_X509_LOOKUP;
2051
1906
  return -1;
2052
1907
  }
2053
- s->rwstate = SSL_NOTHING;
1908
+ ssl->rwstate = SSL_NOTHING;
2054
1909
  if (i == 1 && pkey != NULL && x509 != NULL) {
2055
- s->state = SSL3_ST_CW_CERT_B;
2056
- if (!SSL_use_certificate(s, x509) || !SSL_use_PrivateKey(s, pkey)) {
1910
+ ssl->state = SSL3_ST_CW_CERT_B;
1911
+ if (!SSL_use_certificate(ssl, x509) || !SSL_use_PrivateKey(ssl, pkey)) {
2057
1912
  i = 0;
2058
1913
  }
2059
1914
  } else if (i == 1) {
@@ -2063,42 +1918,42 @@ int ssl3_send_client_certificate(SSL *s) {
2063
1918
 
2064
1919
  X509_free(x509);
2065
1920
  EVP_PKEY_free(pkey);
2066
- if (i && !ssl3_has_client_certificate(s)) {
1921
+ if (i && !ssl3_has_client_certificate(ssl)) {
2067
1922
  i = 0;
2068
1923
  }
2069
1924
  if (i == 0) {
2070
- if (s->version == SSL3_VERSION) {
2071
- s->s3->tmp.cert_req = 0;
2072
- ssl3_send_alert(s, SSL3_AL_WARNING, SSL_AD_NO_CERTIFICATE);
1925
+ if (ssl->version == SSL3_VERSION) {
1926
+ ssl->s3->tmp.cert_req = 0;
1927
+ ssl3_send_alert(ssl, SSL3_AL_WARNING, SSL_AD_NO_CERTIFICATE);
2073
1928
  return 1;
2074
1929
  } else {
2075
- s->s3->tmp.cert_req = 2;
1930
+ ssl->s3->tmp.cert_req = 2;
2076
1931
  /* There is no client certificate, so the handshake buffer may be
2077
1932
  * released. */
2078
- ssl3_free_handshake_buffer(s);
1933
+ ssl3_free_handshake_buffer(ssl);
2079
1934
  }
2080
1935
  }
2081
1936
 
2082
1937
  /* Ok, we have a cert */
2083
- s->state = SSL3_ST_CW_CERT_C;
1938
+ ssl->state = SSL3_ST_CW_CERT_C;
2084
1939
  }
2085
1940
 
2086
- if (s->state == SSL3_ST_CW_CERT_C) {
2087
- if (s->s3->tmp.cert_req == 2) {
1941
+ if (ssl->state == SSL3_ST_CW_CERT_C) {
1942
+ if (ssl->s3->tmp.cert_req == 2) {
2088
1943
  /* Send an empty Certificate message. */
2089
- uint8_t *p = ssl_handshake_start(s);
1944
+ uint8_t *p = ssl_handshake_start(ssl);
2090
1945
  l2n3(0, p);
2091
- if (!ssl_set_handshake_header(s, SSL3_MT_CERTIFICATE, 3)) {
1946
+ if (!ssl_set_handshake_header(ssl, SSL3_MT_CERTIFICATE, 3)) {
2092
1947
  return -1;
2093
1948
  }
2094
- } else if (!ssl3_output_cert_chain(s)) {
1949
+ } else if (!ssl3_output_cert_chain(ssl)) {
2095
1950
  return -1;
2096
1951
  }
2097
- s->state = SSL3_ST_CW_CERT_D;
1952
+ ssl->state = SSL3_ST_CW_CERT_D;
2098
1953
  }
2099
1954
 
2100
1955
  /* SSL3_ST_CW_CERT_D */
2101
- return ssl_do_write(s);
1956
+ return ssl_do_write(ssl);
2102
1957
  }
2103
1958
 
2104
1959
  int ssl3_send_next_proto(SSL *ssl) {
@@ -2109,7 +1964,7 @@ int ssl3_send_next_proto(SSL *ssl) {
2109
1964
  assert(ssl->state == SSL3_ST_CW_NEXT_PROTO_A);
2110
1965
 
2111
1966
  static const uint8_t kZero[32] = {0};
2112
- size_t padding_len = 32 - ((ssl->next_proto_negotiated_len + 2) % 32);
1967
+ size_t padding_len = 32 - ((ssl->s3->next_proto_negotiated_len + 2) % 32);
2113
1968
 
2114
1969
  CBB cbb, child;
2115
1970
  size_t length;
@@ -2117,8 +1972,8 @@ int ssl3_send_next_proto(SSL *ssl) {
2117
1972
  if (!CBB_init_fixed(&cbb, ssl_handshake_start(ssl),
2118
1973
  ssl->init_buf->max - SSL_HM_HEADER_LENGTH(ssl)) ||
2119
1974
  !CBB_add_u8_length_prefixed(&cbb, &child) ||
2120
- !CBB_add_bytes(&child, ssl->next_proto_negotiated,
2121
- ssl->next_proto_negotiated_len) ||
1975
+ !CBB_add_bytes(&child, ssl->s3->next_proto_negotiated,
1976
+ ssl->s3->next_proto_negotiated_len) ||
2122
1977
  !CBB_add_u8_length_prefixed(&cbb, &child) ||
2123
1978
  !CBB_add_bytes(&child, kZero, padding_len) ||
2124
1979
  !CBB_finish(&cbb, NULL, &length) ||
@@ -2132,12 +1987,6 @@ int ssl3_send_next_proto(SSL *ssl) {
2132
1987
  return ssl_do_write(ssl);
2133
1988
  }
2134
1989
 
2135
- static int write_32_byte_big_endian(CBB *out, const BIGNUM *in) {
2136
- uint8_t *ptr;
2137
- return CBB_add_space(out, &ptr, 32) &&
2138
- BN_bn2bin_padded(ptr, 32, in);
2139
- }
2140
-
2141
1990
  int ssl3_send_channel_id(SSL *ssl) {
2142
1991
  if (ssl->state == SSL3_ST_CW_CHANNEL_ID_B) {
2143
1992
  return ssl_do_write(ssl);
@@ -2198,10 +2047,10 @@ int ssl3_send_channel_id(SSL *ssl) {
2198
2047
  ssl->init_buf->max - SSL_HM_HEADER_LENGTH(ssl)) ||
2199
2048
  !CBB_add_u16(&cbb, TLSEXT_TYPE_channel_id) ||
2200
2049
  !CBB_add_u16_length_prefixed(&cbb, &child) ||
2201
- !write_32_byte_big_endian(&child, x) ||
2202
- !write_32_byte_big_endian(&child, y) ||
2203
- !write_32_byte_big_endian(&child, sig->r) ||
2204
- !write_32_byte_big_endian(&child, sig->s) ||
2050
+ !BN_bn2cbb_padded(&child, 32, x) ||
2051
+ !BN_bn2cbb_padded(&child, 32, y) ||
2052
+ !BN_bn2cbb_padded(&child, 32, sig->r) ||
2053
+ !BN_bn2cbb_padded(&child, 32, sig->s) ||
2205
2054
  !CBB_finish(&cbb, NULL, &length) ||
2206
2055
  !ssl_set_handshake_header(ssl, SSL3_MT_ENCRYPTED_EXTENSIONS, length)) {
2207
2056
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
@@ -2226,15 +2075,15 @@ int ssl_do_client_cert_cb(SSL *ssl, X509 **out_x509, EVP_PKEY **out_pkey) {
2226
2075
  return ssl->ctx->client_cert_cb(ssl, out_x509, out_pkey);
2227
2076
  }
2228
2077
 
2229
- int ssl3_verify_server_cert(SSL *s) {
2230
- int ret = ssl_verify_cert_chain(s, s->session->cert_chain);
2231
- if (s->verify_mode != SSL_VERIFY_NONE && ret <= 0) {
2232
- int al = ssl_verify_alarm_type(s->verify_result);
2233
- ssl3_send_alert(s, SSL3_AL_FATAL, al);
2078
+ int ssl3_verify_server_cert(SSL *ssl) {
2079
+ int ret = ssl_verify_cert_chain(ssl, ssl->session->cert_chain);
2080
+ if (ssl->verify_mode != SSL_VERIFY_NONE && ret <= 0) {
2081
+ int al = ssl_verify_alarm_type(ssl->verify_result);
2082
+ ssl3_send_alert(ssl, SSL3_AL_FATAL, al);
2234
2083
  OPENSSL_PUT_ERROR(SSL, SSL_R_CERTIFICATE_VERIFY_FAILED);
2235
2084
  } else {
2236
2085
  ret = 1;
2237
- ERR_clear_error(); /* but we keep s->verify_result */
2086
+ ERR_clear_error(); /* but we keep ssl->verify_result */
2238
2087
  }
2239
2088
 
2240
2089
  return ret;