Shows how to use TlsServerSocket class to write custom TLS proxy server.


This sample is a console application that provides TLS proxy server functionality. It listens on specified port for incoming TCP connections, secures them using TLS and forwards all communication between the connected client and the specified remote host. This makes it possible to add TLS 1.3/1.2/1.1/1.0 security to existing servers using plain (unencrypted) protocols

For example, to secure your HTTP service running at IP address, making it accessible via HTTPS protocol:

> TlsProxy c:\data\cert.pfx password


// start the server
var server = new TcpListener(IPAddress.Any, 1234);

// accept incoming connection
var inboundSocket = server.AcceptSocket();

// create an instance of TLS server socket
using (var socket = new TlsServerSocket(inboundSocket))
    // log communication
    socket.LogWriter = new ConsoleLogWriter(LogLevel.Info);

    // specify certificate to be used for server authentication
    socket.Parameters.Certificate = CertificateChain.LoadPfx(certPath, certPassword);

    // negotiate TLS layer

    // receive requests and send responses
    byte[] buffer = new byte[8 * 1024];
    // ... socket.Receive(buffer);
    // ... socket.Send(buffer);

Also see Rebex TLS Proxy, our simple yet powerful TLS server with rich command-line interface.