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
@@ -144,13 +144,26 @@
144
144
 
145
145
  #include <openssl/base.h>
146
146
 
147
+ #include <stdlib.h>
148
+
149
+ #include <limits>
150
+ #include <new>
151
+ #include <type_traits>
152
+ #include <utility>
153
+
147
154
  #include <openssl/aead.h>
155
+ #include <openssl/err.h>
156
+ #include <openssl/mem.h>
148
157
  #include <openssl/ssl.h>
158
+ #include <openssl/span.h>
149
159
  #include <openssl/stack.h>
150
160
 
161
+ #include "../crypto/err/internal.h"
162
+ #include "../crypto/internal.h"
163
+
151
164
 
152
165
  #if defined(OPENSSL_WINDOWS)
153
- /* Windows defines struct timeval in winsock2.h. */
166
+ // Windows defines struct timeval in winsock2.h.
154
167
  OPENSSL_MSVC_PRAGMA(warning(push, 3))
155
168
  #include <winsock2.h>
156
169
  OPENSSL_MSVC_PRAGMA(warning(pop))
@@ -158,286 +171,598 @@ OPENSSL_MSVC_PRAGMA(warning(pop))
158
171
  #include <sys/time.h>
159
172
  #endif
160
173
 
161
- #if defined(__cplusplus)
162
- extern "C" {
174
+
175
+ namespace bssl {
176
+
177
+ struct SSL_HANDSHAKE;
178
+ struct SSL_PROTOCOL_METHOD;
179
+
180
+ // C++ utilities.
181
+
182
+ // New behaves like |new| but uses |OPENSSL_malloc| for memory allocation. It
183
+ // returns nullptr on allocation error. It only implements single-object
184
+ // allocation and not new T[n].
185
+ //
186
+ // Note: unlike |new|, this does not support non-public constructors.
187
+ template <typename T, typename... Args>
188
+ T *New(Args &&... args) {
189
+ void *t = OPENSSL_malloc(sizeof(T));
190
+ if (t == nullptr) {
191
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
192
+ return nullptr;
193
+ }
194
+ return new (t) T(std::forward<Args>(args)...);
195
+ }
196
+
197
+ // Delete behaves like |delete| but uses |OPENSSL_free| to release memory.
198
+ //
199
+ // Note: unlike |delete| this does not support non-public destructors.
200
+ template <typename T>
201
+ void Delete(T *t) {
202
+ if (t != nullptr) {
203
+ t->~T();
204
+ OPENSSL_free(t);
205
+ }
206
+ }
207
+
208
+ // All types with kAllowUniquePtr set may be used with UniquePtr. Other types
209
+ // may be C structs which require a |BORINGSSL_MAKE_DELETER| registration.
210
+ namespace internal {
211
+ template <typename T>
212
+ struct DeleterImpl<T, typename std::enable_if<T::kAllowUniquePtr>::type> {
213
+ static void Free(T *t) { Delete(t); }
214
+ };
215
+ }
216
+
217
+ // MakeUnique behaves like |std::make_unique| but returns nullptr on allocation
218
+ // error.
219
+ template <typename T, typename... Args>
220
+ UniquePtr<T> MakeUnique(Args &&... args) {
221
+ return UniquePtr<T>(New<T>(std::forward<Args>(args)...));
222
+ }
223
+
224
+ #if defined(BORINGSSL_ALLOW_CXX_RUNTIME)
225
+ #define HAS_VIRTUAL_DESTRUCTOR
226
+ #define PURE_VIRTUAL = 0
227
+ #else
228
+ // HAS_VIRTUAL_DESTRUCTOR should be declared in any base class which defines a
229
+ // virtual destructor. This avoids a dependency on |_ZdlPv| and prevents the
230
+ // class from being used with |delete|.
231
+ #define HAS_VIRTUAL_DESTRUCTOR \
232
+ void operator delete(void *) { abort(); }
233
+
234
+ // PURE_VIRTUAL should be used instead of = 0 when defining pure-virtual
235
+ // functions. This avoids a dependency on |__cxa_pure_virtual| but loses
236
+ // compile-time checking.
237
+ #define PURE_VIRTUAL { abort(); }
163
238
  #endif
164
239
 
240
+ // CONSTEXPR_ARRAY works around a VS 2015 bug where ranged for loops don't work
241
+ // on constexpr arrays.
242
+ #if defined(_MSC_VER) && !defined(__clang__) && _MSC_VER < 1910
243
+ #define CONSTEXPR_ARRAY const
244
+ #else
245
+ #define CONSTEXPR_ARRAY constexpr
246
+ #endif
247
+
248
+ // Array<T> is an owning array of elements of |T|.
249
+ template <typename T>
250
+ class Array {
251
+ public:
252
+ // Array's default constructor creates an empty array.
253
+ Array() {}
254
+ Array(const Array &) = delete;
255
+ Array(Array &&other) { *this = std::move(other); }
256
+
257
+ ~Array() { Reset(); }
258
+
259
+ Array &operator=(const Array &) = delete;
260
+ Array &operator=(Array &&other) {
261
+ Reset();
262
+ other.Release(&data_, &size_);
263
+ return *this;
264
+ }
265
+
266
+ const T *data() const { return data_; }
267
+ T *data() { return data_; }
268
+ size_t size() const { return size_; }
269
+ bool empty() const { return size_ == 0; }
270
+
271
+ const T &operator[](size_t i) const { return data_[i]; }
272
+ T &operator[](size_t i) { return data_[i]; }
273
+
274
+ T *begin() { return data_; }
275
+ const T *cbegin() const { return data_; }
276
+ T *end() { return data_ + size_; }
277
+ const T *cend() const { return data_ + size_; }
278
+
279
+ void Reset() { Reset(nullptr, 0); }
280
+
281
+ // Reset releases the current contents of the array and takes ownership of the
282
+ // raw pointer supplied by the caller.
283
+ void Reset(T *new_data, size_t new_size) {
284
+ for (size_t i = 0; i < size_; i++) {
285
+ data_[i].~T();
286
+ }
287
+ OPENSSL_free(data_);
288
+ data_ = new_data;
289
+ size_ = new_size;
290
+ }
291
+
292
+ // Release releases ownership of the array to a raw pointer supplied by the
293
+ // caller.
294
+ void Release(T **out, size_t *out_size) {
295
+ *out = data_;
296
+ *out_size = size_;
297
+ data_ = nullptr;
298
+ size_ = 0;
299
+ }
300
+
301
+ // Init replaces the array with a newly-allocated array of |new_size|
302
+ // default-constructed copies of |T|. It returns true on success and false on
303
+ // error.
304
+ //
305
+ // Note that if |T| is a primitive type like |uint8_t|, it is uninitialized.
306
+ bool Init(size_t new_size) {
307
+ Reset();
308
+ if (new_size == 0) {
309
+ return true;
310
+ }
311
+
312
+ if (new_size > std::numeric_limits<size_t>::max() / sizeof(T)) {
313
+ OPENSSL_PUT_ERROR(SSL, ERR_R_OVERFLOW);
314
+ return false;
315
+ }
316
+ data_ = reinterpret_cast<T*>(OPENSSL_malloc(new_size * sizeof(T)));
317
+ if (data_ == nullptr) {
318
+ OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
319
+ return false;
320
+ }
321
+ size_ = new_size;
322
+ for (size_t i = 0; i < size_; i++) {
323
+ new (&data_[i]) T;
324
+ }
325
+ return true;
326
+ }
327
+
328
+ // CopyFrom replaces the array with a newly-allocated copy of |in|. It returns
329
+ // true on success and false on error.
330
+ bool CopyFrom(Span<const uint8_t> in) {
331
+ if (!Init(in.size())) {
332
+ return false;
333
+ }
334
+ OPENSSL_memcpy(data_, in.data(), in.size());
335
+ return true;
336
+ }
337
+
338
+ private:
339
+ T *data_ = nullptr;
340
+ size_t size_ = 0;
341
+ };
342
+
343
+ // CBBFinishArray behaves like |CBB_finish| but stores the result in an Array.
344
+ bool CBBFinishArray(CBB *cbb, Array<uint8_t> *out);
345
+
346
+
347
+ // Protocol versions.
348
+ //
349
+ // Due to DTLS's historical wire version differences and to support multiple
350
+ // variants of the same protocol during development, we maintain two notions of
351
+ // version.
352
+ //
353
+ // The "version" or "wire version" is the actual 16-bit value that appears on
354
+ // the wire. It uniquely identifies a version and is also used at API
355
+ // boundaries. The set of supported versions differs between TLS and DTLS. Wire
356
+ // versions are opaque values and may not be compared numerically.
357
+ //
358
+ // The "protocol version" identifies the high-level handshake variant being
359
+ // used. DTLS versions map to the corresponding TLS versions. Draft TLS 1.3
360
+ // variants all map to TLS 1.3. Protocol versions are sequential and may be
361
+ // compared numerically.
362
+
363
+ // ssl_protocol_version_from_wire sets |*out| to the protocol version
364
+ // corresponding to wire version |version| and returns true. If |version| is not
365
+ // a valid TLS or DTLS version, it returns false.
366
+ //
367
+ // Note this simultaneously handles both DTLS and TLS. Use one of the
368
+ // higher-level functions below for most operations.
369
+ bool ssl_protocol_version_from_wire(uint16_t *out, uint16_t version);
370
+
371
+ // ssl_get_version_range sets |*out_min_version| and |*out_max_version| to the
372
+ // minimum and maximum enabled protocol versions, respectively.
373
+ bool ssl_get_version_range(const SSL *ssl, uint16_t *out_min_version,
374
+ uint16_t *out_max_version);
375
+
376
+ // ssl_supports_version returns whether |hs| supports |version|.
377
+ bool ssl_supports_version(SSL_HANDSHAKE *hs, uint16_t version);
378
+
379
+ // ssl_add_supported_versions writes the supported versions of |hs| to |cbb|, in
380
+ // decreasing preference order.
381
+ bool ssl_add_supported_versions(SSL_HANDSHAKE *hs, CBB *cbb);
382
+
383
+ // ssl_negotiate_version negotiates a common version based on |hs|'s preferences
384
+ // and the peer preference list in |peer_versions|. On success, it returns true
385
+ // and sets |*out_version| to the selected version. Otherwise, it returns false
386
+ // and sets |*out_alert| to an alert to send.
387
+ bool ssl_negotiate_version(SSL_HANDSHAKE *hs, uint8_t *out_alert,
388
+ uint16_t *out_version, const CBS *peer_versions);
389
+
390
+ // ssl3_protocol_version returns |ssl|'s protocol version. It is an error to
391
+ // call this function before the version is determined.
392
+ uint16_t ssl3_protocol_version(const SSL *ssl);
393
+
394
+ // ssl_is_resumption_experiment returns whether the version corresponds to a
395
+ // TLS 1.3 resumption experiment.
396
+ bool ssl_is_resumption_experiment(uint16_t version);
397
+
398
+ // ssl_is_resumption_variant returns whether the version corresponds to a
399
+ // TLS 1.3 resumption experiment.
400
+ bool ssl_is_resumption_variant(enum tls13_variant_t variant);
401
+
402
+ // ssl_is_resumption_client_ccs_experiment returns whether the version
403
+ // corresponds to a TLS 1.3 resumption experiment that sends a client CCS.
404
+ bool ssl_is_resumption_client_ccs_experiment(uint16_t version);
165
405
 
166
- /* Cipher suites. */
406
+ // ssl_is_resumption_record_version_experiment returns whether the version
407
+ // corresponds to a TLS 1.3 resumption experiment that modifies the record
408
+ // version.
409
+ bool ssl_is_resumption_record_version_experiment(uint16_t version);
167
410
 
168
- /* Bits for |algorithm_mkey| (key exchange algorithm). */
169
- #define SSL_kRSA 0x00000001L
170
- #define SSL_kDHE 0x00000002L
171
- #define SSL_kECDHE 0x00000004L
172
- /* SSL_kPSK is only set for plain PSK, not ECDHE_PSK. */
173
- #define SSL_kPSK 0x00000008L
174
- #define SSL_kGENERIC 0x00000010L
175
411
 
176
- /* Bits for |algorithm_auth| (server authentication). */
177
- #define SSL_aRSA 0x00000001L
178
- #define SSL_aECDSA 0x00000002L
179
- /* SSL_aPSK is set for both PSK and ECDHE_PSK. */
180
- #define SSL_aPSK 0x00000004L
181
- #define SSL_aGENERIC 0x00000008L
412
+ // Cipher suites.
413
+
414
+ } // namespace bssl
415
+
416
+ struct ssl_cipher_st {
417
+ // name is the OpenSSL name for the cipher.
418
+ const char *name;
419
+ // standard_name is the IETF name for the cipher.
420
+ const char *standard_name;
421
+ // id is the cipher suite value bitwise OR-d with 0x03000000.
422
+ uint32_t id;
423
+
424
+ // algorithm_* determine the cipher suite. See constants below for the values.
425
+ uint32_t algorithm_mkey;
426
+ uint32_t algorithm_auth;
427
+ uint32_t algorithm_enc;
428
+ uint32_t algorithm_mac;
429
+ uint32_t algorithm_prf;
430
+ };
431
+
432
+ namespace bssl {
433
+
434
+ // Bits for |algorithm_mkey| (key exchange algorithm).
435
+ #define SSL_kRSA 0x00000001u
436
+ #define SSL_kECDHE 0x00000002u
437
+ // SSL_kPSK is only set for plain PSK, not ECDHE_PSK.
438
+ #define SSL_kPSK 0x00000004u
439
+ #define SSL_kGENERIC 0x00000008u
440
+
441
+ // Bits for |algorithm_auth| (server authentication).
442
+ #define SSL_aRSA 0x00000001u
443
+ #define SSL_aECDSA 0x00000002u
444
+ // SSL_aPSK is set for both PSK and ECDHE_PSK.
445
+ #define SSL_aPSK 0x00000004u
446
+ #define SSL_aGENERIC 0x00000008u
182
447
 
183
448
  #define SSL_aCERT (SSL_aRSA | SSL_aECDSA)
184
449
 
185
- /* Bits for |algorithm_enc| (symmetric encryption). */
186
- #define SSL_3DES 0x00000001L
187
- #define SSL_AES128 0x00000002L
188
- #define SSL_AES256 0x00000004L
189
- #define SSL_AES128GCM 0x00000008L
190
- #define SSL_AES256GCM 0x00000010L
191
- #define SSL_eNULL 0x00000020L
192
- #define SSL_CHACHA20POLY1305 0x00000040L
450
+ // Bits for |algorithm_enc| (symmetric encryption).
451
+ #define SSL_3DES 0x00000001u
452
+ #define SSL_AES128 0x00000002u
453
+ #define SSL_AES256 0x00000004u
454
+ #define SSL_AES128GCM 0x00000008u
455
+ #define SSL_AES256GCM 0x00000010u
456
+ #define SSL_eNULL 0x00000020u
457
+ #define SSL_CHACHA20POLY1305 0x00000040u
193
458
 
194
459
  #define SSL_AES (SSL_AES128 | SSL_AES256 | SSL_AES128GCM | SSL_AES256GCM)
195
460
 
196
- /* Bits for |algorithm_mac| (symmetric authentication). */
197
- #define SSL_SHA1 0x00000001L
198
- #define SSL_SHA256 0x00000002L
199
- #define SSL_SHA384 0x00000004L
200
- /* SSL_AEAD is set for all AEADs. */
201
- #define SSL_AEAD 0x00000008L
461
+ // Bits for |algorithm_mac| (symmetric authentication).
462
+ #define SSL_SHA1 0x00000001u
463
+ #define SSL_SHA256 0x00000002u
464
+ #define SSL_SHA384 0x00000004u
465
+ // SSL_AEAD is set for all AEADs.
466
+ #define SSL_AEAD 0x00000008u
202
467
 
203
- /* Bits for |algorithm_prf| (handshake digest). */
468
+ // Bits for |algorithm_prf| (handshake digest).
204
469
  #define SSL_HANDSHAKE_MAC_DEFAULT 0x1
205
470
  #define SSL_HANDSHAKE_MAC_SHA256 0x2
206
471
  #define SSL_HANDSHAKE_MAC_SHA384 0x4
207
472
 
208
- /* SSL_MAX_DIGEST is the number of digest types which exist. When adding a new
209
- * one, update the table in ssl_cipher.c. */
473
+ // SSL_MAX_DIGEST is the number of digest types which exist. When adding a new
474
+ // one, update the table in ssl_cipher.c.
210
475
  #define SSL_MAX_DIGEST 4
211
476
 
212
- /* ssl_cipher_get_evp_aead sets |*out_aead| to point to the correct EVP_AEAD
213
- * object for |cipher| protocol version |version|. It sets |*out_mac_secret_len|
214
- * and |*out_fixed_iv_len| to the MAC key length and fixed IV length,
215
- * respectively. The MAC key length is zero except for legacy block and stream
216
- * ciphers. It returns 1 on success and 0 on error. */
217
- int ssl_cipher_get_evp_aead(const EVP_AEAD **out_aead,
218
- size_t *out_mac_secret_len,
219
- size_t *out_fixed_iv_len,
220
- const SSL_CIPHER *cipher, uint16_t version);
221
-
222
- /* ssl_get_handshake_digest returns the |EVP_MD| corresponding to
223
- * |algorithm_prf| and the |version|. */
224
- const EVP_MD *ssl_get_handshake_digest(uint32_t algorithm_prf,
225
- uint16_t version);
226
-
227
- /* ssl_create_cipher_list evaluates |rule_str| according to the ciphers in
228
- * |ssl_method|. It sets |*out_cipher_list| to a newly-allocated
229
- * |ssl_cipher_preference_list_st| containing the result. It returns
230
- * |(*out_cipher_list)->ciphers| on success and NULL on failure. If |strict| is
231
- * true, nonsense will be rejected. If false, nonsense will be silently
232
- * ignored. */
233
- STACK_OF(SSL_CIPHER) *
234
- ssl_create_cipher_list(const SSL_PROTOCOL_METHOD *ssl_method,
235
- struct ssl_cipher_preference_list_st **out_cipher_list,
236
- const char *rule_str, int strict);
237
-
238
- /* ssl_cipher_get_value returns the cipher suite id of |cipher|. */
477
+ // ssl_cipher_get_evp_aead sets |*out_aead| to point to the correct EVP_AEAD
478
+ // object for |cipher| protocol version |version|. It sets |*out_mac_secret_len|
479
+ // and |*out_fixed_iv_len| to the MAC key length and fixed IV length,
480
+ // respectively. The MAC key length is zero except for legacy block and stream
481
+ // ciphers. It returns true on success and false on error.
482
+ bool ssl_cipher_get_evp_aead(const EVP_AEAD **out_aead,
483
+ size_t *out_mac_secret_len,
484
+ size_t *out_fixed_iv_len, const SSL_CIPHER *cipher,
485
+ uint16_t version, int is_dtls);
486
+
487
+ // ssl_get_handshake_digest returns the |EVP_MD| corresponding to |version| and
488
+ // |cipher|.
489
+ const EVP_MD *ssl_get_handshake_digest(uint16_t version,
490
+ const SSL_CIPHER *cipher);
491
+
492
+ // ssl_create_cipher_list evaluates |rule_str| according to the ciphers in
493
+ // |ssl_method|. It sets |*out_cipher_list| to a newly-allocated
494
+ // |ssl_cipher_preference_list_st| containing the result. It returns true on
495
+ // success and false on failure. If |strict| is true, nonsense will be
496
+ // rejected. If false, nonsense will be silently ignored. An empty result is
497
+ // considered an error regardless of |strict|.
498
+ bool ssl_create_cipher_list(
499
+ const SSL_PROTOCOL_METHOD *ssl_method,
500
+ struct ssl_cipher_preference_list_st **out_cipher_list,
501
+ const char *rule_str, bool strict);
502
+
503
+ // ssl_cipher_get_value returns the cipher suite id of |cipher|.
239
504
  uint16_t ssl_cipher_get_value(const SSL_CIPHER *cipher);
240
505
 
241
- /* ssl_cipher_get_key_type returns the |EVP_PKEY_*| value corresponding to the
242
- * server key used in |cipher| or |EVP_PKEY_NONE| if there is none. */
243
- int ssl_cipher_get_key_type(const SSL_CIPHER *cipher);
506
+ // ssl_cipher_auth_mask_for_key returns the mask of cipher |algorithm_auth|
507
+ // values suitable for use with |key| in TLS 1.2 and below.
508
+ uint32_t ssl_cipher_auth_mask_for_key(const EVP_PKEY *key);
244
509
 
245
- /* ssl_cipher_uses_certificate_auth returns one if |cipher| authenticates the
246
- * server and, optionally, the client with a certificate. Otherwise it returns
247
- * zero. */
248
- int ssl_cipher_uses_certificate_auth(const SSL_CIPHER *cipher);
510
+ // ssl_cipher_uses_certificate_auth returns whether |cipher| authenticates the
511
+ // server and, optionally, the client with a certificate.
512
+ bool ssl_cipher_uses_certificate_auth(const SSL_CIPHER *cipher);
249
513
 
250
- /* ssl_cipher_requires_server_key_exchange returns 1 if |cipher| requires a
251
- * ServerKeyExchange message. Otherwise it returns 0.
252
- *
253
- * This function may return zero while still allowing |cipher| an optional
254
- * ServerKeyExchange. This is the case for plain PSK ciphers. */
255
- int ssl_cipher_requires_server_key_exchange(const SSL_CIPHER *cipher);
514
+ // ssl_cipher_requires_server_key_exchange returns whether |cipher| requires a
515
+ // ServerKeyExchange message.
516
+ //
517
+ // This function may return false while still allowing |cipher| an optional
518
+ // ServerKeyExchange. This is the case for plain PSK ciphers.
519
+ bool ssl_cipher_requires_server_key_exchange(const SSL_CIPHER *cipher);
256
520
 
257
- /* ssl_cipher_get_record_split_len, for TLS 1.0 CBC mode ciphers, returns the
258
- * length of an encrypted 1-byte record, for use in record-splitting. Otherwise
259
- * it returns zero. */
521
+ // ssl_cipher_get_record_split_len, for TLS 1.0 CBC mode ciphers, returns the
522
+ // length of an encrypted 1-byte record, for use in record-splitting. Otherwise
523
+ // it returns zero.
260
524
  size_t ssl_cipher_get_record_split_len(const SSL_CIPHER *cipher);
261
525
 
262
526
 
263
- /* Transcript layer. */
264
-
265
- /* SSL_TRANSCRIPT maintains the handshake transcript as a combination of a
266
- * buffer and running hash. */
267
- typedef struct ssl_transcript_st {
268
- /* buffer, if non-NULL, contains the handshake transcript. */
269
- BUF_MEM *buffer;
270
- /* hash, if initialized with an |EVP_MD|, maintains the handshake hash. For
271
- * TLS 1.1 and below, it is the SHA-1 half. */
272
- EVP_MD_CTX hash;
273
- /* md5, if initialized with an |EVP_MD|, maintains the MD5 half of the
274
- * handshake hash for TLS 1.1 and below. */
275
- EVP_MD_CTX md5;
276
- } SSL_TRANSCRIPT;
277
-
278
- /* SSL_TRANSCRIPT_init initializes the handshake transcript. If called on an
279
- * existing transcript, it resets the transcript and hash. It returns one on
280
- * success and zero on failure. */
281
- int SSL_TRANSCRIPT_init(SSL_TRANSCRIPT *transcript);
282
-
283
- /* SSL_TRANSCRIPT_init_hash initializes the handshake hash based on the PRF and
284
- * contents of the handshake transcript. Subsequent calls to
285
- * |SSL_TRANSCRIPT_update| will update the rolling hash. It returns one on
286
- * success and zero on failure. It is an error to call this function after the
287
- * handshake buffer is released. */
288
- int SSL_TRANSCRIPT_init_hash(SSL_TRANSCRIPT *transcript, uint16_t version,
289
- int algorithm_prf);
290
-
291
- /* SSL_TRANSCRIPT_cleanup cleans up the hash and transcript. */
292
- void SSL_TRANSCRIPT_cleanup(SSL_TRANSCRIPT *transcript);
293
-
294
- /* SSL_TRANSCRIPT_free_buffer releases the handshake buffer. Subsequent calls to
295
- * |SSL_TRANSCRIPT_update| will not update the handshake buffer. */
296
- void SSL_TRANSCRIPT_free_buffer(SSL_TRANSCRIPT *transcript);
297
-
298
- /* SSL_TRANSCRIPT_digest_len returns the length of the PRF hash. */
299
- size_t SSL_TRANSCRIPT_digest_len(const SSL_TRANSCRIPT *transcript);
300
-
301
- /* SSL_TRANSCRIPT_md returns the PRF hash. For TLS 1.1 and below, this is
302
- * |EVP_md5_sha1|. */
303
- const EVP_MD *SSL_TRANSCRIPT_md(const SSL_TRANSCRIPT *transcript);
304
-
305
- /* SSL_TRANSCRIPT_update adds |in| to the handshake buffer and handshake hash,
306
- * whichever is enabled. It returns one on success and zero on failure. */
307
- int SSL_TRANSCRIPT_update(SSL_TRANSCRIPT *transcript, const uint8_t *in,
308
- size_t in_len);
309
-
310
- /* SSL_TRANSCRIPT_get_hash writes the handshake hash to |out| which must have
311
- * room for at least |SSL_TRANSCRIPT_digest_len| bytes. On success, it returns
312
- * one and sets |*out_len| to the number of bytes written. Otherwise, it returns
313
- * zero. */
314
- int SSL_TRANSCRIPT_get_hash(const SSL_TRANSCRIPT *transcript, uint8_t *out,
315
- size_t *out_len);
316
-
317
- /* SSL_TRANSCRIPT_ssl3_cert_verify_hash writes the SSL 3.0 CertificateVerify
318
- * hash into the bytes pointed to by |out| and writes the number of bytes to
319
- * |*out_len|. |out| must have room for |EVP_MAX_MD_SIZE| bytes. It returns one
320
- * on success and zero on failure. */
321
- int SSL_TRANSCRIPT_ssl3_cert_verify_hash(SSL_TRANSCRIPT *transcript,
322
- uint8_t *out, size_t *out_len,
323
- const SSL_SESSION *session,
324
- int signature_algorithm);
325
-
326
- /* SSL_TRANSCRIPT_finish_mac computes the MAC for the Finished message into the
327
- * bytes pointed by |out| and writes the number of bytes to |*out_len|. |out|
328
- * must have room for |EVP_MAX_MD_SIZE| bytes. It returns one on success and
329
- * zero on failure. */
330
- int SSL_TRANSCRIPT_finish_mac(SSL_TRANSCRIPT *transcript, uint8_t *out,
331
- size_t *out_len, const SSL_SESSION *session,
332
- int from_server, uint16_t version);
333
-
334
- /* tls1_prf computes the PRF function for |ssl|. It writes |out_len| bytes to
335
- * |out|, using |secret| as the secret and |label| as the label. |seed1| and
336
- * |seed2| are concatenated to form the seed parameter. It returns one on
337
- * success and zero on failure. */
527
+ // Transcript layer.
528
+
529
+ // SSLTranscript maintains the handshake transcript as a combination of a
530
+ // buffer and running hash.
531
+ class SSLTranscript {
532
+ public:
533
+ SSLTranscript();
534
+ ~SSLTranscript();
535
+
536
+ // Init initializes the handshake transcript. If called on an existing
537
+ // transcript, it resets the transcript and hash. It returns true on success
538
+ // and false on failure.
539
+ bool Init();
540
+
541
+ // InitHash initializes the handshake hash based on the PRF and contents of
542
+ // the handshake transcript. Subsequent calls to |Update| will update the
543
+ // rolling hash. It returns one on success and zero on failure. It is an error
544
+ // to call this function after the handshake buffer is released.
545
+ bool InitHash(uint16_t version, const SSL_CIPHER *cipher);
546
+
547
+ const uint8_t *buffer_data() const {
548
+ return reinterpret_cast<const uint8_t *>(buffer_->data);
549
+ }
550
+ size_t buffer_len() const { return buffer_->length; }
551
+
552
+ // FreeBuffer releases the handshake buffer. Subsequent calls to
553
+ // |Update| will not update the handshake buffer.
554
+ void FreeBuffer();
555
+
556
+ // DigestLen returns the length of the PRF hash.
557
+ size_t DigestLen() const;
558
+
559
+ // Digest returns the PRF hash. For TLS 1.1 and below, this is
560
+ // |EVP_md5_sha1|.
561
+ const EVP_MD *Digest() const;
562
+
563
+ // Update adds |in| to the handshake buffer and handshake hash, whichever is
564
+ // enabled. It returns true on success and false on failure.
565
+ bool Update(const uint8_t *in, size_t in_len);
566
+
567
+ // GetHash writes the handshake hash to |out| which must have room for at
568
+ // least |DigestLen| bytes. On success, it returns true and sets |*out_len| to
569
+ // the number of bytes written. Otherwise, it returns false.
570
+ bool GetHash(uint8_t *out, size_t *out_len);
571
+
572
+ // GetSSL3CertVerifyHash writes the SSL 3.0 CertificateVerify hash into the
573
+ // bytes pointed to by |out| and writes the number of bytes to
574
+ // |*out_len|. |out| must have room for |EVP_MAX_MD_SIZE| bytes. It returns
575
+ // one on success and zero on failure.
576
+ bool GetSSL3CertVerifyHash(uint8_t *out, size_t *out_len,
577
+ const SSL_SESSION *session,
578
+ uint16_t signature_algorithm);
579
+
580
+ // GetFinishedMAC computes the MAC for the Finished message into the bytes
581
+ // pointed by |out| and writes the number of bytes to |*out_len|. |out| must
582
+ // have room for |EVP_MAX_MD_SIZE| bytes. It returns true on success and false
583
+ // on failure.
584
+ bool GetFinishedMAC(uint8_t *out, size_t *out_len, const SSL_SESSION *session,
585
+ bool from_server);
586
+
587
+ private:
588
+ // buffer_, if non-null, contains the handshake transcript.
589
+ UniquePtr<BUF_MEM> buffer_;
590
+ // hash, if initialized with an |EVP_MD|, maintains the handshake hash. For
591
+ // TLS 1.1 and below, it is the SHA-1 half.
592
+ ScopedEVP_MD_CTX hash_;
593
+ // md5, if initialized with an |EVP_MD|, maintains the MD5 half of the
594
+ // handshake hash for TLS 1.1 and below.
595
+ ScopedEVP_MD_CTX md5_;
596
+ };
597
+
598
+ // tls1_prf computes the PRF function for |ssl|. It writes |out_len| bytes to
599
+ // |out|, using |secret| as the secret and |label| as the label. |seed1| and
600
+ // |seed2| are concatenated to form the seed parameter. It returns one on
601
+ // success and zero on failure.
338
602
  int tls1_prf(const EVP_MD *digest, uint8_t *out, size_t out_len,
339
603
  const uint8_t *secret, size_t secret_len, const char *label,
340
604
  size_t label_len, const uint8_t *seed1, size_t seed1_len,
341
605
  const uint8_t *seed2, size_t seed2_len);
342
606
 
343
607
 
344
- /* Encryption layer. */
345
-
346
- /* SSL_AEAD_CTX contains information about an AEAD that is being used to encrypt
347
- * an SSL connection. */
348
- typedef struct ssl_aead_ctx_st {
349
- const SSL_CIPHER *cipher;
350
- EVP_AEAD_CTX ctx;
351
- /* fixed_nonce contains any bytes of the nonce that are fixed for all
352
- * records. */
353
- uint8_t fixed_nonce[12];
354
- uint8_t fixed_nonce_len, variable_nonce_len;
355
- /* variable_nonce_included_in_record is non-zero if the variable nonce
356
- * for a record is included as a prefix before the ciphertext. */
357
- unsigned variable_nonce_included_in_record : 1;
358
- /* random_variable_nonce is non-zero if the variable nonce is
359
- * randomly generated, rather than derived from the sequence
360
- * number. */
361
- unsigned random_variable_nonce : 1;
362
- /* omit_length_in_ad is non-zero if the length should be omitted in the
363
- * AEAD's ad parameter. */
364
- unsigned omit_length_in_ad : 1;
365
- /* omit_version_in_ad is non-zero if the version should be omitted
366
- * in the AEAD's ad parameter. */
367
- unsigned omit_version_in_ad : 1;
368
- /* omit_ad is non-zero if the AEAD's ad parameter should be omitted. */
369
- unsigned omit_ad : 1;
370
- /* xor_fixed_nonce is non-zero if the fixed nonce should be XOR'd into the
371
- * variable nonce rather than prepended. */
372
- unsigned xor_fixed_nonce : 1;
373
- } SSL_AEAD_CTX;
374
-
375
- /* SSL_AEAD_CTX_new creates a newly-allocated |SSL_AEAD_CTX| using the supplied
376
- * key material. It returns NULL on error. Only one of |SSL_AEAD_CTX_open| or
377
- * |SSL_AEAD_CTX_seal| may be used with the resulting object, depending on
378
- * |direction|. |version| is the normalized protocol version, so DTLS 1.0 is
379
- * represented as 0x0301, not 0xffef. */
380
- SSL_AEAD_CTX *SSL_AEAD_CTX_new(enum evp_aead_direction_t direction,
381
- uint16_t version, const SSL_CIPHER *cipher,
382
- const uint8_t *enc_key, size_t enc_key_len,
383
- const uint8_t *mac_key, size_t mac_key_len,
384
- const uint8_t *fixed_iv, size_t fixed_iv_len);
385
-
386
- /* SSL_AEAD_CTX_free frees |ctx|. */
387
- void SSL_AEAD_CTX_free(SSL_AEAD_CTX *ctx);
388
-
389
- /* SSL_AEAD_CTX_explicit_nonce_len returns the length of the explicit nonce for
390
- * |ctx|, if any. |ctx| may be NULL to denote the null cipher. */
391
- size_t SSL_AEAD_CTX_explicit_nonce_len(const SSL_AEAD_CTX *ctx);
392
-
393
- /* SSL_AEAD_CTX_max_overhead returns the maximum overhead of calling
394
- * |SSL_AEAD_CTX_seal|. |ctx| may be NULL to denote the null cipher. */
395
- size_t SSL_AEAD_CTX_max_overhead(const SSL_AEAD_CTX *ctx);
396
-
397
- /* SSL_AEAD_CTX_open authenticates and decrypts |in_len| bytes from |in|
398
- * in-place. On success, it sets |*out| to the plaintext in |in| and returns
399
- * one. Otherwise, it returns zero. |ctx| may be NULL to denote the null cipher.
400
- * The output will always be |explicit_nonce_len| bytes ahead of |in|. */
401
- int SSL_AEAD_CTX_open(SSL_AEAD_CTX *ctx, CBS *out, uint8_t type,
402
- uint16_t wire_version, const uint8_t seqnum[8],
403
- uint8_t *in, size_t in_len);
404
-
405
- /* SSL_AEAD_CTX_seal encrypts and authenticates |in_len| bytes from |in| and
406
- * writes the result to |out|. It returns one on success and zero on
407
- * error. |ctx| may be NULL to denote the null cipher.
408
- *
409
- * If |in| and |out| alias then |out| + |explicit_nonce_len| must be == |in|. */
410
- int SSL_AEAD_CTX_seal(SSL_AEAD_CTX *ctx, uint8_t *out, size_t *out_len,
411
- size_t max_out, uint8_t type, uint16_t wire_version,
412
- const uint8_t seqnum[8], const uint8_t *in,
413
- size_t in_len);
608
+ // Encryption layer.
609
+
610
+ // SSLAEADContext contains information about an AEAD that is being used to
611
+ // encrypt an SSL connection.
612
+ class SSLAEADContext {
613
+ public:
614
+ SSLAEADContext(uint16_t version, bool is_dtls, const SSL_CIPHER *cipher);
615
+ ~SSLAEADContext();
616
+ static constexpr bool kAllowUniquePtr = true;
617
+
618
+ SSLAEADContext(const SSLAEADContext &&) = delete;
619
+ SSLAEADContext &operator=(const SSLAEADContext &&) = delete;
620
+
621
+ // CreateNullCipher creates an |SSLAEADContext| for the null cipher.
622
+ static UniquePtr<SSLAEADContext> CreateNullCipher(bool is_dtls);
623
+
624
+ // Create creates an |SSLAEADContext| using the supplied key material. It
625
+ // returns nullptr on error. Only one of |Open| or |Seal| may be used with the
626
+ // resulting object, depending on |direction|. |version| is the normalized
627
+ // protocol version, so DTLS 1.0 is represented as 0x0301, not 0xffef.
628
+ static UniquePtr<SSLAEADContext> Create(enum evp_aead_direction_t direction,
629
+ uint16_t version, int is_dtls,
630
+ const SSL_CIPHER *cipher,
631
+ Span<const uint8_t> enc_key,
632
+ Span<const uint8_t> mac_key,
633
+ Span<const uint8_t> fixed_iv);
634
+
635
+ // SetVersionIfNullCipher sets the version the SSLAEADContext for the null
636
+ // cipher, to make version-specific determinations in the record layer prior
637
+ // to a cipher being selected.
638
+ void SetVersionIfNullCipher(uint16_t version);
639
+
640
+ // ProtocolVersion returns the protocol version associated with this
641
+ // SSLAEADContext. It can only be called once |version_| has been set to a
642
+ // valid value.
643
+ uint16_t ProtocolVersion() const;
644
+
645
+ // RecordVersion returns the record version that should be used with this
646
+ // SSLAEADContext for record construction and crypto.
647
+ uint16_t RecordVersion() const;
648
+
649
+ const SSL_CIPHER *cipher() const { return cipher_; }
650
+
651
+ // is_null_cipher returns true if this is the null cipher.
652
+ bool is_null_cipher() const { return !cipher_; }
653
+
654
+ // ExplicitNonceLen returns the length of the explicit nonce.
655
+ size_t ExplicitNonceLen() const;
656
+
657
+ // MaxOverhead returns the maximum overhead of calling |Seal|.
658
+ size_t MaxOverhead() const;
659
+
660
+ // SuffixLen calculates the suffix length written by |SealScatter| and writes
661
+ // it to |*out_suffix_len|. It returns true on success and false on error.
662
+ // |in_len| and |extra_in_len| should equal the argument of the same names
663
+ // passed to |SealScatter|.
664
+ bool SuffixLen(size_t *out_suffix_len, size_t in_len,
665
+ size_t extra_in_len) const;
666
+
667
+ // Open authenticates and decrypts |in| in-place. On success, it sets |*out|
668
+ // to the plaintext in |in| and returns true. Otherwise, it returns
669
+ // false. The output will always be |ExplicitNonceLen| bytes ahead of |in|.
670
+ bool Open(Span<uint8_t> *out, uint8_t type, uint16_t record_version,
671
+ const uint8_t seqnum[8], Span<uint8_t> in);
672
+
673
+ // Seal encrypts and authenticates |in_len| bytes from |in| and writes the
674
+ // result to |out|. It returns true on success and false on error.
675
+ //
676
+ // If |in| and |out| alias then |out| + |ExplicitNonceLen| must be == |in|.
677
+ bool Seal(uint8_t *out, size_t *out_len, size_t max_out, uint8_t type,
678
+ uint16_t record_version, const uint8_t seqnum[8], const uint8_t *in,
679
+ size_t in_len);
680
+
681
+ // SealScatter encrypts and authenticates |in_len| bytes from |in| and splits
682
+ // the result between |out_prefix|, |out| and |out_suffix|. It returns one on
683
+ // success and zero on error.
684
+ //
685
+ // On successful return, exactly |ExplicitNonceLen| bytes are written to
686
+ // |out_prefix|, |in_len| bytes to |out|, and |SuffixLen| bytes to
687
+ // |out_suffix|.
688
+ //
689
+ // |extra_in| may point to an additional plaintext buffer. If present,
690
+ // |extra_in_len| additional bytes are encrypted and authenticated, and the
691
+ // ciphertext is written to the beginning of |out_suffix|. |SuffixLen| should
692
+ // be used to size |out_suffix| accordingly.
693
+ //
694
+ // If |in| and |out| alias then |out| must be == |in|. Other arguments may not
695
+ // alias anything.
696
+ bool SealScatter(uint8_t *out_prefix, uint8_t *out, uint8_t *out_suffix,
697
+ uint8_t type, uint16_t record_version,
698
+ const uint8_t seqnum[8], const uint8_t *in, size_t in_len,
699
+ const uint8_t *extra_in, size_t extra_in_len);
700
+
701
+ bool GetIV(const uint8_t **out_iv, size_t *out_iv_len) const;
702
+
703
+ private:
704
+ // GetAdditionalData writes the additional data into |out| and returns the
705
+ // number of bytes written.
706
+ size_t GetAdditionalData(uint8_t out[13], uint8_t type,
707
+ uint16_t record_version, const uint8_t seqnum[8],
708
+ size_t plaintext_len);
709
+
710
+ const SSL_CIPHER *cipher_;
711
+ ScopedEVP_AEAD_CTX ctx_;
712
+ // fixed_nonce_ contains any bytes of the nonce that are fixed for all
713
+ // records.
714
+ uint8_t fixed_nonce_[12];
715
+ uint8_t fixed_nonce_len_ = 0, variable_nonce_len_ = 0;
716
+ // version_ is the wire version that should be used with this AEAD.
717
+ uint16_t version_;
718
+ // is_dtls_ is whether DTLS is being used with this AEAD.
719
+ bool is_dtls_;
720
+ // variable_nonce_included_in_record_ is true if the variable nonce
721
+ // for a record is included as a prefix before the ciphertext.
722
+ bool variable_nonce_included_in_record_ : 1;
723
+ // random_variable_nonce_ is true if the variable nonce is
724
+ // randomly generated, rather than derived from the sequence
725
+ // number.
726
+ bool random_variable_nonce_ : 1;
727
+ // omit_length_in_ad_ is true if the length should be omitted in the
728
+ // AEAD's ad parameter.
729
+ bool omit_length_in_ad_ : 1;
730
+ // omit_version_in_ad_ is true if the version should be omitted
731
+ // in the AEAD's ad parameter.
732
+ bool omit_version_in_ad_ : 1;
733
+ // omit_ad_ is true if the AEAD's ad parameter should be omitted.
734
+ bool omit_ad_ : 1;
735
+ // xor_fixed_nonce_ is true if the fixed nonce should be XOR'd into the
736
+ // variable nonce rather than prepended.
737
+ bool xor_fixed_nonce_ : 1;
738
+ };
414
739
 
415
740
 
416
- /* DTLS replay bitmap. */
741
+ // DTLS replay bitmap.
417
742
 
418
- /* DTLS1_BITMAP maintains a sliding window of 64 sequence numbers to detect
419
- * replayed packets. It should be initialized by zeroing every field. */
420
- typedef struct dtls1_bitmap_st {
421
- /* map is a bit mask of the last 64 sequence numbers. Bit
422
- * |1<<i| corresponds to |max_seq_num - i|. */
743
+ // DTLS1_BITMAP maintains a sliding window of 64 sequence numbers to detect
744
+ // replayed packets. It should be initialized by zeroing every field.
745
+ struct DTLS1_BITMAP {
746
+ // map is a bit mask of the last 64 sequence numbers. Bit
747
+ // |1<<i| corresponds to |max_seq_num - i|.
423
748
  uint64_t map;
424
- /* max_seq_num is the largest sequence number seen so far as a 64-bit
425
- * integer. */
749
+ // max_seq_num is the largest sequence number seen so far as a 64-bit
750
+ // integer.
426
751
  uint64_t max_seq_num;
427
- } DTLS1_BITMAP;
752
+ };
428
753
 
429
754
 
430
- /* Record layer. */
755
+ // Record layer.
431
756
 
432
- /* ssl_record_sequence_update increments the sequence number in |seq|. It
433
- * returns one on success and zero on wraparound. */
757
+ // ssl_record_sequence_update increments the sequence number in |seq|. It
758
+ // returns one on success and zero on wraparound.
434
759
  int ssl_record_sequence_update(uint8_t *seq, size_t seq_len);
435
760
 
436
- /* ssl_record_prefix_len returns the length of the prefix before the ciphertext
437
- * of a record for |ssl|.
438
- *
439
- * TODO(davidben): Expose this as part of public API once the high-level
440
- * buffer-free APIs are available. */
761
+ // ssl_record_prefix_len returns the length of the prefix before the ciphertext
762
+ // of a record for |ssl|.
763
+ //
764
+ // TODO(davidben): Expose this as part of public API once the high-level
765
+ // buffer-free APIs are available.
441
766
  size_t ssl_record_prefix_len(const SSL *ssl);
442
767
 
443
768
  enum ssl_open_record_t {
@@ -445,67 +770,66 @@ enum ssl_open_record_t {
445
770
  ssl_open_record_discard,
446
771
  ssl_open_record_partial,
447
772
  ssl_open_record_close_notify,
448
- ssl_open_record_fatal_alert,
449
773
  ssl_open_record_error,
450
774
  };
451
775
 
452
- /* tls_open_record decrypts a record from |in| in-place.
453
- *
454
- * If the input did not contain a complete record, it returns
455
- * |ssl_open_record_partial|. It sets |*out_consumed| to the total number of
456
- * bytes necessary. It is guaranteed that a successful call to |tls_open_record|
457
- * will consume at least that many bytes.
458
- *
459
- * Otherwise, it sets |*out_consumed| to the number of bytes of input
460
- * consumed. Note that input may be consumed on all return codes if a record was
461
- * decrypted.
462
- *
463
- * On success, it returns |ssl_open_record_success|. It sets |*out_type| to the
464
- * record type and |*out| to the record body in |in|. Note that |*out| may be
465
- * empty.
466
- *
467
- * If a record was successfully processed but should be discarded, it returns
468
- * |ssl_open_record_discard|.
469
- *
470
- * If a record was successfully processed but is a close_notify or fatal alert,
471
- * it returns |ssl_open_record_close_notify| or |ssl_open_record_fatal_alert|.
472
- *
473
- * On failure, it returns |ssl_open_record_error| and sets |*out_alert| to an
474
- * alert to emit. */
475
- enum ssl_open_record_t tls_open_record(SSL *ssl, uint8_t *out_type, CBS *out,
476
- size_t *out_consumed, uint8_t *out_alert,
477
- uint8_t *in, size_t in_len);
478
-
479
- /* dtls_open_record implements |tls_open_record| for DTLS. It never returns
480
- * |ssl_open_record_partial| but otherwise behaves analogously. */
481
- enum ssl_open_record_t dtls_open_record(SSL *ssl, uint8_t *out_type, CBS *out,
776
+ // tls_open_record decrypts a record from |in| in-place.
777
+ //
778
+ // If the input did not contain a complete record, it returns
779
+ // |ssl_open_record_partial|. It sets |*out_consumed| to the total number of
780
+ // bytes necessary. It is guaranteed that a successful call to |tls_open_record|
781
+ // will consume at least that many bytes.
782
+ //
783
+ // Otherwise, it sets |*out_consumed| to the number of bytes of input
784
+ // consumed. Note that input may be consumed on all return codes if a record was
785
+ // decrypted.
786
+ //
787
+ // On success, it returns |ssl_open_record_success|. It sets |*out_type| to the
788
+ // record type and |*out| to the record body in |in|. Note that |*out| may be
789
+ // empty.
790
+ //
791
+ // If a record was successfully processed but should be discarded, it returns
792
+ // |ssl_open_record_discard|.
793
+ //
794
+ // If a record was successfully processed but is a close_notify, it returns
795
+ // |ssl_open_record_close_notify|.
796
+ //
797
+ // On failure or fatal alert, it returns |ssl_open_record_error| and sets
798
+ // |*out_alert| to an alert to emit, or zero if no alert should be emitted.
799
+ enum ssl_open_record_t tls_open_record(SSL *ssl, uint8_t *out_type,
800
+ Span<uint8_t> *out, size_t *out_consumed,
801
+ uint8_t *out_alert, Span<uint8_t> in);
802
+
803
+ // dtls_open_record implements |tls_open_record| for DTLS. It never returns
804
+ // |ssl_open_record_partial| but otherwise behaves analogously.
805
+ enum ssl_open_record_t dtls_open_record(SSL *ssl, uint8_t *out_type,
806
+ Span<uint8_t> *out,
482
807
  size_t *out_consumed,
483
- uint8_t *out_alert, uint8_t *in,
484
- size_t in_len);
485
-
486
- /* ssl_seal_align_prefix_len returns the length of the prefix before the start
487
- * of the bulk of the ciphertext when sealing a record with |ssl|. Callers may
488
- * use this to align buffers.
489
- *
490
- * Note when TLS 1.0 CBC record-splitting is enabled, this includes the one byte
491
- * record and is the offset into second record's ciphertext. Thus sealing a
492
- * small record may result in a smaller output than this value.
493
- *
494
- * TODO(davidben): Is this alignment valuable? Record-splitting makes this a
495
- * mess. */
808
+ uint8_t *out_alert, Span<uint8_t> in);
809
+
810
+ // ssl_seal_align_prefix_len returns the length of the prefix before the start
811
+ // of the bulk of the ciphertext when sealing a record with |ssl|. Callers may
812
+ // use this to align buffers.
813
+ //
814
+ // Note when TLS 1.0 CBC record-splitting is enabled, this includes the one byte
815
+ // record and is the offset into second record's ciphertext. Thus sealing a
816
+ // small record may result in a smaller output than this value.
817
+ //
818
+ // TODO(davidben): Is this alignment valuable? Record-splitting makes this a
819
+ // mess.
496
820
  size_t ssl_seal_align_prefix_len(const SSL *ssl);
497
821
 
498
- /* tls_seal_record seals a new record of type |type| and body |in| and writes it
499
- * to |out|. At most |max_out| bytes will be written. It returns one on success
500
- * and zero on error. If enabled, |tls_seal_record| implements TLS 1.0 CBC 1/n-1
501
- * record splitting and may write two records concatenated.
502
- *
503
- * For a large record, the bulk of the ciphertext will begin
504
- * |ssl_seal_align_prefix_len| bytes into out. Aligning |out| appropriately may
505
- * improve performance. It writes at most |in_len| + |SSL_max_seal_overhead|
506
- * bytes to |out|.
507
- *
508
- * |in| and |out| may not alias. */
822
+ // tls_seal_record seals a new record of type |type| and body |in| and writes it
823
+ // to |out|. At most |max_out| bytes will be written. It returns one on success
824
+ // and zero on error. If enabled, |tls_seal_record| implements TLS 1.0 CBC 1/n-1
825
+ // record splitting and may write two records concatenated.
826
+ //
827
+ // For a large record, the bulk of the ciphertext will begin
828
+ // |ssl_seal_align_prefix_len| bytes into out. Aligning |out| appropriately may
829
+ // improve performance. It writes at most |in_len| + |SSL_max_seal_overhead|
830
+ // bytes to |out|.
831
+ //
832
+ // |in| and |out| may not alias.
509
833
  int tls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
510
834
  uint8_t type, const uint8_t *in, size_t in_len);
511
835
 
@@ -514,87 +838,81 @@ enum dtls1_use_epoch_t {
514
838
  dtls1_use_current_epoch,
515
839
  };
516
840
 
517
- /* dtls_max_seal_overhead returns the maximum overhead, in bytes, of sealing a
518
- * record. */
841
+ // dtls_max_seal_overhead returns the maximum overhead, in bytes, of sealing a
842
+ // record.
519
843
  size_t dtls_max_seal_overhead(const SSL *ssl, enum dtls1_use_epoch_t use_epoch);
520
844
 
521
- /* dtls_seal_prefix_len returns the number of bytes of prefix to reserve in
522
- * front of the plaintext when sealing a record in-place. */
845
+ // dtls_seal_prefix_len returns the number of bytes of prefix to reserve in
846
+ // front of the plaintext when sealing a record in-place.
523
847
  size_t dtls_seal_prefix_len(const SSL *ssl, enum dtls1_use_epoch_t use_epoch);
524
848
 
525
- /* dtls_seal_record implements |tls_seal_record| for DTLS. |use_epoch| selects
526
- * which epoch's cipher state to use. Unlike |tls_seal_record|, |in| and |out|
527
- * may alias but, if they do, |in| must be exactly |dtls_seal_prefix_len| bytes
528
- * ahead of |out|. */
849
+ // dtls_seal_record implements |tls_seal_record| for DTLS. |use_epoch| selects
850
+ // which epoch's cipher state to use. Unlike |tls_seal_record|, |in| and |out|
851
+ // may alias but, if they do, |in| must be exactly |dtls_seal_prefix_len| bytes
852
+ // ahead of |out|.
529
853
  int dtls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
530
854
  uint8_t type, const uint8_t *in, size_t in_len,
531
855
  enum dtls1_use_epoch_t use_epoch);
532
856
 
533
- /* ssl_process_alert processes |in| as an alert and updates |ssl|'s shutdown
534
- * state. It returns one of |ssl_open_record_discard|, |ssl_open_record_error|,
535
- * |ssl_open_record_close_notify|, or |ssl_open_record_fatal_alert| as
536
- * appropriate. */
857
+ // ssl_process_alert processes |in| as an alert and updates |ssl|'s shutdown
858
+ // state. It returns one of |ssl_open_record_discard|, |ssl_open_record_error|,
859
+ // |ssl_open_record_close_notify|, or |ssl_open_record_fatal_alert| as
860
+ // appropriate.
537
861
  enum ssl_open_record_t ssl_process_alert(SSL *ssl, uint8_t *out_alert,
538
- const uint8_t *in, size_t in_len);
862
+ Span<const uint8_t> in);
539
863
 
540
864
 
541
- /* Private key operations. */
865
+ // Private key operations.
542
866
 
543
- /* ssl_has_private_key returns one if |ssl| has a private key
544
- * configured and zero otherwise. */
867
+ // ssl_has_private_key returns one if |ssl| has a private key
868
+ // configured and zero otherwise.
545
869
  int ssl_has_private_key(const SSL *ssl);
546
870
 
547
- /* ssl_is_ecdsa_key_type returns one if |type| is an ECDSA key type and zero
548
- * otherwise. */
549
- int ssl_is_ecdsa_key_type(int type);
550
-
551
- /* ssl_private_key_* call the corresponding function on the
552
- * |SSL_PRIVATE_KEY_METHOD| for |ssl|, if configured. Otherwise, they implement
553
- * the operation with |EVP_PKEY|. */
554
-
555
- int ssl_private_key_type(SSL *ssl);
556
-
557
- size_t ssl_private_key_max_signature_len(SSL *ssl);
871
+ // ssl_private_key_* perform the corresponding operation on
872
+ // |SSL_PRIVATE_KEY_METHOD|. If there is a custom private key configured, they
873
+ // call the corresponding function or |complete| depending on whether there is a
874
+ // pending operation. Otherwise, they implement the operation with
875
+ // |EVP_PKEY|.
558
876
 
559
877
  enum ssl_private_key_result_t ssl_private_key_sign(
560
- SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
561
- uint16_t signature_algorithm, const uint8_t *in, size_t in_len);
878
+ SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len, size_t max_out,
879
+ uint16_t sigalg, const uint8_t *in, size_t in_len);
562
880
 
563
881
  enum ssl_private_key_result_t ssl_private_key_decrypt(
564
- SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
882
+ SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len, size_t max_out,
565
883
  const uint8_t *in, size_t in_len);
566
884
 
567
- enum ssl_private_key_result_t ssl_private_key_complete(SSL *ssl, uint8_t *out,
568
- size_t *out_len,
569
- size_t max_out);
885
+ // ssl_private_key_supports_signature_algorithm returns one if |hs|'s private
886
+ // key supports |sigalg| and zero otherwise.
887
+ int ssl_private_key_supports_signature_algorithm(SSL_HANDSHAKE *hs,
888
+ uint16_t sigalg);
570
889
 
571
- /* ssl_private_key_supports_signature_algorithm returns one if |ssl|'s private
572
- * key supports |signature_algorithm| and zero otherwise. */
573
- int ssl_private_key_supports_signature_algorithm(SSL *ssl,
574
- uint16_t signature_algorithm);
575
-
576
- /* ssl_public_key_verify verifies that the |signature| is valid for the public
577
- * key |pkey| and input |in|, using the |signature_algorithm| specified. */
578
- int ssl_public_key_verify(
579
- SSL *ssl, const uint8_t *signature, size_t signature_len,
580
- uint16_t signature_algorithm, EVP_PKEY *pkey,
581
- const uint8_t *in, size_t in_len);
890
+ // ssl_public_key_verify verifies that the |signature| is valid for the public
891
+ // key |pkey| and input |in|, using the signature algorithm |sigalg|.
892
+ int ssl_public_key_verify(SSL *ssl, const uint8_t *signature,
893
+ size_t signature_len, uint16_t sigalg, EVP_PKEY *pkey,
894
+ const uint8_t *in, size_t in_len);
582
895
 
583
896
 
584
- /* Custom extensions */
897
+ // Custom extensions
585
898
 
586
- typedef struct ssl_handshake_st SSL_HANDSHAKE;
899
+ } // namespace bssl
587
900
 
588
- /* ssl_custom_extension (a.k.a. SSL_CUSTOM_EXTENSION) is a structure that
589
- * contains information about custom-extension callbacks. */
590
- struct ssl_custom_extension {
901
+ // |SSL_CUSTOM_EXTENSION| is a structure that contains information about
902
+ // custom-extension callbacks. It is defined unnamespaced for compatibility with
903
+ // |STACK_OF(SSL_CUSTOM_EXTENSION)|.
904
+ typedef struct ssl_custom_extension {
591
905
  SSL_custom_ext_add_cb add_callback;
592
906
  void *add_arg;
593
907
  SSL_custom_ext_free_cb free_callback;
594
908
  SSL_custom_ext_parse_cb parse_callback;
595
909
  void *parse_arg;
596
910
  uint16_t value;
597
- };
911
+ } SSL_CUSTOM_EXTENSION;
912
+
913
+ DEFINE_STACK_OF(SSL_CUSTOM_EXTENSION)
914
+
915
+ namespace bssl {
598
916
 
599
917
  void SSL_CUSTOM_EXTENSION_free(SSL_CUSTOM_EXTENSION *custom_extension);
600
918
 
@@ -606,624 +924,657 @@ int custom_ext_parse_clienthello(SSL_HANDSHAKE *hs, int *out_alert,
606
924
  int custom_ext_add_serverhello(SSL_HANDSHAKE *hs, CBB *extensions);
607
925
 
608
926
 
609
- /* ECDH groups. */
610
-
611
- typedef struct ssl_ecdh_ctx_st SSL_ECDH_CTX;
612
-
613
- /* An SSL_ECDH_METHOD is an implementation of ECDH-like key exchanges for
614
- * TLS. */
615
- typedef struct ssl_ecdh_method_st {
616
- int nid;
617
- uint16_t group_id;
618
- const char name[8];
619
-
620
- /* cleanup releases state in |ctx|. */
621
- void (*cleanup)(SSL_ECDH_CTX *ctx);
622
-
623
- /* offer generates a keypair and writes the public value to
624
- * |out_public_key|. It returns one on success and zero on error. */
625
- int (*offer)(SSL_ECDH_CTX *ctx, CBB *out_public_key);
626
-
627
- /* accept performs a key exchange against the |peer_key| generated by |offer|.
628
- * On success, it returns one, writes the public value to |out_public_key|,
629
- * and sets |*out_secret| and |*out_secret_len| to a newly-allocated buffer
630
- * containing the shared secret. The caller must release this buffer with
631
- * |OPENSSL_free|. On failure, it returns zero and sets |*out_alert| to an
632
- * alert to send to the peer. */
633
- int (*accept)(SSL_ECDH_CTX *ctx, CBB *out_public_key, uint8_t **out_secret,
634
- size_t *out_secret_len, uint8_t *out_alert,
635
- const uint8_t *peer_key, size_t peer_key_len);
636
-
637
- /* finish performs a key exchange against the |peer_key| generated by
638
- * |accept|. On success, it returns one and sets |*out_secret| and
639
- * |*out_secret_len| to a newly-allocated buffer containing the shared
640
- * secret. The caller must release this buffer with |OPENSSL_free|. On
641
- * failure, it returns zero and sets |*out_alert| to an alert to send to the
642
- * peer. */
643
- int (*finish)(SSL_ECDH_CTX *ctx, uint8_t **out_secret, size_t *out_secret_len,
644
- uint8_t *out_alert, const uint8_t *peer_key,
645
- size_t peer_key_len);
646
-
647
- /* get_key initializes |out| with a length-prefixed key from |cbs|. It returns
648
- * one on success and zero on error. */
649
- int (*get_key)(CBS *cbs, CBS *out);
650
-
651
- /* add_key initializes |out_contents| to receive a key. Typically it will then
652
- * be passed to |offer| or |accept|. It returns one on success and zero on
653
- * error. */
654
- int (*add_key)(CBB *cbb, CBB *out_contents);
655
- } SSL_ECDH_METHOD;
656
-
657
- struct ssl_ecdh_ctx_st {
658
- const SSL_ECDH_METHOD *method;
659
- void *data;
927
+ // Key shares.
928
+
929
+ // SSLKeyShare abstracts over Diffie-Hellman-like key exchanges.
930
+ class SSLKeyShare {
931
+ public:
932
+ virtual ~SSLKeyShare() {}
933
+ static constexpr bool kAllowUniquePtr = true;
934
+ HAS_VIRTUAL_DESTRUCTOR
935
+
936
+ // Create returns a SSLKeyShare instance for use with group |group_id| or
937
+ // nullptr on error.
938
+ static UniquePtr<SSLKeyShare> Create(uint16_t group_id);
939
+
940
+ // GroupID returns the group ID.
941
+ virtual uint16_t GroupID() const PURE_VIRTUAL;
942
+
943
+ // Offer generates a keypair and writes the public value to
944
+ // |out_public_key|. It returns true on success and false on error.
945
+ virtual bool Offer(CBB *out_public_key) PURE_VIRTUAL;
946
+
947
+ // Accept performs a key exchange against the |peer_key| generated by |offer|.
948
+ // On success, it returns true, writes the public value to |out_public_key|,
949
+ // and sets |*out_secret| the shared secret. On failure, it returns false and
950
+ // sets |*out_alert| to an alert to send to the peer.
951
+ //
952
+ // The default implementation calls |Offer| and then |Finish|, assuming a key
953
+ // exchange protocol where the peers are symmetric.
954
+ virtual bool Accept(CBB *out_public_key, Array<uint8_t> *out_secret,
955
+ uint8_t *out_alert, Span<const uint8_t> peer_key);
956
+
957
+ // Finish performs a key exchange against the |peer_key| generated by
958
+ // |Accept|. On success, it returns true and sets |*out_secret| to the shared
959
+ // secret. On failure, it returns zero and sets |*out_alert| to an alert to
960
+ // send to the peer.
961
+ virtual bool Finish(Array<uint8_t> *out_secret, uint8_t *out_alert,
962
+ Span<const uint8_t> peer_key) PURE_VIRTUAL;
660
963
  };
661
964
 
662
- /* ssl_nid_to_group_id looks up the group corresponding to |nid|. On success, it
663
- * sets |*out_group_id| to the group ID and returns one. Otherwise, it returns
664
- * zero. */
965
+ // ssl_nid_to_group_id looks up the group corresponding to |nid|. On success, it
966
+ // sets |*out_group_id| to the group ID and returns one. Otherwise, it returns
967
+ // zero.
665
968
  int ssl_nid_to_group_id(uint16_t *out_group_id, int nid);
666
969
 
667
- /* ssl_name_to_group_id looks up the group corresponding to the |name| string
668
- * of length |len|. On success, it sets |*out_group_id| to the group ID and
669
- * returns one. Otherwise, it returns zero. */
970
+ // ssl_name_to_group_id looks up the group corresponding to the |name| string
971
+ // of length |len|. On success, it sets |*out_group_id| to the group ID and
972
+ // returns one. Otherwise, it returns zero.
670
973
  int ssl_name_to_group_id(uint16_t *out_group_id, const char *name, size_t len);
671
974
 
672
- /* SSL_ECDH_CTX_init sets up |ctx| for use with curve |group_id|. It returns one
673
- * on success and zero on error. */
674
- int SSL_ECDH_CTX_init(SSL_ECDH_CTX *ctx, uint16_t group_id);
675
-
676
- /* SSL_ECDH_CTX_init_for_dhe sets up |ctx| for use with legacy DHE-based ciphers
677
- * where the server specifies a group. It takes ownership of |params|. */
678
- void SSL_ECDH_CTX_init_for_dhe(SSL_ECDH_CTX *ctx, DH *params);
679
-
680
- /* SSL_ECDH_CTX_cleanup releases memory associated with |ctx|. It is legal to
681
- * call it in the zero state. */
682
- void SSL_ECDH_CTX_cleanup(SSL_ECDH_CTX *ctx);
683
975
 
684
- /* SSL_ECDH_CTX_get_id returns the group ID for |ctx|. */
685
- uint16_t SSL_ECDH_CTX_get_id(const SSL_ECDH_CTX *ctx);
976
+ // Handshake messages.
686
977
 
687
- /* SSL_ECDH_CTX_get_key calls the |get_key| method of |SSL_ECDH_METHOD|. */
688
- int SSL_ECDH_CTX_get_key(SSL_ECDH_CTX *ctx, CBS *cbs, CBS *out);
689
-
690
- /* SSL_ECDH_CTX_add_key calls the |add_key| method of |SSL_ECDH_METHOD|. */
691
- int SSL_ECDH_CTX_add_key(SSL_ECDH_CTX *ctx, CBB *cbb, CBB *out_contents);
692
-
693
- /* SSL_ECDH_CTX_offer calls the |offer| method of |SSL_ECDH_METHOD|. */
694
- int SSL_ECDH_CTX_offer(SSL_ECDH_CTX *ctx, CBB *out_public_key);
695
-
696
- /* SSL_ECDH_CTX_accept calls the |accept| method of |SSL_ECDH_METHOD|. */
697
- int SSL_ECDH_CTX_accept(SSL_ECDH_CTX *ctx, CBB *out_public_key,
698
- uint8_t **out_secret, size_t *out_secret_len,
699
- uint8_t *out_alert, const uint8_t *peer_key,
700
- size_t peer_key_len);
701
-
702
- /* SSL_ECDH_CTX_finish the |finish| method of |SSL_ECDH_METHOD|. */
703
- int SSL_ECDH_CTX_finish(SSL_ECDH_CTX *ctx, uint8_t **out_secret,
704
- size_t *out_secret_len, uint8_t *out_alert,
705
- const uint8_t *peer_key, size_t peer_key_len);
706
-
707
- /* Handshake messages. */
978
+ struct SSLMessage {
979
+ bool is_v2_hello;
980
+ uint8_t type;
981
+ CBS body;
982
+ // raw is the entire serialized handshake message, including the TLS or DTLS
983
+ // message header.
984
+ CBS raw;
985
+ };
708
986
 
709
- /* SSL_MAX_HANDSHAKE_FLIGHT is the number of messages, including
710
- * ChangeCipherSpec, in the longest handshake flight. Currently this is the
711
- * client's second leg in a full handshake when client certificates, NPN, and
712
- * Channel ID, are all enabled. */
987
+ // SSL_MAX_HANDSHAKE_FLIGHT is the number of messages, including
988
+ // ChangeCipherSpec, in the longest handshake flight. Currently this is the
989
+ // client's second leg in a full handshake when client certificates, NPN, and
990
+ // Channel ID, are all enabled.
713
991
  #define SSL_MAX_HANDSHAKE_FLIGHT 7
714
992
 
715
- /* ssl_max_handshake_message_len returns the maximum number of bytes permitted
716
- * in a handshake message for |ssl|. */
993
+ // ssl_max_handshake_message_len returns the maximum number of bytes permitted
994
+ // in a handshake message for |ssl|.
717
995
  size_t ssl_max_handshake_message_len(const SSL *ssl);
718
996
 
719
- /* dtls_clear_incoming_messages releases all buffered incoming messages. */
997
+ // dtls_clear_incoming_messages releases all buffered incoming messages.
720
998
  void dtls_clear_incoming_messages(SSL *ssl);
721
999
 
722
- /* dtls_has_incoming_messages returns one if there are buffered incoming
723
- * messages ahead of the current message and zero otherwise. */
1000
+ // dtls_has_incoming_messages returns one if there are buffered incoming
1001
+ // messages ahead of the current message and zero otherwise.
724
1002
  int dtls_has_incoming_messages(const SSL *ssl);
725
1003
 
726
- typedef struct dtls_outgoing_message_st {
1004
+ struct DTLS_OUTGOING_MESSAGE {
727
1005
  uint8_t *data;
728
1006
  uint32_t len;
729
1007
  uint16_t epoch;
730
1008
  char is_ccs;
731
- } DTLS_OUTGOING_MESSAGE;
1009
+ };
732
1010
 
733
- /* dtls_clear_outgoing_messages releases all buffered outgoing messages. */
1011
+ // dtls_clear_outgoing_messages releases all buffered outgoing messages.
734
1012
  void dtls_clear_outgoing_messages(SSL *ssl);
735
1013
 
736
1014
 
737
- /* Callbacks. */
1015
+ // Callbacks.
738
1016
 
739
- /* ssl_do_info_callback calls |ssl|'s info callback, if set. */
1017
+ // ssl_do_info_callback calls |ssl|'s info callback, if set.
740
1018
  void ssl_do_info_callback(const SSL *ssl, int type, int value);
741
1019
 
742
- /* ssl_do_msg_callback calls |ssl|'s message callback, if set. */
1020
+ // ssl_do_msg_callback calls |ssl|'s message callback, if set.
743
1021
  void ssl_do_msg_callback(SSL *ssl, int is_write, int content_type,
744
- const void *buf, size_t len);
745
-
1022
+ Span<const uint8_t> in);
746
1023
 
747
- /* Transport buffers. */
748
1024
 
749
- /* ssl_read_buffer returns a pointer to contents of the read buffer. */
750
- uint8_t *ssl_read_buffer(SSL *ssl);
1025
+ // Transport buffers.
751
1026
 
752
- /* ssl_read_buffer_len returns the length of the read buffer. */
753
- size_t ssl_read_buffer_len(const SSL *ssl);
1027
+ // ssl_read_buffer returns the current read buffer.
1028
+ Span<uint8_t> ssl_read_buffer(SSL *ssl);
754
1029
 
755
- /* ssl_read_buffer_extend_to extends the read buffer to the desired length. For
756
- * TLS, it reads to the end of the buffer until the buffer is |len| bytes
757
- * long. For DTLS, it reads a new packet and ignores |len|. It returns one on
758
- * success, zero on EOF, and a negative number on error.
759
- *
760
- * It is an error to call |ssl_read_buffer_extend_to| in DTLS when the buffer is
761
- * non-empty. */
1030
+ // ssl_read_buffer_extend_to extends the read buffer to the desired length. For
1031
+ // TLS, it reads to the end of the buffer until the buffer is |len| bytes
1032
+ // long. For DTLS, it reads a new packet and ignores |len|. It returns one on
1033
+ // success, zero on EOF, and a negative number on error.
1034
+ //
1035
+ // It is an error to call |ssl_read_buffer_extend_to| in DTLS when the buffer is
1036
+ // non-empty.
762
1037
  int ssl_read_buffer_extend_to(SSL *ssl, size_t len);
763
1038
 
764
- /* ssl_read_buffer_consume consumes |len| bytes from the read buffer. It
765
- * advances the data pointer and decrements the length. The memory consumed will
766
- * remain valid until the next call to |ssl_read_buffer_extend| or it is
767
- * discarded with |ssl_read_buffer_discard|. */
1039
+ // ssl_read_buffer_consume consumes |len| bytes from the read buffer. It
1040
+ // advances the data pointer and decrements the length. The memory consumed will
1041
+ // remain valid until the next call to |ssl_read_buffer_extend| or it is
1042
+ // discarded with |ssl_read_buffer_discard|.
768
1043
  void ssl_read_buffer_consume(SSL *ssl, size_t len);
769
1044
 
770
- /* ssl_read_buffer_discard discards the consumed bytes from the read buffer. If
771
- * the buffer is now empty, it releases memory used by it. */
1045
+ // ssl_read_buffer_discard discards the consumed bytes from the read buffer. If
1046
+ // the buffer is now empty, it releases memory used by it.
772
1047
  void ssl_read_buffer_discard(SSL *ssl);
773
1048
 
774
- /* ssl_read_buffer_clear releases all memory associated with the read buffer and
775
- * zero-initializes it. */
1049
+ // ssl_read_buffer_clear releases all memory associated with the read buffer and
1050
+ // zero-initializes it.
776
1051
  void ssl_read_buffer_clear(SSL *ssl);
777
1052
 
778
- /* ssl_write_buffer_is_pending returns one if the write buffer has pending data
779
- * and zero if is empty. */
1053
+ // ssl_write_buffer_is_pending returns one if the write buffer has pending data
1054
+ // and zero if is empty.
780
1055
  int ssl_write_buffer_is_pending(const SSL *ssl);
781
1056
 
782
- /* ssl_write_buffer_init initializes the write buffer. On success, it sets
783
- * |*out_ptr| to the start of the write buffer with space for up to |max_len|
784
- * bytes. It returns one on success and zero on failure. Call
785
- * |ssl_write_buffer_set_len| to complete initialization. */
1057
+ // ssl_write_buffer_init initializes the write buffer. On success, it sets
1058
+ // |*out_ptr| to the start of the write buffer with space for up to |max_len|
1059
+ // bytes. It returns one on success and zero on failure. Call
1060
+ // |ssl_write_buffer_set_len| to complete initialization.
786
1061
  int ssl_write_buffer_init(SSL *ssl, uint8_t **out_ptr, size_t max_len);
787
1062
 
788
- /* ssl_write_buffer_set_len is called after |ssl_write_buffer_init| to complete
789
- * initialization after |len| bytes are written to the buffer. */
1063
+ // ssl_write_buffer_set_len is called after |ssl_write_buffer_init| to complete
1064
+ // initialization after |len| bytes are written to the buffer.
790
1065
  void ssl_write_buffer_set_len(SSL *ssl, size_t len);
791
1066
 
792
- /* ssl_write_buffer_flush flushes the write buffer to the transport. It returns
793
- * one on success and <= 0 on error. For DTLS, whether or not the write
794
- * succeeds, the write buffer will be cleared. */
1067
+ // ssl_write_buffer_flush flushes the write buffer to the transport. It returns
1068
+ // one on success and <= 0 on error. For DTLS, whether or not the write
1069
+ // succeeds, the write buffer will be cleared.
795
1070
  int ssl_write_buffer_flush(SSL *ssl);
796
1071
 
797
- /* ssl_write_buffer_clear releases all memory associated with the write buffer
798
- * and zero-initializes it. */
1072
+ // ssl_write_buffer_clear releases all memory associated with the write buffer
1073
+ // and zero-initializes it.
799
1074
  void ssl_write_buffer_clear(SSL *ssl);
800
1075
 
801
1076
 
802
- /* Certificate functions. */
1077
+ // Certificate functions.
803
1078
 
804
- /* ssl_has_certificate returns one if a certificate and private key are
805
- * configured and zero otherwise. */
1079
+ // ssl_has_certificate returns one if a certificate and private key are
1080
+ // configured and zero otherwise.
806
1081
  int ssl_has_certificate(const SSL *ssl);
807
1082
 
808
- /* ssl_parse_cert_chain parses a certificate list from |cbs| in the format used
809
- * by a TLS Certificate message. On success, it returns a newly-allocated
810
- * |CRYPTO_BUFFER| list and advances |cbs|. Otherwise, it returns NULL and sets
811
- * |*out_alert| to an alert to send to the peer.
812
- *
813
- * If the list is non-empty then |*out_pubkey| will be set to a freshly
814
- * allocated public-key from the leaf certificate.
815
- *
816
- * If the list is non-empty and |out_leaf_sha256| is non-NULL, it writes the
817
- * SHA-256 hash of the leaf to |out_leaf_sha256|. */
818
- STACK_OF(CRYPTO_BUFFER) *ssl_parse_cert_chain(uint8_t *out_alert,
819
- EVP_PKEY **out_pubkey,
820
- uint8_t *out_leaf_sha256,
821
- CBS *cbs,
822
- CRYPTO_BUFFER_POOL *pool);
823
-
824
- /* ssl_add_cert_chain adds |ssl|'s certificate chain to |cbb| in the format used
825
- * by a TLS Certificate message. If there is no certificate chain, it emits an
826
- * empty certificate list. It returns one on success and zero on error. */
1083
+ // ssl_parse_cert_chain parses a certificate list from |cbs| in the format used
1084
+ // by a TLS Certificate message. On success, it advances |cbs| and returns
1085
+ // true. Otherwise, it returns false and sets |*out_alert| to an alert to send
1086
+ // to the peer.
1087
+ //
1088
+ // If the list is non-empty then |*out_chain| and |*out_pubkey| will be set to
1089
+ // the certificate chain and the leaf certificate's public key
1090
+ // respectively. Otherwise, both will be set to nullptr.
1091
+ //
1092
+ // If the list is non-empty and |out_leaf_sha256| is non-NULL, it writes the
1093
+ // SHA-256 hash of the leaf to |out_leaf_sha256|.
1094
+ bool ssl_parse_cert_chain(uint8_t *out_alert,
1095
+ UniquePtr<STACK_OF(CRYPTO_BUFFER)> *out_chain,
1096
+ UniquePtr<EVP_PKEY> *out_pubkey,
1097
+ uint8_t *out_leaf_sha256, CBS *cbs,
1098
+ CRYPTO_BUFFER_POOL *pool);
1099
+
1100
+ // ssl_add_cert_chain adds |ssl|'s certificate chain to |cbb| in the format used
1101
+ // by a TLS Certificate message. If there is no certificate chain, it emits an
1102
+ // empty certificate list. It returns one on success and zero on error.
827
1103
  int ssl_add_cert_chain(SSL *ssl, CBB *cbb);
828
1104
 
829
- /* ssl_auto_chain_if_needed runs the deprecated auto-chaining logic if
830
- * necessary. On success, it updates |ssl|'s certificate configuration as needed
831
- * and returns one. Otherwise, it returns zero. */
832
- int ssl_auto_chain_if_needed(SSL *ssl);
833
-
834
- /* ssl_cert_check_digital_signature_key_usage parses the DER-encoded, X.509
835
- * certificate in |in| and returns one if doesn't specify a key usage or, if it
836
- * does, if it includes digitalSignature. Otherwise it pushes to the error
837
- * queue and returns zero. */
1105
+ // ssl_cert_check_digital_signature_key_usage parses the DER-encoded, X.509
1106
+ // certificate in |in| and returns one if doesn't specify a key usage or, if it
1107
+ // does, if it includes digitalSignature. Otherwise it pushes to the error
1108
+ // queue and returns zero.
838
1109
  int ssl_cert_check_digital_signature_key_usage(const CBS *in);
839
1110
 
840
- /* ssl_cert_parse_pubkey extracts the public key from the DER-encoded, X.509
841
- * certificate in |in|. It returns an allocated |EVP_PKEY| or else returns NULL
842
- * and pushes to the error queue. */
843
- EVP_PKEY *ssl_cert_parse_pubkey(const CBS *in);
844
-
845
- /* ssl_parse_client_CA_list parses a CA list from |cbs| in the format used by a
846
- * TLS CertificateRequest message. On success, it returns a newly-allocated
847
- * |X509_NAME| list and advances |cbs|. Otherwise, it returns NULL and sets
848
- * |*out_alert| to an alert to send to the peer. */
849
- STACK_OF(X509_NAME) *
850
- ssl_parse_client_CA_list(SSL *ssl, uint8_t *out_alert, CBS *cbs);
851
-
852
- /* ssl_add_client_CA_list adds the configured CA list to |cbb| in the format
853
- * used by a TLS CertificateRequest message. It returns one on success and zero
854
- * on error. */
1111
+ // ssl_cert_parse_pubkey extracts the public key from the DER-encoded, X.509
1112
+ // certificate in |in|. It returns an allocated |EVP_PKEY| or else returns
1113
+ // nullptr and pushes to the error queue.
1114
+ UniquePtr<EVP_PKEY> ssl_cert_parse_pubkey(const CBS *in);
1115
+
1116
+ // ssl_parse_client_CA_list parses a CA list from |cbs| in the format used by a
1117
+ // TLS CertificateRequest message. On success, it returns a newly-allocated
1118
+ // |CRYPTO_BUFFER| list and advances |cbs|. Otherwise, it returns nullptr and
1119
+ // sets |*out_alert| to an alert to send to the peer.
1120
+ UniquePtr<STACK_OF(CRYPTO_BUFFER)> ssl_parse_client_CA_list(SSL *ssl,
1121
+ uint8_t *out_alert,
1122
+ CBS *cbs);
1123
+
1124
+ // ssl_add_client_CA_list adds the configured CA list to |cbb| in the format
1125
+ // used by a TLS CertificateRequest message. It returns one on success and zero
1126
+ // on error.
855
1127
  int ssl_add_client_CA_list(SSL *ssl, CBB *cbb);
856
1128
 
857
- /* ssl_check_leaf_certificate returns one if |pkey| and |leaf| are suitable as
858
- * a server's leaf certificate for |hs|. Otherwise, it returns zero and pushes
859
- * an error on the error queue. */
1129
+ // ssl_check_leaf_certificate returns one if |pkey| and |leaf| are suitable as
1130
+ // a server's leaf certificate for |hs|. Otherwise, it returns zero and pushes
1131
+ // an error on the error queue.
860
1132
  int ssl_check_leaf_certificate(SSL_HANDSHAKE *hs, EVP_PKEY *pkey,
861
1133
  const CRYPTO_BUFFER *leaf);
862
1134
 
1135
+ // ssl_on_certificate_selected is called once the certificate has been selected.
1136
+ // It finalizes the certificate and initializes |hs->local_pubkey|. It returns
1137
+ // one on success and zero on error.
1138
+ int ssl_on_certificate_selected(SSL_HANDSHAKE *hs);
863
1139
 
864
- /* TLS 1.3 key derivation. */
865
1140
 
866
- /* tls13_init_key_schedule initializes the handshake hash and key derivation
867
- * state. The cipher suite and PRF hash must have been selected at this point.
868
- * It returns one on success and zero on error. */
1141
+ // TLS 1.3 key derivation.
1142
+
1143
+ // tls13_init_key_schedule initializes the handshake hash and key derivation
1144
+ // state. The cipher suite and PRF hash must have been selected at this point.
1145
+ // It returns one on success and zero on error.
869
1146
  int tls13_init_key_schedule(SSL_HANDSHAKE *hs);
870
1147
 
871
- /* tls13_advance_key_schedule incorporates |in| into the key schedule with
872
- * HKDF-Extract. It returns one on success and zero on error. */
1148
+ // tls13_init_early_key_schedule initializes the handshake hash and key
1149
+ // derivation state from the resumption secret to derive the early secrets. It
1150
+ // returns one on success and zero on error.
1151
+ int tls13_init_early_key_schedule(SSL_HANDSHAKE *hs);
1152
+
1153
+ // tls13_advance_key_schedule incorporates |in| into the key schedule with
1154
+ // HKDF-Extract. It returns one on success and zero on error.
873
1155
  int tls13_advance_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *in,
874
1156
  size_t len);
875
1157
 
876
- /* tls13_set_traffic_key sets the read or write traffic keys to
877
- * |traffic_secret|. It returns one on success and zero on error. */
1158
+ // tls13_set_traffic_key sets the read or write traffic keys to
1159
+ // |traffic_secret|. It returns one on success and zero on error.
878
1160
  int tls13_set_traffic_key(SSL *ssl, enum evp_aead_direction_t direction,
879
1161
  const uint8_t *traffic_secret,
880
1162
  size_t traffic_secret_len);
881
1163
 
882
- /* tls13_derive_handshake_secrets derives the handshake traffic secret. It
883
- * returns one on success and zero on error. */
1164
+ // tls13_derive_early_secrets derives the early traffic secret. It returns one
1165
+ // on success and zero on error.
1166
+ int tls13_derive_early_secrets(SSL_HANDSHAKE *hs);
1167
+
1168
+ // tls13_derive_handshake_secrets derives the handshake traffic secret. It
1169
+ // returns one on success and zero on error.
884
1170
  int tls13_derive_handshake_secrets(SSL_HANDSHAKE *hs);
885
1171
 
886
- /* tls13_rotate_traffic_key derives the next read or write traffic secret. It
887
- * returns one on success and zero on error. */
1172
+ // tls13_rotate_traffic_key derives the next read or write traffic secret. It
1173
+ // returns one on success and zero on error.
888
1174
  int tls13_rotate_traffic_key(SSL *ssl, enum evp_aead_direction_t direction);
889
1175
 
890
- /* tls13_derive_application_secrets derives the initial application data traffic
891
- * and exporter secrets based on the handshake transcripts and |master_secret|.
892
- * It returns one on success and zero on error. */
1176
+ // tls13_derive_application_secrets derives the initial application data traffic
1177
+ // and exporter secrets based on the handshake transcripts and |master_secret|.
1178
+ // It returns one on success and zero on error.
893
1179
  int tls13_derive_application_secrets(SSL_HANDSHAKE *hs);
894
1180
 
895
- /* tls13_derive_resumption_secret derives the |resumption_secret|. */
1181
+ // tls13_derive_resumption_secret derives the |resumption_secret|.
896
1182
  int tls13_derive_resumption_secret(SSL_HANDSHAKE *hs);
897
1183
 
898
- /* tls13_export_keying_material provides an exporter interface to use the
899
- * |exporter_secret|. */
1184
+ // tls13_export_keying_material provides an exporter interface to use the
1185
+ // |exporter_secret|.
900
1186
  int tls13_export_keying_material(SSL *ssl, uint8_t *out, size_t out_len,
901
1187
  const char *label, size_t label_len,
902
1188
  const uint8_t *context, size_t context_len,
903
1189
  int use_context);
904
1190
 
905
- /* tls13_finished_mac calculates the MAC of the handshake transcript to verify
906
- * the integrity of the Finished message, and stores the result in |out| and
907
- * length in |out_len|. |is_server| is 1 if this is for the Server Finished and
908
- * 0 for the Client Finished. */
1191
+ // tls13_finished_mac calculates the MAC of the handshake transcript to verify
1192
+ // the integrity of the Finished message, and stores the result in |out| and
1193
+ // length in |out_len|. |is_server| is 1 if this is for the Server Finished and
1194
+ // 0 for the Client Finished.
909
1195
  int tls13_finished_mac(SSL_HANDSHAKE *hs, uint8_t *out,
910
1196
  size_t *out_len, int is_server);
911
1197
 
912
- /* tls13_write_psk_binder calculates the PSK binder value and replaces the last
913
- * bytes of |msg| with the resulting value. It returns 1 on success, and 0 on
914
- * failure. */
1198
+ // tls13_write_psk_binder calculates the PSK binder value and replaces the last
1199
+ // bytes of |msg| with the resulting value. It returns 1 on success, and 0 on
1200
+ // failure.
915
1201
  int tls13_write_psk_binder(SSL_HANDSHAKE *hs, uint8_t *msg, size_t len);
916
1202
 
917
- /* tls13_verify_psk_binder verifies that the handshake transcript, truncated
918
- * up to the binders has a valid signature using the value of |session|'s
919
- * resumption secret. It returns 1 on success, and 0 on failure. */
1203
+ // tls13_verify_psk_binder verifies that the handshake transcript, truncated
1204
+ // up to the binders has a valid signature using the value of |session|'s
1205
+ // resumption secret. It returns 1 on success, and 0 on failure.
920
1206
  int tls13_verify_psk_binder(SSL_HANDSHAKE *hs, SSL_SESSION *session,
921
- CBS *binders);
1207
+ const SSLMessage &msg, CBS *binders);
922
1208
 
923
1209
 
924
- /* Handshake functions. */
1210
+ // Handshake functions.
925
1211
 
926
1212
  enum ssl_hs_wait_t {
927
1213
  ssl_hs_error,
928
1214
  ssl_hs_ok,
1215
+ ssl_hs_read_server_hello,
929
1216
  ssl_hs_read_message,
930
1217
  ssl_hs_flush,
931
- ssl_hs_flush_and_read_message,
1218
+ ssl_hs_certificate_selection_pending,
932
1219
  ssl_hs_x509_lookup,
933
1220
  ssl_hs_channel_id_lookup,
934
1221
  ssl_hs_private_key_operation,
1222
+ ssl_hs_pending_session,
1223
+ ssl_hs_pending_ticket,
1224
+ ssl_hs_early_return,
1225
+ ssl_hs_early_data_rejected,
1226
+ ssl_hs_read_end_of_early_data,
1227
+ ssl_hs_read_change_cipher_spec,
1228
+ ssl_hs_certificate_verify,
935
1229
  };
936
1230
 
937
- struct ssl_handshake_st {
938
- /* ssl is a non-owning pointer to the parent |SSL| object. */
1231
+ struct SSL_HANDSHAKE {
1232
+ explicit SSL_HANDSHAKE(SSL *ssl);
1233
+ ~SSL_HANDSHAKE();
1234
+ static constexpr bool kAllowUniquePtr = true;
1235
+
1236
+ // ssl is a non-owning pointer to the parent |SSL| object.
939
1237
  SSL *ssl;
940
1238
 
941
- /* do_tls13_handshake runs the TLS 1.3 handshake. On completion, it returns
942
- * |ssl_hs_ok|. Otherwise, it returns a value corresponding to what operation
943
- * is needed to progress. */
944
- enum ssl_hs_wait_t (*do_tls13_handshake)(SSL_HANDSHAKE *hs);
1239
+ // wait contains the operation the handshake is currently blocking on or
1240
+ // |ssl_hs_ok| if none.
1241
+ enum ssl_hs_wait_t wait = ssl_hs_ok;
945
1242
 
946
- /* wait contains the operation |do_tls13_handshake| is currently blocking on
947
- * or |ssl_hs_ok| if none. */
948
- enum ssl_hs_wait_t wait;
1243
+ // state is the internal state for the TLS 1.2 and below handshake. Its
1244
+ // values depend on |do_handshake| but the starting state is always zero.
1245
+ int state = 0;
949
1246
 
950
- /* state contains one of the SSL3_ST_* values. */
951
- int state;
1247
+ // tls13_state is the internal state for the TLS 1.3 handshake. Its values
1248
+ // depend on |do_handshake| but the starting state is always zero.
1249
+ int tls13_state = 0;
952
1250
 
953
- /* next_state is used when SSL_ST_FLUSH_DATA is entered */
954
- int next_state;
1251
+ // min_version is the minimum accepted protocol version, taking account both
1252
+ // |SSL_OP_NO_*| and |SSL_CTX_set_min_proto_version| APIs.
1253
+ uint16_t min_version = 0;
955
1254
 
956
- /* tls13_state is the internal state for the TLS 1.3 handshake. Its values
957
- * depend on |do_tls13_handshake| but the starting state is always zero. */
958
- int tls13_state;
1255
+ // max_version is the maximum accepted protocol version, taking account both
1256
+ // |SSL_OP_NO_*| and |SSL_CTX_set_max_proto_version| APIs.
1257
+ uint16_t max_version = 0;
959
1258
 
960
- size_t hash_len;
961
- uint8_t secret[EVP_MAX_MD_SIZE];
962
- uint8_t client_handshake_secret[EVP_MAX_MD_SIZE];
963
- uint8_t server_handshake_secret[EVP_MAX_MD_SIZE];
964
- uint8_t client_traffic_secret_0[EVP_MAX_MD_SIZE];
965
- uint8_t server_traffic_secret_0[EVP_MAX_MD_SIZE];
1259
+ // session_id is the session ID in the ClientHello, used for the experimental
1260
+ // TLS 1.3 variant.
1261
+ uint8_t session_id[SSL_MAX_SSL_SESSION_ID_LENGTH] = {0};
1262
+ uint8_t session_id_len = 0;
1263
+
1264
+ size_t hash_len = 0;
1265
+ uint8_t secret[EVP_MAX_MD_SIZE] = {0};
1266
+ uint8_t early_traffic_secret[EVP_MAX_MD_SIZE] = {0};
1267
+ uint8_t client_handshake_secret[EVP_MAX_MD_SIZE] = {0};
1268
+ uint8_t server_handshake_secret[EVP_MAX_MD_SIZE] = {0};
1269
+ uint8_t client_traffic_secret_0[EVP_MAX_MD_SIZE] = {0};
1270
+ uint8_t server_traffic_secret_0[EVP_MAX_MD_SIZE] = {0};
1271
+ uint8_t expected_client_finished[EVP_MAX_MD_SIZE] = {0};
966
1272
 
967
1273
  union {
968
- /* sent is a bitset where the bits correspond to elements of kExtensions
969
- * in t1_lib.c. Each bit is set if that extension was sent in a
970
- * ClientHello. It's not used by servers. */
971
- uint32_t sent;
972
- /* received is a bitset, like |sent|, but is used by servers to record
973
- * which extensions were received from a client. */
1274
+ // sent is a bitset where the bits correspond to elements of kExtensions
1275
+ // in t1_lib.c. Each bit is set if that extension was sent in a
1276
+ // ClientHello. It's not used by servers.
1277
+ uint32_t sent = 0;
1278
+ // received is a bitset, like |sent|, but is used by servers to record
1279
+ // which extensions were received from a client.
974
1280
  uint32_t received;
975
1281
  } extensions;
976
1282
 
977
1283
  union {
978
- /* sent is a bitset where the bits correspond to elements of
979
- * |client_custom_extensions| in the |SSL_CTX|. Each bit is set if that
980
- * extension was sent in a ClientHello. It's not used by servers. */
981
- uint16_t sent;
982
- /* received is a bitset, like |sent|, but is used by servers to record
983
- * which custom extensions were received from a client. The bits here
984
- * correspond to |server_custom_extensions|. */
1284
+ // sent is a bitset where the bits correspond to elements of
1285
+ // |client_custom_extensions| in the |SSL_CTX|. Each bit is set if that
1286
+ // extension was sent in a ClientHello. It's not used by servers.
1287
+ uint16_t sent = 0;
1288
+ // received is a bitset, like |sent|, but is used by servers to record
1289
+ // which custom extensions were received from a client. The bits here
1290
+ // correspond to |server_custom_extensions|.
985
1291
  uint16_t received;
986
1292
  } custom_extensions;
987
1293
 
988
- /* retry_group is the group ID selected by the server in HelloRetryRequest in
989
- * TLS 1.3. */
990
- uint16_t retry_group;
1294
+ // retry_group is the group ID selected by the server in HelloRetryRequest in
1295
+ // TLS 1.3.
1296
+ uint16_t retry_group = 0;
991
1297
 
992
- /* ecdh_ctx is the current ECDH instance. */
993
- SSL_ECDH_CTX ecdh_ctx;
1298
+ // error, if |wait| is |ssl_hs_error|, is the error the handshake failed on.
1299
+ UniquePtr<ERR_SAVE_STATE> error;
994
1300
 
995
- /* transcript is the current handshake transcript. */
996
- SSL_TRANSCRIPT transcript;
1301
+ // key_share is the current key exchange instance.
1302
+ UniquePtr<SSLKeyShare> key_share;
997
1303
 
998
- /* cookie is the value of the cookie received from the server, if any. */
999
- uint8_t *cookie;
1000
- size_t cookie_len;
1304
+ // transcript is the current handshake transcript.
1305
+ SSLTranscript transcript;
1001
1306
 
1002
- /* key_share_bytes is the value of the previously sent KeyShare extension by
1003
- * the client in TLS 1.3. */
1004
- uint8_t *key_share_bytes;
1005
- size_t key_share_bytes_len;
1006
-
1007
- /* public_key, for servers, is the key share to be sent to the client in TLS
1008
- * 1.3. */
1009
- uint8_t *public_key;
1010
- size_t public_key_len;
1011
-
1012
- /* peer_sigalgs are the signature algorithms that the peer supports. These are
1013
- * taken from the contents of the signature algorithms extension for a server
1014
- * or from the CertificateRequest for a client. */
1015
- uint16_t *peer_sigalgs;
1016
- /* num_peer_sigalgs is the number of entries in |peer_sigalgs|. */
1017
- size_t num_peer_sigalgs;
1018
-
1019
- /* peer_supported_group_list contains the supported group IDs advertised by
1020
- * the peer. This is only set on the server's end. The server does not
1021
- * advertise this extension to the client. */
1022
- uint16_t *peer_supported_group_list;
1023
- size_t peer_supported_group_list_len;
1024
-
1025
- /* peer_key is the peer's ECDH key for a TLS 1.2 client. */
1026
- uint8_t *peer_key;
1027
- size_t peer_key_len;
1028
-
1029
- /* server_params, in TLS 1.2, stores the ServerKeyExchange parameters to be
1030
- * signed while the signature is being computed. */
1031
- uint8_t *server_params;
1032
- size_t server_params_len;
1033
-
1034
- /* peer_psk_identity_hint, on the client, is the psk_identity_hint sent by the
1035
- * server when using a TLS 1.2 PSK key exchange. */
1036
- char *peer_psk_identity_hint;
1037
-
1038
- /* ca_names, on the client, contains the list of CAs received in a
1039
- * CertificateRequest message. */
1040
- STACK_OF(X509_NAME) *ca_names;
1041
-
1042
- /* certificate_types, on the client, contains the set of certificate types
1043
- * received in a CertificateRequest message. */
1044
- uint8_t *certificate_types;
1045
- size_t num_certificate_types;
1046
-
1047
- /* hostname, on the server, is the value of the SNI extension. */
1048
- char *hostname;
1307
+ // cookie is the value of the cookie received from the server, if any.
1308
+ Array<uint8_t> cookie;
1309
+
1310
+ // key_share_bytes is the value of the previously sent KeyShare extension by
1311
+ // the client in TLS 1.3.
1312
+ Array<uint8_t> key_share_bytes;
1313
+
1314
+ // ecdh_public_key, for servers, is the key share to be sent to the client in
1315
+ // TLS 1.3.
1316
+ Array<uint8_t> ecdh_public_key;
1317
+
1318
+ // peer_sigalgs are the signature algorithms that the peer supports. These are
1319
+ // taken from the contents of the signature algorithms extension for a server
1320
+ // or from the CertificateRequest for a client.
1321
+ Array<uint16_t> peer_sigalgs;
1322
+
1323
+ // peer_supported_group_list contains the supported group IDs advertised by
1324
+ // the peer. This is only set on the server's end. The server does not
1325
+ // advertise this extension to the client.
1326
+ Array<uint16_t> peer_supported_group_list;
1327
+
1328
+ // peer_key is the peer's ECDH key for a TLS 1.2 client.
1329
+ Array<uint8_t> peer_key;
1330
+
1331
+ // server_params, in a TLS 1.2 server, stores the ServerKeyExchange
1332
+ // parameters. It has client and server randoms prepended for signing
1333
+ // convenience.
1334
+ Array<uint8_t> server_params;
1335
+
1336
+ // peer_psk_identity_hint, on the client, is the psk_identity_hint sent by the
1337
+ // server when using a TLS 1.2 PSK key exchange.
1338
+ UniquePtr<char> peer_psk_identity_hint;
1339
+
1340
+ // ca_names, on the client, contains the list of CAs received in a
1341
+ // CertificateRequest message.
1342
+ UniquePtr<STACK_OF(CRYPTO_BUFFER)> ca_names;
1343
+
1344
+ // cached_x509_ca_names contains a cache of parsed versions of the elements of
1345
+ // |ca_names|. This pointer is left non-owning so only
1346
+ // |ssl_crypto_x509_method| needs to link against crypto/x509.
1347
+ STACK_OF(X509_NAME) *cached_x509_ca_names = nullptr;
1348
+
1349
+ // certificate_types, on the client, contains the set of certificate types
1350
+ // received in a CertificateRequest message.
1351
+ Array<uint8_t> certificate_types;
1352
+
1353
+ // local_pubkey is the public key we are authenticating as.
1354
+ UniquePtr<EVP_PKEY> local_pubkey;
1355
+
1356
+ // peer_pubkey is the public key parsed from the peer's leaf certificate.
1357
+ UniquePtr<EVP_PKEY> peer_pubkey;
1358
+
1359
+ // new_session is the new mutable session being established by the current
1360
+ // handshake. It should not be cached.
1361
+ UniquePtr<SSL_SESSION> new_session;
1362
+
1363
+ // early_session is the session corresponding to the current 0-RTT state on
1364
+ // the client if |in_early_data| is true.
1365
+ UniquePtr<SSL_SESSION> early_session;
1366
+
1367
+ // new_cipher is the cipher being negotiated in this handshake.
1368
+ const SSL_CIPHER *new_cipher = nullptr;
1369
+
1370
+ // key_block is the record-layer key block for TLS 1.2 and earlier.
1371
+ Array<uint8_t> key_block;
1049
1372
 
1050
- /* peer_pubkey is the public key parsed from the peer's leaf certificate. */
1051
- EVP_PKEY *peer_pubkey;
1373
+ // scts_requested is true if the SCT extension is in the ClientHello.
1374
+ bool scts_requested:1;
1052
1375
 
1053
- /* new_session is the new mutable session being established by the current
1054
- * handshake. It should not be cached. */
1055
- SSL_SESSION *new_session;
1376
+ // needs_psk_binder is true if the ClientHello has a placeholder PSK binder to
1377
+ // be filled in.
1378
+ bool needs_psk_binder:1;
1056
1379
 
1057
- /* new_cipher is the cipher being negotiated in this handshake. */
1058
- const SSL_CIPHER *new_cipher;
1380
+ bool received_hello_retry_request:1;
1059
1381
 
1060
- /* key_block is the record-layer key block for TLS 1.2 and earlier. */
1061
- uint8_t *key_block;
1062
- uint8_t key_block_len;
1382
+ bool received_custom_extension:1;
1063
1383
 
1064
- /* session_tickets_sent, in TLS 1.3, is the number of tickets the server has
1065
- * sent. */
1066
- uint8_t session_tickets_sent;
1384
+ // handshake_finalized is true once the handshake has completed, at which
1385
+ // point accessors should use the established state.
1386
+ bool handshake_finalized:1;
1067
1387
 
1068
- /* scts_requested is one if the SCT extension is in the ClientHello. */
1069
- unsigned scts_requested:1;
1388
+ // accept_psk_mode stores whether the client's PSK mode is compatible with our
1389
+ // preferences.
1390
+ bool accept_psk_mode:1;
1070
1391
 
1071
- /* needs_psk_binder if the ClientHello has a placeholder PSK binder to be
1072
- * filled in. */
1073
- unsigned needs_psk_binder:1;
1392
+ // cert_request is true if a client certificate was requested.
1393
+ bool cert_request:1;
1074
1394
 
1075
- unsigned received_hello_retry_request:1;
1395
+ // certificate_status_expected is true if OCSP stapling was negotiated and the
1396
+ // server is expected to send a CertificateStatus message. (This is used on
1397
+ // both the client and server sides.)
1398
+ bool certificate_status_expected:1;
1076
1399
 
1077
- /* accept_psk_mode stores whether the client's PSK mode is compatible with our
1078
- * preferences. */
1079
- unsigned accept_psk_mode:1;
1400
+ // ocsp_stapling_requested is true if a client requested OCSP stapling.
1401
+ bool ocsp_stapling_requested:1;
1080
1402
 
1081
- /* cert_request is one if a client certificate was requested and zero
1082
- * otherwise. */
1083
- unsigned cert_request:1;
1403
+ // should_ack_sni is used by a server and indicates that the SNI extension
1404
+ // should be echoed in the ServerHello.
1405
+ bool should_ack_sni:1;
1084
1406
 
1085
- /* certificate_status_expected is one if OCSP stapling was negotiated and the
1086
- * server is expected to send a CertificateStatus message. (This is used on
1087
- * both the client and server sides.) */
1088
- unsigned certificate_status_expected:1;
1407
+ // in_false_start is true if there is a pending client handshake in False
1408
+ // Start. The client may write data at this point.
1409
+ bool in_false_start:1;
1089
1410
 
1090
- /* ocsp_stapling_requested is one if a client requested OCSP stapling. */
1091
- unsigned ocsp_stapling_requested:1;
1411
+ // in_early_data is true if there is a pending handshake that has progressed
1412
+ // enough to send and receive early data.
1413
+ bool in_early_data:1;
1092
1414
 
1093
- /* should_ack_sni is used by a server and indicates that the SNI extension
1094
- * should be echoed in the ServerHello. */
1095
- unsigned should_ack_sni:1;
1415
+ // early_data_offered is true if the client sent the early_data extension.
1416
+ bool early_data_offered:1;
1096
1417
 
1097
- /* in_false_start is one if there is a pending client handshake in False
1098
- * Start. The client may write data at this point. */
1099
- unsigned in_false_start:1;
1418
+ // can_early_read is true if application data may be read at this point in the
1419
+ // handshake.
1420
+ bool can_early_read:1;
1100
1421
 
1101
- /* next_proto_neg_seen is one of NPN was negotiated. */
1102
- unsigned next_proto_neg_seen:1;
1422
+ // can_early_write is true if application data may be written at this point in
1423
+ // the handshake.
1424
+ bool can_early_write:1;
1103
1425
 
1104
- /* ticket_expected is one if a TLS 1.2 NewSessionTicket message is to be sent
1105
- * or received. */
1106
- unsigned ticket_expected:1;
1426
+ // next_proto_neg_seen is one of NPN was negotiated.
1427
+ bool next_proto_neg_seen:1;
1107
1428
 
1108
- /* v2_clienthello is one if we received a V2ClientHello. */
1109
- unsigned v2_clienthello:1;
1429
+ // ticket_expected is true if a TLS 1.2 NewSessionTicket message is to be sent
1430
+ // or received.
1431
+ bool ticket_expected:1;
1110
1432
 
1111
- /* extended_master_secret is one if the extended master secret extension is
1112
- * negotiated in this handshake. */
1113
- unsigned extended_master_secret:1;
1433
+ // extended_master_secret is true if the extended master secret extension is
1434
+ // negotiated in this handshake.
1435
+ bool extended_master_secret:1;
1114
1436
 
1115
- /* client_version is the value sent or received in the ClientHello version. */
1116
- uint16_t client_version;
1117
- } /* SSL_HANDSHAKE */;
1437
+ // pending_private_key_op is true if there is a pending private key operation
1438
+ // in progress.
1439
+ bool pending_private_key_op:1;
1440
+
1441
+ // client_version is the value sent or received in the ClientHello version.
1442
+ uint16_t client_version = 0;
1443
+
1444
+ // early_data_read is the amount of early data that has been read by the
1445
+ // record layer.
1446
+ uint16_t early_data_read = 0;
1447
+
1448
+ // early_data_written is the amount of early data that has been written by the
1449
+ // record layer.
1450
+ uint16_t early_data_written = 0;
1451
+ };
1118
1452
 
1119
1453
  SSL_HANDSHAKE *ssl_handshake_new(SSL *ssl);
1120
1454
 
1121
- /* ssl_handshake_free releases all memory associated with |hs|. */
1455
+ // ssl_handshake_free releases all memory associated with |hs|.
1122
1456
  void ssl_handshake_free(SSL_HANDSHAKE *hs);
1123
1457
 
1124
- /* ssl_check_message_type checks if the current message has type |type|. If so
1125
- * it returns one. Otherwise, it sends an alert and returns zero. */
1126
- int ssl_check_message_type(SSL *ssl, int type);
1458
+ // ssl_check_message_type checks if |msg| has type |type|. If so it returns
1459
+ // one. Otherwise, it sends an alert and returns zero.
1460
+ int ssl_check_message_type(SSL *ssl, const SSLMessage &msg, int type);
1127
1461
 
1128
- /* tls13_handshake runs the TLS 1.3 handshake. It returns one on success and <=
1129
- * 0 on error. */
1130
- int tls13_handshake(SSL_HANDSHAKE *hs);
1462
+ // ssl_run_handshake runs the TLS handshake. It returns one on success and <= 0
1463
+ // on error. It sets |out_early_return| to one if we've completed the handshake
1464
+ // early.
1465
+ int ssl_run_handshake(SSL_HANDSHAKE *hs, bool *out_early_return);
1131
1466
 
1132
- /* The following are implementations of |do_tls13_handshake| for the client and
1133
- * server. */
1467
+ // The following are implementations of |do_handshake| for the client and
1468
+ // server.
1469
+ enum ssl_hs_wait_t ssl_client_handshake(SSL_HANDSHAKE *hs);
1470
+ enum ssl_hs_wait_t ssl_server_handshake(SSL_HANDSHAKE *hs);
1134
1471
  enum ssl_hs_wait_t tls13_client_handshake(SSL_HANDSHAKE *hs);
1135
1472
  enum ssl_hs_wait_t tls13_server_handshake(SSL_HANDSHAKE *hs);
1136
1473
 
1137
- /* tls13_post_handshake processes a post-handshake message. It returns one on
1138
- * success and zero on failure. */
1139
- int tls13_post_handshake(SSL *ssl);
1474
+ // The following functions return human-readable representations of the TLS
1475
+ // handshake states for debugging.
1476
+ const char *ssl_client_handshake_state(SSL_HANDSHAKE *hs);
1477
+ const char *ssl_server_handshake_state(SSL_HANDSHAKE *hs);
1478
+ const char *tls13_client_handshake_state(SSL_HANDSHAKE *hs);
1479
+ const char *tls13_server_handshake_state(SSL_HANDSHAKE *hs);
1140
1480
 
1141
- int tls13_process_certificate(SSL_HANDSHAKE *hs, int allow_anonymous);
1142
- int tls13_process_certificate_verify(SSL_HANDSHAKE *hs);
1143
- int tls13_process_finished(SSL_HANDSHAKE *hs);
1481
+ // tls13_post_handshake processes a post-handshake message. It returns one on
1482
+ // success and zero on failure.
1483
+ int tls13_post_handshake(SSL *ssl, const SSLMessage &msg);
1484
+
1485
+ int tls13_process_certificate(SSL_HANDSHAKE *hs, const SSLMessage &msg,
1486
+ int allow_anonymous);
1487
+ int tls13_process_certificate_verify(SSL_HANDSHAKE *hs, const SSLMessage &msg);
1488
+
1489
+ // tls13_process_finished processes |msg| as a Finished message from the
1490
+ // peer. If |use_saved_value| is one, the verify_data is compared against
1491
+ // |hs->expected_client_finished| rather than computed fresh.
1492
+ int tls13_process_finished(SSL_HANDSHAKE *hs, const SSLMessage &msg,
1493
+ int use_saved_value);
1144
1494
 
1145
1495
  int tls13_add_certificate(SSL_HANDSHAKE *hs);
1146
- enum ssl_private_key_result_t tls13_add_certificate_verify(SSL_HANDSHAKE *hs,
1147
- int is_first_run);
1496
+
1497
+ // tls13_add_certificate_verify adds a TLS 1.3 CertificateVerify message to the
1498
+ // handshake. If it returns |ssl_private_key_retry|, it should be called again
1499
+ // to retry when the signing operation is completed.
1500
+ enum ssl_private_key_result_t tls13_add_certificate_verify(SSL_HANDSHAKE *hs);
1501
+
1148
1502
  int tls13_add_finished(SSL_HANDSHAKE *hs);
1149
- int tls13_process_new_session_ticket(SSL *ssl);
1503
+ int tls13_process_new_session_ticket(SSL *ssl, const SSLMessage &msg);
1150
1504
 
1151
- int ssl_ext_key_share_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t **out_secret,
1152
- size_t *out_secret_len,
1505
+ int ssl_ext_key_share_parse_serverhello(SSL_HANDSHAKE *hs,
1506
+ Array<uint8_t> *out_secret,
1153
1507
  uint8_t *out_alert, CBS *contents);
1154
- int ssl_ext_key_share_parse_clienthello(SSL_HANDSHAKE *hs, int *out_found,
1155
- uint8_t **out_secret,
1156
- size_t *out_secret_len,
1508
+ int ssl_ext_key_share_parse_clienthello(SSL_HANDSHAKE *hs, bool *out_found,
1509
+ Array<uint8_t> *out_secret,
1157
1510
  uint8_t *out_alert, CBS *contents);
1158
1511
  int ssl_ext_key_share_add_serverhello(SSL_HANDSHAKE *hs, CBB *out);
1159
1512
 
1160
1513
  int ssl_ext_pre_shared_key_parse_serverhello(SSL_HANDSHAKE *hs,
1161
1514
  uint8_t *out_alert, CBS *contents);
1162
- int ssl_ext_pre_shared_key_parse_clienthello(SSL_HANDSHAKE *hs,
1163
- SSL_SESSION **out_session,
1164
- CBS *out_binders,
1165
- uint8_t *out_alert, CBS *contents);
1515
+ int ssl_ext_pre_shared_key_parse_clienthello(
1516
+ SSL_HANDSHAKE *hs, CBS *out_ticket, CBS *out_binders,
1517
+ uint32_t *out_obfuscated_ticket_age, uint8_t *out_alert, CBS *contents);
1166
1518
  int ssl_ext_pre_shared_key_add_serverhello(SSL_HANDSHAKE *hs, CBB *out);
1167
1519
 
1168
- /* ssl_is_sct_list_valid does a shallow parse of the SCT list in |contents| and
1169
- * returns one iff it's valid. */
1520
+ // ssl_is_sct_list_valid does a shallow parse of the SCT list in |contents| and
1521
+ // returns one iff it's valid.
1170
1522
  int ssl_is_sct_list_valid(const CBS *contents);
1171
1523
 
1172
1524
  int ssl_write_client_hello(SSL_HANDSHAKE *hs);
1173
1525
 
1174
- /* ssl_clear_tls13_state releases client state only needed for TLS 1.3. It
1175
- * should be called once the version is known to be TLS 1.2 or earlier. */
1176
- void ssl_clear_tls13_state(SSL_HANDSHAKE *hs);
1177
-
1178
1526
  enum ssl_cert_verify_context_t {
1179
1527
  ssl_cert_verify_server,
1180
1528
  ssl_cert_verify_client,
1181
1529
  ssl_cert_verify_channel_id,
1182
1530
  };
1183
1531
 
1184
- /* tls13_get_cert_verify_signature_input generates the message to be signed for
1185
- * TLS 1.3's CertificateVerify message. |cert_verify_context| determines the
1186
- * type of signature. It sets |*out| and |*out_len| to a newly allocated buffer
1187
- * containing the result. The caller must free it with |OPENSSL_free| to release
1188
- * it. This function returns one on success and zero on failure. */
1532
+ // tls13_get_cert_verify_signature_input generates the message to be signed for
1533
+ // TLS 1.3's CertificateVerify message. |cert_verify_context| determines the
1534
+ // type of signature. It sets |*out| and |*out_len| to a newly allocated buffer
1535
+ // containing the result. The caller must free it with |OPENSSL_free| to release
1536
+ // it. This function returns one on success and zero on failure.
1189
1537
  int tls13_get_cert_verify_signature_input(
1190
1538
  SSL_HANDSHAKE *hs, uint8_t **out, size_t *out_len,
1191
1539
  enum ssl_cert_verify_context_t cert_verify_context);
1192
1540
 
1193
- /* ssl_negotiate_alpn negotiates the ALPN extension, if applicable. It returns
1194
- * one on successful negotiation or if nothing was negotiated. It returns zero
1195
- * and sets |*out_alert| to an alert on error. */
1541
+ // ssl_negotiate_alpn negotiates the ALPN extension, if applicable. It returns
1542
+ // one on successful negotiation or if nothing was negotiated. It returns zero
1543
+ // and sets |*out_alert| to an alert on error.
1196
1544
  int ssl_negotiate_alpn(SSL_HANDSHAKE *hs, uint8_t *out_alert,
1197
1545
  const SSL_CLIENT_HELLO *client_hello);
1198
1546
 
1199
- typedef struct {
1547
+ struct SSL_EXTENSION_TYPE {
1200
1548
  uint16_t type;
1201
- int *out_present;
1549
+ bool *out_present;
1202
1550
  CBS *out_data;
1203
- } SSL_EXTENSION_TYPE;
1551
+ };
1204
1552
 
1205
- /* ssl_parse_extensions parses a TLS extensions block out of |cbs| and advances
1206
- * it. It writes the parsed extensions to pointers denoted by |ext_types|. On
1207
- * success, it fills in the |out_present| and |out_data| fields and returns one.
1208
- * Otherwise, it sets |*out_alert| to an alert to send and returns zero. Unknown
1209
- * extensions are rejected unless |ignore_unknown| is 1. */
1553
+ // ssl_parse_extensions parses a TLS extensions block out of |cbs| and advances
1554
+ // it. It writes the parsed extensions to pointers denoted by |ext_types|. On
1555
+ // success, it fills in the |out_present| and |out_data| fields and returns one.
1556
+ // Otherwise, it sets |*out_alert| to an alert to send and returns zero. Unknown
1557
+ // extensions are rejected unless |ignore_unknown| is 1.
1210
1558
  int ssl_parse_extensions(const CBS *cbs, uint8_t *out_alert,
1211
1559
  const SSL_EXTENSION_TYPE *ext_types,
1212
1560
  size_t num_ext_types, int ignore_unknown);
1213
1561
 
1562
+ // ssl_verify_peer_cert verifies the peer certificate for |hs|.
1563
+ enum ssl_verify_result_t ssl_verify_peer_cert(SSL_HANDSHAKE *hs);
1214
1564
 
1215
- /* SSLKEYLOGFILE functions. */
1216
1565
 
1217
- /* ssl_log_secret logs |secret| with label |label|, if logging is enabled for
1218
- * |ssl|. It returns one on success and zero on failure. */
1566
+ // SSLKEYLOGFILE functions.
1567
+
1568
+ // ssl_log_secret logs |secret| with label |label|, if logging is enabled for
1569
+ // |ssl|. It returns one on success and zero on failure.
1219
1570
  int ssl_log_secret(const SSL *ssl, const char *label, const uint8_t *secret,
1220
1571
  size_t secret_len);
1221
1572
 
1222
1573
 
1223
- /* ClientHello functions. */
1574
+ // ClientHello functions.
1224
1575
 
1225
- int ssl_client_hello_init(SSL *ssl, SSL_CLIENT_HELLO *out, const uint8_t *in,
1226
- size_t in_len);
1576
+ int ssl_client_hello_init(SSL *ssl, SSL_CLIENT_HELLO *out,
1577
+ const SSLMessage &msg);
1227
1578
 
1228
1579
  int ssl_client_hello_get_extension(const SSL_CLIENT_HELLO *client_hello,
1229
1580
  CBS *out, uint16_t extension_type);
@@ -1232,7 +1583,7 @@ int ssl_client_cipher_list_contains_cipher(const SSL_CLIENT_HELLO *client_hello,
1232
1583
  uint16_t id);
1233
1584
 
1234
1585
 
1235
- /* GREASE. */
1586
+ // GREASE.
1236
1587
 
1237
1588
  enum ssl_grease_index_t {
1238
1589
  ssl_grease_cipher = 0,
@@ -1243,420 +1594,699 @@ enum ssl_grease_index_t {
1243
1594
  ssl_grease_ticket_extension,
1244
1595
  };
1245
1596
 
1246
- /* ssl_get_grease_value returns a GREASE value for |ssl|. For a given
1247
- * connection, the values for each index will be deterministic. This allows the
1248
- * same ClientHello be sent twice for a HelloRetryRequest or the same group be
1249
- * advertised in both supported_groups and key_shares. */
1597
+ // ssl_get_grease_value returns a GREASE value for |ssl|. For a given
1598
+ // connection, the values for each index will be deterministic. This allows the
1599
+ // same ClientHello be sent twice for a HelloRetryRequest or the same group be
1600
+ // advertised in both supported_groups and key_shares.
1250
1601
  uint16_t ssl_get_grease_value(const SSL *ssl, enum ssl_grease_index_t index);
1251
1602
 
1252
1603
 
1253
- /* Signature algorithms. */
1604
+ // Signature algorithms.
1254
1605
 
1255
- /* tls1_parse_peer_sigalgs parses |sigalgs| as the list of peer signature
1256
- * algorithms and saves them on |hs|. It returns one on success and zero on
1257
- * error. */
1606
+ // tls1_parse_peer_sigalgs parses |sigalgs| as the list of peer signature
1607
+ // algorithms and saves them on |hs|. It returns one on success and zero on
1608
+ // error.
1258
1609
  int tls1_parse_peer_sigalgs(SSL_HANDSHAKE *hs, const CBS *sigalgs);
1259
1610
 
1260
- /* tls1_choose_signature_algorithm sets |*out| to a signature algorithm for use
1261
- * with |hs|'s private key based on the peer's preferences and the algorithms
1262
- * supported. It returns one on success and zero on error. */
1611
+ // tls1_get_legacy_signature_algorithm sets |*out| to the signature algorithm
1612
+ // that should be used with |pkey| in TLS 1.1 and earlier. It returns one on
1613
+ // success and zero if |pkey| may not be used at those versions.
1614
+ int tls1_get_legacy_signature_algorithm(uint16_t *out, const EVP_PKEY *pkey);
1615
+
1616
+ // tls1_choose_signature_algorithm sets |*out| to a signature algorithm for use
1617
+ // with |hs|'s private key based on the peer's preferences and the algorithms
1618
+ // supported. It returns one on success and zero on error.
1263
1619
  int tls1_choose_signature_algorithm(SSL_HANDSHAKE *hs, uint16_t *out);
1264
1620
 
1265
- /* tls12_get_verify_sigalgs sets |*out| to the signature algorithms acceptable
1266
- * for the peer signature and returns the length of the list. */
1267
- size_t tls12_get_verify_sigalgs(const SSL *ssl, const uint16_t **out);
1621
+ // tls12_add_verify_sigalgs adds the signature algorithms acceptable for the
1622
+ // peer signature to |out|. It returns one on success and zero on error.
1623
+ int tls12_add_verify_sigalgs(const SSL *ssl, CBB *out);
1268
1624
 
1269
- /* tls12_check_peer_sigalg checks if |sigalg| is acceptable for the peer
1270
- * signature. It returns one on success and zero on error, setting |*out_alert|
1271
- * to an alert to send. */
1272
- int tls12_check_peer_sigalg(SSL *ssl, int *out_alert, uint16_t sigalg);
1625
+ // tls12_check_peer_sigalg checks if |sigalg| is acceptable for the peer
1626
+ // signature. It returns one on success and zero on error, setting |*out_alert|
1627
+ // to an alert to send.
1628
+ int tls12_check_peer_sigalg(SSL *ssl, uint8_t *out_alert, uint16_t sigalg);
1273
1629
 
1274
1630
 
1275
- /* Underdocumented functions.
1276
- *
1277
- * Functions below here haven't been touched up and may be underdocumented. */
1631
+ // Underdocumented functions.
1632
+ //
1633
+ // Functions below here haven't been touched up and may be underdocumented.
1278
1634
 
1279
1635
  #define TLSEXT_CHANNEL_ID_SIZE 128
1280
1636
 
1281
- /* From RFC4492, used in encoding the curve type in ECParameters */
1637
+ // From RFC4492, used in encoding the curve type in ECParameters
1282
1638
  #define NAMED_CURVE_TYPE 3
1283
1639
 
1284
- typedef struct cert_st {
1640
+ struct CERT {
1285
1641
  EVP_PKEY *privatekey;
1286
1642
 
1287
- /* chain contains the certificate chain, with the leaf at the beginning. The
1288
- * first element of |chain| may be NULL to indicate that the leaf certificate
1289
- * has not yet been set.
1290
- * If |chain| != NULL -> len(chain) >= 1
1291
- * If |chain[0]| == NULL -> len(chain) >= 2.
1292
- * |chain[1..]| != NULL */
1643
+ // chain contains the certificate chain, with the leaf at the beginning. The
1644
+ // first element of |chain| may be NULL to indicate that the leaf certificate
1645
+ // has not yet been set.
1646
+ // If |chain| != NULL -> len(chain) >= 1
1647
+ // If |chain[0]| == NULL -> len(chain) >= 2.
1648
+ // |chain[1..]| != NULL
1293
1649
  STACK_OF(CRYPTO_BUFFER) *chain;
1294
1650
 
1295
- /* x509_chain may contain a parsed copy of |chain[1..]|. This is only used as
1296
- * a cache in order to implement “get0” functions that return a non-owning
1297
- * pointer to the certificate chain. */
1651
+ // x509_chain may contain a parsed copy of |chain[1..]|. This is only used as
1652
+ // a cache in order to implement “get0” functions that return a non-owning
1653
+ // pointer to the certificate chain.
1298
1654
  STACK_OF(X509) *x509_chain;
1299
1655
 
1300
- /* x509_leaf may contain a parsed copy of the first element of |chain|. This
1301
- * is only used as a cache in order to implement “get0” functions that return
1302
- * a non-owning pointer to the certificate chain. */
1656
+ // x509_leaf may contain a parsed copy of the first element of |chain|. This
1657
+ // is only used as a cache in order to implement “get0” functions that return
1658
+ // a non-owning pointer to the certificate chain.
1303
1659
  X509 *x509_leaf;
1304
1660
 
1305
- /* x509_stash contains the last |X509| object append to the chain. This is a
1306
- * workaround for some third-party code that continue to use an |X509| object
1307
- * even after passing ownership with an “add0” function. */
1661
+ // x509_stash contains the last |X509| object append to the chain. This is a
1662
+ // workaround for some third-party code that continue to use an |X509| object
1663
+ // even after passing ownership with an “add0” function.
1308
1664
  X509 *x509_stash;
1309
1665
 
1310
- /* key_method, if non-NULL, is a set of callbacks to call for private key
1311
- * operations. */
1666
+ // key_method, if non-NULL, is a set of callbacks to call for private key
1667
+ // operations.
1312
1668
  const SSL_PRIVATE_KEY_METHOD *key_method;
1313
1669
 
1314
- /* x509_method contains pointers to functions that might deal with |X509|
1315
- * compatibility, or might be a no-op, depending on the application. */
1670
+ // x509_method contains pointers to functions that might deal with |X509|
1671
+ // compatibility, or might be a no-op, depending on the application.
1316
1672
  const SSL_X509_METHOD *x509_method;
1317
1673
 
1318
- DH *dh_tmp;
1319
- DH *(*dh_tmp_cb)(SSL *ssl, int is_export, int keysize);
1320
-
1321
- /* sigalgs, if non-NULL, is the set of signature algorithms supported by
1322
- * |privatekey| in decreasing order of preference. */
1674
+ // sigalgs, if non-NULL, is the set of signature algorithms supported by
1675
+ // |privatekey| in decreasing order of preference.
1323
1676
  uint16_t *sigalgs;
1324
1677
  size_t num_sigalgs;
1325
1678
 
1326
- /* Certificate setup callback: if set is called whenever a
1327
- * certificate may be required (client or server). the callback
1328
- * can then examine any appropriate parameters and setup any
1329
- * certificates required. This allows advanced applications
1330
- * to select certificates on the fly: for example based on
1331
- * supported signature algorithms or curves. */
1679
+ // Certificate setup callback: if set is called whenever a
1680
+ // certificate may be required (client or server). the callback
1681
+ // can then examine any appropriate parameters and setup any
1682
+ // certificates required. This allows advanced applications
1683
+ // to select certificates on the fly: for example based on
1684
+ // supported signature algorithms or curves.
1332
1685
  int (*cert_cb)(SSL *ssl, void *arg);
1333
1686
  void *cert_cb_arg;
1334
1687
 
1335
- /* Optional X509_STORE for certificate validation. If NULL the parent SSL_CTX
1336
- * store is used instead. */
1688
+ // Optional X509_STORE for certificate validation. If NULL the parent SSL_CTX
1689
+ // store is used instead.
1337
1690
  X509_STORE *verify_store;
1338
1691
 
1339
- /* Signed certificate timestamp list to be sent to the client, if requested */
1692
+ // Signed certificate timestamp list to be sent to the client, if requested
1340
1693
  CRYPTO_BUFFER *signed_cert_timestamp_list;
1341
1694
 
1342
- /* OCSP response to be sent to the client, if requested. */
1695
+ // OCSP response to be sent to the client, if requested.
1343
1696
  CRYPTO_BUFFER *ocsp_response;
1344
1697
 
1345
- /* sid_ctx partitions the session space within a shared session cache or
1346
- * ticket key. Only sessions with a matching value will be accepted. */
1698
+ // sid_ctx partitions the session space within a shared session cache or
1699
+ // ticket key. Only sessions with a matching value will be accepted.
1347
1700
  uint8_t sid_ctx_length;
1348
1701
  uint8_t sid_ctx[SSL_MAX_SID_CTX_LENGTH];
1349
- } CERT;
1350
1702
 
1351
- /* SSL_METHOD is a compatibility structure to support the legacy version-locked
1352
- * methods. */
1353
- struct ssl_method_st {
1354
- /* version, if non-zero, is the only protocol version acceptable to an
1355
- * SSL_CTX initialized from this method. */
1356
- uint16_t version;
1357
- /* method is the underlying SSL_PROTOCOL_METHOD that initializes the
1358
- * SSL_CTX. */
1359
- const SSL_PROTOCOL_METHOD *method;
1360
- /* x509_method contains pointers to functions that might deal with |X509|
1361
- * compatibility, or might be a no-op, depending on the application. */
1362
- const SSL_X509_METHOD *x509_method;
1703
+ // If enable_early_data is true, early data can be sent and accepted.
1704
+ bool enable_early_data:1;
1363
1705
  };
1364
1706
 
1365
- /* Used to hold functions for SSLv2 or SSLv3/TLSv1 functions */
1366
- struct ssl_protocol_method_st {
1367
- /* is_dtls is one if the protocol is DTLS and zero otherwise. */
1707
+ // |SSL_PROTOCOL_METHOD| abstracts between TLS and DTLS.
1708
+ struct SSL_PROTOCOL_METHOD {
1709
+ // is_dtls is one if the protocol is DTLS and zero otherwise.
1368
1710
  char is_dtls;
1369
- /* min_version is the minimum implemented version. */
1370
- uint16_t min_version;
1371
- /* max_version is the maximum implemented version. */
1372
- uint16_t max_version;
1373
- /* version_from_wire maps |wire_version| to a protocol version. On success, it
1374
- * sets |*out_version| to the result and returns one. If the version is
1375
- * unknown, it returns zero. */
1376
- int (*version_from_wire)(uint16_t *out_version, uint16_t wire_version);
1377
- /* version_to_wire maps |version| to the wire representation. It is an error
1378
- * to call it with an invalid version. */
1379
- uint16_t (*version_to_wire)(uint16_t version);
1380
1711
  int (*ssl_new)(SSL *ssl);
1381
1712
  void (*ssl_free)(SSL *ssl);
1382
- /* ssl_get_message reads the next handshake message. On success, it returns
1383
- * one and sets |ssl->s3->tmp.message_type|, |ssl->init_msg|, and
1384
- * |ssl->init_num|. Otherwise, it returns <= 0. */
1385
- int (*ssl_get_message)(SSL *ssl);
1386
- /* get_current_message sets |*out| to the current handshake message. This
1387
- * includes the protocol-specific message header. */
1388
- void (*get_current_message)(const SSL *ssl, CBS *out);
1389
- /* release_current_message is called to release the current handshake message.
1390
- * If |free_buffer| is one, buffers will also be released. */
1391
- void (*release_current_message)(SSL *ssl, int free_buffer);
1392
- /* read_app_data reads up to |len| bytes of application data into |buf|. On
1393
- * success, it returns the number of bytes read. Otherwise, it returns <= 0
1394
- * and sets |*out_got_handshake| to whether the failure was due to a
1395
- * post-handshake handshake message. If so, it fills in the current message as
1396
- * in |ssl_get_message|. */
1397
- int (*read_app_data)(SSL *ssl, int *out_got_handshake, uint8_t *buf, int len,
1713
+ // get_message sets |*out| to the current handshake message and returns true
1714
+ // if one has been received. It returns false if more input is needed.
1715
+ bool (*get_message)(SSL *ssl, SSLMessage *out);
1716
+ // read_message reads additional handshake data for |get_message|. On success,
1717
+ // it returns one. Otherwise, it returns <= 0.
1718
+ int (*read_message)(SSL *ssl);
1719
+ // next_message is called to release the current handshake message.
1720
+ void (*next_message)(SSL *ssl);
1721
+ // read_app_data reads up to |len| bytes of application data into |buf|. On
1722
+ // success, it returns the number of bytes read. Otherwise, it returns <= 0
1723
+ // and sets |*out_got_handshake| to whether the failure was due to a
1724
+ // post-handshake handshake message. If so, any handshake messages consumed
1725
+ // may be read with |get_message|.
1726
+ int (*read_app_data)(SSL *ssl, bool *out_got_handshake, uint8_t *buf, int len,
1398
1727
  int peek);
1399
1728
  int (*read_change_cipher_spec)(SSL *ssl);
1400
1729
  void (*read_close_notify)(SSL *ssl);
1401
- int (*write_app_data)(SSL *ssl, const uint8_t *buf, int len);
1730
+ int (*write_app_data)(SSL *ssl, bool *out_needs_handshake, const uint8_t *buf,
1731
+ int len);
1402
1732
  int (*dispatch_alert)(SSL *ssl);
1403
- /* supports_cipher returns one if |cipher| is supported by this protocol and
1404
- * zero otherwise. */
1733
+ // supports_cipher returns one if |cipher| is supported by this protocol and
1734
+ // zero otherwise.
1405
1735
  int (*supports_cipher)(const SSL_CIPHER *cipher);
1406
- /* init_message begins a new handshake message of type |type|. |cbb| is the
1407
- * root CBB to be passed into |finish_message|. |*body| is set to a child CBB
1408
- * the caller should write to. It returns one on success and zero on error. */
1736
+ // init_message begins a new handshake message of type |type|. |cbb| is the
1737
+ // root CBB to be passed into |finish_message|. |*body| is set to a child CBB
1738
+ // the caller should write to. It returns one on success and zero on error.
1409
1739
  int (*init_message)(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
1410
- /* finish_message finishes a handshake message. It sets |*out_msg| to a
1411
- * newly-allocated buffer with the serialized message. The caller must
1412
- * release it with |OPENSSL_free| when done. It returns one on success and
1413
- * zero on error. */
1414
- int (*finish_message)(SSL *ssl, CBB *cbb, uint8_t **out_msg, size_t *out_len);
1415
- /* add_message adds a handshake message to the pending flight. It returns one
1416
- * on success and zero on error. In either case, it takes ownership of |msg|
1417
- * and releases it with |OPENSSL_free| when done. */
1418
- int (*add_message)(SSL *ssl, uint8_t *msg, size_t len);
1419
- /* add_change_cipher_spec adds a ChangeCipherSpec record to the pending
1420
- * flight. It returns one on success and zero on error. */
1740
+ // finish_message finishes a handshake message. It sets |*out_msg| to the
1741
+ // serialized message. It returns one on success and zero on error.
1742
+ int (*finish_message)(SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
1743
+ // add_message adds a handshake message to the pending flight. It returns one
1744
+ // on success and zero on error.
1745
+ int (*add_message)(SSL *ssl, Array<uint8_t> msg);
1746
+ // add_change_cipher_spec adds a ChangeCipherSpec record to the pending
1747
+ // flight. It returns one on success and zero on error.
1421
1748
  int (*add_change_cipher_spec)(SSL *ssl);
1422
- /* add_alert adds an alert to the pending flight. It returns one on success
1423
- * and zero on error. */
1749
+ // add_alert adds an alert to the pending flight. It returns one on success
1750
+ // and zero on error.
1424
1751
  int (*add_alert)(SSL *ssl, uint8_t level, uint8_t desc);
1425
- /* flush_flight flushes the pending flight to the transport. It returns one on
1426
- * success and <= 0 on error. */
1752
+ // flush_flight flushes the pending flight to the transport. It returns one on
1753
+ // success and <= 0 on error.
1427
1754
  int (*flush_flight)(SSL *ssl);
1428
- /* expect_flight is called when the handshake expects a flight of messages from
1429
- * the peer. */
1430
- void (*expect_flight)(SSL *ssl);
1431
- /* received_flight is called when the handshake has received a flight of
1432
- * messages from the peer. */
1433
- void (*received_flight)(SSL *ssl);
1434
- /* set_read_state sets |ssl|'s read cipher state to |aead_ctx|. It takes
1435
- * ownership of |aead_ctx|. It returns one on success and zero if changing the
1436
- * read state is forbidden at this point. */
1437
- int (*set_read_state)(SSL *ssl, SSL_AEAD_CTX *aead_ctx);
1438
- /* set_write_state sets |ssl|'s write cipher state to |aead_ctx|. It takes
1439
- * ownership of |aead_ctx|. It returns one on success and zero if changing the
1440
- * write state is forbidden at this point. */
1441
- int (*set_write_state)(SSL *ssl, SSL_AEAD_CTX *aead_ctx);
1755
+ // on_handshake_complete is called when the handshake is complete.
1756
+ void (*on_handshake_complete)(SSL *ssl);
1757
+ // set_read_state sets |ssl|'s read cipher state to |aead_ctx|. It returns
1758
+ // one on success and zero if changing the read state is forbidden at this
1759
+ // point.
1760
+ int (*set_read_state)(SSL *ssl, UniquePtr<SSLAEADContext> aead_ctx);
1761
+ // set_write_state sets |ssl|'s write cipher state to |aead_ctx|. It returns
1762
+ // one on success and zero if changing the write state is forbidden at this
1763
+ // point.
1764
+ int (*set_write_state)(SSL *ssl, UniquePtr<SSLAEADContext> aead_ctx);
1442
1765
  };
1443
1766
 
1444
- struct ssl_x509_method_st {
1445
- /* cert_clear frees and NULLs all X509-related state. */
1446
- void (*cert_clear)(CERT *cert);
1447
- /* cert_flush_cached_chain drops any cached |X509|-based certificate chain
1448
- * from |cert|. */
1449
- void (*cert_flush_cached_chain)(CERT *cert);
1450
- /* cert_flush_cached_chain drops any cached |X509|-based leaf certificate
1451
- * from |cert|. */
1452
- void (*cert_flush_cached_leaf)(CERT *cert);
1453
-
1454
- /* session_cache_objects fills out |sess->x509_peer| and |sess->x509_chain|
1455
- * from |sess->certs| and erases |sess->x509_chain_without_leaf|. It returns
1456
- * one on success or zero on error. */
1457
- int (*session_cache_objects)(SSL_SESSION *session);
1458
- /* session_dup duplicates any needed fields from |session| to |new_session|.
1459
- * It returns one on success or zero on error. */
1460
- int (*session_dup)(SSL_SESSION *new_session, const SSL_SESSION *session);
1461
- /* session_clear frees any X509-related state from |session|. */
1462
- void (*session_clear)(SSL_SESSION *session);
1767
+ // ssl_crypto_x509_method provides the |SSL_X509_METHOD| functions using
1768
+ // crypto/x509.
1769
+ extern const SSL_X509_METHOD ssl_crypto_x509_method;
1770
+
1771
+ // ssl_noop_x509_method provides the |SSL_X509_METHOD| functions that avoid
1772
+ // crypto/x509.
1773
+ extern const SSL_X509_METHOD ssl_noop_x509_method;
1774
+
1775
+ // ssl_cipher_preference_list_st contains a list of SSL_CIPHERs with
1776
+ // equal-preference groups. For TLS clients, the groups are moot because the
1777
+ // server picks the cipher and groups cannot be expressed on the wire. However,
1778
+ // for servers, the equal-preference groups allow the client's preferences to
1779
+ // be partially respected. (This only has an effect with
1780
+ // SSL_OP_CIPHER_SERVER_PREFERENCE).
1781
+ //
1782
+ // The equal-preference groups are expressed by grouping SSL_CIPHERs together.
1783
+ // All elements of a group have the same priority: no ordering is expressed
1784
+ // within a group.
1785
+ //
1786
+ // The values in |ciphers| are in one-to-one correspondence with
1787
+ // |in_group_flags|. (That is, sk_SSL_CIPHER_num(ciphers) is the number of
1788
+ // bytes in |in_group_flags|.) The bytes in |in_group_flags| are either 1, to
1789
+ // indicate that the corresponding SSL_CIPHER is not the last element of a
1790
+ // group, or 0 to indicate that it is.
1791
+ //
1792
+ // For example, if |in_group_flags| contains all zeros then that indicates a
1793
+ // traditional, fully-ordered preference. Every SSL_CIPHER is the last element
1794
+ // of the group (i.e. they are all in a one-element group).
1795
+ //
1796
+ // For a more complex example, consider:
1797
+ // ciphers: A B C D E F
1798
+ // in_group_flags: 1 1 0 0 1 0
1799
+ //
1800
+ // That would express the following, order:
1801
+ //
1802
+ // A E
1803
+ // B -> D -> F
1804
+ // C
1805
+ struct ssl_cipher_preference_list_st {
1806
+ STACK_OF(SSL_CIPHER) *ciphers;
1807
+ uint8_t *in_group_flags;
1808
+ };
1809
+
1810
+ struct tlsext_ticket_key {
1811
+ static constexpr bool kAllowUniquePtr = true;
1812
+
1813
+ uint8_t name[SSL_TICKET_KEY_NAME_LEN];
1814
+ uint8_t hmac_key[16];
1815
+ uint8_t aes_key[16];
1816
+ // next_rotation_tv_sec is the time (in seconds from the epoch) when the
1817
+ // current key should be superseded by a new key, or the time when a previous
1818
+ // key should be dropped. If zero, then the key should not be automatically
1819
+ // rotated.
1820
+ uint64_t next_rotation_tv_sec;
1463
1821
  };
1464
1822
 
1465
- /* ssl_noop_x509_method is implements the |ssl_x509_method_st| functions by
1466
- * doing nothing. */
1467
- extern const struct ssl_x509_method_st ssl_noop_x509_method;
1823
+ // SSLContext backs the public |SSL_CTX| type. Due to compatibility constraints,
1824
+ // it is a base class for |ssl_ctx_st|.
1825
+ struct SSLContext {
1826
+ const SSL_PROTOCOL_METHOD *method;
1827
+ const SSL_X509_METHOD *x509_method;
1828
+
1829
+ // lock is used to protect various operations on this object.
1830
+ CRYPTO_MUTEX lock;
1468
1831
 
1469
- /* ssl_crypto_x509_method provides the |ssl_x509_method_st| functions using
1470
- * crypto/x509. */
1471
- extern const struct ssl_x509_method_st ssl_crypto_x509_method;
1832
+ // conf_max_version is the maximum acceptable protocol version configured by
1833
+ // |SSL_CTX_set_max_proto_version|. Note this version is normalized in DTLS
1834
+ // and is further constrainted by |SSL_OP_NO_*|.
1835
+ uint16_t conf_max_version;
1472
1836
 
1473
- typedef struct ssl3_record_st {
1474
- /* type is the record type. */
1837
+ // conf_min_version is the minimum acceptable protocol version configured by
1838
+ // |SSL_CTX_set_min_proto_version|. Note this version is normalized in DTLS
1839
+ // and is further constrainted by |SSL_OP_NO_*|.
1840
+ uint16_t conf_min_version;
1841
+
1842
+ // tls13_variant is the variant of TLS 1.3 we are using for this
1843
+ // configuration.
1844
+ enum tls13_variant_t tls13_variant;
1845
+
1846
+ struct ssl_cipher_preference_list_st *cipher_list;
1847
+
1848
+ X509_STORE *cert_store;
1849
+ LHASH_OF(SSL_SESSION) *sessions;
1850
+ // Most session-ids that will be cached, default is
1851
+ // SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited.
1852
+ unsigned long session_cache_size;
1853
+ SSL_SESSION *session_cache_head;
1854
+ SSL_SESSION *session_cache_tail;
1855
+
1856
+ // handshakes_since_cache_flush is the number of successful handshakes since
1857
+ // the last cache flush.
1858
+ int handshakes_since_cache_flush;
1859
+
1860
+ // This can have one of 2 values, ored together,
1861
+ // SSL_SESS_CACHE_CLIENT,
1862
+ // SSL_SESS_CACHE_SERVER,
1863
+ // Default is SSL_SESSION_CACHE_SERVER, which means only
1864
+ // SSL_accept which cache SSL_SESSIONS.
1865
+ int session_cache_mode;
1866
+
1867
+ // session_timeout is the default lifetime for new sessions in TLS 1.2 and
1868
+ // earlier, in seconds.
1869
+ uint32_t session_timeout;
1870
+
1871
+ // session_psk_dhe_timeout is the default lifetime for new sessions in TLS
1872
+ // 1.3, in seconds.
1873
+ uint32_t session_psk_dhe_timeout;
1874
+
1875
+ // If this callback is not null, it will be called each time a session id is
1876
+ // added to the cache. If this function returns 1, it means that the
1877
+ // callback will do a SSL_SESSION_free() when it has finished using it.
1878
+ // Otherwise, on 0, it means the callback has finished with it. If
1879
+ // remove_session_cb is not null, it will be called when a session-id is
1880
+ // removed from the cache. After the call, OpenSSL will SSL_SESSION_free()
1881
+ // it.
1882
+ int (*new_session_cb)(SSL *ssl, SSL_SESSION *sess);
1883
+ void (*remove_session_cb)(SSL_CTX *ctx, SSL_SESSION *sess);
1884
+ SSL_SESSION *(*get_session_cb)(SSL *ssl, const uint8_t *data, int len,
1885
+ int *copy);
1886
+ SSL_SESSION *(*get_session_cb_legacy)(SSL *ssl, uint8_t *data, int len,
1887
+ int *copy);
1888
+
1889
+ CRYPTO_refcount_t references;
1890
+
1891
+ // if defined, these override the X509_verify_cert() calls
1892
+ int (*app_verify_callback)(X509_STORE_CTX *store_ctx, void *arg);
1893
+ void *app_verify_arg;
1894
+
1895
+ enum ssl_verify_result_t (*custom_verify_callback)(SSL *ssl,
1896
+ uint8_t *out_alert);
1897
+
1898
+ // Default password callback.
1899
+ pem_password_cb *default_passwd_callback;
1900
+
1901
+ // Default password callback user data.
1902
+ void *default_passwd_callback_userdata;
1903
+
1904
+ // get client cert callback
1905
+ int (*client_cert_cb)(SSL *ssl, X509 **out_x509, EVP_PKEY **out_pkey);
1906
+
1907
+ // get channel id callback
1908
+ void (*channel_id_cb)(SSL *ssl, EVP_PKEY **out_pkey);
1909
+
1910
+ CRYPTO_EX_DATA ex_data;
1911
+
1912
+ // custom_*_extensions stores any callback sets for custom extensions. Note
1913
+ // that these pointers will be NULL if the stack would otherwise be empty.
1914
+ STACK_OF(SSL_CUSTOM_EXTENSION) *client_custom_extensions;
1915
+ STACK_OF(SSL_CUSTOM_EXTENSION) *server_custom_extensions;
1916
+
1917
+ // Default values used when no per-SSL value is defined follow
1918
+
1919
+ void (*info_callback)(const SSL *ssl, int type, int value);
1920
+
1921
+ // what we put in client cert requests
1922
+ STACK_OF(CRYPTO_BUFFER) *client_CA;
1923
+
1924
+ // cached_x509_client_CA is a cache of parsed versions of the elements of
1925
+ // |client_CA|.
1926
+ STACK_OF(X509_NAME) *cached_x509_client_CA;
1927
+
1928
+
1929
+ // Default values to use in SSL structures follow (these are copied by
1930
+ // SSL_new)
1931
+
1932
+ uint32_t options;
1933
+ uint32_t mode;
1934
+ uint32_t max_cert_list;
1935
+
1936
+ CERT *cert;
1937
+
1938
+ // callback that allows applications to peek at protocol messages
1939
+ void (*msg_callback)(int write_p, int version, int content_type,
1940
+ const void *buf, size_t len, SSL *ssl, void *arg);
1941
+ void *msg_callback_arg;
1942
+
1943
+ int verify_mode;
1944
+ int (*default_verify_callback)(
1945
+ int ok, X509_STORE_CTX *ctx); // called 'verify_callback' in the SSL
1946
+
1947
+ X509_VERIFY_PARAM *param;
1948
+
1949
+ // select_certificate_cb is called before most ClientHello processing and
1950
+ // before the decision whether to resume a session is made. See
1951
+ // |ssl_select_cert_result_t| for details of the return values.
1952
+ enum ssl_select_cert_result_t (*select_certificate_cb)(
1953
+ const SSL_CLIENT_HELLO *);
1954
+
1955
+ // dos_protection_cb is called once the resumption decision for a ClientHello
1956
+ // has been made. It returns one to continue the handshake or zero to
1957
+ // abort.
1958
+ int (*dos_protection_cb) (const SSL_CLIENT_HELLO *);
1959
+
1960
+ // Maximum amount of data to send in one fragment. actual record size can be
1961
+ // more than this due to padding and MAC overheads.
1962
+ uint16_t max_send_fragment;
1963
+
1964
+ // TLS extensions servername callback
1965
+ int (*tlsext_servername_callback)(SSL *, int *, void *);
1966
+ void *tlsext_servername_arg;
1967
+
1968
+ // RFC 4507 session ticket keys. |tlsext_ticket_key_current| may be NULL
1969
+ // before the first handshake and |tlsext_ticket_key_prev| may be NULL at any
1970
+ // time. Automatically generated ticket keys are rotated as needed at
1971
+ // handshake time. Hence, all access must be synchronized through |lock|.
1972
+ struct tlsext_ticket_key *tlsext_ticket_key_current;
1973
+ struct tlsext_ticket_key *tlsext_ticket_key_prev;
1974
+
1975
+ // Callback to support customisation of ticket key setting
1976
+ int (*tlsext_ticket_key_cb)(SSL *ssl, uint8_t *name, uint8_t *iv,
1977
+ EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc);
1978
+
1979
+ // Server-only: psk_identity_hint is the default identity hint to send in
1980
+ // PSK-based key exchanges.
1981
+ char *psk_identity_hint;
1982
+
1983
+ unsigned int (*psk_client_callback)(SSL *ssl, const char *hint,
1984
+ char *identity,
1985
+ unsigned int max_identity_len,
1986
+ uint8_t *psk, unsigned int max_psk_len);
1987
+ unsigned int (*psk_server_callback)(SSL *ssl, const char *identity,
1988
+ uint8_t *psk, unsigned int max_psk_len);
1989
+
1990
+
1991
+ // retain_only_sha256_of_client_certs is true if we should compute the SHA256
1992
+ // hash of the peer's certificate and then discard it to save memory and
1993
+ // session space. Only effective on the server side.
1994
+ char retain_only_sha256_of_client_certs;
1995
+
1996
+ // Next protocol negotiation information
1997
+ // (for experimental NPN extension).
1998
+
1999
+ // For a server, this contains a callback function by which the set of
2000
+ // advertised protocols can be provided.
2001
+ int (*next_protos_advertised_cb)(SSL *ssl, const uint8_t **out,
2002
+ unsigned *out_len, void *arg);
2003
+ void *next_protos_advertised_cb_arg;
2004
+ // For a client, this contains a callback function that selects the
2005
+ // next protocol from the list provided by the server.
2006
+ int (*next_proto_select_cb)(SSL *ssl, uint8_t **out, uint8_t *out_len,
2007
+ const uint8_t *in, unsigned in_len, void *arg);
2008
+ void *next_proto_select_cb_arg;
2009
+
2010
+ // ALPN information
2011
+ // (we are in the process of transitioning from NPN to ALPN.)
2012
+
2013
+ // For a server, this contains a callback function that allows the
2014
+ // server to select the protocol for the connection.
2015
+ // out: on successful return, this must point to the raw protocol
2016
+ // name (without the length prefix).
2017
+ // outlen: on successful return, this contains the length of |*out|.
2018
+ // in: points to the client's list of supported protocols in
2019
+ // wire-format.
2020
+ // inlen: the length of |in|.
2021
+ int (*alpn_select_cb)(SSL *ssl, const uint8_t **out, uint8_t *out_len,
2022
+ const uint8_t *in, unsigned in_len, void *arg);
2023
+ void *alpn_select_cb_arg;
2024
+
2025
+ // For a client, this contains the list of supported protocols in wire
2026
+ // format.
2027
+ uint8_t *alpn_client_proto_list;
2028
+ unsigned alpn_client_proto_list_len;
2029
+
2030
+ // SRTP profiles we are willing to do from RFC 5764
2031
+ STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
2032
+
2033
+ // Supported group values inherited by SSL structure
2034
+ size_t supported_group_list_len;
2035
+ uint16_t *supported_group_list;
2036
+
2037
+ // The client's Channel ID private key.
2038
+ EVP_PKEY *tlsext_channel_id_private;
2039
+
2040
+ // keylog_callback, if not NULL, is the key logging callback. See
2041
+ // |SSL_CTX_set_keylog_callback|.
2042
+ void (*keylog_callback)(const SSL *ssl, const char *line);
2043
+
2044
+ // current_time_cb, if not NULL, is the function to use to get the current
2045
+ // time. It sets |*out_clock| to the current time. The |ssl| argument is
2046
+ // always NULL. See |SSL_CTX_set_current_time_cb|.
2047
+ void (*current_time_cb)(const SSL *ssl, struct timeval *out_clock);
2048
+
2049
+ // pool is used for all |CRYPTO_BUFFER|s in case we wish to share certificate
2050
+ // memory.
2051
+ CRYPTO_BUFFER_POOL *pool;
2052
+
2053
+ // ticket_aead_method contains function pointers for opening and sealing
2054
+ // session tickets.
2055
+ const SSL_TICKET_AEAD_METHOD *ticket_aead_method;
2056
+
2057
+ // verify_sigalgs, if not empty, is the set of signature algorithms
2058
+ // accepted from the peer in decreasing order of preference.
2059
+ uint16_t *verify_sigalgs;
2060
+ size_t num_verify_sigalgs;
2061
+
2062
+ // quiet_shutdown is true if the connection should not send a close_notify on
2063
+ // shutdown.
2064
+ unsigned quiet_shutdown:1;
2065
+
2066
+ // ocsp_stapling_enabled is only used by client connections and indicates
2067
+ // whether OCSP stapling will be requested.
2068
+ unsigned ocsp_stapling_enabled:1;
2069
+
2070
+ // If true, a client will request certificate timestamps.
2071
+ unsigned signed_cert_timestamps_enabled:1;
2072
+
2073
+ // tlsext_channel_id_enabled is one if Channel ID is enabled and zero
2074
+ // otherwise. For a server, means that we'll accept Channel IDs from clients.
2075
+ // For a client, means that we'll advertise support.
2076
+ unsigned tlsext_channel_id_enabled:1;
2077
+
2078
+ // grease_enabled is one if draft-davidben-tls-grease-01 is enabled and zero
2079
+ // otherwise.
2080
+ unsigned grease_enabled:1;
2081
+
2082
+ // allow_unknown_alpn_protos is one if the client allows unsolicited ALPN
2083
+ // protocols from the peer.
2084
+ unsigned allow_unknown_alpn_protos:1;
2085
+
2086
+ // ed25519_enabled is one if Ed25519 is advertised in the handshake.
2087
+ unsigned ed25519_enabled:1;
2088
+ };
2089
+
2090
+ struct SSL3_RECORD {
2091
+ // type is the record type.
1475
2092
  uint8_t type;
1476
- /* length is the number of unconsumed bytes in the record. */
2093
+ // length is the number of unconsumed bytes in the record.
1477
2094
  uint16_t length;
1478
- /* data is a non-owning pointer to the first unconsumed byte of the record. */
2095
+ // data is a non-owning pointer to the first unconsumed byte of the record.
1479
2096
  uint8_t *data;
1480
- } SSL3_RECORD;
2097
+ };
1481
2098
 
1482
- typedef struct ssl3_buffer_st {
1483
- /* buf is the memory allocated for this buffer. */
2099
+ struct SSL3_BUFFER {
2100
+ // buf is the memory allocated for this buffer.
1484
2101
  uint8_t *buf;
1485
- /* offset is the offset into |buf| which the buffer contents start at. */
2102
+ // offset is the offset into |buf| which the buffer contents start at.
1486
2103
  uint16_t offset;
1487
- /* len is the length of the buffer contents from |buf| + |offset|. */
2104
+ // len is the length of the buffer contents from |buf| + |offset|.
1488
2105
  uint16_t len;
1489
- /* cap is how much memory beyond |buf| + |offset| is available. */
2106
+ // cap is how much memory beyond |buf| + |offset| is available.
1490
2107
  uint16_t cap;
1491
- } SSL3_BUFFER;
2108
+ };
1492
2109
 
1493
- /* An ssl_shutdown_t describes the shutdown state of one end of the connection,
1494
- * whether it is alive or has been shutdown via close_notify or fatal alert. */
2110
+ // An ssl_shutdown_t describes the shutdown state of one end of the connection,
2111
+ // whether it is alive or has been shutdown via close_notify or fatal alert.
1495
2112
  enum ssl_shutdown_t {
1496
2113
  ssl_shutdown_none = 0,
1497
2114
  ssl_shutdown_close_notify = 1,
1498
2115
  ssl_shutdown_fatal_alert = 2,
1499
2116
  };
1500
2117
 
1501
- typedef struct ssl3_state_st {
2118
+ struct SSL3_STATE {
1502
2119
  uint8_t read_sequence[8];
1503
2120
  uint8_t write_sequence[8];
1504
2121
 
1505
2122
  uint8_t server_random[SSL3_RANDOM_SIZE];
1506
2123
  uint8_t client_random[SSL3_RANDOM_SIZE];
1507
2124
 
1508
- /* read_buffer holds data from the transport to be processed. */
2125
+ // read_buffer holds data from the transport to be processed.
1509
2126
  SSL3_BUFFER read_buffer;
1510
- /* write_buffer holds data to be written to the transport. */
2127
+ // write_buffer holds data to be written to the transport.
1511
2128
  SSL3_BUFFER write_buffer;
1512
2129
 
1513
- SSL3_RECORD rrec; /* each decoded record goes in here */
2130
+ SSL3_RECORD rrec; // each decoded record goes in here
1514
2131
 
1515
- /* partial write - check the numbers match */
1516
- unsigned int wnum; /* number of bytes sent so far */
1517
- int wpend_tot; /* number bytes written */
2132
+ // partial write - check the numbers match
2133
+ unsigned int wnum; // number of bytes sent so far
2134
+ int wpend_tot; // number bytes written
1518
2135
  int wpend_type;
1519
- int wpend_ret; /* number of bytes submitted */
2136
+ int wpend_ret; // number of bytes submitted
1520
2137
  const uint8_t *wpend_buf;
1521
2138
 
1522
- /* recv_shutdown is the shutdown state for the receive half of the
1523
- * connection. */
1524
- enum ssl_shutdown_t recv_shutdown;
2139
+ // read_shutdown is the shutdown state for the read half of the connection.
2140
+ enum ssl_shutdown_t read_shutdown;
1525
2141
 
1526
- /* recv_shutdown is the shutdown state for the send half of the connection. */
1527
- enum ssl_shutdown_t send_shutdown;
2142
+ // write_shutdown is the shutdown state for the write half of the connection.
2143
+ enum ssl_shutdown_t write_shutdown;
1528
2144
 
1529
2145
  int alert_dispatch;
1530
2146
 
1531
2147
  int total_renegotiations;
1532
2148
 
1533
- /* early_data_skipped is the amount of early data that has been skipped by the
1534
- * record layer. */
2149
+ // early_data_skipped is the amount of early data that has been skipped by the
2150
+ // record layer.
1535
2151
  uint16_t early_data_skipped;
1536
2152
 
1537
- /* empty_record_count is the number of consecutive empty records received. */
2153
+ // empty_record_count is the number of consecutive empty records received.
1538
2154
  uint8_t empty_record_count;
1539
2155
 
1540
- /* warning_alert_count is the number of consecutive warning alerts
1541
- * received. */
2156
+ // warning_alert_count is the number of consecutive warning alerts
2157
+ // received.
1542
2158
  uint8_t warning_alert_count;
1543
2159
 
1544
- /* key_update_count is the number of consecutive KeyUpdates received. */
2160
+ // key_update_count is the number of consecutive KeyUpdates received.
1545
2161
  uint8_t key_update_count;
1546
2162
 
1547
- /* skip_early_data instructs the record layer to skip unexpected early data
1548
- * messages when 0RTT is rejected. */
1549
- unsigned skip_early_data:1;
2163
+ // skip_early_data instructs the record layer to skip unexpected early data
2164
+ // messages when 0RTT is rejected.
2165
+ bool skip_early_data:1;
2166
+
2167
+ // have_version is true if the connection's final version is known. Otherwise
2168
+ // the version has not been negotiated yet.
2169
+ bool have_version:1;
2170
+
2171
+ // v2_hello_done is true if the peer's V2ClientHello, if any, has been handled
2172
+ // and future messages should use the record layer.
2173
+ bool v2_hello_done:1;
1550
2174
 
1551
- /* have_version is true if the connection's final version is known. Otherwise
1552
- * the version has not been negotiated yet. */
1553
- unsigned have_version:1;
2175
+ // is_v2_hello is true if the current handshake message was derived from a
2176
+ // V2ClientHello rather than received from the peer directly.
2177
+ bool is_v2_hello:1;
1554
2178
 
1555
- /* v2_hello_done is true if the peer's V2ClientHello, if any, has been handled
1556
- * and future messages should use the record layer. */
1557
- unsigned v2_hello_done:1;
2179
+ // has_message is true if the current handshake message has been returned
2180
+ // at least once by |get_message| and false otherwise.
2181
+ bool has_message:1;
1558
2182
 
1559
- /* is_v2_hello is true if the current handshake message was derived from a
1560
- * V2ClientHello rather than received from the peer directly. */
1561
- unsigned is_v2_hello:1;
2183
+ // initial_handshake_complete is true if the initial handshake has
2184
+ // completed.
2185
+ bool initial_handshake_complete:1;
1562
2186
 
1563
- /* initial_handshake_complete is true if the initial handshake has
1564
- * completed. */
1565
- unsigned initial_handshake_complete:1;
2187
+ // session_reused indicates whether a session was resumed.
2188
+ bool session_reused:1;
1566
2189
 
1567
- /* session_reused indicates whether a session was resumed. */
1568
- unsigned session_reused:1;
2190
+ bool send_connection_binding:1;
1569
2191
 
1570
- unsigned send_connection_binding:1;
2192
+ // In a client, this means that the server supported Channel ID and that a
2193
+ // Channel ID was sent. In a server it means that we echoed support for
2194
+ // Channel IDs and that tlsext_channel_id will be valid after the
2195
+ // handshake.
2196
+ bool tlsext_channel_id_valid:1;
1571
2197
 
1572
- /* In a client, this means that the server supported Channel ID and that a
1573
- * Channel ID was sent. In a server it means that we echoed support for
1574
- * Channel IDs and that tlsext_channel_id will be valid after the
1575
- * handshake. */
1576
- unsigned tlsext_channel_id_valid:1;
2198
+ // key_update_pending is true if we have a KeyUpdate acknowledgment
2199
+ // outstanding.
2200
+ bool key_update_pending:1;
1577
2201
 
1578
- /* short_header is one if https://github.com/tlswg/tls13-spec/pull/762 has
1579
- * been negotiated. */
1580
- unsigned short_header:1;
2202
+ // wpend_pending is true if we have a pending write outstanding.
2203
+ bool wpend_pending:1;
1581
2204
 
1582
2205
  uint8_t send_alert[2];
1583
2206
 
1584
- /* pending_flight is the pending outgoing flight. This is used to flush each
1585
- * handshake flight in a single write. */
2207
+ // pending_flight is the pending outgoing flight. This is used to flush each
2208
+ // handshake flight in a single write. |write_buffer| must be written out
2209
+ // before this data.
1586
2210
  BUF_MEM *pending_flight;
1587
2211
 
1588
- /* pending_flight_offset is the number of bytes of |pending_flight| which have
1589
- * been successfully written. */
2212
+ // pending_flight_offset is the number of bytes of |pending_flight| which have
2213
+ // been successfully written.
1590
2214
  uint32_t pending_flight_offset;
1591
2215
 
1592
- /* aead_read_ctx is the current read cipher state. */
1593
- SSL_AEAD_CTX *aead_read_ctx;
2216
+ // aead_read_ctx is the current read cipher state.
2217
+ SSLAEADContext *aead_read_ctx;
1594
2218
 
1595
- /* aead_write_ctx is the current write cipher state. */
1596
- SSL_AEAD_CTX *aead_write_ctx;
2219
+ // aead_write_ctx is the current write cipher state.
2220
+ SSLAEADContext *aead_write_ctx;
1597
2221
 
1598
- /* hs is the handshake state for the current handshake or NULL if there isn't
1599
- * one. */
2222
+ // hs is the handshake state for the current handshake or NULL if there isn't
2223
+ // one.
1600
2224
  SSL_HANDSHAKE *hs;
1601
2225
 
1602
2226
  uint8_t write_traffic_secret[EVP_MAX_MD_SIZE];
1603
2227
  uint8_t read_traffic_secret[EVP_MAX_MD_SIZE];
1604
2228
  uint8_t exporter_secret[EVP_MAX_MD_SIZE];
2229
+ uint8_t early_exporter_secret[EVP_MAX_MD_SIZE];
1605
2230
  uint8_t write_traffic_secret_len;
1606
2231
  uint8_t read_traffic_secret_len;
1607
2232
  uint8_t exporter_secret_len;
2233
+ uint8_t early_exporter_secret_len;
1608
2234
 
1609
- /* Connection binding to prevent renegotiation attacks */
2235
+ // Connection binding to prevent renegotiation attacks
1610
2236
  uint8_t previous_client_finished[12];
1611
2237
  uint8_t previous_client_finished_len;
1612
2238
  uint8_t previous_server_finished_len;
1613
2239
  uint8_t previous_server_finished[12];
1614
2240
 
1615
- /* State pertaining to the pending handshake.
1616
- *
1617
- * TODO(davidben): Move everything not needed after the handshake completes to
1618
- * |hs| and remove this. */
2241
+ // State pertaining to the pending handshake.
2242
+ //
2243
+ // TODO(davidben): Move everything not needed after the handshake completes to
2244
+ // |hs| and remove this.
1619
2245
  struct {
1620
- int message_type;
1621
-
1622
- int reuse_message;
1623
-
1624
2246
  uint8_t new_mac_secret_len;
1625
2247
  uint8_t new_key_len;
1626
2248
  uint8_t new_fixed_iv_len;
1627
2249
  } tmp;
1628
2250
 
1629
- /* established_session is the session established by the connection. This
1630
- * session is only filled upon the completion of the handshake and is
1631
- * immutable. */
2251
+ // established_session is the session established by the connection. This
2252
+ // session is only filled upon the completion of the handshake and is
2253
+ // immutable.
1632
2254
  SSL_SESSION *established_session;
1633
2255
 
1634
- /* Next protocol negotiation. For the client, this is the protocol that we
1635
- * sent in NextProtocol and is set when handling ServerHello extensions.
1636
- *
1637
- * For a server, this is the client's selected_protocol from NextProtocol and
1638
- * is set when handling the NextProtocol message, before the Finished
1639
- * message. */
2256
+ // Next protocol negotiation. For the client, this is the protocol that we
2257
+ // sent in NextProtocol and is set when handling ServerHello extensions.
2258
+ //
2259
+ // For a server, this is the client's selected_protocol from NextProtocol and
2260
+ // is set when handling the NextProtocol message, before the Finished
2261
+ // message.
1640
2262
  uint8_t *next_proto_negotiated;
1641
2263
  size_t next_proto_negotiated_len;
1642
2264
 
1643
- /* ALPN information
1644
- * (we are in the process of transitioning from NPN to ALPN.) */
2265
+ // ALPN information
2266
+ // (we are in the process of transitioning from NPN to ALPN.)
1645
2267
 
1646
- /* In a server these point to the selected ALPN protocol after the
1647
- * ClientHello has been processed. In a client these contain the protocol
1648
- * that the server selected once the ServerHello has been processed. */
2268
+ // In a server these point to the selected ALPN protocol after the
2269
+ // ClientHello has been processed. In a client these contain the protocol
2270
+ // that the server selected once the ServerHello has been processed.
1649
2271
  uint8_t *alpn_selected;
1650
2272
  size_t alpn_selected_len;
1651
2273
 
1652
- /* For a server:
1653
- * If |tlsext_channel_id_valid| is true, then this contains the
1654
- * verified Channel ID from the client: a P256 point, (x,y), where
1655
- * each are big-endian values. */
2274
+ // hostname, on the server, is the value of the SNI extension.
2275
+ char *hostname;
2276
+
2277
+ // For a server:
2278
+ // If |tlsext_channel_id_valid| is true, then this contains the
2279
+ // verified Channel ID from the client: a P256 point, (x,y), where
2280
+ // each are big-endian values.
1656
2281
  uint8_t tlsext_channel_id[64];
1657
- } SSL3_STATE;
1658
2282
 
1659
- /* lengths of messages */
2283
+ // ticket_age_skew is the difference, in seconds, between the client-sent
2284
+ // ticket age and the server-computed value in TLS 1.3 server connections
2285
+ // which resumed a session.
2286
+ int32_t ticket_age_skew;
2287
+ };
2288
+
2289
+ // lengths of messages
1660
2290
  #define DTLS1_COOKIE_LENGTH 256
1661
2291
 
1662
2292
  #define DTLS1_RT_HEADER_LENGTH 13
@@ -1675,148 +2305,173 @@ struct hm_header_st {
1675
2305
  uint32_t frag_len;
1676
2306
  };
1677
2307
 
1678
- /* An hm_fragment is an incoming DTLS message, possibly not yet assembled. */
1679
- typedef struct hm_fragment_st {
1680
- /* type is the type of the message. */
2308
+ // An hm_fragment is an incoming DTLS message, possibly not yet assembled.
2309
+ struct hm_fragment {
2310
+ // type is the type of the message.
1681
2311
  uint8_t type;
1682
- /* seq is the sequence number of this message. */
2312
+ // seq is the sequence number of this message.
1683
2313
  uint16_t seq;
1684
- /* msg_len is the length of the message body. */
2314
+ // msg_len is the length of the message body.
1685
2315
  uint32_t msg_len;
1686
- /* data is a pointer to the message, including message header. It has length
1687
- * |DTLS1_HM_HEADER_LENGTH| + |msg_len|. */
2316
+ // data is a pointer to the message, including message header. It has length
2317
+ // |DTLS1_HM_HEADER_LENGTH| + |msg_len|.
1688
2318
  uint8_t *data;
1689
- /* reassembly is a bitmask of |msg_len| bits corresponding to which parts of
1690
- * the message have been received. It is NULL if the message is complete. */
2319
+ // reassembly is a bitmask of |msg_len| bits corresponding to which parts of
2320
+ // the message have been received. It is NULL if the message is complete.
1691
2321
  uint8_t *reassembly;
1692
- } hm_fragment;
2322
+ };
1693
2323
 
1694
- typedef struct dtls1_state_st {
1695
- /* send_cookie is true if we are resending the ClientHello
1696
- * with a cookie from a HelloVerifyRequest. */
1697
- unsigned int send_cookie;
2324
+ struct OPENSSL_timeval {
2325
+ uint64_t tv_sec;
2326
+ uint32_t tv_usec;
2327
+ };
2328
+
2329
+ struct DTLS1_STATE {
2330
+ // has_change_cipher_spec is true if we have received a ChangeCipherSpec from
2331
+ // the peer in this epoch.
2332
+ bool has_change_cipher_spec:1;
2333
+
2334
+ // outgoing_messages_complete is true if |outgoing_messages| has been
2335
+ // completed by an attempt to flush it. Future calls to |add_message| and
2336
+ // |add_change_cipher_spec| will start a new flight.
2337
+ bool outgoing_messages_complete:1;
2338
+
2339
+ // flight_has_reply is true if the current outgoing flight is complete and has
2340
+ // processed at least one message. This is used to detect whether we or the
2341
+ // peer sent the final flight.
2342
+ bool flight_has_reply:1;
1698
2343
 
1699
2344
  uint8_t cookie[DTLS1_COOKIE_LENGTH];
1700
2345
  size_t cookie_len;
1701
2346
 
1702
- /* The current data and handshake epoch. This is initially undefined, and
1703
- * starts at zero once the initial handshake is completed. */
2347
+ // The current data and handshake epoch. This is initially undefined, and
2348
+ // starts at zero once the initial handshake is completed.
1704
2349
  uint16_t r_epoch;
1705
2350
  uint16_t w_epoch;
1706
2351
 
1707
- /* records being received in the current epoch */
2352
+ // records being received in the current epoch
1708
2353
  DTLS1_BITMAP bitmap;
1709
2354
 
1710
2355
  uint16_t handshake_write_seq;
1711
2356
  uint16_t handshake_read_seq;
1712
2357
 
1713
- /* save last sequence number for retransmissions */
2358
+ // save last sequence number for retransmissions
1714
2359
  uint8_t last_write_sequence[8];
2360
+ SSLAEADContext *last_aead_write_ctx;
1715
2361
 
1716
- /* incoming_messages is a ring buffer of incoming handshake messages that have
1717
- * yet to be processed. The front of the ring buffer is message number
1718
- * |handshake_read_seq|, at position |handshake_read_seq| %
1719
- * |SSL_MAX_HANDSHAKE_FLIGHT|. */
2362
+ // incoming_messages is a ring buffer of incoming handshake messages that have
2363
+ // yet to be processed. The front of the ring buffer is message number
2364
+ // |handshake_read_seq|, at position |handshake_read_seq| %
2365
+ // |SSL_MAX_HANDSHAKE_FLIGHT|.
1720
2366
  hm_fragment *incoming_messages[SSL_MAX_HANDSHAKE_FLIGHT];
1721
2367
 
1722
- /* outgoing_messages is the queue of outgoing messages from the last handshake
1723
- * flight. */
2368
+ // outgoing_messages is the queue of outgoing messages from the last handshake
2369
+ // flight.
1724
2370
  DTLS_OUTGOING_MESSAGE outgoing_messages[SSL_MAX_HANDSHAKE_FLIGHT];
1725
2371
  uint8_t outgoing_messages_len;
1726
2372
 
1727
- /* outgoing_written is the number of outgoing messages that have been
1728
- * written. */
2373
+ // outgoing_written is the number of outgoing messages that have been
2374
+ // written.
1729
2375
  uint8_t outgoing_written;
1730
- /* outgoing_offset is the number of bytes of the next outgoing message have
1731
- * been written. */
2376
+ // outgoing_offset is the number of bytes of the next outgoing message have
2377
+ // been written.
1732
2378
  uint32_t outgoing_offset;
1733
2379
 
1734
- unsigned int mtu; /* max DTLS packet size */
2380
+ unsigned int mtu; // max DTLS packet size
1735
2381
 
1736
- /* num_timeouts is the number of times the retransmit timer has fired since
1737
- * the last time it was reset. */
2382
+ // num_timeouts is the number of times the retransmit timer has fired since
2383
+ // the last time it was reset.
1738
2384
  unsigned int num_timeouts;
1739
2385
 
1740
- /* Indicates when the last handshake msg or heartbeat sent will
1741
- * timeout. */
1742
- struct timeval next_timeout;
2386
+ // Indicates when the last handshake msg or heartbeat sent will
2387
+ // timeout.
2388
+ struct OPENSSL_timeval next_timeout;
1743
2389
 
1744
- /* timeout_duration_ms is the timeout duration in milliseconds. */
2390
+ // timeout_duration_ms is the timeout duration in milliseconds.
1745
2391
  unsigned timeout_duration_ms;
1746
- } DTLS1_STATE;
2392
+ };
1747
2393
 
1748
- struct ssl_st {
1749
- /* method is the method table corresponding to the current protocol (DTLS or
1750
- * TLS). */
2394
+ // SSLConnection backs the public |SSL| type. Due to compatibility constraints,
2395
+ // it is a base class for |ssl_st|.
2396
+ struct SSLConnection {
2397
+ // method is the method table corresponding to the current protocol (DTLS or
2398
+ // TLS).
1751
2399
  const SSL_PROTOCOL_METHOD *method;
1752
2400
 
1753
- /* version is the protocol version. */
1754
- int version;
2401
+ // version is the protocol version.
2402
+ uint16_t version;
1755
2403
 
1756
- /* max_version is the maximum acceptable protocol version. Note this version
1757
- * is normalized in DTLS. */
1758
- uint16_t max_version;
2404
+ // conf_max_version is the maximum acceptable protocol version configured by
2405
+ // |SSL_set_max_proto_version|. Note this version is normalized in DTLS and is
2406
+ // further constrainted by |SSL_OP_NO_*|.
2407
+ uint16_t conf_max_version;
1759
2408
 
1760
- /* min_version is the minimum acceptable protocol version. Note this version
1761
- * is normalized in DTLS. */
1762
- uint16_t min_version;
2409
+ // conf_min_version is the minimum acceptable protocol version configured by
2410
+ // |SSL_set_min_proto_version|. Note this version is normalized in DTLS and is
2411
+ // further constrainted by |SSL_OP_NO_*|.
2412
+ uint16_t conf_min_version;
1763
2413
 
1764
- uint16_t max_send_fragment;
2414
+ // tls13_variant is the variant of TLS 1.3 we are using for this
2415
+ // configuration.
2416
+ enum tls13_variant_t tls13_variant;
1765
2417
 
1766
- /* There are 2 BIO's even though they are normally both the same. This is so
1767
- * data can be read and written to different handlers */
2418
+ uint16_t max_send_fragment;
1768
2419
 
1769
- BIO *rbio; /* used by SSL_read */
1770
- BIO *wbio; /* used by SSL_write */
2420
+ // There are 2 BIO's even though they are normally both the same. This is so
2421
+ // data can be read and written to different handlers
1771
2422
 
1772
- int (*handshake_func)(SSL_HANDSHAKE *hs);
2423
+ BIO *rbio; // used by SSL_read
2424
+ BIO *wbio; // used by SSL_write
1773
2425
 
1774
- BUF_MEM *init_buf; /* buffer used during init */
2426
+ // do_handshake runs the handshake. On completion, it returns |ssl_hs_ok|.
2427
+ // Otherwise, it returns a value corresponding to what operation is needed to
2428
+ // progress.
2429
+ enum ssl_hs_wait_t (*do_handshake)(SSL_HANDSHAKE *hs);
1775
2430
 
1776
- /* init_msg is a pointer to the current handshake message body. */
1777
- const uint8_t *init_msg;
1778
- /* init_num is the length of the current handshake message body. */
1779
- uint32_t init_num;
2431
+ BUF_MEM *init_buf; // buffer used during init
1780
2432
 
1781
- struct ssl3_state_st *s3; /* SSLv3 variables */
1782
- struct dtls1_state_st *d1; /* DTLSv1 variables */
2433
+ SSL3_STATE *s3; // SSLv3 variables
2434
+ DTLS1_STATE *d1; // DTLSv1 variables
1783
2435
 
1784
- /* callback that allows applications to peek at protocol messages */
2436
+ // callback that allows applications to peek at protocol messages
1785
2437
  void (*msg_callback)(int write_p, int version, int content_type,
1786
2438
  const void *buf, size_t len, SSL *ssl, void *arg);
1787
2439
  void *msg_callback_arg;
1788
2440
 
1789
2441
  X509_VERIFY_PARAM *param;
1790
2442
 
1791
- /* crypto */
2443
+ // crypto
1792
2444
  struct ssl_cipher_preference_list_st *cipher_list;
1793
2445
 
1794
- /* session info */
2446
+ // session info
1795
2447
 
1796
- /* client cert? */
1797
- /* This is used to hold the server certificate used */
1798
- struct cert_st /* CERT */ *cert;
2448
+ // client cert?
2449
+ // This is used to hold the server certificate used
2450
+ CERT *cert;
1799
2451
 
1800
- /* This holds a variable that indicates what we were doing when a 0 or -1 is
1801
- * returned. This is needed for non-blocking IO so we know what request
1802
- * needs re-doing when in SSL_accept or SSL_connect */
2452
+ // This holds a variable that indicates what we were doing when a 0 or -1 is
2453
+ // returned. This is needed for non-blocking IO so we know what request
2454
+ // needs re-doing when in SSL_accept or SSL_connect
1803
2455
  int rwstate;
1804
2456
 
1805
- /* initial_timeout_duration_ms is the default DTLS timeout duration in
1806
- * milliseconds. It's used to initialize the timer any time it's restarted. */
2457
+ // initial_timeout_duration_ms is the default DTLS timeout duration in
2458
+ // milliseconds. It's used to initialize the timer any time it's restarted.
1807
2459
  unsigned initial_timeout_duration_ms;
1808
2460
 
1809
- /* session is the configured session to be offered by the client. This session
1810
- * is immutable. */
2461
+ // session is the configured session to be offered by the client. This session
2462
+ // is immutable.
1811
2463
  SSL_SESSION *session;
1812
2464
 
1813
2465
  int (*verify_callback)(int ok,
1814
- X509_STORE_CTX *ctx); /* fail if callback returns 0 */
2466
+ X509_STORE_CTX *ctx); // fail if callback returns 0
2467
+
2468
+ enum ssl_verify_result_t (*custom_verify_callback)(SSL *ssl,
2469
+ uint8_t *out_alert);
1815
2470
 
1816
2471
  void (*info_callback)(const SSL *ssl, int type, int value);
1817
2472
 
1818
- /* Server-only: psk_identity_hint is the identity hint to send in
1819
- * PSK-based key exchanges. */
2473
+ // Server-only: psk_identity_hint is the identity hint to send in
2474
+ // PSK-based key exchanges.
1820
2475
  char *psk_identity_hint;
1821
2476
 
1822
2477
  unsigned int (*psk_client_callback)(SSL *ssl, const char *hint,
@@ -1828,232 +2483,244 @@ struct ssl_st {
1828
2483
 
1829
2484
  SSL_CTX *ctx;
1830
2485
 
1831
- /* extra application data */
2486
+ // extra application data
1832
2487
  CRYPTO_EX_DATA ex_data;
1833
2488
 
1834
- /* for server side, keep the list of CA_dn we can use */
1835
- STACK_OF(X509_NAME) *client_CA;
2489
+ // for server side, keep the list of CA_dn we can use
2490
+ STACK_OF(CRYPTO_BUFFER) *client_CA;
1836
2491
 
1837
- uint32_t options; /* protocol behaviour */
1838
- uint32_t mode; /* API behaviour */
2492
+ // cached_x509_client_CA is a cache of parsed versions of the elements of
2493
+ // |client_CA|.
2494
+ STACK_OF(X509_NAME) *cached_x509_client_CA;
2495
+
2496
+ uint32_t options; // protocol behaviour
2497
+ uint32_t mode; // API behaviour
1839
2498
  uint32_t max_cert_list;
1840
2499
  char *tlsext_hostname;
1841
2500
  size_t supported_group_list_len;
1842
- uint16_t *supported_group_list; /* our list */
2501
+ uint16_t *supported_group_list; // our list
1843
2502
 
1844
- SSL_CTX *initial_ctx; /* initial ctx, used to store sessions */
2503
+ // session_ctx is the |SSL_CTX| used for the session cache and related
2504
+ // settings.
2505
+ SSL_CTX *session_ctx;
1845
2506
 
1846
- /* srtp_profiles is the list of configured SRTP protection profiles for
1847
- * DTLS-SRTP. */
2507
+ // srtp_profiles is the list of configured SRTP protection profiles for
2508
+ // DTLS-SRTP.
1848
2509
  STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
1849
2510
 
1850
- /* srtp_profile is the selected SRTP protection profile for
1851
- * DTLS-SRTP. */
2511
+ // srtp_profile is the selected SRTP protection profile for
2512
+ // DTLS-SRTP.
1852
2513
  const SRTP_PROTECTION_PROFILE *srtp_profile;
1853
2514
 
1854
- /* The client's Channel ID private key. */
2515
+ // The client's Channel ID private key.
1855
2516
  EVP_PKEY *tlsext_channel_id_private;
1856
2517
 
1857
- /* For a client, this contains the list of supported protocols in wire
1858
- * format. */
2518
+ // For a client, this contains the list of supported protocols in wire
2519
+ // format.
1859
2520
  uint8_t *alpn_client_proto_list;
1860
2521
  unsigned alpn_client_proto_list_len;
1861
2522
 
1862
- /* renegotiate_mode controls how peer renegotiation attempts are handled. */
2523
+ // renegotiate_mode controls how peer renegotiation attempts are handled.
1863
2524
  enum ssl_renegotiate_mode_t renegotiate_mode;
1864
2525
 
1865
- /* verify_mode is a bitmask of |SSL_VERIFY_*| values. */
2526
+ // verify_mode is a bitmask of |SSL_VERIFY_*| values.
1866
2527
  uint8_t verify_mode;
1867
2528
 
1868
- /* server is true iff the this SSL* is the server half. Note: before the SSL*
1869
- * is initialized by either SSL_set_accept_state or SSL_set_connect_state,
1870
- * the side is not determined. In this state, server is always false. */
2529
+ // server is true iff the this SSL* is the server half. Note: before the SSL*
2530
+ // is initialized by either SSL_set_accept_state or SSL_set_connect_state,
2531
+ // the side is not determined. In this state, server is always false.
1871
2532
  unsigned server:1;
1872
2533
 
1873
- /* quiet_shutdown is true if the connection should not send a close_notify on
1874
- * shutdown. */
2534
+ // quiet_shutdown is true if the connection should not send a close_notify on
2535
+ // shutdown.
1875
2536
  unsigned quiet_shutdown:1;
1876
2537
 
1877
- /* Enable signed certificate time stamps. Currently client only. */
2538
+ // Enable signed certificate time stamps. Currently client only.
1878
2539
  unsigned signed_cert_timestamps_enabled:1;
1879
2540
 
1880
- /* ocsp_stapling_enabled is only used by client connections and indicates
1881
- * whether OCSP stapling will be requested. */
2541
+ // ocsp_stapling_enabled is only used by client connections and indicates
2542
+ // whether OCSP stapling will be requested.
1882
2543
  unsigned ocsp_stapling_enabled:1;
1883
2544
 
1884
- /* tlsext_channel_id_enabled is copied from the |SSL_CTX|. For a server,
1885
- * means that we'll accept Channel IDs from clients. For a client, means that
1886
- * we'll advertise support. */
2545
+ // tlsext_channel_id_enabled is copied from the |SSL_CTX|. For a server,
2546
+ // means that we'll accept Channel IDs from clients. For a client, means that
2547
+ // we'll advertise support.
1887
2548
  unsigned tlsext_channel_id_enabled:1;
1888
2549
 
1889
- /* retain_only_sha256_of_client_certs is true if we should compute the SHA256
1890
- * hash of the peer's certificate and then discard it to save memory and
1891
- * session space. Only effective on the server side. */
2550
+ // retain_only_sha256_of_client_certs is true if we should compute the SHA256
2551
+ // hash of the peer's certificate and then discard it to save memory and
2552
+ // session space. Only effective on the server side.
1892
2553
  unsigned retain_only_sha256_of_client_certs:1;
2554
+
2555
+ // early_data_accepted is true if early data was accepted by the server.
2556
+ unsigned early_data_accepted:1;
1893
2557
  };
1894
2558
 
1895
- /* From draft-ietf-tls-tls13-18, used in determining PSK modes. */
2559
+ // From draft-ietf-tls-tls13-18, used in determining PSK modes.
1896
2560
  #define SSL_PSK_KE 0x0
1897
2561
  #define SSL_PSK_DHE_KE 0x1
1898
2562
 
1899
- /* From draft-ietf-tls-tls13-16, used in determining whether to respond with a
1900
- * KeyUpdate. */
2563
+ // From draft-ietf-tls-tls13-16, used in determining whether to respond with a
2564
+ // KeyUpdate.
1901
2565
  #define SSL_KEY_UPDATE_NOT_REQUESTED 0
1902
2566
  #define SSL_KEY_UPDATE_REQUESTED 1
1903
2567
 
2568
+ // kMaxEarlyDataAccepted is the advertised number of plaintext bytes of early
2569
+ // data that will be accepted. This value should be slightly below
2570
+ // kMaxEarlyDataSkipped in tls_record.c, which is measured in ciphertext.
2571
+ static const size_t kMaxEarlyDataAccepted = 14336;
2572
+
1904
2573
  CERT *ssl_cert_new(const SSL_X509_METHOD *x509_method);
1905
2574
  CERT *ssl_cert_dup(CERT *cert);
1906
- void ssl_cert_clear_certs(CERT *c);
1907
- void ssl_cert_free(CERT *c);
1908
- int ssl_set_cert(CERT *cert, CRYPTO_BUFFER *buffer);
2575
+ void ssl_cert_clear_certs(CERT *cert);
2576
+ void ssl_cert_free(CERT *cert);
2577
+ int ssl_set_cert(CERT *cert, UniquePtr<CRYPTO_BUFFER> buffer);
1909
2578
  int ssl_is_key_type_supported(int key_type);
1910
- /* ssl_compare_public_and_private_key returns one if |pubkey| is the public
1911
- * counterpart to |privkey|. Otherwise it returns zero and pushes a helpful
1912
- * message on the error queue. */
2579
+ // ssl_compare_public_and_private_key returns one if |pubkey| is the public
2580
+ // counterpart to |privkey|. Otherwise it returns zero and pushes a helpful
2581
+ // message on the error queue.
1913
2582
  int ssl_compare_public_and_private_key(const EVP_PKEY *pubkey,
1914
2583
  const EVP_PKEY *privkey);
1915
2584
  int ssl_cert_check_private_key(const CERT *cert, const EVP_PKEY *privkey);
1916
2585
  int ssl_get_new_session(SSL_HANDSHAKE *hs, int is_server);
1917
2586
  int ssl_encrypt_ticket(SSL *ssl, CBB *out, const SSL_SESSION *session);
2587
+ int ssl_ctx_rotate_ticket_encryption_key(SSL_CTX *ctx);
1918
2588
 
1919
- /* ssl_session_new returns a newly-allocated blank |SSL_SESSION| or NULL on
1920
- * error. */
1921
- SSL_SESSION *ssl_session_new(const SSL_X509_METHOD *x509_method);
2589
+ // ssl_session_new returns a newly-allocated blank |SSL_SESSION| or nullptr on
2590
+ // error.
2591
+ UniquePtr<SSL_SESSION> ssl_session_new(const SSL_X509_METHOD *x509_method);
1922
2592
 
1923
- /* SSL_SESSION_parse parses an |SSL_SESSION| from |cbs| and advances |cbs| over
1924
- * the parsed data. */
1925
- SSL_SESSION *SSL_SESSION_parse(CBS *cbs, const SSL_X509_METHOD *x509_method,
1926
- CRYPTO_BUFFER_POOL *pool);
2593
+ // SSL_SESSION_parse parses an |SSL_SESSION| from |cbs| and advances |cbs| over
2594
+ // the parsed data.
2595
+ UniquePtr<SSL_SESSION> SSL_SESSION_parse(CBS *cbs,
2596
+ const SSL_X509_METHOD *x509_method,
2597
+ CRYPTO_BUFFER_POOL *pool);
1927
2598
 
1928
- /* ssl_session_is_context_valid returns one if |session|'s session ID context
1929
- * matches the one set on |ssl| and zero otherwise. */
2599
+ // ssl_session_is_context_valid returns one if |session|'s session ID context
2600
+ // matches the one set on |ssl| and zero otherwise.
1930
2601
  int ssl_session_is_context_valid(const SSL *ssl, const SSL_SESSION *session);
1931
2602
 
1932
- /* ssl_session_is_time_valid returns one if |session| is still valid and zero if
1933
- * it has expired. */
2603
+ // ssl_session_is_time_valid returns one if |session| is still valid and zero if
2604
+ // it has expired.
1934
2605
  int ssl_session_is_time_valid(const SSL *ssl, const SSL_SESSION *session);
1935
2606
 
1936
- /* ssl_session_is_resumable returns one if |session| is resumable for |hs| and
1937
- * zero otherwise. */
2607
+ // ssl_session_is_resumable returns one if |session| is resumable for |hs| and
2608
+ // zero otherwise.
1938
2609
  int ssl_session_is_resumable(const SSL_HANDSHAKE *hs,
1939
2610
  const SSL_SESSION *session);
1940
2611
 
1941
- /* SSL_SESSION_get_digest returns the digest used in |session|. If the digest is
1942
- * invalid, it returns NULL. */
1943
- const EVP_MD *SSL_SESSION_get_digest(const SSL_SESSION *session,
1944
- const SSL *ssl);
1945
-
1946
- void ssl_set_session(SSL *ssl, SSL_SESSION *session);
2612
+ // ssl_session_protocol_version returns the protocol version associated with
2613
+ // |session|. Note that despite the name, this is not the same as
2614
+ // |SSL_SESSION_get_protocol_version|. The latter is based on upstream's name.
2615
+ uint16_t ssl_session_protocol_version(const SSL_SESSION *session);
1947
2616
 
1948
- enum ssl_session_result_t {
1949
- ssl_session_success,
1950
- ssl_session_error,
1951
- ssl_session_retry,
1952
- };
2617
+ // ssl_session_get_digest returns the digest used in |session|.
2618
+ const EVP_MD *ssl_session_get_digest(const SSL_SESSION *session);
1953
2619
 
1954
- /* ssl_get_prev_session looks up the previous session based on |client_hello|.
1955
- * On success, it sets |*out_session| to the session or NULL if none was found.
1956
- * If the session could not be looked up synchronously, it returns
1957
- * |ssl_session_retry| and should be called again. Otherwise, it returns
1958
- * |ssl_session_error|. */
1959
- enum ssl_session_result_t ssl_get_prev_session(
1960
- SSL *ssl, SSL_SESSION **out_session, int *out_tickets_supported,
1961
- int *out_renew_ticket, const SSL_CLIENT_HELLO *client_hello);
2620
+ void ssl_set_session(SSL *ssl, SSL_SESSION *session);
1962
2621
 
1963
- /* The following flags determine which parts of the session are duplicated. */
2622
+ // ssl_get_prev_session looks up the previous session based on |client_hello|.
2623
+ // On success, it sets |*out_session| to the session or nullptr if none was
2624
+ // found. If the session could not be looked up synchronously, it returns
2625
+ // |ssl_hs_pending_session| and should be called again. If a ticket could not be
2626
+ // decrypted immediately it returns |ssl_hs_pending_ticket| and should also
2627
+ // be called again. Otherwise, it returns |ssl_hs_error|.
2628
+ enum ssl_hs_wait_t ssl_get_prev_session(SSL *ssl,
2629
+ UniquePtr<SSL_SESSION> *out_session,
2630
+ bool *out_tickets_supported,
2631
+ bool *out_renew_ticket,
2632
+ const SSL_CLIENT_HELLO *client_hello);
2633
+
2634
+ // The following flags determine which parts of the session are duplicated.
1964
2635
  #define SSL_SESSION_DUP_AUTH_ONLY 0x0
1965
2636
  #define SSL_SESSION_INCLUDE_TICKET 0x1
1966
2637
  #define SSL_SESSION_INCLUDE_NONAUTH 0x2
1967
2638
  #define SSL_SESSION_DUP_ALL \
1968
2639
  (SSL_SESSION_INCLUDE_TICKET | SSL_SESSION_INCLUDE_NONAUTH)
1969
2640
 
1970
- /* SSL_SESSION_dup returns a newly-allocated |SSL_SESSION| with a copy of the
1971
- * fields in |session| or NULL on error. The new session is non-resumable and
1972
- * must be explicitly marked resumable once it has been filled in. */
1973
- OPENSSL_EXPORT SSL_SESSION *SSL_SESSION_dup(SSL_SESSION *session,
1974
- int dup_flags);
2641
+ // SSL_SESSION_dup returns a newly-allocated |SSL_SESSION| with a copy of the
2642
+ // fields in |session| or nullptr on error. The new session is non-resumable and
2643
+ // must be explicitly marked resumable once it has been filled in.
2644
+ OPENSSL_EXPORT UniquePtr<SSL_SESSION> SSL_SESSION_dup(SSL_SESSION *session,
2645
+ int dup_flags);
1975
2646
 
1976
- /* ssl_session_rebase_time updates |session|'s start time to the current time,
1977
- * adjusting the timeout so the expiration time is unchanged. */
2647
+ // ssl_session_rebase_time updates |session|'s start time to the current time,
2648
+ // adjusting the timeout so the expiration time is unchanged.
1978
2649
  void ssl_session_rebase_time(SSL *ssl, SSL_SESSION *session);
1979
2650
 
1980
- /* ssl_session_renew_timeout calls |ssl_session_rebase_time| and renews
1981
- * |session|'s timeout to |timeout| (measured from the current time). The
1982
- * renewal is clamped to the session's auth_timeout. */
1983
- void ssl_session_renew_timeout(SSL *ssl, SSL_SESSION *session, long timeout);
2651
+ // ssl_session_renew_timeout calls |ssl_session_rebase_time| and renews
2652
+ // |session|'s timeout to |timeout| (measured from the current time). The
2653
+ // renewal is clamped to the session's auth_timeout.
2654
+ void ssl_session_renew_timeout(SSL *ssl, SSL_SESSION *session,
2655
+ uint32_t timeout);
1984
2656
 
1985
2657
  void ssl_cipher_preference_list_free(
1986
2658
  struct ssl_cipher_preference_list_st *cipher_list);
1987
2659
 
1988
- /* ssl_get_cipher_preferences returns the cipher preference list for TLS 1.2 and
1989
- * below. */
2660
+ // ssl_get_cipher_preferences returns the cipher preference list for TLS 1.2 and
2661
+ // below.
1990
2662
  const struct ssl_cipher_preference_list_st *ssl_get_cipher_preferences(
1991
2663
  const SSL *ssl);
1992
2664
 
1993
- int ssl_verify_cert_chain(SSL *ssl, long *out_verify_result,
1994
- STACK_OF(X509) *cert_chain);
1995
2665
  void ssl_update_cache(SSL_HANDSHAKE *hs, int mode);
1996
2666
 
1997
- int ssl_verify_alarm_type(long type);
1998
-
1999
- int ssl3_get_finished(SSL_HANDSHAKE *hs);
2667
+ enum ssl_hs_wait_t ssl_get_finished(SSL_HANDSHAKE *hs);
2000
2668
  int ssl3_send_alert(SSL *ssl, int level, int desc);
2001
- int ssl3_get_message(SSL *ssl);
2002
- void ssl3_get_current_message(const SSL *ssl, CBS *out);
2003
- void ssl3_release_current_message(SSL *ssl, int free_buffer);
2669
+ bool ssl3_get_message(SSL *ssl, SSLMessage *out);
2670
+ int ssl3_read_message(SSL *ssl);
2671
+ void ssl3_next_message(SSL *ssl);
2004
2672
 
2005
2673
  int ssl3_send_finished(SSL_HANDSHAKE *hs);
2006
2674
  int ssl3_dispatch_alert(SSL *ssl);
2007
- int ssl3_read_app_data(SSL *ssl, int *out_got_handshake, uint8_t *buf, int len,
2675
+ int ssl3_read_app_data(SSL *ssl, bool *out_got_handshake, uint8_t *buf, int len,
2008
2676
  int peek);
2009
2677
  int ssl3_read_change_cipher_spec(SSL *ssl);
2010
2678
  void ssl3_read_close_notify(SSL *ssl);
2011
2679
  int ssl3_read_handshake_bytes(SSL *ssl, uint8_t *buf, int len);
2012
- int ssl3_write_app_data(SSL *ssl, const uint8_t *buf, int len);
2680
+ int ssl3_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *buf,
2681
+ int len);
2013
2682
  int ssl3_output_cert_chain(SSL *ssl);
2014
2683
 
2015
2684
  int ssl3_new(SSL *ssl);
2016
2685
  void ssl3_free(SSL *ssl);
2017
- int ssl3_accept(SSL_HANDSHAKE *hs);
2018
- int ssl3_connect(SSL_HANDSHAKE *hs);
2019
2686
 
2020
2687
  int ssl3_init_message(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
2021
- int ssl3_finish_message(SSL *ssl, CBB *cbb, uint8_t **out_msg, size_t *out_len);
2022
- int ssl3_add_message(SSL *ssl, uint8_t *msg, size_t len);
2688
+ int ssl3_finish_message(SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
2689
+ int ssl3_add_message(SSL *ssl, Array<uint8_t> msg);
2023
2690
  int ssl3_add_change_cipher_spec(SSL *ssl);
2024
2691
  int ssl3_add_alert(SSL *ssl, uint8_t level, uint8_t desc);
2025
2692
  int ssl3_flush_flight(SSL *ssl);
2026
2693
 
2027
2694
  int dtls1_init_message(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
2028
- int dtls1_finish_message(SSL *ssl, CBB *cbb, uint8_t **out_msg,
2029
- size_t *out_len);
2030
- int dtls1_add_message(SSL *ssl, uint8_t *msg, size_t len);
2695
+ int dtls1_finish_message(SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
2696
+ int dtls1_add_message(SSL *ssl, Array<uint8_t> msg);
2031
2697
  int dtls1_add_change_cipher_spec(SSL *ssl);
2032
2698
  int dtls1_add_alert(SSL *ssl, uint8_t level, uint8_t desc);
2033
2699
  int dtls1_flush_flight(SSL *ssl);
2034
2700
 
2035
- /* ssl_add_message_cbb finishes the handshake message in |cbb| and adds it to
2036
- * the pending flight. It returns one on success and zero on error. */
2701
+ // ssl_add_message_cbb finishes the handshake message in |cbb| and adds it to
2702
+ // the pending flight. It returns one on success and zero on error.
2037
2703
  int ssl_add_message_cbb(SSL *ssl, CBB *cbb);
2038
2704
 
2039
- /* ssl_hash_current_message incorporates the current handshake message into the
2040
- * handshake hash. It returns one on success and zero on allocation failure. */
2041
- int ssl_hash_current_message(SSL_HANDSHAKE *hs);
2705
+ // ssl_hash_message incorporates |msg| into the handshake hash. It returns one
2706
+ // on success and zero on allocation failure.
2707
+ bool ssl_hash_message(SSL_HANDSHAKE *hs, const SSLMessage &msg);
2042
2708
 
2043
- /* dtls1_get_record reads a new input record. On success, it places it in
2044
- * |ssl->s3->rrec| and returns one. Otherwise it returns <= 0 on error or if
2045
- * more data is needed. */
2709
+ // dtls1_get_record reads a new input record. On success, it places it in
2710
+ // |ssl->s3->rrec| and returns one. Otherwise it returns <= 0 on error or if
2711
+ // more data is needed.
2046
2712
  int dtls1_get_record(SSL *ssl);
2047
2713
 
2048
- int dtls1_read_app_data(SSL *ssl, int *out_got_handshake, uint8_t *buf, int len,
2049
- int peek);
2714
+ int dtls1_read_app_data(SSL *ssl, bool *out_got_handshake, uint8_t *buf,
2715
+ int len, int peek);
2050
2716
  int dtls1_read_change_cipher_spec(SSL *ssl);
2051
2717
  void dtls1_read_close_notify(SSL *ssl);
2052
2718
 
2053
- int dtls1_write_app_data(SSL *ssl, const uint8_t *buf, int len);
2719
+ int dtls1_write_app_data(SSL *ssl, bool *out_needs_handshake,
2720
+ const uint8_t *buf, int len);
2054
2721
 
2055
- /* dtls1_write_record sends a record. It returns one on success and <= 0 on
2056
- * error. */
2722
+ // dtls1_write_record sends a record. It returns one on success and <= 0 on
2723
+ // error.
2057
2724
  int dtls1_write_record(SSL *ssl, int type, const uint8_t *buf, size_t len,
2058
2725
  enum dtls1_use_epoch_t use_epoch);
2059
2726
 
@@ -2068,7 +2735,6 @@ int dtls1_handshake_write(SSL *ssl);
2068
2735
  void dtls1_start_timer(SSL *ssl);
2069
2736
  void dtls1_stop_timer(SSL *ssl);
2070
2737
  int dtls1_is_timer_expired(SSL *ssl);
2071
- void dtls1_double_timeout(SSL *ssl);
2072
2738
  unsigned int dtls1_min_mtu(void);
2073
2739
 
2074
2740
  int dtls1_new(SSL *ssl);
@@ -2076,47 +2742,45 @@ int dtls1_accept(SSL *ssl);
2076
2742
  int dtls1_connect(SSL *ssl);
2077
2743
  void dtls1_free(SSL *ssl);
2078
2744
 
2079
- int dtls1_get_message(SSL *ssl);
2080
- void dtls1_get_current_message(const SSL *ssl, CBS *out);
2081
- void dtls1_release_current_message(SSL *ssl, int free_buffer);
2745
+ bool dtls1_get_message(SSL *ssl, SSLMessage *out);
2746
+ int dtls1_read_message(SSL *ssl);
2747
+ void dtls1_next_message(SSL *ssl);
2082
2748
  int dtls1_dispatch_alert(SSL *ssl);
2083
2749
 
2084
- int tls1_change_cipher_state(SSL_HANDSHAKE *hs, int which);
2750
+ int tls1_change_cipher_state(SSL_HANDSHAKE *hs, evp_aead_direction_t direction);
2085
2751
  int tls1_generate_master_secret(SSL_HANDSHAKE *hs, uint8_t *out,
2086
2752
  const uint8_t *premaster, size_t premaster_len);
2087
2753
 
2088
- /* tls1_get_grouplist sets |*out_group_ids| and |*out_group_ids_len| to the
2089
- * locally-configured group preference list. */
2090
- void tls1_get_grouplist(SSL *ssl, const uint16_t **out_group_ids,
2091
- size_t *out_group_ids_len);
2754
+ // tls1_get_grouplist returns the locally-configured group preference list.
2755
+ Span<const uint16_t> tls1_get_grouplist(const SSL *ssl);
2092
2756
 
2093
- /* tls1_check_group_id returns one if |group_id| is consistent with
2094
- * locally-configured group preferences. */
2095
- int tls1_check_group_id(SSL *ssl, uint16_t group_id);
2757
+ // tls1_check_group_id returns one if |group_id| is consistent with
2758
+ // locally-configured group preferences.
2759
+ int tls1_check_group_id(const SSL *ssl, uint16_t group_id);
2096
2760
 
2097
- /* tls1_get_shared_group sets |*out_group_id| to the first preferred shared
2098
- * group between client and server preferences and returns one. If none may be
2099
- * found, it returns zero. */
2761
+ // tls1_get_shared_group sets |*out_group_id| to the first preferred shared
2762
+ // group between client and server preferences and returns one. If none may be
2763
+ // found, it returns zero.
2100
2764
  int tls1_get_shared_group(SSL_HANDSHAKE *hs, uint16_t *out_group_id);
2101
2765
 
2102
- /* tls1_set_curves converts the array of |ncurves| NIDs pointed to by |curves|
2103
- * into a newly allocated array of TLS group IDs. On success, the function
2104
- * returns one and writes the array to |*out_group_ids| and its size to
2105
- * |*out_group_ids_len|. Otherwise, it returns zero. */
2766
+ // tls1_set_curves converts the array of |ncurves| NIDs pointed to by |curves|
2767
+ // into a newly allocated array of TLS group IDs. On success, the function
2768
+ // returns one and writes the array to |*out_group_ids| and its size to
2769
+ // |*out_group_ids_len|. Otherwise, it returns zero.
2106
2770
  int tls1_set_curves(uint16_t **out_group_ids, size_t *out_group_ids_len,
2107
2771
  const int *curves, size_t ncurves);
2108
2772
 
2109
- /* tls1_set_curves_list converts the string of curves pointed to by |curves|
2110
- * into a newly allocated array of TLS group IDs. On success, the function
2111
- * returns one and writes the array to |*out_group_ids| and its size to
2112
- * |*out_group_ids_len|. Otherwise, it returns zero. */
2773
+ // tls1_set_curves_list converts the string of curves pointed to by |curves|
2774
+ // into a newly allocated array of TLS group IDs. On success, the function
2775
+ // returns one and writes the array to |*out_group_ids| and its size to
2776
+ // |*out_group_ids_len|. Otherwise, it returns zero.
2113
2777
  int tls1_set_curves_list(uint16_t **out_group_ids, size_t *out_group_ids_len,
2114
2778
  const char *curves);
2115
2779
 
2116
- /* ssl_add_clienthello_tlsext writes ClientHello extensions to |out|. It
2117
- * returns one on success and zero on failure. The |header_len| argument is the
2118
- * length of the ClientHello written so far and is used to compute the padding
2119
- * length. (It does not include the record header.) */
2780
+ // ssl_add_clienthello_tlsext writes ClientHello extensions to |out|. It
2781
+ // returns one on success and zero on failure. The |header_len| argument is the
2782
+ // length of the ClientHello written so far and is used to compute the padding
2783
+ // length. (It does not include the record header.)
2120
2784
  int ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, size_t header_len);
2121
2785
 
2122
2786
  int ssl_add_serverhello_tlsext(SSL_HANDSHAKE *hs, CBB *out);
@@ -2126,60 +2790,143 @@ int ssl_parse_serverhello_tlsext(SSL_HANDSHAKE *hs, CBS *cbs);
2126
2790
 
2127
2791
  #define tlsext_tick_md EVP_sha256
2128
2792
 
2129
- /* tls_process_ticket processes a session ticket from the client. On success,
2130
- * it sets |*out_session| to the decrypted session or NULL if the ticket was
2131
- * rejected. If the ticket was valid, it sets |*out_renew_ticket| to whether
2132
- * the ticket should be renewed. It returns one on success and zero on fatal
2133
- * error. */
2134
- int tls_process_ticket(SSL *ssl, SSL_SESSION **out_session,
2135
- int *out_renew_ticket, const uint8_t *ticket,
2136
- size_t ticket_len, const uint8_t *session_id,
2137
- size_t session_id_len);
2138
-
2139
- /* tls1_verify_channel_id processes the current message as a Channel ID message,
2140
- * and verifies the signature. If the key is valid, it saves the Channel ID and
2141
- * returns one. Otherwise, it returns zero. */
2142
- int tls1_verify_channel_id(SSL_HANDSHAKE *hs);
2143
-
2144
- /* tls1_write_channel_id generates a Channel ID message and puts the output in
2145
- * |cbb|. |ssl->tlsext_channel_id_private| must already be set before calling.
2146
- * This function returns one on success and zero on error. */
2793
+ // ssl_process_ticket processes a session ticket from the client. It returns
2794
+ // one of:
2795
+ // |ssl_ticket_aead_success|: |*out_session| is set to the parsed session and
2796
+ // |*out_renew_ticket| is set to whether the ticket should be renewed.
2797
+ // |ssl_ticket_aead_ignore_ticket|: |*out_renew_ticket| is set to whether a
2798
+ // fresh ticket should be sent, but the given ticket cannot be used.
2799
+ // |ssl_ticket_aead_retry|: the ticket could not be immediately decrypted.
2800
+ // Retry later.
2801
+ // |ssl_ticket_aead_error|: an error occured that is fatal to the connection.
2802
+ enum ssl_ticket_aead_result_t ssl_process_ticket(
2803
+ SSL *ssl, UniquePtr<SSL_SESSION> *out_session, bool *out_renew_ticket,
2804
+ const uint8_t *ticket, size_t ticket_len, const uint8_t *session_id,
2805
+ size_t session_id_len);
2806
+
2807
+ // tls1_verify_channel_id processes |msg| as a Channel ID message, and verifies
2808
+ // the signature. If the key is valid, it saves the Channel ID and returns
2809
+ // one. Otherwise, it returns zero.
2810
+ int tls1_verify_channel_id(SSL_HANDSHAKE *hs, const SSLMessage &msg);
2811
+
2812
+ // tls1_write_channel_id generates a Channel ID message and puts the output in
2813
+ // |cbb|. |ssl->tlsext_channel_id_private| must already be set before calling.
2814
+ // This function returns one on success and zero on error.
2147
2815
  int tls1_write_channel_id(SSL_HANDSHAKE *hs, CBB *cbb);
2148
2816
 
2149
- /* tls1_channel_id_hash computes the hash to be signed by Channel ID and writes
2150
- * it to |out|, which must contain at least |EVP_MAX_MD_SIZE| bytes. It returns
2151
- * one on success and zero on failure. */
2817
+ // tls1_channel_id_hash computes the hash to be signed by Channel ID and writes
2818
+ // it to |out|, which must contain at least |EVP_MAX_MD_SIZE| bytes. It returns
2819
+ // one on success and zero on failure.
2152
2820
  int tls1_channel_id_hash(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len);
2153
2821
 
2154
2822
  int tls1_record_handshake_hashes_for_channel_id(SSL_HANDSHAKE *hs);
2155
2823
 
2156
- /* ssl_do_channel_id_callback checks runs |ssl->ctx->channel_id_cb| if
2157
- * necessary. It returns one on success and zero on fatal error. Note that, on
2158
- * success, |ssl->tlsext_channel_id_private| may be unset, in which case the
2159
- * operation should be retried later. */
2824
+ // ssl_do_channel_id_callback checks runs |ssl->ctx->channel_id_cb| if
2825
+ // necessary. It returns one on success and zero on fatal error. Note that, on
2826
+ // success, |ssl->tlsext_channel_id_private| may be unset, in which case the
2827
+ // operation should be retried later.
2160
2828
  int ssl_do_channel_id_callback(SSL *ssl);
2161
2829
 
2162
- /* ssl3_can_false_start returns one if |ssl| is allowed to False Start and zero
2163
- * otherwise. */
2830
+ // ssl3_can_false_start returns one if |ssl| is allowed to False Start and zero
2831
+ // otherwise.
2164
2832
  int ssl3_can_false_start(const SSL *ssl);
2165
2833
 
2166
- /* ssl_get_version_range sets |*out_min_version| and |*out_max_version| to the
2167
- * minimum and maximum enabled protocol versions, respectively. */
2168
- int ssl_get_version_range(const SSL *ssl, uint16_t *out_min_version,
2169
- uint16_t *out_max_version);
2834
+ // ssl_can_write returns one if |ssl| is allowed to write and zero otherwise.
2835
+ int ssl_can_write(const SSL *ssl);
2170
2836
 
2171
- /* ssl3_protocol_version returns |ssl|'s protocol version. It is an error to
2172
- * call this function before the version is determined. */
2173
- uint16_t ssl3_protocol_version(const SSL *ssl);
2837
+ // ssl_can_read returns one if |ssl| is allowed to read and zero otherwise.
2838
+ int ssl_can_read(const SSL *ssl);
2174
2839
 
2175
- void ssl_get_current_time(const SSL *ssl, struct timeval *out_clock);
2840
+ void ssl_get_current_time(const SSL *ssl, struct OPENSSL_timeval *out_clock);
2841
+ void ssl_ctx_get_current_time(const SSL_CTX *ctx,
2842
+ struct OPENSSL_timeval *out_clock);
2176
2843
 
2177
- /* ssl_reset_error_state resets state for |SSL_get_error|. */
2844
+ // ssl_reset_error_state resets state for |SSL_get_error|.
2178
2845
  void ssl_reset_error_state(SSL *ssl);
2179
2846
 
2847
+ } // namespace bssl
2848
+
2849
+
2850
+ // Opaque C types.
2851
+ //
2852
+ // The following types are exported to C code as public typedefs, so they must
2853
+ // be defined outside of the namespace.
2854
+
2855
+ // ssl_method_st backs the public |SSL_METHOD| type. It is a compatibility
2856
+ // structure to support the legacy version-locked methods.
2857
+ struct ssl_method_st {
2858
+ // version, if non-zero, is the only protocol version acceptable to an
2859
+ // SSL_CTX initialized from this method.
2860
+ uint16_t version;
2861
+ // method is the underlying SSL_PROTOCOL_METHOD that initializes the
2862
+ // SSL_CTX.
2863
+ const bssl::SSL_PROTOCOL_METHOD *method;
2864
+ // x509_method contains pointers to functions that might deal with |X509|
2865
+ // compatibility, or might be a no-op, depending on the application.
2866
+ const SSL_X509_METHOD *x509_method;
2867
+ };
2868
+
2869
+ struct ssl_x509_method_st {
2870
+ // check_client_CA_list returns one if |names| is a good list of X.509
2871
+ // distinguished names and zero otherwise. This is used to ensure that we can
2872
+ // reject unparsable values at handshake time when using crypto/x509.
2873
+ int (*check_client_CA_list)(STACK_OF(CRYPTO_BUFFER) *names);
2874
+
2875
+ // cert_clear frees and NULLs all X509 certificate-related state.
2876
+ void (*cert_clear)(bssl::CERT *cert);
2877
+ // cert_free frees all X509-related state.
2878
+ void (*cert_free)(bssl::CERT *cert);
2879
+ // cert_flush_cached_chain drops any cached |X509|-based certificate chain
2880
+ // from |cert|.
2881
+ // cert_dup duplicates any needed fields from |cert| to |new_cert|.
2882
+ void (*cert_dup)(bssl::CERT *new_cert, const bssl::CERT *cert);
2883
+ void (*cert_flush_cached_chain)(bssl::CERT *cert);
2884
+ // cert_flush_cached_chain drops any cached |X509|-based leaf certificate
2885
+ // from |cert|.
2886
+ void (*cert_flush_cached_leaf)(bssl::CERT *cert);
2887
+
2888
+ // session_cache_objects fills out |sess->x509_peer| and |sess->x509_chain|
2889
+ // from |sess->certs| and erases |sess->x509_chain_without_leaf|. It returns
2890
+ // one on success or zero on error.
2891
+ int (*session_cache_objects)(SSL_SESSION *session);
2892
+ // session_dup duplicates any needed fields from |session| to |new_session|.
2893
+ // It returns one on success or zero on error.
2894
+ int (*session_dup)(SSL_SESSION *new_session, const SSL_SESSION *session);
2895
+ // session_clear frees any X509-related state from |session|.
2896
+ void (*session_clear)(SSL_SESSION *session);
2897
+ // session_verify_cert_chain verifies the certificate chain in |session|,
2898
+ // sets |session->verify_result| and returns one on success or zero on
2899
+ // error.
2900
+ int (*session_verify_cert_chain)(SSL_SESSION *session, SSL *ssl,
2901
+ uint8_t *out_alert);
2902
+
2903
+ // hs_flush_cached_ca_names drops any cached |X509_NAME|s from |hs|.
2904
+ void (*hs_flush_cached_ca_names)(bssl::SSL_HANDSHAKE *hs);
2905
+ // ssl_new does any neccessary initialisation of |ssl|. It returns one on
2906
+ // success or zero on error.
2907
+ int (*ssl_new)(SSL *ssl);
2908
+ // ssl_free frees anything created by |ssl_new|.
2909
+ void (*ssl_free)(SSL *ssl);
2910
+ // ssl_flush_cached_client_CA drops any cached |X509_NAME|s from |ssl|.
2911
+ void (*ssl_flush_cached_client_CA)(SSL *ssl);
2912
+ // ssl_auto_chain_if_needed runs the deprecated auto-chaining logic if
2913
+ // necessary. On success, it updates |ssl|'s certificate configuration as
2914
+ // needed and returns one. Otherwise, it returns zero.
2915
+ int (*ssl_auto_chain_if_needed)(SSL *ssl);
2916
+ // ssl_ctx_new does any neccessary initialisation of |ctx|. It returns one on
2917
+ // success or zero on error.
2918
+ int (*ssl_ctx_new)(SSL_CTX *ctx);
2919
+ // ssl_ctx_free frees anything created by |ssl_ctx_new|.
2920
+ void (*ssl_ctx_free)(SSL_CTX *ctx);
2921
+ // ssl_ctx_flush_cached_client_CA drops any cached |X509_NAME|s from |ctx|.
2922
+ void (*ssl_ctx_flush_cached_client_CA)(SSL_CTX *ssl);
2923
+ };
2924
+
2925
+ // The following types back public C-exposed types which must live in the global
2926
+ // namespace. We use subclassing so the implementations may be C++ types with
2927
+ // methods and destructor without polluting the global namespace.
2928
+ struct ssl_ctx_st : public bssl::SSLContext {};
2929
+ struct ssl_st : public bssl::SSLConnection {};
2180
2930
 
2181
- #if defined(__cplusplus)
2182
- } /* extern C */
2183
- #endif
2184
2931
 
2185
- #endif /* OPENSSL_HEADER_SSL_INTERNAL_H */
2932
+ #endif // OPENSSL_HEADER_SSL_INTERNAL_H