From e9b2e6ec6a72d1ad5ee4126e36bf9681a20bcbc5 Mon Sep 17 00:00:00 2001 From: Erevoc <188392309+Erevoc@users.noreply.github.com> Date: Sat, 16 Nov 2024 12:36:18 +0200 Subject: [PATCH] Exception Handling and RemoteCDM Improvement --- pyplayready/__init__.py | 2 +- pyplayready/cdm.py | 2 ++ pyplayready/key.py | 2 +- pyplayready/remotecdm.py | 2 +- pyplayready/serve.py | 13 +++++++++---- pyproject.toml | 2 +- 6 files changed, 15 insertions(+), 8 deletions(-) diff --git a/pyplayready/__init__.py b/pyplayready/__init__.py index 5a5d21f..26962a5 100644 --- a/pyplayready/__init__.py +++ b/pyplayready/__init__.py @@ -10,4 +10,4 @@ from .session import * from .xml_key import * from .xmrlicense import * -__version__ = "0.3.1" +__version__ = "0.3.2" diff --git a/pyplayready/cdm.py b/pyplayready/cdm.py index a29c8c4..2096c89 100644 --- a/pyplayready/cdm.py +++ b/pyplayready/cdm.py @@ -270,6 +270,8 @@ class Cdm: key_length=key.key_length, key=self._decrypt_ecc256_key(session, key.encrypted_key) )) + except InvalidLicense as e: + raise InvalidLicense(e) except Exception as e: raise Exception(f"Unable to parse license, {e}") diff --git a/pyplayready/key.py b/pyplayready/key.py index d3df185..4acc555 100644 --- a/pyplayready/key.py +++ b/pyplayready/key.py @@ -1,7 +1,7 @@ import base64 from enum import Enum from uuid import UUID -from typing import Optional, Union +from typing import Union class Key: diff --git a/pyplayready/remotecdm.py b/pyplayready/remotecdm.py index 317e131..9f3d8ce 100644 --- a/pyplayready/remotecdm.py +++ b/pyplayready/remotecdm.py @@ -64,7 +64,7 @@ class RemoteCdm(Cdm): if not server_version_re: raise ValueError("The pyplayready server API is not stating the version correctly, cannot continue.") server_version = server_version_re.group(1) - if server_version < "0.0.2": + if server_version < "0.3.1": raise ValueError(f"This pyplayready serve API version ({server_version}) is not supported.") @classmethod diff --git a/pyplayready/serve.py b/pyplayready/serve.py index 63e123c..6582f2f 100644 --- a/pyplayready/serve.py +++ b/pyplayready/serve.py @@ -9,7 +9,7 @@ from pyplayready import __version__ from pyplayready.cdm import Cdm from pyplayready.device import Device -from pyplayready.exceptions import (InvalidSession, TooManySessions) +from pyplayready.exceptions import (InvalidSession, TooManySessions, InvalidLicense) routes = web.RouteTableDef() @@ -192,6 +192,11 @@ async def parse_license(request: web.Request) -> web.Response: "status": 400, "message": f"Invalid Session ID '{session_id.hex()}', it may have expired." }, status=400) + except InvalidLicense as e: + return web.json_response({ + "status": 400, + "message": f"Invalid License, {e}" + }, status=400) except Exception as e: return web.json_response({ "status": 400, @@ -247,9 +252,9 @@ async def get_keys(request: web.Request) -> web.Response: { "key_id": key.key_id.hex, "key": key.key.hex(), - "type": str(key.key_type), - "cipher_type": str(key.cipher_type), - "key_length": str(key.key_length), + "type": key.key_type.value, + "cipher_type": key.cipher_type.value, + "key_length": key.key_length, } for key in keys ] diff --git a/pyproject.toml b/pyproject.toml index eebe7e1..d5bd297 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "pyplayready" -version = "0.3.1" +version = "0.3.2" description = "pyplayready CDM (Content Decryption Module) implementation in Python." license = "CC BY-NC-ND 4.0" authors = ["DevLARLEY, Erevoc"]