]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix sofia recovery on srtp legs
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 19 Oct 2012 20:49:13 +0000 (15:49 -0500)
committerBrian West <brian@freeswitch.org>
Fri, 19 Oct 2012 20:49:22 +0000 (15:49 -0500)
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c

index b0fc019b1ce1234af8548d8122c1dc2d2af8a653..2b5cae81bd8d6e843e0facc7430af088ce21a1a9 100644 (file)
@@ -344,6 +344,7 @@ typedef enum {
        TFLAG_SLA_BARGE,
        TFLAG_SLA_BARGING,
        TFLAG_PASS_ACK,
+       TFLAG_CRYPTO_RECOVER,
        /* No new flags below this line */
        TFLAG_MAX
 } TFLAGS;
@@ -739,6 +740,7 @@ struct private_object {
        char *fmtp_out;
        char *remote_sdp_str;
        int crypto_tag;
+       int callstate;
        unsigned char local_raw_key[SWITCH_RTP_MAX_CRYPTO_LEN];
        unsigned char remote_raw_key[SWITCH_RTP_MAX_CRYPTO_LEN];
        switch_rtp_crypto_key_type_t crypto_send_type;
index 979e185781bc55ce14ce2b64e3a73e82bd516737..bee732b597a1523435ed8c6a01178b88ec22f7fd 100644 (file)
@@ -6420,6 +6420,8 @@ static void sofia_handle_sip_i_state(switch_core_session_t *session, int status,
 
   state_process:
 
+       tech_pvt->callstate = ss_state;
+
        switch ((enum nua_callstate) ss_state) {
        case nua_callstate_terminated:
        case nua_callstate_terminating:
index 8568a5bc42a853f03f93eee9c4338c2904539ce1..10ce4deba17129fb0bf50e1d24f34d96497cfa95 100644 (file)
@@ -4924,7 +4924,10 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
                                                        const char *b = switch_stristr("AES", crypto);
 
                                                        /* Change our key every time we can */
-                                                       if (switch_stristr(SWITCH_RTP_CRYPTO_KEY_32, crypto)) {
+                                                       
+                                                       if (sofia_test_flag(tech_pvt, TFLAG_CRYPTO_RECOVER)) {
+                                                               sofia_clear_flag(tech_pvt, TFLAG_CRYPTO_RECOVER);
+                                                       } else if (switch_stristr(SWITCH_RTP_CRYPTO_KEY_32, crypto)) {
                                                                switch_channel_set_variable(tech_pvt->channel, SOFIA_HAS_CRYPTO_VARIABLE, SWITCH_RTP_CRYPTO_KEY_32);
                                                                sofia_glue_build_crypto(tech_pvt, atoi(crypto), AES_CM_128_HMAC_SHA1_32, SWITCH_RTP_CRYPTO_SEND);
                                                                switch_rtp_add_crypto_key(tech_pvt->rtp_session, SWITCH_RTP_CRYPTO_SEND, atoi(crypto), tech_pvt->crypto_type,
@@ -4941,8 +4944,9 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
                                                        if (a && b && !strncasecmp(a, b, 23)) {
                                                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Change Remote key to [%s]\n", crypto);
                                                                tech_pvt->remote_crypto_key = switch_core_session_strdup(tech_pvt->session, crypto);
+                                                               switch_channel_set_variable(tech_pvt->channel, "srtp_remote_audio_crypto_key", crypto);
                                                                tech_pvt->crypto_tag = crypto_tag;
-
+                                                               
                                                                if (switch_rtp_ready(tech_pvt->rtp_session) && sofia_test_flag(tech_pvt, TFLAG_SECURE)) {
                                                                        sofia_glue_add_crypto(tech_pvt, tech_pvt->remote_crypto_key, SWITCH_RTP_CRYPTO_RECV);
                                                                        switch_rtp_add_crypto_key(tech_pvt->rtp_session, SWITCH_RTP_CRYPTO_RECV, tech_pvt->crypto_tag,
@@ -4956,6 +4960,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
                                        } else if (!switch_rtp_ready(tech_pvt->rtp_session)) {
                                                tech_pvt->remote_crypto_key = switch_core_session_strdup(tech_pvt->session, crypto);
                                                switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Set Remote Key [%s]\n", tech_pvt->remote_crypto_key);
+                                               switch_channel_set_variable(tech_pvt->channel, "srtp_remote_audio_crypto_key", crypto);
                                                tech_pvt->crypto_tag = crypto_tag;
                                                got_crypto++;
 
@@ -5873,6 +5878,10 @@ int sofia_recover_callback(switch_core_session_t *session)
        sofia_glue_attach_private(session, profile, tech_pvt, NULL);
        switch_channel_set_name(tech_pvt->channel, switch_channel_get_variable(channel, "channel_name"));
 
+       if ((tmp = switch_channel_get_variable(channel, "srtp_remote_audio_crypto_key"))) {
+               tech_pvt->remote_crypto_key = switch_core_session_strdup(session, tmp);
+               sofia_set_flag(tech_pvt, TFLAG_CRYPTO_RECOVER);
+       }
 
        if ((tmp = switch_channel_get_variable(channel, "sip_local_sdp_str"))) {
                tech_pvt->local_sdp_str = switch_core_session_strdup(session, tmp);