Skip to content

Commit

Permalink
Add support for 'individualization-request'.
Browse files Browse the repository at this point in the history
There is now a separate server URL for 'individualization-request'
messages; if it isn't given, it will fallback to the license server.
There is also a new field in the Request object so a request filter
can act differently based on the message type.

Closes #1565

Change-Id: I970a8651ef05ec533d9fd41841cb52021e3c0489
  • Loading branch information
TheModMaker committed Sep 5, 2018
1 parent b5637db commit 66bdd49
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 35 deletions.
8 changes: 7 additions & 1 deletion externs/shaka/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ shaka.extern.RetryParameters;
* body: ArrayBuffer,
* headers: !Object.<string, string>,
* allowCrossSiteCredentials: boolean,
* retryParameters: !shaka.extern.RetryParameters
* retryParameters: !shaka.extern.RetryParameters,
* licenseRequestType: ?string
* }}
*
* @description
Expand All @@ -81,6 +82,11 @@ shaka.extern.RetryParameters;
* requests. See {@link https://bit.ly/CorsCred}.
* @property {!shaka.extern.RetryParameters} retryParameters
* An object used to define how often to make retries.
* @property {?string} licenseRequestType
* If this is a LICENSE request, this field contains the type of license
* request it is (not the type of license). This is the |messageType| field
* of the EME message. For example, this could be 'license-request' or
* 'license-renewal'.
*
* @exportDoc
*/
Expand Down
8 changes: 6 additions & 2 deletions externs/shaka/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ shaka.extern.DashContentProtectionCallback;
* persistentStateRequired: boolean,
* videoRobustness: string,
* audioRobustness: string,
* serverCertificate: Uint8Array
* serverCertificate: Uint8Array,
* individualizationServer: string
* }}
*
* @property {boolean} distinctiveIdentifierRequired
Expand All @@ -465,6 +466,9 @@ shaka.extern.DashContentProtectionCallback;
* A key-system-specific server certificate used to encrypt license requests.
* Its use is optional and is meant as an optimization to avoid a round-trip
* to request a certificate.
* @property {string} individualizationServer
* The server that handles an 'individualiation-request'. If the server isn't
* given, it will default to the license server.
*
* @exportDoc
*/
Expand All @@ -485,7 +489,7 @@ shaka.extern.AdvancedDrmConfiguration;
* @property {!Object.<string, string>} servers
* <i>Required for all but the clear key CDM.</i> <br>
* A dictionary which maps key system IDs to their license servers.
* For example, {'com.widevine.alpha': 'http://example.com/drm'}.
* For example, {'com.widevine.alpha': 'https://example.com/drm'}.
* @property {!Object.<string, string>} clearKeys
* <i>Forces the use of the Clear Key CDM.</i>
* A map of key IDs (hex) to keys (hex).
Expand Down
10 changes: 9 additions & 1 deletion lib/media/drm_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1245,11 +1245,19 @@ shaka.media.DrmEngine.prototype.sendLicenseRequest_ = function(event) {
}
}

let url = this.currentDrmInfo_.licenseServerUri;
const advancedConfig = this.config_.advanced[this.currentDrmInfo_.keySystem];
if (event.messageType == 'individualization-request' && advancedConfig &&
advancedConfig.individualizationServer) {
url = advancedConfig.individualizationServer;
}

const requestType = shaka.net.NetworkingEngine.RequestType.LICENSE;
let request = shaka.net.NetworkingEngine.makeRequest(
[this.currentDrmInfo_.licenseServerUri], this.config_.retryParameters);
[url], this.config_.retryParameters);
request.body = event.message;
request.method = 'POST';
request.licenseRequestType = event.messageType;
// NOTE: allowCrossSiteCredentials can be set in a request filter.

if (this.currentDrmInfo_.keySystem == 'com.microsoft.playready' ||
Expand Down
4 changes: 2 additions & 2 deletions lib/net/networking_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,15 @@ shaka.net.NetworkingEngine.defaultRetryParameters =
* @param {shaka.extern.RetryParameters} retryParams
* @return {shaka.extern.Request}
*/
shaka.net.NetworkingEngine.makeRequest = function(
uris, retryParams) {
shaka.net.NetworkingEngine.makeRequest = function(uris, retryParams) {
return {
uris: uris,
method: 'GET',
body: null,
headers: {},
allowCrossSiteCredentials: false,
retryParameters: retryParams,
licenseRequestType: null,
};
};

Expand Down
1 change: 1 addition & 0 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -2347,6 +2347,7 @@ shaka.Player.prototype.configOverrides_ = function() {
videoRobustness: '',
audioRobustness: '',
serverCertificate: new Uint8Array(0),
individualizationServer: '',
},
};
};
Expand Down
80 changes: 51 additions & 29 deletions test/media/drm_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,7 @@ describe('DrmEngine', function() {
audioRobustness: 'good',
videoRobustness: 'really_really_ridiculously_good',
serverCertificate: null,
individualizationServer: '',
distinctiveIdentifierRequired: true,
persistentStateRequired: true,
};
Expand Down Expand Up @@ -546,6 +547,7 @@ describe('DrmEngine', function() {
audioRobustness: 'bad',
videoRobustness: 'so_bad_it_hurts',
serverCertificate: null,
individualizationServer: '',
distinctiveIdentifierRequired: false,
persistentStateRequired: false,
};
Expand Down Expand Up @@ -902,44 +904,34 @@ describe('DrmEngine', function() {
});

it('triggers a license request', async () => {
await initAndAttach();
let initData = new Uint8Array(0);
mockVideo.on['encrypted'](
{initDataType: 'webm', initData: initData, keyId: null});

let operation = shaka.util.AbortableOperation.completed({});
fakeNetEngine.request.and.returnValue(operation);
let message = new Uint8Array(0);
session1.on['message']({target: session1, message: message});

expect(fakeNetEngine.request).toHaveBeenCalledWith(
shaka.net.NetworkingEngine.RequestType.LICENSE,
jasmine.objectContaining({
uris: ['http://abc.drm/license'],
method: 'POST',
body: message,
}));
await sendMessageTest('http://abc.drm/license');
});

it('prefers a license server URI from DrmInfo', async () => {
manifest.periods[0].variants[0].drmInfos[0].licenseServerUri =
'http://foo.bar/drm';
await sendMessageTest('http://foo.bar/drm');
});

await initAndAttach();
let initData = new Uint8Array(0);
mockVideo.on['encrypted'](
{initDataType: 'webm', initData: initData, keyId: null});

let operation = shaka.util.AbortableOperation.completed({});
fakeNetEngine.request.and.returnValue(operation);
let message = new Uint8Array(0);
session1.on['message']({target: session1, message: message});
it('handles "individualization-request" messages special', async () => {
config.advanced['drm.abc'] = createAdvancedConfig(null);
config.advanced['drm.abc'].individualizationServer =
'http://foo.bar/drm';
expect(config.servers['drm.abc']).not.toBe('http://foo.bar/drm');

expect(fakeNetEngine.request).toHaveBeenCalledWith(
shaka.net.NetworkingEngine.RequestType.LICENSE,
jasmine.objectContaining({uris: ['http://foo.bar/drm']}));
await sendMessageTest(
'http://foo.bar/drm', 'individualization-request');
});

it('uses license server for "individualization-request" by default',
async () => {
config.advanced['drm.abc'] = createAdvancedConfig(null);
config.advanced['drm.abc'].individualizationServer = '';

await sendMessageTest(
'http://abc.drm/license', 'individualization-request');
});

it('dispatches an error if license request fails', async () => {
onErrorSpy.and.stub();

Expand Down Expand Up @@ -973,6 +965,34 @@ describe('DrmEngine', function() {
data: ['http://abc.drm/license', 403],
})));
});

/**
* @param {string=} expectedUrl
* @param {string=} messageType
* @return {!Promise}
*/
async function sendMessageTest(
expectedUrl, messageType = 'license-request') {
await initAndAttach();
let initData = new Uint8Array(0);
mockVideo.on['encrypted'](
{initDataType: 'webm', initData: initData, keyId: null});

let operation = shaka.util.AbortableOperation.completed({});
fakeNetEngine.request.and.returnValue(operation);
let message = new Uint8Array(0);
session1.on['message'](
{target: session1, message: message, messageType: messageType});

expect(fakeNetEngine.request).toHaveBeenCalledWith(
shaka.net.NetworkingEngine.RequestType.LICENSE,
jasmine.objectContaining({
uris: [expectedUrl],
method: 'POST',
body: message,
licenseRequestType: messageType,
}));
}
}); // describe('message')

describe('keystatuseschange', function() {
Expand Down Expand Up @@ -1676,6 +1696,7 @@ describe('DrmEngine', function() {
videoRobustness: 'really_really_ridiculously_good',
distinctiveIdentifierRequired: true,
serverCertificate: null,
individualizationServer: '',
persistentStateRequired: true,
};
drmEngine.configure(config);
Expand Down Expand Up @@ -2044,6 +2065,7 @@ describe('DrmEngine', function() {
distinctiveIdentifierRequired: false,
persistentStateRequired: false,
serverCertificate: serverCert,
individualizationServer: '',
videoRobustness: '',
};
}
Expand Down

0 comments on commit 66bdd49

Please sign in to comment.