grpc 1.38.0 → 1.39.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 (199) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +50 -19
  3. data/include/grpc/event_engine/endpoint_config.h +48 -0
  4. data/include/grpc/event_engine/event_engine.h +13 -15
  5. data/include/grpc/event_engine/port.h +2 -0
  6. data/include/grpc/event_engine/slice_allocator.h +17 -7
  7. data/include/grpc/grpc.h +9 -2
  8. data/include/grpc/grpc_security.h +32 -0
  9. data/include/grpc/grpc_security_constants.h +1 -0
  10. data/include/grpc/impl/codegen/grpc_types.h +17 -13
  11. data/include/grpc/impl/codegen/port_platform.h +17 -0
  12. data/src/core/ext/filters/client_channel/client_channel.cc +2 -2
  13. data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -0
  14. data/src/core/ext/filters/client_channel/health/health_check_client.h +3 -3
  15. data/src/core/ext/filters/client_channel/http_proxy.cc +16 -1
  16. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +755 -0
  17. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +10 -0
  18. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +10 -24
  19. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +63 -95
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -3
  21. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc +31 -0
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc +28 -0
  23. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -3
  24. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +7 -2
  25. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +15 -3
  26. data/src/core/ext/filters/client_channel/retry_filter.cc +665 -404
  27. data/src/core/ext/filters/client_channel/retry_service_config.cc +43 -24
  28. data/src/core/ext/filters/client_channel/retry_service_config.h +8 -2
  29. data/src/core/ext/filters/client_idle/client_idle_filter.cc +1 -1
  30. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +6 -0
  31. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +2 -1
  32. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +3 -2
  33. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +10 -4
  34. data/src/core/ext/transport/chttp2/transport/internal.h +1 -0
  35. data/src/core/ext/transport/chttp2/transport/parsing.cc +2 -2
  36. data/src/core/ext/transport/inproc/inproc_transport.cc +42 -31
  37. data/src/core/ext/xds/xds_api.cc +247 -106
  38. data/src/core/ext/xds/xds_api.h +15 -6
  39. data/src/core/lib/address_utils/sockaddr_utils.cc +13 -0
  40. data/src/core/lib/address_utils/sockaddr_utils.h +10 -0
  41. data/src/core/lib/channel/channelz.h +3 -0
  42. data/src/core/lib/event_engine/endpoint_config.cc +46 -0
  43. data/src/core/lib/event_engine/endpoint_config_internal.h +42 -0
  44. data/src/core/lib/event_engine/event_engine.cc +50 -0
  45. data/src/core/lib/event_engine/slice_allocator.cc +33 -3
  46. data/src/core/lib/event_engine/sockaddr.cc +14 -12
  47. data/src/core/lib/event_engine/sockaddr.h +44 -0
  48. data/src/core/lib/gpr/wrap_memcpy.cc +2 -1
  49. data/src/core/lib/gprpp/status_helper.h +3 -0
  50. data/src/core/lib/iomgr/endpoint_pair_event_engine.cc +33 -0
  51. data/src/core/lib/iomgr/error.cc +5 -4
  52. data/src/core/lib/iomgr/error.h +1 -1
  53. data/src/core/lib/iomgr/event_engine/closure.cc +54 -0
  54. data/src/core/lib/iomgr/event_engine/closure.h +33 -0
  55. data/src/core/lib/iomgr/event_engine/endpoint.cc +194 -0
  56. data/src/core/lib/iomgr/event_engine/endpoint.h +53 -0
  57. data/src/core/lib/iomgr/event_engine/iomgr.cc +105 -0
  58. data/src/core/lib/iomgr/event_engine/iomgr.h +24 -0
  59. data/src/core/lib/iomgr/event_engine/pollset.cc +87 -0
  60. data/{include/grpc/event_engine/channel_args.h → src/core/lib/iomgr/event_engine/pollset.h} +7 -10
  61. data/src/core/lib/iomgr/event_engine/promise.h +51 -0
  62. data/src/core/lib/iomgr/event_engine/resolved_address_internal.cc +41 -0
  63. data/src/core/lib/iomgr/event_engine/resolved_address_internal.h +35 -0
  64. data/src/core/lib/iomgr/event_engine/resolver.cc +110 -0
  65. data/src/core/lib/iomgr/event_engine/tcp.cc +243 -0
  66. data/src/core/lib/iomgr/event_engine/timer.cc +57 -0
  67. data/src/core/lib/iomgr/exec_ctx.cc +8 -0
  68. data/src/core/lib/iomgr/exec_ctx.h +3 -4
  69. data/src/core/lib/iomgr/executor/threadpool.cc +2 -3
  70. data/src/core/lib/iomgr/executor/threadpool.h +2 -2
  71. data/src/core/lib/iomgr/iomgr.cc +1 -1
  72. data/src/core/lib/iomgr/iomgr_posix.cc +2 -0
  73. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +40 -10
  74. data/src/core/lib/iomgr/pollset_custom.cc +2 -2
  75. data/src/core/lib/iomgr/pollset_custom.h +3 -1
  76. data/src/core/lib/iomgr/pollset_uv.cc +3 -1
  77. data/src/core/lib/iomgr/pollset_uv.h +5 -1
  78. data/src/core/lib/iomgr/port.h +7 -5
  79. data/src/core/lib/iomgr/resolve_address.cc +5 -1
  80. data/src/core/lib/iomgr/resolve_address.h +6 -0
  81. data/src/core/lib/iomgr/sockaddr.h +1 -0
  82. data/src/core/lib/iomgr/socket_mutator.cc +15 -2
  83. data/src/core/lib/iomgr/socket_mutator.h +26 -2
  84. data/src/core/lib/iomgr/socket_utils_common_posix.cc +4 -4
  85. data/src/core/lib/iomgr/socket_utils_posix.h +2 -2
  86. data/src/core/lib/iomgr/tcp_client_posix.cc +7 -2
  87. data/src/core/lib/iomgr/tcp_posix.cc +42 -39
  88. data/src/core/lib/iomgr/tcp_posix.h +8 -0
  89. data/src/core/lib/iomgr/tcp_server_custom.cc +3 -4
  90. data/src/core/lib/iomgr/tcp_server_posix.cc +6 -0
  91. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +2 -1
  92. data/src/core/lib/iomgr/timer.h +6 -1
  93. data/src/core/lib/security/authorization/authorization_engine.h +44 -0
  94. data/src/core/lib/security/authorization/authorization_policy_provider.h +32 -0
  95. data/src/core/lib/security/authorization/authorization_policy_provider_vtable.cc +46 -0
  96. data/src/core/lib/security/authorization/evaluate_args.cc +209 -0
  97. data/src/core/lib/security/authorization/evaluate_args.h +91 -0
  98. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +3 -1
  99. data/src/core/lib/security/credentials/tls/tls_utils.cc +32 -0
  100. data/src/core/lib/security/credentials/tls/tls_utils.h +13 -0
  101. data/src/core/lib/security/security_connector/local/local_security_connector.cc +9 -6
  102. data/src/core/lib/security/security_connector/ssl_utils.cc +5 -0
  103. data/src/core/lib/surface/call.cc +21 -1
  104. data/src/core/lib/surface/call.h +11 -0
  105. data/src/core/lib/surface/completion_queue.cc +22 -22
  106. data/src/core/lib/surface/completion_queue.h +1 -1
  107. data/src/core/lib/surface/completion_queue_factory.cc +1 -2
  108. data/src/core/lib/surface/init.cc +1 -3
  109. data/src/core/lib/surface/init.h +10 -1
  110. data/src/core/lib/surface/version.cc +1 -1
  111. data/src/core/lib/transport/error_utils.cc +2 -2
  112. data/src/core/lib/transport/transport.h +2 -0
  113. data/src/core/lib/transport/transport_op_string.cc +1 -1
  114. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  115. data/src/core/tsi/alts/crypt/gsec.h +2 -0
  116. data/src/ruby/ext/grpc/extconf.rb +2 -0
  117. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +6 -0
  118. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +10 -1
  119. data/src/ruby/lib/grpc/version.rb +1 -1
  120. data/third_party/boringssl-with-bazel/err_data.c +269 -263
  121. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +8 -6
  122. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/cipher_extra.c +4 -0
  123. data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519.c +1 -1
  124. data/third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h +1 -1
  125. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +9 -0
  126. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/prime.c +0 -4
  127. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +7 -0
  128. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/md32_common.h +87 -121
  129. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md4/md4.c +20 -30
  130. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md5/md5.c +19 -30
  131. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +1 -4
  132. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +0 -13
  133. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +26 -24
  134. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +10 -7
  135. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha1.c +28 -39
  136. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha256.c +48 -66
  137. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha512.c +4 -5
  138. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +362 -371
  139. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7_x509.c +4 -2
  140. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/passive.c +2 -2
  141. data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/rsa_asn1.c +1 -2
  142. data/third_party/boringssl-with-bazel/src/crypto/x509/internal.h +101 -11
  143. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509a.c +3 -0
  144. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +2 -2
  145. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +3 -0
  146. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +1 -1
  147. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +2 -0
  148. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +14 -15
  149. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vpm.c +53 -73
  150. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +31 -0
  151. data/third_party/boringssl-with-bazel/src/crypto/x509/x509rset.c +3 -0
  152. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +3 -0
  153. data/third_party/boringssl-with-bazel/src/crypto/x509/x_req.c +5 -8
  154. data/third_party/boringssl-with-bazel/src/crypto/x509/x_sig.c +5 -0
  155. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509a.c +3 -0
  156. data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +7 -0
  157. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +1 -1
  158. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_utl.c +5 -8
  159. data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +1 -1
  160. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +66 -1
  161. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +40 -9
  162. data/third_party/boringssl-with-bazel/src/include/openssl/bytestring.h +1 -0
  163. data/third_party/boringssl-with-bazel/src/include/openssl/chacha.h +1 -1
  164. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +6 -2
  165. data/third_party/boringssl-with-bazel/src/include/openssl/ecdsa.h +14 -0
  166. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +19 -11
  167. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +325 -0
  168. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +23 -7
  169. data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +99 -63
  170. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +139 -109
  171. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +12 -19
  172. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +48 -50
  173. data/third_party/boringssl-with-bazel/src/include/openssl/x509_vfy.h +451 -435
  174. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +0 -1
  175. data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +2 -2
  176. data/third_party/boringssl-with-bazel/src/ssl/d1_srtp.cc +1 -1
  177. data/third_party/boringssl-with-bazel/src/ssl/encrypted_client_hello.cc +773 -84
  178. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +80 -47
  179. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +24 -19
  180. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +189 -86
  181. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +45 -56
  182. data/third_party/boringssl-with-bazel/src/ssl/internal.h +272 -167
  183. data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +2 -2
  184. data/third_party/boringssl-with-bazel/src/ssl/s3_lib.cc +2 -2
  185. data/third_party/boringssl-with-bazel/src/ssl/s3_pkt.cc +14 -19
  186. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +34 -102
  187. data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +2 -0
  188. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +8 -31
  189. data/third_party/boringssl-with-bazel/src/ssl/ssl_stat.cc +3 -0
  190. data/third_party/boringssl-with-bazel/src/ssl/ssl_transcript.cc +4 -3
  191. data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +7 -3
  192. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +576 -648
  193. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +31 -3
  194. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +98 -39
  195. data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +141 -94
  196. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +58 -68
  197. metadata +65 -40
  198. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +0 -267
  199. data/third_party/boringssl-with-bazel/src/crypto/x509/vpm_int.h +0 -71
@@ -169,7 +169,6 @@
169
169
 
170
170
  #include "internal.h"
171
171
  #include "../crypto/internal.h"
172
- #include "../crypto/hpke/internal.h"
173
172
 
174
173
 
175
174
  BSSL_NAMESPACE_BEGIN
@@ -599,11 +598,12 @@ static enum ssl_hs_wait_t do_read_client_hello(SSL_HANDSHAKE *hs) {
599
598
  }
600
599
 
601
600
  // Parse a ClientECH out of the extension body.
601
+ uint8_t config_id;
602
602
  uint16_t kdf_id, aead_id;
603
- CBS config_id, enc, payload;
603
+ CBS enc, payload;
604
604
  if (!CBS_get_u16(&ech_body, &kdf_id) || //
605
605
  !CBS_get_u16(&ech_body, &aead_id) ||
606
- !CBS_get_u8_length_prefixed(&ech_body, &config_id) ||
606
+ !CBS_get_u8(&ech_body, &config_id) ||
607
607
  !CBS_get_u16_length_prefixed(&ech_body, &enc) ||
608
608
  !CBS_get_u16_length_prefixed(&ech_body, &payload) ||
609
609
  CBS_len(&ech_body) != 0) {
@@ -614,41 +614,15 @@ static enum ssl_hs_wait_t do_read_client_hello(SSL_HANDSHAKE *hs) {
614
614
 
615
615
  {
616
616
  MutexReadLock lock(&ssl->ctx->lock);
617
- hs->ech_server_config_list = UpRef(ssl->ctx->ech_server_config_list);
617
+ hs->ech_keys = UpRef(ssl->ctx->ech_keys);
618
618
  }
619
619
 
620
- if (hs->ech_server_config_list) {
621
- for (const ECHServerConfig &ech_config :
622
- hs->ech_server_config_list->configs) {
623
- // Skip this config if the client-provided config_id does not match or
624
- // if the client indicated an unsupported HPKE ciphersuite.
625
- if (config_id != ech_config.config_id_sha256() ||
626
- !ech_config.SupportsCipherSuite(kdf_id, aead_id)) {
627
- continue;
628
- }
629
-
630
- static const uint8_t kInfoLabel[] = "tls ech";
631
- ScopedCBB info_cbb;
632
- if (!CBB_init(info_cbb.get(),
633
- sizeof(kInfoLabel) + ech_config.raw().size()) ||
634
- !CBB_add_bytes(info_cbb.get(), kInfoLabel,
635
- sizeof(kInfoLabel) /* includes trailing NUL */) ||
636
- !CBB_add_bytes(info_cbb.get(), ech_config.raw().data(),
637
- ech_config.raw().size())) {
638
- OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
639
- return ssl_hs_error;
640
- }
641
-
642
- // Set up a fresh HPKE context for each decryption attempt.
620
+ if (hs->ech_keys) {
621
+ for (const auto &config : hs->ech_keys->configs) {
643
622
  hs->ech_hpke_ctx.Reset();
644
-
645
- if (CBS_len(&enc) != X25519_PUBLIC_VALUE_LEN ||
646
- !EVP_HPKE_CTX_setup_base_r_x25519(
647
- hs->ech_hpke_ctx.get(), kdf_id, aead_id, CBS_data(&enc),
648
- CBS_len(&enc), ech_config.public_key().data(),
649
- ech_config.public_key().size(), ech_config.private_key().data(),
650
- ech_config.private_key().size(), CBB_data(info_cbb.get()),
651
- CBB_len(info_cbb.get()))) {
623
+ if (config_id != config->ech_config().config_id ||
624
+ !config->SetupContext(hs->ech_hpke_ctx.get(), kdf_id, aead_id,
625
+ enc)) {
652
626
  // Ignore the error and try another ECHConfig.
653
627
  ERR_clear_error();
654
628
  continue;
@@ -686,14 +660,15 @@ static enum ssl_hs_wait_t do_read_client_hello(SSL_HANDSHAKE *hs) {
686
660
  return ssl_hs_error;
687
661
  }
688
662
 
689
- hs->ech_accept = true;
663
+ hs->ech_config_id = config_id;
664
+ ssl->s3->ech_accept = true;
690
665
  break;
691
666
  }
692
667
  }
693
668
 
694
- // If we did not set |hs->ech_accept| to true, we will send the current
695
- // ECHConfigs as retry_configs in the ServerHello's encrypted extensions.
696
- // Proceed with the ClientHelloOuter.
669
+ // If we did not accept ECH, we will send the current ECHConfigs as
670
+ // retry_configs in the ServerHello's encrypted extensions. Proceed with the
671
+ // ClientHelloOuter.
697
672
  }
698
673
 
699
674
  uint8_t alert = SSL_AD_DECODE_ERROR;
@@ -828,7 +803,7 @@ static enum ssl_hs_wait_t do_select_certificate(SSL_HANDSHAKE *hs) {
828
803
  // It should not be possible to negotiate TLS 1.2 with ECH. The
829
804
  // ClientHelloInner decoding function rejects ClientHellos which offer TLS 1.2
830
805
  // or below.
831
- assert(!hs->ech_accept);
806
+ assert(!ssl->s3->ech_accept);
832
807
 
833
808
  // TODO(davidben): Also compute hints for TLS 1.2. When doing so, update the
834
809
  // check in bssl_shim.cc to test this.
@@ -883,6 +858,11 @@ static enum ssl_hs_wait_t do_select_parameters(SSL_HANDSHAKE *hs) {
883
858
  return ssl_hs_error;
884
859
  }
885
860
 
861
+ hs->session_id_len = client_hello.session_id_len;
862
+ // This is checked in |ssl_client_hello_init|.
863
+ assert(hs->session_id_len <= sizeof(hs->session_id));
864
+ OPENSSL_memcpy(hs->session_id, client_hello.session_id, hs->session_id_len);
865
+
886
866
  // Determine whether we are doing session resumption.
887
867
  UniquePtr<SSL_SESSION> session;
888
868
  bool tickets_supported = false, renew_ticket = false;
@@ -914,16 +894,20 @@ static enum ssl_hs_wait_t do_select_parameters(SSL_HANDSHAKE *hs) {
914
894
  hs->ticket_expected = renew_ticket;
915
895
  ssl->session = std::move(session);
916
896
  ssl->s3->session_reused = true;
897
+ hs->can_release_private_key = true;
917
898
  } else {
918
899
  hs->ticket_expected = tickets_supported;
919
- ssl_set_session(ssl, NULL);
920
- if (!ssl_get_new_session(hs, 1 /* server */)) {
900
+ ssl_set_session(ssl, nullptr);
901
+ if (!ssl_get_new_session(hs)) {
921
902
  return ssl_hs_error;
922
903
  }
923
904
 
924
- // Clear the session ID if we want the session to be single-use.
925
- if (!(ssl->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) {
926
- hs->new_session->session_id_length = 0;
905
+ // Assign a session ID if not using session tickets.
906
+ if (!hs->ticket_expected &&
907
+ (ssl->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)) {
908
+ hs->new_session->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
909
+ RAND_bytes(hs->new_session->session_id,
910
+ hs->new_session->session_id_length);
927
911
  }
928
912
  }
929
913
 
@@ -942,7 +926,7 @@ static enum ssl_hs_wait_t do_select_parameters(SSL_HANDSHAKE *hs) {
942
926
  hs->cert_request = !!(hs->config->verify_mode & SSL_VERIFY_PEER);
943
927
  // Only request a certificate if Channel ID isn't negotiated.
944
928
  if ((hs->config->verify_mode & SSL_VERIFY_PEER_IF_NO_OBC) &&
945
- ssl->s3->channel_id_valid) {
929
+ hs->channel_id_negotiated) {
946
930
  hs->cert_request = false;
947
931
  }
948
932
  // CertificateRequest may only be sent in certificate-based ciphers.
@@ -996,9 +980,9 @@ static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) {
996
980
 
997
981
  // We only accept ChannelIDs on connections with ECDHE in order to avoid a
998
982
  // known attack while we fix ChannelID itself.
999
- if (ssl->s3->channel_id_valid &&
983
+ if (hs->channel_id_negotiated &&
1000
984
  (hs->new_cipher->algorithm_mkey & SSL_kECDHE) == 0) {
1001
- ssl->s3->channel_id_valid = false;
985
+ hs->channel_id_negotiated = false;
1002
986
  }
1003
987
 
1004
988
  // If this is a resumption and the original handshake didn't support
@@ -1006,7 +990,7 @@ static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) {
1006
990
  // session and so cannot resume with ChannelIDs.
1007
991
  if (ssl->session != NULL &&
1008
992
  ssl->session->original_handshake_hash_len == 0) {
1009
- ssl->s3->channel_id_valid = false;
993
+ hs->channel_id_negotiated = false;
1010
994
  }
1011
995
 
1012
996
  struct OPENSSL_timeval now;
@@ -1037,19 +1021,22 @@ static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) {
1037
1021
  }
1038
1022
  }
1039
1023
 
1040
- const SSL_SESSION *session = hs->new_session.get();
1024
+ Span<const uint8_t> session_id;
1041
1025
  if (ssl->session != nullptr) {
1042
- session = ssl->session.get();
1026
+ // Echo the session ID from the ClientHello to indicate resumption.
1027
+ session_id = MakeConstSpan(hs->session_id, hs->session_id_len);
1028
+ } else {
1029
+ session_id = MakeConstSpan(hs->new_session->session_id,
1030
+ hs->new_session->session_id_length);
1043
1031
  }
1044
1032
 
1045
1033
  ScopedCBB cbb;
1046
- CBB body, session_id;
1034
+ CBB body, session_id_bytes;
1047
1035
  if (!ssl->method->init_message(ssl, cbb.get(), &body, SSL3_MT_SERVER_HELLO) ||
1048
1036
  !CBB_add_u16(&body, ssl->version) ||
1049
1037
  !CBB_add_bytes(&body, ssl->s3->server_random, SSL3_RANDOM_SIZE) ||
1050
- !CBB_add_u8_length_prefixed(&body, &session_id) ||
1051
- !CBB_add_bytes(&session_id, session->session_id,
1052
- session->session_id_length) ||
1038
+ !CBB_add_u8_length_prefixed(&body, &session_id_bytes) ||
1039
+ !CBB_add_bytes(&session_id_bytes, session_id.data(), session_id.size()) ||
1053
1040
  !CBB_add_u16(&body, SSL_CIPHER_get_protocol_id(hs->new_cipher)) ||
1054
1041
  !CBB_add_u8(&body, 0 /* no compression */) ||
1055
1042
  !ssl_add_serverhello_tlsext(hs, &body) ||
@@ -1219,6 +1206,7 @@ static enum ssl_hs_wait_t do_send_server_key_exchange(SSL_HANDSHAKE *hs) {
1219
1206
  }
1220
1207
  }
1221
1208
 
1209
+ hs->can_release_private_key = true;
1222
1210
  if (!ssl_add_message_cbb(ssl, cbb.get())) {
1223
1211
  return ssl_hs_error;
1224
1212
  }
@@ -1551,6 +1539,7 @@ static enum ssl_hs_wait_t do_read_client_key_exchange(SSL_HANDSHAKE *hs) {
1551
1539
  }
1552
1540
  hs->new_session->extended_master_secret = hs->extended_master_secret;
1553
1541
  CONSTTIME_DECLASSIFY(hs->new_session->secret, hs->new_session->secret_length);
1542
+ hs->can_release_private_key = true;
1554
1543
 
1555
1544
  ssl->method->next_message(ssl);
1556
1545
  hs->state = state12_read_client_certificate_verify;
@@ -1692,7 +1681,7 @@ static enum ssl_hs_wait_t do_read_next_proto(SSL_HANDSHAKE *hs) {
1692
1681
  static enum ssl_hs_wait_t do_read_channel_id(SSL_HANDSHAKE *hs) {
1693
1682
  SSL *const ssl = hs->ssl;
1694
1683
 
1695
- if (!ssl->s3->channel_id_valid) {
1684
+ if (!hs->channel_id_negotiated) {
1696
1685
  hs->state = state12_read_client_finished;
1697
1686
  return ssl_hs_ok;
1698
1687
  }
@@ -154,6 +154,7 @@
154
154
  #include <openssl/aead.h>
155
155
  #include <openssl/curve25519.h>
156
156
  #include <openssl/err.h>
157
+ #include <openssl/hpke.h>
157
158
  #include <openssl/lhash.h>
158
159
  #include <openssl/mem.h>
159
160
  #include <openssl/span.h>
@@ -162,7 +163,6 @@
162
163
 
163
164
  #include "../crypto/err/internal.h"
164
165
  #include "../crypto/internal.h"
165
- #include "../crypto/hpke/internal.h"
166
166
 
167
167
 
168
168
  #if defined(OPENSSL_WINDOWS)
@@ -278,9 +278,9 @@ class Array {
278
278
  T &operator[](size_t i) { return data_[i]; }
279
279
 
280
280
  T *begin() { return data_; }
281
- const T *cbegin() const { return data_; }
281
+ const T *begin() const { return data_; }
282
282
  T *end() { return data_ + size_; }
283
- const T *cend() const { return data_ + size_; }
283
+ const T *end() const { return data_ + size_; }
284
284
 
285
285
  void Reset() { Reset(nullptr, 0); }
286
286
 
@@ -389,9 +389,9 @@ class GrowableArray {
389
389
  T &operator[](size_t i) { return array_[i]; }
390
390
 
391
391
  T *begin() { return array_.data(); }
392
- const T *cbegin() const { return array_.data(); }
392
+ const T *begin() const { return array_.data(); }
393
393
  T *end() { return array_.data() + size_; }
394
- const T *cend() const { return array_.data() + size_; }
394
+ const T *end() const { return array_.data() + size_; }
395
395
 
396
396
  void clear() {
397
397
  size_ = 0;
@@ -488,15 +488,17 @@ bool ssl_get_version_range(const SSL_HANDSHAKE *hs, uint16_t *out_min_version,
488
488
  uint16_t *out_max_version);
489
489
 
490
490
  // ssl_supports_version returns whether |hs| supports |version|.
491
- bool ssl_supports_version(SSL_HANDSHAKE *hs, uint16_t version);
491
+ bool ssl_supports_version(const SSL_HANDSHAKE *hs, uint16_t version);
492
492
 
493
493
  // ssl_method_supports_version returns whether |method| supports |version|.
494
494
  bool ssl_method_supports_version(const SSL_PROTOCOL_METHOD *method,
495
495
  uint16_t version);
496
496
 
497
497
  // ssl_add_supported_versions writes the supported versions of |hs| to |cbb|, in
498
- // decreasing preference order.
499
- bool ssl_add_supported_versions(SSL_HANDSHAKE *hs, CBB *cbb);
498
+ // decreasing preference order. The version list is filtered to those whose
499
+ // protocol version is at least |extra_min_version|.
500
+ bool ssl_add_supported_versions(const SSL_HANDSHAKE *hs, CBB *cbb,
501
+ uint16_t extra_min_version);
500
502
 
501
503
  // ssl_negotiate_version negotiates a common version based on |hs|'s preferences
502
504
  // and the peer preference list in |peer_versions|. On success, it returns true
@@ -679,6 +681,9 @@ class SSLTranscript {
679
681
  SSLTranscript();
680
682
  ~SSLTranscript();
681
683
 
684
+ SSLTranscript(SSLTranscript &&other) = default;
685
+ SSLTranscript &operator=(SSLTranscript &&other) = default;
686
+
682
687
  // Init initializes the handshake transcript. If called on an existing
683
688
  // transcript, it resets the transcript and hash. It returns true on success
684
689
  // and false on failure.
@@ -700,9 +705,9 @@ class SSLTranscript {
700
705
  // the transcript. It returns true on success and false on failure. If the
701
706
  // handshake buffer is still present, |digest| may be any supported digest.
702
707
  // Otherwise, |digest| must match the transcript hash.
703
- bool CopyToHashContext(EVP_MD_CTX *ctx, const EVP_MD *digest);
708
+ bool CopyToHashContext(EVP_MD_CTX *ctx, const EVP_MD *digest) const;
704
709
 
705
- Span<const uint8_t> buffer() {
710
+ Span<const uint8_t> buffer() const {
706
711
  return MakeConstSpan(reinterpret_cast<const uint8_t *>(buffer_->data),
707
712
  buffer_->length);
708
713
  }
@@ -725,14 +730,14 @@ class SSLTranscript {
725
730
  // GetHash writes the handshake hash to |out| which must have room for at
726
731
  // least |DigestLen| bytes. On success, it returns true and sets |*out_len| to
727
732
  // the number of bytes written. Otherwise, it returns false.
728
- bool GetHash(uint8_t *out, size_t *out_len);
733
+ bool GetHash(uint8_t *out, size_t *out_len) const;
729
734
 
730
735
  // GetFinishedMAC computes the MAC for the Finished message into the bytes
731
736
  // pointed by |out| and writes the number of bytes to |*out_len|. |out| must
732
737
  // have room for |EVP_MAX_MD_SIZE| bytes. It returns true on success and false
733
738
  // on failure.
734
739
  bool GetFinishedMAC(uint8_t *out, size_t *out_len, const SSL_SESSION *session,
735
- bool from_server);
740
+ bool from_server) const;
736
741
 
737
742
  private:
738
743
  // buffer_, if non-null, contains the handshake transcript.
@@ -1360,9 +1365,10 @@ bool ssl_on_certificate_selected(SSL_HANDSHAKE *hs);
1360
1365
  bool tls13_init_key_schedule(SSL_HANDSHAKE *hs, Span<const uint8_t> psk);
1361
1366
 
1362
1367
  // tls13_init_early_key_schedule initializes the handshake hash and key
1363
- // derivation state from the resumption secret and incorporates the PSK to
1364
- // derive the early secrets. It returns one on success and zero on error.
1365
- bool tls13_init_early_key_schedule(SSL_HANDSHAKE *hs, Span<const uint8_t> psk);
1368
+ // derivation state from |session| for use with 0-RTT. It returns one on success
1369
+ // and zero on error.
1370
+ bool tls13_init_early_key_schedule(SSL_HANDSHAKE *hs,
1371
+ const SSL_SESSION *session);
1366
1372
 
1367
1373
  // tls13_advance_key_schedule incorporates |in| into the key schedule with
1368
1374
  // HKDF-Extract. It returns true on success and false on error.
@@ -1415,76 +1421,68 @@ bool tls13_finished_mac(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len,
1415
1421
  // on failure.
1416
1422
  bool tls13_derive_session_psk(SSL_SESSION *session, Span<const uint8_t> nonce);
1417
1423
 
1418
- // tls13_write_psk_binder calculates the PSK binder value and replaces the last
1419
- // bytes of |msg| with the resulting value. It returns true on success, and
1420
- // false on failure.
1421
- bool tls13_write_psk_binder(SSL_HANDSHAKE *hs, Span<uint8_t> msg);
1424
+ // tls13_write_psk_binder calculates the PSK binder value over |transcript| and
1425
+ // |msg|, and replaces the last bytes of |msg| with the resulting value. It
1426
+ // returns true on success, and false on failure. If |out_binder_len| is
1427
+ // non-NULL, it sets |*out_binder_len| to the length of the value computed.
1428
+ bool tls13_write_psk_binder(const SSL_HANDSHAKE *hs,
1429
+ const SSLTranscript &transcript, Span<uint8_t> msg,
1430
+ size_t *out_binder_len);
1422
1431
 
1423
1432
  // tls13_verify_psk_binder verifies that the handshake transcript, truncated up
1424
1433
  // to the binders has a valid signature using the value of |session|'s
1425
1434
  // resumption secret. It returns true on success, and false on failure.
1426
- bool tls13_verify_psk_binder(SSL_HANDSHAKE *hs, SSL_SESSION *session,
1427
- const SSLMessage &msg, CBS *binders);
1435
+ bool tls13_verify_psk_binder(const SSL_HANDSHAKE *hs,
1436
+ const SSL_SESSION *session, const SSLMessage &msg,
1437
+ CBS *binders);
1428
1438
 
1429
1439
 
1430
1440
  // Encrypted ClientHello.
1431
1441
 
1442
+ struct ECHConfig {
1443
+ static constexpr bool kAllowUniquePtr = true;
1444
+ // raw contains the serialized ECHConfig.
1445
+ Array<uint8_t> raw;
1446
+ // The following fields alias into |raw|.
1447
+ Span<const uint8_t> public_key;
1448
+ Span<const uint8_t> public_name;
1449
+ Span<const uint8_t> cipher_suites;
1450
+ uint16_t kem_id = 0;
1451
+ uint16_t maximum_name_length = 0;
1452
+ uint8_t config_id = 0;
1453
+ };
1454
+
1432
1455
  class ECHServerConfig {
1433
1456
  public:
1434
- ECHServerConfig() : is_retry_config_(false), initialized_(false) {}
1435
- ECHServerConfig(ECHServerConfig &&other) = default;
1436
- ~ECHServerConfig() = default;
1437
- ECHServerConfig &operator=(ECHServerConfig &&) = default;
1438
-
1439
- // Init parses |ech_config| as an ECHConfig and saves a copy of |private_key|.
1440
- // It returns true on success and false on error. It will also error if
1441
- // |private_key| is not a valid X25519 private key or it does not correspond
1442
- // to the parsed public key.
1443
- bool Init(Span<const uint8_t> ech_config, Span<const uint8_t> private_key,
1457
+ static constexpr bool kAllowUniquePtr = true;
1458
+ ECHServerConfig() = default;
1459
+ ECHServerConfig(const ECHServerConfig &other) = delete;
1460
+ ECHServerConfig &operator=(ECHServerConfig &&) = delete;
1461
+
1462
+ // Init parses |ech_config| as an ECHConfig and saves a copy of |key|.
1463
+ // It returns true on success and false on error.
1464
+ bool Init(Span<const uint8_t> ech_config, const EVP_HPKE_KEY *key,
1444
1465
  bool is_retry_config);
1445
1466
 
1446
- // SupportsCipherSuite returns true when this ECHConfig supports the HPKE
1447
- // ciphersuite composed of |kdf_id| and |aead_id|. This function must only be
1448
- // called on an initialized object.
1449
- bool SupportsCipherSuite(uint16_t kdf_id, uint16_t aead_id) const;
1467
+ // SetupContext sets up |ctx| for a new connection, given the specified
1468
+ // HPKE ciphersuite and encapsulated KEM key. It returns true on success and
1469
+ // false on error. This function may only be called on an initialized object.
1470
+ bool SetupContext(EVP_HPKE_CTX *ctx, uint16_t kdf_id, uint16_t aead_id,
1471
+ Span<const uint8_t> enc) const;
1450
1472
 
1451
- Span<const uint8_t> raw() const {
1452
- assert(initialized_);
1453
- return raw_;
1454
- }
1455
- Span<const uint8_t> public_key() const {
1456
- assert(initialized_);
1457
- return public_key_;
1458
- }
1459
- Span<const uint8_t> private_key() const {
1460
- assert(initialized_);
1461
- return MakeConstSpan(private_key_, sizeof(private_key_));
1462
- }
1463
- Span<const uint8_t> config_id_sha256() const {
1464
- assert(initialized_);
1465
- return MakeConstSpan(config_id_sha256_, sizeof(config_id_sha256_));
1466
- }
1467
- bool is_retry_config() const {
1468
- assert(initialized_);
1469
- return is_retry_config_;
1470
- }
1473
+ const ECHConfig &ech_config() const { return ech_config_; }
1474
+ bool is_retry_config() const { return is_retry_config_; }
1471
1475
 
1472
1476
  private:
1473
- Array<uint8_t> raw_;
1474
- Span<const uint8_t> public_key_;
1475
- Span<const uint8_t> cipher_suites_;
1476
-
1477
- // private_key_ is the key corresponding to |public_key|. For clients, it must
1478
- // be empty (|private_key_present_ == false|). For servers, it must be a valid
1479
- // X25519 private key.
1480
- uint8_t private_key_[X25519_PRIVATE_KEY_LEN];
1481
-
1482
- // config_id_ stores the precomputed result of |ConfigID| for
1483
- // |EVP_HPKE_HKDF_SHA256|.
1484
- uint8_t config_id_sha256_[8];
1477
+ ECHConfig ech_config_;
1478
+ ScopedEVP_HPKE_KEY key_;
1479
+ bool is_retry_config_ = false;
1480
+ };
1485
1481
 
1486
- bool is_retry_config_ : 1;
1487
- bool initialized_ : 1;
1482
+ enum ssl_client_hello_type_t {
1483
+ ssl_client_hello_unencrypted,
1484
+ ssl_client_hello_inner,
1485
+ ssl_client_hello_outer,
1488
1486
  };
1489
1487
 
1490
1488
  // ssl_decode_client_hello_inner recovers the full ClientHelloInner from the
@@ -1504,17 +1502,64 @@ OPENSSL_EXPORT bool ssl_decode_client_hello_inner(
1504
1502
  // otherwise, regardless of whether the decrypt was successful. It sets
1505
1503
  // |out_encoded_client_hello_inner| to true if the decryption fails, and false
1506
1504
  // otherwise.
1507
- bool ssl_client_hello_decrypt(
1508
- EVP_HPKE_CTX *hpke_ctx, Array<uint8_t> *out_encoded_client_hello_inner,
1509
- bool *out_is_decrypt_error, const SSL_CLIENT_HELLO *client_hello_outer,
1510
- uint16_t kdf_id, uint16_t aead_id, Span<const uint8_t> config_id,
1511
- Span<const uint8_t> enc, Span<const uint8_t> payload);
1512
-
1513
- // tls13_ech_accept_confirmation computes the server's ECH acceptance signal,
1514
- // writing it to |out|. It returns true on success, and false on failure.
1515
- bool tls13_ech_accept_confirmation(
1516
- SSL_HANDSHAKE *hs, bssl::Span<uint8_t> out,
1517
- bssl::Span<const uint8_t> server_hello_ech_conf);
1505
+ bool ssl_client_hello_decrypt(EVP_HPKE_CTX *hpke_ctx,
1506
+ Array<uint8_t> *out_encoded_client_hello_inner,
1507
+ bool *out_is_decrypt_error,
1508
+ const SSL_CLIENT_HELLO *client_hello_outer,
1509
+ uint16_t kdf_id, uint16_t aead_id,
1510
+ uint8_t config_id, Span<const uint8_t> enc,
1511
+ Span<const uint8_t> payload);
1512
+
1513
+ #define ECH_CONFIRMATION_SIGNAL_LEN 8
1514
+
1515
+ // ssl_ech_confirmation_signal_hello_offset returns the offset of the ECH
1516
+ // confirmation signal in a ServerHello message, including the handshake header.
1517
+ size_t ssl_ech_confirmation_signal_hello_offset(const SSL *ssl);
1518
+
1519
+ // ssl_ech_accept_confirmation computes the server's ECH acceptance signal,
1520
+ // writing it to |out|. The signal is computed by concatenating |transcript|
1521
+ // with |server_hello|. This function handles the fact that eight bytes of
1522
+ // |server_hello| need to be replaced with zeros before hashing. It returns true
1523
+ // on success, and false on failure.
1524
+ bool ssl_ech_accept_confirmation(const SSL_HANDSHAKE *hs, Span<uint8_t> out,
1525
+ const SSLTranscript &transcript,
1526
+ Span<const uint8_t> server_hello);
1527
+
1528
+ // ssl_is_valid_ech_public_name returns true if |public_name| is a valid ECH
1529
+ // public name and false otherwise. It is exported for testing.
1530
+ OPENSSL_EXPORT bool ssl_is_valid_ech_public_name(
1531
+ Span<const uint8_t> public_name);
1532
+
1533
+ // ssl_is_valid_ech_config_list returns true if |ech_config_list| is a valid
1534
+ // ECHConfigList structure and false otherwise.
1535
+ bool ssl_is_valid_ech_config_list(Span<const uint8_t> ech_config_list);
1536
+
1537
+ // ssl_select_ech_config selects an ECHConfig and associated parameters to offer
1538
+ // on the client and updates |hs|. It returns true on success, whether an
1539
+ // ECHConfig was found or not, and false on internal error. On success, the
1540
+ // encapsulated key is written to |out_enc| and |*out_enc_len| is set to the
1541
+ // number of bytes written. If the function did not select an ECHConfig, the
1542
+ // encapsulated key is the empty string.
1543
+ bool ssl_select_ech_config(SSL_HANDSHAKE *hs, Span<uint8_t> out_enc,
1544
+ size_t *out_enc_len);
1545
+
1546
+ // ssl_ech_extension_body_length returns the length of the body of a ClientHello
1547
+ // ECH extension that encrypts |in_len| bytes with |aead| and an 'enc' value of
1548
+ // length |enc_len|. The result does not include the four-byte extension header.
1549
+ size_t ssl_ech_extension_body_length(const EVP_HPKE_AEAD *aead, size_t enc_len,
1550
+ size_t in_len);
1551
+
1552
+ // ssl_encrypt_client_hello constructs a new ClientHelloInner, adds it to the
1553
+ // inner transcript, and encrypts for inclusion in the ClientHelloOuter. |enc|
1554
+ // is the encapsulated key to include in the extension. It returns true on
1555
+ // success and false on error. If not offering ECH, |enc| is ignored and the
1556
+ // function will compute a GREASE ECH extension if necessary, and otherwise
1557
+ // return success while doing nothing.
1558
+ //
1559
+ // Encrypting the ClientHelloInner incorporates all extensions in the
1560
+ // ClientHelloOuter, so all other state necessary for |ssl_add_client_hello|
1561
+ // must already be computed.
1562
+ bool ssl_encrypt_client_hello(SSL_HANDSHAKE *hs, Span<const uint8_t> enc);
1518
1563
 
1519
1564
 
1520
1565
  // Delegated credentials.
@@ -1568,7 +1613,6 @@ enum ssl_hs_wait_t {
1568
1613
  ssl_hs_handoff,
1569
1614
  ssl_hs_handback,
1570
1615
  ssl_hs_x509_lookup,
1571
- ssl_hs_channel_id_lookup,
1572
1616
  ssl_hs_private_key_operation,
1573
1617
  ssl_hs_pending_session,
1574
1618
  ssl_hs_pending_ticket,
@@ -1587,7 +1631,8 @@ enum ssl_grease_index_t {
1587
1631
  ssl_grease_extension2,
1588
1632
  ssl_grease_version,
1589
1633
  ssl_grease_ticket_extension,
1590
- ssl_grease_last_index = ssl_grease_ticket_extension,
1634
+ ssl_grease_ech_config_id,
1635
+ ssl_grease_last_index = ssl_grease_ech_config_id,
1591
1636
  };
1592
1637
 
1593
1638
  enum tls12_server_hs_state_t {
@@ -1663,6 +1708,10 @@ struct SSL_HANDSHAKE_HINTS {
1663
1708
 
1664
1709
  Array<uint8_t> decrypted_psk;
1665
1710
  bool ignore_psk = false;
1711
+
1712
+ uint16_t cert_compression_alg_id = 0;
1713
+ Array<uint8_t> cert_compression_input;
1714
+ Array<uint8_t> cert_compression_output;
1666
1715
  };
1667
1716
 
1668
1717
  struct SSL_HANDSHAKE {
@@ -1721,6 +1770,9 @@ struct SSL_HANDSHAKE {
1721
1770
  bool GetClientHello(SSLMessage *out_msg, SSL_CLIENT_HELLO *out_client_hello);
1722
1771
 
1723
1772
  Span<uint8_t> secret() { return MakeSpan(secret_, hash_len_); }
1773
+ Span<const uint8_t> secret() const {
1774
+ return MakeConstSpan(secret_, hash_len_);
1775
+ }
1724
1776
  Span<uint8_t> early_traffic_secret() {
1725
1777
  return MakeSpan(early_traffic_secret_, hash_len_);
1726
1778
  }
@@ -1750,9 +1802,9 @@ struct SSL_HANDSHAKE {
1750
1802
  uint32_t received;
1751
1803
  } extensions;
1752
1804
 
1753
- // retry_group is the group ID selected by the server in HelloRetryRequest in
1754
- // TLS 1.3.
1755
- uint16_t retry_group = 0;
1805
+ // inner_extensions_sent, on clients that offer ECH, is |extensions.sent| for
1806
+ // the ClientHelloInner.
1807
+ uint32_t inner_extensions_sent = 0;
1756
1808
 
1757
1809
  // error, if |wait| is |ssl_hs_error|, is the error the handshake failed on.
1758
1810
  UniquePtr<ERR_SAVE_STATE> error;
@@ -1765,19 +1817,26 @@ struct SSL_HANDSHAKE {
1765
1817
  // transcript is the current handshake transcript.
1766
1818
  SSLTranscript transcript;
1767
1819
 
1820
+ // inner_transcript, on the client, is the handshake transcript for the
1821
+ // ClientHelloInner handshake. It is moved to |transcript| if the server
1822
+ // accepts ECH.
1823
+ SSLTranscript inner_transcript;
1824
+
1825
+ // inner_client_random is the ClientHello random value used with
1826
+ // ClientHelloInner.
1827
+ uint8_t inner_client_random[SSL3_RANDOM_SIZE] = {0};
1828
+
1768
1829
  // cookie is the value of the cookie received from the server, if any.
1769
1830
  Array<uint8_t> cookie;
1770
1831
 
1771
- // ech_grease contains the bytes of the GREASE ECH extension that was sent in
1772
- // the first ClientHello.
1773
- Array<uint8_t> ech_grease;
1832
+ // ech_client_bytes contains the ECH extension to send in the ClientHello.
1833
+ Array<uint8_t> ech_client_bytes;
1774
1834
 
1775
1835
  // ech_client_hello_buf, on the server, contains the bytes of the
1776
1836
  // reconstructed ClientHelloInner message.
1777
1837
  Array<uint8_t> ech_client_hello_buf;
1778
1838
 
1779
- // key_share_bytes is the value of the previously sent KeyShare extension by
1780
- // the client in TLS 1.3.
1839
+ // key_share_bytes is the key_share extension that the client should send.
1781
1840
  Array<uint8_t> key_share_bytes;
1782
1841
 
1783
1842
  // ecdh_public_key, for servers, is the key share to be sent to the client in
@@ -1801,19 +1860,19 @@ struct SSL_HANDSHAKE {
1801
1860
  // peer_key is the peer's ECDH key for a TLS 1.2 client.
1802
1861
  Array<uint8_t> peer_key;
1803
1862
 
1804
- // negotiated_token_binding_version is used by a server to store the
1805
- // on-the-wire encoding of the Token Binding protocol version to advertise in
1806
- // the ServerHello/EncryptedExtensions if the Token Binding extension is to be
1807
- // sent.
1808
- uint16_t negotiated_token_binding_version;
1863
+ // extension_permutation is the permutation to apply to ClientHello
1864
+ // extensions. It maps indices into the |kExtensions| table into other
1865
+ // indices.
1866
+ Array<uint8_t> extension_permutation;
1809
1867
 
1810
1868
  // cert_compression_alg_id, for a server, contains the negotiated certificate
1811
1869
  // compression algorithm for this client. It is only valid if
1812
1870
  // |cert_compression_negotiated| is true.
1813
1871
  uint16_t cert_compression_alg_id;
1814
1872
 
1815
- // ech_hpke_ctx, on the server, is the HPKE context used to decrypt the
1816
- // client's ECH payloads.
1873
+ // ech_hpke_ctx is the HPKE context used in ECH. On the server, it is
1874
+ // initialized if |ech_accept| is true. On the client, it is initialized if
1875
+ // |selected_ech_config| is not nullptr.
1817
1876
  ScopedEVP_HPKE_CTX ech_hpke_ctx;
1818
1877
 
1819
1878
  // server_params, in a TLS 1.2 server, stores the ServerKeyExchange
@@ -1852,10 +1911,15 @@ struct SSL_HANDSHAKE {
1852
1911
  // the client if |in_early_data| is true.
1853
1912
  UniquePtr<SSL_SESSION> early_session;
1854
1913
 
1855
- // ech_server_config_list, for servers, is the list of ECHConfig values that
1856
- // were valid when the server received the first ClientHello. Its value will
1857
- // not change when the config list on |SSL_CTX| is updated.
1858
- UniquePtr<SSL_ECH_SERVER_CONFIG_LIST> ech_server_config_list;
1914
+ // ssl_ech_keys, for servers, is the set of ECH keys to use with this
1915
+ // handshake. This is copied from |SSL_CTX| to ensure consistent behavior as
1916
+ // |SSL_CTX| rotates keys.
1917
+ UniquePtr<SSL_ECH_KEYS> ech_keys;
1918
+
1919
+ // selected_ech_config, for clients, is the ECHConfig the client uses to offer
1920
+ // ECH, or nullptr if ECH is not being offered. If non-NULL, |ech_hpke_ctx|
1921
+ // will be initialized.
1922
+ UniquePtr<ECHConfig> selected_ech_config;
1859
1923
 
1860
1924
  // new_cipher is the cipher being negotiated in this handshake.
1861
1925
  const SSL_CIPHER *new_cipher = nullptr;
@@ -1870,10 +1934,6 @@ struct SSL_HANDSHAKE {
1870
1934
  // influence the handshake on match.
1871
1935
  UniquePtr<SSL_HANDSHAKE_HINTS> hints;
1872
1936
 
1873
- // ech_accept, on the server, indicates whether the server should overwrite
1874
- // part of ServerHello.random with the ECH accept_confirmation value.
1875
- bool ech_accept : 1;
1876
-
1877
1937
  // ech_present, on the server, indicates whether the ClientHello contained an
1878
1938
  // encrypted_client_hello extension.
1879
1939
  bool ech_present : 1;
@@ -1885,10 +1945,6 @@ struct SSL_HANDSHAKE {
1885
1945
  // scts_requested is true if the SCT extension is in the ClientHello.
1886
1946
  bool scts_requested : 1;
1887
1947
 
1888
- // needs_psk_binder is true if the ClientHello has a placeholder PSK binder to
1889
- // be filled in.
1890
- bool needs_psk_binder : 1;
1891
-
1892
1948
  // handshake_finalized is true once the handshake has completed, at which
1893
1949
  // point accessors should use the established state.
1894
1950
  bool handshake_finalized : 1;
@@ -1950,9 +2006,6 @@ struct SSL_HANDSHAKE {
1950
2006
  // in progress.
1951
2007
  bool pending_private_key_op : 1;
1952
2008
 
1953
- // grease_seeded is true if |grease_seed| has been initialized.
1954
- bool grease_seeded : 1;
1955
-
1956
2009
  // handback indicates that a server should pause the handshake after
1957
2010
  // finishing operations that require private key material, in such a way that
1958
2011
  // |SSL_get_error| returns |SSL_ERROR_HANDBACK|. It is set by
@@ -1971,6 +2024,14 @@ struct SSL_HANDSHAKE {
1971
2024
  // which implemented TLS 1.3 incorrectly.
1972
2025
  bool apply_jdk11_workaround : 1;
1973
2026
 
2027
+ // can_release_private_key is true if the private key will no longer be used
2028
+ // in this handshake.
2029
+ bool can_release_private_key : 1;
2030
+
2031
+ // channel_id_negotiated is true if Channel ID should be used in this
2032
+ // handshake.
2033
+ bool channel_id_negotiated : 1;
2034
+
1974
2035
  // client_version is the value sent or received in the ClientHello version.
1975
2036
  uint16_t client_version = 0;
1976
2037
 
@@ -1982,12 +2043,14 @@ struct SSL_HANDSHAKE {
1982
2043
  // record layer.
1983
2044
  uint16_t early_data_written = 0;
1984
2045
 
2046
+ // ech_config_id is the ECH config sent by the client.
2047
+ uint8_t ech_config_id = 0;
2048
+
1985
2049
  // session_id is the session ID in the ClientHello.
1986
2050
  uint8_t session_id[SSL_MAX_SSL_SESSION_ID_LENGTH] = {0};
1987
2051
  uint8_t session_id_len = 0;
1988
2052
 
1989
- // grease_seed is the entropy for GREASE values. It is valid if
1990
- // |grease_seeded| is true.
2053
+ // grease_seed is the entropy for GREASE values.
1991
2054
  uint8_t grease_seed[ssl_grease_last_index + 1] = {0};
1992
2055
  };
1993
2056
 
@@ -2047,6 +2110,16 @@ bool tls13_process_new_session_ticket(SSL *ssl, const SSLMessage &msg);
2047
2110
  bssl::UniquePtr<SSL_SESSION> tls13_create_session_with_ticket(SSL *ssl,
2048
2111
  CBS *body);
2049
2112
 
2113
+ // ssl_setup_extension_permutation computes a ClientHello extension permutation
2114
+ // for |hs|, if applicable. It returns true on success and false on error.
2115
+ bool ssl_setup_extension_permutation(SSL_HANDSHAKE *hs);
2116
+
2117
+ // ssl_setup_key_shares computes client key shares and saves them in |hs|. It
2118
+ // returns true on success and false on failure. If |override_group_id| is zero,
2119
+ // it offers the default groups, including GREASE. If it is non-zero, it offers
2120
+ // a single key share of the specified group.
2121
+ bool ssl_setup_key_shares(SSL_HANDSHAKE *hs, uint16_t override_group_id);
2122
+
2050
2123
  bool ssl_ext_key_share_parse_serverhello(SSL_HANDSHAKE *hs,
2051
2124
  Array<uint8_t> *out_secret,
2052
2125
  uint8_t *out_alert, CBS *contents);
@@ -2069,7 +2142,17 @@ bool ssl_ext_pre_shared_key_add_serverhello(SSL_HANDSHAKE *hs, CBB *out);
2069
2142
  // returns whether it's valid.
2070
2143
  bool ssl_is_sct_list_valid(const CBS *contents);
2071
2144
 
2072
- bool ssl_write_client_hello(SSL_HANDSHAKE *hs);
2145
+ // ssl_write_client_hello_without_extensions writes a ClientHello to |out|,
2146
+ // up to the extensions field. |type| determines the type of ClientHello to
2147
+ // write. If |omit_session_id| is true, the session ID is empty.
2148
+ bool ssl_write_client_hello_without_extensions(const SSL_HANDSHAKE *hs,
2149
+ CBB *cbb,
2150
+ ssl_client_hello_type_t type,
2151
+ bool empty_session_id);
2152
+
2153
+ // ssl_add_client_hello constructs a ClientHello and adds it to the outgoing
2154
+ // flight. It returns true on success and false on error.
2155
+ bool ssl_add_client_hello(SSL_HANDSHAKE *hs);
2073
2156
 
2074
2157
  enum ssl_cert_verify_context_t {
2075
2158
  ssl_cert_verify_server,
@@ -2099,6 +2182,13 @@ bool ssl_is_alpn_protocol_allowed(const SSL_HANDSHAKE *hs,
2099
2182
  bool ssl_negotiate_alpn(SSL_HANDSHAKE *hs, uint8_t *out_alert,
2100
2183
  const SSL_CLIENT_HELLO *client_hello);
2101
2184
 
2185
+ // ssl_get_local_application_settings looks up the configured ALPS value for
2186
+ // |protocol|. If found, it sets |*out_settings| to the value and returns true.
2187
+ // Otherwise, it returns false.
2188
+ bool ssl_get_local_application_settings(const SSL_HANDSHAKE *hs,
2189
+ Span<const uint8_t> *out_settings,
2190
+ Span<const uint8_t> protocol);
2191
+
2102
2192
  // ssl_negotiate_alps negotiates the ALPS extension, if applicable. It returns
2103
2193
  // true on successful negotiation or if nothing was negotiated. It returns false
2104
2194
  // and sets |*out_alert| to an alert on error.
@@ -2135,6 +2225,10 @@ bool ssl_output_cert_chain(SSL_HANDSHAKE *hs);
2135
2225
  // handshake. Note, in TLS 1.2 resumptions, this session is immutable.
2136
2226
  const SSL_SESSION *ssl_handshake_session(const SSL_HANDSHAKE *hs);
2137
2227
 
2228
+ // ssl_done_writing_client_hello is called after the last ClientHello is written
2229
+ // by |hs|. It releases some memory that is no longer needed.
2230
+ void ssl_done_writing_client_hello(SSL_HANDSHAKE *hs);
2231
+
2138
2232
 
2139
2233
  // SSLKEYLOGFILE functions.
2140
2234
 
@@ -2165,7 +2259,8 @@ bool ssl_client_cipher_list_contains_cipher(
2165
2259
  // connection, the values for each index will be deterministic. This allows the
2166
2260
  // same ClientHello be sent twice for a HelloRetryRequest or the same group be
2167
2261
  // advertised in both supported_groups and key_shares.
2168
- uint16_t ssl_get_grease_value(SSL_HANDSHAKE *hs, enum ssl_grease_index_t index);
2262
+ uint16_t ssl_get_grease_value(const SSL_HANDSHAKE *hs,
2263
+ enum ssl_grease_index_t index);
2169
2264
 
2170
2265
 
2171
2266
  // Signature algorithms.
@@ -2325,10 +2420,11 @@ struct SSL_PROTOCOL_METHOD {
2325
2420
  // init_message begins a new handshake message of type |type|. |cbb| is the
2326
2421
  // root CBB to be passed into |finish_message|. |*body| is set to a child CBB
2327
2422
  // the caller should write to. It returns true on success and false on error.
2328
- bool (*init_message)(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
2423
+ bool (*init_message)(const SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
2329
2424
  // finish_message finishes a handshake message. It sets |*out_msg| to the
2330
2425
  // serialized message. It returns true on success and false on error.
2331
- bool (*finish_message)(SSL *ssl, CBB *cbb, bssl::Array<uint8_t> *out_msg);
2426
+ bool (*finish_message)(const SSL *ssl, CBB *cbb,
2427
+ bssl::Array<uint8_t> *out_msg);
2332
2428
  // add_message adds a handshake message to the pending flight. It returns
2333
2429
  // true on success and false on error.
2334
2430
  bool (*add_message)(SSL *ssl, bssl::Array<uint8_t> msg);
@@ -2539,9 +2635,8 @@ struct SSL3_STATE {
2539
2635
  // key_update_count is the number of consecutive KeyUpdates received.
2540
2636
  uint8_t key_update_count = 0;
2541
2637
 
2542
- // The negotiated Token Binding key parameter. Only valid if
2543
- // |token_binding_negotiated| is set.
2544
- uint8_t negotiated_token_binding_param = 0;
2638
+ // ech_accept indicates whether ECH was accepted by the server.
2639
+ bool ech_accept : 1;
2545
2640
 
2546
2641
  // skip_early_data instructs the record layer to skip unexpected early data
2547
2642
  // messages when 0RTT is rejected.
@@ -2576,9 +2671,8 @@ struct SSL3_STATE {
2576
2671
 
2577
2672
  bool send_connection_binding : 1;
2578
2673
 
2579
- // In a client, this means that the server supported Channel ID and that a
2580
- // Channel ID was sent. In a server it means that we echoed support for
2581
- // Channel IDs and that |channel_id| will be valid after the handshake.
2674
+ // channel_id_valid is true if, on the server, the client has negotiated a
2675
+ // Channel ID and the |channel_id| field is filled in.
2582
2676
  bool channel_id_valid : 1;
2583
2677
 
2584
2678
  // key_update_pending is true if we have a KeyUpdate acknowledgment
@@ -2591,9 +2685,6 @@ struct SSL3_STATE {
2591
2685
  // early_data_accepted is true if early data was accepted by the server.
2592
2686
  bool early_data_accepted : 1;
2593
2687
 
2594
- // token_binding_negotiated is set if Token Binding was negotiated.
2595
- bool token_binding_negotiated : 1;
2596
-
2597
2688
  // alert_dispatch is true there is an alert in |send_alert| to be sent.
2598
2689
  bool alert_dispatch : 1;
2599
2690
 
@@ -2876,7 +2967,8 @@ struct SSL_CONFIG {
2876
2967
 
2877
2968
  Array<uint16_t> supported_group_list; // our list
2878
2969
 
2879
- // The client's Channel ID private key.
2970
+ // channel_id_private is the client's Channel ID private key, or null if
2971
+ // Channel ID should not be offered on this connection.
2880
2972
  UniquePtr<EVP_PKEY> channel_id_private;
2881
2973
 
2882
2974
  // For a client, this contains the list of supported protocols in wire
@@ -2887,9 +2979,6 @@ struct SSL_CONFIG {
2887
2979
  // along with their corresponding ALPS values.
2888
2980
  GrowableArray<ALPSConfig> alps_configs;
2889
2981
 
2890
- // Contains a list of supported Token Binding key parameters.
2891
- Array<uint8_t> token_binding_params;
2892
-
2893
2982
  // Contains the QUIC transport params that this endpoint will send.
2894
2983
  Array<uint8_t> quic_transport_params;
2895
2984
 
@@ -2904,6 +2993,10 @@ struct SSL_CONFIG {
2904
2993
  // DTLS-SRTP.
2905
2994
  UniquePtr<STACK_OF(SRTP_PROTECTION_PROFILE)> srtp_profiles;
2906
2995
 
2996
+ // client_ech_config_list, if not empty, is a serialized ECHConfigList
2997
+ // structure for the client to use when negotiating ECH.
2998
+ Array<uint8_t> client_ech_config_list;
2999
+
2907
3000
  // verify_mode is a bitmask of |SSL_VERIFY_*| values.
2908
3001
  uint8_t verify_mode = SSL_VERIFY_NONE;
2909
3002
 
@@ -2918,9 +3011,8 @@ struct SSL_CONFIG {
2918
3011
  // whether OCSP stapling will be requested.
2919
3012
  bool ocsp_stapling_enabled : 1;
2920
3013
 
2921
- // channel_id_enabled is copied from the |SSL_CTX|. For a server, means that
2922
- // we'll accept Channel IDs from clients. For a client, means that we'll
2923
- // advertise support.
3014
+ // channel_id_enabled is copied from the |SSL_CTX|. For a server, it means
3015
+ // that we'll accept Channel IDs from clients. It is ignored on the client.
2924
3016
  bool channel_id_enabled : 1;
2925
3017
 
2926
3018
  // If enforce_rsa_key_usage is true, the handshake will fail if the
@@ -2950,6 +3042,9 @@ struct SSL_CONFIG {
2950
3042
  // QUIC drafts up to and including 32 used a different TLS extension
2951
3043
  // codepoint to convey QUIC's transport parameters.
2952
3044
  bool quic_use_legacy_codepoint : 1;
3045
+
3046
+ // permute_extensions is whether to permute extensions when sending messages.
3047
+ bool permute_extensions : 1;
2953
3048
  };
2954
3049
 
2955
3050
  // From RFC 8446, used in determining PSK modes.
@@ -2970,7 +3065,7 @@ bool ssl_is_key_type_supported(int key_type);
2970
3065
  bool ssl_compare_public_and_private_key(const EVP_PKEY *pubkey,
2971
3066
  const EVP_PKEY *privkey);
2972
3067
  bool ssl_cert_check_private_key(const CERT *cert, const EVP_PKEY *privkey);
2973
- int ssl_get_new_session(SSL_HANDSHAKE *hs, int is_server);
3068
+ bool ssl_get_new_session(SSL_HANDSHAKE *hs);
2974
3069
  int ssl_encrypt_ticket(SSL_HANDSHAKE *hs, CBB *out, const SSL_SESSION *session);
2975
3070
  int ssl_ctx_rotate_ticket_encryption_key(SSL_CTX *ctx);
2976
3071
 
@@ -3073,14 +3168,14 @@ int tls_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *buf,
3073
3168
  bool tls_new(SSL *ssl);
3074
3169
  void tls_free(SSL *ssl);
3075
3170
 
3076
- bool tls_init_message(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
3077
- bool tls_finish_message(SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
3171
+ bool tls_init_message(const SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
3172
+ bool tls_finish_message(const SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
3078
3173
  bool tls_add_message(SSL *ssl, Array<uint8_t> msg);
3079
3174
  bool tls_add_change_cipher_spec(SSL *ssl);
3080
3175
  int tls_flush_flight(SSL *ssl);
3081
3176
 
3082
- bool dtls1_init_message(SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
3083
- bool dtls1_finish_message(SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
3177
+ bool dtls1_init_message(const SSL *ssl, CBB *cbb, CBB *body, uint8_t type);
3178
+ bool dtls1_finish_message(const SSL *ssl, CBB *cbb, Array<uint8_t> *out_msg);
3084
3179
  bool dtls1_add_message(SSL *ssl, Array<uint8_t> msg);
3085
3180
  bool dtls1_add_change_cipher_spec(SSL *ssl);
3086
3181
  int dtls1_flush_flight(SSL *ssl);
@@ -3165,11 +3260,27 @@ bool tls1_set_curves(Array<uint16_t> *out_group_ids, Span<const int> curves);
3165
3260
  // false.
3166
3261
  bool tls1_set_curves_list(Array<uint16_t> *out_group_ids, const char *curves);
3167
3262
 
3168
- // ssl_add_clienthello_tlsext writes ClientHello extensions to |out|. It returns
3169
- // true on success and false on failure. The |header_len| argument is the length
3170
- // of the ClientHello written so far and is used to compute the padding length.
3171
- // (It does not include the record header.)
3172
- bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, size_t header_len);
3263
+ // ssl_add_clienthello_tlsext writes ClientHello extensions to |out| for |type|.
3264
+ // It returns true on success and false on failure. The |header_len| argument is
3265
+ // the length of the ClientHello written so far and is used to compute the
3266
+ // padding length. (It does not include the record header or handshake headers.)
3267
+ //
3268
+ // If |type| is |ssl_client_hello_inner|, this function also writes the
3269
+ // compressed extensions to |out_encoded|. Otherwise, |out_encoded| should be
3270
+ // nullptr.
3271
+ //
3272
+ // On success, the function sets |*out_needs_psk_binder| to whether the last
3273
+ // ClientHello extension was the pre_shared_key extension and needs a PSK binder
3274
+ // filled in. The caller should then update |out| and, if applicable,
3275
+ // |out_encoded| with the binder after completing the whole message.
3276
+ //
3277
+ // If |omit_ech_len| is non-zero, the ECH extension is omitted, but padding is
3278
+ // computed as if there were an extension of length |omit_ech_len|. This is used
3279
+ // to compute ClientHelloOuterAAD.
3280
+ bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, CBB *out_encoded,
3281
+ bool *out_needs_psk_binder,
3282
+ ssl_client_hello_type_t type, size_t header_len,
3283
+ size_t omit_ech_len);
3173
3284
 
3174
3285
  bool ssl_add_serverhello_tlsext(SSL_HANDSHAKE *hs, CBB *out);
3175
3286
  bool ssl_parse_clienthello_tlsext(SSL_HANDSHAKE *hs,
@@ -3212,12 +3323,6 @@ bool tls1_channel_id_hash(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len);
3212
3323
  // data.
3213
3324
  bool tls1_record_handshake_hashes_for_channel_id(SSL_HANDSHAKE *hs);
3214
3325
 
3215
- // ssl_do_channel_id_callback checks runs |hs->ssl->ctx->channel_id_cb| if
3216
- // necessary. It returns true on success and false on fatal error. Note that, on
3217
- // success, |hs->ssl->channel_id_private| may be unset, in which case the
3218
- // operation should be retried later.
3219
- bool ssl_do_channel_id_callback(SSL_HANDSHAKE *hs);
3220
-
3221
3326
  // ssl_can_write returns whether |ssl| is allowed to write.
3222
3327
  bool ssl_can_write(const SSL *ssl);
3223
3328
 
@@ -3341,9 +3446,6 @@ struct ssl_ctx_st {
3341
3446
  int (*client_cert_cb)(SSL *ssl, X509 **out_x509,
3342
3447
  EVP_PKEY **out_pkey) = nullptr;
3343
3448
 
3344
- // get channel id callback
3345
- void (*channel_id_cb)(SSL *ssl, EVP_PKEY **out_pkey) = nullptr;
3346
-
3347
3449
  CRYPTO_EX_DATA ex_data;
3348
3450
 
3349
3451
  // Default values used when no per-SSL value is defined follow
@@ -3471,13 +3573,14 @@ struct ssl_ctx_st {
3471
3573
  // Supported group values inherited by SSL structure
3472
3574
  bssl::Array<uint16_t> supported_group_list;
3473
3575
 
3474
- // The client's Channel ID private key.
3576
+ // channel_id_private is the client's Channel ID private key, or null if
3577
+ // Channel ID should not be offered on this connection.
3475
3578
  bssl::UniquePtr<EVP_PKEY> channel_id_private;
3476
3579
 
3477
- // ech_server_config_list contains the server's list of ECHConfig values and
3478
- // associated private keys. This list may be swapped out at any time, so all
3479
- // access must be synchronized through |lock|.
3480
- bssl::UniquePtr<SSL_ECH_SERVER_CONFIG_LIST> ech_server_config_list;
3580
+ // ech_keys contains the server's list of ECHConfig values and associated
3581
+ // private keys. This list may be swapped out at any time, so all access must
3582
+ // be synchronized through |lock|.
3583
+ bssl::UniquePtr<SSL_ECH_KEYS> ech_keys;
3481
3584
 
3482
3585
  // keylog_callback, if not NULL, is the key logging callback. See
3483
3586
  // |SSL_CTX_set_keylog_callback|.
@@ -3526,9 +3629,12 @@ struct ssl_ctx_st {
3526
3629
  // advertise support.
3527
3630
  bool channel_id_enabled : 1;
3528
3631
 
3529
- // grease_enabled is whether draft-davidben-tls-grease-01 is enabled.
3632
+ // grease_enabled is whether GREASE (RFC 8701) is enabled.
3530
3633
  bool grease_enabled : 1;
3531
3634
 
3635
+ // permute_extensions is whether to permute extensions when sending messages.
3636
+ bool permute_extensions : 1;
3637
+
3532
3638
  // allow_unknown_alpn_protos is whether the client allows unsolicited ALPN
3533
3639
  // protocols from the peer.
3534
3640
  bool allow_unknown_alpn_protos : 1;
@@ -3792,18 +3898,17 @@ struct ssl_session_st {
3792
3898
  friend void SSL_SESSION_free(SSL_SESSION *);
3793
3899
  };
3794
3900
 
3795
- struct ssl_ech_server_config_list_st {
3796
- ssl_ech_server_config_list_st() = default;
3797
- ssl_ech_server_config_list_st(const ssl_ech_server_config_list_st &) = delete;
3798
- ssl_ech_server_config_list_st &operator=(
3799
- const ssl_ech_server_config_list_st &) = delete;
3901
+ struct ssl_ech_keys_st {
3902
+ ssl_ech_keys_st() = default;
3903
+ ssl_ech_keys_st(const ssl_ech_keys_st &) = delete;
3904
+ ssl_ech_keys_st &operator=(const ssl_ech_keys_st &) = delete;
3800
3905
 
3801
- bssl::GrowableArray<bssl::ECHServerConfig> configs;
3906
+ bssl::GrowableArray<bssl::UniquePtr<bssl::ECHServerConfig>> configs;
3802
3907
  CRYPTO_refcount_t references = 1;
3803
3908
 
3804
3909
  private:
3805
- ~ssl_ech_server_config_list_st() = default;
3806
- friend void SSL_ECH_SERVER_CONFIG_LIST_free(SSL_ECH_SERVER_CONFIG_LIST *);
3910
+ ~ssl_ech_keys_st() = default;
3911
+ friend void SSL_ECH_KEYS_free(SSL_ECH_KEYS *);
3807
3912
  };
3808
3913
 
3809
3914
  #endif // OPENSSL_HEADER_SSL_INTERNAL_H