-
Notifications
You must be signed in to change notification settings - Fork 137
fix(compat): on Edge test comprehensively KeySystems before considering them as usable #1434
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5a13989
WIP
Florent-Bouisset bd31bc0
create an utils to generate playready init data
Florent-Bouisset e78c575
use generate init Data instead of having a raw uint8Array
Florent-Bouisset 791ec0e
PR feedback
Florent-Bouisset c2a6327
update file path
Florent-Bouisset e86a289
PR review
Florent-Bouisset File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /** | ||
| * Copyright 2015 CANAL+ Group | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import { isEdgeChromium } from "./browser_detection"; | ||
|
|
||
| /** | ||
| * This functions tells if the RxPlayer can trust the browser when it has | ||
| * successfully granted the MediaKeySystemAccess with | ||
| * `navigator.requestMediaKeySystemAccess(keySystem)` function, or if it should do | ||
| * some additional testing to confirm that the `keySystem` is supported on the device. | ||
| * | ||
| * This behavior has been experienced on the following device: | ||
| * | ||
| * On a Microsoft Surface with Edge v.124: | ||
| * - Althought `requestMediaKeySystemAccess` resolve correctly with the keySystem | ||
| * "com.microsoft.playready.recommendation.3000", generating a request with | ||
| * `generateRequest` throws an error: "NotSupportedError: Failed to execute | ||
| * 'generateRequest' on 'MediaKeySession': Failed to create MF PR CdmSession". | ||
| * In this particular case, the work-around was to consider recommendation.3000 as not supported | ||
| * and try another keySystem. | ||
| * @param keySystem - The key system in use. | ||
| * @returns {boolean} | ||
| */ | ||
| export function canRelyOnRequestMediaKeySystemAccess(keySystem: string): boolean { | ||
| if (isEdgeChromium && keySystem.indexOf("playready") !== -1) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } |
74 changes: 74 additions & 0 deletions
74
src/main_thread/decrypt/__tests__/__global__/find_key_system.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /** | ||
| * Copyright 2015 CANAL+ Group | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| import * as compat from "../../../../compat/can_rely_on_request_media_key_system_access"; | ||
| import eme from "../../../../compat/eme"; | ||
| import { testOneKeySystem } from "../../find_key_system"; | ||
|
|
||
| describe("find_key_systems - ", () => { | ||
| let requestMediaKeySystemAccessMock: jest.SpyInstance; | ||
| let canRelyOnEMEMock: jest.SpyInstance; | ||
| const keySystem = "com.microsoft.playready.recommendation"; | ||
|
|
||
| beforeEach(() => { | ||
| jest.resetModules(); | ||
| jest.restoreAllMocks(); | ||
| requestMediaKeySystemAccessMock = jest.spyOn(eme, "requestMediaKeySystemAccess"); | ||
| canRelyOnEMEMock = jest.spyOn(compat, "canRelyOnRequestMediaKeySystemAccess"); | ||
| }); | ||
|
|
||
| it("should resolve if the keySystem is supported", async () => { | ||
| /* mock implementation of requestMediaKeySystemAccess that support the keySystem */ | ||
| requestMediaKeySystemAccessMock.mockImplementation(() => ({ | ||
| createMediaKeys: () => ({ | ||
| createSession: () => ({ | ||
| // eslint-disable-next-line @typescript-eslint/no-empty-function | ||
| generateRequest: () => {}, | ||
| }), | ||
| }), | ||
| })); | ||
| await expect(testOneKeySystem(keySystem, [])).resolves.toBeTruthy(); | ||
| expect(requestMediaKeySystemAccessMock).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("should reject if the keySystem is not supported", async () => { | ||
| /* mock implementation of requestMediaKeySystemAccess that does not support the keySystem */ | ||
| requestMediaKeySystemAccessMock.mockImplementation(() => { | ||
| throw new Error(); | ||
| }); | ||
| await expect(testOneKeySystem(keySystem, [])).rejects.toThrow(); | ||
| expect(requestMediaKeySystemAccessMock).toHaveBeenCalledTimes(1); | ||
| }); | ||
|
|
||
| it("should reject if the keySystem seems to be supported but the EME workflow fail", async () => { | ||
| /* mock implementation of requestMediaKeySystemAccess that seems to support the keySystem | ||
| but that is failing when performing the usual EME workflow of creating mediaKeys, creating a session | ||
| and generating a request. */ | ||
|
|
||
| canRelyOnEMEMock.mockImplementation(() => false); | ||
| requestMediaKeySystemAccessMock.mockImplementation(() => ({ | ||
| createMediaKeys: () => ({ | ||
| createSession: () => ({ | ||
| generateRequest: () => { | ||
| throw new Error("generateRequest failed"); | ||
| }, | ||
| }), | ||
| }), | ||
| })); | ||
| await expect(testOneKeySystem(keySystem, [])).rejects.toThrow(); | ||
| expect(requestMediaKeySystemAccessMock).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { generatePlayReadyInitData } from "../generate_init_data"; | ||
| import { utf16LEToStr } from "../string_parsing"; | ||
|
|
||
| describe("utils - generatePlayReadyInitData", () => { | ||
| const playReadyHeader = | ||
| '<WRMHEADER xmlns="http://schemas.microsoft.com/DRM/2007/03/PlayReadyHeader" version="4.0.0.0"><DATA><PROTECTINFO><KEYLEN>16</KEYLEN><ALGID>AESCTR</ALGID></PROTECTINFO><KID>ckB07BNLskeUq0qd83fTbA==</KID><LA_URL>http://drm.canal-plus.com/</LA_URL><LUI_URL>http://drm.canal-plus.com/</LUI_URL><DS_ID>yYIPDBca1kmMfL60IsfgAQ==</DS_ID><CUSTOMATTRIBUTES xmlns=""><encryptionref>312_4024_2018127108</encryptionref></CUSTOMATTRIBUTES><CHECKSUM>U/tsUYRgMzw=</CHECKSUM></DATA></WRMHEADER>'; | ||
|
|
||
| const initData = generatePlayReadyInitData(playReadyHeader); | ||
| const decodedInitDataUtf16LE = utf16LEToStr(initData); | ||
|
|
||
| it("has correct length", () => { | ||
| // the expected length for an initData with that PlayReady header. | ||
| expect(initData.length).toBe(996); | ||
| }); | ||
|
|
||
| it("has the playerReadyHeader in it", () => { | ||
| expect(decodedInitDataUtf16LE).toMatch(playReadyHeader); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { itole4, itobe4, itole2, concat } from "./byte_parsing"; | ||
| import { strToUtf8, strToUtf16LE, hexToBytes } from "./string_parsing"; | ||
|
|
||
| /** | ||
| * Generate the "cenc" init data for playready from the PlayreadyHeader string. | ||
| * @param {string} playreadyHeader - String representing the PlayreadyHeader XML. | ||
| * @returns {Uint8Array} The init data generated for that PlayreadyHeader. | ||
| * @see https://learn.microsoft.com/en-us/playready/specifications/playready-header-specification | ||
| */ | ||
| export function generatePlayReadyInitData(playreadyHeader: string): Uint8Array { | ||
|
peaBerberian marked this conversation as resolved.
|
||
| const recordValueEncoded = strToUtf16LE(playreadyHeader); | ||
| const recordLength = itole2(recordValueEncoded.length); | ||
| // RecordType: 0x0001 Indicates that the record contains a PlayReady Header (PRH). | ||
| const recordType = new Uint8Array([1, 0]); | ||
| const numberOfObjects = new Uint8Array([1, 0]); // 1 PlayReady object | ||
|
|
||
| /* playReadyObjectLength equals = X bytes for record + 2 bytes for record length, | ||
| + 2 bytes for record types + 2 bytes for number of object */ | ||
| const playReadyObjectLength = itole4(recordValueEncoded.length + 6); | ||
| const playReadyObject = concat( | ||
| playReadyObjectLength, // 4 bytes for the Playready object length | ||
| numberOfObjects, // 2 bytes for the number of PlayReady objects | ||
| recordType, // 2 bytes for record type | ||
| recordLength, // 2 bytes for record length | ||
| recordValueEncoded, // X bytes for record value | ||
| ); | ||
|
|
||
| /** the systemId is define at https://dashif.org/identifiers/content_protection/ */ | ||
| const playreadySystemId = hexToBytes("9a04f07998404286ab92e65be0885f95"); | ||
|
|
||
| return generateInitData(playReadyObject, playreadySystemId); | ||
| } | ||
|
|
||
| /** | ||
| * Generate the "cenc" initData given the data and the systemId to use. | ||
| * Note this will generate an initData for version 0 of pssh. | ||
| * @param data - The data that is contained inside the pssh. | ||
| * @param systemId - The systemId to use. | ||
| * @returns | ||
| */ | ||
| function generateInitData(data: Uint8Array, systemId: Uint8Array): Uint8Array { | ||
| const psshBoxName = strToUtf8("pssh"); | ||
| const versionAndFlags = new Uint8Array([0, 0, 0, 0]); // pssh version 0 | ||
| const sizeOfData = itobe4(data.length); | ||
| const psshSize = itobe4( | ||
| 4 /* pssh size */ + | ||
| 4 /* pssh box */ + | ||
| 4 /* version and flags */ + | ||
| 16 /* systemId */ + | ||
| 4 /* size of data */ + | ||
| data.length /* data */, | ||
| ); | ||
| return concat( | ||
| psshSize, // 4 bytes for the pssh size | ||
| psshBoxName, // 4 bytes for the pssh box | ||
| versionAndFlags, // 4 bytes for version and flags | ||
| systemId, // 16 bytes for the systemId | ||
| sizeOfData, // 4 bytes for the data size | ||
| data, // X bytes for data | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.