Home
STUN module (rfc5389)

MessageIntegrity

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

MessageIntegrity

#include <icy/stun/attributes.h>
class MessageIntegrity

Defined in src/stun/include/icy/stun/attributes.h:468

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().

List of all members

NameKindOwner
MessageIntegrityfunctionDeclared here
MessageIntegrityfunctionDeclared here
~MessageIntegrityfunctionDeclared here
clonefunctionDeclared here
verifyHmacfunctionDeclared here
inputfunctionDeclared here
hmacfunctionDeclared here
keyfunctionDeclared here
setInputfunctionDeclared here
setHmacfunctionDeclared here
setKeyfunctionDeclared here
readfunctionDeclared here
writefunctionDeclared here
TypeIDvariableDeclared here
SizevariableDeclared here
_inputvariableDeclared here
_hmacvariableDeclared here
_keyvariableDeclared here
~AttributefunctionInherited from Attribute
clonefunctionInherited from Attribute
readfunctionInherited from Attribute
writefunctionInherited from Attribute
typefunctionInherited from Attribute
sizefunctionInherited from Attribute
paddingBytesfunctionInherited from Attribute
paddedBytesfunctionInherited from Attribute
consumePaddingfunctionInherited from Attribute
writePaddingfunctionInherited from Attribute
typeStringfunctionInherited from Attribute
TypeIDvariableInherited from Attribute
createfunctionInherited from Attribute
paddingBytesfunctionInherited from Attribute
paddedBytesfunctionInherited from Attribute
typeStringfunctionInherited from Attribute
_typevariableInherited from Attribute
_sizevariableInherited from Attribute
AttributefunctionInherited from Attribute
setLengthfunctionInherited from Attribute
TypeenumInherited from Attribute

Inherited from Attribute

KindNameDescription
function~Attribute virtual inline
functionclone virtualReturns a deep copy of this attribute.
functionread virtualReads the body (not the type or size) for this type of attribute from the given buffer.
functionwrite virtual constWrites the body (not the type or size) to the given buffer.
functiontype const
functionsize const
functionpaddingBytes const inline
functionpaddedBytes const inline
functionconsumePadding constAdvances the reader past any 4-byte alignment padding that follows this attribute's body.
functionwritePadding constWrites zero-fill padding bytes to align this attribute to a 4-byte boundary.
functiontypeString
variableTypeID static constexpr
functioncreate staticCreates an attribute of the given wire type and body size. Returns nullptr if the type is unknown or the size is invalid.
functionpaddingBytes static inline constexprReturns the 4-byte alignment padding required for a body of size bytes.
functionpaddedBytes static inline constexprReturns the body length including 4-byte alignment padding.
functiontypeString static
variable_type
variable_size
functionAttribute
functionsetLengthUpdates the stored body length.
enumType

Public Methods

ReturnNameDescription
MessageIntegrity
MessageIntegrity
std::unique_ptr< Attribute >clone virtual overrideReturns a deep copy of this attribute.
boolverifyHmac constVerifies the stored HMAC against the stored input bytes using key.
std::stringinput const inline
std::stringhmac const inline
std::stringkey const inline
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 virtual overrideReads the body (not the type or size) for this type of attribute from the given buffer.
voidwrite virtual const overrideWrites the body (not the type or size) to the given buffer.

MessageIntegrity

MessageIntegrity()

Defined in src/stun/include/icy/stun/attributes.h:471


MessageIntegrity

MessageIntegrity(const MessageIntegrity & r)

Defined in src/stun/include/icy/stun/attributes.h:472


clone

virtual override

virtual std::unique_ptr< Attribute > clone() override

Defined in src/stun/include/icy/stun/attributes.h:476

Returns a deep copy of this attribute.

Reimplements

verifyHmac

const

bool verifyHmac(std::string_view key) const

Defined in src/stun/include/icy/stun/attributes.h:484

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

Defined in src/stun/include/icy/stun/attributes.h:487

Returns

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


hmac

const inline

inline std::string hmac() const

Defined in src/stun/include/icy/stun/attributes.h:490

Returns

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


key

const inline

inline std::string key() const

Defined in src/stun/include/icy/stun/attributes.h:493

Returns

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


setInput

inline

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

Defined in src/stun/include/icy/stun/attributes.h:497

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)

Defined in src/stun/include/icy/stun/attributes.h:501

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)

Defined in src/stun/include/icy/stun/attributes.h:505

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

Parameters

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

read

virtual override

virtual void read(BitReader & reader) override

Defined in src/stun/include/icy/stun/attributes.h:507

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.
Reimplements

write

virtual const override

virtual void write(BitWriter & writer) const override

Defined in src/stun/include/icy/stun/attributes.h:508

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

Parameters

  • writer Destination bit writer.
Reimplements

Public Static Attributes

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

TypeID

static constexpr

constexpr uint16_t TypeID = 0x0008

Defined in src/stun/include/icy/stun/attributes.h:478


Size

static constexpr

constexpr uint16_t Size = 20

Defined in src/stun/include/icy/stun/attributes.h:479

HMAC-SHA1 output is always 20 bytes.

Private Attributes

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

_input

std::string _input

Defined in src/stun/include/icy/stun/attributes.h:511


_hmac

std::string _hmac

Defined in src/stun/include/icy/stun/attributes.h:512


_key

std::string _key

Defined in src/stun/include/icy/stun/attributes.h:513