internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TlsInfo obj) { return((obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr); }
static async Task Main(string[] args) { if (args.Length == 0) { Console.WriteLine("No host names specified!"); } foreach (var hostName in args) { Console.WriteLine(); WriteLineWithColour(GetHeader(hostName), ConsoleColor.DarkGreen); Console.WriteLine(); try { string host; var port = DefaultPortNumber; var m = s_hostNameWithPort.Match(hostName); if (m.Success) { host = m.Groups["host"].Value; port = int.Parse(m.Groups["port"].Value); } else { host = hostName; } string resolvedHostNameOrIp; if (IPAddress.TryParse(host, out var ip)) { resolvedHostNameOrIp = ip.ToString(); } else if (string.Equals(host, Localhost, StringComparison.OrdinalIgnoreCase)) { resolvedHostNameOrIp = Localhost; } else { var dnsEntry = await Dns.GetHostEntryAsync(host).ConfigureAwait(false); resolvedHostNameOrIp = dnsEntry.HostName; } Console.WriteLine($"Resolved Host Name: {resolvedHostNameOrIp}"); using (var tcpClient = new TcpClient(resolvedHostNameOrIp, port)) using (var sslStream = new SslStream(tcpClient.GetStream(), false, ValidateServerCertificate, null)) { await sslStream.AuthenticateAsClientAsync( resolvedHostNameOrIp, null, SslProtocols.Tls12, true ).ConfigureAwait(false); var tlsInfo = new TlsInfo(sslStream); Console.WriteLine($"TLS Version: {tlsInfo.ProtocolVersion}"); Console.WriteLine($"Key Exchange Algorithm: {tlsInfo.KeyExchangeAlgorithm}"); Console.WriteLine($"Cipher Algorithm: {tlsInfo.CipherAlgorithm}"); Console.WriteLine($"Hash Algorithm: {tlsInfo.HashAlgorithm}"); Console.WriteLine("Certificate:"); Console.WriteLine(); Console.WriteLine(tlsInfo.RemoteCertificate.ToString(false)); } } catch (Exception e) { WriteLineWithColour(e.ToString(), ConsoleColor.DarkRed); Console.WriteLine(); } } }