diff --git a/conf/freeswitch.conf b/conf/freeswitch.conf index 37b46bbba7..b5e1a98864 100644 --- a/conf/freeswitch.conf +++ b/conf/freeswitch.conf @@ -86,6 +86,12 @@ ip => guess ;extip => stun:stun.server.com ;extip => 100.101.102.103 +; specify 'myrealm' with certian key +; use !myrealm! at beginning of url to activate +; exosip/!myrealm!1000@dest +;srtp:myrealm => ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + + ;---- WOOMERA PROTOCOL ;-------------------------------------------------------------------------------- [+woomera.conf] diff --git a/src/mod/endpoints/mod_exosip/mod_exosip.c b/src/mod/endpoints/mod_exosip/mod_exosip.c index b133b69637..972881dbec 100644 --- a/src/mod/endpoints/mod_exosip/mod_exosip.c +++ b/src/mod/endpoints/mod_exosip/mod_exosip.c @@ -354,6 +354,10 @@ static switch_status exosip_on_init(switch_core_session *session) switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OUTBOUND SDP:\n%s\n", buf); free(buf); /* Send the INVITE */ + + if (tech_pvt->realm) { + osip_message_set_header(invite, "SrtpRealm", tech_pvt->realm); + } tech_pvt->cid = eXosip_call_send_initial_invite(invite); snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", tech_pvt->cid); switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt); @@ -1081,6 +1085,7 @@ static switch_status exosip_create_call(eXosip_event_t * event) osip_uri_t *uri; osip_from_t *from; char *displayname, *username; + osip_header_t *tedious; switch_core_session_add_stream(session, NULL); if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) { @@ -1097,6 +1102,11 @@ static switch_status exosip_create_call(eXosip_event_t * event) snprintf(name, sizeof(name), "Exosip/%s-%04x", event->request->from->url->username, rand() & 0xffff); switch_channel_set_name(channel, name); + if (osip_message_header_get_byname (event->request, "SrtpRealm", 0, &tedious)) { + tech_pvt->realm = switch_core_session_strdup(session, osip_header_get_value(tedious)); + } + + if (!(from = osip_message_get_from(event->request))) { switch_core_session_destroy(&session); @@ -1476,6 +1486,7 @@ static void handle_answer(eXosip_event_t * event) if (activate_rtp(tech_pvt) != SWITCH_STATUS_SUCCESS) { + exosip_on_hangup(tech_pvt->session); switch_channel_hangup(channel); return; } @@ -1638,7 +1649,10 @@ static int config_exosip(int reload) set_global_dialplan(val); } else if (!strncasecmp(var, "srtp:", 5)) { char *name = var + 5; - switch_core_hash_insert_dup(globals.srtp_hash, name, val); + if (name) { + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Add Realm [%s][%s]\n", name, val); + switch_core_hash_insert(globals.srtp_hash, switch_core_strdup(module_pool, name), switch_core_strdup(module_pool, val)); + } } else if (!strcmp(var, "codec_prefs")) { set_global_codec_string(val); globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS); diff --git a/src/switch_rtp.c b/src/switch_rtp.c index cf1b697e92..d27e70e85e 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -297,6 +297,7 @@ SWITCH_DECLARE(switch_status) switch_rtp_create(switch_rtp **new_rtp_session, "error: too few digits in key/salt " "(should be %d hexadecimal digits, found %d)\n", MASTER_KEY_LEN*2, len); + *err = "Crypt Error"; return SWITCH_STATUS_FALSE; } if (strlen(crypto_key) > MASTER_KEY_LEN*2) { @@ -304,11 +305,13 @@ SWITCH_DECLARE(switch_status) switch_rtp_create(switch_rtp **new_rtp_session, "error: too many digits in key/salt " "(should be %d hexadecimal digits, found %u)\n", MASTER_KEY_LEN*2, (unsigned)strlen(crypto_key)); + *err = "Crypt Error"; return SWITCH_STATUS_FALSE; } - switch_console_printf(SWITCH_CHANNEL_CONSOLE, "set master key/salt to %s/", octet_string_hex_string(key, 16)); - switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "%s\n", octet_string_hex_string(key+16, 14)); + //switch_console_printf(SWITCH_CHANNEL_CONSOLE, "set master key/salt to %s/", octet_string_hex_string(key, 16)); + //switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "%s\n", octet_string_hex_string(key+16, 14)); + switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activating Secure RTP!\n"); } rtp_session->send_msg.header.ssrc = htonl(ssrc); @@ -342,12 +345,12 @@ SWITCH_DECLARE(switch_status) switch_rtp_create(switch_rtp **new_rtp_session, if ((stat = srtp_create(&rtp_session->recv_ctx, &policy))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error allocating srtp [%d]\n", stat); - *err = "Error"; + *err = "Crypt Error"; return SWITCH_STATUS_FALSE; } if ((stat = srtp_create(&rtp_session->send_ctx, &policy))) { switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error allocating srtp [%d]\n", stat); - *err = "Error"; + *err = "Crypt Error"; return SWITCH_STATUS_FALSE; } }