Skip to content
Snippets Groups Projects
Commit 26131ec2 authored by Alexandre Savard's avatar Alexandre Savard
Browse files

[#1722] Use a vector<string> instead of a simgle string when init crypto attribute

parent 30f31c93
Branches
Tags
No related merge requests found
......@@ -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;
}
......
......@@ -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);
......
......@@ -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++;
}
}
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment