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

[#1722] Add accessors in SdesNegotiator to get srtp info after negotiation

parent fbaf32a5
No related branches found
No related tags found
No related merge requests found
...@@ -143,9 +143,8 @@ void SdesNegotiator::parse (void) ...@@ -143,9 +143,8 @@ void SdesNegotiator::parse (void)
cryptoSuitePattern->matches(); cryptoSuitePattern->matches();
try { try {
std::string cryptoSuite; _cryptoSuite = cryptoSuitePattern->group ("cryptoSuite");
cryptoSuite = cryptoSuitePattern->group ("cryptoSuite"); std::cout << "crypto-suite = " << _cryptoSuite << std::endl;
std::cout << "crypto-suite = " << cryptoSuite << std::endl;
} catch (match_error& exception) { } catch (match_error& exception) {
throw parse_error ("Error while parsing the crypto-suite field"); throw parse_error ("Error while parsing the crypto-suite field");
} }
...@@ -155,25 +154,21 @@ void SdesNegotiator::parse (void) ...@@ -155,25 +154,21 @@ void SdesNegotiator::parse (void)
try { try {
while (keyParamsPattern->matches()) { while (keyParamsPattern->matches()) {
std::string srtpKeyMethod;
srtpKeyMethod = keyParamsPattern->group ("srtpKeyMethod");
std::cout << "srtp-key-method = " << srtpKeyMethod << std::endl;
std::string srtpKeyInfo; _srtpKeyMethod = keyParamsPattern->group ("srtpKeyMethod");
srtpKeyInfo = keyParamsPattern->group ("srtpKeyInfo"); std::cout << "srtp-key-method = " << _srtpKeyMethod << std::endl;
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");
lifetime = keyParamsPattern->group ("lifetime"); std::cout << "lifetime = " << _lifetime << std::endl;
std::cout << "lifetime = " << lifetime << std::endl;
std::string mkiValue; _mkiValue = keyParamsPattern->group ("mkiValue");
mkiValue = keyParamsPattern->group ("mkiValue"); std::cout << "mkiValue = " << _mkiValue << std::endl;
std::cout << "mkiValue = " << mkiValue << std::endl;
std::string mkiLength; _mkiLength = keyParamsPattern->group ("mkiLength");
mkiLength = keyParamsPattern->group ("mkiLength"); std::cout << "mkiLength = " << _mkiLength << std::endl;
std::cout << "mkiLength = " << mkiLength << std::endl;
} }
} catch (match_error& exception) { } catch (match_error& exception) {
throw parse_error ("Error while parsing the key-params field"); throw parse_error ("Error while parsing the key-params field");
......
...@@ -97,9 +97,38 @@ namespace sfl { ...@@ -97,9 +97,38 @@ namespace sfl {
SdesNegotiator(const std::vector<CryptoSuiteDefinition>& localCapabilites, const std::vector<std::string>& remoteAttribute); SdesNegotiator(const std::vector<CryptoSuiteDefinition>& localCapabilites, const std::vector<std::string>& remoteAttribute);
~SdesNegotiator() { }; ~SdesNegotiator() { };
public:
bool negotiate(void); 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: private:
/** /**
* A vector list containing the remote attributes. * A vector list containing the remote attributes.
...@@ -107,12 +136,41 @@ namespace sfl { ...@@ -107,12 +136,41 @@ namespace sfl {
* prefered method is then chosen from that list. * prefered method is then chosen from that list.
*/ */
std::vector<std::string> _remoteAttribute; std::vector<std::string> _remoteAttribute;
std::vector<CryptoSuiteDefinition> _localCapabilities; std::vector<CryptoSuiteDefinition> _localCapabilities;
/**
* Selected crypto suite after negotiation
*/
std::string _cryptoSuite;
/**
* 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;
private:
void parse(void); void parse(void);
CryptoAttribute * tokenize(const std::string& attributeLine); CryptoAttribute * tokenize(const std::string& attributeLine);
}; };
} }
......
...@@ -114,14 +114,30 @@ void SdesNegotiatorTest::testKeyParamsPattern() ...@@ -114,14 +114,30 @@ void SdesNegotiatorTest::testKeyParamsPattern()
"(?P<srtpKeyInfo>[A-Za-z0-9\x2B\x2F\x3D]+)\\|" \ "(?P<srtpKeyInfo>[A-Za-z0-9\x2B\x2F\x3D]+)\\|" \
"2\\^(?P<lifetime>[0-9]+)\\|" \ "2\\^(?P<lifetime>[0-9]+)\\|" \
"(?P<mkiValue>[0-9]+)\\:" \ "(?P<mkiValue>[0-9]+)\\:" \
"(?P<mkiLength>[0-9]{1,3})\\;?"); "(?P<mkiLength>[0-9]{1,3})\\;?", "g");
*pattern << subject; *pattern << subject;
CPPUNIT_ASSERT(pattern->matches()); pattern->matches();
CPPUNIT_ASSERT(pattern->group("srtpKeyMethod").compare("inline:")); CPPUNIT_ASSERT(pattern->group("srtpKeyMethod").compare("inline:"));
// printf("srtpKeyInfo %s\n", pattern->group("srtpKeyInfo").c_str());
// CPPUNIT_ASSERT(pattern->group("srtpKeyInfo").compare("d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj")); /*
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:"));
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; delete pattern;
pattern = NULL; pattern = NULL;
...@@ -131,6 +147,12 @@ void SdesNegotiatorTest::testKeyParamsPattern() ...@@ -131,6 +147,12 @@ void SdesNegotiatorTest::testKeyParamsPattern()
void SdesNegotiatorTest::testNegotiation() void SdesNegotiatorTest::testNegotiation()
{ {
CPPUNIT_ASSERT(sdesnego->negotiate()); 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);
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment