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

[#1722] added base64 encode/decode methods for Srtp master key

parent 9091c20f
No related branches found
No related tags found
No related merge requests found
......@@ -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:
......
......@@ -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;
}
}
......@@ -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];
......
......@@ -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 ();
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment