stunnel
under the Django development environment on Ubuntu 12.04.1 LTS x64.stunnel
(version 4.x, branch 3.x is no longer supported): $ sudo apt-get install stunnel4
stunnel
settings are in the /etc/default/stunnel4
: # /etc/default/stunnel # Julien LEMOINE <speedblue@debian.org> # September 2003 # Change to one to enable stunnel automatic startup ENABLED=0 # Configuration file loacation mask FILES="/etc/stunnel/*.conf" OPTIONS="" # Change to one to enable ppp restart scripts PPP_RESTART=0
stunnel
will be used only in conjunction with the Django web server at the time of development and testing.... Each SSL enabled daemon needs a valid X.509 certificate to the peer. It also needs to enter the incoming data. OpenSSL package ...
... The order of contents of the .pem file is important. It should contain the unencrypted private key first, then a signed certificate (not certificate request). There should be also empty lines after certificate and private key. Plaintext certificate information appended should not be discarded. So the file should look like this:
----- BEGIN RSA PRIVATE KEY -----
[encoded key]
----- END RSA PRIVATE KEY -----
[empty line]
----- BEGIN CERTIFICATE -----
[encoded certificate]
----- END CERTIFICATE -----
[empty line]
$ cd ~ $ openssl genrsa -out private.key $ openssl req -new -x509 -key private.key -out stunnel.cert -days 365
private.key
and stunnel.cert
, which need to be merged and add empty lines according to the template: $ (cat private.key ; echo ; cat stunnel.cert ; echo) > stunnel.pem
stunnel.conf-sample
configuration file is located in /usr/share/doc/stunnel4/examples/
, and the description of the parameters can be found in man stunel4
or in the documentation . Plus, the FAQ section on the program’s website contains some useful tips. $ cd ~ $ vim stunnel.conf
; Certificate & Key cert = ./stunnel.pem ; Use SSL version 3, which is more secure sslVersion = SSLv3 ; If next argument is empty, then no pid file will be created pid = ; if 'yes' stay in foreground (don't fork) and log to stderr instead of via syslog foreground = no ; Performance tweak from FAQ (https://www.stunnel.org/faq.html) socket = l:TCP_NODELAY=1 socket = r:TCP_NODELAY=1 ; Enable compression compression = zlib ; Debugging - emerg (0), alert (1), crit (2), err (3), warning (4), notice (5), info (6), or debug (7) debug = 7 output = /var/log/stunnel4/stunnel.log ; HTTPS service section [https] ; Port to listen incoming client connections accept = 8443 ; Port which Django development server listens to connect = 8000 ; Tweak for MSIE (see FAQ or manual) TIMEOUTclose = 0
stunnel
and the built-in Django web server for the test project (empty project, immediately after django-admin.py startproject
): $ cd ~ $ stunnel4 stunnel.conf $ source django/bin/activate (django)$ cd django/projects (django)$ django-admin.py startproject testone (django)$ cd testone/ (djanho)$ HTTPS=on python manage.py runserver
$ netstat –an
Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State ... tcp 0 0 0.0.0.0:8443 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN ...
stunnel
listens on all external interfaces port 8443, and the web server local connections on port 8000.killall
command will work: $ ps -e | grep stunnel4
12530 pts/1 00:00:00 stunnel4 12531 pts/1 00:00:00 stunnel4 12532 pts/1 00:00:00 stunnel4 12533 pts/1 00:00:00 stunnel4 12534 pts/1 00:00:00 stunnel4 12535 ? 00:00:00 stunnel4
$ killall stunnel4
https://
instead of http://
. At the first request, we should see warnings about an unreliable certificate, since It was signed by us personally, and not by an accredited center (Certificate Authority). After confirming the security exception, we will see the requested page received via the HTTPS protocol.stunnel
, so you can try to build a similar scheme on these operating systems.Source: https://habr.com/ru/post/188106/
All Articles