Cdm: Improve parsing of service certificates

This commit is contained in:
rlaphoenix 2022-07-30 02:44:34 +01:00
parent 7078759cdf
commit d1974ad1fb
1 changed files with 8 additions and 12 deletions

View File

@ -130,18 +130,14 @@ class Cdm:
signed_message = SignedMessage() signed_message = SignedMessage()
signed_drm_certificate = SignedDrmCertificate() signed_drm_certificate = SignedDrmCertificate()
try: # SignedMessage input try:
signed_message.ParseFromString(certificate) signed_message.ParseFromString(certificate)
if signed_message.SerializeToString() == certificate:
signed_drm_certificate.ParseFromString(signed_message.msg) signed_drm_certificate.ParseFromString(signed_message.msg)
if not signed_drm_certificate.drm_certificate: else:
raise DecodeError()
DrmCertificate().ParseFromString(signed_drm_certificate.drm_certificate)
except DecodeError:
try: # SignedDrmCertificate input
signed_drm_certificate.ParseFromString(certificate) signed_drm_certificate.ParseFromString(certificate)
if not signed_drm_certificate.drm_certificate: if signed_drm_certificate.SerializeToString() != certificate:
raise DecodeError() raise DecodeError()
DrmCertificate().ParseFromString(signed_drm_certificate.drm_certificate)
except DecodeError: except DecodeError:
# could be a direct unsigned DrmCertificate, but reject those anyway # could be a direct unsigned DrmCertificate, but reject those anyway
raise DecodeError("Could not parse certificate as a SignedDrmCertificate") raise DecodeError("Could not parse certificate as a SignedDrmCertificate")