Playing clearkey protected mpd content in html5 dashjs player with already acquired kty k and kid values

1.4k views Asked by At

I am trying to play clearkey protected mpd file in dash.js/shaka player with already acquired kty k and kid values , for which i have written the following code but somehow unable to play it because of being a newbie to js

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Shaka Player Example: Encrypted Content with ClearKey</title>

<script src="http://cdn.shaka-player-demo.appspot.com/v2.5.9/shaka-player.compiled.js"></script>

<style>

      video {

        width: 640px;

        height: 360px;

      }

    </style>

  </head>

  <body>

    <div>

      <video id="video" poster="poster.jpg" controls autoplay></video>

    </div>

    <script>

      // Acquired kty k and kid

      var kTyK = {

        kty: "oct",

        alg: "A128KW",

        kid: "LyfQU9g9UoSFnN2LJrsX4g",

        k: "fL6zOZA4Awax9bmg+09v0A"

      };

      // Initialize the player and set up the manifest

      var manifestUri = 'example.mpd';

      var video = document.getElementById('video');

      var player = new shaka.Player(video);

      player.configure({

        drm: {

          clearKeys: {

            "key-id": kTyK.k

          },

        }

      });

      // Listen for errors and log them.

      player.addEventListener('error', function(event) {

        console.error('Error code', event.detail.code, 'object', event.detail);

      });

      // Try to load a manifest.

      player.load(manifestUri).then(function() {

        console.log('The video has now been loaded!');

      }).catch(onError);    

      function onError(error) {

        console.error('Error code', error.code, 'object', error);

      }

    </script>

  </body>

</html>

The project fails to play the video somehow and the kty k and kid are derived from a m3u playlist like below

#KODIPROP:inputstreamaddon=inputstream.adaptive

#KODIPROP:inputstream.adaptive.manifest_type=dash

#KODIPROP:inputstream.adaptive.license_type=org.w3.clearkey

#KODIPROP:inputstream.adaptive.license_key={"keys":[ {"kty":"oct","k":"fL6zOZA4Awax9bmg+09v0A","kid":"LyfQU9g9UoSFnN2LJrsX4g"}]}

#EXTINF:-1 tvg-id="Test" tvg-name="Test" group-title="Test" group-logo="Test.jpg" tvg-logo="Test.png",example

http://example.com/manifest.mpd

Any help would be appreciated and thanks in advance

I tried to play a clearkey protected mpd in dashjs/shaka player but failed to do so , the streams are being extracted from a kodi playable m3u playlist . The console gave an error decrypting the stream via key but same worked in kodi/tivimate . Any help is appreciated.

2

There are 2 answers

0
Yassine Boudra On

I think your keys are somehow encrypted, as far as I know drm keys are kind of similar to md5 encryption.

0
Anonymous Coward On

You need to provide the actual key ID, rather than the string "key-id".

Try

player.configure({
    drm: {
      clearKeys: {
        [kTyk.kid]: kTyK.k
      },
    }
  });

Note that EME requires that keys and kids are base64url encoded, which yours are not (see the + in the key). Not sure if Shaka would do that conversion automatically for you.

Note also the use of ES6 computed property names in clearkeys object.