From 53f7c1dd623d7f45d862bf1da11276918a8924a9 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Wed, 20 Jul 2022 21:40:40 +0100 Subject: [PATCH] Cdm: Fix size and Improve code of Android Session IDs --- pywidevine/cdm.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pywidevine/cdm.py b/pywidevine/cdm.py index 73c0475..a8def28 100644 --- a/pywidevine/cdm.py +++ b/pywidevine/cdm.py @@ -257,12 +257,9 @@ class Cdm: def create_session_id(self, device: Device) -> bytes: """Create a Session ID based on OEM Crypto API session values.""" if device.type == device.Types.ANDROID: - session_id = "{hex:16X}{counter}".format( - hex=random.getrandbits(64), - counter=f"{self.NUM_OF_SESSIONS:02}" - ) - session_id.ljust(32, "0") - return session_id.encode("ascii") + # Note: this reversing is quite old and needs verifying in later OEM Crypto versions like 16 + # though ultimately it shouldn't really matter + return get_random_bytes(8) + self.NUM_OF_SESSIONS.to_bytes(8, "little") if device.type == device.Types.CHROME: return get_random_bytes(16)