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 pssh parsing #3262

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "dashjs",
"version": "3.1.1",
"version": "3.1.2",
"description": "A reference client implementation for the playback of MPEG DASH via Javascript and compliant browsers.",
"main": "build/es5/index.js",
"types": "build/typings/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/core/Version.js
@@ -1,4 +1,4 @@
const VERSION = '3.1.1';
const VERSION = '3.1.2';
export function getVersionString() {
return VERSION;
}
4 changes: 4 additions & 0 deletions src/streaming/protection/CommonEncryption.js
Expand Up @@ -104,6 +104,10 @@ class CommonEncryption {
*/
static parseInitDataFromContentProtection(cpData, BASE64) {
if ('pssh' in cpData) {

// Remove whitespaces and newlines from pssh text
cpData.pssh.__text = cpData.pssh.__text.replace(/\r?\n|\r/g,'').replace(/\s+/g,'');

return BASE64.decodeArray(cpData.pssh.__text).buffer;
}
return null;
Expand Down
68 changes: 68 additions & 0 deletions test/unit/streaming.protection.CommonEncryption.js
@@ -0,0 +1,68 @@
import CommonEncryption from '../../src/streaming/protection/CommonEncryption';
import Base64 from '../../externals/base64';

const expect = require('chai').expect;
let cpData;

describe('CommonEncryption', () => {

beforeEach(() => {
cpData = {
'pssh': {
'__text': 'AAAANHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABQIARABGgZlbHV2aW8iBmVsdXZpbw=='
},
'value': 'Widevine',
'schemeIdUri': 'urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed',
'KID': null
};
});

describe('parseInitDataFromContentProtection', () => {

it('should return null if no init data is available in the ContentProtection element', () => {
cpData = {};
const result = CommonEncryption.parseInitDataFromContentProtection(cpData,Base64);

expect(result).to.be.null; // jshint ignore:line
});

it('should return base64 decoded string if init data is available in the ContentProtection element', () => {
const result = CommonEncryption.parseInitDataFromContentProtection(cpData,Base64);
const expectedByteLength = Base64.decodeArray(cpData.pssh.__text).buffer.byteLength;

expect(result.byteLength).to.equal(expectedByteLength);
});

it('should remove newlines and return base64 decoded string if init data is available in the ContentProtection element', () => {
const expectedByteLength = Base64.decodeArray(cpData.pssh.__text).buffer.byteLength;
cpData.pssh.__text = '\nAAAANHBzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAABQIARABGgZlbHV2aW8iBmVsdXZpbw==\n';
const originalByteLength = Base64.decodeArray(cpData.pssh.__text).buffer.byteLength;
const result = CommonEncryption.parseInitDataFromContentProtection(cpData,Base64);

expect(originalByteLength).to.not.equal(result.byteLength);
expect(result.byteLength).to.equal(expectedByteLength);
});

it('should remove whitespaces and return base64 decoded string if init data is available in the ContentProtection element', () => {
const expectedByteLength = Base64.decodeArray(cpData.pssh.__text).buffer.byteLength;
cpData.pssh.__text = 'AAAANHBzc2gAAAAA7e+LqXnWSs6jy Cfc1R0h7QAAABQIARABGgZlbHV2aW8iBmVsdXZpbw==';
const originalByteLength = Base64.decodeArray(cpData.pssh.__text).buffer.byteLength;
const result = CommonEncryption.parseInitDataFromContentProtection(cpData,Base64);

expect(originalByteLength).to.not.equal(result.byteLength);
expect(result.byteLength).to.equal(expectedByteLength);
});

it('should remove whitespaces and newlines and return base64 decoded string if init data is available in the ContentProtection element', () => {
const expectedByteLength = Base64.decodeArray(cpData.pssh.__text).buffer.byteLength;
cpData.pssh.__text = '\n\n\nAAAANHBzc2gAAAAA7e+LqXnWSs6jy Cfc1R0h7QAAABQIARABGgZlbHV2aW8iBmVsdXZpbw==\n\n';
const originalByteLength = Base64.decodeArray(cpData.pssh.__text).buffer.byteLength;
const result = CommonEncryption.parseInitDataFromContentProtection(cpData,Base64);

expect(originalByteLength).to.not.equal(result.byteLength);
expect(result.byteLength).to.equal(expectedByteLength);
});

});

});