Skip to content

Commit

Permalink
Merge pull request #1698 from CastagnaIT/wv_fixes
Browse files Browse the repository at this point in the history
[widevine] Fix to wrapped license, and saved debug files
  • Loading branch information
CastagnaIT authored Oct 15, 2024
2 parents 952fb05 + 3d33f35 commit 0b8bdbb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 26 deletions.
17 changes: 10 additions & 7 deletions src/decrypters/widevine/WVCencSingleSampleDecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ CWVCencSingleSampleDecrypter::CWVCencSingleSampleDecrypter(
{
std::string debugFilePath = FILESYS::PathCombine(m_cdmAdapter->GetLibraryPath(),
"EDEF8BA9-79D6-4ACE-A3C8-27DCD51D21ED.init");

std::string data{reinterpret_cast<const char*>(m_pssh.data()), m_pssh.size()};
UTILS::FILESYS::SaveFile(debugFilePath, data, true);
UTILS::FILESYS::SaveFile(debugFilePath, {m_pssh.cbegin(), m_pssh.cend()}, true);
}

m_cdmAdapter->GetCDM()->CreateSessionAndGenerateRequest(
Expand Down Expand Up @@ -328,7 +326,7 @@ bool CWVCencSingleSampleDecrypter::SendSessionMessage()
int hdcpLimit{0};

// Unwrap license response
if (!isCertRequest && m_cdmAdapter->GetKeySystem() == DRM::KS_WIDEVINE)
if (!licConfig.unwrapper.empty() && m_cdmAdapter->GetKeySystem() == DRM::KS_WIDEVINE)
{
std::string unwrappedData;
// Some services have a customized license server that require data to be wrapped with their formats (e.g. JSON).
Expand All @@ -342,10 +340,15 @@ bool CWVCencSingleSampleDecrypter::SendSessionMessage()
respData = unwrappedData;
}

if (!isCertRequest && CSrvBroker::GetSettings().IsDebugLicense())
if (CSrvBroker::GetSettings().IsDebugLicense())
{
std::string debugFilePath = FILESYS::PathCombine(
m_cdmAdapter->GetLibraryPath(), "EDEF8BA9-79D6-4ACE-A3C8-27DCD51D21ED.response");
std::string debugFilePath = FILESYS::PathCombine(m_cdmAdapter->GetLibraryPath(),
"EDEF8BA9-79D6-4ACE-A3C8-27DCD51D21ED");
if (isCertRequest)
debugFilePath += ".cert.response";
else
debugFilePath += ".response";

FILESYS::SaveFile(debugFilePath, respData, true);
}

Expand Down
41 changes: 22 additions & 19 deletions src/decrypters/widevineandroid/WVCencSingleSampleDecrypter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ CWVCencSingleSampleDecrypterA::CWVCencSingleSampleDecrypterA(
std::string fileName =
STRING::ToUpper(DRM::KeySystemToUUIDstr(m_cdmAdapter->GetKeySystem())) + ".init";
std::string debugFilePath = FILESYS::PathCombine(m_cdmAdapter->GetLibraryPath(), fileName);
std::string data{reinterpret_cast<const char*>(m_pssh.data()), m_pssh.size()};
FILESYS::SaveFile(debugFilePath, data, true);
FILESYS::SaveFile(debugFilePath, {m_pssh.cbegin(), m_pssh.cend()}, true);
}

m_initialPssh = m_pssh;
Expand Down Expand Up @@ -342,7 +341,7 @@ bool CWVCencSingleSampleDecrypterA::SendSessionMessage(const std::vector<uint8_t
std::string fileName =
STRING::ToUpper(DRM::KeySystemToUUIDstr(m_cdmAdapter->GetKeySystem())) + ".challenge";
std::string debugFilePath = FILESYS::PathCombine(m_cdmAdapter->GetLibraryPath(), fileName);
UTILS::FILESYS::SaveFile(debugFilePath, reinterpret_cast<const char*>(challenge.data()), true);
UTILS::FILESYS::SaveFile(debugFilePath, {challenge.cbegin(), challenge.cend()}, true);
}

const DRM::Config drmCfg = m_cdmAdapter->GetConfig();
Expand Down Expand Up @@ -420,23 +419,23 @@ bool CWVCencSingleSampleDecrypterA::SendSessionMessage(const std::vector<uint8_t

int hdcpLimit{0};

if (!isCertRequest)
// Unwrap license response
if (!licConfig.unwrapper.empty() && m_cdmAdapter->GetKeySystem() == DRM::KS_WIDEVINE)
{
// Unwrap license response
if (m_cdmAdapter->GetKeySystem() == DRM::KS_WIDEVINE)
std::string unwrappedData;
// Some services have a customized license server that require data to be wrapped with their formats (e.g. JSON).
// Here we provide a built-in way to unwrap the license data received, this avoid force add-ons to integrate
// a HTTP server proxy to manage the license data request/response, and so use Kodi properties to set wrappers.
if (!DRM::WvUnwrapLicense(licConfig.unwrapper, licConfig.unwrapperParams, respContentType,
respData, unwrappedData, hdcpLimit))
{
std::string unwrappedData;
// Some services have a customized license server that require data to be wrapped with their formats (e.g. JSON).
// Here we provide a built-in way to unwrap the license data received, this avoid force add-ons to integrate
// a HTTP server proxy to manage the license data request/response, and so use Kodi properties to set wrappers.
if (!DRM::WvUnwrapLicense(licConfig.unwrapper, licConfig.unwrapperParams, respContentType,
respData, unwrappedData, hdcpLimit))
{
return false;
}
respData = unwrappedData;
return false;
}
respData = unwrappedData;
}

if (!isCertRequest)
{
if (m_cdmAdapter->GetKeySystem() == DRM::KS_PLAYREADY &&
respData.find("<LicenseNonce>") == std::string::npos)
{
Expand All @@ -453,10 +452,14 @@ bool CWVCencSingleSampleDecrypterA::SendSessionMessage(const std::vector<uint8_t
}
}

if (!isCertRequest && CSrvBroker::GetSettings().IsDebugLicense())
if (CSrvBroker::GetSettings().IsDebugLicense())
{
std::string fileName =
STRING::ToUpper(DRM::KeySystemToUUIDstr(m_cdmAdapter->GetKeySystem())) + ".response";
std::string fileName = STRING::ToUpper(DRM::KeySystemToUUIDstr(m_cdmAdapter->GetKeySystem()));
if (isCertRequest)
fileName += ".cert.response";
else
fileName += ".response";

std::string debugFilePath = FILESYS::PathCombine(m_cdmAdapter->GetLibraryPath(), fileName);
FILESYS::SaveFile(debugFilePath, respData, true);
}
Expand Down

0 comments on commit 0b8bdbb

Please sign in to comment.