• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 24648292556

19 Apr 2026 10:53PM UTC coverage: 89.474% (+0.03%) from 89.442%
24648292556

push

github

web-flow
Merge pull request #5536 from randombit/jack/x509-misc

Various PKIX optimizations and bug fixes

106453 of 118977 relevant lines covered (89.47%)

11452293.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.74
/src/lib/tls/tls13/msg_encrypted_extensions.cpp
1
/*
2
* TLS Hello Request and Client Hello Messages
3
* (C) 2022 Jack Lloyd
4
*     2022 René Meusel, Hannes Rantzsch - neXenio GmbH
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
*/
8

9
#include <botan/tls_messages_13.h>
10

11
#include <botan/tls_callbacks.h>
12
#include <botan/tls_exceptn.h>
13
#include <botan/tls_policy.h>
14
#include <botan/internal/tls_reader.h>
15

16
namespace Botan::TLS {
17

18
Encrypted_Extensions::Encrypted_Extensions(const Client_Hello_13& client_hello,
390✔
19
                                           const Policy& policy,
20
                                           Callbacks& cb,
21
                                           bool is_resumption) {
390✔
22
   const auto& exts = client_hello.extensions();
390✔
23

24
   // NOLINTBEGIN(*-owning-memory)
25

26
   // RFC 8446 4.2.7
27
   //    As of TLS 1.3, servers are permitted to send the "supported_groups"
28
   //    extension to the client.  Clients [...] MAY use the information
29
   //    learned from a successfully completed handshake to change what groups
30
   //    they use in their "key_share" extension in subsequent connections.
31
   if(exts.has<Supported_Groups>()) {
390✔
32
      m_extensions.add(new Supported_Groups(policy.key_exchange_groups()));
780✔
33
   }
34

35
   const auto record_size_limit = policy.record_size_limit();
390✔
36
   const auto max_record_size = MAX_PLAINTEXT_SIZE + 1 /* encrypted content type byte */;
390✔
37
   if(exts.has<Record_Size_Limit>()) {
390✔
38
      // RFC 8449 4
39
      //    Endpoints SHOULD advertise the "record_size_limit" extension, even
40
      //    if they have no need to limit the size of records. [...]  For
41
      //    servers, this allows clients to know that their limit will be
42
      //    respected.
43
      m_extensions.add(new Record_Size_Limit(record_size_limit.value_or(max_record_size)));
15✔
44
   } else if(record_size_limit.has_value() && record_size_limit.value() < max_record_size) {
382✔
45
      // RFC 8449 4
46
      //    Endpoints SHOULD advertise the "record_size_limit" extension, even if
47
      //    they have no need to limit the size of records. For clients, this
48
      //    allows servers to advertise a limit at their discretion.
49
      throw TLS_Exception(Alert::MissingExtension,
×
50
                          "Server cannot enforce record size limit without the client supporting it");
×
51
   }
52

53
   // RFC 7250 4.2
54
   //    If the TLS server wants to request a certificate from the client
55
   //    (via the certificate_request message), it MUST include the
56
   //    client_certificate_type extension in the server hello.
57
   //    [...]
58
   //    If the server does not send a certificate_request payload [...],
59
   //    then the client_certificate_type payload in the server hello MUST be
60
   //    omitted.
61
   if(auto* ch_client_cert_types = exts.get<Client_Certificate_Type>();
390✔
62
      ch_client_cert_types != nullptr && policy.request_client_certificate_authentication()) {
390✔
63
      m_extensions.add(new Client_Certificate_Type(*ch_client_cert_types, policy));
9✔
64
   }
65

66
   // RFC 7250 4.2
67
   //    The server_certificate_type extension in the client hello indicates the
68
   //    types of certificates the client is able to process when provided by
69
   //    the server in a subsequent certificate payload. [...] With the
70
   //    server_certificate_type extension in the server hello, the TLS server
71
   //    indicates the certificate type carried in the Certificate payload.
72
   if(auto* ch_server_cert_types = exts.get<Server_Certificate_Type>()) {
390✔
73
      m_extensions.add(new Server_Certificate_Type(*ch_server_cert_types, policy));
1✔
74
   }
75

76
   // RFC 6066 3
77
   //    A server that receives a client hello containing the "server_name"
78
   //    extension [...] SHALL include an extension of type "server_name" in the
79
   //    (extended) server hello. The "extension_data" field of this extension
80
   //    SHALL be empty.
81
   //
82
   //    When resuming a session, the server MUST NOT include a server_name
83
   //    extension in the server hello.
84
   if(exts.has<Server_Name_Indicator>() && !is_resumption) {
390✔
85
      m_extensions.add(new Server_Name_Indicator(""));
289✔
86
   }
87

88
   if(auto* alpn_ext = exts.get<Application_Layer_Protocol_Notification>()) {
390✔
89
      const auto next_protocol = cb.tls_server_choose_app_protocol(alpn_ext->protocols());
7✔
90
      if(!next_protocol.empty()) {
6✔
91
         m_extensions.add(new Application_Layer_Protocol_Notification(next_protocol));
4✔
92
      }
93
   }
6✔
94

95
   // NOLINTEND(*-owning-memory)
96

97
   // TODO: Implement handling for (at least)
98
   //       * SRTP
99

100
   cb.tls_modify_extensions(m_extensions, Connection_Side::Server, type());
389✔
101
}
390✔
102

103
Encrypted_Extensions::Encrypted_Extensions(const std::vector<uint8_t>& buf) {
486✔
104
   TLS_Data_Reader reader("encrypted extensions reader", buf);
486✔
105

106
   // Encrypted Extensions contains a list of extensions. This list may legally
107
   // be empty. However, in that case we should at least see a two-byte length
108
   // field that reads 0x00 0x00.
109
   if(buf.size() < 2) {
486✔
110
      throw TLS_Exception(Alert::DecodeError, "Server sent an empty Encrypted Extensions message");
1✔
111
   }
112

113
   m_extensions.deserialize(reader, Connection_Side::Server, type());
485✔
114

115
   // RFC 8446 4.2
116
   //    If an implementation receives an extension which it recognizes and
117
   //    which is not specified for the message in which it appears, it MUST
118
   //    abort the handshake with an "illegal_parameter" alert.
119
   //
120
   // Note that we cannot encounter any extensions that we don't recognize here,
121
   // since only extensions we previously offered are allowed in EE.
122
   const auto allowed_exts = std::set<Extension_Code>{
481✔
123
      // Allowed extensions listed in RFC 8446 and implemented in Botan
124
      Extension_Code::ServerNameIndication,
125
      // MAX_FRAGMENT_LENGTH
126
      Extension_Code::SupportedGroups,
127
      Extension_Code::UseSrtp,
128
      // HEARTBEAT
129
      Extension_Code::ApplicationLayerProtocolNegotiation,
130
      // RFC 7250
131
      Extension_Code::ClientCertificateType,
132
      Extension_Code::ServerCertificateType,
133
      // EARLY_DATA
134

135
      // Allowed extensions not listed in RFC 8446 but acceptable as Botan implements them
136
      Extension_Code::RecordSizeLimit,
137
   };
481✔
138
   if(m_extensions.contains_implemented_extensions_other_than(allowed_exts)) {
481✔
139
      throw TLS_Exception(Alert::IllegalParameter, "Encrypted Extensions contained an extension that is not allowed");
5✔
140
   }
141
}
486✔
142

143
std::vector<uint8_t> Encrypted_Extensions::serialize() const {
402✔
144
   return m_extensions.serialize(Connection_Side::Server);
402✔
145
}
146

147
}  // namespace Botan::TLS
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc