This commit is contained in:
jsaey 2023-11-17 09:47:50 +01:00
parent bab70bca3d
commit e6517ad662
10 changed files with 33 additions and 35 deletions

View File

@ -123,7 +123,7 @@ internal class Program
private static void StartServer(string serverUri, string certificatePath, string certificatePassword, string requiredPassword) private static void StartServer(string serverUri, string certificatePath, string certificatePassword, string requiredPassword)
{ {
_server = new WSServer(serverUri); _server = new WSServer(serverUri);
_server.SslConfiguration.Certificate = new X509Certificate2(certificatePath, certificatePassword); _server.SSL.Certificate = new X509Certificate2(certificatePath, certificatePassword);
_server.AddEndpoint<WelcomeEndpoint>("/Welcome"); _server.AddEndpoint<WelcomeEndpoint>("/Welcome");
_server.Start(); _server.Start();
} }

View File

@ -36,8 +36,7 @@ namespace EonaCat.Network
/// <param name="tcpClient">The <see cref="TcpClient"/> associated with the WebSocket connection.</param> /// <param name="tcpClient">The <see cref="TcpClient"/> associated with the WebSocket connection.</param>
/// <param name="protocol">The WebSocket protocol negotiated during the connection.</param> /// <param name="protocol">The WebSocket protocol negotiated during the connection.</param>
/// <param name="secure">A boolean indicating whether the connection is secure.</param> /// <param name="secure">A boolean indicating whether the connection is secure.</param>
/// <param name="sslConfig">The SSL configuration for secure connections.</param> /// <param name="sslConfig">The SSL config for secure connections.</param>
/// <param name="logger">The logger for logging.</param>
internal TcpListenerWSContext( internal TcpListenerWSContext(
TcpClient tcpClient, TcpClient tcpClient,
string protocol, string protocol,

View File

@ -89,7 +89,7 @@ namespace EonaCat.Network
public int Port => _endpoint.Port; public int Port => _endpoint.Port;
/// <summary> /// <summary>
/// Gets the SSL configuration for the secure endpoint. /// Gets the SSL config for the secure endpoint.
/// </summary> /// </summary>
public SSLConfigServer SSL { get; } public SSLConfigServer SSL { get; }

View File

@ -77,7 +77,7 @@ namespace EonaCat.Network
endpoint, endpoint,
pref.IsSecure, pref.IsSecure,
listener.CertificateFolderPath, listener.CertificateFolderPath,
listener.SslConfiguration, listener.SSL,
listener.ReuseAddress listener.ReuseAddress
); );

View File

@ -154,7 +154,7 @@ namespace EonaCat.Network
} }
} }
public SSLConfigServer SslConfiguration public SSLConfigServer SSL
{ {
get get
{ {

View File

@ -25,19 +25,19 @@ namespace EonaCat.Network
SslProtocols = SslProtocols.Tls12; SslProtocols = SslProtocols.Tls12;
} }
public SSLConfigClient(SSLConfigClient configuration) public SSLConfigClient(SSLConfigClient sslConfig)
{ {
if (configuration == null) if (sslConfig == null)
{ {
throw new ArgumentNullException(nameof(configuration)); throw new ArgumentNullException(nameof(sslConfig));
} }
CheckForCertificateRevocation = configuration.CheckForCertificateRevocation; CheckForCertificateRevocation = sslConfig.CheckForCertificateRevocation;
_clientCertSelectionCallback = configuration._clientCertSelectionCallback; _clientCertSelectionCallback = sslConfig._clientCertSelectionCallback;
_clientCertificates = configuration._clientCertificates; _clientCertificates = sslConfig._clientCertificates;
SslProtocols = configuration.SslProtocols; SslProtocols = sslConfig.SslProtocols;
_serverCertValidationCallback = configuration._serverCertValidationCallback; _serverCertValidationCallback = sslConfig._serverCertValidationCallback;
TargetHost = configuration.TargetHost; TargetHost = sslConfig.TargetHost;
} }
public bool CheckForCertificateRevocation { get; set; } public bool CheckForCertificateRevocation { get; set; }

View File

@ -23,18 +23,18 @@ namespace EonaCat.Network
SslProtocols = SslProtocols.Tls12; SslProtocols = SslProtocols.Tls12;
} }
public SSLConfigServer(SSLConfigServer configuration) public SSLConfigServer(SSLConfigServer sslConfig)
{ {
if (configuration == null) if (sslConfig == null)
{ {
throw new ArgumentNullException(nameof(configuration)); throw new ArgumentNullException(nameof(sslConfig));
} }
CheckForCertificateRevocation = configuration.CheckForCertificateRevocation; CheckForCertificateRevocation = sslConfig.CheckForCertificateRevocation;
IsClientCertificateRequired = configuration.IsClientCertificateRequired; IsClientCertificateRequired = sslConfig.IsClientCertificateRequired;
_clientCertificationValidationCallback = configuration._clientCertificationValidationCallback; _clientCertificationValidationCallback = sslConfig._clientCertificationValidationCallback;
SslProtocols = configuration.SslProtocols; SslProtocols = sslConfig.SslProtocols;
Certificate = configuration.Certificate; Certificate = sslConfig.Certificate;
} }
public bool CheckForCertificateRevocation { get; set; } public bool CheckForCertificateRevocation { get; set; }

View File

@ -283,7 +283,7 @@ namespace EonaCat.Network
} }
} }
public SSLConfigServer SslConfiguration public SSLConfigServer SSL
{ {
get get
{ {
@ -293,7 +293,7 @@ namespace EonaCat.Network
throw new InvalidOperationException(message); throw new InvalidOperationException(message);
} }
return _listener.SslConfiguration; return _listener.SSL;
} }
} }
@ -411,7 +411,7 @@ namespace EonaCat.Network
{ {
message = null; message = null;
var byUser = _listener.SslConfiguration.Certificate != null; var byUser = _listener.SSL.Certificate != null;
var path = _listener.CertificateFolderPath; var path = _listener.CertificateFolderPath;
var withPort = EndPointListener.CertificateExists(Port, path); var withPort = EndPointListener.CertificateExists(Port, path);

View File

@ -253,7 +253,7 @@ namespace EonaCat.Network
} }
} }
public SSLConfigServer SslConfiguration public SSLConfigServer SSL
{ {
get get
{ {
@ -263,7 +263,7 @@ namespace EonaCat.Network
throw new InvalidOperationException(message); throw new InvalidOperationException(message);
} }
return GetSslConfiguration(); return GetSSLConfig();
} }
} }
@ -366,13 +366,12 @@ namespace EonaCat.Network
|| name == _hostname; || name == _hostname;
} }
private static bool CheckSslConfiguration( private static bool CheckSslConfig(SSLConfigServer sslConfig, out string message
SSLConfigServer configuration, out string message
) )
{ {
message = null; message = null;
if (configuration.Certificate == null) if (sslConfig.Certificate == null)
{ {
message = "There is no server certificate for secure connections."; message = "There is no server certificate for secure connections.";
return false; return false;
@ -387,7 +386,7 @@ namespace EonaCat.Network
return realm != null && realm.Length > 0 ? realm : _defaultRealm; return realm != null && realm.Length > 0 ? realm : _defaultRealm;
} }
private SSLConfigServer GetSslConfiguration() private SSLConfigServer GetSSLConfig()
{ {
_sslConfig ??= new SSLConfigServer(); _sslConfig ??= new SSLConfigServer();
@ -705,9 +704,9 @@ namespace EonaCat.Network
if (IsSecure) if (IsSecure)
{ {
sslConfig = new SSLConfigServer(GetSslConfiguration()); sslConfig = new SSLConfigServer(GetSSLConfig());
if (!CheckSslConfiguration(sslConfig, out string message)) if (!CheckSslConfig(sslConfig, out string message))
{ {
throw new InvalidOperationException(message); throw new InvalidOperationException(message);
} }

View File

@ -10,7 +10,7 @@ namespace EonaCat.Network
public class FileReader public class FileReader
{ {
/// <summary> /// <summary>
/// Read a configuration file (varName=varValue format #beginning with comments) /// Reads a configuration file (varName=varValue format #beginning with comments)
/// </summary> /// </summary>
/// <returns>Parameter list.</returns> /// <returns>Parameter list.</returns>
/// <param name="filePath">File path.</param> /// <param name="filePath">File path.</param>