diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp index e5fdf99b8c65a769e6710a80c309a865b0281d66..921e4a908b01d13809be65b7173e545811bda122 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp +++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp @@ -110,7 +110,7 @@ void AudioRtpFactory::initAudioRtpSession (SIPCall * ca) _rtpSession = new AudioSrtpSession (&Manager::instance(), ca); _rtpSessionType = Sdes; - ca->getLocalSDP()->set_srtp_crypto(static_cast<AudioSrtpSession *> (_rtpSession)->getCryptoSdpInfo()); + ca->getLocalSDP()->set_srtp_crypto(static_cast<AudioSrtpSession *> (_rtpSession)->getLocalCryptoInfo()); break; default: @@ -197,4 +197,16 @@ sfl::AudioZrtpSession * AudioRtpFactory::getAudioZrtpSession() throw AudioRtpFactoryException(); } } + +void AudioRtpFactory::setRemoteCryptoInfo() +{ + if ( (_rtpSessionType != NULL) && (_rtpSessionType != Sdes)) { + static_cast<AudioSrtpSession *> (_rtpSession)->setRemoteCryptoInfo(); + } + else { + throw AudioRtpFactoryException(); + } +} } + + diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.h b/sflphone-common/src/audio/audiortp/AudioRtpFactory.h index 9d827a5d878739479de03ed97278313d3af69a1f..421498010694d26912652cfbec442c02790b2a7f 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.h +++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.h @@ -91,7 +91,13 @@ namespace sfl { * if the current rtp thread is null, or if it's not of the correct type. * @return The current AudioZrtpSession thread. */ - sfl::AudioZrtpSession * getAudioZrtpSession(); + sfl::AudioZrtpSession * getAudioZrtpSession(); + + /** + * Set remote cryptographic info. Should be called after negotiation in SDP + * offer/answer session. + */ + void setRemoteCryptoInfo(); private: void * _rtpSession; diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp index 5471e4dd67d49efc99d8bbb4ed1df2efbb210fab..44e23dd9b29142a8e477bbf46e93c4c983575cdb 100644 --- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp +++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp @@ -52,14 +52,14 @@ AudioSrtpSession::AudioSrtpSession (ManagerImpl * manager, SIPCall * sipcall) : initializeInputCryptoContext(); initializeOutputCryptoContext(); - outputCryptoCtx->deriveSrtpKeys(0); + _outputCryptoCtx->deriveSrtpKeys(0); - setInQueueCryptoContext(inputCryptoCtx); - setOutQueueCryptoContext(outputCryptoCtx); + setInQueueCryptoContext(_inputCryptoCtx); + setOutQueueCryptoContext(_outputCryptoCtx); } -std::string AudioSrtpSession::getCryptoSdpInfo() { +std::string AudioSrtpSession::getLocalCryptoInfo() { _debug("Get Cryptographic info from this rtp session"); @@ -86,6 +86,13 @@ std::string AudioSrtpSession::getCryptoSdpInfo() { } +void AudioSrtpSession::setRemoteCryptoInfo() { + + _debug("Set remote Cryptographic info for this rtp session"); + +} + + void AudioSrtpSession::initializeMasterKey(void) { _masterKeyLength = 16; @@ -131,31 +138,9 @@ std::string AudioSrtpSession::getBase64ConcatenatedKeys() void AudioSrtpSession::initializeInputCryptoContext(void) { - // this one does not works - // inputCryptoCtx = new ost::CryptoContext(IncomingDataQueue::getLocalSSRCNetwork(), - inputCryptoCtx = new ost::CryptoContext(0x0, - 0, // roc, - 0L, // keydr, - SrtpEncryptionAESCM, // encryption algo - SrtpAuthenticationSha1Hmac, // authtication algo - _masterKey, // Master Key - 128 / 8, // Master Key length - _masterSalt, // Master Salt - 112 / 8, // Master Salt length - 128 / 8, // encryption keyl - 160 / 8, // authentication key len - 112 / 8, // session salt len - 80 / 8); // authentication tag len - - -} - -void AudioSrtpSession::initializeOutputCryptoContext(void) -{ - - // this one works - // outputCryptoCtx = new ost::CryptoContext(OutgoingDataQueue::getLocalSSRC(), - outputCryptoCtx = new ost::CryptoContext(OutgoingDataQueue::getLocalSSRC(), + // this one does not works + // inputCryptoCtx = new ost::CryptoContext(IncomingDataQueue::getLocalSSRCNetwork(), + _inputCryptoCtx = new ost::CryptoContext(0x0, 0, // roc, 0L, // keydr, SrtpEncryptionAESCM, // encryption algo @@ -169,6 +154,28 @@ void AudioSrtpSession::initializeOutputCryptoContext(void) 112 / 8, // session salt len 80 / 8); // authentication tag len + +} + +void AudioSrtpSession::initializeOutputCryptoContext(void) +{ + + // this one works + // outputCryptoCtx = new ost::CryptoContext(OutgoingDataQueue::getLocalSSRC(), + _outputCryptoCtx = new ost::CryptoContext(OutgoingDataQueue::getLocalSSRC(), + 0, // roc, + 0L, // keydr, + SrtpEncryptionAESCM, // encryption algo + SrtpAuthenticationSha1Hmac, // authtication algo + _masterKey, // Master Key + 128 / 8, // Master Key length + _masterSalt, // Master Salt + 112 / 8, // Master Salt length + 128 / 8, // encryption keyl + 160 / 8, // authentication key len + 112 / 8, // session salt len + 80 / 8); // authentication tag len + } diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h index cf932f257d64e945ab6c4ff835a077313a72d41e..a41a90361b3ab200047cfa7f389500b410ce20a0 100644 --- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h +++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h @@ -42,7 +42,9 @@ namespace sfl { AudioSrtpSession(ManagerImpl * manager, SIPCall * sipcall); - std::string getCryptoSdpInfo(void); + std::string getLocalCryptoInfo(void); + + void setRemoteCryptoInfo(void); private: @@ -68,9 +70,9 @@ namespace sfl { int _masterSaltLength; - ost::CryptoContext* inputCryptoCtx; + ost::CryptoContext* _inputCryptoCtx; - ost::CryptoContext* outputCryptoCtx; + ost::CryptoContext* _outputCryptoCtx; }; } diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index b28606f29daf509ad7452a8c380c117c5e1b5cda..9c0fba7f7dd8fba4a96e053c3048bbbf27d1650b 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -3217,6 +3217,8 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) pjmedia_sdp_attr *attribute; call->getLocalSDP()->get_remote_sdp_crypto_from_offer(remote_sdp, &attribute); + + // create remote cryptografic offer std::vector<std::string> remoteOffer; @@ -3231,6 +3233,14 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status) sfl::SdesNegotiator sdesnego(localCapabilities, remoteOffer); + sdesnego.negotiate(); + + if(sdesnego.negotiate()) { + _debug("******************** Negociation Is Successfull *********************\n"); + + call->getAudioRtp()->setRemoteCryptoInfo(); + } + try { call->setAudioStart (true);