From 92128756a2f63d83d0004eb2b5eeaf6b27f115c7 Mon Sep 17 00:00:00 2001 From: Piotr Gregor Date: Wed, 20 Dec 2017 18:31:50 +0000 Subject: [PATCH] FS-10853: Fix failed build for mod_dingaling Fixes build but must be tested at runtime. --- src/include/switch_core_media.h | 4 ++- .../endpoints/mod_dingaling/mod_dingaling.c | 25 +++++++++---------- src/switch_core_media.c | 8 +++++- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/include/switch_core_media.h b/src/include/switch_core_media.h index cf9b321655..1c73c2367a 100644 --- a/src/include/switch_core_media.h +++ b/src/include/switch_core_media.h @@ -210,6 +210,7 @@ SWITCH_DECLARE(void) switch_core_media_set_rtp_session(switch_core_session_t *se SWITCH_DECLARE(const char *)switch_core_media_get_codec_string(switch_core_session_t *session); SWITCH_DECLARE(void) switch_core_media_parse_rtp_bugs(switch_rtp_bug_flag_t *flag_pole, const char *str); +SWITCH_DECLARE(switch_status_t) switch_core_media_add_crypto(switch_core_session_t *session, switch_secure_settings_t *ssec, switch_rtp_crypto_direction_t direction); SWITCH_DECLARE(switch_t38_options_t *) switch_core_media_extract_t38_options(switch_core_session_t *session, const char *r_sdp); SWITCH_DECLARE(void) switch_core_media_pass_zrtp_hash(switch_core_session_t *session); SWITCH_DECLARE(const char *) switch_core_media_get_zrtp_hash(switch_core_session_t *session, switch_media_type_t type, switch_bool_t local); @@ -309,7 +310,8 @@ SWITCH_DECLARE(payload_map_t *) switch_core_media_add_payload_map(switch_core_se SWITCH_DECLARE(switch_status_t) switch_core_media_check_autoadj(switch_core_session_t *session); SWITCH_DECLARE(switch_rtp_crypto_key_type_t) switch_core_media_crypto_str2type(const char *str); SWITCH_DECLARE(const char *) switch_core_media_crypto_type2str(switch_rtp_crypto_key_type_t type); -SWITCH_DECLARE(int) switch_core_media_crypto_keylen(switch_rtp_crypto_key_type_t type); +SWITCH_DECLARE(int) switch_core_media_crypto_keysalt_len(switch_rtp_crypto_key_type_t type); +SWITCH_DECLARE(int) switch_core_media_crypto_salt_len(switch_rtp_crypto_key_type_t type); SWITCH_DECLARE(char *) switch_core_media_filter_sdp(const char *sdp, const char *cmd, const char *arg); SWITCH_DECLARE(char *) switch_core_media_process_sdp_filter(const char *sdp, const char *cmd_buf, switch_core_session_t *session); diff --git a/src/mod/endpoints/mod_dingaling/mod_dingaling.c b/src/mod/endpoints/mod_dingaling/mod_dingaling.c index 898b21345f..2717190355 100644 --- a/src/mod/endpoints/mod_dingaling/mod_dingaling.c +++ b/src/mod/endpoints/mod_dingaling/mod_dingaling.c @@ -255,7 +255,6 @@ struct rfc2833_digit { int duration; }; - SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string); SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string); @@ -1102,35 +1101,35 @@ static switch_status_t mdl_add_crypto(struct private_object *tech_pvt, static void try_secure(struct private_object *tech_pvt, ldl_transport_type_t ttype) { + switch_secure_settings_t ssec; /* Used just to wrap over params in a call to switch_rtp_add_crypto_key. */ if (!switch_test_flag(tech_pvt, TFLAG_SECURE)) { return; } + memset(&ssec, 0, sizeof(ssec)); if (tech_pvt->transports[ttype].crypto_recv_type) { tech_pvt->transports[ttype].crypto_type = tech_pvt->transports[ttype].crypto_recv_type; } - if (tech_pvt->transports[ttype].crypto_type) { - switch_rtp_add_crypto_key(tech_pvt->transports[ttype].rtp_session, - SWITCH_RTP_CRYPTO_SEND, 1, tech_pvt->transports[ttype].crypto_type, - tech_pvt->transports[ttype].local_raw_key, SWITCH_RTP_KEY_LEN); + memcpy(ssec.local_raw_key, tech_pvt->transports[ttype].local_raw_key, switch_core_media_crypto_keysalt_len(tech_pvt->transports[ttype].crypto_type)); + ssec.local_crypto_key = switch_core_session_strdup(tech_pvt->session, tech_pvt->transports[ttype].local_crypto_key); + switch_core_media_add_crypto(tech_pvt->session, &ssec, SWITCH_RTP_CRYPTO_SEND); + switch_rtp_add_crypto_key(tech_pvt->transports[ttype].rtp_session, SWITCH_RTP_CRYPTO_SEND_RTCP, tech_pvt->transports[ttype].crypto_type, &ssec); - switch_rtp_add_crypto_key(tech_pvt->transports[ttype].rtp_session, - SWITCH_RTP_CRYPTO_RECV, tech_pvt->transports[ttype].crypto_tag, - tech_pvt->transports[ttype].crypto_type, - tech_pvt->transports[ttype].remote_raw_key, SWITCH_RTP_KEY_LEN); + memcpy(ssec.remote_raw_key, tech_pvt->transports[ttype].remote_raw_key, switch_core_media_crypto_keysalt_len(tech_pvt->transports[ttype].crypto_type)); + ssec.remote_crypto_key = switch_core_session_strdup(tech_pvt->session, tech_pvt->transports[ttype].local_crypto_key); + switch_core_media_add_crypto(tech_pvt->session, &ssec, SWITCH_RTP_CRYPTO_RECV); + switch_rtp_add_crypto_key(tech_pvt->transports[ttype].rtp_session, SWITCH_RTP_CRYPTO_RECV, tech_pvt->transports[ttype].crypto_type, &ssec); switch_channel_set_variable(tech_pvt->channel, "jingle_secure_audio_confirmed", "true"); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_NOTICE, - "%s %s crypto confirmed\n", ldl_transport_type_str(ttype), switch_core_session_get_name(tech_pvt->session)); - - } - + "%s %s crypto confirmed\n", ldl_transport_type_str(ttype), switch_core_session_get_name(tech_pvt->session)); + } } diff --git a/src/switch_core_media.c b/src/switch_core_media.c index 677fdabd52..2ef6775a89 100644 --- a/src/switch_core_media.c +++ b/src/switch_core_media.c @@ -311,6 +311,12 @@ SWITCH_DECLARE(int) switch_core_media_crypto_keysalt_len(switch_rtp_crypto_key_t return SUITES[type].keysalt_len; } +SWITCH_DECLARE(int) switch_core_media_crypto_salt_len(switch_rtp_crypto_key_type_t type) +{ + switch_assert(type < CRYPTO_INVALID); + return SUITES[type].salt_len; +} + static const char* CRYPTO_KEY_PARAM_METHOD[CRYPTO_KEY_PARAM_METHOD_INVALID] = { [CRYPTO_KEY_PARAM_METHOD_INLINE] = "inline", }; @@ -1343,7 +1349,7 @@ static const char* switch_core_media_crypto_find_key_material_candidate_end(cons return end; } -switch_status_t switch_core_media_add_crypto(switch_core_session_t *session, switch_secure_settings_t *ssec, switch_rtp_crypto_direction_t direction) +SWITCH_DECLARE(switch_status_t) switch_core_media_add_crypto(switch_core_session_t *session, switch_secure_settings_t *ssec, switch_rtp_crypto_direction_t direction) { unsigned char key[SWITCH_RTP_MAX_CRYPTO_LEN]; switch_rtp_crypto_key_type_t type;