pssh-tools
Advanced tools
Comparing version 0.0.2 to 0.0.3
24
index.js
@@ -1,23 +0,3 @@ | ||
const widevine = require('./lib/pssh/widevine') | ||
const playready = require('./lib/pssh/playready') | ||
const pssh = require('./lib/pssh') | ||
const system = { | ||
WIDEVINE: 'widevine', | ||
PLAYREADY: 'playready' | ||
} | ||
const tools = (systemId) => { | ||
switch (systemId.toLowerCase()) { | ||
case system.WIDEVINE: | ||
return widevine | ||
case system.PLAYREADY: | ||
return playready | ||
default: | ||
throw new Error('Unknown drm system') | ||
} | ||
} | ||
module.exports = { | ||
system, | ||
tools | ||
} | ||
module.exports = pssh |
const crypto = require('crypto') | ||
const utils = require('./utils') | ||
@@ -69,4 +70,4 @@ const DRM_AES_KEYSIZE_128 = 16 | ||
const constructProXML = (kids, licenseUrl, keySeed) => { | ||
let contentKeys = kids.map((k) => { | ||
const constructProXML = (keyIds, licenseUrl, keySeed) => { | ||
let contentKeys = keyIds.map((k) => { | ||
return generateContentKey(k, keySeed) | ||
@@ -91,3 +92,3 @@ }) | ||
xmlArray.push(`(kid:${contentKeys[i].kid})`) | ||
if (i < kids.length - 1) { | ||
if (i < keyIds.length - 1) { | ||
xmlArray.push(',') | ||
@@ -128,2 +129,18 @@ } | ||
const getPsshBox = ({ keyIds, licenseUrl, keySeed }) => { | ||
return new Promise((resolve, reject) => { | ||
// data | ||
getPsshData({ keyIds, licenseUrl, keySeed }).then((data) => { | ||
let psshHeader = utils.getPsshHeader({ | ||
systemId: utils.system.PLAYREADY.id, | ||
keyIds: keyIds, | ||
data: data | ||
}) | ||
return resolve(psshHeader) | ||
}).catch((err) => { | ||
return reject(err) | ||
}) | ||
}) | ||
} | ||
const generatePssh = ({ keyIds = [], licenseUrl = undefined, keySeed = undefined, dataOnly = false }) => { | ||
@@ -137,3 +154,7 @@ if (dataOnly) { | ||
} | ||
return null | ||
return getPsshBox({ | ||
keyIds: keyIds, | ||
licenseUrl: licenseUrl, | ||
keySeed: keySeed | ||
}) | ||
} | ||
@@ -140,0 +161,0 @@ |
const protobuf = require('protobufjs') | ||
const utils = require('./utils') | ||
@@ -29,3 +30,3 @@ const getPsshData = ({ contentId = null, trackType = '', keyIds = [], provider = '', protectionScheme = 'cenc' }) => { | ||
} | ||
if (protectionScheme !== '' && protectionScheme !== 'cenc') { | ||
if (protectionScheme !== '') { | ||
payload.protectionScheme = Buffer.from(protectionScheme).readInt32BE() | ||
@@ -47,3 +48,24 @@ } | ||
const generatePssh = ({ contentId, keyIds = [], provider = '', dataOnly = false }) => { | ||
const getPsshBox = ({ contentId, keyIds = [], provider = '', protectionScheme = 'cenc' }) => { | ||
return new Promise((resolve, reject) => { | ||
// data | ||
getPsshData({ | ||
contentId: contentId, | ||
keyIds: keyIds, | ||
provider: provider, | ||
protectionScheme: protectionScheme | ||
}).then((data) => { | ||
let psshHeader = utils.getPsshHeader({ | ||
systemId: utils.system.WIDEVINE.id, | ||
keyIds: keyIds, | ||
data: data | ||
}) | ||
return resolve(psshHeader) | ||
}).catch((err) => { | ||
return reject(err) | ||
}) | ||
}) | ||
} | ||
const generatePssh = ({ contentId, keyIds = [], provider = '', protectionScheme = 'cenc', dataOnly = false }) => { | ||
if (dataOnly) { | ||
@@ -53,6 +75,12 @@ return getPsshData({ | ||
keyIds: keyIds, | ||
provider: provider | ||
provider: provider, | ||
protectionScheme: protectionScheme | ||
}) | ||
} | ||
return null | ||
return getPsshBox({ | ||
contentId: contentId, | ||
keyIds: keyIds, | ||
provider: provider, | ||
protectionScheme: protectionScheme | ||
}) | ||
} | ||
@@ -59,0 +87,0 @@ |
{ | ||
"name": "pssh-tools", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Tools to generate PSSH Data and PSSH Box", | ||
@@ -8,3 +8,3 @@ "main": "index.js", | ||
"pretest": "standard --fix", | ||
"test": "ava" | ||
"test": "ava --verbose" | ||
}, | ||
@@ -11,0 +11,0 @@ "keywords": [ |
const test = require('ava') | ||
const pssh = require('../index') | ||
const utils = require('../lib/pssh/utils') | ||
const KID = '0123456789abcdef0123456789abcdef' | ||
const WV_PSSH_DATA = 'CAESEAEjRWeJq83vASNFZ4mrze8aDXdpZGV2aW5lX3Rlc3QiD2NlbmMtY29udGVudC1pZA==' | ||
const PR_PSSH_DATA = 'IAMAAAEAAQAWAzwAPwB4AG0AbAAgAHYAZQByAHMAaQBvAG4APQAiADEALgAwACIAIABlAG4AYwBvAGQAaQBuAGcAPQAiAFUAVABGAC0AOAAiAD8APgA8AFcAUgBNAEgARQBBAEQARQBSACAAeABtAGwAbgBzAD0AIgBoAHQAdABwADoALwAvAHMAYwBoAGUAbQBhAHMALgBtAGkAYwByAG8AcwBvAGYAdAAuAGMAbwBtAC8ARABSAE0ALwAyADAAMAA3AC8AMAAzAC8AUABsAGEAeQBSAGUAYQBkAHkASABlAGEAZABlAHIAIgAgAHYAZQByAHMAaQBvAG4APQAiADQALgAyAC4AMAAuADAAIgA+ADwARABBAFQAQQA+ADwAUABSAE8AVABFAEMAVABJAE4ARgBPAD4APABLAEkARABTAD4APABLAEkARAAgAEEATABHAEkARAA9ACIAQQBFAFMAQwBUAFIAIgAgAEMASABFAEMASwBTAFUATQA9ACIASQBTAGUAbgBvAHUASQA4AGYATQBZAD0AIgAgAFYAQQBMAFUARQA9ACIAMABOAEIAcgBxAGsAegBUAFoAbwBCAEUAcQBqAEkAMgB5AHgARABKAGIAUQA9AD0AIgA+ADwALwBLAEkARAA+ADwALwBLAEkARABTAD4APAAvAFAAUgBPAFQARQBDAFQASQBOAEYATwA+ADwATABBAF8AVQBSAEwAPgBoAHQAdABwAHMAOgAvAC8AdABlAHMAdAAuAHAAbABhAHkAcgBlAGEAZAB5AC4AbQBpAGMAcgBvAHMAbwBmAHQALgBjAG8AbQAvAHMAZQByAHYAaQBjAGUALwByAGkAZwBoAHQAcwBtAGEAbgBhAGcAZQByAC4AYQBzAG0AeAA/AGMAZgBnAD0AKABrAGkAZAA6ADAATgBCAHIAcQBrAHoAVABaAG8AQgBFAHEAagBJADIAeQB4AEQASgBiAFEAPQA9ACkAPAAvAEwAQQBfAFUAUgBMAD4APAAvAEQAQQBUAEEAPgA8AC8AVwBSAE0ASABFAEEARABFAFIAPgA=' | ||
const LA_URL = 'https://test.playready.microsoft.com/service/rightsmanager.asmx' | ||
test('Widevine PSSH Data Generator Test', async t => { | ||
const wvTools = pssh.tools(pssh.system.WIDEVINE) | ||
const payload = { contentId: 'cenc-content-id', trackType: 'HD', keyIds: [KID], provider: 'widevine_test', protectionScheme: 'cenc', dataOnly: true } | ||
test('Should return Widevine PSSH version 0 with no KID', async t => { | ||
const wvTools = pssh.tools(pssh.system.WIDEVINE.name) | ||
const payload = { contentId: 'cenc-content-id', trackType: 'HD', keyIds: [KID], provider: 'widevine_test', protectionScheme: 'cenc', dataOnly: false } | ||
await wvTools.generatePssh(payload).then((data) => { | ||
t.is(data, WV_PSSH_DATA) | ||
console.log(data) | ||
let result = utils.decodePSSH(data) | ||
t.is(result.version, 0) | ||
t.is(result.keyCount, 0) | ||
}) | ||
}) | ||
test('Playready PSSH Data Generator Test', async t => { | ||
const prTools = pssh.tools(pssh.system.PLAYREADY) | ||
const payload = { keyIds: [KID], licenseUrl: LA_URL, dataOnly: true } | ||
test.skip('Should return Widevine PSSH version 0 with KIDs', async t => { | ||
const wvTools = pssh.tools(pssh.system.WIDEVINE.name) | ||
const payload = { contentId: 'cenc-content-id', trackType: 'HD', keyIds: [KID], provider: 'widevine_test', protectionScheme: 'cenc', dataOnly: false } | ||
await wvTools.generatePssh(payload).then((data) => { | ||
console.log(data) | ||
let result = utils.decodePSSH(data) | ||
t.is(result.version, 0) | ||
t.not(result.keyCount, 0) | ||
}) | ||
}) | ||
test('Should return PlayReady PSSH version 1 with KID', async t => { | ||
const prTools = pssh.tools(pssh.system.PLAYREADY.name) | ||
const payload = { keyIds: [KID], licenseUrl: LA_URL, dataOnly: false } | ||
await prTools.generatePssh(payload).then((data) => { | ||
t.is(data, PR_PSSH_DATA) | ||
let result = utils.decodePSSH(data) | ||
t.is(result.version, 1) | ||
t.is(result.keyCount, 1) | ||
}) | ||
}) |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
18320
11
406
1
0