Azure / amqpnetlite

AMQP 1.0 .NET Library
Apache License 2.0
401 stars 143 forks source link

SSl settings with net35 #452

Closed Viktorstst closed 3 years ago

Viktorstst commented 3 years ago

Is there a way to access connection SSL settings under .NET 3.5?

xinchen10 commented 3 years ago

It is not accessible currently. Which SSL setting(s) do you need to control?

Viktorstst commented 3 years ago

CheckCertificateRevocation and ClientCertificates from SSL settings and Timeout(send/receive) from TCP settings.

xinchen10 commented 3 years ago

It can be done. However, the SSL and TCP settings are part of the ConnectionFactory API which is not available to net35. One option is the enhance the IHandler interface with two events: SocketConnected and SslNegotiation, where user can configure the socket or SslStream settings.

xinchen10 commented 3 years ago

Socket and SslStream are exposed through new handler events. To set socket properties or perform custom SslStream authentication, do something as follows.

            var handler = new TestHandler(e =>
            {
                if (e.Id == EventId.SocketConnect)
                {
                    ((System.Net.Sockets.Socket)e.Context).SendBufferSize = 4096;
                }
                else if (e.Id == EventId.SslAuthenticate)
                {
                    ((System.Net.Security.SslStream)e.Context).AuthenticateAsClient("localhost");
                }
            });

            Address sslAddress = new Address("amqps://guest:guest@localhost:5671");
            Connection connection = new Connection(sslAddress, handler);