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
@@ -122,7 +122,7 @@
122
122
  #include "internal.h"
123
123
 
124
124
 
125
- namespace bssl {
125
+ BSSL_NAMESPACE_BEGIN
126
126
 
127
127
  SSL_HANDSHAKE::SSL_HANDSHAKE(SSL *ssl_arg)
128
128
  : ssl(ssl_arg),
@@ -130,12 +130,12 @@ SSL_HANDSHAKE::SSL_HANDSHAKE(SSL *ssl_arg)
130
130
  needs_psk_binder(false),
131
131
  received_hello_retry_request(false),
132
132
  sent_hello_retry_request(false),
133
- received_custom_extension(false),
134
133
  handshake_finalized(false),
135
134
  accept_psk_mode(false),
136
135
  cert_request(false),
137
136
  certificate_status_expected(false),
138
137
  ocsp_stapling_requested(false),
138
+ delegated_credential_requested(false),
139
139
  should_ack_sni(false),
140
140
  in_false_start(false),
141
141
  in_early_data(false),
@@ -146,17 +146,32 @@ SSL_HANDSHAKE::SSL_HANDSHAKE(SSL *ssl_arg)
146
146
  ticket_expected(false),
147
147
  extended_master_secret(false),
148
148
  pending_private_key_op(false),
149
- grease_seeded(false) {
149
+ grease_seeded(false),
150
+ handback(false),
151
+ cert_compression_negotiated(false),
152
+ apply_jdk11_workaround(false) {
153
+ assert(ssl);
150
154
  }
151
155
 
152
156
  SSL_HANDSHAKE::~SSL_HANDSHAKE() {
153
157
  ssl->ctx->x509_method->hs_flush_cached_ca_names(this);
154
158
  }
155
159
 
160
+ void SSL_HANDSHAKE::ResizeSecrets(size_t hash_len) {
161
+ if (hash_len > SSL_MAX_MD_SIZE) {
162
+ abort();
163
+ }
164
+ hash_len_ = hash_len;
165
+ }
166
+
156
167
  UniquePtr<SSL_HANDSHAKE> ssl_handshake_new(SSL *ssl) {
157
168
  UniquePtr<SSL_HANDSHAKE> hs = MakeUnique<SSL_HANDSHAKE>(ssl);
158
- if (!hs ||
159
- !hs->transcript.Init()) {
169
+ if (!hs || !hs->transcript.Init()) {
170
+ return nullptr;
171
+ }
172
+ hs->config = ssl->config.get();
173
+ if (!hs->config) {
174
+ assert(hs->config);
160
175
  return nullptr;
161
176
  }
162
177
  return hs;
@@ -189,7 +204,8 @@ size_t ssl_max_handshake_message_len(const SSL *ssl) {
189
204
  static const size_t kMaxMessageLen = 16384;
190
205
 
191
206
  if (SSL_in_init(ssl)) {
192
- if ((!ssl->server || (ssl->verify_mode & SSL_VERIFY_PEER)) &&
207
+ SSL_CONFIG *config = ssl->config.get(); // SSL_in_init() implies not NULL.
208
+ if ((!ssl->server || (config->verify_mode & SSL_VERIFY_PEER)) &&
193
209
  kMaxMessageLen < ssl->max_cert_list) {
194
210
  return ssl->max_cert_list;
195
211
  }
@@ -272,16 +288,6 @@ int ssl_parse_extensions(const CBS *cbs, uint8_t *out_alert,
272
288
  return 1;
273
289
  }
274
290
 
275
- static void set_crypto_buffer(CRYPTO_BUFFER **dest, CRYPTO_BUFFER *src) {
276
- // TODO(davidben): Remove this helper once |SSL_SESSION| can use |UniquePtr|
277
- // and |UniquePtr| has up_ref helpers.
278
- CRYPTO_BUFFER_free(*dest);
279
- *dest = src;
280
- if (src != nullptr) {
281
- CRYPTO_BUFFER_up_ref(src);
282
- }
283
- }
284
-
285
291
  enum ssl_verify_result_t ssl_verify_peer_cert(SSL_HANDSHAKE *hs) {
286
292
  SSL *const ssl = hs->ssl;
287
293
  const SSL_SESSION *prev_session = ssl->s3->established_session.get();
@@ -291,18 +297,19 @@ enum ssl_verify_result_t ssl_verify_peer_cert(SSL_HANDSHAKE *hs) {
291
297
  // so this check is sufficient to ensure the reported peer certificate never
292
298
  // changes on renegotiation.
293
299
  assert(!ssl->server);
294
- if (sk_CRYPTO_BUFFER_num(prev_session->certs) !=
295
- sk_CRYPTO_BUFFER_num(hs->new_session->certs)) {
300
+ if (sk_CRYPTO_BUFFER_num(prev_session->certs.get()) !=
301
+ sk_CRYPTO_BUFFER_num(hs->new_session->certs.get())) {
296
302
  OPENSSL_PUT_ERROR(SSL, SSL_R_SERVER_CERT_CHANGED);
297
303
  ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
298
304
  return ssl_verify_invalid;
299
305
  }
300
306
 
301
- for (size_t i = 0; i < sk_CRYPTO_BUFFER_num(hs->new_session->certs); i++) {
307
+ for (size_t i = 0; i < sk_CRYPTO_BUFFER_num(hs->new_session->certs.get());
308
+ i++) {
302
309
  const CRYPTO_BUFFER *old_cert =
303
- sk_CRYPTO_BUFFER_value(prev_session->certs, i);
310
+ sk_CRYPTO_BUFFER_value(prev_session->certs.get(), i);
304
311
  const CRYPTO_BUFFER *new_cert =
305
- sk_CRYPTO_BUFFER_value(hs->new_session->certs, i);
312
+ sk_CRYPTO_BUFFER_value(hs->new_session->certs.get(), i);
306
313
  if (CRYPTO_BUFFER_len(old_cert) != CRYPTO_BUFFER_len(new_cert) ||
307
314
  OPENSSL_memcmp(CRYPTO_BUFFER_data(old_cert),
308
315
  CRYPTO_BUFFER_data(new_cert),
@@ -317,25 +324,24 @@ enum ssl_verify_result_t ssl_verify_peer_cert(SSL_HANDSHAKE *hs) {
317
324
  // certificate. Since we only authenticated the previous one, copy other
318
325
  // authentication from the established session and ignore what was newly
319
326
  // received.
320
- set_crypto_buffer(&hs->new_session->ocsp_response,
321
- prev_session->ocsp_response);
322
- set_crypto_buffer(&hs->new_session->signed_cert_timestamp_list,
323
- prev_session->signed_cert_timestamp_list);
327
+ hs->new_session->ocsp_response = UpRef(prev_session->ocsp_response);
328
+ hs->new_session->signed_cert_timestamp_list =
329
+ UpRef(prev_session->signed_cert_timestamp_list);
324
330
  hs->new_session->verify_result = prev_session->verify_result;
325
331
  return ssl_verify_ok;
326
332
  }
327
333
 
328
334
  uint8_t alert = SSL_AD_CERTIFICATE_UNKNOWN;
329
335
  enum ssl_verify_result_t ret;
330
- if (ssl->custom_verify_callback != nullptr) {
331
- ret = ssl->custom_verify_callback(ssl, &alert);
336
+ if (hs->config->custom_verify_callback != nullptr) {
337
+ ret = hs->config->custom_verify_callback(ssl, &alert);
332
338
  switch (ret) {
333
339
  case ssl_verify_ok:
334
340
  hs->new_session->verify_result = X509_V_OK;
335
341
  break;
336
342
  case ssl_verify_invalid:
337
343
  // If |SSL_VERIFY_NONE|, the error is non-fatal, but we keep the result.
338
- if (ssl->verify_mode == SSL_VERIFY_NONE) {
344
+ if (hs->config->verify_mode == SSL_VERIFY_NONE) {
339
345
  ERR_clear_error();
340
346
  ret = ssl_verify_ok;
341
347
  }
@@ -346,7 +352,7 @@ enum ssl_verify_result_t ssl_verify_peer_cert(SSL_HANDSHAKE *hs) {
346
352
  }
347
353
  } else {
348
354
  ret = ssl->ctx->x509_method->session_verify_cert_chain(
349
- hs->new_session.get(), ssl, &alert)
355
+ hs->new_session.get(), hs, &alert)
350
356
  ? ssl_verify_ok
351
357
  : ssl_verify_invalid;
352
358
  }
@@ -356,6 +362,48 @@ enum ssl_verify_result_t ssl_verify_peer_cert(SSL_HANDSHAKE *hs) {
356
362
  ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
357
363
  }
358
364
 
365
+ // Emulate OpenSSL's client OCSP callback. OpenSSL verifies certificates
366
+ // before it receives the OCSP, so it needs a second callback for OCSP.
367
+ if (ret == ssl_verify_ok && !ssl->server &&
368
+ hs->config->ocsp_stapling_enabled &&
369
+ ssl->ctx->legacy_ocsp_callback != nullptr) {
370
+ int cb_ret =
371
+ ssl->ctx->legacy_ocsp_callback(ssl, ssl->ctx->legacy_ocsp_callback_arg);
372
+ if (cb_ret <= 0) {
373
+ OPENSSL_PUT_ERROR(SSL, SSL_R_OCSP_CB_ERROR);
374
+ ssl_send_alert(ssl, SSL3_AL_FATAL,
375
+ cb_ret == 0 ? SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE
376
+ : SSL_AD_INTERNAL_ERROR);
377
+ ret = ssl_verify_invalid;
378
+ }
379
+ }
380
+
381
+ return ret;
382
+ }
383
+
384
+ // Verifies a stored certificate when resuming a session. A few things are
385
+ // different from verify_peer_cert:
386
+ // 1. We can't be renegotiating if we're resuming a session.
387
+ // 2. The session is immutable, so we don't support verify_mode ==
388
+ // SSL_VERIFY_NONE
389
+ // 3. We don't call the OCSP callback.
390
+ // 4. We only support custom verify callbacks.
391
+ enum ssl_verify_result_t ssl_reverify_peer_cert(SSL_HANDSHAKE *hs) {
392
+ SSL *const ssl = hs->ssl;
393
+ assert(ssl->s3->established_session == nullptr);
394
+ assert(hs->config->verify_mode != SSL_VERIFY_NONE);
395
+
396
+ uint8_t alert = SSL_AD_CERTIFICATE_UNKNOWN;
397
+ enum ssl_verify_result_t ret = ssl_verify_invalid;
398
+ if (hs->config->custom_verify_callback != nullptr) {
399
+ ret = hs->config->custom_verify_callback(ssl, &alert);
400
+ }
401
+
402
+ if (ret == ssl_verify_invalid) {
403
+ OPENSSL_PUT_ERROR(SSL, SSL_R_CERTIFICATE_VERIFY_FAILED);
404
+ ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
405
+ }
406
+
359
407
  return ret;
360
408
  }
361
409
 
@@ -408,20 +456,18 @@ enum ssl_hs_wait_t ssl_get_finished(SSL_HANDSHAKE *hs) {
408
456
  }
409
457
 
410
458
  // Copy the Finished so we can use it for renegotiation checks.
411
- if (ssl->version != SSL3_VERSION) {
412
- if (finished_len > sizeof(ssl->s3->previous_client_finished) ||
413
- finished_len > sizeof(ssl->s3->previous_server_finished)) {
414
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
415
- return ssl_hs_error;
416
- }
459
+ if (finished_len > sizeof(ssl->s3->previous_client_finished) ||
460
+ finished_len > sizeof(ssl->s3->previous_server_finished)) {
461
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
462
+ return ssl_hs_error;
463
+ }
417
464
 
418
- if (ssl->server) {
419
- OPENSSL_memcpy(ssl->s3->previous_client_finished, finished, finished_len);
420
- ssl->s3->previous_client_finished_len = finished_len;
421
- } else {
422
- OPENSSL_memcpy(ssl->s3->previous_server_finished, finished, finished_len);
423
- ssl->s3->previous_server_finished_len = finished_len;
424
- }
465
+ if (ssl->server) {
466
+ OPENSSL_memcpy(ssl->s3->previous_client_finished, finished, finished_len);
467
+ ssl->s3->previous_client_finished_len = finished_len;
468
+ } else {
469
+ OPENSSL_memcpy(ssl->s3->previous_server_finished, finished, finished_len);
470
+ ssl->s3->previous_server_finished_len = finished_len;
425
471
  }
426
472
 
427
473
  ssl->method->next_message(ssl);
@@ -440,27 +486,25 @@ bool ssl_send_finished(SSL_HANDSHAKE *hs) {
440
486
  }
441
487
 
442
488
  // Log the master secret, if logging is enabled.
443
- if (!ssl_log_secret(ssl, "CLIENT_RANDOM",
444
- session->master_key,
445
- session->master_key_length)) {
489
+ if (!ssl_log_secret(
490
+ ssl, "CLIENT_RANDOM",
491
+ MakeConstSpan(session->master_key, session->master_key_length))) {
446
492
  return 0;
447
493
  }
448
494
 
449
495
  // Copy the Finished so we can use it for renegotiation checks.
450
- if (ssl->version != SSL3_VERSION) {
451
- if (finished_len > sizeof(ssl->s3->previous_client_finished) ||
452
- finished_len > sizeof(ssl->s3->previous_server_finished)) {
453
- OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
454
- return 0;
455
- }
496
+ if (finished_len > sizeof(ssl->s3->previous_client_finished) ||
497
+ finished_len > sizeof(ssl->s3->previous_server_finished)) {
498
+ OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
499
+ return 0;
500
+ }
456
501
 
457
- if (ssl->server) {
458
- OPENSSL_memcpy(ssl->s3->previous_server_finished, finished, finished_len);
459
- ssl->s3->previous_server_finished_len = finished_len;
460
- } else {
461
- OPENSSL_memcpy(ssl->s3->previous_client_finished, finished, finished_len);
462
- ssl->s3->previous_client_finished_len = finished_len;
463
- }
502
+ if (ssl->server) {
503
+ OPENSSL_memcpy(ssl->s3->previous_server_finished, finished, finished_len);
504
+ ssl->s3->previous_server_finished_len = finished_len;
505
+ } else {
506
+ OPENSSL_memcpy(ssl->s3->previous_client_finished, finished, finished_len);
507
+ ssl->s3->previous_client_finished_len = finished_len;
464
508
  }
465
509
 
466
510
  ScopedCBB cbb;
@@ -475,12 +519,13 @@ bool ssl_send_finished(SSL_HANDSHAKE *hs) {
475
519
  return 1;
476
520
  }
477
521
 
478
- bool ssl_output_cert_chain(SSL *ssl) {
522
+ bool ssl_output_cert_chain(SSL_HANDSHAKE *hs) {
479
523
  ScopedCBB cbb;
480
524
  CBB body;
481
- if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_CERTIFICATE) ||
482
- !ssl_add_cert_chain(ssl, &body) ||
483
- !ssl_add_message_cbb(ssl, cbb.get())) {
525
+ if (!hs->ssl->method->init_message(hs->ssl, cbb.get(), &body,
526
+ SSL3_MT_CERTIFICATE) ||
527
+ !ssl_add_cert_chain(hs, &body) ||
528
+ !ssl_add_message_cbb(hs->ssl, cbb.get())) {
484
529
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
485
530
  return false;
486
531
  }
@@ -508,6 +553,16 @@ int ssl_run_handshake(SSL_HANDSHAKE *hs, bool *out_early_return) {
508
553
  case ssl_hs_read_server_hello:
509
554
  case ssl_hs_read_message:
510
555
  case ssl_hs_read_change_cipher_spec: {
556
+ if (ssl->quic_method) {
557
+ hs->wait = ssl_hs_ok;
558
+ // The change cipher spec is omitted in QUIC.
559
+ if (hs->wait != ssl_hs_read_change_cipher_spec) {
560
+ ssl->s3->rwstate = SSL_ERROR_WANT_READ;
561
+ return -1;
562
+ }
563
+ break;
564
+ }
565
+
511
566
  uint8_t alert = SSL_AD_DECODE_ERROR;
512
567
  size_t consumed = 0;
513
568
  ssl_open_record_t ret;
@@ -556,47 +611,53 @@ int ssl_run_handshake(SSL_HANDSHAKE *hs, bool *out_early_return) {
556
611
  }
557
612
 
558
613
  case ssl_hs_certificate_selection_pending:
559
- ssl->s3->rwstate = SSL_CERTIFICATE_SELECTION_PENDING;
614
+ ssl->s3->rwstate = SSL_ERROR_PENDING_CERTIFICATE;
560
615
  hs->wait = ssl_hs_ok;
561
616
  return -1;
562
617
 
563
618
  case ssl_hs_handoff:
564
- ssl->s3->rwstate = SSL_HANDOFF;
619
+ ssl->s3->rwstate = SSL_ERROR_HANDOFF;
565
620
  hs->wait = ssl_hs_ok;
566
621
  return -1;
567
622
 
623
+ case ssl_hs_handback:
624
+ ssl->s3->rwstate = SSL_ERROR_HANDBACK;
625
+ hs->wait = ssl_hs_handback;
626
+ return -1;
627
+
568
628
  case ssl_hs_x509_lookup:
569
- ssl->s3->rwstate = SSL_X509_LOOKUP;
629
+ ssl->s3->rwstate = SSL_ERROR_WANT_X509_LOOKUP;
570
630
  hs->wait = ssl_hs_ok;
571
631
  return -1;
572
632
 
573
633
  case ssl_hs_channel_id_lookup:
574
- ssl->s3->rwstate = SSL_CHANNEL_ID_LOOKUP;
634
+ ssl->s3->rwstate = SSL_ERROR_WANT_CHANNEL_ID_LOOKUP;
575
635
  hs->wait = ssl_hs_ok;
576
636
  return -1;
577
637
 
578
638
  case ssl_hs_private_key_operation:
579
- ssl->s3->rwstate = SSL_PRIVATE_KEY_OPERATION;
639
+ ssl->s3->rwstate = SSL_ERROR_WANT_PRIVATE_KEY_OPERATION;
580
640
  hs->wait = ssl_hs_ok;
581
641
  return -1;
582
642
 
583
643
  case ssl_hs_pending_session:
584
- ssl->s3->rwstate = SSL_PENDING_SESSION;
644
+ ssl->s3->rwstate = SSL_ERROR_PENDING_SESSION;
585
645
  hs->wait = ssl_hs_ok;
586
646
  return -1;
587
647
 
588
648
  case ssl_hs_pending_ticket:
589
- ssl->s3->rwstate = SSL_PENDING_TICKET;
649
+ ssl->s3->rwstate = SSL_ERROR_PENDING_TICKET;
590
650
  hs->wait = ssl_hs_ok;
591
651
  return -1;
592
652
 
593
653
  case ssl_hs_certificate_verify:
594
- ssl->s3->rwstate = SSL_CERTIFICATE_VERIFY;
654
+ ssl->s3->rwstate = SSL_ERROR_WANT_CERTIFICATE_VERIFY;
595
655
  hs->wait = ssl_hs_ok;
596
656
  return -1;
597
657
 
598
658
  case ssl_hs_early_data_rejected:
599
- ssl->s3->rwstate = SSL_EARLY_DATA_REJECTED;
659
+ assert(ssl->s3->early_data_reason != ssl_early_data_unknown);
660
+ ssl->s3->rwstate = SSL_ERROR_EARLY_DATA_REJECTED;
600
661
  // Cause |SSL_write| to start failing immediately.
601
662
  hs->can_early_write = false;
602
663
  return -1;
@@ -627,4 +688,4 @@ int ssl_run_handshake(SSL_HANDSHAKE *hs, bool *out_early_return) {
627
688
  }
628
689
  }
629
690
 
630
- } // namespace bssl
691
+ BSSL_NAMESPACE_END
@@ -166,22 +166,25 @@
166
166
  #include <openssl/md5.h>
167
167
  #include <openssl/mem.h>
168
168
  #include <openssl/rand.h>
169
+ #include <openssl/sha.h>
169
170
 
170
171
  #include "../crypto/internal.h"
171
172
  #include "internal.h"
172
173
 
173
174
 
174
- namespace bssl {
175
+ BSSL_NAMESPACE_BEGIN
175
176
 
176
177
  enum ssl_client_hs_state_t {
177
178
  state_start_connect = 0,
178
179
  state_enter_early_data,
180
+ state_early_reverify_server_certificate,
179
181
  state_read_hello_verify_request,
180
182
  state_read_server_hello,
181
183
  state_tls13,
182
184
  state_read_server_certificate,
183
185
  state_read_certificate_status,
184
186
  state_verify_server_certificate,
187
+ state_reverify_server_certificate,
185
188
  state_read_server_key_exchange,
186
189
  state_read_certificate_request,
187
190
  state_read_server_hello_done,
@@ -199,32 +202,32 @@ enum ssl_client_hs_state_t {
199
202
 
200
203
  // ssl_get_client_disabled sets |*out_mask_a| and |*out_mask_k| to masks of
201
204
  // disabled algorithms.
202
- static void ssl_get_client_disabled(SSL *ssl, uint32_t *out_mask_a,
205
+ static void ssl_get_client_disabled(SSL_HANDSHAKE *hs, uint32_t *out_mask_a,
203
206
  uint32_t *out_mask_k) {
204
207
  *out_mask_a = 0;
205
208
  *out_mask_k = 0;
206
209
 
207
210
  // PSK requires a client callback.
208
- if (ssl->psk_client_callback == NULL) {
211
+ if (hs->config->psk_client_callback == NULL) {
209
212
  *out_mask_a |= SSL_aPSK;
210
213
  *out_mask_k |= SSL_kPSK;
211
214
  }
212
215
  }
213
216
 
214
- static int ssl_write_client_cipher_list(SSL_HANDSHAKE *hs, CBB *out) {
217
+ static bool ssl_write_client_cipher_list(SSL_HANDSHAKE *hs, CBB *out) {
215
218
  SSL *const ssl = hs->ssl;
216
219
  uint32_t mask_a, mask_k;
217
- ssl_get_client_disabled(ssl, &mask_a, &mask_k);
220
+ ssl_get_client_disabled(hs, &mask_a, &mask_k);
218
221
 
219
222
  CBB child;
220
223
  if (!CBB_add_u16_length_prefixed(out, &child)) {
221
- return 0;
224
+ return false;
222
225
  }
223
226
 
224
227
  // Add a fake cipher suite. See draft-davidben-tls-grease-01.
225
228
  if (ssl->ctx->grease_enabled &&
226
229
  !CBB_add_u16(&child, ssl_get_grease_value(hs, ssl_grease_cipher))) {
227
- return 0;
230
+ return false;
228
231
  }
229
232
 
230
233
  // Add TLS 1.3 ciphers. Order ChaCha20-Poly1305 relative to AES-GCM based on
@@ -232,20 +235,20 @@ static int ssl_write_client_cipher_list(SSL_HANDSHAKE *hs, CBB *out) {
232
235
  if (hs->max_version >= TLS1_3_VERSION) {
233
236
  if (!EVP_has_aes_hardware() &&
234
237
  !CBB_add_u16(&child, TLS1_CK_CHACHA20_POLY1305_SHA256 & 0xffff)) {
235
- return 0;
238
+ return false;
236
239
  }
237
240
  if (!CBB_add_u16(&child, TLS1_CK_AES_128_GCM_SHA256 & 0xffff) ||
238
241
  !CBB_add_u16(&child, TLS1_CK_AES_256_GCM_SHA384 & 0xffff)) {
239
- return 0;
242
+ return false;
240
243
  }
241
244
  if (EVP_has_aes_hardware() &&
242
245
  !CBB_add_u16(&child, TLS1_CK_CHACHA20_POLY1305_SHA256 & 0xffff)) {
243
- return 0;
246
+ return false;
244
247
  }
245
248
  }
246
249
 
247
250
  if (hs->min_version < TLS1_3_VERSION) {
248
- int any_enabled = 0;
251
+ bool any_enabled = false;
249
252
  for (const SSL_CIPHER *cipher : SSL_get_ciphers(ssl)) {
250
253
  // Skip disabled ciphers
251
254
  if ((cipher->algorithm_mkey & mask_k) ||
@@ -256,62 +259,53 @@ static int ssl_write_client_cipher_list(SSL_HANDSHAKE *hs, CBB *out) {
256
259
  SSL_CIPHER_get_max_version(cipher) < hs->min_version) {
257
260
  continue;
258
261
  }
259
- any_enabled = 1;
262
+ any_enabled = true;
260
263
  if (!CBB_add_u16(&child, ssl_cipher_get_value(cipher))) {
261
- return 0;
264
+ return false;
262
265
  }
263
266
  }
264
267
 
265
268
  // If all ciphers were disabled, return the error to the caller.
266
269
  if (!any_enabled && hs->max_version < TLS1_3_VERSION) {
267
270
  OPENSSL_PUT_ERROR(SSL, SSL_R_NO_CIPHERS_AVAILABLE);
268
- return 0;
269
- }
270
- }
271
-
272
- // For SSLv3, the SCSV is added. Otherwise the renegotiation extension is
273
- // added.
274
- if (hs->max_version == SSL3_VERSION &&
275
- !ssl->s3->initial_handshake_complete) {
276
- if (!CBB_add_u16(&child, SSL3_CK_SCSV & 0xffff)) {
277
- return 0;
271
+ return false;
278
272
  }
279
273
  }
280
274
 
281
275
  if (ssl->mode & SSL_MODE_SEND_FALLBACK_SCSV) {
282
276
  if (!CBB_add_u16(&child, SSL3_CK_FALLBACK_SCSV & 0xffff)) {
283
- return 0;
277
+ return false;
284
278
  }
285
279
  }
286
280
 
287
281
  return CBB_flush(out);
288
282
  }
289
283
 
290
- int ssl_write_client_hello(SSL_HANDSHAKE *hs) {
284
+ bool ssl_write_client_hello(SSL_HANDSHAKE *hs) {
291
285
  SSL *const ssl = hs->ssl;
292
286
  ScopedCBB cbb;
293
287
  CBB body;
294
288
  if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_CLIENT_HELLO)) {
295
- return 0;
289
+ return false;
296
290
  }
297
291
 
298
292
  CBB child;
299
293
  if (!CBB_add_u16(&body, hs->client_version) ||
300
294
  !CBB_add_bytes(&body, ssl->s3->client_random, SSL3_RANDOM_SIZE) ||
301
295
  !CBB_add_u8_length_prefixed(&body, &child)) {
302
- return 0;
296
+ return false;
303
297
  }
304
298
 
305
299
  // Do not send a session ID on renegotiation.
306
300
  if (!ssl->s3->initial_handshake_complete &&
307
301
  !CBB_add_bytes(&child, hs->session_id, hs->session_id_len)) {
308
- return 0;
302
+ return false;
309
303
  }
310
304
 
311
305
  if (SSL_is_dtls(ssl)) {
312
306
  if (!CBB_add_u8_length_prefixed(&body, &child) ||
313
307
  !CBB_add_bytes(&child, ssl->d1->cookie, ssl->d1->cookie_len)) {
314
- return 0;
308
+ return false;
315
309
  }
316
310
  }
317
311
 
@@ -321,19 +315,19 @@ int ssl_write_client_hello(SSL_HANDSHAKE *hs) {
321
315
  !CBB_add_u8(&body, 1 /* one compression method */) ||
322
316
  !CBB_add_u8(&body, 0 /* null compression */) ||
323
317
  !ssl_add_clienthello_tlsext(hs, &body, header_len + CBB_len(&body))) {
324
- return 0;
318
+ return false;
325
319
  }
326
320
 
327
321
  Array<uint8_t> msg;
328
322
  if (!ssl->method->finish_message(ssl, cbb.get(), &msg)) {
329
- return 0;
323
+ return false;
330
324
  }
331
325
 
332
326
  // Now that the length prefixes have been computed, fill in the placeholder
333
327
  // PSK binder.
334
328
  if (hs->needs_psk_binder &&
335
- !tls13_write_psk_binder(hs, msg.data(), msg.size())) {
336
- return 0;
329
+ !tls13_write_psk_binder(hs, MakeSpan(msg))) {
330
+ return false;
337
331
  }
338
332
 
339
333
  return ssl->method->add_message(ssl, std::move(msg));
@@ -390,16 +384,10 @@ static enum ssl_hs_wait_t do_start_connect(SSL_HANDSHAKE *hs) {
390
384
  ssl->s3->session_reused = false;
391
385
 
392
386
  // Freeze the version range.
393
- if (!ssl_get_version_range(ssl, &hs->min_version, &hs->max_version)) {
387
+ if (!ssl_get_version_range(hs, &hs->min_version, &hs->max_version)) {
394
388
  return ssl_hs_error;
395
389
  }
396
390
 
397
- // SSL 3.0 ClientHellos should use SSL 3.0 not TLS 1.0, for the record-layer
398
- // version.
399
- if (hs->max_version == SSL3_VERSION) {
400
- ssl->s3->aead_write_ctx->SetVersionIfNullCipher(SSL3_VERSION);
401
- }
402
-
403
391
  // Always advertise the ClientHello version from the original maximum version,
404
392
  // even on renegotiation. The static RSA key exchange uses this field, and
405
393
  // some servers fail when it changes across handshakes.
@@ -417,9 +405,9 @@ static enum ssl_hs_wait_t do_start_connect(SSL_HANDSHAKE *hs) {
417
405
  if (ssl->session->is_server ||
418
406
  !ssl_supports_version(hs, ssl->session->ssl_version) ||
419
407
  (ssl->session->session_id_length == 0 &&
420
- ssl->session->tlsext_ticklen == 0) ||
408
+ ssl->session->ticket.empty()) ||
421
409
  ssl->session->not_resumable ||
422
- !ssl_session_is_time_valid(ssl, ssl->session)) {
410
+ !ssl_session_is_time_valid(ssl, ssl->session.get())) {
423
411
  ssl_set_session(ssl, NULL);
424
412
  }
425
413
  }
@@ -428,8 +416,6 @@ static enum ssl_hs_wait_t do_start_connect(SSL_HANDSHAKE *hs) {
428
416
  return ssl_hs_error;
429
417
  }
430
418
 
431
- // Initialize a random session ID for the experimental TLS 1.3 variant
432
- // requiring a session id.
433
419
  if (ssl->session != nullptr &&
434
420
  !ssl->s3->initial_handshake_complete &&
435
421
  ssl->session->session_id_length > 0) {
@@ -437,6 +423,7 @@ static enum ssl_hs_wait_t do_start_connect(SSL_HANDSHAKE *hs) {
437
423
  OPENSSL_memcpy(hs->session_id, ssl->session->session_id,
438
424
  hs->session_id_len);
439
425
  } else if (hs->max_version >= TLS1_3_VERSION) {
426
+ // Initialize a random session ID.
440
427
  hs->session_id_len = sizeof(hs->session_id);
441
428
  if (!RAND_bytes(hs->session_id, hs->session_id_len)) {
442
429
  return ssl_hs_error;
@@ -469,21 +456,41 @@ static enum ssl_hs_wait_t do_enter_early_data(SSL_HANDSHAKE *hs) {
469
456
  return ssl_hs_error;
470
457
  }
471
458
 
472
- if (!tls13_init_early_key_schedule(hs, ssl->session->master_key,
473
- ssl->session->master_key_length) ||
474
- !tls13_derive_early_secrets(hs) ||
475
- !tls13_set_traffic_key(ssl, evp_aead_seal, hs->early_traffic_secret,
476
- hs->hash_len)) {
459
+ if (!tls13_init_early_key_schedule(
460
+ hs, MakeConstSpan(ssl->session->master_key,
461
+ ssl->session->master_key_length)) ||
462
+ !tls13_derive_early_secret(hs) ||
463
+ !tls13_set_early_secret_for_quic(hs)) {
464
+ return ssl_hs_error;
465
+ }
466
+ if (ssl->quic_method == nullptr &&
467
+ !tls13_set_traffic_key(ssl, ssl_encryption_early_data, evp_aead_seal,
468
+ hs->early_traffic_secret())) {
477
469
  return ssl_hs_error;
478
470
  }
479
471
 
480
472
  // Stash the early data session, so connection properties may be queried out
481
473
  // of it.
474
+ hs->early_session = UpRef(ssl->session);
475
+ hs->state = state_early_reverify_server_certificate;
476
+ return ssl_hs_ok;
477
+ }
478
+
479
+ static enum ssl_hs_wait_t do_early_reverify_server_certificate(SSL_HANDSHAKE *hs) {
480
+ if (hs->ssl->ctx->reverify_on_resume) {
481
+ switch (ssl_reverify_peer_cert(hs)) {
482
+ case ssl_verify_ok:
483
+ break;
484
+ case ssl_verify_invalid:
485
+ return ssl_hs_error;
486
+ case ssl_verify_retry:
487
+ hs->state = state_early_reverify_server_certificate;
488
+ return ssl_hs_certificate_verify;
489
+ }
490
+ }
491
+
482
492
  hs->in_early_data = true;
483
- SSL_SESSION_up_ref(ssl->session);
484
- hs->early_session.reset(ssl->session);
485
493
  hs->can_early_write = true;
486
-
487
494
  hs->state = state_read_server_hello;
488
495
  return ssl_hs_early_return;
489
496
  }
@@ -587,12 +594,13 @@ static enum ssl_hs_wait_t do_read_server_hello(SSL_HANDSHAKE *hs) {
587
594
  }
588
595
 
589
596
  // Clear some TLS 1.3 state that no longer needs to be retained.
590
- hs->key_share.reset();
597
+ hs->key_shares[0].reset();
598
+ hs->key_shares[1].reset();
591
599
  hs->key_share_bytes.Reset();
592
600
 
593
601
  // A TLS 1.2 server would not know to skip the early data we offered. Report
594
602
  // an error code sooner. The caller may use this error code to implement the
595
- // fallback described in draft-ietf-tls-tls13-18 appendix C.3.
603
+ // fallback described in RFC 8446 appendix D.3.
596
604
  if (hs->early_data_offered) {
597
605
  OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_VERSION_ON_EARLY_DATA);
598
606
  ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_PROTOCOL_VERSION);
@@ -603,22 +611,30 @@ static enum ssl_hs_wait_t do_read_server_hello(SSL_HANDSHAKE *hs) {
603
611
  OPENSSL_memcpy(ssl->s3->server_random, CBS_data(&server_random),
604
612
  SSL3_RANDOM_SIZE);
605
613
 
606
- // Measure, but do not enforce, the TLS 1.3 anti-downgrade feature, with a
607
- // different value.
608
- //
609
- // For draft TLS 1.3 versions, it is not safe to deploy this feature. However,
610
- // some TLS terminators are non-compliant and copy the origin server's value,
611
- // so we wish to measure eventual compatibility impact.
614
+ // Enforce the TLS 1.3 anti-downgrade feature.
612
615
  if (!ssl->s3->initial_handshake_complete &&
613
- hs->max_version >= TLS1_3_VERSION &&
614
- OPENSSL_memcmp(ssl->s3->server_random + SSL3_RANDOM_SIZE -
615
- sizeof(kDraftDowngradeRandom),
616
- kDraftDowngradeRandom,
617
- sizeof(kDraftDowngradeRandom)) == 0) {
618
- ssl->s3->draft_downgrade = true;
616
+ ssl_supports_version(hs, TLS1_3_VERSION)) {
617
+ static_assert(
618
+ sizeof(kTLS12DowngradeRandom) == sizeof(kTLS13DowngradeRandom),
619
+ "downgrade signals have different size");
620
+ static_assert(
621
+ sizeof(kJDK11DowngradeRandom) == sizeof(kTLS13DowngradeRandom),
622
+ "downgrade signals have different size");
623
+ auto suffix =
624
+ MakeConstSpan(ssl->s3->server_random, sizeof(ssl->s3->server_random))
625
+ .subspan(SSL3_RANDOM_SIZE - sizeof(kTLS13DowngradeRandom));
626
+ if (suffix == kTLS12DowngradeRandom || suffix == kTLS13DowngradeRandom ||
627
+ suffix == kJDK11DowngradeRandom) {
628
+ ssl->s3->tls13_downgrade = true;
629
+ if (!hs->config->ignore_tls13_downgrade) {
630
+ OPENSSL_PUT_ERROR(SSL, SSL_R_TLS13_DOWNGRADE);
631
+ ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
632
+ return ssl_hs_error;
633
+ }
634
+ }
619
635
  }
620
636
 
621
- if (!ssl->s3->initial_handshake_complete && ssl->session != NULL &&
637
+ if (!ssl->s3->initial_handshake_complete && ssl->session != nullptr &&
622
638
  ssl->session->session_id_length != 0 &&
623
639
  CBS_mem_equal(&session_id, ssl->session->session_id,
624
640
  ssl->session->session_id_length)) {
@@ -659,7 +675,7 @@ static enum ssl_hs_wait_t do_read_server_hello(SSL_HANDSHAKE *hs) {
659
675
 
660
676
  // The cipher must be allowed in the selected version and enabled.
661
677
  uint32_t mask_a, mask_k;
662
- ssl_get_client_disabled(ssl, &mask_a, &mask_k);
678
+ ssl_get_client_disabled(hs, &mask_a, &mask_k);
663
679
  if ((cipher->algorithm_mkey & mask_k) || (cipher->algorithm_auth & mask_a) ||
664
680
  SSL_CIPHER_get_min_version(cipher) > ssl_protocol_version(ssl) ||
665
681
  SSL_CIPHER_get_max_version(cipher) < ssl_protocol_version(ssl) ||
@@ -680,7 +696,7 @@ static enum ssl_hs_wait_t do_read_server_hello(SSL_HANDSHAKE *hs) {
680
696
  ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
681
697
  return ssl_hs_error;
682
698
  }
683
- if (!ssl_session_is_context_valid(ssl, ssl->session)) {
699
+ if (!ssl_session_is_context_valid(hs, ssl->session.get())) {
684
700
  // This is actually a client application bug.
685
701
  OPENSSL_PUT_ERROR(SSL,
686
702
  SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
@@ -740,7 +756,7 @@ static enum ssl_hs_wait_t do_read_server_hello(SSL_HANDSHAKE *hs) {
740
756
  return ssl_hs_error;
741
757
  }
742
758
 
743
- if (ssl->token_binding_negotiated &&
759
+ if (ssl->s3->token_binding_negotiated &&
744
760
  (!hs->extended_master_secret || !ssl->s3->send_connection_binding)) {
745
761
  OPENSSL_PUT_ERROR(SSL, SSL_R_NEGOTIATED_TB_WITHOUT_EMS_OR_RI);
746
762
  ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_UNSUPPORTED_EXTENSION);
@@ -750,7 +766,12 @@ static enum ssl_hs_wait_t do_read_server_hello(SSL_HANDSHAKE *hs) {
750
766
  ssl->method->next_message(ssl);
751
767
 
752
768
  if (ssl->session != NULL) {
753
- hs->state = state_read_session_ticket;
769
+ if (ssl->ctx->reverify_on_resume &&
770
+ ssl_cipher_uses_certificate_auth(hs->new_cipher)) {
771
+ hs->state = state_reverify_server_certificate;
772
+ } else {
773
+ hs->state = state_read_session_ticket;
774
+ }
754
775
  return ssl_hs_ok;
755
776
  }
756
777
 
@@ -788,16 +809,13 @@ static enum ssl_hs_wait_t do_read_server_certificate(SSL_HANDSHAKE *hs) {
788
809
 
789
810
  CBS body = msg.body;
790
811
  uint8_t alert = SSL_AD_DECODE_ERROR;
791
- UniquePtr<STACK_OF(CRYPTO_BUFFER)> chain;
792
- if (!ssl_parse_cert_chain(&alert, &chain, &hs->peer_pubkey, NULL, &body,
793
- ssl->ctx->pool)) {
812
+ if (!ssl_parse_cert_chain(&alert, &hs->new_session->certs, &hs->peer_pubkey,
813
+ NULL, &body, ssl->ctx->pool)) {
794
814
  ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
795
815
  return ssl_hs_error;
796
816
  }
797
- sk_CRYPTO_BUFFER_pop_free(hs->new_session->certs, CRYPTO_BUFFER_free);
798
- hs->new_session->certs = chain.release();
799
817
 
800
- if (sk_CRYPTO_BUFFER_num(hs->new_session->certs) == 0 ||
818
+ if (sk_CRYPTO_BUFFER_num(hs->new_session->certs.get()) == 0 ||
801
819
  CBS_len(&body) != 0 ||
802
820
  !ssl->ctx->x509_method->session_cache_objects(hs->new_session.get())) {
803
821
  OPENSSL_PUT_ERROR(SSL, SSL_R_DECODE_ERROR);
@@ -807,7 +825,7 @@ static enum ssl_hs_wait_t do_read_server_certificate(SSL_HANDSHAKE *hs) {
807
825
 
808
826
  if (!ssl_check_leaf_certificate(
809
827
  hs, hs->peer_pubkey.get(),
810
- sk_CRYPTO_BUFFER_value(hs->new_session->certs, 0))) {
828
+ sk_CRYPTO_BUFFER_value(hs->new_session->certs.get(), 0))) {
811
829
  ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
812
830
  return ssl_hs_error;
813
831
  }
@@ -854,9 +872,8 @@ static enum ssl_hs_wait_t do_read_certificate_status(SSL_HANDSHAKE *hs) {
854
872
  return ssl_hs_error;
855
873
  }
856
874
 
857
- CRYPTO_BUFFER_free(hs->new_session->ocsp_response);
858
- hs->new_session->ocsp_response =
859
- CRYPTO_BUFFER_new_from_CBS(&ocsp_response, ssl->ctx->pool);
875
+ hs->new_session->ocsp_response.reset(
876
+ CRYPTO_BUFFER_new_from_CBS(&ocsp_response, ssl->ctx->pool));
860
877
  if (hs->new_session->ocsp_response == nullptr) {
861
878
  ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
862
879
  return ssl_hs_error;
@@ -888,6 +905,23 @@ static enum ssl_hs_wait_t do_verify_server_certificate(SSL_HANDSHAKE *hs) {
888
905
  return ssl_hs_ok;
889
906
  }
890
907
 
908
+ static enum ssl_hs_wait_t do_reverify_server_certificate(SSL_HANDSHAKE *hs) {
909
+ assert(hs->ssl->ctx->reverify_on_resume);
910
+
911
+ switch (ssl_reverify_peer_cert(hs)) {
912
+ case ssl_verify_ok:
913
+ break;
914
+ case ssl_verify_invalid:
915
+ return ssl_hs_error;
916
+ case ssl_verify_retry:
917
+ hs->state = state_reverify_server_certificate;
918
+ return ssl_hs_certificate_verify;
919
+ }
920
+
921
+ hs->state = state_read_session_ticket;
922
+ return ssl_hs_ok;
923
+ }
924
+
891
925
  static enum ssl_hs_wait_t do_read_server_key_exchange(SSL_HANDSHAKE *hs) {
892
926
  SSL *const ssl = hs->ssl;
893
927
  SSLMessage msg;
@@ -970,15 +1004,15 @@ static enum ssl_hs_wait_t do_read_server_key_exchange(SSL_HANDSHAKE *hs) {
970
1004
  hs->new_session->group_id = group_id;
971
1005
 
972
1006
  // Ensure the group is consistent with preferences.
973
- if (!tls1_check_group_id(ssl, group_id)) {
1007
+ if (!tls1_check_group_id(hs, group_id)) {
974
1008
  OPENSSL_PUT_ERROR(SSL, SSL_R_WRONG_CURVE);
975
1009
  ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
976
1010
  return ssl_hs_error;
977
1011
  }
978
1012
 
979
1013
  // Initialize ECDH and save the peer public key for later.
980
- hs->key_share = SSLKeyShare::Create(group_id);
981
- if (!hs->key_share ||
1014
+ hs->key_shares[0] = SSLKeyShare::Create(group_id);
1015
+ if (!hs->key_shares[0] ||
982
1016
  !hs->peer_key.CopyFrom(point)) {
983
1017
  return ssl_hs_error;
984
1018
  }
@@ -1042,13 +1076,8 @@ static enum ssl_hs_wait_t do_read_server_key_exchange(SSL_HANDSHAKE *hs) {
1042
1076
  return ssl_hs_error;
1043
1077
  }
1044
1078
 
1045
- bool sig_ok = ssl_public_key_verify(ssl, signature, signature_algorithm,
1046
- hs->peer_pubkey.get(), transcript_data);
1047
- #if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
1048
- sig_ok = true;
1049
- ERR_clear_error();
1050
- #endif
1051
- if (!sig_ok) {
1079
+ if (!ssl_public_key_verify(ssl, signature, signature_algorithm,
1080
+ hs->peer_pubkey.get(), transcript_data)) {
1052
1081
  // bad signature
1053
1082
  OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SIGNATURE);
1054
1083
  ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR);
@@ -1176,8 +1205,8 @@ static enum ssl_hs_wait_t do_send_client_certificate(SSL_HANDSHAKE *hs) {
1176
1205
  }
1177
1206
 
1178
1207
  // Call cert_cb to update the certificate.
1179
- if (ssl->cert->cert_cb != NULL) {
1180
- int rv = ssl->cert->cert_cb(ssl, ssl->cert->cert_cb_arg);
1208
+ if (hs->config->cert->cert_cb != NULL) {
1209
+ int rv = hs->config->cert->cert_cb(ssl, hs->config->cert->cert_cb_arg);
1181
1210
  if (rv == 0) {
1182
1211
  ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR);
1183
1212
  OPENSSL_PUT_ERROR(SSL, SSL_R_CERT_CB_ERROR);
@@ -1189,23 +1218,13 @@ static enum ssl_hs_wait_t do_send_client_certificate(SSL_HANDSHAKE *hs) {
1189
1218
  }
1190
1219
  }
1191
1220
 
1192
- if (!ssl_has_certificate(ssl)) {
1221
+ if (!ssl_has_certificate(hs)) {
1193
1222
  // Without a client certificate, the handshake buffer may be released.
1194
1223
  hs->transcript.FreeBuffer();
1195
-
1196
- // In SSL 3.0, the Certificate message is replaced with a warning alert.
1197
- if (ssl->version == SSL3_VERSION) {
1198
- if (!ssl->method->add_alert(ssl, SSL3_AL_WARNING,
1199
- SSL_AD_NO_CERTIFICATE)) {
1200
- return ssl_hs_error;
1201
- }
1202
- hs->state = state_send_client_key_exchange;
1203
- return ssl_hs_ok;
1204
- }
1205
1224
  }
1206
1225
 
1207
1226
  if (!ssl_on_certificate_selected(hs) ||
1208
- !ssl_output_cert_chain(ssl)) {
1227
+ !ssl_output_cert_chain(hs)) {
1209
1228
  return ssl_hs_error;
1210
1229
  }
1211
1230
 
@@ -1229,21 +1248,42 @@ static enum ssl_hs_wait_t do_send_client_key_exchange(SSL_HANDSHAKE *hs) {
1229
1248
  Array<uint8_t> pms;
1230
1249
  uint32_t alg_k = hs->new_cipher->algorithm_mkey;
1231
1250
  uint32_t alg_a = hs->new_cipher->algorithm_auth;
1251
+ if (ssl_cipher_uses_certificate_auth(hs->new_cipher)) {
1252
+ CRYPTO_BUFFER *leaf =
1253
+ sk_CRYPTO_BUFFER_value(hs->new_session->certs.get(), 0);
1254
+ CBS leaf_cbs;
1255
+ CBS_init(&leaf_cbs, CRYPTO_BUFFER_data(leaf), CRYPTO_BUFFER_len(leaf));
1256
+
1257
+ // Check the key usage matches the cipher suite. We do this unconditionally
1258
+ // for non-RSA certificates. In particular, it's needed to distinguish ECDH
1259
+ // certificates, which we do not support, from ECDSA certificates.
1260
+ // Historically, we have not checked RSA key usages, so it is controlled by
1261
+ // a flag for now. See https://crbug.com/795089.
1262
+ ssl_key_usage_t intended_use = (alg_k & SSL_kRSA)
1263
+ ? key_usage_encipherment
1264
+ : key_usage_digital_signature;
1265
+ if (ssl->config->enforce_rsa_key_usage ||
1266
+ EVP_PKEY_id(hs->peer_pubkey.get()) != EVP_PKEY_RSA) {
1267
+ if (!ssl_cert_check_key_usage(&leaf_cbs, intended_use)) {
1268
+ return ssl_hs_error;
1269
+ }
1270
+ }
1271
+ }
1232
1272
 
1233
1273
  // If using a PSK key exchange, prepare the pre-shared key.
1234
1274
  unsigned psk_len = 0;
1235
1275
  uint8_t psk[PSK_MAX_PSK_LEN];
1236
1276
  if (alg_a & SSL_aPSK) {
1237
- if (ssl->psk_client_callback == NULL) {
1277
+ if (hs->config->psk_client_callback == NULL) {
1238
1278
  OPENSSL_PUT_ERROR(SSL, SSL_R_PSK_NO_CLIENT_CB);
1239
1279
  return ssl_hs_error;
1240
1280
  }
1241
1281
 
1242
1282
  char identity[PSK_MAX_IDENTITY_LEN + 1];
1243
1283
  OPENSSL_memset(identity, 0, sizeof(identity));
1244
- psk_len =
1245
- ssl->psk_client_callback(ssl, hs->peer_psk_identity_hint.get(),
1246
- identity, sizeof(identity), psk, sizeof(psk));
1284
+ psk_len = hs->config->psk_client_callback(
1285
+ ssl, hs->peer_psk_identity_hint.get(), identity, sizeof(identity), psk,
1286
+ sizeof(psk));
1247
1287
  if (psk_len == 0) {
1248
1288
  OPENSSL_PUT_ERROR(SSL, SSL_R_PSK_IDENTITY_NOT_FOUND);
1249
1289
  ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
@@ -1251,9 +1291,8 @@ static enum ssl_hs_wait_t do_send_client_key_exchange(SSL_HANDSHAKE *hs) {
1251
1291
  }
1252
1292
  assert(psk_len <= PSK_MAX_PSK_LEN);
1253
1293
 
1254
- OPENSSL_free(hs->new_session->psk_identity);
1255
- hs->new_session->psk_identity = BUF_strdup(identity);
1256
- if (hs->new_session->psk_identity == NULL) {
1294
+ hs->new_session->psk_identity.reset(BUF_strdup(identity));
1295
+ if (hs->new_session->psk_identity == nullptr) {
1257
1296
  OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1258
1297
  return ssl_hs_error;
1259
1298
  }
@@ -1286,21 +1325,14 @@ static enum ssl_hs_wait_t do_send_client_key_exchange(SSL_HANDSHAKE *hs) {
1286
1325
  return ssl_hs_error;
1287
1326
  }
1288
1327
 
1289
- CBB child, *enc_pms = &body;
1290
- size_t enc_pms_len;
1291
- // In TLS, there is a length prefix.
1292
- if (ssl->version > SSL3_VERSION) {
1293
- if (!CBB_add_u16_length_prefixed(&body, &child)) {
1294
- return ssl_hs_error;
1295
- }
1296
- enc_pms = &child;
1297
- }
1298
-
1328
+ CBB enc_pms;
1299
1329
  uint8_t *ptr;
1300
- if (!CBB_reserve(enc_pms, &ptr, RSA_size(rsa)) ||
1330
+ size_t enc_pms_len;
1331
+ if (!CBB_add_u16_length_prefixed(&body, &enc_pms) ||
1332
+ !CBB_reserve(&enc_pms, &ptr, RSA_size(rsa)) ||
1301
1333
  !RSA_encrypt(rsa, &enc_pms_len, ptr, RSA_size(rsa), pms.data(),
1302
1334
  pms.size(), RSA_PKCS1_PADDING) ||
1303
- !CBB_did_write(enc_pms, enc_pms_len) ||
1335
+ !CBB_did_write(&enc_pms, enc_pms_len) ||
1304
1336
  !CBB_flush(&body)) {
1305
1337
  return ssl_hs_error;
1306
1338
  }
@@ -1313,7 +1345,7 @@ static enum ssl_hs_wait_t do_send_client_key_exchange(SSL_HANDSHAKE *hs) {
1313
1345
 
1314
1346
  // Compute the premaster.
1315
1347
  uint8_t alert = SSL_AD_DECODE_ERROR;
1316
- if (!hs->key_share->Accept(&child, &pms, &alert, hs->peer_key)) {
1348
+ if (!hs->key_shares[0]->Accept(&child, &pms, &alert, hs->peer_key)) {
1317
1349
  ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
1318
1350
  return ssl_hs_error;
1319
1351
  }
@@ -1322,7 +1354,8 @@ static enum ssl_hs_wait_t do_send_client_key_exchange(SSL_HANDSHAKE *hs) {
1322
1354
  }
1323
1355
 
1324
1356
  // The key exchange state may now be discarded.
1325
- hs->key_share.reset();
1357
+ hs->key_shares[0].reset();
1358
+ hs->key_shares[1].reset();
1326
1359
  hs->peer_key.Reset();
1327
1360
  } else if (alg_k & SSL_kPSK) {
1328
1361
  // For plain PSK, other_secret is a block of 0s with the same length as
@@ -1373,12 +1406,12 @@ static enum ssl_hs_wait_t do_send_client_key_exchange(SSL_HANDSHAKE *hs) {
1373
1406
  static enum ssl_hs_wait_t do_send_client_certificate_verify(SSL_HANDSHAKE *hs) {
1374
1407
  SSL *const ssl = hs->ssl;
1375
1408
 
1376
- if (!hs->cert_request || !ssl_has_certificate(ssl)) {
1409
+ if (!hs->cert_request || !ssl_has_certificate(hs)) {
1377
1410
  hs->state = state_send_client_finished;
1378
1411
  return ssl_hs_ok;
1379
1412
  }
1380
1413
 
1381
- assert(ssl_has_private_key(ssl));
1414
+ assert(ssl_has_private_key(hs));
1382
1415
  ScopedCBB cbb;
1383
1416
  CBB body, child;
1384
1417
  if (!ssl->method->init_message(ssl, cbb.get(), &body,
@@ -1388,6 +1421,7 @@ static enum ssl_hs_wait_t do_send_client_certificate_verify(SSL_HANDSHAKE *hs) {
1388
1421
 
1389
1422
  uint16_t signature_algorithm;
1390
1423
  if (!tls1_choose_signature_algorithm(hs, &signature_algorithm)) {
1424
+ ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1391
1425
  return ssl_hs_error;
1392
1426
  }
1393
1427
  if (ssl_protocol_version(ssl) >= TLS1_2_VERSION) {
@@ -1407,39 +1441,16 @@ static enum ssl_hs_wait_t do_send_client_certificate_verify(SSL_HANDSHAKE *hs) {
1407
1441
  }
1408
1442
 
1409
1443
  size_t sig_len = max_sig_len;
1410
- // The SSL3 construction for CertificateVerify does not decompose into a
1411
- // single final digest and signature, and must be special-cased.
1412
- if (ssl_protocol_version(ssl) == SSL3_VERSION) {
1413
- if (ssl->cert->key_method != NULL) {
1414
- OPENSSL_PUT_ERROR(SSL, SSL_R_UNSUPPORTED_PROTOCOL_FOR_CUSTOM_KEY);
1415
- return ssl_hs_error;
1416
- }
1417
-
1418
- uint8_t digest[EVP_MAX_MD_SIZE];
1419
- size_t digest_len;
1420
- if (!hs->transcript.GetSSL3CertVerifyHash(
1421
- digest, &digest_len, hs->new_session.get(), signature_algorithm)) {
1422
- return ssl_hs_error;
1423
- }
1424
-
1425
- UniquePtr<EVP_PKEY_CTX> pctx(EVP_PKEY_CTX_new(ssl->cert->privatekey, NULL));
1426
- if (!pctx ||
1427
- !EVP_PKEY_sign_init(pctx.get()) ||
1428
- !EVP_PKEY_sign(pctx.get(), ptr, &sig_len, digest, digest_len)) {
1444
+ switch (ssl_private_key_sign(hs, ptr, &sig_len, max_sig_len,
1445
+ signature_algorithm,
1446
+ hs->transcript.buffer())) {
1447
+ case ssl_private_key_success:
1448
+ break;
1449
+ case ssl_private_key_failure:
1429
1450
  return ssl_hs_error;
1430
- }
1431
- } else {
1432
- switch (ssl_private_key_sign(hs, ptr, &sig_len, max_sig_len,
1433
- signature_algorithm,
1434
- hs->transcript.buffer())) {
1435
- case ssl_private_key_success:
1436
- break;
1437
- case ssl_private_key_failure:
1438
- return ssl_hs_error;
1439
- case ssl_private_key_retry:
1440
- hs->state = state_send_client_certificate_verify;
1441
- return ssl_hs_private_key_operation;
1442
- }
1451
+ case ssl_private_key_retry:
1452
+ hs->state = state_send_client_certificate_verify;
1453
+ return ssl_hs_private_key_operation;
1443
1454
  }
1444
1455
 
1445
1456
  if (!CBB_did_write(&child, sig_len) ||
@@ -1457,12 +1468,12 @@ static enum ssl_hs_wait_t do_send_client_certificate_verify(SSL_HANDSHAKE *hs) {
1457
1468
  static enum ssl_hs_wait_t do_send_client_finished(SSL_HANDSHAKE *hs) {
1458
1469
  SSL *const ssl = hs->ssl;
1459
1470
  // Resolve Channel ID first, before any non-idempotent operations.
1460
- if (ssl->s3->tlsext_channel_id_valid) {
1461
- if (!ssl_do_channel_id_callback(ssl)) {
1471
+ if (ssl->s3->channel_id_valid) {
1472
+ if (!ssl_do_channel_id_callback(hs)) {
1462
1473
  return ssl_hs_error;
1463
1474
  }
1464
1475
 
1465
- if (ssl->tlsext_channel_id_private == NULL) {
1476
+ if (hs->config->channel_id_private == NULL) {
1466
1477
  hs->state = state_send_client_finished;
1467
1478
  return ssl_hs_channel_id_lookup;
1468
1479
  }
@@ -1492,7 +1503,7 @@ static enum ssl_hs_wait_t do_send_client_finished(SSL_HANDSHAKE *hs) {
1492
1503
  }
1493
1504
  }
1494
1505
 
1495
- if (ssl->s3->tlsext_channel_id_valid) {
1506
+ if (ssl->s3->channel_id_valid) {
1496
1507
  ScopedCBB cbb;
1497
1508
  CBB body;
1498
1509
  if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_CHANNEL_ID) ||
@@ -1514,18 +1525,32 @@ static enum ssl_hs_wait_t do_send_client_finished(SSL_HANDSHAKE *hs) {
1514
1525
  static bool can_false_start(const SSL_HANDSHAKE *hs) {
1515
1526
  SSL *const ssl = hs->ssl;
1516
1527
 
1517
- // False Start only for TLS 1.2 with an ECDHE+AEAD cipher.
1528
+ // False Start bypasses the Finished check's downgrade protection. This can
1529
+ // enable attacks where we send data under weaker settings than supported
1530
+ // (e.g. the Logjam attack). Thus we require TLS 1.2 with an ECDHE+AEAD
1531
+ // cipher, our strongest settings before TLS 1.3.
1532
+ //
1533
+ // Now that TLS 1.3 exists, we would like to avoid similar attacks between
1534
+ // TLS 1.2 and TLS 1.3, but there are too many TLS 1.2 deployments to
1535
+ // sacrifice False Start on them. TLS 1.3's downgrade signal fixes this, but
1536
+ // |SSL_CTX_set_ignore_tls13_downgrade| can disable it due to compatibility
1537
+ // issues.
1538
+ //
1539
+ // |SSL_CTX_set_ignore_tls13_downgrade| normally still retains Finished-based
1540
+ // downgrade protection, but False Start bypasses that. Thus, we disable False
1541
+ // Start based on the TLS 1.3 downgrade signal, even if otherwise unenforced.
1518
1542
  if (SSL_is_dtls(ssl) ||
1519
1543
  SSL_version(ssl) != TLS1_2_VERSION ||
1520
1544
  hs->new_cipher->algorithm_mkey != SSL_kECDHE ||
1521
- hs->new_cipher->algorithm_mac != SSL_AEAD) {
1545
+ hs->new_cipher->algorithm_mac != SSL_AEAD ||
1546
+ ssl->s3->tls13_downgrade) {
1522
1547
  return false;
1523
1548
  }
1524
1549
 
1525
1550
  // Additionally require ALPN or NPN by default.
1526
1551
  //
1527
1552
  // TODO(davidben): Can this constraint be relaxed globally now that cipher
1528
- // suite requirements have been relaxed?
1553
+ // suite requirements have been tightened?
1529
1554
  if (!ssl->ctx->false_start_allowed_without_alpn &&
1530
1555
  ssl->s3->alpn_selected.empty() &&
1531
1556
  ssl->s3->next_proto_negotiated.empty()) {
@@ -1582,8 +1607,8 @@ static enum ssl_hs_wait_t do_read_session_ticket(SSL_HANDSHAKE *hs) {
1582
1607
  }
1583
1608
 
1584
1609
  CBS new_session_ticket = msg.body, ticket;
1585
- uint32_t tlsext_tick_lifetime_hint;
1586
- if (!CBS_get_u32(&new_session_ticket, &tlsext_tick_lifetime_hint) ||
1610
+ uint32_t ticket_lifetime_hint;
1611
+ if (!CBS_get_u32(&new_session_ticket, &ticket_lifetime_hint) ||
1587
1612
  !CBS_get_u16_length_prefixed(&new_session_ticket, &ticket) ||
1588
1613
  CBS_len(&new_session_ticket) != 0) {
1589
1614
  ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
@@ -1608,7 +1633,7 @@ static enum ssl_hs_wait_t do_read_session_ticket(SSL_HANDSHAKE *hs) {
1608
1633
  // immutable once established, so duplicate all but the ticket of the
1609
1634
  // existing session.
1610
1635
  renewed_session =
1611
- SSL_SESSION_dup(ssl->session, SSL_SESSION_INCLUDE_NONAUTH);
1636
+ SSL_SESSION_dup(ssl->session.get(), SSL_SESSION_INCLUDE_NONAUTH);
1612
1637
  if (!renewed_session) {
1613
1638
  // This should never happen.
1614
1639
  OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR);
@@ -1617,28 +1642,23 @@ static enum ssl_hs_wait_t do_read_session_ticket(SSL_HANDSHAKE *hs) {
1617
1642
  session = renewed_session.get();
1618
1643
  }
1619
1644
 
1620
- // |tlsext_tick_lifetime_hint| is measured from when the ticket was issued.
1645
+ // |ticket_lifetime_hint| is measured from when the ticket was issued.
1621
1646
  ssl_session_rebase_time(ssl, session);
1622
1647
 
1623
- if (!CBS_stow(&ticket, &session->tlsext_tick, &session->tlsext_ticklen)) {
1624
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
1648
+ if (!session->ticket.CopyFrom(ticket)) {
1625
1649
  return ssl_hs_error;
1626
1650
  }
1627
- session->tlsext_tick_lifetime_hint = tlsext_tick_lifetime_hint;
1651
+ session->ticket_lifetime_hint = ticket_lifetime_hint;
1628
1652
 
1629
- // Generate a session ID for this session based on the session ticket. We use
1630
- // the session ID mechanism for detecting ticket resumption. This also fits in
1631
- // with assumptions elsewhere in OpenSSL.
1632
- if (!EVP_Digest(CBS_data(&ticket), CBS_len(&ticket),
1633
- session->session_id, &session->session_id_length,
1634
- EVP_sha256(), NULL)) {
1635
- return ssl_hs_error;
1636
- }
1653
+ // Generate a session ID for this session. Some callers expect all sessions to
1654
+ // have a session ID. Additionally, it acts as the session ID to signal
1655
+ // resumption.
1656
+ SHA256(CBS_data(&ticket), CBS_len(&ticket), session->session_id);
1657
+ session->session_id_length = SHA256_DIGEST_LENGTH;
1637
1658
 
1638
1659
  if (renewed_session) {
1639
- session->not_resumable = 0;
1640
- SSL_SESSION_free(ssl->session);
1641
- ssl->session = renewed_session.release();
1660
+ session->not_resumable = false;
1661
+ ssl->session = std::move(renewed_session);
1642
1662
  }
1643
1663
 
1644
1664
  ssl->method->next_message(ssl);
@@ -1677,8 +1697,7 @@ static enum ssl_hs_wait_t do_finish_client_handshake(SSL_HANDSHAKE *hs) {
1677
1697
  ssl->method->on_handshake_complete(ssl);
1678
1698
 
1679
1699
  if (ssl->session != NULL) {
1680
- SSL_SESSION_up_ref(ssl->session);
1681
- ssl->s3->established_session.reset(ssl->session);
1700
+ ssl->s3->established_session = UpRef(ssl->session);
1682
1701
  } else {
1683
1702
  // We make a copy of the session in order to maintain the immutability
1684
1703
  // of the new established_session due to False Start. The caller may
@@ -1690,7 +1709,7 @@ static enum ssl_hs_wait_t do_finish_client_handshake(SSL_HANDSHAKE *hs) {
1690
1709
  }
1691
1710
  // Renegotiations do not participate in session resumption.
1692
1711
  if (!ssl->s3->initial_handshake_complete) {
1693
- ssl->s3->established_session->not_resumable = 0;
1712
+ ssl->s3->established_session->not_resumable = false;
1694
1713
  }
1695
1714
 
1696
1715
  hs->new_session.reset();
@@ -1716,6 +1735,9 @@ enum ssl_hs_wait_t ssl_client_handshake(SSL_HANDSHAKE *hs) {
1716
1735
  case state_enter_early_data:
1717
1736
  ret = do_enter_early_data(hs);
1718
1737
  break;
1738
+ case state_early_reverify_server_certificate:
1739
+ ret = do_early_reverify_server_certificate(hs);
1740
+ break;
1719
1741
  case state_read_hello_verify_request:
1720
1742
  ret = do_read_hello_verify_request(hs);
1721
1743
  break;
@@ -1734,6 +1756,9 @@ enum ssl_hs_wait_t ssl_client_handshake(SSL_HANDSHAKE *hs) {
1734
1756
  case state_verify_server_certificate:
1735
1757
  ret = do_verify_server_certificate(hs);
1736
1758
  break;
1759
+ case state_reverify_server_certificate:
1760
+ ret = do_reverify_server_certificate(hs);
1761
+ break;
1737
1762
  case state_read_server_key_exchange:
1738
1763
  ret = do_read_server_key_exchange(hs);
1739
1764
  break;
@@ -1796,6 +1821,8 @@ const char *ssl_client_handshake_state(SSL_HANDSHAKE *hs) {
1796
1821
  return "TLS client start_connect";
1797
1822
  case state_enter_early_data:
1798
1823
  return "TLS client enter_early_data";
1824
+ case state_early_reverify_server_certificate:
1825
+ return "TLS client early_reverify_server_certificate";
1799
1826
  case state_read_hello_verify_request:
1800
1827
  return "TLS client read_hello_verify_request";
1801
1828
  case state_read_server_hello:
@@ -1808,6 +1835,8 @@ const char *ssl_client_handshake_state(SSL_HANDSHAKE *hs) {
1808
1835
  return "TLS client read_certificate_status";
1809
1836
  case state_verify_server_certificate:
1810
1837
  return "TLS client verify_server_certificate";
1838
+ case state_reverify_server_certificate:
1839
+ return "TLS client reverify_server_certificate";
1811
1840
  case state_read_server_key_exchange:
1812
1841
  return "TLS client read_server_key_exchange";
1813
1842
  case state_read_certificate_request:
@@ -1839,4 +1868,4 @@ const char *ssl_client_handshake_state(SSL_HANDSHAKE *hs) {
1839
1868
  return "TLS client unknown";
1840
1869
  }
1841
1870
 
1842
- }
1871
+ BSSL_NAMESPACE_END