Botan 3.11.0
Crypto and TLS for C&
tls_extensions_12.cpp
Go to the documentation of this file.
1/*
2* TLS 1.2 Specific Extensions
3* (C) 2011,2012,2015,2016 Jack Lloyd
4* 2016 Juraj Somorovsky
5* 2021 Elektrobit Automotive GmbH
6* 2022 René Meusel, Hannes Rantzsch - neXenio GmbH
7* 2023 Mateusz Berezecki
8* 2023 Fabian Albert, René Meusel - Rohde & Schwarz Cybersecurity
9* 2026 René Meusel - Rohde & Schwarz Cybersecurity
10*
11* Botan is released under the Simplified BSD License (see license.txt)
12*/
13
14#include <botan/tls_extensions_12.h>
15
16#include <botan/tls_alert.h>
17#include <botan/tls_exceptn.h>
18#include <botan/internal/tls_reader.h>
19#include <algorithm>
20
21namespace Botan::TLS {
22
24 m_reneg_data(reader.get_range<uint8_t>(1, 0, 255)) {
25 if(m_reneg_data.size() + 1 != extension_size) {
26 throw Decoding_Error("Bad encoding for secure renegotiation extn");
27 }
28}
29
30std::vector<uint8_t> Renegotiation_Extension::serialize(Connection_Side /*whoami*/) const {
31 std::vector<uint8_t> buf;
32 append_tls_length_value(buf, m_reneg_data, 1);
33 return buf;
34}
35
36std::vector<uint8_t> Supported_Point_Formats::serialize(Connection_Side /*whoami*/) const {
37 // if this extension is sent, it MUST include uncompressed (RFC 4492, section 5.1)
38 if(m_prefers_compressed) {
39 return std::vector<uint8_t>{2, ANSIX962_COMPRESSED_PRIME, UNCOMPRESSED};
40 } else {
41 return std::vector<uint8_t>{1, UNCOMPRESSED};
42 }
43}
44
46 const uint8_t len = reader.get_byte();
47
48 if(len + 1 != extension_size) {
49 throw Decoding_Error("Inconsistent length field in supported point formats list");
50 }
51
52 bool includes_uncompressed = false;
53 for(size_t i = 0; i != len; ++i) {
54 const uint8_t format = reader.get_byte();
55
56 if(static_cast<ECPointFormat>(format) == UNCOMPRESSED) {
57 m_prefers_compressed = false;
58 reader.discard_next(len - i - 1);
59 return;
60 } else if(static_cast<ECPointFormat>(format) == ANSIX962_COMPRESSED_PRIME) {
61 m_prefers_compressed = true;
62 std::vector<uint8_t> remaining_formats = reader.get_fixed<uint8_t>(len - i - 1);
63 includes_uncompressed =
64 std::any_of(std::begin(remaining_formats), std::end(remaining_formats), [](uint8_t remaining_format) {
65 return static_cast<ECPointFormat>(remaining_format) == UNCOMPRESSED;
66 });
67 break;
68 }
69
70 // ignore ANSIX962_COMPRESSED_CHAR2, we don't support these curves
71 }
72
73 // RFC 4492 5.1.:
74 // If the Supported Point Formats Extension is indeed sent, it MUST contain the value 0 (uncompressed)
75 // as one of the items in the list of point formats.
76 // Note:
77 // RFC 8422 5.1.2. explicitly requires this check,
78 // but only if the Supported Groups extension was sent.
79 if(!includes_uncompressed) {
80 throw TLS_Exception(Alert::IllegalParameter,
81 "Supported Point Formats Extension must contain the uncompressed point format");
82 }
83}
84
86 m_ticket(Session_Ticket(reader.get_elem<uint8_t, std::vector<uint8_t>>(extension_size))) {}
87
89 if(extension_size != 0) {
90 throw Decoding_Error("Invalid extended_master_secret extension");
91 }
92}
93
94std::vector<uint8_t> Extended_Master_Secret::serialize(Connection_Side /*whoami*/) const {
95 return std::vector<uint8_t>();
96}
97
98Encrypt_then_MAC::Encrypt_then_MAC(TLS_Data_Reader& /*unused*/, uint16_t extension_size) {
99 if(extension_size != 0) {
100 throw Decoding_Error("Invalid encrypt_then_mac extension");
101 }
102}
103
104std::vector<uint8_t> Encrypt_then_MAC::serialize(Connection_Side /*whoami*/) const {
105 return std::vector<uint8_t>();
106}
107
108} // namespace Botan::TLS
std::vector< uint8_t > serialize(Connection_Side whoami) const override
std::vector< uint8_t > serialize(Connection_Side whoami) const override
std::vector< uint8_t > serialize(Connection_Side whoami) const override
std::vector< uint8_t > serialize(Connection_Side whoami) const override
Supported_Point_Formats(bool prefer_compressed)
void discard_next(size_t bytes)
Definition tls_reader.h:51
std::vector< T > get_fixed(size_t size)
Definition tls_reader.h:129
void append_tls_length_value(std::vector< uint8_t, Alloc > &buf, const T *vals, size_t vals_size, size_t tag_size)
Definition tls_reader.h:177
Strong< std::vector< uint8_t >, struct Session_Ticket_ > Session_Ticket
holds a TLS 1.2 session ticket for stateless resumption