Commit 23747ed7 authored by Kai Vehmanen's avatar Kai Vehmanen

Modified STUN debugging output.

darcs-hash:20070720213036-77cd4-ab26e5411537a906f39c739df65a92c38f5602d7.gz
parent 45ee17d1
...@@ -47,15 +47,6 @@ ...@@ -47,15 +47,6 @@
#include <errno.h> #include <errno.h>
#include <netinet/in.h> #include <netinet/in.h>
#ifndef NDEBUG
static inline
int stun_valid (const uint8_t *msg)
{
size_t length = 20u + stun_length (msg);
return stun_validate (msg, length) == (ssize_t)length;
}
#endif
ssize_t stun_validate (const uint8_t *msg, size_t len) ssize_t stun_validate (const uint8_t *msg, size_t len)
{ {
size_t mlen; size_t mlen;
...@@ -417,12 +408,10 @@ bool stun_demux (const uint8_t *msg) ...@@ -417,12 +408,10 @@ bool stun_demux (const uint8_t *msg)
assert (stun_valid (msg)); assert (stun_valid (msg));
DBG ("Demultiplexing STUN message @%p\n", msg);
/* Checks cookie */ /* Checks cookie */
if (!check_cookie (msg)) if (!check_cookie (msg))
{ {
DBG (" No STUN cookie!\n"); DBG ("STUN demux error: no cookie!\n");
return 0; return 0;
} }
...@@ -430,7 +419,7 @@ bool stun_demux (const uint8_t *msg) ...@@ -430,7 +419,7 @@ bool stun_demux (const uint8_t *msg)
fpr = stun_end (msg) - 4; fpr = stun_end (msg) - 4;
if ((fpr != stun_find (msg, STUN_FINGERPRINT, &fprlen)) || (fprlen != 4)) if ((fpr != stun_find (msg, STUN_FINGERPRINT, &fprlen)) || (fprlen != 4))
{ {
DBG (" No FINGERPRINT attribute!\n"); DBG ("STUN demux error: no FINGERPRINT attribute!\n");
return 0; return 0;
} }
...@@ -438,12 +427,12 @@ bool stun_demux (const uint8_t *msg) ...@@ -438,12 +427,12 @@ bool stun_demux (const uint8_t *msg)
crc32 = htonl (stun_fingerprint (msg)); crc32 = htonl (stun_fingerprint (msg));
if (memcmp (fpr, &crc32, 4)) if (memcmp (fpr, &crc32, 4))
{ {
DBG (" Incorrect message fingerprint (expected: 0x%08x)!\n", DBG ("STUN demux error: bad fingerprint (expected: 0x%08x)!\n",
stun_fingerprint (msg)); stun_fingerprint (msg));
return 0; return 0;
} }
DBG (" Valid multiplexed STUN message!\n"); DBG ("STUN demux: OK!\n");
return 1; return 1;
} }
...@@ -466,8 +455,6 @@ stun_verify_key (const uint8_t *msg, const void *key, size_t keylen) ...@@ -466,8 +455,6 @@ stun_verify_key (const uint8_t *msg, const void *key, size_t keylen)
assert (msg != NULL); assert (msg != NULL);
assert ((keylen == 0) || (key != NULL)); assert ((keylen == 0) || (key != NULL));
DBG ("Authenticating STUN message @%p\n", msg);
hash = stun_end (msg) - 20; hash = stun_end (msg) - 20;
if (stun_demux (msg)) if (stun_demux (msg))
hash -= 8; // room for FINGERPRINT at the end hash -= 8; // room for FINGERPRINT at the end
...@@ -475,7 +462,7 @@ stun_verify_key (const uint8_t *msg, const void *key, size_t keylen) ...@@ -475,7 +462,7 @@ stun_verify_key (const uint8_t *msg, const void *key, size_t keylen)
if ((stun_find (msg, STUN_MESSAGE_INTEGRITY, &hlen) != hash) if ((stun_find (msg, STUN_MESSAGE_INTEGRITY, &hlen) != hash)
|| (hlen != 20)) || (hlen != 20))
{ {
DBG (" No MESSAGE-INTEGRITY attribute!\n"); DBG ("STUN auth error: no MESSAGE-INTEGRITY attribute!\n");
return ENOENT; return ENOENT;
} }
...@@ -485,7 +472,7 @@ stun_verify_key (const uint8_t *msg, const void *key, size_t keylen) ...@@ -485,7 +472,7 @@ stun_verify_key (const uint8_t *msg, const void *key, size_t keylen)
#ifndef NDEBUG #ifndef NDEBUG
unsigned i; unsigned i;
DBG (" Message HMAC-SHA1 fingerprint mismatch!" DBG ("STUN auth error: SHA1 fingerprint mismatch!"
"\n key : 0x"); "\n key : 0x");
for (i = 0; i < keylen; i++) for (i = 0; i < keylen; i++)
DBG ("%02x", ((uint8_t *)key)[i]); DBG ("%02x", ((uint8_t *)key)[i]);
...@@ -500,7 +487,7 @@ stun_verify_key (const uint8_t *msg, const void *key, size_t keylen) ...@@ -500,7 +487,7 @@ stun_verify_key (const uint8_t *msg, const void *key, size_t keylen)
return EPERM; return EPERM;
} }
DBG (" Message authenticated successfully!\n"); DBG ("STUN auth: OK!\n");
return 0; return 0;
} }
...@@ -673,13 +660,12 @@ stun_find_unknown (const uint8_t *restrict msg, uint16_t *restrict list, ...@@ -673,13 +660,12 @@ stun_find_unknown (const uint8_t *restrict msg, uint16_t *restrict list,
if (!stun_optional (atype) if (!stun_optional (atype)
&& stun_is_unknown (atype)) && stun_is_unknown (atype))
{ {
DBG (" found unknown attribute: 0x%04x (%u bytes)\n", DBG ("STUN unknown: attribute 0x%04x(%u bytes)\n",
(unsigned)atype, (unsigned)alen); (unsigned)atype, (unsigned)alen);
list[count++] = atype; list[count++] = atype;
} }
} }
DBG (" %u unknown mandatory attribute%s\n", count, DBG ("STUN unknown: %u mandatory attribute(s)!\n", count);
(count != 1) ? "s" : "");
return count; return count;
} }
...@@ -475,7 +475,7 @@ stun_finish_long (uint8_t *msg, size_t *restrict plen, ...@@ -475,7 +475,7 @@ stun_finish_long (uint8_t *msg, size_t *restrict plen,
if (sha != NULL) if (sha != NULL)
{ {
stun_sha1 (msg, sha, key, keylen); stun_sha1 (msg, sha, key, keylen);
#if 0 #ifndef NDEBUG
DBG (" Message HMAC-SHA1 fingerprint:" DBG (" Message HMAC-SHA1 fingerprint:"
"\n key : 0x"); "\n key : 0x");
for (unsigned i = 0; i < keylen; i++) for (unsigned i = 0; i < keylen; i++)
......
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