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
Branches
Tags
No related merge requests found
......@@ -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");
......
......@@ -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);
};
}
......
......@@ -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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment