From d1974ad1fb5f0fd9def8e069ed47bdc5aa0a01ed Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Sat, 30 Jul 2022 02:44:34 +0100 Subject: [PATCH] Cdm: Improve parsing of service certificates --- pywidevine/cdm.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pywidevine/cdm.py b/pywidevine/cdm.py index a75f872..696b9ca 100644 --- a/pywidevine/cdm.py +++ b/pywidevine/cdm.py @@ -130,21 +130,17 @@ class Cdm: signed_message = SignedMessage() signed_drm_certificate = SignedDrmCertificate() - try: # SignedMessage input + try: signed_message.ParseFromString(certificate) - signed_drm_certificate.ParseFromString(signed_message.msg) - if not signed_drm_certificate.drm_certificate: - raise DecodeError() - DrmCertificate().ParseFromString(signed_drm_certificate.drm_certificate) - except DecodeError: - try: # SignedDrmCertificate input + if signed_message.SerializeToString() == certificate: + signed_drm_certificate.ParseFromString(signed_message.msg) + else: signed_drm_certificate.ParseFromString(certificate) - if not signed_drm_certificate.drm_certificate: + if signed_drm_certificate.SerializeToString() != certificate: raise DecodeError() - DrmCertificate().ParseFromString(signed_drm_certificate.drm_certificate) - except DecodeError: - # could be a direct unsigned DrmCertificate, but reject those anyway - raise DecodeError("Could not parse certificate as a SignedDrmCertificate") + except DecodeError: + # could be a direct unsigned DrmCertificate, but reject those anyway + raise DecodeError("Could not parse certificate as a SignedDrmCertificate") try: pss. \