From 93286f4aea84ef3b0684dda981ad66732fba3f65 Mon Sep 17 00:00:00 2001
From: Andrew Osmond <aosmond@gmail.com>
Date: Sat, 23 Nov 2019 14:27:16 -0500
Subject: [PATCH] sip: add preference to disable secure dialog checks for
 SIP/TLS

Some VoIP services, such as VoIP.ms, support SIP/TLS and SRTP, but
give the wrong schema in the INVITE's Contact header; specifically
"sip" instead of "sips." The relevant ticket for pjsip is as
follows:

https://trac.pjsip.org/repos/ticket/1735

This patch adds a preference to allow a user to disable the checks,
which allows them to answer incoming calls in this situation. By
default, the checks are enabled, and it will silently drop calls
which are not RFC-compliant.

Reviewed-by: mingrui.zhang@savoirfairelinux.com
Change-Id: I401ef481ef29f7ae7bbc56025d2e8b461e850791
---
 src/manager.cpp     | 7 +++++++
 src/preferences.cpp | 6 +++++-
 src/preferences.h   | 8 ++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/manager.cpp b/src/manager.cpp
index 04f4952856..a99ee20015 100644
--- a/src/manager.cpp
+++ b/src/manager.cpp
@@ -762,6 +762,13 @@ Manager::init(const std::string &config_file)
         no_errors = false;
     }
 
+    // Some VoIP services support SIP/TLS and SRTP, but do not set the
+    // correct schema in the INVITE request. For more details, see:
+    // https://trac.pjsip.org/repos/ticket/1735
+    if (voipPreferences.getDisableSecureDlgCheck()) {
+        pjsip_cfg()->endpt.disable_secure_dlg_check = PJ_TRUE;
+    }
+
     // always back up last error-free configuration
     if (no_errors) {
         make_backup(pimpl_->path_);
diff --git a/src/preferences.cpp b/src/preferences.cpp
index 86367c22dd..686e3c0ff0 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -92,6 +92,7 @@ static constexpr const char* MD5_HASH_KEY {"md5Hash"};
 
 // voip preferences
 constexpr const char * const VoipPreference::CONFIG_LABEL;
+static constexpr const char* DISABLE_SECURE_DLG_CHECK_KEY {"disableSecureDlgCheck"};
 static constexpr const char* PLAY_DTMF_KEY {"playDtmf"};
 static constexpr const char* PLAY_TONES_KEY {"playTones"};
 static constexpr const char* PULSE_LENGTH_KEY {"pulseLength"};
@@ -240,7 +241,8 @@ void Preferences::unserialize(const YAML::Node &in)
 }
 
 VoipPreference::VoipPreference() :
-    playDtmf_(true)
+    disableSecureDlgCheck_(false)
+    , playDtmf_(true)
     , playTones_(true)
     , pulseLength_(PULSE_LENGTH_DEFAULT)
     , symmetricRtp_(true)
@@ -249,6 +251,7 @@ VoipPreference::VoipPreference() :
 void VoipPreference::serialize(YAML::Emitter &out) const
 {
     out << YAML::Key << CONFIG_LABEL << YAML::Value << YAML::BeginMap;
+    out << YAML::Key << DISABLE_SECURE_DLG_CHECK_KEY << YAML::Value << disableSecureDlgCheck_;
     out << YAML::Key << PLAY_DTMF_KEY << YAML::Value << playDtmf_;
     out << YAML::Key << PLAY_TONES_KEY << YAML::Value << playTones_;
     out << YAML::Key << PULSE_LENGTH_KEY << YAML::Value << pulseLength_;
@@ -260,6 +263,7 @@ void VoipPreference::serialize(YAML::Emitter &out) const
 void VoipPreference::unserialize(const YAML::Node &in)
 {
     const auto &node = in[CONFIG_LABEL];
+    parseValue(node, DISABLE_SECURE_DLG_CHECK_KEY, disableSecureDlgCheck_);
     parseValue(node, PLAY_DTMF_KEY, playDtmf_);
     parseValue(node, PLAY_TONES_KEY, playTones_);
     parseValue(node, PULSE_LENGTH_KEY, pulseLength_);
diff --git a/src/preferences.h b/src/preferences.h
index f78c81c4f7..90511764e9 100644
--- a/src/preferences.h
+++ b/src/preferences.h
@@ -146,6 +146,13 @@ class VoipPreference : public Serializable {
         void serialize(YAML::Emitter &out) const override;
         void unserialize(const YAML::Node &in) override;
 
+        bool getDisableSecureDlgCheck() const {
+            return disableSecureDlgCheck_;
+        }
+        void setDisableSecureDlgCheck(bool disable) {
+            disableSecureDlgCheck_ = disable;
+        }
+
         bool getPlayDtmf() const {
             return playDtmf_;
         }
@@ -185,6 +192,7 @@ class VoipPreference : public Serializable {
         }
 
     private:
+        bool disableSecureDlgCheck_;
         bool playDtmf_;
         bool playTones_;
         int pulseLength_;
-- 
GitLab