public class SecureProxy
{
private TcpListener listener;
private HttpClient proxyClient;
public void Start()
{
listener.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
listener.Server.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, 120);
listener.Server.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, 10);
listener.Server.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveRetryCount, 5);
listener.Start();
listener.BeginAcceptTcpClient(ReceiveClientAsync, null);
}
void ReceiveClientAsync(IAsyncResult ar)
{
var client = listener.EndAcceptTcpClient(ar);
listener.BeginAcceptTcpClient(ReceiveClientAsync, null);
using var ns = client.GetStream();
using var sn = new SslStream(ns, true);
try
{
sn.AuthenticateAsServer(ServerCertificate, ClientCertificateRequired, AllowedProtocols, CheckCertificateRevocation);
}
catch
{
return; // client refused the self signed cert
}
// read the https request and send a https response through sn
sn.Flush();
}
}
public class SecureProxy
{
private TcpListener listener;
private HttpClient proxyClient;
public void Start()
{
listener.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
listener.Server.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, 120);
listener.Server.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, 10);
listener.Server.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveRetryCount, 5);
listener.Start();
listener.BeginAcceptTcpClient(ReceiveClientAsync, null);
}
void ReceiveClientAsync(IAsyncResult ar)
{
var client = listener.EndAcceptTcpClient(ar);
listener.BeginAcceptTcpClient(ReceiveClientAsync, null);
using var ns = client.GetStream();
using var sn = new SslStream(ns, true);
try
{
sn.AuthenticateAsServer(ServerCertificate, ClientCertificateRequired, AllowedProtocols, CheckCertificateRevocation);
}
catch
{
return; // client refused the self signed cert
}
// read the https request and send a https response through sn
sn.Flush();
}
}