How to decrypt encrypted m3u8 AES-128 video files?

I am trying to decrypt encrypted m3u8 AES-128 video files such as:

m3u8 file:

#EXTM3U #EXT-X-MEDIA-SEQUENCE:0 #EXT-X-ALLOW-CACHE:NO #EXT-X-VERSION:2 #EXT-X-FAXS-CM:MII6lAYJKoZIhvcNAQcCoII6hTCCOoECAQExCzAJBgUrDgMCGgUAM... very long key... #EXT-X-KEY:METHOD=AES-128,URI="faxs://faxs.adobe.com",IV=0X99b74007b6254e4bd1c6e03631cad15b #EXT-X-TARGETDURATION:8 #EXTINF:8, video.mp4Frag1Num0.ts #EXTINF:8, video.mp4Frag1Num1.ts ... 

I tried with openssl:

 openssl aes-128-cbc -d -kfile key.txt -iv 99b74007b6254e4bd1c6e03631cad15b -nosalt -in video_enc.ts -out video_dec.ts 

key.txt contains a very long key ->

 bad decrypt 1074529488:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:539: 

What am I doing wrong?

+5
source share
5 answers

To decrypt an encrypted video stream, you need an encryption key. This key is not part of the stream. It must be obtained separately.

The EXT-X-FAXS-CM header contains DRM metadata, not a key.

This came out of the Adobe Media Server Developer's Guide: In a playlist protected by Adobe Access Server, you also need to include the tag # EXT-X-FAXS-CM. The value of the # EXT-X-FAXS-CM tag in the alternate playlist is a relative URI related to the DRM metadata of one of the individual streams. As a client, the tag # EXT-X-FAXS-CM in the alternate playlist will be used to create a DRM session. The same DRM session will be used for all encrypted M3U8 files within the playlist.

The full guide can be found here: http://help.adobe.com/en_US/adobemediaserver/devguide/WS5262178513756206-4b6aabd1378392bb59-7fe8.html

It is also mentioned that the fax: //faxs.adobe.com URI is for local key maintenance. Thus, the key is obtained locally from the device.

+4
source

This might be a bit hacky, but given the URL in the .m3u8 file, it will download and decrypt the files that make up the stream:

 #!/usr/bin/env bash curl "$1" -s | awk 'BEGIN {c=0} $0 ~ "EXT-X-KEY" {urlpos=index($0,"URI=")+5; ivpos=index($0,"IV="); keyurl=substr($0, urlpos, ivpos-urlpos-2); iv=substr($0, ivpos+5); print "key=`curl -s '\''"keyurl"'\'' | hexdump -C | head -1 | sed \"s/00000000//;s/|.*//;s/ //g\"`"; print "iv="iv} $0 !~ "-KEY" && $0 ~ "http" {printf("curl -s '\''"$0"'\'' | openssl aes-128-cbc -K $key -iv $iv -d >seg%05i.ts\n", c++)}' | bash 

This script creates a second script that extracts the keys and initialization vectors and uses them to decrypt at boot. This requires curls, awk, hexdump, sed and openssl. It will probably suffocate in an unencrypted stream or in a stream that uses something other than AES-128 (is any other encryption supported?).

You will get a bunch of files: seg00000.ts, seg00001.ts, etc. Use tsMuxeR ( https://www.videohelp.com/software/tsMuxeR ) to merge them into one file (simple concatenation did not work for me ... this is what I tried first):

 (echo "MUXOPT --no-pcr-on-video-pid --new-audio-pes --vbr --vbv-len=500"; (echo -n "V_MPEG4/ISO/AVC, "; for i in seg*.ts; do echo -n "\"$i\"+"; done; echo ", fps=30, insertSEI, contSPS, track=258") | sed "s/+,/,/"; (echo -n "A_AAC, "; for i in seg*.ts; do echo -n "\"$i\"+"; done; echo ", track=257") | sed "s/+,/,/") >video.meta tsMuxeR video.meta video.ts 

(Track identifiers and frame rate may need to be set up ... get the values ​​to be used by transferring one of the downloaded files to tsMuxeR.)

Then use ffmpeg to remux for something more widely understood:

 ffmpeg -i video.ts -vcodec copy -acodec copy video.m4v 
+2
source

Even through this file encrypted AES data is included, openssl does not know the m3u8 format. However, FFmpeg can handle this.

0
source

Although some of the bash scripts in the existing answers give you part (or even all) of the way, depending on which site you are trying to download from, you may encounter other obstacles (another auth method, a custom license server server, etc. )

I found streamlink in order to be the most reliable solution for this, which also allows you to directly transfer (rather than download) if you need it, and it has all the work related to the site, a list of sites has already been done for you for a long time ( see the plugins section , but keep in mind that it is under active development, and the last release was in June, so for some of the newer ones you will need to git clone and install from the source).

0
source

All Articles