I am currentry writing a C# client (with Mono using SSLStream) for an already existing OpenSSL server written in C++. I know that in theory, they should be able to communicate, but I always get an Exception:
Authentication or decryption has failed.
Which takes place in Mono.Security.Protocol.Tls.SslStreamBase.AsyncHandshakeCallback when I invoke sslStream.AuthenticateAsClient(ServerName)
;
I do not need client authentication, so i don't use any client certificate, and i can't load my server certificate into a client's trust store, as I can't use the command line on the client side.
On the server, I seem to receive some random data, which should not happen, as I never invoke sslStream.Write()
in the client code. Maybe I don't completely understand how the handshake happens. I have an OpenSSL C++ client that works perfectly though.
Does someone know How I could get this working?
I am using, on the server side, a self-signed certificate generated by OpenSSL, which i converted to DER format.
How I proceed:
Server side
- Initialize OpenSSL
- Load server certificate (DER) and private key (PEM)
- Open a non-SSL listening socket
- As a client connects, I open a new socket which I connect to an SSL_Bio and accept the connection
- Read the SSL socket for incoming data.
Client side
I am trying to connect using a temporary client adapted from the one in this topic.
- Open a new TCPClient
- Link a new SSLStream to it with the same validation callback as in the thread above;
- Calling AuthenticateAsClient(ServerName) which brings this exception.
- Invoke
sslStream.Write
but the execution never gets here.
Any help would be greatly appreciated as I am not sure to understand how sslStream internally works.