mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-12 22:09:25 +08:00
[#1722] use sfl::CryptoSuites to init crypto context
This commit is contained in:
@ -45,6 +45,8 @@ namespace sfl
|
||||
|
||||
AudioSrtpSession::AudioSrtpSession (ManagerImpl * manager, SIPCall * sipcall) :
|
||||
ost::SymmetricRTPSession (ost::InetHostAddress (sipcall->getLocalIp().c_str()), sipcall->getLocalAudioPort()),
|
||||
_localCryptoSuite(0),
|
||||
_remoteCryptoSuite(0),
|
||||
AudioRtpSession<AudioSrtpSession> (manager, sipcall)
|
||||
{
|
||||
|
||||
@ -68,7 +70,7 @@ std::string AudioSrtpSession::getLocalCryptoInfo() {
|
||||
// cryptographic context tagged 1, 2, 3...
|
||||
std::string tag = "1";
|
||||
|
||||
std::string crypto_suite = "AES_CM_128_HMAC_SHA1_32";
|
||||
std::string crypto_suite = sfl::CryptoSuites[_localCryptoSuite].name;
|
||||
|
||||
// srtp keys formated as the following as the following
|
||||
// inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32
|
||||
@ -104,7 +106,7 @@ void AudioSrtpSession::initializeLocalMasterKey(void)
|
||||
{
|
||||
|
||||
// @TODO key may have different length depending on cipher suite
|
||||
_localMasterKeyLength = 16;
|
||||
_localMasterKeyLength = sfl::CryptoSuites[_localCryptoSuite].masterKeyLength / 8;
|
||||
|
||||
// Allocate memory for key
|
||||
unsigned char *random_key = new unsigned char[_localMasterKeyLength];
|
||||
@ -130,7 +132,7 @@ void AudioSrtpSession::initializeLocalMasterSalt(void)
|
||||
{
|
||||
|
||||
// @TODO key may have different length depending on cipher suite
|
||||
_localMasterSaltLength = 14;
|
||||
_localMasterSaltLength = sfl::CryptoSuites[_localCryptoSuite].masterSaltLength / 8;
|
||||
|
||||
// Allocate memory for key
|
||||
unsigned char *random_key = new unsigned char[_localMasterSaltLength];
|
||||
@ -174,8 +176,9 @@ std::string AudioSrtpSession::getBase64ConcatenatedKeys()
|
||||
void AudioSrtpSession::unBase64ConcatenatedKeys(std::string base64keys)
|
||||
{
|
||||
|
||||
_remoteMasterKeyLength = 16;
|
||||
_remoteMasterSaltLength = 14;
|
||||
|
||||
_remoteMasterKeyLength = sfl::CryptoSuites[1].masterKeyLength / 8;
|
||||
_remoteMasterSaltLength = sfl::CryptoSuites[1].masterSaltLength / 8;
|
||||
|
||||
// length of decoded data data
|
||||
int length;
|
||||
@ -203,9 +206,9 @@ void AudioSrtpSession::initializeRemoteCryptoContext(void)
|
||||
SrtpEncryptionAESCM, // encryption algo
|
||||
SrtpAuthenticationSha1Hmac, // authtication algo
|
||||
_remoteMasterKey, // Master Key
|
||||
128 / 8, // Master Key length
|
||||
_remoteMasterKeyLength, // Master Key length
|
||||
_remoteMasterSalt, // Master Salt
|
||||
112 / 8, // Master Salt length
|
||||
_remoteMasterSaltLength, // Master Salt length
|
||||
128 / 8, // encryption keyl
|
||||
160 / 8, // authentication key len
|
||||
112 / 8, // session salt len
|
||||
@ -223,9 +226,9 @@ void AudioSrtpSession::initializeLocalCryptoContext(void)
|
||||
SrtpEncryptionAESCM, // encryption algo
|
||||
SrtpAuthenticationSha1Hmac, // authtication algo
|
||||
_localMasterKey, // Master Key
|
||||
128 / 8, // Master Key length
|
||||
_localMasterKeyLength, // Master Key length
|
||||
_localMasterSalt, // Master Salt
|
||||
112 / 8, // Master Salt length
|
||||
_localMasterSaltLength, // Master Salt length
|
||||
128 / 8, // encryption keyl
|
||||
160 / 8, // authentication key len
|
||||
112 / 8, // session salt len
|
||||
|
@ -28,6 +28,30 @@ class SdesNegotiator;
|
||||
class ManagerImpl;
|
||||
class SIPCall;
|
||||
|
||||
/*
|
||||
Table from RFC 4568 6.2. Crypto-Suites, which define key parameters for supported
|
||||
cipher suite
|
||||
|
||||
+---------------------+-------------+--------------+---------------+
|
||||
| |AES_CM_128_ | AES_CM_128_ | F8_128_ |
|
||||
| |HMAC_SHA1_80 | HMAC_SHA1_32 | HMAC_SHA1_80 |
|
||||
+---------------------+-------------+--------------+---------------+
|
||||
| Master key length | 128 bits | 128 bits | 128 bits |
|
||||
| Master salt length | 112 bits | 112 bits | 112 bits |
|
||||
| SRTP lifetime | 2^48 packets| 2^48 packets | 2^48 packets |
|
||||
| SRTCP lifetime | 2^31 packets| 2^31 packets | 2^31 packets |
|
||||
| Cipher | AES Counter | AES Counter | AES F8 Mode |
|
||||
| | Mode | Mode | |
|
||||
| Encryption key | 128 bits | 128 bits | 128 bits |
|
||||
| MAC | HMAC-SHA1 | HMAC-SHA1 | HMAC-SHA1 |
|
||||
| SRTP auth. tag | 80 bits | 32 bits | 80 bits |
|
||||
| SRTCP auth. tag | 80 bits | 80 bits | 80 bits |
|
||||
| SRTP auth. key len. | 160 bits | 160 bits | 160 bits |
|
||||
| SRTCP auth. key len.| 160 bits | 160 bits | 160 bits |
|
||||
+---------------------+-------------+--------------+---------------+
|
||||
*/
|
||||
|
||||
|
||||
namespace sfl {
|
||||
|
||||
class SrtpException: public std::exception
|
||||
@ -66,20 +90,30 @@ namespace sfl {
|
||||
|
||||
char* decodeBase64(unsigned char *input, int length, int *length_out);
|
||||
|
||||
/** Default local crypto suite is AES_CM_128_HMAC_SHA1_80*/
|
||||
int _localCryptoSuite;
|
||||
|
||||
/** Remote crypto suite is initialized at AES_CM_128_HMAC_SHA1_80*/
|
||||
int _remoteCryptoSuite;
|
||||
|
||||
uint8 _localMasterKey[16];
|
||||
|
||||
/** local master key length in byte */
|
||||
int _localMasterKeyLength;
|
||||
|
||||
uint8 _localMasterSalt[14];
|
||||
|
||||
/** local master salt length in byte */
|
||||
int _localMasterSaltLength;
|
||||
|
||||
uint8 _remoteMasterKey[16];
|
||||
|
||||
/** remote master key length in byte */
|
||||
int _remoteMasterKeyLength;
|
||||
|
||||
uint8 _remoteMasterSalt[14];
|
||||
|
||||
/** remote master salt length in byte */
|
||||
int _remoteMasterSaltLength;
|
||||
|
||||
ost::CryptoContext* _remoteCryptoCtx;
|
||||
|
Reference in New Issue
Block a user