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

#include <tls_extensions.h>

Inheritance diagram for Botan::TLS::SRTP_Protection_Profiles:
Botan::TLS::Extension

Public Member Functions

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

Static Public Member Functions

static Extension_Code static_type ()

Detailed Description

Used to indicate SRTP algorithms for DTLS (RFC 5764)

Definition at line 342 of file tls_extensions.h.

Constructor & Destructor Documentation

◆ SRTP_Protection_Profiles() [1/3]

Botan::TLS::SRTP_Protection_Profiles::SRTP_Protection_Profiles ( std::vector< uint16_t > pp)
inlineexplicit

Definition at line 354 of file tls_extensions.h.

354: m_pp(std::move(pp)) {}

◆ SRTP_Protection_Profiles() [2/3]

Botan::TLS::SRTP_Protection_Profiles::SRTP_Protection_Profiles ( uint16_t pp)
inlineexplicit

Definition at line 356 of file tls_extensions.h.

356: m_pp(1, pp) {}

◆ SRTP_Protection_Profiles() [3/3]

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

Definition at line 818 of file tls_extensions.cpp.

820 {
821 // RFC 5764 4.1.1: UseSRTPData consists of
822 // SRTPProtectionProfile SRTPProtectionProfiles<2..2^16-1>;
823 // opaque srtp_mki<0..255>;
824 // for a wire size of 2 (profiles len) + 2*N + 1 (mki len) + mki_bytes,
825 // with N >= 1.
826 if(extension_size < 5) {
827 throw Decoding_Error("Truncated SRTP protection extension");
828 }
829 const size_t max_profile_pairs = (static_cast<size_t>(extension_size) - 3) / 2;
830 m_pp = reader.get_range<uint16_t>(2, 1, max_profile_pairs);
831 const std::vector<uint8_t> mki = reader.get_range<uint8_t>(1, 0, 255);
832
833 if(m_pp.size() * 2 + mki.size() + 3 != extension_size) {
834 throw Decoding_Error("Bad encoding for SRTP protection extension");
835 }
836
837 // RFC 5764 4.1.1
838 // The extension_data field MUST contain a [...] single
839 // SRTPProtectionProfile value that the server has chosen for use with
840 // this connection.
841 if(from == Connection_Side::Server && (m_pp.size() != 1 || m_pp.front() == 0)) {
842 throw TLS_Exception(Alert::DecodeError, "Server sent malformed DTLS-SRTP extension");
843 }
844
845 // Any srtp_mki the client offers is ignored; serialize() always answers
846 // with an empty srtp_mki, per RFC 5764 4.1.3:
847 // 2. return an empty "srtp_mki" value to indicate that it cannot make
848 // use of the MKI.
849 //
850 // As a client we always offer an empty MKI, so a server cannot select one:
851 //
852 // RFC 5764 4.1.3
853 // If the client detects a nonzero-length MKI in the server's response
854 // that is different than the one the client offered, then the client
855 // MUST abort the handshake and SHOULD send an invalid_parameter alert.
856 if(from == Connection_Side::Server && !mki.empty()) {
857 throw TLS_Exception(Alert::IllegalParameter, "Server selected a DTLS-SRTP MKI that was not offered");
858 }
859}

References Botan::TLS::TLS_Data_Reader::get_range(), and Botan::TLS::Server.

Member Function Documentation

◆ empty()

bool Botan::TLS::SRTP_Protection_Profiles::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 352 of file tls_extensions.h.

352{ return m_pp.empty(); }

◆ 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; }

◆ profiles()

const std::vector< uint16_t > & Botan::TLS::SRTP_Protection_Profiles::profiles ( ) const
inline

Definition at line 348 of file tls_extensions.h.

348{ return m_pp; }

◆ serialize()

std::vector< uint8_t > Botan::TLS::SRTP_Protection_Profiles::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 861 of file tls_extensions.cpp.

861 {
862 std::vector<uint8_t> buf;
863
864 const uint16_t pp_len = static_cast<uint16_t>(m_pp.size() * 2);
865 buf.push_back(get_byte<0>(pp_len));
866 buf.push_back(get_byte<1>(pp_len));
867
868 for(const uint16_t pp : m_pp) {
869 buf.push_back(get_byte<0>(pp));
870 buf.push_back(get_byte<1>(pp));
871 }
872
873 buf.push_back(0); // srtp_mki, always empty here
874
875 return buf;
876}
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79

References Botan::get_byte().

◆ static_type()

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

Definition at line 344 of file tls_extensions.h.

References Botan::TLS::UseSrtp.

Referenced by type().

◆ type()

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

Return TLS extension code

Returns
code number of the extension

Implements Botan::TLS::Extension.

Definition at line 346 of file tls_extensions.h.

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

References static_type().


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