Commit 9c1a19d7 authored by Dafydd Harries's avatar Dafydd Harries

discard STUN binding requests that don't have a password

darcs-hash:20070130141518-c9803-1d7e3b52bf73bf33d97d9e00ae410d137ccc1823.gz
parent a13249bf
......@@ -346,12 +346,34 @@ _handle_stun (
StunMessage *msg)
{
StunMessage *response;
StunAttribute **attr;
guint len;
gchar *packed;
gchar *username = NULL;
if (msg->type != STUN_MESSAGE_BINDING_REQUEST)
return;
/* msg shoukd have either:
*
* Jingle P2P:
* username = remote candidate pwd + local candidate pwd
* ICE:
* username = remote candidate pwd + ":" + local candidate pwd
* password = local candidate pwd
*/
for (attr = msg->attributes; *attr; attr++)
if ((*attr)->type == STUN_ATTRIBUTE_USERNAME)
{
username = (*attr)->username;
break;
}
if (username == NULL)
/* no username attribute found */
return;
response = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE);
memcpy (response->transaction_id, msg->transaction_id, 16);
response->attributes = g_malloc0 (2 * sizeof (StunAttribute));
......
......@@ -51,7 +51,7 @@ main (void)
candidate = agent->local_candidates->data;
sock = &(candidate->sock);
/* send binding request */
/* send binding request without password */
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST);
memcpy (breq->transaction_id, "0123456789abcdef", 16);
packed_len = stun_message_pack (breq, &packed);
......@@ -62,6 +62,25 @@ main (void)
/* tell the agent there's a packet waiting */
nice_agent_recv (agent, candidate->id);
/* no reply should have been sent */
len = udp_fake_socket_pop_send (sock, &to, sizeof (buf) / sizeof (gchar),
buf);
g_assert (len == 0);
/* send binding request with password */
breq = stun_message_new (STUN_MESSAGE_BINDING_REQUEST);
breq->attributes = g_malloc0 (2 * sizeof (StunAttribute *));
breq->attributes[0] = stun_attribute_username_new ("lala");
memcpy (breq->transaction_id, "0123456789abcdef", 16);
packed_len = stun_message_pack (breq, &packed);
g_assert (packed_len != 0);
udp_fake_socket_push_recv (sock, &from, packed_len, packed);
g_free (packed);
stun_message_free (breq);
/* tell the agent there's a packet waiting */
nice_agent_recv (agent, candidate->id);
/* construct expected response packet */
bres = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE);
memcpy (bres->transaction_id, "0123456789abcdef", 16);
......
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