[object Object] Icon

Encoding
Learn how to create, start, manage and modify Encodings

[object Object] Icon

Player
Learn how to create, start, manage and modify Players

[object Object] Icon

Analytics
Learn how to create, start, manage and modify Analyticss

Docs Home
User shortcuts for search
Focus by pressing f
Hide results by pressing Esc
Navigate via   keys

Thu Mar 24 2022

Streaming DRM protected content with Bitmovin Player Web SDK

Briefly About DRMLink Icon

As DRM (Digital Rights Management) protected content can be often crucial for certain streaming infrastructures, this tutorial is made to help you get started with Bitmovin Player Web SDK DRM setup as soon as possible.

In a nutshell, DRM systems provide the ability to control how people can consume your content while securing it against piracy using various encryption schemes. As the topic itself is quite complex we will not cover the details of how it works as part of this tutorial, but if you are completely new to the topic of DRM and you want to learn more you can visit our What is DRM and How Does it Work dedicated article. More advanced resources are also present in What's next section down below.

All the DRM solutions mentioned in this tutorial are self sufficient systems that can be used independently of one other.

As the device portfolio that needs to be covered for streaming across the userbase is very diverse in terms of DRM systems support, it leads to a need to use of so called Common Encryption Schema (CENC). This approach allows different DRM systems to decrypt commonly encrypted content to save the infrastructure costs. This means that Multi-DRM content packaging output supports more DRM systems so more devices can be covered.

Example of CENC present in MPEG-DASH mpd manifest file

1<!-- Common Encryption -->
2<ContentProtection
3 schemeIdUri="urn:mpeg:dash:mp4protection:2011"
4 value="cenc"
5 cenc:default_KID="8D1A585A-A0B4-A942-917A-C1B659142B2A">
6</ContentProtection>
7<!-- PlayReady -->
8<ContentProtection
9 schemeIdUri="urn:uuid:9A04F079-9840-4286-AB92-E65BE0885F95">
10</ContentProtection>
11<!-- Widevine -->
12<ContentProtection
13 schemeIdUri="urn:uuid:EDEF8BA9-79D6-4ACE-A3C8-27DCD51D21ED">
14</ContentProtection>

This tutorial will focus on DRM systems that are mainly used across the OTT industry. We will cover examples for Widevine (Google), Playready (Microsoft) and Fairplay (Apple) systems and we will also mention ClearKey enctyption system as a free security alternative. You can check the complete support list in our Bitmovin Player DRM support page.

Multi-DRM exampleLink Icon

This approach is the simplest way to setup DRM playback with Bitmovin Player to cover most devices. The DRMConfig object in the Bitmovin Player Web SDK API is used to configure the DRM details required for successful playback. This DRMConfig object is part of the SourceConfig object that gets passed to the player.load method.

Considering the stream has Multi-DRM output for Playready and Widevine, all you need to do is to add drm property to the SourceConfig object and add one property for each DRM system, containing its DRM system-specific configuration object.

The most important property to add is the license acqusition URL LA_URL, which specifies the URI to the DRM license server. Note that each DRM system configuration can differ and license servers may require additional configuration. We will try to cover some cases in other examples but full configuration options are available in our API docs.

1var config = {
2 key: '<YOUR PLAYER KEY>',
3 cast: {
4 enable: true
5 }
6};
7
8var source = {
9 dash: 'https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/mpds/11331.mpd',
10 hls: 'https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/m3u8s/11331.m3u8',
11 smooth: 'https://test.playready.microsoft.com/smoothstreaming/SSWSS720H264/SuperSpeedway_720.ism/manifest',
12 drm: {
13 widevine: {
14 LA_URL: 'https://widevine-proxy.appspot.com/proxy'
15 },
16 playready: {
17 LA_URL: 'https://playready.directtaps.net/pr/svc/rightsmanager.asmx?PlayRight=1&ContentKey=EAtsIJQPd5pFiRUrV9Layw=='
18 }
19 }
20};
21
22var player = new bitmovin.player.Player(document.getElementById('player'), config);
23
24player.load(source);

You can run this example or test your own stream on our DRM Demo Page

WidevineLink Icon

The Bitmovin Player supports Widevine system through Encrypted Media Extensions. This DRM system is available on platforms like Chrome, Firefox, MSEdge (Chromium Based), Smart TVs (LG WebOS, Samsung Tizen) and more.

Widevine is usually very easy to setup for playback using a license server URL configured via LA_URL property using the WidevineModularDRMConfig interface. The license server URL can be also defined inside of the stream manifest, but player will prefer the one defined in the DRMConfig if it is present.

Audio and video Robustness

Through the configuration it is possible to define the robustness, or security level of the DRM key system. If a string specifies a higher security level than the system is able to support playback will fail. Setting of the required security level is configurable using videoRobustness and audioRobustness properties which can have specific string value. This configuration also helps to get rid of the warning thrown by Chrome regarding the robustness.

1// SourceConfig object to be passed to Bitmovin Player instance
2var source = {
3 dash: 'https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/mpds/11331.mpd',
4 drm: {
5 widevine: {
6 LA_URL: 'https://widevine-proxy.appspot.com/proxy',
7 audioRobustness : 'HW_SECURE_DECODE',
8 videoRobustness : 'HW_SECURE_DECODE',
9 },
10 },
11};

Preparing license message

In some workflows it may be required to prepare the license acquisition message which will be sent to the license acquisition server. As many DRM providers expect different, vendor-specific message, this can be done using the prepareMessage property to which a function should be assigned. The parameter passed to the function is the key message event object as given by the Widevine Content Decryption Module (CDM). Also the prepareLicense option can be used for custom widevine servers where the response is not just the license itself, but instead the license is e.g. wrapped in an JSON object.

1// SourceConfig object to be passed to Bitmovin Player instance
2var source = {
3 dash: 'https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/mpds/11331.mpd',
4 drm: {
5 widevine: {
6 LA_URL: 'https://widevine-proxy.appspot.com/proxy',
7 prepareMessage : (keyMessage) => {
8 return keyMessage.message;
9 },
10 },
11 },
12 },
13};

The Bitmovin Player Web SDK also covers more advanced configuration options for Widevine which are described in the Widevine API docs.

PlayreadyLink Icon

The PlayReady DRM system is supported by most of the Microsoft platforms like Xbox, Internet Explorer, MS Edge on Windows 10+, and also Android TV and some Smart TVs, so its support is almost as widespread as Widevine. It is usually configured simply by providing the license server URL through the LA_URL property, similar to the way the Widevine is configured, but it can also have the license server URL present directly inside of the stream manifest or even the DRM system-specific data ("PSSH boxes") of the stream segments. Specific configurations may also be required to make PlayReady work with some platforms like Smart TVs (Samsung Tizen, LG WebOS).

Plaintext challenge

Specifies, whether the Challenge specified in the keymessage is provided in plaintext rather than being Base64 encoded. On most desktop browsers, the Challenge is Base64 encoded, which requires additional preprocessing before a license request can be sent. Devices like smart TVs or set-top boxes often already provide a plaintext challenge in the key message, so the preprocessing step can be skipped. Default value is false.

UTF-8 message

Specifies whether the keymessage provided by the browser is already UTF-8 encoded. On most desktop browsers, the keymessage is UTF-16 encoded, which requires additional preprocessing before a license request can be sent. Devices like smart TVs or set-top boxes often already provide a UTF-8 encoded key messages, so the preprocessing step can be skipped. The default value is false.

1// SourceConfig object to be passed to Bitmovin Player instance
2var source = {
3 dash: 'https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/mpds/11331.mpd',
4 drm: {
5 playready: {
6 LA_URL: 'https://playready.directtaps.net/pr/svc/rightsmanager.asmx?PlayRight=1&ContentKey=EAtsIJQPd5pFiRUrV9Layw==',
7 utf8Message: true,
8 plaintextChallenge: true,
9 headers: { 'Content-Type': 'text/xml' },
10 }
11 },
12};

Bitmovin Player also covers more advanced configuration options for PlayReady which are described in the PlayReady system API docs.

FairplayLink Icon

The Fairplay DRM system is the only DRM system that Apple platforms support, so it is often required to enable streaming of content on these devices. As it is an Apple proprietary system it is usually packed with HLS protocol and Bitmovin Player supports it with Safari native player.

To make Fairplay work some additional configuration apart from license server URL is required. Usually it is certificateURL or directly serverCertificate as ArrayBuffer that needs to get passed all along with a specific content ID. The prepareContentId callback can be used to prepare the value of the content ID, and the prepareMessage callback can be used to append the contentID to the message sent with the license request.

Fairplay configuration example with DRM Today provider

1// SourceConfig object to be passed to Bitmovin Player instance
2var source = {
3 hls: 'https://hls-manifest-url'
4 fairplay: {
5 LA_URL: 'https://license-server-url-provided-by-drmtoday',
6 certificateURL: 'https://certificate-url-provided-by-drmtoday',
7 headers: {
8 'dt-custom-data': 'INSERT-YOUR-BASE64-ENCODED-CUSTOMDATA',
9 },
10 prepareMessage : (event, session) => {
11 return 'spc=' + encodeURIComponent(event.messageBase64Encoded) + '&' + session.contentId;
12 },
13 prepareContentId : (contentId) => {
14 const pattern='skd://drmtoday?';
15 let parameters;
16 let idx = contentId.indexOf(pattern);
17
18 if (idx > -1) {
19 parameters = contentId.substring(idx + pattern.length);
20 parameters = parameters.replace(/assetid/gi, 'assetId');
21 parameters = parameters.replace(/variantid/gi, 'variantId');
22 return parameters;
23 } else {
24 return '';
25 }
26 }
27 }
28};

More examples of Fairplay implementations are present in our API docs. Also more details sbout Fairplay setup can be found in the DRM Today tutorial.

License Request HandlingLink Icon

The license request is common to all DRM systems, and is initiated by the Bitmovin Player in order to aquire the license from the provided license server. The licence is then passed into the EME API so the stream can be decrypted and played back by the device. The license request must use HTTPS and is often required to have some header configuration. Also it is worth mentioning that the web application needs to be hosted on HTTPS (or localhost for testing) in order for DRM to be made available by browsers.

If the infrastructure requires such a setup it is possile to use the headers property on the specific DRM system present in DRMConfig to add the apropriate HttpHeaders to the license requests. In addition the withCredentials property can also be configured. This will ensure that credentials such as cookies or authorization headers are sent along with the license requests.

Example Of Headers Setup

1// SourceConfig object to be passed to Bitmovin Player instance
2var source = {
3 dash: 'https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/mpds/11331.mpd',
4 hls: 'https://bitmovin-a.akamaihd.net/content/art-of-motion_drm/m3u8s/11331.m3u8',
5 smooth: 'https://test.playready.microsoft.com/smoothstreaming/SSWSS720H264/SuperSpeedway_720.ism/manifest',
6 drm: {
7 widevine: {
8 LA_URL: 'https://widevine-proxy.appspot.com/proxy',
9 headers: {
10 'custom-header': 'INSERT-VALUE'
11 },
12 withCredentials: true,
13 },
14 playready: {
15 LA_URL: 'https://playready.directtaps.net/pr/svc/rightsmanager.asmx?PlayRight=1&ContentKey=EAtsIJQPd5pFiRUrV9Layw==',
16 headers: {
17 'custom-header': 'INSERT-VALUE'
18 },
19 withCredentials: true,
20 }
21 }
22};

Using Bitmovin Player network API

It is also possible to use the network API to intercept the license requests or responses using preprocessHttpRequest or preprocessHttpResponse properties on the network configuration.

1// Bitmovin Player configuration object
2var config = {
3 key: '<YOUR PLAYER KEY>',
4 network: {
5 preprocessHttpRequest: function(type, request) {
6 if (type === bitmovin.player.HttpRequestType.DRM_LICENSE_WIDEVINE) {
7 // withCredentials = true
8 request.credentials = 'include';
9 // custom headers
10 request.headers['custom-header'] = 'INSERT-VALUE';
11 }
12 return Promise.resolve(request);
13 }
14 }
15};

ClearKey Free AlternativeLink Icon

MPEG-CENC ClearKey is implemented as part of the Media Source Extensions (MSE) and Encrypted Media Extension (EME), which enable playback of protected content in web browsers. These content protection technologies protect the actual content themselves, scrambling the video with the AES-128 algorithm in either the CTR mode for DASH or the CBC mode for HLS.

The first notable advantage is that encrypted content is unviewable without access to the decryption keys. Implementing an encryption does not carry any additional costs beyond its implementation. ClearKey handling is required by the specification within EME support for all browsers, but it could be seen primarily as a reference mechanism, rather than a commercial grade security solution.

1var config = {
2 key: "YOUR-PLAYER-LICENSE-KEY-HERE",
3};
4
5var source = {
6 dash: "https://example.com/path/to/your/clear-key/content/manifest.mpd",
7 drm: {
8 clearkey: [{
9 key: 'YOUR-KEY-HERE',
10 kid: 'YOUR-KID-HERE' //optional
11 }]
12 },
13};
14
15var player = new bitmovin.player.Player(document.getElementById('player'), config);
16
17player.load(source);

ClearKey Security Considerations

Although this approach is a handy and free alternative it is also necesery to point out some security risks that come with it. With DRM systems the content is decrypted inside of CDM which is securely encapsuled inside of the system.

Although it is possible to decrypt content via CDM using the ClearKey, the Bitmovin Player Web SDK decrypts the content in the browser and it ends up unencrypted within the JavaScript scope. Also the decryption key is available in clear format in the JavaScript scope, contrary to other DRM systems where the decryption key is within an encrypted license and never available to the JavaScript application or any insecure part of the system.

For this reason there may be a room for attacks where the unencrypted content could be ripped or the keys could be stolen to decrypt the content elsewhere. Therefore this approach is not suitable to e.g. secure proprietary content.

Smart TV specificsLink Icon

The DRM playback configuration for Smart TVs works pretty much the same way as in web browsers from the API perspective, but on certain plaforms some special handling is required to make the playback work conrectly. Bitmovin Player abstracts this logic into specific modules which are not part of the full bundle distribution and need to be added at load time.

In the case of LG WebOS, the WebOS module is required. More detailed information can be found in the LG WebOS tutorial. For Samsung Tizen there is a specific setup required which is also described in a separate Samsung Tizen tutorial.

What's nextLink Icon

API Documentaiton

Testing Resources

Github Examples

Give us feedback