Media Name Aliasing¶
Flussonic offers a convenient feature: aliasing of stream and file names. It allows to hide names of streams from end users: on each request the name that user provided will be rewritten to internal name that you have configured.
Assume that you have the stream "clock" and you give people the link http://192.168.2.3/clock/index.m3u8
.
Now you can retain the stream named "clock" in configuration but give users the link like the following: http://192.168.2.3/crf7930803e4e334e104/index.m3u8
.
There are different situations when you may want to use it:
- hiding stream or file names from users, creating temporary names
- managing stream names that you have shared to users, revoking embeds
To enable it you need to implement alias rewriting backend and enable it in Flussonic config:
aliaser /opt/flussonic/priv/rewrite.lua;
At the moment only lua backend is accepted. You need to return false or a media name from it.
Object req
with field name
is provided into this backend.
If aliaser is enabled then Flussonic authorization backend will receive additional parameter:
user_name
— it is an original requested media name.
Example of a rewriting backend¶
We will show you example of such rewriting script that will help you to understand this mechanism.
Let's imagine that we want to hide original stream name clock
from user and give him temporary link.
Create file /etc/flussonic/alias.lua
with:
a = {}
a["alias"] = "clock"
if a[req.name] ~= nil then
return a[req.name]
else
return req.name
end
and then enable it in /etc/flussonic/flussonic.conf
:
# Global settings:
...
aliaser /etc/flussonic/alias.lua;
Now, we can access clock
stream via two names:
http://flussonic/clock/index.m3u8
http://flussonic/alias/index.m3u8
You can add more aliases for your streams. Example:
a = {}
a["alias"] = "clock"
a["alias2"] = "clock"
a["alias3"] = "clock"
a["bbc-news"] = "bbc"
a["bbc-entertainment"] = "bbc"
a["BBC"] = "bbc"
if a[req.name] ~= nil then
return a[req.name]
else
return req.name
end
Example of a rewriting backend: Crypto version¶
We will show you example of such rewriting script that will help you to understand this mechanism.
Let's imagine that we want to hide original stream name clock
from user and give him temporary link.
As we do not want to mess with some databases, we will just encrypt with some known key original stream name and give it to user.
For example our key will be 000102030405060708090A0B0C0D0E0F (16 bytes), IV will be full of zeros so hex value of encrypted
string clock
with aes ctr encryption will be: a5cd5454ec
To encrypt it in our lua script we will need to write following backend:
key = crypto.from_hex("000102030405060708090A0B0C0D0E0F")
encrypted = crypto.aes_ctr_encrypt(key, stream_name)
return crypto.to_hex(encrypted)
and to decrypt:
key = crypto.from_hex("000102030405060708090A0B0C0D0E0F")
decrypted = crypto.aes_ctr_decrypt(key, crypto.from_hex(req.name))
return decrypted
Ok, this is nice, but this new stream name doesn't look like something unique, it will be the same.
Let's add some random 4 bytes salt to our stream name. Now encrypted "1234" + "clock"
will be: f7930803e4e334e104
key = crypto.from_hex("000102030405060708090A0B0C0D0E0F")
encrypted = crypto.aes_ctr_encrypt(key, "12345"..stream_name)
return crypto.to_hex(encrypted)
Something different. Now on our website we need to add 4 random bytes before our stream name and then encrypt. Our alias rewriting backend will look rather simple:
decrypted = crypto.aes_ctr_decrypt(crypto.from_hex("000102030405060708090A0B0C0D0E0F"), crypto.from_hex(req.name))
return string.sub(decrypted,5)