STUN module (rfc5389)

MessageIntegrity

Implements the STUN MESSAGE-INTEGRITY attribute (RFC 5389 section 15.4).

MessageIntegrity

#include <icy/stun/attributes.h>

Inherits: Attribute

Implements the STUN MESSAGE-INTEGRITY attribute (RFC 5389 section 15.4). On write, computes an HMAC-SHA1 over the message bytes preceding this attribute when a key is set. On read, captures the raw HMAC bytes and the input bytes needed to verify them later via verifyHmac().

Public Methods

ReturnNameDescription
MessageIntegrity
MessageIntegrity
std::unique_ptr< Attribute >clone virtualReturns a deep copy of this attribute.
boolverifyHmac constVerifies the stored HMAC against the stored input bytes using key.
std::stringinput const inline#### Returns
std::stringhmac const inline#### Returns
std::stringkey const inline#### Returns
voidsetInput inlineSets the raw message bytes used as HMAC input during verification.
voidsetHmac inlineSets the raw HMAC value (used when copying a received attribute).
voidsetKey inlineSets the HMAC key; triggers HMAC computation on write().
voidread virtualReads the body (not the type or size) for this type of attribute from the given buffer.
voidwrite virtual constWrites the body (not the type or size) to the given buffer.

MessageIntegrity

MessageIntegrity()

MessageIntegrity

MessageIntegrity(const MessageIntegrity & r)

clone

virtual

virtual std::unique_ptr< Attribute > clone()

Returns a deep copy of this attribute.


verifyHmac

const

bool verifyHmac(std::string_view key) const

Verifies the stored HMAC against the stored input bytes using key.

Parameters

  • key HMAC key (MD5 of username:realm:password for long-term creds).

Returns

true if the computed HMAC matches the stored HMAC.


input

const inline

inline std::string input() const

Returns

The raw message bytes captured at read time, used for HMAC verification.


hmac

const inline

inline std::string hmac() const

Returns

The raw 20-byte HMAC value as read from the wire.


key

const inline

inline std::string key() const

Returns

The HMAC key set for outgoing message signing (empty if not set).


setInput

inline

inline void setInput(const std::string & input)

Sets the raw message bytes used as HMAC input during verification.

Parameters

  • input Byte string of the message up to this attribute.

setHmac

inline

inline void setHmac(const std::string & hmac)

Sets the raw HMAC value (used when copying a received attribute).

Parameters

  • hmac 20-byte HMAC string.

setKey

inline

inline void setKey(const std::string & key)

Sets the HMAC key; triggers HMAC computation on write().

Parameters

  • key MD5 digest of the long-term credential (username:realm:password).

read

virtual

virtual void read(BitReader & reader)

Reads the body (not the type or size) for this type of attribute from the given buffer.

Parameters

  • reader Source bit reader positioned at the attribute body.

write

virtual const

virtual void write(BitWriter & writer) const

Writes the body (not the type or size) to the given buffer.

Parameters

  • writer Destination bit writer.

Public Static Attributes

ReturnNameDescription
constexpr uint16_tTypeID static
constexpr uint16_tSize staticHMAC-SHA1 output is always 20 bytes.

TypeID

static

constexpr uint16_t TypeID = 0x0008

Size

static

constexpr uint16_t Size = 20

HMAC-SHA1 output is always 20 bytes.

Private Attributes

ReturnNameDescription
std::string_input
std::string_hmac
std::string_key

_input

std::string _input

_hmac

std::string _hmac

_key

std::string _key