Skip to content

Commit

Permalink
best effort tls enabled if env DRACHTIO_SUPPORT_BEST_EFFORT_TLS=1, me…
Browse files Browse the repository at this point in the history
…aning if remote side sends over tls with contact of sip rather than sip we will respond in kind with our contact header (#327)
  • Loading branch information
davehorton committed Jan 8, 2024
1 parent 91abe6a commit 72b762e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/sip-dialog-controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ THE SOFTWARE.
*/
#include <algorithm>
#include <regex>
#include <cstdlib> // For std::getenv

#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/find.hpp>
Expand All @@ -41,6 +42,8 @@ namespace drachtio {

namespace {

const char* envSupportBestEffortTls = std::getenv("DRACHTIO_SUPPORT_BEST_EFFORT_TLS");

std::string combineCallIdAndCSeq(nta_outgoing_t* orq) {
string callIdAndCSeq = nta_outgoing_call_id(orq);
callIdAndCSeq.append(" ");
Expand Down Expand Up @@ -1122,6 +1125,15 @@ namespace drachtio {
assert(pSelectedTransport);

pSelectedTransport->getContactUri(contact, true);

/* is far end requesting "best effort" tls ?*/
if (envSupportBestEffortTls && atoi(envSupportBestEffortTls) == 1 &&
pSelectedTransport->isSips() && sip->sip_contact && sip->sip_contact->m_url &&
0 == strcmp(sip->sip_contact->m_url->url_scheme, "sip")) {
contact.replace(0, 5, "sip:");
DR_LOG(log_info) << "SipDialogController::doRespondToSipRequest - far end wants best effort tls, replacing sips with sip in Contact";
}

contact = "<" + contact + ">" ;

pSelectedTransport->getDescription(transportDesc);
Expand Down
1 change: 1 addition & 0 deletions src/sip-transports.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ namespace drachtio {
bool isIpV6(void) ;
bool isLocalhost(void) ;
bool isLocal(const char* szHost) ;
bool isSips(void) { return 0 == m_contactScheme.compare("sips"); }

void setNetwork(const string& network) { m_network = network;}
void setNetmask(uint32_t netmask) { m_netmask = netmask;}
Expand Down

0 comments on commit 72b762e

Please sign in to comment.