Skip to content
Konstantin Bogdanoski edited this page Jun 27, 2020 · 10 revisions

Споделување енкриптирани видеа преку HLS

Sharing encrypted videos through HLS

Целта на овој проект е да се имплементира стримање – споделување на мултимедиски содржини, поточно видеа, со произволна големина, вo m3u8 формат, а со многу лесна промена во кодот може и да се користи mpd форматот. Исто така видеата потребно е да бидат енкриптирани со код. Секое видео да добива сопствен String token со кој ќе може да се отклучи содржината. Целосната имплементација можете да ја видите на ова git репозитори.

The goal of this project is to implement a streaming service of multimedia content, videos to be precise, with arbitrary length in .m3u8 format. It is also very easy to transform it to .mpd format. Each video receives it's String token which represents the key with which our video has been encrypted. The full implementation can be viewed on this repository.

Имплементација

Implementation

Овој проект е составен од 3 компоненти:

  1. SpringBoot апликација – за бизнис логиката на апликацијата
  2. ReactJS апликација – за веб кориснички интерфејс
  3. Shell скрипти – за форматирање и енкриптирање на видеото

This project contains 3 components:

  1. SpringBoot application - for our business logic
  2. ReactJS app - for our end-user UI
  3. Shell scripts - for formatting and encryption of the videos

SpringBoot апликација

SpringBoot application

SpringBoot апликацијата е доста едноставна. Се базира врз REST принципите и во неа има:

  1. Model:
  • Base
  • BaseEntity
  • UserRole
  • User
  • Video
  • Quality
  1. Web:
  • AdminController
  • MainController

The SpringBoot app is very simple. It is based on the REST principles and contains the listed classes.

За слојот за базата на податоци и сервисниот слој изоставени се податоците бидејќи се подразбира дека треба да бидат имплементирани за да работи апликацијата.

For the service and persistence layer, the classes are left out, because we know they should be implemented in the app

Апликацијата исто така е заштитена со едноставан OAuth JWT автентикација и авторизација. Имплементацијата е достапна на ова репо. Aпликацијата во себе содржи неколку класи кои се потребни за да функционира подобро.

The application is also protected with a simple OAuth JWT authentication and authorization. The implementation is pretty straight forward and is available in this repo. The application itself contains a couple of other classes which are needed for it to function better.

Тоа се Initializer.java и CustomExceptionHandler.java. Можете да ги погледнете и лесно е да се заклучи за што служат. Во секоја класа е поставено соодветно објаснување за методите. Доколку имате некакво двоумење, слободно контактирајте не на mail. Покрај java класите, потребно е да се постават соодветно application.properties. Можете слободно да ги погледнете на git.

The needed classes are Initializer.java and CustomExceptionHandler.java. You can check them out and easily conclude their role in the app.

ReactJS апликација

ReactJS Application

За корисничкиот интерфејс се користи исто така едноставна React апликација со неколку компоненти.

The UI is also pretty simple, just a couple of components needed for the app to work as it should.

Апликацијата би требало да ви функционира без никакви измени, но доколку направите промени на портата од вашата Spring апликација, истата треба да ја пропагирате на само едно место во React апликацијата, тоа е axios компонентата, а таа се наоѓа во frontend/src/axios/axios.js. Сите промени и подобрувања се добредојдени и охрабрени.

The application should work without any modifications. If you do some modifications on the port of your Spring app, please propagate them in the axios component in the React app, located in frontend/src/axios/axios.js. All changes and upgrades are welcome and encouraged.

Shell скрипти

Shell scripts

На git постои само една скрипта и таа делува како master скрипта. Скриптата служи за да се постави квалитетот и да се креира .m3u8 датотека – formatVideo.sh. Потребно е истата да ја поставите во датотеката што е родител на видеата (пр. /home/konstantin/Videos). Покрај преместувањето на таа скрипта, потребно е да се дадат пермисии за апликацијата да ја извршува

chmod 755 formatVideo.sh

Oсвен таа скрипта, потребно е да направите уште една скрипта m3u8gen.sh, која ќе биде празна, но со исти пермисии како и formatVideo.sh. Неопходно е скриптите да бидат именувани вака и да бидат со потребните пермисии за извршување.

This git contains only one script which acts as a master script (formatVideo.sh). The script encodes and encrypts the given video and creates an .m3u8 file, accordingly. It is important that you put the script in the parent folder of your videos (ex. /home/konstantin/Videos). After relocating the script in the needed location, make sure you give it executable permission: chmod 755 formatVideo.sh. Other than that script, you need to create another one named m3u8gen.sh which will be empty. This script will be used by the master script when working with the videos. Make sure you give it executable permissions as well.

Енкрипцијата на видеата се врши преку генериран код од страна на Spring апликацијата. Тој код, скриптата formatVideo.sh го добива и со него го енкриптира добиеното видео. Енкрипцијата е од AES-128 формат, поточно 16 бајтен хексадецимален код.

The encryption of the videos is done by generating a hexadecimal token on the Spring app and passing it to the formatVideo.sh script, which uses the received token to encrypt the video. The encryption is in format of AES-128, 16 Byte.

Apache2 конфигурација

Apache2 configuration

За да се овозможи стримањето на видеа, потребно е Apache да се конфигурира за да ги опслужува тие видеа. Едноставна конфигурација треба да се додаде во конфигурациската датотека од Apache. Јас користев Apache2, можете да погледнете како да се направи тоа со NginX, доколку сакате.

To enable the streaming altogether, you need to configure your Apache server to serve the videos. A simple configuration needs to be added to the config file of Apache. I used Apache2 on Ubuntu 19.10, but you can use NginX, if you choose to.

<VirtualHost *:80>
    DocumentRoot /home/konstantin/Videos/
    Alias /videos "/home/konstantin/Videos"
    ProxyPass /videos !
    ProxyPass / http://localhost:8080
    ProxyPassReverse / http://localhost:8080
    <Directory "/home/konstantin/Videos">
        Header set Access-Control-Allow-Origin "*"
        Require all granted
    </Directory>
</VirtualHost>

Во конфигурациската датотека потребно е само да ги додадете овие линии xml текст. По успешно завршување и тестирање преку systemctl status apache2 / httpd Би требало Apache успешно да работи. (Јас користам Ubuntu 19.10, па конфигурациската датотека се наоѓа во /etc/apache2/sites-enabled/000-default.conf, доколку користите CentOS, датотеката барајте ја како httpd.conf.

In the config file, you just need to add the following lines of xml text. After successfully updating the config file, check if it works at all with systemctl statys apache2 / httpd. Using my config, but updating the paths (/home/konstantin/Videos), you should be able to get it to work. The config file on Ubuntu 19.10 is located in /etc/apache2/sites-enabled/000-default.conf. If you are using CentOS, the config file should be named httpd.conf.

Овој проект беше изработен од Константин Богданоски и Наташа Стојанова, заедно со професорот Д-р. Сашо Граматиков, како дел од курсот Мултимедиски Мрежи на Факултетот за Информатички Науки и Компјутерско Инженерство (ФИНКИ), 2019-2020, Скопје, Северна Македонија.

This project was done by Konstantin Bogdanoski and Natasha Stojanova, together with professor PhD. Sasho Gramatikov, as part of the course Multimedia Networks, of the Faculty of Computer Science and Engineering (FCSE), 2019-2020, Skopje, North Macedonia.