stunnel: Authentication

Either the TLS client, the TLS server, or both need to be authenticated:

  • Server authentication prevents Man-In-The-Middle (MITM) attacks on the encryption protocol.
  • Client authentication allows for restricting access for individual clients (access control).

PSK

The easiest way to configure authentication is with PSK (Pre-Shared Key). It provides both client and server authentication. PSK is also the fastest TLS authentication.

 

PSK authentication requires stunnel version 5.09 or higher.

Server Configuration

A trivial configuration example:

[PSK server]
accept = <server_port>
connect = <dst_port>
ciphers = PSK
PSKsecrets = psk.txt

The psk.txt file contains one line for each client:

test1:oaP4EishaeSaishei6rio6xeeph3az
test2:yah5uS4aijooxilier8iaphuwah1Lo

Client Configuration

A trivial configuration example:

[PSK client 1]
client = yes
accept = 127.0.0.1:<src_port>
connect = <server_host>:<server_port>
PSKsecrets = psk1.txt

The psk1.txt file only needs a single line:

test1:oaP4EishaeSaishei6rio6xeeph3az

Each client needs a separate secret. Otherwise, all the clients sharing the same key will have to be reconfigured if the key is compromised.

Certificates

For simplicity, this tutorial only covers server authentication. The advantage of this configuration is that it does not require individual secrets for each of the clients.

Server Configuration

Unless PSK authentication is configured, each stunnel server needs a certificate with the corresponding private key. The Windows installer of stunnel automatically builds a certificate. On Unix platforms, a certificate can be built with "make cert". A certificate can also be purchased from one of the available commercial certificate authorities.

A trivial configuration example:

[certificate-based server]
accept = <server_port>
connect = <dst_port>
cert = cert.pem
key = key.pem

The "key" option may be omitted if cert.pem also contains the private key.

Client Configuration

stunnel can use an existing PKI (Public Key Infrastructure). The following configuration requires stunnel 5.15 or later:

[PKI client]
client = yes
accept = 127.0.0.1:<src_port>
connect = <server_host>:<server_port>
verifyChain = yes
CAfile = ca-certs.pem
checkHost = <server_host>

The ca-certs.pem file contains the certificates of trusted certificate authorities.

Alternatively, a technique known as certificate pinning can be used. The following configuration requires stunnel version 4.46 or higher:

[pinning client]
client = yes
accept = 127.0.0.1:<src_port>
connect = <server_host>:<server_port>
verifyPeer = yes
CAfile = peer-certificate.pem

The peer-certificate.pem file needs to contain the server certificate.

0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Using renice and taskset to manage process priority and CPU affinity with Linux OEL 6.4
Viewed 3723 times since Mon, Feb 17, 2020
ubuntu How to Reset Forgotten Root Password in Ubuntu
Viewed 2980 times since Tue, Dec 8, 2020
How to do a Filesystem Resize (ext3/ext4) on Redhat running on VMware
Viewed 11100 times since Wed, Jul 25, 2018
How to encrypt a partition with DM-Crypt LUKS on Linux
Viewed 8294 times since Fri, Jul 13, 2018
Linux - How to get Memory information
Viewed 1997 times since Fri, Jun 8, 2018
linux manual tools
Viewed 2879 times since Fri, Sep 28, 2018
stunnel Howto A Guide to create SSL access to a HTTP-only webserver with stunnel
Viewed 2781 times since Fri, Sep 28, 2018
Jak wygenerować silne hasła jednorazowe w Linuksie?
Viewed 2409 times since Thu, May 24, 2018
RHEL: Create a local RPM repository
Viewed 11304 times since Sun, May 27, 2018
Using grep to find string in files
Viewed 2322 times since Fri, May 15, 2020