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

Fix to FairPlay request license #1932

Merged
merged 1 commit into from
May 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Aaron Vaage <[email protected]>
Alvaro Velad Galvan <[email protected]>
Andy Hochhaus <[email protected]>
Benjamin Wallberg <[email protected]>
Boris Cupac <[email protected]>
Bryan Huh <[email protected]>
Chad Assareh <[email protected]>
Chris Fillmore <[email protected]>
Expand Down
5 changes: 3 additions & 2 deletions lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1332,10 +1332,11 @@ shaka.media.DrmEngine.prototype.formatFairPlayRequest_ = function(request) {
// The standard format for FairPlay seems to be to place the request into a
// POST parameter (spc=).
const originalPayload = new Uint8Array(request.body);
const base64Payload = shaka.util.Uint8ArrayUtils.toBase64(originalPayload);
const base64Payload = shaka.util.
Uint8ArrayUtils.toStandardBase64(originalPayload);
const params = 'spc=' + base64Payload;
request.headers['Content-Type'] = 'application/x-www-form-urlencoded';
request.body = shaka.util.StringUtils.toUTF8(params);
request.body = shaka.util.StringUtils.toUTF8(encodeURIComponent(params));
};


Expand Down
18 changes: 14 additions & 4 deletions lib/util/uint8array_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ goog.require('shaka.util.StringUtils');
* @exportDoc
*/

/**
* Convert a Uint8Array to a base64 string. The output will be standard alphabet
* as opposed to base64url safe alphabet.
* @param {!Uint8Array} u8Arr
* @return {string}
* @export
*/

shaka.util.Uint8ArrayUtils.toStandardBase64 = function(u8Arr) {
const bytes = shaka.util.StringUtils.fromCharCode(u8Arr);
return btoa(bytes);
};

/**
* Convert a Uint8Array to a base64 string. The output will always use the
Expand All @@ -37,14 +49,12 @@ goog.require('shaka.util.StringUtils');
* @export
*/
shaka.util.Uint8ArrayUtils.toBase64 = function(arr, padding) {
// btoa expects a "raw string" where each character is interpreted as a byte.
const bytes = shaka.util.StringUtils.fromCharCode(arr);
padding = (padding == undefined) ? true : padding;
const base64 = window.btoa(bytes).replace(/\+/g, '-').replace(/\//g, '_');
const base64 = shaka.util.Uint8ArrayUtils.toStandardBase64(arr)
.replace(/\+/g, '-').replace(/\//g, '_');
return padding ? base64 : base64.replace(/=*$/, '');
};


/**
* Convert a base64 string to a Uint8Array. Accepts either the standard
* alphabet or the alternate "base64url" alphabet.
Expand Down