This Rust project demonstrates a mutual TLS (mTLS) echo server and client using the rustls library.
Mutual TLS is an extension of standard TLS where both the server and client must present valid certificates.
This project securely exchanges data between a client and server over an encrypted connection, where both parties authenticate each other using certificates.
--TLS Server (server.rs):
The TLS echo server listens on TCP port 8443 and establishes secure connections using Rustls.
It loads a server certificate (cert.pem) and a corresponding private key (key.pem) to authenticate itself to clients.
To enforce mutual authentication, the server is configured to verify client certificates against a trusted Certificate Authority (CA) specified in ca_cert.pem.
When a client connects, the server ensures that the client presents a valid certificate signed by the trusted CA.
Upon successful authentication, the server receives a message from the client, echoes the exact message back over the encrypted TLS channel,
and then shuts down the TLS session to ensure a proper and secure connection termination.
--TLS Client (client.rs):
The TLS client establishes a secure connection to the server at localhost:8443 using Rustls.
It loads the server’s CA certificate to verify the authenticity of the server during the TLS handshake.
Additionally, the client presents its own certificate (client_cert.pem) and private key (client_key.pem) to authenticate itself to the server, enabling mutual TLS authentication.
After the connection is established and both identities are verified, the client sends a simple message—“Hello from client!”—and waits for the server to echo it back.
Once the message is received and printed, the client cleanly shuts down the TLS session, ensuring a proper and secure connection closure.
--Server Cert Configuration (openssl_server_with_san.cnf):
Contains the configuration for generating a proper server certificate.
--Client Cert Configuration (openssl_client.cnf):
Contains the configuration for generating a proper server certificate.
Unlike the server certificate, the client certificate does not require a SAN (Rustls only checks SANs for server identities).
--Generate Certificates (gen_certs.ps1):
The commands used to generate the cert and the key.