diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp index eabf054b16c08dd13c6cb93672fa118e8ac11452..71ed7952af089a88d7385643c1d75633ecc20aad 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp +++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.cpp @@ -136,6 +136,8 @@ void AudioRtpFactory::initAudioRtpSession (SIPCall * ca) _rtpSession = new AudioSrtpSession (&Manager::instance(), ca); _rtpSessionType = Sdes; + static_cast<AudioSrtpSession *> (_rtpSession)->initLocalCryptoInfo (); + ca->getLocalSDP()->set_srtp_crypto (static_cast<AudioSrtpSession *> (_rtpSession)->getLocalCryptoInfo()); break; @@ -260,6 +262,13 @@ sfl::AudioZrtpSession * AudioRtpFactory::getAudioZrtpSession() } } +void sfl::AudioRtpFactory::initLocalCryptoInfo () +{ + if (_rtpSession && _rtpSessionType && (_rtpSessionType == Sdes)) { + static_cast<AudioSrtpSession *> (_rtpSession)->initLocalCryptoInfo (); + } +} + void AudioRtpFactory::setRemoteCryptoInfo (sfl::SdesNegotiator& nego) { if (_rtpSession && _rtpSessionType && (_rtpSessionType == Sdes)) { diff --git a/sflphone-common/src/audio/audiortp/AudioRtpFactory.h b/sflphone-common/src/audio/audiortp/AudioRtpFactory.h index b870333fb055a655aa842e8cd1c833511b6a6d70..263e9fee10c4166213af3d7b46950a3fb3df5b15 100644 --- a/sflphone-common/src/audio/audiortp/AudioRtpFactory.h +++ b/sflphone-common/src/audio/audiortp/AudioRtpFactory.h @@ -166,6 +166,8 @@ class AudioRtpFactory */ sfl::AudioZrtpSession * getAudioZrtpSession(); + void initLocalCryptoInfo (void); + /** * Set remote cryptographic info. Should be called after negotiation in SDP * offer/answer session. diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp index 522164ab34dd537b7e52b115cec782827aca2497..67000fc55005660d29758394e685044632b2db80 100644 --- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp +++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.cpp @@ -51,8 +51,8 @@ namespace sfl AudioSrtpSession::AudioSrtpSession (ManagerImpl * manager, SIPCall * sipcall) : ost::SymmetricRTPSession (ost::InetHostAddress (sipcall->getLocalIp().c_str()), sipcall->getLocalAudioPort()), AudioRtpSession<AudioSrtpSession> (manager, sipcall), - _localCryptoSuite (1), - _remoteCryptoSuite (1), + _localCryptoSuite (0), + _remoteCryptoSuite (0), _localMasterKeyLength (0), _localMasterSaltLength (0), _remoteMasterKeyLength (0), @@ -120,8 +120,8 @@ void AudioSrtpSession::setRemoteCryptoInfo (sfl::SdesNegotiator& nego) // Use second crypto suite if key length is 32 bit, default is 80; - if (nego.getMkiLength() == "32") { - _debug ("AudioSrtp: Using %s byte key length", nego.getMkiLength().c_str()); + if (nego.getAuthTagLength() == "32") { + _debug ("AudioSrtp: Using %s byte authentication tag length", nego.getAuthTagLength().c_str()); _localCryptoSuite = 1; _remoteCryptoSuite = 1; } @@ -251,7 +251,7 @@ void AudioSrtpSession::initializeRemoteCryptoContext (void) _remoteMasterSaltLength, crypto.encryptionKeyLength / 8, crypto.srtpAuthKeyLength / 8, - 112 / 8, // session salt len + crypto.masterSaltLength / 8, // session salt len crypto.srtpAuthTagLength / 8); } @@ -273,7 +273,7 @@ void AudioSrtpSession::initializeLocalCryptoContext (void) _localMasterSaltLength, crypto.encryptionKeyLength / 8, crypto.srtpAuthKeyLength / 8, - 112 / 8, // session salt len + crypto.masterSaltLength / 8, // session salt len crypto.srtpAuthTagLength / 8); } diff --git a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h index b461a5a13294e6bea8b8889d228756be1fb8d729..34e680f343e2eab7b2a5c6bbcb11a0fc0af3e49b 100644 --- a/sflphone-common/src/audio/audiortp/AudioSrtpSession.h +++ b/sflphone-common/src/audio/audiortp/AudioSrtpSession.h @@ -84,10 +84,10 @@ class AudioSrtpSession : public ost::SymmetricRTPSession, public AudioRtpSession void setRemoteCryptoInfo (sfl::SdesNegotiator& nego); - private: - void initLocalCryptoInfo (void); + private: + void initializeLocalMasterKey (void); void initializeLocalMasterSalt (void); diff --git a/sflphone-common/src/managerimpl.cpp b/sflphone-common/src/managerimpl.cpp index b453b4866d1ed82d119a748b5da4980f3603aa78..8c165cdb47e40da481f60e956e2347bb055831c7 100644 --- a/sflphone-common/src/managerimpl.cpp +++ b/sflphone-common/src/managerimpl.cpp @@ -3942,7 +3942,7 @@ ManagerImpl::getAccount (const AccountID& accountID) return iter->second; } - _debug ("Manager: Did not found account %s, returning IP2IP account"); + _debug ("Manager: Did not found account %s, returning IP2IP account", accountID.c_str()); return _directIpAccount; } diff --git a/sflphone-common/src/sip/SdesNegotiator.cpp b/sflphone-common/src/sip/SdesNegotiator.cpp index cce934716c094a0f2b879dc765968d577c0a423a..9e85492b49867b046b2f393736edbd9cf741d766 100644 --- a/sflphone-common/src/sip/SdesNegotiator.cpp +++ b/sflphone-common/src/sip/SdesNegotiator.cpp @@ -248,7 +248,7 @@ bool SdesNegotiator::negotiate (void) // _mkiValue = (*iter_offer)->getMkiValue(); // _mkiLength = (*iter_offer)->getMkiLength(); - _mkiLength = _cryptoSuite.substr (_cryptoSuite.size()-2, 2); + _authTagLength = _cryptoSuite.substr (_cryptoSuite.size()-2, 2); std::cout << "Negotiate tag: " + (*iter_offer)->getTag() << std::endl; std::cout << "Crypto Suite: " + _cryptoSuite << std::endl; @@ -256,7 +256,8 @@ bool SdesNegotiator::negotiate (void) std::cout << "SRTP Key Info: " + _srtpKeyInfo << std::endl; // std::cout << "Lifetime: " + _lifetime << std::endl; // std::cout << "MKI Value: " + _mkiValue << std::endl; - std::cout << "MKI Length: " + _mkiLength << std::endl; + // std::cout << "MKI Length: " + _mkiLength << std::endl; + std::cout << "Auth tag length: " + _authTagLength << std::endl; } iter_local++; diff --git a/sflphone-common/src/sip/SdesNegotiator.h b/sflphone-common/src/sip/SdesNegotiator.h index dc78fa11324316b122a680147b98a68b0eaab7c4..f62a597e9d5aac6039c8fd34ac28d51c20586b38 100644 --- a/sflphone-common/src/sip/SdesNegotiator.h +++ b/sflphone-common/src/sip/SdesNegotiator.h @@ -202,6 +202,13 @@ class SdesNegotiator return _mkiLength; } + /** + * Authentication tag lenth + */ + std::string getAuthTagLength (void) { + return _authTagLength; + } + private: /** @@ -243,6 +250,11 @@ class SdesNegotiator */ std::string _mkiLength; + /** + * Authenticvation tag length in byte + */ + std::string _authTagLength; + std::vector<CryptoAttribute *> parse (void); }; } diff --git a/sflphone-common/test/sdesnegotiatortest.cpp b/sflphone-common/test/sdesnegotiatortest.cpp index fd1f630fe70d3288f722b3e3fbb92a77f188d2d0..df6b3675d2679f185f42315b8c8254dd7e9efa50 100644 --- a/sflphone-common/test/sdesnegotiatortest.cpp +++ b/sflphone-common/test/sdesnegotiatortest.cpp @@ -222,12 +222,14 @@ void SdesNegotiatorTest::testMostSimpleCase() CPPUNIT_ASSERT (negotiator->negotiate() == true); - CPPUNIT_ASSERT (negotiator->getCryptoSuite().compare ("AES_CM_128_HMAC_SHA1_80") == 0); - CPPUNIT_ASSERT (negotiator->getKeyMethod().compare ("inline") == 0); - CPPUNIT_ASSERT (negotiator->getKeyInfo().compare ("AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd") == 0); - CPPUNIT_ASSERT (negotiator->getLifeTime().compare ("") == 0); - CPPUNIT_ASSERT (negotiator->getMkiValue().compare ("") == 0); - CPPUNIT_ASSERT (negotiator->getMkiLength().compare ("") == 0); + CPPUNIT_ASSERT (negotiator->getCryptoSuite() == "AES_CM_128_HMAC_SHA1_80"); + CPPUNIT_ASSERT (negotiator->getKeyMethod() == "inline"); + CPPUNIT_ASSERT (negotiator->getKeyInfo() == "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); + CPPUNIT_ASSERT (negotiator->getLifeTime() == ""); + CPPUNIT_ASSERT (negotiator->getMkiValue() == ""); + CPPUNIT_ASSERT (negotiator->getMkiLength() == ""); + CPPUNIT_ASSERT (negotiator->getAuthTagLength() == "80"); + delete capabilities; capabilities = NULL; @@ -236,3 +238,41 @@ void SdesNegotiatorTest::testMostSimpleCase() delete negotiator; negotiator = NULL; } + + +void SdesNegotiatorTest::test32ByteKeyLength() +{ + _debug ("-------------------- SdesNegotiatorTest::test32ByteKeyLength --------------------\n"); + + // Register the local capabilities. + std::vector<sfl::CryptoSuiteDefinition> * capabilities = new std::vector<sfl::CryptoSuiteDefinition>(); + + //Support all the CryptoSuites + for (int i = 0; i < 3; i++) { + capabilities->push_back (sfl::CryptoSuites[i]); + } + + std::string cryptoLine ("a=crypto:1 AES_CM_128_HMAC_SHA1_32 inline:AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); + std::vector<std::string> * cryptoOffer = new std::vector<std::string>(); + cryptoOffer->push_back (cryptoLine); + + sfl::SdesNegotiator * negotiator = new sfl::SdesNegotiator (*capabilities, *cryptoOffer); + + CPPUNIT_ASSERT (negotiator->negotiate() == true); + + CPPUNIT_ASSERT (negotiator->getCryptoSuite() == "AES_CM_128_HMAC_SHA1_32"); + CPPUNIT_ASSERT (negotiator->getKeyMethod() == "inline"); + CPPUNIT_ASSERT (negotiator->getKeyInfo() == "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwd"); + CPPUNIT_ASSERT (negotiator->getLifeTime() == ""); + CPPUNIT_ASSERT (negotiator->getMkiValue() == ""); + CPPUNIT_ASSERT (negotiator->getMkiLength() == ""); + CPPUNIT_ASSERT (negotiator->getAuthTagLength() == "32"); + + delete capabilities; + capabilities = NULL; + delete cryptoOffer; + cryptoOffer = NULL; + delete negotiator; + negotiator = NULL; +} + diff --git a/sflphone-common/test/sdesnegotiatortest.h b/sflphone-common/test/sdesnegotiatortest.h index ee5cb339645004f6fffc53caf9f596c7c7f53552..eee9de5b356bf1f420645beae14cf7e3169b218f 100644 --- a/sflphone-common/test/sdesnegotiatortest.h +++ b/sflphone-common/test/sdesnegotiatortest.h @@ -76,6 +76,7 @@ class SdesNegotiatorTest : public CppUnit::TestCase { CPPUNIT_TEST( testKeyParamsPatternWithoutMKI ); CPPUNIT_TEST( testNegotiation ); CPPUNIT_TEST( testMostSimpleCase ); + CPPUNIT_TEST( test32ByteKeyLength ); CPPUNIT_TEST_SUITE_END(); public: @@ -90,7 +91,7 @@ class SdesNegotiatorTest : public CppUnit::TestCase { void testKeyParamsPattern(); - void testKeyParamsPatternCiscoStyle(); + void testKeyParamsPatternCiscoStyle(); void testKeyParamsPatternWithoutMKI(); @@ -100,6 +101,8 @@ class SdesNegotiatorTest : public CppUnit::TestCase { void testMostSimpleCase(); + void test32ByteKeyLength(); + private: sfl::Pattern *pattern;