Skip to content

Commit

Permalink
Merge pull request #1599 from CastagnaIT/ignore_ssl
Browse files Browse the repository at this point in the history
[CurlUtils] Implemented way to skip SSL verify peer and moved "internal_cookies" prop
  • Loading branch information
CastagnaIT authored Jul 9, 2024
2 parents 70b0bba + c641562 commit f558724
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 9 deletions.
2 changes: 1 addition & 1 deletion inputstream.adaptive/addon.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
name="adaptive"
extension=""
tags="true"
listitemprops="license_type|license_key|license_url|license_url_append|license_data|license_flags|manifest_type|server_certificate|manifest_update_parameter|manifest_upd_params|manifest_params|manifest_headers|stream_params|stream_headers|original_audio_language|play_timeshift_buffer|pre_init_data|stream_selection_type|chooser_bandwidth_max|chooser_resolution_max|chooser_resolution_secure_max|live_delay|internal_cookies|manifest_config"
listitemprops="license_type|license_key|license_url|license_url_append|license_data|license_flags|manifest_type|server_certificate|manifest_update_parameter|manifest_upd_params|manifest_params|manifest_headers|stream_params|stream_headers|original_audio_language|play_timeshift_buffer|pre_init_data|stream_selection_type|chooser_bandwidth_max|chooser_resolution_max|chooser_resolution_secure_max|live_delay|internal_cookies|config|manifest_config"
library_@PLATFORM@="@LIBRARY_FILENAME@"/>
<extension point="xbmc.addon.metadata">
<platform>@PLATFORM@</platform>
Expand Down
50 changes: 48 additions & 2 deletions src/CompKodiProps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ constexpr std::string_view PROP_PLAY_TIMESHIFT_BUFFER = "inputstream.adaptive.pl
constexpr std::string_view PROP_LIVE_DELAY = "inputstream.adaptive.live_delay";
constexpr std::string_view PROP_PRE_INIT_DATA = "inputstream.adaptive.pre_init_data";

constexpr std::string_view PROP_INTERNAL_COOKIES = "inputstream.adaptive.internal_cookies";
constexpr std::string_view PROP_CONFIG = "inputstream.adaptive.config";
constexpr std::string_view PROP_INTERNAL_COOKIES = "inputstream.adaptive.internal_cookies"; //! @todo: to remove on Kodi 22

// Chooser's properties
constexpr std::string_view PROP_STREAM_SELECTION_TYPE = "inputstream.adaptive.stream_selection_type";
Expand Down Expand Up @@ -207,9 +208,17 @@ ADP::KODI_PROPS::CCompKodiProps::CCompKodiProps(const std::map<std::string, std:
else
LOG::Log(LOGERROR, "Resolution not valid on \"%s\" property.", prop.first.c_str());
}
else if (prop.first == PROP_CONFIG)
{
ParseConfig(prop.second);
}
else if (prop.first == PROP_INTERNAL_COOKIES)
{
m_isInternalCookies = STRING::CompareNoCase(prop.second, "true");
LOG::Log(LOGERROR,
"Warning \"inputstream.adaptive.internal_cookies\" property has been moved to the new "
"\"inputstream.adaptive.config\". The old property will be removed from next Kodi 22.\n"
"See Wiki integration page for more details.");
m_config.internalCookies = STRING::CompareNoCase(prop.second, "true");
}
else if (prop.first == PROP_MANIFEST_CONFIG)
{
Expand All @@ -236,6 +245,43 @@ ADP::KODI_PROPS::CCompKodiProps::CCompKodiProps(const std::map<std::string, std:
}
}

void ADP::KODI_PROPS::CCompKodiProps::ParseConfig(const std::string& data)
{
/*
* Expected JSON structure:
* { "config_name": "value", ... }
*/
rapidjson::Document jDoc;
jDoc.Parse(data.c_str(), data.size());

if (!jDoc.IsObject())
{
LOG::LogF(LOGERROR, "Malformed JSON data in to \"%s\" property", PROP_MANIFEST_CONFIG.data());
return;
}

// Iterate dictionary
for (auto& jChildObj : jDoc.GetObject())
{
const std::string configName = jChildObj.name.GetString();
rapidjson::Value& jDictVal = jChildObj.value;

if (configName == "ssl_verify_peer" && jDictVal.IsBool())
{
m_config.curlSSLVerifyPeer = jDictVal.GetBool();
}
else if (configName == "internal_cookies" && jDictVal.IsBool())
{
m_config.internalCookies = jDictVal.GetBool();
}
else
{
LOG::LogF(LOGERROR, "Unsupported \"%s\" config or wrong data type on \"%s\" property",
configName.c_str(), PROP_MANIFEST_CONFIG.data());
}
}
}

void ADP::KODI_PROPS::CCompKodiProps::ParseManifestConfig(const std::string& data)
{
/*
Expand Down
19 changes: 15 additions & 4 deletions src/CompKodiProps.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ struct ChooserProps
std::pair<int, int> m_resolutionSecureMax; // Res. limit for DRM protected videos (values 0 means auto)
};

// Generic add-on configuration
struct Config
{
// Determines whether curl verifies the authenticity of the peer's certificate,
// if set to false CA certificates are not loaded and verification will be skipped.
bool curlSSLVerifyPeer{true};
// Determines if cookies are internally handled by InputStream Adaptive add-on
bool internalCookies{false};
};

struct ManifestConfig
{
// Limit the timeshift buffer depth, in seconds
Expand Down Expand Up @@ -102,16 +112,17 @@ class ATTR_DLL_LOCAL CCompKodiProps
*/
std::string_view GetDrmPreInitData() const { return m_drmPreInitData; }

// \brief Defines if cookies are internally handled by InputStream Adaptive add-on
bool IsInternalCookies() const { return m_isInternalCookies; }

// \brief Specifies the chooser properties that will override XML settings
const ChooserProps& GetChooserProps() const { return m_chooserProps; }

// \brief Specifies generic add-on configuration
const Config& GetConfig() const { return m_config; }

// \brief Specifies the manifest configuration
const ManifestConfig& GetManifestConfig() const { return m_manifestConfig; }

private:
void ParseConfig(const std::string& data);
void ParseManifestConfig(const std::string& data);

std::string m_licenseType;
Expand All @@ -131,8 +142,8 @@ class ATTR_DLL_LOCAL CCompKodiProps
bool m_playTimeshiftBuffer{false};
uint64_t m_liveDelay{0};
std::string m_drmPreInitData;
bool m_isInternalCookies{false};
ChooserProps m_chooserProps;
Config m_config;
ManifestConfig m_manifestConfig;
};

Expand Down
8 changes: 6 additions & 2 deletions src/utils/CurlUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,22 +184,26 @@ UTILS::CURL::CUrl::CUrl(std::string_view url)
{
if (m_file.CURLCreate(url.data()))
{
auto& kodiProps = CSrvBroker::GetKodiProps();

// Default curl options
m_file.CURLAddOption(ADDON_CURL_OPTION_PROTOCOL, "seekable", "0");
m_file.CURLAddOption(ADDON_CURL_OPTION_PROTOCOL, "acceptencoding", "gzip, deflate");
m_file.CURLAddOption(ADDON_CURL_OPTION_PROTOCOL, "failonerror", "false");
if (!kodiProps.GetConfig().curlSSLVerifyPeer)
m_file.CURLAddOption(ADDON_CURL_OPTION_PROTOCOL, "verifypeer", "false");

// Add session cookies
// NOTE: if kodi property inputstream.adaptive.stream_headers is set with "cookie" header
// the cookies set by the property will replace these
if (CSrvBroker::GetKodiProps().IsInternalCookies())
if (kodiProps.GetConfig().internalCookies)
m_file.CURLAddOption(ADDON_CURL_OPTION_PROTOCOL, "cookie", GetCookies(url));
}
}

UTILS::CURL::CUrl::~CUrl()
{
if (CSrvBroker::GetKodiProps().IsInternalCookies())
if (CSrvBroker::GetKodiProps().GetConfig().internalCookies)
StoreCookies(GetEffectiveUrl(), GetResponseHeaders("set-cookie"));

m_file.Close();
Expand Down

0 comments on commit f558724

Please sign in to comment.