Commit 84674be7 authored by Youness Alaoui's avatar Youness Alaoui

We should validate correctly all local/remote candidate combinations

parent 5576d7e8
...@@ -1840,7 +1840,7 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -1840,7 +1840,7 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
StunMessage msg; StunMessage msg;
StunValidationStatus valid; StunValidationStatus valid;
stun_validater_data *validater_data = NULL; stun_validater_data *validater_data = NULL;
GSList *i; GSList *i, *ri;
int j, k; int j, k;
NiceCandidate *remote_candidate = NULL; NiceCandidate *remote_candidate = NULL;
NiceCandidate *local_candidate = NULL; NiceCandidate *local_candidate = NULL;
...@@ -1855,20 +1855,27 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -1855,20 +1855,27 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
} }
} }
/* TODO : if we get a peer reflexive, we should check all local:remote possibilities */ /* if we get a peer reflexive, we should check all local:remote possibilities
also, we could receive from the external interface the username used
with the internal interface, so the remote_candidate is not the
same remote candidate used by the peer */
validater_data = g_new0(stun_validater_data, validater_data = g_new0(stun_validater_data,
g_slist_length(component->local_candidates) + 1); g_slist_length(component->local_candidates) *
g_slist_length (component->remote_candidates));
/* We have to check all the local candidates into our validater_data because a /* We have to check all the local candidates into our validater_data because a
server reflexive candidate shares the same socket as the host candidate, server reflexive candidate shares the same socket as the host candidate,
so we have no idea the user/pass is coming from which candidate */ so we have no idea the user/pass is coming from which candidate */
j = 0; j = 0;
for (ri = component->remote_candidates; ri; ri = ri->next) {
NiceCandidate *rcand = ri->data;
for (i = component->local_candidates; i; i = i->next) { for (i = component->local_candidates; i; i = i->next) {
NiceCandidate *cand = i->data; NiceCandidate *cand = i->data;
uname_len = priv_create_username (agent, stream, uname_len = priv_create_username (agent, stream,
component->id, remote_candidate, cand, component->id, rcand, cand,
uname, sizeof (uname), TRUE); uname, sizeof (uname), TRUE);
validater_data[j].username = g_memdup(uname, uname_len); validater_data[j].username = g_memdup(uname, uname_len);
...@@ -1888,8 +1895,11 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -1888,8 +1895,11 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
g_base64_decode ((gchar *) validater_data[j].password, g_base64_decode ((gchar *) validater_data[j].password,
&validater_data[j].password_len); &validater_data[j].password_len);
} }
nice_debug ("Agent %p : Adding to validater data '%s' : '%s'",
agent, validater_data[j].username, validater_data[j].password);
j++; j++;
} }
}
/* note: contents of 'buf' already validated, so it is /* note: contents of 'buf' already validated, so it is
......
...@@ -76,11 +76,17 @@ bool stun_agent_default_validater (StunAgent *agent, ...@@ -76,11 +76,17 @@ bool stun_agent_default_validater (StunAgent *agent,
int i; int i;
for (i = 0; val && val[i].username ; i++) { for (i = 0; val && val[i].username ; i++) {
stun_debug ("Comparing username '");
stun_debug_bytes (username, username_len);
stun_debug ("' (%d) with '", username_len);
stun_debug_bytes (val[i].username, val[i].username_len);
stun_debug ("' (%d) : %d\n",
val[i].username_len, memcmp (username, val[i].username, username_len));
if (username_len == val[i].username_len && if (username_len == val[i].username_len &&
memcmp (username, val[i].username, username_len) == 0) { memcmp (username, val[i].username, username_len) == 0) {
*password = (uint8_t *) val[i].password; *password = (uint8_t *) val[i].password;
*password_len = val[i].password_len; *password_len = val[i].password_len;
stun_debug ("Found valid username, returning password : '%s'\n", *password);
return true; return true;
} }
} }
......
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