diff --git a/sflphone-common/src/sip/SdesNegotiator.cpp b/sflphone-common/src/sip/SdesNegotiator.cpp index 40a736eeb2696ba871a17aa0c855a57673eede1b..e8618e3ab8d80f0bfb9b13fc5205cda5c847c869 100644 --- a/sflphone-common/src/sip/SdesNegotiator.cpp +++ b/sflphone-common/src/sip/SdesNegotiator.cpp @@ -143,9 +143,8 @@ void SdesNegotiator::parse (void) cryptoSuitePattern->matches(); try { - std::string cryptoSuite; - cryptoSuite = cryptoSuitePattern->group ("cryptoSuite"); - std::cout << "crypto-suite = " << cryptoSuite << std::endl; + _cryptoSuite = cryptoSuitePattern->group ("cryptoSuite"); + std::cout << "crypto-suite = " << _cryptoSuite << std::endl; } catch (match_error& exception) { throw parse_error ("Error while parsing the crypto-suite field"); } @@ -155,25 +154,21 @@ void SdesNegotiator::parse (void) try { while (keyParamsPattern->matches()) { - std::string srtpKeyMethod; - srtpKeyMethod = keyParamsPattern->group ("srtpKeyMethod"); - std::cout << "srtp-key-method = " << srtpKeyMethod << std::endl; + + _srtpKeyMethod = keyParamsPattern->group ("srtpKeyMethod"); + std::cout << "srtp-key-method = " << _srtpKeyMethod << std::endl; - std::string srtpKeyInfo; - srtpKeyInfo = keyParamsPattern->group ("srtpKeyInfo"); - std::cout << "srtp-key-info = " << srtpKeyInfo << std::endl; + _srtpKeyInfo = keyParamsPattern->group ("srtpKeyInfo"); + std::cout << "srtp-key-info = " << _srtpKeyInfo << std::endl; - std::string lifetime; - lifetime = keyParamsPattern->group ("lifetime"); - std::cout << "lifetime = " << lifetime << std::endl; + _lifetime = keyParamsPattern->group ("lifetime"); + std::cout << "lifetime = " << _lifetime << std::endl; - std::string mkiValue; - mkiValue = keyParamsPattern->group ("mkiValue"); - std::cout << "mkiValue = " << mkiValue << std::endl; + _mkiValue = keyParamsPattern->group ("mkiValue"); + std::cout << "mkiValue = " << _mkiValue << std::endl; - std::string mkiLength; - mkiLength = keyParamsPattern->group ("mkiLength"); - std::cout << "mkiLength = " << mkiLength << std::endl; + _mkiLength = keyParamsPattern->group ("mkiLength"); + std::cout << "mkiLength = " << _mkiLength << std::endl; } } catch (match_error& exception) { throw parse_error ("Error while parsing the key-params field"); diff --git a/sflphone-common/src/sip/SdesNegotiator.h b/sflphone-common/src/sip/SdesNegotiator.h index 2dded5b1a7582002646dc07451ca8e8bb40fb107..08e32090ef5e64b5731f2fab2ace701135414fc0 100644 --- a/sflphone-common/src/sip/SdesNegotiator.h +++ b/sflphone-common/src/sip/SdesNegotiator.h @@ -97,9 +97,38 @@ namespace sfl { SdesNegotiator(const std::vector<CryptoSuiteDefinition>& localCapabilites, const std::vector<std::string>& remoteAttribute); ~SdesNegotiator() { }; - public: bool negotiate(void); + /** + * Return crypto suite after negotiation + */ + std::string getCryptoSuite(void) { return _cryptoSuite; } + + /** + * Return key method after negotiation (most likely inline:) + */ + std::string getKeyMethod(void) { return _srtpKeyMethod; } + + /** + * Return crypto suite after negotiation + */ + std::string getKeyInfo(void) { return _srtpKeyInfo; } + + /** + * Return key lifetime after negotiation + */ + std::string getLifeTime(void) { return _lifetime; } + + /** + * Return mki value after negotiation + */ + std::string getMkiValue(void) { return _mkiValue; } + + /** + * Return mki length after negotiation + */ + std::string getMkiLength(void) { return _mkiLength; } + private: /** * A vector list containing the remote attributes. @@ -107,12 +136,41 @@ namespace sfl { * prefered method is then chosen from that list. */ std::vector<std::string> _remoteAttribute; + std::vector<CryptoSuiteDefinition> _localCapabilities; - + /** + * Selected crypto suite after negotiation + */ + std::string _cryptoSuite; - private: + /** + * Selected key method after negotiation (most likely inline:) + */ + std::string _srtpKeyMethod; + + /** + * Selected crypto suite after negotiation + */ + std::string _srtpKeyInfo; + + /** + * Selected key lifetime after negotiation + */ + std::string _lifetime; + + /** + * Selected mki value after negotiation + */ + std::string _mkiValue; + + /** + * Selected mki length after negotiation + */ + std::string _mkiLength; + void parse(void); + CryptoAttribute * tokenize(const std::string& attributeLine); }; } diff --git a/sflphone-common/test/sdesnegotiatorTest.cpp b/sflphone-common/test/sdesnegotiatorTest.cpp index bf5f442aa3cad5f6dcdf47a122186a2874040af4..ec208664524f6ef32d8e42a8506762dfcf8fe14b 100644 --- a/sflphone-common/test/sdesnegotiatorTest.cpp +++ b/sflphone-common/test/sdesnegotiatorTest.cpp @@ -114,14 +114,30 @@ void SdesNegotiatorTest::testKeyParamsPattern() "(?P<srtpKeyInfo>[A-Za-z0-9\x2B\x2F\x3D]+)\\|" \ "2\\^(?P<lifetime>[0-9]+)\\|" \ "(?P<mkiValue>[0-9]+)\\:" \ - "(?P<mkiLength>[0-9]{1,3})\\;?"); + "(?P<mkiLength>[0-9]{1,3})\\;?", "g"); *pattern << subject; - CPPUNIT_ASSERT(pattern->matches()); + pattern->matches(); + CPPUNIT_ASSERT(pattern->group("srtpKeyMethod").compare("inline:")); + + /* + while (pattern->matches()) { + + std::string _srtpKeyMethod = pattern->group ("srtpKeyMethod"); + std::string _srtpKeyInfo = pattern->group ("srtpKeyInfo"); + std::string _lifetime = pattern->group ("lifetime"); + std::string _mkiValue = pattern->group ("mkiValue"); + std::string _mkiLength = pattern->group ("mkiLength"); + } + + CPPUNIT_ASSERT(pattern->group("srtpKeyMethod").compare("inline:")); - // printf("srtpKeyInfo %s\n", pattern->group("srtpKeyInfo").c_str()); - // CPPUNIT_ASSERT(pattern->group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj")); + CPPUNIT_ASSERT(pattern->group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj")); + CPPUNIT_ASSERT(pattern->group("lifetime").compare("20")); + CPPUNIT_ASSERT(pattern->group("mkivalue").compare("1")); + CPPUNIT_ASSERT(pattern->group("mkilength").compare("32")); + */ delete pattern; pattern = NULL; @@ -131,6 +147,12 @@ void SdesNegotiatorTest::testKeyParamsPattern() void SdesNegotiatorTest::testNegotiation() { CPPUNIT_ASSERT(sdesnego->negotiate()); + CPPUNIT_ASSERT(sdesnego->getCryptoSuite().compare("AES_CM_128_HMAC_SHA1_80") == 0); + CPPUNIT_ASSERT(sdesnego->getKeyMethod().compare("inline") == 0); + CPPUNIT_ASSERT(sdesnego->getKeyInfo().compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); + CPPUNIT_ASSERT(sdesnego->getLifeTime().compare("20") == 0); + CPPUNIT_ASSERT(sdesnego->getMkiValue().compare("1") == 0); + CPPUNIT_ASSERT(sdesnego->getMkiLength().compare("32") == 0); }