diff --git a/sflphone-common/src/sip/SdesNegotiator.cpp b/sflphone-common/src/sip/SdesNegotiator.cpp index f9411df3d9649187f0c59e129ea16240489c7b68..b2d1aafd3e00e73b932da64dd6f56ce0bfaac6a6 100644 --- a/sflphone-common/src/sip/SdesNegotiator.cpp +++ b/sflphone-common/src/sip/SdesNegotiator.cpp @@ -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; } diff --git a/sflphone-common/src/sip/SdesNegotiator.h b/sflphone-common/src/sip/SdesNegotiator.h index d8a568421e14cdccf540a44ba3f6267d09863775..f038d012bacab8abbde0f72b1093aa92c155a98e 100644 --- a/sflphone-common/src/sip/SdesNegotiator.h +++ b/sflphone-common/src/sip/SdesNegotiator.h @@ -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 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 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: /** @@ -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 diff --git a/sflphone-common/src/sip/sdp.cpp b/sflphone-common/src/sip/sdp.cpp index 69ab580cc40d4811fcdf324f425605f6426a5e9a..45efccf15bb75e95544ed4ba67c6dd49030bd3d4 100644 --- a/sflphone-common/src/sip/sdp.cpp +++ b/sflphone-common/src/sip/sdp.cpp @@ -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 diff --git a/sflphone-common/src/sip/sipvoiplink.cpp b/sflphone-common/src/sip/sipvoiplink.cpp index ed81c182f92f36fac8117d3a55cfc43ff2e09bf3..8d597bc2523a51a15b0aabfde9cb421168334f8b 100644 --- a/sflphone-common/src/sip/sipvoiplink.cpp +++ b/sflphone-common/src/sip/sipvoiplink.cpp @@ -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 { diff --git a/sflphone-common/src/sip/sipvoiplink.h b/sflphone-common/src/sip/sipvoiplink.h index 620dc9919e5859ad9da211b201214bcd52dd423a..94b08bdc898182a9c22163b5634942cca67275a1 100644 --- a/sflphone-common/src/sip/sipvoiplink.h +++ b/sflphone-common/src/sip/sipvoiplink.h @@ -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