Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if PlayReady license message is wrapped in XML. #815

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

Andy Hochhaus <ahochhaus@samegoal.com>
Chad Assareh <assareh@google.com>
Chris Fillmore <fillmore.chris@gmail.com>
Costel Madalin Grecu <madalin.grecu@adswizz.com>
Donato Borrello <donato@jwplayer.com>
Duc Pham <duc.pham@edgeware.tv>
Expand Down
18 changes: 14 additions & 4 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1106,9 +1106,19 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) {
* @private
*/
shaka.media.DrmEngine.prototype.unpackPlayReadyRequest_ = function(request) {
// The PlayReady license message as it comes from the CDM can't be directly
// delivered to a license server. Other CDMs do not seem to need this kind
// of special handling.
// PlayReady CDMs in some clients (e.g. IE11, Edge) wrap the license message
// in UTF-16 encoded XML which can't be directly delivered to a license
// server. However, not all clients exhibit this behaviour. The Tizen
// PlayReady CDM message is UTF-8 encoded and can be passed to the license
// server as-is. Other CDMs do not seem to need this kind of special
// handling.
var xml = String.fromCharCode.apply(null, request.body);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

request.body is typed as an ArrayBuffer, so you will need to wrap that in "new Uint8Array".

Here's a demo of fromCharCode applied to both a Uint8Array and an ArrayBuffer:

u = new Uint8Array([61, 62, 63, 64, 65]);

String.fromCharCode.apply(null, u);
"=>?@A"

String.fromCharCode.apply(null, u.buffer);
""

If request.body is a Uint8Array at runtime, wrapping it again will not cause a problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.


if (xml.indexOf('<PlayReadyKeyMessage') !== 0) {
// The message is not wrapped.
request.headers['Content-Type'] = 'text/xml; charset=utf-8';
return;
}

// The raw license message is UTF-16-encoded XML. We need to unpack the
// Challenge element (base64-encoded string containing the actual license
Expand All @@ -1132,7 +1142,7 @@ shaka.media.DrmEngine.prototype.unpackPlayReadyRequest_ = function(request) {
// </LicenseAcquisition>
// </PlayReadyKeyMessage>

var xml = shaka.util.StringUtils.fromUTF16(
xml = shaka.util.StringUtils.fromUTF16(
request.body, true /* littleEndian */);
var dom = new DOMParser().parseFromString(xml, 'application/xml');

Expand Down