diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp index 69eeac0428255e0706393a7830658cff01b72332..17e9242152e43816740e5f7414d3852c499c880a 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp +++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp @@ -110,6 +110,8 @@ void AudioRtpFactory::initAudioRtpSession (SIPCall * ca) _rtpSession = new AudioSrtpSession (&Manager::instance(), ca); _rtpSessionType = Sdes; + // ca->getLocalSDP()->set_srtp_master_key (static_cast<AudioSrtpSession *> (_rtpSession)->getMasterKey()); + break; default: diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp index d3d1d83cdb109ba2df8fa98d764d16c101b114e5..67a07d1311ab1de4f180c2de3fc62615cf5e9789 100644 --- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp +++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp @@ -21,6 +21,10 @@ #include "sip/sipcall.h" +#include <openssl/bio.h> +#include <openssl/evp.h> + + #include <cstdio> #include <cstring> #include <cerrno> @@ -31,6 +35,13 @@ static uint8 mk[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 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 { @@ -50,6 +61,14 @@ AudioSrtpSession::AudioSrtpSession (ManagerImpl * manager, SIPCall * sipcall) : setOutQueueCryptoContext(outputCryptoCtx); } + /* +std::string AudioSrtpSession::getCryptoInfo() { + + + return ; +} + */ + void AudioSrtpSession::initializeMasterKey(void) { @@ -88,7 +107,7 @@ void AudioSrtpSession::initializeInputCryptoContext(void) 112 / 8, // session salt len 80 / 8); // authentication tag len - _debug("********************* Crypto Context IN with SSRC %i ******************", IncomingDataQueue::getLocalSSRCNetwork()); + } void AudioSrtpSession::initializeOutputCryptoContext(void) @@ -110,6 +129,44 @@ void AudioSrtpSession::initializeOutputCryptoContext(void) 112 / 8, // session salt len 80 / 8); // authentication tag len - _debug("********************* Crypto Context OUT with SSRC %i ******************", OutgoingDataQueue::getLocalSSRC()); + +} + + +char* AudioSrtpSession::encodeBase64(unsigned char *input, int length) +{ + BIO *b64, *bmem; + + char *buffer = (char *)malloc(length); + memset(buffer, 0, length); + + b64 = BIO_new(BIO_f_base64()); + bmem = BIO_new_mem_buf(input, length); + bmem = BIO_push(bmem, b64); + + BIO_read(bmem, buffer, length); + + BIO_free_all(bmem); + + return buffer; +} + +char* AudioSrtpSession::decodeBase64(unsigned char *input, int length) +{ + BIO *b64, *bmem; + + char *buffer = (char *)malloc(length); + memset(buffer, 0, length); + + b64 = BIO_new(BIO_f_base64()); + bmem = BIO_new_mem_buf(input, length); + bmem = BIO_push(b64, bmem); + + BIO_read(bmem, buffer, length); + + BIO_free_all(bmem); + + return buffer; } + } diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h index c37a898a1f4852890c3fba1c38d0995b2d319966..89bc2450ed7b565c042ea676efee55e97cb71790 100644 --- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h +++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h @@ -39,8 +39,13 @@ namespace sfl { class AudioSrtpSession : public ost::SymmetricRTPSession, public AudioRtpSession<AudioSrtpSession> { public: - AudioSrtpSession(ManagerImpl * manager, SIPCall * sipcall); - + + AudioSrtpSession(ManagerImpl * manager, SIPCall * sipcall); + + // std::string getCryptoInfo(void); + + uint8* getMasterKey(void){ return _masterKey; } + private: void initializeMasterKey(void); @@ -51,6 +56,10 @@ namespace sfl { void initializeOutputCryptoContext(void); + char* encodeBase64(unsigned char *input, int length); + + char* decodeBase64(unsigned char *input, int length); + uint8 _masterKey[16]; uint8 _masterSalt[14]; diff --git a/sflphone-common/src/sip/sdp.cpp b/sflphone-common/src/sip/sdp.cpp index 545601e96e5a256e3f86b7bc9543e40a22fb3eb0..524d6f9fc1f8fd42b3915e57a62b1b9bcbc7f017 100644 --- a/sflphone-common/src/sip/sdp.cpp +++ b/sflphone-common/src/sip/sdp.cpp @@ -158,7 +158,10 @@ int Sdp::create_local_offer () //sdp_addAttributes( _pool ); sdp_add_media_description(); + // if(!_srtp_master_key.empty()) { + sdp_add_sdes_attribute(); + // } //toString (); diff --git a/sflphone-common/src/sip/sdp.h b/sflphone-common/src/sip/sdp.h index 68eaa771d8f8f82bd7156bf523d1e203c872e368..9f5fc9ea44902c909e99e1f13b47858590055bf5 100644 --- a/sflphone-common/src/sip/sdp.h +++ b/sflphone-common/src/sip/sdp.h @@ -101,6 +101,11 @@ class Sdp { * @param hash The hello hash of a rtp session. (Only audio at the moment) */ inline void set_zrtp_hash(const std::string& hash) { _zrtp_hello_hash = hash; _debug("Zrtp hash set with %s\n", hash.c_str()); } + + /* 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; } /* * On building an invite outside a dialog, build the local offer and create the @@ -246,7 +251,9 @@ class Sdp { /** Remote's audio port */ unsigned int _remote_audio_port; - std::string _zrtp_hello_hash; + std::string _zrtp_hello_hash; + + std::string _srtp_master_key; Sdp(const Sdp&); //No Copy Constructor Sdp& operator=(const Sdp&); //No Assignment Operator