Securing mjpg streamer

I mentioned that I turned my raspi with the camera module into a video streamer (actually image streamer). I did this by using a very nice software called mjpg_streamer. Once I got that working and with NAT on my router I could see the image streaming from any machine on the Internet which includes my phone. As per a friend’s advice I wanted to make it secure. It doesn’t seem like mjpg_streamer has an option to support https. After a little search I found a nice utility called stunnel. What it can do is turn any unsecured network service into a secured service. Essentially at the simplest level you can say any network request on port A should map to another service on port B. So, I enabled mjpg_streamer on one port and stunnel routing via another port and finally the port forwarding on my router points to the port that stunnel accepts on.

The configuration file to make this happen with stunnel is very simple.

cert = /etc/stunnel/stunnel.pem
key = /etc/stunnel/stunnel.pem
sslVersion = all
debug = 7

[https]
client = no
accept = 1234
connect = 127.0.0.1:5678

Here, 1234 is the external port to which the router should forward the incoming request. And 5678 is the port that mjpg_streamer should be streaming. Note that “client = no” ensures the call to mjpg_streamer is done using http. Otherwise, it will try to use https and you would end up with an error like “GnuTLS: A TLS packet with unexpected length was received.”

This entry was posted in Uncategorized and tagged . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.