grpc 1.0.1 → 1.1.2

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 (705) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +3696 -867
  3. data/etc/roots.pem +39 -111
  4. data/include/grpc/byte_buffer.h +64 -1
  5. data/include/grpc/census.h +40 -96
  6. data/include/grpc/compression.h +2 -1
  7. data/include/grpc/grpc.h +42 -7
  8. data/include/grpc/grpc_posix.h +8 -5
  9. data/include/grpc/impl/codegen/atm.h +3 -0
  10. data/include/grpc/impl/codegen/atm_gcc_atomic.h +2 -0
  11. data/include/grpc/impl/codegen/atm_gcc_sync.h +8 -0
  12. data/include/grpc/impl/codegen/atm_windows.h +4 -0
  13. data/include/grpc/impl/codegen/byte_buffer_reader.h +4 -4
  14. data/include/grpc/impl/codegen/compression_types.h +1 -1
  15. data/include/grpc/impl/codegen/connectivity_state.h +2 -0
  16. data/include/grpc/impl/codegen/exec_ctx_fwd.h +41 -0
  17. data/include/grpc/impl/codegen/gpr_slice.h +84 -0
  18. data/include/grpc/impl/codegen/{alloc.h → gpr_types.h} +30 -29
  19. data/include/grpc/impl/codegen/grpc_types.h +91 -9
  20. data/include/grpc/impl/codegen/port_platform.h +25 -92
  21. data/include/grpc/impl/codegen/slice.h +54 -97
  22. data/include/grpc/impl/codegen/sync.h +0 -253
  23. data/include/grpc/module.modulemap +0 -2
  24. data/include/grpc/slice.h +132 -0
  25. data/include/grpc/{impl/codegen/slice_buffer.h → slice_buffer.h} +22 -39
  26. data/include/grpc/support/alloc.h +40 -1
  27. data/include/grpc/support/log.h +80 -1
  28. data/include/grpc/support/log_windows.h +2 -0
  29. data/include/grpc/support/string_util.h +1 -1
  30. data/include/grpc/support/sync.h +252 -0
  31. data/include/grpc/support/time.h +67 -1
  32. data/src/boringssl/err_data.c +639 -627
  33. data/src/core/ext/census/base_resources.c +71 -0
  34. data/src/core/ext/census/base_resources.h +39 -0
  35. data/src/core/ext/census/gen/census.pb.c +26 -29
  36. data/src/core/ext/census/gen/census.pb.h +68 -67
  37. data/src/core/ext/census/gen/trace_context.pb.c +81 -0
  38. data/src/core/ext/census/gen/trace_context.pb.h +99 -0
  39. data/src/core/ext/census/grpc_filter.c +22 -16
  40. data/src/core/ext/census/grpc_plugin.c +2 -1
  41. data/src/core/ext/census/initialize.c +16 -4
  42. data/src/core/ext/census/mlog.h +1 -1
  43. data/src/core/ext/census/placeholders.c +0 -45
  44. data/src/core/ext/census/resource.c +312 -0
  45. data/src/core/ext/census/resource.h +63 -0
  46. data/src/core/ext/census/trace_context.c +86 -0
  47. data/src/core/ext/census/trace_context.h +68 -0
  48. data/src/core/ext/census/tracing.c +8 -2
  49. data/src/core/ext/{client_config → client_channel}/channel_connectivity.c +8 -4
  50. data/src/core/ext/client_channel/client_channel.c +1218 -0
  51. data/src/core/ext/{client_config → client_channel}/client_channel.h +8 -11
  52. data/src/core/ext/{client_config → client_channel}/client_channel_factory.c +33 -3
  53. data/src/core/ext/{client_config → client_channel}/client_channel_factory.h +15 -8
  54. data/src/core/ext/{client_config/client_config_plugin.c → client_channel/client_channel_plugin.c} +16 -15
  55. data/src/core/ext/{client_config → client_channel}/connector.c +1 -1
  56. data/src/core/ext/{client_config → client_channel}/connector.h +5 -8
  57. data/{include/grpc/support/slice_buffer.h → src/core/ext/client_channel/default_initial_connect_string.c} +4 -5
  58. data/src/core/ext/client_channel/http_connect_handshaker.c +399 -0
  59. data/src/core/ext/client_channel/http_connect_handshaker.h +52 -0
  60. data/src/core/ext/{client_config → client_channel}/initial_connect_string.c +6 -7
  61. data/src/core/ext/{client_config → client_channel}/initial_connect_string.h +10 -10
  62. data/src/core/ext/{client_config → client_channel}/lb_policy.c +11 -11
  63. data/src/core/ext/{client_config → client_channel}/lb_policy.h +68 -27
  64. data/src/core/ext/client_channel/lb_policy_factory.c +163 -0
  65. data/src/core/ext/{client_config → client_channel}/lb_policy_factory.h +64 -9
  66. data/src/core/ext/{client_config → client_channel}/lb_policy_registry.c +6 -4
  67. data/src/core/ext/{client_config → client_channel}/lb_policy_registry.h +4 -4
  68. data/src/core/ext/{client_config → client_channel}/parse_address.c +21 -14
  69. data/src/core/ext/{client_config → client_channel}/parse_address.h +8 -10
  70. data/src/core/ext/{client_config → client_channel}/resolver.c +3 -4
  71. data/src/core/ext/{client_config → client_channel}/resolver.h +11 -15
  72. data/src/core/ext/{client_config → client_channel}/resolver_factory.c +4 -3
  73. data/src/core/ext/{client_config → client_channel}/resolver_factory.h +13 -11
  74. data/src/core/ext/{client_config → client_channel}/resolver_registry.c +54 -34
  75. data/src/core/ext/{client_config → client_channel}/resolver_registry.h +21 -8
  76. data/src/core/ext/{client_config → client_channel}/subchannel.c +208 -119
  77. data/src/core/ext/{client_config → client_channel}/subchannel.h +21 -11
  78. data/src/core/ext/{client_config → client_channel}/subchannel_index.c +6 -17
  79. data/src/core/ext/{client_config → client_channel}/subchannel_index.h +7 -7
  80. data/src/core/ext/{client_config → client_channel}/uri_parser.c +21 -28
  81. data/src/core/ext/{client_config → client_channel}/uri_parser.h +3 -3
  82. data/src/core/ext/lb_policy/grpclb/grpclb.c +1406 -0
  83. data/src/core/ext/lb_policy/grpclb/grpclb.h +44 -0
  84. data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +117 -37
  85. data/src/core/ext/lb_policy/grpclb/load_balancer_api.h +31 -12
  86. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +6 -36
  87. data/src/core/ext/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +22 -42
  88. data/src/core/ext/lb_policy/pick_first/pick_first.c +64 -46
  89. data/src/core/ext/lb_policy/round_robin/round_robin.c +324 -160
  90. data/src/core/ext/load_reporting/load_reporting.c +7 -56
  91. data/src/core/ext/load_reporting/load_reporting.h +41 -28
  92. data/src/core/ext/load_reporting/load_reporting_filter.c +132 -42
  93. data/src/core/ext/load_reporting/load_reporting_filter.h +1 -0
  94. data/src/core/ext/resolver/dns/native/dns_resolver.c +88 -80
  95. data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +57 -102
  96. data/src/core/ext/transport/chttp2/alpn/alpn.c +1 -1
  97. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +253 -0
  98. data/src/core/{lib/iomgr/ev_poll_and_epoll_posix.h → ext/transport/chttp2/client/chttp2_connector.h} +5 -5
  99. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +31 -160
  100. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +5 -5
  101. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +44 -243
  102. data/src/core/ext/transport/chttp2/server/chttp2_server.c +342 -0
  103. data/src/core/ext/transport/chttp2/server/chttp2_server.h +47 -0
  104. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +11 -124
  105. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +20 -9
  106. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +28 -236
  107. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +31 -27
  108. data/src/core/ext/transport/chttp2/transport/bin_decoder.h +5 -4
  109. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +25 -22
  110. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +8 -7
  111. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +0 -3
  112. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +1345 -1521
  113. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
  114. data/src/core/ext/transport/chttp2/transport/frame.h +3 -5
  115. data/src/core/ext/transport/chttp2/transport/frame_data.c +50 -47
  116. data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -9
  117. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +19 -21
  118. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +9 -8
  119. data/src/core/ext/transport/chttp2/transport/frame_ping.c +13 -12
  120. data/src/core/ext/transport/chttp2/transport/frame_ping.h +6 -6
  121. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +31 -19
  122. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +8 -7
  123. data/src/core/ext/transport/chttp2/transport/frame_settings.c +22 -25
  124. data/src/core/ext/transport/chttp2/transport/frame_settings.h +9 -8
  125. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +26 -18
  126. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +5 -6
  127. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +68 -58
  128. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +8 -5
  129. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +327 -214
  130. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +14 -9
  131. data/src/core/ext/transport/chttp2/transport/hpack_table.c +24 -19
  132. data/src/core/ext/transport/chttp2/transport/hpack_table.h +9 -6
  133. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +2 -2
  134. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +1 -1
  135. data/src/core/ext/transport/chttp2/transport/internal.h +284 -436
  136. data/src/core/ext/transport/chttp2/transport/parsing.c +355 -590
  137. data/src/core/ext/transport/chttp2/transport/stream_lists.c +36 -309
  138. data/src/core/ext/transport/chttp2/transport/stream_map.c +13 -34
  139. data/src/core/ext/transport/chttp2/transport/stream_map.h +3 -4
  140. data/src/core/ext/transport/chttp2/transport/writing.c +174 -286
  141. data/src/core/lib/channel/channel_args.c +70 -13
  142. data/src/core/lib/channel/channel_args.h +28 -2
  143. data/src/core/lib/channel/channel_stack.c +77 -28
  144. data/src/core/lib/channel/channel_stack.h +61 -23
  145. data/src/core/lib/channel/channel_stack_builder.c +33 -25
  146. data/src/core/lib/channel/channel_stack_builder.h +17 -8
  147. data/src/core/lib/channel/compress_filter.c +52 -36
  148. data/src/core/lib/channel/connected_channel.c +20 -12
  149. data/src/core/lib/channel/connected_channel.h +2 -1
  150. data/src/core/lib/channel/context.h +13 -1
  151. data/src/core/lib/channel/deadline_filter.c +344 -0
  152. data/src/core/lib/channel/deadline_filter.h +99 -0
  153. data/src/core/lib/channel/handshaker.c +240 -0
  154. data/src/core/lib/channel/handshaker.h +164 -0
  155. data/src/core/lib/{security/credentials/google_default/credentials_windows.c → channel/handshaker_factory.c} +16 -23
  156. data/src/core/lib/channel/handshaker_factory.h +66 -0
  157. data/src/core/lib/channel/handshaker_registry.c +113 -0
  158. data/src/core/{ext/client_config/client_config.h → lib/channel/handshaker_registry.h} +26 -16
  159. data/src/core/lib/channel/http_client_filter.c +248 -46
  160. data/src/core/lib/channel/http_client_filter.h +3 -0
  161. data/src/core/lib/channel/http_server_filter.c +136 -24
  162. data/src/core/lib/channel/message_size_filter.c +261 -0
  163. data/src/core/lib/channel/message_size_filter.h +39 -0
  164. data/src/core/lib/compression/message_compress.c +43 -37
  165. data/src/core/lib/compression/message_compress.h +7 -5
  166. data/src/core/lib/http/format_request.c +26 -11
  167. data/src/core/lib/http/format_request.h +7 -5
  168. data/src/core/lib/http/httpcli.c +45 -27
  169. data/src/core/lib/http/httpcli.h +4 -4
  170. data/src/core/lib/http/httpcli_security_connector.c +56 -46
  171. data/src/core/lib/http/parser.c +17 -14
  172. data/src/core/lib/http/parser.h +4 -2
  173. data/src/core/lib/iomgr/closure.c +49 -7
  174. data/src/core/lib/iomgr/closure.h +56 -14
  175. data/src/core/lib/iomgr/combiner.c +422 -0
  176. data/src/core/lib/iomgr/combiner.h +64 -0
  177. data/src/core/lib/iomgr/endpoint.c +8 -2
  178. data/src/core/lib/iomgr/endpoint.h +17 -7
  179. data/src/core/lib/iomgr/endpoint_pair.h +3 -2
  180. data/src/core/lib/iomgr/endpoint_pair_posix.c +9 -8
  181. data/src/core/{ext/client_config/lb_policy_factory.c → lib/iomgr/endpoint_pair_uv.c} +18 -13
  182. data/src/core/lib/iomgr/endpoint_pair_windows.c +7 -6
  183. data/src/core/lib/iomgr/error.c +72 -6
  184. data/src/core/lib/iomgr/error.h +30 -3
  185. data/src/core/lib/iomgr/ev_epoll_linux.c +500 -382
  186. data/src/core/lib/iomgr/ev_epoll_linux.h +3 -2
  187. data/src/core/lib/iomgr/ev_poll_posix.c +317 -30
  188. data/src/core/lib/iomgr/ev_poll_posix.h +1 -0
  189. data/src/core/lib/iomgr/ev_posix.c +26 -5
  190. data/src/core/lib/iomgr/ev_posix.h +12 -1
  191. data/src/core/lib/iomgr/exec_ctx.c +27 -94
  192. data/src/core/lib/iomgr/exec_ctx.h +19 -22
  193. data/src/core/lib/iomgr/executor.c +29 -8
  194. data/src/core/lib/iomgr/executor.h +2 -4
  195. data/src/core/lib/iomgr/iocp_windows.c +3 -4
  196. data/src/core/lib/iomgr/iomgr.c +14 -10
  197. data/src/core/lib/iomgr/iomgr.h +6 -2
  198. data/src/core/lib/iomgr/iomgr_posix.c +2 -2
  199. data/src/core/lib/iomgr/iomgr_uv.c +49 -0
  200. data/src/core/lib/iomgr/iomgr_windows.c +2 -2
  201. data/src/core/lib/iomgr/load_file.c +3 -3
  202. data/src/core/lib/iomgr/load_file.h +2 -2
  203. data/src/core/lib/iomgr/network_status_tracker.c +1 -1
  204. data/src/core/lib/iomgr/pollset_set_uv.c +62 -0
  205. data/src/core/lib/iomgr/pollset_set_windows.c +3 -3
  206. data/src/core/lib/iomgr/pollset_uv.c +142 -0
  207. data/src/core/lib/iomgr/pollset_uv.h +42 -0
  208. data/src/core/lib/iomgr/pollset_windows.c +5 -6
  209. data/src/core/lib/iomgr/port.h +129 -0
  210. data/src/core/lib/iomgr/resolve_address.h +2 -1
  211. data/src/core/lib/iomgr/resolve_address_posix.c +14 -13
  212. data/src/core/lib/iomgr/resolve_address_uv.c +233 -0
  213. data/src/core/lib/iomgr/resolve_address_windows.c +14 -12
  214. data/src/core/lib/iomgr/resource_quota.c +832 -0
  215. data/src/core/lib/iomgr/resource_quota.h +159 -0
  216. data/src/core/lib/iomgr/sockaddr.h +10 -2
  217. data/src/core/lib/iomgr/sockaddr_utils.c +63 -36
  218. data/src/core/lib/iomgr/sockaddr_utils.h +14 -14
  219. data/src/core/lib/iomgr/socket_mutator.c +98 -0
  220. data/src/core/lib/iomgr/socket_mutator.h +80 -0
  221. data/src/core/lib/iomgr/socket_utils.h +42 -0
  222. data/src/core/lib/iomgr/socket_utils_common_posix.c +28 -13
  223. data/src/core/lib/iomgr/socket_utils_linux.c +11 -5
  224. data/src/core/lib/iomgr/socket_utils_posix.c +10 -7
  225. data/src/core/lib/iomgr/socket_utils_posix.h +11 -4
  226. data/src/core/lib/iomgr/socket_utils_uv.c +49 -0
  227. data/src/core/lib/iomgr/socket_utils_windows.c +52 -0
  228. data/src/core/lib/iomgr/socket_windows.c +14 -6
  229. data/src/core/lib/iomgr/socket_windows.h +1 -0
  230. data/src/core/lib/iomgr/tcp_client.h +8 -2
  231. data/src/core/lib/iomgr/tcp_client_posix.c +131 -82
  232. data/src/core/lib/iomgr/tcp_client_posix.h +45 -0
  233. data/src/core/lib/iomgr/tcp_client_uv.c +190 -0
  234. data/src/core/lib/iomgr/tcp_client_windows.c +54 -30
  235. data/src/core/lib/iomgr/tcp_posix.c +135 -56
  236. data/src/core/lib/iomgr/tcp_posix.h +2 -2
  237. data/src/core/lib/iomgr/tcp_server.h +14 -6
  238. data/src/core/lib/iomgr/tcp_server_posix.c +154 -118
  239. data/src/core/lib/iomgr/tcp_server_uv.c +388 -0
  240. data/src/core/lib/iomgr/tcp_server_windows.c +127 -100
  241. data/src/core/lib/iomgr/tcp_uv.c +367 -0
  242. data/src/core/lib/iomgr/tcp_uv.h +59 -0
  243. data/src/core/lib/iomgr/tcp_windows.c +65 -48
  244. data/src/core/lib/iomgr/tcp_windows.h +3 -1
  245. data/src/core/lib/iomgr/timer.h +21 -21
  246. data/src/core/lib/iomgr/{timer.c → timer_generic.c} +15 -10
  247. data/src/core/lib/iomgr/timer_generic.h +49 -0
  248. data/src/core/lib/iomgr/timer_heap.c +6 -0
  249. data/src/core/lib/iomgr/timer_uv.c +99 -0
  250. data/src/core/lib/iomgr/timer_uv.h +47 -0
  251. data/src/core/lib/iomgr/udp_server.c +116 -98
  252. data/src/core/lib/iomgr/udp_server.h +5 -3
  253. data/src/core/lib/iomgr/unix_sockets_posix.c +14 -6
  254. data/src/core/lib/iomgr/unix_sockets_posix.h +6 -5
  255. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +4 -4
  256. data/src/core/lib/iomgr/wakeup_fd_cv.c +118 -0
  257. data/src/core/lib/iomgr/wakeup_fd_cv.h +80 -0
  258. data/src/core/lib/iomgr/wakeup_fd_eventfd.c +3 -3
  259. data/src/core/lib/iomgr/wakeup_fd_nospecial.c +3 -3
  260. data/src/core/lib/iomgr/wakeup_fd_pipe.c +12 -6
  261. data/src/core/lib/iomgr/wakeup_fd_posix.c +34 -5
  262. data/src/core/lib/iomgr/wakeup_fd_posix.h +5 -0
  263. data/src/core/lib/iomgr/workqueue.h +12 -20
  264. data/src/core/{ext/client_config/client_config.c → lib/iomgr/workqueue_uv.c} +24 -33
  265. data/{include/grpc/support/slice.h → src/core/lib/iomgr/workqueue_uv.h} +4 -6
  266. data/src/core/lib/iomgr/workqueue_windows.c +9 -8
  267. data/src/core/lib/json/json.c +3 -3
  268. data/src/core/lib/json/json.h +11 -11
  269. data/src/core/lib/json/json_reader.c +9 -5
  270. data/src/core/lib/profiling/basic_timers.c +10 -1
  271. data/src/core/lib/profiling/timers.h +2 -0
  272. data/src/core/lib/security/context/security_context.c +13 -3
  273. data/src/core/lib/security/context/security_context.h +20 -0
  274. data/src/core/lib/security/credentials/composite/composite_credentials.c +28 -14
  275. data/src/core/lib/security/credentials/composite/composite_credentials.h +2 -2
  276. data/src/core/lib/security/credentials/credentials.c +48 -19
  277. data/src/core/lib/security/credentials/credentials.h +36 -19
  278. data/src/core/lib/security/credentials/credentials_metadata.c +11 -8
  279. data/src/core/lib/security/credentials/fake/fake_credentials.c +15 -11
  280. data/src/core/lib/security/credentials/google_default/{credentials_posix.c → credentials_generic.c} +7 -14
  281. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +33 -21
  282. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +14 -0
  283. data/src/core/lib/security/credentials/iam/iam_credentials.c +3 -2
  284. data/src/core/lib/security/credentials/jwt/json_token.c +1 -0
  285. data/src/core/lib/security/credentials/jwt/json_token.h +1 -1
  286. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +54 -19
  287. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +2 -1
  288. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +129 -79
  289. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +9 -6
  290. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +63 -28
  291. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +1 -1
  292. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +32 -11
  293. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +13 -9
  294. data/src/core/lib/security/transport/client_auth_filter.c +33 -27
  295. data/src/core/lib/security/transport/secure_endpoint.c +93 -68
  296. data/src/core/lib/security/transport/secure_endpoint.h +2 -2
  297. data/src/core/lib/security/transport/security_connector.c +133 -168
  298. data/src/core/lib/security/transport/security_connector.h +31 -46
  299. data/src/core/lib/security/transport/security_handshaker.c +501 -0
  300. data/src/core/lib/security/transport/{handshake.h → security_handshaker.h} +10 -10
  301. data/src/core/lib/security/transport/server_auth_filter.c +50 -38
  302. data/src/core/lib/security/util/b64.c +11 -8
  303. data/src/core/lib/security/util/b64.h +5 -4
  304. data/src/core/lib/slice/percent_encoding.c +182 -0
  305. data/src/core/lib/slice/percent_encoding.h +78 -0
  306. data/src/core/lib/{support → slice}/slice.c +81 -50
  307. data/src/core/lib/{support → slice}/slice_buffer.c +78 -60
  308. data/src/core/lib/slice/slice_internal.h +49 -0
  309. data/src/core/lib/slice/slice_string_helpers.c +90 -0
  310. data/src/core/lib/{iomgr/workqueue_posix.h → slice/slice_string_helpers.h} +18 -18
  311. data/src/core/lib/support/backoff.c +24 -13
  312. data/src/core/lib/support/backoff.h +5 -2
  313. data/src/core/lib/support/env.h +0 -2
  314. data/src/core/lib/support/log.c +5 -4
  315. data/src/core/lib/support/log_linux.c +0 -1
  316. data/src/core/lib/support/log_posix.c +1 -1
  317. data/src/core/lib/support/mpscq.c +83 -0
  318. data/src/core/lib/support/mpscq.h +65 -0
  319. data/src/core/lib/support/string.c +58 -49
  320. data/src/core/lib/support/string.h +11 -8
  321. data/src/core/lib/support/subprocess_posix.c +5 -2
  322. data/src/core/lib/support/thd.c +1 -1
  323. data/src/core/lib/support/time.c +43 -79
  324. data/src/core/lib/support/time_posix.c +1 -1
  325. data/src/core/lib/support/tmpfile.h +0 -2
  326. data/src/core/lib/surface/alarm.c +4 -1
  327. data/src/core/lib/surface/byte_buffer.c +17 -11
  328. data/src/core/lib/surface/byte_buffer_reader.c +23 -15
  329. data/src/core/lib/surface/call.c +294 -276
  330. data/src/core/lib/surface/call.h +24 -9
  331. data/src/core/lib/surface/call_log_batch.c +5 -3
  332. data/src/core/lib/surface/channel.c +127 -111
  333. data/src/core/lib/surface/channel.h +14 -5
  334. data/src/core/lib/surface/channel_init.c +1 -1
  335. data/src/core/lib/surface/channel_init.h +10 -1
  336. data/src/core/lib/surface/channel_ping.c +7 -6
  337. data/src/core/lib/surface/completion_queue.c +154 -18
  338. data/src/core/lib/surface/completion_queue.h +5 -0
  339. data/src/core/lib/surface/init.c +40 -6
  340. data/src/core/lib/surface/init.h +1 -0
  341. data/src/core/lib/surface/init_secure.c +5 -2
  342. data/src/core/lib/surface/lame_client.c +28 -18
  343. data/src/core/lib/surface/server.c +134 -87
  344. data/src/core/lib/surface/server.h +8 -0
  345. data/src/core/lib/surface/validate_metadata.c +1 -1
  346. data/src/core/lib/surface/version.c +3 -1
  347. data/src/core/lib/transport/byte_stream.c +7 -4
  348. data/src/core/lib/transport/byte_stream.h +6 -10
  349. data/src/core/lib/transport/connectivity_state.c +21 -12
  350. data/src/core/lib/transport/connectivity_state.h +4 -1
  351. data/src/core/lib/transport/mdstr_hash_table.c +118 -0
  352. data/src/core/lib/transport/mdstr_hash_table.h +77 -0
  353. data/src/core/lib/transport/metadata.c +83 -60
  354. data/src/core/lib/transport/metadata.h +41 -23
  355. data/src/core/lib/transport/metadata_batch.c +17 -11
  356. data/src/core/lib/transport/metadata_batch.h +20 -6
  357. data/src/core/lib/transport/pid_controller.c +57 -0
  358. data/src/core/lib/transport/pid_controller.h +64 -0
  359. data/src/core/lib/transport/service_config.c +251 -0
  360. data/src/core/lib/transport/service_config.h +71 -0
  361. data/src/core/lib/transport/static_metadata.c +18 -16
  362. data/src/core/lib/transport/static_metadata.h +113 -107
  363. data/src/core/{ext/transport/chttp2 → lib}/transport/timeout_encoding.c +3 -3
  364. data/src/core/{ext/transport/chttp2 → lib}/transport/timeout_encoding.h +7 -7
  365. data/src/core/lib/transport/transport.c +84 -23
  366. data/src/core/lib/transport/transport.h +53 -8
  367. data/src/core/lib/transport/transport_impl.h +3 -0
  368. data/src/core/lib/transport/transport_op_string.c +92 -20
  369. data/src/core/lib/tsi/ssl_transport_security.c +3 -1
  370. data/src/core/plugin_registry/grpc_plugin_registry.c +8 -4
  371. data/src/ruby/ext/grpc/extconf.rb +0 -1
  372. data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -7
  373. data/src/ruby/ext/grpc/rb_call.c +15 -5
  374. data/src/ruby/ext/grpc/rb_channel.c +1 -1
  375. data/src/ruby/ext/grpc/rb_compression_options.c +466 -0
  376. data/src/{core/ext/client_config/default_initial_connect_string.c → ruby/ext/grpc/rb_compression_options.h} +10 -5
  377. data/src/ruby/ext/grpc/rb_grpc.c +3 -1
  378. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +198 -190
  379. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +306 -294
  380. data/src/ruby/ext/grpc/rb_server.c +18 -12
  381. data/src/ruby/lib/grpc/errors.rb +154 -2
  382. data/src/ruby/lib/grpc/generic/active_call.rb +144 -63
  383. data/src/ruby/lib/grpc/generic/bidi_call.rb +18 -2
  384. data/src/ruby/lib/grpc/generic/client_stub.rb +7 -5
  385. data/src/ruby/lib/grpc/generic/rpc_desc.rb +39 -13
  386. data/src/ruby/lib/grpc/generic/rpc_server.rb +51 -24
  387. data/src/ruby/lib/grpc/generic/service.rb +3 -2
  388. data/src/ruby/lib/grpc/version.rb +1 -1
  389. data/src/ruby/pb/grpc/health/checker.rb +3 -1
  390. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +7 -0
  391. data/src/ruby/pb/test/client.rb +307 -7
  392. data/src/ruby/pb/test/server.rb +26 -1
  393. data/src/ruby/spec/compression_options_spec.rb +164 -0
  394. data/src/ruby/spec/error_sanity_spec.rb +64 -0
  395. data/src/ruby/spec/generic/active_call_spec.rb +290 -12
  396. data/src/ruby/spec/generic/client_stub_spec.rb +91 -41
  397. data/src/ruby/spec/generic/rpc_desc_spec.rb +36 -16
  398. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +22 -28
  399. data/src/ruby/spec/generic/rpc_server_spec.rb +6 -6
  400. data/src/ruby/spec/pb/health/checker_spec.rb +27 -19
  401. data/src/ruby/spec/spec_helper.rb +2 -0
  402. data/third_party/boringssl/crypto/aes/aes.c +12 -12
  403. data/third_party/boringssl/crypto/aes/mode_wrappers.c +6 -2
  404. data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +28 -13
  405. data/third_party/boringssl/crypto/asn1/a_gentm.c +2 -0
  406. data/third_party/boringssl/crypto/asn1/a_object.c +7 -3
  407. data/third_party/boringssl/crypto/asn1/a_strnid.c +1 -0
  408. data/third_party/boringssl/crypto/asn1/a_time.c +0 -11
  409. data/third_party/boringssl/crypto/asn1/a_type.c +0 -2
  410. data/third_party/boringssl/crypto/asn1/a_utctm.c +1 -30
  411. data/third_party/boringssl/crypto/asn1/asn1_lib.c +56 -76
  412. data/third_party/boringssl/crypto/asn1/asn1_locl.h +0 -10
  413. data/third_party/boringssl/crypto/asn1/asn1_par.c +0 -322
  414. data/third_party/boringssl/crypto/asn1/f_enum.c +1 -108
  415. data/third_party/boringssl/crypto/asn1/f_int.c +1 -106
  416. data/third_party/boringssl/crypto/asn1/f_string.c +1 -106
  417. data/third_party/boringssl/crypto/asn1/tasn_dec.c +10 -14
  418. data/third_party/boringssl/crypto/asn1/tasn_enc.c +17 -11
  419. data/third_party/boringssl/crypto/asn1/tasn_typ.c +29 -42
  420. data/third_party/boringssl/crypto/asn1/tasn_utl.c +1 -1
  421. data/third_party/boringssl/crypto/base64/base64.c +249 -285
  422. data/third_party/boringssl/crypto/bio/bio.c +13 -23
  423. data/third_party/boringssl/crypto/bio/bio_mem.c +3 -2
  424. data/third_party/boringssl/crypto/bio/connect.c +12 -3
  425. data/third_party/boringssl/crypto/bio/fd.c +22 -15
  426. data/third_party/boringssl/crypto/bio/file.c +2 -38
  427. data/third_party/boringssl/crypto/bio/hexdump.c +1 -2
  428. data/third_party/boringssl/crypto/bio/internal.h +3 -0
  429. data/third_party/boringssl/crypto/bio/pair.c +1 -1
  430. data/third_party/boringssl/crypto/bio/socket.c +10 -2
  431. data/third_party/boringssl/crypto/bio/socket_helper.c +2 -2
  432. data/third_party/boringssl/crypto/bn/asm/x86_64-gcc.c +0 -8
  433. data/third_party/boringssl/crypto/bn/bn.c +38 -0
  434. data/third_party/boringssl/crypto/bn/cmp.c +25 -0
  435. data/third_party/boringssl/crypto/bn/convert.c +73 -76
  436. data/third_party/boringssl/crypto/bn/div.c +136 -70
  437. data/third_party/boringssl/crypto/bn/exponentiation.c +86 -381
  438. data/third_party/boringssl/crypto/bn/gcd.c +213 -296
  439. data/third_party/boringssl/crypto/bn/generic.c +0 -80
  440. data/third_party/boringssl/crypto/bn/internal.h +15 -3
  441. data/third_party/boringssl/crypto/bn/montgomery.c +57 -207
  442. data/third_party/boringssl/crypto/bn/montgomery_inv.c +160 -0
  443. data/third_party/boringssl/crypto/bn/mul.c +2 -1
  444. data/third_party/boringssl/crypto/bn/prime.c +24 -8
  445. data/third_party/boringssl/crypto/bn/random.c +47 -33
  446. data/third_party/boringssl/crypto/bn/sqrt.c +4 -5
  447. data/third_party/boringssl/crypto/buf/buf.c +25 -21
  448. data/third_party/boringssl/crypto/bytestring/ber.c +1 -0
  449. data/third_party/boringssl/crypto/bytestring/cbb.c +50 -22
  450. data/third_party/boringssl/crypto/bytestring/cbs.c +28 -4
  451. data/third_party/boringssl/crypto/chacha/{chacha_generic.c → chacha.c} +56 -29
  452. data/third_party/boringssl/crypto/cipher/aead.c +11 -22
  453. data/third_party/boringssl/crypto/cipher/cipher.c +2 -2
  454. data/third_party/boringssl/crypto/cipher/e_aes.c +53 -103
  455. data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +2 -8
  456. data/third_party/boringssl/crypto/cipher/e_des.c +3 -5
  457. data/third_party/boringssl/crypto/cipher/e_null.c +1 -1
  458. data/third_party/boringssl/crypto/cipher/e_rc2.c +1 -1
  459. data/third_party/boringssl/crypto/cipher/e_rc4.c +1 -1
  460. data/third_party/boringssl/crypto/cipher/e_ssl3.c +3 -63
  461. data/third_party/boringssl/crypto/cipher/e_tls.c +12 -83
  462. data/third_party/boringssl/crypto/cipher/internal.h +8 -10
  463. data/third_party/boringssl/crypto/cipher/tls_cbc.c +69 -40
  464. data/third_party/boringssl/crypto/conf/conf.c +2 -1
  465. data/third_party/boringssl/crypto/cpu-aarch64-linux.c +61 -0
  466. data/third_party/boringssl/crypto/cpu-arm-linux.c +360 -0
  467. data/third_party/boringssl/crypto/cpu-arm.c +0 -161
  468. data/third_party/boringssl/crypto/cpu-intel.c +5 -3
  469. data/third_party/boringssl/{ssl/test/scoped_types.h → crypto/cpu-ppc64le.c} +21 -9
  470. data/third_party/boringssl/crypto/crypto.c +29 -7
  471. data/third_party/boringssl/crypto/curve25519/curve25519.c +284 -242
  472. data/third_party/boringssl/crypto/curve25519/internal.h +64 -0
  473. data/third_party/boringssl/crypto/curve25519/spake25519.c +464 -0
  474. data/third_party/boringssl/crypto/curve25519/x25519-x86_64.c +21 -0
  475. data/third_party/boringssl/crypto/dh/check.c +22 -6
  476. data/third_party/boringssl/crypto/dh/dh.c +45 -21
  477. data/third_party/boringssl/crypto/dh/dh_asn1.c +96 -20
  478. data/third_party/boringssl/crypto/dh/params.c +30 -78
  479. data/third_party/boringssl/crypto/digest/digest.c +3 -3
  480. data/third_party/boringssl/crypto/dsa/dsa.c +59 -29
  481. data/third_party/boringssl/crypto/dsa/dsa_asn1.c +4 -0
  482. data/third_party/boringssl/crypto/ec/ec.c +84 -140
  483. data/third_party/boringssl/crypto/ec/ec_asn1.c +82 -52
  484. data/third_party/boringssl/crypto/ec/ec_key.c +15 -15
  485. data/third_party/boringssl/crypto/ec/ec_montgomery.c +87 -50
  486. data/third_party/boringssl/crypto/ec/internal.h +12 -36
  487. data/third_party/boringssl/crypto/ec/oct.c +11 -11
  488. data/third_party/boringssl/crypto/ec/p224-64.c +59 -116
  489. data/third_party/boringssl/crypto/ec/p256-64.c +88 -163
  490. data/third_party/boringssl/crypto/ec/p256-x86_64.c +46 -58
  491. data/third_party/boringssl/crypto/ec/simple.c +81 -201
  492. data/third_party/boringssl/crypto/ec/util-64.c +0 -74
  493. data/third_party/boringssl/crypto/ecdh/ecdh.c +7 -1
  494. data/third_party/boringssl/crypto/ecdsa/ecdsa.c +28 -46
  495. data/third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c +1 -0
  496. data/third_party/boringssl/crypto/engine/engine.c +1 -1
  497. data/third_party/boringssl/crypto/err/err.c +3 -3
  498. data/third_party/boringssl/crypto/evp/evp.c +14 -59
  499. data/third_party/boringssl/crypto/evp/evp_asn1.c +144 -87
  500. data/third_party/boringssl/crypto/evp/evp_ctx.c +7 -7
  501. data/third_party/boringssl/crypto/evp/internal.h +4 -46
  502. data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +8 -157
  503. data/third_party/boringssl/crypto/evp/p_ec.c +1 -1
  504. data/third_party/boringssl/crypto/evp/p_ec_asn1.c +22 -170
  505. data/third_party/boringssl/crypto/evp/p_rsa.c +1 -1
  506. data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +10 -548
  507. data/third_party/boringssl/crypto/evp/print.c +520 -0
  508. data/third_party/boringssl/crypto/ex_data.c +4 -6
  509. data/third_party/boringssl/crypto/hkdf/hkdf.c +38 -17
  510. data/third_party/boringssl/crypto/hmac/hmac.c +6 -6
  511. data/third_party/boringssl/crypto/internal.h +57 -77
  512. data/third_party/boringssl/crypto/lhash/lhash.c +6 -10
  513. data/third_party/boringssl/crypto/md4/md4.c +9 -0
  514. data/third_party/boringssl/crypto/mem.c +19 -19
  515. data/third_party/boringssl/crypto/modes/cfb.c +5 -6
  516. data/third_party/boringssl/crypto/modes/ctr.c +10 -18
  517. data/third_party/boringssl/crypto/modes/gcm.c +100 -66
  518. data/third_party/boringssl/crypto/modes/internal.h +15 -27
  519. data/third_party/boringssl/crypto/modes/ofb.c +9 -22
  520. data/third_party/boringssl/crypto/newhope/error_correction.c +131 -0
  521. data/third_party/boringssl/crypto/newhope/internal.h +71 -0
  522. data/third_party/boringssl/crypto/newhope/newhope.c +174 -0
  523. data/third_party/boringssl/crypto/newhope/ntt.c +148 -0
  524. data/third_party/boringssl/crypto/newhope/poly.c +183 -0
  525. data/third_party/boringssl/crypto/newhope/precomp.c +306 -0
  526. data/third_party/boringssl/crypto/newhope/reduce.c +42 -0
  527. data/third_party/boringssl/crypto/obj/obj.c +111 -135
  528. data/third_party/boringssl/crypto/obj/obj_dat.h +4 -10
  529. data/third_party/boringssl/crypto/pem/pem_lib.c +6 -43
  530. data/third_party/boringssl/crypto/pem/pem_pkey.c +10 -19
  531. data/third_party/boringssl/crypto/pkcs8/p5_pbe.c +1 -0
  532. data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +2 -1
  533. data/third_party/boringssl/crypto/pkcs8/p8_pkey.c +2 -2
  534. data/third_party/boringssl/crypto/pkcs8/pkcs8.c +95 -87
  535. data/third_party/boringssl/crypto/{test/test_util.h → poly1305/internal.h} +15 -10
  536. data/third_party/boringssl/crypto/poly1305/poly1305.c +8 -15
  537. data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +1 -0
  538. data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +3 -3
  539. data/third_party/boringssl/crypto/rand/deterministic.c +47 -0
  540. data/third_party/boringssl/crypto/rand/rand.c +4 -1
  541. data/third_party/boringssl/crypto/rand/urandom.c +5 -7
  542. data/third_party/boringssl/crypto/rand/windows.c +5 -8
  543. data/third_party/boringssl/crypto/rc4/rc4.c +24 -209
  544. data/third_party/boringssl/crypto/refcount_lock.c +2 -2
  545. data/third_party/boringssl/crypto/rsa/blinding.c +74 -232
  546. data/third_party/boringssl/crypto/rsa/internal.h +5 -13
  547. data/third_party/boringssl/crypto/rsa/padding.c +64 -63
  548. data/third_party/boringssl/crypto/rsa/rsa.c +50 -28
  549. data/third_party/boringssl/crypto/rsa/rsa_asn1.c +8 -16
  550. data/third_party/boringssl/crypto/rsa/rsa_impl.c +134 -122
  551. data/third_party/boringssl/crypto/sha/sha256.c +2 -2
  552. data/third_party/boringssl/crypto/sha/sha512.c +7 -7
  553. data/third_party/boringssl/crypto/stack/stack.c +13 -22
  554. data/third_party/boringssl/crypto/thread.c +21 -12
  555. data/third_party/boringssl/crypto/thread_none.c +6 -2
  556. data/third_party/boringssl/crypto/thread_pthread.c +16 -7
  557. data/third_party/boringssl/crypto/thread_win.c +38 -85
  558. data/third_party/boringssl/crypto/x509/a_sign.c +3 -3
  559. data/third_party/boringssl/crypto/x509/a_strex.c +1 -1
  560. data/third_party/boringssl/crypto/x509/a_verify.c +2 -2
  561. data/third_party/boringssl/crypto/{evp → x509}/algorithm.c +37 -53
  562. data/third_party/boringssl/crypto/x509/asn1_gen.c +1 -2
  563. data/third_party/boringssl/crypto/x509/by_dir.c +6 -6
  564. data/third_party/boringssl/crypto/x509/internal.h +66 -0
  565. data/third_party/boringssl/crypto/x509/rsa_pss.c +385 -0
  566. data/third_party/boringssl/crypto/x509/t_x509.c +10 -12
  567. data/third_party/boringssl/crypto/x509/x509.c +5 -0
  568. data/third_party/boringssl/crypto/x509/x509_att.c +9 -3
  569. data/third_party/boringssl/crypto/x509/x509_lu.c +34 -44
  570. data/third_party/boringssl/crypto/x509/x509_obj.c +19 -2
  571. data/third_party/boringssl/crypto/x509/x509_r2x.c +9 -5
  572. data/third_party/boringssl/crypto/x509/x509_set.c +5 -0
  573. data/third_party/boringssl/crypto/x509/x509_txt.c +5 -0
  574. data/third_party/boringssl/crypto/x509/x509_vfy.c +63 -32
  575. data/third_party/boringssl/crypto/x509/x509_vpm.c +29 -18
  576. data/third_party/boringssl/crypto/x509/x509cset.c +2 -1
  577. data/third_party/boringssl/crypto/x509/x_crl.c +2 -2
  578. data/third_party/boringssl/crypto/x509/x_name.c +14 -17
  579. data/third_party/boringssl/crypto/x509/x_pubkey.c +10 -7
  580. data/third_party/boringssl/crypto/x509/x_x509.c +67 -6
  581. data/third_party/boringssl/crypto/x509v3/pcy_cache.c +2 -2
  582. data/third_party/boringssl/crypto/x509v3/pcy_tree.c +2 -1
  583. data/third_party/boringssl/crypto/x509v3/v3_conf.c +4 -3
  584. data/third_party/boringssl/crypto/x509v3/v3_cpols.c +5 -0
  585. data/third_party/boringssl/crypto/x509v3/v3_prn.c +0 -3
  586. data/third_party/boringssl/crypto/x509v3/v3_purp.c +2 -2
  587. data/third_party/boringssl/crypto/x509v3/v3_utl.c +2 -1
  588. data/third_party/boringssl/include/openssl/aead.h +72 -73
  589. data/third_party/boringssl/include/openssl/arm_arch.h +0 -6
  590. data/third_party/boringssl/include/openssl/asn1.h +103 -235
  591. data/third_party/boringssl/include/openssl/asn1_mac.h +17 -74
  592. data/third_party/boringssl/include/openssl/asn1t.h +1 -11
  593. data/third_party/boringssl/include/openssl/base.h +145 -3
  594. data/third_party/boringssl/include/openssl/base64.h +20 -17
  595. data/third_party/boringssl/include/openssl/bio.h +59 -34
  596. data/third_party/boringssl/include/openssl/bn.h +118 -51
  597. data/third_party/boringssl/include/openssl/buf.h +15 -0
  598. data/third_party/boringssl/include/openssl/bytestring.h +52 -4
  599. data/third_party/boringssl/include/openssl/chacha.h +2 -2
  600. data/third_party/boringssl/include/openssl/cipher.h +18 -1
  601. data/third_party/boringssl/include/openssl/cmac.h +11 -0
  602. data/third_party/boringssl/include/openssl/conf.h +13 -2
  603. data/third_party/boringssl/include/openssl/cpu.h +20 -23
  604. data/third_party/boringssl/include/openssl/crypto.h +22 -1
  605. data/third_party/boringssl/include/openssl/curve25519.h +96 -4
  606. data/third_party/boringssl/include/openssl/dh.h +71 -16
  607. data/third_party/boringssl/include/openssl/digest.h +38 -11
  608. data/third_party/boringssl/include/openssl/dsa.h +40 -4
  609. data/third_party/boringssl/include/openssl/ec.h +44 -18
  610. data/third_party/boringssl/include/openssl/ec_key.h +27 -6
  611. data/third_party/boringssl/include/openssl/ecdsa.h +11 -0
  612. data/third_party/boringssl/include/openssl/engine.h +11 -0
  613. data/third_party/boringssl/include/openssl/evp.h +52 -88
  614. data/third_party/boringssl/include/openssl/hkdf.h +24 -4
  615. data/third_party/boringssl/include/openssl/hmac.h +20 -6
  616. data/third_party/boringssl/include/openssl/md4.h +4 -0
  617. data/third_party/boringssl/include/openssl/mem.h +19 -0
  618. data/third_party/boringssl/include/openssl/newhope.h +158 -0
  619. data/third_party/boringssl/include/openssl/nid.h +4166 -0
  620. data/third_party/boringssl/include/openssl/obj.h +31 -3
  621. data/third_party/boringssl/include/openssl/obj_mac.h +17 -4143
  622. data/third_party/boringssl/include/openssl/{opensslfeatures.h → opensslconf.h} +3 -3
  623. data/third_party/boringssl/include/openssl/pem.h +5 -0
  624. data/third_party/boringssl/include/openssl/pkcs8.h +12 -0
  625. data/third_party/boringssl/include/openssl/rand.h +6 -0
  626. data/third_party/boringssl/include/openssl/rc4.h +6 -0
  627. data/third_party/boringssl/{crypto/dh/internal.h → include/openssl/ripemd.h} +38 -11
  628. data/third_party/boringssl/include/openssl/rsa.h +127 -65
  629. data/third_party/boringssl/include/openssl/sha.h +14 -10
  630. data/third_party/boringssl/include/openssl/ssl.h +561 -275
  631. data/third_party/boringssl/include/openssl/ssl3.h +18 -25
  632. data/third_party/boringssl/include/openssl/stack.h +2 -4
  633. data/third_party/boringssl/include/openssl/stack_macros.h +321 -353
  634. data/third_party/boringssl/include/openssl/thread.h +31 -13
  635. data/third_party/boringssl/include/openssl/time_support.h +1 -0
  636. data/third_party/boringssl/include/openssl/tls1.h +37 -33
  637. data/third_party/boringssl/include/openssl/x509.h +69 -26
  638. data/third_party/boringssl/include/openssl/x509_vfy.h +12 -10
  639. data/third_party/boringssl/include/openssl/x509v3.h +23 -2
  640. data/third_party/boringssl/ssl/custom_extensions.c +3 -5
  641. data/third_party/boringssl/ssl/d1_both.c +463 -499
  642. data/third_party/boringssl/ssl/d1_lib.c +38 -109
  643. data/third_party/boringssl/ssl/d1_pkt.c +173 -334
  644. data/third_party/boringssl/ssl/d1_srtp.c +20 -18
  645. data/third_party/boringssl/ssl/{d1_meth.c → dtls_method.c} +88 -15
  646. data/third_party/boringssl/ssl/dtls_record.c +27 -26
  647. data/third_party/boringssl/ssl/{s3_clnt.c → handshake_client.c} +816 -904
  648. data/third_party/boringssl/ssl/handshake_server.c +1932 -0
  649. data/third_party/boringssl/ssl/internal.h +712 -439
  650. data/third_party/boringssl/ssl/s3_both.c +445 -257
  651. data/third_party/boringssl/ssl/s3_enc.c +53 -36
  652. data/third_party/boringssl/ssl/s3_lib.c +23 -268
  653. data/third_party/boringssl/ssl/s3_pkt.c +168 -364
  654. data/third_party/boringssl/ssl/ssl_aead_ctx.c +46 -17
  655. data/third_party/boringssl/ssl/ssl_asn1.c +56 -26
  656. data/third_party/boringssl/ssl/ssl_buffer.c +16 -24
  657. data/third_party/boringssl/ssl/ssl_cert.c +324 -49
  658. data/third_party/boringssl/ssl/ssl_cipher.c +205 -150
  659. data/third_party/boringssl/ssl/ssl_ecdh.c +287 -51
  660. data/third_party/boringssl/ssl/ssl_file.c +21 -68
  661. data/third_party/boringssl/ssl/ssl_lib.c +881 -510
  662. data/third_party/boringssl/ssl/ssl_rsa.c +404 -34
  663. data/third_party/boringssl/ssl/ssl_session.c +324 -103
  664. data/third_party/boringssl/ssl/ssl_stat.c +6 -88
  665. data/third_party/boringssl/ssl/t1_enc.c +23 -39
  666. data/third_party/boringssl/ssl/t1_lib.c +1120 -622
  667. data/third_party/boringssl/ssl/tls13_both.c +440 -0
  668. data/third_party/boringssl/ssl/tls13_client.c +682 -0
  669. data/third_party/boringssl/ssl/tls13_enc.c +391 -0
  670. data/third_party/boringssl/ssl/tls13_server.c +672 -0
  671. data/third_party/boringssl/ssl/{s3_meth.c → tls_method.c} +100 -21
  672. data/third_party/boringssl/ssl/tls_record.c +159 -77
  673. data/third_party/nanopb/pb.h +60 -28
  674. data/third_party/nanopb/pb_decode.c +120 -92
  675. data/third_party/nanopb/pb_decode.h +3 -3
  676. data/third_party/nanopb/pb_encode.c +73 -67
  677. data/third_party/nanopb/pb_encode.h +4 -4
  678. metadata +155 -89
  679. data/include/grpc/impl/codegen/byte_buffer.h +0 -122
  680. data/include/grpc/impl/codegen/log.h +0 -118
  681. data/include/grpc/impl/codegen/time.h +0 -130
  682. data/src/core/ext/client_config/client_channel.c +0 -593
  683. data/src/core/ext/client_config/subchannel_call_holder.c +0 -272
  684. data/src/core/ext/client_config/subchannel_call_holder.h +0 -99
  685. data/src/core/lib/iomgr/ev_poll_and_epoll_posix.c +0 -2046
  686. data/src/core/lib/iomgr/workqueue_posix.c +0 -151
  687. data/src/core/lib/security/transport/handshake.c +0 -368
  688. data/third_party/boringssl/crypto/asn1/a_bytes.c +0 -308
  689. data/third_party/boringssl/crypto/asn1/bio_asn1.c +0 -477
  690. data/third_party/boringssl/crypto/asn1/bio_ndef.c +0 -251
  691. data/third_party/boringssl/crypto/asn1/t_pkey.c +0 -110
  692. data/third_party/boringssl/crypto/asn1/tasn_prn.c +0 -596
  693. data/third_party/boringssl/crypto/chacha/chacha_vec.c +0 -328
  694. data/third_party/boringssl/crypto/directory.h +0 -66
  695. data/third_party/boringssl/crypto/directory_posix.c +0 -108
  696. data/third_party/boringssl/crypto/directory_win.c +0 -144
  697. data/third_party/boringssl/crypto/test/scoped_types.h +0 -140
  698. data/third_party/boringssl/include/openssl/pqueue.h +0 -146
  699. data/third_party/boringssl/ssl/d1_clnt.c +0 -561
  700. data/third_party/boringssl/ssl/d1_srvr.c +0 -476
  701. data/third_party/boringssl/ssl/pqueue/pqueue.c +0 -197
  702. data/third_party/boringssl/ssl/s3_srvr.c +0 -2272
  703. data/third_party/boringssl/ssl/test/async_bio.h +0 -45
  704. data/third_party/boringssl/ssl/test/packeted_bio.h +0 -44
  705. data/third_party/boringssl/ssl/test/test_config.h +0 -110
@@ -145,19 +145,23 @@
145
145
  #include <openssl/base.h>
146
146
 
147
147
  #include <openssl/aead.h>
148
- #include <openssl/pqueue.h>
149
148
  #include <openssl/ssl.h>
150
149
  #include <openssl/stack.h>
151
150
 
151
+
152
152
  #if defined(OPENSSL_WINDOWS)
153
153
  /* Windows defines struct timeval in winsock2.h. */
154
- #pragma warning(push, 3)
154
+ OPENSSL_MSVC_PRAGMA(warning(push, 3))
155
155
  #include <winsock2.h>
156
- #pragma warning(pop)
156
+ OPENSSL_MSVC_PRAGMA(warning(pop))
157
157
  #else
158
158
  #include <sys/time.h>
159
159
  #endif
160
160
 
161
+ #if defined(__cplusplus)
162
+ extern "C" {
163
+ #endif
164
+
161
165
 
162
166
  /* Cipher suites. */
163
167
 
@@ -167,6 +171,7 @@
167
171
  #define SSL_kECDHE 0x00000004L
168
172
  /* SSL_kPSK is only set for plain PSK, not ECDHE_PSK. */
169
173
  #define SSL_kPSK 0x00000008L
174
+ #define SSL_kCECPQ1 0x00000010L
170
175
 
171
176
  /* Bits for |algorithm_auth| (server authentication). */
172
177
  #define SSL_aRSA 0x00000001L
@@ -174,16 +179,17 @@
174
179
  /* SSL_aPSK is set for both PSK and ECDHE_PSK. */
175
180
  #define SSL_aPSK 0x00000004L
176
181
 
182
+ #define SSL_aCERT (SSL_aRSA | SSL_aECDSA)
183
+
177
184
  /* Bits for |algorithm_enc| (symmetric encryption). */
178
- #define SSL_3DES 0x00000001L
179
- #define SSL_RC4 0x00000002L
180
- #define SSL_AES128 0x00000004L
181
- #define SSL_AES256 0x00000008L
182
- #define SSL_AES128GCM 0x00000010L
183
- #define SSL_AES256GCM 0x00000020L
184
- #define SSL_CHACHA20POLY1305_OLD 0x00000040L
185
- #define SSL_eNULL 0x00000080L
186
- #define SSL_CHACHA20POLY1305 0x00000100L
185
+ #define SSL_3DES 0x00000001L
186
+ #define SSL_AES128 0x00000002L
187
+ #define SSL_AES256 0x00000004L
188
+ #define SSL_AES128GCM 0x00000008L
189
+ #define SSL_AES256GCM 0x00000010L
190
+ #define SSL_CHACHA20POLY1305_OLD 0x00000020L
191
+ #define SSL_eNULL 0x00000040L
192
+ #define SSL_CHACHA20POLY1305 0x00000080L
187
193
 
188
194
  #define SSL_AES (SSL_AES128 | SSL_AES256 | SSL_AES128GCM | SSL_AES256GCM)
189
195
 
@@ -235,21 +241,25 @@ ssl_create_cipher_list(const SSL_PROTOCOL_METHOD *ssl_method,
235
241
  /* ssl_cipher_get_value returns the cipher suite id of |cipher|. */
236
242
  uint16_t ssl_cipher_get_value(const SSL_CIPHER *cipher);
237
243
 
244
+ /* ssl_cipher_get_resumption_cipher returns the cipher suite id of the cipher
245
+ * matching |cipher| with PSK enabled. */
246
+ int ssl_cipher_get_ecdhe_psk_cipher(const SSL_CIPHER *cipher,
247
+ uint16_t *out_cipher);
248
+
238
249
  /* ssl_cipher_get_key_type returns the |EVP_PKEY_*| value corresponding to the
239
250
  * server key used in |cipher| or |EVP_PKEY_NONE| if there is none. */
240
251
  int ssl_cipher_get_key_type(const SSL_CIPHER *cipher);
241
252
 
242
- /* ssl_cipher_has_server_public_key returns 1 if |cipher| involves a server
243
- * public key in the key exchange, sent in a server Certificate message.
244
- * Otherwise it returns 0. */
245
- int ssl_cipher_has_server_public_key(const SSL_CIPHER *cipher);
253
+ /* ssl_cipher_uses_certificate_auth returns one if |cipher| authenticates the
254
+ * server and, optionally, the client with a certificate. Otherwise it returns
255
+ * zero. */
256
+ int ssl_cipher_uses_certificate_auth(const SSL_CIPHER *cipher);
246
257
 
247
258
  /* ssl_cipher_requires_server_key_exchange returns 1 if |cipher| requires a
248
259
  * ServerKeyExchange message. Otherwise it returns 0.
249
260
  *
250
- * Unlike |ssl_cipher_has_server_public_key|, this function may return zero
251
- * while still allowing |cipher| an optional ServerKeyExchange. This is the
252
- * case for plain PSK ciphers. */
261
+ * This function may return zero while still allowing |cipher| an optional
262
+ * ServerKeyExchange. This is the case for plain PSK ciphers. */
253
263
  int ssl_cipher_requires_server_key_exchange(const SSL_CIPHER *cipher);
254
264
 
255
265
  /* ssl_cipher_get_record_split_len, for TLS 1.0 CBC mode ciphers, returns the
@@ -282,6 +292,8 @@ struct ssl_aead_ctx_st {
282
292
  /* omit_version_in_ad is non-zero if the version should be omitted
283
293
  * in the AEAD's ad parameter. */
284
294
  char omit_version_in_ad;
295
+ /* omit_ad is non-zero if the AEAD's ad parameter should be omitted. */
296
+ char omit_ad;
285
297
  /* xor_fixed_nonce is non-zero if the fixed nonce should be XOR'd into the
286
298
  * variable nonce rather than prepended. */
287
299
  char xor_fixed_nonce;
@@ -309,21 +321,19 @@ size_t SSL_AEAD_CTX_explicit_nonce_len(SSL_AEAD_CTX *ctx);
309
321
  * |SSL_AEAD_CTX_seal|. |ctx| may be NULL to denote the null cipher. */
310
322
  size_t SSL_AEAD_CTX_max_overhead(SSL_AEAD_CTX *ctx);
311
323
 
312
- /* SSL_AEAD_CTX_open authenticates and decrypts |in_len| bytes from |in| and
313
- * writes the result to |out|. It returns one on success and zero on
314
- * error. |ctx| may be NULL to denote the null cipher.
315
- *
316
- * If |in| and |out| alias then |out| must be <= |in| + |explicit_nonce_len|. */
317
- int SSL_AEAD_CTX_open(SSL_AEAD_CTX *ctx, uint8_t *out, size_t *out_len,
318
- size_t max_out, uint8_t type, uint16_t wire_version,
319
- const uint8_t seqnum[8], const uint8_t *in,
320
- size_t in_len);
324
+ /* SSL_AEAD_CTX_open authenticates and decrypts |in_len| bytes from |in|
325
+ * in-place. On success, it sets |*out| to the plaintext in |in| and returns
326
+ * one. Otherwise, it returns zero. |ctx| may be NULL to denote the null cipher.
327
+ * The output will always be |explicit_nonce_len| bytes ahead of |in|. */
328
+ int SSL_AEAD_CTX_open(SSL_AEAD_CTX *ctx, CBS *out, uint8_t type,
329
+ uint16_t wire_version, const uint8_t seqnum[8],
330
+ uint8_t *in, size_t in_len);
321
331
 
322
332
  /* SSL_AEAD_CTX_seal encrypts and authenticates |in_len| bytes from |in| and
323
333
  * writes the result to |out|. It returns one on success and zero on
324
334
  * error. |ctx| may be NULL to denote the null cipher.
325
335
  *
326
- * If |in| and |out| alias then |out| + |explicit_nonce_len| must be <= |in| */
336
+ * If |in| and |out| alias then |out| + |explicit_nonce_len| must be == |in|. */
327
337
  int SSL_AEAD_CTX_seal(SSL_AEAD_CTX *ctx, uint8_t *out, size_t *out_len,
328
338
  size_t max_out, uint8_t type, uint16_t wire_version,
329
339
  const uint8_t seqnum[8], const uint8_t *in,
@@ -361,52 +371,60 @@ enum ssl_open_record_t {
361
371
  ssl_open_record_success,
362
372
  ssl_open_record_discard,
363
373
  ssl_open_record_partial,
374
+ ssl_open_record_close_notify,
375
+ ssl_open_record_fatal_alert,
364
376
  ssl_open_record_error,
365
377
  };
366
378
 
367
- /* tls_open_record decrypts a record from |in|.
368
- *
369
- * On success, it returns |ssl_open_record_success|. It sets |*out_type| to the
370
- * record type, |*out_len| to the plaintext length, and writes the record body
371
- * to |out|. It sets |*out_consumed| to the number of bytes of |in| consumed.
372
- * Note that |*out_len| may be zero.
373
- *
374
- * If a record was successfully processed but should be discarded, it returns
375
- * |ssl_open_record_discard| and sets |*out_consumed| to the number of bytes
376
- * consumed.
379
+ /* tls_open_record decrypts a record from |in| in-place.
377
380
  *
378
381
  * If the input did not contain a complete record, it returns
379
382
  * |ssl_open_record_partial|. It sets |*out_consumed| to the total number of
380
383
  * bytes necessary. It is guaranteed that a successful call to |tls_open_record|
381
384
  * will consume at least that many bytes.
382
385
  *
383
- * On failure, it returns |ssl_open_record_error| and sets |*out_alert| to an
384
- * alert to emit.
386
+ * Otherwise, it sets |*out_consumed| to the number of bytes of input
387
+ * consumed. Note that input may be consumed on all return codes if a record was
388
+ * decrypted.
389
+ *
390
+ * On success, it returns |ssl_open_record_success|. It sets |*out_type| to the
391
+ * record type and |*out| to the record body in |in|. Note that |*out| may be
392
+ * empty.
393
+ *
394
+ * If a record was successfully processed but should be discarded, it returns
395
+ * |ssl_open_record_discard|.
385
396
  *
386
- * If |in| and |out| alias, |out| must be <= |in| + |ssl_record_prefix_len|. */
387
- enum ssl_open_record_t tls_open_record(
388
- SSL *ssl, uint8_t *out_type, uint8_t *out, size_t *out_len,
389
- size_t *out_consumed, uint8_t *out_alert, size_t max_out, const uint8_t *in,
390
- size_t in_len);
397
+ * If a record was successfully processed but is a close_notify or fatal alert,
398
+ * it returns |ssl_open_record_close_notify| or |ssl_open_record_fatal_alert|.
399
+ *
400
+ * On failure, it returns |ssl_open_record_error| and sets |*out_alert| to an
401
+ * alert to emit. */
402
+ enum ssl_open_record_t tls_open_record(SSL *ssl, uint8_t *out_type, CBS *out,
403
+ size_t *out_consumed, uint8_t *out_alert,
404
+ uint8_t *in, size_t in_len);
391
405
 
392
406
  /* dtls_open_record implements |tls_open_record| for DTLS. It never returns
393
407
  * |ssl_open_record_partial| but otherwise behaves analogously. */
394
- enum ssl_open_record_t dtls_open_record(
395
- SSL *ssl, uint8_t *out_type, uint8_t *out, size_t *out_len,
396
- size_t *out_consumed, uint8_t *out_alert, size_t max_out, const uint8_t *in,
397
- size_t in_len);
398
-
399
- /* ssl_seal_prefix_len returns the length of the prefix before the ciphertext
400
- * when sealing a record with |ssl|. Note that this value may differ from
401
- * |ssl_record_prefix_len| when TLS 1.0 CBC record-splitting is enabled. Sealing
402
- * a small record may also result in a smaller output than this value.
408
+ enum ssl_open_record_t dtls_open_record(SSL *ssl, uint8_t *out_type, CBS *out,
409
+ size_t *out_consumed,
410
+ uint8_t *out_alert, uint8_t *in,
411
+ size_t in_len);
412
+
413
+ /* ssl_seal_align_prefix_len returns the length of the prefix before the start
414
+ * of the bulk of the ciphertext when sealing a record with |ssl|. Callers may
415
+ * use this to align buffers.
416
+ *
417
+ * Note when TLS 1.0 CBC record-splitting is enabled, this includes the one byte
418
+ * record and is the offset into second record's ciphertext. Thus this value may
419
+ * differ from |ssl_record_prefix_len| and sealing a small record may result in
420
+ * a smaller output than this value.
403
421
  *
404
422
  * TODO(davidben): Expose this as part of public API once the high-level
405
423
  * buffer-free APIs are available. */
406
- size_t ssl_seal_prefix_len(const SSL *ssl);
424
+ size_t ssl_seal_align_prefix_len(const SSL *ssl);
407
425
 
408
426
  /* ssl_max_seal_overhead returns the maximum overhead of sealing a record with
409
- * |ssl|. This includes |ssl_seal_prefix_len|.
427
+ * |ssl|.
410
428
  *
411
429
  * TODO(davidben): Expose this as part of public API once the high-level
412
430
  * buffer-free APIs are available. */
@@ -417,11 +435,12 @@ size_t ssl_max_seal_overhead(const SSL *ssl);
417
435
  * and zero on error. If enabled, |tls_seal_record| implements TLS 1.0 CBC 1/n-1
418
436
  * record splitting and may write two records concatenated.
419
437
  *
420
- * For a large record, the ciphertext will begin |ssl_seal_prefix_len| bytes
421
- * into out. Aligning |out| appropriately may improve performance. It writes at
422
- * most |in_len| + |ssl_max_seal_overhead| bytes to |out|.
438
+ * For a large record, the bulk of the ciphertext will begin
439
+ * |ssl_seal_align_prefix_len| bytes into out. Aligning |out| appropriately may
440
+ * improve performance. It writes at most |in_len| + |ssl_max_seal_overhead|
441
+ * bytes to |out|.
423
442
  *
424
- * If |in| and |out| alias, |out| + |ssl_seal_prefix_len| must be <= |in|. */
443
+ * |in| and |out| may not alias. */
425
444
  int tls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
426
445
  uint8_t type, const uint8_t *in, size_t in_len);
427
446
 
@@ -436,20 +455,23 @@ int dtls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
436
455
  uint8_t type, const uint8_t *in, size_t in_len,
437
456
  enum dtls1_use_epoch_t use_epoch);
438
457
 
439
- /* ssl_set_read_state sets |ssl|'s read cipher state to |aead_ctx|. It takes
440
- * ownership of |aead_ctx|. */
441
- void ssl_set_read_state(SSL *ssl, SSL_AEAD_CTX *aead_ctx);
442
-
443
- /* ssl_set_write_state sets |ssl|'s write cipher state to |aead_ctx|. It takes
444
- * ownership of |aead_ctx|. */
445
- void ssl_set_write_state(SSL *ssl, SSL_AEAD_CTX *aead_ctx);
458
+ /* ssl_process_alert processes |in| as an alert and updates |ssl|'s shutdown
459
+ * state. It returns one of |ssl_open_record_discard|, |ssl_open_record_error|,
460
+ * |ssl_open_record_close_notify|, or |ssl_open_record_fatal_alert| as
461
+ * appropriate. */
462
+ enum ssl_open_record_t ssl_process_alert(SSL *ssl, uint8_t *out_alert,
463
+ const uint8_t *in, size_t in_len);
446
464
 
447
465
 
448
466
  /* Private key operations. */
449
467
 
450
468
  /* ssl_has_private_key returns one if |ssl| has a private key
451
469
  * configured and zero otherwise. */
452
- int ssl_has_private_key(SSL *ssl);
470
+ int ssl_has_private_key(const SSL *ssl);
471
+
472
+ /* ssl_is_ecdsa_key_type returns one if |type| is an ECDSA key type and zero
473
+ * otherwise. */
474
+ int ssl_is_ecdsa_key_type(int type);
453
475
 
454
476
  /* ssl_private_key_* call the corresponding function on the
455
477
  * |SSL_PRIVATE_KEY_METHOD| for |ssl|, if configured. Otherwise, they implement
@@ -460,18 +482,28 @@ int ssl_private_key_type(SSL *ssl);
460
482
  size_t ssl_private_key_max_signature_len(SSL *ssl);
461
483
 
462
484
  enum ssl_private_key_result_t ssl_private_key_sign(
463
- SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out, const EVP_MD *md,
464
- const uint8_t *in, size_t in_len);
465
-
466
- enum ssl_private_key_result_t ssl_private_key_sign_complete(
467
- SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out);
485
+ SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
486
+ uint16_t signature_algorithm, const uint8_t *in, size_t in_len);
468
487
 
469
488
  enum ssl_private_key_result_t ssl_private_key_decrypt(
470
489
  SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
471
490
  const uint8_t *in, size_t in_len);
472
491
 
473
- enum ssl_private_key_result_t ssl_private_key_decrypt_complete(
474
- SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out);
492
+ enum ssl_private_key_result_t ssl_private_key_complete(SSL *ssl, uint8_t *out,
493
+ size_t *out_len,
494
+ size_t max_out);
495
+
496
+ /* ssl_private_key_supports_signature_algorithm returns one if |ssl|'s private
497
+ * key supports |signature_algorithm| and zero otherwise. */
498
+ int ssl_private_key_supports_signature_algorithm(SSL *ssl,
499
+ uint16_t signature_algorithm);
500
+
501
+ /* ssl_public_key_verify verifies that the |signature| is valid for the public
502
+ * key |pkey| and input |in|, using the |signature_algorithm| specified. */
503
+ int ssl_public_key_verify(
504
+ SSL *ssl, const uint8_t *signature, size_t signature_len,
505
+ uint16_t signature_algorithm, EVP_PKEY *pkey,
506
+ const uint8_t *in, size_t in_len);
475
507
 
476
508
 
477
509
  /* Custom extensions */
@@ -526,60 +558,133 @@ void ssl3_free_handshake_hash(SSL *ssl);
526
558
  int ssl3_update_handshake_hash(SSL *ssl, const uint8_t *in, size_t in_len);
527
559
 
528
560
 
529
- /* ECDH curves. */
530
-
531
- #define SSL_CURVE_SECP256R1 23
532
- #define SSL_CURVE_SECP384R1 24
533
- #define SSL_CURVE_SECP521R1 25
534
- #define SSL_CURVE_X25519 29
561
+ /* ECDH groups. */
535
562
 
536
563
  /* An SSL_ECDH_METHOD is an implementation of ECDH-like key exchanges for
537
564
  * TLS. */
538
565
  struct ssl_ecdh_method_st {
539
566
  int nid;
540
- uint16_t curve_id;
567
+ uint16_t group_id;
541
568
  const char name[8];
542
569
 
543
570
  /* cleanup releases state in |ctx|. */
544
571
  void (*cleanup)(SSL_ECDH_CTX *ctx);
545
572
 
546
- /* generate_keypair generates a keypair and writes the public value to
573
+ /* offer generates a keypair and writes the public value to
547
574
  * |out_public_key|. It returns one on success and zero on error. */
548
- int (*generate_keypair)(SSL_ECDH_CTX *ctx, CBB *out_public_key);
549
-
550
- /* compute_secret performs a key exchange against |peer_key| and, on
551
- * success, returns one and sets |*out_secret| and |*out_secret_len| to
552
- * a newly-allocated buffer containing the shared secret. The caller must
553
- * release this buffer with |OPENSSL_free|. Otherwise, it returns zero and
554
- * sets |*out_alert| to an alert to send to the peer. */
555
- int (*compute_secret)(SSL_ECDH_CTX *ctx, uint8_t **out_secret,
556
- size_t *out_secret_len, uint8_t *out_alert,
557
- const uint8_t *peer_key, size_t peer_key_len);
575
+ int (*offer)(SSL_ECDH_CTX *ctx, CBB *out_public_key);
576
+
577
+ /* accept performs a key exchange against the |peer_key| generated by |offer|.
578
+ * On success, it returns one, writes the public value to |out_public_key|,
579
+ * and sets |*out_secret| and |*out_secret_len| to a newly-allocated buffer
580
+ * containing the shared secret. The caller must release this buffer with
581
+ * |OPENSSL_free|. On failure, it returns zero and sets |*out_alert| to an
582
+ * alert to send to the peer. */
583
+ int (*accept)(SSL_ECDH_CTX *ctx, CBB *out_public_key, uint8_t **out_secret,
584
+ size_t *out_secret_len, uint8_t *out_alert,
585
+ const uint8_t *peer_key, size_t peer_key_len);
586
+
587
+ /* finish performs a key exchange against the |peer_key| generated by
588
+ * |accept|. On success, it returns one and sets |*out_secret| and
589
+ * |*out_secret_len| to a newly-allocated buffer containing the shared
590
+ * secret. The caller must release this buffer with |OPENSSL_free|. On
591
+ * failure, it returns zero and sets |*out_alert| to an alert to send to the
592
+ * peer. */
593
+ int (*finish)(SSL_ECDH_CTX *ctx, uint8_t **out_secret, size_t *out_secret_len,
594
+ uint8_t *out_alert, const uint8_t *peer_key,
595
+ size_t peer_key_len);
596
+
597
+ /* get_key initializes |out| with a length-prefixed key from |cbs|. It returns
598
+ * one on success and zero on error. */
599
+ int (*get_key)(CBS *cbs, CBS *out);
600
+
601
+ /* add_key initializes |out_contents| to receive a key. Typically it will then
602
+ * be passed to |offer| or |accept|. It returns one on success and zero on
603
+ * error. */
604
+ int (*add_key)(CBB *cbb, CBB *out_contents);
558
605
  } /* SSL_ECDH_METHOD */;
559
606
 
560
- /* ssl_nid_to_curve_id looks up the curve corresponding to |nid|. On success, it
561
- * sets |*out_curve_id| to the curve ID and returns one. Otherwise, it returns
607
+ /* ssl_nid_to_group_id looks up the group corresponding to |nid|. On success, it
608
+ * sets |*out_group_id| to the group ID and returns one. Otherwise, it returns
562
609
  * zero. */
563
- int ssl_nid_to_curve_id(uint16_t *out_curve_id, int nid);
610
+ int ssl_nid_to_group_id(uint16_t *out_group_id, int nid);
564
611
 
565
- /* SSL_ECDH_CTX_init sets up |ctx| for use with curve |curve_id|. It returns one
612
+ /* SSL_ECDH_CTX_init sets up |ctx| for use with curve |group_id|. It returns one
566
613
  * on success and zero on error. */
567
- int SSL_ECDH_CTX_init(SSL_ECDH_CTX *ctx, uint16_t curve_id);
614
+ int SSL_ECDH_CTX_init(SSL_ECDH_CTX *ctx, uint16_t group_id);
568
615
 
569
616
  /* SSL_ECDH_CTX_init_for_dhe sets up |ctx| for use with legacy DHE-based ciphers
570
617
  * where the server specifies a group. It takes ownership of |params|. */
571
618
  void SSL_ECDH_CTX_init_for_dhe(SSL_ECDH_CTX *ctx, DH *params);
572
619
 
620
+ /* SSL_ECDH_CTX_init_for_cecpq1 sets up |ctx| for use with CECPQ1. */
621
+ void SSL_ECDH_CTX_init_for_cecpq1(SSL_ECDH_CTX *ctx);
622
+
573
623
  /* SSL_ECDH_CTX_cleanup releases memory associated with |ctx|. It is legal to
574
624
  * call it in the zero state. */
575
625
  void SSL_ECDH_CTX_cleanup(SSL_ECDH_CTX *ctx);
576
626
 
577
- /* The following functions call the corresponding method of
578
- * |SSL_ECDH_METHOD|. */
579
- int SSL_ECDH_CTX_generate_keypair(SSL_ECDH_CTX *ctx, CBB *out_public_key);
580
- int SSL_ECDH_CTX_compute_secret(SSL_ECDH_CTX *ctx, uint8_t **out_secret,
581
- size_t *out_secret_len, uint8_t *out_alert,
582
- const uint8_t *peer_key, size_t peer_key_len);
627
+ /* SSL_ECDH_CTX_get_id returns the group ID for |ctx|. */
628
+ uint16_t SSL_ECDH_CTX_get_id(const SSL_ECDH_CTX *ctx);
629
+
630
+ /* SSL_ECDH_CTX_get_key calls the |get_key| method of |SSL_ECDH_METHOD|. */
631
+ int SSL_ECDH_CTX_get_key(SSL_ECDH_CTX *ctx, CBS *cbs, CBS *out);
632
+
633
+ /* SSL_ECDH_CTX_add_key calls the |add_key| method of |SSL_ECDH_METHOD|. */
634
+ int SSL_ECDH_CTX_add_key(SSL_ECDH_CTX *ctx, CBB *cbb, CBB *out_contents);
635
+
636
+ /* SSL_ECDH_CTX_offer calls the |offer| method of |SSL_ECDH_METHOD|. */
637
+ int SSL_ECDH_CTX_offer(SSL_ECDH_CTX *ctx, CBB *out_public_key);
638
+
639
+ /* SSL_ECDH_CTX_accept calls the |accept| method of |SSL_ECDH_METHOD|. */
640
+ int SSL_ECDH_CTX_accept(SSL_ECDH_CTX *ctx, CBB *out_public_key,
641
+ uint8_t **out_secret, size_t *out_secret_len,
642
+ uint8_t *out_alert, const uint8_t *peer_key,
643
+ size_t peer_key_len);
644
+
645
+ /* SSL_ECDH_CTX_finish the |finish| method of |SSL_ECDH_METHOD|. */
646
+ int SSL_ECDH_CTX_finish(SSL_ECDH_CTX *ctx, uint8_t **out_secret,
647
+ size_t *out_secret_len, uint8_t *out_alert,
648
+ const uint8_t *peer_key, size_t peer_key_len);
649
+
650
+ /* Handshake messages. */
651
+
652
+ /* SSL_MAX_HANDSHAKE_FLIGHT is the number of messages, including
653
+ * ChangeCipherSpec, in the longest handshake flight. Currently this is the
654
+ * client's second leg in a full handshake when client certificates, NPN, and
655
+ * Channel ID, are all enabled. */
656
+ #define SSL_MAX_HANDSHAKE_FLIGHT 7
657
+
658
+ /* ssl_max_handshake_message_len returns the maximum number of bytes permitted
659
+ * in a handshake message for |ssl|. */
660
+ size_t ssl_max_handshake_message_len(const SSL *ssl);
661
+
662
+ /* dtls_clear_incoming_messages releases all buffered incoming messages. */
663
+ void dtls_clear_incoming_messages(SSL *ssl);
664
+
665
+ /* dtls_has_incoming_messages returns one if there are buffered incoming
666
+ * messages ahead of the current message and zero otherwise. */
667
+ int dtls_has_incoming_messages(const SSL *ssl);
668
+
669
+ typedef struct dtls_outgoing_message_st {
670
+ uint8_t *data;
671
+ uint32_t len;
672
+ uint16_t epoch;
673
+ char is_ccs;
674
+ } DTLS_OUTGOING_MESSAGE;
675
+
676
+ /* dtls_clear_outgoing_messages releases all buffered outgoing messages. */
677
+ void dtls_clear_outgoing_messages(SSL *ssl);
678
+
679
+
680
+ /* Callbacks. */
681
+
682
+ /* ssl_do_info_callback calls |ssl|'s info callback, if set. */
683
+ void ssl_do_info_callback(const SSL *ssl, int type, int value);
684
+
685
+ /* ssl_do_msg_callback calls |ssl|'s message callback, if set. */
686
+ void ssl_do_msg_callback(SSL *ssl, int is_write, int content_type,
687
+ const void *buf, size_t len);
583
688
 
584
689
 
585
690
  /* Transport buffers. */
@@ -637,117 +742,301 @@ int ssl_write_buffer_flush(SSL *ssl);
637
742
  void ssl_write_buffer_clear(SSL *ssl);
638
743
 
639
744
 
745
+ /* Certificate functions. */
746
+
747
+ /* ssl_has_certificate returns one if a certificate and private key are
748
+ * configured and zero otherwise. */
749
+ int ssl_has_certificate(const SSL *ssl);
750
+
751
+ /* ssl_parse_cert_chain parses a certificate list from |cbs| in the format used
752
+ * by a TLS Certificate message. On success, it returns a newly-allocated
753
+ * |X509| list and advances |cbs|. Otherwise, it returns NULL and sets
754
+ * |*out_alert| to an alert to send to the peer. If the list is non-empty and
755
+ * |out_leaf_sha256| is non-NULL, it writes the SHA-256 hash of the leaf to
756
+ * |out_leaf_sha256|. */
757
+ STACK_OF(X509) *ssl_parse_cert_chain(SSL *ssl, uint8_t *out_alert,
758
+ uint8_t *out_leaf_sha256, CBS *cbs);
759
+
760
+ /* ssl_add_cert_to_cbb adds |x509| to |cbb|. It returns one on success and zero
761
+ * on error. */
762
+ int ssl_add_cert_to_cbb(CBB *cbb, X509 *x509);
763
+
764
+ /* ssl_add_cert_chain adds |ssl|'s certificate chain to |cbb| in the format used
765
+ * by a TLS Certificate message. If there is no certificate chain, it emits an
766
+ * empty certificate list. It returns one on success and zero on error. */
767
+ int ssl_add_cert_chain(SSL *ssl, CBB *cbb);
768
+
769
+ /* ssl_parse_client_CA_list parses a CA list from |cbs| in the format used by a
770
+ * TLS CertificateRequest message. On success, it returns a newly-allocated
771
+ * |X509_NAME| list and advances |cbs|. Otherwise, it returns NULL and sets
772
+ * |*out_alert| to an alert to send to the peer. */
773
+ STACK_OF(X509_NAME) *
774
+ ssl_parse_client_CA_list(SSL *ssl, uint8_t *out_alert, CBS *cbs);
775
+
776
+ /* ssl_add_client_CA_list adds the configured CA list to |cbb| in the format
777
+ * used by a TLS CertificateRequest message. It returns one on success and zero
778
+ * on error. */
779
+ int ssl_add_client_CA_list(SSL *ssl, CBB *cbb);
780
+
781
+ /* ssl_check_leaf_certificate returns one if |leaf| is a suitable leaf server
782
+ * certificate for |ssl|. Otherwise, it returns zero and pushes an error on the
783
+ * error queue. */
784
+ int ssl_check_leaf_certificate(SSL *ssl, X509 *leaf);
785
+
786
+ /* ssl_do_client_cert_cb runs the client_cert_cb, if any, and returns one on
787
+ * success and zero on error. On error, it sets |*out_should_retry| to one if
788
+ * the callback failed and should be retried and zero otherwise. */
789
+ int ssl_do_client_cert_cb(SSL *ssl, int *out_should_retry);
790
+
791
+
792
+ /* TLS 1.3 key derivation. */
793
+
794
+ /* tls13_init_key_schedule initializes the handshake hash and key derivation
795
+ * state with the given resumption context. The cipher suite and PRF hash must
796
+ * have been selected at this point. It returns one on success and zero on
797
+ * error. */
798
+ int tls13_init_key_schedule(SSL *ssl, const uint8_t *resumption_ctx,
799
+ size_t resumption_ctx_len);
800
+
801
+ /* tls13_advance_key_schedule incorporates |in| into the key schedule with
802
+ * HKDF-Extract. It returns one on success and zero on error. */
803
+ int tls13_advance_key_schedule(SSL *ssl, const uint8_t *in, size_t len);
804
+
805
+ /* tls13_get_context_hashes writes Hash(Handshake Context) +
806
+ * Hash(resumption_context) to |out| which much have room for at least 2 *
807
+ * |EVP_MAX_MD_SIZE| bytes. On success, it returns one and sets |*out_len| to
808
+ * the number of bytes written. Otherwise, it returns zero. */
809
+ int tls13_get_context_hashes(SSL *ssl, uint8_t *out, size_t *out_len);
810
+
811
+ enum tls_record_type_t {
812
+ type_early_handshake,
813
+ type_early_data,
814
+ type_handshake,
815
+ type_data,
816
+ };
817
+
818
+ /* tls13_set_traffic_key sets the read or write traffic keys to |traffic_secret|
819
+ * for the given traffic phase |type|. It returns one on success and zero on
820
+ * error. */
821
+ int tls13_set_traffic_key(SSL *ssl, enum tls_record_type_t type,
822
+ enum evp_aead_direction_t direction,
823
+ const uint8_t *traffic_secret,
824
+ size_t traffic_secret_len);
825
+
826
+ /* tls13_set_handshake_traffic derives the handshake traffic secret and
827
+ * switches both read and write traffic to it. It returns one on success and
828
+ * zero on error. */
829
+ int tls13_set_handshake_traffic(SSL *ssl);
830
+
831
+ /* tls13_rotate_traffic_key derives the next read or write traffic secret. It
832
+ * returns one on success and zero on error. */
833
+ int tls13_rotate_traffic_key(SSL *ssl, enum evp_aead_direction_t direction);
834
+
835
+ /* tls13_derive_traffic_secret_0 derives the initial application data traffic
836
+ * secret based on the handshake transcripts and |master_secret|. It returns one
837
+ * on success and zero on error. */
838
+ int tls13_derive_traffic_secret_0(SSL *ssl);
839
+
840
+ /* tls13_finalize_keys derives the |exporter_secret| and |resumption_secret|. */
841
+ int tls13_finalize_keys(SSL *ssl);
842
+
843
+ /* tls13_export_keying_material provides and exporter interface to use the
844
+ * |exporter_secret|. */
845
+ int tls13_export_keying_material(SSL *ssl, uint8_t *out, size_t out_len,
846
+ const char *label, size_t label_len,
847
+ const uint8_t *context, size_t context_len,
848
+ int use_context);
849
+
850
+ /* tls13_finished_mac calculates the MAC of the handshake transcript to verify
851
+ * the integrity of the Finished message, and stores the result in |out| and
852
+ * length in |out_len|. |is_server| is 1 if this is for the Server Finished and
853
+ * 0 for the Client Finished. */
854
+ int tls13_finished_mac(SSL *ssl, uint8_t *out, size_t *out_len, int is_server);
855
+
856
+ /* tls13_resumption_psk calculates the PSK to use for the resumption of
857
+ * |session| and stores the result in |out|. It returns one on success, and
858
+ * zero on failure. */
859
+ int tls13_resumption_psk(SSL *ssl, uint8_t *out, size_t out_len,
860
+ const SSL_SESSION *session);
861
+
862
+ /* tls13_resumption_context derives the context to be used for the handshake
863
+ * transcript on the resumption of |session|. It returns one on success, and
864
+ * zero on failure. */
865
+ int tls13_resumption_context(SSL *ssl, uint8_t *out, size_t out_len,
866
+ const SSL_SESSION *session);
867
+
868
+
869
+ /* Handshake functions. */
870
+
871
+ enum ssl_hs_wait_t {
872
+ ssl_hs_error,
873
+ ssl_hs_ok,
874
+ ssl_hs_read_message,
875
+ ssl_hs_write_message,
876
+ ssl_hs_flush,
877
+ ssl_hs_flush_and_read_message,
878
+ ssl_hs_x509_lookup,
879
+ ssl_hs_private_key_operation,
880
+ };
881
+
882
+ struct ssl_handshake_st {
883
+ /* wait contains the operation |do_handshake| is currently blocking on or
884
+ * |ssl_hs_ok| if none. */
885
+ enum ssl_hs_wait_t wait;
886
+
887
+ /* do_handshake runs the handshake. On completion, it returns |ssl_hs_ok|.
888
+ * Otherwise, it returns a value corresponding to what operation is needed to
889
+ * progress. */
890
+ enum ssl_hs_wait_t (*do_handshake)(SSL *ssl);
891
+
892
+ int state;
893
+
894
+ size_t hash_len;
895
+ uint8_t resumption_hash[EVP_MAX_MD_SIZE];
896
+ uint8_t secret[EVP_MAX_MD_SIZE];
897
+ uint8_t traffic_secret_0[EVP_MAX_MD_SIZE];
898
+
899
+ /* ecdh_ctx is the active client ECDH offer in TLS 1.3. */
900
+ SSL_ECDH_CTX ecdh_ctx;
901
+
902
+ /* retry_group is the group ID selected by the server in HelloRetryRequest in
903
+ * TLS 1.3. */
904
+ uint16_t retry_group;
905
+
906
+ /* key_share_bytes is the value of the previously sent KeyShare extension by
907
+ * the client in TLS 1.3. */
908
+ uint8_t *key_share_bytes;
909
+ size_t key_share_bytes_len;
910
+
911
+ /* public_key, for servers, is the key share to be sent to the client in TLS
912
+ * 1.3. */
913
+ uint8_t *public_key;
914
+ size_t public_key_len;
915
+
916
+ /* peer_sigalgs are the signature algorithms that the peer supports. These are
917
+ * taken from the contents of the signature algorithms extension for a server
918
+ * or from the CertificateRequest for a client. */
919
+ uint16_t *peer_sigalgs;
920
+ /* num_peer_sigalgs is the number of entries in |peer_sigalgs|. */
921
+ size_t num_peer_sigalgs;
922
+
923
+ uint8_t session_tickets_sent;
924
+
925
+ /* peer_psk_identity_hint, on the client, is the psk_identity_hint sent by the
926
+ * server when using a TLS 1.2 PSK key exchange. */
927
+ char *peer_psk_identity_hint;
928
+ } /* SSL_HANDSHAKE */;
929
+
930
+ SSL_HANDSHAKE *ssl_handshake_new(enum ssl_hs_wait_t (*do_handshake)(SSL *ssl));
931
+
932
+ /* ssl_handshake_free releases all memory associated with |hs|. */
933
+ void ssl_handshake_free(SSL_HANDSHAKE *hs);
934
+
935
+ /* tls13_handshake runs the TLS 1.3 handshake. It returns one on success and <=
936
+ * 0 on error. */
937
+ int tls13_handshake(SSL *ssl);
938
+
939
+ /* The following are implementations of |do_handshake| for the client and
940
+ * server. */
941
+ enum ssl_hs_wait_t tls13_client_handshake(SSL *ssl);
942
+ enum ssl_hs_wait_t tls13_server_handshake(SSL *ssl);
943
+
944
+ /* tls13_post_handshake processes a post-handshake message. It returns one on
945
+ * success and zero on failure. */
946
+ int tls13_post_handshake(SSL *ssl);
947
+
948
+ /* tls13_check_message_type checks if the current message has type |type|. If so
949
+ * it returns one. Otherwise, it sends an alert and returns zero. */
950
+ int tls13_check_message_type(SSL *ssl, int type);
951
+
952
+ int tls13_process_certificate(SSL *ssl, int allow_anonymous);
953
+ int tls13_process_certificate_verify(SSL *ssl);
954
+ int tls13_process_finished(SSL *ssl);
955
+
956
+ int tls13_prepare_certificate(SSL *ssl);
957
+ enum ssl_private_key_result_t tls13_prepare_certificate_verify(
958
+ SSL *ssl, int is_first_run);
959
+ int tls13_prepare_finished(SSL *ssl);
960
+ int tls13_process_new_session_ticket(SSL *ssl);
961
+
962
+ int ssl_ext_key_share_parse_serverhello(SSL *ssl, uint8_t **out_secret,
963
+ size_t *out_secret_len,
964
+ uint8_t *out_alert, CBS *contents);
965
+ int ssl_ext_key_share_parse_clienthello(SSL *ssl, int *out_found,
966
+ uint8_t **out_secret,
967
+ size_t *out_secret_len,
968
+ uint8_t *out_alert, CBS *contents);
969
+ int ssl_ext_key_share_add_serverhello(SSL *ssl, CBB *out);
970
+
971
+ int ssl_ext_pre_shared_key_parse_serverhello(SSL *ssl, uint8_t *out_alert,
972
+ CBS *contents);
973
+ int ssl_ext_pre_shared_key_parse_clienthello(SSL *ssl,
974
+ SSL_SESSION **out_session,
975
+ uint8_t *out_alert, CBS *contents);
976
+ int ssl_ext_pre_shared_key_add_serverhello(SSL *ssl, CBB *out);
977
+
978
+ int ssl_add_client_hello_body(SSL *ssl, CBB *body);
979
+
980
+ /* ssl_clear_tls13_state releases client state only needed for TLS 1.3. It
981
+ * should be called once the version is known to be TLS 1.2 or earlier. */
982
+ void ssl_clear_tls13_state(SSL *ssl);
983
+
984
+
985
+ /* SSLKEYLOGFILE functions. */
986
+
987
+ /* ssl_log_rsa_client_key_exchange logs |premaster|, if logging is enabled for
988
+ * |ssl|. It returns one on success and zero on failure. The entry is identified
989
+ * by the first 8 bytes of |encrypted_premaster|. */
990
+ int ssl_log_rsa_client_key_exchange(const SSL *ssl,
991
+ const uint8_t *encrypted_premaster,
992
+ size_t encrypted_premaster_len,
993
+ const uint8_t *premaster,
994
+ size_t premaster_len);
995
+
996
+ /* ssl_log_secret logs |secret| with label |label|, if logging is enabled for
997
+ * |ssl|. It returns one on success and zero on failure. */
998
+ int ssl_log_secret(const SSL *ssl, const char *label, const uint8_t *secret,
999
+ size_t secret_len);
1000
+
1001
+
1002
+ /* ClientHello functions. */
1003
+
1004
+ int ssl_early_callback_init(SSL *ssl, struct ssl_early_callback_ctx *ctx,
1005
+ const uint8_t *in, size_t in_len);
1006
+
1007
+ int ssl_early_callback_get_extension(const struct ssl_early_callback_ctx *ctx,
1008
+ CBS *out, uint16_t extension_type);
1009
+
1010
+ STACK_OF(SSL_CIPHER) *
1011
+ ssl_parse_client_cipher_list(const struct ssl_early_callback_ctx *ctx);
1012
+
1013
+ int ssl_client_cipher_list_contains_cipher(
1014
+ const struct ssl_early_callback_ctx *client_hello, uint16_t id);
1015
+
1016
+
1017
+ /* GREASE. */
1018
+
1019
+ enum ssl_grease_index_t {
1020
+ ssl_grease_cipher = 0,
1021
+ ssl_grease_group,
1022
+ ssl_grease_extension1,
1023
+ ssl_grease_extension2,
1024
+ ssl_grease_version,
1025
+ };
1026
+
1027
+ /* ssl_get_grease_value returns a GREASE value for |ssl|. For a given
1028
+ * connection, the values for each index will be deterministic. This allows the
1029
+ * same ClientHello be sent twice for a HelloRetryRequest or the same group be
1030
+ * advertised in both supported_groups and key_shares. */
1031
+ uint16_t ssl_get_grease_value(const SSL *ssl, enum ssl_grease_index_t index);
1032
+
1033
+
640
1034
  /* Underdocumented functions.
641
1035
  *
642
1036
  * Functions below here haven't been touched up and may be underdocumented. */
643
1037
 
644
- #define c2l(c, l) \
645
- (l = ((unsigned long)(*((c)++))), l |= (((unsigned long)(*((c)++))) << 8), \
646
- l |= (((unsigned long)(*((c)++))) << 16), \
647
- l |= (((unsigned long)(*((c)++))) << 24))
648
-
649
- /* NOTE - c is not incremented as per c2l */
650
- #define c2ln(c, l1, l2, n) \
651
- { \
652
- c += n; \
653
- l1 = l2 = 0; \
654
- switch (n) { \
655
- case 8: \
656
- l2 = ((unsigned long)(*(--(c)))) << 24; \
657
- case 7: \
658
- l2 |= ((unsigned long)(*(--(c)))) << 16; \
659
- case 6: \
660
- l2 |= ((unsigned long)(*(--(c)))) << 8; \
661
- case 5: \
662
- l2 |= ((unsigned long)(*(--(c)))); \
663
- case 4: \
664
- l1 = ((unsigned long)(*(--(c)))) << 24; \
665
- case 3: \
666
- l1 |= ((unsigned long)(*(--(c)))) << 16; \
667
- case 2: \
668
- l1 |= ((unsigned long)(*(--(c)))) << 8; \
669
- case 1: \
670
- l1 |= ((unsigned long)(*(--(c)))); \
671
- } \
672
- }
673
-
674
- #define l2c(l, c) \
675
- (*((c)++) = (uint8_t)(((l)) & 0xff), \
676
- *((c)++) = (uint8_t)(((l) >> 8) & 0xff), \
677
- *((c)++) = (uint8_t)(((l) >> 16) & 0xff), \
678
- *((c)++) = (uint8_t)(((l) >> 24) & 0xff))
679
-
680
- #define n2l(c, l) \
681
- (l = ((unsigned long)(*((c)++))) << 24, \
682
- l |= ((unsigned long)(*((c)++))) << 16, \
683
- l |= ((unsigned long)(*((c)++))) << 8, l |= ((unsigned long)(*((c)++))))
684
-
685
- #define l2n(l, c) \
686
- (*((c)++) = (uint8_t)(((l) >> 24) & 0xff), \
687
- *((c)++) = (uint8_t)(((l) >> 16) & 0xff), \
688
- *((c)++) = (uint8_t)(((l) >> 8) & 0xff), \
689
- *((c)++) = (uint8_t)(((l)) & 0xff))
690
-
691
- #define l2n8(l, c) \
692
- (*((c)++) = (uint8_t)(((l) >> 56) & 0xff), \
693
- *((c)++) = (uint8_t)(((l) >> 48) & 0xff), \
694
- *((c)++) = (uint8_t)(((l) >> 40) & 0xff), \
695
- *((c)++) = (uint8_t)(((l) >> 32) & 0xff), \
696
- *((c)++) = (uint8_t)(((l) >> 24) & 0xff), \
697
- *((c)++) = (uint8_t)(((l) >> 16) & 0xff), \
698
- *((c)++) = (uint8_t)(((l) >> 8) & 0xff), \
699
- *((c)++) = (uint8_t)(((l)) & 0xff))
700
-
701
- /* NOTE - c is not incremented as per l2c */
702
- #define l2cn(l1, l2, c, n) \
703
- { \
704
- c += n; \
705
- switch (n) { \
706
- case 8: \
707
- *(--(c)) = (uint8_t)(((l2) >> 24) & 0xff); \
708
- case 7: \
709
- *(--(c)) = (uint8_t)(((l2) >> 16) & 0xff); \
710
- case 6: \
711
- *(--(c)) = (uint8_t)(((l2) >> 8) & 0xff); \
712
- case 5: \
713
- *(--(c)) = (uint8_t)(((l2)) & 0xff); \
714
- case 4: \
715
- *(--(c)) = (uint8_t)(((l1) >> 24) & 0xff); \
716
- case 3: \
717
- *(--(c)) = (uint8_t)(((l1) >> 16) & 0xff); \
718
- case 2: \
719
- *(--(c)) = (uint8_t)(((l1) >> 8) & 0xff); \
720
- case 1: \
721
- *(--(c)) = (uint8_t)(((l1)) & 0xff); \
722
- } \
723
- }
724
-
725
- #define n2s(c, s) \
726
- ((s = (((unsigned int)(c[0])) << 8) | (((unsigned int)(c[1])))), c += 2)
727
-
728
- #define s2n(s, c) \
729
- ((c[0] = (uint8_t)(((s) >> 8) & 0xff), \
730
- c[1] = (uint8_t)(((s)) & 0xff)), \
731
- c += 2)
732
-
733
- #define n2l3(c, l) \
734
- ((l = (((unsigned long)(c[0])) << 16) | (((unsigned long)(c[1])) << 8) | \
735
- (((unsigned long)(c[2])))), \
736
- c += 3)
737
-
738
- #define l2n3(l, c) \
739
- ((c[0] = (uint8_t)(((l) >> 16) & 0xff), \
740
- c[1] = (uint8_t)(((l) >> 8) & 0xff), \
741
- c[2] = (uint8_t)(((l)) & 0xff)), \
742
- c += 3)
743
-
744
- /* LOCAL STUFF */
745
-
746
1038
  #define TLSEXT_CHANNEL_ID_SIZE 128
747
1039
 
748
- /* Check if an SSL structure is using DTLS */
749
- #define SSL_IS_DTLS(ssl) (ssl->method->is_dtls)
750
-
751
1040
  /* From RFC4492, used in encoding the curve type in ECParameters */
752
1041
  #define NAMED_CURVE_TYPE 3
753
1042
 
@@ -756,12 +1045,6 @@ enum ssl_hash_message_t {
756
1045
  ssl_hash_message,
757
1046
  };
758
1047
 
759
- /* Structure containing decoded values of signature algorithms extension */
760
- typedef struct tls_sigalgs_st {
761
- uint8_t rsign;
762
- uint8_t rhash;
763
- } TLS_SIGALGS;
764
-
765
1048
  typedef struct cert_st {
766
1049
  X509 *x509;
767
1050
  EVP_PKEY *privatekey;
@@ -783,17 +1066,10 @@ typedef struct cert_st {
783
1066
  DH *dh_tmp;
784
1067
  DH *(*dh_tmp_cb)(SSL *ssl, int is_export, int keysize);
785
1068
 
786
- /* peer_sigalgs are the algorithm/hash pairs that the peer supports. These
787
- * are taken from the contents of signature algorithms extension for a server
788
- * or from the CertificateRequest for a client. */
789
- TLS_SIGALGS *peer_sigalgs;
790
- /* peer_sigalgslen is the number of entries in |peer_sigalgs|. */
791
- size_t peer_sigalgslen;
792
-
793
- /* digest_nids, if non-NULL, is the set of digests supported by |privatekey|
794
- * in decreasing order of preference. */
795
- int *digest_nids;
796
- size_t num_digest_nids;
1069
+ /* sigalgs, if non-NULL, is the set of signature algorithms supported by
1070
+ * |privatekey| in decreasing order of preference. */
1071
+ uint16_t *sigalgs;
1072
+ size_t num_sigalgs;
797
1073
 
798
1074
  /* Certificate setup callback: if set is called whenever a
799
1075
  * certificate may be required (client or server). the callback
@@ -803,6 +1079,10 @@ typedef struct cert_st {
803
1079
  * supported signature algorithms or curves. */
804
1080
  int (*cert_cb)(SSL *ssl, void *arg);
805
1081
  void *cert_cb_arg;
1082
+
1083
+ /* Optional X509_STORE for certificate validation. If NULL the parent SSL_CTX
1084
+ * store is used instead. */
1085
+ X509_STORE *verify_store;
806
1086
  } CERT;
807
1087
 
808
1088
  /* SSL_METHOD is a compatibility structure to support the legacy version-locked
@@ -820,27 +1100,72 @@ struct ssl_method_st {
820
1100
  struct ssl_protocol_method_st {
821
1101
  /* is_dtls is one if the protocol is DTLS and zero otherwise. */
822
1102
  char is_dtls;
1103
+ /* min_version is the minimum implemented version. */
1104
+ uint16_t min_version;
1105
+ /* max_version is the maximum implemented version. */
1106
+ uint16_t max_version;
1107
+ /* version_from_wire maps |wire_version| to a protocol version. On success, it
1108
+ * sets |*out_version| to the result and returns one. If the version is
1109
+ * unknown, it returns zero. */
1110
+ int (*version_from_wire)(uint16_t *out_version, uint16_t wire_version);
1111
+ /* version_to_wire maps |version| to the wire representation. It is an error
1112
+ * to call it with an invalid version. */
1113
+ uint16_t (*version_to_wire)(uint16_t version);
823
1114
  int (*ssl_new)(SSL *ssl);
824
1115
  void (*ssl_free)(SSL *ssl);
825
- int (*ssl_accept)(SSL *ssl);
826
- int (*ssl_connect)(SSL *ssl);
827
- long (*ssl_get_message)(SSL *ssl, int header_state, int body_state,
828
- int msg_type, long max,
829
- enum ssl_hash_message_t hash_message, int *ok);
830
- int (*ssl_read_app_data)(SSL *ssl, uint8_t *buf, int len, int peek);
831
- int (*ssl_read_change_cipher_spec)(SSL *ssl);
832
- void (*ssl_read_close_notify)(SSL *ssl);
833
- int (*ssl_write_app_data)(SSL *ssl, const void *buf_, int len);
834
- int (*ssl_dispatch_alert)(SSL *ssl);
1116
+ /* ssl_get_message reads the next handshake message. If |msg_type| is not -1,
1117
+ * the message must have the specified type. On success, it returns one and
1118
+ * sets |ssl->s3->tmp.message_type|, |ssl->init_msg|, and |ssl->init_num|.
1119
+ * Otherwise, it returns <= 0. */
1120
+ int (*ssl_get_message)(SSL *ssl, int msg_type,
1121
+ enum ssl_hash_message_t hash_message);
1122
+ /* hash_current_message incorporates the current handshake message into the
1123
+ * handshake hash. It returns one on success and zero on allocation
1124
+ * failure. */
1125
+ int (*hash_current_message)(SSL *ssl);
1126
+ /* release_current_message is called to release the current handshake message.
1127
+ * If |free_buffer| is one, buffers will also be released. */
1128
+ void (*release_current_message)(SSL *ssl, int free_buffer);
1129
+ /* read_app_data reads up to |len| bytes of application data into |buf|. On
1130
+ * success, it returns the number of bytes read. Otherwise, it returns <= 0
1131
+ * and sets |*out_got_handshake| to whether the failure was due to a
1132
+ * post-handshake handshake message. If so, it fills in the current message as
1133
+ * in |ssl_get_message|. */
1134
+ int (*read_app_data)(SSL *ssl, int *out_got_handshake, uint8_t *buf, int len,
1135
+ int peek);
1136
+ int (*read_change_cipher_spec)(SSL *ssl);
1137
+ void (*read_close_notify)(SSL *ssl);
1138
+ int (*write_app_data)(SSL *ssl, const void *buf_, int len);
1139
+ int (*dispatch_alert)(SSL *ssl);
835
1140
  /* supports_cipher returns one if |cipher| is supported by this protocol and
836
1141
  * zero otherwise. */
837
1142
  int (*supports_cipher)(const SSL_CIPHER *cipher);
838
- /* Handshake header length */
839
- unsigned int hhlen;
840
- /* Set the handshake header */
841
- int (*set_handshake_header)(SSL *ssl, int type, unsigned long len);
842
- /* Write out handshake message */
843
- int (*do_write)(SSL *ssl);
1143
+ /* init_message begins a new handshake message of type |type|. |cbb| is the
1144
+ * root CBB to be passed into |finish_message|. |*body| is set to a child CBB
1145
+ * the caller should write to. It returns one on success and zero on error. */
1146
+ int (*init_message)(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
1147
+ /* finish_message finishes a handshake message and prepares it to be
1148
+ * written. It returns one on success and zero on error. */
1149
+ int (*finish_message)(SSL *ssl, CBB *cbb);
1150
+ /* write_message writes the next message to the transport. It returns one on
1151
+ * success and <= 0 on error. */
1152
+ int (*write_message)(SSL *ssl);
1153
+ /* send_change_cipher_spec sends a ChangeCipherSpec message. */
1154
+ int (*send_change_cipher_spec)(SSL *ssl);
1155
+ /* expect_flight is called when the handshake expects a flight of messages from
1156
+ * the peer. */
1157
+ void (*expect_flight)(SSL *ssl);
1158
+ /* received_flight is called when the handshake has received a flight of
1159
+ * messages from the peer. */
1160
+ void (*received_flight)(SSL *ssl);
1161
+ /* set_read_state sets |ssl|'s read cipher state to |aead_ctx|. It takes
1162
+ * ownership of |aead_ctx|. It returns one on success and zero if changing the
1163
+ * read state is forbidden at this point. */
1164
+ int (*set_read_state)(SSL *ssl, SSL_AEAD_CTX *aead_ctx);
1165
+ /* set_write_state sets |ssl|'s write cipher state to |aead_ctx|. It takes
1166
+ * ownership of |aead_ctx|. It returns one on success and zero if changing the
1167
+ * write state is forbidden at this point. */
1168
+ int (*set_write_state)(SSL *ssl, SSL_AEAD_CTX *aead_ctx);
844
1169
  };
845
1170
 
846
1171
  /* This is for the SSLv3/TLSv1.0 differences in crypto/hash stuff It is a bit
@@ -855,16 +1180,8 @@ struct ssl3_enc_method {
855
1180
  size_t label_len, const uint8_t *seed1, size_t seed1_len,
856
1181
  const uint8_t *seed2, size_t seed2_len);
857
1182
  int (*final_finish_mac)(SSL *ssl, int from_server, uint8_t *out);
858
- int (*cert_verify_mac)(SSL *, int, uint8_t *);
859
1183
  };
860
1184
 
861
- #define SSL_HM_HEADER_LENGTH(ssl) ssl->method->hhlen
862
- #define ssl_handshake_start(ssl) \
863
- (((uint8_t *)ssl->init_buf->data) + ssl->method->hhlen)
864
- #define ssl_set_handshake_header(ssl, htype, len) \
865
- ssl->method->set_handshake_header(ssl, htype, len)
866
- #define ssl_do_write(ssl) ssl->method->do_write(ssl)
867
-
868
1185
  /* lengths of messages */
869
1186
  #define DTLS1_COOKIE_LENGTH 256
870
1187
 
@@ -876,27 +1193,27 @@ struct ssl3_enc_method {
876
1193
 
877
1194
  #define DTLS1_AL_HEADER_LENGTH 2
878
1195
 
879
- /* TODO(davidben): This structure is used for both incoming messages and
880
- * outgoing messages. |is_ccs| and |epoch| are only used in the latter and
881
- * should be moved elsewhere. */
882
1196
  struct hm_header_st {
883
1197
  uint8_t type;
884
1198
  uint32_t msg_len;
885
1199
  uint16_t seq;
886
1200
  uint32_t frag_off;
887
1201
  uint32_t frag_len;
888
- int is_ccs;
889
- /* epoch, for buffered outgoing messages, is the epoch the message was
890
- * originally sent in. */
891
- uint16_t epoch;
892
1202
  };
893
1203
 
894
- /* TODO(davidben): This structure is used for both incoming messages and
895
- * outgoing messages. |fragment| and |reassembly| are only used in the former
896
- * and should be moved elsewhere. */
1204
+ /* An hm_fragment is an incoming DTLS message, possibly not yet assembled. */
897
1205
  typedef struct hm_fragment_st {
898
- struct hm_header_st msg_header;
899
- uint8_t *fragment;
1206
+ /* type is the type of the message. */
1207
+ uint8_t type;
1208
+ /* seq is the sequence number of this message. */
1209
+ uint16_t seq;
1210
+ /* msg_len is the length of the message body. */
1211
+ uint32_t msg_len;
1212
+ /* data is a pointer to the message, including message header. It has length
1213
+ * |DTLS1_HM_HEADER_LENGTH| + |msg_len|. */
1214
+ uint8_t *data;
1215
+ /* reassembly is a bitmask of |msg_len| bits corresponding to which parts of
1216
+ * the message have been received. It is NULL if the message is complete. */
900
1217
  uint8_t *reassembly;
901
1218
  } hm_fragment;
902
1219
 
@@ -916,34 +1233,25 @@ typedef struct dtls1_state_st {
916
1233
  /* records being received in the current epoch */
917
1234
  DTLS1_BITMAP bitmap;
918
1235
 
919
- /* handshake message numbers.
920
- * TODO(davidben): It doesn't make much sense to store both of these. Only
921
- * store one. */
922
1236
  uint16_t handshake_write_seq;
923
- uint16_t next_handshake_write_seq;
924
-
925
1237
  uint16_t handshake_read_seq;
926
1238
 
927
1239
  /* save last sequence number for retransmissions */
928
1240
  uint8_t last_write_sequence[8];
929
1241
 
930
- /* buffered_messages is a priority queue of incoming handshake messages that
931
- * have yet to be processed.
932
- *
933
- * TODO(davidben): This data structure may as well be a ring buffer of fixed
934
- * size. */
935
- pqueue buffered_messages;
1242
+ /* incoming_messages is a ring buffer of incoming handshake messages that have
1243
+ * yet to be processed. The front of the ring buffer is message number
1244
+ * |handshake_read_seq|, at position |handshake_read_seq| %
1245
+ * |SSL_MAX_HANDSHAKE_FLIGHT|. */
1246
+ hm_fragment *incoming_messages[SSL_MAX_HANDSHAKE_FLIGHT];
936
1247
 
937
- /* send_messages is a priority queue of outgoing handshake messages sent in
938
- * the most recent handshake flight.
939
- *
940
- * TODO(davidben): This data structure may as well be a STACK_OF(T). */
941
- pqueue sent_messages;
1248
+ /* outgoing_messages is the queue of outgoing messages from the last handshake
1249
+ * flight. */
1250
+ DTLS_OUTGOING_MESSAGE outgoing_messages[SSL_MAX_HANDSHAKE_FLIGHT];
1251
+ uint8_t outgoing_messages_len;
942
1252
 
943
1253
  unsigned int mtu; /* max DTLS packet size */
944
1254
 
945
- struct hm_header_st w_msg_hdr;
946
-
947
1255
  /* num_timeouts is the number of times the retransmit timer has fired since
948
1256
  * the last time it was reset. */
949
1257
  unsigned int num_timeouts;
@@ -952,20 +1260,34 @@ typedef struct dtls1_state_st {
952
1260
  * timeout. */
953
1261
  struct timeval next_timeout;
954
1262
 
955
- /* Timeout duration */
956
- unsigned short timeout_duration;
1263
+ /* timeout_duration_ms is the timeout duration in milliseconds. */
1264
+ unsigned timeout_duration_ms;
957
1265
  } DTLS1_STATE;
958
1266
 
959
1267
  extern const SSL3_ENC_METHOD TLSv1_enc_data;
960
1268
  extern const SSL3_ENC_METHOD SSLv3_enc_data;
961
- extern const SRTP_PROTECTION_PROFILE kSRTPProfiles[];
962
1269
 
963
- int ssl_clear_bad_session(SSL *ssl);
1270
+ /* From draft-ietf-tls-tls13-14, used in determining ticket validity. */
1271
+ #define SSL_TICKET_ALLOW_EARLY_DATA 1
1272
+ #define SSL_TICKET_ALLOW_DHE_RESUMPTION 2
1273
+ #define SSL_TICKET_ALLOW_PSK_RESUMPTION 4
1274
+
964
1275
  CERT *ssl_cert_new(void);
965
1276
  CERT *ssl_cert_dup(CERT *cert);
966
1277
  void ssl_cert_clear_certs(CERT *c);
967
1278
  void ssl_cert_free(CERT *c);
968
1279
  int ssl_get_new_session(SSL *ssl, int is_server);
1280
+ int ssl_encrypt_ticket(SSL *ssl, CBB *out, const SSL_SESSION *session);
1281
+
1282
+ /* ssl_session_is_context_valid returns one if |session|'s session ID context
1283
+ * matches the one set on |ssl| and zero otherwise. */
1284
+ int ssl_session_is_context_valid(const SSL *ssl, const SSL_SESSION *session);
1285
+
1286
+ /* ssl_session_is_time_valid returns one if |session| is still valid and zero if
1287
+ * it has expired. */
1288
+ int ssl_session_is_time_valid(const SSL *ssl, const SSL_SESSION *session);
1289
+
1290
+ void ssl_set_session(SSL *ssl, SSL_SESSION *session);
969
1291
 
970
1292
  enum ssl_session_result_t {
971
1293
  ssl_session_success,
@@ -983,7 +1305,19 @@ enum ssl_session_result_t ssl_get_prev_session(
983
1305
  SSL *ssl, SSL_SESSION **out_session, int *out_send_ticket,
984
1306
  const struct ssl_early_callback_ctx *ctx);
985
1307
 
986
- STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *ssl, const CBS *cbs);
1308
+ /* The following flags determine which parts of the session are duplicated. */
1309
+ #define SSL_SESSION_DUP_AUTH_ONLY 0x0
1310
+ #define SSL_SESSION_INCLUDE_TICKET 0x1
1311
+ #define SSL_SESSION_INCLUDE_NONAUTH 0x2
1312
+ #define SSL_SESSION_DUP_ALL \
1313
+ (SSL_SESSION_INCLUDE_TICKET | SSL_SESSION_INCLUDE_NONAUTH)
1314
+
1315
+ /* SSL_SESSION_dup returns a newly-allocated |SSL_SESSION| with a copy of the
1316
+ * fields in |session| or NULL on error. The new session is non-resumable and
1317
+ * must be explicitly marked resumable once it has been filled in. */
1318
+ OPENSSL_EXPORT SSL_SESSION *SSL_SESSION_dup(SSL_SESSION *session,
1319
+ int dup_flags);
1320
+
987
1321
  void ssl_cipher_preference_list_free(
988
1322
  struct ssl_cipher_preference_list_st *cipher_list);
989
1323
  struct ssl_cipher_preference_list_st *ssl_get_cipher_preferences(SSL *ssl);
@@ -995,8 +1329,8 @@ int ssl_cert_add1_chain_cert(CERT *cert, X509 *x509);
995
1329
  void ssl_cert_set_cert_cb(CERT *cert,
996
1330
  int (*cb)(SSL *ssl, void *arg), void *arg);
997
1331
 
998
- int ssl_verify_cert_chain(SSL *ssl, STACK_OF(X509) *cert_chain);
999
- int ssl_add_cert_chain(SSL *ssl, unsigned long *l);
1332
+ int ssl_verify_cert_chain(SSL *ssl, long *out_verify_result,
1333
+ STACK_OF(X509) * cert_chain);
1000
1334
  void ssl_update_cache(SSL *ssl, int mode);
1001
1335
 
1002
1336
  /* ssl_get_compatible_server_ciphers determines the key exchange and
@@ -1009,80 +1343,80 @@ void ssl_get_compatible_server_ciphers(SSL *ssl, uint32_t *out_mask_k,
1009
1343
  STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *ssl);
1010
1344
  int ssl_verify_alarm_type(long type);
1011
1345
 
1012
- /* ssl_fill_hello_random fills a client_random or server_random field of length
1013
- * |len|. It returns one on success and zero on failure. */
1014
- int ssl_fill_hello_random(uint8_t *out, size_t len, int is_server);
1015
-
1016
- int ssl3_send_server_certificate(SSL *ssl);
1017
- int ssl3_send_new_session_ticket(SSL *ssl);
1018
- int ssl3_send_certificate_status(SSL *ssl);
1019
- int ssl3_get_finished(SSL *ssl, int state_a, int state_b);
1020
- int ssl3_send_change_cipher_spec(SSL *ssl, int state_a, int state_b);
1346
+ int ssl3_get_finished(SSL *ssl);
1347
+ int ssl3_send_change_cipher_spec(SSL *ssl);
1021
1348
  void ssl3_cleanup_key_block(SSL *ssl);
1022
- int ssl3_do_write(SSL *ssl, int type);
1023
1349
  int ssl3_send_alert(SSL *ssl, int level, int desc);
1024
- int ssl3_get_req_cert_type(SSL *ssl, uint8_t *p);
1025
- long ssl3_get_message(SSL *ssl, int header_state, int body_state, int msg_type,
1026
- long max, enum ssl_hash_message_t hash_message, int *ok);
1027
-
1028
- /* ssl3_hash_current_message incorporates the current handshake message into the
1029
- * handshake hash. It returns one on success and zero on allocation failure. */
1350
+ int ssl3_get_message(SSL *ssl, int msg_type,
1351
+ enum ssl_hash_message_t hash_message);
1030
1352
  int ssl3_hash_current_message(SSL *ssl);
1353
+ void ssl3_release_current_message(SSL *ssl, int free_buffer);
1031
1354
 
1032
- /* ssl3_cert_verify_hash writes the CertificateVerify hash into the bytes
1033
- * pointed to by |out| and writes the number of bytes to |*out_len|. |out| must
1034
- * have room for EVP_MAX_MD_SIZE bytes. For TLS 1.2 and up, |*out_md| is used
1035
- * for the hash function, otherwise the hash function depends on |pkey_type|
1036
- * and is written to |*out_md|. It returns one on success and zero on
1037
- * failure. */
1038
- int ssl3_cert_verify_hash(SSL *ssl, uint8_t *out, size_t *out_len,
1039
- const EVP_MD **out_md, int pkey_type);
1355
+ /* ssl3_cert_verify_hash writes the SSL 3.0 CertificateVerify hash into the
1356
+ * bytes pointed to by |out| and writes the number of bytes to |*out_len|. |out|
1357
+ * must have room for |EVP_MAX_MD_SIZE| bytes. It sets |*out_md| to the hash
1358
+ * function used. It returns one on success and zero on failure. */
1359
+ int ssl3_cert_verify_hash(SSL *ssl, const EVP_MD **out_md, uint8_t *out,
1360
+ size_t *out_len, uint16_t signature_algorithm);
1040
1361
 
1041
1362
  int ssl3_send_finished(SSL *ssl, int a, int b);
1042
1363
  int ssl3_supports_cipher(const SSL_CIPHER *cipher);
1043
1364
  int ssl3_dispatch_alert(SSL *ssl);
1044
- int ssl3_read_app_data(SSL *ssl, uint8_t *buf, int len, int peek);
1365
+ int ssl3_read_app_data(SSL *ssl, int *out_got_handshake, uint8_t *buf, int len,
1366
+ int peek);
1045
1367
  int ssl3_read_change_cipher_spec(SSL *ssl);
1046
1368
  void ssl3_read_close_notify(SSL *ssl);
1047
- int ssl3_read_bytes(SSL *ssl, int type, uint8_t *buf, int len, int peek);
1369
+ int ssl3_read_handshake_bytes(SSL *ssl, uint8_t *buf, int len);
1048
1370
  int ssl3_write_app_data(SSL *ssl, const void *buf, int len);
1049
1371
  int ssl3_write_bytes(SSL *ssl, int type, const void *buf, int len);
1050
1372
  int ssl3_output_cert_chain(SSL *ssl);
1051
1373
  const SSL_CIPHER *ssl3_choose_cipher(
1052
- SSL *ssl, STACK_OF(SSL_CIPHER) *clnt,
1053
- struct ssl_cipher_preference_list_st *srvr);
1374
+ SSL *ssl, const struct ssl_early_callback_ctx *client_hello,
1375
+ const struct ssl_cipher_preference_list_st *srvr);
1054
1376
 
1055
1377
  int ssl3_new(SSL *ssl);
1056
1378
  void ssl3_free(SSL *ssl);
1057
1379
  int ssl3_accept(SSL *ssl);
1058
1380
  int ssl3_connect(SSL *ssl);
1059
1381
 
1060
- int ssl3_set_handshake_header(SSL *ssl, int htype, unsigned long len);
1061
- int ssl3_handshake_write(SSL *ssl);
1382
+ int ssl3_init_message(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
1383
+ int ssl3_finish_message(SSL *ssl, CBB *cbb);
1384
+ int ssl3_write_message(SSL *ssl);
1385
+
1386
+ void ssl3_expect_flight(SSL *ssl);
1387
+ void ssl3_received_flight(SSL *ssl);
1388
+
1389
+ int dtls1_init_message(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
1390
+ int dtls1_finish_message(SSL *ssl, CBB *cbb);
1391
+ int dtls1_write_message(SSL *ssl);
1062
1392
 
1063
- int dtls1_do_handshake_write(SSL *ssl, enum dtls1_use_epoch_t use_epoch);
1064
- int dtls1_read_app_data(SSL *ssl, uint8_t *buf, int len, int peek);
1393
+ /* dtls1_get_record reads a new input record. On success, it places it in
1394
+ * |ssl->s3->rrec| and returns one. Otherwise it returns <= 0 on error or if
1395
+ * more data is needed. */
1396
+ int dtls1_get_record(SSL *ssl);
1397
+
1398
+ int dtls1_read_app_data(SSL *ssl, int *out_got_handshake, uint8_t *buf, int len,
1399
+ int peek);
1065
1400
  int dtls1_read_change_cipher_spec(SSL *ssl);
1066
1401
  void dtls1_read_close_notify(SSL *ssl);
1067
- int dtls1_read_bytes(SSL *ssl, int type, uint8_t *buf, int len, int peek);
1068
- void dtls1_set_message_header(SSL *ssl, uint8_t mt, unsigned long len,
1069
- unsigned short seq_num, unsigned long frag_off,
1070
- unsigned long frag_len);
1071
1402
 
1072
1403
  int dtls1_write_app_data(SSL *ssl, const void *buf, int len);
1073
- int dtls1_write_bytes(SSL *ssl, int type, const void *buf, int len,
1074
- enum dtls1_use_epoch_t use_epoch);
1075
1404
 
1076
- int dtls1_send_change_cipher_spec(SSL *ssl, int a, int b);
1405
+ /* dtls1_write_record sends a record. It returns one on success and <= 0 on
1406
+ * error. */
1407
+ int dtls1_write_record(SSL *ssl, int type, const uint8_t *buf, size_t len,
1408
+ enum dtls1_use_epoch_t use_epoch);
1409
+
1410
+ int dtls1_send_change_cipher_spec(SSL *ssl);
1077
1411
  int dtls1_send_finished(SSL *ssl, int a, int b, const char *sender, int slen);
1078
- int dtls1_read_failed(SSL *ssl, int code);
1079
- int dtls1_buffer_message(SSL *ssl);
1080
- int dtls1_retransmit_buffered_messages(SSL *ssl);
1412
+ int dtls1_retransmit_outgoing_messages(SSL *ssl);
1081
1413
  void dtls1_clear_record_buffer(SSL *ssl);
1082
- void dtls1_get_message_header(uint8_t *data, struct hm_header_st *msg_hdr);
1414
+ int dtls1_parse_fragment(CBS *cbs, struct hm_header_st *out_hdr,
1415
+ CBS *out_body);
1083
1416
  int dtls1_check_timeout_num(SSL *ssl);
1084
- int dtls1_set_handshake_header(SSL *ssl, int type, unsigned long len);
1085
1417
  int dtls1_handshake_write(SSL *ssl);
1418
+ void dtls1_expect_flight(SSL *ssl);
1419
+ void dtls1_received_flight(SSL *ssl);
1086
1420
 
1087
1421
  int dtls1_supports_cipher(const SSL_CIPHER *cipher);
1088
1422
  void dtls1_start_timer(SSL *ssl);
@@ -1090,49 +1424,22 @@ void dtls1_stop_timer(SSL *ssl);
1090
1424
  int dtls1_is_timer_expired(SSL *ssl);
1091
1425
  void dtls1_double_timeout(SSL *ssl);
1092
1426
  unsigned int dtls1_min_mtu(void);
1093
- void dtls1_hm_fragment_free(hm_fragment *frag);
1094
-
1095
- /* some client-only functions */
1096
- int ssl3_send_client_hello(SSL *ssl);
1097
- int ssl3_get_server_hello(SSL *ssl);
1098
- int ssl3_get_certificate_request(SSL *ssl);
1099
- int ssl3_get_new_session_ticket(SSL *ssl);
1100
- int ssl3_get_cert_status(SSL *ssl);
1101
- int ssl3_get_server_done(SSL *ssl);
1102
- int ssl3_send_cert_verify(SSL *ssl);
1103
- int ssl3_send_client_certificate(SSL *ssl);
1104
- int ssl_do_client_cert_cb(SSL *ssl, X509 **px509, EVP_PKEY **ppkey);
1105
- int ssl3_send_client_key_exchange(SSL *ssl);
1106
- int ssl3_get_server_key_exchange(SSL *ssl);
1107
- int ssl3_get_server_certificate(SSL *ssl);
1108
- int ssl3_send_next_proto(SSL *ssl);
1109
- int ssl3_send_channel_id(SSL *ssl);
1110
- int ssl3_verify_server_cert(SSL *ssl);
1111
-
1112
- /* some server-only functions */
1113
- int ssl3_get_initial_bytes(SSL *ssl);
1114
- int ssl3_get_v2_client_hello(SSL *ssl);
1115
- int ssl3_get_client_hello(SSL *ssl);
1116
- int ssl3_send_server_hello(SSL *ssl);
1117
- int ssl3_send_server_key_exchange(SSL *ssl);
1118
- int ssl3_send_certificate_request(SSL *ssl);
1119
- int ssl3_send_server_done(SSL *ssl);
1120
- int ssl3_get_client_certificate(SSL *ssl);
1121
- int ssl3_get_client_key_exchange(SSL *ssl);
1122
- int ssl3_get_cert_verify(SSL *ssl);
1123
- int ssl3_get_next_proto(SSL *ssl);
1124
- int ssl3_get_channel_id(SSL *ssl);
1125
1427
 
1126
1428
  int dtls1_new(SSL *ssl);
1127
1429
  int dtls1_accept(SSL *ssl);
1128
1430
  int dtls1_connect(SSL *ssl);
1129
1431
  void dtls1_free(SSL *ssl);
1130
1432
 
1131
- long dtls1_get_message(SSL *ssl, int st1, int stn, int mt, long max,
1132
- enum ssl_hash_message_t hash_message, int *ok);
1433
+ int dtls1_get_message(SSL *ssl, int mt, enum ssl_hash_message_t hash_message);
1434
+ int dtls1_hash_current_message(SSL *ssl);
1435
+ void dtls1_release_current_message(SSL *ssl, int free_buffer);
1133
1436
  int dtls1_dispatch_alert(SSL *ssl);
1134
1437
 
1135
- int ssl_init_wbio_buffer(SSL *ssl, int push);
1438
+ /* ssl_is_wbio_buffered returns one if |ssl|'s write BIO is buffered and zero
1439
+ * otherwise. */
1440
+ int ssl_is_wbio_buffered(const SSL *ssl);
1441
+
1442
+ int ssl_init_wbio_buffer(SSL *ssl);
1136
1443
  void ssl_free_wbio_buffer(SSL *ssl);
1137
1444
 
1138
1445
  int tls1_change_cipher_state(SSL *ssl, int which);
@@ -1141,23 +1448,28 @@ int tls1_handshake_digest(SSL *ssl, uint8_t *out, size_t out_len);
1141
1448
  int tls1_generate_master_secret(SSL *ssl, uint8_t *out, const uint8_t *premaster,
1142
1449
  size_t premaster_len);
1143
1450
 
1144
- char ssl_early_callback_init(struct ssl_early_callback_ctx *ctx);
1451
+ /* tls1_get_grouplist sets |*out_group_ids| and |*out_group_ids_len| to the
1452
+ * list of allowed group IDs. If |get_peer_groups| is non-zero, return the
1453
+ * peer's group list. Otherwise, return the preferred list. */
1454
+ void tls1_get_grouplist(SSL *ssl, int get_peer_groups,
1455
+ const uint16_t **out_group_ids,
1456
+ size_t *out_group_ids_len);
1145
1457
 
1146
- /* tls1_check_curve_id returns one if |curve_id| is consistent with both our
1147
- * and the peer's curve preferences. Note: if called as the client, only our
1458
+ /* tls1_check_group_id returns one if |group_id| is consistent with both our
1459
+ * and the peer's group preferences. Note: if called as the client, only our
1148
1460
  * preferences are checked; the peer (the server) does not send preferences. */
1149
- int tls1_check_curve_id(SSL *ssl, uint16_t curve_id);
1461
+ int tls1_check_group_id(SSL *ssl, uint16_t group_id);
1150
1462
 
1151
- /* tls1_get_shared_curve sets |*out_curve_id| to the first preferred shared
1152
- * curve between client and server preferences and returns one. If none may be
1463
+ /* tls1_get_shared_group sets |*out_group_id| to the first preferred shared
1464
+ * group between client and server preferences and returns one. If none may be
1153
1465
  * found, it returns zero. */
1154
- int tls1_get_shared_curve(SSL *ssl, uint16_t *out_curve_id);
1466
+ int tls1_get_shared_group(SSL *ssl, uint16_t *out_group_id);
1155
1467
 
1156
1468
  /* tls1_set_curves converts the array of |ncurves| NIDs pointed to by |curves|
1157
- * into a newly allocated array of TLS curve IDs. On success, the function
1158
- * returns one and writes the array to |*out_curve_ids| and its size to
1159
- * |*out_curve_ids_len|. Otherwise, it returns zero. */
1160
- int tls1_set_curves(uint16_t **out_curve_ids, size_t *out_curve_ids_len,
1469
+ * into a newly allocated array of TLS group IDs. On success, the function
1470
+ * returns one and writes the array to |*out_group_ids| and its size to
1471
+ * |*out_group_ids_len|. Otherwise, it returns zero. */
1472
+ int tls1_set_curves(uint16_t **out_group_ids, size_t *out_group_ids_len,
1161
1473
  const int *curves, size_t ncurves);
1162
1474
 
1163
1475
  /* tls1_check_ec_cert returns one if |x| is an ECC certificate with curve and
@@ -1172,7 +1484,8 @@ int tls1_check_ec_cert(SSL *ssl, X509 *x);
1172
1484
  int ssl_add_clienthello_tlsext(SSL *ssl, CBB *out, size_t header_len);
1173
1485
 
1174
1486
  int ssl_add_serverhello_tlsext(SSL *ssl, CBB *out);
1175
- int ssl_parse_clienthello_tlsext(SSL *ssl, CBS *cbs);
1487
+ int ssl_parse_clienthello_tlsext(
1488
+ SSL *ssl, const struct ssl_early_callback_ctx *client_hello);
1176
1489
  int ssl_parse_serverhello_tlsext(SSL *ssl, CBS *cbs);
1177
1490
 
1178
1491
  #define tlsext_tick_md EVP_sha256
@@ -1187,14 +1500,6 @@ int tls_process_ticket(SSL *ssl, SSL_SESSION **out_session,
1187
1500
  size_t ticket_len, const uint8_t *session_id,
1188
1501
  size_t session_id_len);
1189
1502
 
1190
- /* tls12_add_sigandhash assembles the SignatureAndHashAlgorithm corresponding to
1191
- * |ssl|'s private key and |md|. The two-byte value is written to |out|. It
1192
- * returns one on success and zero on failure. */
1193
- int tls12_add_sigandhash(SSL *ssl, CBB *out, const EVP_MD *md);
1194
-
1195
- int tls12_get_sigid(int pkey_type);
1196
- const EVP_MD *tls12_get_hash(uint8_t hash_alg);
1197
-
1198
1503
  /* tls1_channel_id_hash computes the hash to be signed by Channel ID and writes
1199
1504
  * it to |out|, which must contain at least |EVP_MAX_MD_SIZE| bytes. It returns
1200
1505
  * one on success and zero on failure. */
@@ -1202,22 +1507,6 @@ int tls1_channel_id_hash(SSL *ssl, uint8_t *out, size_t *out_len);
1202
1507
 
1203
1508
  int tls1_record_handshake_hashes_for_channel_id(SSL *ssl);
1204
1509
 
1205
- /* ssl_log_rsa_client_key_exchange logs |premaster|, if logging is enabled for
1206
- * |ssl|. It returns one on success and zero on failure. The entry is identified
1207
- * by the first 8 bytes of |encrypted_premaster|. */
1208
- int ssl_log_rsa_client_key_exchange(const SSL *ssl,
1209
- const uint8_t *encrypted_premaster,
1210
- size_t encrypted_premaster_len,
1211
- const uint8_t *premaster,
1212
- size_t premaster_len);
1213
-
1214
- /* ssl_log_master_secret logs |master|, if logging is enabled for |ssl|. It
1215
- * returns one on success and zero on failure. The entry is identified by
1216
- * |client_random|. */
1217
- int ssl_log_master_secret(const SSL *ssl, const uint8_t *client_random,
1218
- size_t client_random_len, const uint8_t *master,
1219
- size_t master_len);
1220
-
1221
1510
  /* ssl3_can_false_start returns one if |ssl| is allowed to False Start and zero
1222
1511
  * otherwise. */
1223
1512
  int ssl3_can_false_start(const SSL *ssl);
@@ -1226,33 +1515,10 @@ int ssl3_can_false_start(const SSL *ssl);
1226
1515
  * |version|. */
1227
1516
  const SSL3_ENC_METHOD *ssl3_get_enc_method(uint16_t version);
1228
1517
 
1229
- /* ssl3_get_max_server_version returns the maximum SSL/TLS version number
1230
- * supported by |ssl| as a server, or zero if all versions are disabled. */
1231
- uint16_t ssl3_get_max_server_version(const SSL *ssl);
1232
-
1233
- /* ssl3_get_mutual_version selects the protocol version on |ssl| for a client
1234
- * which advertises |client_version|. If no suitable version exists, it returns
1235
- * zero. */
1236
- uint16_t ssl3_get_mutual_version(SSL *ssl, uint16_t client_version);
1237
-
1238
- /* ssl3_get_max_client_version returns the maximum protocol version configured
1239
- * for the client. It is guaranteed that the set of allowed versions at or below
1240
- * this maximum version is contiguous. If all versions are disabled, it returns
1241
- * zero. */
1242
- uint16_t ssl3_get_max_client_version(SSL *ssl);
1243
-
1244
- /* ssl3_is_version_enabled returns one if |version| is an enabled protocol
1245
- * version for |ssl| and zero otherwise. */
1246
- int ssl3_is_version_enabled(SSL *ssl, uint16_t version);
1247
-
1248
- /* ssl3_version_from_wire maps |wire_version| to a protocol version. For
1249
- * SSLv3/TLS, the version is returned as-is. For DTLS, the corresponding TLS
1250
- * version is used. Note that this mapping is not injective but preserves
1251
- * comparisons.
1252
- *
1253
- * TODO(davidben): To normalize some DTLS-specific code, move away from using
1254
- * the wire version except at API boundaries. */
1255
- uint16_t ssl3_version_from_wire(const SSL *ssl, uint16_t wire_version);
1518
+ /* ssl_get_version_range sets |*out_min_version| and |*out_max_version| to the
1519
+ * minimum and maximum enabled protocol versions, respectively. */
1520
+ int ssl_get_version_range(const SSL *ssl, uint16_t *out_min_version,
1521
+ uint16_t *out_max_version);
1256
1522
 
1257
1523
  /* ssl3_protocol_version returns |ssl|'s protocol version. It is an error to
1258
1524
  * call this function before the version is determined. */
@@ -1261,18 +1527,25 @@ uint16_t ssl3_protocol_version(const SSL *ssl);
1261
1527
  uint32_t ssl_get_algorithm_prf(const SSL *ssl);
1262
1528
  int tls1_parse_peer_sigalgs(SSL *ssl, const CBS *sigalgs);
1263
1529
 
1264
- /* tls1_choose_signing_digest returns a digest for use with |ssl|'s private key
1265
- * based on the peer's preferences the digests supported. */
1266
- const EVP_MD *tls1_choose_signing_digest(SSL *ssl);
1530
+ /* tls1_choose_signature_algorithm sets |*out| to a signature algorithm for use
1531
+ * with |ssl|'s private key based on the peer's preferences and the digests
1532
+ * supported. It returns one on success and zero on error. */
1533
+ int tls1_choose_signature_algorithm(SSL *ssl, uint16_t *out);
1267
1534
 
1268
- size_t tls12_get_psigalgs(SSL *ssl, const uint8_t **psigs);
1535
+ size_t tls12_get_psigalgs(SSL *ssl, const uint16_t **psigs);
1269
1536
 
1270
- /* tls12_check_peer_sigalg checks that |hash| and |signature| are consistent
1271
- * with |pkey| and |ssl|'s sent, supported signature algorithms and, if so,
1272
- * writes the relevant digest into |*out_md| and returns 1. Otherwise it
1537
+ /* tls12_check_peer_sigalg checks that |signature_algorithm| is consistent with
1538
+ * |ssl|'s sent, supported signature algorithms and returns 1. Otherwise it
1273
1539
  * returns 0 and writes an alert into |*out_alert|. */
1274
- int tls12_check_peer_sigalg(SSL *ssl, const EVP_MD **out_md, int *out_alert,
1275
- uint8_t hash, uint8_t signature, EVP_PKEY *pkey);
1540
+ int tls12_check_peer_sigalg(SSL *ssl, int *out_alert,
1541
+ uint16_t signature_algorithm);
1276
1542
  void ssl_set_client_disabled(SSL *ssl);
1277
1543
 
1544
+ void ssl_get_current_time(const SSL *ssl, struct timeval *out_clock);
1545
+
1546
+
1547
+ #if defined(__cplusplus)
1548
+ } /* extern C */
1549
+ #endif
1550
+
1278
1551
  #endif /* OPENSSL_HEADER_SSL_INTERNAL_H */