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

fix(HLS): Fix support for mixed AES-128/NONE decryption #4847

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions lib/hls/hls_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2639,9 +2639,12 @@ shaka.hls.HlsParser = class {

// Apply new AES-128 tags as you see them, keeping a running total.
for (const drmTag of item.tags) {
if (drmTag.name == 'EXT-X-KEY' &&
drmTag.getRequiredAttrValue('METHOD') == 'AES-128') {
hlsAes128Key = this.parseAES128DrmTag_(drmTag, playlist);
if (drmTag.name == 'EXT-X-KEY') {
if (drmTag.getRequiredAttrValue('METHOD') == 'AES-128') {
hlsAes128Key = this.parseAES128DrmTag_(drmTag, playlist);
} else {
hlsAes128Key = undefined;
}
}
}

Expand Down
30 changes: 30 additions & 0 deletions test/hls/hls_parser_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -2669,6 +2669,9 @@ describe('HlsParser', () => {
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
'#EXTINF:5,\n',
'#EXT-X-BYTERANGE:121090@616\n',
'main.mp4\n',
'#EXTINF:5,\n',
'#EXT-X-BYTERANGE:121090@616\n',
'main.mp4',
].join('');

Expand All @@ -2680,6 +2683,10 @@ describe('HlsParser', () => {
'#EXT-X-MAP:URI="init.mp4",BYTERANGE="616@0"\n',
'#EXTINF:5,\n',
'#EXT-X-BYTERANGE:121090@616\n',
'main.mp4\n',
'#EXTINF:5,\n',
'#EXT-X-BYTERANGE:121090@616\n',
'#EXT-X-KEY:METHOD=NONE\n',
'main.mp4',
].join('');

Expand All @@ -2689,6 +2696,9 @@ describe('HlsParser', () => {
'#EXT-X-KEY:METHOD=AES-128,',
'URI="800k.key"\n',
'#EXTINF:5,\n',
'main.ts\n',
'#EXTINF:5,\n',
'#EXT-X-KEY:METHOD=NONE\n',
'main.ts',
].join('');

Expand Down Expand Up @@ -2742,6 +2752,26 @@ describe('HlsParser', () => {
const actual = await parser.start('test:/master', playerInterface);
await loadAllStreamsFor(actual);
expect(actual).toEqual(manifest);

const mp4AesEncryptionVideo = actual.variants[1].video;
await mp4AesEncryptionVideo.createSegmentIndex();
goog.asserts.assert(mp4AesEncryptionVideo.segmentIndex != null,
'Null segmentIndex!');

const firstMp4Segment = mp4AesEncryptionVideo.segmentIndex.get(0);
expect(firstMp4Segment.hlsAes128Key).toBeDefined();
const secondMp4Segment = mp4AesEncryptionVideo.segmentIndex.get(1);
expect(secondMp4Segment.hlsAes128Key).toBeNull();

const tsAesEncryptionVideo = actual.variants[2].video;
await tsAesEncryptionVideo.createSegmentIndex();
goog.asserts.assert(tsAesEncryptionVideo.segmentIndex != null,
'Null segmentIndex!');

const firstTsSegment = tsAesEncryptionVideo.segmentIndex.get(0);
expect(firstTsSegment.hlsAes128Key).toBeDefined();
const secondTsSegment = tsAesEncryptionVideo.segmentIndex.get(1);
expect(secondTsSegment.hlsAes128Key).toBeNull();
});

it('fails on AES-128 if WebCrypto APIs are not available', async () => {
Expand Down