Search code examples
c#sslnetwork-programmingssl-certificate.net-7.0

Authentication hangs for SSL over named pipes


I've implemented named pipes communication between server and client applications in .NET 7 using NamedPipeServerStream and NamedPipeClientStream. This is all working. Now I am trying to add SSL. From server side

NamedPipeServerStream server; 

//server is initialized and named pipe connection done

using var sslStream = new SslStream(server, true, (s, cert, chain, policy) => true);

var cert = new X509Certificate2("my_installed_server_cert.pfx");
sslStream.AuthenticateAsServer(cert);

// some further reading/writing operations

From client side:

NamedPipeClientStream pipeClient;

// initialize, connect - ok

using var sslStream = new SslStream(pipeClient, true);
sslStream.AuthenticateAsClient("localhost");

Now the problem - both AuthenticateAsServer and AuthenticateAsClient hangs.

The certificate is self-signed, generated by makecert. It is loaded correctly, as far as I see in debugger.

What can be a reason of this behaviour?

OS is Windows 11.


Solution

  • The handing was a result of server and client couldn't define suitable protocol. After I set protocol Tls12 in both client and server, the hanging disappeared:

    // server
    sslStream.AuthenticateAsServer(cert, false, SslProtocols.Tls12, false);
    
    // client
    sslStream.AuthenticateAsClient(targetHost, null, SslProtocols.Tls12, false);