Giter VIP home page Giter VIP logo

pywidevine's Introduction

pywidevine
Python Widevine CDM implementation

Build status Python version DeepSource

Linter: Ruff Dependency management: Poetry

Features

  • ๐Ÿš€ Seamless Installation via pip
  • ๐Ÿ›ก๏ธ Robust Security with message signature verification
  • ๐Ÿ™ˆ Privacy Mode with Service Certificates
  • ๐ŸŒ Servable CDM API Server and Client with Authentication
  • ๐Ÿ“ฆ Custom provision serialization format (WVD v2)
  • ๐Ÿงฐ Create, parse, or convert PSSH headers with ease
  • ๐Ÿ—ƒ๏ธ User-friendly YAML configuration
  • โค๏ธ Forever FOSS!

Installation

$ pip install pywidevine

Note If pip gives you a warning about a path not being in your PATH environment variable then promptly add that path then close all open command prompt/terminal windows, or pywidevine CLI won't work as it will not be found.

Voilร  ๐ŸŽ‰ โ€” You now have the pywidevine package installed!
You can now import pywidevine in scripts (see below).
A command-line interface is also available, try pywidevine --help.

Usage

The following is a minimal example of using pywidevine in a script to get a License for Bitmovin's Art of Motion Demo.

from pywidevine.cdm import Cdm
from pywidevine.device import Device
from pywidevine.pssh import PSSH

import requests

# prepare pssh
pssh = PSSH("AAAAW3Bzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAADsIARIQ62dqu8s0Xpa"
            "7z2FmMPGj2hoNd2lkZXZpbmVfdGVzdCIQZmtqM2xqYVNkZmFsa3IzaioCSEQyAA==")

# load device
device = Device.load("C:/Path/To/A/Provision.wvd")

# load cdm
cdm = Cdm.from_device(device)

# open cdm session
session_id = cdm.open()

# get license challenge
challenge = cdm.get_license_challenge(session_id, pssh)

# send license challenge (assuming a generic license server SDK with no API front)
licence = requests.post("https://...", data=challenge)
licence.raise_for_status()

# parse license challenge
cdm.parse_license(session_id, licence.content)

# print keys
for key in cdm.get_keys(session_id):
    print(f"[{key.type}] {key.kid.hex}:{key.key.hex()}")

# close session, disposes of session data
cdm.close(session_id)

Note There are various features not shown in this specific example like:

  • Privacy Mode
  • Setting Service Certificates
  • Remote CDMs and Serving
  • Choosing a License Type to request
  • Creating WVD files
  • and much more!

Take a look at the methods available in the Cdm class and their doc-strings for further information. For more examples see the CLI functions which uses a lot of previously mentioned features.

Disclaimer

  1. This project requires a valid Google-provisioned Private Key and Client Identification blob which are not provided by this project.
  2. Public test provisions are available and provided by Google to use for testing projects such as this one.
  3. License Servers have the ability to block requests from any provision, and are likely already blocking test provisions on production endpoints.
  4. This project does not condone piracy or any action against the terms of the DRM systems.
  5. All efforts in this project have been the result of Reverse-Engineering, Publicly available research, and Trial & Error.

Key and Output Security

Licenses, Content Keys, and Decrypted Data is not secure in this CDM implementation.

The Content Decryption Module is meant to do all downloading, decrypting, and decoding of content, not just license acquisition. This Python implementation only does License Acquisition within the CDM.

The section of which a 'Decrypt Frame' call is made would be more of a 'Decrypt File' in this implementation. Just returning the original file in plain text defeats the point of the DRM. Even if 'Decrypt File' was somehow secure, the Content Keys used to decrypt the files are already exposed to the caller anyway, allowing them to manually decrypt.

An attack on a 'Decrypt Frame' system would be analogous to doing an HDMI capture or similar attack. This is because it would require re-encoding the video by splicing each individual frame with the right frame-rate, syncing to audio, and more.

While a 'Decrypt Video' system would be analogous to downloading a Video and passing it through a script. Not much of an attack if at all. The only protection against a system like this would be monitoring the provision and acquisitions of licenses and prevent them. This can be done by revoking the device provision, or the user or their authorization to the service.

There isn't any immediate way to secure either Key or Decrypted information within a Python environment that is not Hardware backed. Even if obfuscation or some other form of Security by Obscurity was used, this is a Software-based Content Protection Module (in Python no less) with no hardware backed security. It would be incredibly trivial to break any sort of protection against retrieving the original video data.

Though, it's not impossible. Google's Chrome Browser CDM is a simple library extension file programmed in C++ that has been improving its security using math and obscurity for years. It's getting harder and harder to break with its latest versions only being beaten by Brute-force style methods. However, they have a huge team of very skilled workers, and making a CDM in C++ has immediate security benefits and a lot of methods to obscure and obfuscate the code.

Contributors

Licensing

This software is licensed under the terms of GNU General Public License, Version 3.0.
You can find a copy of the license in the LICENSE file in the root folder.

  • Widevine Icon ยฉ Google.
  • Props to the awesome community for their shared research and insight into the Widevine Protocol and Key Derivation.

ยฉ rlaphoenix 2022-2023

pywidevine's People

Contributors

rlaphoenix avatar dependabot[bot] avatar mediaminister avatar sr0lle avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.