update widevine cdm detection and key container

This commit is contained in:
stratumadev 2025-10-09 23:00:46 +02:00
parent 50af4964a5
commit 1e27f59669
2 changed files with 19 additions and 17 deletions

View file

@ -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);
}

View file

@ -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');
}