diff --git a/modules/cdm.ts b/modules/cdm.ts index 5e39145..1a87cfa 100644 --- a/modules/cdm.ts +++ b/modules/cdm.ts @@ -46,8 +46,8 @@ try { if (stats.size < 1024 * 8 && stats.isFile()) { const fileContents = fs.readFileSync(file, { encoding: 'utf8' }); if ( - (fileContents.startsWith('-----BEGIN RSA PRIVATE KEY-----') && fileContents.endsWith('-----END RSA PRIVATE KEY-----')) || - (fileContents.startsWith('-----BEGIN PRIVATE KEY-----') && fileContents.endsWith('-----END PRIVATE KEY-----')) + (fileContents.includes('-----BEGIN RSA PRIVATE KEY-----') && fileContents.includes('-----END RSA PRIVATE KEY-----')) || + (fileContents.includes('-----BEGIN PRIVATE KEY-----') && fileContents.includes('-----END PRIVATE KEY-----')) ) { privateKey = fs.readFileSync(file); } diff --git a/modules/widevine/license.ts b/modules/widevine/license.ts index f1c30c0..7362673 100644 --- a/modules/widevine/license.ts +++ b/modules/widevine/license.ts @@ -212,21 +212,23 @@ export class Session { const license = fromBinary(LicenseSchema, signedLicense.msg); - const keyContainers = license.key.map((keyContainer) => { - if (keyContainer.type && keyContainer.key && keyContainer.iv) { - const keyId = keyContainer.id ? Buffer.from(keyContainer.id).toString('hex') : '00000000000000000000000000000000'; - const decipher = forge.cipher.createDecipher('AES-CBC', encKey.toString('binary')); - decipher.start({ iv: Buffer.from(keyContainer.iv).toString('binary') }); - decipher.update(forge.util.createBuffer(new Uint8Array(keyContainer.key))); - decipher.finish(); - const decryptedKey = Buffer.from(decipher.output.data, 'binary'); - const key: KeyContainer = { - kid: keyId, - key: decryptedKey.toString('hex') - }; - return key; - } - }); + const keyContainers = license.key + .filter((k) => k.id) + .map((keyContainer) => { + if (keyContainer.type && keyContainer.key && keyContainer.iv) { + const keyId = Buffer.from(keyContainer.id!).toString('hex'); + const decipher = forge.cipher.createDecipher('AES-CBC', encKey.toString('binary')); + decipher.start({ iv: Buffer.from(keyContainer.iv).toString('binary') }); + decipher.update(forge.util.createBuffer(new Uint8Array(keyContainer.key))); + decipher.finish(); + const decryptedKey = Buffer.from(decipher.output.data, 'binary'); + const key: KeyContainer = { + kid: keyId, + key: decryptedKey.toString('hex') + }; + return key; + } + }); if (keyContainers.filter((container) => !!container).length < 1) { throw new Error('there was not a single valid key in the response'); }