/*
* Neuroxiq 2022
* Arctium Project / Code example
* TLS 1.3 - Record Size Limit
* Example demonstrates how to configure Record Size Limit
*
*/
using Arctium.Standards.Connection.Tls.Tls13.API;
using Arctium.Standards.Connection.Tls.Tls13.API.Extensions;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Web;
namespace ConsoleAppTest
{
internal class MainProgram
{
static Socket socket;
static void Main()
{
socket = new Socket(SocketType.Stream, ProtocolType.Tcp);
socket.Bind(new IPEndPoint(IPAddress.Loopback, 444));
socket.Listen(20);
StartServer();
}
static void StartServer()
{
var certificateWithPrivateKey = Tls13Resources.CERT_WITH_KEY_cert_rsaencrypt_2048_sha256_1;
var serverContext = Tls13ServerContext.Default(new[] { certificateWithPrivateKey });
/* Configuration Record Size limit */
// If client support Record Size Limit server negotiate
// lower value. If client do not support Size Limit server uses default
int maxRecordSize = 1024;
serverContext.Config.ConfigureExtensionRecordSizeLimit(maxRecordSize);
// After configuration - create server and accept client
var tlsServer = new Tls13Server(serverContext);
var networkStream = AcceptSocketNetworkStream();
var tlsStream = tlsServer.Accept(networkStream);
// read from stream, do something etc. ...
// tlsstream.read(...)
}
static NetworkStream AcceptSocketNetworkStream()
{
var rawSocket = socket.Accept();
return new NetworkStream(rawSocket);
}
}
}