linting and added prettier config

This commit is contained in:
stratumadev 2025-05-07 14:01:51 +02:00
parent 70fb4306b2
commit dce1deab28
4 changed files with 2013 additions and 1993 deletions

20
.prettierrc Normal file
View file

@ -0,0 +1,20 @@
{
"arrowParens": "always",
"bracketSameLine": false,
"bracketSpacing": true,
"embeddedLanguageFormatting": "auto",
"htmlWhitespaceSensitivity": "strict",
"insertPragma": false,
"jsxSingleQuote": false,
"proseWrap": "never",
"quoteProps": "as-needed",
"requirePragma": false,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false,
"vueIndentScriptAndStyle": false,
"printWidth": 180,
"endOfLine": "auto"
}

View file

@ -1,113 +1,113 @@
// Modified version of https://github.com/Frooastside/node-widevine
import crypto from 'crypto'
import crypto from 'crypto';
export class AES_CMAC {
private readonly BLOCK_SIZE = 16
private readonly XOR_RIGHT = Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87])
private readonly EMPTY_BLOCK_SIZE_BUFFER = Buffer.alloc(this.BLOCK_SIZE)
private readonly BLOCK_SIZE = 16;
private readonly XOR_RIGHT = Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x87]);
private readonly EMPTY_BLOCK_SIZE_BUFFER = Buffer.alloc(this.BLOCK_SIZE);
private _key: Buffer
private _subkeys: { first: Buffer; second: Buffer }
private _key: Buffer;
private _subkeys: { first: Buffer; second: Buffer };
public constructor(key: Buffer) {
if (![16, 24, 32].includes(key.length)) {
throw new Error('Key size must be 128, 192, or 256 bits.')
throw new Error('Key size must be 128, 192, or 256 bits.');
}
this._key = key
this._subkeys = this._generateSubkeys()
this._key = key;
this._subkeys = this._generateSubkeys();
}
public calculate(message: Buffer): Buffer {
const blockCount = this._getBlockCount(message)
const blockCount = this._getBlockCount(message);
let x = this.EMPTY_BLOCK_SIZE_BUFFER
let y
let x = this.EMPTY_BLOCK_SIZE_BUFFER;
let y;
for (let i = 0; i < blockCount - 1; i++) {
const from = i * this.BLOCK_SIZE
const block = message.subarray(from, from + this.BLOCK_SIZE)
y = this._xor(x, block)
x = this._aes(y)
const from = i * this.BLOCK_SIZE;
const block = message.subarray(from, from + this.BLOCK_SIZE);
y = this._xor(x, block);
x = this._aes(y);
}
y = this._xor(x, this._getLastBlock(message))
x = this._aes(y)
y = this._xor(x, this._getLastBlock(message));
x = this._aes(y);
return x
return x;
}
private _generateSubkeys(): { first: Buffer; second: Buffer } {
const l = this._aes(this.EMPTY_BLOCK_SIZE_BUFFER)
const l = this._aes(this.EMPTY_BLOCK_SIZE_BUFFER);
let first = this._bitShiftLeft(l)
let first = this._bitShiftLeft(l);
if (l[0] & 0x80) {
first = this._xor(first, this.XOR_RIGHT)
first = this._xor(first, this.XOR_RIGHT);
}
let second = this._bitShiftLeft(first)
let second = this._bitShiftLeft(first);
if (first[0] & 0x80) {
second = this._xor(second, this.XOR_RIGHT)
second = this._xor(second, this.XOR_RIGHT);
}
return { first: first, second: second }
return { first: first, second: second };
}
private _getBlockCount(message: Buffer): number {
const blockCount = Math.ceil(message.length / this.BLOCK_SIZE)
return blockCount === 0 ? 1 : blockCount
const blockCount = Math.ceil(message.length / this.BLOCK_SIZE);
return blockCount === 0 ? 1 : blockCount;
}
private _aes(message: Buffer): Buffer {
const cipher = crypto.createCipheriv(`aes-${this._key.length * 8}-cbc`, this._key, Buffer.alloc(this.BLOCK_SIZE))
const result = cipher.update(message).subarray(0, 16)
cipher.destroy()
return result
const cipher = crypto.createCipheriv(`aes-${this._key.length * 8}-cbc`, this._key, Buffer.alloc(this.BLOCK_SIZE));
const result = cipher.update(message).subarray(0, 16);
cipher.destroy();
return result;
}
private _getLastBlock(message: Buffer): Buffer {
const blockCount = this._getBlockCount(message)
const paddedBlock = this._padding(message, blockCount - 1)
const blockCount = this._getBlockCount(message);
const paddedBlock = this._padding(message, blockCount - 1);
let complete = false
let complete = false;
if (message.length > 0) {
complete = message.length % this.BLOCK_SIZE === 0
complete = message.length % this.BLOCK_SIZE === 0;
}
const key = complete ? this._subkeys.first : this._subkeys.second
return this._xor(paddedBlock, key)
const key = complete ? this._subkeys.first : this._subkeys.second;
return this._xor(paddedBlock, key);
}
private _padding(message: Buffer, blockIndex: number): Buffer {
const block = Buffer.alloc(this.BLOCK_SIZE)
const block = Buffer.alloc(this.BLOCK_SIZE);
const from = blockIndex * this.BLOCK_SIZE
const from = blockIndex * this.BLOCK_SIZE;
const slice = message.subarray(from, from + this.BLOCK_SIZE)
block.set(slice)
const slice = message.subarray(from, from + this.BLOCK_SIZE);
block.set(slice);
if (slice.length !== this.BLOCK_SIZE) {
block[slice.length] = 0x80
block[slice.length] = 0x80;
}
return block
return block;
}
private _bitShiftLeft(input: Buffer): Buffer {
const output = Buffer.alloc(input.length)
let overflow = 0
const output = Buffer.alloc(input.length);
let overflow = 0;
for (let i = input.length - 1; i >= 0; i--) {
output[i] = (input[i] << 1) | overflow
overflow = input[i] & 0x80 ? 1 : 0
output[i] = (input[i] << 1) | overflow;
overflow = input[i] & 0x80 ? 1 : 0;
}
return output
return output;
}
private _xor(a: Buffer, b: Buffer): Buffer {
const length = Math.min(a.length, b.length)
const output = Buffer.alloc(length)
const length = Math.min(a.length, b.length);
const output = Buffer.alloc(length);
for (let i = 0; i < length; i++) {
output[i] = a[i] ^ b[i]
output[i] = a[i] ^ b[i];
}
return output
return output;
}
}

View file

@ -1,7 +1,7 @@
// Modified version of https://github.com/Frooastside/node-widevine
import { AES_CMAC } from './cmac'
import forge from 'node-forge'
import { AES_CMAC } from './cmac';
import forge from 'node-forge';
import {
ClientIdentification,
ClientIdentificationSchema,
@ -23,10 +23,10 @@ import {
SignedMessageSchema,
WidevinePsshData,
WidevinePsshDataSchema
} from './license_protocol_pb3'
import { create, fromBinary, toBinary } from '@bufbuild/protobuf'
} from './license_protocol_pb3';
import { create, fromBinary, toBinary } from '@bufbuild/protobuf';
const WIDEVINE_SYSTEM_ID = new Uint8Array([0xed, 0xef, 0x8b, 0xa9, 0x79, 0xd6, 0x4a, 0xce, 0xa3, 0xc8, 0x27, 0xdc, 0xd5, 0x1d, 0x21, 0xed])
const WIDEVINE_SYSTEM_ID = new Uint8Array([0xed, 0xef, 0x8b, 0xa9, 0x79, 0xd6, 0x4a, 0xce, 0xa3, 0xc8, 0x27, 0xdc, 0xd5, 0x1d, 0x21, 0xed]);
const WIDEVINE_ROOT_PUBLIC_KEY = new Uint8Array([
0x30, 0x82, 0x01, 0x8a, 0x02, 0x82, 0x01, 0x81, 0x00, 0xb4, 0xfe, 0x39, 0xc3, 0x65, 0x90, 0x03, 0xdb, 0x3c, 0x11, 0x97, 0x09, 0xe8, 0x68, 0xcd, 0xf2, 0xc3, 0x5e, 0x9b, 0xf2,
@ -43,9 +43,9 @@ const WIDEVINE_ROOT_PUBLIC_KEY = new Uint8Array([
0xea, 0x4b, 0x7f, 0x97, 0x31, 0x1c, 0x81, 0x7c, 0x94, 0x8a, 0x4c, 0x7d, 0x68, 0x15, 0x84, 0xff, 0xa5, 0x08, 0xfd, 0x18, 0xe7, 0xe7, 0x2b, 0xe4, 0x47, 0x27, 0x12, 0x11, 0xb8,
0x23, 0xec, 0x58, 0x93, 0x3c, 0xac, 0x12, 0xd2, 0x88, 0x6d, 0x41, 0x3d, 0xc5, 0xfe, 0x1c, 0xdc, 0xb9, 0xf8, 0xd4, 0x51, 0x3e, 0x07, 0xe5, 0x03, 0x6f, 0xa7, 0x12, 0xe8, 0x12,
0xf7, 0xb5, 0xce, 0xa6, 0x96, 0x55, 0x3f, 0x78, 0xb4, 0x64, 0x82, 0x50, 0xd2, 0x33, 0x5f, 0x91, 0x02, 0x03, 0x01, 0x00, 0x01
])
]);
export const SERVICE_CERTIFICATE_CHALLENGE = new Uint8Array([0x08, 0x04])
export const SERVICE_CERTIFICATE_CHALLENGE = new Uint8Array([0x08, 0x04]);
const COMMON_SERVICE_CERTIFICATE = new Uint8Array([
0x08, 0x05, 0x12, 0xc7, 0x05, 0x0a, 0xc1, 0x02, 0x08, 0x03, 0x12, 0x10, 0x17, 0x05, 0xb9, 0x17, 0xcc, 0x12, 0x04, 0x86, 0x8b, 0x06, 0x33, 0x3a, 0x2f, 0x77, 0x2a, 0x8c, 0x18,
@ -73,60 +73,60 @@ const COMMON_SERVICE_CERTIFICATE = new Uint8Array([
0x2c, 0xc8, 0xdf, 0x54, 0x3c, 0xb1, 0xa1, 0x18, 0x2f, 0x7c, 0x5f, 0xff, 0x33, 0xf1, 0x04, 0x90, 0xfa, 0xca, 0x5b, 0x25, 0x36, 0x0b, 0x76, 0x01, 0x5e, 0x9c, 0x5a, 0x06, 0xab,
0x8e, 0xe0, 0x2f, 0x00, 0xd2, 0xe8, 0xd5, 0x98, 0x61, 0x04, 0xaa, 0xcc, 0x4d, 0xd4, 0x75, 0xfd, 0x96, 0xee, 0x9c, 0xe4, 0xe3, 0x26, 0xf2, 0x1b, 0x83, 0xc7, 0x05, 0x85, 0x77,
0xb3, 0x87, 0x32, 0xcd, 0xda, 0xbc, 0x6a, 0x6b, 0xed, 0x13, 0xfb, 0x0d, 0x49, 0xd3, 0x8a, 0x45, 0xeb, 0x87, 0xa5, 0xf4
])
]);
export type KeyContainer = {
kid: string
key: string
}
kid: string;
key: string;
};
export type ContentDecryptionModule = {
privateKey: Buffer
identifierBlob: Buffer
}
privateKey: Buffer;
identifierBlob: Buffer;
};
export class Session {
private _devicePrivateKey: forge.pki.rsa.PrivateKey
private _identifierBlob: ClientIdentification
private _pssh: Buffer
private _rawLicenseRequest?: Buffer
private _serviceCertificate?: SignedDrmCertificate
private _devicePrivateKey: forge.pki.rsa.PrivateKey;
private _identifierBlob: ClientIdentification;
private _pssh: Buffer;
private _rawLicenseRequest?: Buffer;
private _serviceCertificate?: SignedDrmCertificate;
constructor(contentDecryptionModule: ContentDecryptionModule, pssh: Buffer) {
this._devicePrivateKey = forge.pki.privateKeyFromPem(contentDecryptionModule.privateKey.toString('binary'))
this._devicePrivateKey = forge.pki.privateKeyFromPem(contentDecryptionModule.privateKey.toString('binary'));
this._identifierBlob = fromBinary(ClientIdentificationSchema, contentDecryptionModule.identifierBlob)
this._pssh = pssh
this._identifierBlob = fromBinary(ClientIdentificationSchema, contentDecryptionModule.identifierBlob);
this._pssh = pssh;
}
async setDefaultServiceCertificate() {
await this.setServiceCertificate(Buffer.from(COMMON_SERVICE_CERTIFICATE))
await this.setServiceCertificate(Buffer.from(COMMON_SERVICE_CERTIFICATE));
}
async setServiceCertificateFromMessage(rawSignedMessage: Buffer) {
const signedMessage: SignedMessage = fromBinary(SignedMessageSchema, rawSignedMessage)
const signedMessage: SignedMessage = fromBinary(SignedMessageSchema, rawSignedMessage);
if (!signedMessage.msg) {
throw new Error('the service certificate message does not contain a message')
throw new Error('the service certificate message does not contain a message');
}
await this.setServiceCertificate(Buffer.from(signedMessage.msg))
await this.setServiceCertificate(Buffer.from(signedMessage.msg));
}
async setServiceCertificate(serviceCertificate: Buffer) {
const signedServiceCertificate: SignedDrmCertificate = fromBinary(SignedDrmCertificateSchema, serviceCertificate)
const signedServiceCertificate: SignedDrmCertificate = fromBinary(SignedDrmCertificateSchema, serviceCertificate);
if (!(await this._verifyServiceCertificate(signedServiceCertificate))) {
throw new Error('Service certificate is not signed by the Widevine root certificate')
throw new Error('Service certificate is not signed by the Widevine root certificate');
}
this._serviceCertificate = signedServiceCertificate
this._serviceCertificate = signedServiceCertificate;
}
createLicenseRequest(licenseType: LicenseType = LicenseType.STREAMING, android: boolean = false): Buffer {
if (!this._pssh.subarray(12, 28).equals(Buffer.from(WIDEVINE_SYSTEM_ID))) {
throw new Error('the pssh is not an actuall pssh')
throw new Error('the pssh is not an actuall pssh');
}
const pssh = this._parsePSSH(this._pssh)
const pssh = this._parsePSSH(this._pssh);
if (!pssh) {
throw new Error('pssh is invalid')
throw new Error('pssh is invalid');
}
const licenseRequest: LicenseRequest = create(LicenseRequestSchema, {
@ -144,115 +144,115 @@ export class Session {
requestTime: BigInt(Date.now()) / BigInt(1000),
protocolVersion: ProtocolVersion.VERSION_2_1,
keyControlNonce: Math.floor(Math.random() * 2 ** 31)
})
});
if (this._serviceCertificate) {
const encryptedClientIdentification = this._encryptClientIdentification(this._identifierBlob, this._serviceCertificate)
licenseRequest.encryptedClientId = encryptedClientIdentification
const encryptedClientIdentification = this._encryptClientIdentification(this._identifierBlob, this._serviceCertificate);
licenseRequest.encryptedClientId = encryptedClientIdentification;
} else {
licenseRequest.clientId = this._identifierBlob
licenseRequest.clientId = this._identifierBlob;
}
this._rawLicenseRequest = Buffer.from(toBinary(LicenseRequestSchema, licenseRequest))
this._rawLicenseRequest = Buffer.from(toBinary(LicenseRequestSchema, licenseRequest));
const pss: forge.pss.PSS = forge.pss.create({ md: forge.md.sha1.create(), mgf: forge.mgf.mgf1.create(forge.md.sha1.create()), saltLength: 20 })
const md = forge.md.sha1.create()
md.update(this._rawLicenseRequest.toString('binary'), 'raw')
const signature = Buffer.from(this._devicePrivateKey.sign(md, pss), 'binary')
const pss: forge.pss.PSS = forge.pss.create({ md: forge.md.sha1.create(), mgf: forge.mgf.mgf1.create(forge.md.sha1.create()), saltLength: 20 });
const md = forge.md.sha1.create();
md.update(this._rawLicenseRequest.toString('binary'), 'raw');
const signature = Buffer.from(this._devicePrivateKey.sign(md, pss), 'binary');
const signedLicenseRequest: SignedMessage = create(SignedMessageSchema, {
type: SignedMessage_MessageType.LICENSE_REQUEST,
msg: this._rawLicenseRequest,
signature: signature
})
});
return Buffer.from(toBinary(SignedMessageSchema, signedLicenseRequest))
return Buffer.from(toBinary(SignedMessageSchema, signedLicenseRequest));
}
parseLicense(rawLicense: Buffer) {
if (!this._rawLicenseRequest) {
throw new Error('please request a license first')
throw new Error('please request a license first');
}
const signedLicense = fromBinary(SignedMessageSchema, rawLicense)
const signedLicense = fromBinary(SignedMessageSchema, rawLicense);
if (!signedLicense.sessionKey) {
throw new Error('the license does not contain a session key')
throw new Error('the license does not contain a session key');
}
if (!signedLicense.msg) {
throw new Error('the license does not contain a message')
throw new Error('the license does not contain a message');
}
if (!signedLicense.signature) {
throw new Error('the license does not contain a signature')
throw new Error('the license does not contain a signature');
}
const sessionKey = this._devicePrivateKey.decrypt(Buffer.from(signedLicense.sessionKey).toString('binary'), 'RSA-OAEP', {
md: forge.md.sha1.create()
})
});
const cmac = new AES_CMAC(Buffer.from(sessionKey, 'binary'))
const cmac = new AES_CMAC(Buffer.from(sessionKey, 'binary'));
const encKeyBase = Buffer.concat([Buffer.from('ENCRYPTION'), Buffer.from('\x00', 'ascii'), this._rawLicenseRequest, Buffer.from('\x00\x00\x00\x80', 'ascii')])
const authKeyBase = Buffer.concat([Buffer.from('AUTHENTICATION'), Buffer.from('\x00', 'ascii'), this._rawLicenseRequest, Buffer.from('\x00\x00\x02\x00', 'ascii')])
const encKeyBase = Buffer.concat([Buffer.from('ENCRYPTION'), Buffer.from('\x00', 'ascii'), this._rawLicenseRequest, Buffer.from('\x00\x00\x00\x80', 'ascii')]);
const authKeyBase = Buffer.concat([Buffer.from('AUTHENTICATION'), Buffer.from('\x00', 'ascii'), this._rawLicenseRequest, Buffer.from('\x00\x00\x02\x00', 'ascii')]);
const encKey = cmac.calculate(Buffer.concat([Buffer.from('\x01'), encKeyBase]))
const serverKey = Buffer.concat([cmac.calculate(Buffer.concat([Buffer.from('\x01'), authKeyBase])), cmac.calculate(Buffer.concat([Buffer.from('\x02'), authKeyBase]))])
const encKey = cmac.calculate(Buffer.concat([Buffer.from('\x01'), encKeyBase]));
const serverKey = Buffer.concat([cmac.calculate(Buffer.concat([Buffer.from('\x01'), authKeyBase])), cmac.calculate(Buffer.concat([Buffer.from('\x02'), authKeyBase]))]);
/*const clientKey = Buffer.concat([
cmac.calculate(Buffer.concat([Buffer.from("\x03"), authKeyBase])),
cmac.calculate(Buffer.concat([Buffer.from("\x04"), authKeyBase]))
]);*/
const hmac = forge.hmac.create()
hmac.start(forge.md.sha256.create(), serverKey.toString('binary'))
hmac.update(Buffer.from(signedLicense.msg).toString('binary'))
const calculatedSignature = Buffer.from(hmac.digest().data, 'binary')
const hmac = forge.hmac.create();
hmac.start(forge.md.sha256.create(), serverKey.toString('binary'));
hmac.update(Buffer.from(signedLicense.msg).toString('binary'));
const calculatedSignature = Buffer.from(hmac.digest().data, 'binary');
if (!calculatedSignature.equals(signedLicense.signature)) {
throw new Error('signatures do not match')
throw new Error('signatures do not match');
}
const license = fromBinary(LicenseSchema, signedLicense.msg)
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(keyContainer.key))
decipher.finish()
const decryptedKey = Buffer.from(decipher.output.data, 'binary')
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(keyContainer.key));
decipher.finish();
const decryptedKey = Buffer.from(decipher.output.data, 'binary');
const key: KeyContainer = {
kid: keyId,
key: decryptedKey.toString('hex')
};
return key;
}
return key
}
})
});
if (keyContainers.filter((container) => !!container).length < 1) {
throw new Error('there was not a single valid key in the response')
throw new Error('there was not a single valid key in the response');
}
return keyContainers
return keyContainers;
}
private _encryptClientIdentification(clientIdentification: ClientIdentification, signedServiceCertificate: SignedDrmCertificate): EncryptedClientIdentification {
if (!signedServiceCertificate.drmCertificate) {
throw new Error('the service certificate does not contain an actual certificate')
throw new Error('the service certificate does not contain an actual certificate');
}
const serviceCertificate = fromBinary(DrmCertificateSchema, signedServiceCertificate.drmCertificate)
const serviceCertificate = fromBinary(DrmCertificateSchema, signedServiceCertificate.drmCertificate);
if (!serviceCertificate.publicKey) {
throw new Error('the service certificate does not contain a public key')
throw new Error('the service certificate does not contain a public key');
}
const key = forge.random.getBytesSync(16)
const iv = forge.random.getBytesSync(16)
const cipher = forge.cipher.createCipher('AES-CBC', key)
cipher.start({ iv: iv })
cipher.update(forge.util.createBuffer(toBinary(ClientIdentificationSchema, clientIdentification)))
cipher.finish()
const rawEncryptedClientIdentification = Buffer.from(cipher.output.data, 'binary')
const key = forge.random.getBytesSync(16);
const iv = forge.random.getBytesSync(16);
const cipher = forge.cipher.createCipher('AES-CBC', key);
cipher.start({ iv: iv });
cipher.update(forge.util.createBuffer(toBinary(ClientIdentificationSchema, clientIdentification)));
cipher.finish();
const rawEncryptedClientIdentification = Buffer.from(cipher.output.data, 'binary');
const publicKey = forge.pki.publicKeyFromAsn1(forge.asn1.fromDer(Buffer.from(serviceCertificate.publicKey).toString('binary')))
const encryptedKey = publicKey.encrypt(key, 'RSA-OAEP', { md: forge.md.sha1.create() })
const publicKey = forge.pki.publicKeyFromAsn1(forge.asn1.fromDer(Buffer.from(serviceCertificate.publicKey).toString('binary')));
const encryptedKey = publicKey.encrypt(key, 'RSA-OAEP', { md: forge.md.sha1.create() });
const encryptedClientIdentification: EncryptedClientIdentification = create(EncryptedClientIdentificationSchema, {
encryptedClientId: rawEncryptedClientIdentification,
@ -260,42 +260,42 @@ export class Session {
encryptedPrivacyKey: Buffer.from(encryptedKey, 'binary'),
providerId: serviceCertificate.providerId,
serviceCertificateSerialNumber: serviceCertificate.serialNumber
})
return encryptedClientIdentification
});
return encryptedClientIdentification;
}
private async _verifyServiceCertificate(signedServiceCertificate: SignedDrmCertificate): Promise<boolean> {
if (!signedServiceCertificate.drmCertificate) {
throw new Error('the service certificate does not contain an actual certificate')
throw new Error('the service certificate does not contain an actual certificate');
}
if (!signedServiceCertificate.signature) {
throw new Error('the service certificate does not contain a signature')
throw new Error('the service certificate does not contain a signature');
}
const publicKey = forge.pki.publicKeyFromAsn1(forge.asn1.fromDer(Buffer.from(WIDEVINE_ROOT_PUBLIC_KEY).toString('binary')))
const pss: forge.pss.PSS = forge.pss.create({ md: forge.md.sha1.create(), mgf: forge.mgf.mgf1.create(forge.md.sha1.create()), saltLength: 20 })
const sha1 = forge.md.sha1.create()
sha1.update(Buffer.from(signedServiceCertificate.drmCertificate).toString('binary'), 'raw')
return publicKey.verify(sha1.digest().bytes(), Buffer.from(signedServiceCertificate.signature).toString('binary'), pss)
const publicKey = forge.pki.publicKeyFromAsn1(forge.asn1.fromDer(Buffer.from(WIDEVINE_ROOT_PUBLIC_KEY).toString('binary')));
const pss: forge.pss.PSS = forge.pss.create({ md: forge.md.sha1.create(), mgf: forge.mgf.mgf1.create(forge.md.sha1.create()), saltLength: 20 });
const sha1 = forge.md.sha1.create();
sha1.update(Buffer.from(signedServiceCertificate.drmCertificate).toString('binary'), 'raw');
return publicKey.verify(sha1.digest().bytes(), Buffer.from(signedServiceCertificate.signature).toString('binary'), pss);
}
private _parsePSSH(pssh: Buffer): WidevinePsshData | null {
try {
return fromBinary(WidevinePsshDataSchema, pssh.subarray(32))
return fromBinary(WidevinePsshDataSchema, pssh.subarray(32));
} catch {
return null
return null;
}
}
private _generateAndroidIdentifier(): Buffer {
return Buffer.from(`${forge.util.bytesToHex(forge.random.getBytesSync(8))}${'01'}${'00000000000000'}`)
return Buffer.from(`${forge.util.bytesToHex(forge.random.getBytesSync(8))}${'01'}${'00000000000000'}`);
}
private _generateGenericIdentifier(): Buffer {
return Buffer.from(forge.random.getBytesSync(16), 'binary')
return Buffer.from(forge.random.getBytesSync(16), 'binary');
}
get pssh(): Buffer {
return this._pssh
return this._pssh;
}
}

File diff suppressed because one or more lines are too long