From 5b6779edf2c4f520ed43477835306a570008045e Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Sat, 23 Mar 2019 01:00:44 +0100 Subject: [PATCH] Replace pycryptodome with cryptography. This will make it easier to support older distros. For example ubuntu 16.04 and Debian stable (9) --- README.md | 2 +- dockerfile/Dockerfile | 4 +--- lib/svtplay_dl/fetcher/hls.py | 15 +++++++-------- requirements.txt | 2 +- setup.py | 2 +- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 39df847..434aad0 100644 --- a/README.md +++ b/README.md @@ -88,7 +88,7 @@ are usually available from your distribution’s package repositories. If you don’t have them, some features will not be working. - [Python](https://www.python.org/) 3.4 or higher -- [pycryptodome](https://www.pycryptodome.org/en/latest/) to download encrypted HLS streams +- [cryptography](https://cryptography.io/en/latest/) to download encrypted HLS streams - [PyYaml](https://github.com/yaml/pyyaml) for configure file - [Requests](http://www.python-requests.org/) - [PySocks](https://github.com/Anorov/PySocks) to enable proxy support diff --git a/dockerfile/Dockerfile b/dockerfile/Dockerfile index 416aaf5..35ab900 100644 --- a/dockerfile/Dockerfile +++ b/dockerfile/Dockerfile @@ -1,18 +1,16 @@ # using edge to get ffmpeg-4.x -# using testing repo to get pycryptodome FROM alpine:edge MAINTAINER spaam COPY dist/*.whl . RUN set -xe \ - && echo 'http://dl-cdn.alpinelinux.org/alpine/edge/testing' >> /etc/apk/repositories \ && apk add --no-cache \ ca-certificates \ python3 \ py3-pip \ rtmpdump \ - py3-pycryptodome \ + py3-cryptography \ ffmpeg \ && python3 -m pip install *.whl \ && rm -f *.whl diff --git a/lib/svtplay_dl/fetcher/hls.py b/lib/svtplay_dl/fetcher/hls.py index e690f0a..d8618b8 100644 --- a/lib/svtplay_dl/fetcher/hls.py +++ b/lib/svtplay_dl/fetcher/hls.py @@ -127,14 +127,11 @@ class HLS(VideoRetriever): key = None if m3u8.encrypted: - from Crypto.Cipher import AES + from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes + from cryptography.hazmat.backends import default_backend def random_iv(): - try: - from Crypto import Random - return Random.new().read(AES.block_size) - except ImportError: - return os.urandom(16) + return os.urandom(16) file_d = output(file_name[0], self.config, file_name[1]) if file_d is None: return @@ -180,10 +177,12 @@ class HLS(VideoRetriever): raise HLSException(keyurl, "Can't decrypt beacuse of DRM") key = self.http.request("get", keyurl, cookies=keycookies, headers=headers).content iv = binascii.unhexlify(i["EXT-X-KEY"]["IV"][2:].zfill(32)) if "IV" in i["EXT-X-KEY"] else random_iv() - decryptor = AES.new(key, AES.MODE_CBC, iv) + backend = default_backend() + cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=backend) + decryptor = cipher.decryptor() if decryptor: - data = decryptor.decrypt(data) + data = decryptor.update(data) + decryptor.finalize() else: raise ValueError("No decryptor found for encrypted hls steam.") diff --git a/requirements.txt b/requirements.txt index 2743d22..2fcb8ad 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ requests PySocks -pycryptodome +cryptography pyyaml \ No newline at end of file diff --git a/setup.py b/setup.py index d235f42..7ef3423 100644 --- a/setup.py +++ b/setup.py @@ -18,7 +18,7 @@ with open(os.path.join(srcdir, 'svtplay_dl', '__version__.py'), 'r') as f: deps = [] deps.append("requests>=2.0.0") deps.append("PySocks") -deps.append("pycryptodome") +deps.append("cryptography") deps.append("pyyaml") setup(