Commit ce13b71f authored by Youness Alaoui's avatar Youness Alaoui

Add RFC 3489 support for stun by having padding in the message integrity generation

parent 49a92546
......@@ -213,7 +213,8 @@ StunValidationStatus stun_agent_validate (StunAgent *agent, StunMessage *msg,
if (hash) {
/* We must give the size from start to the end of the attribute
because you might have a FINGERPRINT attribute after it... */
stun_sha1 (msg->buffer, hash + 20 - msg->buffer, sha, key, key_len);
stun_sha1 (msg->buffer, hash + 20 - msg->buffer, sha, key, key_len,
agent->compatibility == STUN_COMPATIBILITY_RFC3489 ? TRUE : FALSE);
stun_debug (" Message HMAC-SHA1 fingerprint:");
stun_debug ("\nkey : ");
stun_debug_bytes (key, key_len);
......@@ -422,7 +423,8 @@ size_t stun_agent_finish_message (StunAgent *agent, StunMessage *msg,
return 0;
}
stun_sha1 (msg->buffer, stun_message_length (msg), ptr, key, key_len);
stun_sha1 (msg->buffer, stun_message_length (msg), ptr, key, key_len,
agent->compatibility == STUN_COMPATIBILITY_RFC3489 ? TRUE : FALSE);
stun_debug (" Message HMAC-SHA1 message integrity:"
"\n key : ");
......
......@@ -52,7 +52,7 @@
#include <assert.h>
void stun_sha1 (const uint8_t *msg, size_t len, uint8_t *sha,
const void *restrict key, size_t keylen)
const void *restrict key, size_t keylen, int padding)
{
HMAC_CTX ctx;
uint16_t fakelen = htons (len - 20u);
......@@ -65,6 +65,18 @@ void stun_sha1 (const uint8_t *msg, size_t len, uint8_t *sha,
HMAC_Update (&ctx, (const uint8_t *)&fakelen, 2);
/* first 4 bytes done, last 24 bytes not summed */
HMAC_Update (&ctx, msg + 4, len - 28u);
/* RFC 3489 specifies that the message's size should be 64 bytes,
and \x00 padding should be done */
if (padding) {
uint16_t pad_size = 64 - ((len - 24) % 64);
int i;
uint8_t pad_char[1] = {0};
for (i = 0; i < pad_size; i++) {
HMAC_Update (&ctx, pad_char, 1);
}
}
HMAC_Final (&ctx, sha, NULL);
HMAC_CTX_cleanup (&ctx);
}
......
......@@ -49,7 +49,7 @@
* @return fingerprint value in <b>host</b> byte order.
*/
void stun_sha1 (const uint8_t *msg, size_t len,
uint8_t *sha, const void *key, size_t keylen);
uint8_t *sha, const void *key, size_t keylen, int padding);
/**
* SIP H(A1) computation
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment