From a012e378f8a06176d7b37e36701ef08ed5f44111 Mon Sep 17 00:00:00 2001 From: Alexandre Savard <alexandresavard@alexandresavard-desktop.(none)> Date: Mon, 11 Jan 2010 14:53:11 -0500 Subject: [PATCH] [#1722] Encode concatenated srtp keys --- .../src/audio/audiortp/AudioSrtpSession.cpp | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp index 1b2a0b61f6..5471e4dd67 100644 --- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp +++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp @@ -61,19 +61,26 @@ AudioSrtpSession::AudioSrtpSession (ManagerImpl * manager, SIPCall * sipcall) : std::string AudioSrtpSession::getCryptoSdpInfo() { + _debug("Get Cryptographic info from this rtp session"); + 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"; + // std::string srtp_keys = "inline:16/14/NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj/2^20/1:32"; + + // format srtp keys as the following + // inline:16/14/NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj/2^20/1:32 + std::string srtp_keys = "inline:"; + srtp_keys.append("16/14/"); + srtp_keys += getBase64ConcatenatedKeys(); + srtp_keys.append("/2^20/1:32"); - std::string crypto = tag; + std::string crypto = tag.append(" "); + crypto += crypto_suite.append(" "); + crypto += application.append(" "); + crypto += srtp_keys; - crypto.append(" "); - crypto.append(crypto_suite); - crypto.append(" "); - crypto.append(application); - crypto.append(" "); - crypto.append(srtp_key); + _debug("%s", crypto.c_str()); return crypto; } @@ -105,10 +112,12 @@ void AudioSrtpSession::initializeMasterSalt(void) std::string AudioSrtpSession::getBase64ConcatenatedKeys() { + // concatenate master and salt uint8 concatenated[30]; memcpy((void*)concatenated, (void*)_masterKey, 16); memcpy((void*)(concatenated+16), (void*)_masterSalt, 14); + // encode concatenated keys in base64 char *output = encodeBase64((unsigned char*)concatenated, 30); std::string keys(output); @@ -185,8 +194,8 @@ char* AudioSrtpSession::encodeBase64(unsigned char *input, int length) // get pointer to data BIO_get_mem_ptr(b64, &bptr); - // copy result in output buffer - strncpy(buffer, (char*)(bptr->data), bptr->length); + // copy result in output buffer (-1 since we do not want the EOF character) + strncpy(buffer, (char*)(bptr->data), bptr->length-1); BIO_free_all(bmem); -- GitLab