Stunnel Guide
Stunnel Guide
Contents
Introduction ............................................................................................................................................... 1
Configuring Stunnel to use with TestCaddy
Server configuration.................................................................................................................................. 2
Client configuration ................................................................................................................................. 3
Creating self-signed certificate ............................................................................................................. 4
References ................................................................................................................................................ 9
Stunnel is a program that allows you to encrypt arbitrary TCP connections inside SSL (Secure Sockets
Layer) available on both Unix and Windows. Stunnel can allow you to secure non-SSL aware daemons
and protocols (like POP, IMAP, LDAP, etc) by having Stunnel provide the encryption, requiring no
changes to the daemon's code.
Using Stunnel in conjunction with TestCaddy enables a secure point-to-point connection to a remote SQL
Server over the internet. To do this, the following are required:
1. An instance of Stunnel must be installed on the server machine (where SQL Server is located)
2. An instance of Stunnel must be installed on the client machine (where TestCaddy is located or going
to be installed once Stunnel is installed)
3. An SSL certificate for Stunnel to use, to ensure a secure connection
4. SQL Server must have a static port set.
Server configuration
Download and install Stunnel on the machine where SQL Server is located.
Before running Stunnel, it must be configured to enable a secure connection. This can be done by
editing the stunnel.conf file located in the Stunnel installation folder.
To modify, open stunnel.conf using Notepad, or your favourite text editor. If the lines mentioned below
do not exist, add them, or otherwise change the existing lines.
Note: If any of the lines mentioned below begin with the ; character in the stunnel.conf file then they are
comments which will not take effect, so the ; character at the beginning of the line must be removed.
4. Add the following. This is telling Stunnel to listen on the local port 1956, and forward to the local
port 1955.
[sql]
;listen on port 1956
accept = 1956
; forward to port 1955 (this is the static port of the SQL Server)
connect = localhost:1955
Note: If you are only using Stunnel with TestCaddy, please make sure all the other lines begin with ;
with the exception of the following two lines:
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
To modify, open stunnel.conf using Notepad, or your favourite text editor. If the lines mentioned below
do not exist, add them, or otherwise change the existing lines.
Note: If any of the lines mentioned below begin with the ; character in the stunnel.conf file then they are
comments which will not take effect, so the ; character at the beginning of the line must be removed.
5. Add the following. This is telling Stunnel to listen on the local port 1956, and forward to the specified
IP address at the specified port. NOTE: You should specify the external IP address of the network
where your SQL server is located.
[sql]
;listen on port 1956
accept = 1956
; forward to ip:port (this is the address of the Stunnel at the server machine)
connect = 1.2.3.4:1956
Note: If you are only using Stunnel with TestCaddy, please make sure all the other lines begin with ;
with the exception of the following two lines:
socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1
You can use your own certificate if you have one; alternatively you can create a self-signed certificate.
5. At this stage, you will be asked to fill out the certificates X.509 attributes. The answers should be
adjusted for the location. Note: When the certificate is going to be used in a peer to peer situation
(as in this case), it does not really matter what information is in the certificate. Some minimal
information should be supplied as in the following example.
Country Name (2 letter code) [AU]:NZ
State or Province Name (full name) [Some-State]:Auckland
Locality Name (eg, city) []:Auckland
Organization Name (eg, company) [Internet Widgits Pty Ltd]:TamihaiLtd
Organizational Unit Name (eg, section) []:
Common Name (eg, YOUR name) []:mail.yourdomain.org
Email Address []:[email protected]
6. Next, were going to combine Key and Certificate files into host.pem.
copy host.cert+host.key host.pem
The data in the host.key and key.pem file must be protected, as anyone possessing the private key can read
any data encrypted with this key! Do not give these files to anyone, except to clients that need to
connect to the remote SQL Server.
Running Stunnel
Once Stunnel has been configured, the Stunnel service needs to be installed, and then Stunnel run. This
needs to be done on both the Client and Server machines.
A firewall can be used to restrict access to your network by forwarding only requests targeted at specific
TCP/IP addresses in the local network. Requests for all other network addresses are blocked by the
firewall.
Your IT administrator must configure the firewall which protects the network/office. A pinhole
(port forwarding) must be added to the firewall, to forward incoming requests to the server box. For our
example, open incoming port 1956, and forward to the server box on port 1956.
If you are running Windows Firewall on the SQL Server box itself, then you must also pinhole through
the Windows Firewall.
To open a port in the Windows Firewall for TestCaddy to access the remote SQL Server
You need to configure SQL server to listen on a static TCP/IP port, i.e. one which does not change when
the server restarts.
Note: Here, we mention SQL Server 2005; however the same steps apply for SQL Server 2008
1. Open SQL Server Configuration Manager, located in Start > Programs > Microsoft SQL Server 2005 >
Configuration Tools > SQL Server Configuration Manager
2. In SQL Server Configuration Manager, in the console pane, expand SQL Server 2005 Network
Configuration, expand Protocols for <instance name>, and then double-click TCP/IP.
3. In the TCP/IP Properties dialog box, on the IP Addresses tab, several IP addresses appear, in the
format IP1, IP2, up to IPAll. E.g. one of these is for the IP address of the loopback adapter, 127.0.0.1.
4. In the IPAll Properties area box, in the TCP Port box, type the port number you wish this IP address
to listen on (e.g. 1955 for our example), and then click OK.
5. In the console pane, click SQL Server 2005 Services.
6. In the details pane, right-click SQL Server (<instance name>) and then click restart, to stop and
restart SQL Server.
NOTE: After the SQL Server has restarted, any client applications which connect to this SQL server
should specify the server using the port number after a comma rather than specifying the instance name,
e.g.
127.0.0.1\TestCaddy
Becomes
127.0.0.1,1955
To connect TestCaddy to the remote SQL Server using Stunnel, you must point TestCaddy to the
specified local port.
Firstly, Stunnel must be running both on client and server machines (see previous section).
If you have not yet installed TestCaddy or you have installed it but not yet run the Configuration Wizard,
then go ahead and install TestCaddy on the client machine and run it from the Start menu, which will start
the Configuration Wizard:
1. During the TestCaddy Configuration Wizard, at the SQL Instance Details screen, set:
SQL Server: localhost,1956
Else, if you want to setup TestCaddy with Stunnel after you have installed TestCaddy:
1. Run TestCaddy
5. Save.
6. The list of TestCaddy databases on the SQL Server should show in the Database Manager list of
databases.
7. Close the TestCaddy Database Manager screen, and then you will be prompted to select a product
database.
8. Select the product database that you want to use, click OK, and continue to use TestCaddy as usual.
We would like to recognise all those that have contributed to Stunnel as displayed at
www.stunnel.org/about/credits.html
We would like to recognise all those that have contributed to the OpenSSL Project, as displayed at
http://www.openssl.org/about/