From 1a2e0d75eac159b2ed6d665e57044e842216eb2c Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Fri, 22 Feb 2013 14:45:59 -0500 Subject: [PATCH] create a random but constant "foundation" string for ice candidates --- daemon/main.c | 2 ++ daemon/sdp.c | 30 ++++++++++++++++++++++-------- daemon/sdp.h | 2 ++ 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/daemon/main.c b/daemon/main.c index 1e60ba78e..fc058abcb 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -18,6 +18,7 @@ #include "call.h" #include "kernel.h" #include "redis.h" +#include "sdp.h" @@ -330,6 +331,7 @@ static void init_everything() { openlog("mediaproxy-ng", LOG_PID | LOG_NDELAY, LOG_DAEMON); signals(); resources(); + sdp_init(); } void redis_mod_verify(void *dlh) { diff --git a/daemon/sdp.c b/daemon/sdp.c index 6b8acaca8..0b15ecd08 100644 --- a/daemon/sdp.c +++ b/daemon/sdp.c @@ -69,6 +69,9 @@ struct sdp_attribute { static const char ice_chars[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; +static char ice_foundation[17]; +static str ice_foundation_str; + @@ -656,19 +659,20 @@ strip: return 0; } +static void random_string(char *buf, int len) { + while (len--) + *buf++ = ice_chars[random() % strlen(ice_chars)]; +} + static void create_random_string(struct call *call, str *s, int len) { char buf[30]; - char *p; assert(len < sizeof(buf)); if (s->s) return; - p = buf; - while (len--) - *p++ = ice_chars[random() % strlen(ice_chars)]; - - call_str_cpy_len(call, s, buf, p - buf); + random_string(buf, len); + call_str_cpy_len(call, s, buf, len); } int sdp_replace(struct sdp_chopper *chop, GQueue *sessions, struct call *call, @@ -748,10 +752,14 @@ int sdp_replace(struct sdp_chopper *chop, GQueue *sessions, struct call *call, if (flags->ice_force) { copy_up_to_end_of(chop, &media->s); /* prio = (2^24) * 126 + (2^8) * 65535 + (256 - componentID) */ - chopper_append_c(chop, "a=candidate:1 1 UDP 2130706431 "); + chopper_append_c(chop, "a=candidate:"); + chopper_append_str(chop, &ice_foundation_str); + chopper_append_c(chop, " 1 UDP 2130706431 "); insert_ice_address(chop, m, off, flags, 0); chopper_append_c(chop, " typ host\r\n"); - chopper_append_c(chop, "a=candidate:1 2 UDP 2130706430 "); + chopper_append_c(chop, "a=candidate:"); + chopper_append_str(chop, &ice_foundation_str); + chopper_append_c(chop, " 2 UDP 2130706430 "); insert_ice_address(chop, m, off, flags, 1); chopper_append_c(chop, " typ host\r\n"); } @@ -765,3 +773,9 @@ error: mylog(LOG_ERROR, "Error rewriting SDP"); return -1; } + +void sdp_init() { + random_string(ice_foundation, sizeof(ice_foundation) - 1); + ice_foundation_str.s = ice_foundation; + ice_foundation_str.len = sizeof(ice_foundation) - 1; +} diff --git a/daemon/sdp.h b/daemon/sdp.h index eb5dedcbf..25b8e4988 100644 --- a/daemon/sdp.h +++ b/daemon/sdp.h @@ -28,6 +28,8 @@ struct sdp_chopper { int str_len; }; +void sdp_init(void); + int sdp_parse(str *body, GQueue *sessions); int sdp_streams(const GQueue *sessions, GQueue *streams, GHashTable *); void sdp_free(GQueue *sessions);