From fa00bbd8e4432cf79af1a9ec5e419c6126ddef2e Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Wed, 28 Sep 2022 06:49:41 +0100 Subject: [PATCH] Cdm: Fix acquisition of provider_id when removing a service cert The logic of parsing the session's stored service cert to get the provider_id was wrong. It assumed it was a SignedDrmCertificate, when in reality it was a SignedMessage containing a SignedDrmCertificate. It would also panic if you try to remove a certificate when none was set. --- pywidevine/cdm.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pywidevine/cdm.py b/pywidevine/cdm.py index 6191d74..e215573 100644 --- a/pywidevine/cdm.py +++ b/pywidevine/cdm.py @@ -185,10 +185,16 @@ class Cdm: raise InvalidSession(f"Session identifier {session_id!r} is invalid.") if certificate is None: - drm_certificate = DrmCertificate() - drm_certificate.ParseFromString(session.service_certificate.drm_certificate) + if session.service_certificate: + signed_drm_certificate = SignedDrmCertificate() + signed_drm_certificate.ParseFromString(session.service_certificate) + drm_certificate = DrmCertificate() + drm_certificate.ParseFromString(signed_drm_certificate.drm_certificate) + provider_id = drm_certificate.provider_id + else: + provider_id = None session.service_certificate = None - return drm_certificate.provider_id + return provider_id if isinstance(certificate, str): try: