how to send out a TLS Alert during handshaking

subkawa 1 Reputation point
2021-02-22T14:32:01.32+00:00

I'm trying to use TLS to communicate between computers in a local network.
So I implemented the server in OpenSSL(C++) and the client in C#, .NET Framework 4.7.2.

I execute TLS handshake by SSL_accept of OpenSSL and AuthenticateAsClient of C#, but currently the client does not send TLS alerts to the server when an error occurs during the handshake.
(For example, if the client does not accept the certificate, it should send out unknown_ca, but now the server is not notified and the handshake proceeds to the end.)
I implemented the client as follows:

private static ManualResetEvent connectDone = new ManualResetEvent(false);

static void Main(string[] args)
{
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(args[0]), 2500);
IAsyncResult result = socket.BeginConnect(ipEndPoint, new AsyncCallback(OnConnectServer), socket);

    connectDone.WaitOne();
}

}

private static void OnConnectServer(IAsyncResult asyncResult)
{
Socket socket = (Socket)asyncResult.AsyncState;
socket.EndConnect(asyncResult);

SslStream sslStream = new SslStream(
    new NetworkStream(socket),
    false,
    new RemoteCertificateValidationCallback(CertificateValidation)
);

try
{
    sslStream.AuthenticateAsClient(serverName);
}
catch (AuthenticationException ex)
{
    Console.WriteLine(ex.Message);
}
sslStream.Close();
connectDone.Set();

}

Does anyone know how to send an alert from the client?

Thanks.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,493 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,136 questions
0 comments No comments
{count} votes