From 91ceed874100fc06209e7eeedcc530237d25fe76 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 23 Oct 2024 09:56:02 +0200 Subject: [PATCH] + Fixed video being allowed to play when the keys were already retrieved --- background.js | 11 +++++++++-- license.js | 23 ++++++++++------------- manifest.json | 2 +- util.js | 7 +++++++ 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/background.js b/background.js index d489d19..ca787da 100644 --- a/background.js +++ b/background.js @@ -3,7 +3,14 @@ import "./license_protocol.js"; import "./forge.min.js"; import { Session } from "./license.js"; -import { DeviceManager, base64toUint8Array, uint8ArrayToBase64, uint8ArrayToHex, SettingsManager, AsyncLocalStorage } from "./util.js"; +import { + DeviceManager, + base64toUint8Array, + uint8ArrayToBase64, + uint8ArrayToHex, + SettingsManager, + AsyncLocalStorage +} from "./util.js"; import { WidevineDevice } from "./device.js"; const { LicenseType, SignedMessage, LicenseRequest, License } = protobuf.roots.default.license_protocol; @@ -34,7 +41,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { return; } - if (logs.filter(log => log.pssh_data === uint8ArrayToBase64(pssh_data)).length > 0) { + if (logs.filter(log => log.pssh_data === Session.psshDataToPsshBoxB64(pssh_data)).length > 0) { console.log("[WidevineProxy2]", `KEYS_ALREADY_RETRIEVED: ${uint8ArrayToBase64(pssh_data)}`); sendResponse(message.body); return; diff --git a/license.js b/license.js index c667e48..3e20bd3 100644 --- a/license.js +++ b/license.js @@ -5,7 +5,7 @@ import { uint8ArrayToString, stringToUint8Array, stringToHex, - base64toUint8Array, uint8ArrayToBase64 + base64toUint8Array, uint8ArrayToBase64, intToUint8Array } from "./util.js" const { ClientIdentification, DrmCertificate, EncryptedClientIdentification, License, LicenseRequest, LicenseType, ProtocolVersion, SignedDrmCertificate, SignedMessage, WidevinePsshData } = protobuf.roots.default.license_protocol; @@ -365,24 +365,21 @@ export class Session { return forge.random.getBytesSync(16) } - _intToUint8Array(num) { - const buffer = new ArrayBuffer(4); - const view = new DataView(buffer); - view.setUint32(0, num, false); - return new Uint8Array(buffer); - } - - getPSSH() { - const dataLength = this._pssh.length; + static psshDataToPsshBoxB64(pssh_data) { + const dataLength = pssh_data.length; const totalLength = dataLength + 32; const pssh = new Uint8Array([ - ...this._intToUint8Array(totalLength), + ...intToUint8Array(totalLength), ...PSSH_MAGIC, ...new Uint8Array(4), ...WIDEVINE_SYSTEM_ID, - ...this._intToUint8Array(dataLength), - ...this._pssh + ...intToUint8Array(dataLength), + ...pssh_data ]); return uint8ArrayToBase64(pssh); } + + getPSSH() { + return Session.psshDataToPsshBoxB64(this._pssh) + } } diff --git a/manifest.json b/manifest.json index d504bbb..65c5fe9 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "WidevineProxy2", - "version": "0.3", + "version": "0.4", "permissions": [ "activeTab", "tabs", diff --git a/util.js b/util.js index 46dd943..e6b1206 100644 --- a/util.js +++ b/util.js @@ -182,6 +182,13 @@ export class SettingsManager { } } +export function intToUint8Array(num) { + const buffer = new ArrayBuffer(4); + const view = new DataView(buffer); + view.setUint32(0, num, false); + return new Uint8Array(buffer); +} + export function compareUint8Arrays(arr1, arr2) { if (arr1.length !== arr2.length) return false;