Exception Handling and RemoteCDM Improvement

This commit is contained in:
Erevoc 2024-11-16 12:36:18 +02:00
parent 02f4cfa90e
commit e9b2e6ec6a
6 changed files with 15 additions and 8 deletions

View File

@ -10,4 +10,4 @@ from .session import *
from .xml_key import * from .xml_key import *
from .xmrlicense import * from .xmrlicense import *
__version__ = "0.3.1" __version__ = "0.3.2"

View File

@ -270,6 +270,8 @@ class Cdm:
key_length=key.key_length, key_length=key.key_length,
key=self._decrypt_ecc256_key(session, key.encrypted_key) key=self._decrypt_ecc256_key(session, key.encrypted_key)
)) ))
except InvalidLicense as e:
raise InvalidLicense(e)
except Exception as e: except Exception as e:
raise Exception(f"Unable to parse license, {e}") raise Exception(f"Unable to parse license, {e}")

View File

@ -1,7 +1,7 @@
import base64 import base64
from enum import Enum from enum import Enum
from uuid import UUID from uuid import UUID
from typing import Optional, Union from typing import Union
class Key: class Key:

View File

@ -64,7 +64,7 @@ class RemoteCdm(Cdm):
if not server_version_re: if not server_version_re:
raise ValueError("The pyplayready server API is not stating the version correctly, cannot continue.") raise ValueError("The pyplayready server API is not stating the version correctly, cannot continue.")
server_version = server_version_re.group(1) 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.") raise ValueError(f"This pyplayready serve API version ({server_version}) is not supported.")
@classmethod @classmethod

View File

@ -9,7 +9,7 @@ from pyplayready import __version__
from pyplayready.cdm import Cdm from pyplayready.cdm import Cdm
from pyplayready.device import Device from pyplayready.device import Device
from pyplayready.exceptions import (InvalidSession, TooManySessions) from pyplayready.exceptions import (InvalidSession, TooManySessions, InvalidLicense)
routes = web.RouteTableDef() routes = web.RouteTableDef()
@ -192,6 +192,11 @@ async def parse_license(request: web.Request) -> web.Response:
"status": 400, "status": 400,
"message": f"Invalid Session ID '{session_id.hex()}', it may have expired." "message": f"Invalid Session ID '{session_id.hex()}', it may have expired."
}, status=400) }, status=400)
except InvalidLicense as e:
return web.json_response({
"status": 400,
"message": f"Invalid License, {e}"
}, status=400)
except Exception as e: except Exception as e:
return web.json_response({ return web.json_response({
"status": 400, "status": 400,
@ -247,9 +252,9 @@ async def get_keys(request: web.Request) -> web.Response:
{ {
"key_id": key.key_id.hex, "key_id": key.key_id.hex,
"key": key.key.hex(), "key": key.key.hex(),
"type": str(key.key_type), "type": key.key_type.value,
"cipher_type": str(key.cipher_type), "cipher_type": key.cipher_type.value,
"key_length": str(key.key_length), "key_length": key.key_length,
} }
for key in keys for key in keys
] ]

View File

@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry] [tool.poetry]
name = "pyplayready" name = "pyplayready"
version = "0.3.1" version = "0.3.2"
description = "pyplayready CDM (Content Decryption Module) implementation in Python." description = "pyplayready CDM (Content Decryption Module) implementation in Python."
license = "CC BY-NC-ND 4.0" license = "CC BY-NC-ND 4.0"
authors = ["DevLARLEY, Erevoc"] authors = ["DevLARLEY, Erevoc"]