Stunnel: Basics

From The Uniform Server Wiki
Revision as of 10:19, 24 November 2010 by Upazixorys (talk | contribs)
Jump to navigation Jump to search

This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page

<span id="top"></span> <div style="padding:0;margin:0; border-bottom:3px inset #000000">

MPG UniCenter

Stunnel: Home | Upgrade 4.24 | Install | SSL Certificate | Single Vhost | Resolved | Basics | Cost | Original


Stunnel SSL Basic

Stunnel is very flexible this page provides additional information for Uniform Server 3.5-Apollo’s implementation. Stunnel is configured for server operation allowing a secure connection between Apache and a browser client.

SSL Basics

Normal web pages are sent unencrypted over the Internet allowing anyone to intercept them and read their content. This presents a security issue where security and privacy is necessary for credit card and bank transactions. The Secure Socket Layer (SSL) is used to encrypt the data stream between the web server and a web browser.

SSL makes use of what is known as asymmetric cryptography, commonly referred to as public key cryptography (PKI). With public key cryptography, two keys are created, one public the other private. Anything encrypted with either key can only be decrypted with its corresponding key. Thus if a message or data stream were encrypted with the server's private key, it can be decrypted only using its corresponding public key, ensuring that the data only could have come from the server.

A certificate is not really necessary because data is secure and cannot easily be decrypted. However, certificates do serve a crucial role in the communication process. The certificate, signed by a trusted Certificate Authority (CA), ensures that the certificate holder is really who he claims to be. Without a trusted signed certificate, your data may be encrypted, however, the party you are communicating with may not be whom you think.

Self-Signed Certificate

You need to generate a self-signed certificate it contains the public key. UniServer’s Stunnel certificate is compromised because every one has access to it after downloading the plugin, this poses a security risk therefore you must generate a new certificate and key.

If you don't plan on having your certificate signed by a CA it will generate an error in the client browser to the effect that the signing certificate authority is unknown and not trusted view screen shots. I am going to cover only self-signed certificate here.


Batch Generator

To generate the certificate and public key you can use the command prompt and enter parameters manually. This is open to errors hence I created a batch file to ease the task.

This batch file is named mpg_create.bat and located in folder <nowiki>*\Uniform Server\udrive\home\admin\www\plugins\stunnel_424\bin</nowiki>


&nbsp;<nowiki>:</nowiki> File Name : mpg_create.bat<br> &nbsp;<nowiki>:</nowiki> Created By: UniCenter - MPG<br> &nbsp;<nowiki>:</nowiki> Create Stunnel pem certificate and public key file stunnel.pem<br> &nbsp;<nowiki>:</nowiki> Increased days to give 10year MPG 22/8/07 3.5-Apollo<br> &nbsp;<nowiki>:</nowiki> Updated to Stunnel 4.24 MPG 31/5/08<br> &nbsp;<nowiki>:</nowiki> Upgraded OpenSSL to openssl-0.9.8g MPG 31/5/08<br> &nbsp;<nowiki>:</nowiki> Updated for 3.5-Apollo MPG 18/8/07<br> &nbsp;<nowiki>:</nowiki> Version 1.1 18/8/07<br> &nbsp;<nowiki>:===============================================================</nowiki>

&nbsp;openssl req -new -x509 -days 3650 -nodes -config stunnel.cnf -out stunnel.pem -keyout stunnel.pem


This batch file runs the program openssl with the following parameters. Create a certificate request (req) that is new in the X.509 digital certificate format, using the RSA cipher with a 1,024-bit key, good for 3650 days use the config file (stunnel.cnf) for additional information and write out both its key (private) and (public) certificate to the same file, stunnel.pem.



Openssl is extremely flexible because of this flexibility requires a configuration file you can use any name so long as it ends with the file extension cnf Stunnel uses the file stunnel.cnf in this file you specify the type of certificate (in this case a server) encryption strength and other certificate details.

The file stunnel.cnf is located in folder <nowiki>*\Uniform Server\udrive\home\admin\www\plugins\stunnel_424\bin</nowiki>


&nbsp;<nowiki>#</nowiki> create RSA certs - Server

&nbsp;RANDFILE = stunnel.rnd

&nbsp;[ req ]<br> &nbsp;default_bits = 1024<br> &nbsp;encrypt_key = yes<br> &nbsp;distinguished_name = req_dn<br> &nbsp;x509_extensions = cert_type

&nbsp;[ req_dn ]<br> &nbsp;countryName = Country Name (2 letter code)<br> &nbsp;countryName_default = PL<br> &nbsp;countryName_min = 2<br> &nbsp;countryName_max = 2

&nbsp;stateOrProvinceName = State or Province Name (full name)<br> &nbsp;stateOrProvinceName_default = Some-State

&nbsp;localityName = Locality Name (eg, city)

&nbsp;0.organizationName = Organization Name (eg, company)<br> &nbsp;0.organizationName_default = Stunnel Developers Ltd

&nbsp;organizationalUnitName = Organizational Unit Name (eg, section)<br> &nbsp;<nowiki>#</nowiki>organizationalUnitName_default =

&nbsp;0.commonName = Common Name (FQDN of your server)<br> &nbsp;0.commonName_default = localhost

&nbsp;<nowiki>#</nowiki> To create a certificate for more than one name uncomment:<br> &nbsp;<nowiki>#</nowiki> 1.commonName = DNS alias of your server<br> &nbsp;<nowiki>#</nowiki> 2.commonName = DNS alias of your server<br> &nbsp;<nowiki>#</nowiki> ...<br> &nbsp;<nowiki>#</nowiki> See <nowiki></nowiki><br> &nbsp;<nowiki>#</nowiki> to see how Netscape understands commonName.

&nbsp;[ cert_type ]<br> &nbsp;nsCertType = server

When you run the batch file (mpg_create.bat) it runs openssl which reads this configuration file.

Note 1: All lines highlighted (bold) are questions presented to you during certificate generation. If you press enter as a response the default value will be used otherwise the value you enter is used.

When you reach the line fully qualified domain name (FQDN) enter your server's full name (the name you type in a browser to access your site without the <nowiki>http://</nowiki> bit) or IP address of your server.

Note 2: FQDN example, given a device with a hostname of "fred" and a domain name of "", the fully qualified domain name is "" Like an IP address it is unique and removes any ambiguity.

Note: Windows does not display the file extention (cnf) hence file stunnel.cnf will display as stunnel (the icon is a speed dial)


Generating a certificate

The batch file allows you to create both the private key and public key in one go. You can generate each file individually and then manually combine them into a single file in the PEM format. However using a batch file makes it just that little bit easier and less error prone.

The file is located in folder: <nowiki>*</nowiki>\Uniform Server\udrive\home\admin\www\plugins\stunnel_424\bin

  1. If running shut down your servers.
  2. To start the process double click on the batch file mpg_create.bat.
  3. First the private key is automatically created and requires no input from you.
  4. The next phase is a Certificate Signing Request (CSR).<br>During this generation process you will be prompted for several pieces of information. These are the X.509 attributes of the certificate.
  5. I have highlighted in bold the type of information you enter.

Country Name (2 letter code) [PL]:UK<br> State or Province Name (full name) [Some-State]:Cambridgeshire<br> Locality Name (eg, city) []:Cambridge<br> Organization Name (eg, company) [Stunnel Developers Ltd]:Mike Gleaves UniCenter<br> Organizational Unit Name (eg, section) []:Uniform Server 3.5-Apollo example<br> Common Name (FQDN of your server) []<br> Press any key to continue

You can repeat this process at any time, for a self-signed certificate the information you enter is unimportant with the exception of FQDN (fully qualified domain name) if you have one use it (its the full address you would enter in a browser apart from the <nowiki>http://</nowiki> bit).

Note 1: A default value is displayed in square brackets press return to accept this value. If you are feeling lazy press return at each prompt. The resulting certificate is fully functional however it does not look very professional when displayed in a browser.

Note 2: The only thing of importance each certificate you generate is unique.

It really is that easy to produce a self signed certificate to secure your personal server. If you want some background information take a look at this page SSL basics.



Stunnel also extremely flexible requires a configuration file amongst other things it sets Stunnels mode of operation either client or server mode. Uniform Server uses Stunnel's default server mode.

The section that you may need to change is uniform35 in this section you set accept and connect port values. These have been set to the standard ports values, if you change the Apache listening port change connect to match. If you wish to set the Internet secure port change accept to match this. (Note: You will also need to change your firewall and router forwarding ports)


&nbsp;; File Name : stunnel.conf<br> &nbsp;; Created By: UniCenter - MPG<br> &nbsp;; Updated to Stunnel 4.24 MPG 1/6/08<br> &nbsp;; Added an addtional start file mpg_perl_php_start.bat<br> &nbsp;; Updated to Stunnel 4.20 MPG 25/3/07<br> &nbsp;; Updated for 3.5-Apollo MPG 20/8/07<br> &nbsp;; Version 1.1 20/8/07<br> &nbsp;; Notes:<br> &nbsp;; Drive independent use mpg_stunnel_start.bat and mpg_stunnel_stop.bat<br> &nbsp;; If not run from these files full path must be specified eg<br> &nbsp;;cert = w:\home\admin\www\plugins\stunnel_424\bin\stunnel.pem<br> &nbsp;;key = w:\home\admin\www\plugins\stunnel_424\bin\stunnel.pem<br> &nbsp;; ========================================================================

&nbsp;cert = stunnel.pem<br> &nbsp;key = stunnel.pem

&nbsp;ciphers = ALL:!ADH:RC4+RSA:+SSLv2:@STRENGTH<br> &nbsp;;debug 5=notice 7= full debug<br> &nbsp;debug = 5

&nbsp;RNDbytes = 64<br> &nbsp;RNDoverwrite = yes<br> &nbsp;session = 300 seconds<br> &nbsp;verify = level 1

&nbsp;[uniform35]<br> &nbsp;;htpps port 443<br> &nbsp;accept = 443<br> &nbsp;;default connects to local host<br> &nbsp;connect = 80

&nbsp;TIMEOUTbusy = 300 seconds<br> &nbsp;TIMEOUTclose = 60 seconds<br> &nbsp;TIMEOUTidle = 43200 seconds

Note: You can disable the taskbar icon by adding the line: taskbar = no


Uc small logo.gif Ric