Windows OS Hub
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows 10
    • Windows Server 2025
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
    • Proxmox
  • PowerShell
  • Linux

 Windows OS Hub / Windows Server 2025 / Encrypt Any Client-Server App Traffic on Windows with Stunnel

June 12, 2025

Encrypt Any Client-Server App Traffic on Windows with Stunnel

The Stunnel tool can be used as a proxy service to create a secure TLS tunnel for client-server network apps that do not support encryption themselves. In some cases, it is preferable to use this tool to secure remote access to a single app (service) rather than implementing a full-featured VPN solution.

The Stunnel service can be run in server or client mode. In client mode, Stunnel receives traffic from the client app, encrypts it, and then sends it to the server. Traffic is decrypted on the Stunnel server-side and then sent to the target app or service. The important thing is that the administrator doesn’t need to modify either the client or the server part of the app. Certificates can be used for client authentication. Stunnel is supported for both Windows and Linux.

Let’s look at how to use stunnel to create secure access between the client and the server. In this example, the server is a Windows host with an IIS web server running an unencrypted HTTP site. The task is to restrict access to this website from clients with certificate authentication and to enable traffic encryption.

Configuring Stunnel Server on Windows

Download the Stunnel installer for Windows from https://www.stunnel.org/downloads.html and install it with the default settings, including openssl.

Install Stunnel on Windows

The next step is to generate keys and certificates for the CA, server, and clients. Open a command prompt and navigate to the directory:

cd "c:\Program Files (x86)\stunnel\bin"

Generate CA key:

openssl genpkey -algorithm RSA -out ca.key

In this case, we are not using a password phrase to protect the certificate private key.

Create a CA certificate:

openssl req -new -x509 -key ca.key -out ca.crt -subj "/O=woshubLTD/OU=IT/CN=CA_webserver1.com"

Add information about the certificate in the subj field for easy identification.

Create a private key for the server:

openssl genpkey -algorithm RSA -out server.key

Create a certificate signing request (CSR):

openssl req -key server.key -new -out server.csr

Use the root CA to sign the server certificate.

openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 365 -subj "/O=woshubLTD/OU=IT/CN=server_webserver1.com"

Now, create a private key for the client:

openssl genpkey -algorithm RSA -out client.key

Generate a request for a client certificate:

openssl req -key client.key -new -out client.csr

Sign the client certificate:

openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 365 -subj "/O=woshubLTD/OU=IT/CN=client1_webserver1.com"

On the web server, copy the ca.crt, server.crt, and server.key files to the C:\Program Files (x86)\stunnel\config folder.

generate stunnel certificates

Edit the stunnel.conf file (you can clear the default settings) and add the following configuration:

; Write logs to stunnel.log
debug = info
output = stunnel.log
; Strong encryption settings. We assume that both devices have modern CPUs that support AES hardware acceleration. If such encryption settings cause server performance degradation under heavy traffic, you can simplify them.
options = CIPHER_SERVER_PREFERENCE
options = NO_SSLv2
options = NO_SSLv3
options = NO_TLSv1
sslVersion = TLSv1.2
sslVersion = TLSv1.3
ciphers = ECDHE-RSA-AES256-GCM-SHA384
; names (paths) to certificate files
cert = server.crt
key = server.key
CAfile = ca.crt
; This section contains the configuration of the service that the client will access via Stunnel.
[ITPoral]
; This is the IP address and port on which the Stunnel instance should listen for connections.
accept = 192.168.158.144:443
; or accept = 443
; The IP address and port of the service to which the connection should be redirected. In our case, this is a local HTTP site.
connect = 127.0.0.1:80
; or connect = 80
; Always check the remote computer's client certificate. Clients without a certificate will not be able to connect to the service.
verify=2
Make sure that the accept line contains a port number that is not being used by another Windows process.

Open the specified port in Windows Defender Firewall to allow incoming connections. You can create a firewall rule with PowerShell.

New-NetFirewallRule -DisplayName "ITPoral_stunnel_443" -Direction Inbound -LocalPort 443 -Protocol TCP -Action Allow

Block external connections to the insecure TCP port 80 at the router or firewall level.

Run Stunnel.exe and check the GUI logs to ensure your configuration does not contain errors. The graphical interface allows quick re-read the configuration file and immediately view error logs, which makes debugging easier.

1 stunnel server connection log on windows

Close the stunnel.exe GUI by clicking Terminate in the menu, then start stunnel as a Windows service. Run the command:

"C:\Program Files (x86)\stunnel\bin\stunnel.exe" -install "C:\Program Files (x86)\stunnel\config\stunnel.conf"

The Stunnel TLS wrapper service will be created. Start it:

Start-Service wrapper

The stunnel process listens on port 443 once it is started.

Install Stunnel TLS wrapper service on Windows

Stunnel Client Configuration Example on Windows

Then, install stunnel from the same distribution on the client Windows device. Then copy the ca.crt, client.crt, and client.key files from the server to the C:\Program Files (x86)\stunnel\config folder.

Add the following to the stunnel.conf configuration file:

[ITPoral]
; Run Stunnel in the client mode.
client = yes
; Specify the IP address and TCP port through which your service will be accessible to your clients.
accept = localhost:8080
; the address of the stunnel server to redirect connections to
connect = 192.168.158.144:443
; certificate paths
CAfile = ca.crt
cert = client.crt
key = client.key
; Certificates must be checked explicitly when establishing a connection.
verify=2

Save the configuration file. First, run Stunnel manually and check the logs for errors. Now, when you access the address localhost:8080 from the browser, Stunnel will redirect the connection to the remote server.

Stunnel: redirect traffic by creating a secure TLS tunnel

For convenience, you can combine certificates and keys into a single file. For example:

Get-Content client.key, client.crt | Set-Content client.pem

In this case, only specify the following in the stunnel configuration file:

cert = client1.pem

If everything is working properly, you can run stunnel on a client as a service.

stunnel.exe -install

stunnel.exe -install - run client on windows

To revoke certificates (for example, compromised ones), add the CRLpath option to the stunnel server configuration. Specify the path to the folder where the revoked certificates (Certificate Revocation Lists) in PEM format are stored.

You can also use the CApath option to specify the location of the folder containing the allowed certificates.

0 comment
0
Facebook Twitter Google + Pinterest
Questions and AnswersWindows 11Windows Server 2025
previous post
How to Manually Install Any Driver on a Windows Computer

Related Reading

Cannot Install Network Adapter Drivers on Windows Server

May 6, 2025

WMIC Command Not Found on Windows

May 19, 2025

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Failed to Open the Group Policy Object on a Computer

    June 2, 2025
  • Remote Desktop Printing with RD Easy Print Redirection

    June 2, 2025
  • Disable the Lock Screen Widgets in Windows 11

    May 26, 2025
  • Configuring Windows Protected Print Mode (WPP)

    May 19, 2025
  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Fix: Windows Update Tab (Button) is Missing from Settings
  • Fix: Your IT Administrator Has Limited Access to Virus & Threat Protection
  • Permanently Disable Driver Signature Enforcement on Windows 11
  • Fix: Multiple Connections to a Server or Shared Resources by the Same User
  • How to Add or Reinstall the Microsoft PDF Printer on Windows
  • How to Remove ‘Some Settings are Managed by Your Organization’ on Windows 11 or 10
  • Cannot Install Language Pack on Windows 10 or 11
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top