grpc 1.9.1 → 1.10.0.pre1

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

Potentially problematic release.


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

Files changed (637) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +2654 -953
  3. data/etc/roots.pem +282 -683
  4. data/include/grpc/compression.h +9 -26
  5. data/include/grpc/grpc.h +10 -24
  6. data/include/grpc/grpc_security.h +7 -1
  7. data/include/grpc/impl/codegen/compression_types.h +5 -62
  8. data/include/grpc/impl/codegen/grpc_types.h +10 -6
  9. data/include/grpc/module.modulemap +1 -10
  10. data/include/grpc/support/alloc.h +3 -2
  11. data/include/grpc/support/log.h +1 -2
  12. data/{src/core/lib/gpr/thd_internal.h → include/grpc/support/thd_id.h} +23 -9
  13. data/src/boringssl/err_data.c +550 -496
  14. data/src/core/ext/census/grpc_context.cc +2 -1
  15. data/src/core/ext/filters/client_channel/backup_poller.cc +5 -4
  16. data/src/core/ext/filters/client_channel/channel_connectivity.cc +7 -7
  17. data/src/core/ext/filters/client_channel/client_channel.cc +162 -172
  18. data/src/core/ext/filters/client_channel/client_channel_factory.cc +4 -2
  19. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +10 -10
  20. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +18 -14
  21. data/src/core/ext/filters/client_channel/http_proxy.cc +3 -1
  22. data/src/core/ext/filters/client_channel/lb_policy.cc +21 -105
  23. data/src/core/ext/filters/client_channel/lb_policy.h +166 -170
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +41 -36
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +1452 -1459
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +7 -8
  29. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +27 -27
  30. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +279 -304
  31. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +358 -330
  32. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.cc +30 -41
  33. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +7 -14
  34. data/src/core/ext/filters/client_channel/lb_policy_factory.cc +8 -21
  35. data/src/core/ext/filters/client_channel/lb_policy_factory.h +23 -27
  36. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +58 -33
  37. data/src/core/ext/filters/client_channel/lb_policy_registry.h +25 -12
  38. data/src/core/ext/filters/client_channel/parse_address.cc +10 -8
  39. data/src/core/ext/filters/client_channel/proxy_mapper_registry.cc +2 -2
  40. data/src/core/ext/filters/client_channel/resolver.cc +6 -52
  41. data/src/core/ext/filters/client_channel/resolver.h +98 -55
  42. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +266 -237
  43. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +5 -5
  44. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +31 -27
  45. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +244 -207
  46. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +161 -148
  47. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +47 -31
  48. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +126 -126
  49. data/src/core/ext/filters/client_channel/resolver_factory.h +33 -32
  50. data/src/core/ext/filters/client_channel/resolver_registry.cc +110 -90
  51. data/src/core/ext/filters/client_channel/resolver_registry.h +49 -36
  52. data/src/core/ext/filters/client_channel/retry_throttle.cc +29 -22
  53. data/src/core/ext/filters/client_channel/subchannel.cc +173 -173
  54. data/src/core/ext/filters/client_channel/subchannel.h +38 -45
  55. data/src/core/ext/filters/client_channel/subchannel_index.cc +44 -40
  56. data/src/core/ext/filters/client_channel/uri_parser.cc +3 -3
  57. data/src/core/ext/filters/deadline/deadline_filter.cc +27 -18
  58. data/src/core/ext/filters/http/client/http_client_filter.cc +26 -23
  59. data/src/core/ext/filters/http/http_filters_plugin.cc +3 -2
  60. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +78 -110
  61. data/src/core/ext/filters/http/server/http_server_filter.cc +29 -26
  62. data/src/core/ext/filters/load_reporting/server_load_reporting_filter.cc +9 -11
  63. data/src/core/ext/filters/load_reporting/server_load_reporting_plugin.cc +2 -1
  64. data/src/core/ext/filters/max_age/max_age_filter.cc +14 -14
  65. data/src/core/ext/filters/message_size/message_size_filter.cc +20 -18
  66. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +4 -4
  67. data/src/core/ext/filters/workarounds/workaround_utils.cc +4 -4
  68. data/src/core/ext/transport/chttp2/alpn/alpn.cc +2 -1
  69. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +10 -10
  70. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +4 -4
  71. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +11 -12
  72. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +16 -13
  73. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +36 -9
  74. data/src/core/ext/transport/chttp2/transport/bin_decoder.h +3 -0
  75. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +17 -14
  76. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +139 -145
  77. data/src/core/ext/transport/chttp2/transport/flow_control.cc +16 -14
  78. data/src/core/ext/transport/chttp2/transport/flow_control.h +8 -7
  79. data/src/core/ext/transport/chttp2/transport/frame_data.cc +35 -33
  80. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +27 -25
  81. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +12 -12
  82. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +16 -15
  83. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +19 -19
  84. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +11 -11
  85. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +23 -22
  86. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +35 -35
  87. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +10 -7
  88. data/src/core/ext/transport/chttp2/transport/http2_settings.cc +2 -2
  89. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +2 -2
  90. data/src/core/ext/transport/chttp2/transport/internal.h +1 -1
  91. data/src/core/ext/transport/chttp2/transport/parsing.cc +35 -39
  92. data/src/core/ext/transport/chttp2/transport/stream_map.cc +8 -7
  93. data/src/core/ext/transport/chttp2/transport/varint.cc +5 -5
  94. data/src/core/ext/transport/chttp2/transport/writing.cc +18 -18
  95. data/src/core/ext/transport/inproc/inproc_transport.cc +43 -23
  96. data/src/core/lib/{gpr → avl}/avl.cc +61 -57
  97. data/{include/grpc/support → src/core/lib/avl}/avl.h +25 -35
  98. data/src/core/lib/backoff/backoff.cc +6 -5
  99. data/src/core/lib/channel/channel_args.cc +23 -109
  100. data/src/core/lib/channel/channel_args.h +5 -31
  101. data/src/core/lib/channel/channel_stack.cc +11 -8
  102. data/src/core/lib/channel/channel_stack_builder.cc +10 -7
  103. data/src/core/lib/channel/connected_channel.cc +18 -17
  104. data/src/core/lib/channel/handshaker.cc +8 -8
  105. data/src/core/lib/channel/handshaker_registry.cc +3 -2
  106. data/src/core/lib/compression/algorithm_metadata.h +13 -6
  107. data/src/core/lib/compression/compression.cc +72 -183
  108. data/src/core/lib/compression/compression_internal.cc +274 -0
  109. data/src/core/lib/compression/compression_internal.h +86 -0
  110. data/src/core/lib/compression/message_compress.cc +15 -15
  111. data/src/core/lib/compression/message_compress.h +4 -3
  112. data/src/core/lib/compression/stream_compression_gzip.cc +8 -8
  113. data/src/core/lib/compression/stream_compression_identity.cc +1 -1
  114. data/src/core/lib/debug/stats.cc +10 -8
  115. data/src/core/lib/debug/stats_data.cc +2 -1
  116. data/src/core/lib/debug/trace.cc +3 -3
  117. data/src/core/lib/gpr/alloc.cc +7 -11
  118. data/src/core/lib/gpr/arena.cc +34 -12
  119. data/src/core/lib/gpr/atm.cc +2 -1
  120. data/src/core/lib/gpr/cpu_linux.cc +3 -3
  121. data/src/core/lib/gpr/cpu_posix.cc +2 -1
  122. data/src/core/lib/gpr/env.h +1 -1
  123. data/src/core/lib/gpr/env_linux.cc +1 -1
  124. data/src/core/lib/gpr/env_windows.cc +4 -4
  125. data/src/core/lib/gpr/fork.cc +16 -2
  126. data/src/core/lib/gpr/host_port.cc +5 -4
  127. data/{include/grpc/support → src/core/lib/gpr}/host_port.h +5 -13
  128. data/src/core/lib/gpr/log.cc +5 -4
  129. data/src/core/lib/gpr/log_linux.cc +1 -1
  130. data/src/core/lib/gpr/mpscq.cc +1 -0
  131. data/src/core/lib/gpr/murmur_hash.cc +4 -4
  132. data/src/core/lib/gpr/string.cc +19 -16
  133. data/src/core/lib/gpr/string_posix.cc +3 -3
  134. data/src/core/lib/gpr/sync_posix.cc +5 -9
  135. data/src/core/lib/gpr/thd.cc +3 -3
  136. data/{include/grpc/support → src/core/lib/gpr}/thd.h +20 -28
  137. data/src/core/lib/gpr/thd_posix.cc +6 -4
  138. data/src/core/lib/gpr/thd_windows.cc +3 -1
  139. data/src/core/lib/gpr/time.cc +6 -4
  140. data/src/core/lib/gpr/time_posix.cc +2 -2
  141. data/{include/grpc/support → src/core/lib/gpr}/tls.h +6 -6
  142. data/{include/grpc/support → src/core/lib/gpr}/tls_gcc.h +3 -3
  143. data/{include/grpc/support → src/core/lib/gpr}/tls_msvc.h +3 -3
  144. data/src/core/lib/gpr/tls_pthread.cc +1 -1
  145. data/{include/grpc/support → src/core/lib/gpr}/tls_pthread.h +3 -3
  146. data/{include/grpc/support → src/core/lib/gpr}/useful.h +3 -3
  147. data/src/core/lib/{gpr++ → gprpp}/abstract.h +3 -3
  148. data/src/core/lib/{gpr++ → gprpp}/atomic.h +5 -5
  149. data/src/core/lib/{gpr++ → gprpp}/atomic_with_atm.h +3 -3
  150. data/src/core/lib/{gpr++ → gprpp}/atomic_with_std.h +3 -3
  151. data/src/core/lib/{gpr++ → gprpp}/debug_location.h +3 -3
  152. data/src/core/lib/{gpr++ → gprpp}/inlined_vector.h +44 -22
  153. data/src/core/lib/{gpr++ → gprpp}/manual_constructor.h +2 -2
  154. data/src/core/lib/{gpr++ → gprpp}/memory.h +14 -5
  155. data/src/core/lib/{gpr++ → gprpp}/orphanable.h +39 -14
  156. data/src/core/lib/{gpr++ → gprpp}/ref_counted.h +42 -10
  157. data/src/core/lib/{gpr++ → gprpp}/ref_counted_ptr.h +18 -8
  158. data/src/core/lib/http/format_request.cc +3 -3
  159. data/src/core/lib/http/httpcli.cc +6 -7
  160. data/src/core/lib/http/httpcli_security_connector.cc +10 -10
  161. data/src/core/lib/http/parser.cc +16 -12
  162. data/src/core/lib/iomgr/call_combiner.cc +12 -13
  163. data/src/core/lib/iomgr/closure.h +4 -6
  164. data/src/core/lib/iomgr/combiner.cc +10 -21
  165. data/src/core/lib/iomgr/error.cc +50 -55
  166. data/src/core/lib/iomgr/ev_epoll1_linux.cc +41 -52
  167. data/src/core/lib/iomgr/ev_epollex_linux.cc +80 -28
  168. data/src/core/lib/iomgr/ev_epollsig_linux.cc +23 -30
  169. data/src/core/lib/iomgr/ev_poll_posix.cc +52 -46
  170. data/src/core/lib/iomgr/ev_posix.cc +47 -6
  171. data/src/core/lib/iomgr/exec_ctx.cc +10 -10
  172. data/src/core/lib/iomgr/exec_ctx.h +1 -1
  173. data/src/core/lib/iomgr/executor.cc +16 -13
  174. data/src/core/lib/iomgr/fork_posix.cc +1 -3
  175. data/src/core/lib/iomgr/gethostname_host_name_max.cc +1 -1
  176. data/src/core/lib/iomgr/iocp_windows.cc +1 -2
  177. data/src/core/lib/iomgr/iomgr.cc +2 -2
  178. data/src/core/lib/iomgr/iomgr_uv.cc +2 -0
  179. data/src/core/lib/iomgr/iomgr_uv.h +1 -1
  180. data/src/core/lib/iomgr/is_epollexclusive_available.cc +5 -4
  181. data/src/core/lib/iomgr/load_file.cc +3 -3
  182. data/src/core/lib/iomgr/pollset_windows.cc +1 -1
  183. data/src/core/lib/iomgr/resolve_address_posix.cc +10 -9
  184. data/src/core/lib/iomgr/resolve_address_uv.cc +2 -2
  185. data/src/core/lib/iomgr/resolve_address_windows.cc +3 -2
  186. data/src/core/lib/iomgr/resource_quota.cc +36 -34
  187. data/src/core/lib/iomgr/sockaddr_utils.cc +39 -23
  188. data/src/core/lib/iomgr/socket_factory_posix.cc +5 -5
  189. data/src/core/lib/iomgr/socket_mutator.cc +7 -7
  190. data/src/core/lib/iomgr/socket_utils_common_posix.cc +7 -4
  191. data/src/core/lib/iomgr/socket_utils_linux.cc +3 -2
  192. data/src/core/lib/iomgr/tcp_client_posix.cc +7 -6
  193. data/src/core/lib/iomgr/tcp_client_windows.cc +0 -1
  194. data/src/core/lib/iomgr/tcp_posix.cc +47 -55
  195. data/src/core/lib/iomgr/tcp_server_posix.cc +12 -10
  196. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +7 -5
  197. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +4 -3
  198. data/src/core/lib/iomgr/tcp_windows.cc +1 -1
  199. data/src/core/lib/iomgr/timer_generic.cc +16 -14
  200. data/src/core/lib/iomgr/timer_heap.cc +8 -7
  201. data/src/core/lib/iomgr/timer_manager.cc +4 -3
  202. data/src/core/lib/iomgr/udp_server.cc +24 -16
  203. data/src/core/lib/iomgr/unix_sockets_posix.cc +15 -10
  204. data/src/core/lib/iomgr/wakeup_fd_cv.cc +6 -5
  205. data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +1 -2
  206. data/src/core/lib/json/json.cc +1 -1
  207. data/src/core/lib/json/json_reader.cc +8 -6
  208. data/src/core/lib/json/json_string.cc +19 -18
  209. data/src/core/lib/json/json_writer.cc +10 -8
  210. data/src/core/lib/profiling/basic_timers.cc +1 -1
  211. data/src/core/lib/profiling/timers.h +3 -20
  212. data/src/core/lib/security/context/security_context.cc +16 -14
  213. data/src/core/lib/security/credentials/composite/composite_credentials.cc +17 -14
  214. data/src/core/lib/security/credentials/credentials.cc +9 -8
  215. data/src/core/lib/security/credentials/credentials.h +1 -1
  216. data/src/core/lib/security/credentials/credentials_metadata.cc +2 -2
  217. data/src/core/lib/security/credentials/fake/fake_credentials.cc +12 -13
  218. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +7 -4
  219. data/src/core/lib/security/credentials/iam/iam_credentials.cc +5 -3
  220. data/src/core/lib/security/credentials/jwt/json_token.cc +4 -3
  221. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +7 -7
  222. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +21 -18
  223. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +23 -18
  224. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +11 -7
  225. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +22 -21
  226. data/src/core/lib/security/{transport → security_connector}/security_connector.cc +46 -43
  227. data/src/core/lib/security/{transport → security_connector}/security_connector.h +3 -3
  228. data/src/core/lib/security/transport/client_auth_filter.cc +32 -34
  229. data/src/core/lib/security/transport/lb_targets_info.cc +7 -5
  230. data/src/core/lib/security/transport/secure_endpoint.cc +21 -21
  231. data/src/core/lib/security/transport/security_handshaker.cc +19 -18
  232. data/src/core/lib/security/transport/security_handshaker.h +1 -1
  233. data/src/core/lib/security/transport/server_auth_filter.cc +21 -21
  234. data/src/core/lib/slice/b64.cc +19 -16
  235. data/src/core/lib/slice/percent_encoding.cc +5 -5
  236. data/src/core/lib/slice/slice.cc +35 -33
  237. data/src/core/lib/slice/slice_buffer.cc +16 -14
  238. data/src/core/lib/slice/slice_hash_table.cc +3 -2
  239. data/src/core/lib/slice/slice_intern.cc +21 -25
  240. data/src/core/lib/slice/slice_string_helpers.cc +45 -9
  241. data/src/core/lib/slice/slice_string_helpers.h +6 -0
  242. data/src/core/lib/surface/byte_buffer.cc +2 -2
  243. data/src/core/lib/surface/byte_buffer_reader.cc +6 -3
  244. data/src/core/lib/surface/call.cc +171 -260
  245. data/src/core/lib/surface/call_test_only.h +1 -13
  246. data/src/core/lib/surface/channel.cc +20 -43
  247. data/src/core/lib/surface/channel_init.cc +7 -7
  248. data/src/core/lib/surface/channel_ping.cc +2 -2
  249. data/src/core/lib/surface/completion_queue.cc +69 -75
  250. data/src/core/lib/surface/init.cc +4 -5
  251. data/src/core/lib/surface/init_secure.cc +1 -1
  252. data/src/core/lib/surface/lame_client.cc +1 -1
  253. data/src/core/lib/surface/server.cc +64 -59
  254. data/src/core/lib/surface/version.cc +2 -2
  255. data/src/core/lib/transport/bdp_estimator.cc +6 -5
  256. data/src/core/lib/transport/byte_stream.cc +23 -14
  257. data/src/core/lib/transport/byte_stream.h +1 -1
  258. data/src/core/lib/transport/connectivity_state.cc +9 -13
  259. data/src/core/lib/transport/error_utils.cc +10 -7
  260. data/src/core/lib/transport/metadata.cc +27 -26
  261. data/src/core/lib/transport/metadata.h +1 -1
  262. data/src/core/lib/transport/pid_controller.cc +2 -1
  263. data/src/core/lib/transport/service_config.cc +5 -5
  264. data/src/core/lib/transport/static_metadata.cc +225 -222
  265. data/src/core/lib/transport/static_metadata.h +77 -76
  266. data/src/core/lib/transport/timeout_encoding.cc +3 -2
  267. data/src/core/lib/transport/transport.cc +6 -5
  268. data/src/core/lib/transport/transport_op_string.cc +0 -1
  269. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -4
  270. data/src/core/tsi/alts_transport_security.cc +61 -0
  271. data/src/core/tsi/{gts_transport_security.h → alts_transport_security.h} +16 -8
  272. data/src/core/tsi/fake_transport_security.cc +59 -43
  273. data/src/core/tsi/ssl_transport_security.cc +122 -107
  274. data/src/core/tsi/transport_security.cc +3 -3
  275. data/src/core/tsi/transport_security_adapter.cc +16 -10
  276. data/src/ruby/bin/apis/pubsub_demo.rb +1 -1
  277. data/src/ruby/ext/grpc/rb_channel.c +3 -4
  278. data/src/ruby/ext/grpc/rb_compression_options.c +13 -3
  279. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -76
  280. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +8 -120
  281. data/src/ruby/ext/grpc/rb_server.c +52 -28
  282. data/src/ruby/lib/grpc/generic/rpc_server.rb +7 -4
  283. data/src/ruby/lib/grpc/version.rb +1 -1
  284. data/src/ruby/pb/test/client.rb +1 -1
  285. data/src/ruby/pb/test/server.rb +1 -1
  286. data/src/ruby/spec/client_server_spec.rb +4 -2
  287. data/src/ruby/spec/generic/active_call_spec.rb +2 -1
  288. data/src/ruby/spec/generic/client_stub_spec.rb +32 -8
  289. data/src/ruby/spec/server_spec.rb +26 -7
  290. data/third_party/boringssl/crypto/asn1/a_bitstr.c +7 -2
  291. data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +15 -0
  292. data/third_party/boringssl/crypto/asn1/a_gentm.c +1 -1
  293. data/third_party/boringssl/crypto/asn1/a_print.c +0 -28
  294. data/third_party/boringssl/crypto/asn1/a_strnid.c +3 -0
  295. data/third_party/boringssl/crypto/asn1/a_time.c +17 -9
  296. data/third_party/boringssl/crypto/asn1/a_utctm.c +1 -1
  297. data/third_party/boringssl/crypto/asn1/asn1_lib.c +5 -49
  298. data/third_party/boringssl/crypto/asn1/asn1_locl.h +1 -1
  299. data/third_party/boringssl/crypto/asn1/tasn_dec.c +9 -9
  300. data/third_party/boringssl/crypto/asn1/tasn_enc.c +0 -6
  301. data/third_party/boringssl/crypto/asn1/time_support.c +5 -5
  302. data/third_party/boringssl/crypto/base64/base64.c +65 -43
  303. data/third_party/boringssl/crypto/bio/bio.c +134 -110
  304. data/third_party/boringssl/crypto/bio/bio_mem.c +9 -9
  305. data/third_party/boringssl/crypto/bio/connect.c +17 -17
  306. data/third_party/boringssl/crypto/bio/fd.c +2 -1
  307. data/third_party/boringssl/crypto/bio/file.c +14 -14
  308. data/third_party/boringssl/crypto/bio/hexdump.c +15 -16
  309. data/third_party/boringssl/crypto/bio/internal.h +14 -14
  310. data/third_party/boringssl/crypto/bio/pair.c +45 -45
  311. data/third_party/boringssl/crypto/bio/printf.c +6 -10
  312. data/third_party/boringssl/crypto/{bn → bn_extra}/bn_asn1.c +9 -9
  313. data/third_party/boringssl/crypto/{bn → bn_extra}/convert.c +18 -223
  314. data/third_party/boringssl/crypto/buf/buf.c +20 -44
  315. data/third_party/boringssl/crypto/bytestring/ber.c +35 -35
  316. data/third_party/boringssl/crypto/bytestring/cbb.c +24 -24
  317. data/third_party/boringssl/crypto/bytestring/cbs.c +33 -37
  318. data/third_party/boringssl/crypto/bytestring/internal.h +38 -38
  319. data/third_party/boringssl/crypto/chacha/chacha.c +7 -7
  320. data/third_party/boringssl/crypto/{asn1/t_bitst.c → cipher_extra/cipher_extra.c} +49 -38
  321. data/third_party/boringssl/crypto/{cipher → cipher_extra}/derive_key.c +0 -2
  322. data/third_party/boringssl/crypto/cipher_extra/e_aesctrhmac.c +281 -0
  323. data/third_party/boringssl/crypto/cipher_extra/e_aesgcmsiv.c +867 -0
  324. data/third_party/boringssl/crypto/cipher_extra/e_chacha20poly1305.c +326 -0
  325. data/third_party/boringssl/crypto/{cipher → cipher_extra}/e_null.c +0 -1
  326. data/third_party/boringssl/crypto/{cipher → cipher_extra}/e_rc2.c +22 -10
  327. data/third_party/boringssl/crypto/{cipher → cipher_extra}/e_rc4.c +0 -0
  328. data/third_party/boringssl/crypto/{cipher → cipher_extra}/e_ssl3.c +120 -64
  329. data/third_party/boringssl/crypto/{cipher → cipher_extra}/e_tls.c +220 -141
  330. data/third_party/boringssl/crypto/{asn1/x_bignum.c → cipher_extra/internal.h} +61 -86
  331. data/third_party/boringssl/crypto/cipher_extra/tls_cbc.c +482 -0
  332. data/third_party/boringssl/crypto/cmac/cmac.c +20 -20
  333. data/third_party/boringssl/crypto/conf/conf.c +32 -20
  334. data/third_party/boringssl/crypto/conf/internal.h +3 -3
  335. data/third_party/boringssl/crypto/cpu-aarch64-linux.c +5 -5
  336. data/third_party/boringssl/crypto/cpu-arm-linux.c +44 -41
  337. data/third_party/boringssl/crypto/cpu-intel.c +68 -43
  338. data/third_party/boringssl/crypto/cpu-ppc64le.c +5 -7
  339. data/third_party/boringssl/crypto/crypto.c +54 -32
  340. data/third_party/boringssl/crypto/curve25519/curve25519.c +269 -269
  341. data/third_party/boringssl/crypto/curve25519/internal.h +28 -8
  342. data/third_party/boringssl/crypto/curve25519/spake25519.c +180 -106
  343. data/third_party/boringssl/crypto/curve25519/x25519-x86_64.c +9 -9
  344. data/third_party/boringssl/crypto/dh/check.c +33 -34
  345. data/third_party/boringssl/crypto/dh/dh.c +72 -36
  346. data/third_party/boringssl/crypto/dh/dh_asn1.c +1 -1
  347. data/third_party/boringssl/crypto/dh/params.c +1 -161
  348. data/third_party/boringssl/crypto/digest_extra/digest_extra.c +240 -0
  349. data/third_party/boringssl/crypto/dsa/dsa.c +127 -87
  350. data/third_party/boringssl/crypto/dsa/dsa_asn1.c +1 -1
  351. data/third_party/boringssl/crypto/{ec → ec_extra}/ec_asn1.c +83 -70
  352. data/third_party/boringssl/crypto/ecdh/ecdh.c +1 -1
  353. data/third_party/boringssl/crypto/{ecdsa → ecdsa_extra}/ecdsa_asn1.c +86 -31
  354. data/third_party/boringssl/crypto/engine/engine.c +6 -6
  355. data/third_party/boringssl/crypto/err/err.c +197 -106
  356. data/third_party/boringssl/crypto/err/internal.h +58 -0
  357. data/third_party/boringssl/crypto/evp/digestsign.c +86 -14
  358. data/third_party/boringssl/crypto/evp/evp.c +6 -11
  359. data/third_party/boringssl/crypto/evp/evp_asn1.c +17 -17
  360. data/third_party/boringssl/crypto/evp/evp_ctx.c +15 -11
  361. data/third_party/boringssl/crypto/evp/internal.h +66 -51
  362. data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +11 -11
  363. data/third_party/boringssl/crypto/evp/p_ec.c +10 -8
  364. data/third_party/boringssl/crypto/evp/p_ec_asn1.c +11 -12
  365. data/third_party/boringssl/crypto/evp/p_ed25519.c +71 -0
  366. data/third_party/boringssl/crypto/evp/p_ed25519_asn1.c +190 -0
  367. data/third_party/boringssl/crypto/evp/p_rsa.c +50 -95
  368. data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +28 -18
  369. data/third_party/boringssl/crypto/evp/pbkdf.c +49 -56
  370. data/third_party/boringssl/crypto/evp/print.c +5 -36
  371. data/third_party/boringssl/crypto/evp/scrypt.c +209 -0
  372. data/third_party/boringssl/crypto/ex_data.c +15 -45
  373. data/third_party/boringssl/crypto/fipsmodule/aes/internal.h +100 -0
  374. data/third_party/boringssl/crypto/fipsmodule/bcm.c +679 -0
  375. data/third_party/boringssl/crypto/{bn → fipsmodule/bn}/internal.h +40 -27
  376. data/third_party/boringssl/crypto/{bn → fipsmodule/bn}/rsaz_exp.h +0 -0
  377. data/third_party/boringssl/crypto/{cipher → fipsmodule/cipher}/internal.h +34 -67
  378. data/third_party/boringssl/crypto/fipsmodule/delocate.h +88 -0
  379. data/third_party/boringssl/crypto/{des → fipsmodule/des}/internal.h +18 -4
  380. data/third_party/boringssl/crypto/{digest → fipsmodule/digest}/internal.h +18 -18
  381. data/third_party/boringssl/crypto/{digest → fipsmodule/digest}/md32_common.h +58 -64
  382. data/third_party/boringssl/crypto/{ec → fipsmodule/ec}/internal.h +58 -52
  383. data/third_party/boringssl/crypto/{ec → fipsmodule/ec}/p256-x86_64-table.h +11 -11
  384. data/third_party/boringssl/crypto/{ec → fipsmodule/ec}/p256-x86_64.h +32 -32
  385. data/third_party/boringssl/crypto/{rand/internal.h → fipsmodule/is_fips.c} +10 -15
  386. data/third_party/boringssl/crypto/{modes → fipsmodule/modes}/internal.h +112 -119
  387. data/third_party/boringssl/crypto/fipsmodule/rand/internal.h +92 -0
  388. data/third_party/boringssl/crypto/{rsa → fipsmodule/rsa}/internal.h +36 -49
  389. data/third_party/boringssl/crypto/hkdf/hkdf.c +6 -6
  390. data/third_party/boringssl/crypto/internal.h +301 -233
  391. data/third_party/boringssl/crypto/lhash/lhash.c +26 -45
  392. data/third_party/boringssl/crypto/mem.c +76 -33
  393. data/third_party/boringssl/crypto/obj/obj.c +44 -28
  394. data/third_party/boringssl/crypto/obj/obj_dat.h +102 -34
  395. data/third_party/boringssl/crypto/obj/obj_xref.c +6 -6
  396. data/third_party/boringssl/crypto/pem/pem_info.c +3 -5
  397. data/third_party/boringssl/crypto/pem/pem_lib.c +1 -6
  398. data/third_party/boringssl/crypto/pem/pem_pk8.c +1 -0
  399. data/third_party/boringssl/crypto/pem/pem_pkey.c +1 -1
  400. data/third_party/boringssl/crypto/pem/pem_xaux.c +0 -2
  401. data/third_party/boringssl/crypto/pkcs7/internal.h +49 -0
  402. data/third_party/boringssl/crypto/pkcs7/pkcs7.c +166 -0
  403. data/third_party/boringssl/crypto/{x509/pkcs7.c → pkcs7/pkcs7_x509.c} +27 -147
  404. data/third_party/boringssl/crypto/pkcs8/internal.h +34 -16
  405. data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +120 -39
  406. data/third_party/boringssl/crypto/pkcs8/pkcs8.c +144 -857
  407. data/third_party/boringssl/crypto/pkcs8/pkcs8_x509.c +789 -0
  408. data/third_party/boringssl/crypto/poly1305/internal.h +4 -3
  409. data/third_party/boringssl/crypto/poly1305/poly1305.c +14 -14
  410. data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +11 -11
  411. data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +41 -41
  412. data/third_party/boringssl/crypto/pool/internal.h +2 -2
  413. data/third_party/boringssl/crypto/pool/pool.c +15 -15
  414. data/third_party/boringssl/crypto/{rand → rand_extra}/deterministic.c +7 -7
  415. data/third_party/boringssl/crypto/rand_extra/forkunsafe.c +46 -0
  416. data/third_party/boringssl/crypto/{rand → rand_extra}/fuchsia.c +7 -7
  417. data/third_party/boringssl/crypto/rand_extra/rand_extra.c +70 -0
  418. data/third_party/boringssl/crypto/{rand → rand_extra}/windows.c +5 -5
  419. data/third_party/boringssl/crypto/refcount_c11.c +2 -2
  420. data/third_party/boringssl/crypto/refcount_lock.c +1 -1
  421. data/third_party/boringssl/crypto/{rsa → rsa_extra}/rsa_asn1.c +12 -120
  422. data/third_party/boringssl/crypto/stack/stack.c +13 -13
  423. data/third_party/boringssl/crypto/thread_none.c +1 -1
  424. data/third_party/boringssl/crypto/thread_pthread.c +1 -1
  425. data/third_party/boringssl/crypto/thread_win.c +40 -40
  426. data/third_party/boringssl/crypto/x509/a_sign.c +5 -12
  427. data/third_party/boringssl/crypto/x509/a_verify.c +6 -18
  428. data/third_party/boringssl/crypto/x509/algorithm.c +22 -6
  429. data/third_party/boringssl/crypto/x509/asn1_gen.c +30 -7
  430. data/third_party/boringssl/crypto/x509/by_dir.c +2 -2
  431. data/third_party/boringssl/crypto/x509/by_file.c +2 -2
  432. data/third_party/boringssl/crypto/x509/rsa_pss.c +5 -5
  433. data/third_party/boringssl/crypto/x509/t_x509.c +2 -1
  434. data/third_party/boringssl/crypto/x509/x509_def.c +5 -0
  435. data/third_party/boringssl/crypto/x509/x509_lu.c +35 -4
  436. data/third_party/boringssl/crypto/x509/x509_set.c +10 -0
  437. data/third_party/boringssl/crypto/x509/x509_vfy.c +20 -17
  438. data/third_party/boringssl/crypto/x509/x_name.c +13 -16
  439. data/third_party/boringssl/crypto/x509/x_x509.c +3 -3
  440. data/third_party/boringssl/crypto/x509/x_x509a.c +0 -7
  441. data/third_party/boringssl/crypto/x509v3/ext_dat.h +8 -0
  442. data/third_party/boringssl/crypto/x509v3/pcy_int.h +2 -2
  443. data/third_party/boringssl/crypto/x509v3/pcy_lib.c +0 -9
  444. data/third_party/boringssl/crypto/x509v3/pcy_node.c +1 -1
  445. data/third_party/boringssl/crypto/x509v3/pcy_tree.c +25 -15
  446. data/third_party/boringssl/crypto/x509v3/v3_alt.c +21 -11
  447. data/third_party/boringssl/crypto/x509v3/v3_cpols.c +9 -3
  448. data/third_party/boringssl/crypto/x509v3/v3_info.c +22 -14
  449. data/third_party/boringssl/crypto/x509v3/v3_ncons.c +27 -11
  450. data/third_party/boringssl/crypto/x509v3/v3_pci.c +0 -33
  451. data/third_party/boringssl/crypto/x509v3/v3_utl.c +4 -4
  452. data/third_party/boringssl/include/openssl/aead.h +280 -191
  453. data/third_party/boringssl/include/openssl/aes.h +50 -50
  454. data/third_party/boringssl/include/openssl/arm_arch.h +12 -12
  455. data/third_party/boringssl/include/openssl/asn1.h +14 -77
  456. data/third_party/boringssl/include/openssl/asn1t.h +11 -15
  457. data/third_party/boringssl/include/openssl/base.h +78 -51
  458. data/third_party/boringssl/include/openssl/base64.h +68 -68
  459. data/third_party/boringssl/include/openssl/bio.h +472 -406
  460. data/third_party/boringssl/include/openssl/blowfish.h +1 -1
  461. data/third_party/boringssl/include/openssl/bn.h +454 -435
  462. data/third_party/boringssl/include/openssl/buf.h +27 -27
  463. data/third_party/boringssl/include/openssl/bytestring.h +282 -267
  464. data/third_party/boringssl/include/openssl/cast.h +2 -2
  465. data/third_party/boringssl/include/openssl/chacha.h +5 -5
  466. data/third_party/boringssl/include/openssl/cipher.h +209 -200
  467. data/third_party/boringssl/include/openssl/cmac.h +27 -27
  468. data/third_party/boringssl/include/openssl/conf.h +49 -46
  469. data/third_party/boringssl/include/openssl/cpu.h +60 -45
  470. data/third_party/boringssl/include/openssl/crypto.h +59 -35
  471. data/third_party/boringssl/include/openssl/curve25519.h +97 -92
  472. data/third_party/boringssl/include/openssl/des.h +25 -25
  473. data/third_party/boringssl/include/openssl/dh.h +98 -97
  474. data/third_party/boringssl/include/openssl/digest.h +143 -114
  475. data/third_party/boringssl/include/openssl/dsa.h +217 -202
  476. data/third_party/boringssl/include/openssl/ec.h +132 -131
  477. data/third_party/boringssl/include/openssl/ec_key.h +132 -128
  478. data/third_party/boringssl/include/openssl/ecdh.h +9 -9
  479. data/third_party/boringssl/include/openssl/ecdsa.h +66 -66
  480. data/third_party/boringssl/include/openssl/engine.h +38 -38
  481. data/third_party/boringssl/include/openssl/err.h +189 -219
  482. data/third_party/boringssl/include/openssl/evp.h +473 -397
  483. data/third_party/boringssl/include/openssl/ex_data.h +46 -56
  484. data/third_party/boringssl/include/openssl/hkdf.h +17 -17
  485. data/third_party/boringssl/include/openssl/hmac.h +55 -43
  486. data/third_party/boringssl/include/openssl/is_boringssl.h +16 -0
  487. data/third_party/boringssl/include/openssl/lhash.h +67 -67
  488. data/third_party/boringssl/include/openssl/lhash_macros.h +4 -4
  489. data/third_party/boringssl/include/openssl/md4.h +14 -14
  490. data/third_party/boringssl/include/openssl/md5.h +14 -14
  491. data/third_party/boringssl/include/openssl/mem.h +39 -33
  492. data/third_party/boringssl/include/openssl/nid.h +43 -0
  493. data/third_party/boringssl/include/openssl/obj.h +93 -87
  494. data/third_party/boringssl/include/openssl/opensslconf.h +8 -1
  495. data/third_party/boringssl/include/openssl/pem.h +2 -122
  496. data/third_party/boringssl/include/openssl/pkcs7.h +68 -2
  497. data/third_party/boringssl/include/openssl/pkcs8.h +81 -66
  498. data/third_party/boringssl/include/openssl/poly1305.h +11 -11
  499. data/third_party/boringssl/include/openssl/pool.h +29 -25
  500. data/third_party/boringssl/include/openssl/rand.h +48 -45
  501. data/third_party/boringssl/include/openssl/rc4.h +9 -9
  502. data/third_party/boringssl/include/openssl/ripemd.h +13 -13
  503. data/third_party/boringssl/include/openssl/rsa.h +371 -340
  504. data/third_party/boringssl/include/openssl/sha.h +71 -71
  505. data/third_party/boringssl/include/openssl/span.h +191 -0
  506. data/third_party/boringssl/include/openssl/ssl.h +2639 -2519
  507. data/third_party/boringssl/include/openssl/ssl3.h +39 -122
  508. data/third_party/boringssl/include/openssl/stack.h +355 -164
  509. data/third_party/boringssl/include/openssl/thread.h +43 -43
  510. data/third_party/boringssl/include/openssl/tls1.h +60 -63
  511. data/third_party/boringssl/include/openssl/type_check.h +10 -14
  512. data/third_party/boringssl/include/openssl/x509.h +41 -116
  513. data/third_party/boringssl/include/openssl/x509_vfy.h +17 -25
  514. data/third_party/boringssl/include/openssl/x509v3.h +27 -21
  515. data/third_party/boringssl/ssl/{bio_ssl.c → bio_ssl.cc} +9 -5
  516. data/third_party/boringssl/ssl/{custom_extensions.c → custom_extensions.cc} +19 -12
  517. data/third_party/boringssl/ssl/{d1_both.c → d1_both.cc} +224 -193
  518. data/third_party/boringssl/ssl/{d1_lib.c → d1_lib.cc} +86 -79
  519. data/third_party/boringssl/ssl/{d1_pkt.c → d1_pkt.cc} +55 -87
  520. data/third_party/boringssl/ssl/{d1_srtp.c → d1_srtp.cc} +12 -16
  521. data/third_party/boringssl/ssl/{dtls_method.c → dtls_method.cc} +33 -50
  522. data/third_party/boringssl/ssl/{dtls_record.c → dtls_record.cc} +76 -64
  523. data/third_party/boringssl/ssl/handshake.cc +547 -0
  524. data/third_party/boringssl/ssl/handshake_client.cc +1828 -0
  525. data/third_party/boringssl/ssl/handshake_server.cc +1672 -0
  526. data/third_party/boringssl/ssl/internal.h +2027 -1280
  527. data/third_party/boringssl/ssl/s3_both.cc +603 -0
  528. data/third_party/boringssl/ssl/{s3_lib.c → s3_lib.cc} +22 -10
  529. data/third_party/boringssl/ssl/{s3_pkt.c → s3_pkt.cc} +171 -75
  530. data/third_party/boringssl/ssl/ssl_aead_ctx.cc +415 -0
  531. data/third_party/boringssl/ssl/{ssl_asn1.c → ssl_asn1.cc} +257 -261
  532. data/third_party/boringssl/ssl/{ssl_buffer.c → ssl_buffer.cc} +81 -97
  533. data/third_party/boringssl/ssl/{ssl_cert.c → ssl_cert.cc} +304 -414
  534. data/third_party/boringssl/ssl/{ssl_cipher.c → ssl_cipher.cc} +427 -505
  535. data/third_party/boringssl/ssl/{ssl_file.c → ssl_file.cc} +24 -16
  536. data/third_party/boringssl/ssl/ssl_key_share.cc +245 -0
  537. data/third_party/boringssl/ssl/{ssl_lib.c → ssl_lib.cc} +665 -828
  538. data/third_party/boringssl/ssl/ssl_privkey.cc +518 -0
  539. data/third_party/boringssl/ssl/{ssl_session.c → ssl_session.cc} +596 -471
  540. data/third_party/boringssl/ssl/{ssl_stat.c → ssl_stat.cc} +5 -224
  541. data/third_party/boringssl/ssl/{ssl_transcript.c → ssl_transcript.cc} +117 -140
  542. data/third_party/boringssl/ssl/ssl_versions.cc +439 -0
  543. data/third_party/boringssl/ssl/{ssl_x509.c → ssl_x509.cc} +751 -267
  544. data/third_party/boringssl/ssl/{t1_enc.c → t1_enc.cc} +120 -161
  545. data/third_party/boringssl/ssl/{t1_lib.c → t1_lib.cc} +859 -966
  546. data/third_party/boringssl/ssl/{tls13_both.c → tls13_both.cc} +202 -284
  547. data/third_party/boringssl/ssl/tls13_client.cc +842 -0
  548. data/third_party/boringssl/ssl/{tls13_enc.c → tls13_enc.cc} +108 -90
  549. data/third_party/boringssl/ssl/tls13_server.cc +967 -0
  550. data/third_party/boringssl/ssl/{tls_method.c → tls_method.cc} +94 -73
  551. data/third_party/boringssl/ssl/tls_record.cc +675 -0
  552. metadata +117 -168
  553. data/include/grpc/support/cmdline.h +0 -88
  554. data/include/grpc/support/subprocess.h +0 -44
  555. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +0 -29
  556. data/src/core/ext/filters/client_channel/resolver_factory.cc +0 -40
  557. data/src/core/lib/gpr/cmdline.cc +0 -330
  558. data/src/core/lib/gpr/subprocess_posix.cc +0 -99
  559. data/src/core/lib/gpr/subprocess_windows.cc +0 -126
  560. data/src/core/lib/surface/alarm.cc +0 -137
  561. data/src/core/lib/surface/alarm_internal.h +0 -40
  562. data/src/core/tsi/gts_transport_security.cc +0 -40
  563. data/third_party/boringssl/crypto/aes/aes.c +0 -1142
  564. data/third_party/boringssl/crypto/aes/internal.h +0 -87
  565. data/third_party/boringssl/crypto/aes/key_wrap.c +0 -138
  566. data/third_party/boringssl/crypto/aes/mode_wrappers.c +0 -112
  567. data/third_party/boringssl/crypto/asn1/x_long.c +0 -200
  568. data/third_party/boringssl/crypto/bn/add.c +0 -377
  569. data/third_party/boringssl/crypto/bn/asm/x86_64-gcc.c +0 -532
  570. data/third_party/boringssl/crypto/bn/bn.c +0 -365
  571. data/third_party/boringssl/crypto/bn/cmp.c +0 -239
  572. data/third_party/boringssl/crypto/bn/ctx.c +0 -313
  573. data/third_party/boringssl/crypto/bn/div.c +0 -728
  574. data/third_party/boringssl/crypto/bn/exponentiation.c +0 -1240
  575. data/third_party/boringssl/crypto/bn/gcd.c +0 -635
  576. data/third_party/boringssl/crypto/bn/generic.c +0 -707
  577. data/third_party/boringssl/crypto/bn/kronecker.c +0 -176
  578. data/third_party/boringssl/crypto/bn/montgomery.c +0 -409
  579. data/third_party/boringssl/crypto/bn/montgomery_inv.c +0 -207
  580. data/third_party/boringssl/crypto/bn/mul.c +0 -871
  581. data/third_party/boringssl/crypto/bn/prime.c +0 -861
  582. data/third_party/boringssl/crypto/bn/random.c +0 -343
  583. data/third_party/boringssl/crypto/bn/rsaz_exp.c +0 -254
  584. data/third_party/boringssl/crypto/bn/shift.c +0 -307
  585. data/third_party/boringssl/crypto/bn/sqrt.c +0 -506
  586. data/third_party/boringssl/crypto/cipher/aead.c +0 -156
  587. data/third_party/boringssl/crypto/cipher/cipher.c +0 -657
  588. data/third_party/boringssl/crypto/cipher/e_aes.c +0 -1771
  589. data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +0 -276
  590. data/third_party/boringssl/crypto/cipher/e_des.c +0 -205
  591. data/third_party/boringssl/crypto/cipher/tls_cbc.c +0 -482
  592. data/third_party/boringssl/crypto/des/des.c +0 -771
  593. data/third_party/boringssl/crypto/digest/digest.c +0 -251
  594. data/third_party/boringssl/crypto/digest/digests.c +0 -358
  595. data/third_party/boringssl/crypto/ec/ec.c +0 -847
  596. data/third_party/boringssl/crypto/ec/ec_key.c +0 -479
  597. data/third_party/boringssl/crypto/ec/ec_montgomery.c +0 -303
  598. data/third_party/boringssl/crypto/ec/oct.c +0 -416
  599. data/third_party/boringssl/crypto/ec/p224-64.c +0 -1143
  600. data/third_party/boringssl/crypto/ec/p256-64.c +0 -1701
  601. data/third_party/boringssl/crypto/ec/p256-x86_64.c +0 -561
  602. data/third_party/boringssl/crypto/ec/simple.c +0 -1118
  603. data/third_party/boringssl/crypto/ec/util-64.c +0 -109
  604. data/third_party/boringssl/crypto/ec/wnaf.c +0 -458
  605. data/third_party/boringssl/crypto/ecdsa/ecdsa.c +0 -479
  606. data/third_party/boringssl/crypto/hmac/hmac.c +0 -215
  607. data/third_party/boringssl/crypto/md4/md4.c +0 -236
  608. data/third_party/boringssl/crypto/md5/md5.c +0 -285
  609. data/third_party/boringssl/crypto/modes/cbc.c +0 -212
  610. data/third_party/boringssl/crypto/modes/cfb.c +0 -230
  611. data/third_party/boringssl/crypto/modes/ctr.c +0 -219
  612. data/third_party/boringssl/crypto/modes/gcm.c +0 -1071
  613. data/third_party/boringssl/crypto/modes/ofb.c +0 -95
  614. data/third_party/boringssl/crypto/modes/polyval.c +0 -94
  615. data/third_party/boringssl/crypto/pkcs8/p8_pkey.c +0 -85
  616. data/third_party/boringssl/crypto/rand/rand.c +0 -244
  617. data/third_party/boringssl/crypto/rand/urandom.c +0 -335
  618. data/third_party/boringssl/crypto/rsa/blinding.c +0 -265
  619. data/third_party/boringssl/crypto/rsa/padding.c +0 -708
  620. data/third_party/boringssl/crypto/rsa/rsa.c +0 -830
  621. data/third_party/boringssl/crypto/rsa/rsa_impl.c +0 -1100
  622. data/third_party/boringssl/crypto/sha/sha1-altivec.c +0 -346
  623. data/third_party/boringssl/crypto/sha/sha1.c +0 -355
  624. data/third_party/boringssl/crypto/sha/sha256.c +0 -329
  625. data/third_party/boringssl/crypto/sha/sha512.c +0 -609
  626. data/third_party/boringssl/crypto/x509/x509type.c +0 -126
  627. data/third_party/boringssl/include/openssl/stack_macros.h +0 -3987
  628. data/third_party/boringssl/ssl/handshake_client.c +0 -1883
  629. data/third_party/boringssl/ssl/handshake_server.c +0 -1950
  630. data/third_party/boringssl/ssl/s3_both.c +0 -895
  631. data/third_party/boringssl/ssl/ssl_aead_ctx.c +0 -335
  632. data/third_party/boringssl/ssl/ssl_ecdh.c +0 -465
  633. data/third_party/boringssl/ssl/ssl_privkey.c +0 -683
  634. data/third_party/boringssl/ssl/ssl_privkey_cc.cc +0 -76
  635. data/third_party/boringssl/ssl/tls13_client.c +0 -712
  636. data/third_party/boringssl/ssl/tls13_server.c +0 -680
  637. data/third_party/boringssl/ssl/tls_record.c +0 -556
@@ -128,8 +128,8 @@ static int xname_cmp(const X509_NAME **a, const X509_NAME **b) {
128
128
  return X509_NAME_cmp(*a, *b);
129
129
  }
130
130
 
131
- /* TODO(davidben): Is there any reason this doesn't call
132
- * |SSL_add_file_cert_subjects_to_stack|? */
131
+ // TODO(davidben): Is there any reason this doesn't call
132
+ // |SSL_add_file_cert_subjects_to_stack|?
133
133
  STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file) {
134
134
  BIO *in;
135
135
  X509 *x = NULL;
@@ -164,7 +164,7 @@ STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file) {
164
164
  goto err;
165
165
  }
166
166
 
167
- /* Check for duplicates. */
167
+ // Check for duplicates.
168
168
  if (sk_X509_NAME_find(sk, NULL, xn)) {
169
169
  continue;
170
170
  }
@@ -222,7 +222,7 @@ int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
222
222
  goto err;
223
223
  }
224
224
 
225
- /* Check for duplicates. */
225
+ // Check for duplicates.
226
226
  if (sk_X509_NAME_find(stack, NULL, xn)) {
227
227
  continue;
228
228
  }
@@ -493,15 +493,15 @@ end:
493
493
  return ret;
494
494
  }
495
495
 
496
- /* Read a file that contains our certificate in "PEM" format, possibly followed
497
- * by a sequence of CA certificates that should be sent to the peer in the
498
- * Certificate message. */
496
+ // Read a file that contains our certificate in "PEM" format, possibly followed
497
+ // by a sequence of CA certificates that should be sent to the peer in the
498
+ // Certificate message.
499
499
  int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) {
500
500
  BIO *in;
501
501
  int ret = 0;
502
502
  X509 *x = NULL;
503
503
 
504
- ERR_clear_error(); /* clear error stack for SSL_CTX_use_certificate() */
504
+ ERR_clear_error(); // clear error stack for SSL_CTX_use_certificate()
505
505
 
506
506
  in = BIO_new(BIO_s_file());
507
507
  if (in == NULL) {
@@ -524,12 +524,12 @@ int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) {
524
524
  ret = SSL_CTX_use_certificate(ctx, x);
525
525
 
526
526
  if (ERR_peek_error() != 0) {
527
- ret = 0; /* Key/certificate mismatch doesn't imply ret==0 ... */
527
+ ret = 0; // Key/certificate mismatch doesn't imply ret==0 ...
528
528
  }
529
529
 
530
530
  if (ret) {
531
- /* If we could set up our certificate, now proceed to the CA
532
- * certificates. */
531
+ // If we could set up our certificate, now proceed to the CA
532
+ // certificates.
533
533
  X509 *ca;
534
534
  int r;
535
535
  uint32_t err;
@@ -545,18 +545,18 @@ int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) {
545
545
  ret = 0;
546
546
  goto end;
547
547
  }
548
- /* Note that we must not free r if it was successfully added to the chain
549
- * (while we must free the main certificate, since its reference count is
550
- * increased by SSL_CTX_use_certificate). */
548
+ // Note that we must not free r if it was successfully added to the chain
549
+ // (while we must free the main certificate, since its reference count is
550
+ // increased by SSL_CTX_use_certificate).
551
551
  }
552
552
 
553
- /* When the while loop ends, it's usually just EOF. */
553
+ // When the while loop ends, it's usually just EOF.
554
554
  err = ERR_peek_last_error();
555
555
  if (ERR_GET_LIB(err) == ERR_LIB_PEM &&
556
556
  ERR_GET_REASON(err) == PEM_R_NO_START_LINE) {
557
557
  ERR_clear_error();
558
558
  } else {
559
- ret = 0; /* some real error */
559
+ ret = 0; // some real error
560
560
  }
561
561
  }
562
562
 
@@ -570,6 +570,14 @@ void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb) {
570
570
  ctx->default_passwd_callback = cb;
571
571
  }
572
572
 
573
+ pem_password_cb *SSL_CTX_get_default_passwd_cb(const SSL_CTX *ctx) {
574
+ return ctx->default_passwd_callback;
575
+ }
576
+
573
577
  void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *data) {
574
578
  ctx->default_passwd_callback_userdata = data;
575
579
  }
580
+
581
+ void *SSL_CTX_get_default_passwd_cb_userdata(const SSL_CTX *ctx) {
582
+ return ctx->default_passwd_callback_userdata;
583
+ }
@@ -0,0 +1,245 @@
1
+ /* Copyright (c) 2015, Google Inc.
2
+ *
3
+ * Permission to use, copy, modify, and/or distribute this software for any
4
+ * purpose with or without fee is hereby granted, provided that the above
5
+ * copyright notice and this permission notice appear in all copies.
6
+ *
7
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10
+ * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14
+
15
+ #include <openssl/ssl.h>
16
+
17
+ #include <assert.h>
18
+ #include <string.h>
19
+
20
+ #include <utility>
21
+
22
+ #include <openssl/bn.h>
23
+ #include <openssl/bytestring.h>
24
+ #include <openssl/curve25519.h>
25
+ #include <openssl/ec.h>
26
+ #include <openssl/err.h>
27
+ #include <openssl/mem.h>
28
+ #include <openssl/nid.h>
29
+
30
+ #include "internal.h"
31
+ #include "../crypto/internal.h"
32
+
33
+
34
+ namespace bssl {
35
+
36
+ namespace {
37
+
38
+ class ECKeyShare : public SSLKeyShare {
39
+ public:
40
+ ECKeyShare(int nid, uint16_t group_id) : nid_(nid), group_id_(group_id) {}
41
+ ~ECKeyShare() override {}
42
+
43
+ uint16_t GroupID() const override { return group_id_; }
44
+
45
+ bool Offer(CBB *out) override {
46
+ assert(!private_key_);
47
+ // Set up a shared |BN_CTX| for all operations.
48
+ UniquePtr<BN_CTX> bn_ctx(BN_CTX_new());
49
+ if (!bn_ctx) {
50
+ return false;
51
+ }
52
+ BN_CTXScope scope(bn_ctx.get());
53
+
54
+ // Generate a private key.
55
+ UniquePtr<EC_GROUP> group(EC_GROUP_new_by_curve_name(nid_));
56
+ private_key_.reset(BN_new());
57
+ if (!group || !private_key_ ||
58
+ !BN_rand_range_ex(private_key_.get(), 1,
59
+ EC_GROUP_get0_order(group.get()))) {
60
+ return false;
61
+ }
62
+
63
+ // Compute the corresponding public key and serialize it.
64
+ UniquePtr<EC_POINT> public_key(EC_POINT_new(group.get()));
65
+ if (!public_key ||
66
+ !EC_POINT_mul(group.get(), public_key.get(), private_key_.get(), NULL,
67
+ NULL, bn_ctx.get()) ||
68
+ !EC_POINT_point2cbb(out, group.get(), public_key.get(),
69
+ POINT_CONVERSION_UNCOMPRESSED, bn_ctx.get())) {
70
+ return false;
71
+ }
72
+
73
+ return true;
74
+ }
75
+
76
+ bool Finish(Array<uint8_t> *out_secret, uint8_t *out_alert,
77
+ Span<const uint8_t> peer_key) override {
78
+ assert(private_key_);
79
+ *out_alert = SSL_AD_INTERNAL_ERROR;
80
+
81
+ // Set up a shared |BN_CTX| for all operations.
82
+ UniquePtr<BN_CTX> bn_ctx(BN_CTX_new());
83
+ if (!bn_ctx) {
84
+ return false;
85
+ }
86
+ BN_CTXScope scope(bn_ctx.get());
87
+
88
+ UniquePtr<EC_GROUP> group(EC_GROUP_new_by_curve_name(nid_));
89
+ if (!group) {
90
+ return false;
91
+ }
92
+
93
+ UniquePtr<EC_POINT> peer_point(EC_POINT_new(group.get()));
94
+ UniquePtr<EC_POINT> result(EC_POINT_new(group.get()));
95
+ BIGNUM *x = BN_CTX_get(bn_ctx.get());
96
+ if (!peer_point || !result || !x) {
97
+ return false;
98
+ }
99
+
100
+ if (!EC_POINT_oct2point(group.get(), peer_point.get(), peer_key.data(),
101
+ peer_key.size(), bn_ctx.get())) {
102
+ *out_alert = SSL_AD_DECODE_ERROR;
103
+ return false;
104
+ }
105
+
106
+ // Compute the x-coordinate of |peer_key| * |private_key_|.
107
+ if (!EC_POINT_mul(group.get(), result.get(), NULL, peer_point.get(),
108
+ private_key_.get(), bn_ctx.get()) ||
109
+ !EC_POINT_get_affine_coordinates_GFp(group.get(), result.get(), x, NULL,
110
+ bn_ctx.get())) {
111
+ return false;
112
+ }
113
+
114
+ // Encode the x-coordinate left-padded with zeros.
115
+ Array<uint8_t> secret;
116
+ if (!secret.Init((EC_GROUP_get_degree(group.get()) + 7) / 8) ||
117
+ !BN_bn2bin_padded(secret.data(), secret.size(), x)) {
118
+ return false;
119
+ }
120
+
121
+ *out_secret = std::move(secret);
122
+ return true;
123
+ }
124
+
125
+ private:
126
+ UniquePtr<BIGNUM> private_key_;
127
+ int nid_;
128
+ uint16_t group_id_;
129
+ };
130
+
131
+ class X25519KeyShare : public SSLKeyShare {
132
+ public:
133
+ X25519KeyShare() {}
134
+ ~X25519KeyShare() override {
135
+ OPENSSL_cleanse(private_key_, sizeof(private_key_));
136
+ }
137
+
138
+ uint16_t GroupID() const override { return SSL_CURVE_X25519; }
139
+
140
+ bool Offer(CBB *out) override {
141
+ uint8_t public_key[32];
142
+ X25519_keypair(public_key, private_key_);
143
+ return !!CBB_add_bytes(out, public_key, sizeof(public_key));
144
+ }
145
+
146
+ bool Finish(Array<uint8_t> *out_secret, uint8_t *out_alert,
147
+ Span<const uint8_t> peer_key) override {
148
+ *out_alert = SSL_AD_INTERNAL_ERROR;
149
+
150
+ Array<uint8_t> secret;
151
+ if (!secret.Init(32)) {
152
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
153
+ return false;
154
+ }
155
+
156
+ if (peer_key.size() != 32 ||
157
+ !X25519(secret.data(), private_key_, peer_key.data())) {
158
+ *out_alert = SSL_AD_DECODE_ERROR;
159
+ OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_ECPOINT);
160
+ return false;
161
+ }
162
+
163
+ *out_secret = std::move(secret);
164
+ return true;
165
+ }
166
+
167
+ private:
168
+ uint8_t private_key_[32];
169
+ };
170
+
171
+ CONSTEXPR_ARRAY struct {
172
+ int nid;
173
+ uint16_t group_id;
174
+ const char name[8];
175
+ } kNamedGroups[] = {
176
+ {NID_secp224r1, SSL_CURVE_SECP224R1, "P-224"},
177
+ {NID_X9_62_prime256v1, SSL_CURVE_SECP256R1, "P-256"},
178
+ {NID_secp384r1, SSL_CURVE_SECP384R1, "P-384"},
179
+ {NID_secp521r1, SSL_CURVE_SECP521R1, "P-521"},
180
+ {NID_X25519, SSL_CURVE_X25519, "X25519"},
181
+ };
182
+
183
+ } // namespace
184
+
185
+ UniquePtr<SSLKeyShare> SSLKeyShare::Create(uint16_t group_id) {
186
+ switch (group_id) {
187
+ case SSL_CURVE_SECP224R1:
188
+ return UniquePtr<SSLKeyShare>(
189
+ New<ECKeyShare>(NID_secp224r1, SSL_CURVE_SECP224R1));
190
+ case SSL_CURVE_SECP256R1:
191
+ return UniquePtr<SSLKeyShare>(
192
+ New<ECKeyShare>(NID_X9_62_prime256v1, SSL_CURVE_SECP256R1));
193
+ case SSL_CURVE_SECP384R1:
194
+ return UniquePtr<SSLKeyShare>(
195
+ New<ECKeyShare>(NID_secp384r1, SSL_CURVE_SECP384R1));
196
+ case SSL_CURVE_SECP521R1:
197
+ return UniquePtr<SSLKeyShare>(
198
+ New<ECKeyShare>(NID_secp521r1, SSL_CURVE_SECP521R1));
199
+ case SSL_CURVE_X25519:
200
+ return UniquePtr<SSLKeyShare>(New<X25519KeyShare>());
201
+ default:
202
+ return nullptr;
203
+ }
204
+ }
205
+
206
+ bool SSLKeyShare::Accept(CBB *out_public_key, Array<uint8_t> *out_secret,
207
+ uint8_t *out_alert, Span<const uint8_t> peer_key) {
208
+ *out_alert = SSL_AD_INTERNAL_ERROR;
209
+ return Offer(out_public_key) &&
210
+ Finish(out_secret, out_alert, peer_key);
211
+ }
212
+
213
+ int ssl_nid_to_group_id(uint16_t *out_group_id, int nid) {
214
+ for (const auto &group : kNamedGroups) {
215
+ if (group.nid == nid) {
216
+ *out_group_id = group.group_id;
217
+ return 1;
218
+ }
219
+ }
220
+ return 0;
221
+ }
222
+
223
+ int ssl_name_to_group_id(uint16_t *out_group_id, const char *name, size_t len) {
224
+ for (const auto &group : kNamedGroups) {
225
+ if (len == strlen(group.name) &&
226
+ !strncmp(group.name, name, len)) {
227
+ *out_group_id = group.group_id;
228
+ return 1;
229
+ }
230
+ }
231
+ return 0;
232
+ }
233
+
234
+ } // namespace bssl
235
+
236
+ using namespace bssl;
237
+
238
+ const char* SSL_get_curve_name(uint16_t group_id) {
239
+ for (const auto &group : kNamedGroups) {
240
+ if (group.group_id == group_id) {
241
+ return group.name;
242
+ }
243
+ }
244
+ return nullptr;
245
+ }
@@ -146,7 +146,6 @@
146
146
 
147
147
  #include <openssl/bytestring.h>
148
148
  #include <openssl/crypto.h>
149
- #include <openssl/dh.h>
150
149
  #include <openssl/err.h>
151
150
  #include <openssl/lhash.h>
152
151
  #include <openssl/mem.h>
@@ -163,22 +162,24 @@
163
162
  #endif
164
163
 
165
164
 
166
- /* |SSL_R_UNKNOWN_PROTOCOL| is no longer emitted, but continue to define it
167
- * to avoid downstream churn. */
165
+ namespace bssl {
166
+
167
+ // |SSL_R_UNKNOWN_PROTOCOL| is no longer emitted, but continue to define it
168
+ // to avoid downstream churn.
168
169
  OPENSSL_DECLARE_ERROR_REASON(SSL, UNKNOWN_PROTOCOL)
169
170
 
170
- /* The following errors are no longer emitted, but are used in nginx without
171
- * #ifdefs. */
171
+ // The following errors are no longer emitted, but are used in nginx without
172
+ // #ifdefs.
172
173
  OPENSSL_DECLARE_ERROR_REASON(SSL, BLOCK_CIPHER_PAD_IS_WRONG)
173
174
  OPENSSL_DECLARE_ERROR_REASON(SSL, NO_CIPHERS_SPECIFIED)
174
175
 
175
- /* Some error codes are special. Ensure the make_errors.go script never
176
- * regresses this. */
177
- OPENSSL_COMPILE_ASSERT(SSL_R_TLSV1_ALERT_NO_RENEGOTIATION ==
178
- SSL_AD_NO_RENEGOTIATION + SSL_AD_REASON_OFFSET,
179
- ssl_alert_reason_code_mismatch);
176
+ // Some error codes are special. Ensure the make_errors.go script never
177
+ // regresses this.
178
+ static_assert(SSL_R_TLSV1_ALERT_NO_RENEGOTIATION ==
179
+ SSL_AD_NO_RENEGOTIATION + SSL_AD_REASON_OFFSET,
180
+ "alert reason code mismatch");
180
181
 
181
- /* kMaxHandshakeSize is the maximum size, in bytes, of a handshake message. */
182
+ // kMaxHandshakeSize is the maximum size, in bytes, of a handshake message.
182
183
  static const size_t kMaxHandshakeSize = (1u << 24) - 1;
183
184
 
184
185
  static CRYPTO_EX_DATA_CLASS g_ex_data_class_ssl =
@@ -186,11 +187,253 @@ static CRYPTO_EX_DATA_CLASS g_ex_data_class_ssl =
186
187
  static CRYPTO_EX_DATA_CLASS g_ex_data_class_ssl_ctx =
187
188
  CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA;
188
189
 
190
+ bool CBBFinishArray(CBB *cbb, Array<uint8_t> *out) {
191
+ uint8_t *ptr;
192
+ size_t len;
193
+ if (!CBB_finish(cbb, &ptr, &len)) {
194
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
195
+ return false;
196
+ }
197
+ out->Reset(ptr, len);
198
+ return true;
199
+ }
200
+
201
+ void ssl_reset_error_state(SSL *ssl) {
202
+ // Functions which use |SSL_get_error| must reset I/O and error state on
203
+ // entry.
204
+ ssl->rwstate = SSL_NOTHING;
205
+ ERR_clear_error();
206
+ ERR_clear_system_error();
207
+ }
208
+
209
+ int ssl_can_write(const SSL *ssl) {
210
+ return !SSL_in_init(ssl) || ssl->s3->hs->can_early_write;
211
+ }
212
+
213
+ int ssl_can_read(const SSL *ssl) {
214
+ return !SSL_in_init(ssl) || ssl->s3->hs->can_early_read;
215
+ }
216
+
217
+ void ssl_cipher_preference_list_free(
218
+ struct ssl_cipher_preference_list_st *cipher_list) {
219
+ if (cipher_list == NULL) {
220
+ return;
221
+ }
222
+ sk_SSL_CIPHER_free(cipher_list->ciphers);
223
+ OPENSSL_free(cipher_list->in_group_flags);
224
+ OPENSSL_free(cipher_list);
225
+ }
226
+
227
+ void ssl_update_cache(SSL_HANDSHAKE *hs, int mode) {
228
+ SSL *const ssl = hs->ssl;
229
+ SSL_CTX *ctx = ssl->session_ctx;
230
+ // Never cache sessions with empty session IDs.
231
+ if (ssl->s3->established_session->session_id_length == 0 ||
232
+ ssl->s3->established_session->not_resumable ||
233
+ (ctx->session_cache_mode & mode) != mode) {
234
+ return;
235
+ }
236
+
237
+ // Clients never use the internal session cache.
238
+ int use_internal_cache = ssl->server && !(ctx->session_cache_mode &
239
+ SSL_SESS_CACHE_NO_INTERNAL_STORE);
240
+
241
+ // A client may see new sessions on abbreviated handshakes if the server
242
+ // decides to renew the ticket. Once the handshake is completed, it should be
243
+ // inserted into the cache.
244
+ if (ssl->s3->established_session != ssl->session ||
245
+ (!ssl->server && hs->ticket_expected)) {
246
+ if (use_internal_cache) {
247
+ SSL_CTX_add_session(ctx, ssl->s3->established_session);
248
+ }
249
+ if (ctx->new_session_cb != NULL) {
250
+ SSL_SESSION_up_ref(ssl->s3->established_session);
251
+ if (!ctx->new_session_cb(ssl, ssl->s3->established_session)) {
252
+ // |new_session_cb|'s return value signals whether it took ownership.
253
+ SSL_SESSION_free(ssl->s3->established_session);
254
+ }
255
+ }
256
+ }
257
+
258
+ if (use_internal_cache &&
259
+ !(ctx->session_cache_mode & SSL_SESS_CACHE_NO_AUTO_CLEAR)) {
260
+ // Automatically flush the internal session cache every 255 connections.
261
+ int flush_cache = 0;
262
+ CRYPTO_MUTEX_lock_write(&ctx->lock);
263
+ ctx->handshakes_since_cache_flush++;
264
+ if (ctx->handshakes_since_cache_flush >= 255) {
265
+ flush_cache = 1;
266
+ ctx->handshakes_since_cache_flush = 0;
267
+ }
268
+ CRYPTO_MUTEX_unlock_write(&ctx->lock);
269
+
270
+ if (flush_cache) {
271
+ struct OPENSSL_timeval now;
272
+ ssl_get_current_time(ssl, &now);
273
+ SSL_CTX_flush_sessions(ctx, now.tv_sec);
274
+ }
275
+ }
276
+ }
277
+
278
+ static int cbb_add_hex(CBB *cbb, const uint8_t *in, size_t in_len) {
279
+ static const char hextable[] = "0123456789abcdef";
280
+ uint8_t *out;
281
+
282
+ if (!CBB_add_space(cbb, &out, in_len * 2)) {
283
+ return 0;
284
+ }
285
+
286
+ for (size_t i = 0; i < in_len; i++) {
287
+ *(out++) = (uint8_t)hextable[in[i] >> 4];
288
+ *(out++) = (uint8_t)hextable[in[i] & 0xf];
289
+ }
290
+
291
+ return 1;
292
+ }
293
+
294
+ int ssl_log_secret(const SSL *ssl, const char *label, const uint8_t *secret,
295
+ size_t secret_len) {
296
+ if (ssl->ctx->keylog_callback == NULL) {
297
+ return 1;
298
+ }
299
+
300
+ ScopedCBB cbb;
301
+ uint8_t *out;
302
+ size_t out_len;
303
+ if (!CBB_init(cbb.get(), strlen(label) + 1 + SSL3_RANDOM_SIZE * 2 + 1 +
304
+ secret_len * 2 + 1) ||
305
+ !CBB_add_bytes(cbb.get(), (const uint8_t *)label, strlen(label)) ||
306
+ !CBB_add_bytes(cbb.get(), (const uint8_t *)" ", 1) ||
307
+ !cbb_add_hex(cbb.get(), ssl->s3->client_random, SSL3_RANDOM_SIZE) ||
308
+ !CBB_add_bytes(cbb.get(), (const uint8_t *)" ", 1) ||
309
+ !cbb_add_hex(cbb.get(), secret, secret_len) ||
310
+ !CBB_add_u8(cbb.get(), 0 /* NUL */) ||
311
+ !CBB_finish(cbb.get(), &out, &out_len)) {
312
+ return 0;
313
+ }
314
+
315
+ ssl->ctx->keylog_callback(ssl, (const char *)out);
316
+ OPENSSL_free(out);
317
+ return 1;
318
+ }
319
+
320
+ int ssl3_can_false_start(const SSL *ssl) {
321
+ const SSL_CIPHER *const cipher = SSL_get_current_cipher(ssl);
322
+
323
+ // False Start only for TLS 1.2 with an ECDHE+AEAD cipher and ALPN or NPN.
324
+ return !SSL_is_dtls(ssl) &&
325
+ SSL_version(ssl) == TLS1_2_VERSION &&
326
+ (ssl->s3->alpn_selected != NULL ||
327
+ ssl->s3->next_proto_negotiated != NULL) &&
328
+ cipher != NULL &&
329
+ cipher->algorithm_mkey == SSL_kECDHE &&
330
+ cipher->algorithm_mac == SSL_AEAD;
331
+ }
332
+
333
+ void ssl_do_info_callback(const SSL *ssl, int type, int value) {
334
+ void (*cb)(const SSL *ssl, int type, int value) = NULL;
335
+ if (ssl->info_callback != NULL) {
336
+ cb = ssl->info_callback;
337
+ } else if (ssl->ctx->info_callback != NULL) {
338
+ cb = ssl->ctx->info_callback;
339
+ }
340
+
341
+ if (cb != NULL) {
342
+ cb(ssl, type, value);
343
+ }
344
+ }
345
+
346
+ void ssl_do_msg_callback(SSL *ssl, int is_write, int content_type,
347
+ Span<const uint8_t> in) {
348
+ if (ssl->msg_callback == NULL) {
349
+ return;
350
+ }
351
+
352
+ // |version| is zero when calling for |SSL3_RT_HEADER| and |SSL2_VERSION| for
353
+ // a V2ClientHello.
354
+ int version;
355
+ switch (content_type) {
356
+ case 0:
357
+ // V2ClientHello
358
+ version = SSL2_VERSION;
359
+ break;
360
+ case SSL3_RT_HEADER:
361
+ version = 0;
362
+ break;
363
+ default:
364
+ version = SSL_version(ssl);
365
+ }
366
+
367
+ ssl->msg_callback(is_write, version, content_type, in.data(), in.size(), ssl,
368
+ ssl->msg_callback_arg);
369
+ }
370
+
371
+ void ssl_get_current_time(const SSL *ssl, struct OPENSSL_timeval *out_clock) {
372
+ // TODO(martinkr): Change callers to |ssl_ctx_get_current_time| and drop the
373
+ // |ssl| arg from |current_time_cb| if possible.
374
+ ssl_ctx_get_current_time(ssl->ctx, out_clock);
375
+ }
376
+
377
+ void ssl_ctx_get_current_time(const SSL_CTX *ctx,
378
+ struct OPENSSL_timeval *out_clock) {
379
+ if (ctx->current_time_cb != NULL) {
380
+ // TODO(davidben): Update current_time_cb to use OPENSSL_timeval. See
381
+ // https://crbug.com/boringssl/155.
382
+ struct timeval clock;
383
+ ctx->current_time_cb(nullptr /* ssl */, &clock);
384
+ if (clock.tv_sec < 0) {
385
+ assert(0);
386
+ out_clock->tv_sec = 0;
387
+ out_clock->tv_usec = 0;
388
+ } else {
389
+ out_clock->tv_sec = (uint64_t)clock.tv_sec;
390
+ out_clock->tv_usec = (uint32_t)clock.tv_usec;
391
+ }
392
+ return;
393
+ }
394
+
395
+ #if defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
396
+ out_clock->tv_sec = 1234;
397
+ out_clock->tv_usec = 1234;
398
+ #elif defined(OPENSSL_WINDOWS)
399
+ struct _timeb time;
400
+ _ftime(&time);
401
+ if (time.time < 0) {
402
+ assert(0);
403
+ out_clock->tv_sec = 0;
404
+ out_clock->tv_usec = 0;
405
+ } else {
406
+ out_clock->tv_sec = time.time;
407
+ out_clock->tv_usec = time.millitm * 1000;
408
+ }
409
+ #else
410
+ struct timeval clock;
411
+ gettimeofday(&clock, NULL);
412
+ if (clock.tv_sec < 0) {
413
+ assert(0);
414
+ out_clock->tv_sec = 0;
415
+ out_clock->tv_usec = 0;
416
+ } else {
417
+ out_clock->tv_sec = (uint64_t)clock.tv_sec;
418
+ out_clock->tv_usec = (uint32_t)clock.tv_usec;
419
+ }
420
+ #endif
421
+ }
422
+
423
+ } // namespace bssl
424
+
425
+ using namespace bssl;
426
+
189
427
  int SSL_library_init(void) {
190
428
  CRYPTO_library_init();
191
429
  return 1;
192
430
  }
193
431
 
432
+ int OPENSSL_init_ssl(uint64_t opts, const OPENSSL_INIT_SETTINGS *settings) {
433
+ CRYPTO_library_init();
434
+ return 1;
435
+ }
436
+
194
437
  static uint32_t ssl_session_hash(const SSL_SESSION *sess) {
195
438
  const uint8_t *session_id = sess->session_id;
196
439
 
@@ -210,11 +453,11 @@ static uint32_t ssl_session_hash(const SSL_SESSION *sess) {
210
453
  return hash;
211
454
  }
212
455
 
213
- /* NB: If this function (or indeed the hash function which uses a sort of
214
- * coarser function than this one) is changed, ensure
215
- * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being
216
- * able to construct an SSL_SESSION that will collide with any existing session
217
- * with a matching session ID. */
456
+ // NB: If this function (or indeed the hash function which uses a sort of
457
+ // coarser function than this one) is changed, ensure
458
+ // SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being
459
+ // able to construct an SSL_SESSION that will collide with any existing session
460
+ // with a matching session ID.
218
461
  static int ssl_session_cmp(const SSL_SESSION *a, const SSL_SESSION *b) {
219
462
  if (a->ssl_version != b->ssl_version) {
220
463
  return 1;
@@ -235,12 +478,7 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *method) {
235
478
  return NULL;
236
479
  }
237
480
 
238
- if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) {
239
- OPENSSL_PUT_ERROR(SSL, SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
240
- goto err;
241
- }
242
-
243
- ret = OPENSSL_malloc(sizeof(SSL_CTX));
481
+ ret = (SSL_CTX *)OPENSSL_malloc(sizeof(SSL_CTX));
244
482
  if (ret == NULL) {
245
483
  goto err;
246
484
  }
@@ -271,25 +509,16 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *method) {
271
509
  if (ret->sessions == NULL) {
272
510
  goto err;
273
511
  }
274
- ret->cert_store = X509_STORE_new();
275
- if (ret->cert_store == NULL) {
512
+
513
+ if (!ret->x509_method->ssl_ctx_new(ret)) {
276
514
  goto err;
277
515
  }
278
516
 
279
- ssl_create_cipher_list(ret->method, &ret->cipher_list,
280
- SSL_DEFAULT_CIPHER_LIST, 1 /* strict */);
281
- if (ret->cipher_list == NULL ||
282
- sk_SSL_CIPHER_num(ret->cipher_list->ciphers) <= 0) {
283
- OPENSSL_PUT_ERROR(SSL, SSL_R_LIBRARY_HAS_NO_CIPHERS);
517
+ if (!SSL_CTX_set_strict_cipher_list(ret, SSL_DEFAULT_CIPHER_LIST)) {
284
518
  goto err2;
285
519
  }
286
520
 
287
- ret->param = X509_VERIFY_PARAM_new();
288
- if (!ret->param) {
289
- goto err;
290
- }
291
-
292
- ret->client_CA = sk_X509_NAME_new_null();
521
+ ret->client_CA = sk_CRYPTO_BUFFER_new_null();
293
522
  if (ret->client_CA == NULL) {
294
523
  goto err;
295
524
  }
@@ -298,21 +527,17 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *method) {
298
527
 
299
528
  ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;
300
529
 
301
- /* Setup RFC4507 ticket keys */
302
- if (!RAND_bytes(ret->tlsext_tick_key_name, 16) ||
303
- !RAND_bytes(ret->tlsext_tick_hmac_key, 16) ||
304
- !RAND_bytes(ret->tlsext_tick_aes_key, 16)) {
305
- ret->options |= SSL_OP_NO_TICKET;
306
- }
307
-
308
- /* Disable the auto-chaining feature by default. Once this has stuck without
309
- * problems, the feature will be removed entirely. */
530
+ // Disable the auto-chaining feature by default. Once this has stuck without
531
+ // problems, the feature will be removed entirely.
310
532
  ret->mode = SSL_MODE_NO_AUTO_CHAIN;
311
533
 
312
- /* Lock the SSL_CTX to the specified version, for compatibility with legacy
313
- * uses of SSL_METHOD. */
534
+ // Lock the SSL_CTX to the specified version, for compatibility with legacy
535
+ // uses of SSL_METHOD, but we do not set the minimum version for
536
+ // |SSLv3_method|.
314
537
  if (!SSL_CTX_set_max_proto_version(ret, method->version) ||
315
- !SSL_CTX_set_min_proto_version(ret, method->version)) {
538
+ !SSL_CTX_set_min_proto_version(ret, method->version == SSL3_VERSION
539
+ ? 0 // default
540
+ : method->version)) {
316
541
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
317
542
  goto err2;
318
543
  }
@@ -337,33 +562,34 @@ void SSL_CTX_free(SSL_CTX *ctx) {
337
562
  return;
338
563
  }
339
564
 
340
- X509_VERIFY_PARAM_free(ctx->param);
341
-
342
- /* Free internal session cache. However: the remove_cb() may reference the
343
- * ex_data of SSL_CTX, thus the ex_data store can only be removed after the
344
- * sessions were flushed. As the ex_data handling routines might also touch
345
- * the session cache, the most secure solution seems to be: empty (flush) the
346
- * cache, then free ex_data, then finally free the cache. (See ticket
347
- * [openssl.org #212].) */
565
+ // Free internal session cache. However: the remove_cb() may reference the
566
+ // ex_data of SSL_CTX, thus the ex_data store can only be removed after the
567
+ // sessions were flushed. As the ex_data handling routines might also touch
568
+ // the session cache, the most secure solution seems to be: empty (flush) the
569
+ // cache, then free ex_data, then finally free the cache. (See ticket
570
+ // [openssl.org #212].)
348
571
  SSL_CTX_flush_sessions(ctx, 0);
349
572
 
350
573
  CRYPTO_free_ex_data(&g_ex_data_class_ssl_ctx, ctx, &ctx->ex_data);
351
574
 
352
575
  CRYPTO_MUTEX_cleanup(&ctx->lock);
353
576
  lh_SSL_SESSION_free(ctx->sessions);
354
- X509_STORE_free(ctx->cert_store);
355
577
  ssl_cipher_preference_list_free(ctx->cipher_list);
356
578
  ssl_cert_free(ctx->cert);
357
579
  sk_SSL_CUSTOM_EXTENSION_pop_free(ctx->client_custom_extensions,
358
580
  SSL_CUSTOM_EXTENSION_free);
359
581
  sk_SSL_CUSTOM_EXTENSION_pop_free(ctx->server_custom_extensions,
360
582
  SSL_CUSTOM_EXTENSION_free);
361
- sk_X509_NAME_pop_free(ctx->client_CA, X509_NAME_free);
583
+ sk_CRYPTO_BUFFER_pop_free(ctx->client_CA, CRYPTO_BUFFER_free);
584
+ ctx->x509_method->ssl_ctx_free(ctx);
362
585
  sk_SRTP_PROTECTION_PROFILE_free(ctx->srtp_profiles);
363
586
  OPENSSL_free(ctx->psk_identity_hint);
364
587
  OPENSSL_free(ctx->supported_group_list);
365
588
  OPENSSL_free(ctx->alpn_client_proto_list);
366
589
  EVP_PKEY_free(ctx->tlsext_channel_id_private);
590
+ OPENSSL_free(ctx->verify_sigalgs);
591
+ OPENSSL_free(ctx->tlsext_ticket_key_current);
592
+ OPENSSL_free(ctx->tlsext_ticket_key_prev);
367
593
 
368
594
  OPENSSL_free(ctx);
369
595
  }
@@ -378,17 +604,18 @@ SSL *SSL_new(SSL_CTX *ctx) {
378
604
  return NULL;
379
605
  }
380
606
 
381
- SSL *ssl = OPENSSL_malloc(sizeof(SSL));
607
+ SSL *ssl = (SSL *)OPENSSL_malloc(sizeof(SSL));
382
608
  if (ssl == NULL) {
383
609
  goto err;
384
610
  }
385
611
  OPENSSL_memset(ssl, 0, sizeof(SSL));
386
612
 
387
- ssl->min_version = ctx->min_version;
388
- ssl->max_version = ctx->max_version;
613
+ ssl->conf_min_version = ctx->conf_min_version;
614
+ ssl->conf_max_version = ctx->conf_max_version;
615
+ ssl->tls13_variant = ctx->tls13_variant;
389
616
 
390
- /* RFC 6347 states that implementations SHOULD use an initial timer value of
391
- * 1 second. */
617
+ // RFC 6347 states that implementations SHOULD use an initial timer value of
618
+ // 1 second.
392
619
  ssl->initial_timeout_duration_ms = 1000;
393
620
 
394
621
  ssl->options = ctx->options;
@@ -404,25 +631,25 @@ SSL *SSL_new(SSL_CTX *ctx) {
404
631
  ssl->msg_callback_arg = ctx->msg_callback_arg;
405
632
  ssl->verify_mode = ctx->verify_mode;
406
633
  ssl->verify_callback = ctx->default_verify_callback;
634
+ ssl->custom_verify_callback = ctx->custom_verify_callback;
407
635
  ssl->retain_only_sha256_of_client_certs =
408
636
  ctx->retain_only_sha256_of_client_certs;
409
637
 
410
- ssl->param = X509_VERIFY_PARAM_new();
411
- if (!ssl->param) {
412
- goto err;
413
- }
414
- X509_VERIFY_PARAM_inherit(ssl->param, ctx->param);
415
638
  ssl->quiet_shutdown = ctx->quiet_shutdown;
416
639
  ssl->max_send_fragment = ctx->max_send_fragment;
417
640
 
418
641
  SSL_CTX_up_ref(ctx);
419
642
  ssl->ctx = ctx;
420
643
  SSL_CTX_up_ref(ctx);
421
- ssl->initial_ctx = ctx;
644
+ ssl->session_ctx = ctx;
645
+
646
+ if (!ssl->ctx->x509_method->ssl_new(ssl)) {
647
+ goto err;
648
+ }
422
649
 
423
650
  if (ctx->supported_group_list) {
424
- ssl->supported_group_list = BUF_memdup(ctx->supported_group_list,
425
- ctx->supported_group_list_len * 2);
651
+ ssl->supported_group_list = (uint16_t *)BUF_memdup(
652
+ ctx->supported_group_list, ctx->supported_group_list_len * 2);
426
653
  if (!ssl->supported_group_list) {
427
654
  goto err;
428
655
  }
@@ -430,8 +657,8 @@ SSL *SSL_new(SSL_CTX *ctx) {
430
657
  }
431
658
 
432
659
  if (ctx->alpn_client_proto_list) {
433
- ssl->alpn_client_proto_list = BUF_memdup(ctx->alpn_client_proto_list,
434
- ctx->alpn_client_proto_list_len);
660
+ ssl->alpn_client_proto_list = (uint8_t *)BUF_memdup(
661
+ ctx->alpn_client_proto_list, ctx->alpn_client_proto_list_len);
435
662
  if (ssl->alpn_client_proto_list == NULL) {
436
663
  goto err;
437
664
  }
@@ -481,7 +708,9 @@ void SSL_free(SSL *ssl) {
481
708
  return;
482
709
  }
483
710
 
484
- X509_VERIFY_PARAM_free(ssl->param);
711
+ if (ssl->ctx != NULL) {
712
+ ssl->ctx->x509_method->ssl_free(ssl);
713
+ }
485
714
 
486
715
  CRYPTO_free_ex_data(&g_ex_data_class_ssl, ssl, &ssl->ex_data);
487
716
 
@@ -490,7 +719,7 @@ void SSL_free(SSL *ssl) {
490
719
 
491
720
  BUF_MEM_free(ssl->init_buf);
492
721
 
493
- /* add extra stuff */
722
+ // add extra stuff
494
723
  ssl_cipher_preference_list_free(ssl->cipher_list);
495
724
 
496
725
  SSL_SESSION_free(ssl->session);
@@ -498,12 +727,12 @@ void SSL_free(SSL *ssl) {
498
727
  ssl_cert_free(ssl->cert);
499
728
 
500
729
  OPENSSL_free(ssl->tlsext_hostname);
501
- SSL_CTX_free(ssl->initial_ctx);
730
+ SSL_CTX_free(ssl->session_ctx);
502
731
  OPENSSL_free(ssl->supported_group_list);
503
732
  OPENSSL_free(ssl->alpn_client_proto_list);
504
733
  EVP_PKEY_free(ssl->tlsext_channel_id_private);
505
734
  OPENSSL_free(ssl->psk_identity_hint);
506
- sk_X509_NAME_pop_free(ssl->client_CA, X509_NAME_free);
735
+ sk_CRYPTO_BUFFER_pop_free(ssl->client_CA, CRYPTO_BUFFER_free);
507
736
  sk_SRTP_PROTECTION_PROFILE_free(ssl->srtp_profiles);
508
737
 
509
738
  if (ssl->method != NULL) {
@@ -516,12 +745,12 @@ void SSL_free(SSL *ssl) {
516
745
 
517
746
  void SSL_set_connect_state(SSL *ssl) {
518
747
  ssl->server = 0;
519
- ssl->handshake_func = ssl3_connect;
748
+ ssl->do_handshake = ssl_client_handshake;
520
749
  }
521
750
 
522
751
  void SSL_set_accept_state(SSL *ssl) {
523
752
  ssl->server = 1;
524
- ssl->handshake_func = ssl3_accept;
753
+ ssl->do_handshake = ssl_server_handshake;
525
754
  }
526
755
 
527
756
  void SSL_set0_rbio(SSL *ssl, BIO *rbio) {
@@ -535,35 +764,35 @@ void SSL_set0_wbio(SSL *ssl, BIO *wbio) {
535
764
  }
536
765
 
537
766
  void SSL_set_bio(SSL *ssl, BIO *rbio, BIO *wbio) {
538
- /* For historical reasons, this function has many different cases in ownership
539
- * handling. */
767
+ // For historical reasons, this function has many different cases in ownership
768
+ // handling.
540
769
 
541
- /* If nothing has changed, do nothing */
770
+ // If nothing has changed, do nothing
542
771
  if (rbio == SSL_get_rbio(ssl) && wbio == SSL_get_wbio(ssl)) {
543
772
  return;
544
773
  }
545
774
 
546
- /* If the two arguments are equal, one fewer reference is granted than
547
- * taken. */
775
+ // If the two arguments are equal, one fewer reference is granted than
776
+ // taken.
548
777
  if (rbio != NULL && rbio == wbio) {
549
778
  BIO_up_ref(rbio);
550
779
  }
551
780
 
552
- /* If only the wbio is changed, adopt only one reference. */
781
+ // If only the wbio is changed, adopt only one reference.
553
782
  if (rbio == SSL_get_rbio(ssl)) {
554
783
  SSL_set0_wbio(ssl, wbio);
555
784
  return;
556
785
  }
557
786
 
558
- /* There is an asymmetry here for historical reasons. If only the rbio is
559
- * changed AND the rbio and wbio were originally different, then we only adopt
560
- * one reference. */
787
+ // There is an asymmetry here for historical reasons. If only the rbio is
788
+ // changed AND the rbio and wbio were originally different, then we only adopt
789
+ // one reference.
561
790
  if (wbio == SSL_get_wbio(ssl) && SSL_get_rbio(ssl) != SSL_get_wbio(ssl)) {
562
791
  SSL_set0_rbio(ssl, rbio);
563
792
  return;
564
793
  }
565
794
 
566
- /* Otherwise, adopt both references. */
795
+ // Otherwise, adopt both references.
567
796
  SSL_set0_rbio(ssl, rbio);
568
797
  SSL_set0_wbio(ssl, wbio);
569
798
  }
@@ -572,18 +801,10 @@ BIO *SSL_get_rbio(const SSL *ssl) { return ssl->rbio; }
572
801
 
573
802
  BIO *SSL_get_wbio(const SSL *ssl) { return ssl->wbio; }
574
803
 
575
- void ssl_reset_error_state(SSL *ssl) {
576
- /* Functions which use |SSL_get_error| must reset I/O and error state on
577
- * entry. */
578
- ssl->rwstate = SSL_NOTHING;
579
- ERR_clear_error();
580
- ERR_clear_system_error();
581
- }
582
-
583
804
  int SSL_do_handshake(SSL *ssl) {
584
805
  ssl_reset_error_state(ssl);
585
806
 
586
- if (ssl->handshake_func == NULL) {
807
+ if (ssl->do_handshake == NULL) {
587
808
  OPENSSL_PUT_ERROR(SSL, SSL_R_CONNECTION_TYPE_NOT_SET);
588
809
  return -1;
589
810
  }
@@ -592,20 +813,19 @@ int SSL_do_handshake(SSL *ssl) {
592
813
  return 1;
593
814
  }
594
815
 
595
- if (ssl->s3->hs == NULL) {
596
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
597
- return -1;
598
- }
816
+ // Run the handshake.
817
+ SSL_HANDSHAKE *hs = ssl->s3->hs;
599
818
 
600
- /* Run the handshake. */
601
- assert(ssl->s3->hs != NULL);
602
- int ret = ssl->handshake_func(ssl->s3->hs);
819
+ bool early_return = false;
820
+ int ret = ssl_run_handshake(hs, &early_return);
821
+ ssl_do_info_callback(
822
+ ssl, ssl->server ? SSL_CB_ACCEPT_EXIT : SSL_CB_CONNECT_EXIT, ret);
603
823
  if (ret <= 0) {
604
824
  return ret;
605
825
  }
606
826
 
607
- /* Destroy the handshake object if the handshake has completely finished. */
608
- if (!SSL_in_init(ssl)) {
827
+ // Destroy the handshake object if the handshake has completely finished.
828
+ if (!early_return) {
609
829
  ssl_handshake_free(ssl->s3->hs);
610
830
  ssl->s3->hs = NULL;
611
831
  }
@@ -614,8 +834,8 @@ int SSL_do_handshake(SSL *ssl) {
614
834
  }
615
835
 
616
836
  int SSL_connect(SSL *ssl) {
617
- if (ssl->handshake_func == NULL) {
618
- /* Not properly initialized yet */
837
+ if (ssl->do_handshake == NULL) {
838
+ // Not properly initialized yet
619
839
  SSL_set_connect_state(ssl);
620
840
  }
621
841
 
@@ -623,24 +843,27 @@ int SSL_connect(SSL *ssl) {
623
843
  }
624
844
 
625
845
  int SSL_accept(SSL *ssl) {
626
- if (ssl->handshake_func == NULL) {
627
- /* Not properly initialized yet */
846
+ if (ssl->do_handshake == NULL) {
847
+ // Not properly initialized yet
628
848
  SSL_set_accept_state(ssl);
629
849
  }
630
850
 
631
851
  return SSL_do_handshake(ssl);
632
852
  }
633
853
 
634
- static int ssl_do_renegotiate(SSL *ssl) {
635
- /* We do not accept renegotiations as a server or SSL 3.0. SSL 3.0 will be
636
- * removed entirely in the future and requires retaining more data for
637
- * renegotiation_info. */
854
+ static int ssl_do_post_handshake(SSL *ssl, const SSLMessage &msg) {
855
+ if (ssl3_protocol_version(ssl) >= TLS1_3_VERSION) {
856
+ return tls13_post_handshake(ssl, msg);
857
+ }
858
+
859
+ // We do not accept renegotiations as a server or SSL 3.0. SSL 3.0 will be
860
+ // removed entirely in the future and requires retaining more data for
861
+ // renegotiation_info.
638
862
  if (ssl->server || ssl->version == SSL3_VERSION) {
639
863
  goto no_renegotiation;
640
864
  }
641
865
 
642
- if (ssl->s3->tmp.message_type != SSL3_MT_HELLO_REQUEST ||
643
- ssl->init_num != 0) {
866
+ if (msg.type != SSL3_MT_HELLO_REQUEST || CBS_len(&msg.body) != 0) {
644
867
  ssl3_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
645
868
  OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_HELLO_REQUEST);
646
869
  return 0;
@@ -648,7 +871,7 @@ static int ssl_do_renegotiate(SSL *ssl) {
648
871
 
649
872
  switch (ssl->renegotiate_mode) {
650
873
  case ssl_renegotiate_ignore:
651
- /* Ignore the HelloRequest. */
874
+ // Ignore the HelloRequest.
652
875
  return 1;
653
876
 
654
877
  case ssl_renegotiate_once:
@@ -664,15 +887,15 @@ static int ssl_do_renegotiate(SSL *ssl) {
664
887
  break;
665
888
  }
666
889
 
667
- /* Renegotiation is only supported at quiescent points in the application
668
- * protocol, namely in HTTPS, just before reading the HTTP response. Require
669
- * the record-layer be idle and avoid complexities of sending a handshake
670
- * record while an application_data record is being written. */
890
+ // Renegotiation is only supported at quiescent points in the application
891
+ // protocol, namely in HTTPS, just before reading the HTTP response. Require
892
+ // the record-layer be idle and avoid complexities of sending a handshake
893
+ // record while an application_data record is being written.
671
894
  if (ssl_write_buffer_is_pending(ssl)) {
672
895
  goto no_renegotiation;
673
896
  }
674
897
 
675
- /* Begin a new handshake. */
898
+ // Begin a new handshake.
676
899
  if (ssl->s3->hs != NULL) {
677
900
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
678
901
  return 0;
@@ -691,27 +914,19 @@ no_renegotiation:
691
914
  return 0;
692
915
  }
693
916
 
694
- static int ssl_do_post_handshake(SSL *ssl) {
695
- if (ssl3_protocol_version(ssl) < TLS1_3_VERSION) {
696
- return ssl_do_renegotiate(ssl);
697
- }
698
-
699
- return tls13_post_handshake(ssl);
700
- }
701
-
702
917
  static int ssl_read_impl(SSL *ssl, void *buf, int num, int peek) {
703
918
  ssl_reset_error_state(ssl);
704
919
 
705
- if (ssl->handshake_func == NULL) {
920
+ if (ssl->do_handshake == NULL) {
706
921
  OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED);
707
922
  return -1;
708
923
  }
709
924
 
710
925
  for (;;) {
711
- /* Complete the current handshake, if any. False Start will cause
712
- * |SSL_do_handshake| to return mid-handshake, so this may require multiple
713
- * iterations. */
714
- while (SSL_in_init(ssl)) {
926
+ // Complete the current handshake, if any. False Start will cause
927
+ // |SSL_do_handshake| to return mid-handshake, so this may require multiple
928
+ // iterations.
929
+ while (!ssl_can_read(ssl)) {
715
930
  int ret = SSL_do_handshake(ssl);
716
931
  if (ret < 0) {
717
932
  return ret;
@@ -722,18 +937,28 @@ static int ssl_read_impl(SSL *ssl, void *buf, int num, int peek) {
722
937
  }
723
938
  }
724
939
 
725
- int got_handshake;
726
- int ret = ssl->method->read_app_data(ssl, &got_handshake, buf, num, peek);
940
+ bool got_handshake = false;
941
+ int ret = ssl->method->read_app_data(ssl, &got_handshake, (uint8_t *)buf,
942
+ num, peek);
727
943
  if (ret > 0 || !got_handshake) {
728
944
  ssl->s3->key_update_count = 0;
729
945
  return ret;
730
946
  }
731
947
 
732
- /* Handle the post-handshake message and try again. */
733
- if (!ssl_do_post_handshake(ssl)) {
734
- return -1;
948
+ // If we received an interrupt in early read (the end_of_early_data alert),
949
+ // loop again for the handshake to process it.
950
+ if (SSL_in_init(ssl)) {
951
+ continue;
952
+ }
953
+
954
+ SSLMessage msg;
955
+ while (ssl->method->get_message(ssl, &msg)) {
956
+ // Handle the post-handshake message and try again.
957
+ if (!ssl_do_post_handshake(ssl, msg)) {
958
+ return -1;
959
+ }
960
+ ssl->method->next_message(ssl);
735
961
  }
736
- ssl->method->release_current_message(ssl, 1 /* free buffer */);
737
962
  }
738
963
  }
739
964
 
@@ -748,84 +973,90 @@ int SSL_peek(SSL *ssl, void *buf, int num) {
748
973
  int SSL_write(SSL *ssl, const void *buf, int num) {
749
974
  ssl_reset_error_state(ssl);
750
975
 
751
- if (ssl->handshake_func == NULL) {
976
+ if (ssl->do_handshake == NULL) {
752
977
  OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED);
753
978
  return -1;
754
979
  }
755
980
 
756
- if (ssl->s3->send_shutdown != ssl_shutdown_none) {
981
+ if (ssl->s3->write_shutdown != ssl_shutdown_none) {
757
982
  OPENSSL_PUT_ERROR(SSL, SSL_R_PROTOCOL_IS_SHUTDOWN);
758
983
  return -1;
759
984
  }
760
985
 
761
- /* If necessary, complete the handshake implicitly. */
762
- if (SSL_in_init(ssl) && !SSL_in_false_start(ssl)) {
763
- int ret = SSL_do_handshake(ssl);
764
- if (ret < 0) {
765
- return ret;
766
- }
767
- if (ret == 0) {
768
- OPENSSL_PUT_ERROR(SSL, SSL_R_SSL_HANDSHAKE_FAILURE);
769
- return -1;
986
+ int ret = 0;
987
+ bool needs_handshake = false;
988
+ do {
989
+ // If necessary, complete the handshake implicitly.
990
+ if (!ssl_can_write(ssl)) {
991
+ ret = SSL_do_handshake(ssl);
992
+ if (ret < 0) {
993
+ return ret;
994
+ }
995
+ if (ret == 0) {
996
+ OPENSSL_PUT_ERROR(SSL, SSL_R_SSL_HANDSHAKE_FAILURE);
997
+ return -1;
998
+ }
770
999
  }
771
- }
772
1000
 
773
- return ssl->method->write_app_data(ssl, buf, num);
1001
+ ret = ssl->method->write_app_data(ssl, &needs_handshake,
1002
+ (const uint8_t *)buf, num);
1003
+ } while (needs_handshake);
1004
+ return ret;
774
1005
  }
775
1006
 
776
1007
  int SSL_shutdown(SSL *ssl) {
777
1008
  ssl_reset_error_state(ssl);
778
1009
 
779
- if (ssl->handshake_func == NULL) {
1010
+ if (ssl->do_handshake == NULL) {
780
1011
  OPENSSL_PUT_ERROR(SSL, SSL_R_UNINITIALIZED);
781
1012
  return -1;
782
1013
  }
783
1014
 
784
- /* If we are in the middle of a handshake, silently succeed. Consumers often
785
- * call this function before |SSL_free|, whether the handshake succeeded or
786
- * not. We assume the caller has already handled failed handshakes. */
1015
+ // If we are in the middle of a handshake, silently succeed. Consumers often
1016
+ // call this function before |SSL_free|, whether the handshake succeeded or
1017
+ // not. We assume the caller has already handled failed handshakes.
787
1018
  if (SSL_in_init(ssl)) {
788
1019
  return 1;
789
1020
  }
790
1021
 
791
1022
  if (ssl->quiet_shutdown) {
792
- /* Do nothing if configured not to send a close_notify. */
793
- ssl->s3->send_shutdown = ssl_shutdown_close_notify;
794
- ssl->s3->recv_shutdown = ssl_shutdown_close_notify;
1023
+ // Do nothing if configured not to send a close_notify.
1024
+ ssl->s3->write_shutdown = ssl_shutdown_close_notify;
1025
+ ssl->s3->read_shutdown = ssl_shutdown_close_notify;
795
1026
  return 1;
796
1027
  }
797
1028
 
798
- /* This function completes in two stages. It sends a close_notify and then it
799
- * waits for a close_notify to come in. Perform exactly one action and return
800
- * whether or not it succeeds. */
1029
+ // This function completes in two stages. It sends a close_notify and then it
1030
+ // waits for a close_notify to come in. Perform exactly one action and return
1031
+ // whether or not it succeeds.
801
1032
 
802
- if (ssl->s3->send_shutdown != ssl_shutdown_close_notify) {
803
- /* Send a close_notify. */
1033
+ if (ssl->s3->write_shutdown != ssl_shutdown_close_notify) {
1034
+ // Send a close_notify.
804
1035
  if (ssl3_send_alert(ssl, SSL3_AL_WARNING, SSL_AD_CLOSE_NOTIFY) <= 0) {
805
1036
  return -1;
806
1037
  }
807
1038
  } else if (ssl->s3->alert_dispatch) {
808
- /* Finish sending the close_notify. */
1039
+ // Finish sending the close_notify.
809
1040
  if (ssl->method->dispatch_alert(ssl) <= 0) {
810
1041
  return -1;
811
1042
  }
812
- } else if (ssl->s3->recv_shutdown != ssl_shutdown_close_notify) {
813
- /* Wait for the peer's close_notify. */
1043
+ } else if (ssl->s3->read_shutdown != ssl_shutdown_close_notify) {
1044
+ // Wait for the peer's close_notify.
814
1045
  ssl->method->read_close_notify(ssl);
815
- if (ssl->s3->recv_shutdown != ssl_shutdown_close_notify) {
1046
+ if (ssl->s3->read_shutdown != ssl_shutdown_close_notify) {
816
1047
  return -1;
817
1048
  }
818
1049
  }
819
1050
 
820
- /* Return 0 for unidirectional shutdown and 1 for bidirectional shutdown. */
821
- return ssl->s3->recv_shutdown == ssl_shutdown_close_notify;
1051
+ // Return 0 for unidirectional shutdown and 1 for bidirectional shutdown.
1052
+ return ssl->s3->read_shutdown == ssl_shutdown_close_notify;
822
1053
  }
823
1054
 
824
1055
  int SSL_send_fatal_alert(SSL *ssl, uint8_t alert) {
825
1056
  if (ssl->s3->alert_dispatch) {
826
1057
  if (ssl->s3->send_alert[0] != SSL3_AL_FATAL ||
827
1058
  ssl->s3->send_alert[1] != alert) {
828
- /* We are already attempting to write a different alert. */
1059
+ // We are already attempting to write a different alert.
829
1060
  OPENSSL_PUT_ERROR(SSL, SSL_R_PROTOCOL_IS_SHUTDOWN);
830
1061
  return -1;
831
1062
  }
@@ -836,7 +1067,47 @@ int SSL_send_fatal_alert(SSL *ssl, uint8_t alert) {
836
1067
  }
837
1068
 
838
1069
  void SSL_CTX_set_early_data_enabled(SSL_CTX *ctx, int enabled) {
839
- ctx->enable_early_data = !!enabled;
1070
+ ctx->cert->enable_early_data = !!enabled;
1071
+ }
1072
+
1073
+ void SSL_CTX_set_tls13_variant(SSL_CTX *ctx, enum tls13_variant_t variant) {
1074
+ ctx->tls13_variant = variant;
1075
+ }
1076
+
1077
+ void SSL_set_tls13_variant(SSL *ssl, enum tls13_variant_t variant) {
1078
+ ssl->tls13_variant = variant;
1079
+ }
1080
+
1081
+ void SSL_set_early_data_enabled(SSL *ssl, int enabled) {
1082
+ ssl->cert->enable_early_data = !!enabled;
1083
+ }
1084
+
1085
+ int SSL_in_early_data(const SSL *ssl) {
1086
+ if (ssl->s3->hs == NULL) {
1087
+ return 0;
1088
+ }
1089
+ return ssl->s3->hs->in_early_data;
1090
+ }
1091
+
1092
+ int SSL_early_data_accepted(const SSL *ssl) {
1093
+ return ssl->early_data_accepted;
1094
+ }
1095
+
1096
+ void SSL_reset_early_data_reject(SSL *ssl) {
1097
+ SSL_HANDSHAKE *hs = ssl->s3->hs;
1098
+ if (hs == NULL ||
1099
+ hs->wait != ssl_hs_early_data_rejected) {
1100
+ abort();
1101
+ }
1102
+
1103
+ hs->wait = ssl_hs_ok;
1104
+ hs->in_early_data = false;
1105
+ hs->early_session.reset();
1106
+
1107
+ // Discard any unfinished writes from the perspective of |SSL_write|'s
1108
+ // retry. The handshake will transparently flush out the pending record
1109
+ // (discarded by the server) to keep the framing correct.
1110
+ ssl->s3->wpend_pending = false;
840
1111
  }
841
1112
 
842
1113
  static int bio_retry_reason_to_error(int reason) {
@@ -855,8 +1126,8 @@ int SSL_get_error(const SSL *ssl, int ret_code) {
855
1126
  return SSL_ERROR_NONE;
856
1127
  }
857
1128
 
858
- /* Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake etc,
859
- * where we do encode the error */
1129
+ // Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake etc,
1130
+ // where we do encode the error
860
1131
  uint32_t err = ERR_peek_error();
861
1132
  if (err != 0) {
862
1133
  if (ERR_GET_LIB(err) == ERR_LIB_SYS) {
@@ -866,12 +1137,12 @@ int SSL_get_error(const SSL *ssl, int ret_code) {
866
1137
  }
867
1138
 
868
1139
  if (ret_code == 0) {
869
- if (ssl->s3->recv_shutdown == ssl_shutdown_close_notify) {
1140
+ if (ssl->s3->read_shutdown == ssl_shutdown_close_notify) {
870
1141
  return SSL_ERROR_ZERO_RETURN;
871
1142
  }
872
- /* An EOF was observed which violates the protocol, and the underlying
873
- * transport does not participate in the error queue. Bubble up to the
874
- * caller. */
1143
+ // An EOF was observed which violates the protocol, and the underlying
1144
+ // transport does not participate in the error queue. Bubble up to the
1145
+ // caller.
875
1146
  return SSL_ERROR_SYSCALL;
876
1147
  }
877
1148
 
@@ -889,8 +1160,8 @@ int SSL_get_error(const SSL *ssl, int ret_code) {
889
1160
  }
890
1161
 
891
1162
  if (BIO_should_write(bio)) {
892
- /* TODO(davidben): OpenSSL historically checked for writes on the read
893
- * BIO. Can this be removed? */
1163
+ // TODO(davidben): OpenSSL historically checked for writes on the read
1164
+ // BIO. Can this be removed?
894
1165
  return SSL_ERROR_WANT_WRITE;
895
1166
  }
896
1167
 
@@ -908,8 +1179,8 @@ int SSL_get_error(const SSL *ssl, int ret_code) {
908
1179
  }
909
1180
 
910
1181
  if (BIO_should_read(bio)) {
911
- /* TODO(davidben): OpenSSL historically checked for reads on the write
912
- * BIO. Can this be removed? */
1182
+ // TODO(davidben): OpenSSL historically checked for reads on the write
1183
+ // BIO. Can this be removed?
913
1184
  return SSL_ERROR_WANT_READ;
914
1185
  }
915
1186
 
@@ -928,57 +1199,18 @@ int SSL_get_error(const SSL *ssl, int ret_code) {
928
1199
 
929
1200
  case SSL_PRIVATE_KEY_OPERATION:
930
1201
  return SSL_ERROR_WANT_PRIVATE_KEY_OPERATION;
931
- }
932
-
933
- return SSL_ERROR_SYSCALL;
934
- }
935
-
936
- static int set_min_version(const SSL_PROTOCOL_METHOD *method, uint16_t *out,
937
- uint16_t version) {
938
- if (version == 0) {
939
- *out = method->min_version;
940
- return 1;
941
- }
942
1202
 
943
- if (version == TLS1_3_VERSION) {
944
- version = TLS1_3_DRAFT_VERSION;
945
- }
946
-
947
- return method->version_from_wire(out, version);
948
- }
1203
+ case SSL_PENDING_TICKET:
1204
+ return SSL_ERROR_PENDING_TICKET;
949
1205
 
950
- static int set_max_version(const SSL_PROTOCOL_METHOD *method, uint16_t *out,
951
- uint16_t version) {
952
- if (version == 0) {
953
- *out = method->max_version;
954
- /* TODO(svaldez): Enable TLS 1.3 by default once fully implemented. */
955
- if (*out > TLS1_2_VERSION) {
956
- *out = TLS1_2_VERSION;
957
- }
958
- return 1;
959
- }
1206
+ case SSL_EARLY_DATA_REJECTED:
1207
+ return SSL_ERROR_EARLY_DATA_REJECTED;
960
1208
 
961
- if (version == TLS1_3_VERSION) {
962
- version = TLS1_3_DRAFT_VERSION;
1209
+ case SSL_CERTIFICATE_VERIFY:
1210
+ return SSL_ERROR_WANT_CERTIFICATE_VERIFY;
963
1211
  }
964
1212
 
965
- return method->version_from_wire(out, version);
966
- }
967
-
968
- int SSL_CTX_set_min_proto_version(SSL_CTX *ctx, uint16_t version) {
969
- return set_min_version(ctx->method, &ctx->min_version, version);
970
- }
971
-
972
- int SSL_CTX_set_max_proto_version(SSL_CTX *ctx, uint16_t version) {
973
- return set_max_version(ctx->method, &ctx->max_version, version);
974
- }
975
-
976
- int SSL_set_min_proto_version(SSL *ssl, uint16_t version) {
977
- return set_min_version(ssl->method, &ssl->min_version, version);
978
- }
979
-
980
- int SSL_set_max_proto_version(SSL *ssl, uint16_t version) {
981
- return set_max_version(ssl->method, &ssl->max_version, version);
1213
+ return SSL_ERROR_SYSCALL;
982
1214
  }
983
1215
 
984
1216
  uint32_t SSL_CTX_set_options(SSL_CTX *ctx, uint32_t options) {
@@ -1035,22 +1267,25 @@ void SSL_CTX_set0_buffer_pool(SSL_CTX *ctx, CRYPTO_BUFFER_POOL *pool) {
1035
1267
 
1036
1268
  int SSL_get_tls_unique(const SSL *ssl, uint8_t *out, size_t *out_len,
1037
1269
  size_t max_out) {
1038
- /* tls-unique is not defined for SSL 3.0 or TLS 1.3. */
1270
+ *out_len = 0;
1271
+ OPENSSL_memset(out, 0, max_out);
1272
+
1273
+ // tls-unique is not defined for SSL 3.0 or TLS 1.3.
1039
1274
  if (!ssl->s3->initial_handshake_complete ||
1040
1275
  ssl3_protocol_version(ssl) < TLS1_VERSION ||
1041
1276
  ssl3_protocol_version(ssl) >= TLS1_3_VERSION) {
1042
- goto err;
1277
+ return 0;
1043
1278
  }
1044
1279
 
1045
- /* The tls-unique value is the first Finished message in the handshake, which
1046
- * is the client's in a full handshake and the server's for a resumption. See
1047
- * https://tools.ietf.org/html/rfc5929#section-3.1. */
1280
+ // The tls-unique value is the first Finished message in the handshake, which
1281
+ // is the client's in a full handshake and the server's for a resumption. See
1282
+ // https://tools.ietf.org/html/rfc5929#section-3.1.
1048
1283
  const uint8_t *finished = ssl->s3->previous_client_finished;
1049
1284
  size_t finished_len = ssl->s3->previous_client_finished_len;
1050
1285
  if (ssl->session != NULL) {
1051
- /* tls-unique is broken for resumed sessions unless EMS is used. */
1286
+ // tls-unique is broken for resumed sessions unless EMS is used.
1052
1287
  if (!ssl->session->extended_master_secret) {
1053
- goto err;
1288
+ return 0;
1054
1289
  }
1055
1290
  finished = ssl->s3->previous_server_finished;
1056
1291
  finished_len = ssl->s3->previous_server_finished_len;
@@ -1063,11 +1298,6 @@ int SSL_get_tls_unique(const SSL *ssl, uint8_t *out, size_t *out_len,
1063
1298
 
1064
1299
  OPENSSL_memcpy(out, finished, *out_len);
1065
1300
  return 1;
1066
-
1067
- err:
1068
- *out_len = 0;
1069
- OPENSSL_memset(out, 0, max_out);
1070
- return 0;
1071
1301
  }
1072
1302
 
1073
1303
  static int set_session_id_context(CERT *cert, const uint8_t *sid_ctx,
@@ -1077,7 +1307,7 @@ static int set_session_id_context(CERT *cert, const uint8_t *sid_ctx,
1077
1307
  return 0;
1078
1308
  }
1079
1309
 
1080
- OPENSSL_COMPILE_ASSERT(sizeof(cert->sid_ctx) < 256, sid_ctx_too_large);
1310
+ static_assert(sizeof(cert->sid_ctx) < 256, "sid_ctx too large");
1081
1311
  cert->sid_ctx_length = (uint8_t)sid_ctx_len;
1082
1312
  OPENSSL_memcpy(cert->sid_ctx, sid_ctx, sid_ctx_len);
1083
1313
  return 1;
@@ -1098,16 +1328,6 @@ const uint8_t *SSL_get0_session_id_context(const SSL *ssl, size_t *out_len) {
1098
1328
  return ssl->cert->sid_ctx;
1099
1329
  }
1100
1330
 
1101
- void ssl_cipher_preference_list_free(
1102
- struct ssl_cipher_preference_list_st *cipher_list) {
1103
- if (cipher_list == NULL) {
1104
- return;
1105
- }
1106
- sk_SSL_CIPHER_free(cipher_list->ciphers);
1107
- OPENSSL_free(cipher_list->in_group_flags);
1108
- OPENSSL_free(cipher_list);
1109
- }
1110
-
1111
1331
  void SSL_certs_clear(SSL *ssl) { ssl_cert_clear_certs(ssl->cert); }
1112
1332
 
1113
1333
  int SSL_get_fd(const SSL *ssl) { return SSL_get_rfd(ssl); }
@@ -1153,7 +1373,7 @@ int SSL_set_wfd(SSL *ssl, int fd) {
1153
1373
  BIO_set_fd(bio, fd, BIO_NOCLOSE);
1154
1374
  SSL_set0_wbio(ssl, bio);
1155
1375
  } else {
1156
- /* Copy the rbio over to the wbio. */
1376
+ // Copy the rbio over to the wbio.
1157
1377
  BIO_up_ref(rbio);
1158
1378
  SSL_set0_wbio(ssl, rbio);
1159
1379
  }
@@ -1173,7 +1393,7 @@ int SSL_set_rfd(SSL *ssl, int fd) {
1173
1393
  BIO_set_fd(bio, fd, BIO_NOCLOSE);
1174
1394
  SSL_set0_rbio(ssl, bio);
1175
1395
  } else {
1176
- /* Copy the wbio over to the rbio. */
1396
+ // Copy the wbio over to the rbio.
1177
1397
  BIO_up_ref(wbio);
1178
1398
  SSL_set0_rbio(ssl, wbio);
1179
1399
  }
@@ -1224,8 +1444,8 @@ size_t SSL_get_peer_finished(const SSL *ssl, void *buf, size_t count) {
1224
1444
  int SSL_get_verify_mode(const SSL *ssl) { return ssl->verify_mode; }
1225
1445
 
1226
1446
  int SSL_get_extms_support(const SSL *ssl) {
1227
- /* TLS 1.3 does not require extended master secret and always reports as
1228
- * supporting it. */
1447
+ // TLS 1.3 does not require extended master secret and always reports as
1448
+ // supporting it.
1229
1449
  if (!ssl->s3->have_version) {
1230
1450
  return 0;
1231
1451
  }
@@ -1233,12 +1453,12 @@ int SSL_get_extms_support(const SSL *ssl) {
1233
1453
  return 1;
1234
1454
  }
1235
1455
 
1236
- /* If the initial handshake completed, query the established session. */
1456
+ // If the initial handshake completed, query the established session.
1237
1457
  if (ssl->s3->established_session != NULL) {
1238
1458
  return ssl->s3->established_session->extended_master_secret;
1239
1459
  }
1240
1460
 
1241
- /* Otherwise, query the in-progress handshake. */
1461
+ // Otherwise, query the in-progress handshake.
1242
1462
  if (ssl->s3->hs != NULL) {
1243
1463
  return ssl->s3->hs->extended_master_secret;
1244
1464
  }
@@ -1261,12 +1481,12 @@ int SSL_pending(const SSL *ssl) {
1261
1481
  return ssl->s3->rrec.length;
1262
1482
  }
1263
1483
 
1264
- /* Fix this so it checks all the valid key/cert options */
1484
+ // Fix this so it checks all the valid key/cert options
1265
1485
  int SSL_CTX_check_private_key(const SSL_CTX *ctx) {
1266
1486
  return ssl_cert_check_private_key(ctx->cert, ctx->cert->privatekey);
1267
1487
  }
1268
1488
 
1269
- /* Fix this function so that it takes an optional type parameter */
1489
+ // Fix this function so that it takes an optional type parameter
1270
1490
  int SSL_check_private_key(const SSL *ssl) {
1271
1491
  return ssl_cert_check_private_key(ssl->cert, ssl->cert->privatekey);
1272
1492
  }
@@ -1276,7 +1496,7 @@ long SSL_get_default_timeout(const SSL *ssl) {
1276
1496
  }
1277
1497
 
1278
1498
  int SSL_renegotiate(SSL *ssl) {
1279
- /* Caller-initiated renegotiation is not supported. */
1499
+ // Caller-initiated renegotiation is not supported.
1280
1500
  OPENSSL_PUT_ERROR(SSL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1281
1501
  return 0;
1282
1502
  }
@@ -1351,9 +1571,8 @@ int SSL_get_secure_renegotiation_support(const SSL *ssl) {
1351
1571
  ssl->s3->send_connection_binding;
1352
1572
  }
1353
1573
 
1354
- LHASH_OF(SSL_SESSION) *SSL_CTX_sessions(SSL_CTX *ctx) { return ctx->sessions; }
1355
-
1356
1574
  size_t SSL_CTX_sess_number(const SSL_CTX *ctx) {
1575
+ MutexReadLock lock(const_cast<CRYPTO_MUTEX *>(&ctx->lock));
1357
1576
  return lh_SSL_SESSION_num_items(ctx->sessions);
1358
1577
  }
1359
1578
 
@@ -1386,10 +1605,18 @@ int SSL_CTX_get_tlsext_ticket_keys(SSL_CTX *ctx, void *out, size_t len) {
1386
1605
  OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_TICKET_KEYS_LENGTH);
1387
1606
  return 0;
1388
1607
  }
1389
- uint8_t *out_bytes = out;
1390
- OPENSSL_memcpy(out_bytes, ctx->tlsext_tick_key_name, 16);
1391
- OPENSSL_memcpy(out_bytes + 16, ctx->tlsext_tick_hmac_key, 16);
1392
- OPENSSL_memcpy(out_bytes + 32, ctx->tlsext_tick_aes_key, 16);
1608
+
1609
+ // The default ticket keys are initialized lazily. Trigger a key
1610
+ // rotation to initialize them.
1611
+ if (!ssl_ctx_rotate_ticket_encryption_key(ctx)) {
1612
+ return 0;
1613
+ }
1614
+
1615
+ uint8_t *out_bytes = reinterpret_cast<uint8_t *>(out);
1616
+ MutexReadLock lock(&ctx->lock);
1617
+ OPENSSL_memcpy(out_bytes, ctx->tlsext_ticket_key_current->name, 16);
1618
+ OPENSSL_memcpy(out_bytes + 16, ctx->tlsext_ticket_key_current->hmac_key, 16);
1619
+ OPENSSL_memcpy(out_bytes + 32, ctx->tlsext_ticket_key_current->aes_key, 16);
1393
1620
  return 1;
1394
1621
  }
1395
1622
 
@@ -1401,10 +1628,22 @@ int SSL_CTX_set_tlsext_ticket_keys(SSL_CTX *ctx, const void *in, size_t len) {
1401
1628
  OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_TICKET_KEYS_LENGTH);
1402
1629
  return 0;
1403
1630
  }
1404
- const uint8_t *in_bytes = in;
1405
- OPENSSL_memcpy(ctx->tlsext_tick_key_name, in_bytes, 16);
1406
- OPENSSL_memcpy(ctx->tlsext_tick_hmac_key, in_bytes + 16, 16);
1407
- OPENSSL_memcpy(ctx->tlsext_tick_aes_key, in_bytes + 32, 16);
1631
+ if (!ctx->tlsext_ticket_key_current) {
1632
+ ctx->tlsext_ticket_key_current =
1633
+ (tlsext_ticket_key *)OPENSSL_malloc(sizeof(tlsext_ticket_key));
1634
+ if (!ctx->tlsext_ticket_key_current) {
1635
+ return 0;
1636
+ }
1637
+ }
1638
+ OPENSSL_memset(ctx->tlsext_ticket_key_current, 0, sizeof(tlsext_ticket_key));
1639
+ const uint8_t *in_bytes = reinterpret_cast<const uint8_t *>(in);
1640
+ OPENSSL_memcpy(ctx->tlsext_ticket_key_current->name, in_bytes, 16);
1641
+ OPENSSL_memcpy(ctx->tlsext_ticket_key_current->hmac_key, in_bytes + 16, 16);
1642
+ OPENSSL_memcpy(ctx->tlsext_ticket_key_current->aes_key, in_bytes + 32, 16);
1643
+ OPENSSL_free(ctx->tlsext_ticket_key_prev);
1644
+ ctx->tlsext_ticket_key_prev = nullptr;
1645
+ // Disable automatic key rotation.
1646
+ ctx->tlsext_ticket_key_current->next_rotation_tv_sec = 0;
1408
1647
  return 1;
1409
1648
  }
1410
1649
 
@@ -1439,8 +1678,8 @@ int SSL_set1_curves_list(SSL *ssl, const char *curves) {
1439
1678
  }
1440
1679
 
1441
1680
  uint16_t SSL_get_curve_id(const SSL *ssl) {
1442
- /* TODO(davidben): This checks the wrong session if there is a renegotiation in
1443
- * progress. */
1681
+ // TODO(davidben): This checks the wrong session if there is a renegotiation
1682
+ // in progress.
1444
1683
  SSL_SESSION *session = SSL_get_session(ssl);
1445
1684
  if (session == NULL) {
1446
1685
  return 0;
@@ -1450,23 +1689,22 @@ uint16_t SSL_get_curve_id(const SSL *ssl) {
1450
1689
  }
1451
1690
 
1452
1691
  int SSL_CTX_set_tmp_dh(SSL_CTX *ctx, const DH *dh) {
1453
- DH_free(ctx->cert->dh_tmp);
1454
- ctx->cert->dh_tmp = DHparams_dup(dh);
1455
- if (ctx->cert->dh_tmp == NULL) {
1456
- OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1457
- return 0;
1458
- }
1459
1692
  return 1;
1460
1693
  }
1461
1694
 
1462
1695
  int SSL_set_tmp_dh(SSL *ssl, const DH *dh) {
1463
- DH_free(ssl->cert->dh_tmp);
1464
- ssl->cert->dh_tmp = DHparams_dup(dh);
1465
- if (ssl->cert->dh_tmp == NULL) {
1466
- OPENSSL_PUT_ERROR(SSL, ERR_R_DH_LIB);
1696
+ return 1;
1697
+ }
1698
+
1699
+ STACK_OF(SSL_CIPHER) *SSL_CTX_get_ciphers(const SSL_CTX *ctx) {
1700
+ return ctx->cipher_list->ciphers;
1701
+ }
1702
+
1703
+ int SSL_CTX_cipher_in_group(const SSL_CTX *ctx, size_t i) {
1704
+ if (i >= sk_SSL_CIPHER_num(ctx->cipher_list->ciphers)) {
1467
1705
  return 0;
1468
1706
  }
1469
- return 1;
1707
+ return ctx->cipher_list->in_group_flags[i];
1470
1708
  }
1471
1709
 
1472
1710
  STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *ssl) {
@@ -1484,19 +1722,16 @@ STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *ssl) {
1484
1722
  }
1485
1723
 
1486
1724
  const char *SSL_get_cipher_list(const SSL *ssl, int n) {
1487
- const SSL_CIPHER *c;
1488
- STACK_OF(SSL_CIPHER) *sk;
1489
-
1490
1725
  if (ssl == NULL) {
1491
1726
  return NULL;
1492
1727
  }
1493
1728
 
1494
- sk = SSL_get_ciphers(ssl);
1729
+ STACK_OF(SSL_CIPHER) *sk = SSL_get_ciphers(ssl);
1495
1730
  if (sk == NULL || n < 0 || (size_t)n >= sk_SSL_CIPHER_num(sk)) {
1496
1731
  return NULL;
1497
1732
  }
1498
1733
 
1499
- c = sk_SSL_CIPHER_value(sk, n);
1734
+ const SSL_CIPHER *c = sk_SSL_CIPHER_value(sk, n);
1500
1735
  if (c == NULL) {
1501
1736
  return NULL;
1502
1737
  }
@@ -1505,71 +1740,23 @@ const char *SSL_get_cipher_list(const SSL *ssl, int n) {
1505
1740
  }
1506
1741
 
1507
1742
  int SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str) {
1508
- STACK_OF(SSL_CIPHER) *cipher_list =
1509
- ssl_create_cipher_list(ctx->method, &ctx->cipher_list, str,
1510
- 0 /* not strict */);
1511
- if (cipher_list == NULL) {
1512
- return 0;
1513
- }
1514
-
1515
- /* |ssl_create_cipher_list| may succeed but return an empty cipher list. */
1516
- if (sk_SSL_CIPHER_num(cipher_list) == 0) {
1517
- OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH);
1518
- return 0;
1519
- }
1520
-
1521
- return 1;
1743
+ return ssl_create_cipher_list(ctx->method, &ctx->cipher_list, str,
1744
+ false /* not strict */);
1522
1745
  }
1523
1746
 
1524
1747
  int SSL_CTX_set_strict_cipher_list(SSL_CTX *ctx, const char *str) {
1525
- STACK_OF(SSL_CIPHER) *cipher_list =
1526
- ssl_create_cipher_list(ctx->method, &ctx->cipher_list, str,
1527
- 1 /* strict */);
1528
- if (cipher_list == NULL) {
1529
- return 0;
1530
- }
1531
-
1532
- /* |ssl_create_cipher_list| may succeed but return an empty cipher list. */
1533
- if (sk_SSL_CIPHER_num(cipher_list) == 0) {
1534
- OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH);
1535
- return 0;
1536
- }
1537
-
1538
- return 1;
1748
+ return ssl_create_cipher_list(ctx->method, &ctx->cipher_list, str,
1749
+ true /* strict */);
1539
1750
  }
1540
1751
 
1541
1752
  int SSL_set_cipher_list(SSL *ssl, const char *str) {
1542
- STACK_OF(SSL_CIPHER) *cipher_list =
1543
- ssl_create_cipher_list(ssl->ctx->method, &ssl->cipher_list, str,
1544
- 0 /* not strict */);
1545
- if (cipher_list == NULL) {
1546
- return 0;
1547
- }
1548
-
1549
- /* |ssl_create_cipher_list| may succeed but return an empty cipher list. */
1550
- if (sk_SSL_CIPHER_num(cipher_list) == 0) {
1551
- OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH);
1552
- return 0;
1553
- }
1554
-
1555
- return 1;
1753
+ return ssl_create_cipher_list(ssl->ctx->method, &ssl->cipher_list, str,
1754
+ false /* not strict */);
1556
1755
  }
1557
1756
 
1558
- int SSL_set_strict_cipher_list(SSL *ssl, const char *str) {
1559
- STACK_OF(SSL_CIPHER) *cipher_list =
1560
- ssl_create_cipher_list(ssl->ctx->method, &ssl->cipher_list, str,
1561
- 1 /* strict */);
1562
- if (cipher_list == NULL) {
1563
- return 0;
1564
- }
1565
-
1566
- /* |ssl_create_cipher_list| may succeed but return an empty cipher list. */
1567
- if (sk_SSL_CIPHER_num(cipher_list) == 0) {
1568
- OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHER_MATCH);
1569
- return 0;
1570
- }
1571
-
1572
- return 1;
1757
+ int SSL_set_strict_cipher_list(SSL *ssl, const char *str) {
1758
+ return ssl_create_cipher_list(ssl->ctx->method, &ssl->cipher_list, str,
1759
+ true /* strict */);
1573
1760
  }
1574
1761
 
1575
1762
  const char *SSL_get_servername(const SSL *ssl, const int type) {
@@ -1577,36 +1764,36 @@ const char *SSL_get_servername(const SSL *ssl, const int type) {
1577
1764
  return NULL;
1578
1765
  }
1579
1766
 
1580
- /* Historically, |SSL_get_servername| was also the configuration getter
1581
- * corresponding to |SSL_set_tlsext_host_name|. */
1767
+ // Historically, |SSL_get_servername| was also the configuration getter
1768
+ // corresponding to |SSL_set_tlsext_host_name|.
1582
1769
  if (ssl->tlsext_hostname != NULL) {
1583
1770
  return ssl->tlsext_hostname;
1584
1771
  }
1585
1772
 
1586
- /* During the handshake, report the handshake value. */
1587
- if (ssl->s3->hs != NULL) {
1588
- return ssl->s3->hs->hostname;
1589
- }
1590
-
1591
- /* SSL_get_servername may also be called after the handshake to look up the
1592
- * SNI value.
1593
- *
1594
- * TODO(davidben): This is almost unused. Can we remove it? */
1595
- SSL_SESSION *session = SSL_get_session(ssl);
1596
- if (session == NULL) {
1597
- return NULL;
1598
- }
1599
- return session->tlsext_hostname;
1773
+ return ssl->s3->hostname;
1600
1774
  }
1601
1775
 
1602
1776
  int SSL_get_servername_type(const SSL *ssl) {
1603
- SSL_SESSION *session = SSL_get_session(ssl);
1604
- if (session == NULL || session->tlsext_hostname == NULL) {
1777
+ if (SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name) == NULL) {
1605
1778
  return -1;
1606
1779
  }
1607
1780
  return TLSEXT_NAMETYPE_host_name;
1608
1781
  }
1609
1782
 
1783
+ void SSL_CTX_set_custom_verify(
1784
+ SSL_CTX *ctx, int mode,
1785
+ enum ssl_verify_result_t (*callback)(SSL *ssl, uint8_t *out_alert)) {
1786
+ ctx->verify_mode = mode;
1787
+ ctx->custom_verify_callback = callback;
1788
+ }
1789
+
1790
+ void SSL_set_custom_verify(
1791
+ SSL *ssl, int mode,
1792
+ enum ssl_verify_result_t (*callback)(SSL *ssl, uint8_t *out_alert)) {
1793
+ ssl->verify_mode = mode;
1794
+ ssl->custom_verify_callback = callback;
1795
+ }
1796
+
1610
1797
  void SSL_CTX_enable_signed_cert_timestamps(SSL_CTX *ctx) {
1611
1798
  ctx->signed_cert_timestamps_enabled = 1;
1612
1799
  }
@@ -1626,28 +1813,27 @@ void SSL_enable_ocsp_stapling(SSL *ssl) {
1626
1813
  void SSL_get0_signed_cert_timestamp_list(const SSL *ssl, const uint8_t **out,
1627
1814
  size_t *out_len) {
1628
1815
  SSL_SESSION *session = SSL_get_session(ssl);
1629
-
1630
- *out_len = 0;
1631
- *out = NULL;
1632
- if (ssl->server || !session || !session->tlsext_signed_cert_timestamp_list) {
1816
+ if (ssl->server || !session || !session->signed_cert_timestamp_list) {
1817
+ *out_len = 0;
1818
+ *out = NULL;
1633
1819
  return;
1634
1820
  }
1635
1821
 
1636
- *out = session->tlsext_signed_cert_timestamp_list;
1637
- *out_len = session->tlsext_signed_cert_timestamp_list_length;
1822
+ *out = CRYPTO_BUFFER_data(session->signed_cert_timestamp_list);
1823
+ *out_len = CRYPTO_BUFFER_len(session->signed_cert_timestamp_list);
1638
1824
  }
1639
1825
 
1640
1826
  void SSL_get0_ocsp_response(const SSL *ssl, const uint8_t **out,
1641
1827
  size_t *out_len) {
1642
1828
  SSL_SESSION *session = SSL_get_session(ssl);
1643
-
1644
- *out_len = 0;
1645
- *out = NULL;
1646
1829
  if (ssl->server || !session || !session->ocsp_response) {
1830
+ *out_len = 0;
1831
+ *out = NULL;
1647
1832
  return;
1648
1833
  }
1649
- *out = session->ocsp_response;
1650
- *out_len = session->ocsp_response_length;
1834
+
1835
+ *out = CRYPTO_BUFFER_data(session->ocsp_response);
1836
+ *out_len = CRYPTO_BUFFER_len(session->ocsp_response);
1651
1837
  }
1652
1838
 
1653
1839
  int SSL_set_tlsext_host_name(SSL *ssl, const char *name) {
@@ -1682,32 +1868,31 @@ int SSL_CTX_set_tlsext_servername_arg(SSL_CTX *ctx, void *arg) {
1682
1868
  return 1;
1683
1869
  }
1684
1870
 
1685
- int SSL_select_next_proto(uint8_t **out, uint8_t *out_len,
1686
- const uint8_t *server, unsigned server_len,
1687
- const uint8_t *client, unsigned client_len) {
1688
- unsigned int i, j;
1871
+ int SSL_select_next_proto(uint8_t **out, uint8_t *out_len, const uint8_t *peer,
1872
+ unsigned peer_len, const uint8_t *supported,
1873
+ unsigned supported_len) {
1689
1874
  const uint8_t *result;
1690
- int status = OPENSSL_NPN_UNSUPPORTED;
1691
-
1692
- /* For each protocol in server preference order, see if we support it. */
1693
- for (i = 0; i < server_len;) {
1694
- for (j = 0; j < client_len;) {
1695
- if (server[i] == client[j] &&
1696
- OPENSSL_memcmp(&server[i + 1], &client[j + 1], server[i]) == 0) {
1697
- /* We found a match */
1698
- result = &server[i];
1875
+ int status;
1876
+
1877
+ // For each protocol in peer preference order, see if we support it.
1878
+ for (unsigned i = 0; i < peer_len;) {
1879
+ for (unsigned j = 0; j < supported_len;) {
1880
+ if (peer[i] == supported[j] &&
1881
+ OPENSSL_memcmp(&peer[i + 1], &supported[j + 1], peer[i]) == 0) {
1882
+ // We found a match
1883
+ result = &peer[i];
1699
1884
  status = OPENSSL_NPN_NEGOTIATED;
1700
1885
  goto found;
1701
1886
  }
1702
- j += client[j];
1887
+ j += supported[j];
1703
1888
  j++;
1704
1889
  }
1705
- i += server[i];
1890
+ i += peer[i];
1706
1891
  i++;
1707
1892
  }
1708
1893
 
1709
- /* There's no overlap between our protocols and the server's list. */
1710
- result = client;
1894
+ // There's no overlap between our protocols and the peer's list.
1895
+ result = supported;
1711
1896
  status = OPENSSL_NPN_NO_OVERLAP;
1712
1897
 
1713
1898
  found:
@@ -1719,11 +1904,7 @@ found:
1719
1904
  void SSL_get0_next_proto_negotiated(const SSL *ssl, const uint8_t **out_data,
1720
1905
  unsigned *out_len) {
1721
1906
  *out_data = ssl->s3->next_proto_negotiated;
1722
- if (*out_data == NULL) {
1723
- *out_len = 0;
1724
- } else {
1725
- *out_len = ssl->s3->next_proto_negotiated_len;
1726
- }
1907
+ *out_len = ssl->s3->next_proto_negotiated_len;
1727
1908
  }
1728
1909
 
1729
1910
  void SSL_CTX_set_next_protos_advertised_cb(
@@ -1745,7 +1926,7 @@ void SSL_CTX_set_next_proto_select_cb(
1745
1926
  int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const uint8_t *protos,
1746
1927
  unsigned protos_len) {
1747
1928
  OPENSSL_free(ctx->alpn_client_proto_list);
1748
- ctx->alpn_client_proto_list = BUF_memdup(protos, protos_len);
1929
+ ctx->alpn_client_proto_list = (uint8_t *)BUF_memdup(protos, protos_len);
1749
1930
  if (!ctx->alpn_client_proto_list) {
1750
1931
  return 1;
1751
1932
  }
@@ -1756,7 +1937,7 @@ int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const uint8_t *protos,
1756
1937
 
1757
1938
  int SSL_set_alpn_protos(SSL *ssl, const uint8_t *protos, unsigned protos_len) {
1758
1939
  OPENSSL_free(ssl->alpn_client_proto_list);
1759
- ssl->alpn_client_proto_list = BUF_memdup(protos, protos_len);
1940
+ ssl->alpn_client_proto_list = (uint8_t *)BUF_memdup(protos, protos_len);
1760
1941
  if (!ssl->alpn_client_proto_list) {
1761
1942
  return 1;
1762
1943
  }
@@ -1776,17 +1957,18 @@ void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx,
1776
1957
 
1777
1958
  void SSL_get0_alpn_selected(const SSL *ssl, const uint8_t **out_data,
1778
1959
  unsigned *out_len) {
1779
- *out_data = NULL;
1780
- if (ssl->s3) {
1781
- *out_data = ssl->s3->alpn_selected;
1782
- }
1783
- if (*out_data == NULL) {
1784
- *out_len = 0;
1960
+ if (SSL_in_early_data(ssl) && !ssl->server) {
1961
+ *out_data = ssl->s3->hs->early_session->early_alpn;
1962
+ *out_len = ssl->s3->hs->early_session->early_alpn_len;
1785
1963
  } else {
1964
+ *out_data = ssl->s3->alpn_selected;
1786
1965
  *out_len = ssl->s3->alpn_selected_len;
1787
1966
  }
1788
1967
  }
1789
1968
 
1969
+ void SSL_CTX_set_allow_unknown_alpn_protos(SSL_CTX *ctx, int enabled) {
1970
+ ctx->allow_unknown_alpn_protos = !!enabled;
1971
+ }
1790
1972
 
1791
1973
  void SSL_CTX_set_tls_channel_id_enabled(SSL_CTX *ctx, int enabled) {
1792
1974
  ctx->tlsext_channel_id_enabled = !!enabled;
@@ -1855,95 +2037,8 @@ size_t SSL_get0_certificate_types(SSL *ssl, const uint8_t **out_types) {
1855
2037
  *out_types = NULL;
1856
2038
  return 0;
1857
2039
  }
1858
- *out_types = ssl->s3->hs->certificate_types;
1859
- return ssl->s3->hs->num_certificate_types;
1860
- }
1861
-
1862
- void ssl_update_cache(SSL_HANDSHAKE *hs, int mode) {
1863
- SSL *const ssl = hs->ssl;
1864
- SSL_CTX *ctx = ssl->initial_ctx;
1865
- /* Never cache sessions with empty session IDs. */
1866
- if (ssl->s3->established_session->session_id_length == 0 ||
1867
- (ctx->session_cache_mode & mode) != mode) {
1868
- return;
1869
- }
1870
-
1871
- /* Clients never use the internal session cache. */
1872
- int use_internal_cache = ssl->server && !(ctx->session_cache_mode &
1873
- SSL_SESS_CACHE_NO_INTERNAL_STORE);
1874
-
1875
- /* A client may see new sessions on abbreviated handshakes if the server
1876
- * decides to renew the ticket. Once the handshake is completed, it should be
1877
- * inserted into the cache. */
1878
- if (ssl->s3->established_session != ssl->session ||
1879
- (!ssl->server && hs->ticket_expected)) {
1880
- if (use_internal_cache) {
1881
- SSL_CTX_add_session(ctx, ssl->s3->established_session);
1882
- }
1883
- if (ctx->new_session_cb != NULL) {
1884
- SSL_SESSION_up_ref(ssl->s3->established_session);
1885
- if (!ctx->new_session_cb(ssl, ssl->s3->established_session)) {
1886
- /* |new_session_cb|'s return value signals whether it took ownership. */
1887
- SSL_SESSION_free(ssl->s3->established_session);
1888
- }
1889
- }
1890
- }
1891
-
1892
- if (use_internal_cache &&
1893
- !(ctx->session_cache_mode & SSL_SESS_CACHE_NO_AUTO_CLEAR)) {
1894
- /* Automatically flush the internal session cache every 255 connections. */
1895
- int flush_cache = 0;
1896
- CRYPTO_MUTEX_lock_write(&ctx->lock);
1897
- ctx->handshakes_since_cache_flush++;
1898
- if (ctx->handshakes_since_cache_flush >= 255) {
1899
- flush_cache = 1;
1900
- ctx->handshakes_since_cache_flush = 0;
1901
- }
1902
- CRYPTO_MUTEX_unlock_write(&ctx->lock);
1903
-
1904
- if (flush_cache) {
1905
- struct timeval now;
1906
- ssl_get_current_time(ssl, &now);
1907
- SSL_CTX_flush_sessions(ctx, (long)now.tv_sec);
1908
- }
1909
- }
1910
- }
1911
-
1912
- static const char *ssl_get_version(int version) {
1913
- switch (version) {
1914
- /* Report TLS 1.3 draft version as TLS 1.3 in the public API. */
1915
- case TLS1_3_DRAFT_VERSION:
1916
- return "TLSv1.3";
1917
-
1918
- case TLS1_2_VERSION:
1919
- return "TLSv1.2";
1920
-
1921
- case TLS1_1_VERSION:
1922
- return "TLSv1.1";
1923
-
1924
- case TLS1_VERSION:
1925
- return "TLSv1";
1926
-
1927
- case SSL3_VERSION:
1928
- return "SSLv3";
1929
-
1930
- case DTLS1_VERSION:
1931
- return "DTLSv1";
1932
-
1933
- case DTLS1_2_VERSION:
1934
- return "DTLSv1.2";
1935
-
1936
- default:
1937
- return "unknown";
1938
- }
1939
- }
1940
-
1941
- const char *SSL_get_version(const SSL *ssl) {
1942
- return ssl_get_version(ssl->version);
1943
- }
1944
-
1945
- const char *SSL_SESSION_get_version(const SSL_SESSION *session) {
1946
- return ssl_get_version(session->ssl_version);
2040
+ *out_types = ssl->s3->hs->certificate_types.data();
2041
+ return ssl->s3->hs->certificate_types.size();
1947
2042
  }
1948
2043
 
1949
2044
  EVP_PKEY *SSL_get_privatekey(const SSL *ssl) {
@@ -1963,14 +2058,11 @@ EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx) {
1963
2058
  }
1964
2059
 
1965
2060
  const SSL_CIPHER *SSL_get_current_cipher(const SSL *ssl) {
1966
- if (ssl->s3->aead_write_ctx == NULL) {
1967
- return NULL;
1968
- }
1969
- return ssl->s3->aead_write_ctx->cipher;
2061
+ return ssl->s3->aead_write_ctx->cipher();
1970
2062
  }
1971
2063
 
1972
2064
  int SSL_session_reused(const SSL *ssl) {
1973
- return ssl->s3->session_reused;
2065
+ return ssl->s3->session_reused || SSL_in_early_data(ssl);
1974
2066
  }
1975
2067
 
1976
2068
  const COMP_METHOD *SSL_get_current_compression(SSL *ssl) { return NULL; }
@@ -1994,44 +2086,35 @@ void SSL_set_quiet_shutdown(SSL *ssl, int mode) {
1994
2086
  int SSL_get_quiet_shutdown(const SSL *ssl) { return ssl->quiet_shutdown; }
1995
2087
 
1996
2088
  void SSL_set_shutdown(SSL *ssl, int mode) {
1997
- /* It is an error to clear any bits that have already been set. (We can't try
1998
- * to get a second close_notify or send two.) */
2089
+ // It is an error to clear any bits that have already been set. (We can't try
2090
+ // to get a second close_notify or send two.)
1999
2091
  assert((SSL_get_shutdown(ssl) & mode) == SSL_get_shutdown(ssl));
2000
2092
 
2001
2093
  if (mode & SSL_RECEIVED_SHUTDOWN &&
2002
- ssl->s3->recv_shutdown == ssl_shutdown_none) {
2003
- ssl->s3->recv_shutdown = ssl_shutdown_close_notify;
2094
+ ssl->s3->read_shutdown == ssl_shutdown_none) {
2095
+ ssl->s3->read_shutdown = ssl_shutdown_close_notify;
2004
2096
  }
2005
2097
 
2006
2098
  if (mode & SSL_SENT_SHUTDOWN &&
2007
- ssl->s3->send_shutdown == ssl_shutdown_none) {
2008
- ssl->s3->send_shutdown = ssl_shutdown_close_notify;
2099
+ ssl->s3->write_shutdown == ssl_shutdown_none) {
2100
+ ssl->s3->write_shutdown = ssl_shutdown_close_notify;
2009
2101
  }
2010
2102
  }
2011
2103
 
2012
2104
  int SSL_get_shutdown(const SSL *ssl) {
2013
2105
  int ret = 0;
2014
- if (ssl->s3->recv_shutdown != ssl_shutdown_none) {
2015
- /* Historically, OpenSSL set |SSL_RECEIVED_SHUTDOWN| on both close_notify
2016
- * and fatal alert. */
2106
+ if (ssl->s3->read_shutdown != ssl_shutdown_none) {
2107
+ // Historically, OpenSSL set |SSL_RECEIVED_SHUTDOWN| on both close_notify
2108
+ // and fatal alert.
2017
2109
  ret |= SSL_RECEIVED_SHUTDOWN;
2018
2110
  }
2019
- if (ssl->s3->send_shutdown == ssl_shutdown_close_notify) {
2020
- /* Historically, OpenSSL set |SSL_SENT_SHUTDOWN| on only close_notify. */
2111
+ if (ssl->s3->write_shutdown == ssl_shutdown_close_notify) {
2112
+ // Historically, OpenSSL set |SSL_SENT_SHUTDOWN| on only close_notify.
2021
2113
  ret |= SSL_SENT_SHUTDOWN;
2022
2114
  }
2023
2115
  return ret;
2024
2116
  }
2025
2117
 
2026
- int SSL_version(const SSL *ssl) {
2027
- /* Report TLS 1.3 draft version as TLS 1.3 in the public API. */
2028
- if (ssl->version == TLS1_3_DRAFT_VERSION) {
2029
- return TLS1_3_VERSION;
2030
- }
2031
-
2032
- return ssl->version;
2033
- }
2034
-
2035
2118
  SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl) { return ssl->ctx; }
2036
2119
 
2037
2120
  SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx) {
@@ -2039,14 +2122,14 @@ SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX *ctx) {
2039
2122
  return ssl->ctx;
2040
2123
  }
2041
2124
 
2042
- /* One cannot change the X.509 callbacks during a connection. */
2125
+ // One cannot change the X.509 callbacks during a connection.
2043
2126
  if (ssl->ctx->x509_method != ctx->x509_method) {
2044
2127
  assert(0);
2045
2128
  return NULL;
2046
2129
  }
2047
2130
 
2048
2131
  if (ctx == NULL) {
2049
- ctx = ssl->initial_ctx;
2132
+ ctx = ssl->session_ctx;
2050
2133
  }
2051
2134
 
2052
2135
  ssl_cert_free(ssl->cert);
@@ -2084,17 +2167,17 @@ char *SSL_get_shared_ciphers(const SSL *ssl, char *buf, int len) {
2084
2167
  }
2085
2168
 
2086
2169
  int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused,
2087
- CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) {
2170
+ CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) {
2088
2171
  int index;
2089
2172
  if (!CRYPTO_get_ex_new_index(&g_ex_data_class_ssl, &index, argl, argp,
2090
- dup_func, free_func)) {
2173
+ free_func)) {
2091
2174
  return -1;
2092
2175
  }
2093
2176
  return index;
2094
2177
  }
2095
2178
 
2096
- int SSL_set_ex_data(SSL *ssl, int idx, void *arg) {
2097
- return CRYPTO_set_ex_data(&ssl->ex_data, idx, arg);
2179
+ int SSL_set_ex_data(SSL *ssl, int idx, void *data) {
2180
+ return CRYPTO_set_ex_data(&ssl->ex_data, idx, data);
2098
2181
  }
2099
2182
 
2100
2183
  void *SSL_get_ex_data(const SSL *ssl, int idx) {
@@ -2102,18 +2185,18 @@ void *SSL_get_ex_data(const SSL *ssl, int idx) {
2102
2185
  }
2103
2186
 
2104
2187
  int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused,
2105
- CRYPTO_EX_dup *dup_func,
2188
+ CRYPTO_EX_dup *dup_unused,
2106
2189
  CRYPTO_EX_free *free_func) {
2107
2190
  int index;
2108
2191
  if (!CRYPTO_get_ex_new_index(&g_ex_data_class_ssl_ctx, &index, argl, argp,
2109
- dup_func, free_func)) {
2192
+ free_func)) {
2110
2193
  return -1;
2111
2194
  }
2112
2195
  return index;
2113
2196
  }
2114
2197
 
2115
- int SSL_CTX_set_ex_data(SSL_CTX *ctx, int idx, void *arg) {
2116
- return CRYPTO_set_ex_data(&ctx->ex_data, idx, arg);
2198
+ int SSL_CTX_set_ex_data(SSL_CTX *ctx, int idx, void *data) {
2199
+ return CRYPTO_set_ex_data(&ctx->ex_data, idx, data);
2117
2200
  }
2118
2201
 
2119
2202
  void *SSL_CTX_get_ex_data(const SSL_CTX *ctx, int idx) {
@@ -2124,70 +2207,48 @@ int SSL_want(const SSL *ssl) { return ssl->rwstate; }
2124
2207
 
2125
2208
  void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
2126
2209
  RSA *(*cb)(SSL *ssl, int is_export,
2127
- int keylength)) {
2128
- }
2210
+ int keylength)) {}
2129
2211
 
2130
2212
  void SSL_set_tmp_rsa_callback(SSL *ssl, RSA *(*cb)(SSL *ssl, int is_export,
2131
- int keylength)) {
2132
- }
2213
+ int keylength)) {}
2133
2214
 
2134
2215
  void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
2135
- DH *(*callback)(SSL *ssl, int is_export,
2136
- int keylength)) {
2137
- ctx->cert->dh_tmp_cb = callback;
2138
- }
2216
+ DH *(*cb)(SSL *ssl, int is_export,
2217
+ int keylength)) {}
2139
2218
 
2140
- void SSL_set_tmp_dh_callback(SSL *ssl, DH *(*callback)(SSL *ssl, int is_export,
2141
- int keylength)) {
2142
- ssl->cert->dh_tmp_cb = callback;
2143
- }
2219
+ void SSL_set_tmp_dh_callback(SSL *ssl, DH *(*cb)(SSL *ssl, int is_export,
2220
+ int keylength)) {}
2144
2221
 
2145
- int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint) {
2222
+ static int use_psk_identity_hint(char **out, const char *identity_hint) {
2146
2223
  if (identity_hint != NULL && strlen(identity_hint) > PSK_MAX_IDENTITY_LEN) {
2147
2224
  OPENSSL_PUT_ERROR(SSL, SSL_R_DATA_LENGTH_TOO_LONG);
2148
2225
  return 0;
2149
2226
  }
2150
2227
 
2151
- OPENSSL_free(ctx->psk_identity_hint);
2228
+ // Clear currently configured hint, if any.
2229
+ OPENSSL_free(*out);
2230
+ *out = NULL;
2152
2231
 
2153
- if (identity_hint != NULL) {
2154
- ctx->psk_identity_hint = BUF_strdup(identity_hint);
2155
- if (ctx->psk_identity_hint == NULL) {
2232
+ // Treat the empty hint as not supplying one. Plain PSK makes it possible to
2233
+ // send either no hint (omit ServerKeyExchange) or an empty hint, while
2234
+ // ECDHE_PSK can only spell empty hint. Having different capabilities is odd,
2235
+ // so we interpret empty and missing as identical.
2236
+ if (identity_hint != NULL && identity_hint[0] != '\0') {
2237
+ *out = BUF_strdup(identity_hint);
2238
+ if (*out == NULL) {
2156
2239
  return 0;
2157
2240
  }
2158
- } else {
2159
- ctx->psk_identity_hint = NULL;
2160
2241
  }
2161
2242
 
2162
2243
  return 1;
2163
2244
  }
2164
2245
 
2165
- int SSL_use_psk_identity_hint(SSL *ssl, const char *identity_hint) {
2166
- if (ssl == NULL) {
2167
- return 0;
2168
- }
2169
-
2170
- if (identity_hint != NULL && strlen(identity_hint) > PSK_MAX_IDENTITY_LEN) {
2171
- OPENSSL_PUT_ERROR(SSL, SSL_R_DATA_LENGTH_TOO_LONG);
2172
- return 0;
2173
- }
2174
-
2175
- /* Clear currently configured hint, if any. */
2176
- OPENSSL_free(ssl->psk_identity_hint);
2177
- ssl->psk_identity_hint = NULL;
2178
-
2179
- /* Treat the empty hint as not supplying one. Plain PSK makes it possible to
2180
- * send either no hint (omit ServerKeyExchange) or an empty hint, while
2181
- * ECDHE_PSK can only spell empty hint. Having different capabilities is odd,
2182
- * so we interpret empty and missing as identical. */
2183
- if (identity_hint != NULL && identity_hint[0] != '\0') {
2184
- ssl->psk_identity_hint = BUF_strdup(identity_hint);
2185
- if (ssl->psk_identity_hint == NULL) {
2186
- return 0;
2187
- }
2188
- }
2246
+ int SSL_CTX_use_psk_identity_hint(SSL_CTX *ctx, const char *identity_hint) {
2247
+ return use_psk_identity_hint(&ctx->psk_identity_hint, identity_hint);
2248
+ }
2189
2249
 
2190
- return 1;
2250
+ int SSL_use_psk_identity_hint(SSL *ssl, const char *identity_hint) {
2251
+ return use_psk_identity_hint(&ssl->psk_identity_hint, identity_hint);
2191
2252
  }
2192
2253
 
2193
2254
  const char *SSL_get_psk_identity_hint(const SSL *ssl) {
@@ -2272,56 +2333,16 @@ void SSL_CTX_set_current_time_cb(SSL_CTX *ctx,
2272
2333
  ctx->current_time_cb = cb;
2273
2334
  }
2274
2335
 
2275
- static int cbb_add_hex(CBB *cbb, const uint8_t *in, size_t in_len) {
2276
- static const char hextable[] = "0123456789abcdef";
2277
- uint8_t *out;
2278
-
2279
- if (!CBB_add_space(cbb, &out, in_len * 2)) {
2280
- return 0;
2281
- }
2282
-
2283
- for (size_t i = 0; i < in_len; i++) {
2284
- *(out++) = (uint8_t)hextable[in[i] >> 4];
2285
- *(out++) = (uint8_t)hextable[in[i] & 0xf];
2286
- }
2287
-
2288
- return 1;
2289
- }
2290
-
2291
- int ssl_log_secret(const SSL *ssl, const char *label, const uint8_t *secret,
2292
- size_t secret_len) {
2293
- if (ssl->ctx->keylog_callback == NULL) {
2294
- return 1;
2295
- }
2296
-
2297
- CBB cbb;
2298
- uint8_t *out;
2299
- size_t out_len;
2300
- if (!CBB_init(&cbb, strlen(label) + 1 + SSL3_RANDOM_SIZE * 2 + 1 +
2301
- secret_len * 2 + 1) ||
2302
- !CBB_add_bytes(&cbb, (const uint8_t *)label, strlen(label)) ||
2303
- !CBB_add_bytes(&cbb, (const uint8_t *)" ", 1) ||
2304
- !cbb_add_hex(&cbb, ssl->s3->client_random, SSL3_RANDOM_SIZE) ||
2305
- !CBB_add_bytes(&cbb, (const uint8_t *)" ", 1) ||
2306
- !cbb_add_hex(&cbb, secret, secret_len) ||
2307
- !CBB_add_u8(&cbb, 0 /* NUL */) ||
2308
- !CBB_finish(&cbb, &out, &out_len)) {
2309
- CBB_cleanup(&cbb);
2310
- return 0;
2311
- }
2312
-
2313
- ssl->ctx->keylog_callback(ssl, (const char *)out);
2314
- OPENSSL_free(out);
2315
- return 1;
2316
- }
2317
-
2318
2336
  int SSL_is_init_finished(const SSL *ssl) {
2319
2337
  return !SSL_in_init(ssl);
2320
2338
  }
2321
2339
 
2322
2340
  int SSL_in_init(const SSL *ssl) {
2341
+ // This returns false once all the handshake state has been finalized, to
2342
+ // allow callbacks and getters based on SSL_in_init to return the correct
2343
+ // values.
2323
2344
  SSL_HANDSHAKE *hs = ssl->s3->hs;
2324
- return hs != NULL && hs->state != SSL_ST_OK;
2345
+ return hs != nullptr && !hs->handshake_finalized;
2325
2346
  }
2326
2347
 
2327
2348
  int SSL_in_false_start(const SSL *ssl) {
@@ -2342,121 +2363,13 @@ void SSL_get_structure_sizes(size_t *ssl_size, size_t *ssl_ctx_size,
2342
2363
  *ssl_session_size = sizeof(SSL_SESSION);
2343
2364
  }
2344
2365
 
2345
- int ssl3_can_false_start(const SSL *ssl) {
2346
- const SSL_CIPHER *const cipher = SSL_get_current_cipher(ssl);
2347
-
2348
- /* False Start only for TLS 1.2 with an ECDHE+AEAD cipher and ALPN or NPN. */
2349
- return !SSL_is_dtls(ssl) &&
2350
- SSL_version(ssl) == TLS1_2_VERSION &&
2351
- (ssl->s3->alpn_selected != NULL ||
2352
- ssl->s3->next_proto_negotiated != NULL) &&
2353
- cipher != NULL &&
2354
- cipher->algorithm_mkey == SSL_kECDHE &&
2355
- cipher->algorithm_mac == SSL_AEAD;
2356
- }
2357
-
2358
- const struct {
2359
- uint16_t version;
2360
- uint32_t flag;
2361
- } kVersions[] = {
2362
- {SSL3_VERSION, SSL_OP_NO_SSLv3},
2363
- {TLS1_VERSION, SSL_OP_NO_TLSv1},
2364
- {TLS1_1_VERSION, SSL_OP_NO_TLSv1_1},
2365
- {TLS1_2_VERSION, SSL_OP_NO_TLSv1_2},
2366
- {TLS1_3_VERSION, SSL_OP_NO_TLSv1_3},
2367
- };
2368
-
2369
- static const size_t kVersionsLen = OPENSSL_ARRAY_SIZE(kVersions);
2370
-
2371
- int ssl_get_version_range(const SSL *ssl, uint16_t *out_min_version,
2372
- uint16_t *out_max_version) {
2373
- /* For historical reasons, |SSL_OP_NO_DTLSv1| aliases |SSL_OP_NO_TLSv1|, but
2374
- * DTLS 1.0 should be mapped to TLS 1.1. */
2375
- uint32_t options = ssl->options;
2376
- if (SSL_is_dtls(ssl)) {
2377
- options &= ~SSL_OP_NO_TLSv1_1;
2378
- if (options & SSL_OP_NO_DTLSv1) {
2379
- options |= SSL_OP_NO_TLSv1_1;
2380
- }
2381
- }
2382
-
2383
- uint16_t min_version = ssl->min_version;
2384
- uint16_t max_version = ssl->max_version;
2385
-
2386
- /* Bound the range to only those implemented in this protocol. */
2387
- if (min_version < ssl->method->min_version) {
2388
- min_version = ssl->method->min_version;
2389
- }
2390
- if (max_version > ssl->method->max_version) {
2391
- max_version = ssl->method->max_version;
2392
- }
2393
-
2394
- /* OpenSSL's API for controlling versions entails blacklisting individual
2395
- * protocols. This has two problems. First, on the client, the protocol can
2396
- * only express a contiguous range of versions. Second, a library consumer
2397
- * trying to set a maximum version cannot disable protocol versions that get
2398
- * added in a future version of the library.
2399
- *
2400
- * To account for both of these, OpenSSL interprets the client-side bitmask
2401
- * as a min/max range by picking the lowest contiguous non-empty range of
2402
- * enabled protocols. Note that this means it is impossible to set a maximum
2403
- * version of the higest supported TLS version in a future-proof way. */
2404
- int any_enabled = 0;
2405
- for (size_t i = 0; i < kVersionsLen; i++) {
2406
- /* Only look at the versions already enabled. */
2407
- if (min_version > kVersions[i].version) {
2408
- continue;
2409
- }
2410
- if (max_version < kVersions[i].version) {
2411
- break;
2412
- }
2413
-
2414
- if (!(options & kVersions[i].flag)) {
2415
- /* The minimum version is the first enabled version. */
2416
- if (!any_enabled) {
2417
- any_enabled = 1;
2418
- min_version = kVersions[i].version;
2419
- }
2420
- continue;
2421
- }
2422
-
2423
- /* If there is a disabled version after the first enabled one, all versions
2424
- * after it are implicitly disabled. */
2425
- if (any_enabled) {
2426
- max_version = kVersions[i-1].version;
2427
- break;
2428
- }
2429
- }
2430
-
2431
- if (!any_enabled) {
2432
- OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_SSL_VERSION);
2433
- return 0;
2434
- }
2435
-
2436
- *out_min_version = min_version;
2437
- *out_max_version = max_version;
2438
- return 1;
2439
- }
2440
-
2441
- uint16_t ssl3_protocol_version(const SSL *ssl) {
2442
- assert(ssl->s3->have_version);
2443
- uint16_t version;
2444
- if (!ssl->method->version_from_wire(&version, ssl->version)) {
2445
- /* TODO(davidben): Use the internal version representation for ssl->version
2446
- * and map to the public API representation at API boundaries. */
2447
- assert(0);
2448
- return 0;
2449
- }
2450
-
2451
- return version;
2452
- }
2453
-
2454
2366
  int SSL_is_server(const SSL *ssl) { return ssl->server; }
2455
2367
 
2456
2368
  int SSL_is_dtls(const SSL *ssl) { return ssl->method->is_dtls; }
2457
2369
 
2458
- void SSL_CTX_set_select_certificate_cb(SSL_CTX *ctx,
2459
- int (*cb)(const SSL_CLIENT_HELLO *)) {
2370
+ void SSL_CTX_set_select_certificate_cb(
2371
+ SSL_CTX *ctx,
2372
+ enum ssl_select_cert_result_t (*cb)(const SSL_CLIENT_HELLO *)) {
2460
2373
  ctx->select_certificate_cb = cb;
2461
2374
  }
2462
2375
 
@@ -2471,15 +2384,9 @@ void SSL_set_renegotiate_mode(SSL *ssl, enum ssl_renegotiate_mode_t mode) {
2471
2384
 
2472
2385
  int SSL_get_ivs(const SSL *ssl, const uint8_t **out_read_iv,
2473
2386
  const uint8_t **out_write_iv, size_t *out_iv_len) {
2474
- if (ssl->s3->aead_read_ctx == NULL || ssl->s3->aead_write_ctx == NULL) {
2475
- return 0;
2476
- }
2477
-
2478
2387
  size_t write_iv_len;
2479
- if (!EVP_AEAD_CTX_get_iv(&ssl->s3->aead_read_ctx->ctx, out_read_iv,
2480
- out_iv_len) ||
2481
- !EVP_AEAD_CTX_get_iv(&ssl->s3->aead_write_ctx->ctx, out_write_iv,
2482
- &write_iv_len) ||
2388
+ if (!ssl->s3->aead_read_ctx->GetIV(out_read_iv, out_iv_len) ||
2389
+ !ssl->s3->aead_write_ctx->GetIV(out_write_iv, &write_iv_len) ||
2483
2390
  *out_iv_len != write_iv_len) {
2484
2391
  return 0;
2485
2392
  }
@@ -2495,9 +2402,9 @@ static uint64_t be_to_u64(const uint8_t in[8]) {
2495
2402
  }
2496
2403
 
2497
2404
  uint64_t SSL_get_read_sequence(const SSL *ssl) {
2498
- /* TODO(davidben): Internally represent sequence numbers as uint64_t. */
2405
+ // TODO(davidben): Internally represent sequence numbers as uint64_t.
2499
2406
  if (SSL_is_dtls(ssl)) {
2500
- /* max_seq_num already includes the epoch. */
2407
+ // max_seq_num already includes the epoch.
2501
2408
  assert(ssl->d1->r_epoch == (ssl->d1->bitmap.max_seq_num >> 48));
2502
2409
  return ssl->d1->bitmap.max_seq_num;
2503
2410
  }
@@ -2514,8 +2421,8 @@ uint64_t SSL_get_write_sequence(const SSL *ssl) {
2514
2421
  }
2515
2422
 
2516
2423
  uint16_t SSL_get_peer_signature_algorithm(const SSL *ssl) {
2517
- /* TODO(davidben): This checks the wrong session if there is a renegotiation
2518
- * in progress. */
2424
+ // TODO(davidben): This checks the wrong session if there is a renegotiation
2425
+ // in progress.
2519
2426
  SSL_SESSION *session = SSL_get_session(ssl);
2520
2427
  if (session == NULL) {
2521
2428
  return 0;
@@ -2566,37 +2473,35 @@ void SSL_CTX_set_grease_enabled(SSL_CTX *ctx, int enabled) {
2566
2473
  ctx->grease_enabled = !!enabled;
2567
2474
  }
2568
2475
 
2569
- void SSL_CTX_set_short_header_enabled(SSL_CTX *ctx, int enabled) {
2570
- ctx->short_header_enabled = !!enabled;
2476
+ int32_t SSL_get_ticket_age_skew(const SSL *ssl) {
2477
+ return ssl->s3->ticket_age_skew;
2571
2478
  }
2572
2479
 
2573
2480
  int SSL_clear(SSL *ssl) {
2574
- /* In OpenSSL, reusing a client |SSL| with |SSL_clear| causes the previously
2575
- * established session to be offered the next time around. wpa_supplicant
2576
- * depends on this behavior, so emulate it. */
2481
+ // In OpenSSL, reusing a client |SSL| with |SSL_clear| causes the previously
2482
+ // established session to be offered the next time around. wpa_supplicant
2483
+ // depends on this behavior, so emulate it.
2577
2484
  SSL_SESSION *session = NULL;
2578
2485
  if (!ssl->server && ssl->s3->established_session != NULL) {
2579
2486
  session = ssl->s3->established_session;
2580
2487
  SSL_SESSION_up_ref(session);
2581
2488
  }
2582
2489
 
2583
- /* TODO(davidben): Some state on |ssl| is reset both in |SSL_new| and
2584
- * |SSL_clear| because it is per-connection state rather than configuration
2585
- * state. Per-connection state should be on |ssl->s3| and |ssl->d1| so it is
2586
- * naturally reset at the right points between |SSL_new|, |SSL_clear|, and
2587
- * |ssl3_new|. */
2490
+ // TODO(davidben): Some state on |ssl| is reset both in |SSL_new| and
2491
+ // |SSL_clear| because it is per-connection state rather than configuration
2492
+ // state. Per-connection state should be on |ssl->s3| and |ssl->d1| so it is
2493
+ // naturally reset at the right points between |SSL_new|, |SSL_clear|, and
2494
+ // |ssl3_new|.
2588
2495
 
2589
2496
  ssl->rwstate = SSL_NOTHING;
2590
2497
 
2591
2498
  BUF_MEM_free(ssl->init_buf);
2592
2499
  ssl->init_buf = NULL;
2593
- ssl->init_msg = NULL;
2594
- ssl->init_num = 0;
2595
2500
 
2596
- /* The ssl->d1->mtu is simultaneously configuration (preserved across
2597
- * clear) and connection-specific state (gets reset).
2598
- *
2599
- * TODO(davidben): Avoid this. */
2501
+ // The ssl->d1->mtu is simultaneously configuration (preserved across
2502
+ // clear) and connection-specific state (gets reset).
2503
+ //
2504
+ // TODO(davidben): Avoid this.
2600
2505
  unsigned mtu = 0;
2601
2506
  if (ssl->d1 != NULL) {
2602
2507
  mtu = ssl->d1->mtu;
@@ -2620,44 +2525,6 @@ int SSL_clear(SSL *ssl) {
2620
2525
  return 1;
2621
2526
  }
2622
2527
 
2623
- void ssl_do_info_callback(const SSL *ssl, int type, int value) {
2624
- void (*cb)(const SSL *ssl, int type, int value) = NULL;
2625
- if (ssl->info_callback != NULL) {
2626
- cb = ssl->info_callback;
2627
- } else if (ssl->ctx->info_callback != NULL) {
2628
- cb = ssl->ctx->info_callback;
2629
- }
2630
-
2631
- if (cb != NULL) {
2632
- cb(ssl, type, value);
2633
- }
2634
- }
2635
-
2636
- void ssl_do_msg_callback(SSL *ssl, int is_write, int content_type,
2637
- const void *buf, size_t len) {
2638
- if (ssl->msg_callback == NULL) {
2639
- return;
2640
- }
2641
-
2642
- /* |version| is zero when calling for |SSL3_RT_HEADER| and |SSL2_VERSION| for
2643
- * a V2ClientHello. */
2644
- int version;
2645
- switch (content_type) {
2646
- case 0:
2647
- /* V2ClientHello */
2648
- version = SSL2_VERSION;
2649
- break;
2650
- case SSL3_RT_HEADER:
2651
- version = 0;
2652
- break;
2653
- default:
2654
- version = SSL_version(ssl);
2655
- }
2656
-
2657
- ssl->msg_callback(is_write, version, content_type, buf, len, ssl,
2658
- ssl->msg_callback_arg);
2659
- }
2660
-
2661
2528
  int SSL_CTX_sess_connect(const SSL_CTX *ctx) { return 0; }
2662
2529
  int SSL_CTX_sess_connect_good(const SSL_CTX *ctx) { return 0; }
2663
2530
  int SSL_CTX_sess_connect_renegotiate(const SSL_CTX *ctx) { return 0; }
@@ -2700,37 +2567,7 @@ int SSL_set_tmp_ecdh(SSL *ssl, const EC_KEY *ec_key) {
2700
2567
  return SSL_set1_curves(ssl, &nid, 1);
2701
2568
  }
2702
2569
 
2703
- void ssl_get_current_time(const SSL *ssl, struct timeval *out_clock) {
2704
- if (ssl->ctx->current_time_cb != NULL) {
2705
- ssl->ctx->current_time_cb(ssl, out_clock);
2706
- return;
2707
- }
2708
-
2709
- #if defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
2710
- out_clock->tv_sec = 1234;
2711
- out_clock->tv_usec = 1234;
2712
- #elif defined(OPENSSL_WINDOWS)
2713
- struct _timeb time;
2714
- _ftime(&time);
2715
- out_clock->tv_sec = time.time;
2716
- out_clock->tv_usec = time.millitm * 1000;
2717
- #else
2718
- gettimeofday(out_clock, NULL);
2719
- #endif
2720
- }
2721
-
2722
- int SSL_CTX_set_min_version(SSL_CTX *ctx, uint16_t version) {
2723
- return SSL_CTX_set_min_proto_version(ctx, version);
2724
- }
2725
-
2726
- int SSL_CTX_set_max_version(SSL_CTX *ctx, uint16_t version) {
2727
- return SSL_CTX_set_max_proto_version(ctx, version);
2728
- }
2729
-
2730
- int SSL_set_min_version(SSL *ssl, uint16_t version) {
2731
- return SSL_set_min_proto_version(ssl, version);
2732
- }
2733
-
2734
- int SSL_set_max_version(SSL *ssl, uint16_t version) {
2735
- return SSL_set_max_proto_version(ssl, version);
2570
+ void SSL_CTX_set_ticket_aead_method(SSL_CTX *ctx,
2571
+ const SSL_TICKET_AEAD_METHOD *aead_method) {
2572
+ ctx->ticket_aead_method = aead_method;
2736
2573
  }