Commit dcf203e0 authored by Youness Alaoui's avatar Youness Alaoui

Correctly check for errors when processing TURN response and support long term...

Correctly check for errors when processing TURN response and support long term credentials unauthorized message correctly
parent d4c7f32c
...@@ -1796,11 +1796,46 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage * ...@@ -1796,11 +1796,46 @@ static gboolean priv_map_reply_to_relay_request (NiceAgent *agent, StunMessage *
d->stun_message.buffer_len = 0; d->stun_message.buffer_len = 0;
d->done = TRUE; d->done = TRUE;
trans_found = TRUE; trans_found = TRUE;
} else if (res == STUN_USAGE_BIND_RETURN_ERROR) { } else if (res == STUN_USAGE_TURN_RETURN_ERROR) {
/* case: STUN error, the check STUN context was freed */ int code = -1;
d->stun_message.buffer = NULL; uint8_t *sent_nonce = NULL;
d->stun_message.buffer_len = 0; uint8_t *recv_nonce = NULL;
d->done = TRUE; uint16_t sent_nonce_len = 0;
uint16_t recv_nonce_len = 0;
sent_nonce = (uint8_t *) stun_message_find (&d->stun_message,
STUN_ATTRIBUTE_NONCE, &sent_nonce_len);
recv_nonce = (uint8_t *) stun_message_find (resp,
STUN_ATTRIBUTE_NONCE, &recv_nonce_len);
/* check for unauthorized error response */
if (d->component->turn_long_term &&
stun_message_get_class (resp) == STUN_ERROR &&
stun_message_find_error (resp, &code) == 0 &&
code == 401 && recv_nonce != NULL &&
recv_nonce_len > 0) {
if (recv_nonce_len == sent_nonce_len &&
sent_nonce != NULL &&
memcmp (sent_nonce, recv_nonce, sent_nonce_len) == 0) {
/* case: a real unauthorized error */
d->stun_message.buffer = NULL;
d->stun_message.buffer_len = 0;
d->done = TRUE;
} else {
d->stun_resp_msg = *resp;
memcpy (d->stun_resp_buffer, resp->buffer,
stun_message_length (resp));
d->stun_resp_msg.buffer = d->stun_resp_buffer;
d->stun_resp_msg.buffer_len = sizeof(d->stun_resp_buffer);
d->pending = FALSE;
}
} else {
/* case: STUN error, the check STUN context was freed */
d->stun_message.buffer = NULL;
d->stun_message.buffer_len = 0;
d->done = TRUE;
}
trans_found = TRUE; trans_found = TRUE;
} }
} }
......
...@@ -697,9 +697,9 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer) ...@@ -697,9 +697,9 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer)
buffer_len = stun_usage_bind_create (&agent->stun_agent, buffer_len = stun_usage_bind_create (&agent->stun_agent,
&cand->stun_message, cand->stun_buffer, sizeof(cand->stun_buffer)); &cand->stun_message, cand->stun_buffer, sizeof(cand->stun_buffer));
} else if (cand->type == NICE_CANDIDATE_TYPE_RELAYED) { } else if (cand->type == NICE_CANDIDATE_TYPE_RELAYED) {
buffer_len = stun_usage_turn_create (&agent->stun_agent, buffer_len = stun_usage_turn_create (&cand->turn_agent,
&cand->stun_message, cand->stun_buffer, sizeof(cand->stun_buffer), &cand->stun_message, cand->stun_buffer, sizeof(cand->stun_buffer),
NULL, cand->stun_resp_msg.buffer == NULL ? NULL : &cand->stun_resp_msg,
STUN_USAGE_TURN_REQUEST_PORT_NORMAL, STUN_USAGE_TURN_REQUEST_PORT_NORMAL,
0, 0, 0, 0,
(uint8_t *)cand->component->turn_username, (uint8_t *)cand->component->turn_username,
......
...@@ -61,7 +61,7 @@ struct _CandidateDiscovery ...@@ -61,7 +61,7 @@ struct _CandidateDiscovery
uint8_t stun_buffer[STUN_MAX_MESSAGE_SIZE]; uint8_t stun_buffer[STUN_MAX_MESSAGE_SIZE];
StunMessage stun_message; StunMessage stun_message;
uint8_t stun_resp_buffer[STUN_MAX_MESSAGE_SIZE]; uint8_t stun_resp_buffer[STUN_MAX_MESSAGE_SIZE];
StunMessage stun_resp_message; StunMessage stun_resp_msg;
}; };
void discovery_free_item (gpointer data, gpointer user_data); void discovery_free_item (gpointer data, gpointer user_data);
......
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