Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Decrypters] Introduction of protection_scheme to Widevine PSSH #1652

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/decrypters/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ namespace
constexpr uint8_t PSSHBOX_HEADER_PSSH[4] = {0x70, 0x73, 0x73, 0x68};
constexpr uint8_t PSSHBOX_HEADER_VER0[4] = {0x00, 0x00, 0x00, 0x00};

// Protection scheme identifying the encryption algorithm. The protection
// scheme is represented as a uint32 value. The uint32 contains 4 bytes each
// representing a single ascii character in one of the 4CC protection scheme values.
enum class WIDEVINE_PROT_SCHEME {
CENC = 0x63656E63,
CBC1 = 0x63626331,
CENS = 0x63656E73,
CBCS = 0x63626373
};

/*!
* \brief Make a protobuf tag.
* \param fieldNumber The field number
Expand All @@ -38,8 +48,8 @@ int MakeProtobufTag(int fieldNumber, int wireType)
return (fieldNumber << 3) | wireType;
}

// \brief Write the size value to the data as varint format
void WriteProtobufVarintSize(std::vector<uint8_t>& data, int size)
// \brief Write a protobuf varint value to the data
void WriteProtobufVarint(std::vector<uint8_t>& data, int size)
{
do
{
Expand Down Expand Up @@ -220,7 +230,7 @@ bool DRM::MakeWidevinePsshData(const std::vector<uint8_t>& kid,

// Create "key_id" field, id: 2 (can be repeated if multiples)
wvPsshData.push_back(MakeProtobufTag(2, 2));
WriteProtobufVarintSize(wvPsshData, static_cast<int>(kid.size()));
WriteProtobufVarint(wvPsshData, static_cast<int>(kid.size())); // Write data size
wvPsshData.insert(wvPsshData.end(), kid.begin(), kid.end());

// Prepare "content_id" data
Expand All @@ -241,9 +251,13 @@ bool DRM::MakeWidevinePsshData(const std::vector<uint8_t>& kid,

// Create "content_id" field, id: 4
wvPsshData.push_back(MakeProtobufTag(4, 2));
WriteProtobufVarintSize(wvPsshData, static_cast<int>(contentIdData.size()));
WriteProtobufVarint(wvPsshData, static_cast<int>(contentIdData.size())); // Write data size
wvPsshData.insert(wvPsshData.end(), contentIdData.begin(), contentIdData.end());

// Create "protection_scheme" field, id: 9
// wvPsshData.push_back(MakeProtobufTag(9, 0));
// WriteProtobufVarint(wvPsshData, static_cast<int>(WIDEVINE_PROT_SCHEME::CENC));

return true;
}

Expand Down