Skip to content

Commit

Permalink
change behavior for "init-data" singleLicensePer
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent-Bouisset committed Jun 17, 2024
1 parent 6bb784c commit 5a2a115
Showing 1 changed file with 36 additions and 48 deletions.
84 changes: 36 additions & 48 deletions src/main_thread/decrypt/content_decryptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ export function getMissingInitDataKeyIds(
* - `blacklisted`: Array of key ids for keys that are considered unusable.
* The qualities linked to those keys should not be played.
*/
function getKeyIdsLinkedToSession(
export function getKeyIdsLinkedToSession(
initializationData: IProcessedProtectionData,
keySessionRecord: KeySessionRecord,
singleLicensePer: undefined | "init-data" | "content" | "periods",
Expand All @@ -1025,53 +1025,41 @@ function getKeyIdsLinkedToSession(
const missingKnownKeyIds = getMissingKnownKeyIds(keySessionRecord, keyIdsInLicense);
const associatedKeyIds = keyIdsInLicense.concat(missingKnownKeyIds);

if (singleLicensePer !== undefined && singleLicensePer !== "init-data") {
// We want to add the current key ids in the blacklist if it is
// not already there.
//
// We only do that when `singleLicensePer` is set to something
// else than the default `"init-data"` because this logic:
// 1. might result in a quality fallback, which is a v3.x.x
// breaking change if some APIs (like `singleLicensePer`)
// aren't used.
// 2. Rely on the EME spec regarding key statuses being well
// implemented on all supported devices, which we're not
// sure yet. Because in any other `singleLicensePer`, we
// need a good implementation anyway, it doesn't matter
// there.
const missingInitDataKeyIds = getMissingInitDataKeyIds(
initializationData,
associatedKeyIds,
);
associatedKeyIds.push(...missingInitDataKeyIds);

const { content } = initializationData;
if (isCurrentLicense && content !== undefined) {
if (singleLicensePer === "content") {
// Put it in a Set to automatically filter out duplicates (by ref)
const contentKeys = new Set<Uint8Array>();
const { manifest } = content;
for (const period of manifest.periods) {
addKeyIdsFromPeriod(contentKeys, period);
}
mergeKeyIdSetIntoArray(contentKeys, associatedKeyIds);
} else if (singleLicensePer === "periods") {
const { manifest } = content;
for (const period of manifest.periods) {
const periodKeys = new Set<Uint8Array>();
addKeyIdsFromPeriod(periodKeys, period);
if (initializationData.content?.period.id === period.id) {
mergeKeyIdSetIntoArray(periodKeys, associatedKeyIds);
} else {
const periodKeysArr = Array.from(periodKeys);
for (const kid of periodKeysArr) {
const isFound = associatedKeyIds.some((k) =>
areArraysOfNumbersEqual(k, kid),
);
if (isFound) {
mergeKeyIdSetIntoArray(periodKeys, associatedKeyIds);
break;
}
const missingInitDataKeyIds = getMissingInitDataKeyIds(
initializationData,
associatedKeyIds,
);

associatedKeyIds.push(...missingInitDataKeyIds);
console.log(

Check failure on line 1034 in src/main_thread/decrypt/content_decryptor.ts

View workflow job for this annotation

GitHub Actions / typechecking_and_linting (20.x)

Unexpected console statement
`DEBUG issue-1427: getKeyIdsLinkedToSession - ${missingInitDataKeyIds.length} missing keys in initData:`,
missingInitDataKeyIds.map((keyId) => bytesToHex(keyId)).join("-"),
);

const { content } = initializationData;
if (isCurrentLicense && content !== undefined) {
if (singleLicensePer === "content") {
// Put it in a Set to automatically filter out duplicates (by ref)
const contentKeys = new Set<Uint8Array>();
const { manifest } = content;
for (const period of manifest.periods) {
addKeyIdsFromPeriod(contentKeys, period);
}
mergeKeyIdSetIntoArray(contentKeys, associatedKeyIds);
} else if (singleLicensePer === "periods") {
const { manifest } = content;
for (const period of manifest.periods) {
const periodKeys = new Set<Uint8Array>();
addKeyIdsFromPeriod(periodKeys, period);
if (initializationData.content?.period.id === period.id) {
mergeKeyIdSetIntoArray(periodKeys, associatedKeyIds);
} else {
const periodKeysArr = Array.from(periodKeys);
for (const kid of periodKeysArr) {
const isFound = associatedKeyIds.some((k) => areArraysOfNumbersEqual(k, kid));
if (isFound) {
mergeKeyIdSetIntoArray(periodKeys, associatedKeyIds);
break;
}
}
}
Expand Down

0 comments on commit 5a2a115

Please sign in to comment.