extensions.cc
Go to the documentation of this file.
1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young (eay@cryptsoft.com).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to. The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  * notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  * notice, this list of conditions and the following disclaimer in the
29  * documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  * must display the following acknowledgement:
32  * "This product includes cryptographic software written by
33  * Eric Young (eay@cryptsoft.com)"
34  * The word 'cryptographic' can be left out if the rouines from the library
35  * being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  * the apps directory (application code) you must include an acknowledgement:
38  * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed. i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.]
56  */
57 /* ====================================================================
58  * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
59  *
60  * Redistribution and use in source and binary forms, with or without
61  * modification, are permitted provided that the following conditions
62  * are met:
63  *
64  * 1. Redistributions of source code must retain the above copyright
65  * notice, this list of conditions and the following disclaimer.
66  *
67  * 2. Redistributions in binary form must reproduce the above copyright
68  * notice, this list of conditions and the following disclaimer in
69  * the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3. All advertising materials mentioning features or use of this
73  * software must display the following acknowledgment:
74  * "This product includes software developed by the OpenSSL Project
75  * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
76  *
77  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
78  * endorse or promote products derived from this software without
79  * prior written permission. For written permission, please contact
80  * openssl-core@openssl.org.
81  *
82  * 5. Products derived from this software may not be called "OpenSSL"
83  * nor may "OpenSSL" appear in their names without prior written
84  * permission of the OpenSSL Project.
85  *
86  * 6. Redistributions of any form whatsoever must retain the following
87  * acknowledgment:
88  * "This product includes software developed by the OpenSSL Project
89  * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
90  *
91  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
92  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
93  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
94  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
95  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
96  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
97  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
98  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
99  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
100  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
101  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
102  * OF THE POSSIBILITY OF SUCH DAMAGE.
103  * ====================================================================
104  *
105  * This product includes cryptographic software written by Eric Young
106  * (eay@cryptsoft.com). This product includes software written by Tim
107  * Hudson (tjh@cryptsoft.com). */
108 
109 #include <openssl/ssl.h>
110 
111 #include <assert.h>
112 #include <limits.h>
113 #include <stdlib.h>
114 #include <string.h>
115 
116 #include <algorithm>
117 #include <utility>
118 
119 #include <openssl/aead.h>
120 #include <openssl/bytestring.h>
121 #include <openssl/chacha.h>
122 #include <openssl/curve25519.h>
123 #include <openssl/digest.h>
124 #include <openssl/err.h>
125 #include <openssl/evp.h>
126 #include <openssl/hmac.h>
127 #include <openssl/hpke.h>
128 #include <openssl/mem.h>
129 #include <openssl/nid.h>
130 #include <openssl/rand.h>
131 
132 #include "../crypto/internal.h"
133 #include "internal.h"
134 
135 
137 
140 
141 static int compare_uint16_t(const void *p1, const void *p2) {
142  uint16_t u1 = *((const uint16_t *)p1);
143  uint16_t u2 = *((const uint16_t *)p2);
144  if (u1 < u2) {
145  return -1;
146  } else if (u1 > u2) {
147  return 1;
148  } else {
149  return 0;
150  }
151 }
152 
153 // Per http://tools.ietf.org/html/rfc5246#section-7.4.1.4, there may not be
154 // more than one extension of the same type in a ClientHello or ServerHello.
155 // This function does an initial scan over the extensions block to filter those
156 // out.
158  // First pass: count the extensions.
159  size_t num_extensions = 0;
160  CBS extensions = *cbs;
161  while (CBS_len(&extensions) > 0) {
162  uint16_t type;
163  CBS extension;
164 
165  if (!CBS_get_u16(&extensions, &type) ||
167  return false;
168  }
169 
170  num_extensions++;
171  }
172 
173  if (num_extensions == 0) {
174  return true;
175  }
176 
177  Array<uint16_t> extension_types;
178  if (!extension_types.Init(num_extensions)) {
179  return false;
180  }
181 
182  // Second pass: gather the extension types.
183  extensions = *cbs;
184  for (size_t i = 0; i < extension_types.size(); i++) {
185  CBS extension;
186 
187  if (!CBS_get_u16(&extensions, &extension_types[i]) ||
189  // This should not happen.
190  return false;
191  }
192  }
193  assert(CBS_len(&extensions) == 0);
194 
195  // Sort the extensions and make sure there are no duplicates.
196  qsort(extension_types.data(), extension_types.size(), sizeof(uint16_t),
198  for (size_t i = 1; i < num_extensions; i++) {
199  if (extension_types[i - 1] == extension_types[i]) {
200  return false;
201  }
202  }
203 
204  return true;
205 }
206 
208  return id == SSL_CURVE_CECPQ2;
209 }
210 
212  Span<const uint8_t> body) {
213  CBS cbs = body;
215  CBS_len(&cbs) != 0) {
216  return false;
217  }
218  return true;
219 }
220 
223  OPENSSL_memset(out, 0, sizeof(*out));
224  out->ssl = const_cast<SSL *>(ssl);
225 
226  CBS copy = *cbs;
227  CBS random, session_id;
228  if (!CBS_get_u16(cbs, &out->version) ||
229  !CBS_get_bytes(cbs, &random, SSL3_RANDOM_SIZE) ||
230  !CBS_get_u8_length_prefixed(cbs, &session_id) ||
231  CBS_len(&session_id) > SSL_MAX_SSL_SESSION_ID_LENGTH) {
232  return false;
233  }
234 
235  out->random = CBS_data(&random);
236  out->random_len = CBS_len(&random);
237  out->session_id = CBS_data(&session_id);
238  out->session_id_len = CBS_len(&session_id);
239 
240  // Skip past DTLS cookie
241  if (SSL_is_dtls(out->ssl)) {
242  CBS cookie;
243  if (!CBS_get_u8_length_prefixed(cbs, &cookie) ||
244  CBS_len(&cookie) > DTLS1_COOKIE_LENGTH) {
245  return false;
246  }
247  }
248 
249  CBS cipher_suites, compression_methods;
251  CBS_len(&cipher_suites) < 2 || (CBS_len(&cipher_suites) & 1) != 0 ||
252  !CBS_get_u8_length_prefixed(cbs, &compression_methods) ||
253  CBS_len(&compression_methods) < 1) {
254  return false;
255  }
256 
257  out->cipher_suites = CBS_data(&cipher_suites);
258  out->cipher_suites_len = CBS_len(&cipher_suites);
259  out->compression_methods = CBS_data(&compression_methods);
260  out->compression_methods_len = CBS_len(&compression_methods);
261 
262  // If the ClientHello ends here then it's valid, but doesn't have any
263  // extensions.
264  if (CBS_len(cbs) == 0) {
265  out->extensions = nullptr;
266  out->extensions_len = 0;
267  } else {
268  // Extract extensions and check it is valid.
269  CBS extensions;
272  return false;
273  }
274  out->extensions = CBS_data(&extensions);
275  out->extensions_len = CBS_len(&extensions);
276  }
277 
278  out->client_hello = CBS_data(&copy);
279  out->client_hello_len = CBS_len(&copy) - CBS_len(cbs);
280  return true;
281 }
282 
284  CBS *out, uint16_t extension_type) {
285  CBS extensions;
286  CBS_init(&extensions, client_hello->extensions, client_hello->extensions_len);
287  while (CBS_len(&extensions) != 0) {
288  // Decode the next extension.
289  uint16_t type;
290  CBS extension;
291  if (!CBS_get_u16(&extensions, &type) ||
293  return false;
294  }
295 
296  if (type == extension_type) {
297  *out = extension;
298  return true;
299  }
300  }
301 
302  return false;
303 }
304 
305 static const uint16_t kDefaultGroups[] = {
309 };
310 
312  if (!hs->config->supported_group_list.empty()) {
313  return hs->config->supported_group_list;
314  }
316 }
317 
318 bool tls1_get_shared_group(SSL_HANDSHAKE *hs, uint16_t *out_group_id) {
319  SSL *const ssl = hs->ssl;
320  assert(ssl->server);
321 
322  // Clients are not required to send a supported_groups extension. In this
323  // case, the server is free to pick any group it likes. See RFC 4492,
324  // section 4, paragraph 3.
325  //
326  // However, in the interests of compatibility, we will skip ECDH if the
327  // client didn't send an extension because we can't be sure that they'll
328  // support our favoured group. Thus we do not special-case an emtpy
329  // |peer_supported_group_list|.
330 
332  Span<const uint16_t> pref, supp;
334  pref = groups;
335  supp = hs->peer_supported_group_list;
336  } else {
337  pref = hs->peer_supported_group_list;
338  supp = groups;
339  }
340 
341  for (uint16_t pref_group : pref) {
342  for (uint16_t supp_group : supp) {
343  if (pref_group == supp_group &&
344  // CECPQ2(b) doesn't fit in the u8-length-prefixed ECPoint field in
345  // TLS 1.2 and below.
347  !is_post_quantum_group(pref_group))) {
348  *out_group_id = pref_group;
349  return true;
350  }
351  }
352  }
353 
354  return false;
355 }
356 
357 bool tls1_set_curves(Array<uint16_t> *out_group_ids, Span<const int> curves) {
358  Array<uint16_t> group_ids;
359  if (!group_ids.Init(curves.size())) {
360  return false;
361  }
362 
363  for (size_t i = 0; i < curves.size(); i++) {
364  if (!ssl_nid_to_group_id(&group_ids[i], curves[i])) {
365  return false;
366  }
367  }
368 
369  *out_group_ids = std::move(group_ids);
370  return true;
371 }
372 
373 bool tls1_set_curves_list(Array<uint16_t> *out_group_ids, const char *curves) {
374  // Count the number of curves in the list.
375  size_t count = 0;
376  const char *ptr = curves, *col;
377  do {
378  col = strchr(ptr, ':');
379  count++;
380  if (col) {
381  ptr = col + 1;
382  }
383  } while (col);
384 
385  Array<uint16_t> group_ids;
386  if (!group_ids.Init(count)) {
387  return false;
388  }
389 
390  size_t i = 0;
391  ptr = curves;
392  do {
393  col = strchr(ptr, ':');
394  if (!ssl_name_to_group_id(&group_ids[i++], ptr,
395  col ? (size_t)(col - ptr) : strlen(ptr))) {
396  return false;
397  }
398  if (col) {
399  ptr = col + 1;
400  }
401  } while (col);
402 
403  assert(i == count);
404  *out_group_ids = std::move(group_ids);
405  return true;
406 }
407 
408 bool tls1_check_group_id(const SSL_HANDSHAKE *hs, uint16_t group_id) {
409  if (is_post_quantum_group(group_id) &&
411  // CECPQ2(b) requires TLS 1.3.
412  return false;
413  }
414 
415  // We internally assume zero is never allocated as a group ID.
416  if (group_id == 0) {
417  return false;
418  }
419 
420  for (uint16_t supported : tls1_get_grouplist(hs)) {
421  if (supported == group_id) {
422  return true;
423  }
424  }
425 
426  return false;
427 }
428 
429 // kVerifySignatureAlgorithms is the default list of accepted signature
430 // algorithms for verifying.
432  // List our preferred algorithms first.
436 
437  // Larger hashes are acceptable.
441 
444 
445  // For now, SHA-1 is still accepted but least preferable.
447 };
448 
449 // kSignSignatureAlgorithms is the default list of supported signature
450 // algorithms for signing.
452  // List our preferred algorithms first.
457 
458  // If needed, sign larger hashes.
459  //
460  // TODO(davidben): Determine which of these may be pruned.
464 
468 
469  // If the peer supports nothing else, sign with SHA-1.
472 };
473 
475  if (hs->config->verify_sigalgs.empty()) {
477  }
478  return hs->config->verify_sigalgs;
479 }
480 
482  for (uint16_t sigalg : tls12_get_verify_sigalgs(hs)) {
483  if (!CBB_add_u16(out, sigalg)) {
484  return false;
485  }
486  }
487  return true;
488 }
489 
490 bool tls12_check_peer_sigalg(const SSL_HANDSHAKE *hs, uint8_t *out_alert,
491  uint16_t sigalg) {
492  for (uint16_t verify_sigalg : tls12_get_verify_sigalgs(hs)) {
493  if (verify_sigalg == sigalg) {
494  return true;
495  }
496  }
497 
499  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
500  return false;
501 }
502 
503 // tls_extension represents a TLS extension that is handled internally.
504 //
505 // The parse callbacks receive a |CBS| that contains the contents of the
506 // extension (i.e. not including the type and length bytes). If an extension is
507 // not received then the parse callbacks will be called with a NULL CBS so that
508 // they can do any processing needed to handle the absence of an extension.
509 //
510 // The add callbacks receive a |CBB| to which the extension can be appended but
511 // the function is responsible for appending the type and length bytes too.
512 //
513 // |add_clienthello| may be called multiple times and must not mutate |hs|. It
514 // is additionally passed two output |CBB|s. If the extension is the same
515 // independent of the value of |type|, the callback may write to
516 // |out_compressible| instead of |out|. When serializing the ClientHelloInner,
517 // all compressible extensions will be made continguous and replaced with
518 // ech_outer_extensions when encrypted. When serializing the ClientHelloOuter
519 // or not offering ECH, |out| will be equal to |out_compressible|, so writing to
520 // |out_compressible| still works.
521 //
522 // Note the |parse_serverhello| and |add_serverhello| callbacks refer to the
523 // TLS 1.2 ServerHello. In TLS 1.3, these callbacks act on EncryptedExtensions,
524 // with ServerHello extensions handled elsewhere in the handshake.
525 //
526 // All callbacks return true for success and false for error. If a parse
527 // function returns zero then a fatal alert with value |*out_alert| will be
528 // sent. If |*out_alert| isn't set, then a |decode_error| alert will be sent.
531 
533  CBB *out_compressible, ssl_client_hello_type_t type);
535  CBS *contents);
536 
538  CBS *contents);
540 };
541 
542 static bool forbid_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
543  CBS *contents) {
544  if (contents != NULL) {
545  // Servers MUST NOT send this extension.
546  *out_alert = SSL_AD_UNSUPPORTED_EXTENSION;
548  return false;
549  }
550 
551  return true;
552 }
553 
554 static bool ignore_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
555  CBS *contents) {
556  // This extension from the client is handled elsewhere.
557  return true;
558 }
559 
561  return true;
562 }
563 
564 // Server name indication (SNI).
565 //
566 // https://tools.ietf.org/html/rfc6066#section-3.
567 
569  CBB *out_compressible,
571  const SSL *const ssl = hs->ssl;
572  // If offering ECH, send the public name instead of the configured name.
573  Span<const uint8_t> hostname;
574  if (type == ssl_client_hello_outer) {
575  hostname = hs->selected_ech_config->public_name;
576  } else {
577  if (ssl->hostname == nullptr) {
578  return true;
579  }
580  hostname =
581  MakeConstSpan(reinterpret_cast<const uint8_t *>(ssl->hostname.get()),
582  strlen(ssl->hostname.get()));
583  }
584 
585  CBB contents, server_name_list, name;
588  !CBB_add_u16_length_prefixed(&contents, &server_name_list) ||
589  !CBB_add_u8(&server_name_list, TLSEXT_NAMETYPE_host_name) ||
590  !CBB_add_u16_length_prefixed(&server_name_list, &name) ||
591  !CBB_add_bytes(&name, hostname.data(), hostname.size()) ||
592  !CBB_flush(out)) {
593  return false;
594  }
595 
596  return true;
597 }
598 
599 static bool ext_sni_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
600  CBS *contents) {
601  // The server may acknowledge SNI with an empty extension. We check the syntax
602  // but otherwise ignore this signal.
603  return contents == NULL || CBS_len(contents) == 0;
604 }
605 
606 static bool ext_sni_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
607  CBS *contents) {
608  // SNI has already been parsed earlier in the handshake. See |extract_sni|.
609  return true;
610 }
611 
613  if (hs->ssl->s3->session_reused ||
614  !hs->should_ack_sni) {
615  return true;
616  }
617 
619  !CBB_add_u16(out, 0 /* length */)) {
620  return false;
621  }
622 
623  return true;
624 }
625 
626 
627 // Encrypted ClientHello (ECH)
628 //
629 // https://tools.ietf.org/html/draft-ietf-tls-esni-13
630 
632  CBB *out_compressible,
634  if (type == ssl_client_hello_inner) {
636  !CBB_add_u16(out, /* length */ 1) ||
638  return false;
639  }
640  return true;
641  }
642 
643  if (hs->ech_client_outer.empty()) {
644  return true;
645  }
646 
647  CBB ech_body;
649  !CBB_add_u16_length_prefixed(out, &ech_body) ||
650  !CBB_add_u8(&ech_body, ECH_CLIENT_OUTER) ||
651  !CBB_add_bytes(&ech_body, hs->ech_client_outer.data(),
652  hs->ech_client_outer.size()) ||
653  !CBB_flush(out)) {
654  return false;
655  }
656  return true;
657 }
658 
659 static bool ext_ech_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
660  CBS *contents) {
661  SSL *const ssl = hs->ssl;
662  if (contents == NULL) {
663  return true;
664  }
665 
666  // The ECH extension may not be sent in TLS 1.2 ServerHello, only TLS 1.3
667  // EncryptedExtensions. It also may not be sent in response to an inner ECH
668  // extension.
670  ssl->s3->ech_status == ssl_ech_accepted) {
671  *out_alert = SSL_AD_UNSUPPORTED_EXTENSION;
673  return false;
674  }
675 
677  *out_alert = SSL_AD_DECODE_ERROR;
678  return false;
679  }
680 
681  if (ssl->s3->ech_status == ssl_ech_rejected &&
683  *out_alert = SSL_AD_INTERNAL_ERROR;
684  return false;
685  }
686 
687  return true;
688 }
689 
690 static bool ext_ech_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
691  CBS *contents) {
692  if (contents == nullptr) {
693  return true;
694  }
695 
696  uint8_t type;
697  if (!CBS_get_u8(contents, &type)) {
698  return false;
699  }
700  if (type == ECH_CLIENT_OUTER) {
701  // Outer ECH extensions are handled outside the callback.
702  return true;
703  }
704  if (type != ECH_CLIENT_INNER || CBS_len(contents) != 0) {
705  return false;
706  }
707 
708  hs->ech_is_inner = true;
709  return true;
710 }
711 
713  SSL *const ssl = hs->ssl;
715  ssl->s3->ech_status == ssl_ech_accepted || //
716  hs->ech_keys == nullptr) {
717  return true;
718  }
719 
720  // Write the list of retry configs to |out|. Note |SSL_CTX_set1_ech_keys|
721  // ensures |ech_keys| contains at least one retry config.
722  CBB body, retry_configs;
724  !CBB_add_u16_length_prefixed(out, &body) ||
725  !CBB_add_u16_length_prefixed(&body, &retry_configs)) {
726  return false;
727  }
728  for (const auto &config : hs->ech_keys->configs) {
729  if (!config->is_retry_config()) {
730  continue;
731  }
732  if (!CBB_add_bytes(&retry_configs, config->ech_config().raw.data(),
733  config->ech_config().raw.size())) {
734  return false;
735  }
736  }
737  return CBB_flush(out);
738 }
739 
740 
741 // Renegotiation indication.
742 //
743 // https://tools.ietf.org/html/rfc5746
744 
745 static bool ext_ri_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out,
746  CBB *out_compressible,
748  const SSL *const ssl = hs->ssl;
749  // Renegotiation indication is not necessary in TLS 1.3.
750  if (hs->min_version >= TLS1_3_VERSION ||
752  return true;
753  }
754 
755  assert(ssl->s3->initial_handshake_complete ==
756  (ssl->s3->previous_client_finished_len != 0));
757 
758  CBB contents, prev_finished;
761  !CBB_add_u8_length_prefixed(&contents, &prev_finished) ||
762  !CBB_add_bytes(&prev_finished, ssl->s3->previous_client_finished,
763  ssl->s3->previous_client_finished_len) ||
764  !CBB_flush(out)) {
765  return false;
766  }
767 
768  return true;
769 }
770 
771 static bool ext_ri_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
772  CBS *contents) {
773  SSL *const ssl = hs->ssl;
774  if (contents != NULL && ssl_protocol_version(ssl) >= TLS1_3_VERSION) {
775  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
776  return false;
777  }
778 
779  // Servers may not switch between omitting the extension and supporting it.
780  // See RFC 5746, sections 3.5 and 4.2.
781  if (ssl->s3->initial_handshake_complete &&
782  (contents != NULL) != ssl->s3->send_connection_binding) {
783  *out_alert = SSL_AD_HANDSHAKE_FAILURE;
785  return false;
786  }
787 
788  if (contents == NULL) {
789  // Strictly speaking, if we want to avoid an attack we should *always* see
790  // RI even on initial ServerHello because the client doesn't see any
791  // renegotiation during an attack. However this would mean we could not
792  // connect to any server which doesn't support RI.
793  //
794  // OpenSSL has |SSL_OP_LEGACY_SERVER_CONNECT| to control this, but in
795  // practical terms every client sets it so it's just assumed here.
796  return true;
797  }
798 
799  const size_t expected_len = ssl->s3->previous_client_finished_len +
800  ssl->s3->previous_server_finished_len;
801 
802  // Check for logic errors
803  assert(!expected_len || ssl->s3->previous_client_finished_len);
804  assert(!expected_len || ssl->s3->previous_server_finished_len);
805  assert(ssl->s3->initial_handshake_complete ==
806  (ssl->s3->previous_client_finished_len != 0));
807  assert(ssl->s3->initial_handshake_complete ==
808  (ssl->s3->previous_server_finished_len != 0));
809 
810  // Parse out the extension contents.
811  CBS renegotiated_connection;
812  if (!CBS_get_u8_length_prefixed(contents, &renegotiated_connection) ||
813  CBS_len(contents) != 0) {
815  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
816  return false;
817  }
818 
819  // Check that the extension matches.
820  if (CBS_len(&renegotiated_connection) != expected_len) {
822  *out_alert = SSL_AD_HANDSHAKE_FAILURE;
823  return false;
824  }
825 
826  const uint8_t *d = CBS_data(&renegotiated_connection);
827  bool ok = CRYPTO_memcmp(d, ssl->s3->previous_client_finished,
828  ssl->s3->previous_client_finished_len) == 0;
829 #if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
830  ok = true;
831 #endif
832  if (!ok) {
834  *out_alert = SSL_AD_HANDSHAKE_FAILURE;
835  return false;
836  }
837  d += ssl->s3->previous_client_finished_len;
838 
839  ok = CRYPTO_memcmp(d, ssl->s3->previous_server_finished,
840  ssl->s3->previous_server_finished_len) == 0;
841 #if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
842  ok = true;
843 #endif
844  if (!ok) {
846  *out_alert = SSL_AD_HANDSHAKE_FAILURE;
847  return false;
848  }
849  ssl->s3->send_connection_binding = true;
850 
851  return true;
852 }
853 
854 static bool ext_ri_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
855  CBS *contents) {
856  SSL *const ssl = hs->ssl;
857  // Renegotiation isn't supported as a server so this function should never be
858  // called after the initial handshake.
859  assert(!ssl->s3->initial_handshake_complete);
860 
861  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION) {
862  return true;
863  }
864 
865  if (contents == NULL) {
866  return true;
867  }
868 
869  CBS renegotiated_connection;
870  if (!CBS_get_u8_length_prefixed(contents, &renegotiated_connection) ||
871  CBS_len(contents) != 0) {
873  return false;
874  }
875 
876  // Check that the extension matches. We do not support renegotiation as a
877  // server, so this must be empty.
878  if (CBS_len(&renegotiated_connection) != 0) {
880  *out_alert = SSL_AD_HANDSHAKE_FAILURE;
881  return false;
882  }
883 
884  ssl->s3->send_connection_binding = true;
885 
886  return true;
887 }
888 
890  SSL *const ssl = hs->ssl;
891  // Renegotiation isn't supported as a server so this function should never be
892  // called after the initial handshake.
893  assert(!ssl->s3->initial_handshake_complete);
894 
895  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION) {
896  return true;
897  }
898 
900  !CBB_add_u16(out, 1 /* length */) ||
901  !CBB_add_u8(out, 0 /* empty renegotiation info */)) {
902  return false;
903  }
904 
905  return true;
906 }
907 
908 
909 // Extended Master Secret.
910 //
911 // https://tools.ietf.org/html/rfc7627
912 
914  CBB *out_compressible,
916  // Extended master secret is not necessary in TLS 1.3.
918  return true;
919  }
920 
922  !CBB_add_u16(out, 0 /* length */)) {
923  return false;
924  }
925 
926  return true;
927 }
928 
929 static bool ext_ems_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
930  CBS *contents) {
931  SSL *const ssl = hs->ssl;
932 
933  if (contents != NULL) {
934  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION ||
935  CBS_len(contents) != 0) {
936  return false;
937  }
938 
939  hs->extended_master_secret = true;
940  }
941 
942  // Whether EMS is negotiated may not change on renegotiation.
943  if (ssl->s3->established_session != nullptr &&
945  !!ssl->s3->established_session->extended_master_secret) {
947  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
948  return false;
949  }
950 
951  return true;
952 }
953 
954 static bool ext_ems_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
955  CBS *contents) {
957  return true;
958  }
959 
960  if (contents == NULL) {
961  return true;
962  }
963 
964  if (CBS_len(contents) != 0) {
965  return false;
966  }
967 
968  hs->extended_master_secret = true;
969  return true;
970 }
971 
973  if (!hs->extended_master_secret) {
974  return true;
975  }
976 
978  !CBB_add_u16(out, 0 /* length */)) {
979  return false;
980  }
981 
982  return true;
983 }
984 
985 
986 // Session tickets.
987 //
988 // https://tools.ietf.org/html/rfc5077
989 
991  CBB *out_compressible,
993  const SSL *const ssl = hs->ssl;
994  // TLS 1.3 uses a different ticket extension.
997  return true;
998  }
999 
1000  Span<const uint8_t> ticket;
1001 
1002  // Renegotiation does not participate in session resumption. However, still
1003  // advertise the extension to avoid potentially breaking servers which carry
1004  // over the state from the previous handshake, such as OpenSSL servers
1005  // without upstream's 3c3f0259238594d77264a78944d409f2127642c4.
1006  if (!ssl->s3->initial_handshake_complete &&
1007  ssl->session != nullptr &&
1008  !ssl->session->ticket.empty() &&
1009  // Don't send TLS 1.3 session tickets in the ticket extension.
1011  ticket = ssl->session->ticket;
1012  }
1013 
1014  CBB ticket_cbb;
1016  !CBB_add_u16_length_prefixed(out, &ticket_cbb) ||
1017  !CBB_add_bytes(&ticket_cbb, ticket.data(), ticket.size()) ||
1018  !CBB_flush(out)) {
1019  return false;
1020  }
1021 
1022  return true;
1023 }
1024 
1026  CBS *contents) {
1027  SSL *const ssl = hs->ssl;
1028  if (contents == NULL) {
1029  return true;
1030  }
1031 
1032  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION) {
1033  return false;
1034  }
1035 
1036  // If |SSL_OP_NO_TICKET| is set then no extension will have been sent and
1037  // this function should never be called, even if the server tries to send the
1038  // extension.
1039  assert((SSL_get_options(ssl) & SSL_OP_NO_TICKET) == 0);
1040 
1041  if (CBS_len(contents) != 0) {
1042  return false;
1043  }
1044 
1045  hs->ticket_expected = true;
1046  return true;
1047 }
1048 
1050  if (!hs->ticket_expected) {
1051  return true;
1052  }
1053 
1054  // If |SSL_OP_NO_TICKET| is set, |ticket_expected| should never be true.
1055  assert((SSL_get_options(hs->ssl) & SSL_OP_NO_TICKET) == 0);
1056 
1058  !CBB_add_u16(out, 0 /* length */)) {
1059  return false;
1060  }
1061 
1062  return true;
1063 }
1064 
1065 
1066 // Signature Algorithms.
1067 //
1068 // https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1
1069 
1071  CBB *out_compressible,
1073  if (hs->max_version < TLS1_2_VERSION) {
1074  return true;
1075  }
1076 
1077  CBB contents, sigalgs_cbb;
1078  if (!CBB_add_u16(out_compressible, TLSEXT_TYPE_signature_algorithms) ||
1079  !CBB_add_u16_length_prefixed(out_compressible, &contents) ||
1080  !CBB_add_u16_length_prefixed(&contents, &sigalgs_cbb) ||
1081  !tls12_add_verify_sigalgs(hs, &sigalgs_cbb) ||
1082  !CBB_flush(out_compressible)) {
1083  return false;
1084  }
1085 
1086  return true;
1087 }
1088 
1090  CBS *contents) {
1091  hs->peer_sigalgs.Reset();
1092  if (contents == NULL) {
1093  return true;
1094  }
1095 
1096  CBS supported_signature_algorithms;
1097  if (!CBS_get_u16_length_prefixed(contents, &supported_signature_algorithms) ||
1098  CBS_len(contents) != 0 ||
1099  !tls1_parse_peer_sigalgs(hs, &supported_signature_algorithms)) {
1100  return false;
1101  }
1102 
1103  return true;
1104 }
1105 
1106 
1107 // OCSP Stapling.
1108 //
1109 // https://tools.ietf.org/html/rfc6066#section-8
1110 
1112  CBB *out_compressible,
1114  if (!hs->config->ocsp_stapling_enabled) {
1115  return true;
1116  }
1117 
1118  CBB contents;
1119  if (!CBB_add_u16(out_compressible, TLSEXT_TYPE_status_request) ||
1120  !CBB_add_u16_length_prefixed(out_compressible, &contents) ||
1122  !CBB_add_u16(&contents, 0 /* empty responder ID list */) ||
1123  !CBB_add_u16(&contents, 0 /* empty request extensions */) ||
1124  !CBB_flush(out_compressible)) {
1125  return false;
1126  }
1127 
1128  return true;
1129 }
1130 
1132  CBS *contents) {
1133  SSL *const ssl = hs->ssl;
1134  if (contents == NULL) {
1135  return true;
1136  }
1137 
1138  // TLS 1.3 OCSP responses are included in the Certificate extensions.
1139  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION) {
1140  return false;
1141  }
1142 
1143  // OCSP stapling is forbidden on non-certificate ciphers.
1144  if (CBS_len(contents) != 0 ||
1146  return false;
1147  }
1148 
1149  // Note this does not check for resumption in TLS 1.2. Sending
1150  // status_request here does not make sense, but OpenSSL does so and the
1151  // specification does not say anything. Tolerate it but ignore it.
1152 
1153  hs->certificate_status_expected = true;
1154  return true;
1155 }
1156 
1158  CBS *contents) {
1159  if (contents == NULL) {
1160  return true;
1161  }
1162 
1163  uint8_t status_type;
1164  if (!CBS_get_u8(contents, &status_type)) {
1165  return false;
1166  }
1167 
1168  // We cannot decide whether OCSP stapling will occur yet because the correct
1169  // SSL_CTX might not have been selected.
1170  hs->ocsp_stapling_requested = status_type == TLSEXT_STATUSTYPE_ocsp;
1171 
1172  return true;
1173 }
1174 
1176  SSL *const ssl = hs->ssl;
1177  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION ||
1178  !hs->ocsp_stapling_requested || hs->config->cert->ocsp_response == NULL ||
1179  ssl->s3->session_reused ||
1181  return true;
1182  }
1183 
1184  hs->certificate_status_expected = true;
1185 
1187  CBB_add_u16(out, 0 /* length */);
1188 }
1189 
1190 
1191 // Next protocol negotiation.
1192 //
1193 // https://htmlpreview.github.io/?https://github.com/agl/technotes/blob/master/nextprotoneg.html
1194 
1196  CBB *out_compressible,
1198  const SSL *const ssl = hs->ssl;
1199  if (ssl->ctx->next_proto_select_cb == NULL ||
1200  // Do not allow NPN to change on renegotiation.
1201  ssl->s3->initial_handshake_complete ||
1202  // NPN is not defined in DTLS or TLS 1.3.
1203  SSL_is_dtls(ssl) || hs->min_version >= TLS1_3_VERSION ||
1205  return true;
1206  }
1207 
1209  !CBB_add_u16(out, 0 /* length */)) {
1210  return false;
1211  }
1212 
1213  return true;
1214 }
1215 
1217  CBS *contents) {
1218  SSL *const ssl = hs->ssl;
1219  if (contents == NULL) {
1220  return true;
1221  }
1222 
1223  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION) {
1224  return false;
1225  }
1226 
1227  // If any of these are false then we should never have sent the NPN
1228  // extension in the ClientHello and thus this function should never have been
1229  // called.
1230  assert(!ssl->s3->initial_handshake_complete);
1231  assert(!SSL_is_dtls(ssl));
1232  assert(ssl->ctx->next_proto_select_cb != NULL);
1233 
1234  if (!ssl->s3->alpn_selected.empty()) {
1235  // NPN and ALPN may not be negotiated in the same connection.
1236  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
1238  return false;
1239  }
1240 
1241  const uint8_t *const orig_contents = CBS_data(contents);
1242  const size_t orig_len = CBS_len(contents);
1243 
1244  while (CBS_len(contents) != 0) {
1245  CBS proto;
1246  if (!CBS_get_u8_length_prefixed(contents, &proto) ||
1247  CBS_len(&proto) == 0) {
1248  return false;
1249  }
1250  }
1251 
1252  uint8_t *selected;
1253  uint8_t selected_len;
1254  if (ssl->ctx->next_proto_select_cb(
1255  ssl, &selected, &selected_len, orig_contents, orig_len,
1256  ssl->ctx->next_proto_select_cb_arg) != SSL_TLSEXT_ERR_OK ||
1257  !ssl->s3->next_proto_negotiated.CopyFrom(
1258  MakeConstSpan(selected, selected_len))) {
1259  *out_alert = SSL_AD_INTERNAL_ERROR;
1260  return false;
1261  }
1262 
1263  hs->next_proto_neg_seen = true;
1264  return true;
1265 }
1266 
1268  CBS *contents) {
1269  SSL *const ssl = hs->ssl;
1270  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION) {
1271  return true;
1272  }
1273 
1274  if (contents != NULL && CBS_len(contents) != 0) {
1275  return false;
1276  }
1277 
1278  if (contents == NULL ||
1279  ssl->s3->initial_handshake_complete ||
1280  ssl->ctx->next_protos_advertised_cb == NULL ||
1281  SSL_is_dtls(ssl)) {
1282  return true;
1283  }
1284 
1285  hs->next_proto_neg_seen = true;
1286  return true;
1287 }
1288 
1290  SSL *const ssl = hs->ssl;
1291  // |next_proto_neg_seen| might have been cleared when an ALPN extension was
1292  // parsed.
1293  if (!hs->next_proto_neg_seen) {
1294  return true;
1295  }
1296 
1297  const uint8_t *npa;
1298  unsigned npa_len;
1299 
1300  if (ssl->ctx->next_protos_advertised_cb(
1301  ssl, &npa, &npa_len, ssl->ctx->next_protos_advertised_cb_arg) !=
1303  hs->next_proto_neg_seen = false;
1304  return true;
1305  }
1306 
1307  CBB contents;
1310  !CBB_add_bytes(&contents, npa, npa_len) ||
1311  !CBB_flush(out)) {
1312  return false;
1313  }
1314 
1315  return true;
1316 }
1317 
1318 
1319 // Signed certificate timestamps.
1320 //
1321 // https://tools.ietf.org/html/rfc6962#section-3.3.1
1322 
1324  CBB *out_compressible,
1327  return true;
1328  }
1329 
1330  if (!CBB_add_u16(out_compressible, TLSEXT_TYPE_certificate_timestamp) ||
1331  !CBB_add_u16(out_compressible, 0 /* length */)) {
1332  return false;
1333  }
1334 
1335  return true;
1336 }
1337 
1339  CBS *contents) {
1340  SSL *const ssl = hs->ssl;
1341  if (contents == NULL) {
1342  return true;
1343  }
1344 
1345  // TLS 1.3 SCTs are included in the Certificate extensions.
1346  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION) {
1347  *out_alert = SSL_AD_DECODE_ERROR;
1348  return false;
1349  }
1350 
1351  // If this is false then we should never have sent the SCT extension in the
1352  // ClientHello and thus this function should never have been called.
1354 
1356  *out_alert = SSL_AD_DECODE_ERROR;
1357  return false;
1358  }
1359 
1360  // Session resumption uses the original session information. The extension
1361  // should not be sent on resumption, but RFC 6962 did not make it a
1362  // requirement, so tolerate this.
1363  //
1364  // TODO(davidben): Enforce this anyway.
1365  if (!ssl->s3->session_reused) {
1366  hs->new_session->signed_cert_timestamp_list.reset(
1367  CRYPTO_BUFFER_new_from_CBS(contents, ssl->ctx->pool));
1368  if (hs->new_session->signed_cert_timestamp_list == nullptr) {
1369  *out_alert = SSL_AD_INTERNAL_ERROR;
1370  return false;
1371  }
1372  }
1373 
1374  return true;
1375 }
1376 
1378  CBS *contents) {
1379  if (contents == NULL) {
1380  return true;
1381  }
1382 
1383  if (CBS_len(contents) != 0) {
1384  return false;
1385  }
1386 
1387  hs->scts_requested = true;
1388  return true;
1389 }
1390 
1392  SSL *const ssl = hs->ssl;
1393  // The extension shouldn't be sent when resuming sessions.
1394  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION || ssl->s3->session_reused ||
1395  hs->config->cert->signed_cert_timestamp_list == NULL) {
1396  return true;
1397  }
1398 
1399  CBB contents;
1402  CBB_add_bytes(
1403  &contents,
1405  hs->config->cert->signed_cert_timestamp_list.get()),
1407  hs->config->cert->signed_cert_timestamp_list.get())) &&
1408  CBB_flush(out);
1409 }
1410 
1411 
1412 // Application-level Protocol Negotiation.
1413 //
1414 // https://tools.ietf.org/html/rfc7301
1415 
1417  CBB *out_compressible,
1419  const SSL *const ssl = hs->ssl;
1420  if (hs->config->alpn_client_proto_list.empty() && ssl->quic_method) {
1421  // ALPN MUST be used with QUIC.
1423  return false;
1424  }
1425 
1426  if (hs->config->alpn_client_proto_list.empty() ||
1427  ssl->s3->initial_handshake_complete) {
1428  return true;
1429  }
1430 
1431  CBB contents, proto_list;
1432  if (!CBB_add_u16(out_compressible,
1434  !CBB_add_u16_length_prefixed(out_compressible, &contents) ||
1435  !CBB_add_u16_length_prefixed(&contents, &proto_list) ||
1436  !CBB_add_bytes(&proto_list, hs->config->alpn_client_proto_list.data(),
1438  !CBB_flush(out_compressible)) {
1439  return false;
1440  }
1441 
1442  return true;
1443 }
1444 
1446  CBS *contents) {
1447  SSL *const ssl = hs->ssl;
1448  if (contents == NULL) {
1449  if (ssl->quic_method) {
1450  // ALPN is required when QUIC is used.
1452  *out_alert = SSL_AD_NO_APPLICATION_PROTOCOL;
1453  return false;
1454  }
1455  return true;
1456  }
1457 
1458  assert(!ssl->s3->initial_handshake_complete);
1459  assert(!hs->config->alpn_client_proto_list.empty());
1460 
1461  if (hs->next_proto_neg_seen) {
1462  // NPN and ALPN may not be negotiated in the same connection.
1463  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
1465  return false;
1466  }
1467 
1468  // The extension data consists of a ProtocolNameList which must have
1469  // exactly one ProtocolName. Each of these is length-prefixed.
1470  CBS protocol_name_list, protocol_name;
1471  if (!CBS_get_u16_length_prefixed(contents, &protocol_name_list) ||
1472  CBS_len(contents) != 0 ||
1473  !CBS_get_u8_length_prefixed(&protocol_name_list, &protocol_name) ||
1474  // Empty protocol names are forbidden.
1475  CBS_len(&protocol_name) == 0 ||
1476  CBS_len(&protocol_name_list) != 0) {
1477  return false;
1478  }
1479 
1480  if (!ssl_is_alpn_protocol_allowed(hs, protocol_name)) {
1482  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
1483  return false;
1484  }
1485 
1486  if (!ssl->s3->alpn_selected.CopyFrom(protocol_name)) {
1487  *out_alert = SSL_AD_INTERNAL_ERROR;
1488  return false;
1489  }
1490 
1491  return true;
1492 }
1493 
1495  CBS protocol_name_list = in;
1496  if (CBS_len(&protocol_name_list) == 0) {
1497  return false;
1498  }
1499  while (CBS_len(&protocol_name_list) > 0) {
1500  CBS protocol_name;
1501  if (!CBS_get_u8_length_prefixed(&protocol_name_list, &protocol_name) ||
1502  // Empty protocol names are forbidden.
1503  CBS_len(&protocol_name) == 0) {
1504  return false;
1505  }
1506  }
1507  return true;
1508 }
1509 
1512  if (hs->config->alpn_client_proto_list.empty()) {
1513  return false;
1514  }
1515 
1516  if (hs->ssl->ctx->allow_unknown_alpn_protos) {
1517  return true;
1518  }
1519 
1520  // Check that the protocol name is one of the ones we advertised.
1521  CBS client_protocol_name_list =
1523  client_protocol_name;
1524  while (CBS_len(&client_protocol_name_list) > 0) {
1525  if (!CBS_get_u8_length_prefixed(&client_protocol_name_list,
1526  &client_protocol_name)) {
1527  return false;
1528  }
1529 
1530  if (client_protocol_name == protocol) {
1531  return true;
1532  }
1533  }
1534 
1535  return false;
1536 }
1537 
1539  const SSL_CLIENT_HELLO *client_hello) {
1540  SSL *const ssl = hs->ssl;
1541  CBS contents;
1542  if (ssl->ctx->alpn_select_cb == NULL ||
1544  client_hello, &contents,
1546  if (ssl->quic_method) {
1547  // ALPN is required when QUIC is used.
1549  *out_alert = SSL_AD_NO_APPLICATION_PROTOCOL;
1550  return false;
1551  }
1552  // Ignore ALPN if not configured or no extension was supplied.
1553  return true;
1554  }
1555 
1556  // ALPN takes precedence over NPN.
1557  hs->next_proto_neg_seen = false;
1558 
1559  CBS protocol_name_list;
1560  if (!CBS_get_u16_length_prefixed(&contents, &protocol_name_list) ||
1561  CBS_len(&contents) != 0 ||
1562  !ssl_is_valid_alpn_list(protocol_name_list)) {
1564  *out_alert = SSL_AD_DECODE_ERROR;
1565  return false;
1566  }
1567 
1568  const uint8_t *selected;
1569  uint8_t selected_len;
1570  int ret = ssl->ctx->alpn_select_cb(
1571  ssl, &selected, &selected_len, CBS_data(&protocol_name_list),
1572  CBS_len(&protocol_name_list), ssl->ctx->alpn_select_cb_arg);
1573  // ALPN is required when QUIC is used.
1574  if (ssl->quic_method &&
1577  }
1578  switch (ret) {
1579  case SSL_TLSEXT_ERR_OK:
1580  if (selected_len == 0) {
1582  *out_alert = SSL_AD_INTERNAL_ERROR;
1583  return false;
1584  }
1585  if (!ssl->s3->alpn_selected.CopyFrom(
1586  MakeConstSpan(selected, selected_len))) {
1587  *out_alert = SSL_AD_INTERNAL_ERROR;
1588  return false;
1589  }
1590  break;
1591  case SSL_TLSEXT_ERR_NOACK:
1593  break;
1595  *out_alert = SSL_AD_NO_APPLICATION_PROTOCOL;
1597  return false;
1598  default:
1599  // Invalid return value.
1600  *out_alert = SSL_AD_INTERNAL_ERROR;
1602  return false;
1603  }
1604 
1605  return true;
1606 }
1607 
1609  SSL *const ssl = hs->ssl;
1610  if (ssl->s3->alpn_selected.empty()) {
1611  return true;
1612  }
1613 
1614  CBB contents, proto_list, proto;
1617  !CBB_add_u16_length_prefixed(&contents, &proto_list) ||
1618  !CBB_add_u8_length_prefixed(&proto_list, &proto) ||
1619  !CBB_add_bytes(&proto, ssl->s3->alpn_selected.data(),
1620  ssl->s3->alpn_selected.size()) ||
1621  !CBB_flush(out)) {
1622  return false;
1623  }
1624 
1625  return true;
1626 }
1627 
1628 
1629 // Channel ID.
1630 //
1631 // https://tools.ietf.org/html/draft-balfanz-tls-channelid-01
1632 
1634  CBB *out_compressible,
1636  const SSL *const ssl = hs->ssl;
1637  if (!hs->config->channel_id_private || SSL_is_dtls(ssl) ||
1638  // Don't offer Channel ID in ClientHelloOuter. ClientHelloOuter handshakes
1639  // are not authenticated for the name that can learn the Channel ID.
1640  //
1641  // We could alternatively offer the extension but sign with a random key.
1642  // For other extensions, we try to align |ssl_client_hello_outer| and
1643  // |ssl_client_hello_unencrypted|, to improve the effectiveness of ECH
1644  // GREASE. However, Channel ID is deprecated and unlikely to be used with
1645  // ECH, so do the simplest thing.
1647  return true;
1648  }
1649 
1651  !CBB_add_u16(out, 0 /* length */)) {
1652  return false;
1653  }
1654 
1655  return true;
1656 }
1657 
1659  uint8_t *out_alert,
1660  CBS *contents) {
1661  if (contents == NULL) {
1662  return true;
1663  }
1664 
1665  assert(!SSL_is_dtls(hs->ssl));
1666  assert(hs->config->channel_id_private);
1667 
1668  if (CBS_len(contents) != 0) {
1669  return false;
1670  }
1671 
1672  hs->channel_id_negotiated = true;
1673  return true;
1674 }
1675 
1677  uint8_t *out_alert,
1678  CBS *contents) {
1679  SSL *const ssl = hs->ssl;
1680  if (contents == NULL || !hs->config->channel_id_enabled || SSL_is_dtls(ssl)) {
1681  return true;
1682  }
1683 
1684  if (CBS_len(contents) != 0) {
1685  return false;
1686  }
1687 
1688  hs->channel_id_negotiated = true;
1689  return true;
1690 }
1691 
1693  if (!hs->channel_id_negotiated) {
1694  return true;
1695  }
1696 
1698  !CBB_add_u16(out, 0 /* length */)) {
1699  return false;
1700  }
1701 
1702  return true;
1703 }
1704 
1705 
1706 // Secure Real-time Transport Protocol (SRTP) extension.
1707 //
1708 // https://tools.ietf.org/html/rfc5764
1709 
1711  CBB *out_compressible,
1713  const SSL *const ssl = hs->ssl;
1714  const STACK_OF(SRTP_PROTECTION_PROFILE) *profiles =
1715  SSL_get_srtp_profiles(ssl);
1716  if (profiles == NULL ||
1717  sk_SRTP_PROTECTION_PROFILE_num(profiles) == 0 ||
1718  !SSL_is_dtls(ssl)) {
1719  return true;
1720  }
1721 
1722  CBB contents, profile_ids;
1723  if (!CBB_add_u16(out_compressible, TLSEXT_TYPE_srtp) ||
1724  !CBB_add_u16_length_prefixed(out_compressible, &contents) ||
1725  !CBB_add_u16_length_prefixed(&contents, &profile_ids)) {
1726  return false;
1727  }
1728 
1729  for (const SRTP_PROTECTION_PROFILE *profile : profiles) {
1730  if (!CBB_add_u16(&profile_ids, profile->id)) {
1731  return false;
1732  }
1733  }
1734 
1735  if (!CBB_add_u8(&contents, 0 /* empty use_mki value */) ||
1736  !CBB_flush(out_compressible)) {
1737  return false;
1738  }
1739 
1740  return true;
1741 }
1742 
1744  CBS *contents) {
1745  SSL *const ssl = hs->ssl;
1746  if (contents == NULL) {
1747  return true;
1748  }
1749 
1750  // The extension consists of a u16-prefixed profile ID list containing a
1751  // single uint16_t profile ID, then followed by a u8-prefixed srtp_mki field.
1752  //
1753  // See https://tools.ietf.org/html/rfc5764#section-4.1.1
1754  assert(SSL_is_dtls(ssl));
1755  CBS profile_ids, srtp_mki;
1756  uint16_t profile_id;
1757  if (!CBS_get_u16_length_prefixed(contents, &profile_ids) ||
1758  !CBS_get_u16(&profile_ids, &profile_id) ||
1759  CBS_len(&profile_ids) != 0 ||
1760  !CBS_get_u8_length_prefixed(contents, &srtp_mki) ||
1761  CBS_len(contents) != 0) {
1763  return false;
1764  }
1765 
1766  if (CBS_len(&srtp_mki) != 0) {
1767  // Must be no MKI, since we never offer one.
1769  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
1770  return false;
1771  }
1772 
1773  // Check to see if the server gave us something we support and offered.
1775  if (profile->id == profile_id) {
1776  ssl->s3->srtp_profile = profile;
1777  return true;
1778  }
1779  }
1780 
1782  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
1783  return false;
1784 }
1785 
1787  CBS *contents) {
1788  SSL *const ssl = hs->ssl;
1789  // DTLS-SRTP is only defined for DTLS.
1790  if (contents == NULL || !SSL_is_dtls(ssl)) {
1791  return true;
1792  }
1793 
1794  CBS profile_ids, srtp_mki;
1795  if (!CBS_get_u16_length_prefixed(contents, &profile_ids) ||
1796  CBS_len(&profile_ids) < 2 ||
1797  !CBS_get_u8_length_prefixed(contents, &srtp_mki) ||
1798  CBS_len(contents) != 0) {
1800  return false;
1801  }
1802  // Discard the MKI value for now.
1803 
1804  const STACK_OF(SRTP_PROTECTION_PROFILE) *server_profiles =
1805  SSL_get_srtp_profiles(ssl);
1806 
1807  // Pick the server's most preferred profile.
1808  for (const SRTP_PROTECTION_PROFILE *server_profile : server_profiles) {
1809  CBS profile_ids_tmp;
1810  CBS_init(&profile_ids_tmp, CBS_data(&profile_ids), CBS_len(&profile_ids));
1811 
1812  while (CBS_len(&profile_ids_tmp) > 0) {
1813  uint16_t profile_id;
1814  if (!CBS_get_u16(&profile_ids_tmp, &profile_id)) {
1815  return false;
1816  }
1817 
1818  if (server_profile->id == profile_id) {
1819  ssl->s3->srtp_profile = server_profile;
1820  return true;
1821  }
1822  }
1823  }
1824 
1825  return true;
1826 }
1827 
1829  SSL *const ssl = hs->ssl;
1830  if (ssl->s3->srtp_profile == NULL) {
1831  return true;
1832  }
1833 
1834  assert(SSL_is_dtls(ssl));
1835  CBB contents, profile_ids;
1836  if (!CBB_add_u16(out, TLSEXT_TYPE_srtp) ||
1838  !CBB_add_u16_length_prefixed(&contents, &profile_ids) ||
1839  !CBB_add_u16(&profile_ids, ssl->s3->srtp_profile->id) ||
1840  !CBB_add_u8(&contents, 0 /* empty MKI */) ||
1841  !CBB_flush(out)) {
1842  return false;
1843  }
1844 
1845  return true;
1846 }
1847 
1848 
1849 // EC point formats.
1850 //
1851 // https://tools.ietf.org/html/rfc4492#section-5.1.2
1852 
1854  CBB contents, formats;
1857  !CBB_add_u8_length_prefixed(&contents, &formats) ||
1859  !CBB_flush(out)) {
1860  return false;
1861  }
1862 
1863  return true;
1864 }
1865 
1867  CBB *out_compressible,
1869  // The point format extension is unnecessary in TLS 1.3.
1871  return true;
1872  }
1873 
1874  return ext_ec_point_add_extension(hs, out);
1875 }
1876 
1878  CBS *contents) {
1879  if (contents == NULL) {
1880  return true;
1881  }
1882 
1883  if (ssl_protocol_version(hs->ssl) >= TLS1_3_VERSION) {
1884  return false;
1885  }
1886 
1887  CBS ec_point_format_list;
1888  if (!CBS_get_u8_length_prefixed(contents, &ec_point_format_list) ||
1889  CBS_len(contents) != 0) {
1890  return false;
1891  }
1892 
1893  // Per RFC 4492, section 5.1.2, implementations MUST support the uncompressed
1894  // point format.
1895  if (OPENSSL_memchr(CBS_data(&ec_point_format_list),
1897  CBS_len(&ec_point_format_list)) == NULL) {
1898  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
1899  return false;
1900  }
1901 
1902  return true;
1903 }
1904 
1906  CBS *contents) {
1907  if (ssl_protocol_version(hs->ssl) >= TLS1_3_VERSION) {
1908  return true;
1909  }
1910 
1911  return ext_ec_point_parse_serverhello(hs, out_alert, contents);
1912 }
1913 
1915  SSL *const ssl = hs->ssl;
1916  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION) {
1917  return true;
1918  }
1919 
1920  const uint32_t alg_k = hs->new_cipher->algorithm_mkey;
1921  const uint32_t alg_a = hs->new_cipher->algorithm_auth;
1922  const bool using_ecc = (alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA);
1923 
1924  if (!using_ecc) {
1925  return true;
1926  }
1927 
1928  return ext_ec_point_add_extension(hs, out);
1929 }
1930 
1931 
1932 // Pre Shared Key
1933 //
1934 // https://tools.ietf.org/html/rfc8446#section-4.2.11
1935 
1936 static bool should_offer_psk(const SSL_HANDSHAKE *hs,
1938  const SSL *const ssl = hs->ssl;
1939  if (hs->max_version < TLS1_3_VERSION || ssl->session == nullptr ||
1941  // TODO(https://crbug.com/boringssl/275): Should we synthesize a
1942  // placeholder PSK, at least when we offer early data? Otherwise
1943  // ClientHelloOuter will contain an early_data extension without a
1944  // pre_shared_key extension and potentially break the recovery flow.
1946  return false;
1947  }
1948 
1949  // Per RFC 8446 section 4.1.4, skip offering the session if the selected
1950  // cipher in HelloRetryRequest does not match. This avoids performing the
1951  // transcript hash transformation for multiple hashes.
1952  if (ssl->s3->used_hello_retry_request &&
1953  ssl->session->cipher->algorithm_prf != hs->new_cipher->algorithm_prf) {
1954  return false;
1955  }
1956 
1957  return true;
1958 }
1959 
1962  const SSL *const ssl = hs->ssl;
1963  if (!should_offer_psk(hs, type)) {
1964  return 0;
1965  }
1966 
1967  size_t binder_len = EVP_MD_size(ssl_session_get_digest(ssl->session.get()));
1968  return 15 + ssl->session->ticket.size() + binder_len;
1969 }
1970 
1972  CBB *out, bool *out_needs_binder,
1974  const SSL *const ssl = hs->ssl;
1975  *out_needs_binder = false;
1976  if (!should_offer_psk(hs, type)) {
1977  return true;
1978  }
1979 
1980  struct OPENSSL_timeval now;
1981  ssl_get_current_time(ssl, &now);
1982  uint32_t ticket_age = 1000 * (now.tv_sec - ssl->session->time);
1983  uint32_t obfuscated_ticket_age = ticket_age + ssl->session->ticket_age_add;
1984 
1985  // Fill in a placeholder zero binder of the appropriate length. It will be
1986  // computed and filled in later after length prefixes are computed.
1987  size_t binder_len = EVP_MD_size(ssl_session_get_digest(ssl->session.get()));
1988 
1989  CBB contents, identity, ticket, binders, binder;
1992  !CBB_add_u16_length_prefixed(&contents, &identity) ||
1993  !CBB_add_u16_length_prefixed(&identity, &ticket) ||
1994  !CBB_add_bytes(&ticket, ssl->session->ticket.data(),
1995  ssl->session->ticket.size()) ||
1996  !CBB_add_u32(&identity, obfuscated_ticket_age) ||
1997  !CBB_add_u16_length_prefixed(&contents, &binders) ||
1998  !CBB_add_u8_length_prefixed(&binders, &binder) ||
1999  !CBB_add_zeros(&binder, binder_len)) {
2000  return false;
2001  }
2002 
2003  *out_needs_binder = true;
2004  return CBB_flush(out);
2005 }
2006 
2008  uint8_t *out_alert,
2009  CBS *contents) {
2010  uint16_t psk_id;
2011  if (!CBS_get_u16(contents, &psk_id) ||
2012  CBS_len(contents) != 0) {
2014  *out_alert = SSL_AD_DECODE_ERROR;
2015  return false;
2016  }
2017 
2018  // We only advertise one PSK identity, so the only legal index is zero.
2019  if (psk_id != 0) {
2021  *out_alert = SSL_AD_UNKNOWN_PSK_IDENTITY;
2022  return false;
2023  }
2024 
2025  return true;
2026 }
2027 
2029  SSL_HANDSHAKE *hs, CBS *out_ticket, CBS *out_binders,
2030  uint32_t *out_obfuscated_ticket_age, uint8_t *out_alert,
2031  const SSL_CLIENT_HELLO *client_hello, CBS *contents) {
2032  // Verify that the pre_shared_key extension is the last extension in
2033  // ClientHello.
2034  if (CBS_data(contents) + CBS_len(contents) !=
2035  client_hello->extensions + client_hello->extensions_len) {
2037  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
2038  return false;
2039  }
2040 
2041  // We only process the first PSK identity since we don't support pure PSK.
2042  CBS identities, binders;
2043  if (!CBS_get_u16_length_prefixed(contents, &identities) ||
2044  !CBS_get_u16_length_prefixed(&identities, out_ticket) ||
2045  !CBS_get_u32(&identities, out_obfuscated_ticket_age) ||
2046  !CBS_get_u16_length_prefixed(contents, &binders) ||
2047  CBS_len(&binders) == 0 ||
2048  CBS_len(contents) != 0) {
2050  *out_alert = SSL_AD_DECODE_ERROR;
2051  return false;
2052  }
2053 
2054  *out_binders = binders;
2055 
2056  // Check the syntax of the remaining identities, but do not process them.
2057  size_t num_identities = 1;
2058  while (CBS_len(&identities) != 0) {
2059  CBS unused_ticket;
2060  uint32_t unused_obfuscated_ticket_age;
2061  if (!CBS_get_u16_length_prefixed(&identities, &unused_ticket) ||
2062  !CBS_get_u32(&identities, &unused_obfuscated_ticket_age)) {
2064  *out_alert = SSL_AD_DECODE_ERROR;
2065  return false;
2066  }
2067 
2068  num_identities++;
2069  }
2070 
2071  // Check the syntax of the binders. The value will be checked later if
2072  // resuming.
2073  size_t num_binders = 0;
2074  while (CBS_len(&binders) != 0) {
2075  CBS binder;
2076  if (!CBS_get_u8_length_prefixed(&binders, &binder)) {
2078  *out_alert = SSL_AD_DECODE_ERROR;
2079  return false;
2080  }
2081 
2082  num_binders++;
2083  }
2084 
2085  if (num_identities != num_binders) {
2087  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
2088  return false;
2089  }
2090 
2091  return true;
2092 }
2093 
2095  if (!hs->ssl->s3->session_reused) {
2096  return true;
2097  }
2098 
2099  CBB contents;
2102  // We only consider the first identity for resumption
2103  !CBB_add_u16(&contents, 0) ||
2104  !CBB_flush(out)) {
2105  return false;
2106  }
2107 
2108  return true;
2109 }
2110 
2111 
2112 // Pre-Shared Key Exchange Modes
2113 //
2114 // https://tools.ietf.org/html/rfc8446#section-4.2.9
2115 
2117  const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible,
2119  if (hs->max_version < TLS1_3_VERSION) {
2120  return true;
2121  }
2122 
2123  CBB contents, ke_modes;
2124  if (!CBB_add_u16(out_compressible, TLSEXT_TYPE_psk_key_exchange_modes) ||
2125  !CBB_add_u16_length_prefixed(out_compressible, &contents) ||
2126  !CBB_add_u8_length_prefixed(&contents, &ke_modes) ||
2127  !CBB_add_u8(&ke_modes, SSL_PSK_DHE_KE)) {
2128  return false;
2129  }
2130 
2131  return CBB_flush(out_compressible);
2132 }
2133 
2135  uint8_t *out_alert,
2136  CBS *contents) {
2137  if (contents == NULL) {
2138  return true;
2139  }
2140 
2141  CBS ke_modes;
2142  if (!CBS_get_u8_length_prefixed(contents, &ke_modes) ||
2143  CBS_len(&ke_modes) == 0 ||
2144  CBS_len(contents) != 0) {
2145  *out_alert = SSL_AD_DECODE_ERROR;
2146  return false;
2147  }
2148 
2149  // We only support tickets with PSK_DHE_KE.
2151  CBS_len(&ke_modes)) != NULL;
2152 
2153  return true;
2154 }
2155 
2156 
2157 // Early Data Indication
2158 //
2159 // https://tools.ietf.org/html/rfc8446#section-4.2.10
2160 
2162  CBB *out_compressible,
2164  const SSL *const ssl = hs->ssl;
2165  // The second ClientHello never offers early data, and we must have already
2166  // filled in |early_data_reason| by this point.
2167  if (ssl->s3->used_hello_retry_request) {
2168  assert(ssl->s3->early_data_reason != ssl_early_data_unknown);
2169  return true;
2170  }
2171 
2172  if (!hs->early_data_offered) {
2173  return true;
2174  }
2175 
2176  // If offering ECH, the extension only applies to ClientHelloInner, but we
2177  // send the extension in both ClientHellos. This ensures that, if the server
2178  // handshakes with ClientHelloOuter, it can skip past early data. See
2179  // draft-ietf-tls-esni-13, section 6.1.
2180  if (!CBB_add_u16(out_compressible, TLSEXT_TYPE_early_data) ||
2181  !CBB_add_u16(out_compressible, 0) ||
2182  !CBB_flush(out_compressible)) {
2183  return false;
2184  }
2185 
2186  return true;
2187 }
2188 
2190  uint8_t *out_alert,
2191  CBS *contents) {
2192  SSL *const ssl = hs->ssl;
2193  if (contents == NULL) {
2194  if (hs->early_data_offered && !ssl->s3->used_hello_retry_request) {
2195  ssl->s3->early_data_reason = ssl->s3->session_reused
2198  } else {
2199  // We already filled in |early_data_reason| when declining to offer 0-RTT
2200  // or handling the implicit HelloRetryRequest reject.
2201  assert(ssl->s3->early_data_reason != ssl_early_data_unknown);
2202  }
2203  return true;
2204  }
2205 
2206  // If we received an HRR, the second ClientHello never offers early data, so
2207  // the extensions logic will automatically reject early data extensions as
2208  // unsolicited. This covered by the ServerAcceptsEarlyDataOnHRR test.
2209  assert(!ssl->s3->used_hello_retry_request);
2210 
2211  if (CBS_len(contents) != 0) {
2212  *out_alert = SSL_AD_DECODE_ERROR;
2213  return false;
2214  }
2215 
2216  if (!ssl->s3->session_reused) {
2217  *out_alert = SSL_AD_UNSUPPORTED_EXTENSION;
2219  return false;
2220  }
2221 
2222  ssl->s3->early_data_reason = ssl_early_data_accepted;
2223  ssl->s3->early_data_accepted = true;
2224  return true;
2225 }
2226 
2228  uint8_t *out_alert, CBS *contents) {
2229  SSL *const ssl = hs->ssl;
2230  if (contents == NULL ||
2232  return true;
2233  }
2234 
2235  if (CBS_len(contents) != 0) {
2236  *out_alert = SSL_AD_DECODE_ERROR;
2237  return false;
2238  }
2239 
2240  hs->early_data_offered = true;
2241  return true;
2242 }
2243 
2245  if (!hs->ssl->s3->early_data_accepted) {
2246  return true;
2247  }
2248 
2250  !CBB_add_u16(out, 0) ||
2251  !CBB_flush(out)) {
2252  return false;
2253  }
2254 
2255  return true;
2256 }
2257 
2258 
2259 // Key Share
2260 //
2261 // https://tools.ietf.org/html/rfc8446#section-4.2.8
2262 
2263 bool ssl_setup_key_shares(SSL_HANDSHAKE *hs, uint16_t override_group_id) {
2264  SSL *const ssl = hs->ssl;
2265  hs->key_shares[0].reset();
2266  hs->key_shares[1].reset();
2267  hs->key_share_bytes.Reset();
2268 
2269  if (hs->max_version < TLS1_3_VERSION) {
2270  return true;
2271  }
2272 
2273  bssl::ScopedCBB cbb;
2274  if (!CBB_init(cbb.get(), 64)) {
2275  return false;
2276  }
2277 
2278  if (override_group_id == 0 && ssl->ctx->grease_enabled) {
2279  // Add a fake group. See RFC 8701.
2280  if (!CBB_add_u16(cbb.get(), ssl_get_grease_value(hs, ssl_grease_group)) ||
2281  !CBB_add_u16(cbb.get(), 1 /* length */) ||
2282  !CBB_add_u8(cbb.get(), 0 /* one byte key share */)) {
2283  return false;
2284  }
2285  }
2286 
2287  uint16_t group_id = override_group_id;
2288  uint16_t second_group_id = 0;
2289  if (override_group_id == 0) {
2290  // Predict the most preferred group.
2292  if (groups.empty()) {
2294  return false;
2295  }
2296 
2297  group_id = groups[0];
2298 
2299  if (is_post_quantum_group(group_id) && groups.size() >= 2) {
2300  // CECPQ2(b) is not sent as the only initial key share. We'll include the
2301  // 2nd preference group too to avoid round-trips.
2302  second_group_id = groups[1];
2303  assert(second_group_id != group_id);
2304  }
2305  }
2306 
2307  CBB key_exchange;
2308  hs->key_shares[0] = SSLKeyShare::Create(group_id);
2309  if (!hs->key_shares[0] || //
2310  !CBB_add_u16(cbb.get(), group_id) ||
2311  !CBB_add_u16_length_prefixed(cbb.get(), &key_exchange) ||
2312  !hs->key_shares[0]->Offer(&key_exchange)) {
2313  return false;
2314  }
2315 
2316  if (second_group_id != 0) {
2317  hs->key_shares[1] = SSLKeyShare::Create(second_group_id);
2318  if (!hs->key_shares[1] || //
2319  !CBB_add_u16(cbb.get(), second_group_id) ||
2320  !CBB_add_u16_length_prefixed(cbb.get(), &key_exchange) ||
2321  !hs->key_shares[1]->Offer(&key_exchange)) {
2322  return false;
2323  }
2324  }
2325 
2326  return CBBFinishArray(cbb.get(), &hs->key_share_bytes);
2327 }
2328 
2330  CBB *out_compressible,
2332  if (hs->max_version < TLS1_3_VERSION) {
2333  return true;
2334  }
2335 
2336  assert(!hs->key_share_bytes.empty());
2337  CBB contents, kse_bytes;
2338  if (!CBB_add_u16(out_compressible, TLSEXT_TYPE_key_share) ||
2339  !CBB_add_u16_length_prefixed(out_compressible, &contents) ||
2340  !CBB_add_u16_length_prefixed(&contents, &kse_bytes) ||
2341  !CBB_add_bytes(&kse_bytes, hs->key_share_bytes.data(),
2342  hs->key_share_bytes.size()) ||
2343  !CBB_flush(out_compressible)) {
2344  return false;
2345  }
2346 
2347  return true;
2348 }
2349 
2351  Array<uint8_t> *out_secret,
2352  uint8_t *out_alert, CBS *contents) {
2353  CBS peer_key;
2354  uint16_t group_id;
2355  if (!CBS_get_u16(contents, &group_id) ||
2356  !CBS_get_u16_length_prefixed(contents, &peer_key) ||
2357  CBS_len(contents) != 0) {
2359  *out_alert = SSL_AD_DECODE_ERROR;
2360  return false;
2361  }
2362 
2363  SSLKeyShare *key_share = hs->key_shares[0].get();
2364  if (key_share->GroupID() != group_id) {
2365  if (!hs->key_shares[1] || hs->key_shares[1]->GroupID() != group_id) {
2366  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
2368  return false;
2369  }
2370  key_share = hs->key_shares[1].get();
2371  }
2372 
2373  if (!key_share->Finish(out_secret, out_alert, peer_key)) {
2374  *out_alert = SSL_AD_INTERNAL_ERROR;
2375  return false;
2376  }
2377 
2378  hs->new_session->group_id = group_id;
2379  hs->key_shares[0].reset();
2380  hs->key_shares[1].reset();
2381  return true;
2382 }
2383 
2385  Span<const uint8_t> *out_peer_key,
2386  uint8_t *out_alert,
2387  const SSL_CLIENT_HELLO *client_hello) {
2388  // We only support connections that include an ECDHE key exchange.
2389  CBS contents;
2390  if (!ssl_client_hello_get_extension(client_hello, &contents,
2393  *out_alert = SSL_AD_MISSING_EXTENSION;
2394  return false;
2395  }
2396 
2397  CBS key_shares;
2398  if (!CBS_get_u16_length_prefixed(&contents, &key_shares) ||
2399  CBS_len(&contents) != 0) {
2401  return false;
2402  }
2403 
2404  // Find the corresponding key share.
2405  const uint16_t group_id = hs->new_session->group_id;
2406  CBS peer_key;
2407  CBS_init(&peer_key, nullptr, 0);
2408  while (CBS_len(&key_shares) > 0) {
2409  uint16_t id;
2410  CBS peer_key_tmp;
2411  if (!CBS_get_u16(&key_shares, &id) ||
2412  !CBS_get_u16_length_prefixed(&key_shares, &peer_key_tmp) ||
2413  CBS_len(&peer_key_tmp) == 0) {
2415  return false;
2416  }
2417 
2418  if (id == group_id) {
2419  if (CBS_len(&peer_key) != 0) {
2421  *out_alert = SSL_AD_ILLEGAL_PARAMETER;
2422  return false;
2423  }
2424 
2425  peer_key = peer_key_tmp;
2426  // Continue parsing the structure to keep peers honest.
2427  }
2428  }
2429 
2430  if (out_peer_key != nullptr) {
2431  *out_peer_key = peer_key;
2432  }
2433  *out_found = CBS_len(&peer_key) != 0;
2434  return true;
2435 }
2436 
2438  CBB kse_bytes, public_key;
2440  !CBB_add_u16_length_prefixed(out, &kse_bytes) ||
2441  !CBB_add_u16(&kse_bytes, hs->new_session->group_id) ||
2442  !CBB_add_u16_length_prefixed(&kse_bytes, &public_key) ||
2444  hs->ecdh_public_key.size()) ||
2445  !CBB_flush(out)) {
2446  return false;
2447  }
2448  return true;
2449 }
2450 
2451 
2452 // Supported Versions
2453 //
2454 // https://tools.ietf.org/html/rfc8446#section-4.2.1
2455 
2457  const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible,
2459  const SSL *const ssl = hs->ssl;
2460  if (hs->max_version <= TLS1_2_VERSION) {
2461  return true;
2462  }
2463 
2464  // supported_versions is compressible in ECH if ClientHelloOuter already
2465  // requires TLS 1.3. Otherwise the extensions differ in the older versions.
2466  if (hs->min_version >= TLS1_3_VERSION) {
2467  out = out_compressible;
2468  }
2469 
2470  CBB contents, versions;
2473  !CBB_add_u8_length_prefixed(&contents, &versions)) {
2474  return false;
2475  }
2476 
2477  // Add a fake version. See RFC 8701.
2478  if (ssl->ctx->grease_enabled &&
2480  return false;
2481  }
2482 
2483  // Encrypted ClientHellos requires TLS 1.3 or later.
2484  uint16_t extra_min_version =
2486  if (!ssl_add_supported_versions(hs, &versions, extra_min_version) ||
2487  !CBB_flush(out)) {
2488  return false;
2489  }
2490 
2491  return true;
2492 }
2493 
2494 
2495 // Cookie
2496 //
2497 // https://tools.ietf.org/html/rfc8446#section-4.2.2
2498 
2500  CBB *out_compressible,
2502  if (hs->cookie.empty()) {
2503  return true;
2504  }
2505 
2506  CBB contents, cookie;
2507  if (!CBB_add_u16(out_compressible, TLSEXT_TYPE_cookie) ||
2508  !CBB_add_u16_length_prefixed(out_compressible, &contents) ||
2509  !CBB_add_u16_length_prefixed(&contents, &cookie) ||
2510  !CBB_add_bytes(&cookie, hs->cookie.data(), hs->cookie.size()) ||
2511  !CBB_flush(out_compressible)) {
2512  return false;
2513  }
2514 
2515  return true;
2516 }
2517 
2518 
2519 // Supported Groups
2520 //
2521 // https://tools.ietf.org/html/rfc4492#section-5.1.1
2522 // https://tools.ietf.org/html/rfc8446#section-4.2.7
2523 
2525  CBB *out,
2526  CBB *out_compressible,
2528  const SSL *const ssl = hs->ssl;
2529  CBB contents, groups_bytes;
2530  if (!CBB_add_u16(out_compressible, TLSEXT_TYPE_supported_groups) ||
2531  !CBB_add_u16_length_prefixed(out_compressible, &contents) ||
2532  !CBB_add_u16_length_prefixed(&contents, &groups_bytes)) {
2533  return false;
2534  }
2535 
2536  // Add a fake group. See RFC 8701.
2537  if (ssl->ctx->grease_enabled &&
2538  !CBB_add_u16(&groups_bytes,
2540  return false;
2541  }
2542 
2543  for (uint16_t group : tls1_get_grouplist(hs)) {
2545  hs->max_version < TLS1_3_VERSION) {
2546  continue;
2547  }
2548  if (!CBB_add_u16(&groups_bytes, group)) {
2549  return false;
2550  }
2551  }
2552 
2553  return CBB_flush(out_compressible);
2554 }
2555 
2557  uint8_t *out_alert,
2558  CBS *contents) {
2559  // This extension is not expected to be echoed by servers in TLS 1.2, but some
2560  // BigIP servers send it nonetheless, so do not enforce this.
2561  return true;
2562 }
2563 
2564 static bool parse_u16_array(const CBS *cbs, Array<uint16_t> *out) {
2565  CBS copy = *cbs;
2566  if ((CBS_len(&copy) & 1) != 0) {
2568  return false;
2569  }
2570 
2572  if (!ret.Init(CBS_len(&copy) / 2)) {
2573  return false;
2574  }
2575  for (size_t i = 0; i < ret.size(); i++) {
2576  if (!CBS_get_u16(&copy, &ret[i])) {
2578  return false;
2579  }
2580  }
2581 
2582  assert(CBS_len(&copy) == 0);
2583  *out = std::move(ret);
2584  return 1;
2585 }
2586 
2588  uint8_t *out_alert,
2589  CBS *contents) {
2590  if (contents == NULL) {
2591  return true;
2592  }
2593 
2594  CBS supported_group_list;
2595  if (!CBS_get_u16_length_prefixed(contents, &supported_group_list) ||
2596  CBS_len(&supported_group_list) == 0 ||
2597  CBS_len(contents) != 0 ||
2598  !parse_u16_array(&supported_group_list, &hs->peer_supported_group_list)) {
2599  return false;
2600  }
2601 
2602  return true;
2603 }
2604 
2605 
2606 // QUIC Transport Parameters
2607 
2609  const SSL_HANDSHAKE *hs, CBB *out, bool use_legacy_codepoint) {
2610  if (hs->config->quic_transport_params.empty() && !hs->ssl->quic_method) {
2611  return true;
2612  }
2613  if (hs->config->quic_transport_params.empty() || !hs->ssl->quic_method) {
2614  // QUIC Transport Parameters must be sent over QUIC, and they must not be
2615  // sent over non-QUIC transports. If transport params are set, then
2616  // SSL(_CTX)_set_quic_method must also be called.
2618  return false;
2619  }
2620  assert(hs->min_version > TLS1_2_VERSION);
2621  if (use_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
2622  // Do nothing, we'll send the other codepoint.
2623  return true;
2624  }
2625 
2627  if (hs->config->quic_use_legacy_codepoint) {
2629  }
2630 
2631  CBB contents;
2632  if (!CBB_add_u16(out, extension_type) ||
2635  hs->config->quic_transport_params.size()) ||
2636  !CBB_flush(out)) {
2637  return false;
2638  }
2639  return true;
2640 }
2641 
2643  const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible,
2646  hs, out_compressible, /*use_legacy_codepoint=*/false);
2647 }
2648 
2650  const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible,
2653  hs, out_compressible, /*use_legacy_codepoint=*/true);
2654 }
2655 
2657  SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents,
2658  bool used_legacy_codepoint) {
2659  SSL *const ssl = hs->ssl;
2660  if (contents == nullptr) {
2661  if (used_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
2662  // Silently ignore because we expect the other QUIC codepoint.
2663  return true;
2664  }
2665  if (!ssl->quic_method) {
2666  return true;
2667  }
2668  *out_alert = SSL_AD_MISSING_EXTENSION;
2669  return false;
2670  }
2671  // The extensions parser will check for unsolicited extensions before
2672  // calling the callback.
2673  assert(ssl->quic_method != nullptr);
2674  assert(ssl_protocol_version(ssl) == TLS1_3_VERSION);
2675  assert(used_legacy_codepoint == hs->config->quic_use_legacy_codepoint);
2676  return ssl->s3->peer_quic_transport_params.CopyFrom(*contents);
2677 }
2678 
2680  uint8_t *out_alert,
2681  CBS *contents) {
2683  hs, out_alert, contents, /*used_legacy_codepoint=*/false);
2684 }
2685 
2687  SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents) {
2689  hs, out_alert, contents, /*used_legacy_codepoint=*/true);
2690 }
2691 
2693  SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents,
2694  bool used_legacy_codepoint) {
2695  SSL *const ssl = hs->ssl;
2696  if (!contents) {
2697  if (!ssl->quic_method) {
2698  if (hs->config->quic_transport_params.empty()) {
2699  return true;
2700  }
2701  // QUIC transport parameters must not be set if |ssl| is not configured
2702  // for QUIC.
2704  *out_alert = SSL_AD_INTERNAL_ERROR;
2705  return false;
2706  }
2707  if (used_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
2708  // Silently ignore because we expect the other QUIC codepoint.
2709  return true;
2710  }
2711  *out_alert = SSL_AD_MISSING_EXTENSION;
2712  return false;
2713  }
2714  if (!ssl->quic_method) {
2715  if (used_legacy_codepoint) {
2716  // Ignore the legacy private-use codepoint because that could be sent
2717  // to mean something else than QUIC transport parameters.
2718  return true;
2719  }
2720  // Fail if we received the codepoint registered with IANA for QUIC
2721  // because that is not allowed outside of QUIC.
2722  *out_alert = SSL_AD_UNSUPPORTED_EXTENSION;
2723  return false;
2724  }
2725  assert(ssl_protocol_version(ssl) == TLS1_3_VERSION);
2726  if (used_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
2727  // Silently ignore because we expect the other QUIC codepoint.
2728  return true;
2729  }
2730  return ssl->s3->peer_quic_transport_params.CopyFrom(*contents);
2731 }
2732 
2734  uint8_t *out_alert,
2735  CBS *contents) {
2737  hs, out_alert, contents, /*used_legacy_codepoint=*/false);
2738 }
2739 
2741  SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents) {
2743  hs, out_alert, contents, /*used_legacy_codepoint=*/true);
2744 }
2745 
2747  SSL_HANDSHAKE *hs, CBB *out, bool use_legacy_codepoint) {
2748  if (hs->ssl->quic_method == nullptr && use_legacy_codepoint) {
2749  // Ignore the legacy private-use codepoint because that could be sent
2750  // to mean something else than QUIC transport parameters.
2751  return true;
2752  }
2753  assert(hs->ssl->quic_method != nullptr);
2754  if (hs->config->quic_transport_params.empty()) {
2755  // Transport parameters must be set when using QUIC.
2757  return false;
2758  }
2759  if (use_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
2760  // Do nothing, we'll send the other codepoint.
2761  return true;
2762  }
2763 
2765  if (hs->config->quic_use_legacy_codepoint) {
2767  }
2768 
2769  CBB contents;
2770  if (!CBB_add_u16(out, extension_type) ||
2773  hs->config->quic_transport_params.size()) ||
2774  !CBB_flush(out)) {
2775  return false;
2776  }
2777 
2778  return true;
2779 }
2780 
2782  CBB *out) {
2784  hs, out, /*use_legacy_codepoint=*/false);
2785 }
2786 
2788  CBB *out) {
2790  hs, out, /*use_legacy_codepoint=*/true);
2791 }
2792 
2793 // Delegated credentials.
2794 //
2795 // https://tools.ietf.org/html/draft-ietf-tls-subcerts
2796 
2798  const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible,
2800  return true;
2801 }
2802 
2804  uint8_t *out_alert,
2805  CBS *contents) {
2806  if (contents == nullptr || ssl_protocol_version(hs->ssl) < TLS1_3_VERSION) {
2807  // Don't use delegated credentials unless we're negotiating TLS 1.3 or
2808  // higher.
2809  return true;
2810  }
2811 
2812  // The contents of the extension are the signature algorithms the client will
2813  // accept for a delegated credential.
2814  CBS sigalg_list;
2815  if (!CBS_get_u16_length_prefixed(contents, &sigalg_list) ||
2816  CBS_len(&sigalg_list) == 0 ||
2817  CBS_len(contents) != 0 ||
2818  !parse_u16_array(&sigalg_list, &hs->peer_delegated_credential_sigalgs)) {
2819  return false;
2820  }
2821 
2822  hs->delegated_credential_requested = true;
2823  return true;
2824 }
2825 
2826 // Certificate compression
2827 
2829  CBB *out_compressible,
2831  bool first = true;
2832  CBB contents, algs;
2833 
2834  for (const auto &alg : hs->ssl->ctx->cert_compression_algs) {
2835  if (alg.decompress == nullptr) {
2836  continue;
2837  }
2838 
2839  if (first &&
2840  (!CBB_add_u16(out_compressible, TLSEXT_TYPE_cert_compression) ||
2841  !CBB_add_u16_length_prefixed(out_compressible, &contents) ||
2842  !CBB_add_u8_length_prefixed(&contents, &algs))) {
2843  return false;
2844  }
2845  first = false;
2846  if (!CBB_add_u16(&algs, alg.alg_id)) {
2847  return false;
2848  }
2849  }
2850 
2851  return first || CBB_flush(out_compressible);
2852 }
2853 
2855  uint8_t *out_alert,
2856  CBS *contents) {
2857  if (contents == nullptr) {
2858  return true;
2859  }
2860 
2861  // The server may not echo this extension. Any server to client negotiation is
2862  // advertised in the CertificateRequest message.
2863  return false;
2864 }
2865 
2867  uint8_t *out_alert,
2868  CBS *contents) {
2869  if (contents == nullptr) {
2870  return true;
2871  }
2872 
2873  const SSL_CTX *ctx = hs->ssl->ctx.get();
2874  const size_t num_algs = ctx->cert_compression_algs.size();
2875 
2876  CBS alg_ids;
2877  if (!CBS_get_u8_length_prefixed(contents, &alg_ids) ||
2878  CBS_len(contents) != 0 ||
2879  CBS_len(&alg_ids) == 0 ||
2880  CBS_len(&alg_ids) % 2 == 1) {
2881  return false;
2882  }
2883 
2884  const size_t num_given_alg_ids = CBS_len(&alg_ids) / 2;
2885  Array<uint16_t> given_alg_ids;
2886  if (!given_alg_ids.Init(num_given_alg_ids)) {
2887  return false;
2888  }
2889 
2890  size_t best_index = num_algs;
2891  size_t given_alg_idx = 0;
2892 
2893  while (CBS_len(&alg_ids) > 0) {
2894  uint16_t alg_id;
2895  if (!CBS_get_u16(&alg_ids, &alg_id)) {
2896  return false;
2897  }
2898 
2899  given_alg_ids[given_alg_idx++] = alg_id;
2900 
2901  for (size_t i = 0; i < num_algs; i++) {
2902  const auto &alg = ctx->cert_compression_algs[i];
2903  if (alg.alg_id == alg_id && alg.compress != nullptr) {
2904  if (i < best_index) {
2905  best_index = i;
2906  }
2907  break;
2908  }
2909  }
2910  }
2911 
2912  qsort(given_alg_ids.data(), given_alg_ids.size(), sizeof(uint16_t),
2914  for (size_t i = 1; i < num_given_alg_ids; i++) {
2915  if (given_alg_ids[i - 1] == given_alg_ids[i]) {
2916  return false;
2917  }
2918  }
2919 
2920  if (best_index < num_algs &&
2922  hs->cert_compression_negotiated = true;
2923  hs->cert_compression_alg_id = ctx->cert_compression_algs[best_index].alg_id;
2924  }
2925 
2926  return true;
2927 }
2928 
2930  return true;
2931 }
2932 
2933 // Application-level Protocol Settings
2934 //
2935 // https://tools.ietf.org/html/draft-vvv-tls-alps-01
2936 
2938  Span<const uint8_t> *out_settings,
2940  for (const ALPSConfig &config : hs->config->alps_configs) {
2941  if (protocol == config.protocol) {
2942  *out_settings = config.settings;
2943  return true;
2944  }
2945  }
2946  return false;
2947 }
2948 
2950  CBB *out_compressible,
2952  const SSL *const ssl = hs->ssl;
2953  if (// ALPS requires TLS 1.3.
2954  hs->max_version < TLS1_3_VERSION ||
2955  // Do not offer ALPS without ALPN.
2957  // Do not offer ALPS if not configured.
2958  hs->config->alps_configs.empty() ||
2959  // Do not offer ALPS on renegotiation handshakes.
2960  ssl->s3->initial_handshake_complete) {
2961  return true;
2962  }
2963 
2964  CBB contents, proto_list, proto;
2965  if (!CBB_add_u16(out_compressible, TLSEXT_TYPE_application_settings) ||
2966  !CBB_add_u16_length_prefixed(out_compressible, &contents) ||
2967  !CBB_add_u16_length_prefixed(&contents, &proto_list)) {
2968  return false;
2969  }
2970 
2971  for (const ALPSConfig &config : hs->config->alps_configs) {
2972  if (!CBB_add_u8_length_prefixed(&proto_list, &proto) ||
2973  !CBB_add_bytes(&proto, config.protocol.data(),
2974  config.protocol.size())) {
2975  return false;
2976  }
2977  }
2978 
2979  return CBB_flush(out_compressible);
2980 }
2981 
2983  CBS *contents) {
2984  SSL *const ssl = hs->ssl;
2985  if (contents == nullptr) {
2986  return true;
2987  }
2988 
2989  assert(!ssl->s3->initial_handshake_complete);
2990  assert(!hs->config->alpn_client_proto_list.empty());
2991  assert(!hs->config->alps_configs.empty());
2992 
2993  // ALPS requires TLS 1.3.
2994  if (ssl_protocol_version(ssl) < TLS1_3_VERSION) {
2995  *out_alert = SSL_AD_UNSUPPORTED_EXTENSION;
2997  return false;
2998  }
2999 
3000  // Note extension callbacks may run in any order, so we defer checking
3001  // consistency with ALPN to |ssl_check_serverhello_tlsext|.
3002  if (!hs->new_session->peer_application_settings.CopyFrom(*contents)) {
3003  *out_alert = SSL_AD_INTERNAL_ERROR;
3004  return false;
3005  }
3006 
3007  hs->new_session->has_application_settings = true;
3008  return true;
3009 }
3010 
3012  SSL *const ssl = hs->ssl;
3013  // If early data is accepted, we omit the ALPS extension. It is implicitly
3014  // carried over from the previous connection.
3015  if (hs->new_session == nullptr ||
3016  !hs->new_session->has_application_settings ||
3017  ssl->s3->early_data_accepted) {
3018  return true;
3019  }
3020 
3021  CBB contents;
3025  hs->new_session->local_application_settings.data(),
3026  hs->new_session->local_application_settings.size()) ||
3027  !CBB_flush(out)) {
3028  return false;
3029  }
3030 
3031  return true;
3032 }
3033 
3035  const SSL_CLIENT_HELLO *client_hello) {
3036  SSL *const ssl = hs->ssl;
3037  if (ssl->s3->alpn_selected.empty()) {
3038  return true;
3039  }
3040 
3041  // If we negotiate ALPN over TLS 1.3, try to negotiate ALPS.
3042  CBS alps_contents;
3044  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION &&
3046  ssl->s3->alpn_selected) &&
3047  ssl_client_hello_get_extension(client_hello, &alps_contents,
3049  // Check if the client supports ALPS with the selected ALPN.
3050  bool found = false;
3051  CBS alps_list;
3052  if (!CBS_get_u16_length_prefixed(&alps_contents, &alps_list) ||
3053  CBS_len(&alps_contents) != 0 ||
3054  CBS_len(&alps_list) == 0) {
3056  *out_alert = SSL_AD_DECODE_ERROR;
3057  return false;
3058  }
3059  while (CBS_len(&alps_list) > 0) {
3060  CBS protocol_name;
3061  if (!CBS_get_u8_length_prefixed(&alps_list, &protocol_name) ||
3062  // Empty protocol names are forbidden.
3063  CBS_len(&protocol_name) == 0) {
3065  *out_alert = SSL_AD_DECODE_ERROR;
3066  return false;
3067  }
3068  if (protocol_name == MakeConstSpan(ssl->s3->alpn_selected)) {
3069  found = true;
3070  }
3071  }
3072 
3073  // Negotiate ALPS if both client also supports ALPS for this protocol.
3074  if (found) {
3075  hs->new_session->has_application_settings = true;
3076  if (!hs->new_session->local_application_settings.CopyFrom(settings)) {
3077  *out_alert = SSL_AD_INTERNAL_ERROR;
3078  return false;
3079  }
3080  }
3081  }
3082 
3083  return true;
3084 }
3085 
3086 // kExtensions contains all the supported extensions.
3087 static const struct tls_extension kExtensions[] = {
3088  {
3094  },
3095  {
3101  },
3102  {
3108  },
3109  {
3115  },
3116  {
3122  },
3123  {
3129  },
3130  {
3134  // Ticket extension client parsing is handled in ssl_session.c
3137  },
3138  {
3142  // ALPN is negotiated late in |ssl_negotiate_alpn|.
3145  },
3146  {
3152  },
3153  {
3159  },
3160  {
3166  },
3167  {
3173  },
3174  {
3180  },
3181  {
3187  },
3188  {
3194  },
3195  {
3201  },
3202  {
3208  },
3209  {
3215  },
3216  {
3222  },
3223  {
3229  },
3230  {
3236  },
3237  {
3243  },
3244  {
3250  },
3251  {
3255  // ALPS is negotiated late in |ssl_negotiate_alpn|.
3258  },
3259 };
3260 
3261 #define kNumExtensions (sizeof(kExtensions) / sizeof(struct tls_extension))
3262 
3263 static_assert(kNumExtensions <=
3264  sizeof(((SSL_HANDSHAKE *)NULL)->extensions.sent) * 8,
3265  "too many extensions for sent bitset");
3266 static_assert(kNumExtensions <=
3267  sizeof(((SSL_HANDSHAKE *)NULL)->extensions.received) * 8,
3268  "too many extensions for received bitset");
3269 
3271  if (!hs->config->permute_extensions) {
3272  return true;
3273  }
3274 
3275  static_assert(kNumExtensions <= UINT8_MAX,
3276  "extensions_permutation type is too small");
3277  uint32_t seeds[kNumExtensions - 1];
3278  Array<uint8_t> permutation;
3279  if (!RAND_bytes(reinterpret_cast<uint8_t *>(seeds), sizeof(seeds)) ||
3280  !permutation.Init(kNumExtensions)) {
3281  return false;
3282  }
3283  for (size_t i = 0; i < kNumExtensions; i++) {
3284  permutation[i] = i;
3285  }
3286  for (size_t i = kNumExtensions - 1; i > 0; i--) {
3287  // Set element |i| to a randomly-selected element 0 <= j <= i.
3288  std::swap(permutation[i], permutation[seeds[i - 1] % (i + 1)]);
3289  }
3290  hs->extension_permutation = std::move(permutation);
3291  return true;
3292 }
3293 
3294 static const struct tls_extension *tls_extension_find(uint32_t *out_index,
3295  uint16_t value) {
3296  unsigned i;
3297  for (i = 0; i < kNumExtensions; i++) {
3298  if (kExtensions[i].value == value) {
3299  *out_index = i;
3300  return &kExtensions[i];
3301  }
3302  }
3303 
3304  return NULL;
3305 }
3306 
3307 static bool add_padding_extension(CBB *cbb, uint16_t ext, size_t len) {
3308  CBB child;
3309  if (!CBB_add_u16(cbb, ext) || //
3311  !CBB_add_zeros(&child, len)) {
3313  return false;
3314  }
3315  return CBB_flush(cbb);
3316 }
3317 
3319  CBB *out_encoded,
3320  bool *out_needs_psk_binder) {
3321  // When writing ClientHelloInner, we construct the real and encoded
3322  // ClientHellos concurrently, to handle compression. Uncompressed extensions
3323  // are written to |extensions| and copied to |extensions_encoded|. Compressed
3324  // extensions are buffered in |compressed| and written to the end. (ECH can
3325  // only compress continguous extensions.)
3326  SSL *const ssl = hs->ssl;
3327  bssl::ScopedCBB compressed, outer_extensions;
3328  CBB extensions, extensions_encoded;
3330  !CBB_add_u16_length_prefixed(out_encoded, &extensions_encoded) ||
3331  !CBB_init(compressed.get(), 64) ||
3332  !CBB_init(outer_extensions.get(), 64)) {
3334  return false;
3335  }
3336 
3337  hs->inner_extensions_sent = 0;
3338 
3339  if (ssl->ctx->grease_enabled) {
3340  // Add a fake empty extension. See RFC 8701. This always matches
3341  // |ssl_add_clienthello_tlsext|, so compress it.
3343  if (!add_padding_extension(compressed.get(), grease_ext, 0) ||
3344  !CBB_add_u16(outer_extensions.get(), grease_ext)) {
3345  return false;
3346  }
3347  }
3348 
3349  for (size_t unpermuted = 0; unpermuted < kNumExtensions; unpermuted++) {
3350  size_t i = hs->extension_permutation.empty()
3351  ? unpermuted
3352  : hs->extension_permutation[unpermuted];
3353  const size_t len_before = CBB_len(&extensions);
3354  const size_t len_compressed_before = CBB_len(compressed.get());
3355  if (!kExtensions[i].add_clienthello(hs, &extensions, compressed.get(),
3358  ERR_add_error_dataf("extension %u", (unsigned)kExtensions[i].value);
3359  return false;
3360  }
3361 
3362  const size_t bytes_written = CBB_len(&extensions) - len_before;
3363  const size_t bytes_written_compressed =
3364  CBB_len(compressed.get()) - len_compressed_before;
3365  // The callback may write to at most one output.
3366  assert(bytes_written == 0 || bytes_written_compressed == 0);
3367  if (bytes_written != 0 || bytes_written_compressed != 0) {
3368  hs->inner_extensions_sent |= (1u << i);
3369  }
3370  // If compressed, update the running ech_outer_extensions extension.
3371  if (bytes_written_compressed != 0 &&
3372  !CBB_add_u16(outer_extensions.get(), kExtensions[i].value)) {
3373  return false;
3374  }
3375  }
3376 
3377  if (ssl->ctx->grease_enabled) {
3378  // Add a fake non-empty extension. See RFC 8701. This always matches
3379  // |ssl_add_clienthello_tlsext|, so compress it.
3381  if (!add_padding_extension(compressed.get(), grease_ext, 1) ||
3382  !CBB_add_u16(outer_extensions.get(), grease_ext)) {
3383  return false;
3384  }
3385  }
3386 
3387  // Uncompressed extensions are encoded as-is.
3388  if (!CBB_add_bytes(&extensions_encoded, CBB_data(&extensions),
3389  CBB_len(&extensions))) {
3390  return false;
3391  }
3392 
3393  // Flush all the compressed extensions.
3394  if (CBB_len(compressed.get()) != 0) {
3395  CBB extension, child;
3396  // Copy them as-is in the real ClientHelloInner.
3397  if (!CBB_add_bytes(&extensions, CBB_data(compressed.get()),
3398  CBB_len(compressed.get())) ||
3399  // Replace with ech_outer_extensions in the encoded form.
3400  !CBB_add_u16(&extensions_encoded, TLSEXT_TYPE_ech_outer_extensions) ||
3401  !CBB_add_u16_length_prefixed(&extensions_encoded, &extension) ||
3403  !CBB_add_bytes(&child, CBB_data(outer_extensions.get()),
3404  CBB_len(outer_extensions.get())) ||
3405  !CBB_flush(&extensions_encoded)) {
3406  return false;
3407  }
3408  }
3409 
3410  // The PSK extension must be last. It is never compressed. Note, if there is a
3411  // binder, the caller will need to update both ClientHelloInner and
3412  // EncodedClientHelloInner after computing it.
3413  const size_t len_before = CBB_len(&extensions);
3414  if (!ext_pre_shared_key_add_clienthello(hs, &extensions, out_needs_psk_binder,
3416  !CBB_add_bytes(&extensions_encoded, CBB_data(&extensions) + len_before,
3417  CBB_len(&extensions) - len_before) ||
3418  !CBB_flush(out) || //
3419  !CBB_flush(out_encoded)) {
3420  return false;
3421  }
3422 
3423  return true;
3424 }
3425 
3427  bool *out_needs_psk_binder,
3429  size_t header_len) {
3430  *out_needs_psk_binder = false;
3431 
3432  if (type == ssl_client_hello_inner) {
3433  return ssl_add_clienthello_tlsext_inner(hs, out, out_encoded,
3434  out_needs_psk_binder);
3435  }
3436 
3437  assert(out_encoded == nullptr); // Only ClientHelloInner needs two outputs.
3438  SSL *const ssl = hs->ssl;
3439  CBB extensions;
3442  return false;
3443  }
3444 
3445  // Note we may send multiple ClientHellos for DTLS HelloVerifyRequest and TLS
3446  // 1.3 HelloRetryRequest. For the latter, the extensions may change, so it is
3447  // important to reset this value.
3448  hs->extensions.sent = 0;
3449 
3450  // Add a fake empty extension. See RFC 8701.
3451  if (ssl->ctx->grease_enabled &&
3454  return false;
3455  }
3456 
3457  bool last_was_empty = false;
3458  for (size_t unpermuted = 0; unpermuted < kNumExtensions; unpermuted++) {
3459  size_t i = hs->extension_permutation.empty()
3460  ? unpermuted
3461  : hs->extension_permutation[unpermuted];
3462  const size_t len_before = CBB_len(&extensions);
3465  ERR_add_error_dataf("extension %u", (unsigned)kExtensions[i].value);
3466  return false;
3467  }
3468 
3469  const size_t bytes_written = CBB_len(&extensions) - len_before;
3470  if (bytes_written != 0) {
3471  hs->extensions.sent |= (1u << i);
3472  }
3473  // If the difference in lengths is only four bytes then the extension had
3474  // an empty body.
3475  last_was_empty = (bytes_written == 4);
3476  }
3477 
3478  if (ssl->ctx->grease_enabled) {
3479  // Add a fake non-empty extension. See RFC 8701.
3480  if (!add_padding_extension(
3482  return false;
3483  }
3484  last_was_empty = false;
3485  }
3486 
3487  // In cleartext ClientHellos, we add the padding extension to work around
3488  // bugs. We also apply this padding to ClientHelloOuter, to keep the wire
3489  // images aligned.
3490  size_t psk_extension_len = ext_pre_shared_key_clienthello_length(hs, type);
3491  if (!SSL_is_dtls(ssl) && !ssl->quic_method &&
3492  !ssl->s3->used_hello_retry_request) {
3493  header_len +=
3494  SSL3_HM_HEADER_LENGTH + 2 + CBB_len(&extensions) + psk_extension_len;
3495  size_t padding_len = 0;
3496 
3497  // The final extension must be non-empty. WebSphere Application
3498  // Server 7.0 is intolerant to the last extension being zero-length. See
3499  // https://crbug.com/363583.
3500  if (last_was_empty && psk_extension_len == 0) {
3501  padding_len = 1;
3502  // The addition of the padding extension may push us into the F5 bug.
3503  header_len += 4 + padding_len;
3504  }
3505 
3506  // Add padding to workaround bugs in F5 terminators. See RFC 7685.
3507  //
3508  // NB: because this code works out the length of all existing extensions
3509  // it MUST always appear last (save for any PSK extension).
3510  if (header_len > 0xff && header_len < 0x200) {
3511  // If our calculations already included a padding extension, remove that
3512  // factor because we're about to change its length.
3513  if (padding_len != 0) {
3514  header_len -= 4 + padding_len;
3515  }
3516  padding_len = 0x200 - header_len;
3517  // Extensions take at least four bytes to encode. Always include at least
3518  // one byte of data if including the extension. WebSphere Application
3519  // Server 7.0 is intolerant to the last extension being zero-length. See
3520  // https://crbug.com/363583.
3521  if (padding_len >= 4 + 1) {
3522  padding_len -= 4;
3523  } else {
3524  padding_len = 1;
3525  }
3526  }
3527 
3528  if (padding_len != 0 &&
3530  return false;
3531  }
3532  }
3533 
3534  // The PSK extension must be last, including after the padding.
3535  const size_t len_before = CBB_len(&extensions);
3536  if (!ext_pre_shared_key_add_clienthello(hs, &extensions, out_needs_psk_binder,
3537  type)) {
3539  return false;
3540  }
3541  assert(psk_extension_len == CBB_len(&extensions) - len_before);
3542  (void)len_before; // |assert| is omitted in release builds.
3543 
3544  // Discard empty extensions blocks.
3545  if (CBB_len(&extensions) == 0) {
3547  }
3548 
3549  return CBB_flush(out);
3550 }
3551 
3553  SSL *const ssl = hs->ssl;
3554  CBB extensions;
3556  goto err;
3557  }
3558 
3559  for (unsigned i = 0; i < kNumExtensions; i++) {
3560  if (!(hs->extensions.received & (1u << i))) {
3561  // Don't send extensions that were not received.
3562  continue;
3563  }
3564 
3565  if (!kExtensions[i].add_serverhello(hs, &extensions)) {
3567  ERR_add_error_dataf("extension %u", (unsigned)kExtensions[i].value);
3568  goto err;
3569  }
3570  }
3571 
3572  // Discard empty extensions blocks before TLS 1.3.
3573  if (ssl_protocol_version(ssl) < TLS1_3_VERSION &&
3574  CBB_len(&extensions) == 0) {
3576  }
3577 
3578  return CBB_flush(out);
3579 
3580 err:
3582  return false;
3583 }
3584 
3586  const SSL_CLIENT_HELLO *client_hello,
3587  int *out_alert) {
3588  hs->extensions.received = 0;
3589  CBS extensions;
3590  CBS_init(&extensions, client_hello->extensions, client_hello->extensions_len);
3591  while (CBS_len(&extensions) != 0) {
3592  uint16_t type;
3593  CBS extension;
3594 
3595  // Decode the next extension.
3596  if (!CBS_get_u16(&extensions, &type) ||
3598  *out_alert = SSL_AD_DECODE_ERROR;
3599  return false;
3600  }
3601 
3602  unsigned ext_index;
3603  const struct tls_extension *const ext =
3604  tls_extension_find(&ext_index, type);
3605  if (ext == NULL) {
3606  continue;
3607  }
3608 
3609  hs->extensions.received |= (1u << ext_index);
3610  uint8_t alert = SSL_AD_DECODE_ERROR;
3611  if (!ext->parse_clienthello(hs, &alert, &extension)) {
3612  *out_alert = alert;
3614  ERR_add_error_dataf("extension %u", (unsigned)type);
3615  return false;
3616  }
3617  }
3618 
3619  for (size_t i = 0; i < kNumExtensions; i++) {
3620  if (hs->extensions.received & (1u << i)) {
3621  continue;
3622  }
3623 
3624  CBS *contents = NULL, fake_contents;
3625  static const uint8_t kFakeRenegotiateExtension[] = {0};
3628  SSL3_CK_SCSV & 0xffff)) {
3629  // The renegotiation SCSV was received so pretend that we received a
3630  // renegotiation extension.
3631  CBS_init(&fake_contents, kFakeRenegotiateExtension,
3632  sizeof(kFakeRenegotiateExtension));
3633  contents = &fake_contents;
3634  hs->extensions.received |= (1u << i);
3635  }
3636 
3637  // Extension wasn't observed so call the callback with a NULL
3638  // parameter.
3639  uint8_t alert = SSL_AD_DECODE_ERROR;
3640  if (!kExtensions[i].parse_clienthello(hs, &alert, contents)) {
3642  ERR_add_error_dataf("extension %u", (unsigned)kExtensions[i].value);
3643  *out_alert = alert;
3644  return false;
3645  }
3646  }
3647 
3648  return true;
3649 }
3650 
3652  const SSL_CLIENT_HELLO *client_hello) {
3653  SSL *const ssl = hs->ssl;
3654  int alert = SSL_AD_DECODE_ERROR;
3655  if (!ssl_scan_clienthello_tlsext(hs, client_hello, &alert)) {
3656  ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
3657  return false;
3658  }
3659 
3660  if (!ssl_check_clienthello_tlsext(hs)) {
3662  return false;
3663  }
3664 
3665  return true;
3666 }
3667 
3669  int *out_alert) {
3670  CBS extensions = *cbs;
3672  *out_alert = SSL_AD_DECODE_ERROR;
3673  return false;
3674  }
3675 
3676  uint32_t received = 0;
3677  while (CBS_len(&extensions) != 0) {
3678  uint16_t type;
3679  CBS extension;
3680 
3681  // Decode the next extension.
3682  if (!CBS_get_u16(&extensions, &type) ||
3684  *out_alert = SSL_AD_DECODE_ERROR;
3685  return false;
3686  }
3687 
3688  unsigned ext_index;
3689  const struct tls_extension *const ext =
3690  tls_extension_find(&ext_index, type);
3691 
3692  if (ext == NULL) {
3694  ERR_add_error_dataf("extension %u", (unsigned)type);
3695  *out_alert = SSL_AD_UNSUPPORTED_EXTENSION;
3696  return false;
3697  }
3698 
3699  static_assert(kNumExtensions <= sizeof(hs->extensions.sent) * 8,
3700  "too many bits");
3701 
3702  if (!(hs->extensions.sent & (1u << ext_index))) {
3703  // If the extension was never sent then it is illegal.
3705  ERR_add_error_dataf("extension :%u", (unsigned)type);
3706  *out_alert = SSL_AD_UNSUPPORTED_EXTENSION;
3707  return false;
3708  }
3709 
3710  received |= (1u << ext_index);
3711 
3712  uint8_t alert = SSL_AD_DECODE_ERROR;
3713  if (!ext->parse_serverhello(hs, &alert, &extension)) {
3715  ERR_add_error_dataf("extension %u", (unsigned)type);
3716  *out_alert = alert;
3717  return false;
3718  }
3719  }
3720 
3721  for (size_t i = 0; i < kNumExtensions; i++) {
3722  if (!(received & (1u << i))) {
3723  // Extension wasn't observed so call the callback with a NULL
3724  // parameter.
3725  uint8_t alert = SSL_AD_DECODE_ERROR;
3726  if (!kExtensions[i].parse_serverhello(hs, &alert, NULL)) {
3728  ERR_add_error_dataf("extension %u", (unsigned)kExtensions[i].value);
3729  *out_alert = alert;
3730  return false;
3731  }
3732  }
3733  }
3734 
3735  return true;
3736 }
3737 
3739  SSL *const ssl = hs->ssl;
3740  int ret = SSL_TLSEXT_ERR_NOACK;
3741  int al = SSL_AD_UNRECOGNIZED_NAME;
3742  if (ssl->ctx->servername_callback != 0) {
3743  ret = ssl->ctx->servername_callback(ssl, &al, ssl->ctx->servername_arg);
3744  } else if (ssl->session_ctx->servername_callback != 0) {
3745  ret = ssl->session_ctx->servername_callback(
3746  ssl, &al, ssl->session_ctx->servername_arg);
3747  }
3748 
3749  switch (ret) {
3751  ssl_send_alert(ssl, SSL3_AL_FATAL, al);
3752  return false;
3753 
3754  case SSL_TLSEXT_ERR_NOACK:
3755  hs->should_ack_sni = false;
3756  return true;
3757 
3758  default:
3759  return true;
3760  }
3761 }
3762 
3764  SSL *const ssl = hs->ssl;
3765  // ALPS and ALPN have a dependency between each other, so we defer checking
3766  // consistency to after the callbacks run.
3767  if (hs->new_session != nullptr && hs->new_session->has_application_settings) {
3768  // ALPN must be negotiated.
3769  if (ssl->s3->alpn_selected.empty()) {
3772  return false;
3773  }
3774 
3775  // The negotiated protocol must be one of the ones we advertised for ALPS.
3778  ssl->s3->alpn_selected)) {
3781  return false;
3782  }
3783 
3784  if (!hs->new_session->local_application_settings.CopyFrom(settings)) {
3786  return false;
3787  }
3788  }
3789 
3790  return true;
3791 }
3792 
3794  SSL *const ssl = hs->ssl;
3795  int alert = SSL_AD_DECODE_ERROR;
3796  if (!ssl_scan_serverhello_tlsext(hs, cbs, &alert)) {
3797  ssl_send_alert(ssl, SSL3_AL_FATAL, alert);
3798  return false;
3799  }
3800 
3801  if (!ssl_check_serverhello_tlsext(hs)) {
3802  return false;
3803  }
3804 
3805  return true;
3806 }
3807 
3808 static enum ssl_ticket_aead_result_t decrypt_ticket_with_cipher_ctx(
3809  Array<uint8_t> *out, EVP_CIPHER_CTX *cipher_ctx, HMAC_CTX *hmac_ctx,
3810  Span<const uint8_t> ticket) {
3811  size_t iv_len = EVP_CIPHER_CTX_iv_length(cipher_ctx);
3812 
3813  // Check the MAC at the end of the ticket.
3814  uint8_t mac[EVP_MAX_MD_SIZE];
3815  size_t mac_len = HMAC_size(hmac_ctx);
3816  if (ticket.size() < SSL_TICKET_KEY_NAME_LEN + iv_len + 1 + mac_len) {
3817  // The ticket must be large enough for key name, IV, data, and MAC.
3819  }
3820  // Split the ticket into the ticket and the MAC.
3821  auto ticket_mac = ticket.last(mac_len);
3822  ticket = ticket.first(ticket.size() - mac_len);
3823  HMAC_Update(hmac_ctx, ticket.data(), ticket.size());
3824  HMAC_Final(hmac_ctx, mac, NULL);
3825  assert(mac_len == ticket_mac.size());
3826  bool mac_ok = CRYPTO_memcmp(mac, ticket_mac.data(), mac_len) == 0;
3827 #if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
3828  mac_ok = true;
3829 #endif
3830  if (!mac_ok) {
3832  }
3833 
3834  // Decrypt the session data.
3835  auto ciphertext = ticket.subspan(SSL_TICKET_KEY_NAME_LEN + iv_len);
3837 #if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
3838  if (!plaintext.CopyFrom(ciphertext)) {
3839  return ssl_ticket_aead_error;
3840  }
3841 #else
3842  if (ciphertext.size() >= INT_MAX) {
3844  }
3845  if (!plaintext.Init(ciphertext.size())) {
3846  return ssl_ticket_aead_error;
3847  }
3848  int len1, len2;
3849  if (!EVP_DecryptUpdate(cipher_ctx, plaintext.data(), &len1, ciphertext.data(),
3850  (int)ciphertext.size()) ||
3851  !EVP_DecryptFinal_ex(cipher_ctx, plaintext.data() + len1, &len2)) {
3852  ERR_clear_error();
3854  }
3855  plaintext.Shrink(static_cast<size_t>(len1) + len2);
3856 #endif
3857 
3858  *out = std::move(plaintext);
3859  return ssl_ticket_aead_success;
3860 }
3861 
3862 static enum ssl_ticket_aead_result_t ssl_decrypt_ticket_with_cb(
3863  SSL_HANDSHAKE *hs, Array<uint8_t> *out, bool *out_renew_ticket,
3864  Span<const uint8_t> ticket) {
3865  assert(ticket.size() >= SSL_TICKET_KEY_NAME_LEN + EVP_MAX_IV_LENGTH);
3866  ScopedEVP_CIPHER_CTX cipher_ctx;
3867  ScopedHMAC_CTX hmac_ctx;
3868  auto name = ticket.subspan(0, SSL_TICKET_KEY_NAME_LEN);
3869  // The actual IV is shorter, but the length is determined by the callback's
3870  // chosen cipher. Instead we pass in |EVP_MAX_IV_LENGTH| worth of IV to ensure
3871  // the callback has enough.
3873  int cb_ret = hs->ssl->session_ctx->ticket_key_cb(
3874  hs->ssl, const_cast<uint8_t *>(name.data()),
3875  const_cast<uint8_t *>(iv.data()), cipher_ctx.get(), hmac_ctx.get(),
3876  0 /* decrypt */);
3877  if (cb_ret < 0) {
3878  return ssl_ticket_aead_error;
3879  } else if (cb_ret == 0) {
3881  } else if (cb_ret == 2) {
3882  *out_renew_ticket = true;
3883  } else {
3884  assert(cb_ret == 1);
3885  }
3886  return decrypt_ticket_with_cipher_ctx(out, cipher_ctx.get(), hmac_ctx.get(),
3887  ticket);
3888 }
3889 
3890 static enum ssl_ticket_aead_result_t ssl_decrypt_ticket_with_ticket_keys(
3892  assert(ticket.size() >= SSL_TICKET_KEY_NAME_LEN + EVP_MAX_IV_LENGTH);
3893  SSL_CTX *ctx = hs->ssl->session_ctx.get();
3894 
3895  // Rotate the ticket key if necessary.
3897  return ssl_ticket_aead_error;
3898  }
3899 
3900  const EVP_CIPHER *cipher = EVP_aes_128_cbc();
3901  auto name = ticket.subspan(0, SSL_TICKET_KEY_NAME_LEN);
3902  auto iv =
3904 
3905  // Pick the matching ticket key and decrypt.
3906  ScopedEVP_CIPHER_CTX cipher_ctx;
3907  ScopedHMAC_CTX hmac_ctx;
3908  {
3909  MutexReadLock lock(&ctx->lock);
3910  const TicketKey *key;
3911  if (ctx->ticket_key_current && name == ctx->ticket_key_current->name) {
3912  key = ctx->ticket_key_current.get();
3913  } else if (ctx->ticket_key_prev && name == ctx->ticket_key_prev->name) {
3914  key = ctx->ticket_key_prev.get();
3915  } else {
3917  }
3918  if (!HMAC_Init_ex(hmac_ctx.get(), key->hmac_key, sizeof(key->hmac_key),
3919  tlsext_tick_md(), NULL) ||
3920  !EVP_DecryptInit_ex(cipher_ctx.get(), cipher, NULL,
3921  key->aes_key, iv.data())) {
3922  return ssl_ticket_aead_error;
3923  }
3924  }
3925  return decrypt_ticket_with_cipher_ctx(out, cipher_ctx.get(), hmac_ctx.get(),
3926  ticket);
3927 }
3928 
3929 static enum ssl_ticket_aead_result_t ssl_decrypt_ticket_with_method(
3930  SSL_HANDSHAKE *hs, Array<uint8_t> *out, bool *out_renew_ticket,
3931  Span<const uint8_t> ticket) {
3933  if (!plaintext.Init(ticket.size())) {
3935  return ssl_ticket_aead_error;
3936  }
3937 
3938  size_t plaintext_len;
3939  const enum ssl_ticket_aead_result_t result =
3940  hs->ssl->session_ctx->ticket_aead_method->open(
3941  hs->ssl, plaintext.data(), &plaintext_len, ticket.size(),
3942  ticket.data(), ticket.size());
3944  return result;
3945  }
3946 
3947  plaintext.Shrink(plaintext_len);
3948  *out = std::move(plaintext);
3949  return ssl_ticket_aead_success;
3950 }
3951 
3952 enum ssl_ticket_aead_result_t ssl_process_ticket(
3953  SSL_HANDSHAKE *hs, UniquePtr<SSL_SESSION> *out_session,
3954  bool *out_renew_ticket, Span<const uint8_t> ticket,
3955  Span<const uint8_t> session_id) {
3956  SSL *const ssl = hs->ssl;
3957  *out_renew_ticket = false;
3958  out_session->reset();
3959 
3960  if ((SSL_get_options(hs->ssl) & SSL_OP_NO_TICKET) ||
3961  session_id.size() > SSL_MAX_SSL_SESSION_ID_LENGTH) {
3963  }
3964 
3965  // Tickets in TLS 1.3 are tied into pre-shared keys (PSKs), unlike in TLS 1.2
3966  // where that concept doesn't exist. The |decrypted_psk| and |ignore_psk|
3967  // hints only apply to PSKs. We check the version to determine which this is.
3968  const bool is_psk = ssl_protocol_version(ssl) >= TLS1_3_VERSION;
3969 
3971  enum ssl_ticket_aead_result_t result;
3972  SSL_HANDSHAKE_HINTS *const hints = hs->hints.get();
3973  if (is_psk && hints && !hs->hints_requested &&
3974  !hints->decrypted_psk.empty()) {
3977  } else if (is_psk && hints && !hs->hints_requested && hints->ignore_psk) {
3979  } else if (ssl->session_ctx->ticket_aead_method != NULL) {
3980  result = ssl_decrypt_ticket_with_method(hs, &plaintext, out_renew_ticket,
3981  ticket);
3982  } else {
3983  // Ensure there is room for the key name and the largest IV |ticket_key_cb|
3984  // may try to consume. The real limit may be lower, but the maximum IV
3985  // length should be well under the minimum size for the session material and
3986  // HMAC.
3987  if (ticket.size() < SSL_TICKET_KEY_NAME_LEN + EVP_MAX_IV_LENGTH) {
3989  } else if (ssl->session_ctx->ticket_key_cb != NULL) {
3990  result =
3991  ssl_decrypt_ticket_with_cb(hs, &plaintext, out_renew_ticket, ticket);
3992  } else {
3994  }
3995  }
3996 
3997  if (is_psk && hints && hs->hints_requested) {
3999  hints->ignore_psk = true;
4000  } else if (result == ssl_ticket_aead_success &&
4001  !hints->decrypted_psk.CopyFrom(plaintext)) {
4002  return ssl_ticket_aead_error;
4003  }
4004  }
4005 
4007  return result;
4008  }
4009 
4010  // Decode the session.
4011  UniquePtr<SSL_SESSION> session(SSL_SESSION_from_bytes(
4012  plaintext.data(), plaintext.size(), ssl->ctx.get()));
4013  if (!session) {
4014  ERR_clear_error(); // Don't leave an error on the queue.
4016  }
4017 
4018  // Envoy's tests expect the session to have a session ID that matches the
4019  // placeholder used by the client. It's unclear whether this is a good idea,
4020  // but we maintain it for now.
4021  SHA256(ticket.data(), ticket.size(), session->session_id);
4022  // Other consumers may expect a non-empty session ID to indicate resumption.
4023  session->session_id_length = SHA256_DIGEST_LENGTH;
4024 
4025  *out_session = std::move(session);
4026  return ssl_ticket_aead_success;
4027 }
4028 
4029 bool tls1_parse_peer_sigalgs(SSL_HANDSHAKE *hs, const CBS *in_sigalgs) {
4030  // Extension ignored for inappropriate versions
4032  return true;
4033  }
4034 
4035  // In all contexts, the signature algorithms list may not be empty. (It may be
4036  // omitted by clients in TLS 1.2, but then the entire extension is omitted.)
4037  return CBS_len(in_sigalgs) != 0 &&
4038  parse_u16_array(in_sigalgs, &hs->peer_sigalgs);
4039 }
4040 
4042  switch (EVP_PKEY_id(pkey)) {
4043  case EVP_PKEY_RSA:
4045  return true;
4046  case EVP_PKEY_EC:
4048  return true;
4049  default:
4050  return false;
4051  }
4052 }
4053 
4055  SSL *const ssl = hs->ssl;
4056  CERT *cert = hs->config->cert.get();
4057  DC *dc = cert->dc.get();
4058 
4059  // Before TLS 1.2, the signature algorithm isn't negotiated as part of the
4060  // handshake.
4061  if (ssl_protocol_version(ssl) < TLS1_2_VERSION) {
4064  return false;
4065  }
4066  return true;
4067  }
4068 
4070  if (ssl_signing_with_dc(hs)) {
4071  sigalgs = MakeConstSpan(&dc->expected_cert_verify_algorithm, 1);
4072  } else if (!cert->sigalgs.empty()) {
4073  sigalgs = cert->sigalgs;
4074  }
4075 
4077 
4078  for (uint16_t sigalg : sigalgs) {
4079  // SSL_SIGN_RSA_PKCS1_MD5_SHA1 is an internal value and should never be
4080  // negotiated.
4081  if (sigalg == SSL_SIGN_RSA_PKCS1_MD5_SHA1 ||
4083  continue;
4084  }
4085 
4086  for (uint16_t peer_sigalg : peer_sigalgs) {
4087  if (sigalg == peer_sigalg) {
4088  *out = sigalg;
4089  return true;
4090  }
4091  }
4092  }
4093 
4095  return false;
4096 }
4097 
4099  Span<const uint16_t> peer_sigalgs = hs->peer_sigalgs;
4100  if (peer_sigalgs.empty() && ssl_protocol_version(hs->ssl) < TLS1_3_VERSION) {
4101  // If the client didn't specify any signature_algorithms extension then
4102  // we can assume that it supports SHA1. See
4103  // http://tools.ietf.org/html/rfc5246#section-7.4.1.4.1
4104  static const uint16_t kDefaultPeerAlgorithms[] = {SSL_SIGN_RSA_PKCS1_SHA1,
4106  peer_sigalgs = kDefaultPeerAlgorithms;
4107  }
4108  return peer_sigalgs;
4109 }
4110 
4112  SSL *const ssl = hs->ssl;
4113  // A Channel ID handshake message is structured to contain multiple
4114  // extensions, but the only one that can be present is Channel ID.
4115  uint16_t extension_type;
4116  CBS channel_id = msg.body, extension;
4117  if (!CBS_get_u16(&channel_id, &extension_type) ||
4118  !CBS_get_u16_length_prefixed(&channel_id, &extension) ||
4119  CBS_len(&channel_id) != 0 ||
4120  extension_type != TLSEXT_TYPE_channel_id ||
4124  return false;
4125  }
4126 
4127  UniquePtr<EC_GROUP> p256(EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1));
4128  if (!p256) {
4130  return false;
4131  }
4132 
4133  UniquePtr<ECDSA_SIG> sig(ECDSA_SIG_new());
4134  UniquePtr<BIGNUM> x(BN_new()), y(BN_new());
4135  if (!sig || !x || !y) {
4136  return false;
4137  }
4138 
4139  const uint8_t *p = CBS_data(&extension);
4140  if (BN_bin2bn(p + 0, 32, x.get()) == NULL ||
4141  BN_bin2bn(p + 32, 32, y.get()) == NULL ||
4142  BN_bin2bn(p + 64, 32, sig->r) == NULL ||
4143  BN_bin2bn(p + 96, 32, sig->s) == NULL) {
4144  return false;
4145  }
4146 
4147  UniquePtr<EC_KEY> key(EC_KEY_new());
4148  UniquePtr<EC_POINT> point(EC_POINT_new(p256.get()));
4149  if (!key || !point ||
4150  !EC_POINT_set_affine_coordinates_GFp(p256.get(), point.get(), x.get(),
4151  y.get(), nullptr) ||
4152  !EC_KEY_set_group(key.get(), p256.get()) ||
4153  !EC_KEY_set_public_key(key.get(), point.get())) {
4154  return false;
4155  }
4156 
4157  uint8_t digest[EVP_MAX_MD_SIZE];
4158  size_t digest_len;
4159  if (!tls1_channel_id_hash(hs, digest, &digest_len)) {
4160  return false;
4161  }
4162 
4163  bool sig_ok = ECDSA_do_verify(digest, digest_len, sig.get(), key.get());
4164 #if defined(BORINGSSL_UNSAFE_FUZZER_MODE)
4165  sig_ok = true;
4166  ERR_clear_error();
4167 #endif
4168  if (!sig_ok) {
4171  return false;
4172  }
4173 
4174  OPENSSL_memcpy(ssl->s3->channel_id, p, 64);
4175  ssl->s3->channel_id_valid = true;
4176  return true;
4177 }
4178 
4180  uint8_t digest[EVP_MAX_MD_SIZE];
4181  size_t digest_len;
4182  if (!tls1_channel_id_hash(hs, digest, &digest_len)) {
4183  return false;
4184  }
4185 
4186  EC_KEY *ec_key = EVP_PKEY_get0_EC_KEY(hs->config->channel_id_private.get());
4187  if (ec_key == nullptr) {
4189  return false;
4190  }
4191 
4192  UniquePtr<BIGNUM> x(BN_new()), y(BN_new());
4193  if (!x || !y ||
4195  EC_KEY_get0_public_key(ec_key),
4196  x.get(), y.get(), nullptr)) {
4197  return false;
4198  }
4199 
4200  UniquePtr<ECDSA_SIG> sig(ECDSA_do_sign(digest, digest_len, ec_key));
4201  if (!sig) {
4202  return false;
4203  }
4204 
4205  CBB child;
4206  if (!CBB_add_u16(cbb, TLSEXT_TYPE_channel_id) ||
4208  !BN_bn2cbb_padded(&child, 32, x.get()) ||
4209  !BN_bn2cbb_padded(&child, 32, y.get()) ||
4210  !BN_bn2cbb_padded(&child, 32, sig->r) ||
4211  !BN_bn2cbb_padded(&child, 32, sig->s) ||
4212  !CBB_flush(cbb)) {
4213  return false;
4214  }
4215 
4216  return true;
4217 }
4218 
4219 bool tls1_channel_id_hash(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len) {
4220  SSL *const ssl = hs->ssl;
4221  if (ssl_protocol_version(ssl) >= TLS1_3_VERSION) {
4225  return false;
4226  }
4227  SHA256(msg.data(), msg.size(), out);
4228  *out_len = SHA256_DIGEST_LENGTH;
4229  return true;
4230  }
4231 
4232  SHA256_CTX ctx;
4233 
4234  SHA256_Init(&ctx);
4235  static const char kClientIDMagic[] = "TLS Channel ID signature";
4236  SHA256_Update(&ctx, kClientIDMagic, sizeof(kClientIDMagic));
4237 
4238  if (ssl->session != NULL) {
4239  static const char kResumptionMagic[] = "Resumption";
4240  SHA256_Update(&ctx, kResumptionMagic, sizeof(kResumptionMagic));
4241  if (ssl->session->original_handshake_hash_len == 0) {
4243  return false;
4244  }
4245  SHA256_Update(&ctx, ssl->session->original_handshake_hash,
4246  ssl->session->original_handshake_hash_len);
4247  }
4248 
4249  uint8_t hs_hash[EVP_MAX_MD_SIZE];
4250  size_t hs_hash_len;
4251  if (!hs->transcript.GetHash(hs_hash, &hs_hash_len)) {
4252  return false;
4253  }
4254  SHA256_Update(&ctx, hs_hash, (size_t)hs_hash_len);
4255  SHA256_Final(out, &ctx);
4256  *out_len = SHA256_DIGEST_LENGTH;
4257  return true;
4258 }
4259 
4261  SSL *const ssl = hs->ssl;
4262  // This function should never be called for a resumed session because the
4263  // handshake hashes that we wish to record are for the original, full
4264  // handshake.
4265  if (ssl->session != NULL) {
4266  return false;
4267  }
4268 
4269  static_assert(
4270  sizeof(hs->new_session->original_handshake_hash) == EVP_MAX_MD_SIZE,
4271  "original_handshake_hash is too small");
4272 
4273  size_t digest_len;
4274  if (!hs->transcript.GetHash(hs->new_session->original_handshake_hash,
4275  &digest_len)) {
4276  return false;
4277  }
4278 
4279  static_assert(EVP_MAX_MD_SIZE <= 0xff,
4280  "EVP_MAX_MD_SIZE does not fit in uint8_t");
4281  hs->new_session->original_handshake_hash_len = (uint8_t)digest_len;
4282 
4283  return true;
4284 }
4285 
4287  // Shallow parse the SCT list for sanity. By the RFC
4288  // (https://tools.ietf.org/html/rfc6962#section-3.3) neither the list nor any
4289  // of the SCTs may be empty.
4290  CBS copy = *contents;
4291  CBS sct_list;
4292  if (!CBS_get_u16_length_prefixed(&copy, &sct_list) ||
4293  CBS_len(&copy) != 0 ||
4294  CBS_len(&sct_list) == 0) {
4295  return false;
4296  }
4297 
4298  while (CBS_len(&sct_list) > 0) {
4299  CBS sct;
4300  if (!CBS_get_u16_length_prefixed(&sct_list, &sct) ||
4301  CBS_len(&sct) == 0) {
4302  return false;
4303  }
4304  }
4305 
4306  return true;
4307 }
4308 
4310 
4311 using namespace bssl;
4312 
4314  uint16_t extension_type,
4315  const uint8_t **out_data,
4316  size_t *out_len) {
4317  CBS cbs;
4318  if (!ssl_client_hello_get_extension(client_hello, &cbs, extension_type)) {
4319  return 0;
4320  }
4321 
4322  *out_data = CBS_data(&cbs);
4323  *out_len = CBS_len(&cbs);
4324  return 1;
4325 }
SSL_CONFIG::alpn_client_proto_list
Array< uint8_t > alpn_client_proto_list
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3019
ext_ech_add_serverhello
static bool ext_ech_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:712
ssl_send_alert
void ssl_send_alert(SSL *ssl, int level, int desc)
Definition: s3_pkt.cc:379
SSL_HANDSHAKE::hints_requested
bool hints_requested
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2026
ptr
char * ptr
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:45
ssl_st::server
bool server
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3777
ssl_ext_key_share_add_serverhello
bool ssl_ext_key_share_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:2437
tls1_set_curves_list
bool tls1_set_curves_list(Array< uint16_t > *out_group_ids, const char *curves)
Definition: extensions.cc:373
Span::subspan
Span subspan(size_t pos=0, size_t len=npos) const
Definition: boringssl-with-bazel/src/include/openssl/span.h:162
ssl_scan_clienthello_tlsext
static bool ssl_scan_clienthello_tlsext(SSL_HANDSHAKE *hs, const SSL_CLIENT_HELLO *client_hello, int *out_alert)
Definition: extensions.cc:3585
_gevent_test_main.result
result
Definition: _gevent_test_main.py:96
EC_POINT_new
#define EC_POINT_new
Definition: boringssl_prefix_symbols.h:1384
SSL_SIGN_RSA_PSS_RSAE_SHA512
#define SSL_SIGN_RSA_PSS_RSAE_SHA512
Definition: ssl.h:1075
EVP_PKEY_id
#define EVP_PKEY_id
Definition: boringssl_prefix_symbols.h:1638
forbid_parse_serverhello
static bool forbid_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:542
EVP_PKEY_EC
#define EVP_PKEY_EC
Definition: evp.h:178
SSL_CONFIG::channel_id_enabled
bool channel_id_enabled
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3059
CBB_flush
#define CBB_flush
Definition: boringssl_prefix_symbols.h:1045
CBB_data
#define CBB_data
Definition: boringssl_prefix_symbols.h:1040
Array::Init
bool Init(size_t new_size)
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:314
ECH_CLIENT_INNER
#define ECH_CLIENT_INNER
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1493
HMAC_size
#define HMAC_size
Definition: boringssl_prefix_symbols.h:1795
public_key
Definition: hrss.c:1881
CBB_init
#define CBB_init
Definition: boringssl_prefix_symbols.h:1047
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
RAND_bytes
#define RAND_bytes
Definition: boringssl_prefix_symbols.h:2060
now
static double now(void)
Definition: test/core/fling/client.cc:130
CBS_get_u16
#define CBS_get_u16
Definition: boringssl_prefix_symbols.h:1073
ssl_grease_version
@ ssl_grease_version
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1635
SSL_SIGN_RSA_PSS_RSAE_SHA256
#define SSL_SIGN_RSA_PSS_RSAE_SHA256
Definition: ssl.h:1073
SSL3_CK_SCSV
#define SSL3_CK_SCSV
Definition: ssl3.h:134
Span::size
size_t size() const
Definition: boringssl-with-bazel/src/include/openssl/span.h:133
SSL_HANDSHAKE::hints
UniquePtr< SSL_HANDSHAKE_HINTS > hints
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1943
parse_u16_array
static bool parse_u16_array(const CBS *cbs, Array< uint16_t > *out)
Definition: extensions.cc:2564
Span::last
Span last(size_t len)
Definition: boringssl-with-bazel/src/include/openssl/span.h:181
cbs_st
Definition: bytestring.h:39
is_post_quantum_group
static bool is_post_quantum_group(uint16_t id)
Definition: extensions.cc:207
ssl_grease_extension1
@ ssl_grease_extension1
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1633
EC_KEY_new
#define EC_KEY_new
Definition: boringssl_prefix_symbols.h:1355
compare_uint16_t
static int compare_uint16_t(const void *p1, const void *p2)
Definition: extensions.cc:141
ctx
Definition: benchmark-async.c:30
bool
bool
Definition: setup_once.h:312
SSL_CONFIG::supported_group_list
Array< uint16_t > supported_group_list
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3011
NID_X9_62_prime256v1
#define NID_X9_62_prime256v1
Definition: nid.h:1914
SSL_R_NO_GROUPS_SPECIFIED
#define SSL_R_NO_GROUPS_SPECIFIED
Definition: ssl.h:5532
SSL_TICKET_KEY_NAME_LEN
#define SSL_TICKET_KEY_NAME_LEN
Definition: ssl.h:2191
ext_quic_transport_params_parse_clienthello_legacy
static bool ext_quic_transport_params_parse_clienthello_legacy(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2740
ext_sct_add_serverhello
static bool ext_sct_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:1391
TLSEXT_ECPOINTFORMAT_uncompressed
#define TLSEXT_ECPOINTFORMAT_uncompressed
Definition: tls1.h:268
SSL_R_NEGOTIATED_BOTH_NPN_AND_ALPN
#define SSL_R_NEGOTIATED_BOTH_NPN_AND_ALPN
Definition: ssl.h:5437
SSL_R_MISSING_EXTENSION
#define SSL_R_MISSING_EXTENSION
Definition: ssl.h:5431
google::protobuf::extension
const Descriptor::ReservedRange const EnumValueDescriptor const MethodDescriptor extension
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:2001
TLSEXT_TYPE_renegotiate
#define TLSEXT_TYPE_renegotiate
Definition: tls1.h:240
tls12_get_verify_sigalgs
static Span< const uint16_t > tls12_get_verify_sigalgs(const SSL_HANDSHAKE *hs)
Definition: extensions.cc:474
SSL_HANDSHAKE::extended_master_secret
bool extended_master_secret
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2011
tls_extension::add_clienthello
bool(* add_clienthello)(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:532
SSL_R_ERROR_ADDING_EXTENSION
#define SSL_R_ERROR_ADDING_EXTENSION
Definition: ssl.h:5415
ext_alps_parse_serverhello
static bool ext_alps_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2982
Array::data
const T * data() const
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:274
tls1_write_channel_id
bool tls1_write_channel_id(SSL_HANDSHAKE *hs, CBB *cbb)
Definition: extensions.cc:4179
evp.h
ext_srtp_parse_clienthello
static bool ext_srtp_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1786
SSL_HANDSHAKE::local_pubkey
UniquePtr< EVP_PKEY > local_pubkey
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1909
CBS_data
#define CBS_data
Definition: boringssl_prefix_symbols.h:1057
tls_extension
Definition: extensions.cc:529
ssl_is_valid_ech_config_list
bool ssl_is_valid_ech_config_list(Span< const uint8_t > ech_config_list)
Definition: encrypted_client_hello.cc:568
SSL_CONFIG::channel_id_private
UniquePtr< EVP_PKEY > channel_id_private
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3015
ext_alps_add_serverhello
static bool ext_alps_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:3011
kExtensions
static const struct tls_extension kExtensions[]
Definition: extensions.cc:3087
uint16_t
unsigned short uint16_t
Definition: stdint-msvc2008.h:79
ext_ec_point_parse_clienthello
static bool ext_ec_point_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1905
SSL_HANDSHAKE::new_cipher
const SSL_CIPHER * new_cipher
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1933
SSL_CONFIG::alps_configs
GrowableArray< ALPSConfig > alps_configs
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3023
ssl_grease_extension2
@ ssl_grease_extension2
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1634
y
const double y
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3611
SSL_R_PARSE_TLSEXT
#define SSL_R_PARSE_TLSEXT
Definition: ssl.h:5457
BN_bin2bn
#define BN_bin2bn
Definition: boringssl_prefix_symbols.h:900
ignore_parse_clienthello
static bool ignore_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:554
ext_ec_point_add_clienthello
static bool ext_ec_point_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:1866
OPENSSL_PUT_ERROR
#define OPENSSL_PUT_ERROR(library, reason)
Definition: err.h:423
internal.h
CRYPTO_BUFFER_new_from_CBS
#define CRYPTO_BUFFER_new_from_CBS
Definition: boringssl_prefix_symbols.h:1120
ssl_is_valid_alpn_list
bool ssl_is_valid_alpn_list(Span< const uint8_t > in)
Definition: extensions.cc:1494
ext
void * ext
Definition: x509v3.h:87
SSL_HANDSHAKE::peer_supported_group_list
Array< uint16_t > peer_supported_group_list
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1862
ext_quic_transport_params_parse_clienthello_impl
static bool ext_quic_transport_params_parse_clienthello_impl(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents, bool used_legacy_codepoint)
Definition: extensions.cc:2692
decrypt_ticket_with_cipher_ctx
static enum ssl_ticket_aead_result_t decrypt_ticket_with_cipher_ctx(Array< uint8_t > *out, EVP_CIPHER_CTX *cipher_ctx, HMAC_CTX *hmac_ctx, Span< const uint8_t > ticket)
Definition: extensions.cc:3808
string.h
copy
static int copy(grpc_slice_buffer *input, grpc_slice_buffer *output)
Definition: message_compress.cc:145
TLSEXT_TYPE_early_data
#define TLSEXT_TYPE_early_data
Definition: tls1.h:231
CBS_get_u32
#define CBS_get_u32
Definition: boringssl_prefix_symbols.h:1078
ext_psk_key_exchange_modes_add_clienthello
static bool ext_psk_key_exchange_modes_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:2116
CBB_add_u16_length_prefixed
#define CBB_add_u16_length_prefixed
Definition: boringssl_prefix_symbols.h:1028
CBB_add_u8
#define CBB_add_u8
Definition: boringssl_prefix_symbols.h:1036
tls_extension::parse_serverhello
bool(* parse_serverhello)(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:534
ssl_cipher_st::algorithm_prf
uint32_t algorithm_prf
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:533
tls1_parse_peer_sigalgs
bool tls1_parse_peer_sigalgs(SSL_HANDSHAKE *hs, const CBS *in_sigalgs)
Definition: extensions.cc:4029
SSL_HANDSHAKE::ssl
SSL * ssl
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1726
SSL_HANDSHAKE::sent
uint32_t sent
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1802
ext_ri_add_clienthello
static bool ext_ri_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:745
ssl_cipher_uses_certificate_auth
bool ssl_cipher_uses_certificate_auth(const SSL_CIPHER *cipher)
Definition: ssl_cipher.cc:1295
TLSEXT_TYPE_delegated_credential
#define TLSEXT_TYPE_delegated_credential
Definition: tls1.h:243
SSL_TLSEXT_ERR_OK
#define SSL_TLSEXT_ERR_OK
Definition: ssl.h:2755
ext_ocsp_add_serverhello
static bool ext_ocsp_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:1175
hpke.h
SSL_AD_INTERNAL_ERROR
#define SSL_AD_INTERNAL_ERROR
Definition: ssl.h:3815
EC_KEY_set_group
#define EC_KEY_set_group
Definition: boringssl_prefix_symbols.h:1365
CRYPTO_BUFFER_len
#define CRYPTO_BUFFER_len
Definition: boringssl_prefix_symbols.h:1118
CBS_get_u8_length_prefixed
#define CBS_get_u8_length_prefixed
Definition: boringssl_prefix_symbols.h:1083
ext_ems_add_clienthello
static bool ext_ems_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:913
EC_KEY_set_public_key
#define EC_KEY_set_public_key
Definition: boringssl_prefix_symbols.h:1367
error_ref_leak.err
err
Definition: error_ref_leak.py:35
TLSEXT_TYPE_cookie
#define TLSEXT_TYPE_cookie
Definition: tls1.h:233
protocol
Protocol protocol
Definition: client_callback_end2end_test.cc:67
ciphertext
const char * ciphertext
Definition: protobuf/src/google/protobuf/stubs/strutil_unittest.cc:86
dont_add_serverhello
static bool dont_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:560
kSignSignatureAlgorithms
static const uint16_t kSignSignatureAlgorithms[]
Definition: extensions.cc:451
SSL_HANDSHAKE::extension_permutation
Array< uint8_t > extension_permutation
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1874
ext_channel_id_parse_serverhello
static bool ext_channel_id_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1658
OPENSSL_memchr
static void * OPENSSL_memchr(const void *s, int c, size_t n)
Definition: third_party/boringssl-with-bazel/src/crypto/internal.h:801
ssl_parse_serverhello_tlsext
bool ssl_parse_serverhello_tlsext(SSL_HANDSHAKE *hs, const CBS *cbs)
Definition: extensions.cc:3793
CBS_len
#define CBS_len
Definition: boringssl_prefix_symbols.h:1089
SSL_CONFIG::cert
UniquePtr< CERT > cert
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2986
EVP_CIPHER_iv_length
#define EVP_CIPHER_iv_length
Definition: boringssl_prefix_symbols.h:1485
u
OPENSSL_EXPORT pem_password_cb void * u
Definition: pem.h:351
tls1_check_group_id
bool tls1_check_group_id(const SSL_HANDSHAKE *hs, uint16_t group_id)
Definition: extensions.cc:408
ECDSA_SIG_new
#define ECDSA_SIG_new
Definition: boringssl_prefix_symbols.h:1305
ssl_is_alpn_protocol_allowed
bool ssl_is_alpn_protocol_allowed(const SSL_HANDSHAKE *hs, Span< const uint8_t > protocol)
Definition: extensions.cc:1510
SSL_HANDSHAKE::selected_ech_config
UniquePtr< ECHConfig > selected_ech_config
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1930
bssl
Definition: hpke_test.cc:37
SSL_SIGN_RSA_PSS_RSAE_SHA384
#define SSL_SIGN_RSA_PSS_RSAE_SHA384
Definition: ssl.h:1074
SSL_SESSION_from_bytes
#define SSL_SESSION_from_bytes
Definition: boringssl_prefix_symbols.h:242
ext_ocsp_add_clienthello
static bool ext_ocsp_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:1111
ctx
static struct test_ctx ctx
Definition: test-ipc-send-recv.c:65
EC_GROUP_new_by_curve_name
#define EC_GROUP_new_by_curve_name
Definition: boringssl_prefix_symbols.h:1331
EVP_PKEY_RSA
#define EVP_PKEY_RSA
Definition: evp.h:175
setup.name
name
Definition: setup.py:542
TLSEXT_TYPE_quic_transport_parameters_legacy
#define TLSEXT_TYPE_quic_transport_parameters_legacy
Definition: tls1.h:211
SSL_HANDSHAKE::ocsp_stapling_requested
bool ocsp_stapling_requested
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1973
CERT::dc
UniquePtr< DC > dc
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2415
CERT::sigalgs
Array< uint16_t > sigalgs
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2386
SSL_R_QUIC_TRANSPORT_PARAMETERS_MISCONFIGURED
#define SSL_R_QUIC_TRANSPORT_PARAMETERS_MISCONFIGURED
Definition: ssl.h:5572
SSL_HANDSHAKE::extensions
union SSL_HANDSHAKE::@373 extensions
ext_ec_point_add_extension
static bool ext_ec_point_add_extension(const SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:1853
SSL_HANDSHAKE::min_version
uint16_t min_version
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1745
ssl_ext_key_share_parse_clienthello
bool ssl_ext_key_share_parse_clienthello(SSL_HANDSHAKE *hs, bool *out_found, Span< const uint8_t > *out_peer_key, uint8_t *out_alert, const SSL_CLIENT_HELLO *client_hello)
Definition: extensions.cc:2384
SSL_HANDSHAKE::accept_psk_mode
bool accept_psk_mode
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1962
cipher_suites
static const char * cipher_suites
Definition: ssl_utils.cc:78
ext_sni_parse_clienthello
static bool ext_sni_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:606
cbs
const CBS * cbs
Definition: third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h:107
xds_manager.p
p
Definition: xds_manager.py:60
SSL_AD_ILLEGAL_PARAMETER
#define SSL_AD_ILLEGAL_PARAMETER
Definition: ssl.h:3807
ssl_negotiate_alpn
bool ssl_negotiate_alpn(SSL_HANDSHAKE *hs, uint8_t *out_alert, const SSL_CLIENT_HELLO *client_hello)
Definition: extensions.cc:1538
ext_quic_transport_params_add_serverhello_impl
static bool ext_quic_transport_params_add_serverhello_impl(SSL_HANDSHAKE *hs, CBB *out, bool use_legacy_codepoint)
Definition: extensions.cc:2746
ECDSA_do_sign
#define ECDSA_do_sign
Definition: boringssl_prefix_symbols.h:1309
SSL_HANDSHAKE::new_session
UniquePtr< SSL_SESSION > new_session
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1916
ssl_ech_accepted
@ ssl_ech_accepted
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2614
SSL_SIGN_ECDSA_SECP521R1_SHA512
#define SSL_SIGN_ECDSA_SECP521R1_SHA512
Definition: ssl.h:1072
ssl_get_current_time
void ssl_get_current_time(const SSL *ssl, struct OPENSSL_timeval *out_clock)
Definition: ssl_lib.cc:354
SSL3_RANDOM_SIZE
#define SSL3_RANDOM_SIZE
Definition: ssl3.h:204
CBS_init
#define CBS_init
Definition: boringssl_prefix_symbols.h:1085
SSL_SIGN_RSA_PKCS1_SHA256
#define SSL_SIGN_RSA_PKCS1_SHA256
Definition: ssl.h:1066
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
EC_KEY_get0_group
#define EC_KEY_get0_group
Definition: boringssl_prefix_symbols.h:1344
SSL_R_CLIENTHELLO_TLSEXT
#define SSL_R_CLIENTHELLO_TLSEXT
Definition: ssl.h:5400
SSL_HANDSHAKE::cert_compression_alg_id
uint16_t cert_compression_alg_id
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1879
evp_cipher_ctx_st
Definition: cipher.h:536
EVP_CIPHER_CTX_iv_length
#define EVP_CIPHER_CTX_iv_length
Definition: boringssl_prefix_symbols.h:1473
ssl_ctx_st
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3404
TLSEXT_TYPE_ech_outer_extensions
#define TLSEXT_TYPE_ech_outer_extensions
Definition: tls1.h:252
OPENSSL_memset
static void * OPENSSL_memset(void *dst, int c, size_t n)
Definition: third_party/boringssl-with-bazel/src/crypto/internal.h:835
Array::CopyFrom
bool CopyFrom(Span< const T > in)
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:338
ssl_st::quic_method
const SSL_QUIC_METHOD * quic_method
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3769
ssl_name_to_group_id
bool ssl_name_to_group_id(uint16_t *out_group_id, const char *name, size_t len)
Definition: ssl_key_share.cc:373
ext_ri_parse_serverhello
static bool ext_ri_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:771
SSL_R_NO_APPLICATION_PROTOCOL
#define SSL_R_NO_APPLICATION_PROTOCOL
Definition: ssl.h:5574
ext_sni_parse_serverhello
static bool ext_sni_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:599
tls1_record_handshake_hashes_for_channel_id
bool tls1_record_handshake_hashes_for_channel_id(SSL_HANDSHAKE *hs)
Definition: extensions.cc:4260
ext_early_data_add_serverhello
static bool ext_early_data_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:2244
ssl_st::session
bssl::UniquePtr< SSL_SESSION > session
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3750
ext_channel_id_add_serverhello
static bool ext_channel_id_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:1692
ssl_session_protocol_version
uint16_t ssl_session_protocol_version(const SSL_SESSION *session)
Definition: ssl_session.cc:335
ext_pre_shared_key_add_clienthello
static bool ext_pre_shared_key_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, bool *out_needs_binder, ssl_client_hello_type_t type)
Definition: extensions.cc:1971
SSL_HANDSHAKE::ech_client_outer
Array< uint8_t > ech_client_outer
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1837
tlsext_tick_md
#define tlsext_tick_md
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3329
ssl_check_clienthello_tlsext
static BSSL_NAMESPACE_BEGIN bool ssl_check_clienthello_tlsext(SSL_HANDSHAKE *hs)
Definition: extensions.cc:3738
ssl_early_data_peer_declined
ssl_early_data_peer_declined
Definition: ssl.h:3563
EVP_DecryptInit_ex
#define EVP_DecryptInit_ex
Definition: boringssl_prefix_symbols.h:1504
CERT
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2345
SSL_AD_UNSUPPORTED_EXTENSION
#define SSL_AD_UNSUPPORTED_EXTENSION
Definition: ssl.h:3820
ext_delegated_credential_parse_clienthello
static bool ext_delegated_credential_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2803
ext_early_data_add_clienthello
static bool ext_early_data_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:2161
chacha.h
tls1_get_grouplist
Span< const uint16_t > tls1_get_grouplist(const SSL_HANDSHAKE *hs)
Definition: extensions.cc:311
SSL_SIGN_RSA_PKCS1_SHA384
#define SSL_SIGN_RSA_PKCS1_SHA384
Definition: ssl.h:1067
SSL_early_callback_ctx_extension_get
int SSL_early_callback_ctx_extension_get(const SSL_CLIENT_HELLO *client_hello, uint16_t extension_type, const uint8_t **out_data, size_t *out_len)
Definition: extensions.cc:4313
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
TLSEXT_TYPE_supported_versions
#define TLSEXT_TYPE_supported_versions
Definition: tls1.h:232
Array::empty
bool empty() const
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:277
ssl_grease_group
@ ssl_grease_group
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1632
TicketKey
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2574
SSL_SIGN_RSA_PKCS1_SHA512
#define SSL_SIGN_RSA_PKCS1_SHA512
Definition: ssl.h:1068
ext_supported_groups_parse_clienthello
static bool ext_supported_groups_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2587
bytestring.h
ext_supported_groups_parse_serverhello
static bool ext_supported_groups_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2556
should_offer_psk
static bool should_offer_psk(const SSL_HANDSHAKE *hs, ssl_client_hello_type_t type)
Definition: extensions.cc:1936
SSL_HANDSHAKE::inner_extensions_sent
uint32_t inner_extensions_sent
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1810
ssl_add_clienthello_tlsext
bool ssl_add_clienthello_tlsext(SSL_HANDSHAKE *hs, CBB *out, CBB *out_encoded, bool *out_needs_psk_binder, ssl_client_hello_type_t type, size_t header_len)
Definition: extensions.cc:3426
EC_POINT_get_affine_coordinates_GFp
#define EC_POINT_get_affine_coordinates_GFp
Definition: boringssl_prefix_symbols.h:1379
ssl_is_sct_list_valid
bool ssl_is_sct_list_valid(const CBS *contents)
Definition: extensions.cc:4286
ext_alpn_add_serverhello
static bool ext_alpn_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:1608
TLSEXT_CHANNEL_ID_SIZE
#define TLSEXT_CHANNEL_ID_SIZE
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2340
in
const char * in
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:391
ext_sct_parse_clienthello
static bool ext_sct_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1377
ext_quic_transport_params_add_clienthello_impl
static bool ext_quic_transport_params_add_clienthello_impl(const SSL_HANDSHAKE *hs, CBB *out, bool use_legacy_codepoint)
Definition: extensions.cc:2608
UINT8_MAX
#define UINT8_MAX
Definition: stdint-msvc2008.h:140
CBB_add_u16
#define CBB_add_u16
Definition: boringssl_prefix_symbols.h:1027
evp_cipher_st
Definition: cipher.h:585
ext_channel_id_add_clienthello
static bool ext_channel_id_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:1633
ext_quic_transport_params_add_serverhello_legacy
static bool ext_quic_transport_params_add_serverhello_legacy(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:2787
EC_POINT_set_affine_coordinates_GFp
#define EC_POINT_set_affine_coordinates_GFp
Definition: boringssl_prefix_symbols.h:1389
evp_pkey_st
Definition: evp.h:1046
SSL_HANDSHAKE
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1720
ext_ec_point_parse_serverhello
static bool ext_ec_point_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1877
tls1_get_peer_verify_algorithms
Span< const uint16_t > tls1_get_peer_verify_algorithms(const SSL_HANDSHAKE *hs)
Definition: extensions.cc:4098
ext_ticket_add_serverhello
static bool ext_ticket_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:1049
ext_ech_add_clienthello
static bool ext_ech_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:631
ext_ems_parse_clienthello
static bool ext_ems_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:954
absl::move
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
Definition: abseil-cpp/absl/utility/utility.h:221
Array< uint16_t >
cert_compression_add_clienthello
static bool cert_compression_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:2828
SSL_HANDSHAKE::scts_requested
bool scts_requested
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1954
ssl_cipher_st::algorithm_mkey
uint32_t algorithm_mkey
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:529
STACK_OF
#define STACK_OF(type)
Definition: stack.h:125
gen_stats_data.found
bool found
Definition: gen_stats_data.py:61
ext_npn_parse_clienthello
static bool ext_npn_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1267
Span::empty
bool empty() const
Definition: boringssl-with-bazel/src/include/openssl/span.h:134
SSL_HANDSHAKE_HINTS::decrypted_psk
Array< uint8_t > decrypted_psk
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1712
config
struct config_s config
Array::size
size_t size() const
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:276
ext_srtp_parse_serverhello
static bool ext_srtp_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1743
SSL_HANDSHAKE::channel_id_negotiated
bool channel_id_negotiated
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2041
CBB_add_zeros
#define CBB_add_zeros
Definition: boringssl_prefix_symbols.h:1038
CBB_add_u8_length_prefixed
#define CBB_add_u8_length_prefixed
Definition: boringssl_prefix_symbols.h:1037
SSL_HANDSHAKE::should_ack_sni
bool should_ack_sni
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1981
ssl_st
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3698
ssl_setup_extension_permutation
bool ssl_setup_extension_permutation(SSL_HANDSHAKE *hs)
Definition: extensions.cc:3270
ERR_add_error_dataf
#define ERR_add_error_dataf
Definition: boringssl_prefix_symbols.h:1412
tls1_set_curves
bool tls1_set_curves(Array< uint16_t > *out_group_ids, Span< const int > curves)
Definition: extensions.cc:357
cert_compression_parse_serverhello
static bool cert_compression_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2854
TLSEXT_TYPE_srtp
#define TLSEXT_TYPE_srtp
Definition: tls1.h:195
ssl_early_callback_ctx
Definition: ssl.h:4186
TLSEXT_TYPE_channel_id
#define TLSEXT_TYPE_channel_id
Definition: tls1.h:261
SSL_R_PSK_IDENTITY_BINDER_COUNT_MISMATCH
#define SSL_R_PSK_IDENTITY_BINDER_COUNT_MISMATCH
Definition: ssl.h:5538
EVP_MD_size
#define EVP_MD_size
Definition: boringssl_prefix_symbols.h:1579
ext_sni_add_serverhello
static bool ext_sni_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:612
cert_compression_add_serverhello
static bool cert_compression_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:2929
SSL_HANDSHAKE::next_proto_neg_seen
bool next_proto_neg_seen
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2003
ssl_client_hello_type_t
ssl_client_hello_type_t
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1485
SSL_SIGN_RSA_PKCS1_SHA1
#define SSL_SIGN_RSA_PKCS1_SHA1
Definition: ssl.h:1065
TLSEXT_TYPE_padding
#define TLSEXT_TYPE_padding
Definition: tls1.h:201
ext_ech_parse_clienthello
static bool ext_ech_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:690
SSL_AD_UNKNOWN_PSK_IDENTITY
#define SSL_AD_UNKNOWN_PSK_IDENTITY
Definition: ssl.h:3826
BN_bn2cbb_padded
#define BN_bn2cbb_padded
Definition: boringssl_prefix_symbols.h:904
OPENSSL_timeval
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2873
tests.stress.unary_stream_benchmark.profile
def profile(message_size, response_count)
Definition: unary_stream_benchmark.py:78
SSL3_HM_HEADER_LENGTH
#define SSL3_HM_HEADER_LENGTH
Definition: ssl3.h:208
add_padding_extension
static bool add_padding_extension(CBB *cbb, uint16_t ext, size_t len)
Definition: extensions.cc:3307
ssl_scan_serverhello_tlsext
static bool ssl_scan_serverhello_tlsext(SSL_HANDSHAKE *hs, const CBS *cbs, int *out_alert)
Definition: extensions.cc:3668
ssl_client_hello_get_extension
bool ssl_client_hello_get_extension(const SSL_CLIENT_HELLO *client_hello, CBS *out, uint16_t extension_type)
Definition: extensions.cc:283
SSL_is_dtls
#define SSL_is_dtls
Definition: boringssl_prefix_symbols.h:402
ext_key_share_add_clienthello
static bool ext_key_share_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:2329
ssl_get_grease_value
uint16_t ssl_get_grease_value(const SSL_HANDSHAKE *hs, enum ssl_grease_index_t index)
Definition: handshake.cc:454
TLSEXT_TYPE_signature_algorithms
#define TLSEXT_TYPE_signature_algorithms
Definition: tls1.h:192
SSLKeyShare
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1067
tls_extension::value
uint16_t value
Definition: extensions.cc:530
ext_pre_shared_key_clienthello_length
static size_t ext_pre_shared_key_clienthello_length(const SSL_HANDSHAKE *hs, ssl_client_hello_type_t type)
Definition: extensions.cc:1960
SSL_R_WRONG_SIGNATURE_TYPE
#define SSL_R_WRONG_SIGNATURE_TYPE
Definition: ssl.h:5512
OPENSSL_memcpy
static void * OPENSSL_memcpy(void *dst, const void *src, size_t n)
Definition: third_party/boringssl-with-bazel/src/crypto/internal.h:819
tls12_check_peer_sigalg
bool tls12_check_peer_sigalg(const SSL_HANDSHAKE *hs, uint8_t *out_alert, uint16_t sigalg)
Definition: extensions.cc:490
BSSL_NAMESPACE_END
#define BSSL_NAMESPACE_END
Definition: base.h:480
ext_npn_add_clienthello
static bool ext_npn_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:1195
ext_delegated_credential_add_clienthello
static bool ext_delegated_credential_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:2797
SSL_CONFIG::verify_sigalgs
Array< uint16_t > verify_sigalgs
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3033
ssl_negotiate_alps
bool ssl_negotiate_alps(SSL_HANDSHAKE *hs, uint8_t *out_alert, const SSL_CLIENT_HELLO *client_hello)
Definition: extensions.cc:3034
SSL_AD_MISSING_EXTENSION
#define SSL_AD_MISSING_EXTENSION
Definition: ssl.h:3819
CBS_get_u8
#define CBS_get_u8
Definition: boringssl_prefix_symbols.h:1082
SSL_TLSEXT_ERR_NOACK
#define SSL_TLSEXT_ERR_NOACK
Definition: ssl.h:2758
ext_ems_parse_serverhello
static bool ext_ems_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:929
ext_npn_parse_serverhello
static bool ext_npn_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1216
err.h
SSL_R_WRONG_CURVE
#define SSL_R_WRONG_CURVE
Definition: ssl.h:5510
ERR_R_INTERNAL_ERROR
#define ERR_R_INTERNAL_ERROR
Definition: err.h:374
ssl_protocol_version
uint16_t ssl_protocol_version(const SSL *ssl)
Definition: ssl_versions.cc:251
ext_quic_transport_params_add_clienthello_legacy
static bool ext_quic_transport_params_add_clienthello_legacy(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:2649
std::swap
void swap(Json::Value &a, Json::Value &b)
Specialize std::swap() for Json::Value.
Definition: third_party/bloaty/third_party/protobuf/conformance/third_party/jsoncpp/json.h:1226
HMAC_Init_ex
#define HMAC_Init_ex
Definition: boringssl_prefix_symbols.h:1793
tls1_choose_signature_algorithm
bool tls1_choose_signature_algorithm(SSL_HANDSHAKE *hs, uint16_t *out)
Definition: extensions.cc:4054
ext_quic_transport_params_parse_serverhello
static bool ext_quic_transport_params_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2679
TLSEXT_TYPE_key_share
#define TLSEXT_TYPE_key_share
Definition: tls1.h:237
EC_KEY_get0_public_key
#define EC_KEY_get0_public_key
Definition: boringssl_prefix_symbols.h:1346
googletest-filter-unittest.child
child
Definition: bloaty/third_party/googletest/googletest/test/googletest-filter-unittest.py:62
SSL_R_RENEGOTIATION_MISMATCH
#define SSL_R_RENEGOTIATION_MISMATCH
Definition: ssl.h:5469
ext_alps_add_clienthello
static bool ext_alps_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:2949
ext_alpn_parse_serverhello
static bool ext_alpn_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1445
ext_ec_point_add_serverhello
static bool ext_ec_point_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:1914
x
int x
Definition: bloaty/third_party/googletest/googlemock/test/gmock-matchers_test.cc:3610
tls1_get_legacy_signature_algorithm
bool tls1_get_legacy_signature_algorithm(uint16_t *out, const EVP_PKEY *pkey)
Definition: extensions.cc:4041
CBB_add_u32
#define CBB_add_u32
Definition: boringssl_prefix_symbols.h:1032
TLSEXT_TYPE_cert_compression
#define TLSEXT_TYPE_cert_compression
Definition: tls1.h:223
conf.extensions
list extensions
Definition: doc/python/sphinx/conf.py:54
SSL_HANDSHAKE::max_version
uint16_t max_version
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1749
DTLS1_COOKIE_LENGTH
#define DTLS1_COOKIE_LENGTH
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2831
SSL_CURVE_X25519
#define SSL_CURVE_X25519
Definition: ssl.h:2330
Span::first
Span first(size_t len)
Definition: boringssl-with-bazel/src/include/openssl/span.h:174
ext_alpn_add_clienthello
static bool ext_alpn_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:1416
aead.h
SSL_R_NO_P256_SUPPORT
#define SSL_R_NO_P256_SUPPORT
Definition: ssl.h:5447
ALPSConfig
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2949
SSL_HANDSHAKE::ech_retry_configs
Array< uint8_t > ech_retry_configs
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1841
ssl_cipher_st::algorithm_auth
uint32_t algorithm_auth
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:530
SSL_R_RENEGOTIATION_ENCODING_ERR
#define SSL_R_RENEGOTIATION_ENCODING_ERR
Definition: ssl.h:5468
ssl_session_get_digest
const EVP_MD * ssl_session_get_digest(const SSL_SESSION *session)
Definition: ssl_session.cc:347
SSL_CONFIG::ocsp_stapling_enabled
bool ocsp_stapling_enabled
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3055
ECDSA_do_verify
#define ECDSA_do_verify
Definition: boringssl_prefix_symbols.h:1310
SSL_R_RENEGOTIATION_EMS_MISMATCH
#define SSL_R_RENEGOTIATION_EMS_MISMATCH
Definition: ssl.h:5530
d
static const fe d
Definition: curve25519_tables.h:19
Span< const uint8_t >
SSL_R_NEGOTIATED_ALPS_WITHOUT_ALPN
#define SSL_R_NEGOTIATED_ALPS_WITHOUT_ALPN
Definition: ssl.h:5575
qsort
void qsort(void *a, size_t n, size_t es, int(*cmp)(const void *, const void *))
Definition: qsort.h:130
SSL_HANDSHAKE::transcript
SSLTranscript transcript
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1821
ext_sigalgs_add_clienthello
static bool ext_sigalgs_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:1070
SSL_TLSEXT_ERR_ALERT_WARNING
#define SSL_TLSEXT_ERR_ALERT_WARNING
Definition: ssl.h:2756
SSL_HANDSHAKE::peer_sigalgs
Array< uint16_t > peer_sigalgs
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1857
ssl_early_data_accepted
ssl_early_data_accepted
Definition: ssl.h:3559
msg
std::string msg
Definition: client_interceptors_end2end_test.cc:372
SSL3_AL_FATAL
#define SSL3_AL_FATAL
Definition: ssl3.h:280
SSL_R_BAD_SRTP_MKI_VALUE
#define SSL_R_BAD_SRTP_MKI_VALUE
Definition: ssl.h:5383
SSL_HANDSHAKE::early_data_offered
bool early_data_offered
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1992
ssl_ticket_aead_success
ssl_ticket_aead_success
Definition: ssl.h:2226
ssl_st::hostname
bssl::UniquePtr< char > hostname
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3766
ssl_client_hello_init
bool ssl_client_hello_init(const SSL *ssl, SSL_CLIENT_HELLO *out, Span< const uint8_t > body)
Definition: extensions.cc:211
TLSEXT_TYPE_supported_groups
#define TLSEXT_TYPE_supported_groups
Definition: tls1.h:229
ssl.h
SSL_R_MISSING_KEY_SHARE
#define SSL_R_MISSING_KEY_SHARE
Definition: ssl.h:5525
TLSEXT_TYPE_psk_key_exchange_modes
#define TLSEXT_TYPE_psk_key_exchange_modes
Definition: tls1.h:234
DC::expected_cert_verify_algorithm
uint16_t expected_cert_verify_algorithm
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1590
ECH_CLIENT_OUTER
#define ECH_CLIENT_OUTER
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1492
ssl_process_ticket
enum ssl_ticket_aead_result_t ssl_process_ticket(SSL_HANDSHAKE *hs, UniquePtr< SSL_SESSION > *out_session, bool *out_renew_ticket, Span< const uint8_t > ticket, Span< const uint8_t > session_id)
Definition: extensions.cc:3952
ec_key_st
Definition: third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h:723
ssl_parse_client_hello_with_trailing_data
bool ssl_parse_client_hello_with_trailing_data(const SSL *ssl, CBS *cbs, SSL_CLIENT_HELLO *out)
Definition: extensions.cc:221
ext_npn_add_serverhello
static bool ext_npn_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:1289
SHA256
#define SHA256
Definition: boringssl_prefix_symbols.h:2154
point
Definition: bloaty/third_party/zlib/examples/zran.c:67
ext_quic_transport_params_parse_serverhello_impl
static bool ext_quic_transport_params_parse_serverhello_impl(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents, bool used_legacy_codepoint)
Definition: extensions.cc:2656
value
const char * value
Definition: hpack_parser_table.cc:165
ssl_nid_to_group_id
bool ssl_nid_to_group_id(uint16_t *out_group_id, int nid)
Definition: ssl_key_share.cc:363
SSLMessage
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1140
SSL_CONFIG::quic_use_legacy_codepoint
bool quic_use_legacy_codepoint
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3087
SSL_OP_CIPHER_SERVER_PREFERENCE
#define SSL_OP_CIPHER_SERVER_PREFERENCE
Definition: ssl.h:714
DC
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1572
TLS1_3_VERSION
#define TLS1_3_VERSION
Definition: ssl.h:653
ext_ems_add_serverhello
static bool ext_ems_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:972
ssl_early_data_unknown
ssl_early_data_unknown
Definition: ssl.h:3555
SSL_SIGN_ED25519
#define SSL_SIGN_ED25519
Definition: ssl.h:1076
CBB_add_bytes
#define CBB_add_bytes
Definition: boringssl_prefix_symbols.h:1025
contents
string_view contents
Definition: elf.cc:597
TLS1_2_VERSION
#define TLS1_2_VERSION
Definition: ssl.h:652
SSL_R_NO_COMMON_SIGNATURE_ALGORITHMS
#define SSL_R_NO_COMMON_SIGNATURE_ALGORITHMS
Definition: ssl.h:5520
CBBFinishArray
OPENSSL_EXPORT bool CBBFinishArray(CBB *cbb, Array< uint8_t > *out)
Definition: ssl_lib.cc:190
SSL_CONFIG::quic_transport_params
Array< uint8_t > quic_transport_params
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3026
sha256_state_st
Definition: sha.h:189
BSSL_NAMESPACE_BEGIN
Definition: trust_token_test.cc:45
nid.h
ssl_st::s3
bssl::SSL3_STATE * s3
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3730
rand.h
tls_extension::parse_clienthello
bool(* parse_clienthello)(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:537
SSLKeyShare::Create
static HAS_VIRTUAL_DESTRUCTOR UniquePtr< SSLKeyShare > Create(uint16_t group_id)
Definition: ssl_key_share.cc:308
ext_early_data_parse_clienthello
static bool ext_early_data_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2227
digest.h
make_dist_html.groups
list groups
Definition: make_dist_html.py:120
SSL_get_srtp_profiles
#define SSL_get_srtp_profiles
Definition: boringssl_prefix_symbols.h:383
key
const char * key
Definition: hpack_parser_table.cc:164
ext_supported_versions_add_clienthello
static bool ext_supported_versions_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:2456
ext_psk_key_exchange_modes_parse_clienthello
static bool ext_psk_key_exchange_modes_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2134
SSL_SIGN_RSA_PKCS1_MD5_SHA1
#define SSL_SIGN_RSA_PKCS1_MD5_SHA1
Definition: ssl.h:1081
upload.group
group
Definition: bloaty/third_party/googletest/googlemock/scripts/upload.py:397
SSL_HANDSHAKE::config
SSL_CONFIG * config
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1729
TLSEXT_TYPE_certificate_timestamp
#define TLSEXT_TYPE_certificate_timestamp
Definition: tls1.h:255
cert_compression_parse_clienthello
static bool cert_compression_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2866
SSL_R_INVALID_ALPN_PROTOCOL
#define SSL_R_INVALID_ALPN_PROTOCOL
Definition: ssl.h:5526
ssl_early_callback_ctx::extensions
const uint8_t * extensions
Definition: ssl.h:4199
check_version.settings
settings
Definition: check_version.py:61
SSL_R_UNEXPECTED_EXTENSION
#define SSL_R_UNEXPECTED_EXTENSION
Definition: ssl.h:5489
ssl_decrypt_ticket_with_ticket_keys
static enum ssl_ticket_aead_result_t ssl_decrypt_ticket_with_ticket_keys(SSL_HANDSHAKE *hs, Array< uint8_t > *out, Span< const uint8_t > ticket)
Definition: extensions.cc:3890
EVP_DecryptUpdate
#define EVP_DecryptUpdate
Definition: boringssl_prefix_symbols.h:1505
TLSEXT_TYPE_status_request
#define TLSEXT_TYPE_status_request
Definition: tls1.h:186
HMAC_Final
#define HMAC_Final
Definition: boringssl_prefix_symbols.h:1791
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
EVP_PKEY_get0_EC_KEY
#define EVP_PKEY_get0_EC_KEY
Definition: boringssl_prefix_symbols.h:1629
ssl_parse_clienthello_tlsext
bool ssl_parse_clienthello_tlsext(SSL_HANDSHAKE *hs, const SSL_CLIENT_HELLO *client_hello)
Definition: extensions.cc:3651
SSL_HANDSHAKE::ecdh_public_key
Array< uint8_t > ecdh_public_key
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1852
TLSEXT_TYPE_next_proto_neg
#define TLSEXT_TYPE_next_proto_neg
Definition: tls1.h:258
TLSEXT_TYPE_extended_master_secret
#define TLSEXT_TYPE_extended_master_secret
Definition: tls1.h:204
SSL_CURVE_CECPQ2
#define SSL_CURVE_CECPQ2
Definition: ssl.h:2331
ext_quic_transport_params_add_serverhello
static bool ext_quic_transport_params_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:2781
SSL_CURVE_SECP256R1
#define SSL_CURVE_SECP256R1
Definition: ssl.h:2327
SSL_HANDSHAKE_HINTS::ignore_psk
bool ignore_psk
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1713
SSL_AD_DECODE_ERROR
#define SSL_AD_DECODE_ERROR
Definition: ssl.h:3810
kVerifySignatureAlgorithms
static const uint16_t kVerifySignatureAlgorithms[]
Definition: extensions.cc:431
SSL_kECDHE
#define SSL_kECDHE
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:540
SHA256_Init
#define SHA256_Init
Definition: boringssl_prefix_symbols.h:2156
ret
UniquePtr< SSL_SESSION > ret
Definition: ssl_x509.cc:1029
ssl_decrypt_ticket_with_method
static enum ssl_ticket_aead_result_t ssl_decrypt_ticket_with_method(SSL_HANDSHAKE *hs, Array< uint8_t > *out, bool *out_renew_ticket, Span< const uint8_t > ticket)
Definition: extensions.cc:3929
SSL_HANDSHAKE::cookie
Array< uint8_t > cookie
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1833
ssl_ext_pre_shared_key_parse_serverhello
bool ssl_ext_pre_shared_key_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2007
hmac_ctx_st
Definition: hmac.h:158
ssl_add_clienthello_tlsext_inner
static bool ssl_add_clienthello_tlsext_inner(SSL_HANDSHAKE *hs, CBB *out, CBB *out_encoded, bool *out_needs_psk_binder)
Definition: extensions.cc:3318
SSL_HANDSHAKE::ech_is_inner
bool ech_is_inner
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1947
ssl_check_serverhello_tlsext
static bool ssl_check_serverhello_tlsext(SSL_HANDSHAKE *hs)
Definition: extensions.cc:3763
CBS_get_u16_length_prefixed
#define CBS_get_u16_length_prefixed
Definition: boringssl_prefix_symbols.h:1074
SSL_HANDSHAKE::key_shares
UniquePtr< SSLKeyShare > key_shares[2]
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1818
SHA256_DIGEST_LENGTH
#define SHA256_DIGEST_LENGTH
Definition: sha.h:155
ext_sct_add_clienthello
static bool ext_sct_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:1323
ssl_client_hello_inner
@ ssl_client_hello_inner
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1487
Array::Reset
void Reset()
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:287
SSL_CONFIG::signed_cert_timestamps_enabled
bool signed_cert_timestamps_enabled
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3051
first
StrT first
Definition: cxa_demangle.cpp:4884
tls_extension_find
static const struct tls_extension * tls_extension_find(uint32_t *out_index, uint16_t value)
Definition: extensions.cc:3294
ext_ocsp_parse_serverhello
static bool ext_ocsp_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1131
EVP_MAX_MD_SIZE
#define EVP_MAX_MD_SIZE
Definition: digest.h:156
SSL_aECDSA
#define SSL_aECDSA
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:547
ext_ech_parse_serverhello
static bool ext_ech_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:659
SSLKeyShare::GroupID
virtual uint16_t GroupID() const PURE_VIRTUAL
ssl_setup_key_shares
bool ssl_setup_key_shares(SSL_HANDSHAKE *hs, uint16_t override_group_id)
Definition: extensions.cc:2263
EVP_MAX_IV_LENGTH
#define EVP_MAX_IV_LENGTH
Definition: cipher.h:533
ext_supported_groups_add_clienthello
static bool ext_supported_groups_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:2524
curve25519.h
ssl_ext_pre_shared_key_parse_clienthello
bool ssl_ext_pre_shared_key_parse_clienthello(SSL_HANDSHAKE *hs, CBS *out_ticket, CBS *out_binders, uint32_t *out_obfuscated_ticket_age, uint8_t *out_alert, const SSL_CLIENT_HELLO *client_hello, CBS *contents)
Definition: extensions.cc:2028
SSL_R_PRE_SHARED_KEY_MUST_BE_LAST
#define SSL_R_PRE_SHARED_KEY_MUST_BE_LAST
Definition: ssl.h:5534
ssl_client_hello_outer
@ ssl_client_hello_outer
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1488
SSL_AD_HANDSHAKE_FAILURE
#define SSL_AD_HANDSHAKE_FAILURE
Definition: ssl.h:3800
ok
bool ok
Definition: async_end2end_test.cc:197
ssl_ticket_aead_ignore_ticket
ssl_ticket_aead_ignore_ticket
Definition: ssl.h:2233
ext_quic_transport_params_add_clienthello
static bool ext_quic_transport_params_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:2642
ERR_clear_error
#define ERR_clear_error
Definition: boringssl_prefix_symbols.h:1413
EVP_DecryptFinal_ex
#define EVP_DecryptFinal_ex
Definition: boringssl_prefix_symbols.h:1502
ssl_ech_rejected
@ ssl_ech_rejected
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2616
ext_early_data_parse_serverhello
static bool ext_early_data_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2189
TLSEXT_STATUSTYPE_ocsp
#define TLSEXT_STATUSTYPE_ocsp
Definition: tls1.h:265
SSLTranscript::GetHash
bool GetHash(uint8_t *out, size_t *out_len) const
Definition: ssl_transcript.cc:235
CBS_get_bytes
#define CBS_get_bytes
Definition: boringssl_prefix_symbols.h:1067
TLSEXT_TYPE_session_ticket
#define TLSEXT_TYPE_session_ticket
Definition: tls1.h:226
tls_extension::add_serverhello
bool(* add_serverhello)(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:539
ssl_client_cipher_list_contains_cipher
BSSL_NAMESPACE_BEGIN bool ssl_client_cipher_list_contains_cipher(const SSL_CLIENT_HELLO *client_hello, uint16_t id)
Definition: handshake_server.cc:176
SSL_get_options
#define SSL_get_options
Definition: boringssl_prefix_symbols.h:354
kDefaultGroups
static const uint16_t kDefaultGroups[]
Definition: extensions.cc:305
ext_cookie_add_clienthello
static bool ext_cookie_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:2499
GrowableArray::empty
bool empty() const
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:388
srtp_protection_profile_st
Definition: ssl.h:3058
sk_SRTP_PROTECTION_PROFILE_num
#define sk_SRTP_PROTECTION_PROFILE_num
Definition: boringssl_prefix_symbols.h:563
ext_sct_parse_serverhello
static bool ext_sct_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1338
SSL_TLSEXT_ERR_ALERT_FATAL
#define SSL_TLSEXT_ERR_ALERT_FATAL
Definition: ssl.h:2757
SSL_MAX_SSL_SESSION_ID_LENGTH
#define SSL_MAX_SSL_SESSION_ID_LENGTH
Definition: ssl.h:1728
ssl_ctx_rotate_ticket_encryption_key
int ssl_ctx_rotate_ticket_encryption_key(SSL_CTX *ctx)
Definition: ssl_session.cc:403
ssl_st::options
uint32_t options
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3763
tls1_check_duplicate_extensions
static bool tls1_check_duplicate_extensions(const CBS *cbs)
Definition: extensions.cc:157
SSL_R_CHANNEL_ID_SIGNATURE_INVALID
#define SSL_R_CHANNEL_ID_SIGNATURE_INVALID
Definition: ssl.h:5397
ssl_decrypt_ticket_with_cb
static enum ssl_ticket_aead_result_t ssl_decrypt_ticket_with_cb(SSL_HANDSHAKE *hs, Array< uint8_t > *out, bool *out_renew_ticket, Span< const uint8_t > ticket)
Definition: extensions.cc:3862
plaintext
const char * plaintext
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/strutil_unittest.cc:85
SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST
#define SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST
Definition: ssl.h:5384
SSL_HANDSHAKE::certificate_status_expected
bool certificate_status_expected
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1970
ext_srtp_add_serverhello
static bool ext_srtp_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:1828
ssl_cert_verify_channel_id
@ ssl_cert_verify_channel_id
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2184
SSL_CURVE_SECP384R1
#define SSL_CURVE_SECP384R1
Definition: ssl.h:2328
bytes_written
static size_t bytes_written
Definition: test-ipc-heavy-traffic-deadlock-bug.c:46
tls1_channel_id_hash
bool tls1_channel_id_hash(SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len)
Definition: extensions.cc:4219
SSL_CONFIG::permute_extensions
bool permute_extensions
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3090
TLSEXT_TYPE_application_settings
#define TLSEXT_TYPE_application_settings
Definition: tls1.h:247
ext_sigalgs_parse_clienthello
static bool ext_sigalgs_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1089
SSL_AD_UNRECOGNIZED_NAME
#define SSL_AD_UNRECOGNIZED_NAME
Definition: ssl.h:3822
SSL_HANDSHAKE::ticket_expected
bool ticket_expected
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2007
SSL_HANDSHAKE::ech_keys
UniquePtr< SSL_ECH_KEYS > ech_keys
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1925
Span::data
T * data() const
Definition: boringssl-with-bazel/src/include/openssl/span.h:132
ext_ocsp_parse_clienthello
static bool ext_ocsp_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1157
TLSEXT_TYPE_encrypted_client_hello
#define TLSEXT_TYPE_encrypted_client_hello
Definition: tls1.h:251
SSLKeyShare::Finish
virtual bool Finish(Array< uint8_t > *out_secret, uint8_t *out_alert, Span< const uint8_t > peer_key) PURE_VIRTUAL
SSL_SIGN_ECDSA_SHA1
#define SSL_SIGN_ECDSA_SHA1
Definition: ssl.h:1069
CBB_len
#define CBB_len
Definition: boringssl_prefix_symbols.h:1049
SSL_R_DECODE_ERROR
#define SSL_R_DECODE_ERROR
Definition: ssl.h:5405
tls1_get_shared_group
bool tls1_get_shared_group(SSL_HANDSHAKE *hs, uint16_t *out_group_id)
Definition: extensions.cc:318
SSL_HANDSHAKE::received
uint32_t received
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1805
SSL_HANDSHAKE::peer_delegated_credential_sigalgs
Array< uint16_t > peer_delegated_credential_sigalgs
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1866
mem.h
ssl_st::session_ctx
bssl::UniquePtr< SSL_CTX > session_ctx
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3758
ssl_add_serverhello_tlsext
bool ssl_add_serverhello_tlsext(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:3552
ssl_ext_key_share_parse_serverhello
bool ssl_ext_key_share_parse_serverhello(SSL_HANDSHAKE *hs, Array< uint8_t > *out_secret, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2350
ext_ticket_add_clienthello
static bool ext_ticket_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:990
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
ext_ticket_parse_serverhello
static bool ext_ticket_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1025
TLSEXT_TYPE_application_layer_protocol_negotiation
#define TLSEXT_TYPE_application_layer_protocol_negotiation
Definition: tls1.h:198
ssl_add_supported_versions
bool ssl_add_supported_versions(const SSL_HANDSHAKE *hs, CBB *cbb, uint16_t extra_min_version)
Definition: ssl_versions.cc:276
TLSEXT_TYPE_pre_shared_key
#define TLSEXT_TYPE_pre_shared_key
Definition: tls1.h:230
SSL_HANDSHAKE_HINTS
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1698
SSL_PSK_DHE_KE
#define SSL_PSK_DHE_KE
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3094
ssl_signing_with_dc
bool ssl_signing_with_dc(const SSL_HANDSHAKE *hs)
Definition: ssl_cert.cc:831
ext_quic_transport_params_parse_clienthello
static bool ext_quic_transport_params_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2733
tls1_verify_channel_id
bool tls1_verify_channel_id(SSL_HANDSHAKE *hs, const SSLMessage &msg)
Definition: extensions.cc:4111
SSL_R_DUPLICATE_KEY_SHARE
#define SSL_R_DUPLICATE_KEY_SHARE
Definition: ssl.h:5531
EVP_aes_128_cbc
const OPENSSL_EXPORT EVP_CIPHER * EVP_aes_128_cbc(void)
TLSEXT_TYPE_quic_transport_parameters
#define TLSEXT_TYPE_quic_transport_parameters
Definition: tls1.h:214
ext_srtp_add_clienthello
static bool ext_srtp_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:1710
SSL_HANDSHAKE::key_share_bytes
Array< uint8_t > key_share_bytes
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1848
TLSEXT_TYPE_server_name
#define TLSEXT_TYPE_server_name
Definition: tls1.h:185
SSL_OP_NO_TICKET
#define SSL_OP_NO_TICKET
Definition: ssl.h:709
SSL_AD_NO_APPLICATION_PROTOCOL
#define SSL_AD_NO_APPLICATION_PROTOCOL
Definition: ssl.h:3828
SHA256_Final
#define SHA256_Final
Definition: boringssl_prefix_symbols.h:2155
SSL_R_ERROR_PARSING_EXTENSION
#define SSL_R_ERROR_PARSING_EXTENSION
Definition: ssl.h:5417
ext_sni_add_clienthello
static bool ext_sni_add_clienthello(const SSL_HANDSHAKE *hs, CBB *out, CBB *out_compressible, ssl_client_hello_type_t type)
Definition: extensions.cc:568
tls13_get_cert_verify_signature_input
bool tls13_get_cert_verify_signature_input(SSL_HANDSHAKE *hs, Array< uint8_t > *out, enum ssl_cert_verify_context_t cert_verify_context)
Definition: tls13_both.cc:56
ssl_st::ctx
bssl::UniquePtr< SSL_CTX > ctx
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:3754
ext_channel_id_parse_clienthello
static bool ext_channel_id_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:1676
ssl_private_key_supports_signature_algorithm
bool ssl_private_key_supports_signature_algorithm(SSL_HANDSHAKE *hs, uint16_t sigalg)
Definition: ssl_privkey.cc:290
HMAC_Update
#define HMAC_Update
Definition: boringssl_prefix_symbols.h:1794
ext_ri_add_serverhello
static bool ext_ri_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:889
SSL_AD_DECRYPT_ERROR
#define SSL_AD_DECRYPT_ERROR
Definition: ssl.h:3811
SSL_HANDSHAKE::cert_compression_negotiated
bool cert_compression_negotiated
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:2029
SSL_R_PSK_IDENTITY_NOT_FOUND
#define SSL_R_PSK_IDENTITY_NOT_FOUND
Definition: ssl.h:5462
TLSEXT_TYPE_ec_point_formats
#define TLSEXT_TYPE_ec_point_formats
Definition: tls1.h:189
ext_quic_transport_params_parse_serverhello_legacy
static bool ext_quic_transport_params_parse_serverhello_legacy(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:2686
TLSEXT_NAMETYPE_host_name
#define TLSEXT_NAMETYPE_host_name
Definition: ssl.h:2721
ssl_early_data_session_not_resumed
ssl_early_data_session_not_resumed
Definition: ssl.h:3567
ssl_ticket_aead_error
ssl_ticket_aead_error
Definition: ssl.h:2236
CRYPTO_memcmp
#define CRYPTO_memcmp
Definition: boringssl_prefix_symbols.h:1178
CBB_discard_child
#define CBB_discard_child
Definition: boringssl_prefix_symbols.h:1042
kNumExtensions
#define kNumExtensions
Definition: extensions.cc:3261
ssl_early_callback_ctx::extensions_len
size_t extensions_len
Definition: ssl.h:4200
BN_new
#define BN_new
Definition: boringssl_prefix_symbols.h:971
hmac.h
ssl_get_local_application_settings
bool ssl_get_local_application_settings(const SSL_HANDSHAKE *hs, Span< const uint8_t > *out_settings, Span< const uint8_t > protocol)
Definition: extensions.cc:2937
tls12_add_verify_sigalgs
bool tls12_add_verify_sigalgs(const SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:481
ext_ri_parse_clienthello
static bool ext_ri_parse_clienthello(SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents)
Definition: extensions.cc:854
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230
CRYPTO_BUFFER_data
#define CRYPTO_BUFFER_data
Definition: boringssl_prefix_symbols.h:1115
ERR_R_MALLOC_FAILURE
#define ERR_R_MALLOC_FAILURE
Definition: err.h:371
SSL_HANDSHAKE::delegated_credential_requested
bool delegated_credential_requested
Definition: third_party/boringssl-with-bazel/src/ssl/internal.h:1977
id
uint32_t id
Definition: flow_control_fuzzer.cc:70
ssl_ext_pre_shared_key_add_serverhello
bool ssl_ext_pre_shared_key_add_serverhello(SSL_HANDSHAKE *hs, CBB *out)
Definition: extensions.cc:2094
SSL_SIGN_ECDSA_SECP384R1_SHA384
#define SSL_SIGN_ECDSA_SECP384R1_SHA384
Definition: ssl.h:1071
absl::MakeConstSpan
constexpr Span< const T > MakeConstSpan(T *ptr, size_t size) noexcept
Definition: abseil-cpp/absl/types/span.h:707
SSL_SIGN_ECDSA_SECP256R1_SHA256
#define SSL_SIGN_ECDSA_SECP256R1_SHA256
Definition: ssl.h:1070
cbb_st
Definition: bytestring.h:375
SHA256_Update
#define SHA256_Update
Definition: boringssl_prefix_symbols.h:2159


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:18