Commit bef2440b authored by Dafydd Harries's avatar Dafydd Harries

send error response if connectivity check has missing/invalid password

darcs-hash:20070201133653-c9803-39628825dfcc8f7214109bee908259b1ef0df733.gz
parent 842d8848
...@@ -445,8 +445,7 @@ _handle_stun ( ...@@ -445,8 +445,7 @@ _handle_stun (
if (username == NULL) if (username == NULL)
/* no username attribute found */ /* no username attribute found */
/* XXX: send error response */ goto ERROR;
return;
/* validate username */ /* validate username */
/* XXX: what about the case where the username uniquely identifies a remote /* XXX: what about the case where the username uniquely identifies a remote
...@@ -483,8 +482,7 @@ _handle_stun ( ...@@ -483,8 +482,7 @@ _handle_stun (
} }
/* username is not valid */ /* username is not valid */
/* XXX: send error response */ goto ERROR;
return;
RESPOND: RESPOND:
{ {
...@@ -506,6 +504,21 @@ RESPOND: ...@@ -506,6 +504,21 @@ RESPOND:
return; return;
ERROR:
{
StunMessage *response;
guint len;
gchar *packed;
response = stun_message_new (STUN_MESSAGE_BINDING_ERROR_RESPONSE,
msg->transaction_id, 0);
len = stun_message_pack (response, &packed);
udp_socket_send (&local->sock, &from, len, packed);
g_free (packed);
stun_message_free (response);
}
/* XXX: perform a triggered connectivity check here -- or is that only for /* XXX: perform a triggered connectivity check here -- or is that only for
* full implementations? * full implementations?
*/ */
......
...@@ -27,6 +27,8 @@ test_stun_no_password ( ...@@ -27,6 +27,8 @@ test_stun_no_password (
guint len; guint len;
struct sockaddr_in to = {0,}; struct sockaddr_in to = {0,};
gchar buf[1024]; gchar buf[1024];
guint packed_len;
gchar *packed;
memset (buf, '\0', 1024); memset (buf, '\0', 1024);
...@@ -35,8 +37,6 @@ test_stun_no_password ( ...@@ -35,8 +37,6 @@ test_stun_no_password (
{ {
StunMessage *breq; StunMessage *breq;
guint packed_len;
gchar *packed;
/* send binding request without username */ /* send binding request without username */
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST, breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST,
...@@ -50,10 +50,22 @@ test_stun_no_password ( ...@@ -50,10 +50,22 @@ test_stun_no_password (
/* tell the agent there's a packet waiting */ /* tell the agent there's a packet waiting */
nice_agent_recv (agent, candidate->id); nice_agent_recv (agent, candidate->id);
/* no reply should have been sent */ /* error response should have been sent */
len = udp_fake_socket_pop_send (sock, &to, sizeof (buf) / sizeof (gchar), len = udp_fake_socket_pop_send (sock, &to, sizeof (buf) / sizeof (gchar),
buf); buf);
g_assert (len == 0); g_assert (len != 0);
{
StunMessage *bres;
/* construct expected response */
bres = stun_message_new (STUN_MESSAGE_BINDING_ERROR_RESPONSE,
"0123456789abcdef", 0);
packed_len = stun_message_pack (bres, &packed);
}
g_assert (len == packed_len);
g_assert (0 == memcmp (buf, packed, len));
} }
static void static void
...@@ -66,6 +78,8 @@ test_stun_invalid_password ( ...@@ -66,6 +78,8 @@ test_stun_invalid_password (
guint len; guint len;
struct sockaddr_in to = {0,}; struct sockaddr_in to = {0,};
gchar buf[1024]; gchar buf[1024];
guint packed_len;
gchar *packed;
memset (buf, '\0', 1024); memset (buf, '\0', 1024);
...@@ -74,8 +88,6 @@ test_stun_invalid_password ( ...@@ -74,8 +88,6 @@ test_stun_invalid_password (
{ {
StunMessage *breq; StunMessage *breq;
guint packed_len;
gchar *packed;
/* send binding request with incorrect username */ /* send binding request with incorrect username */
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST, breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST,
...@@ -91,10 +103,22 @@ test_stun_invalid_password ( ...@@ -91,10 +103,22 @@ test_stun_invalid_password (
/* tell the agent there's a packet waiting */ /* tell the agent there's a packet waiting */
nice_agent_recv (agent, candidate->id); nice_agent_recv (agent, candidate->id);
/* no reply should have been sent */ /* error should have been sent */
len = udp_fake_socket_pop_send (sock, &to, sizeof (buf) / sizeof (gchar), len = udp_fake_socket_pop_send (sock, &to, sizeof (buf) / sizeof (gchar),
buf); buf);
g_assert (len == 0); g_assert (len != 0);
{
StunMessage *bres;
/* construct expected response */
bres = stun_message_new (STUN_MESSAGE_BINDING_ERROR_RESPONSE,
"0123456789abcdef", 0);
packed_len = stun_message_pack (bres, &packed);
}
g_assert (len == packed_len);
g_assert (0 == memcmp (buf, packed, len));
} }
static void static void
......
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