Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iyear/gowidevine
🐭 Go implementation of Google's Widevine DRM CDM (Content Decryption Module)
https://github.com/iyear/gowidevine
widevine widevine-drm widevine-golang widevine-l3-decryptor
Last synced: about 1 month ago
JSON representation
🐭 Go implementation of Google's Widevine DRM CDM (Content Decryption Module)
- Host: GitHub
- URL: https://github.com/iyear/gowidevine
- Owner: iyear
- License: gpl-3.0
- Created: 2023-10-21T14:22:55.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-04-22T10:27:38.000Z (5 months ago)
- Last Synced: 2024-04-22T11:38:34.619Z (5 months ago)
- Topics: widevine, widevine-drm, widevine-golang, widevine-l3-decryptor
- Language: Go
- Homepage:
- Size: 7.04 MB
- Stars: 31
- Watchers: 2
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
gowidevine
🐭 Go implementation of Google's Widevine DRM CDM (Content Decryption Module)
## Features
- [x] Implementation of Widevine CDM/Device/Protobuf
- [x] Decrypt MP4 with Widevine key
- [x] Covered by realistic data tests
- [x] Few third-party dependencies
- [ ] License proxy server/client## Getting Started
### Install
You first need [Go](https://go.dev/) installed (version 1.18+ is required), then you can use the below Go command to
install gowidevine:```shell
go get -u github.com/iyear/gowidevine
```### Import
Import the package into your project:
```go
import "github.com/iyear/gowidevine"
```### Usage
```go
package mainimport (
"bytes"
"fmt"
"io"
"net/http"widevine "github.com/iyear/gowidevine"
"github.com/iyear/gowidevine/widevinepb"
)var (
clientID = []byte("foo")
privateKey = []byte("bar")
psshData = []byte("baz")
)func main() {
keys, err := getKeys()
if err != nil {
panic(err)
}
if len(keys) == 0 {
panic("no keys")
}for _, key := range keys {
fmt.Printf("type: %s, id: %x, key: %x\n", key.Type, key.ID, key.Key)
}err = widevine.DecryptMP4(bytes.NewBufferString("encrypted data"),
keys[0].Key, io.Discard)
if err != nil {
panic(err)
}
}func getKeys() ([]*widevine.Key, error) {
// Create device from raw data or from wvd file
device, err := widevine.NewDevice(
widevine.FromRaw(clientID, privateKey),
// widevine.FromWVD(bytes.NewReader([]byte("baz"))),
)
if err != nil {
return nil, fmt.Errorf("create device: %w", err)
}
// Create CDM
cdm := widevine.NewCDM(device)// Parse PSSH
pssh, err := widevine.NewPSSH(psshData)
if err != nil {
return nil, fmt.Errorf("parse pssh: %w", err)
}// Get license challenge
challenge, parseLicense, err := cdm.GetLicenseChallenge(pssh, widevinepb.LicenseType_AUTOMATIC, false)
if err != nil {
return nil, fmt.Errorf("get license challenge: %w", err)
}
// Or use privacy mode
cert, err := getServiceCert()
if err != nil {
return nil, fmt.Errorf("get service cert: %w", err)
}
challenge, parseLicense, err = cdm.GetLicenseChallenge(pssh, widevinepb.LicenseType_AUTOMATIC, true, cert)
if err != nil {
return nil, fmt.Errorf("get license challenge: %w", err)
}// Send challenge to license server
resp, err := http.DefaultClient.Do(&http.Request{Body: io.NopCloser(bytes.NewReader(challenge))})
if err != nil {
return nil, fmt.Errorf("request license: %w", err)
}
defer func() { _ = resp.Body.Close() }()license, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("read resp: %w", err)
}// Parse license
keys, err := parseLicense(license)
if err != nil {
return nil, fmt.Errorf("parse license: %w", err)
}return keys, nil
}func getServiceCert() (*widevinepb.DrmCertificate, error) {
resp, err := http.DefaultClient.Do(&http.Request{Body: io.NopCloser(bytes.NewReader(widevine.ServiceCertificateRequest))})
if err != nil {
return nil, fmt.Errorf("request service cert: %w", err)
}
defer func() { _ = resp.Body.Close() }()serviceCert, err := io.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("read response: %w", err)
}cert, err := widevine.ParseServiceCert(serviceCert)
if err != nil {
return nil, fmt.Errorf("parse service cert: %w", err)
}return cert, nil
}
```## Thanks
- [pywidevine](https://github.com/rlaphoenix/pywidevine)
- [mp4ff](https://github.com/Eyevinn/mp4ff/)## Disclaimer
- The project does not provide Google-provisioned private key and client id except for test purpose.
- The project does not condone piracy or any action against the terms of the DRM systems.
- The project is for study and research only, please do not use it for commercial purposes.## License
GPLv3 License