Browse Source

Revert "Upgrade aes-decrypter to use webcrypto for HLSe decryption where available. (#777)" (#922)

This reverts commit b9692e29de.
pull/6/head
Jon-Carlos Rivera 9 years ago
committed by GitHub
parent
commit
933d38457e
  1. 2
      package.json
  2. 27
      src/segment-loader.js
  3. 25
      test/segment-loader.test.js

2
package.json

@ -89,7 +89,7 @@
"test/" "test/"
], ],
"dependencies": { "dependencies": {
"aes-decrypter": "^2.0.0",
"aes-decrypter": "^1.0.3",
"global": "^4.3.0", "global": "^4.3.0",
"m3u8-parser": "^1.0.2", "m3u8-parser": "^1.0.2",
"mux.js": "^3.0.0", "mux.js": "^3.0.0",

27
src/segment-loader.js

@ -4,7 +4,7 @@
import {getMediaInfoForTime_ as getMediaInfoForTime} from './playlist'; import {getMediaInfoForTime_ as getMediaInfoForTime} from './playlist';
import videojs from 'video.js'; import videojs from 'video.js';
import SourceUpdater from './source-updater'; import SourceUpdater from './source-updater';
import {decrypt} from 'aes-decrypter';
import {Decrypter} from 'aes-decrypter';
import Config from './config'; import Config from './config';
import window from 'global/window'; import window from 'global/window';
@ -721,6 +721,7 @@ export default class SegmentLoader extends videojs.EventTarget {
let segmentInfo; let segmentInfo;
let segment; let segment;
let keyXhrRequest; let keyXhrRequest;
let view;
// timeout of previously aborted request // timeout of previously aborted request
if (!this.xhr_ || if (!this.xhr_ ||
@ -803,7 +804,13 @@ export default class SegmentLoader extends videojs.EventTarget {
return this.trigger('error'); return this.trigger('error');
} }
segment.key.bytes = new Uint8Array(request.response);
view = new DataView(request.response);
segment.key.bytes = new Uint32Array([
view.getUint32(0),
view.getUint32(4),
view.getUint32(8),
view.getUint32(12)
]);
// if the media sequence is greater than 2^32, the IV will be incorrect // if the media sequence is greater than 2^32, the IV will be incorrect
// assuming 10s segments, that would be about 1300 years // assuming 10s segments, that would be about 1300 years
@ -882,14 +889,14 @@ export default class SegmentLoader extends videojs.EventTarget {
// this is an encrypted segment // this is an encrypted segment
// incrementally decrypt the segment // incrementally decrypt the segment
/* eslint-disable no-new, handle-callback-err */ /* eslint-disable no-new, handle-callback-err */
decrypt(segmentInfo.encryptedBytes,
segment.key.bytes,
segment.key.iv,
(function(err, bytes) {
// err always null
segmentInfo.bytes = bytes;
this.handleSegment_();
}).bind(this));
new Decrypter(segmentInfo.encryptedBytes,
segment.key.bytes,
segment.key.iv,
(function(err, bytes) {
// err always null
segmentInfo.bytes = bytes;
this.handleSegment_();
}).bind(this));
/* eslint-enable */ /* eslint-enable */
} else { } else {
this.handleSegment_(); this.handleSegment_();

25
test/segment-loader.test.js

@ -847,12 +847,8 @@ QUnit.test('the key is saved to the segment in the correct format', function(ass
segment = segmentInfo.playlist.segments[segmentInfo.mediaIndex]; segment = segmentInfo.playlist.segments[segmentInfo.mediaIndex];
assert.deepEqual(segment.key.bytes, assert.deepEqual(segment.key.bytes,
new Uint8Array([
0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00,
0x02, 0x00, 0x00, 0x00,
0x03, 0x00, 0x00, 0x00]),
'passed the specified segment key');
new Uint32Array([0, 0x01000000, 0x02000000, 0x03000000]),
'passed the specified segment key');
// verify stats // verify stats
assert.equal(loader.mediaBytesTransferred, 10, '10 bytes'); assert.equal(loader.mediaBytesTransferred, 10, '10 bytes');
@ -897,21 +893,15 @@ QUnit.test('segment with key has decrypted bytes appended during processing', fu
let keyRequest; let keyRequest;
let segmentRequest; let segmentRequest;
let doneDecrypting = assert.async();
// stop processing so we can examine segment info // stop processing so we can examine segment info
loader.handleSegment_ = function() {
assert.ok(loader.pendingSegment_.bytes, 'decrypted bytes in segment');
doneDecrypting();
};
loader.handleSegment_ = function() {};
loader.playlist(playlistWithDuration(10, {isEncrypted: true})); loader.playlist(playlistWithDuration(10, {isEncrypted: true}));
loader.mimeType(this.mimeType); loader.mimeType(this.mimeType);
loader.load(); loader.load();
segmentRequest = this.requests.pop(); segmentRequest = this.requests.pop();
// this response is [0, 1, 2, 3, 4, 5, 6, 7] encrypted
segmentRequest.response = new Uint8Array([60, 15, 94, 17, 13, 247, 26, 97, 97, 236, 17, 188, 250, 16, 52, 39]).buffer;
segmentRequest.response = new Uint8Array(8).buffer;
segmentRequest.respond(200, null, ''); segmentRequest.respond(200, null, '');
assert.ok(loader.pendingSegment_.encryptedBytes, 'encrypted bytes in segment'); assert.ok(loader.pendingSegment_.encryptedBytes, 'encrypted bytes in segment');
assert.ok(!loader.pendingSegment_.bytes, 'no decrypted bytes in segment'); assert.ok(!loader.pendingSegment_.bytes, 'no decrypted bytes in segment');
@ -921,10 +911,13 @@ QUnit.test('segment with key has decrypted bytes appended during processing', fu
keyRequest.respond(200, null, ''); keyRequest.respond(200, null, '');
// Allow the decrypter to decrypt // Allow the decrypter to decrypt
this.clock.tick(1000);
this.clock.tick(1);
// Allow the decrypter's async stream to run the callback
this.clock.tick(1);
assert.ok(loader.pendingSegment_.bytes, 'decrypted bytes in segment');
// verify stats // verify stats
assert.equal(loader.mediaBytesTransferred, 16, '16 bytes');
assert.equal(loader.mediaBytesTransferred, 8, '8 bytes');
assert.equal(loader.mediaRequests, 1, '1 request'); assert.equal(loader.mediaRequests, 1, '1 request');
}); });

Loading…
Cancel
Save