private static async Task <string> TestSslProtocol(string hostName, int port, SslProtocols p, string testDescription) { //Console.WriteLine($"P:{p}"); await Task.Yield(); var sb = new StringBuilder(); Stopwatch sw = Stopwatch.StartNew(); var actualProtocol = SslProtocols.None; try { using (var socket = new Socket(SocketType.Stream, ProtocolType.Tcp)) { socket.Connect(hostName, port); var networkStream = new NetworkStream(socket, false); var sslStream = new SslStream(networkStream); var clientCerts = new System.Security.Cryptography.X509Certificates.X509CertificateCollection(); sslStream.AuthenticateAsClient(hostName, clientCerts, p, true); actualProtocol = sslStream.SslProtocol; sw.Stop(); sb.AppendLine($"{testDescription}: Allowed, Duration={sw.ElapsedMilliseconds}ms, Protocols Allowed: {p.ToStringExpanded()}, Protocol Used: {actualProtocol}"); sb.AppendLine($" Cipher: {sslStream.CipherAlgorithm}, strength {sslStream.CipherStrength} bits"); sb.AppendLine($" Hash: {sslStream.HashAlgorithm}, strength {sslStream.HashStrength} bits"); sb.AppendLine($" Key exchange: {sslStream.KeyExchangeAlgorithm}, strength {sslStream.KeyExchangeStrength} bits"); } } catch (Exception) { sb.AppendLine($"{testDescription}: BLOCKED, Duration={sw.ElapsedMilliseconds}ms, Protocols Attempted: {p.ToStringExpanded()}"); } return(sb.ToString()); }