From 42b825dcd55e8f4e1537fefbf3f283b4d0c9102f Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Wed, 28 Sep 2022 07:37:17 +0100 Subject: [PATCH] Cdm: Add parsing error handlers to Service Cert DrmCertificates --- pywidevine/cdm.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pywidevine/cdm.py b/pywidevine/cdm.py index e215573..0655e8d 100644 --- a/pywidevine/cdm.py +++ b/pywidevine/cdm.py @@ -206,6 +206,7 @@ class Cdm: signed_message = SignedMessage() signed_drm_certificate = SignedDrmCertificate() + drm_certificate = DrmCertificate() try: signed_message.ParseFromString(certificate) @@ -232,11 +233,16 @@ class Cdm: ) except (ValueError, TypeError): raise SignatureMismatch("Signature Mismatch on SignedDrmCertificate, rejecting certificate") - else: - session.service_certificate = signed_message - drm_certificate = DrmCertificate() + + try: drm_certificate.ParseFromString(signed_drm_certificate.drm_certificate) - return drm_certificate.provider_id + if drm_certificate.SerializeToString() != signed_drm_certificate.drm_certificate: + raise DecodeError("partial parse") + except DecodeError as e: + raise DecodeError(f"Could not parse signed certificate's message as a DrmCertificate, {e}") + + session.service_certificate = signed_message + return drm_certificate.provider_id def get_service_certificate(self, session_id: bytes) -> Optional[SignedMessage]: """