fe69162d by Rajko Stojadinovic Committed by David LaPalomento

Properly parse the IV in m3u8 AES-128 encryption method, and actually use it to decrypt if present

1 parent 906d9cba
...@@ -305,6 +305,9 @@ ...@@ -305,6 +305,9 @@
305 event.attributes = parseAttributes(match[1]); 305 event.attributes = parseAttributes(match[1]);
306 // parse the IV string into a Uint32Array 306 // parse the IV string into a Uint32Array
307 if (event.attributes.IV) { 307 if (event.attributes.IV) {
308 if (event.attributes.IV.substring(0,2) == '0x')
309 event.attributes.IV = event.attributes.IV.substring(2);
310
308 event.attributes.IV = event.attributes.IV.match(/.{8}/g); 311 event.attributes.IV = event.attributes.IV.match(/.{8}/g);
309 event.attributes.IV[0] = parseInt(event.attributes.IV[0], 16); 312 event.attributes.IV[0] = parseInt(event.attributes.IV[0], 16);
310 event.attributes.IV[1] = parseInt(event.attributes.IV[1], 16); 313 event.attributes.IV[1] = parseInt(event.attributes.IV[1], 16);
...@@ -436,7 +439,8 @@ ...@@ -436,7 +439,8 @@
436 // setup an encryption key for upcoming segments 439 // setup an encryption key for upcoming segments
437 key = { 440 key = {
438 method: entry.attributes.METHOD || 'AES-128', 441 method: entry.attributes.METHOD || 'AES-128',
439 uri: entry.attributes.URI 442 uri: entry.attributes.URI,
443 iv: entry.attributes.IV || null
440 }; 444 };
441 }, 445 },
442 'media-sequence': function() { 446 'media-sequence': function() {
......
...@@ -704,11 +704,13 @@ videojs.Hls.prototype.drainBuffer = function(event) { ...@@ -704,11 +704,13 @@ videojs.Hls.prototype.drainBuffer = function(event) {
704 } else { 704 } else {
705 // if the media sequence is greater than 2^32, the IV will be incorrect 705 // if the media sequence is greater than 2^32, the IV will be incorrect
706 // assuming 10s segments, that would be about 1300 years 706 // assuming 10s segments, that would be about 1300 years
707 var theIv = segment.key.iv;
708 if (theIv === null) {
709 theIv = new Uint32Array([0, 0, 0, mediaIndex + playlist.mediaSequence]);
710 }
707 bytes = videojs.Hls.decrypt(bytes, 711 bytes = videojs.Hls.decrypt(bytes,
708 segment.key.bytes, 712 segment.key.bytes,
709 new Uint32Array([ 713 theIv);
710 0, 0, 0,
711 mediaIndex + playlist.mediaSequence]));
712 } 714 }
713 } 715 }
714 716
......