diff --git a/CONTRIBUTORS b/CONTRIBUTORS index e9c178840..d522c44c7 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -26,6 +26,7 @@ Aaron Vaage Alvaro Velad Galvan Andy Hochhaus Benjamin Wallberg +Boris Cupac Bryan Huh Chad Assareh Chris Fillmore diff --git a/lib/media/drm_engine.js b/lib/media/drm_engine.js index 4defd2738..689cdc9b0 100644 --- a/lib/media/drm_engine.js +++ b/lib/media/drm_engine.js @@ -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)); }; diff --git a/lib/util/uint8array_utils.js b/lib/util/uint8array_utils.js index 544054483..16e9c2650 100644 --- a/lib/util/uint8array_utils.js +++ b/lib/util/uint8array_utils.js @@ -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 @@ -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.