From 05ccb471c8e1924d59b1b93e6881546ef4e6fdf7 Mon Sep 17 00:00:00 2001 From: Alexandre Savard <alexandre.savard@savoirfairelinux.com> Date: Wed, 6 Oct 2010 14:12:36 -0400 Subject: [PATCH] [#4243] Init audio srtp remote crypto context in call_on_media_update --- .../src/audio/audiortp/AudioSrtpSession.cpp | 36 +++++++++++-------- sflphone-common/src/sip/sipvoiplink.cpp | 6 ++-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp index dd52a5184e..9a19490e1e 100644 --- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp +++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp @@ -45,6 +45,8 @@ #include <cerrno> +bool remoteIsSet; + namespace sfl { @@ -59,6 +61,7 @@ AudioSrtpSession::AudioSrtpSession (ManagerImpl * manager, SIPCall * sipcall) : _remoteMasterSaltLength (0) { + remoteIsSet = false; // initLocalCryptoInfo(); } @@ -113,28 +116,31 @@ std::vector<std::string> AudioSrtpSession::getLocalCryptoInfo() void AudioSrtpSession::setRemoteCryptoInfo (sfl::SdesNegotiator& nego) { + if (!remoteIsSet) { + _debug ("----------------------------------------------- AudioSrtp: Set remote Cryptographic info for Srtp"); - _debug ("----------------------------------------------- AudioSrtp: Set remote Cryptographic info for Srtp"); + _debug ("%s", nego.getKeyInfo().c_str()); - _debug ("%s", nego.getKeyInfo().c_str()); + // Use second crypto suite if key length is 32 bit, default is 80; + _debug ("--------------------------------------------------- auth tag %s", nego.getAuthTagLength().c_str()); - // Use second crypto suite if key length is 32 bit, default is 80; - _debug ("--------------------------------------------------- auth tag %s", nego.getAuthTagLength().c_str()); + if (nego.getAuthTagLength() == "32") { + _debug ("--------------------------- AudioSrtp: Using %s byte authentication tag length", nego.getAuthTagLength().c_str()); + _localCryptoSuite = 1; + _remoteCryptoSuite = 1; + } - if (nego.getAuthTagLength() == "32") { - _debug ("--------------------------- AudioSrtp: Using %s byte authentication tag length", nego.getAuthTagLength().c_str()); - _localCryptoSuite = 1; - _remoteCryptoSuite = 1; - } + // decode keys + unBase64ConcatenatedKeys (nego.getKeyInfo()); - // decode keys - unBase64ConcatenatedKeys (nego.getKeyInfo()); + // init crypto content in Srtp session + initializeRemoteCryptoContext(); + setInQueueCryptoContext (_remoteCryptoCtx); - // init crypto content in Srtp session - initializeRemoteCryptoContext(); - setInQueueCryptoContext (_remoteCryptoCtx); + // initLocalCryptoInfo(); + remoteIsSet = true; + } - // initLocalCryptoInfo(); } diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index dbac3dd743..9a5f1146ad 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -3337,7 +3337,7 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) } - /* + // Get the crypto attribute containing srtp's cryptographic context (keys, cipher) CryptoOffer crypto_offer; call->getLocalSDP()->get_remote_sdp_crypto_from_offer (remote_sdp, crypto_offer); @@ -3365,7 +3365,7 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) try { call->getAudioRtp()->setRemoteCryptoInfo (sdesnego); - call->getAudioRtp()->initLocalCryptoInfo (call); + // call->getAudioRtp()->initLocalCryptoInfo (call); } catch (...) {} DBusManager::instance().getCallManager()->secureSdesOn (call->getCallId()); @@ -3399,7 +3399,6 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) // enabled for this call, make a try using RTP only... _debug ("UserAgent: SDES not initialized for this call\n"); } - */ Sdp *sdpSession = call->getLocalSDP(); @@ -3965,7 +3964,6 @@ mod_on_rx_request (pjsip_rx_data *rdata) call->getAudioRtp()->initAudioRtpConfig (call); call->getAudioRtp()->initAudioRtpSession (call); call->getAudioRtp()->setRemoteCryptoInfo (sdesnego); - _debug ("------------------------------------------------ init local crypto info"); call->getAudioRtp()->initLocalCryptoInfo (call); } catch (...) { _warn ("UserAgent: Error: Failed to create rtp thread from answer"); -- GitLab