[#1722] Add negociation to SdesNegotiator

This commit is contained in:
Alexandre Savard
2010-01-18 15:14:51 -05:00
parent 26131ec2d5
commit 80204bfdf7
5 changed files with 182 additions and 145 deletions

View File

@ -1,6 +1,7 @@
/*
* Copyright (C) 2009 Savoir-Faire Linux inc.
* Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -91,14 +92,15 @@ std::vector<CryptoAttribute *> SdesNegotiator::parse (void)
std::vector<std::string>::iterator iter;
std::vector<CryptoAttribute *> cryptoAttributeVector;
std::vector<CryptoAttribute *> cryptoAttributeVector;
for (iter = _remoteAttribute.begin(); iter != _remoteAttribute.end(); iter++) {
// Split the line into its component
// that we will analyze further down.
std::vector<std::string> sdesLine;
std::vector<std::string> sdesLine;
*generalSyntaxPattern << (*iter);
*generalSyntaxPattern << (*iter);
try {
sdesLine = generalSyntaxPattern->split();
@ -115,42 +117,42 @@ std::vector<CryptoAttribute *> SdesNegotiator::parse (void)
// and get the tag for this line
*tagPattern << sdesLine.at (0);
std::string tag;
if (tagPattern->matches()) {
try {
tag = tagPattern->group ("tag");
} catch (match_error& exception) {
throw parse_error ("Error while parsing the tag field");
}
} else {
return cryptoAttributeVector;
}
std::string tag;
if (tagPattern->matches()) {
try {
tag = tagPattern->group ("tag");
} catch (match_error& exception) {
throw parse_error ("Error while parsing the tag field");
}
} else {
return cryptoAttributeVector;
}
// Check if the crypto suite is valid and retreive
// its value.
*cryptoSuitePattern << sdesLine.at (1);
std::string cryptoSuite;
std::string cryptoSuite;
if (cryptoSuitePattern->matches()) {
try {
cryptoSuite = cryptoSuitePattern->group ("cryptoSuite");
} catch (match_error& exception) {
throw parse_error ("Error while parsing the crypto-suite field");
}
} else {
return cryptoAttributeVector;
}
if (cryptoSuitePattern->matches()) {
try {
cryptoSuite = cryptoSuitePattern->group ("cryptoSuite");
} catch (match_error& exception) {
throw parse_error ("Error while parsing the crypto-suite field");
}
} else {
return cryptoAttributeVector;
}
// Parse one or more key-params field.
*keyParamsPattern << sdesLine.at (2);
std::string srtpKeyInfo;
std::string srtpKeyMethod;
std::string lifetime;
std::string mkiLength;
std::string mkiValue;
std::string srtpKeyInfo;
std::string srtpKeyMethod;
std::string lifetime;
std::string mkiLength;
std::string mkiValue;
try {
while (keyParamsPattern->matches()) {
srtpKeyMethod = keyParamsPattern->group ("srtpKeyMethod");
@ -181,38 +183,67 @@ std::vector<CryptoAttribute *> SdesNegotiator::parse (void)
}
} */
// Add the new CryptoAttribute to the vector
std::cout << (*iter) << std::endl;
CryptoAttribute * cryptoAttribute = new CryptoAttribute(tag, cryptoSuite, srtpKeyMethod, srtpKeyInfo, lifetime, mkiValue, mkiLength);
cryptoAttributeVector.push_back(cryptoAttribute);
// Add the new CryptoAttribute to the vector
std::cout << (*iter) << std::endl;
CryptoAttribute * cryptoAttribute = new CryptoAttribute(tag, cryptoSuite, srtpKeyMethod, srtpKeyInfo, lifetime, mkiValue, mkiLength);
cryptoAttributeVector.push_back(cryptoAttribute);
}
return cryptoAttributeVector;
return cryptoAttributeVector;
}
bool SdesNegotiator::negotiate (void)
{
try {
std::vector<CryptoAttribute *> cryptoAttributeVector = parse();
std::vector<CryptoAttribute *> cryptoAttributeVector = parse();
std::vector<CryptoAttribute *>::iterator iter_offer = cryptoAttributeVector.begin();
std::vector<CryptoSuiteDefinition>::iterator iter_local = _localCapabilities.begin();
bool negotiationSuccess = false;
try {
std::vector<CryptoAttribute *>::iterator iter;
for (iter = cryptoAttributeVector.begin(); iter != cryptoAttributeVector.end(); iter++) {
std::cout << "Negotiate tag: " + (*iter)->getTag() << std::endl;
std::cout << "Crypto Suite: " + (*iter)->getCryptoSuite() << std::endl;
std::cout << "SRTP Key Method: " + (*iter)->getSrtpKeyMethod() << std::endl;
std::cout << "SRTP Key Info: " + (*iter)->getSrtpKeyInfo() << std::endl;
std::cout << "Lifetime: " + (*iter)->getLifetime() << std::endl;
std::cout << "MKI Value: " + (*iter)->getMkiValue() << std::endl;
std::cout << "MKI Length: " + (*iter)->getMkiLength() << std::endl;
delete (*iter);
while (!negotiationSuccess && (iter_offer != cryptoAttributeVector.end())) {
/*
std::cout << "Negotiate tag: " + (*iter_offer)->getTag() << std::endl;
std::cout << "Crypto Suite: " + (*iter_offer)->getCryptoSuite() << std::endl;
std::cout << "SRTP Key Method: " + (*iter_offer)->getSrtpKeyMethod() << std::endl;
std::cout << "SRTP Key Info: " + (*iter_offer)->getSrtpKeyInfo() << std::endl;
std::cout << "Lifetime: " + (*iter_offer)->getLifetime() << std::endl;
std::cout << "MKI Value: " + (*iter_offer)->getMkiValue() << std::endl;
std::cout << "MKI Length: " + (*iter_offer)->getMkiLength() << std::endl;
*/
iter_local = _localCapabilities.begin();
while(!negotiationSuccess && (iter_local != _localCapabilities.end())) {
if((*iter_offer)->getCryptoSuite().compare((*iter_local).name)){
negotiationSuccess = true;
_cryptoSuite = (*iter_offer)->getCryptoSuite();
_srtpKeyMethod = (*iter_offer)->getSrtpKeyMethod();
_srtpKeyInfo = (*iter_offer)->getSrtpKeyInfo();
_lifetime = (*iter_offer)->getLifetime();
_mkiValue = (*iter_offer)->getMkiValue();
_mkiLength = (*iter_offer)->getMkiLength();
}
} catch (parse_error& exception) {
return false;
} catch (match_error& exception) {
return false;
iter_local++;
}
delete (*iter_offer);
iter_offer++;
}
return true;
} catch (parse_error& exception) {
return false;
} catch (match_error& exception) {
return false;
}
return negotiationSuccess;
}

View File

@ -1,6 +1,7 @@
/*
* Copyright (C) 2009 Savoir-Faire Linux inc.
* Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -75,42 +76,42 @@ namespace sfl {
{"F8_128_HMAC_SHA1_80", 128, 112, 48, 31, AESF8Mode, 128, HMACSHA1, 80, 80, 160, 160 } };
class CryptoAttribute {
class CryptoAttribute {
public:
CryptoAttribute(std::string tag,
std::string cryptoSuite,
std::string srtpKeyMethod,
std::string srtpKeyInfo,
std::string lifetime,
std::string mkiValue,
std::string mkiLength) :
tag(tag),
cryptoSuite(cryptoSuite),
srtpKeyMethod(srtpKeyMethod),
srtpKeyInfo(srtpKeyInfo),
lifetime(lifetime),
mkiValue(mkiValue),
mkiLength(mkiLength) {};
public:
CryptoAttribute(std::string tag,
std::string cryptoSuite,
std::string srtpKeyMethod,
std::string srtpKeyInfo,
std::string lifetime,
std::string mkiValue,
std::string mkiLength) :
tag(tag),
cryptoSuite(cryptoSuite),
srtpKeyMethod(srtpKeyMethod),
srtpKeyInfo(srtpKeyInfo),
lifetime(lifetime),
mkiValue(mkiValue),
mkiLength(mkiLength) {};
inline std::string getTag() { return tag; };
inline std::string getCryptoSuite() { return cryptoSuite; };
inline std::string getSrtpKeyMethod() { return srtpKeyMethod; };
inline std::string getSrtpKeyInfo() { return srtpKeyInfo; };
inline std::string getLifetime() { return lifetime; };
inline std::string getMkiValue() { return mkiValue; };
inline std::string getMkiLength() { return mkiLength; };
inline std::string getTag() { return tag; };
inline std::string getCryptoSuite() { return cryptoSuite; };
inline std::string getSrtpKeyMethod() { return srtpKeyMethod; };
inline std::string getSrtpKeyInfo() { return srtpKeyInfo; };
inline std::string getLifetime() { return lifetime; };
inline std::string getMkiValue() { return mkiValue; };
inline std::string getMkiLength() { return mkiLength; };
private:
std::string tag;
std::string cryptoSuite;
std::string srtpKeyMethod;
std::string srtpKeyInfo;
std::string lifetime;
std::string mkiValue;
std::string mkiLength;
};
std::string tag;
std::string cryptoSuite;
std::string srtpKeyMethod;
std::string srtpKeyInfo;
std::string lifetime;
std::string mkiValue;
std::string mkiLength;
};
class SdesNegotiator
{
@ -131,35 +132,35 @@ namespace sfl {
bool negotiate(void);
/**
* Return crypto suite after negotiation
*/
std::string getCryptoSuite(void) { return _cryptoSuite; }
/**
* 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; }
/**
* 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:
/**
@ -171,37 +172,37 @@ namespace sfl {
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;
std::vector<CryptoAttribute *> parse(void);
/**
* 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;
std::vector<CryptoAttribute *> parse(void);
};
}
#endif

View File

@ -2,6 +2,7 @@
* Copyright (C) 2009 Savoir-Faire Linux inc.
*
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by

View File

@ -4,6 +4,7 @@
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
* Author: Yun Liu <yun.liu@savoirfairelinux.com>
* Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -3247,8 +3248,10 @@ void call_on_media_update (pjsip_inv_session *inv, pj_status_t status)
_debug("SDES negociation successfull \n");
nego_success = true;
if(call->getAudioRtp()->getAudioRtpType() == sfl::Sdes)
if(call->getAudioRtp()->getAudioRtpType() == sfl::Sdes) {
_debug("Set remote cryptographic context\n");
call->getAudioRtp()->setRemoteCryptoInfo(sdesnego);
}
}
else {

View File

@ -4,6 +4,7 @@
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
* Author: Yun Liu <yun.liu@savoirfairelinux.com>
* Author: Pierre-Luc Bacon <pierre-luc.bacon@savoirfairelinux.com>
* Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by