[#1722] Generate crypto info in AudioSrtpSession and pass it to sdp

This commit is contained in:
Alexandre Savard
2010-01-11 11:19:49 -05:00
parent 9f4c4b181f
commit 096978e602
6 changed files with 40 additions and 30 deletions

View File

@ -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:

View File

@ -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)
{

View File

@ -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:

View File

@ -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);

View File

@ -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

View File

@ -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");