grpc 1.35.0 → 1.36.0

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 (335) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +60 -57
  3. data/include/grpc/grpc_security.h +16 -11
  4. data/src/core/ext/filters/client_channel/client_channel.cc +32 -26
  5. data/src/core/ext/filters/client_channel/client_channel.h +0 -2
  6. data/src/core/ext/filters/client_channel/config_selector.h +1 -1
  7. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +2 -2
  8. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +3 -5
  9. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -2
  10. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -2
  11. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +1 -1
  12. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +8 -6
  13. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +289 -170
  14. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_args.h +5 -0
  15. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +1 -3
  16. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +231 -109
  17. data/src/core/ext/filters/client_channel/resolver.cc +2 -5
  18. data/src/core/ext/filters/client_channel/resolver.h +1 -12
  19. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +36 -45
  20. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +29 -41
  21. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +16 -14
  22. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +18 -15
  23. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +362 -0
  24. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +4 -4
  25. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +22 -74
  26. data/src/core/ext/filters/client_channel/server_address.cc +6 -0
  27. data/src/core/ext/filters/client_channel/server_address.h +31 -0
  28. data/src/core/ext/filters/client_channel/subchannel.cc +2 -2
  29. data/src/core/ext/filters/max_age/max_age_filter.cc +35 -32
  30. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +1 -1
  31. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +47 -22
  32. data/src/core/ext/transport/chttp2/server/chttp2_server.h +11 -2
  33. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +11 -1
  34. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +62 -18
  35. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +0 -1
  36. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +11 -16
  37. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +42 -59
  38. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.c +3 -2
  39. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +15 -0
  40. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +25 -1
  41. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +75 -0
  42. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +2 -2
  43. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +9 -9
  44. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +7 -7
  45. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +28 -13
  46. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +0 -1
  47. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +11 -5
  48. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.h +41 -7
  49. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +0 -1
  50. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +23 -21
  51. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +122 -77
  52. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +13 -9
  53. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +37 -5
  54. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +0 -1
  55. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +11 -9
  56. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +44 -27
  57. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +42 -16
  58. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +106 -0
  59. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +0 -1
  60. data/src/core/ext/upb-generated/envoy/extensions/clusters/aggregate/v3/cluster.upb.c +29 -0
  61. data/src/core/ext/upb-generated/envoy/extensions/clusters/aggregate/v3/cluster.upb.h +67 -0
  62. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +13 -16
  63. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +51 -42
  64. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.c +0 -1
  65. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +16 -13
  66. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +50 -18
  67. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +4 -7
  68. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +0 -17
  69. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +0 -1
  70. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +30 -23
  71. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +85 -73
  72. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.c +0 -3
  73. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.c +0 -3
  74. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +0 -1
  75. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.c +0 -2
  76. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +0 -1
  77. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +21 -4
  78. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +29 -0
  79. data/src/core/ext/upb-generated/{udpa/core/v1 → xds/core/v3}/authority.upb.c +5 -5
  80. data/src/core/ext/upb-generated/xds/core/v3/authority.upb.h +60 -0
  81. data/src/core/ext/upb-generated/xds/core/v3/collection_entry.upb.c +52 -0
  82. data/src/core/ext/upb-generated/xds/core/v3/collection_entry.upb.h +143 -0
  83. data/src/core/ext/upb-generated/xds/core/v3/context_params.upb.c +42 -0
  84. data/src/core/ext/upb-generated/xds/core/v3/context_params.upb.h +84 -0
  85. data/src/core/ext/upb-generated/{udpa/core/v1 → xds/core/v3}/resource.upb.c +9 -9
  86. data/src/core/ext/upb-generated/xds/core/v3/resource.upb.h +94 -0
  87. data/src/core/ext/upb-generated/xds/core/v3/resource_locator.upb.c +54 -0
  88. data/src/core/ext/upb-generated/xds/core/v3/resource_locator.upb.h +166 -0
  89. data/src/core/ext/upb-generated/xds/core/v3/resource_name.upb.c +36 -0
  90. data/src/core/ext/upb-generated/xds/core/v3/resource_name.upb.h +85 -0
  91. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +168 -171
  92. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +405 -420
  93. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.h +2 -2
  94. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/outlier_detection.upbdefs.c +12 -9
  95. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c +177 -171
  96. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.h +10 -0
  97. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +88 -88
  98. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/health_check.upbdefs.c +153 -153
  99. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/proxy_protocol.upbdefs.c +4 -7
  100. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.c +33 -20
  101. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint.upbdefs.c +56 -59
  102. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.c +116 -111
  103. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c +129 -121
  104. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.c +21 -24
  105. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c +17 -13
  106. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +747 -724
  107. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.h +5 -0
  108. data/src/core/ext/upbdefs-generated/envoy/config/trace/v3/http_tracer.upbdefs.c +22 -25
  109. data/src/core/ext/upbdefs-generated/envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.c +51 -0
  110. data/src/core/ext/upbdefs-generated/envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.h +35 -0
  111. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +369 -376
  112. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/cert.upbdefs.c +12 -16
  113. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +112 -108
  114. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.c +45 -53
  115. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +177 -180
  116. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.c +92 -102
  117. data/src/core/ext/upbdefs-generated/envoy/service/discovery/v3/discovery.upbdefs.h +5 -0
  118. data/src/core/ext/upbdefs-generated/envoy/service/endpoint/v3/eds.upbdefs.c +32 -42
  119. data/src/core/ext/upbdefs-generated/envoy/service/listener/v3/lds.upbdefs.c +30 -40
  120. data/src/core/ext/upbdefs-generated/envoy/service/load_stats/v3/lrs.upbdefs.c +4 -7
  121. data/src/core/ext/upbdefs-generated/envoy/service/route/v3/rds.upbdefs.c +38 -44
  122. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/string.upbdefs.c +30 -33
  123. data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.c +14 -11
  124. data/src/core/ext/upbdefs-generated/xds/core/v3/authority.upbdefs.c +42 -0
  125. data/src/core/ext/upbdefs-generated/xds/core/v3/authority.upbdefs.h +35 -0
  126. data/src/core/ext/upbdefs-generated/xds/core/v3/collection_entry.upbdefs.c +62 -0
  127. data/src/core/ext/upbdefs-generated/xds/core/v3/collection_entry.upbdefs.h +40 -0
  128. data/src/core/ext/upbdefs-generated/xds/core/v3/context_params.upbdefs.c +45 -0
  129. data/src/core/ext/upbdefs-generated/xds/core/v3/context_params.upbdefs.h +40 -0
  130. data/src/core/ext/upbdefs-generated/xds/core/v3/resource.upbdefs.c +49 -0
  131. data/src/core/ext/upbdefs-generated/xds/core/v3/resource.upbdefs.h +35 -0
  132. data/src/core/ext/upbdefs-generated/xds/core/v3/resource_locator.upbdefs.c +67 -0
  133. data/src/core/ext/upbdefs-generated/xds/core/v3/resource_locator.upbdefs.h +40 -0
  134. data/src/core/ext/upbdefs-generated/xds/core/v3/resource_name.upbdefs.c +50 -0
  135. data/src/core/ext/upbdefs-generated/xds/core/v3/resource_name.upbdefs.h +35 -0
  136. data/src/core/ext/xds/xds_api.cc +738 -567
  137. data/src/core/ext/xds/xds_api.h +46 -84
  138. data/src/core/ext/xds/xds_bootstrap.cc +59 -40
  139. data/src/core/ext/xds/xds_bootstrap.h +12 -4
  140. data/src/core/ext/xds/xds_certificate_provider.cc +180 -74
  141. data/src/core/ext/xds/xds_certificate_provider.h +83 -44
  142. data/src/core/ext/xds/xds_client.cc +13 -11
  143. data/src/core/ext/xds/xds_client.h +3 -0
  144. data/src/core/ext/xds/xds_client_stats.cc +2 -1
  145. data/src/core/ext/xds/xds_server_config_fetcher.cc +147 -11
  146. data/src/core/lib/channel/handshaker.cc +2 -5
  147. data/src/core/lib/channel/handshaker.h +1 -1
  148. data/src/core/lib/gpr/log.cc +6 -1
  149. data/src/core/lib/gprpp/mpscq.cc +2 -2
  150. data/src/core/lib/gprpp/ref_counted.h +1 -1
  151. data/src/core/lib/gprpp/sync.h +129 -40
  152. data/src/core/lib/gprpp/time_util.cc +77 -0
  153. data/src/core/lib/gprpp/time_util.h +42 -0
  154. data/src/core/lib/http/httpcli_security_connector.cc +2 -2
  155. data/src/core/lib/iomgr/ev_apple.cc +10 -7
  156. data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -4
  157. data/src/core/lib/iomgr/iomgr_posix.cc +0 -1
  158. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +0 -1
  159. data/src/core/lib/iomgr/sockaddr_utils.cc +1 -1
  160. data/src/core/lib/iomgr/socket_utils_common_posix.cc +1 -0
  161. data/src/core/lib/iomgr/tcp_client_posix.cc +1 -1
  162. data/src/core/lib/iomgr/tcp_posix.cc +4 -4
  163. data/src/core/lib/security/authorization/matchers.cc +339 -0
  164. data/src/core/lib/security/authorization/matchers.h +158 -0
  165. data/src/core/lib/security/authorization/mock_cel/activation.h +1 -1
  166. data/src/core/lib/security/authorization/mock_cel/cel_value.h +9 -7
  167. data/src/core/lib/security/credentials/alts/alts_credentials.cc +2 -1
  168. data/src/core/lib/security/credentials/alts/alts_credentials.h +1 -1
  169. data/src/core/lib/security/credentials/credentials.h +2 -1
  170. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +1 -1
  171. data/src/core/lib/security/credentials/external/external_account_credentials.cc +2 -2
  172. data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +1 -1
  173. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +1 -1
  174. data/src/core/lib/security/credentials/fake/fake_credentials.cc +1 -1
  175. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +7 -6
  176. data/src/core/lib/security/credentials/insecure/insecure_credentials.cc +2 -2
  177. data/src/core/lib/security/credentials/jwt/json_token.cc +0 -3
  178. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +0 -3
  179. data/src/core/lib/security/credentials/local/local_credentials.cc +2 -1
  180. data/src/core/lib/security/credentials/local/local_credentials.h +1 -1
  181. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +2 -1
  182. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +1 -1
  183. data/src/core/lib/security/credentials/tls/tls_credentials.cc +2 -1
  184. data/src/core/lib/security/credentials/tls/tls_credentials.h +1 -1
  185. data/src/core/lib/security/credentials/xds/xds_credentials.cc +128 -59
  186. data/src/core/lib/security/credentials/xds/xds_credentials.h +3 -3
  187. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc +5 -5
  188. data/src/core/lib/security/security_connector/ssl_utils.cc +3 -0
  189. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +26 -14
  190. data/src/core/lib/security/transport/security_handshaker.cc +1 -3
  191. data/src/core/lib/slice/slice_intern.cc +1 -1
  192. data/src/core/lib/surface/init.cc +13 -15
  193. data/src/core/lib/surface/server.cc +3 -3
  194. data/src/core/lib/surface/server.h +3 -0
  195. data/src/core/lib/surface/version.cc +2 -2
  196. data/src/core/lib/transport/metadata.cc +6 -2
  197. data/src/core/plugin_registry/grpc_plugin_registry.cc +6 -0
  198. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +17 -20
  199. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +16 -21
  200. data/src/core/tsi/fake_transport_security.cc +1 -1
  201. data/src/core/tsi/ssl/session_cache/ssl_session.h +0 -3
  202. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +0 -2
  203. data/src/core/tsi/ssl/session_cache/ssl_session_cache.h +2 -4
  204. data/src/core/tsi/ssl_transport_security.cc +0 -3
  205. data/src/core/tsi/ssl_transport_security.h +0 -3
  206. data/src/ruby/lib/grpc/version.rb +1 -1
  207. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +7 -0
  208. data/third_party/abseil-cpp/absl/synchronization/internal/graphcycles.cc +1 -0
  209. data/third_party/boringssl-with-bazel/err_data.c +725 -723
  210. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_bitstr.c +3 -3
  211. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_enum.c +2 -2
  212. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_int.c +5 -5
  213. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +3 -10
  214. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_octet.c +3 -3
  215. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_type.c +4 -2
  216. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_utctm.c +2 -2
  217. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +15 -14
  218. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_locl.h +30 -0
  219. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_dec.c +28 -79
  220. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +39 -85
  221. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_fre.c +5 -16
  222. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_new.c +10 -61
  223. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_typ.c +0 -2
  224. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_utl.c +2 -2
  225. data/third_party/boringssl-with-bazel/src/crypto/bio/socket_helper.c +4 -0
  226. data/third_party/boringssl-with-bazel/src/crypto/blake2/blake2.c +158 -0
  227. data/third_party/boringssl-with-bazel/src/crypto/bn_extra/bn_asn1.c +3 -10
  228. data/third_party/boringssl-with-bazel/src/crypto/bytestring/ber.c +8 -9
  229. data/third_party/boringssl-with-bazel/src/crypto/bytestring/cbs.c +60 -45
  230. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/e_chacha20poly1305.c +6 -81
  231. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/internal.h +87 -0
  232. data/third_party/boringssl-with-bazel/src/crypto/cpu-aarch64-win.c +41 -0
  233. data/third_party/boringssl-with-bazel/src/crypto/{dh → dh_extra}/dh_asn1.c +0 -0
  234. data/third_party/boringssl-with-bazel/src/crypto/{dh → dh_extra}/params.c +179 -0
  235. data/third_party/boringssl-with-bazel/src/crypto/digest_extra/digest_extra.c +25 -0
  236. data/third_party/boringssl-with-bazel/src/crypto/ec_extra/ec_asn1.c +2 -17
  237. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm.c +3 -1
  238. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/bn.c +13 -20
  239. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/div.c +2 -3
  240. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +9 -1
  241. data/third_party/boringssl-with-bazel/src/crypto/{dh → fipsmodule/dh}/check.c +0 -0
  242. data/third_party/boringssl-with-bazel/src/crypto/{dh → fipsmodule/dh}/dh.c +136 -213
  243. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.c +12 -0
  244. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.c +9 -1
  245. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +28 -0
  246. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +128 -38
  247. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/urandom.c +0 -7
  248. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +51 -32
  249. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +147 -0
  250. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +18 -29
  251. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +13 -4
  252. data/third_party/boringssl-with-bazel/src/crypto/poly1305/poly1305.c +10 -7
  253. data/third_party/boringssl-with-bazel/src/crypto/poly1305/poly1305_arm.c +13 -11
  254. data/third_party/boringssl-with-bazel/src/crypto/poly1305/poly1305_vec.c +4 -0
  255. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/passive.c +34 -0
  256. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/rand_extra.c +4 -0
  257. data/third_party/boringssl-with-bazel/src/crypto/stack/stack.c +7 -13
  258. data/third_party/boringssl-with-bazel/src/crypto/x509/rsa_pss.c +5 -1
  259. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +1 -1
  260. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_ext.c +10 -7
  261. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_r2x.c +1 -1
  262. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +8 -8
  263. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_v3.c +1 -1
  264. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +29 -23
  265. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +1 -2
  266. data/third_party/boringssl-with-bazel/src/crypto/x509/x_pkey.c +2 -2
  267. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +39 -6
  268. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509a.c +2 -2
  269. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_akey.c +3 -3
  270. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_alt.c +11 -10
  271. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_bitst.c +3 -3
  272. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_conf.c +25 -25
  273. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_cpols.c +2 -2
  274. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_enum.c +2 -1
  275. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_genn.c +40 -20
  276. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_ia5.c +3 -4
  277. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_lib.c +25 -36
  278. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_prn.c +1 -1
  279. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +6 -6
  280. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_utl.c +6 -6
  281. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +3 -3
  282. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +652 -545
  283. data/third_party/boringssl-with-bazel/src/include/openssl/asn1t.h +0 -167
  284. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +10 -5
  285. data/third_party/boringssl-with-bazel/src/include/openssl/blake2.h +62 -0
  286. data/third_party/boringssl-with-bazel/src/include/openssl/bytestring.h +22 -7
  287. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +15 -0
  288. data/third_party/boringssl-with-bazel/src/include/openssl/dh.h +56 -26
  289. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +1 -0
  290. data/third_party/boringssl-with-bazel/src/include/openssl/ec.h +15 -0
  291. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +12 -2
  292. data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +3 -0
  293. data/third_party/boringssl-with-bazel/src/include/openssl/span.h +2 -1
  294. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +42 -24
  295. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +27 -8
  296. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +287 -98
  297. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +139 -36
  298. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +4 -3
  299. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +11 -20
  300. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +10 -5
  301. data/third_party/boringssl-with-bazel/src/ssl/internal.h +37 -16
  302. data/third_party/boringssl-with-bazel/src/ssl/s3_lib.cc +0 -1
  303. data/third_party/boringssl-with-bazel/src/ssl/ssl_asn1.cc +7 -8
  304. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +20 -14
  305. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +7 -8
  306. data/third_party/boringssl-with-bazel/src/ssl/ssl_transcript.cc +2 -2
  307. data/third_party/boringssl-with-bazel/src/ssl/t1_enc.cc +5 -7
  308. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +329 -31
  309. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +2 -2
  310. data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +48 -15
  311. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +66 -24
  312. metadata +77 -65
  313. data/src/core/ext/upb-generated/udpa/core/v1/authority.upb.h +0 -60
  314. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.c +0 -52
  315. data/src/core/ext/upb-generated/udpa/core/v1/collection_entry.upb.h +0 -143
  316. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.c +0 -42
  317. data/src/core/ext/upb-generated/udpa/core/v1/context_params.upb.h +0 -84
  318. data/src/core/ext/upb-generated/udpa/core/v1/resource.upb.h +0 -94
  319. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.c +0 -54
  320. data/src/core/ext/upb-generated/udpa/core/v1/resource_locator.upb.h +0 -173
  321. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.c +0 -36
  322. data/src/core/ext/upb-generated/udpa/core/v1/resource_name.upb.h +0 -92
  323. data/src/core/ext/upbdefs-generated/udpa/core/v1/authority.upbdefs.c +0 -42
  324. data/src/core/ext/upbdefs-generated/udpa/core/v1/authority.upbdefs.h +0 -35
  325. data/src/core/ext/upbdefs-generated/udpa/core/v1/collection_entry.upbdefs.c +0 -62
  326. data/src/core/ext/upbdefs-generated/udpa/core/v1/collection_entry.upbdefs.h +0 -40
  327. data/src/core/ext/upbdefs-generated/udpa/core/v1/context_params.upbdefs.c +0 -45
  328. data/src/core/ext/upbdefs-generated/udpa/core/v1/context_params.upbdefs.h +0 -40
  329. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource.upbdefs.c +0 -49
  330. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource.upbdefs.h +0 -35
  331. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_locator.upbdefs.c +0 -68
  332. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_locator.upbdefs.h +0 -40
  333. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_name.upbdefs.c +0 -51
  334. data/src/core/ext/upbdefs-generated/udpa/core/v1/resource_name.upbdefs.h +0 -35
  335. data/src/core/lib/iomgr/iomgr_posix.h +0 -26
@@ -177,7 +177,6 @@ SSL3_STATE::SSL3_STATE()
177
177
  key_update_pending(false),
178
178
  wpend_pending(false),
179
179
  early_data_accepted(false),
180
- tls13_downgrade(false),
181
180
  token_binding_negotiated(false),
182
181
  alert_dispatch(false),
183
182
  renegotiate_pending(false),
@@ -105,7 +105,7 @@ BSSL_NAMESPACE_BEGIN
105
105
  // sslVersion INTEGER, -- protocol version number
106
106
  // cipher OCTET STRING, -- two bytes long
107
107
  // sessionID OCTET STRING,
108
- // masterKey OCTET STRING,
108
+ // secret OCTET STRING,
109
109
  // time [1] INTEGER, -- seconds since UNIX epoch
110
110
  // timeout [2] INTEGER, -- in seconds
111
111
  // peer [3] Certificate OPTIONAL,
@@ -218,8 +218,7 @@ static int SSL_SESSION_to_bytes_full(const SSL_SESSION *in, CBB *cbb,
218
218
  // The session ID is irrelevant for a session ticket.
219
219
  !CBB_add_asn1_octet_string(&session, in->session_id,
220
220
  for_ticket ? 0 : in->session_id_length) ||
221
- !CBB_add_asn1_octet_string(&session, in->master_key,
222
- in->master_key_length) ||
221
+ !CBB_add_asn1_octet_string(&session, in->secret, in->secret_length) ||
223
222
  !CBB_add_asn1(&session, &child, kTimeTag) ||
224
223
  !CBB_add_asn1_uint64(&child, in->time) ||
225
224
  !CBB_add_asn1(&session, &child, kTimeoutTag) ||
@@ -593,18 +592,18 @@ UniquePtr<SSL_SESSION> SSL_SESSION_parse(CBS *cbs,
593
592
  return nullptr;
594
593
  }
595
594
 
596
- CBS session_id, master_key;
595
+ CBS session_id, secret;
597
596
  if (!CBS_get_asn1(&session, &session_id, CBS_ASN1_OCTETSTRING) ||
598
597
  CBS_len(&session_id) > SSL3_MAX_SSL_SESSION_ID_LENGTH ||
599
- !CBS_get_asn1(&session, &master_key, CBS_ASN1_OCTETSTRING) ||
600
- CBS_len(&master_key) > SSL_MAX_MASTER_KEY_LENGTH) {
598
+ !CBS_get_asn1(&session, &secret, CBS_ASN1_OCTETSTRING) ||
599
+ CBS_len(&secret) > SSL_MAX_MASTER_KEY_LENGTH) {
601
600
  OPENSSL_PUT_ERROR(SSL, SSL_R_INVALID_SSL_SESSION);
602
601
  return nullptr;
603
602
  }
604
603
  OPENSSL_memcpy(ret->session_id, CBS_data(&session_id), CBS_len(&session_id));
605
604
  ret->session_id_length = CBS_len(&session_id);
606
- OPENSSL_memcpy(ret->master_key, CBS_data(&master_key), CBS_len(&master_key));
607
- ret->master_key_length = CBS_len(&master_key);
605
+ OPENSSL_memcpy(ret->secret, CBS_data(&secret), CBS_len(&secret));
606
+ ret->secret_length = CBS_len(&secret);
608
607
 
609
608
  CBS child;
610
609
  uint64_t timeout;
@@ -565,7 +565,6 @@ ssl_ctx_st::ssl_ctx_st(const SSL_METHOD *ssl_method)
565
565
  grease_enabled(false),
566
566
  allow_unknown_alpn_protos(false),
567
567
  false_start_allowed_without_alpn(false),
568
- ignore_tls13_downgrade(false),
569
568
  handoff(false),
570
569
  enable_early_data(false) {
571
570
  CRYPTO_MUTEX_init(&lock);
@@ -711,7 +710,6 @@ SSL *SSL_new(SSL_CTX *ctx) {
711
710
  ctx->signed_cert_timestamps_enabled;
712
711
  ssl->config->ocsp_stapling_enabled = ctx->ocsp_stapling_enabled;
713
712
  ssl->config->handoff = ctx->handoff;
714
- ssl->config->ignore_tls13_downgrade = ctx->ignore_tls13_downgrade;
715
713
  ssl->quic_method = ctx->quic_method;
716
714
 
717
715
  if (!ssl->method->ssl_new(ssl.get()) ||
@@ -724,6 +722,7 @@ SSL *SSL_new(SSL_CTX *ctx) {
724
722
 
725
723
  SSL_CONFIG::SSL_CONFIG(SSL *ssl_arg)
726
724
  : ssl(ssl_arg),
725
+ ech_grease_enabled(false),
727
726
  signed_cert_timestamps_enabled(false),
728
727
  ocsp_stapling_enabled(false),
729
728
  channel_id_enabled(false),
@@ -731,8 +730,8 @@ SSL_CONFIG::SSL_CONFIG(SSL *ssl_arg)
731
730
  retain_only_sha256_of_client_certs(false),
732
731
  handoff(false),
733
732
  shed_handshake_config(false),
734
- ignore_tls13_downgrade(false),
735
- jdk11_workaround(false) {
733
+ jdk11_workaround(false),
734
+ quic_use_legacy_codepoint(true) {
736
735
  assert(ssl);
737
736
  }
738
737
 
@@ -1469,6 +1468,13 @@ const char *SSL_error_description(int err) {
1469
1468
  }
1470
1469
  }
1471
1470
 
1471
+ void SSL_set_enable_ech_grease(SSL *ssl, int enable) {
1472
+ if (!ssl->config) {
1473
+ return;
1474
+ }
1475
+ ssl->config->ech_grease_enabled = !!enable;
1476
+ }
1477
+
1472
1478
  uint32_t SSL_CTX_set_options(SSL_CTX *ctx, uint32_t options) {
1473
1479
  ctx->options |= options;
1474
1480
  return ctx->options;
@@ -2929,22 +2935,15 @@ void SSL_CTX_set_false_start_allowed_without_alpn(SSL_CTX *ctx, int allowed) {
2929
2935
  ctx->false_start_allowed_without_alpn = !!allowed;
2930
2936
  }
2931
2937
 
2932
- int SSL_is_tls13_downgrade(const SSL *ssl) { return ssl->s3->tls13_downgrade; }
2938
+ int SSL_is_tls13_downgrade(const SSL *ssl) { return 0; }
2933
2939
 
2934
2940
  int SSL_used_hello_retry_request(const SSL *ssl) {
2935
2941
  return ssl->s3->used_hello_retry_request;
2936
2942
  }
2937
2943
 
2938
- void SSL_CTX_set_ignore_tls13_downgrade(SSL_CTX *ctx, int ignore) {
2939
- ctx->ignore_tls13_downgrade = !!ignore;
2940
- }
2944
+ void SSL_CTX_set_ignore_tls13_downgrade(SSL_CTX *ctx, int ignore) {}
2941
2945
 
2942
- void SSL_set_ignore_tls13_downgrade(SSL *ssl, int ignore) {
2943
- if (!ssl->config) {
2944
- return;
2945
- }
2946
- ssl->config->ignore_tls13_downgrade = !!ignore;
2947
- }
2946
+ void SSL_set_ignore_tls13_downgrade(SSL *ssl, int ignore) {}
2948
2947
 
2949
2948
  void SSL_set_shed_handshake_config(SSL *ssl, int enable) {
2950
2949
  if (!ssl->config) {
@@ -2960,6 +2959,13 @@ void SSL_set_jdk11_workaround(SSL *ssl, int enable) {
2960
2959
  ssl->config->jdk11_workaround = !!enable;
2961
2960
  }
2962
2961
 
2962
+ void SSL_set_quic_use_legacy_codepoint(SSL *ssl, int use_legacy) {
2963
+ if (!ssl->config) {
2964
+ return;
2965
+ }
2966
+ ssl->config->quic_use_legacy_codepoint = !!use_legacy;
2967
+ }
2968
+
2963
2969
  int SSL_clear(SSL *ssl) {
2964
2970
  if (!ssl->config) {
2965
2971
  return 0; // SSL_clear may not be used after shedding config.
@@ -202,9 +202,8 @@ UniquePtr<SSL_SESSION> SSL_SESSION_dup(SSL_SESSION *session, int dup_flags) {
202
202
  OPENSSL_memcpy(new_session->sid_ctx, session->sid_ctx, session->sid_ctx_length);
203
203
 
204
204
  // Copy the key material.
205
- new_session->master_key_length = session->master_key_length;
206
- OPENSSL_memcpy(new_session->master_key, session->master_key,
207
- session->master_key_length);
205
+ new_session->secret_length = session->secret_length;
206
+ OPENSSL_memcpy(new_session->secret, session->secret, session->secret_length);
208
207
  new_session->cipher = session->cipher;
209
208
 
210
209
  // Copy authentication state.
@@ -963,14 +962,14 @@ void SSL_SESSION_get0_ocsp_response(const SSL_SESSION *session,
963
962
 
964
963
  size_t SSL_SESSION_get_master_key(const SSL_SESSION *session, uint8_t *out,
965
964
  size_t max_out) {
966
- // TODO(davidben): Fix master_key_length's type and remove these casts.
965
+ // TODO(davidben): Fix secret_length's type and remove these casts.
967
966
  if (max_out == 0) {
968
- return (size_t)session->master_key_length;
967
+ return (size_t)session->secret_length;
969
968
  }
970
- if (max_out > (size_t)session->master_key_length) {
971
- max_out = (size_t)session->master_key_length;
969
+ if (max_out > (size_t)session->secret_length) {
970
+ max_out = (size_t)session->secret_length;
972
971
  }
973
- OPENSSL_memcpy(out, session->master_key, max_out);
972
+ OPENSSL_memcpy(out, session->secret, max_out);
974
973
  return max_out;
975
974
  }
976
975
 
@@ -265,8 +265,8 @@ bool SSLTranscript::GetFinishedMAC(uint8_t *out, size_t *out_len,
265
265
 
266
266
  static const size_t kFinishedLen = 12;
267
267
  if (!tls1_prf(Digest(), MakeSpan(out, kFinishedLen),
268
- MakeConstSpan(session->master_key, session->master_key_length),
269
- label, MakeConstSpan(digest, digest_len), {})) {
268
+ MakeConstSpan(session->secret, session->secret_length), label,
269
+ MakeConstSpan(digest, digest_len), {})) {
270
270
  return false;
271
271
  }
272
272
 
@@ -191,15 +191,14 @@ static bool get_key_block_lengths(const SSL *ssl, size_t *out_mac_secret_len,
191
191
 
192
192
  static bool generate_key_block(const SSL *ssl, Span<uint8_t> out,
193
193
  const SSL_SESSION *session) {
194
- auto master_key =
195
- MakeConstSpan(session->master_key, session->master_key_length);
194
+ auto secret = MakeConstSpan(session->secret, session->secret_length);
196
195
  static const char kLabel[] = "key expansion";
197
196
  auto label = MakeConstSpan(kLabel, sizeof(kLabel) - 1);
198
197
 
199
198
  const EVP_MD *digest = ssl_session_get_digest(session);
200
199
  // Note this function assumes that |session|'s key material corresponds to
201
200
  // |ssl->s3->client_random| and |ssl->s3->server_random|.
202
- return tls1_prf(digest, out, master_key, label, ssl->s3->server_random,
201
+ return tls1_prf(digest, out, secret, label, ssl->s3->server_random,
203
202
  ssl->s3->client_random);
204
203
  }
205
204
 
@@ -379,8 +378,7 @@ int SSL_export_keying_material(SSL *ssl, uint8_t *out, size_t out_len,
379
378
 
380
379
  const SSL_SESSION *session = SSL_get_session(ssl);
381
380
  const EVP_MD *digest = ssl_session_get_digest(session);
382
- return tls1_prf(
383
- digest, MakeSpan(out, out_len),
384
- MakeConstSpan(session->master_key, session->master_key_length),
385
- MakeConstSpan(label, label_len), seed, {});
381
+ return tls1_prf(digest, MakeSpan(out, out_len),
382
+ MakeConstSpan(session->secret, session->secret_length),
383
+ MakeConstSpan(label, label_len), seed, {});
386
384
  }
@@ -113,10 +113,13 @@
113
113
  #include <stdlib.h>
114
114
  #include <string.h>
115
115
 
116
+ #include <algorithm>
116
117
  #include <utility>
117
118
 
119
+ #include <openssl/aead.h>
118
120
  #include <openssl/bytestring.h>
119
121
  #include <openssl/chacha.h>
122
+ #include <openssl/curve25519.h>
120
123
  #include <openssl/digest.h>
121
124
  #include <openssl/err.h>
122
125
  #include <openssl/evp.h>
@@ -125,6 +128,7 @@
125
128
  #include <openssl/nid.h>
126
129
  #include <openssl/rand.h>
127
130
 
131
+ #include "../crypto/hpke/internal.h"
128
132
  #include "../crypto/internal.h"
129
133
  #include "internal.h"
130
134
 
@@ -587,6 +591,182 @@ static bool ext_sni_add_serverhello(SSL_HANDSHAKE *hs, CBB *out) {
587
591
  }
588
592
 
589
593
 
594
+ // Encrypted Client Hello (ECH)
595
+ //
596
+ // https://tools.ietf.org/html/draft-ietf-tls-esni-09
597
+
598
+ // random_size returns a random value between |min| and |max|, inclusive.
599
+ static size_t random_size(size_t min, size_t max) {
600
+ assert(min < max);
601
+ size_t value;
602
+ RAND_bytes(reinterpret_cast<uint8_t *>(&value), sizeof(value));
603
+ return value % (max - min + 1) + min;
604
+ }
605
+
606
+ static bool ext_ech_add_clienthello_grease(SSL_HANDSHAKE *hs, CBB *out) {
607
+ // If we are responding to the server's HelloRetryRequest, we repeat the bytes
608
+ // of the first ECH GREASE extension.
609
+ if (hs->ssl->s3->used_hello_retry_request) {
610
+ CBB ech_body;
611
+ if (!CBB_add_u16(out, TLSEXT_TYPE_encrypted_client_hello) ||
612
+ !CBB_add_u16_length_prefixed(out, &ech_body) ||
613
+ !CBB_add_bytes(&ech_body, hs->ech_grease.data(),
614
+ hs->ech_grease.size()) ||
615
+ !CBB_flush(out)) {
616
+ return false;
617
+ }
618
+ return true;
619
+ }
620
+
621
+ constexpr uint16_t kdf_id = EVP_HPKE_HKDF_SHA256;
622
+ const uint16_t aead_id = EVP_has_aes_hardware()
623
+ ? EVP_HPKE_AEAD_AES_GCM_128
624
+ : EVP_HPKE_AEAD_CHACHA20POLY1305;
625
+ const EVP_AEAD *aead = EVP_HPKE_get_aead(aead_id);
626
+ assert(aead != nullptr);
627
+
628
+ uint8_t ech_config_id[8];
629
+ RAND_bytes(ech_config_id, sizeof(ech_config_id));
630
+
631
+ uint8_t ech_enc[X25519_PUBLIC_VALUE_LEN];
632
+ uint8_t private_key_unused[X25519_PRIVATE_KEY_LEN];
633
+ X25519_keypair(ech_enc, private_key_unused);
634
+
635
+ // To determine a plausible length for the payload, we first estimate the size
636
+ // of a typical EncodedClientHelloInner, with an expected use of
637
+ // outer_extensions. To limit the size, we only consider initial ClientHellos
638
+ // that do not offer resumption.
639
+ //
640
+ // Field/Extension Size
641
+ // ---------------------------------------------------------------------
642
+ // version 2
643
+ // random 32
644
+ // legacy_session_id 1
645
+ // - Has a U8 length prefix, but body is
646
+ // always empty string in inner CH.
647
+ // cipher_suites 2 (length prefix)
648
+ // - Only includes TLS 1.3 ciphers (3). 6
649
+ // - Maybe also include a GREASE suite. 2
650
+ // legacy_compression_methods 2 (length prefix)
651
+ // - Always has "null" compression method. 1
652
+ // extensions: 2 (length prefix)
653
+ // - encrypted_client_hello (empty). 4 (id + length prefix)
654
+ // - supported_versions. 4 (id + length prefix)
655
+ // - U8 length prefix 1
656
+ // - U16 protocol version (TLS 1.3) 2
657
+ // - outer_extensions. 4 (id + length prefix)
658
+ // - U8 length prefix 1
659
+ // - N extension IDs (2 bytes each):
660
+ // - key_share 2
661
+ // - sigalgs 2
662
+ // - sct 2
663
+ // - alpn 2
664
+ // - supported_groups. 2
665
+ // - status_request. 2
666
+ // - psk_key_exchange_modes. 2
667
+ // - compress_certificate. 2
668
+ //
669
+ // The server_name extension has an overhead of 9 bytes, plus up to an
670
+ // estimated 100 bytes of hostname. Rounding up to a multiple of 32 yields a
671
+ // range of 96 to 192. Note that this estimate does not fully capture
672
+ // optional extensions like GREASE, but the rounding gives some leeway.
673
+
674
+ uint8_t payload[EVP_AEAD_MAX_OVERHEAD + 192];
675
+ const size_t payload_len =
676
+ EVP_AEAD_max_overhead(aead) + 32 * random_size(96 / 32, 192 / 32);
677
+ assert(payload_len <= sizeof(payload));
678
+ RAND_bytes(payload, payload_len);
679
+
680
+ // Inside the TLS extension contents, write a serialized ClientEncryptedCH.
681
+ CBB ech_body, config_id_cbb, enc_cbb, payload_cbb;
682
+ if (!CBB_add_u16(out, TLSEXT_TYPE_encrypted_client_hello) ||
683
+ !CBB_add_u16_length_prefixed(out, &ech_body) ||
684
+ !CBB_add_u16(&ech_body, kdf_id) || //
685
+ !CBB_add_u16(&ech_body, aead_id) ||
686
+ !CBB_add_u8_length_prefixed(&ech_body, &config_id_cbb) ||
687
+ !CBB_add_bytes(&config_id_cbb, ech_config_id, sizeof(ech_config_id)) ||
688
+ !CBB_add_u16_length_prefixed(&ech_body, &enc_cbb) ||
689
+ !CBB_add_bytes(&enc_cbb, ech_enc, OPENSSL_ARRAY_SIZE(ech_enc)) ||
690
+ !CBB_add_u16_length_prefixed(&ech_body, &payload_cbb) ||
691
+ !CBB_add_bytes(&payload_cbb, payload, payload_len) || //
692
+ !CBB_flush(&ech_body)) {
693
+ return false;
694
+ }
695
+ // Save the bytes of the newly-generated extension in case the server sends
696
+ // a HelloRetryRequest.
697
+ if (!hs->ech_grease.CopyFrom(
698
+ MakeConstSpan(CBB_data(&ech_body), CBB_len(&ech_body)))) {
699
+ return false;
700
+ }
701
+ return CBB_flush(out);
702
+ }
703
+
704
+ static bool ext_ech_add_clienthello(SSL_HANDSHAKE *hs, CBB *out) {
705
+ if (hs->max_version < TLS1_3_VERSION) {
706
+ return true;
707
+ }
708
+ if (hs->config->ech_grease_enabled) {
709
+ return ext_ech_add_clienthello_grease(hs, out);
710
+ }
711
+ // Nothing to do, since we don't yet implement the non-GREASE parts of ECH.
712
+ return true;
713
+ }
714
+
715
+ static bool ext_ech_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
716
+ CBS *contents) {
717
+ if (contents == NULL) {
718
+ return true;
719
+ }
720
+
721
+ // If the client only sent GREASE, we must check the extension syntactically.
722
+ CBS ech_configs;
723
+ if (!CBS_get_u16_length_prefixed(contents, &ech_configs) ||
724
+ CBS_len(&ech_configs) == 0 || //
725
+ CBS_len(contents) > 0) {
726
+ *out_alert = SSL_AD_DECODE_ERROR;
727
+ return false;
728
+ }
729
+ while (CBS_len(&ech_configs) > 0) {
730
+ // Do a top-level parse of the ECHConfig, stopping before ECHConfigContents.
731
+ uint16_t version;
732
+ CBS ech_config_contents;
733
+ if (!CBS_get_u16(&ech_configs, &version) ||
734
+ !CBS_get_u16_length_prefixed(&ech_configs, &ech_config_contents)) {
735
+ *out_alert = SSL_AD_DECODE_ERROR;
736
+ return false;
737
+ }
738
+ }
739
+ return true;
740
+ }
741
+
742
+ static bool ext_ech_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
743
+ CBS *contents) {
744
+ if (contents != nullptr) {
745
+ hs->ech_present = true;
746
+ return true;
747
+ }
748
+ return true;
749
+ }
750
+
751
+ static bool ext_ech_is_inner_add_clienthello(SSL_HANDSHAKE *hs, CBB *out) {
752
+ return true;
753
+ }
754
+
755
+ static bool ext_ech_is_inner_parse_clienthello(SSL_HANDSHAKE *hs,
756
+ uint8_t *out_alert,
757
+ CBS *contents) {
758
+ if (contents == nullptr) {
759
+ return true;
760
+ }
761
+ if (CBS_len(contents) > 0) {
762
+ *out_alert = SSL_AD_ILLEGAL_PARAMETER;
763
+ return false;
764
+ }
765
+ hs->ech_is_inner_present = true;
766
+ return true;
767
+ }
768
+
769
+
590
770
  // Renegotiation indication.
591
771
  //
592
772
  // https://tools.ietf.org/html/rfc5746
@@ -2000,14 +2180,17 @@ static bool ext_early_data_add_clienthello(SSL_HANDSHAKE *hs, CBB *out) {
2000
2180
  return true;
2001
2181
  }
2002
2182
 
2003
- Span<const uint8_t> settings;
2004
- bool has_alps = ssl_get_local_application_settings(
2005
- hs, &settings, ssl->session->early_alpn);
2006
- if (has_alps != ssl->session->has_application_settings ||
2007
- settings != ssl->session->local_application_settings) {
2008
- // 0-RTT carries ALPS over, so we only offer it when the value matches.
2009
- ssl->s3->early_data_reason = ssl_early_data_alps_mismatch;
2010
- return true;
2183
+ // If the previous connection negotiated ALPS, only offer 0-RTT when the
2184
+ // local are settings are consistent with what we'd offer for this
2185
+ // connection.
2186
+ if (ssl->session->has_application_settings) {
2187
+ Span<const uint8_t> settings;
2188
+ if (!ssl_get_local_application_settings(hs, &settings,
2189
+ ssl->session->early_alpn) ||
2190
+ settings != ssl->session->local_application_settings) {
2191
+ ssl->s3->early_data_reason = ssl_early_data_alps_mismatch;
2192
+ return true;
2193
+ }
2011
2194
  }
2012
2195
  }
2013
2196
 
@@ -2282,7 +2465,8 @@ bool ssl_ext_key_share_parse_clienthello(SSL_HANDSHAKE *hs, bool *out_found,
2282
2465
  return true;
2283
2466
  }
2284
2467
 
2285
- bool ssl_ext_key_share_add_serverhello(SSL_HANDSHAKE *hs, CBB *out) {
2468
+ bool ssl_ext_key_share_add_serverhello(SSL_HANDSHAKE *hs, CBB *out,
2469
+ bool dry_run) {
2286
2470
  uint16_t group_id;
2287
2471
  CBB kse_bytes, public_key;
2288
2472
  if (!tls1_get_shared_group(hs, &group_id) ||
@@ -2295,10 +2479,10 @@ bool ssl_ext_key_share_add_serverhello(SSL_HANDSHAKE *hs, CBB *out) {
2295
2479
  !CBB_flush(out)) {
2296
2480
  return false;
2297
2481
  }
2298
-
2299
- hs->ecdh_public_key.Reset();
2300
-
2301
- hs->new_session->group_id = group_id;
2482
+ if (!dry_run) {
2483
+ hs->ecdh_public_key.Reset();
2484
+ hs->new_session->group_id = group_id;
2485
+ }
2302
2486
  return true;
2303
2487
  }
2304
2488
 
@@ -2592,8 +2776,8 @@ static bool ext_token_binding_add_serverhello(SSL_HANDSHAKE *hs, CBB *out) {
2592
2776
 
2593
2777
  // QUIC Transport Parameters
2594
2778
 
2595
- static bool ext_quic_transport_params_add_clienthello(SSL_HANDSHAKE *hs,
2596
- CBB *out) {
2779
+ static bool ext_quic_transport_params_add_clienthello_impl(
2780
+ SSL_HANDSHAKE *hs, CBB *out, bool use_legacy_codepoint) {
2597
2781
  if (hs->config->quic_transport_params.empty() && !hs->ssl->quic_method) {
2598
2782
  return true;
2599
2783
  }
@@ -2605,9 +2789,18 @@ static bool ext_quic_transport_params_add_clienthello(SSL_HANDSHAKE *hs,
2605
2789
  return false;
2606
2790
  }
2607
2791
  assert(hs->min_version > TLS1_2_VERSION);
2792
+ if (use_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
2793
+ // Do nothing, we'll send the other codepoint.
2794
+ return true;
2795
+ }
2796
+
2797
+ uint16_t extension_type = TLSEXT_TYPE_quic_transport_parameters_standard;
2798
+ if (hs->config->quic_use_legacy_codepoint) {
2799
+ extension_type = TLSEXT_TYPE_quic_transport_parameters_legacy;
2800
+ }
2608
2801
 
2609
2802
  CBB contents;
2610
- if (!CBB_add_u16(out, TLSEXT_TYPE_quic_transport_parameters) ||
2803
+ if (!CBB_add_u16(out, extension_type) ||
2611
2804
  !CBB_add_u16_length_prefixed(out, &contents) ||
2612
2805
  !CBB_add_bytes(&contents, hs->config->quic_transport_params.data(),
2613
2806
  hs->config->quic_transport_params.size()) ||
@@ -2617,31 +2810,57 @@ static bool ext_quic_transport_params_add_clienthello(SSL_HANDSHAKE *hs,
2617
2810
  return true;
2618
2811
  }
2619
2812
 
2620
- static bool ext_quic_transport_params_parse_serverhello(SSL_HANDSHAKE *hs,
2621
- uint8_t *out_alert,
2622
- CBS *contents) {
2813
+ static bool ext_quic_transport_params_add_clienthello(SSL_HANDSHAKE *hs,
2814
+ CBB *out) {
2815
+ return ext_quic_transport_params_add_clienthello_impl(
2816
+ hs, out, /*use_legacy_codepoint=*/false);
2817
+ }
2818
+
2819
+ static bool ext_quic_transport_params_add_clienthello_legacy(SSL_HANDSHAKE *hs,
2820
+ CBB *out) {
2821
+ return ext_quic_transport_params_add_clienthello_impl(
2822
+ hs, out, /*use_legacy_codepoint=*/true);
2823
+ }
2824
+
2825
+ static bool ext_quic_transport_params_parse_serverhello_impl(
2826
+ SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents,
2827
+ bool used_legacy_codepoint) {
2623
2828
  SSL *const ssl = hs->ssl;
2624
2829
  if (contents == nullptr) {
2830
+ if (used_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
2831
+ // Silently ignore because we expect the other QUIC codepoint.
2832
+ return true;
2833
+ }
2625
2834
  if (!ssl->quic_method) {
2626
2835
  return true;
2627
2836
  }
2628
- assert(ssl->quic_method);
2629
2837
  *out_alert = SSL_AD_MISSING_EXTENSION;
2630
2838
  return false;
2631
2839
  }
2632
- if (!ssl->quic_method) {
2633
- *out_alert = SSL_AD_UNSUPPORTED_EXTENSION;
2634
- return false;
2635
- }
2636
- // QUIC requires TLS 1.3.
2840
+ // The extensions parser will check for unsolicited extensions before
2841
+ // calling the callback.
2842
+ assert(ssl->quic_method != nullptr);
2637
2843
  assert(ssl_protocol_version(ssl) == TLS1_3_VERSION);
2638
-
2844
+ assert(used_legacy_codepoint == hs->config->quic_use_legacy_codepoint);
2639
2845
  return ssl->s3->peer_quic_transport_params.CopyFrom(*contents);
2640
2846
  }
2641
2847
 
2642
- static bool ext_quic_transport_params_parse_clienthello(SSL_HANDSHAKE *hs,
2848
+ static bool ext_quic_transport_params_parse_serverhello(SSL_HANDSHAKE *hs,
2643
2849
  uint8_t *out_alert,
2644
2850
  CBS *contents) {
2851
+ return ext_quic_transport_params_parse_serverhello_impl(
2852
+ hs, out_alert, contents, /*used_legacy_codepoint=*/false);
2853
+ }
2854
+
2855
+ static bool ext_quic_transport_params_parse_serverhello_legacy(
2856
+ SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents) {
2857
+ return ext_quic_transport_params_parse_serverhello_impl(
2858
+ hs, out_alert, contents, /*used_legacy_codepoint=*/true);
2859
+ }
2860
+
2861
+ static bool ext_quic_transport_params_parse_clienthello_impl(
2862
+ SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents,
2863
+ bool used_legacy_codepoint) {
2645
2864
  SSL *const ssl = hs->ssl;
2646
2865
  if (!contents) {
2647
2866
  if (!ssl->quic_method) {
@@ -2652,29 +2871,72 @@ static bool ext_quic_transport_params_parse_clienthello(SSL_HANDSHAKE *hs,
2652
2871
  // for QUIC.
2653
2872
  OPENSSL_PUT_ERROR(SSL, SSL_R_QUIC_TRANSPORT_PARAMETERS_MISCONFIGURED);
2654
2873
  *out_alert = SSL_AD_INTERNAL_ERROR;
2874
+ return false;
2875
+ }
2876
+ if (used_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
2877
+ // Silently ignore because we expect the other QUIC codepoint.
2878
+ return true;
2655
2879
  }
2656
2880
  *out_alert = SSL_AD_MISSING_EXTENSION;
2657
2881
  return false;
2658
2882
  }
2659
2883
  if (!ssl->quic_method) {
2884
+ if (used_legacy_codepoint) {
2885
+ // Ignore the legacy private-use codepoint because that could be sent
2886
+ // to mean something else than QUIC transport parameters.
2887
+ return true;
2888
+ }
2889
+ // Fail if we received the codepoint registered with IANA for QUIC
2890
+ // because that is not allowed outside of QUIC.
2660
2891
  *out_alert = SSL_AD_UNSUPPORTED_EXTENSION;
2661
2892
  return false;
2662
2893
  }
2663
2894
  assert(ssl_protocol_version(ssl) == TLS1_3_VERSION);
2895
+ if (used_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
2896
+ // Silently ignore because we expect the other QUIC codepoint.
2897
+ return true;
2898
+ }
2664
2899
  return ssl->s3->peer_quic_transport_params.CopyFrom(*contents);
2665
2900
  }
2666
2901
 
2667
- static bool ext_quic_transport_params_add_serverhello(SSL_HANDSHAKE *hs,
2668
- CBB *out) {
2902
+ static bool ext_quic_transport_params_parse_clienthello(SSL_HANDSHAKE *hs,
2903
+ uint8_t *out_alert,
2904
+ CBS *contents) {
2905
+ return ext_quic_transport_params_parse_clienthello_impl(
2906
+ hs, out_alert, contents, /*used_legacy_codepoint=*/false);
2907
+ }
2908
+
2909
+ static bool ext_quic_transport_params_parse_clienthello_legacy(
2910
+ SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents) {
2911
+ return ext_quic_transport_params_parse_clienthello_impl(
2912
+ hs, out_alert, contents, /*used_legacy_codepoint=*/true);
2913
+ }
2914
+
2915
+ static bool ext_quic_transport_params_add_serverhello_impl(
2916
+ SSL_HANDSHAKE *hs, CBB *out, bool use_legacy_codepoint) {
2917
+ if (hs->ssl->quic_method == nullptr && use_legacy_codepoint) {
2918
+ // Ignore the legacy private-use codepoint because that could be sent
2919
+ // to mean something else than QUIC transport parameters.
2920
+ return true;
2921
+ }
2669
2922
  assert(hs->ssl->quic_method != nullptr);
2670
2923
  if (hs->config->quic_transport_params.empty()) {
2671
2924
  // Transport parameters must be set when using QUIC.
2672
2925
  OPENSSL_PUT_ERROR(SSL, SSL_R_QUIC_TRANSPORT_PARAMETERS_MISCONFIGURED);
2673
2926
  return false;
2674
2927
  }
2928
+ if (use_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
2929
+ // Do nothing, we'll send the other codepoint.
2930
+ return true;
2931
+ }
2932
+
2933
+ uint16_t extension_type = TLSEXT_TYPE_quic_transport_parameters_standard;
2934
+ if (hs->config->quic_use_legacy_codepoint) {
2935
+ extension_type = TLSEXT_TYPE_quic_transport_parameters_legacy;
2936
+ }
2675
2937
 
2676
2938
  CBB contents;
2677
- if (!CBB_add_u16(out, TLSEXT_TYPE_quic_transport_parameters) ||
2939
+ if (!CBB_add_u16(out, extension_type) ||
2678
2940
  !CBB_add_u16_length_prefixed(out, &contents) ||
2679
2941
  !CBB_add_bytes(&contents, hs->config->quic_transport_params.data(),
2680
2942
  hs->config->quic_transport_params.size()) ||
@@ -2685,6 +2947,18 @@ static bool ext_quic_transport_params_add_serverhello(SSL_HANDSHAKE *hs,
2685
2947
  return true;
2686
2948
  }
2687
2949
 
2950
+ static bool ext_quic_transport_params_add_serverhello(SSL_HANDSHAKE *hs,
2951
+ CBB *out) {
2952
+ return ext_quic_transport_params_add_serverhello_impl(
2953
+ hs, out, /*use_legacy_codepoint=*/false);
2954
+ }
2955
+
2956
+ static bool ext_quic_transport_params_add_serverhello_legacy(SSL_HANDSHAKE *hs,
2957
+ CBB *out) {
2958
+ return ext_quic_transport_params_add_serverhello_impl(
2959
+ hs, out, /*use_legacy_codepoint=*/true);
2960
+ }
2961
+
2688
2962
  // Delegated credentials.
2689
2963
  //
2690
2964
  // https://tools.ietf.org/html/draft-ietf-tls-subcerts
@@ -2970,6 +3244,22 @@ static const struct tls_extension kExtensions[] = {
2970
3244
  ext_sni_parse_clienthello,
2971
3245
  ext_sni_add_serverhello,
2972
3246
  },
3247
+ {
3248
+ TLSEXT_TYPE_encrypted_client_hello,
3249
+ NULL,
3250
+ ext_ech_add_clienthello,
3251
+ ext_ech_parse_serverhello,
3252
+ ext_ech_parse_clienthello,
3253
+ dont_add_serverhello,
3254
+ },
3255
+ {
3256
+ TLSEXT_TYPE_ech_is_inner,
3257
+ NULL,
3258
+ ext_ech_is_inner_add_clienthello,
3259
+ forbid_parse_serverhello,
3260
+ ext_ech_is_inner_parse_clienthello,
3261
+ dont_add_serverhello,
3262
+ },
2973
3263
  {
2974
3264
  TLSEXT_TYPE_extended_master_secret,
2975
3265
  NULL,
@@ -3109,13 +3399,21 @@ static const struct tls_extension kExtensions[] = {
3109
3399
  dont_add_serverhello,
3110
3400
  },
3111
3401
  {
3112
- TLSEXT_TYPE_quic_transport_parameters,
3402
+ TLSEXT_TYPE_quic_transport_parameters_standard,
3113
3403
  NULL,
3114
3404
  ext_quic_transport_params_add_clienthello,
3115
3405
  ext_quic_transport_params_parse_serverhello,
3116
3406
  ext_quic_transport_params_parse_clienthello,
3117
3407
  ext_quic_transport_params_add_serverhello,
3118
3408
  },
3409
+ {
3410
+ TLSEXT_TYPE_quic_transport_parameters_legacy,
3411
+ NULL,
3412
+ ext_quic_transport_params_add_clienthello_legacy,
3413
+ ext_quic_transport_params_parse_serverhello_legacy,
3414
+ ext_quic_transport_params_parse_clienthello_legacy,
3415
+ ext_quic_transport_params_add_serverhello_legacy,
3416
+ },
3119
3417
  {
3120
3418
  TLSEXT_TYPE_token_binding,
3121
3419
  NULL,