MessageIntegrity
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
| Return | Name | Description |
|---|---|---|
MessageIntegrity | ||
MessageIntegrity | ||
std::unique_ptr< Attribute > | clone virtual | Returns a deep copy of this attribute. |
bool | verifyHmac const | Verifies the stored HMAC against the stored input bytes using key. |
std::string | input const inline | #### Returns |
std::string | hmac const inline | #### Returns |
std::string | key const inline | #### Returns |
void | setInput inline | Sets the raw message bytes used as HMAC input during verification. |
void | setHmac inline | Sets the raw HMAC value (used when copying a received attribute). |
void | setKey inline | Sets the HMAC key; triggers HMAC computation on write(). |
void | read virtual | Reads the body (not the type or size) for this type of attribute from the given buffer. |
void | write virtual const | Writes 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) constVerifies the stored HMAC against the stored input bytes using key.
Parameters
keyHMAC 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() constReturns
The raw message bytes captured at read time, used for HMAC verification.
hmac
const inline
inline std::string hmac() constReturns
The raw 20-byte HMAC value as read from the wire.
key
const inline
inline std::string key() constReturns
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
inputByte 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
hmac20-byte HMAC string.
setKey
inline
inline void setKey(const std::string & key)Sets the HMAC key; triggers HMAC computation on write().
Parameters
keyMD5 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
readerSource bit reader positioned at the attribute body.
write
virtual const
virtual void write(BitWriter & writer) constWrites the body (not the type or size) to the given buffer.
Parameters
writerDestination bit writer.
Public Static Attributes
| Return | Name | Description |
|---|---|---|
constexpr uint16_t | TypeID static | |
constexpr uint16_t | Size static | HMAC-SHA1 output is always 20 bytes. |
TypeID
static
constexpr uint16_t TypeID = 0x0008Size
static
constexpr uint16_t Size = 20HMAC-SHA1 output is always 20 bytes.
Private Attributes
_input
std::string _input_hmac
std::string _hmac_key
std::string _key