grpc 1.24.0 → 1.25.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 (504) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +306 -243
  3. data/etc/roots.pem +0 -100
  4. data/include/grpc/grpc_security.h +44 -18
  5. data/include/grpc/impl/codegen/grpc_types.h +15 -0
  6. data/include/grpc/impl/codegen/port_platform.h +27 -11
  7. data/include/grpc/impl/codegen/sync_generic.h +1 -1
  8. data/src/boringssl/err_data.c +695 -650
  9. data/src/core/ext/filters/client_channel/client_channel.cc +257 -179
  10. data/src/core/ext/filters/client_channel/client_channel.h +24 -0
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +2 -3
  12. data/src/core/ext/filters/client_channel/client_channel_factory.h +1 -5
  13. data/src/core/ext/filters/client_channel/health/health_check_client.cc +18 -45
  14. data/src/core/ext/filters/client_channel/health/health_check_client.h +5 -13
  15. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
  16. data/src/core/ext/filters/client_channel/lb_policy.cc +2 -3
  17. data/src/core/ext/filters/client_channel/lb_policy.h +65 -55
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +14 -14
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +113 -36
  20. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +14 -19
  21. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +36 -13
  22. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +3 -10
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +814 -1589
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.h +2 -5
  25. data/src/core/ext/filters/client_channel/lb_policy_factory.h +3 -6
  26. data/src/core/ext/filters/client_channel/resolver.cc +1 -2
  27. data/src/core/ext/filters/client_channel/resolver.h +8 -16
  28. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +25 -8
  29. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +46 -12
  30. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +10 -17
  31. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +7 -8
  32. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +4 -4
  33. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +111 -44
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +22 -14
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +1 -1
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
  37. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +29 -10
  38. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +27 -36
  39. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +7 -10
  40. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +60 -16
  41. data/src/core/ext/filters/client_channel/resolver_factory.h +4 -8
  42. data/src/core/ext/filters/client_channel/resolver_registry.cc +1 -1
  43. data/src/core/ext/filters/client_channel/resolver_registry.h +1 -1
  44. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +7 -10
  45. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +7 -8
  46. data/src/core/ext/filters/client_channel/resolving_lb_policy.h +1 -1
  47. data/src/core/ext/filters/client_channel/retry_throttle.cc +5 -5
  48. data/src/core/ext/filters/client_channel/retry_throttle.h +1 -4
  49. data/src/core/ext/filters/client_channel/service_config.h +8 -8
  50. data/src/core/ext/filters/client_channel/subchannel.cc +53 -86
  51. data/src/core/ext/filters/client_channel/subchannel.h +7 -9
  52. data/src/core/ext/filters/client_channel/subchannel_interface.h +9 -13
  53. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +3 -6
  54. data/src/core/ext/filters/client_channel/{lb_policy/xds/xds_load_balancer_api.cc → xds/xds_api.cc} +169 -52
  55. data/src/core/ext/filters/client_channel/xds/xds_api.h +171 -0
  56. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +450 -0
  57. data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +99 -0
  58. data/src/core/ext/filters/client_channel/{lb_policy/xds → xds}/xds_channel.h +8 -6
  59. data/src/core/ext/filters/client_channel/xds/xds_channel_args.h +26 -0
  60. data/src/core/ext/filters/client_channel/{lb_policy/xds → xds}/xds_channel_secure.cc +28 -11
  61. data/src/core/ext/filters/client_channel/xds/xds_client.cc +1413 -0
  62. data/src/core/ext/filters/client_channel/xds/xds_client.h +221 -0
  63. data/src/core/ext/filters/client_channel/{lb_policy/xds → xds}/xds_client_stats.cc +1 -5
  64. data/src/core/ext/filters/client_channel/{lb_policy/xds → xds}/xds_client_stats.h +3 -4
  65. data/src/core/ext/filters/deadline/deadline_filter.cc +20 -20
  66. data/src/core/ext/filters/http/client/http_client_filter.cc +15 -15
  67. data/src/core/ext/filters/http/client_authority_filter.cc +14 -14
  68. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +12 -12
  69. data/src/core/ext/filters/max_age/max_age_filter.cc +59 -50
  70. data/src/core/ext/filters/message_size/message_size_filter.cc +18 -18
  71. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +15 -14
  72. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +233 -175
  73. data/src/core/ext/transport/chttp2/transport/flow_control.h +21 -24
  74. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +253 -163
  75. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +24 -12
  76. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +2 -3
  77. data/src/core/ext/transport/chttp2/transport/internal.h +13 -15
  78. data/src/core/ext/transport/chttp2/transport/writing.cc +3 -0
  79. data/src/core/ext/transport/inproc/inproc_transport.cc +20 -13
  80. data/src/core/lib/channel/channel_args.cc +16 -0
  81. data/src/core/lib/channel/channel_args.h +22 -0
  82. data/src/core/lib/channel/channelz.cc +5 -6
  83. data/src/core/lib/channel/channelz.h +1 -1
  84. data/src/core/lib/channel/connected_channel.cc +20 -20
  85. data/src/core/lib/channel/handshaker.h +3 -4
  86. data/src/core/lib/channel/handshaker_factory.h +1 -3
  87. data/src/core/lib/debug/trace.h +3 -2
  88. data/src/core/lib/gprpp/arena.cc +3 -3
  89. data/src/core/lib/gprpp/arena.h +2 -3
  90. data/src/core/lib/gprpp/inlined_vector.h +9 -0
  91. data/src/core/lib/gprpp/map.h +3 -501
  92. data/src/core/lib/gprpp/memory.h +45 -41
  93. data/src/core/lib/gprpp/mpscq.cc +108 -0
  94. data/src/core/lib/gprpp/mpscq.h +98 -0
  95. data/src/core/lib/gprpp/orphanable.h +6 -11
  96. data/src/core/lib/gprpp/ref_counted.h +25 -19
  97. data/src/core/lib/gprpp/set.h +33 -0
  98. data/src/core/lib/gprpp/thd.h +2 -4
  99. data/src/core/lib/http/httpcli.cc +1 -1
  100. data/src/core/lib/http/httpcli_security_connector.cc +15 -11
  101. data/src/core/lib/http/parser.cc +1 -1
  102. data/src/core/lib/iomgr/buffer_list.cc +4 -5
  103. data/src/core/lib/iomgr/buffer_list.h +5 -6
  104. data/src/core/lib/iomgr/call_combiner.cc +4 -5
  105. data/src/core/lib/iomgr/call_combiner.h +2 -2
  106. data/src/core/lib/iomgr/cfstream_handle.h +3 -5
  107. data/src/core/lib/iomgr/closure.h +8 -3
  108. data/src/core/lib/iomgr/combiner.cc +45 -82
  109. data/src/core/lib/iomgr/combiner.h +32 -8
  110. data/src/core/lib/iomgr/endpoint_cfstream.cc +5 -3
  111. data/src/core/lib/iomgr/ev_epoll1_linux.cc +19 -15
  112. data/src/core/lib/iomgr/exec_ctx.h +4 -3
  113. data/src/core/lib/iomgr/executor.cc +4 -2
  114. data/src/core/lib/iomgr/executor.h +3 -0
  115. data/src/core/lib/iomgr/executor/mpmcqueue.h +3 -6
  116. data/src/core/lib/iomgr/executor/threadpool.cc +1 -2
  117. data/src/core/lib/iomgr/executor/threadpool.h +7 -11
  118. data/src/core/lib/iomgr/resource_quota.cc +55 -51
  119. data/src/core/lib/iomgr/resource_quota.h +13 -9
  120. data/src/core/lib/iomgr/socket_utils_common_posix.cc +13 -0
  121. data/src/core/lib/iomgr/socket_utils_posix.h +4 -0
  122. data/src/core/lib/iomgr/tcp_client_posix.cc +4 -11
  123. data/src/core/lib/iomgr/tcp_custom.cc +9 -7
  124. data/src/core/lib/iomgr/tcp_posix.cc +20 -16
  125. data/src/core/lib/iomgr/tcp_server.h +1 -4
  126. data/src/core/lib/iomgr/tcp_server_custom.cc +5 -5
  127. data/src/core/lib/iomgr/tcp_server_posix.cc +1 -1
  128. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +2 -11
  129. data/src/core/lib/iomgr/timer_custom.cc +2 -2
  130. data/src/core/lib/iomgr/udp_server.cc +3 -2
  131. data/src/core/lib/iomgr/udp_server.h +6 -12
  132. data/src/core/lib/json/json.h +1 -1
  133. data/src/core/lib/json/json_string.cc +2 -2
  134. data/src/core/lib/profiling/basic_timers.cc +2 -2
  135. data/src/core/lib/security/credentials/alts/alts_credentials.cc +2 -2
  136. data/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc +1 -1
  137. data/src/core/lib/security/credentials/credentials.h +4 -20
  138. data/src/core/lib/security/credentials/fake/fake_credentials.cc +4 -4
  139. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +1 -3
  140. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +64 -0
  141. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +4 -4
  142. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +9 -7
  143. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -0
  144. data/src/core/lib/security/security_connector/local/local_security_connector.cc +4 -4
  145. data/src/core/lib/security/security_connector/security_connector.cc +1 -0
  146. data/src/core/lib/security/security_connector/security_connector.h +19 -17
  147. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +8 -5
  148. data/src/core/lib/security/security_connector/ssl_utils.cc +2 -2
  149. data/src/core/lib/security/security_connector/ssl_utils.h +1 -1
  150. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +14 -6
  151. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +4 -2
  152. data/src/core/lib/security/transport/client_auth_filter.cc +17 -17
  153. data/src/core/lib/security/transport/security_handshaker.cc +29 -13
  154. data/src/core/lib/security/transport/security_handshaker.h +4 -2
  155. data/src/core/lib/security/transport/server_auth_filter.cc +14 -14
  156. data/src/core/lib/slice/slice.cc +2 -10
  157. data/src/core/lib/slice/slice_hash_table.h +4 -6
  158. data/src/core/lib/slice/slice_intern.cc +42 -39
  159. data/src/core/lib/slice/slice_internal.h +3 -3
  160. data/src/core/lib/slice/slice_utils.h +21 -4
  161. data/src/core/lib/slice/slice_weak_hash_table.h +4 -6
  162. data/src/core/lib/surface/call.cc +3 -3
  163. data/src/core/lib/surface/channel.cc +7 -0
  164. data/src/core/lib/surface/completion_queue.cc +12 -11
  165. data/src/core/lib/surface/completion_queue.h +4 -2
  166. data/src/core/lib/surface/init.cc +1 -0
  167. data/src/core/lib/surface/lame_client.cc +33 -18
  168. data/src/core/lib/surface/server.cc +77 -76
  169. data/src/core/lib/surface/version.cc +1 -1
  170. data/src/core/lib/transport/byte_stream.h +3 -7
  171. data/src/core/lib/transport/connectivity_state.cc +112 -98
  172. data/src/core/lib/transport/connectivity_state.h +100 -50
  173. data/src/core/lib/transport/static_metadata.cc +276 -288
  174. data/src/core/lib/transport/static_metadata.h +73 -76
  175. data/src/core/lib/transport/status_conversion.cc +1 -1
  176. data/src/core/lib/transport/status_metadata.cc +1 -1
  177. data/src/core/lib/transport/transport.cc +2 -2
  178. data/src/core/lib/transport/transport.h +12 -4
  179. data/src/core/lib/transport/transport_op_string.cc +14 -11
  180. data/src/core/tsi/alts/frame_protector/alts_unseal_privacy_integrity_crypter.cc +1 -1
  181. data/src/core/tsi/alts/handshaker/alts_shared_resource.cc +1 -1
  182. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +5 -5
  183. data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +12 -2
  184. data/src/core/tsi/fake_transport_security.cc +7 -5
  185. data/src/core/tsi/grpc_shadow_boringssl.h +2918 -2627
  186. data/src/core/tsi/local_transport_security.cc +8 -6
  187. data/src/core/tsi/ssl/session_cache/ssl_session.h +1 -3
  188. data/src/core/tsi/ssl/session_cache/ssl_session_boringssl.cc +1 -2
  189. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +7 -5
  190. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +4 -6
  191. data/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc +1 -2
  192. data/src/core/tsi/ssl_transport_security.cc +12 -12
  193. data/src/core/tsi/ssl_transport_security.h +2 -2
  194. data/src/core/tsi/transport_security_grpc.cc +7 -0
  195. data/src/core/tsi/transport_security_grpc.h +6 -0
  196. data/src/ruby/ext/grpc/extconf.rb +1 -0
  197. data/src/ruby/ext/grpc/rb_call.c +1 -1
  198. data/src/ruby/ext/grpc/rb_channel.c +1 -1
  199. data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
  200. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  201. data/src/ruby/lib/grpc/version.rb +1 -1
  202. data/src/ruby/spec/google_rpc_status_utils_spec.rb +2 -2
  203. data/third_party/boringssl/crypto/asn1/a_bool.c +18 -5
  204. data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +17 -221
  205. data/third_party/boringssl/crypto/asn1/a_dup.c +0 -24
  206. data/third_party/boringssl/crypto/asn1/a_enum.c +2 -2
  207. data/third_party/boringssl/crypto/asn1/a_i2d_fp.c +10 -72
  208. data/third_party/boringssl/crypto/asn1/a_int.c +12 -71
  209. data/third_party/boringssl/crypto/asn1/a_mbstr.c +110 -216
  210. data/third_party/boringssl/crypto/asn1/a_object.c +16 -5
  211. data/third_party/boringssl/crypto/asn1/a_strnid.c +1 -0
  212. data/third_party/boringssl/crypto/asn1/asn1_lib.c +5 -1
  213. data/third_party/boringssl/crypto/asn1/tasn_enc.c +3 -1
  214. data/third_party/boringssl/crypto/base64/base64.c +2 -2
  215. data/third_party/boringssl/crypto/bio/bio.c +73 -9
  216. data/third_party/boringssl/crypto/bio/connect.c +4 -0
  217. data/third_party/boringssl/crypto/bio/fd.c +4 -0
  218. data/third_party/boringssl/crypto/bio/file.c +5 -2
  219. data/third_party/boringssl/crypto/bio/socket.c +4 -0
  220. data/third_party/boringssl/crypto/bio/socket_helper.c +4 -0
  221. data/third_party/boringssl/crypto/bn_extra/convert.c +11 -7
  222. data/third_party/boringssl/crypto/bytestring/ber.c +8 -4
  223. data/third_party/boringssl/crypto/bytestring/cbb.c +19 -7
  224. data/third_party/boringssl/crypto/bytestring/cbs.c +28 -15
  225. data/third_party/boringssl/crypto/bytestring/internal.h +28 -7
  226. data/third_party/boringssl/crypto/bytestring/unicode.c +155 -0
  227. data/third_party/boringssl/crypto/chacha/chacha.c +36 -19
  228. data/third_party/boringssl/crypto/chacha/internal.h +45 -0
  229. data/third_party/boringssl/crypto/cipher_extra/cipher_extra.c +29 -0
  230. data/third_party/boringssl/crypto/cipher_extra/e_aesccm.c +269 -25
  231. data/third_party/boringssl/crypto/cipher_extra/e_aesctrhmac.c +16 -14
  232. data/third_party/boringssl/crypto/cipher_extra/e_aesgcmsiv.c +54 -38
  233. data/third_party/boringssl/crypto/cipher_extra/e_chacha20poly1305.c +133 -41
  234. data/third_party/boringssl/crypto/cipher_extra/e_tls.c +23 -15
  235. data/third_party/boringssl/crypto/cipher_extra/tls_cbc.c +24 -15
  236. data/third_party/boringssl/crypto/cmac/cmac.c +62 -25
  237. data/third_party/boringssl/crypto/conf/conf.c +7 -0
  238. data/third_party/boringssl/crypto/cpu-arm-linux.c +4 -148
  239. data/third_party/boringssl/crypto/cpu-arm-linux.h +201 -0
  240. data/third_party/boringssl/crypto/cpu-intel.c +45 -51
  241. data/third_party/boringssl/crypto/crypto.c +39 -22
  242. data/third_party/boringssl/crypto/curve25519/spake25519.c +1 -1
  243. data/third_party/boringssl/crypto/dsa/dsa.c +77 -53
  244. data/third_party/boringssl/crypto/ec_extra/ec_asn1.c +20 -8
  245. data/third_party/boringssl/crypto/ec_extra/ec_derive.c +96 -0
  246. data/third_party/boringssl/crypto/{ecdh/ecdh.c → ecdh_extra/ecdh_extra.c} +20 -58
  247. data/third_party/boringssl/crypto/ecdsa_extra/ecdsa_asn1.c +1 -9
  248. data/third_party/boringssl/crypto/engine/engine.c +2 -1
  249. data/third_party/boringssl/crypto/err/err.c +2 -0
  250. data/third_party/boringssl/crypto/err/internal.h +2 -2
  251. data/third_party/boringssl/crypto/evp/evp.c +89 -8
  252. data/third_party/boringssl/crypto/evp/evp_asn1.c +56 -5
  253. data/third_party/boringssl/crypto/evp/evp_ctx.c +52 -14
  254. data/third_party/boringssl/crypto/evp/internal.h +18 -1
  255. data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +5 -0
  256. data/third_party/boringssl/crypto/evp/p_ec.c +51 -3
  257. data/third_party/boringssl/crypto/evp/p_ec_asn1.c +6 -7
  258. data/third_party/boringssl/crypto/evp/p_ed25519.c +36 -3
  259. data/third_party/boringssl/crypto/evp/p_ed25519_asn1.c +76 -45
  260. data/third_party/boringssl/crypto/evp/p_rsa.c +3 -1
  261. data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +5 -0
  262. data/third_party/boringssl/crypto/evp/p_x25519.c +110 -0
  263. data/third_party/boringssl/crypto/evp/p_x25519_asn1.c +249 -0
  264. data/third_party/boringssl/crypto/evp/scrypt.c +6 -2
  265. data/third_party/boringssl/crypto/fipsmodule/aes/aes.c +34 -274
  266. data/third_party/boringssl/crypto/fipsmodule/aes/internal.h +161 -21
  267. data/third_party/boringssl/crypto/fipsmodule/aes/key_wrap.c +111 -13
  268. data/third_party/boringssl/crypto/fipsmodule/aes/mode_wrappers.c +17 -21
  269. data/third_party/boringssl/crypto/fipsmodule/bcm.c +119 -7
  270. data/third_party/boringssl/crypto/fipsmodule/bn/bn.c +19 -2
  271. data/third_party/boringssl/crypto/fipsmodule/bn/cmp.c +2 -2
  272. data/third_party/boringssl/crypto/fipsmodule/bn/ctx.c +93 -160
  273. data/third_party/boringssl/crypto/fipsmodule/bn/div.c +48 -57
  274. data/third_party/boringssl/crypto/fipsmodule/bn/div_extra.c +87 -0
  275. data/third_party/boringssl/crypto/fipsmodule/bn/exponentiation.c +143 -211
  276. data/third_party/boringssl/crypto/fipsmodule/bn/gcd.c +0 -305
  277. data/third_party/boringssl/crypto/fipsmodule/bn/gcd_extra.c +325 -0
  278. data/third_party/boringssl/crypto/fipsmodule/bn/internal.h +168 -50
  279. data/third_party/boringssl/crypto/fipsmodule/bn/montgomery.c +68 -92
  280. data/third_party/boringssl/crypto/fipsmodule/bn/montgomery_inv.c +7 -6
  281. data/third_party/boringssl/crypto/fipsmodule/bn/mul.c +11 -14
  282. data/third_party/boringssl/crypto/fipsmodule/bn/prime.c +358 -443
  283. data/third_party/boringssl/crypto/fipsmodule/bn/random.c +25 -35
  284. data/third_party/boringssl/crypto/fipsmodule/bn/rsaz_exp.c +20 -25
  285. data/third_party/boringssl/crypto/fipsmodule/bn/rsaz_exp.h +76 -5
  286. data/third_party/boringssl/crypto/fipsmodule/bn/shift.c +14 -14
  287. data/third_party/boringssl/crypto/fipsmodule/cipher/cipher.c +7 -2
  288. data/third_party/boringssl/crypto/fipsmodule/cipher/e_aes.c +383 -516
  289. data/third_party/boringssl/crypto/fipsmodule/cipher/e_des.c +4 -0
  290. data/third_party/boringssl/crypto/fipsmodule/cipher/internal.h +3 -4
  291. data/third_party/boringssl/crypto/fipsmodule/delocate.h +3 -2
  292. data/third_party/boringssl/crypto/fipsmodule/digest/digest.c +32 -17
  293. data/third_party/boringssl/crypto/fipsmodule/digest/md32_common.h +3 -3
  294. data/third_party/boringssl/crypto/fipsmodule/ec/ec.c +228 -122
  295. data/third_party/boringssl/crypto/fipsmodule/ec/ec_key.c +34 -8
  296. data/third_party/boringssl/crypto/fipsmodule/ec/ec_montgomery.c +311 -98
  297. data/third_party/boringssl/crypto/fipsmodule/ec/felem.c +82 -0
  298. data/third_party/boringssl/crypto/fipsmodule/ec/internal.h +263 -97
  299. data/third_party/boringssl/crypto/fipsmodule/ec/oct.c +22 -59
  300. data/third_party/boringssl/crypto/fipsmodule/ec/p224-64.c +317 -234
  301. data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64-table.h +9473 -9475
  302. data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64.c +313 -109
  303. data/third_party/boringssl/crypto/fipsmodule/ec/p256-x86_64.h +36 -0
  304. data/third_party/boringssl/crypto/fipsmodule/ec/scalar.c +96 -0
  305. data/third_party/boringssl/crypto/fipsmodule/ec/simple.c +126 -792
  306. data/third_party/boringssl/crypto/fipsmodule/ec/simple_mul.c +84 -0
  307. data/third_party/boringssl/crypto/fipsmodule/ec/util.c +163 -12
  308. data/third_party/boringssl/crypto/fipsmodule/ec/wnaf.c +84 -211
  309. data/third_party/boringssl/crypto/fipsmodule/ecdh/ecdh.c +122 -0
  310. data/third_party/boringssl/crypto/fipsmodule/ecdsa/ecdsa.c +60 -205
  311. data/third_party/boringssl/crypto/fipsmodule/fips_shared_support.c +32 -0
  312. data/third_party/boringssl/crypto/fipsmodule/is_fips.c +2 -0
  313. data/third_party/boringssl/crypto/fipsmodule/md4/md4.c +3 -1
  314. data/third_party/boringssl/crypto/fipsmodule/md5/internal.h +37 -0
  315. data/third_party/boringssl/crypto/fipsmodule/md5/md5.c +11 -8
  316. data/third_party/boringssl/crypto/fipsmodule/modes/cbc.c +35 -79
  317. data/third_party/boringssl/crypto/fipsmodule/modes/cfb.c +7 -39
  318. data/third_party/boringssl/crypto/fipsmodule/modes/ctr.c +7 -27
  319. data/third_party/boringssl/crypto/fipsmodule/modes/gcm.c +123 -309
  320. data/third_party/boringssl/crypto/fipsmodule/modes/internal.h +189 -126
  321. data/third_party/boringssl/crypto/fipsmodule/modes/ofb.c +3 -2
  322. data/third_party/boringssl/crypto/fipsmodule/rand/ctrdrbg.c +2 -2
  323. data/third_party/boringssl/crypto/fipsmodule/rand/internal.h +35 -0
  324. data/third_party/boringssl/crypto/fipsmodule/rand/rand.c +24 -19
  325. data/third_party/boringssl/crypto/fipsmodule/rand/urandom.c +256 -77
  326. data/third_party/boringssl/crypto/fipsmodule/rsa/padding.c +10 -7
  327. data/third_party/boringssl/crypto/fipsmodule/rsa/rsa.c +5 -1
  328. data/third_party/boringssl/crypto/fipsmodule/rsa/rsa_impl.c +131 -14
  329. data/third_party/boringssl/crypto/fipsmodule/self_check/self_check.c +83 -10
  330. data/third_party/boringssl/crypto/fipsmodule/sha/internal.h +53 -0
  331. data/third_party/boringssl/crypto/fipsmodule/sha/sha1.c +9 -13
  332. data/third_party/boringssl/crypto/fipsmodule/sha/sha256.c +18 -12
  333. data/third_party/boringssl/crypto/fipsmodule/sha/sha512.c +95 -168
  334. data/third_party/boringssl/crypto/hrss/hrss.c +2201 -0
  335. data/third_party/boringssl/crypto/hrss/internal.h +62 -0
  336. data/third_party/boringssl/crypto/internal.h +95 -20
  337. data/third_party/boringssl/crypto/lhash/lhash.c +45 -33
  338. data/third_party/boringssl/crypto/mem.c +39 -2
  339. data/third_party/boringssl/crypto/obj/obj.c +4 -4
  340. data/third_party/boringssl/crypto/obj/obj_dat.h +6181 -875
  341. data/third_party/boringssl/crypto/pem/pem_all.c +2 -3
  342. data/third_party/boringssl/crypto/pem/pem_info.c +144 -162
  343. data/third_party/boringssl/crypto/pem/pem_lib.c +53 -52
  344. data/third_party/boringssl/crypto/pem/pem_pkey.c +13 -21
  345. data/third_party/boringssl/crypto/pkcs7/pkcs7.c +15 -22
  346. data/third_party/boringssl/crypto/pkcs7/pkcs7_x509.c +168 -16
  347. data/third_party/boringssl/crypto/pkcs8/internal.h +11 -0
  348. data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +24 -15
  349. data/third_party/boringssl/crypto/pkcs8/pkcs8.c +42 -25
  350. data/third_party/boringssl/crypto/pkcs8/pkcs8_x509.c +559 -43
  351. data/third_party/boringssl/crypto/pool/internal.h +1 -1
  352. data/third_party/boringssl/crypto/pool/pool.c +21 -0
  353. data/third_party/boringssl/crypto/rand_extra/deterministic.c +8 -0
  354. data/third_party/boringssl/crypto/rand_extra/fuchsia.c +1 -14
  355. data/third_party/boringssl/crypto/refcount_lock.c +2 -2
  356. data/third_party/boringssl/crypto/rsa_extra/rsa_print.c +22 -0
  357. data/third_party/boringssl/crypto/siphash/siphash.c +80 -0
  358. data/third_party/boringssl/crypto/stack/stack.c +83 -32
  359. data/third_party/boringssl/crypto/thread_none.c +2 -2
  360. data/third_party/boringssl/crypto/thread_pthread.c +2 -2
  361. data/third_party/boringssl/crypto/thread_win.c +38 -19
  362. data/third_party/boringssl/crypto/x509/a_strex.c +22 -2
  363. data/third_party/boringssl/crypto/x509/asn1_gen.c +2 -1
  364. data/third_party/boringssl/crypto/x509/by_dir.c +7 -0
  365. data/third_party/boringssl/crypto/x509/by_file.c +12 -10
  366. data/third_party/boringssl/crypto/x509/t_crl.c +5 -8
  367. data/third_party/boringssl/crypto/x509/t_req.c +1 -3
  368. data/third_party/boringssl/crypto/x509/t_x509.c +5 -8
  369. data/third_party/boringssl/crypto/x509/x509_cmp.c +1 -1
  370. data/third_party/boringssl/crypto/x509/x509_def.c +1 -1
  371. data/third_party/boringssl/crypto/x509/x509_lu.c +114 -5
  372. data/third_party/boringssl/crypto/x509/x509_req.c +20 -0
  373. data/third_party/boringssl/crypto/x509/x509_set.c +5 -0
  374. data/third_party/boringssl/crypto/x509/x509_trs.c +1 -0
  375. data/third_party/boringssl/crypto/x509/x509_txt.c +4 -5
  376. data/third_party/boringssl/crypto/x509/x509_vfy.c +145 -138
  377. data/third_party/boringssl/crypto/x509/x509_vpm.c +2 -0
  378. data/third_party/boringssl/crypto/x509/x509cset.c +40 -0
  379. data/third_party/boringssl/crypto/x509/x509name.c +2 -3
  380. data/third_party/boringssl/crypto/x509/x_all.c +109 -210
  381. data/third_party/boringssl/crypto/x509/x_x509.c +6 -0
  382. data/third_party/boringssl/crypto/x509v3/ext_dat.h +1 -3
  383. data/third_party/boringssl/crypto/x509v3/internal.h +56 -0
  384. data/third_party/boringssl/crypto/x509v3/pcy_cache.c +2 -0
  385. data/third_party/boringssl/crypto/x509v3/pcy_node.c +1 -0
  386. data/third_party/boringssl/crypto/x509v3/pcy_tree.c +4 -2
  387. data/third_party/boringssl/crypto/x509v3/v3_akey.c +5 -2
  388. data/third_party/boringssl/crypto/x509v3/v3_alt.c +19 -13
  389. data/third_party/boringssl/crypto/x509v3/v3_conf.c +2 -1
  390. data/third_party/boringssl/crypto/x509v3/v3_cpols.c +3 -2
  391. data/third_party/boringssl/crypto/x509v3/v3_genn.c +1 -6
  392. data/third_party/boringssl/crypto/x509v3/v3_lib.c +1 -0
  393. data/third_party/boringssl/crypto/x509v3/v3_ocsp.c +68 -0
  394. data/third_party/boringssl/crypto/x509v3/v3_pci.c +2 -1
  395. data/third_party/boringssl/crypto/x509v3/v3_purp.c +47 -69
  396. data/third_party/boringssl/crypto/x509v3/v3_skey.c +5 -2
  397. data/third_party/boringssl/crypto/x509v3/v3_utl.c +69 -25
  398. data/third_party/boringssl/include/openssl/aead.h +45 -19
  399. data/third_party/boringssl/include/openssl/aes.h +32 -7
  400. data/third_party/boringssl/include/openssl/asn1.h +7 -77
  401. data/third_party/boringssl/include/openssl/base.h +120 -6
  402. data/third_party/boringssl/include/openssl/base64.h +4 -1
  403. data/third_party/boringssl/include/openssl/bio.h +112 -81
  404. data/third_party/boringssl/include/openssl/blowfish.h +3 -3
  405. data/third_party/boringssl/include/openssl/bn.h +55 -29
  406. data/third_party/boringssl/include/openssl/buf.h +2 -2
  407. data/third_party/boringssl/include/openssl/bytestring.h +54 -32
  408. data/third_party/boringssl/include/openssl/cast.h +2 -2
  409. data/third_party/boringssl/include/openssl/cipher.h +46 -16
  410. data/third_party/boringssl/include/openssl/cmac.h +6 -2
  411. data/third_party/boringssl/include/openssl/conf.h +3 -6
  412. data/third_party/boringssl/include/openssl/cpu.h +25 -9
  413. data/third_party/boringssl/include/openssl/crypto.h +32 -10
  414. data/third_party/boringssl/include/openssl/curve25519.h +4 -4
  415. data/third_party/boringssl/include/openssl/dh.h +3 -2
  416. data/third_party/boringssl/include/openssl/digest.h +21 -7
  417. data/third_party/boringssl/include/openssl/dsa.h +8 -2
  418. data/third_party/boringssl/include/openssl/e_os2.h +18 -0
  419. data/third_party/boringssl/include/openssl/ec.h +25 -21
  420. data/third_party/boringssl/include/openssl/ec_key.h +36 -8
  421. data/third_party/boringssl/include/openssl/ecdh.h +17 -0
  422. data/third_party/boringssl/include/openssl/ecdsa.h +3 -3
  423. data/third_party/boringssl/include/openssl/engine.h +4 -4
  424. data/third_party/boringssl/include/openssl/err.h +3 -0
  425. data/third_party/boringssl/include/openssl/evp.h +199 -42
  426. data/third_party/boringssl/include/openssl/hmac.h +4 -4
  427. data/third_party/boringssl/include/openssl/hrss.h +100 -0
  428. data/third_party/boringssl/include/openssl/lhash.h +131 -23
  429. data/third_party/boringssl/include/openssl/md4.h +6 -4
  430. data/third_party/boringssl/include/openssl/md5.h +6 -4
  431. data/third_party/boringssl/include/openssl/mem.h +6 -2
  432. data/third_party/boringssl/include/openssl/nid.h +3 -0
  433. data/third_party/boringssl/include/openssl/obj.h +3 -0
  434. data/third_party/boringssl/include/openssl/pem.h +102 -64
  435. data/third_party/boringssl/include/openssl/pkcs7.h +136 -3
  436. data/third_party/boringssl/include/openssl/pkcs8.h +42 -3
  437. data/third_party/boringssl/include/openssl/pool.h +13 -2
  438. data/third_party/boringssl/include/openssl/ripemd.h +5 -4
  439. data/third_party/boringssl/include/openssl/rsa.h +46 -15
  440. data/third_party/boringssl/include/openssl/sha.h +40 -28
  441. data/third_party/boringssl/include/openssl/siphash.h +37 -0
  442. data/third_party/boringssl/include/openssl/span.h +17 -9
  443. data/third_party/boringssl/include/openssl/ssl.h +766 -393
  444. data/third_party/boringssl/include/openssl/ssl3.h +4 -3
  445. data/third_party/boringssl/include/openssl/stack.h +134 -77
  446. data/third_party/boringssl/include/openssl/thread.h +1 -1
  447. data/third_party/boringssl/include/openssl/tls1.h +25 -9
  448. data/third_party/boringssl/include/openssl/type_check.h +14 -15
  449. data/third_party/boringssl/include/openssl/x509.h +28 -3
  450. data/third_party/boringssl/include/openssl/x509_vfy.h +98 -32
  451. data/third_party/boringssl/include/openssl/x509v3.h +17 -13
  452. data/third_party/boringssl/ssl/d1_both.cc +9 -18
  453. data/third_party/boringssl/ssl/d1_lib.cc +4 -3
  454. data/third_party/boringssl/ssl/d1_pkt.cc +4 -4
  455. data/third_party/boringssl/ssl/d1_srtp.cc +15 -15
  456. data/third_party/boringssl/ssl/dtls_method.cc +0 -1
  457. data/third_party/boringssl/ssl/dtls_record.cc +28 -28
  458. data/third_party/boringssl/ssl/handoff.cc +295 -91
  459. data/third_party/boringssl/ssl/handshake.cc +133 -72
  460. data/third_party/boringssl/ssl/handshake_client.cc +218 -189
  461. data/third_party/boringssl/ssl/handshake_server.cc +399 -272
  462. data/third_party/boringssl/ssl/internal.h +1413 -928
  463. data/third_party/boringssl/ssl/s3_both.cc +175 -36
  464. data/third_party/boringssl/ssl/s3_lib.cc +9 -13
  465. data/third_party/boringssl/ssl/s3_pkt.cc +63 -29
  466. data/third_party/boringssl/ssl/ssl_aead_ctx.cc +55 -35
  467. data/third_party/boringssl/ssl/ssl_asn1.cc +57 -73
  468. data/third_party/boringssl/ssl/ssl_buffer.cc +13 -12
  469. data/third_party/boringssl/ssl/ssl_cert.cc +313 -210
  470. data/third_party/boringssl/ssl/ssl_cipher.cc +159 -221
  471. data/third_party/boringssl/ssl/ssl_file.cc +2 -0
  472. data/third_party/boringssl/ssl/ssl_key_share.cc +164 -19
  473. data/third_party/boringssl/ssl/ssl_lib.cc +847 -555
  474. data/third_party/boringssl/ssl/ssl_privkey.cc +441 -111
  475. data/third_party/boringssl/ssl/ssl_session.cc +230 -178
  476. data/third_party/boringssl/ssl/ssl_transcript.cc +21 -142
  477. data/third_party/boringssl/ssl/ssl_versions.cc +88 -93
  478. data/third_party/boringssl/ssl/ssl_x509.cc +279 -218
  479. data/third_party/boringssl/ssl/t1_enc.cc +5 -96
  480. data/third_party/boringssl/ssl/t1_lib.cc +931 -678
  481. data/third_party/boringssl/ssl/tls13_both.cc +251 -121
  482. data/third_party/boringssl/ssl/tls13_client.cc +129 -73
  483. data/third_party/boringssl/ssl/tls13_enc.cc +350 -282
  484. data/third_party/boringssl/ssl/tls13_server.cc +259 -192
  485. data/third_party/boringssl/ssl/tls_method.cc +26 -21
  486. data/third_party/boringssl/ssl/tls_record.cc +42 -47
  487. data/third_party/boringssl/third_party/fiat/curve25519.c +261 -1324
  488. data/third_party/boringssl/third_party/fiat/curve25519_32.h +911 -0
  489. data/third_party/boringssl/third_party/fiat/curve25519_64.h +559 -0
  490. data/third_party/boringssl/third_party/fiat/p256.c +238 -999
  491. data/third_party/boringssl/third_party/fiat/p256_32.h +3226 -0
  492. data/third_party/boringssl/third_party/fiat/p256_64.h +1217 -0
  493. data/third_party/upb/upb/port_def.inc +1 -1
  494. data/third_party/upb/upb/table.c +2 -1
  495. metadata +71 -43
  496. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +0 -127
  497. data/src/core/lib/gpr/mpscq.cc +0 -117
  498. data/src/core/lib/gpr/mpscq.h +0 -88
  499. data/src/core/lib/gprpp/abstract.h +0 -47
  500. data/src/core/lib/gprpp/pair.h +0 -38
  501. data/third_party/boringssl/crypto/cipher_extra/e_ssl3.c +0 -460
  502. data/third_party/boringssl/crypto/fipsmodule/modes/ccm.c +0 -256
  503. data/third_party/boringssl/include/openssl/lhash_macros.h +0 -174
  504. data/third_party/boringssl/ssl/custom_extensions.cc +0 -265
@@ -155,8 +155,8 @@
155
155
  #include <openssl/err.h>
156
156
  #include <openssl/lhash.h>
157
157
  #include <openssl/mem.h>
158
- #include <openssl/ssl.h>
159
158
  #include <openssl/span.h>
159
+ #include <openssl/ssl.h>
160
160
  #include <openssl/stack.h>
161
161
 
162
162
  #include "../crypto/err/internal.h"
@@ -173,10 +173,12 @@ OPENSSL_MSVC_PRAGMA(warning(pop))
173
173
  #endif
174
174
 
175
175
 
176
- namespace bssl {
176
+ BSSL_NAMESPACE_BEGIN
177
177
 
178
+ struct SSL_CONFIG;
178
179
  struct SSL_HANDSHAKE;
179
180
  struct SSL_PROTOCOL_METHOD;
181
+ struct SSL_X509_METHOD;
180
182
 
181
183
  // C++ utilities.
182
184
 
@@ -213,7 +215,7 @@ template <typename T>
213
215
  struct DeleterImpl<T, typename std::enable_if<T::kAllowUniquePtr>::type> {
214
216
  static void Free(T *t) { Delete(t); }
215
217
  };
216
- }
218
+ } // namespace internal
217
219
 
218
220
  // MakeUnique behaves like |std::make_unique| but returns nullptr on allocation
219
221
  // error.
@@ -235,7 +237,8 @@ UniquePtr<T> MakeUnique(Args &&... args) {
235
237
  // PURE_VIRTUAL should be used instead of = 0 when defining pure-virtual
236
238
  // functions. This avoids a dependency on |__cxa_pure_virtual| but loses
237
239
  // compile-time checking.
238
- #define PURE_VIRTUAL { abort(); }
240
+ #define PURE_VIRTUAL \
241
+ { abort(); }
239
242
  #endif
240
243
 
241
244
  // CONSTEXPR_ARRAY works around a VS 2015 bug where ranged for loops don't work
@@ -314,7 +317,7 @@ class Array {
314
317
  OPENSSL_PUT_ERROR(SSL, ERR_R_OVERFLOW);
315
318
  return false;
316
319
  }
317
- data_ = reinterpret_cast<T*>(OPENSSL_malloc(new_size * sizeof(T)));
320
+ data_ = reinterpret_cast<T *>(OPENSSL_malloc(new_size * sizeof(T)));
318
321
  if (data_ == nullptr) {
319
322
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
320
323
  return false;
@@ -328,27 +331,126 @@ class Array {
328
331
 
329
332
  // CopyFrom replaces the array with a newly-allocated copy of |in|. It returns
330
333
  // true on success and false on error.
331
- bool CopyFrom(Span<const uint8_t> in) {
334
+ bool CopyFrom(Span<const T> in) {
332
335
  if (!Init(in.size())) {
333
336
  return false;
334
337
  }
335
- OPENSSL_memcpy(data_, in.data(), in.size());
338
+ OPENSSL_memcpy(data_, in.data(), sizeof(T) * in.size());
336
339
  return true;
337
340
  }
338
341
 
342
+ // Shrink shrinks the stored size of the array to |new_size|. It crashes if
343
+ // the new size is larger. Note this does not shrink the allocation itself.
344
+ void Shrink(size_t new_size) {
345
+ if (new_size > size_) {
346
+ abort();
347
+ }
348
+ size_ = new_size;
349
+ }
350
+
339
351
  private:
340
352
  T *data_ = nullptr;
341
353
  size_t size_ = 0;
342
354
  };
343
355
 
356
+ // GrowableArray<T> is an array that owns elements of |T|, backed by an
357
+ // Array<T>. When necessary, pushing will automatically trigger a resize.
358
+ //
359
+ // Note, for simplicity, this class currently differs from |std::vector| in that
360
+ // |T| must be efficiently default-constructible. Allocated elements beyond the
361
+ // end of the array are constructed and destructed.
362
+ template <typename T>
363
+ class GrowableArray {
364
+ public:
365
+ GrowableArray() = default;
366
+ GrowableArray(const GrowableArray &) = delete;
367
+ GrowableArray(GrowableArray &&other) { *this = std::move(other); }
368
+ ~GrowableArray() {}
369
+
370
+ GrowableArray &operator=(const GrowableArray &) = delete;
371
+ GrowableArray &operator=(GrowableArray &&other) {
372
+ size_ = other.size_;
373
+ other.size_ = 0;
374
+ array_ = std::move(other.array_);
375
+ return *this;
376
+ }
377
+
378
+ size_t size() const { return size_; }
379
+ bool empty() const { return size_ == 0; }
380
+
381
+ const T &operator[](size_t i) const { return array_[i]; }
382
+ T &operator[](size_t i) { return array_[i]; }
383
+
384
+ T *begin() { return array_.data(); }
385
+ const T *cbegin() const { return array_.data(); }
386
+ T *end() { return array_.data() + size_; }
387
+ const T *cend() const { return array_.data() + size_; }
388
+
389
+ // Push adds |elem| at the end of the internal array, growing if necessary. It
390
+ // returns false when allocation fails.
391
+ bool Push(T elem) {
392
+ if (!MaybeGrow()) {
393
+ return false;
394
+ }
395
+ array_[size_] = std::move(elem);
396
+ size_++;
397
+ return true;
398
+ }
399
+
400
+ // CopyFrom replaces the contents of the array with a copy of |in|. It returns
401
+ // true on success and false on allocation error.
402
+ bool CopyFrom(Span<const T> in) {
403
+ if (!array_.CopyFrom(in)) {
404
+ return false;
405
+ }
406
+ size_ = in.size();
407
+ return true;
408
+ }
409
+
410
+ private:
411
+ // If there is no room for one more element, creates a new backing array with
412
+ // double the size of the old one and copies elements over.
413
+ bool MaybeGrow() {
414
+ if (array_.size() == 0) {
415
+ return array_.Init(kDefaultSize);
416
+ }
417
+ // No need to grow if we have room for one more T.
418
+ if (size_ < array_.size()) {
419
+ return true;
420
+ }
421
+ // Double the array's size if it's safe to do so.
422
+ if (array_.size() > std::numeric_limits<size_t>::max() / 2) {
423
+ OPENSSL_PUT_ERROR(SSL, ERR_R_OVERFLOW);
424
+ return false;
425
+ }
426
+ Array<T> new_array;
427
+ if (!new_array.Init(array_.size() * 2)) {
428
+ return false;
429
+ }
430
+ for (size_t i = 0; i < array_.size(); i++) {
431
+ new_array[i] = std::move(array_[i]);
432
+ }
433
+ array_ = std::move(new_array);
434
+
435
+ return true;
436
+ }
437
+
438
+ // |size_| is the number of elements stored in this GrowableArray.
439
+ size_t size_ = 0;
440
+ // |array_| is the backing array. Note that |array_.size()| is this
441
+ // GrowableArray's current capacity and that |size_ <= array_.size()|.
442
+ Array<T> array_;
443
+ // |kDefaultSize| is the default initial size of the backing array.
444
+ static constexpr size_t kDefaultSize = 16;
445
+ };
446
+
344
447
  // CBBFinishArray behaves like |CBB_finish| but stores the result in an Array.
345
448
  OPENSSL_EXPORT bool CBBFinishArray(CBB *cbb, Array<uint8_t> *out);
346
449
 
347
450
 
348
451
  // Protocol versions.
349
452
  //
350
- // Due to DTLS's historical wire version differences and to support multiple
351
- // variants of the same protocol during development, we maintain two notions of
453
+ // Due to DTLS's historical wire version differences, we maintain two notions of
352
454
  // version.
353
455
  //
354
456
  // The "version" or "wire version" is the actual 16-bit value that appears on
@@ -357,9 +459,8 @@ OPENSSL_EXPORT bool CBBFinishArray(CBB *cbb, Array<uint8_t> *out);
357
459
  // versions are opaque values and may not be compared numerically.
358
460
  //
359
461
  // The "protocol version" identifies the high-level handshake variant being
360
- // used. DTLS versions map to the corresponding TLS versions. Draft TLS 1.3
361
- // variants all map to TLS 1.3. Protocol versions are sequential and may be
362
- // compared numerically.
462
+ // used. DTLS versions map to the corresponding TLS versions. Protocol versions
463
+ // are sequential and may be compared numerically.
363
464
 
364
465
  // ssl_protocol_version_from_wire sets |*out| to the protocol version
365
466
  // corresponding to wire version |version| and returns true. If |version| is not
@@ -371,12 +472,16 @@ bool ssl_protocol_version_from_wire(uint16_t *out, uint16_t version);
371
472
 
372
473
  // ssl_get_version_range sets |*out_min_version| and |*out_max_version| to the
373
474
  // minimum and maximum enabled protocol versions, respectively.
374
- bool ssl_get_version_range(const SSL *ssl, uint16_t *out_min_version,
475
+ bool ssl_get_version_range(const SSL_HANDSHAKE *hs, uint16_t *out_min_version,
375
476
  uint16_t *out_max_version);
376
477
 
377
478
  // ssl_supports_version returns whether |hs| supports |version|.
378
479
  bool ssl_supports_version(SSL_HANDSHAKE *hs, uint16_t version);
379
480
 
481
+ // ssl_method_supports_version returns whether |method| supports |version|.
482
+ bool ssl_method_supports_version(const SSL_PROTOCOL_METHOD *method,
483
+ uint16_t version);
484
+
380
485
  // ssl_add_supported_versions writes the supported versions of |hs| to |cbb|, in
381
486
  // decreasing preference order.
382
487
  bool ssl_add_supported_versions(SSL_HANDSHAKE *hs, CBB *cbb);
@@ -394,7 +499,7 @@ uint16_t ssl_protocol_version(const SSL *ssl);
394
499
 
395
500
  // Cipher suites.
396
501
 
397
- } // namespace bssl
502
+ BSSL_NAMESPACE_END
398
503
 
399
504
  struct ssl_cipher_st {
400
505
  // name is the OpenSSL name for the cipher.
@@ -412,7 +517,7 @@ struct ssl_cipher_st {
412
517
  uint32_t algorithm_prf;
413
518
  };
414
519
 
415
- namespace bssl {
520
+ BSSL_NAMESPACE_BEGIN
416
521
 
417
522
  // Bits for |algorithm_mkey| (key exchange algorithm).
418
523
  #define SSL_kRSA 0x00000001u
@@ -431,31 +536,77 @@ namespace bssl {
431
536
  #define SSL_aCERT (SSL_aRSA | SSL_aECDSA)
432
537
 
433
538
  // Bits for |algorithm_enc| (symmetric encryption).
434
- #define SSL_3DES 0x00000001u
435
- #define SSL_AES128 0x00000002u
436
- #define SSL_AES256 0x00000004u
437
- #define SSL_AES128GCM 0x00000008u
438
- #define SSL_AES256GCM 0x00000010u
439
- #define SSL_eNULL 0x00000020u
440
- #define SSL_CHACHA20POLY1305 0x00000040u
539
+ #define SSL_3DES 0x00000001u
540
+ #define SSL_AES128 0x00000002u
541
+ #define SSL_AES256 0x00000004u
542
+ #define SSL_AES128GCM 0x00000008u
543
+ #define SSL_AES256GCM 0x00000010u
544
+ #define SSL_eNULL 0x00000020u
545
+ #define SSL_CHACHA20POLY1305 0x00000040u
441
546
 
442
547
  #define SSL_AES (SSL_AES128 | SSL_AES256 | SSL_AES128GCM | SSL_AES256GCM)
443
548
 
444
549
  // Bits for |algorithm_mac| (symmetric authentication).
445
550
  #define SSL_SHA1 0x00000001u
446
- #define SSL_SHA256 0x00000002u
447
- #define SSL_SHA384 0x00000004u
448
551
  // SSL_AEAD is set for all AEADs.
449
- #define SSL_AEAD 0x00000008u
552
+ #define SSL_AEAD 0x00000002u
450
553
 
451
554
  // Bits for |algorithm_prf| (handshake digest).
452
555
  #define SSL_HANDSHAKE_MAC_DEFAULT 0x1
453
556
  #define SSL_HANDSHAKE_MAC_SHA256 0x2
454
557
  #define SSL_HANDSHAKE_MAC_SHA384 0x4
455
558
 
456
- // SSL_MAX_DIGEST is the number of digest types which exist. When adding a new
457
- // one, update the table in ssl_cipher.c.
458
- #define SSL_MAX_DIGEST 4
559
+ // SSL_MAX_MD_SIZE is size of the largest hash function used in TLS, SHA-384.
560
+ #define SSL_MAX_MD_SIZE 48
561
+
562
+ // An SSLCipherPreferenceList contains a list of SSL_CIPHERs with equal-
563
+ // preference groups. For TLS clients, the groups are moot because the server
564
+ // picks the cipher and groups cannot be expressed on the wire. However, for
565
+ // servers, the equal-preference groups allow the client's preferences to be
566
+ // partially respected. (This only has an effect with
567
+ // SSL_OP_CIPHER_SERVER_PREFERENCE).
568
+ //
569
+ // The equal-preference groups are expressed by grouping SSL_CIPHERs together.
570
+ // All elements of a group have the same priority: no ordering is expressed
571
+ // within a group.
572
+ //
573
+ // The values in |ciphers| are in one-to-one correspondence with
574
+ // |in_group_flags|. (That is, sk_SSL_CIPHER_num(ciphers) is the number of
575
+ // bytes in |in_group_flags|.) The bytes in |in_group_flags| are either 1, to
576
+ // indicate that the corresponding SSL_CIPHER is not the last element of a
577
+ // group, or 0 to indicate that it is.
578
+ //
579
+ // For example, if |in_group_flags| contains all zeros then that indicates a
580
+ // traditional, fully-ordered preference. Every SSL_CIPHER is the last element
581
+ // of the group (i.e. they are all in a one-element group).
582
+ //
583
+ // For a more complex example, consider:
584
+ // ciphers: A B C D E F
585
+ // in_group_flags: 1 1 0 0 1 0
586
+ //
587
+ // That would express the following, order:
588
+ //
589
+ // A E
590
+ // B -> D -> F
591
+ // C
592
+ struct SSLCipherPreferenceList {
593
+ static constexpr bool kAllowUniquePtr = true;
594
+
595
+ SSLCipherPreferenceList() = default;
596
+ ~SSLCipherPreferenceList();
597
+
598
+ bool Init(UniquePtr<STACK_OF(SSL_CIPHER)> ciphers,
599
+ Span<const bool> in_group_flags);
600
+ bool Init(const SSLCipherPreferenceList &);
601
+
602
+ void Remove(const SSL_CIPHER *cipher);
603
+
604
+ UniquePtr<STACK_OF(SSL_CIPHER)> ciphers;
605
+ bool *in_group_flags = nullptr;
606
+ };
607
+
608
+ // AllCiphers returns an array of all supported ciphers, sorted by id.
609
+ Span<const SSL_CIPHER> AllCiphers();
459
610
 
460
611
  // ssl_cipher_get_evp_aead sets |*out_aead| to point to the correct EVP_AEAD
461
612
  // object for |cipher| protocol version |version|. It sets |*out_mac_secret_len|
@@ -465,7 +616,7 @@ namespace bssl {
465
616
  bool ssl_cipher_get_evp_aead(const EVP_AEAD **out_aead,
466
617
  size_t *out_mac_secret_len,
467
618
  size_t *out_fixed_iv_len, const SSL_CIPHER *cipher,
468
- uint16_t version, int is_dtls);
619
+ uint16_t version, bool is_dtls);
469
620
 
470
621
  // ssl_get_handshake_digest returns the |EVP_MD| corresponding to |version| and
471
622
  // |cipher|.
@@ -473,13 +624,12 @@ const EVP_MD *ssl_get_handshake_digest(uint16_t version,
473
624
  const SSL_CIPHER *cipher);
474
625
 
475
626
  // ssl_create_cipher_list evaluates |rule_str|. It sets |*out_cipher_list| to a
476
- // newly-allocated |ssl_cipher_preference_list_st| containing the result. It
477
- // returns true on success and false on failure. If |strict| is true, nonsense
478
- // will be rejected. If false, nonsense will be silently ignored. An empty
479
- // result is considered an error regardless of |strict|.
480
- bool ssl_create_cipher_list(
481
- struct ssl_cipher_preference_list_st **out_cipher_list,
482
- const char *rule_str, bool strict);
627
+ // newly-allocated |SSLCipherPreferenceList| containing the result. It returns
628
+ // true on success and false on failure. If |strict| is true, nonsense will be
629
+ // rejected. If false, nonsense will be silently ignored. An empty result is
630
+ // considered an error regardless of |strict|.
631
+ bool ssl_create_cipher_list(UniquePtr<SSLCipherPreferenceList> *out_cipher_list,
632
+ const char *rule_str, bool strict);
483
633
 
484
634
  // ssl_cipher_get_value returns the cipher suite id of |cipher|.
485
635
  uint16_t ssl_cipher_get_value(const SSL_CIPHER *cipher);
@@ -504,6 +654,12 @@ bool ssl_cipher_requires_server_key_exchange(const SSL_CIPHER *cipher);
504
654
  // it returns zero.
505
655
  size_t ssl_cipher_get_record_split_len(const SSL_CIPHER *cipher);
506
656
 
657
+ // ssl_choose_tls13_cipher returns an |SSL_CIPHER| corresponding with the best
658
+ // available from |cipher_suites| compatible with |version| and |group_id|. It
659
+ // returns NULL if there isn't a compatible cipher.
660
+ const SSL_CIPHER *ssl_choose_tls13_cipher(CBS cipher_suites, uint16_t version,
661
+ uint16_t group_id);
662
+
507
663
 
508
664
  // Transcript layer.
509
665
 
@@ -531,9 +687,11 @@ class SSLTranscript {
531
687
  // is released.
532
688
  bool UpdateForHelloRetryRequest();
533
689
 
534
- // CopyHashContext copies the hash context into |ctx| and returns true on
535
- // success.
536
- bool CopyHashContext(EVP_MD_CTX *ctx);
690
+ // CopyToHashContext initializes |ctx| with |digest| and the data thus far in
691
+ // the transcript. It returns true on success and false on failure. If the
692
+ // handshake buffer is still present, |digest| may be any supported digest.
693
+ // Otherwise, |digest| must match the transcript hash.
694
+ bool CopyToHashContext(EVP_MD_CTX *ctx, const EVP_MD *digest);
537
695
 
538
696
  Span<const uint8_t> buffer() {
539
697
  return MakeConstSpan(reinterpret_cast<const uint8_t *>(buffer_->data),
@@ -560,14 +718,6 @@ class SSLTranscript {
560
718
  // the number of bytes written. Otherwise, it returns false.
561
719
  bool GetHash(uint8_t *out, size_t *out_len);
562
720
 
563
- // GetSSL3CertVerifyHash writes the SSL 3.0 CertificateVerify hash into the
564
- // bytes pointed to by |out| and writes the number of bytes to
565
- // |*out_len|. |out| must have room for |EVP_MAX_MD_SIZE| bytes. It returns
566
- // one on success and zero on failure.
567
- bool GetSSL3CertVerifyHash(uint8_t *out, size_t *out_len,
568
- const SSL_SESSION *session,
569
- uint16_t signature_algorithm);
570
-
571
721
  // GetFinishedMAC computes the MAC for the Finished message into the bytes
572
722
  // pointed by |out| and writes the number of bytes to |*out_len|. |out| must
573
723
  // have room for |EVP_MAX_MD_SIZE| bytes. It returns true on success and false
@@ -578,12 +728,8 @@ class SSLTranscript {
578
728
  private:
579
729
  // buffer_, if non-null, contains the handshake transcript.
580
730
  UniquePtr<BUF_MEM> buffer_;
581
- // hash, if initialized with an |EVP_MD|, maintains the handshake hash. For
582
- // TLS 1.1 and below, it is the SHA-1 half.
731
+ // hash, if initialized with an |EVP_MD|, maintains the handshake hash.
583
732
  ScopedEVP_MD_CTX hash_;
584
- // md5, if initialized with an |EVP_MD|, maintains the MD5 half of the
585
- // handshake hash for TLS 1.1 and below.
586
- ScopedEVP_MD_CTX md5_;
587
733
  };
588
734
 
589
735
  // tls1_prf computes the PRF function for |ssl|. It fills |out|, using |secret|
@@ -615,12 +761,18 @@ class SSLAEADContext {
615
761
  // resulting object, depending on |direction|. |version| is the normalized
616
762
  // protocol version, so DTLS 1.0 is represented as 0x0301, not 0xffef.
617
763
  static UniquePtr<SSLAEADContext> Create(enum evp_aead_direction_t direction,
618
- uint16_t version, int is_dtls,
764
+ uint16_t version, bool is_dtls,
619
765
  const SSL_CIPHER *cipher,
620
766
  Span<const uint8_t> enc_key,
621
767
  Span<const uint8_t> mac_key,
622
768
  Span<const uint8_t> fixed_iv);
623
769
 
770
+ // CreatePlaceholderForQUIC creates a placeholder |SSLAEADContext| for the
771
+ // given cipher and version. The resulting object can be queried for various
772
+ // properties but cannot encrypt or decrypt data.
773
+ static UniquePtr<SSLAEADContext> CreatePlaceholderForQUIC(
774
+ uint16_t version, const SSL_CIPHER *cipher);
775
+
624
776
  // SetVersionIfNullCipher sets the version the SSLAEADContext for the null
625
777
  // cipher, to make version-specific determinations in the record layer prior
626
778
  // to a cipher being selected.
@@ -653,19 +805,26 @@ class SSLAEADContext {
653
805
  bool SuffixLen(size_t *out_suffix_len, size_t in_len,
654
806
  size_t extra_in_len) const;
655
807
 
808
+ // CiphertextLen calculates the total ciphertext length written by
809
+ // |SealScatter| and writes it to |*out_len|. It returns true on success and
810
+ // false on error. |in_len| and |extra_in_len| should equal the argument of
811
+ // the same names passed to |SealScatter|.
812
+ bool CiphertextLen(size_t *out_len, size_t in_len, size_t extra_in_len) const;
813
+
656
814
  // Open authenticates and decrypts |in| in-place. On success, it sets |*out|
657
815
  // to the plaintext in |in| and returns true. Otherwise, it returns
658
816
  // false. The output will always be |ExplicitNonceLen| bytes ahead of |in|.
659
817
  bool Open(Span<uint8_t> *out, uint8_t type, uint16_t record_version,
660
- const uint8_t seqnum[8], Span<uint8_t> in);
818
+ const uint8_t seqnum[8], Span<const uint8_t> header,
819
+ Span<uint8_t> in);
661
820
 
662
821
  // Seal encrypts and authenticates |in_len| bytes from |in| and writes the
663
822
  // result to |out|. It returns true on success and false on error.
664
823
  //
665
824
  // If |in| and |out| alias then |out| + |ExplicitNonceLen| must be == |in|.
666
825
  bool Seal(uint8_t *out, size_t *out_len, size_t max_out, uint8_t type,
667
- uint16_t record_version, const uint8_t seqnum[8], const uint8_t *in,
668
- size_t in_len);
826
+ uint16_t record_version, const uint8_t seqnum[8],
827
+ Span<const uint8_t> header, const uint8_t *in, size_t in_len);
669
828
 
670
829
  // SealScatter encrypts and authenticates |in_len| bytes from |in| and splits
671
830
  // the result between |out_prefix|, |out| and |out_suffix|. It returns one on
@@ -684,17 +843,20 @@ class SSLAEADContext {
684
843
  // alias anything.
685
844
  bool SealScatter(uint8_t *out_prefix, uint8_t *out, uint8_t *out_suffix,
686
845
  uint8_t type, uint16_t record_version,
687
- const uint8_t seqnum[8], const uint8_t *in, size_t in_len,
688
- const uint8_t *extra_in, size_t extra_in_len);
846
+ const uint8_t seqnum[8], Span<const uint8_t> header,
847
+ const uint8_t *in, size_t in_len, const uint8_t *extra_in,
848
+ size_t extra_in_len);
689
849
 
690
850
  bool GetIV(const uint8_t **out_iv, size_t *out_iv_len) const;
691
851
 
692
852
  private:
693
- // GetAdditionalData writes the additional data into |out| and returns the
694
- // number of bytes written.
695
- size_t GetAdditionalData(uint8_t out[13], uint8_t type,
696
- uint16_t record_version, const uint8_t seqnum[8],
697
- size_t plaintext_len);
853
+ // GetAdditionalData returns the additional data, writing into |storage| if
854
+ // necessary.
855
+ Span<const uint8_t> GetAdditionalData(uint8_t storage[13], uint8_t type,
856
+ uint16_t record_version,
857
+ const uint8_t seqnum[8],
858
+ size_t plaintext_len,
859
+ Span<const uint8_t> header);
698
860
 
699
861
  const SSL_CIPHER *cipher_;
700
862
  ScopedEVP_AEAD_CTX ctx_;
@@ -713,17 +875,14 @@ class SSLAEADContext {
713
875
  // randomly generated, rather than derived from the sequence
714
876
  // number.
715
877
  bool random_variable_nonce_ : 1;
716
- // omit_length_in_ad_ is true if the length should be omitted in the
717
- // AEAD's ad parameter.
718
- bool omit_length_in_ad_ : 1;
719
- // omit_version_in_ad_ is true if the version should be omitted
720
- // in the AEAD's ad parameter.
721
- bool omit_version_in_ad_ : 1;
722
- // omit_ad_ is true if the AEAD's ad parameter should be omitted.
723
- bool omit_ad_ : 1;
724
878
  // xor_fixed_nonce_ is true if the fixed nonce should be XOR'd into the
725
879
  // variable nonce rather than prepended.
726
880
  bool xor_fixed_nonce_ : 1;
881
+ // omit_length_in_ad_ is true if the length should be omitted in the
882
+ // AEAD's ad parameter.
883
+ bool omit_length_in_ad_ : 1;
884
+ // ad_is_header_ is true if the AEAD's ad parameter is the record header.
885
+ bool ad_is_header_ : 1;
727
886
  };
728
887
 
729
888
 
@@ -744,8 +903,8 @@ struct DTLS1_BITMAP {
744
903
  // Record layer.
745
904
 
746
905
  // ssl_record_sequence_update increments the sequence number in |seq|. It
747
- // returns one on success and zero on wraparound.
748
- int ssl_record_sequence_update(uint8_t *seq, size_t seq_len);
906
+ // returns true on success and false on wraparound.
907
+ bool ssl_record_sequence_update(uint8_t *seq, size_t seq_len);
749
908
 
750
909
  // ssl_record_prefix_len returns the length of the prefix before the ciphertext
751
910
  // of a record for |ssl|.
@@ -810,9 +969,9 @@ enum ssl_open_record_t dtls_open_record(SSL *ssl, uint8_t *out_type,
810
969
  size_t ssl_seal_align_prefix_len(const SSL *ssl);
811
970
 
812
971
  // tls_seal_record seals a new record of type |type| and body |in| and writes it
813
- // to |out|. At most |max_out| bytes will be written. It returns one on success
814
- // and zero on error. If enabled, |tls_seal_record| implements TLS 1.0 CBC 1/n-1
815
- // record splitting and may write two records concatenated.
972
+ // to |out|. At most |max_out| bytes will be written. It returns true on success
973
+ // and false on error. If enabled, |tls_seal_record| implements TLS 1.0 CBC
974
+ // 1/n-1 record splitting and may write two records concatenated.
816
975
  //
817
976
  // For a large record, the bulk of the ciphertext will begin
818
977
  // |ssl_seal_align_prefix_len| bytes into out. Aligning |out| appropriately may
@@ -820,8 +979,8 @@ size_t ssl_seal_align_prefix_len(const SSL *ssl);
820
979
  // bytes to |out|.
821
980
  //
822
981
  // |in| and |out| may not alias.
823
- int tls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
824
- uint8_t type, const uint8_t *in, size_t in_len);
982
+ bool tls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
983
+ uint8_t type, const uint8_t *in, size_t in_len);
825
984
 
826
985
  enum dtls1_use_epoch_t {
827
986
  dtls1_use_previous_epoch,
@@ -840,9 +999,9 @@ size_t dtls_seal_prefix_len(const SSL *ssl, enum dtls1_use_epoch_t use_epoch);
840
999
  // which epoch's cipher state to use. Unlike |tls_seal_record|, |in| and |out|
841
1000
  // may alias but, if they do, |in| must be exactly |dtls_seal_prefix_len| bytes
842
1001
  // ahead of |out|.
843
- int dtls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
844
- uint8_t type, const uint8_t *in, size_t in_len,
845
- enum dtls1_use_epoch_t use_epoch);
1002
+ bool dtls_seal_record(SSL *ssl, uint8_t *out, size_t *out_len, size_t max_out,
1003
+ uint8_t type, const uint8_t *in, size_t in_len,
1004
+ enum dtls1_use_epoch_t use_epoch);
846
1005
 
847
1006
  // ssl_process_alert processes |in| as an alert and updates |ssl|'s shutdown
848
1007
  // state. It returns one of |ssl_open_record_discard|, |ssl_open_record_error|,
@@ -854,9 +1013,8 @@ enum ssl_open_record_t ssl_process_alert(SSL *ssl, uint8_t *out_alert,
854
1013
 
855
1014
  // Private key operations.
856
1015
 
857
- // ssl_has_private_key returns one if |ssl| has a private key
858
- // configured and zero otherwise.
859
- int ssl_has_private_key(const SSL *ssl);
1016
+ // ssl_has_private_key returns whether |hs| has a private key configured.
1017
+ bool ssl_has_private_key(const SSL_HANDSHAKE *hs);
860
1018
 
861
1019
  // ssl_private_key_* perform the corresponding operation on
862
1020
  // |SSL_PRIVATE_KEY_METHOD|. If there is a custom private key configured, they
@@ -877,7 +1035,7 @@ enum ssl_private_key_result_t ssl_private_key_decrypt(SSL_HANDSHAKE *hs,
877
1035
  // ssl_private_key_supports_signature_algorithm returns whether |hs|'s private
878
1036
  // key supports |sigalg|.
879
1037
  bool ssl_private_key_supports_signature_algorithm(SSL_HANDSHAKE *hs,
880
- uint16_t sigalg);
1038
+ uint16_t sigalg);
881
1039
 
882
1040
  // ssl_public_key_verify verifies that the |signature| is valid for the public
883
1041
  // key |pkey| and input |in|, using the signature algorithm |sigalg|.
@@ -886,36 +1044,6 @@ bool ssl_public_key_verify(SSL *ssl, Span<const uint8_t> signature,
886
1044
  Span<const uint8_t> in);
887
1045
 
888
1046
 
889
- // Custom extensions
890
-
891
- } // namespace bssl
892
-
893
- // |SSL_CUSTOM_EXTENSION| is a structure that contains information about
894
- // custom-extension callbacks. It is defined unnamespaced for compatibility with
895
- // |STACK_OF(SSL_CUSTOM_EXTENSION)|.
896
- typedef struct ssl_custom_extension {
897
- SSL_custom_ext_add_cb add_callback;
898
- void *add_arg;
899
- SSL_custom_ext_free_cb free_callback;
900
- SSL_custom_ext_parse_cb parse_callback;
901
- void *parse_arg;
902
- uint16_t value;
903
- } SSL_CUSTOM_EXTENSION;
904
-
905
- DEFINE_STACK_OF(SSL_CUSTOM_EXTENSION)
906
-
907
- namespace bssl {
908
-
909
- void SSL_CUSTOM_EXTENSION_free(SSL_CUSTOM_EXTENSION *custom_extension);
910
-
911
- int custom_ext_add_clienthello(SSL_HANDSHAKE *hs, CBB *extensions);
912
- int custom_ext_parse_serverhello(SSL_HANDSHAKE *hs, int *out_alert,
913
- uint16_t value, const CBS *extension);
914
- int custom_ext_parse_clienthello(SSL_HANDSHAKE *hs, int *out_alert,
915
- uint16_t value, const CBS *extension);
916
- int custom_ext_add_serverhello(SSL_HANDSHAKE *hs, CBB *extensions);
917
-
918
-
919
1047
  // Key shares.
920
1048
 
921
1049
  // SSLKeyShare abstracts over Diffie-Hellman-like key exchanges.
@@ -929,6 +1057,10 @@ class SSLKeyShare {
929
1057
  // nullptr on error.
930
1058
  static UniquePtr<SSLKeyShare> Create(uint16_t group_id);
931
1059
 
1060
+ // Create deserializes an SSLKeyShare instance previously serialized by
1061
+ // |Serialize|.
1062
+ static UniquePtr<SSLKeyShare> Create(CBS *in);
1063
+
932
1064
  // GroupID returns the group ID.
933
1065
  virtual uint16_t GroupID() const PURE_VIRTUAL;
934
1066
 
@@ -936,10 +1068,10 @@ class SSLKeyShare {
936
1068
  // |out_public_key|. It returns true on success and false on error.
937
1069
  virtual bool Offer(CBB *out_public_key) PURE_VIRTUAL;
938
1070
 
939
- // Accept performs a key exchange against the |peer_key| generated by |offer|.
1071
+ // Accept performs a key exchange against the |peer_key| generated by |Offer|.
940
1072
  // On success, it returns true, writes the public value to |out_public_key|,
941
- // and sets |*out_secret| the shared secret. On failure, it returns false and
942
- // sets |*out_alert| to an alert to send to the peer.
1073
+ // and sets |*out_secret| to the shared secret. On failure, it returns false
1074
+ // and sets |*out_alert| to an alert to send to the peer.
943
1075
  //
944
1076
  // The default implementation calls |Offer| and then |Finish|, assuming a key
945
1077
  // exchange protocol where the peers are symmetric.
@@ -948,21 +1080,38 @@ class SSLKeyShare {
948
1080
 
949
1081
  // Finish performs a key exchange against the |peer_key| generated by
950
1082
  // |Accept|. On success, it returns true and sets |*out_secret| to the shared
951
- // secret. On failure, it returns zero and sets |*out_alert| to an alert to
1083
+ // secret. On failure, it returns false and sets |*out_alert| to an alert to
952
1084
  // send to the peer.
953
1085
  virtual bool Finish(Array<uint8_t> *out_secret, uint8_t *out_alert,
954
1086
  Span<const uint8_t> peer_key) PURE_VIRTUAL;
1087
+
1088
+ // Serialize writes the state of the key exchange to |out|, returning true if
1089
+ // successful and false otherwise.
1090
+ virtual bool Serialize(CBB *out) { return false; }
1091
+
1092
+ // Deserialize initializes the state of the key exchange from |in|, returning
1093
+ // true if successful and false otherwise. It is called by |Create|.
1094
+ virtual bool Deserialize(CBS *in) { return false; }
955
1095
  };
956
1096
 
1097
+ struct NamedGroup {
1098
+ int nid;
1099
+ uint16_t group_id;
1100
+ const char name[8], alias[11];
1101
+ };
1102
+
1103
+ // NamedGroups returns all supported groups.
1104
+ Span<const NamedGroup> NamedGroups();
1105
+
957
1106
  // ssl_nid_to_group_id looks up the group corresponding to |nid|. On success, it
958
- // sets |*out_group_id| to the group ID and returns one. Otherwise, it returns
959
- // zero.
960
- int ssl_nid_to_group_id(uint16_t *out_group_id, int nid);
1107
+ // sets |*out_group_id| to the group ID and returns true. Otherwise, it returns
1108
+ // false.
1109
+ bool ssl_nid_to_group_id(uint16_t *out_group_id, int nid);
961
1110
 
962
- // ssl_name_to_group_id looks up the group corresponding to the |name| string
963
- // of length |len|. On success, it sets |*out_group_id| to the group ID and
964
- // returns one. Otherwise, it returns zero.
965
- int ssl_name_to_group_id(uint16_t *out_group_id, const char *name, size_t len);
1111
+ // ssl_name_to_group_id looks up the group corresponding to the |name| string of
1112
+ // length |len|. On success, it sets |*out_group_id| to the group ID and returns
1113
+ // true. Otherwise, it returns false.
1114
+ bool ssl_name_to_group_id(uint16_t *out_group_id, const char *name, size_t len);
966
1115
 
967
1116
 
968
1117
  // Handshake messages.
@@ -983,7 +1132,9 @@ struct SSLMessage {
983
1132
  #define SSL_MAX_HANDSHAKE_FLIGHT 7
984
1133
 
985
1134
  extern const uint8_t kHelloRetryRequest[SSL3_RANDOM_SIZE];
986
- extern const uint8_t kDraftDowngradeRandom[8];
1135
+ extern const uint8_t kTLS12DowngradeRandom[8];
1136
+ extern const uint8_t kTLS13DowngradeRandom[8];
1137
+ extern const uint8_t kJDK11DowngradeRandom[8];
987
1138
 
988
1139
  // ssl_max_handshake_message_len returns the maximum number of bytes permitted
989
1140
  // in a handshake message for |ssl|.
@@ -997,10 +1148,17 @@ bool tls_can_accept_handshake_data(const SSL *ssl, uint8_t *out_alert);
997
1148
  // handshake data that has not been consumed by |get_message|.
998
1149
  bool tls_has_unprocessed_handshake_data(const SSL *ssl);
999
1150
 
1151
+ // tls_append_handshake_data appends |data| to the handshake buffer. It returns
1152
+ // true on success and false on allocation failure.
1153
+ bool tls_append_handshake_data(SSL *ssl, Span<const uint8_t> data);
1154
+
1000
1155
  // dtls_has_unprocessed_handshake_data behaves like
1001
1156
  // |tls_has_unprocessed_handshake_data| for DTLS.
1002
1157
  bool dtls_has_unprocessed_handshake_data(const SSL *ssl);
1003
1158
 
1159
+ // tls_flush_pending_hs_data flushes any handshake plaintext data.
1160
+ bool tls_flush_pending_hs_data(SSL *ssl);
1161
+
1004
1162
  struct DTLS_OUTGOING_MESSAGE {
1005
1163
  DTLS_OUTGOING_MESSAGE() {}
1006
1164
  DTLS_OUTGOING_MESSAGE(const DTLS_OUTGOING_MESSAGE &) = delete;
@@ -1025,7 +1183,7 @@ void dtls_clear_outgoing_messages(SSL *ssl);
1025
1183
  void ssl_do_info_callback(const SSL *ssl, int type, int value);
1026
1184
 
1027
1185
  // ssl_do_msg_callback calls |ssl|'s message callback, if set.
1028
- void ssl_do_msg_callback(SSL *ssl, int is_write, int content_type,
1186
+ void ssl_do_msg_callback(const SSL *ssl, int is_write, int content_type,
1029
1187
  Span<const uint8_t> in);
1030
1188
 
1031
1189
 
@@ -1107,9 +1265,9 @@ int ssl_write_buffer_flush(SSL *ssl);
1107
1265
 
1108
1266
  // Certificate functions.
1109
1267
 
1110
- // ssl_has_certificate returns one if a certificate and private key are
1111
- // configured and zero otherwise.
1112
- int ssl_has_certificate(const SSL *ssl);
1268
+ // ssl_has_certificate returns whether a certificate and private key are
1269
+ // configured.
1270
+ bool ssl_has_certificate(const SSL_HANDSHAKE *hs);
1113
1271
 
1114
1272
  // ssl_parse_cert_chain parses a certificate list from |cbs| in the format used
1115
1273
  // by a TLS Certificate message. On success, it advances |cbs| and returns
@@ -1128,16 +1286,20 @@ bool ssl_parse_cert_chain(uint8_t *out_alert,
1128
1286
  uint8_t *out_leaf_sha256, CBS *cbs,
1129
1287
  CRYPTO_BUFFER_POOL *pool);
1130
1288
 
1131
- // ssl_add_cert_chain adds |ssl|'s certificate chain to |cbb| in the format used
1132
- // by a TLS Certificate message. If there is no certificate chain, it emits an
1133
- // empty certificate list. It returns one on success and zero on error.
1134
- int ssl_add_cert_chain(SSL *ssl, CBB *cbb);
1289
+ // ssl_add_cert_chain adds |hs->ssl|'s certificate chain to |cbb| in the format
1290
+ // used by a TLS Certificate message. If there is no certificate chain, it emits
1291
+ // an empty certificate list. It returns true on success and false on error.
1292
+ bool ssl_add_cert_chain(SSL_HANDSHAKE *hs, CBB *cbb);
1293
+
1294
+ enum ssl_key_usage_t {
1295
+ key_usage_digital_signature = 0,
1296
+ key_usage_encipherment = 2,
1297
+ };
1135
1298
 
1136
- // ssl_cert_check_digital_signature_key_usage parses the DER-encoded, X.509
1137
- // certificate in |in| and returns one if doesn't specify a key usage or, if it
1138
- // does, if it includes digitalSignature. Otherwise it pushes to the error
1139
- // queue and returns zero.
1140
- int ssl_cert_check_digital_signature_key_usage(const CBS *in);
1299
+ // ssl_cert_check_key_usage parses the DER-encoded, X.509 certificate in |in|
1300
+ // and returns true if doesn't specify a key usage or, if it does, if it
1301
+ // includes |bit|. Otherwise it pushes to the error queue and returns false.
1302
+ bool ssl_cert_check_key_usage(const CBS *in, enum ssl_key_usage_t bit);
1141
1303
 
1142
1304
  // ssl_cert_parse_pubkey extracts the public key from the DER-encoded, X.509
1143
1305
  // certificate in |in|. It returns an allocated |EVP_PKEY| or else returns
@@ -1153,83 +1315,88 @@ UniquePtr<STACK_OF(CRYPTO_BUFFER)> ssl_parse_client_CA_list(SSL *ssl,
1153
1315
  CBS *cbs);
1154
1316
 
1155
1317
  // ssl_has_client_CAs returns there are configured CAs.
1156
- bool ssl_has_client_CAs(SSL *ssl);
1318
+ bool ssl_has_client_CAs(const SSL_CONFIG *cfg);
1157
1319
 
1158
1320
  // ssl_add_client_CA_list adds the configured CA list to |cbb| in the format
1159
- // used by a TLS CertificateRequest message. It returns one on success and zero
1160
- // on error.
1161
- int ssl_add_client_CA_list(SSL *ssl, CBB *cbb);
1321
+ // used by a TLS CertificateRequest message. It returns true on success and
1322
+ // false on error.
1323
+ bool ssl_add_client_CA_list(SSL_HANDSHAKE *hs, CBB *cbb);
1162
1324
 
1163
1325
  // ssl_check_leaf_certificate returns one if |pkey| and |leaf| are suitable as
1164
1326
  // a server's leaf certificate for |hs|. Otherwise, it returns zero and pushes
1165
1327
  // an error on the error queue.
1166
- int ssl_check_leaf_certificate(SSL_HANDSHAKE *hs, EVP_PKEY *pkey,
1328
+ bool ssl_check_leaf_certificate(SSL_HANDSHAKE *hs, EVP_PKEY *pkey,
1167
1329
  const CRYPTO_BUFFER *leaf);
1168
1330
 
1169
1331
  // ssl_on_certificate_selected is called once the certificate has been selected.
1170
1332
  // It finalizes the certificate and initializes |hs->local_pubkey|. It returns
1171
- // one on success and zero on error.
1172
- int ssl_on_certificate_selected(SSL_HANDSHAKE *hs);
1333
+ // true on success and false on error.
1334
+ bool ssl_on_certificate_selected(SSL_HANDSHAKE *hs);
1173
1335
 
1174
1336
 
1175
1337
  // TLS 1.3 key derivation.
1176
1338
 
1177
1339
  // tls13_init_key_schedule initializes the handshake hash and key derivation
1178
1340
  // state, and incorporates the PSK. The cipher suite and PRF hash must have been
1179
- // selected at this point. It returns one on success and zero on error.
1180
- int tls13_init_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *psk,
1181
- size_t psk_len);
1341
+ // selected at this point. It returns true on success and false on error.
1342
+ bool tls13_init_key_schedule(SSL_HANDSHAKE *hs, Span<const uint8_t> psk);
1182
1343
 
1183
1344
  // tls13_init_early_key_schedule initializes the handshake hash and key
1184
1345
  // derivation state from the resumption secret and incorporates the PSK to
1185
1346
  // derive the early secrets. It returns one on success and zero on error.
1186
- int tls13_init_early_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *psk,
1187
- size_t psk_len);
1347
+ bool tls13_init_early_key_schedule(SSL_HANDSHAKE *hs, Span<const uint8_t> psk);
1188
1348
 
1189
1349
  // tls13_advance_key_schedule incorporates |in| into the key schedule with
1190
- // HKDF-Extract. It returns one on success and zero on error.
1191
- int tls13_advance_key_schedule(SSL_HANDSHAKE *hs, const uint8_t *in,
1192
- size_t len);
1350
+ // HKDF-Extract. It returns true on success and false on error.
1351
+ bool tls13_advance_key_schedule(SSL_HANDSHAKE *hs, Span<const uint8_t> in);
1193
1352
 
1194
1353
  // tls13_set_traffic_key sets the read or write traffic keys to
1195
- // |traffic_secret|. It returns one on success and zero on error.
1196
- int tls13_set_traffic_key(SSL *ssl, enum evp_aead_direction_t direction,
1197
- const uint8_t *traffic_secret,
1198
- size_t traffic_secret_len);
1199
-
1200
- // tls13_derive_early_secrets derives the early traffic secret. It returns one
1201
- // on success and zero on error.
1202
- int tls13_derive_early_secrets(SSL_HANDSHAKE *hs);
1354
+ // |traffic_secret|. It returns true on success and false on error.
1355
+ bool tls13_set_traffic_key(SSL *ssl, enum ssl_encryption_level_t level,
1356
+ enum evp_aead_direction_t direction,
1357
+ Span<const uint8_t> traffic_secret);
1358
+
1359
+ // tls13_derive_early_secret derives the early traffic secret. It returns true
1360
+ // on success and false on error. Unlike with other traffic secrets, this
1361
+ // function does not pass the keys to QUIC. Call
1362
+ // |tls13_set_early_secret_for_quic| to do so. This is done to due to an
1363
+ // ordering complication around resolving HelloRetryRequest on the server.
1364
+ bool tls13_derive_early_secret(SSL_HANDSHAKE *hs);
1365
+
1366
+ // tls13_set_early_secret_for_quic passes the early traffic secrets, as
1367
+ // derived by |tls13_derive_early_secret|, to QUIC. It returns true on success
1368
+ // and false on error.
1369
+ bool tls13_set_early_secret_for_quic(SSL_HANDSHAKE *hs);
1203
1370
 
1204
1371
  // tls13_derive_handshake_secrets derives the handshake traffic secret. It
1205
- // returns one on success and zero on error.
1206
- int tls13_derive_handshake_secrets(SSL_HANDSHAKE *hs);
1372
+ // returns true on success and false on error.
1373
+ bool tls13_derive_handshake_secrets(SSL_HANDSHAKE *hs);
1207
1374
 
1208
1375
  // tls13_rotate_traffic_key derives the next read or write traffic secret. It
1209
- // returns one on success and zero on error.
1210
- int tls13_rotate_traffic_key(SSL *ssl, enum evp_aead_direction_t direction);
1376
+ // returns true on success and false on error.
1377
+ bool tls13_rotate_traffic_key(SSL *ssl, enum evp_aead_direction_t direction);
1211
1378
 
1212
1379
  // tls13_derive_application_secrets derives the initial application data traffic
1213
1380
  // and exporter secrets based on the handshake transcripts and |master_secret|.
1214
- // It returns one on success and zero on error.
1215
- int tls13_derive_application_secrets(SSL_HANDSHAKE *hs);
1381
+ // It returns true on success and false on error.
1382
+ bool tls13_derive_application_secrets(SSL_HANDSHAKE *hs);
1216
1383
 
1217
1384
  // tls13_derive_resumption_secret derives the |resumption_secret|.
1218
- int tls13_derive_resumption_secret(SSL_HANDSHAKE *hs);
1385
+ bool tls13_derive_resumption_secret(SSL_HANDSHAKE *hs);
1219
1386
 
1220
1387
  // tls13_export_keying_material provides an exporter interface to use the
1221
1388
  // |exporter_secret|.
1222
- int tls13_export_keying_material(SSL *ssl, Span<uint8_t> out,
1223
- Span<const uint8_t> secret,
1224
- Span<const char> label,
1225
- Span<const uint8_t> context);
1389
+ bool tls13_export_keying_material(SSL *ssl, Span<uint8_t> out,
1390
+ Span<const uint8_t> secret,
1391
+ Span<const char> label,
1392
+ Span<const uint8_t> context);
1226
1393
 
1227
1394
  // tls13_finished_mac calculates the MAC of the handshake transcript to verify
1228
1395
  // the integrity of the Finished message, and stores the result in |out| and
1229
- // length in |out_len|. |is_server| is 1 if this is for the Server Finished and
1230
- // 0 for the Client Finished.
1231
- int tls13_finished_mac(SSL_HANDSHAKE *hs, uint8_t *out,
1232
- size_t *out_len, int is_server);
1396
+ // length in |out_len|. |is_server| is true if this is for the Server Finished
1397
+ // and false for the Client Finished.
1398
+ bool tls13_finished_mac(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len,
1399
+ bool is_server);
1233
1400
 
1234
1401
  // tls13_derive_session_psk calculates the PSK for this session based on the
1235
1402
  // resumption master secret and |nonce|. It returns true on success, and false
@@ -1237,15 +1404,15 @@ int tls13_finished_mac(SSL_HANDSHAKE *hs, uint8_t *out,
1237
1404
  bool tls13_derive_session_psk(SSL_SESSION *session, Span<const uint8_t> nonce);
1238
1405
 
1239
1406
  // tls13_write_psk_binder calculates the PSK binder value and replaces the last
1240
- // bytes of |msg| with the resulting value. It returns 1 on success, and 0 on
1241
- // failure.
1242
- int tls13_write_psk_binder(SSL_HANDSHAKE *hs, uint8_t *msg, size_t len);
1407
+ // bytes of |msg| with the resulting value. It returns true on success, and
1408
+ // false on failure.
1409
+ bool tls13_write_psk_binder(SSL_HANDSHAKE *hs, Span<uint8_t> msg);
1243
1410
 
1244
- // tls13_verify_psk_binder verifies that the handshake transcript, truncated
1245
- // up to the binders has a valid signature using the value of |session|'s
1246
- // resumption secret. It returns 1 on success, and 0 on failure.
1247
- int tls13_verify_psk_binder(SSL_HANDSHAKE *hs, SSL_SESSION *session,
1248
- const SSLMessage &msg, CBS *binders);
1411
+ // tls13_verify_psk_binder verifies that the handshake transcript, truncated up
1412
+ // to the binders has a valid signature using the value of |session|'s
1413
+ // resumption secret. It returns true on success, and false on failure.
1414
+ bool tls13_verify_psk_binder(SSL_HANDSHAKE *hs, SSL_SESSION *session,
1415
+ const SSLMessage &msg, CBS *binders);
1249
1416
 
1250
1417
 
1251
1418
  // Handshake functions.
@@ -1258,6 +1425,7 @@ enum ssl_hs_wait_t {
1258
1425
  ssl_hs_flush,
1259
1426
  ssl_hs_certificate_selection_pending,
1260
1427
  ssl_hs_handoff,
1428
+ ssl_hs_handback,
1261
1429
  ssl_hs_x509_lookup,
1262
1430
  ssl_hs_channel_id_lookup,
1263
1431
  ssl_hs_private_key_operation,
@@ -1280,6 +1448,78 @@ enum ssl_grease_index_t {
1280
1448
  ssl_grease_last_index = ssl_grease_ticket_extension,
1281
1449
  };
1282
1450
 
1451
+ enum tls12_server_hs_state_t {
1452
+ state12_start_accept = 0,
1453
+ state12_read_client_hello,
1454
+ state12_select_certificate,
1455
+ state12_tls13,
1456
+ state12_select_parameters,
1457
+ state12_send_server_hello,
1458
+ state12_send_server_certificate,
1459
+ state12_send_server_key_exchange,
1460
+ state12_send_server_hello_done,
1461
+ state12_read_client_certificate,
1462
+ state12_verify_client_certificate,
1463
+ state12_read_client_key_exchange,
1464
+ state12_read_client_certificate_verify,
1465
+ state12_read_change_cipher_spec,
1466
+ state12_process_change_cipher_spec,
1467
+ state12_read_next_proto,
1468
+ state12_read_channel_id,
1469
+ state12_read_client_finished,
1470
+ state12_send_server_finished,
1471
+ state12_finish_server_handshake,
1472
+ state12_done,
1473
+ };
1474
+
1475
+ // handback_t lists the points in the state machine where a handback can occur.
1476
+ // These are the different points at which key material is no longer needed.
1477
+ enum handback_t {
1478
+ handback_after_session_resumption,
1479
+ handback_after_ecdhe,
1480
+ handback_after_handshake,
1481
+ };
1482
+
1483
+
1484
+ // Delegated credentials.
1485
+
1486
+ // This structure stores a delegated credential (DC) as defined by
1487
+ // draft-ietf-tls-subcerts-03.
1488
+ struct DC {
1489
+ static constexpr bool kAllowUniquePtr = true;
1490
+ ~DC();
1491
+
1492
+ // Dup returns a copy of this DC and takes references to |raw| and |pkey|.
1493
+ UniquePtr<DC> Dup();
1494
+
1495
+ // Parse parses the delegated credential stored in |in|. If successful it
1496
+ // returns the parsed structure, otherwise it returns |nullptr| and sets
1497
+ // |*out_alert|.
1498
+ static UniquePtr<DC> Parse(CRYPTO_BUFFER *in, uint8_t *out_alert);
1499
+
1500
+ // raw is the delegated credential encoded as specified in draft-ietf-tls-
1501
+ // subcerts-03.
1502
+ UniquePtr<CRYPTO_BUFFER> raw;
1503
+
1504
+ // expected_cert_verify_algorithm is the signature scheme of the DC public
1505
+ // key.
1506
+ uint16_t expected_cert_verify_algorithm = 0;
1507
+
1508
+ // pkey is the public key parsed from |public_key|.
1509
+ UniquePtr<EVP_PKEY> pkey;
1510
+
1511
+ private:
1512
+ friend DC* New<DC>();
1513
+ DC();
1514
+ };
1515
+
1516
+ // ssl_signing_with_dc returns true if the peer has indicated support for
1517
+ // delegated credentials and this host has sent a delegated credential in
1518
+ // response. If this is true then we've committed to using the DC in the
1519
+ // handshake.
1520
+ bool ssl_signing_with_dc(const SSL_HANDSHAKE *hs);
1521
+
1522
+
1283
1523
  struct SSL_HANDSHAKE {
1284
1524
  explicit SSL_HANDSHAKE(SSL *ssl);
1285
1525
  ~SSL_HANDSHAKE();
@@ -1288,6 +1528,9 @@ struct SSL_HANDSHAKE {
1288
1528
  // ssl is a non-owning pointer to the parent |SSL| object.
1289
1529
  SSL *ssl;
1290
1530
 
1531
+ // config is a non-owning pointer to the handshake configuration.
1532
+ SSL_CONFIG *config;
1533
+
1291
1534
  // wait contains the operation the handshake is currently blocking on or
1292
1535
  // |ssl_hs_ok| if none.
1293
1536
  enum ssl_hs_wait_t wait = ssl_hs_ok;
@@ -1308,14 +1551,38 @@ struct SSL_HANDSHAKE {
1308
1551
  // |SSL_OP_NO_*| and |SSL_CTX_set_max_proto_version| APIs.
1309
1552
  uint16_t max_version = 0;
1310
1553
 
1311
- size_t hash_len = 0;
1312
- uint8_t secret[EVP_MAX_MD_SIZE] = {0};
1313
- uint8_t early_traffic_secret[EVP_MAX_MD_SIZE] = {0};
1314
- uint8_t client_handshake_secret[EVP_MAX_MD_SIZE] = {0};
1315
- uint8_t server_handshake_secret[EVP_MAX_MD_SIZE] = {0};
1316
- uint8_t client_traffic_secret_0[EVP_MAX_MD_SIZE] = {0};
1317
- uint8_t server_traffic_secret_0[EVP_MAX_MD_SIZE] = {0};
1318
- uint8_t expected_client_finished[EVP_MAX_MD_SIZE] = {0};
1554
+ private:
1555
+ size_t hash_len_ = 0;
1556
+ uint8_t secret_[SSL_MAX_MD_SIZE] = {0};
1557
+ uint8_t early_traffic_secret_[SSL_MAX_MD_SIZE] = {0};
1558
+ uint8_t client_handshake_secret_[SSL_MAX_MD_SIZE] = {0};
1559
+ uint8_t server_handshake_secret_[SSL_MAX_MD_SIZE] = {0};
1560
+ uint8_t client_traffic_secret_0_[SSL_MAX_MD_SIZE] = {0};
1561
+ uint8_t server_traffic_secret_0_[SSL_MAX_MD_SIZE] = {0};
1562
+ uint8_t expected_client_finished_[SSL_MAX_MD_SIZE] = {0};
1563
+
1564
+ public:
1565
+ void ResizeSecrets(size_t hash_len);
1566
+
1567
+ Span<uint8_t> secret() { return MakeSpan(secret_, hash_len_); }
1568
+ Span<uint8_t> early_traffic_secret() {
1569
+ return MakeSpan(early_traffic_secret_, hash_len_);
1570
+ }
1571
+ Span<uint8_t> client_handshake_secret() {
1572
+ return MakeSpan(client_handshake_secret_, hash_len_);
1573
+ }
1574
+ Span<uint8_t> server_handshake_secret() {
1575
+ return MakeSpan(server_handshake_secret_, hash_len_);
1576
+ }
1577
+ Span<uint8_t> client_traffic_secret_0() {
1578
+ return MakeSpan(client_traffic_secret_0_, hash_len_);
1579
+ }
1580
+ Span<uint8_t> server_traffic_secret_0() {
1581
+ return MakeSpan(server_traffic_secret_0_, hash_len_);
1582
+ }
1583
+ Span<uint8_t> expected_client_finished() {
1584
+ return MakeSpan(expected_client_finished_, hash_len_);
1585
+ }
1319
1586
 
1320
1587
  union {
1321
1588
  // sent is a bitset where the bits correspond to elements of kExtensions
@@ -1327,17 +1594,6 @@ struct SSL_HANDSHAKE {
1327
1594
  uint32_t received;
1328
1595
  } extensions;
1329
1596
 
1330
- union {
1331
- // sent is a bitset where the bits correspond to elements of
1332
- // |client_custom_extensions| in the |SSL_CTX|. Each bit is set if that
1333
- // extension was sent in a ClientHello. It's not used by servers.
1334
- uint16_t sent = 0;
1335
- // received is a bitset, like |sent|, but is used by servers to record
1336
- // which custom extensions were received from a client. The bits here
1337
- // correspond to |server_custom_extensions|.
1338
- uint16_t received;
1339
- } custom_extensions;
1340
-
1341
1597
  // retry_group is the group ID selected by the server in HelloRetryRequest in
1342
1598
  // TLS 1.3.
1343
1599
  uint16_t retry_group = 0;
@@ -1345,8 +1601,10 @@ struct SSL_HANDSHAKE {
1345
1601
  // error, if |wait| is |ssl_hs_error|, is the error the handshake failed on.
1346
1602
  UniquePtr<ERR_SAVE_STATE> error;
1347
1603
 
1348
- // key_share is the current key exchange instance.
1349
- UniquePtr<SSLKeyShare> key_share;
1604
+ // key_shares are the current key exchange instances. The second is only used
1605
+ // as a client if we believe that we should offer two key shares in a
1606
+ // ClientHello.
1607
+ UniquePtr<SSLKeyShare> key_shares[2];
1350
1608
 
1351
1609
  // transcript is the current handshake transcript.
1352
1610
  SSLTranscript transcript;
@@ -1381,6 +1639,11 @@ struct SSL_HANDSHAKE {
1381
1639
  // sent.
1382
1640
  uint16_t negotiated_token_binding_version;
1383
1641
 
1642
+ // cert_compression_alg_id, for a server, contains the negotiated certificate
1643
+ // compression algorithm for this client. It is only valid if
1644
+ // |cert_compression_negotiated| is true.
1645
+ uint16_t cert_compression_alg_id;
1646
+
1384
1647
  // server_params, in a TLS 1.2 server, stores the ServerKeyExchange
1385
1648
  // parameters. It has client and server randoms prepended for signing
1386
1649
  // convenience.
@@ -1424,76 +1687,91 @@ struct SSL_HANDSHAKE {
1424
1687
  Array<uint8_t> key_block;
1425
1688
 
1426
1689
  // scts_requested is true if the SCT extension is in the ClientHello.
1427
- bool scts_requested:1;
1690
+ bool scts_requested : 1;
1428
1691
 
1429
1692
  // needs_psk_binder is true if the ClientHello has a placeholder PSK binder to
1430
1693
  // be filled in.
1431
- bool needs_psk_binder:1;
1432
-
1433
- bool received_hello_retry_request:1;
1434
- bool sent_hello_retry_request:1;
1694
+ bool needs_psk_binder : 1;
1435
1695
 
1436
- bool received_custom_extension:1;
1696
+ bool received_hello_retry_request : 1;
1697
+ bool sent_hello_retry_request : 1;
1437
1698
 
1438
1699
  // handshake_finalized is true once the handshake has completed, at which
1439
1700
  // point accessors should use the established state.
1440
- bool handshake_finalized:1;
1701
+ bool handshake_finalized : 1;
1441
1702
 
1442
1703
  // accept_psk_mode stores whether the client's PSK mode is compatible with our
1443
1704
  // preferences.
1444
- bool accept_psk_mode:1;
1705
+ bool accept_psk_mode : 1;
1445
1706
 
1446
1707
  // cert_request is true if a client certificate was requested.
1447
- bool cert_request:1;
1708
+ bool cert_request : 1;
1448
1709
 
1449
1710
  // certificate_status_expected is true if OCSP stapling was negotiated and the
1450
1711
  // server is expected to send a CertificateStatus message. (This is used on
1451
1712
  // both the client and server sides.)
1452
- bool certificate_status_expected:1;
1713
+ bool certificate_status_expected : 1;
1453
1714
 
1454
1715
  // ocsp_stapling_requested is true if a client requested OCSP stapling.
1455
- bool ocsp_stapling_requested:1;
1716
+ bool ocsp_stapling_requested : 1;
1717
+
1718
+ // delegated_credential_requested is true if the peer indicated support for
1719
+ // the delegated credential extension.
1720
+ bool delegated_credential_requested : 1;
1456
1721
 
1457
1722
  // should_ack_sni is used by a server and indicates that the SNI extension
1458
1723
  // should be echoed in the ServerHello.
1459
- bool should_ack_sni:1;
1724
+ bool should_ack_sni : 1;
1460
1725
 
1461
1726
  // in_false_start is true if there is a pending client handshake in False
1462
1727
  // Start. The client may write data at this point.
1463
- bool in_false_start:1;
1728
+ bool in_false_start : 1;
1464
1729
 
1465
1730
  // in_early_data is true if there is a pending handshake that has progressed
1466
1731
  // enough to send and receive early data.
1467
- bool in_early_data:1;
1732
+ bool in_early_data : 1;
1468
1733
 
1469
1734
  // early_data_offered is true if the client sent the early_data extension.
1470
- bool early_data_offered:1;
1735
+ bool early_data_offered : 1;
1471
1736
 
1472
1737
  // can_early_read is true if application data may be read at this point in the
1473
1738
  // handshake.
1474
- bool can_early_read:1;
1739
+ bool can_early_read : 1;
1475
1740
 
1476
1741
  // can_early_write is true if application data may be written at this point in
1477
1742
  // the handshake.
1478
- bool can_early_write:1;
1743
+ bool can_early_write : 1;
1479
1744
 
1480
1745
  // next_proto_neg_seen is one of NPN was negotiated.
1481
- bool next_proto_neg_seen:1;
1746
+ bool next_proto_neg_seen : 1;
1482
1747
 
1483
1748
  // ticket_expected is true if a TLS 1.2 NewSessionTicket message is to be sent
1484
1749
  // or received.
1485
- bool ticket_expected:1;
1750
+ bool ticket_expected : 1;
1486
1751
 
1487
1752
  // extended_master_secret is true if the extended master secret extension is
1488
1753
  // negotiated in this handshake.
1489
- bool extended_master_secret:1;
1754
+ bool extended_master_secret : 1;
1490
1755
 
1491
1756
  // pending_private_key_op is true if there is a pending private key operation
1492
1757
  // in progress.
1493
- bool pending_private_key_op:1;
1758
+ bool pending_private_key_op : 1;
1494
1759
 
1495
1760
  // grease_seeded is true if |grease_seed| has been initialized.
1496
- bool grease_seeded:1;
1761
+ bool grease_seeded : 1;
1762
+
1763
+ // handback indicates that a server should pause the handshake after
1764
+ // finishing operations that require private key material, in such a way that
1765
+ // |SSL_get_error| returns |SSL_ERROR_HANDBACK|. It is set by
1766
+ // |SSL_apply_handoff|.
1767
+ bool handback : 1;
1768
+
1769
+ // cert_compression_negotiated is true iff |cert_compression_alg_id| is valid.
1770
+ bool cert_compression_negotiated : 1;
1771
+
1772
+ // apply_jdk11_workaround is true if the peer is probably a JDK 11 client
1773
+ // which implemented TLS 1.3 incorrectly.
1774
+ bool apply_jdk11_workaround : 1;
1497
1775
 
1498
1776
  // client_version is the value sent or received in the ClientHello version.
1499
1777
  uint16_t client_version = 0;
@@ -1506,19 +1784,13 @@ struct SSL_HANDSHAKE {
1506
1784
  // record layer.
1507
1785
  uint16_t early_data_written = 0;
1508
1786
 
1509
- // session_id is the session ID in the ClientHello, used for the experimental
1510
- // TLS 1.3 variant.
1787
+ // session_id is the session ID in the ClientHello.
1511
1788
  uint8_t session_id[SSL_MAX_SSL_SESSION_ID_LENGTH] = {0};
1512
1789
  uint8_t session_id_len = 0;
1513
1790
 
1514
1791
  // grease_seed is the entropy for GREASE values. It is valid if
1515
1792
  // |grease_seeded| is true.
1516
1793
  uint8_t grease_seed[ssl_grease_last_index + 1] = {0};
1517
-
1518
- // dummy_pq_padding_len, in a server, is the length of the extension that
1519
- // should be echoed in a ServerHello, or zero if no extension should be
1520
- // echoed.
1521
- uint16_t dummy_pq_padding_len = 0;
1522
1794
  };
1523
1795
 
1524
1796
  UniquePtr<SSL_HANDSHAKE> ssl_handshake_new(SSL *ssl);
@@ -1546,29 +1818,34 @@ const char *ssl_server_handshake_state(SSL_HANDSHAKE *hs);
1546
1818
  const char *tls13_client_handshake_state(SSL_HANDSHAKE *hs);
1547
1819
  const char *tls13_server_handshake_state(SSL_HANDSHAKE *hs);
1548
1820
 
1549
- // tls13_post_handshake processes a post-handshake message. It returns one on
1550
- // success and zero on failure.
1551
- int tls13_post_handshake(SSL *ssl, const SSLMessage &msg);
1821
+ // tls13_add_key_update queues a KeyUpdate message on |ssl|. The
1822
+ // |update_requested| argument must be one of |SSL_KEY_UPDATE_REQUESTED| or
1823
+ // |SSL_KEY_UPDATE_NOT_REQUESTED|.
1824
+ bool tls13_add_key_update(SSL *ssl, int update_requested);
1825
+
1826
+ // tls13_post_handshake processes a post-handshake message. It returns true on
1827
+ // success and false on failure.
1828
+ bool tls13_post_handshake(SSL *ssl, const SSLMessage &msg);
1552
1829
 
1553
- int tls13_process_certificate(SSL_HANDSHAKE *hs, const SSLMessage &msg,
1554
- int allow_anonymous);
1555
- int tls13_process_certificate_verify(SSL_HANDSHAKE *hs, const SSLMessage &msg);
1830
+ bool tls13_process_certificate(SSL_HANDSHAKE *hs, const SSLMessage &msg,
1831
+ bool allow_anonymous);
1832
+ bool tls13_process_certificate_verify(SSL_HANDSHAKE *hs, const SSLMessage &msg);
1556
1833
 
1557
1834
  // tls13_process_finished processes |msg| as a Finished message from the
1558
- // peer. If |use_saved_value| is one, the verify_data is compared against
1835
+ // peer. If |use_saved_value| is true, the verify_data is compared against
1559
1836
  // |hs->expected_client_finished| rather than computed fresh.
1560
- int tls13_process_finished(SSL_HANDSHAKE *hs, const SSLMessage &msg,
1561
- int use_saved_value);
1837
+ bool tls13_process_finished(SSL_HANDSHAKE *hs, const SSLMessage &msg,
1838
+ bool use_saved_value);
1562
1839
 
1563
- int tls13_add_certificate(SSL_HANDSHAKE *hs);
1840
+ bool tls13_add_certificate(SSL_HANDSHAKE *hs);
1564
1841
 
1565
1842
  // tls13_add_certificate_verify adds a TLS 1.3 CertificateVerify message to the
1566
1843
  // handshake. If it returns |ssl_private_key_retry|, it should be called again
1567
1844
  // to retry when the signing operation is completed.
1568
1845
  enum ssl_private_key_result_t tls13_add_certificate_verify(SSL_HANDSHAKE *hs);
1569
1846
 
1570
- int tls13_add_finished(SSL_HANDSHAKE *hs);
1571
- int tls13_process_new_session_ticket(SSL *ssl, const SSLMessage &msg);
1847
+ bool tls13_add_finished(SSL_HANDSHAKE *hs);
1848
+ bool tls13_process_new_session_ticket(SSL *ssl, const SSLMessage &msg);
1572
1849
 
1573
1850
  bool ssl_ext_key_share_parse_serverhello(SSL_HANDSHAKE *hs,
1574
1851
  Array<uint8_t> *out_secret,
@@ -1583,14 +1860,15 @@ bool ssl_ext_pre_shared_key_parse_serverhello(SSL_HANDSHAKE *hs,
1583
1860
  CBS *contents);
1584
1861
  bool ssl_ext_pre_shared_key_parse_clienthello(
1585
1862
  SSL_HANDSHAKE *hs, CBS *out_ticket, CBS *out_binders,
1586
- uint32_t *out_obfuscated_ticket_age, uint8_t *out_alert, CBS *contents);
1863
+ uint32_t *out_obfuscated_ticket_age, uint8_t *out_alert,
1864
+ const SSL_CLIENT_HELLO *client_hello, CBS *contents);
1587
1865
  bool ssl_ext_pre_shared_key_add_serverhello(SSL_HANDSHAKE *hs, CBB *out);
1588
1866
 
1589
1867
  // ssl_is_sct_list_valid does a shallow parse of the SCT list in |contents| and
1590
- // returns one iff it's valid.
1591
- int ssl_is_sct_list_valid(const CBS *contents);
1868
+ // returns whether it's valid.
1869
+ bool ssl_is_sct_list_valid(const CBS *contents);
1592
1870
 
1593
- int ssl_write_client_hello(SSL_HANDSHAKE *hs);
1871
+ bool ssl_write_client_hello(SSL_HANDSHAKE *hs);
1594
1872
 
1595
1873
  enum ssl_cert_verify_context_t {
1596
1874
  ssl_cert_verify_server,
@@ -1607,8 +1885,9 @@ bool tls13_get_cert_verify_signature_input(
1607
1885
  enum ssl_cert_verify_context_t cert_verify_context);
1608
1886
 
1609
1887
  // ssl_is_alpn_protocol_allowed returns whether |protocol| is a valid server
1610
- // selection for |ssl|'s client preferences.
1611
- bool ssl_is_alpn_protocol_allowed(const SSL *ssl, Span<const uint8_t> protocol);
1888
+ // selection for |hs->ssl|'s client preferences.
1889
+ bool ssl_is_alpn_protocol_allowed(const SSL_HANDSHAKE *hs,
1890
+ Span<const uint8_t> protocol);
1612
1891
 
1613
1892
  // ssl_negotiate_alpn negotiates the ALPN extension, if applicable. It returns
1614
1893
  // true on successful negotiation or if nothing was negotiated. It returns false
@@ -1633,30 +1912,32 @@ int ssl_parse_extensions(const CBS *cbs, uint8_t *out_alert,
1633
1912
 
1634
1913
  // ssl_verify_peer_cert verifies the peer certificate for |hs|.
1635
1914
  enum ssl_verify_result_t ssl_verify_peer_cert(SSL_HANDSHAKE *hs);
1915
+ // ssl_reverify_peer_cert verifies the peer certificate for |hs| when resuming a
1916
+ // session.
1917
+ enum ssl_verify_result_t ssl_reverify_peer_cert(SSL_HANDSHAKE *hs);
1636
1918
 
1637
1919
  enum ssl_hs_wait_t ssl_get_finished(SSL_HANDSHAKE *hs);
1638
1920
  bool ssl_send_finished(SSL_HANDSHAKE *hs);
1639
- bool ssl_output_cert_chain(SSL *ssl);
1640
-
1921
+ bool ssl_output_cert_chain(SSL_HANDSHAKE *hs);
1641
1922
 
1642
1923
  // SSLKEYLOGFILE functions.
1643
1924
 
1644
1925
  // ssl_log_secret logs |secret| with label |label|, if logging is enabled for
1645
- // |ssl|. It returns one on success and zero on failure.
1646
- int ssl_log_secret(const SSL *ssl, const char *label, const uint8_t *secret,
1647
- size_t secret_len);
1926
+ // |ssl|. It returns true on success and false on failure.
1927
+ bool ssl_log_secret(const SSL *ssl, const char *label,
1928
+ Span<const uint8_t> secret);
1648
1929
 
1649
1930
 
1650
1931
  // ClientHello functions.
1651
1932
 
1652
- int ssl_client_hello_init(SSL *ssl, SSL_CLIENT_HELLO *out,
1653
- const SSLMessage &msg);
1933
+ bool ssl_client_hello_init(const SSL *ssl, SSL_CLIENT_HELLO *out,
1934
+ const SSLMessage &msg);
1654
1935
 
1655
- int ssl_client_hello_get_extension(const SSL_CLIENT_HELLO *client_hello,
1656
- CBS *out, uint16_t extension_type);
1936
+ bool ssl_client_hello_get_extension(const SSL_CLIENT_HELLO *client_hello,
1937
+ CBS *out, uint16_t extension_type);
1657
1938
 
1658
- int ssl_client_cipher_list_contains_cipher(const SSL_CLIENT_HELLO *client_hello,
1659
- uint16_t id);
1939
+ bool ssl_client_cipher_list_contains_cipher(
1940
+ const SSL_CLIENT_HELLO *client_hello, uint16_t id);
1660
1941
 
1661
1942
 
1662
1943
  // GREASE.
@@ -1685,9 +1966,20 @@ bool tls1_get_legacy_signature_algorithm(uint16_t *out, const EVP_PKEY *pkey);
1685
1966
  // supported. It returns true on success and false on error.
1686
1967
  bool tls1_choose_signature_algorithm(SSL_HANDSHAKE *hs, uint16_t *out);
1687
1968
 
1969
+ // tls1_get_peer_verify_algorithms returns the signature schemes for which the
1970
+ // peer indicated support.
1971
+ //
1972
+ // NOTE: The related function |SSL_get0_peer_verify_algorithms| only has
1973
+ // well-defined behavior during the callbacks set by |SSL_CTX_set_cert_cb| and
1974
+ // |SSL_CTX_set_client_cert_cb|, or when the handshake is paused because of
1975
+ // them.
1976
+ Span<const uint16_t> tls1_get_peer_verify_algorithms(const SSL_HANDSHAKE *hs);
1977
+
1688
1978
  // tls12_add_verify_sigalgs adds the signature algorithms acceptable for the
1689
- // peer signature to |out|. It returns true on success and false on error.
1690
- bool tls12_add_verify_sigalgs(const SSL *ssl, CBB *out);
1979
+ // peer signature to |out|. It returns true on success and false on error. If
1980
+ // |for_certs| is true, the potentially more restrictive list of algorithms for
1981
+ // certificates is used. Otherwise, the online signature one is used.
1982
+ bool tls12_add_verify_sigalgs(const SSL *ssl, CBB *out, bool for_certs);
1691
1983
 
1692
1984
  // tls12_check_peer_sigalg checks if |sigalg| is acceptable for the peer
1693
1985
  // signature. It returns true on success and false on error, setting
@@ -1695,6 +1987,11 @@ bool tls12_add_verify_sigalgs(const SSL *ssl, CBB *out);
1695
1987
  bool tls12_check_peer_sigalg(const SSL *ssl, uint8_t *out_alert,
1696
1988
  uint16_t sigalg);
1697
1989
 
1990
+ // tls12_has_different_verify_sigalgs_for_certs returns whether |ssl| has a
1991
+ // different, more restrictive, list of signature algorithms acceptable for the
1992
+ // certificate than the online signature.
1993
+ bool tls12_has_different_verify_sigalgs_for_certs(const SSL *ssl);
1994
+
1698
1995
 
1699
1996
  // Underdocumented functions.
1700
1997
  //
@@ -1706,7 +2003,12 @@ bool tls12_check_peer_sigalg(const SSL *ssl, uint8_t *out_alert,
1706
2003
  #define NAMED_CURVE_TYPE 3
1707
2004
 
1708
2005
  struct CERT {
1709
- EVP_PKEY *privatekey;
2006
+ static constexpr bool kAllowUniquePtr = true;
2007
+
2008
+ explicit CERT(const SSL_X509_METHOD *x509_method);
2009
+ ~CERT();
2010
+
2011
+ UniquePtr<EVP_PKEY> privatekey;
1710
2012
 
1711
2013
  // chain contains the certificate chain, with the leaf at the beginning. The
1712
2014
  // first element of |chain| may be NULL to indicate that the leaf certificate
@@ -1714,35 +2016,34 @@ struct CERT {
1714
2016
  // If |chain| != NULL -> len(chain) >= 1
1715
2017
  // If |chain[0]| == NULL -> len(chain) >= 2.
1716
2018
  // |chain[1..]| != NULL
1717
- STACK_OF(CRYPTO_BUFFER) *chain;
2019
+ UniquePtr<STACK_OF(CRYPTO_BUFFER)> chain;
1718
2020
 
1719
2021
  // x509_chain may contain a parsed copy of |chain[1..]|. This is only used as
1720
2022
  // a cache in order to implement “get0” functions that return a non-owning
1721
2023
  // pointer to the certificate chain.
1722
- STACK_OF(X509) *x509_chain;
2024
+ STACK_OF(X509) *x509_chain = nullptr;
1723
2025
 
1724
2026
  // x509_leaf may contain a parsed copy of the first element of |chain|. This
1725
2027
  // is only used as a cache in order to implement “get0” functions that return
1726
2028
  // a non-owning pointer to the certificate chain.
1727
- X509 *x509_leaf;
2029
+ X509 *x509_leaf = nullptr;
1728
2030
 
1729
2031
  // x509_stash contains the last |X509| object append to the chain. This is a
1730
2032
  // workaround for some third-party code that continue to use an |X509| object
1731
2033
  // even after passing ownership with an “add0” function.
1732
- X509 *x509_stash;
2034
+ X509 *x509_stash = nullptr;
1733
2035
 
1734
2036
  // key_method, if non-NULL, is a set of callbacks to call for private key
1735
2037
  // operations.
1736
- const SSL_PRIVATE_KEY_METHOD *key_method;
2038
+ const SSL_PRIVATE_KEY_METHOD *key_method = nullptr;
1737
2039
 
1738
2040
  // x509_method contains pointers to functions that might deal with |X509|
1739
2041
  // compatibility, or might be a no-op, depending on the application.
1740
- const SSL_X509_METHOD *x509_method;
2042
+ const SSL_X509_METHOD *x509_method = nullptr;
1741
2043
 
1742
- // sigalgs, if non-NULL, is the set of signature algorithms supported by
2044
+ // sigalgs, if non-empty, is the set of signature algorithms supported by
1743
2045
  // |privatekey| in decreasing order of preference.
1744
- uint16_t *sigalgs;
1745
- size_t num_sigalgs;
2046
+ Array<uint16_t> sigalgs;
1746
2047
 
1747
2048
  // Certificate setup callback: if set is called whenever a
1748
2049
  // certificate may be required (client or server). the callback
@@ -1750,26 +2051,36 @@ struct CERT {
1750
2051
  // certificates required. This allows advanced applications
1751
2052
  // to select certificates on the fly: for example based on
1752
2053
  // supported signature algorithms or curves.
1753
- int (*cert_cb)(SSL *ssl, void *arg);
1754
- void *cert_cb_arg;
2054
+ int (*cert_cb)(SSL *ssl, void *arg) = nullptr;
2055
+ void *cert_cb_arg = nullptr;
1755
2056
 
1756
2057
  // Optional X509_STORE for certificate validation. If NULL the parent SSL_CTX
1757
2058
  // store is used instead.
1758
- X509_STORE *verify_store;
2059
+ X509_STORE *verify_store = nullptr;
1759
2060
 
1760
2061
  // Signed certificate timestamp list to be sent to the client, if requested
1761
- CRYPTO_BUFFER *signed_cert_timestamp_list;
2062
+ UniquePtr<CRYPTO_BUFFER> signed_cert_timestamp_list;
1762
2063
 
1763
2064
  // OCSP response to be sent to the client, if requested.
1764
- CRYPTO_BUFFER *ocsp_response;
2065
+ UniquePtr<CRYPTO_BUFFER> ocsp_response;
1765
2066
 
1766
2067
  // sid_ctx partitions the session space within a shared session cache or
1767
2068
  // ticket key. Only sessions with a matching value will be accepted.
1768
- uint8_t sid_ctx_length;
1769
- uint8_t sid_ctx[SSL_MAX_SID_CTX_LENGTH];
2069
+ uint8_t sid_ctx_length = 0;
2070
+ uint8_t sid_ctx[SSL_MAX_SID_CTX_LENGTH] = {0};
1770
2071
 
1771
- // If enable_early_data is true, early data can be sent and accepted.
1772
- bool enable_early_data:1;
2072
+ // Delegated credentials.
2073
+
2074
+ // dc is the delegated credential to send to the peer (if requested).
2075
+ UniquePtr<DC> dc = nullptr;
2076
+
2077
+ // dc_privatekey is used instead of |privatekey| or |key_method| to
2078
+ // authenticate the host if a delegated credential is used in the handshake.
2079
+ UniquePtr<EVP_PKEY> dc_privatekey = nullptr;
2080
+
2081
+ // dc_key_method, if not NULL, is used instead of |dc_privatekey| to
2082
+ // authenticate the host.
2083
+ const SSL_PRIVATE_KEY_METHOD *dc_key_method = nullptr;
1773
2084
  };
1774
2085
 
1775
2086
  // |SSL_PROTOCOL_METHOD| abstracts between TLS and DTLS.
@@ -1779,7 +2090,7 @@ struct SSL_PROTOCOL_METHOD {
1779
2090
  void (*ssl_free)(SSL *ssl);
1780
2091
  // get_message sets |*out| to the current handshake message and returns true
1781
2092
  // if one has been received. It returns false if more input is needed.
1782
- bool (*get_message)(SSL *ssl, SSLMessage *out);
2093
+ bool (*get_message)(const SSL *ssl, SSLMessage *out);
1783
2094
  // next_message is called to release the current handshake message.
1784
2095
  void (*next_message)(SSL *ssl);
1785
2096
  // Use the |ssl_open_handshake| wrapper.
@@ -1809,9 +2120,6 @@ struct SSL_PROTOCOL_METHOD {
1809
2120
  // add_change_cipher_spec adds a ChangeCipherSpec record to the pending
1810
2121
  // flight. It returns true on success and false on error.
1811
2122
  bool (*add_change_cipher_spec)(SSL *ssl);
1812
- // add_alert adds an alert to the pending flight. It returns true on success
1813
- // and false on error.
1814
- bool (*add_alert)(SSL *ssl, uint8_t level, uint8_t desc);
1815
2123
  // flush_flight flushes the pending flight to the transport. It returns one on
1816
2124
  // success and <= 0 on error.
1817
2125
  int (*flush_flight)(SSL *ssl);
@@ -1849,6 +2157,62 @@ ssl_open_record_t ssl_open_app_data(SSL *ssl, Span<uint8_t> *out,
1849
2157
  size_t *out_consumed, uint8_t *out_alert,
1850
2158
  Span<uint8_t> in);
1851
2159
 
2160
+ struct SSL_X509_METHOD {
2161
+ // check_client_CA_list returns one if |names| is a good list of X.509
2162
+ // distinguished names and zero otherwise. This is used to ensure that we can
2163
+ // reject unparsable values at handshake time when using crypto/x509.
2164
+ bool (*check_client_CA_list)(STACK_OF(CRYPTO_BUFFER) *names);
2165
+
2166
+ // cert_clear frees and NULLs all X509 certificate-related state.
2167
+ void (*cert_clear)(CERT *cert);
2168
+ // cert_free frees all X509-related state.
2169
+ void (*cert_free)(CERT *cert);
2170
+ // cert_flush_cached_chain drops any cached |X509|-based certificate chain
2171
+ // from |cert|.
2172
+ // cert_dup duplicates any needed fields from |cert| to |new_cert|.
2173
+ void (*cert_dup)(CERT *new_cert, const CERT *cert);
2174
+ void (*cert_flush_cached_chain)(CERT *cert);
2175
+ // cert_flush_cached_chain drops any cached |X509|-based leaf certificate
2176
+ // from |cert|.
2177
+ void (*cert_flush_cached_leaf)(CERT *cert);
2178
+
2179
+ // session_cache_objects fills out |sess->x509_peer| and |sess->x509_chain|
2180
+ // from |sess->certs| and erases |sess->x509_chain_without_leaf|. It returns
2181
+ // true on success or false on error.
2182
+ bool (*session_cache_objects)(SSL_SESSION *session);
2183
+ // session_dup duplicates any needed fields from |session| to |new_session|.
2184
+ // It returns true on success or false on error.
2185
+ bool (*session_dup)(SSL_SESSION *new_session, const SSL_SESSION *session);
2186
+ // session_clear frees any X509-related state from |session|.
2187
+ void (*session_clear)(SSL_SESSION *session);
2188
+ // session_verify_cert_chain verifies the certificate chain in |session|,
2189
+ // sets |session->verify_result| and returns true on success or false on
2190
+ // error.
2191
+ bool (*session_verify_cert_chain)(SSL_SESSION *session, SSL_HANDSHAKE *ssl,
2192
+ uint8_t *out_alert);
2193
+
2194
+ // hs_flush_cached_ca_names drops any cached |X509_NAME|s from |hs|.
2195
+ void (*hs_flush_cached_ca_names)(SSL_HANDSHAKE *hs);
2196
+ // ssl_new does any necessary initialisation of |hs|. It returns true on
2197
+ // success or false on error.
2198
+ bool (*ssl_new)(SSL_HANDSHAKE *hs);
2199
+ // ssl_free frees anything created by |ssl_new|.
2200
+ void (*ssl_config_free)(SSL_CONFIG *cfg);
2201
+ // ssl_flush_cached_client_CA drops any cached |X509_NAME|s from |ssl|.
2202
+ void (*ssl_flush_cached_client_CA)(SSL_CONFIG *cfg);
2203
+ // ssl_auto_chain_if_needed runs the deprecated auto-chaining logic if
2204
+ // necessary. On success, it updates |ssl|'s certificate configuration as
2205
+ // needed and returns true. Otherwise, it returns false.
2206
+ bool (*ssl_auto_chain_if_needed)(SSL_HANDSHAKE *hs);
2207
+ // ssl_ctx_new does any necessary initialisation of |ctx|. It returns true on
2208
+ // success or false on error.
2209
+ bool (*ssl_ctx_new)(SSL_CTX *ctx);
2210
+ // ssl_ctx_free frees anything created by |ssl_ctx_new|.
2211
+ void (*ssl_ctx_free)(SSL_CTX *ctx);
2212
+ // ssl_ctx_flush_cached_client_CA drops any cached |X509_NAME|s from |ctx|.
2213
+ void (*ssl_ctx_flush_cached_client_CA)(SSL_CTX *ssl);
2214
+ };
2215
+
1852
2216
  // ssl_crypto_x509_method provides the |SSL_X509_METHOD| functions using
1853
2217
  // crypto/x509.
1854
2218
  extern const SSL_X509_METHOD ssl_crypto_x509_method;
@@ -1857,359 +2221,57 @@ extern const SSL_X509_METHOD ssl_crypto_x509_method;
1857
2221
  // crypto/x509.
1858
2222
  extern const SSL_X509_METHOD ssl_noop_x509_method;
1859
2223
 
1860
- // ssl_cipher_preference_list_st contains a list of SSL_CIPHERs with
1861
- // equal-preference groups. For TLS clients, the groups are moot because the
1862
- // server picks the cipher and groups cannot be expressed on the wire. However,
1863
- // for servers, the equal-preference groups allow the client's preferences to
1864
- // be partially respected. (This only has an effect with
1865
- // SSL_OP_CIPHER_SERVER_PREFERENCE).
1866
- //
1867
- // The equal-preference groups are expressed by grouping SSL_CIPHERs together.
1868
- // All elements of a group have the same priority: no ordering is expressed
1869
- // within a group.
1870
- //
1871
- // The values in |ciphers| are in one-to-one correspondence with
1872
- // |in_group_flags|. (That is, sk_SSL_CIPHER_num(ciphers) is the number of
1873
- // bytes in |in_group_flags|.) The bytes in |in_group_flags| are either 1, to
1874
- // indicate that the corresponding SSL_CIPHER is not the last element of a
1875
- // group, or 0 to indicate that it is.
1876
- //
1877
- // For example, if |in_group_flags| contains all zeros then that indicates a
1878
- // traditional, fully-ordered preference. Every SSL_CIPHER is the last element
1879
- // of the group (i.e. they are all in a one-element group).
1880
- //
1881
- // For a more complex example, consider:
1882
- // ciphers: A B C D E F
1883
- // in_group_flags: 1 1 0 0 1 0
1884
- //
1885
- // That would express the following, order:
1886
- //
1887
- // A E
1888
- // B -> D -> F
1889
- // C
1890
- struct ssl_cipher_preference_list_st {
1891
- STACK_OF(SSL_CIPHER) *ciphers;
1892
- uint8_t *in_group_flags;
1893
- };
1894
-
1895
- struct tlsext_ticket_key {
2224
+ struct TicketKey {
1896
2225
  static constexpr bool kAllowUniquePtr = true;
1897
2226
 
1898
- uint8_t name[SSL_TICKET_KEY_NAME_LEN];
1899
- uint8_t hmac_key[16];
1900
- uint8_t aes_key[16];
2227
+ uint8_t name[SSL_TICKET_KEY_NAME_LEN] = {0};
2228
+ uint8_t hmac_key[16] = {0};
2229
+ uint8_t aes_key[16] = {0};
1901
2230
  // next_rotation_tv_sec is the time (in seconds from the epoch) when the
1902
2231
  // current key should be superseded by a new key, or the time when a previous
1903
2232
  // key should be dropped. If zero, then the key should not be automatically
1904
2233
  // rotated.
1905
- uint64_t next_rotation_tv_sec;
2234
+ uint64_t next_rotation_tv_sec = 0;
1906
2235
  };
1907
2236
 
1908
- } // namespace bssl
1909
-
1910
- DECLARE_LHASH_OF(SSL_SESSION)
2237
+ struct CertCompressionAlg {
2238
+ static constexpr bool kAllowUniquePtr = true;
1911
2239
 
1912
- namespace bssl {
2240
+ ssl_cert_compression_func_t compress = nullptr;
2241
+ ssl_cert_decompression_func_t decompress = nullptr;
2242
+ uint16_t alg_id = 0;
2243
+ };
1913
2244
 
1914
- // SSLContext backs the public |SSL_CTX| type. Due to compatibility constraints,
1915
- // it is a base class for |ssl_ctx_st|.
1916
- struct SSLContext {
1917
- const SSL_PROTOCOL_METHOD *method;
1918
- const SSL_X509_METHOD *x509_method;
2245
+ BSSL_NAMESPACE_END
1919
2246
 
1920
- // lock is used to protect various operations on this object.
1921
- CRYPTO_MUTEX lock;
2247
+ DEFINE_LHASH_OF(SSL_SESSION)
1922
2248
 
1923
- // conf_max_version is the maximum acceptable protocol version configured by
1924
- // |SSL_CTX_set_max_proto_version|. Note this version is normalized in DTLS
1925
- // and is further constrainted by |SSL_OP_NO_*|.
1926
- uint16_t conf_max_version;
2249
+ BSSL_NAMESPACE_BEGIN
1927
2250
 
1928
- // conf_min_version is the minimum acceptable protocol version configured by
1929
- // |SSL_CTX_set_min_proto_version|. Note this version is normalized in DTLS
1930
- // and is further constrainted by |SSL_OP_NO_*|.
1931
- uint16_t conf_min_version;
2251
+ // An ssl_shutdown_t describes the shutdown state of one end of the connection,
2252
+ // whether it is alive or has been shutdown via close_notify or fatal alert.
2253
+ enum ssl_shutdown_t {
2254
+ ssl_shutdown_none = 0,
2255
+ ssl_shutdown_close_notify = 1,
2256
+ ssl_shutdown_error = 2,
2257
+ };
1932
2258
 
1933
- // tls13_variant is the variant of TLS 1.3 we are using for this
1934
- // configuration.
1935
- enum tls13_variant_t tls13_variant;
2259
+ struct SSL3_STATE {
2260
+ static constexpr bool kAllowUniquePtr = true;
1936
2261
 
1937
- struct ssl_cipher_preference_list_st *cipher_list;
2262
+ SSL3_STATE();
2263
+ ~SSL3_STATE();
1938
2264
 
1939
- X509_STORE *cert_store;
1940
- LHASH_OF(SSL_SESSION) *sessions;
1941
- // Most session-ids that will be cached, default is
1942
- // SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited.
1943
- unsigned long session_cache_size;
1944
- SSL_SESSION *session_cache_head;
1945
- SSL_SESSION *session_cache_tail;
2265
+ uint8_t read_sequence[8] = {0};
2266
+ uint8_t write_sequence[8] = {0};
1946
2267
 
1947
- // handshakes_since_cache_flush is the number of successful handshakes since
1948
- // the last cache flush.
1949
- int handshakes_since_cache_flush;
2268
+ uint8_t server_random[SSL3_RANDOM_SIZE] = {0};
2269
+ uint8_t client_random[SSL3_RANDOM_SIZE] = {0};
1950
2270
 
1951
- // This can have one of 2 values, ored together,
1952
- // SSL_SESS_CACHE_CLIENT,
1953
- // SSL_SESS_CACHE_SERVER,
1954
- // Default is SSL_SESSION_CACHE_SERVER, which means only
1955
- // SSL_accept which cache SSL_SESSIONS.
1956
- int session_cache_mode;
1957
-
1958
- // session_timeout is the default lifetime for new sessions in TLS 1.2 and
1959
- // earlier, in seconds.
1960
- uint32_t session_timeout;
1961
-
1962
- // session_psk_dhe_timeout is the default lifetime for new sessions in TLS
1963
- // 1.3, in seconds.
1964
- uint32_t session_psk_dhe_timeout;
1965
-
1966
- // If this callback is not null, it will be called each time a session id is
1967
- // added to the cache. If this function returns 1, it means that the
1968
- // callback will do a SSL_SESSION_free() when it has finished using it.
1969
- // Otherwise, on 0, it means the callback has finished with it. If
1970
- // remove_session_cb is not null, it will be called when a session-id is
1971
- // removed from the cache. After the call, OpenSSL will SSL_SESSION_free()
1972
- // it.
1973
- int (*new_session_cb)(SSL *ssl, SSL_SESSION *sess);
1974
- void (*remove_session_cb)(SSL_CTX *ctx, SSL_SESSION *sess);
1975
- SSL_SESSION *(*get_session_cb)(SSL *ssl, const uint8_t *data, int len,
1976
- int *copy);
1977
- SSL_SESSION *(*get_session_cb_legacy)(SSL *ssl, uint8_t *data, int len,
1978
- int *copy);
1979
-
1980
- CRYPTO_refcount_t references;
1981
-
1982
- // if defined, these override the X509_verify_cert() calls
1983
- int (*app_verify_callback)(X509_STORE_CTX *store_ctx, void *arg);
1984
- void *app_verify_arg;
1985
-
1986
- enum ssl_verify_result_t (*custom_verify_callback)(SSL *ssl,
1987
- uint8_t *out_alert);
1988
-
1989
- // Default password callback.
1990
- pem_password_cb *default_passwd_callback;
1991
-
1992
- // Default password callback user data.
1993
- void *default_passwd_callback_userdata;
1994
-
1995
- // get client cert callback
1996
- int (*client_cert_cb)(SSL *ssl, X509 **out_x509, EVP_PKEY **out_pkey);
1997
-
1998
- // get channel id callback
1999
- void (*channel_id_cb)(SSL *ssl, EVP_PKEY **out_pkey);
2000
-
2001
- CRYPTO_EX_DATA ex_data;
2002
-
2003
- // custom_*_extensions stores any callback sets for custom extensions. Note
2004
- // that these pointers will be NULL if the stack would otherwise be empty.
2005
- STACK_OF(SSL_CUSTOM_EXTENSION) *client_custom_extensions;
2006
- STACK_OF(SSL_CUSTOM_EXTENSION) *server_custom_extensions;
2007
-
2008
- // Default values used when no per-SSL value is defined follow
2009
-
2010
- void (*info_callback)(const SSL *ssl, int type, int value);
2011
-
2012
- // what we put in client cert requests
2013
- STACK_OF(CRYPTO_BUFFER) *client_CA;
2014
-
2015
- // cached_x509_client_CA is a cache of parsed versions of the elements of
2016
- // |client_CA|.
2017
- STACK_OF(X509_NAME) *cached_x509_client_CA;
2018
-
2019
-
2020
- // Default values to use in SSL structures follow (these are copied by
2021
- // SSL_new)
2022
-
2023
- uint32_t options;
2024
- uint32_t mode;
2025
- uint32_t max_cert_list;
2026
-
2027
- CERT *cert;
2028
-
2029
- // callback that allows applications to peek at protocol messages
2030
- void (*msg_callback)(int write_p, int version, int content_type,
2031
- const void *buf, size_t len, SSL *ssl, void *arg);
2032
- void *msg_callback_arg;
2033
-
2034
- int verify_mode;
2035
- int (*default_verify_callback)(
2036
- int ok, X509_STORE_CTX *ctx); // called 'verify_callback' in the SSL
2037
-
2038
- X509_VERIFY_PARAM *param;
2039
-
2040
- // select_certificate_cb is called before most ClientHello processing and
2041
- // before the decision whether to resume a session is made. See
2042
- // |ssl_select_cert_result_t| for details of the return values.
2043
- enum ssl_select_cert_result_t (*select_certificate_cb)(
2044
- const SSL_CLIENT_HELLO *);
2045
-
2046
- // dos_protection_cb is called once the resumption decision for a ClientHello
2047
- // has been made. It returns one to continue the handshake or zero to
2048
- // abort.
2049
- int (*dos_protection_cb) (const SSL_CLIENT_HELLO *);
2050
-
2051
- // Maximum amount of data to send in one fragment. actual record size can be
2052
- // more than this due to padding and MAC overheads.
2053
- uint16_t max_send_fragment;
2054
-
2055
- // TLS extensions servername callback
2056
- int (*tlsext_servername_callback)(SSL *, int *, void *);
2057
- void *tlsext_servername_arg;
2058
-
2059
- // RFC 4507 session ticket keys. |tlsext_ticket_key_current| may be NULL
2060
- // before the first handshake and |tlsext_ticket_key_prev| may be NULL at any
2061
- // time. Automatically generated ticket keys are rotated as needed at
2062
- // handshake time. Hence, all access must be synchronized through |lock|.
2063
- struct tlsext_ticket_key *tlsext_ticket_key_current;
2064
- struct tlsext_ticket_key *tlsext_ticket_key_prev;
2065
-
2066
- // Callback to support customisation of ticket key setting
2067
- int (*tlsext_ticket_key_cb)(SSL *ssl, uint8_t *name, uint8_t *iv,
2068
- EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc);
2069
-
2070
- // Server-only: psk_identity_hint is the default identity hint to send in
2071
- // PSK-based key exchanges.
2072
- char *psk_identity_hint;
2073
-
2074
- unsigned int (*psk_client_callback)(SSL *ssl, const char *hint,
2075
- char *identity,
2076
- unsigned int max_identity_len,
2077
- uint8_t *psk, unsigned int max_psk_len);
2078
- unsigned int (*psk_server_callback)(SSL *ssl, const char *identity,
2079
- uint8_t *psk, unsigned int max_psk_len);
2080
-
2081
-
2082
- // Next protocol negotiation information
2083
- // (for experimental NPN extension).
2084
-
2085
- // For a server, this contains a callback function by which the set of
2086
- // advertised protocols can be provided.
2087
- int (*next_protos_advertised_cb)(SSL *ssl, const uint8_t **out,
2088
- unsigned *out_len, void *arg);
2089
- void *next_protos_advertised_cb_arg;
2090
- // For a client, this contains a callback function that selects the
2091
- // next protocol from the list provided by the server.
2092
- int (*next_proto_select_cb)(SSL *ssl, uint8_t **out, uint8_t *out_len,
2093
- const uint8_t *in, unsigned in_len, void *arg);
2094
- void *next_proto_select_cb_arg;
2095
-
2096
- // ALPN information
2097
- // (we are in the process of transitioning from NPN to ALPN.)
2098
-
2099
- // For a server, this contains a callback function that allows the
2100
- // server to select the protocol for the connection.
2101
- // out: on successful return, this must point to the raw protocol
2102
- // name (without the length prefix).
2103
- // outlen: on successful return, this contains the length of |*out|.
2104
- // in: points to the client's list of supported protocols in
2105
- // wire-format.
2106
- // inlen: the length of |in|.
2107
- int (*alpn_select_cb)(SSL *ssl, const uint8_t **out, uint8_t *out_len,
2108
- const uint8_t *in, unsigned in_len, void *arg);
2109
- void *alpn_select_cb_arg;
2110
-
2111
- // For a client, this contains the list of supported protocols in wire
2112
- // format.
2113
- uint8_t *alpn_client_proto_list;
2114
- unsigned alpn_client_proto_list_len;
2115
-
2116
- // SRTP profiles we are willing to do from RFC 5764
2117
- STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
2118
-
2119
- // Supported group values inherited by SSL structure
2120
- size_t supported_group_list_len;
2121
- uint16_t *supported_group_list;
2122
-
2123
- // The client's Channel ID private key.
2124
- EVP_PKEY *tlsext_channel_id_private;
2125
-
2126
- // keylog_callback, if not NULL, is the key logging callback. See
2127
- // |SSL_CTX_set_keylog_callback|.
2128
- void (*keylog_callback)(const SSL *ssl, const char *line);
2129
-
2130
- // current_time_cb, if not NULL, is the function to use to get the current
2131
- // time. It sets |*out_clock| to the current time. The |ssl| argument is
2132
- // always NULL. See |SSL_CTX_set_current_time_cb|.
2133
- void (*current_time_cb)(const SSL *ssl, struct timeval *out_clock);
2134
-
2135
- // pool is used for all |CRYPTO_BUFFER|s in case we wish to share certificate
2136
- // memory.
2137
- CRYPTO_BUFFER_POOL *pool;
2138
-
2139
- // ticket_aead_method contains function pointers for opening and sealing
2140
- // session tickets.
2141
- const SSL_TICKET_AEAD_METHOD *ticket_aead_method;
2142
-
2143
- // verify_sigalgs, if not empty, is the set of signature algorithms
2144
- // accepted from the peer in decreasing order of preference.
2145
- uint16_t *verify_sigalgs;
2146
- size_t num_verify_sigalgs;
2147
-
2148
- // retain_only_sha256_of_client_certs is true if we should compute the SHA256
2149
- // hash of the peer's certificate and then discard it to save memory and
2150
- // session space. Only effective on the server side.
2151
- bool retain_only_sha256_of_client_certs:1;
2152
-
2153
- // quiet_shutdown is true if the connection should not send a close_notify on
2154
- // shutdown.
2155
- bool quiet_shutdown:1;
2156
-
2157
- // ocsp_stapling_enabled is only used by client connections and indicates
2158
- // whether OCSP stapling will be requested.
2159
- bool ocsp_stapling_enabled:1;
2160
-
2161
- // If true, a client will request certificate timestamps.
2162
- bool signed_cert_timestamps_enabled:1;
2163
-
2164
- // tlsext_channel_id_enabled is whether Channel ID is enabled. For a server,
2165
- // means that we'll accept Channel IDs from clients. For a client, means that
2166
- // we'll advertise support.
2167
- bool tlsext_channel_id_enabled:1;
2168
-
2169
- // grease_enabled is whether draft-davidben-tls-grease-01 is enabled.
2170
- bool grease_enabled:1;
2171
-
2172
- // allow_unknown_alpn_protos is whether the client allows unsolicited ALPN
2173
- // protocols from the peer.
2174
- bool allow_unknown_alpn_protos:1;
2175
-
2176
- // ed25519_enabled is whether Ed25519 is advertised in the handshake.
2177
- bool ed25519_enabled:1;
2178
-
2179
- // false_start_allowed_without_alpn is whether False Start (if
2180
- // |SSL_MODE_ENABLE_FALSE_START| is enabled) is allowed without ALPN.
2181
- bool false_start_allowed_without_alpn:1;
2182
-
2183
- // handoff indicates that a server should stop after receiving the
2184
- // ClientHello and pause the handshake in such a way that |SSL_get_error|
2185
- // returns |SSL_HANDOFF|.
2186
- bool handoff:1;
2187
- };
2188
-
2189
- // An ssl_shutdown_t describes the shutdown state of one end of the connection,
2190
- // whether it is alive or has been shutdown via close_notify or fatal alert.
2191
- enum ssl_shutdown_t {
2192
- ssl_shutdown_none = 0,
2193
- ssl_shutdown_close_notify = 1,
2194
- ssl_shutdown_error = 2,
2195
- };
2196
-
2197
- struct SSL3_STATE {
2198
- static constexpr bool kAllowUniquePtr = true;
2199
-
2200
- SSL3_STATE();
2201
- ~SSL3_STATE();
2202
-
2203
- uint8_t read_sequence[8] = {0};
2204
- uint8_t write_sequence[8] = {0};
2205
-
2206
- uint8_t server_random[SSL3_RANDOM_SIZE] = {0};
2207
- uint8_t client_random[SSL3_RANDOM_SIZE] = {0};
2208
-
2209
- // read_buffer holds data from the transport to be processed.
2210
- SSLBuffer read_buffer;
2211
- // write_buffer holds data to be written to the transport.
2212
- SSLBuffer write_buffer;
2271
+ // read_buffer holds data from the transport to be processed.
2272
+ SSLBuffer read_buffer;
2273
+ // write_buffer holds data to be written to the transport.
2274
+ SSLBuffer write_buffer;
2213
2275
 
2214
2276
  // pending_app_data is the unconsumed application data. It points into
2215
2277
  // |read_buffer|.
@@ -2232,14 +2294,15 @@ struct SSL3_STATE {
2232
2294
  // the receive half of the connection.
2233
2295
  UniquePtr<ERR_SAVE_STATE> read_error;
2234
2296
 
2235
- int alert_dispatch = 0;
2236
-
2237
2297
  int total_renegotiations = 0;
2238
2298
 
2239
2299
  // This holds a variable that indicates what we were doing when a 0 or -1 is
2240
2300
  // returned. This is needed for non-blocking IO so we know what request
2241
2301
  // needs re-doing when in SSL_accept or SSL_connect
2242
- int rwstate = SSL_NOTHING;
2302
+ int rwstate = SSL_ERROR_NONE;
2303
+
2304
+ enum ssl_encryption_level_t read_level = ssl_encryption_initial;
2305
+ enum ssl_encryption_level_t write_level = ssl_encryption_initial;
2243
2306
 
2244
2307
  // early_data_skipped is the amount of early data that has been skipped by the
2245
2308
  // record layer.
@@ -2255,58 +2318,83 @@ struct SSL3_STATE {
2255
2318
  // key_update_count is the number of consecutive KeyUpdates received.
2256
2319
  uint8_t key_update_count = 0;
2257
2320
 
2321
+ // The negotiated Token Binding key parameter. Only valid if
2322
+ // |token_binding_negotiated| is set.
2323
+ uint8_t negotiated_token_binding_param = 0;
2324
+
2258
2325
  // skip_early_data instructs the record layer to skip unexpected early data
2259
2326
  // messages when 0RTT is rejected.
2260
- bool skip_early_data:1;
2327
+ bool skip_early_data : 1;
2261
2328
 
2262
2329
  // have_version is true if the connection's final version is known. Otherwise
2263
2330
  // the version has not been negotiated yet.
2264
- bool have_version:1;
2331
+ bool have_version : 1;
2265
2332
 
2266
2333
  // v2_hello_done is true if the peer's V2ClientHello, if any, has been handled
2267
2334
  // and future messages should use the record layer.
2268
- bool v2_hello_done:1;
2335
+ bool v2_hello_done : 1;
2269
2336
 
2270
2337
  // is_v2_hello is true if the current handshake message was derived from a
2271
2338
  // V2ClientHello rather than received from the peer directly.
2272
- bool is_v2_hello:1;
2339
+ bool is_v2_hello : 1;
2273
2340
 
2274
2341
  // has_message is true if the current handshake message has been returned
2275
2342
  // at least once by |get_message| and false otherwise.
2276
- bool has_message:1;
2343
+ bool has_message : 1;
2277
2344
 
2278
2345
  // initial_handshake_complete is true if the initial handshake has
2279
2346
  // completed.
2280
- bool initial_handshake_complete:1;
2347
+ bool initial_handshake_complete : 1;
2281
2348
 
2282
2349
  // session_reused indicates whether a session was resumed.
2283
- bool session_reused:1;
2350
+ bool session_reused : 1;
2351
+
2352
+ // delegated_credential_used is whether we presented a delegated credential to
2353
+ // the peer.
2354
+ bool delegated_credential_used : 1;
2284
2355
 
2285
- bool send_connection_binding:1;
2356
+ bool send_connection_binding : 1;
2286
2357
 
2287
2358
  // In a client, this means that the server supported Channel ID and that a
2288
2359
  // Channel ID was sent. In a server it means that we echoed support for
2289
- // Channel IDs and that tlsext_channel_id will be valid after the
2290
- // handshake.
2291
- bool tlsext_channel_id_valid:1;
2360
+ // Channel IDs and that |channel_id| will be valid after the handshake.
2361
+ bool channel_id_valid : 1;
2292
2362
 
2293
2363
  // key_update_pending is true if we have a KeyUpdate acknowledgment
2294
2364
  // outstanding.
2295
- bool key_update_pending:1;
2365
+ bool key_update_pending : 1;
2296
2366
 
2297
2367
  // wpend_pending is true if we have a pending write outstanding.
2298
- bool wpend_pending:1;
2368
+ bool wpend_pending : 1;
2299
2369
 
2300
2370
  // early_data_accepted is true if early data was accepted by the server.
2301
- bool early_data_accepted:1;
2371
+ bool early_data_accepted : 1;
2372
+
2373
+ // tls13_downgrade is whether the TLS 1.3 anti-downgrade logic fired.
2374
+ bool tls13_downgrade : 1;
2375
+
2376
+ // token_binding_negotiated is set if Token Binding was negotiated.
2377
+ bool token_binding_negotiated : 1;
2302
2378
 
2303
- // draft_downgrade is whether the TLS 1.3 anti-downgrade logic would have
2304
- // fired, were it not a draft.
2305
- bool draft_downgrade:1;
2379
+ // pq_experimental_signal_seen is true if the peer was observed
2380
+ // sending/echoing the post-quantum experiment signal.
2381
+ bool pq_experiment_signal_seen : 1;
2382
+
2383
+ // alert_dispatch is true there is an alert in |send_alert| to be sent.
2384
+ bool alert_dispatch : 1;
2385
+
2386
+ // renegotiate_pending is whether the read half of the channel is blocked on a
2387
+ // HelloRequest.
2388
+ bool renegotiate_pending : 1;
2306
2389
 
2307
2390
  // hs_buf is the buffer of handshake data to process.
2308
2391
  UniquePtr<BUF_MEM> hs_buf;
2309
2392
 
2393
+ // pending_hs_data contains the pending handshake data that has not yet
2394
+ // been encrypted to |pending_flight|. This allows packing the handshake into
2395
+ // fewer records.
2396
+ UniquePtr<BUF_MEM> pending_hs_data;
2397
+
2310
2398
  // pending_flight is the pending outgoing flight. This is used to flush each
2311
2399
  // handshake flight in a single write. |write_buffer| must be written out
2312
2400
  // before this data.
@@ -2321,6 +2409,9 @@ struct SSL3_STATE {
2321
2409
  // which resumed a session.
2322
2410
  int32_t ticket_age_skew = 0;
2323
2411
 
2412
+ // ssl_early_data_reason stores details on why 0-RTT was accepted or rejected.
2413
+ enum ssl_early_data_reason_t early_data_reason = ssl_early_data_unknown;
2414
+
2324
2415
  // aead_read_ctx is the current read cipher state.
2325
2416
  UniquePtr<SSLAEADContext> aead_read_ctx;
2326
2417
 
@@ -2331,14 +2422,12 @@ struct SSL3_STATE {
2331
2422
  // one.
2332
2423
  UniquePtr<SSL_HANDSHAKE> hs;
2333
2424
 
2334
- uint8_t write_traffic_secret[EVP_MAX_MD_SIZE] = {0};
2335
- uint8_t read_traffic_secret[EVP_MAX_MD_SIZE] = {0};
2336
- uint8_t exporter_secret[EVP_MAX_MD_SIZE] = {0};
2337
- uint8_t early_exporter_secret[EVP_MAX_MD_SIZE] = {0};
2425
+ uint8_t write_traffic_secret[SSL_MAX_MD_SIZE] = {0};
2426
+ uint8_t read_traffic_secret[SSL_MAX_MD_SIZE] = {0};
2427
+ uint8_t exporter_secret[SSL_MAX_MD_SIZE] = {0};
2338
2428
  uint8_t write_traffic_secret_len = 0;
2339
2429
  uint8_t read_traffic_secret_len = 0;
2340
2430
  uint8_t exporter_secret_len = 0;
2341
- uint8_t early_exporter_secret_len = 0;
2342
2431
 
2343
2432
  // Connection binding to prevent renegotiation attacks
2344
2433
  uint8_t previous_client_finished[12] = {0};
@@ -2373,13 +2462,17 @@ struct SSL3_STATE {
2373
2462
  UniquePtr<char> hostname;
2374
2463
 
2375
2464
  // For a server:
2376
- // If |tlsext_channel_id_valid| is true, then this contains the
2465
+ // If |channel_id_valid| is true, then this contains the
2377
2466
  // verified Channel ID from the client: a P256 point, (x,y), where
2378
2467
  // each are big-endian values.
2379
- uint8_t tlsext_channel_id[64] = {0};
2468
+ uint8_t channel_id[64] = {0};
2380
2469
 
2381
2470
  // Contains the QUIC transport params received by the peer.
2382
2471
  Array<uint8_t> peer_quic_transport_params;
2472
+
2473
+ // srtp_profile is the selected SRTP protection profile for
2474
+ // DTLS-SRTP.
2475
+ const SRTP_PROTECTION_PROFILE *srtp_profile = nullptr;
2383
2476
  };
2384
2477
 
2385
2478
  // lengths of messages
@@ -2438,17 +2531,17 @@ struct DTLS1_STATE {
2438
2531
 
2439
2532
  // has_change_cipher_spec is true if we have received a ChangeCipherSpec from
2440
2533
  // the peer in this epoch.
2441
- bool has_change_cipher_spec:1;
2534
+ bool has_change_cipher_spec : 1;
2442
2535
 
2443
2536
  // outgoing_messages_complete is true if |outgoing_messages| has been
2444
2537
  // completed by an attempt to flush it. Future calls to |add_message| and
2445
2538
  // |add_change_cipher_spec| will start a new flight.
2446
- bool outgoing_messages_complete:1;
2539
+ bool outgoing_messages_complete : 1;
2447
2540
 
2448
2541
  // flight_has_reply is true if the current outgoing flight is complete and has
2449
2542
  // processed at least one message. This is used to detect whether we or the
2450
2543
  // peer sent the final flight.
2451
- bool flight_has_reply:1;
2544
+ bool flight_has_reply : 1;
2452
2545
 
2453
2546
  uint8_t cookie[DTLS1_COOKIE_LENGTH] = {0};
2454
2547
  size_t cookie_len = 0;
@@ -2500,235 +2593,174 @@ struct DTLS1_STATE {
2500
2593
  unsigned timeout_duration_ms = 0;
2501
2594
  };
2502
2595
 
2503
- // SSLConnection backs the public |SSL| type. Due to compatibility constraints,
2504
- // it is a base class for |ssl_st|.
2505
- struct SSLConnection {
2506
- // method is the method table corresponding to the current protocol (DTLS or
2507
- // TLS).
2508
- const SSL_PROTOCOL_METHOD *method;
2509
-
2510
- // version is the protocol version.
2511
- uint16_t version;
2512
-
2513
- // conf_max_version is the maximum acceptable protocol version configured by
2514
- // |SSL_set_max_proto_version|. Note this version is normalized in DTLS and is
2515
- // further constrainted by |SSL_OP_NO_*|.
2516
- uint16_t conf_max_version;
2517
-
2518
- // conf_min_version is the minimum acceptable protocol version configured by
2519
- // |SSL_set_min_proto_version|. Note this version is normalized in DTLS and is
2520
- // further constrainted by |SSL_OP_NO_*|.
2521
- uint16_t conf_min_version;
2522
-
2523
- uint16_t max_send_fragment;
2524
-
2525
- // There are 2 BIO's even though they are normally both the same. This is so
2526
- // data can be read and written to different handlers
2596
+ // SSL_CONFIG contains configuration bits that can be shed after the handshake
2597
+ // completes. Objects of this type are not shared; they are unique to a
2598
+ // particular |SSL|.
2599
+ //
2600
+ // See SSL_shed_handshake_config() for more about the conditions under which
2601
+ // configuration can be shed.
2602
+ struct SSL_CONFIG {
2603
+ static constexpr bool kAllowUniquePtr = true;
2527
2604
 
2528
- BIO *rbio; // used by SSL_read
2529
- BIO *wbio; // used by SSL_write
2605
+ explicit SSL_CONFIG(SSL *ssl_arg);
2606
+ ~SSL_CONFIG();
2530
2607
 
2531
- // do_handshake runs the handshake. On completion, it returns |ssl_hs_ok|.
2532
- // Otherwise, it returns a value corresponding to what operation is needed to
2533
- // progress.
2534
- enum ssl_hs_wait_t (*do_handshake)(SSL_HANDSHAKE *hs);
2608
+ // ssl is a non-owning pointer to the parent |SSL| object.
2609
+ SSL *const ssl = nullptr;
2535
2610
 
2536
- SSL3_STATE *s3; // SSLv3 variables
2537
- DTLS1_STATE *d1; // DTLSv1 variables
2611
+ // conf_max_version is the maximum acceptable version configured by
2612
+ // |SSL_set_max_proto_version|. Note this version is not normalized in DTLS
2613
+ // and is further constrained by |SSL_OP_NO_*|.
2614
+ uint16_t conf_max_version = 0;
2538
2615
 
2539
- // callback that allows applications to peek at protocol messages
2540
- void (*msg_callback)(int write_p, int version, int content_type,
2541
- const void *buf, size_t len, SSL *ssl, void *arg);
2542
- void *msg_callback_arg;
2616
+ // conf_min_version is the minimum acceptable version configured by
2617
+ // |SSL_set_min_proto_version|. Note this version is not normalized in DTLS
2618
+ // and is further constrained by |SSL_OP_NO_*|.
2619
+ uint16_t conf_min_version = 0;
2543
2620
 
2544
- X509_VERIFY_PARAM *param;
2621
+ X509_VERIFY_PARAM *param = nullptr;
2545
2622
 
2546
2623
  // crypto
2547
- struct ssl_cipher_preference_list_st *cipher_list;
2548
-
2549
- // session info
2624
+ UniquePtr<SSLCipherPreferenceList> cipher_list;
2550
2625
 
2551
2626
  // This is used to hold the local certificate used (i.e. the server
2552
2627
  // certificate for a server or the client certificate for a client).
2553
- CERT *cert;
2554
-
2555
- // initial_timeout_duration_ms is the default DTLS timeout duration in
2556
- // milliseconds. It's used to initialize the timer any time it's restarted.
2557
- unsigned initial_timeout_duration_ms;
2558
-
2559
- // tls13_variant is the variant of TLS 1.3 we are using for this
2560
- // configuration.
2561
- enum tls13_variant_t tls13_variant;
2562
-
2563
- // session is the configured session to be offered by the client. This session
2564
- // is immutable.
2565
- SSL_SESSION *session;
2628
+ UniquePtr<CERT> cert;
2566
2629
 
2567
2630
  int (*verify_callback)(int ok,
2568
- X509_STORE_CTX *ctx); // fail if callback returns 0
2569
-
2570
- enum ssl_verify_result_t (*custom_verify_callback)(SSL *ssl,
2571
- uint8_t *out_alert);
2572
-
2573
- void (*info_callback)(const SSL *ssl, int type, int value);
2631
+ X509_STORE_CTX *ctx) =
2632
+ nullptr; // fail if callback returns 0
2574
2633
 
2634
+ enum ssl_verify_result_t (*custom_verify_callback)(
2635
+ SSL *ssl, uint8_t *out_alert) = nullptr;
2575
2636
  // Server-only: psk_identity_hint is the identity hint to send in
2576
2637
  // PSK-based key exchanges.
2577
- char *psk_identity_hint;
2578
-
2579
- unsigned int (*psk_client_callback)(SSL *ssl, const char *hint,
2580
- char *identity,
2581
- unsigned int max_identity_len,
2582
- uint8_t *psk, unsigned int max_psk_len);
2583
- unsigned int (*psk_server_callback)(SSL *ssl, const char *identity,
2584
- uint8_t *psk, unsigned int max_psk_len);
2638
+ UniquePtr<char> psk_identity_hint;
2585
2639
 
2586
- SSL_CTX *ctx;
2587
-
2588
- // extra application data
2589
- CRYPTO_EX_DATA ex_data;
2640
+ unsigned (*psk_client_callback)(SSL *ssl, const char *hint, char *identity,
2641
+ unsigned max_identity_len, uint8_t *psk,
2642
+ unsigned max_psk_len) = nullptr;
2643
+ unsigned (*psk_server_callback)(SSL *ssl, const char *identity, uint8_t *psk,
2644
+ unsigned max_psk_len) = nullptr;
2590
2645
 
2591
2646
  // for server side, keep the list of CA_dn we can use
2592
- STACK_OF(CRYPTO_BUFFER) *client_CA;
2647
+ UniquePtr<STACK_OF(CRYPTO_BUFFER)> client_CA;
2593
2648
 
2594
2649
  // cached_x509_client_CA is a cache of parsed versions of the elements of
2595
2650
  // |client_CA|.
2596
- STACK_OF(X509_NAME) *cached_x509_client_CA;
2597
-
2598
- uint32_t options; // protocol behaviour
2599
- uint32_t mode; // API behaviour
2600
- uint32_t max_cert_list;
2601
- uint16_t dummy_pq_padding_len;
2602
- char *tlsext_hostname;
2603
- size_t supported_group_list_len;
2604
- uint16_t *supported_group_list; // our list
2651
+ STACK_OF(X509_NAME) *cached_x509_client_CA = nullptr;
2605
2652
 
2606
- // session_ctx is the |SSL_CTX| used for the session cache and related
2607
- // settings.
2608
- SSL_CTX *session_ctx;
2609
-
2610
- // srtp_profiles is the list of configured SRTP protection profiles for
2611
- // DTLS-SRTP.
2612
- STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
2613
-
2614
- // srtp_profile is the selected SRTP protection profile for
2615
- // DTLS-SRTP.
2616
- const SRTP_PROTECTION_PROFILE *srtp_profile;
2653
+ Array<uint16_t> supported_group_list; // our list
2617
2654
 
2618
2655
  // The client's Channel ID private key.
2619
- EVP_PKEY *tlsext_channel_id_private;
2656
+ UniquePtr<EVP_PKEY> channel_id_private;
2620
2657
 
2621
2658
  // For a client, this contains the list of supported protocols in wire
2622
2659
  // format.
2623
- uint8_t *alpn_client_proto_list;
2624
- unsigned alpn_client_proto_list_len;
2660
+ Array<uint8_t> alpn_client_proto_list;
2625
2661
 
2626
2662
  // Contains a list of supported Token Binding key parameters.
2627
- uint8_t *token_binding_params;
2628
- size_t token_binding_params_len;
2629
-
2630
- // The negotiated Token Binding key parameter. Only valid if
2631
- // |token_binding_negotiated| is set.
2632
- uint8_t negotiated_token_binding_param;
2663
+ Array<uint8_t> token_binding_params;
2633
2664
 
2634
2665
  // Contains the QUIC transport params that this endpoint will send.
2635
- uint8_t *quic_transport_params;
2636
- size_t quic_transport_params_len;
2637
-
2638
- // renegotiate_mode controls how peer renegotiation attempts are handled.
2639
- enum ssl_renegotiate_mode_t renegotiate_mode;
2666
+ Array<uint8_t> quic_transport_params;
2640
2667
 
2641
- // verify_mode is a bitmask of |SSL_VERIFY_*| values.
2642
- uint8_t verify_mode;
2668
+ // verify_sigalgs, if not empty, is the set of signature algorithms
2669
+ // accepted from the peer in decreasing order of preference.
2670
+ Array<uint16_t> verify_sigalgs;
2643
2671
 
2644
- // server is true iff the this SSL* is the server half. Note: before the SSL*
2645
- // is initialized by either SSL_set_accept_state or SSL_set_connect_state,
2646
- // the side is not determined. In this state, server is always false.
2647
- bool server:1;
2672
+ // srtp_profiles is the list of configured SRTP protection profiles for
2673
+ // DTLS-SRTP.
2674
+ UniquePtr<STACK_OF(SRTP_PROTECTION_PROFILE)> srtp_profiles;
2648
2675
 
2649
- // quiet_shutdown is true if the connection should not send a close_notify on
2650
- // shutdown.
2651
- bool quiet_shutdown:1;
2676
+ // verify_mode is a bitmask of |SSL_VERIFY_*| values.
2677
+ uint8_t verify_mode = SSL_VERIFY_NONE;
2652
2678
 
2653
2679
  // Enable signed certificate time stamps. Currently client only.
2654
- bool signed_cert_timestamps_enabled:1;
2680
+ bool signed_cert_timestamps_enabled : 1;
2655
2681
 
2656
2682
  // ocsp_stapling_enabled is only used by client connections and indicates
2657
2683
  // whether OCSP stapling will be requested.
2658
- bool ocsp_stapling_enabled:1;
2684
+ bool ocsp_stapling_enabled : 1;
2659
2685
 
2660
- // tlsext_channel_id_enabled is copied from the |SSL_CTX|. For a server,
2661
- // means that we'll accept Channel IDs from clients. For a client, means that
2662
- // we'll advertise support.
2663
- bool tlsext_channel_id_enabled:1;
2686
+ // channel_id_enabled is copied from the |SSL_CTX|. For a server, means that
2687
+ // we'll accept Channel IDs from clients. For a client, means that we'll
2688
+ // advertise support.
2689
+ bool channel_id_enabled : 1;
2664
2690
 
2665
- // token_binding_negotiated is set if Token Binding was negotiated.
2666
- bool token_binding_negotiated:1;
2691
+ // If enforce_rsa_key_usage is true, the handshake will fail if the
2692
+ // keyUsage extension is present and incompatible with the TLS usage.
2693
+ // This field is not read until after certificate verification.
2694
+ bool enforce_rsa_key_usage : 1;
2667
2695
 
2668
2696
  // retain_only_sha256_of_client_certs is true if we should compute the SHA256
2669
2697
  // hash of the peer's certificate and then discard it to save memory and
2670
2698
  // session space. Only effective on the server side.
2671
- bool retain_only_sha256_of_client_certs:1;
2699
+ bool retain_only_sha256_of_client_certs : 1;
2672
2700
 
2673
2701
  // handoff indicates that a server should stop after receiving the
2674
2702
  // ClientHello and pause the handshake in such a way that |SSL_get_error|
2675
- // returns |SSL_HANDOFF|. This is copied in |SSL_new| from the |SSL_CTX|
2703
+ // returns |SSL_ERROR_HANDOFF|. This is copied in |SSL_new| from the |SSL_CTX|
2676
2704
  // element of the same name and may be cleared if the handoff is declined.
2677
- bool handoff:1;
2705
+ bool handoff : 1;
2706
+
2707
+ // shed_handshake_config indicates that the handshake config (this object!)
2708
+ // should be freed after the handshake completes.
2709
+ bool shed_handshake_config : 1;
2678
2710
 
2679
- // did_dummy_pq_padding is only valid for a client. In that context, it is
2680
- // true iff the client observed the server echoing a dummy PQ padding
2681
- // extension.
2682
- bool did_dummy_pq_padding:1;
2711
+ // ignore_tls13_downgrade is whether the connection should continue when the
2712
+ // server random signals a downgrade.
2713
+ bool ignore_tls13_downgrade : 1;
2714
+
2715
+ // jdk11_workaround is whether to disable TLS 1.3 for JDK 11 clients, as a
2716
+ // workaround for https://bugs.openjdk.java.net/browse/JDK-8211806.
2717
+ bool jdk11_workaround : 1;
2683
2718
  };
2684
2719
 
2685
- // From draft-ietf-tls-tls13-18, used in determining PSK modes.
2720
+ // From RFC 8446, used in determining PSK modes.
2686
2721
  #define SSL_PSK_DHE_KE 0x1
2687
2722
 
2688
- // From draft-ietf-tls-tls13-16, used in determining whether to respond with a
2689
- // KeyUpdate.
2690
- #define SSL_KEY_UPDATE_NOT_REQUESTED 0
2691
- #define SSL_KEY_UPDATE_REQUESTED 1
2692
-
2693
2723
  // kMaxEarlyDataAccepted is the advertised number of plaintext bytes of early
2694
2724
  // data that will be accepted. This value should be slightly below
2695
2725
  // kMaxEarlyDataSkipped in tls_record.c, which is measured in ciphertext.
2696
2726
  static const size_t kMaxEarlyDataAccepted = 14336;
2697
2727
 
2698
- CERT *ssl_cert_new(const SSL_X509_METHOD *x509_method);
2699
- CERT *ssl_cert_dup(CERT *cert);
2728
+ UniquePtr<CERT> ssl_cert_dup(CERT *cert);
2700
2729
  void ssl_cert_clear_certs(CERT *cert);
2701
- void ssl_cert_free(CERT *cert);
2702
- int ssl_set_cert(CERT *cert, UniquePtr<CRYPTO_BUFFER> buffer);
2703
- int ssl_is_key_type_supported(int key_type);
2704
- // ssl_compare_public_and_private_key returns one if |pubkey| is the public
2705
- // counterpart to |privkey|. Otherwise it returns zero and pushes a helpful
2730
+ bool ssl_set_cert(CERT *cert, UniquePtr<CRYPTO_BUFFER> buffer);
2731
+ bool ssl_is_key_type_supported(int key_type);
2732
+ // ssl_compare_public_and_private_key returns true if |pubkey| is the public
2733
+ // counterpart to |privkey|. Otherwise it returns false and pushes a helpful
2706
2734
  // message on the error queue.
2707
- int ssl_compare_public_and_private_key(const EVP_PKEY *pubkey,
2735
+ bool ssl_compare_public_and_private_key(const EVP_PKEY *pubkey,
2708
2736
  const EVP_PKEY *privkey);
2709
- int ssl_cert_check_private_key(const CERT *cert, const EVP_PKEY *privkey);
2737
+ bool ssl_cert_check_private_key(const CERT *cert, const EVP_PKEY *privkey);
2710
2738
  int ssl_get_new_session(SSL_HANDSHAKE *hs, int is_server);
2711
- int ssl_encrypt_ticket(SSL *ssl, CBB *out, const SSL_SESSION *session);
2739
+ int ssl_encrypt_ticket(SSL_HANDSHAKE *hs, CBB *out, const SSL_SESSION *session);
2712
2740
  int ssl_ctx_rotate_ticket_encryption_key(SSL_CTX *ctx);
2713
2741
 
2714
2742
  // ssl_session_new returns a newly-allocated blank |SSL_SESSION| or nullptr on
2715
2743
  // error.
2716
2744
  UniquePtr<SSL_SESSION> ssl_session_new(const SSL_X509_METHOD *x509_method);
2717
2745
 
2746
+ // ssl_hash_session_id returns a hash of |session_id|, suitable for a hash table
2747
+ // keyed on session IDs.
2748
+ uint32_t ssl_hash_session_id(Span<const uint8_t> session_id);
2749
+
2718
2750
  // SSL_SESSION_parse parses an |SSL_SESSION| from |cbs| and advances |cbs| over
2719
2751
  // the parsed data.
2720
- UniquePtr<SSL_SESSION> SSL_SESSION_parse(CBS *cbs,
2721
- const SSL_X509_METHOD *x509_method,
2722
- CRYPTO_BUFFER_POOL *pool);
2752
+ OPENSSL_EXPORT UniquePtr<SSL_SESSION> SSL_SESSION_parse(
2753
+ CBS *cbs, const SSL_X509_METHOD *x509_method, CRYPTO_BUFFER_POOL *pool);
2723
2754
 
2724
2755
  // ssl_session_serialize writes |in| to |cbb| as if it were serialising a
2725
2756
  // session for Session-ID resumption. It returns one on success and zero on
2726
2757
  // error.
2727
- int ssl_session_serialize(const SSL_SESSION *in, CBB *cbb);
2758
+ OPENSSL_EXPORT int ssl_session_serialize(const SSL_SESSION *in, CBB *cbb);
2728
2759
 
2729
2760
  // ssl_session_is_context_valid returns one if |session|'s session ID context
2730
- // matches the one set on |ssl| and zero otherwise.
2731
- int ssl_session_is_context_valid(const SSL *ssl, const SSL_SESSION *session);
2761
+ // matches the one set on |hs| and zero otherwise.
2762
+ int ssl_session_is_context_valid(const SSL_HANDSHAKE *hs,
2763
+ const SSL_SESSION *session);
2732
2764
 
2733
2765
  // ssl_session_is_time_valid returns one if |session| is still valid and zero if
2734
2766
  // it has expired.
@@ -2755,7 +2787,7 @@ void ssl_set_session(SSL *ssl, SSL_SESSION *session);
2755
2787
  // |ssl_hs_pending_session| and should be called again. If a ticket could not be
2756
2788
  // decrypted immediately it returns |ssl_hs_pending_ticket| and should also
2757
2789
  // be called again. Otherwise, it returns |ssl_hs_error|.
2758
- enum ssl_hs_wait_t ssl_get_prev_session(SSL *ssl,
2790
+ enum ssl_hs_wait_t ssl_get_prev_session(SSL_HANDSHAKE *hs,
2759
2791
  UniquePtr<SSL_SESSION> *out_session,
2760
2792
  bool *out_tickets_supported,
2761
2793
  bool *out_renew_ticket,
@@ -2784,18 +2816,11 @@ void ssl_session_rebase_time(SSL *ssl, SSL_SESSION *session);
2784
2816
  void ssl_session_renew_timeout(SSL *ssl, SSL_SESSION *session,
2785
2817
  uint32_t timeout);
2786
2818
 
2787
- void ssl_cipher_preference_list_free(
2788
- struct ssl_cipher_preference_list_st *cipher_list);
2789
-
2790
- // ssl_get_cipher_preferences returns the cipher preference list for TLS 1.2 and
2791
- // below.
2792
- const struct ssl_cipher_preference_list_st *ssl_get_cipher_preferences(
2793
- const SSL *ssl);
2794
-
2795
2819
  void ssl_update_cache(SSL_HANDSHAKE *hs, int mode);
2796
2820
 
2797
- int ssl_send_alert(SSL *ssl, int level, int desc);
2798
- bool ssl3_get_message(SSL *ssl, SSLMessage *out);
2821
+ void ssl_send_alert(SSL *ssl, int level, int desc);
2822
+ int ssl_send_alert_impl(SSL *ssl, int level, int desc);
2823
+ bool ssl3_get_message(const SSL *ssl, SSLMessage *out);
2799
2824
  ssl_open_record_t ssl3_open_handshake(SSL *ssl, size_t *out_consumed,
2800
2825
  uint8_t *out_alert, Span<uint8_t> in);
2801
2826
  void ssl3_next_message(SSL *ssl);
@@ -2817,14 +2842,12 @@ bool ssl3_init_message(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
2817
2842
  bool ssl3_finish_message(SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
2818
2843
  bool ssl3_add_message(SSL *ssl, Array<uint8_t> msg);
2819
2844
  bool ssl3_add_change_cipher_spec(SSL *ssl);
2820
- bool ssl3_add_alert(SSL *ssl, uint8_t level, uint8_t desc);
2821
2845
  int ssl3_flush_flight(SSL *ssl);
2822
2846
 
2823
2847
  bool dtls1_init_message(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
2824
2848
  bool dtls1_finish_message(SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
2825
2849
  bool dtls1_add_message(SSL *ssl, Array<uint8_t> msg);
2826
2850
  bool dtls1_add_change_cipher_spec(SSL *ssl);
2827
- bool dtls1_add_alert(SSL *ssl, uint8_t level, uint8_t desc);
2828
2851
  int dtls1_flush_flight(SSL *ssl);
2829
2852
 
2830
2853
  // ssl_add_message_cbb finishes the handshake message in |cbb| and adds it to
@@ -2852,7 +2875,7 @@ int dtls1_write_record(SSL *ssl, int type, const uint8_t *buf, size_t len,
2852
2875
 
2853
2876
  int dtls1_retransmit_outgoing_messages(SSL *ssl);
2854
2877
  bool dtls1_parse_fragment(CBS *cbs, struct hm_header_st *out_hdr,
2855
- CBS *out_body);
2878
+ CBS *out_body);
2856
2879
  bool dtls1_check_timeout_num(SSL *ssl);
2857
2880
 
2858
2881
  void dtls1_start_timer(SSL *ssl);
@@ -2863,7 +2886,7 @@ unsigned int dtls1_min_mtu(void);
2863
2886
  bool dtls1_new(SSL *ssl);
2864
2887
  void dtls1_free(SSL *ssl);
2865
2888
 
2866
- bool dtls1_get_message(SSL *ssl, SSLMessage *out);
2889
+ bool dtls1_get_message(const SSL *ssl, SSLMessage *out);
2867
2890
  ssl_open_record_t dtls1_open_handshake(SSL *ssl, size_t *out_consumed,
2868
2891
  uint8_t *out_alert, Span<uint8_t> in);
2869
2892
  void dtls1_next_message(SSL *ssl);
@@ -2884,41 +2907,38 @@ int tls1_generate_master_secret(SSL_HANDSHAKE *hs, uint8_t *out,
2884
2907
  Span<const uint8_t> premaster);
2885
2908
 
2886
2909
  // tls1_get_grouplist returns the locally-configured group preference list.
2887
- Span<const uint16_t> tls1_get_grouplist(const SSL *ssl);
2910
+ Span<const uint16_t> tls1_get_grouplist(const SSL_HANDSHAKE *ssl);
2888
2911
 
2889
- // tls1_check_group_id returns one if |group_id| is consistent with
2890
- // locally-configured group preferences.
2891
- int tls1_check_group_id(const SSL *ssl, uint16_t group_id);
2912
+ // tls1_check_group_id returns whether |group_id| is consistent with locally-
2913
+ // configured group preferences.
2914
+ bool tls1_check_group_id(const SSL_HANDSHAKE *ssl, uint16_t group_id);
2892
2915
 
2893
2916
  // tls1_get_shared_group sets |*out_group_id| to the first preferred shared
2894
- // group between client and server preferences and returns one. If none may be
2895
- // found, it returns zero.
2896
- int tls1_get_shared_group(SSL_HANDSHAKE *hs, uint16_t *out_group_id);
2917
+ // group between client and server preferences and returns true. If none may be
2918
+ // found, it returns false.
2919
+ bool tls1_get_shared_group(SSL_HANDSHAKE *hs, uint16_t *out_group_id);
2897
2920
 
2898
- // tls1_set_curves converts the array of |ncurves| NIDs pointed to by |curves|
2899
- // into a newly allocated array of TLS group IDs. On success, the function
2900
- // returns one and writes the array to |*out_group_ids| and its size to
2901
- // |*out_group_ids_len|. Otherwise, it returns zero.
2902
- int tls1_set_curves(uint16_t **out_group_ids, size_t *out_group_ids_len,
2903
- const int *curves, size_t ncurves);
2921
+ // tls1_set_curves converts the array of NIDs in |curves| into a newly allocated
2922
+ // array of TLS group IDs. On success, the function returns true and writes the
2923
+ // array to |*out_group_ids|. Otherwise, it returns false.
2924
+ bool tls1_set_curves(Array<uint16_t> *out_group_ids, Span<const int> curves);
2904
2925
 
2905
2926
  // tls1_set_curves_list converts the string of curves pointed to by |curves|
2906
2927
  // into a newly allocated array of TLS group IDs. On success, the function
2907
- // returns one and writes the array to |*out_group_ids| and its size to
2908
- // |*out_group_ids_len|. Otherwise, it returns zero.
2909
- int tls1_set_curves_list(uint16_t **out_group_ids, size_t *out_group_ids_len,
2910
- const char *curves);
2911
-
2912
- // ssl_add_clienthello_tlsext writes ClientHello extensions to |out|. It
2913
- // returns one on success and zero on failure. The |header_len| argument is the
2914
- // length of the ClientHello written so far and is used to compute the padding
2915
- // length. (It does not include the record header.)
2916
- int ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, size_t header_len);
2917
-
2918
- int ssl_add_serverhello_tlsext(SSL_HANDSHAKE *hs, CBB *out);
2919
- int ssl_parse_clienthello_tlsext(SSL_HANDSHAKE *hs,
2920
- const SSL_CLIENT_HELLO *client_hello);
2921
- int ssl_parse_serverhello_tlsext(SSL_HANDSHAKE *hs, CBS *cbs);
2928
+ // returns true and writes the array to |*out_group_ids|. Otherwise, it returns
2929
+ // false.
2930
+ bool tls1_set_curves_list(Array<uint16_t> *out_group_ids, const char *curves);
2931
+
2932
+ // ssl_add_clienthello_tlsext writes ClientHello extensions to |out|. It returns
2933
+ // true on success and false on failure. The |header_len| argument is the length
2934
+ // of the ClientHello written so far and is used to compute the padding length.
2935
+ // (It does not include the record header.)
2936
+ bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, size_t header_len);
2937
+
2938
+ bool ssl_add_serverhello_tlsext(SSL_HANDSHAKE *hs, CBB *out);
2939
+ bool ssl_parse_clienthello_tlsext(SSL_HANDSHAKE *hs,
2940
+ const SSL_CLIENT_HELLO *client_hello);
2941
+ bool ssl_parse_serverhello_tlsext(SSL_HANDSHAKE *hs, CBS *cbs);
2922
2942
 
2923
2943
  #define tlsext_tick_md EVP_sha256
2924
2944
 
@@ -2932,38 +2952,41 @@ int ssl_parse_serverhello_tlsext(SSL_HANDSHAKE *hs, CBS *cbs);
2932
2952
  // Retry later.
2933
2953
  // |ssl_ticket_aead_error|: an error occured that is fatal to the connection.
2934
2954
  enum ssl_ticket_aead_result_t ssl_process_ticket(
2935
- SSL *ssl, UniquePtr<SSL_SESSION> *out_session, bool *out_renew_ticket,
2936
- const uint8_t *ticket, size_t ticket_len, const uint8_t *session_id,
2937
- size_t session_id_len);
2955
+ SSL_HANDSHAKE *hs, UniquePtr<SSL_SESSION> *out_session,
2956
+ bool *out_renew_ticket, Span<const uint8_t> ticket,
2957
+ Span<const uint8_t> session_id);
2938
2958
 
2939
2959
  // tls1_verify_channel_id processes |msg| as a Channel ID message, and verifies
2940
- // the signature. If the key is valid, it saves the Channel ID and returns
2941
- // one. Otherwise, it returns zero.
2942
- int tls1_verify_channel_id(SSL_HANDSHAKE *hs, const SSLMessage &msg);
2960
+ // the signature. If the key is valid, it saves the Channel ID and returns true.
2961
+ // Otherwise, it returns false.
2962
+ bool tls1_verify_channel_id(SSL_HANDSHAKE *hs, const SSLMessage &msg);
2943
2963
 
2944
2964
  // tls1_write_channel_id generates a Channel ID message and puts the output in
2945
- // |cbb|. |ssl->tlsext_channel_id_private| must already be set before calling.
2946
- // This function returns true on success and false on error.
2965
+ // |cbb|. |ssl->channel_id_private| must already be set before calling. This
2966
+ // function returns true on success and false on error.
2947
2967
  bool tls1_write_channel_id(SSL_HANDSHAKE *hs, CBB *cbb);
2948
2968
 
2949
2969
  // tls1_channel_id_hash computes the hash to be signed by Channel ID and writes
2950
2970
  // it to |out|, which must contain at least |EVP_MAX_MD_SIZE| bytes. It returns
2951
- // one on success and zero on failure.
2952
- int tls1_channel_id_hash(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len);
2971
+ // true on success and false on failure.
2972
+ bool tls1_channel_id_hash(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len);
2953
2973
 
2954
- int tls1_record_handshake_hashes_for_channel_id(SSL_HANDSHAKE *hs);
2974
+ // tls1_record_handshake_hashes_for_channel_id records the current handshake
2975
+ // hashes in |hs->new_session| so that Channel ID resumptions can sign that
2976
+ // data.
2977
+ bool tls1_record_handshake_hashes_for_channel_id(SSL_HANDSHAKE *hs);
2955
2978
 
2956
- // ssl_do_channel_id_callback checks runs |ssl->ctx->channel_id_cb| if
2957
- // necessary. It returns one on success and zero on fatal error. Note that, on
2958
- // success, |ssl->tlsext_channel_id_private| may be unset, in which case the
2979
+ // ssl_do_channel_id_callback checks runs |hs->ssl->ctx->channel_id_cb| if
2980
+ // necessary. It returns true on success and false on fatal error. Note that, on
2981
+ // success, |hs->ssl->channel_id_private| may be unset, in which case the
2959
2982
  // operation should be retried later.
2960
- int ssl_do_channel_id_callback(SSL *ssl);
2983
+ bool ssl_do_channel_id_callback(SSL_HANDSHAKE *hs);
2961
2984
 
2962
- // ssl_can_write returns one if |ssl| is allowed to write and zero otherwise.
2963
- int ssl_can_write(const SSL *ssl);
2985
+ // ssl_can_write returns whether |ssl| is allowed to write.
2986
+ bool ssl_can_write(const SSL *ssl);
2964
2987
 
2965
- // ssl_can_read returns one if |ssl| is allowed to read and zero otherwise.
2966
- int ssl_can_read(const SSL *ssl);
2988
+ // ssl_can_read returns wheter |ssl| is allowed to read.
2989
+ bool ssl_can_read(const SSL *ssl);
2967
2990
 
2968
2991
  void ssl_get_current_time(const SSL *ssl, struct OPENSSL_timeval *out_clock);
2969
2992
  void ssl_ctx_get_current_time(const SSL_CTX *ctx,
@@ -2974,9 +2997,9 @@ void ssl_reset_error_state(SSL *ssl);
2974
2997
 
2975
2998
  // ssl_set_read_error sets |ssl|'s read half into an error state, saving the
2976
2999
  // current state of the error queue.
2977
- void ssl_set_read_error(SSL* ssl);
3000
+ void ssl_set_read_error(SSL *ssl);
2978
3001
 
2979
- } // namespace bssl
3002
+ BSSL_NAMESPACE_END
2980
3003
 
2981
3004
 
2982
3005
  // Opaque C types.
@@ -2995,70 +3018,532 @@ struct ssl_method_st {
2995
3018
  const bssl::SSL_PROTOCOL_METHOD *method;
2996
3019
  // x509_method contains pointers to functions that might deal with |X509|
2997
3020
  // compatibility, or might be a no-op, depending on the application.
2998
- const SSL_X509_METHOD *x509_method;
3021
+ const bssl::SSL_X509_METHOD *x509_method;
2999
3022
  };
3000
3023
 
3001
- struct ssl_x509_method_st {
3002
- // check_client_CA_list returns one if |names| is a good list of X.509
3003
- // distinguished names and zero otherwise. This is used to ensure that we can
3004
- // reject unparsable values at handshake time when using crypto/x509.
3005
- int (*check_client_CA_list)(STACK_OF(CRYPTO_BUFFER) *names);
3024
+ struct ssl_ctx_st {
3025
+ explicit ssl_ctx_st(const SSL_METHOD *ssl_method);
3026
+ ssl_ctx_st(const ssl_ctx_st &) = delete;
3027
+ ssl_ctx_st &operator=(const ssl_ctx_st &) = delete;
3006
3028
 
3007
- // cert_clear frees and NULLs all X509 certificate-related state.
3008
- void (*cert_clear)(bssl::CERT *cert);
3009
- // cert_free frees all X509-related state.
3010
- void (*cert_free)(bssl::CERT *cert);
3011
- // cert_flush_cached_chain drops any cached |X509|-based certificate chain
3012
- // from |cert|.
3013
- // cert_dup duplicates any needed fields from |cert| to |new_cert|.
3014
- void (*cert_dup)(bssl::CERT *new_cert, const bssl::CERT *cert);
3015
- void (*cert_flush_cached_chain)(bssl::CERT *cert);
3016
- // cert_flush_cached_chain drops any cached |X509|-based leaf certificate
3017
- // from |cert|.
3018
- void (*cert_flush_cached_leaf)(bssl::CERT *cert);
3029
+ const bssl::SSL_PROTOCOL_METHOD *method = nullptr;
3030
+ const bssl::SSL_X509_METHOD *x509_method = nullptr;
3019
3031
 
3020
- // session_cache_objects fills out |sess->x509_peer| and |sess->x509_chain|
3021
- // from |sess->certs| and erases |sess->x509_chain_without_leaf|. It returns
3022
- // one on success or zero on error.
3023
- int (*session_cache_objects)(SSL_SESSION *session);
3024
- // session_dup duplicates any needed fields from |session| to |new_session|.
3025
- // It returns one on success or zero on error.
3026
- int (*session_dup)(SSL_SESSION *new_session, const SSL_SESSION *session);
3027
- // session_clear frees any X509-related state from |session|.
3028
- void (*session_clear)(SSL_SESSION *session);
3029
- // session_verify_cert_chain verifies the certificate chain in |session|,
3030
- // sets |session->verify_result| and returns one on success or zero on
3031
- // error.
3032
- int (*session_verify_cert_chain)(SSL_SESSION *session, SSL *ssl,
3033
- uint8_t *out_alert);
3032
+ // lock is used to protect various operations on this object.
3033
+ CRYPTO_MUTEX lock;
3034
3034
 
3035
- // hs_flush_cached_ca_names drops any cached |X509_NAME|s from |hs|.
3036
- void (*hs_flush_cached_ca_names)(bssl::SSL_HANDSHAKE *hs);
3037
- // ssl_new does any neccessary initialisation of |ssl|. It returns one on
3038
- // success or zero on error.
3039
- int (*ssl_new)(SSL *ssl);
3040
- // ssl_free frees anything created by |ssl_new|.
3041
- void (*ssl_free)(SSL *ssl);
3042
- // ssl_flush_cached_client_CA drops any cached |X509_NAME|s from |ssl|.
3043
- void (*ssl_flush_cached_client_CA)(SSL *ssl);
3044
- // ssl_auto_chain_if_needed runs the deprecated auto-chaining logic if
3045
- // necessary. On success, it updates |ssl|'s certificate configuration as
3046
- // needed and returns one. Otherwise, it returns zero.
3047
- int (*ssl_auto_chain_if_needed)(SSL *ssl);
3048
- // ssl_ctx_new does any neccessary initialisation of |ctx|. It returns one on
3049
- // success or zero on error.
3050
- int (*ssl_ctx_new)(SSL_CTX *ctx);
3051
- // ssl_ctx_free frees anything created by |ssl_ctx_new|.
3052
- void (*ssl_ctx_free)(SSL_CTX *ctx);
3053
- // ssl_ctx_flush_cached_client_CA drops any cached |X509_NAME|s from |ctx|.
3054
- void (*ssl_ctx_flush_cached_client_CA)(SSL_CTX *ssl);
3035
+ // conf_max_version is the maximum acceptable protocol version configured by
3036
+ // |SSL_CTX_set_max_proto_version|. Note this version is normalized in DTLS
3037
+ // and is further constrainted by |SSL_OP_NO_*|.
3038
+ uint16_t conf_max_version = 0;
3039
+
3040
+ // conf_min_version is the minimum acceptable protocol version configured by
3041
+ // |SSL_CTX_set_min_proto_version|. Note this version is normalized in DTLS
3042
+ // and is further constrainted by |SSL_OP_NO_*|.
3043
+ uint16_t conf_min_version = 0;
3044
+
3045
+ // quic_method is the method table corresponding to the QUIC hooks.
3046
+ const SSL_QUIC_METHOD *quic_method = nullptr;
3047
+
3048
+ bssl::UniquePtr<bssl::SSLCipherPreferenceList> cipher_list;
3049
+
3050
+ X509_STORE *cert_store = nullptr;
3051
+ LHASH_OF(SSL_SESSION) *sessions = nullptr;
3052
+ // Most session-ids that will be cached, default is
3053
+ // SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited.
3054
+ unsigned long session_cache_size = SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
3055
+ SSL_SESSION *session_cache_head = nullptr;
3056
+ SSL_SESSION *session_cache_tail = nullptr;
3057
+
3058
+ // handshakes_since_cache_flush is the number of successful handshakes since
3059
+ // the last cache flush.
3060
+ int handshakes_since_cache_flush = 0;
3061
+
3062
+ // This can have one of 2 values, ored together,
3063
+ // SSL_SESS_CACHE_CLIENT,
3064
+ // SSL_SESS_CACHE_SERVER,
3065
+ // Default is SSL_SESSION_CACHE_SERVER, which means only
3066
+ // SSL_accept which cache SSL_SESSIONS.
3067
+ int session_cache_mode = SSL_SESS_CACHE_SERVER;
3068
+
3069
+ // session_timeout is the default lifetime for new sessions in TLS 1.2 and
3070
+ // earlier, in seconds.
3071
+ uint32_t session_timeout = SSL_DEFAULT_SESSION_TIMEOUT;
3072
+
3073
+ // session_psk_dhe_timeout is the default lifetime for new sessions in TLS
3074
+ // 1.3, in seconds.
3075
+ uint32_t session_psk_dhe_timeout = SSL_DEFAULT_SESSION_PSK_DHE_TIMEOUT;
3076
+
3077
+ // If this callback is not null, it will be called each time a session id is
3078
+ // added to the cache. If this function returns 1, it means that the
3079
+ // callback will do a SSL_SESSION_free() when it has finished using it.
3080
+ // Otherwise, on 0, it means the callback has finished with it. If
3081
+ // remove_session_cb is not null, it will be called when a session-id is
3082
+ // removed from the cache. After the call, OpenSSL will SSL_SESSION_free()
3083
+ // it.
3084
+ int (*new_session_cb)(SSL *ssl, SSL_SESSION *sess) = nullptr;
3085
+ void (*remove_session_cb)(SSL_CTX *ctx, SSL_SESSION *sess) = nullptr;
3086
+ SSL_SESSION *(*get_session_cb)(SSL *ssl, const uint8_t *data, int len,
3087
+ int *copy) = nullptr;
3088
+
3089
+ CRYPTO_refcount_t references = 1;
3090
+
3091
+ // if defined, these override the X509_verify_cert() calls
3092
+ int (*app_verify_callback)(X509_STORE_CTX *store_ctx, void *arg) = nullptr;
3093
+ void *app_verify_arg = nullptr;
3094
+
3095
+ ssl_verify_result_t (*custom_verify_callback)(SSL *ssl,
3096
+ uint8_t *out_alert) = nullptr;
3097
+
3098
+ // Default password callback.
3099
+ pem_password_cb *default_passwd_callback = nullptr;
3100
+
3101
+ // Default password callback user data.
3102
+ void *default_passwd_callback_userdata = nullptr;
3103
+
3104
+ // get client cert callback
3105
+ int (*client_cert_cb)(SSL *ssl, X509 **out_x509,
3106
+ EVP_PKEY **out_pkey) = nullptr;
3107
+
3108
+ // get channel id callback
3109
+ void (*channel_id_cb)(SSL *ssl, EVP_PKEY **out_pkey) = nullptr;
3110
+
3111
+ CRYPTO_EX_DATA ex_data;
3112
+
3113
+ // Default values used when no per-SSL value is defined follow
3114
+
3115
+ void (*info_callback)(const SSL *ssl, int type, int value) = nullptr;
3116
+
3117
+ // what we put in client cert requests
3118
+ bssl::UniquePtr<STACK_OF(CRYPTO_BUFFER)> client_CA;
3119
+
3120
+ // cached_x509_client_CA is a cache of parsed versions of the elements of
3121
+ // |client_CA|.
3122
+ STACK_OF(X509_NAME) *cached_x509_client_CA = nullptr;
3123
+
3124
+
3125
+ // Default values to use in SSL structures follow (these are copied by
3126
+ // SSL_new)
3127
+
3128
+ uint32_t options = 0;
3129
+ // Disable the auto-chaining feature by default. wpa_supplicant relies on this
3130
+ // feature, but require callers opt into it.
3131
+ uint32_t mode = SSL_MODE_NO_AUTO_CHAIN;
3132
+ uint32_t max_cert_list = SSL_MAX_CERT_LIST_DEFAULT;
3133
+
3134
+ bssl::UniquePtr<bssl::CERT> cert;
3135
+
3136
+ // callback that allows applications to peek at protocol messages
3137
+ void (*msg_callback)(int write_p, int version, int content_type,
3138
+ const void *buf, size_t len, SSL *ssl,
3139
+ void *arg) = nullptr;
3140
+ void *msg_callback_arg = nullptr;
3141
+
3142
+ int verify_mode = SSL_VERIFY_NONE;
3143
+ int (*default_verify_callback)(int ok, X509_STORE_CTX *ctx) =
3144
+ nullptr; // called 'verify_callback' in the SSL
3145
+
3146
+ X509_VERIFY_PARAM *param = nullptr;
3147
+
3148
+ // select_certificate_cb is called before most ClientHello processing and
3149
+ // before the decision whether to resume a session is made. See
3150
+ // |ssl_select_cert_result_t| for details of the return values.
3151
+ ssl_select_cert_result_t (*select_certificate_cb)(const SSL_CLIENT_HELLO *) =
3152
+ nullptr;
3153
+
3154
+ // dos_protection_cb is called once the resumption decision for a ClientHello
3155
+ // has been made. It returns one to continue the handshake or zero to
3156
+ // abort.
3157
+ int (*dos_protection_cb)(const SSL_CLIENT_HELLO *) = nullptr;
3158
+
3159
+ // Controls whether to verify certificates when resuming connections. They
3160
+ // were already verified when the connection was first made, so the default is
3161
+ // false. For now, this is only respected on clients, not servers.
3162
+ bool reverify_on_resume = false;
3163
+
3164
+ // Maximum amount of data to send in one fragment. actual record size can be
3165
+ // more than this due to padding and MAC overheads.
3166
+ uint16_t max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;
3167
+
3168
+ // TLS extensions servername callback
3169
+ int (*servername_callback)(SSL *, int *, void *) = nullptr;
3170
+ void *servername_arg = nullptr;
3171
+
3172
+ // RFC 4507 session ticket keys. |ticket_key_current| may be NULL before the
3173
+ // first handshake and |ticket_key_prev| may be NULL at any time.
3174
+ // Automatically generated ticket keys are rotated as needed at handshake
3175
+ // time. Hence, all access must be synchronized through |lock|.
3176
+ bssl::UniquePtr<bssl::TicketKey> ticket_key_current;
3177
+ bssl::UniquePtr<bssl::TicketKey> ticket_key_prev;
3178
+
3179
+ // Callback to support customisation of ticket key setting
3180
+ int (*ticket_key_cb)(SSL *ssl, uint8_t *name, uint8_t *iv,
3181
+ EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc) = nullptr;
3182
+
3183
+ // Server-only: psk_identity_hint is the default identity hint to send in
3184
+ // PSK-based key exchanges.
3185
+ bssl::UniquePtr<char> psk_identity_hint;
3186
+
3187
+ unsigned (*psk_client_callback)(SSL *ssl, const char *hint, char *identity,
3188
+ unsigned max_identity_len, uint8_t *psk,
3189
+ unsigned max_psk_len) = nullptr;
3190
+ unsigned (*psk_server_callback)(SSL *ssl, const char *identity, uint8_t *psk,
3191
+ unsigned max_psk_len) = nullptr;
3192
+
3193
+
3194
+ // Next protocol negotiation information
3195
+ // (for experimental NPN extension).
3196
+
3197
+ // For a server, this contains a callback function by which the set of
3198
+ // advertised protocols can be provided.
3199
+ int (*next_protos_advertised_cb)(SSL *ssl, const uint8_t **out,
3200
+ unsigned *out_len, void *arg) = nullptr;
3201
+ void *next_protos_advertised_cb_arg = nullptr;
3202
+ // For a client, this contains a callback function that selects the
3203
+ // next protocol from the list provided by the server.
3204
+ int (*next_proto_select_cb)(SSL *ssl, uint8_t **out, uint8_t *out_len,
3205
+ const uint8_t *in, unsigned in_len,
3206
+ void *arg) = nullptr;
3207
+ void *next_proto_select_cb_arg = nullptr;
3208
+
3209
+ // ALPN information
3210
+ // (we are in the process of transitioning from NPN to ALPN.)
3211
+
3212
+ // For a server, this contains a callback function that allows the
3213
+ // server to select the protocol for the connection.
3214
+ // out: on successful return, this must point to the raw protocol
3215
+ // name (without the length prefix).
3216
+ // outlen: on successful return, this contains the length of |*out|.
3217
+ // in: points to the client's list of supported protocols in
3218
+ // wire-format.
3219
+ // inlen: the length of |in|.
3220
+ int (*alpn_select_cb)(SSL *ssl, const uint8_t **out, uint8_t *out_len,
3221
+ const uint8_t *in, unsigned in_len,
3222
+ void *arg) = nullptr;
3223
+ void *alpn_select_cb_arg = nullptr;
3224
+
3225
+ // For a client, this contains the list of supported protocols in wire
3226
+ // format.
3227
+ bssl::Array<uint8_t> alpn_client_proto_list;
3228
+
3229
+ // SRTP profiles we are willing to do from RFC 5764
3230
+ bssl::UniquePtr<STACK_OF(SRTP_PROTECTION_PROFILE)> srtp_profiles;
3231
+
3232
+ // Defined compression algorithms for certificates.
3233
+ bssl::GrowableArray<bssl::CertCompressionAlg> cert_compression_algs;
3234
+
3235
+ // Supported group values inherited by SSL structure
3236
+ bssl::Array<uint16_t> supported_group_list;
3237
+
3238
+ // The client's Channel ID private key.
3239
+ bssl::UniquePtr<EVP_PKEY> channel_id_private;
3240
+
3241
+ // keylog_callback, if not NULL, is the key logging callback. See
3242
+ // |SSL_CTX_set_keylog_callback|.
3243
+ void (*keylog_callback)(const SSL *ssl, const char *line) = nullptr;
3244
+
3245
+ // current_time_cb, if not NULL, is the function to use to get the current
3246
+ // time. It sets |*out_clock| to the current time. The |ssl| argument is
3247
+ // always NULL. See |SSL_CTX_set_current_time_cb|.
3248
+ void (*current_time_cb)(const SSL *ssl, struct timeval *out_clock) = nullptr;
3249
+
3250
+ // pool is used for all |CRYPTO_BUFFER|s in case we wish to share certificate
3251
+ // memory.
3252
+ CRYPTO_BUFFER_POOL *pool = nullptr;
3253
+
3254
+ // ticket_aead_method contains function pointers for opening and sealing
3255
+ // session tickets.
3256
+ const SSL_TICKET_AEAD_METHOD *ticket_aead_method = nullptr;
3257
+
3258
+ // legacy_ocsp_callback implements an OCSP-related callback for OpenSSL
3259
+ // compatibility.
3260
+ int (*legacy_ocsp_callback)(SSL *ssl, void *arg) = nullptr;
3261
+ void *legacy_ocsp_callback_arg = nullptr;
3262
+
3263
+ // verify_sigalgs, if not empty, is the set of signature algorithms
3264
+ // accepted from the peer in decreasing order of preference.
3265
+ bssl::Array<uint16_t> verify_sigalgs;
3266
+
3267
+ // retain_only_sha256_of_client_certs is true if we should compute the SHA256
3268
+ // hash of the peer's certificate and then discard it to save memory and
3269
+ // session space. Only effective on the server side.
3270
+ bool retain_only_sha256_of_client_certs : 1;
3271
+
3272
+ // quiet_shutdown is true if the connection should not send a close_notify on
3273
+ // shutdown.
3274
+ bool quiet_shutdown : 1;
3275
+
3276
+ // ocsp_stapling_enabled is only used by client connections and indicates
3277
+ // whether OCSP stapling will be requested.
3278
+ bool ocsp_stapling_enabled : 1;
3279
+
3280
+ // If true, a client will request certificate timestamps.
3281
+ bool signed_cert_timestamps_enabled : 1;
3282
+
3283
+ // channel_id_enabled is whether Channel ID is enabled. For a server, means
3284
+ // that we'll accept Channel IDs from clients. For a client, means that we'll
3285
+ // advertise support.
3286
+ bool channel_id_enabled : 1;
3287
+
3288
+ // grease_enabled is whether draft-davidben-tls-grease-01 is enabled.
3289
+ bool grease_enabled : 1;
3290
+
3291
+ // allow_unknown_alpn_protos is whether the client allows unsolicited ALPN
3292
+ // protocols from the peer.
3293
+ bool allow_unknown_alpn_protos : 1;
3294
+
3295
+ // ed25519_enabled is whether Ed25519 is advertised in the handshake.
3296
+ bool ed25519_enabled : 1;
3297
+
3298
+ // rsa_pss_rsae_certs_enabled is whether rsa_pss_rsae_* are supported by the
3299
+ // certificate verifier.
3300
+ bool rsa_pss_rsae_certs_enabled : 1;
3301
+
3302
+ // false_start_allowed_without_alpn is whether False Start (if
3303
+ // |SSL_MODE_ENABLE_FALSE_START| is enabled) is allowed without ALPN.
3304
+ bool false_start_allowed_without_alpn : 1;
3305
+
3306
+ // ignore_tls13_downgrade is whether a connection should continue when the
3307
+ // server random signals a downgrade.
3308
+ bool ignore_tls13_downgrade:1;
3309
+
3310
+ // handoff indicates that a server should stop after receiving the
3311
+ // ClientHello and pause the handshake in such a way that |SSL_get_error|
3312
+ // returns |SSL_ERROR_HANDOFF|.
3313
+ bool handoff : 1;
3314
+
3315
+ // If enable_early_data is true, early data can be sent and accepted.
3316
+ bool enable_early_data : 1;
3317
+
3318
+ // pq_experiment_signal indicates that an empty extension should be sent
3319
+ // (for clients) or echoed (for servers) to indicate participation in an
3320
+ // experiment of post-quantum key exchanges.
3321
+ bool pq_experiment_signal : 1;
3322
+
3323
+ private:
3324
+ ~ssl_ctx_st();
3325
+ friend void SSL_CTX_free(SSL_CTX *);
3326
+ };
3327
+
3328
+ struct ssl_st {
3329
+ explicit ssl_st(SSL_CTX *ctx_arg);
3330
+ ssl_st(const ssl_st &) = delete;
3331
+ ssl_st &operator=(const ssl_st &) = delete;
3332
+ ~ssl_st();
3333
+
3334
+ // method is the method table corresponding to the current protocol (DTLS or
3335
+ // TLS).
3336
+ const bssl::SSL_PROTOCOL_METHOD *method = nullptr;
3337
+
3338
+ // config is a container for handshake configuration. Accesses to this field
3339
+ // should check for nullptr, since configuration may be shed after the
3340
+ // handshake completes. (If you have the |SSL_HANDSHAKE| object at hand, use
3341
+ // that instead, and skip the null check.)
3342
+ bssl::UniquePtr<bssl::SSL_CONFIG> config;
3343
+
3344
+ // version is the protocol version.
3345
+ uint16_t version = 0;
3346
+
3347
+ uint16_t max_send_fragment = 0;
3348
+
3349
+ // There are 2 BIO's even though they are normally both the same. This is so
3350
+ // data can be read and written to different handlers
3351
+
3352
+ bssl::UniquePtr<BIO> rbio; // used by SSL_read
3353
+ bssl::UniquePtr<BIO> wbio; // used by SSL_write
3354
+
3355
+ // do_handshake runs the handshake. On completion, it returns |ssl_hs_ok|.
3356
+ // Otherwise, it returns a value corresponding to what operation is needed to
3357
+ // progress.
3358
+ bssl::ssl_hs_wait_t (*do_handshake)(bssl::SSL_HANDSHAKE *hs) = nullptr;
3359
+
3360
+ bssl::SSL3_STATE *s3 = nullptr; // TLS variables
3361
+ bssl::DTLS1_STATE *d1 = nullptr; // DTLS variables
3362
+
3363
+ // callback that allows applications to peek at protocol messages
3364
+ void (*msg_callback)(int write_p, int version, int content_type,
3365
+ const void *buf, size_t len, SSL *ssl,
3366
+ void *arg) = nullptr;
3367
+ void *msg_callback_arg = nullptr;
3368
+
3369
+ // session info
3370
+
3371
+ // initial_timeout_duration_ms is the default DTLS timeout duration in
3372
+ // milliseconds. It's used to initialize the timer any time it's restarted.
3373
+ //
3374
+ // RFC 6347 states that implementations SHOULD use an initial timer value of 1
3375
+ // second.
3376
+ unsigned initial_timeout_duration_ms = 1000;
3377
+
3378
+ // session is the configured session to be offered by the client. This session
3379
+ // is immutable.
3380
+ bssl::UniquePtr<SSL_SESSION> session;
3381
+
3382
+ void (*info_callback)(const SSL *ssl, int type, int value) = nullptr;
3383
+
3384
+ bssl::UniquePtr<SSL_CTX> ctx;
3385
+
3386
+ // session_ctx is the |SSL_CTX| used for the session cache and related
3387
+ // settings.
3388
+ bssl::UniquePtr<SSL_CTX> session_ctx;
3389
+
3390
+ // extra application data
3391
+ CRYPTO_EX_DATA ex_data;
3392
+
3393
+ uint32_t options = 0; // protocol behaviour
3394
+ uint32_t mode = 0; // API behaviour
3395
+ uint32_t max_cert_list = 0;
3396
+ bssl::UniquePtr<char> hostname;
3397
+
3398
+ // quic_method is the method table corresponding to the QUIC hooks.
3399
+ const SSL_QUIC_METHOD *quic_method = nullptr;
3400
+
3401
+ // renegotiate_mode controls how peer renegotiation attempts are handled.
3402
+ ssl_renegotiate_mode_t renegotiate_mode = ssl_renegotiate_never;
3403
+
3404
+ // server is true iff the this SSL* is the server half. Note: before the SSL*
3405
+ // is initialized by either SSL_set_accept_state or SSL_set_connect_state,
3406
+ // the side is not determined. In this state, server is always false.
3407
+ bool server : 1;
3408
+
3409
+ // quiet_shutdown is true if the connection should not send a close_notify on
3410
+ // shutdown.
3411
+ bool quiet_shutdown : 1;
3412
+
3413
+ // If enable_early_data is true, early data can be sent and accepted.
3414
+ bool enable_early_data : 1;
3055
3415
  };
3056
3416
 
3057
- // The following types back public C-exposed types which must live in the global
3058
- // namespace. We use subclassing so the implementations may be C++ types with
3059
- // methods and destructor without polluting the global namespace.
3060
- struct ssl_ctx_st : public bssl::SSLContext {};
3061
- struct ssl_st : public bssl::SSLConnection {};
3417
+ struct ssl_session_st {
3418
+ explicit ssl_session_st(const bssl::SSL_X509_METHOD *method);
3419
+ ssl_session_st(const ssl_session_st &) = delete;
3420
+ ssl_session_st &operator=(const ssl_session_st &) = delete;
3421
+
3422
+ CRYPTO_refcount_t references = 1;
3423
+
3424
+ // ssl_version is the (D)TLS version that established the session.
3425
+ uint16_t ssl_version = 0;
3426
+
3427
+ // group_id is the ID of the ECDH group used to establish this session or zero
3428
+ // if not applicable or unknown.
3429
+ uint16_t group_id = 0;
3430
+
3431
+ // peer_signature_algorithm is the signature algorithm used to authenticate
3432
+ // the peer, or zero if not applicable or unknown.
3433
+ uint16_t peer_signature_algorithm = 0;
3434
+
3435
+ // master_key, in TLS 1.2 and below, is the master secret associated with the
3436
+ // session. In TLS 1.3 and up, it is the resumption secret.
3437
+ int master_key_length = 0;
3438
+ uint8_t master_key[SSL_MAX_MASTER_KEY_LENGTH] = {0};
3439
+
3440
+ // session_id - valid?
3441
+ unsigned session_id_length = 0;
3442
+ uint8_t session_id[SSL_MAX_SSL_SESSION_ID_LENGTH] = {0};
3443
+ // this is used to determine whether the session is being reused in
3444
+ // the appropriate context. It is up to the application to set this,
3445
+ // via SSL_new
3446
+ uint8_t sid_ctx_length = 0;
3447
+ uint8_t sid_ctx[SSL_MAX_SID_CTX_LENGTH] = {0};
3448
+
3449
+ bssl::UniquePtr<char> psk_identity;
3450
+
3451
+ // certs contains the certificate chain from the peer, starting with the leaf
3452
+ // certificate.
3453
+ bssl::UniquePtr<STACK_OF(CRYPTO_BUFFER)> certs;
3454
+
3455
+ const bssl::SSL_X509_METHOD *x509_method = nullptr;
3456
+
3457
+ // x509_peer is the peer's certificate.
3458
+ X509 *x509_peer = nullptr;
3459
+
3460
+ // x509_chain is the certificate chain sent by the peer. NOTE: for historical
3461
+ // reasons, when a client (so the peer is a server), the chain includes
3462
+ // |peer|, but when a server it does not.
3463
+ STACK_OF(X509) *x509_chain = nullptr;
3464
+
3465
+ // x509_chain_without_leaf is a lazily constructed copy of |x509_chain| that
3466
+ // omits the leaf certificate. This exists because OpenSSL, historically,
3467
+ // didn't include the leaf certificate in the chain for a server, but did for
3468
+ // a client. The |x509_chain| always includes it and, if an API call requires
3469
+ // a chain without, it is stored here.
3470
+ STACK_OF(X509) *x509_chain_without_leaf = nullptr;
3471
+
3472
+ // verify_result is the result of certificate verification in the case of
3473
+ // non-fatal certificate errors.
3474
+ long verify_result = X509_V_ERR_INVALID_CALL;
3475
+
3476
+ // timeout is the lifetime of the session in seconds, measured from |time|.
3477
+ // This is renewable up to |auth_timeout|.
3478
+ uint32_t timeout = SSL_DEFAULT_SESSION_TIMEOUT;
3479
+
3480
+ // auth_timeout is the non-renewable lifetime of the session in seconds,
3481
+ // measured from |time|.
3482
+ uint32_t auth_timeout = SSL_DEFAULT_SESSION_TIMEOUT;
3483
+
3484
+ // time is the time the session was issued, measured in seconds from the UNIX
3485
+ // epoch.
3486
+ uint64_t time = 0;
3487
+
3488
+ const SSL_CIPHER *cipher = nullptr;
3489
+
3490
+ CRYPTO_EX_DATA ex_data; // application specific data
3491
+
3492
+ // These are used to make removal of session-ids more efficient and to
3493
+ // implement a maximum cache size.
3494
+ SSL_SESSION *prev = nullptr, *next = nullptr;
3495
+
3496
+ bssl::Array<uint8_t> ticket;
3497
+
3498
+ bssl::UniquePtr<CRYPTO_BUFFER> signed_cert_timestamp_list;
3499
+
3500
+ // The OCSP response that came with the session.
3501
+ bssl::UniquePtr<CRYPTO_BUFFER> ocsp_response;
3502
+
3503
+ // peer_sha256 contains the SHA-256 hash of the peer's certificate if
3504
+ // |peer_sha256_valid| is true.
3505
+ uint8_t peer_sha256[SHA256_DIGEST_LENGTH] = {0};
3506
+
3507
+ // original_handshake_hash contains the handshake hash (either SHA-1+MD5 or
3508
+ // SHA-2, depending on TLS version) for the original, full handshake that
3509
+ // created a session. This is used by Channel IDs during resumption.
3510
+ uint8_t original_handshake_hash[EVP_MAX_MD_SIZE] = {0};
3511
+ uint8_t original_handshake_hash_len = 0;
3512
+
3513
+ uint32_t ticket_lifetime_hint = 0; // Session lifetime hint in seconds
3514
+
3515
+ uint32_t ticket_age_add = 0;
3516
+
3517
+ // ticket_max_early_data is the maximum amount of data allowed to be sent as
3518
+ // early data. If zero, 0-RTT is disallowed.
3519
+ uint32_t ticket_max_early_data = 0;
3520
+
3521
+ // early_alpn is the ALPN protocol from the initial handshake. This is only
3522
+ // stored for TLS 1.3 and above in order to enforce ALPN matching for 0-RTT
3523
+ // resumptions.
3524
+ bssl::Array<uint8_t> early_alpn;
3525
+
3526
+ // extended_master_secret is whether the master secret in this session was
3527
+ // generated using EMS and thus isn't vulnerable to the Triple Handshake
3528
+ // attack.
3529
+ bool extended_master_secret : 1;
3530
+
3531
+ // peer_sha256_valid is whether |peer_sha256| is valid.
3532
+ bool peer_sha256_valid : 1; // Non-zero if peer_sha256 is valid
3533
+
3534
+ // not_resumable is used to indicate that session resumption is disallowed.
3535
+ bool not_resumable : 1;
3536
+
3537
+ // ticket_age_add_valid is whether |ticket_age_add| is valid.
3538
+ bool ticket_age_add_valid : 1;
3539
+
3540
+ // is_server is whether this session was created by a server.
3541
+ bool is_server : 1;
3542
+
3543
+ private:
3544
+ ~ssl_session_st();
3545
+ friend void SSL_SESSION_free(SSL_SESSION *);
3546
+ };
3062
3547
 
3063
3548
 
3064
3549
  #endif // OPENSSL_HEADER_SSL_INTERNAL_H