widevineproxy

package module
v0.0.0-...-1005a0f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2021 License: MIT Imports: 16 Imported by: 0

README

Widevine Proxy

A Golang implementation of Google Widevine Proxy

Accreditation

This repostory is based on alfg/widevine. Thanks for his effort to create the foundation of this code.

Major Modify:

  1. Added logrus for some basic logging.

  2. Added error handling on http request, body parsing, and cryptos.

  3. Restructed the code.

Usage

Define KeyGoverner
type KeyGoverner interface {
	GenerateContentKeyID(contentID []byte) []byte
	GenerateContentKey(contentID []byte) []byte
	GenerateContentIV(contentID []byte) []byte
	GenerateContentKeySpec(contentID []byte, policyConfig map[string]string) (*[]ContentKeySpec, error)
}
New

key := []byte("Widevine Key")
iv := []byte("Widevine iv")
provider := "widevine_test"
keyGenerator := FakeKeyGoverner{}

logger := logrus.New()
/*
    Setup Logger ... 
*/

wp := NewWidevineProxy(key, iv, provider, keyGenerator, logger)
Get License
    /*
        Request License
    */
    licenseResponse, err := wp.GetLicense(contetntID, requestBody)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESCBCDecrypt

func AESCBCDecrypt(key, iv, cipherText []byte) ([]byte, error)

AESCBCDecrypt is given key, iv to decrypt the cipherText in AES CBC way.

func AESCBCEncrypt

func AESCBCEncrypt(key, iv, plainText []byte) ([]byte, error)

AESCBCEncrypt is given key, iv to encrypt the plainText in AES CBC way.

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

Types

type ClientInfo

type ClientInfo struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

type ContentKeyResponse

type ContentKeyResponse struct {
	Status      string   `json:"status"`
	DRM         []drm    `json:"drm"`
	Tracks      []tracks `json:"tracks"`
	AlreadyUsed bool     `json:"already_used"`
}

GetContentKeyResponse JSON response from Widevine Cloud. /cenc/getcontentkey/<provider>

type ContentKeySpec

type ContentKeySpec struct {
	KeyID     string `json:"key_id"`
	Key       string `json:"key"`
	IV        string `json:"iv"`
	TrackType string `json:"track_type"`
}

type KeyGoverner

type KeyGoverner interface {
	GenerateContentKeyID(contentID []byte) []byte
	GenerateContentKey(contentID []byte) []byte
	GenerateContentIV(contentID []byte) []byte
	GenerateContentKeySpec(contentID []byte, policyConfig map[string]string) (*[]ContentKeySpec, error)
}

KeyGoverner is a business logic for judging the premissions in multi-key protection

type LicenseID

type LicenseID struct {
	RequestID  string `json:"request_id"`
	SessionID  string `json:"session_id"`
	PurchaseID string `json:"purchase_id"`
	Type       string `json:"type"`
	Version    int64  `json:"version"`
}

type LicenseMessage

type LicenseMessage struct {
	Payload           string           `json:"payload"`
	ContentID         string           `json:"content_id"`
	Provider          string           `json:"provider"`
	AllowedTrackTypes string           `json:"allowed_track_types"`
	ContentKeySpecs   []ContentKeySpec `json:"content_key_specs"`
}

type LicenseMetadata

type LicenseMetadata struct {
	ContentID   string `json:"content_id"`
	LicenseType string `json:"license_type"`
	RequestType string `json:"request_type"`
}

type LicenseResponse

type LicenseResponse struct {
	Status                     string             `json:"status"`
	StatusMessage              string             `json:"status_message"`
	License                    string             `json:"license"`
	LicenseMetadata            LicenseMetadata    `json:"license_metadata"`
	SupportedTracks            []interface{}      `json:"supported_tracks"`
	Make                       string             `json:"make"`
	Model                      string             `json:"model"`
	SecurityLevel              int64              `json:"security_level"`
	InternalStatus             int64              `json:"internal_status"`
	SessionState               SessionState       `json:"session_state"`
	DRMCERTSerialNumber        string             `json:"drm_cert_serial_number"`
	DeviceWhitelistState       string             `json:"device_whitelist_state"`
	MessageType                string             `json:"message_type"`
	Platform                   string             `json:"platform"`
	DeviceState                string             `json:"device_state"`
	PsshData                   PsshData           `json:"pssh_data"`
	ClientMaxHdcpVersion       string             `json:"client_max_hdcp_version"`
	ClientInfo                 []ClientInfo       `json:"client_info"`
	SignatureExpirationSecs    int64              `json:"signature_expiration_secs"`
	PlatformVerificationStatus string             `json:"platform_verification_status"`
	ContentOwner               string             `json:"content_owner"`
	ContentProvider            string             `json:"content_provider"`
	SystemID                   int64              `json:"system_id"`
	OEMCryptoAPIVersion        int64              `json:"oem_crypto_api_version"`
	ResourceRatingTier         int64              `json:"resource_rating_tier"`
	ServiceVersionInfo         ServiceVersionInfo `json:"service_version_info"`
}

LicenseResponse decoded JSON response from Widevine Cloud. /cenc/getlicense

type Policy

type Policy struct {
	ContentID string
	Tracks    []string
	DRMTypes  []string
	Policy    string
}

Policy struct to set policy options for a ContentKey request.

type Proxy

type Proxy struct {
	PartnerRootKey      []byte
	PartnerRootIV       []byte
	Provider            string
	ContentKeyGenerator KeyGoverner

	Logger *logrus.Logger
	// contains filtered or unexported fields
}

Proxy structure.

func NewWidevineProxy

func NewWidevineProxy(key, iv []byte, provider string, keyGenerator KeyGoverner, logger *logrus.Logger) *Proxy

NewWidevineProxy creates an instance for grant widevine license with Widevine Cloud-based services.

func (*Proxy) GetContentKey

func (wp *Proxy) GetContentKey(contentID string, policy Policy) (*ContentKeyResponse, error)

GetContentKey creates a content key giving a contentID.

func (*Proxy) GetLicense

func (wp *Proxy) GetLicense(contentID string, body string) (*LicenseResponse, error)

GetLicense creates a license request used with a proxy server.

type PsshData

type PsshData struct {
	KeyID     []interface{} `json:"key_id"`
	ContentID string        `json:"content_id"`
}

type ServiceVersionInfo

type ServiceVersionInfo struct {
	LicenseSDKVersion     string `json:"license_sdk_version"`
	LicenseServiceVersion string `json:"license_service_version"`
}

type SessionState

type SessionState struct {
	LicenseID      LicenseID `json:"license_id"`
	SigningKey     string    `json:"signing_key"`
	KeyboxSystemID int64     `json:"keybox_system_id"`
	LicenseCounter int64     `json:"license_counter"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL