Commit 8b0b8320 authored by Youness Alaoui's avatar Youness Alaoui

Fix checking for the remote candidate using the username, and correctly create...

Fix checking for the remote candidate using the username, and correctly create the remote peer reflexive candidate
parent 03f35676
...@@ -635,7 +635,8 @@ void conn_check_remote_candidates_set(NiceAgent *agent) ...@@ -635,7 +635,8 @@ void conn_check_remote_candidates_set(NiceAgent *agent)
component, component,
icheck->priority, icheck->priority,
&icheck->from, &icheck->from,
icheck->local_socket); icheck->local_socket,
NULL, NULL);
if (candidate) { if (candidate) {
priv_schedule_triggered_check (agent, stream, component, icheck->local_socket, candidate, icheck->use_candidate); priv_schedule_triggered_check (agent, stream, component, icheck->local_socket, candidate, icheck->use_candidate);
} }
...@@ -1935,20 +1936,13 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -1935,20 +1936,13 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
StunMessage msg; StunMessage msg;
StunValidationStatus valid; StunValidationStatus valid;
conncheck_validater_data validater_data = {agent, stream, component, NULL}; conncheck_validater_data validater_data = {agent, stream, component, NULL};
GSList *i; GSList *i, *j;
NiceCandidate *remote_candidate = NULL; NiceCandidate *remote_candidate = NULL;
NiceCandidate *remote_candidate2 = NULL;
NiceCandidate *local_candidate = NULL; NiceCandidate *local_candidate = NULL;
nice_address_copy_to_sockaddr (from, &sockaddr); nice_address_copy_to_sockaddr (from, &sockaddr);
for (i = component->remote_candidates; i; i = i->next) {
NiceCandidate *cand = i->data;
if (nice_address_equal (from, &cand->addr)) {
remote_candidate = cand;
break;
}
}
/* 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 */
...@@ -1967,7 +1961,8 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -1967,7 +1961,8 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
valid == STUN_VALIDATION_INCOMPLETE_STUN || valid == STUN_VALIDATION_INCOMPLETE_STUN ||
valid == STUN_VALIDATION_BAD_REQUEST) valid == STUN_VALIDATION_BAD_REQUEST)
{ {
nice_debug ("Agent %p : Incorrectly multiplexed STUN message ignored.", agent); nice_debug ("Agent %p : Incorrectly multiplexed STUN message ignored.",
agent);
return FALSE; return FALSE;
} }
...@@ -2009,10 +2004,20 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -2009,10 +2004,20 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
username = (uint8_t *) stun_message_find (&req, STUN_ATTRIBUTE_USERNAME, username = (uint8_t *) stun_message_find (&req, STUN_ATTRIBUTE_USERNAME,
&username_len); &username_len);
for (i = component->remote_candidates; i; i = i->next) {
NiceCandidate *cand = i->data;
if (nice_address_equal (from, &cand->addr)) {
remote_candidate = cand;
break;
}
}
/* We need to find which local candidate was used */ /* We need to find which local candidate was used */
for (i = component->local_candidates; i; i = i->next) { for (i = component->remote_candidates; i; i = i->next) {
for (j = component->local_candidates; j; j = j->next) {
gboolean inbound = TRUE; gboolean inbound = TRUE;
NiceCandidate *cand = i->data; NiceCandidate *rcand = i->data;
NiceCandidate *lcand = j->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 (agent->compatibility != NICE_COMPATIBILITY_MSN) {
...@@ -2024,15 +2029,17 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -2024,15 +2029,17 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
} }
} }
uname_len = priv_create_username (agent, stream, uname_len = priv_create_username (agent, stream,
component->id, remote_candidate, cand, component->id, rcand, lcand,
uname, sizeof (uname), inbound); uname, sizeof (uname), inbound);
if (username && if (username &&
uname_len == username_len && uname_len == username_len &&
memcmp (uname, username, username_len) == 0) { memcmp (uname, username, username_len) == 0) {
local_candidate = cand; local_candidate = lcand;
remote_candidate2 = rcand;
break; break;
} }
} }
}
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE && if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE &&
local_candidate == NULL) { local_candidate == NULL) {
...@@ -2056,14 +2063,17 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -2056,14 +2063,17 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
if (stun_message_get_class (&req) == STUN_REQUEST) { if (stun_message_get_class (&req) == STUN_REQUEST) {
if (agent->compatibility == NICE_COMPATIBILITY_MSN) { if (agent->compatibility == NICE_COMPATIBILITY_MSN) {
username = (uint8_t *) stun_message_find (&req, STUN_ATTRIBUTE_USERNAME, username = (uint8_t *) stun_message_find (&req,
&username_len); STUN_ATTRIBUTE_USERNAME, &username_len);
uname_len = priv_create_username (agent, stream, uname_len = priv_create_username (agent, stream,
component->id, remote_candidate, local_candidate, component->id, remote_candidate2, local_candidate,
uname, sizeof (uname), FALSE); uname, sizeof (uname), FALSE);
memcpy (username, uname, username_len); memcpy (username, uname, username_len);
req.key = g_base64_decode ((gchar *) remote_candidate->password, if (remote_candidate2)
req.key = g_base64_decode ((gchar *) remote_candidate2->password,
&req.key_len); &req.key_len);
else
req.key = NULL;
} }
rbuf_len = sizeof (rbuf); rbuf_len = sizeof (rbuf);
...@@ -2097,7 +2107,8 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, ...@@ -2097,7 +2107,8 @@ gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream,
nice_debug ("Agent %p : No matching remote candidate for incoming check ->" nice_debug ("Agent %p : No matching remote candidate for incoming check ->"
"peer-reflexive candidate.", agent); "peer-reflexive candidate.", agent);
remote_candidate = discovery_learn_remote_peer_reflexive_candidate ( remote_candidate = discovery_learn_remote_peer_reflexive_candidate (
agent, stream, component, priority, from, udp_socket); agent, stream, component, priority, from, udp_socket,
local_candidate, remote_candidate2);
} }
priv_reply_to_conn_check (agent, stream, component, remote_candidate, priv_reply_to_conn_check (agent, stream, component, remote_candidate,
......
...@@ -465,8 +465,8 @@ discovery_add_peer_reflexive_candidate ( ...@@ -465,8 +465,8 @@ discovery_add_peer_reflexive_candidate (
guint component_id, guint component_id,
NiceAddress *address, NiceAddress *address,
NiceUDPSocket *base_socket, NiceUDPSocket *base_socket,
NiceCandidate *local_candidate, NiceCandidate *local,
NiceCandidate *remote_candidate) NiceCandidate *remote)
{ {
NiceCandidate *candidate; NiceCandidate *candidate;
Component *component; Component *component;
...@@ -497,7 +497,7 @@ discovery_add_peer_reflexive_candidate ( ...@@ -497,7 +497,7 @@ discovery_add_peer_reflexive_candidate (
priv_assign_foundation (agent, candidate); priv_assign_foundation (agent, candidate);
if (agent->compatibility == NICE_COMPATIBILITY_MSN && if (agent->compatibility == NICE_COMPATIBILITY_MSN &&
remote_candidate && local_candidate) { remote && local) {
guchar *new_username = NULL; guchar *new_username = NULL;
guchar *decoded_local = NULL; guchar *decoded_local = NULL;
guchar *decoded_remote = NULL; guchar *decoded_remote = NULL;
...@@ -506,8 +506,8 @@ discovery_add_peer_reflexive_candidate ( ...@@ -506,8 +506,8 @@ discovery_add_peer_reflexive_candidate (
g_free(candidate->username); g_free(candidate->username);
g_free(candidate->password); g_free(candidate->password);
decoded_local = g_base64_decode (local_candidate->username, &local_size); decoded_local = g_base64_decode (local->username, &local_size);
decoded_remote = g_base64_decode (remote_candidate->username, &remote_size); decoded_remote = g_base64_decode (remote->username, &remote_size);
new_username = g_new0(guchar, local_size + remote_size); new_username = g_new0(guchar, local_size + remote_size);
memcpy(new_username, decoded_local, local_size); memcpy(new_username, decoded_local, local_size);
...@@ -518,7 +518,7 @@ discovery_add_peer_reflexive_candidate ( ...@@ -518,7 +518,7 @@ discovery_add_peer_reflexive_candidate (
g_free(decoded_local); g_free(decoded_local);
g_free(decoded_remote); g_free(decoded_remote);
candidate->password = g_strdup(local_candidate->password); candidate->password = g_strdup(local->password);
} }
/* step: link to the base candidate+socket */ /* step: link to the base candidate+socket */
...@@ -565,7 +565,9 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate ( ...@@ -565,7 +565,9 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
Component *component, Component *component,
guint32 priority, guint32 priority,
const NiceAddress *remote_address, const NiceAddress *remote_address,
NiceUDPSocket *udp_socket) NiceUDPSocket *udp_socket,
NiceCandidate *local,
NiceCandidate *remote)
{ {
NiceCandidate *candidate; NiceCandidate *candidate;
...@@ -587,20 +589,20 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate ( ...@@ -587,20 +589,20 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
g_snprintf (candidate->foundation, NICE_CANDIDATE_MAX_FOUNDATION, "%u", next_remote_id); g_snprintf (candidate->foundation, NICE_CANDIDATE_MAX_FOUNDATION, "%u", next_remote_id);
#if 0
if (agent->compatibility == NICE_COMPATIBILITY_MSN && if (agent->compatibility == NICE_COMPATIBILITY_MSN &&
remote && local) { remote && local) {
gchar *new_username = NULL; guchar *new_username = NULL;
gchar *decoded_local = NULL; guchar *decoded_local = NULL;
gchar *decoded_remote = NULL; guchar *decoded_remote = NULL;
gsize local_size; gsize local_size;
gsize remote_size; gsize remote_size;
g_free(candidate->username); g_free(candidate->username);
g_free (candidate->password);
decoded_local = g_base64_decode (local->username, &local_size); decoded_local = g_base64_decode (local->username, &local_size);
decoded_remote = g_base64_decode (remote->username, &remote_size); decoded_remote = g_base64_decode (remote->username, &remote_size);
new_username = g_new0(gchar, local_size + remote_size); new_username = g_new0(guchar, local_size + remote_size);
memcpy(new_username, decoded_remote, remote_size); memcpy(new_username, decoded_remote, remote_size);
memcpy(new_username + remote_size, decoded_local, local_size); memcpy(new_username + remote_size, decoded_local, local_size);
...@@ -608,8 +610,10 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate ( ...@@ -608,8 +610,10 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
g_free(new_username); g_free(new_username);
g_free(decoded_local); g_free(decoded_local);
g_free(decoded_remote); g_free(decoded_remote);
candidate->password = g_strdup(remote->password);
} }
#endif
candidate->sockptr = NULL; /* not stored for remote candidates */ candidate->sockptr = NULL; /* not stored for remote candidates */
/* note: candidate username and password are left NULL as stream /* note: candidate username and password are left NULL as stream
level ufrag/password are used */ level ufrag/password are used */
......
...@@ -99,8 +99,8 @@ discovery_add_peer_reflexive_candidate ( ...@@ -99,8 +99,8 @@ discovery_add_peer_reflexive_candidate (
guint component_id, guint component_id,
NiceAddress *address, NiceAddress *address,
NiceUDPSocket *base_socket, NiceUDPSocket *base_socket,
NiceCandidate *local_candidate, NiceCandidate *local,
NiceCandidate *remote_candidate); NiceCandidate *remote);
NiceCandidate * NiceCandidate *
discovery_learn_remote_peer_reflexive_candidate ( discovery_learn_remote_peer_reflexive_candidate (
...@@ -109,6 +109,8 @@ discovery_learn_remote_peer_reflexive_candidate ( ...@@ -109,6 +109,8 @@ discovery_learn_remote_peer_reflexive_candidate (
Component *component, Component *component,
guint32 priority, guint32 priority,
const NiceAddress *remote_address, const NiceAddress *remote_address,
NiceUDPSocket *udp_socket); NiceUDPSocket *udp_socket,
NiceCandidate *local,
NiceCandidate *remote);
#endif /*_NICE_CONNCHECK_H */ #endif /*_NICE_CONNCHECK_H */
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