From 54596dd3564d6e20ab00ccab9fc5cf8e6ae8c8ff Mon Sep 17 00:00:00 2001 From: Chris Fillmore Date: Wed, 17 May 2017 14:56:16 -0400 Subject: [PATCH 1/3] Add check in DrmEngine#unpackPlayReadyRequest_ to see if license message is wrapped in XML. --- CONTRIBUTORS | 1 + lib/media/drm_engine.js | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 75db7a0b2a..10898aeabd 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -24,6 +24,7 @@ Andy Hochhaus Chad Assareh +Chris Fillmore Costel Madalin Grecu Donato Borrello Duc Pham diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index e653406efb..43e429fcdc 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -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); + + if (xml.indexOf(' // - var xml = shaka.util.StringUtils.fromUTF16( + xml = shaka.util.StringUtils.fromUTF16( request.body, true /* littleEndian */); var dom = new DOMParser().parseFromString(xml, 'application/xml'); From 8da0342209727707fc63dfe62b643fdbb4f9cc5d Mon Sep 17 00:00:00 2001 From: Chris Fillmore Date: Wed, 17 May 2017 14:56:16 -0400 Subject: [PATCH 2/3] Add check in DrmEngine#unpackPlayReadyRequest_ to see if license message is wrapped in XML. --- CONTRIBUTORS | 1 + lib/media/drm_engine.js | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c3d355cb3b..aa15ac0c4c 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -24,6 +24,7 @@ Andy Hochhaus Chad Assareh +Chris Fillmore Costel Madalin Grecu Donato Borrello Duc Pham diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index e653406efb..43e429fcdc 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -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); + + if (xml.indexOf(' // - var xml = shaka.util.StringUtils.fromUTF16( + xml = shaka.util.StringUtils.fromUTF16( request.body, true /* littleEndian */); var dom = new DOMParser().parseFromString(xml, 'application/xml'); From 199e6f0c31f542f0f50044ac7c327401a4cf7704 Mon Sep 17 00:00:00 2001 From: Chris Fillmore Date: Wed, 17 May 2017 16:38:32 -0400 Subject: [PATCH 3/3] Wrap `request.body` in `new Uint8Array`, since it is typed as an ArrayBuffer. --- lib/media/drm_engine.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index 43e429fcdc..f1cea0c0e2 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -1112,7 +1112,7 @@ shaka.media.DrmEngine.prototype.unpackPlayReadyRequest_ = function(request) { // 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); + var xml = String.fromCharCode.apply(null, new Uint8Array(request.body)); if (xml.indexOf('