diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp index 4715587ff03b8e153f56aee346dd689468e0b440..7099b807bd6150f345a988c4c151945ca35f4fe3 100644 --- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp +++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp @@ -62,10 +62,12 @@ AudioSrtpSession::AudioSrtpSession (ManagerImpl * manager, SIPCall * sipcall) : } -std::string AudioSrtpSession::getLocalCryptoInfo() { +std::vector<std::string> AudioSrtpSession::getLocalCryptoInfo() { _debug("Get Cryptographic info from this rtp session"); + std::vector<std::string> crypto_vector; + // @TODO we should return a vector containing supported // cryptographic context tagged 1, 2, 3... std::string tag = "1"; @@ -79,13 +81,15 @@ std::string AudioSrtpSession::getLocalCryptoInfo() { srtp_keys.append("|2^20|1:32"); // generate crypto attribute - std::string crypto = tag.append(" "); - crypto += crypto_suite.append(" "); - crypto += srtp_keys; + std::string crypto_attr = tag.append(" "); + crypto_attr += crypto_suite.append(" "); + crypto_attr += srtp_keys; + + _debug("%s", crypto_attr.c_str()); - _debug("%s", crypto.c_str()); + crypto_vector.push_back(crypto_attr); - return crypto; + return crypto_vector; } diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h index 7e94a62baedf636d46dc21f8ee47513ec54e9aa8..d3b8c3dbfd07d0aa55f9a32883ca1d516eb673f3 100644 --- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h +++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h @@ -23,6 +23,7 @@ #include "sip/SdesNegotiator.h" #include <ccrtp/CryptoContext.h> +#include <vector> class SdesNegotiator; class ManagerImpl; @@ -68,7 +69,7 @@ namespace sfl { AudioSrtpSession(ManagerImpl * manager, SIPCall * sipcall); - std::string getLocalCryptoInfo(void); + std::vector<std::string> getLocalCryptoInfo(void); void setRemoteCryptoInfo(sfl::SdesNegotiator& nego); diff --git a/sflphone-common/src/sip/sdp.cpp b/sflphone-common/src/sip/sdp.cpp index 9e9aed149c0368ce2c8a3e48172014676f594235..69ab580cc40d4811fcdf324f425605f6426a5e9a 100644 --- a/sflphone-common/src/sip/sdp.cpp +++ b/sflphone-common/src/sip/sdp.cpp @@ -365,39 +365,46 @@ void Sdp::sdp_add_media_description() } // @TODO crypto should be a vector of string -void Sdp::sdp_add_sdes_attribute (std::string crypto) +void Sdp::sdp_add_sdes_attribute (std::vector<std::string>& crypto) { // temporary buffer used to store crypto attribute char tempbuf[256]; - // the attribute to add to sdp - pjmedia_sdp_attr *attribute = (pjmedia_sdp_attr*) pj_pool_zalloc(_pool, sizeof(pjmedia_sdp_attr)); + std::vector<std::string>::iterator iter = crypto.begin(); - attribute->name = pj_strdup3(_pool, "crypto"); + while(iter != crypto.end()) { - // _debug("crypto from sdp: %s", crypto.c_str()); + // the attribute to add to sdp + pjmedia_sdp_attr *attribute = (pjmedia_sdp_attr*) pj_pool_zalloc(_pool, sizeof(pjmedia_sdp_attr)); + + attribute->name = pj_strdup3(_pool, "crypto"); + + // _debug("crypto from sdp: %s", crypto.c_str()); - int len = pj_ansi_snprintf(tempbuf, sizeof(tempbuf), - "%.*s",(int)crypto.size(), crypto.c_str()); + int len = pj_ansi_snprintf(tempbuf, sizeof(tempbuf), + "%.*s",(int)(*iter).size(), (*iter).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); + 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); - // get number of media for this SDP - int media_count = _local_offer->media_count; + // get number of media for this SDP + int media_count = _local_offer->media_count; - // add crypto attribute to media - for(int i = 0; i < media_count; i++) { + // add crypto attribute to media + for(int i = 0; i < media_count; i++) { - if(pjmedia_sdp_media_add_attr(_local_offer->media[i], attribute) != PJ_SUCCESS) { - // if(pjmedia_sdp_attr_add(&(_local_offer->attr_count), _local_offer->attr, attribute) != PJ_SUCCESS){ - throw sdpException(); + if(pjmedia_sdp_media_add_attr(_local_offer->media[i], attribute) != PJ_SUCCESS) { + // if(pjmedia_sdp_attr_add(&(_local_offer->attr_count), _local_offer->attr, attribute) != PJ_SUCCESS){ + throw sdpException(); + } } - } + + iter++; + } } diff --git a/sflphone-common/src/sip/sdp.h b/sflphone-common/src/sip/sdp.h index d32ceeaa9016e65ff5ce3ad657315bc29a26c8b5..afba2e67d460fbaa63767f0160016f8717a033ee 100644 --- a/sflphone-common/src/sip/sdp.h +++ b/sflphone-common/src/sip/sdp.h @@ -108,7 +108,7 @@ class Sdp { /* Set the srtp _master_key * @param mk The Master Key of a srtp session. */ - inline void set_srtp_crypto(const std::string& mk) { _srtp_crypto = mk; } + inline void set_srtp_crypto(const std::vector<std::string> lc) { _srtp_crypto = lc; } /* * On building an invite outside a dialog, build the local offer and create the @@ -258,8 +258,8 @@ class Sdp { std::string _zrtp_hello_hash; - /** "a=crypto" sdes attribute obtained from AudioSrtpSession */ - std::string _srtp_crypto; + /** "a=crypto" sdes local attributes obtained from AudioSrtpSession */ + std::vector<std::string> _srtp_crypto; Sdp(const Sdp&); //No Copy Constructor Sdp& operator=(const Sdp&); //No Assignment Operator @@ -355,7 +355,7 @@ class Sdp { * * @param media The media to add the srtp attribute to */ - void sdp_add_sdes_attribute(std::string crypto); + void sdp_add_sdes_attribute(std::vector<std::string>& crypto); /* * Adds a zrtp-hash attribute to