public TlsSyslogServer( NetCoreServer.SslContext context , System.Net.IPAddress address , int port , MessageHandler handler ) : base(context, address, port) { this.m_messageHandler = handler; }
public bool Start() { // Create a new UDP echo server if (this.ServerType == ServerType.UDP) { this.m_udpServer = new UpdSyslogServer(this.ListenAddress, this.Port, MessageHandler.CreateInstance(123, this.Port)); } // Create a new TCP Syslog server if (this.ServerType == ServerType.TCP) { this.m_tcpServer = new TcpSyslogServer(this.ListenAddress, this.Port, MessageHandler.CreateInstance(123, this.Port)); } if (this.ServerType == ServerType.SSL_TLS) { if (this.Certificate != null && this.Protocol != System.Security.Authentication.SslProtocols.None) { // Create and prepare a new SSL server context NetCoreServer.SslContext context = new NetCoreServer.SslContext(this.Protocol, this.Certificate); // Create a new SSL Syslog server this.m_tlsServer = new TlsSyslogServer(context, this.ListenAddress, this.Port, MessageHandler.CreateInstance(123, this.Port)); } } if (this.m_udpServer == null && this.m_tcpServer == null && this.m_tlsServer == null) { // Can't start the server System.Console.Write("Server NOT starting..."); return(false); } // Start the server System.Console.Write("Server starting..."); if (this.m_udpServer != null) { this.m_udpServer.Start(); } if (this.m_tcpServer != null) { this.m_tcpServer.Start(); } if (this.m_tlsServer != null) { this.m_tlsServer.Start(); } System.Console.WriteLine("Done!"); return(true); }
} // End Function AllowAnything public static void Test() { System.Net.ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AllowAnything); // SSL server port int port = 6514; System.Console.WriteLine($"SSL server port: {port}"); System.Console.WriteLine(); string[] altNames = SelfSignedCertificate.SelfSigned.GetAlternativeNames(new string[0]); byte[] pfx = SelfSignedCertificate.SelfSigned.CreateSelfSignedCertificate(altNames, ""); System.Security.Cryptography.X509Certificates.X509Certificate2 cert = new System.Security.Cryptography.X509Certificates.X509Certificate2(pfx, "", System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.Exportable // https://github.com/dotnet/runtime/issues/23749 // | System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.EphemeralKeySet // Error ! ); // Create and prepare a new SSL server context NetCoreServer.SslContext context = new NetCoreServer.SslContext( // System.Security.Authentication.SslProtocols.Tls // System.Security.Authentication.SslProtocols.Tls13 System.Security.Authentication.SslProtocols.Tls12 , cert ); // Create a new SSL Syslog server TlsSyslogServer server = new TlsSyslogServer(context, System.Net.IPAddress.Any, port, MessageHandler.CreateInstance(123, port)); // Start the server System.Console.Write("Server starting..."); server.Start(); System.Console.WriteLine("Done!"); System.Console.WriteLine("Press Enter to stop the server or '!' to restart the server..."); // Perform text input for (; ;) { string line = System.Console.ReadLine(); if (string.IsNullOrEmpty(line)) { break; } // Restart the server if (line == "!") { System.Console.Write("Server restarting..."); server.Restart(); System.Console.WriteLine("Done!"); continue; } // End if (line == "!") // Multicast admin message to all sessions line = "(admin) " + line; server.Multicast(line); } // Next // Stop the server System.Console.Write("Server stopping..."); server.Stop(); System.Console.WriteLine("Done!"); } // End Sub Test