From 5c1b0e89efbcb36a085d2b8dc56242475254a748 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Sun, 31 Jul 2022 13:29:38 +0100 Subject: [PATCH] Cdm: Support multiple forms of Service Certs in encrypt_client_id --- pywidevine/cdm.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pywidevine/cdm.py b/pywidevine/cdm.py index 1b891a1..be14a36 100644 --- a/pywidevine/cdm.py +++ b/pywidevine/cdm.py @@ -424,7 +424,7 @@ class Cdm: @staticmethod def encrypt_client_id( client_id: ClientIdentification, - service_certificate: DrmCertificate, + service_certificate: Union[SignedMessage, SignedDrmCertificate, DrmCertificate], key: bytes = None, iv: bytes = None ) -> EncryptedClientIdentification: @@ -432,6 +432,14 @@ class Cdm: privacy_key = key or get_random_bytes(16) privacy_iv = iv or get_random_bytes(16) + if isinstance(service_certificate, SignedMessage): + signed_drm_certificate = SignedDrmCertificate() + signed_drm_certificate.ParseFromString(service_certificate.msg) + service_certificate = signed_drm_certificate + if isinstance(service_certificate, SignedDrmCertificate): + drm_certificate = DrmCertificate() + drm_certificate.ParseFromString(service_certificate.drm_certificate) + service_certificate = drm_certificate if not isinstance(service_certificate, DrmCertificate): raise ValueError(f"Expecting Service Certificate to be a DrmCertificate, not {service_certificate!r}")