Botan 3.14.1
Crypto and TLS for C&
Botan::TLS::Record_Size_Limit Class Referencefinal

#include <tls_extensions.h>

Inheritance diagram for Botan::TLS::Record_Size_Limit:
Botan::TLS::Extension

Public Member Functions

bool empty () const override
virtual bool is_implemented () const
uint16_t limit () const
 Record_Size_Limit (TLS_Data_Reader &reader, uint16_t extension_size, Connection_Side from)
 Record_Size_Limit (uint16_t limit)
std::vector< uint8_t > serialize (Connection_Side whoami) const override
Extension_Code type () const override

Static Public Member Functions

static Extension_Code static_type ()

Detailed Description

Record Size Limit (RFC 8449)

TODO: the record size limit is currently not honored by the TLS 1.2 stack

Definition at line 439 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ Record_Size_Limit() [1/2]

Botan::TLS::Record_Size_Limit::Record_Size_Limit ( uint16_t limit)
explicit

Definition at line 962 of file tls_extensions.cpp.

962 : m_limit(limit) {
963 BOTAN_ARG_CHECK(limit >= 64, "RFC 8449 does not allow record size limits smaller than 64 bytes");
964 BOTAN_ARG_CHECK(limit <= MAX_PLAINTEXT_SIZE + 1 /* encrypted content type byte */,
965 "RFC 8449 does not allow record size limits larger than 2^14+1");
966}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33
@ MAX_PLAINTEXT_SIZE
Definition tls_magic.h:37

References BOTAN_ARG_CHECK, limit(), and Botan::TLS::MAX_PLAINTEXT_SIZE.

◆ Record_Size_Limit() [2/2]

Botan::TLS::Record_Size_Limit::Record_Size_Limit ( TLS_Data_Reader & reader,
uint16_t extension_size,
Connection_Side from )

Definition at line 968 of file tls_extensions.cpp.

968 {
969 if(extension_size != 2) {
970 throw TLS_Exception(Alert::DecodeError, "invalid record_size_limit extension");
971 }
972
973 m_limit = reader.get_uint16_t();
974
975 // RFC 8449 4.
976 // This value is the length of the plaintext of a protected record.
977 // The value includes the content type and padding added in TLS 1.3 (that
978 // is, the complete length of TLSInnerPlaintext).
979 //
980 // A server MUST NOT enforce this restriction; a client might advertise
981 // a higher limit that is enabled by an extension or version the server
982 // does not understand. A client MAY abort the handshake with an
983 // "illegal_parameter" alert.
984 //
985 // Note: We are currently supporting this extension in TLS 1.3 only, hence
986 // we check for the TLS 1.3 limit. The TLS 1.2 limit would not include
987 // the "content type byte" and hence be one byte less!
988 if(m_limit > MAX_PLAINTEXT_SIZE + 1 /* encrypted content type byte */ && from == Connection_Side::Server) {
989 throw TLS_Exception(Alert::IllegalParameter,
990 "Server requested a record size limit larger than the protocol's maximum");
991 }
992
993 // RFC 8449 4.
994 // Endpoints MUST NOT send a "record_size_limit" extension with a value
995 // smaller than 64. An endpoint MUST treat receipt of a smaller value
996 // as a fatal error and generate an "illegal_parameter" alert.
997 if(m_limit < 64) {
998 throw TLS_Exception(Alert::IllegalParameter, "Received a record size limit smaller than 64 bytes");
999 }
1000}

References Botan::TLS::TLS_Data_Reader::get_uint16_t(), Botan::TLS::MAX_PLAINTEXT_SIZE, and Botan::TLS::Server.

Member Function Documentation

◆ empty()

bool Botan::TLS::Record_Size_Limit::empty ( ) const
inlineoverridevirtual

Predicate if a TLS extension should be included or not

Returns
true if this extension should be encoded, otherwise false

Implements Botan::TLS::Extension.

Definition at line 453 of file tls_extensions.h.

453{ return m_limit == 0; }

◆ is_implemented()

virtual bool Botan::TLS::Extension::is_implemented ( ) const
inlinevirtualinherited

Predicate if the extension is known/implemented

Note
this exists primarily to support unknown extension handling and doesn't need to be overridden even in the custom extension case.
Returns
true if this extension is known

Reimplemented in Botan::TLS::Unknown_Extension.

Definition at line 113 of file tls_extensions.h.

113{ return true; }

◆ limit()

uint16_t Botan::TLS::Record_Size_Limit::limit ( ) const
inline

Definition at line 449 of file tls_extensions.h.

449{ return m_limit; }

Referenced by Record_Size_Limit().

◆ serialize()

std::vector< uint8_t > Botan::TLS::Record_Size_Limit::serialize ( Connection_Side whoami) const
overridevirtual

Serialize a TLS extension

Parameters
whoamiwhich peer we are acting as in the protocol
Returns
serialized binary for the extension

Implements Botan::TLS::Extension.

Definition at line 1002 of file tls_extensions.cpp.

1002 {
1003 std::vector<uint8_t> buf;
1004
1005 buf.push_back(get_byte<0>(m_limit));
1006 buf.push_back(get_byte<1>(m_limit));
1007
1008 return buf;
1009}
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79

References Botan::get_byte().

◆ static_type()

Extension_Code Botan::TLS::Record_Size_Limit::static_type ( )
inlinestatic

Definition at line 441 of file tls_extensions.h.

References Botan::TLS::RecordSizeLimit.

Referenced by type().

◆ type()

Extension_Code Botan::TLS::Record_Size_Limit::type ( ) const
inlineoverridevirtual

Return TLS extension code

Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 443 of file tls_extensions.h.

443{ return static_type(); }
static Extension_Code static_type()

References static_type().


The documentation for this class was generated from the following files: