Commit 3497af12 authored by Youness Alaoui's avatar Youness Alaoui Committed by Youness Alaoui

Should fix authentication issues.. server reflexive candidates have the same...

Should fix authentication issues.. server reflexive candidates have the same udp socket as their base host candidate.. we need to match all local candidates during stun agent validation
parent ff4ca893
...@@ -1739,10 +1739,9 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -1739,10 +1739,9 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
StunMessage req; StunMessage req;
StunMessage msg; StunMessage msg;
StunValidationStatus valid; StunValidationStatus valid;
stun_validater_data validater_data[2] = { stun_validater_data *validater_data = NULL;
{NULL, 0, NULL, 0},
{NULL, 0, NULL, 0}};
GSList *i; GSList *i;
int j, k;
NiceCandidate *remote_candidate = NULL; NiceCandidate *remote_candidate = NULL;
NiceCandidate *local_candidate = NULL; NiceCandidate *local_candidate = NULL;
...@@ -1755,34 +1754,39 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -1755,34 +1754,39 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
break; break;
} }
} }
validater_data = g_new0(stun_validater_data, g_slist_length(component->local_candidates) + 1);
/* 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, so we
have no idea the user/pass is coming from which candidate */
j = 0;
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;
if (cand->sockptr == udp_socket) {
local_candidate = cand;
break;
}
}
uname_len = priv_create_username (agent, stream, uname_len = priv_create_username (agent, stream,
component->id, remote_candidate, local_candidate, component->id, remote_candidate, cand,
uname, sizeof (uname), TRUE); uname, sizeof (uname), TRUE);
validater_data[0].username = uname; validater_data[j].username = g_memdup(uname, uname_len);
validater_data[0].username_len = uname_len; validater_data[j].username_len = uname_len;
if (local_candidate->password) { if (cand->password) {
validater_data[0].password = (uint8_t *) local_candidate->password; validater_data[j].password = (uint8_t *) cand->password;
validater_data[0].password_len = strlen (local_candidate->password); validater_data[j].password_len = strlen (cand->password);
} else { } else {
validater_data[0].password = (uint8_t *) stream->local_password; validater_data[j].password = (uint8_t *) stream->local_password;
validater_data[0].password_len = strlen (stream->local_password); validater_data[j].password_len = strlen (stream->local_password);
} }
if (agent->compatibility == NICE_COMPATIBILITY_MSN) { if (agent->compatibility == NICE_COMPATIBILITY_MSN) {
validater_data[0].password = g_base64_decode ((gchar *) validater_data[0].password, validater_data[j].password = g_base64_decode ((gchar *) validater_data[j].password,
&validater_data[0].password_len); &validater_data[j].password_len);
}
j++;
} }
/* note: contents of 'buf' already validated, so it is /* note: contents of 'buf' already validated, so it is
* a valid and fully received STUN message */ * a valid and fully received STUN message */
...@@ -1841,26 +1845,38 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -1841,26 +1845,38 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
return TRUE; return TRUE;
} }
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) { username = (uint8_t *) stun_message_find (&req, STUN_ATTRIBUTE_USERNAME,
&username_len);
/* We need to find which local candidate was used */
for (i = component->local_candidates; i; i = i->next) {
gboolean inbound = TRUE;
NiceCandidate *cand = i->data;
/* If we receive a response, then the username is local:remote */ /* If we receive a response, then the username is local:remote */
if (agent->compatibility != NICE_COMPATIBILITY_MSN) {
if (stun_message_get_class (&req) == STUN_REQUEST || if (stun_message_get_class (&req) == STUN_REQUEST ||
stun_message_get_class (&req) == STUN_INDICATION) { stun_message_get_class (&req) == STUN_INDICATION) {
uname_len = priv_create_username (agent, stream, inbound = TRUE;
component->id, remote_candidate, local_candidate,
uname, sizeof (uname), TRUE);
} else { } else {
inbound = FALSE;
}
}
uname_len = priv_create_username (agent, stream, uname_len = priv_create_username (agent, stream,
component->id, remote_candidate, local_candidate, component->id, remote_candidate, cand,
uname, sizeof (uname), FALSE); uname, sizeof (uname), inbound);
if (username &&
uname_len == username_len &&
memcmp (uname, username, username_len) == 0) {
local_candidate = cand;
break;
}
} }
username = (uint8_t *) stun_message_find (&req, STUN_ATTRIBUTE_USERNAME,
&username_len);
/* Check the username in case the stun agent has IGNORE_CREDENTIALS flag. if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE &&
We only need to check the username and not care about the password */ local_candidate == NULL) {
if (username && /* if we couldn't match the username and the stun agent has IGNORE_CREDENTIALS,
(uname_len != username_len || then we have an integrity check failing */
memcmp (uname, username, username_len) != 0)) {
g_debug ("Agent %p : Username check failed.", agent); g_debug ("Agent %p : Username check failed.", agent);
if (stun_agent_init_error (&agent->stun_agent, &msg, rbuf, rbuf_len, if (stun_agent_init_error (&agent->stun_agent, &msg, rbuf, rbuf_len,
&req, STUN_ERROR_UNAUTHORIZED)) { &req, STUN_ERROR_UNAUTHORIZED)) {
...@@ -1870,7 +1886,6 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -1870,7 +1886,6 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
} }
return TRUE; return TRUE;
} }
}
if (valid != STUN_VALIDATION_SUCCESS) { if (valid != STUN_VALIDATION_SUCCESS) {
g_debug ("Agent %p : STUN message is unsuccessfull, ignoring", agent); g_debug ("Agent %p : STUN message is unsuccessfull, ignoring", agent);
......
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