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 @@
event.attributes = parseAttributes(match[1]);
// parse the IV string into a Uint32Array
if (event.attributes.IV) {
if (event.attributes.IV.substring(0,2) == '0x')
event.attributes.IV = event.attributes.IV.substring(2);
event.attributes.IV = event.attributes.IV.match(/.{8}/g);
event.attributes.IV[0] = parseInt(event.attributes.IV[0], 16);
event.attributes.IV[1] = parseInt(event.attributes.IV[1], 16);
......@@ -436,7 +439,8 @@
// setup an encryption key for upcoming segments
key = {
method: entry.attributes.METHOD || 'AES-128',
uri: entry.attributes.URI
uri: entry.attributes.URI,
iv: entry.attributes.IV || null
};
},
'media-sequence': function() {
......
......@@ -704,11 +704,13 @@ videojs.Hls.prototype.drainBuffer = function(event) {
} else {
// if the media sequence is greater than 2^32, the IV will be incorrect
// assuming 10s segments, that would be about 1300 years
var theIv = segment.key.iv;
if (theIv === null) {
theIv = new Uint32Array([0, 0, 0, mediaIndex + playlist.mediaSequence]);
}
bytes = videojs.Hls.decrypt(bytes,
segment.key.bytes,
new Uint32Array([
0, 0, 0,
mediaIndex + playlist.mediaSequence]));
theIv);
}
}
......