Skip to content

Commit

Permalink
Fix pssh parsing (#3262)
Browse files Browse the repository at this point in the history
* Update version number to 3.1.2

* Remove newlines and whitespaces from pssh string

* Add unit tests for CommonEncryption class
  • Loading branch information
dsilhavy committed May 23, 2020
1 parent 945cd57 commit 5f0d9b5
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
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);
});

});

});

0 comments on commit 5f0d9b5

Please sign in to comment.