diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp index a081f88dce9d67d19859a772607e2f3c7a9dd573..e5fdf99b8c65a769e6710a80c309a865b0281d66 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp +++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp @@ -110,8 +110,7 @@ void AudioRtpFactory::initAudioRtpSession (SIPCall * ca) _rtpSession = new AudioSrtpSession (&Manager::instance(), ca); _rtpSessionType = Sdes; - // ca->getLocalSDP()->set_srtp_master_key (static_cast<AudioSrtpSession *> (_rtpSession)->getMasterKey()); - + ca->getLocalSDP()->set_srtp_crypto(static_cast<AudioSrtpSession *> (_rtpSession)->getCryptoSdpInfo()); break; default: diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp index 67a07d1311ab1de4f180c2de3fc62615cf5e9789..d6fd2b273ca9861f58ff08b62022a3c013cea883 100644 --- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp +++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp @@ -36,12 +36,6 @@ static uint8 ms[] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d }; -// static std::string crypto_suite = "AES_CM_128_HMAC_SHA1_32"; -// static std::string application = "srtp"; -// static std::string srtp_key = "inline:16/14/NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj/2^20/1:32"; - - - namespace sfl { @@ -61,13 +55,26 @@ AudioSrtpSession::AudioSrtpSession (ManagerImpl * manager, SIPCall * sipcall) : setOutQueueCryptoContext(outputCryptoCtx); } - /* -std::string AudioSrtpSession::getCryptoInfo() { + +std::string AudioSrtpSession::getCryptoSdpInfo() { + std::string tag = "1"; + std::string crypto_suite = "AES_CM_128_HMAC_SHA1_32"; + std::string application = "srtp"; + std::string srtp_key = "inline:16/14/NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj/2^20/1:32"; - return ; + std::string crypto = tag; + + crypto.append(" "); + crypto.append(crypto_suite); + crypto.append(" "); + crypto.append(application); + crypto.append(" "); + crypto.append(srtp_key); + + return crypto; } - */ + void AudioSrtpSession::initializeMasterKey(void) { diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h index 89bc2450ed7b565c042ea676efee55e97cb71790..34adb9d505652afa1df9b7a9f96074ef0008bd46 100644 --- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h +++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h @@ -42,9 +42,7 @@ namespace sfl { AudioSrtpSession(ManagerImpl * manager, SIPCall * sipcall); - // std::string getCryptoInfo(void); - - uint8* getMasterKey(void){ return _masterKey; } + std::string getCryptoSdpInfo(void); private: diff --git a/sflphone-common/src/sip/sdp.cpp b/sflphone-common/src/sip/sdp.cpp index 524d6f9fc1f8fd42b3915e57a62b1b9bcbc7f017..e069369c6188281c724aa0c31ca2df9c841a0eec 100644 --- a/sflphone-common/src/sip/sdp.cpp +++ b/sflphone-common/src/sip/sdp.cpp @@ -158,10 +158,9 @@ int Sdp::create_local_offer () //sdp_addAttributes( _pool ); sdp_add_media_description(); - // if(!_srtp_master_key.empty()) { - - sdp_add_sdes_attribute(); - // } + if(!_srtp_crypto.empty()) { + sdp_add_sdes_attribute(_srtp_crypto); + } //toString (); @@ -368,7 +367,7 @@ void Sdp::sdp_add_media_description() } -void Sdp::sdp_add_sdes_attribute () +void Sdp::sdp_add_sdes_attribute (std::string crypto) { char tempbuf[256]; @@ -382,12 +381,17 @@ void Sdp::sdp_add_sdes_attribute () attribute->name = pj_strdup3(_pool, "crypto"); + /* int len = pj_ansi_snprintf(tempbuf, sizeof(tempbuf), "%.*s %.*s %.*s", (int)tag.size(), tag.c_str(), (int)crypto_suite.size(), crypto_suite.c_str(), (int)key.size(), key.c_str()); - + */ + + int len = pj_ansi_snprintf(tempbuf, sizeof(tempbuf), + "%.*s",(int)crypto.size(), crypto.c_str()); + attribute->value.slen = len; attribute->value.ptr = (char*) pj_pool_alloc (_pool, attribute->value.slen+1); pj_memcpy (attribute->value.ptr, tempbuf, attribute->value.slen+1); diff --git a/sflphone-common/src/sip/sdp.h b/sflphone-common/src/sip/sdp.h index 9f5fc9ea44902c909e99e1f13b47858590055bf5..72ef3f434cf310ae442f36d81f8ce4ecec6d8135 100644 --- a/sflphone-common/src/sip/sdp.h +++ b/sflphone-common/src/sip/sdp.h @@ -105,7 +105,7 @@ class Sdp { /* Set the srtp _master_key * @param mk The Master Key of a srtp session. */ - inline void set_srtp_master_key(const std::string& mk) { _srtp_master_key = mk; } + inline void set_srtp_crypto(const std::string& mk) { _srtp_crypto = mk; } /* * On building an invite outside a dialog, build the local offer and create the @@ -253,7 +253,8 @@ class Sdp { std::string _zrtp_hello_hash; - std::string _srtp_master_key; + /** "a=crypto" sdes attribute obtained from AudioSrtpSession */ + std::string _srtp_crypto; Sdp(const Sdp&); //No Copy Constructor Sdp& operator=(const Sdp&); //No Assignment Operator @@ -344,14 +345,13 @@ class Sdp { void get_remote_sdp_media_from_offer (const pjmedia_sdp_session* r_sdp, pjmedia_sdp_media** r_media); void get_remote_sdp_crypto_from_offer (const pjmedia_sdp_session* remote_sdp, pjmedia_sdp_attr** r_crypto); - /* * Adds a sdes attribute to the given media section. * * @param media The media to add the srtp attribute to */ - void sdp_add_sdes_attribute(); + void sdp_add_sdes_attribute(std::string crypto); /* * Adds a zrtp-hash attribute to diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index bed479fc1654788e6ff069287cd6f05e091a20eb..4c0431382711c131c4b9e0e672c1eca25e277045 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -1559,20 +1559,22 @@ bool SIPVoIPLink::new_ip_to_ip_call (const CallID& id, const std::string& to) setCallAudioLocal (call, localAddress); _debug ("toUri received in new_ip_to_ip call %s", to.c_str()); - std::string toUri = account->getToUri (to); call->setPeerNumber (toUri); _debug ("toUri in new_ip_to_ip call %s", toUri.c_str()); - // Building the local SDP offer - call->getLocalSDP()->set_ip_address (addrSdp); - call->getLocalSDP()->create_initial_offer(); - try { + // Audio Rtp Session must be initialized before creating initial offer in SDP session + // since SDES require crypto attribute. + try { call->getAudioRtp()->initAudioRtpSession (call); } catch (...) { _debug ("! SIP Failure: Unable to create RTP Session in SIPVoIPLink::new_ip_to_ip_call (%s:%d)", __FILE__, __LINE__); } + // Building the local SDP offer + call->getLocalSDP()->set_ip_address (addrSdp); + call->getLocalSDP()->create_initial_offer(); + // If no account already set, use the default one created at pjsip initialization if (account->getAccountTransport() == NULL) { _debug ("No transport for this account, using the default one");