diff --git a/Tcp.NET.Client/Handlers/TcpClientHandlerBase.cs b/Tcp.NET.Client/Handlers/TcpClientHandlerBase.cs index 7efcc83..e72b3e6 100644 --- a/Tcp.NET.Client/Handlers/TcpClientHandlerBase.cs +++ b/Tcp.NET.Client/Handlers/TcpClientHandlerBase.cs @@ -385,7 +385,8 @@ protected virtual async Task CreateSSLConnectionAsync(CancellationToken cancella await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions { - TargetHost = _parameters.Host + TargetHost = _parameters.Host, + ClientCertificates = _parameters.ClientCertificates, }, cancellationToken).ConfigureAwait(false); if (sslStream.IsAuthenticated && sslStream.IsEncrypted && !cancellationToken.IsCancellationRequested) diff --git a/Tcp.NET.Client/Models/IParamsTcpClient.cs b/Tcp.NET.Client/Models/IParamsTcpClient.cs index 7b0df2a..3bd0334 100644 --- a/Tcp.NET.Client/Models/IParamsTcpClient.cs +++ b/Tcp.NET.Client/Models/IParamsTcpClient.cs @@ -1,4 +1,5 @@ using PHS.Networking.Models; +using System.Security.Cryptography.X509Certificates; namespace Tcp.NET.Client.Models { @@ -15,5 +16,6 @@ public interface IParamsTcpClient : IParams byte[] Token { get; } bool UseDisconnectBytes { get; } bool UsePingPong { get; } + X509CertificateCollection ClientCertificates { get; } } } \ No newline at end of file diff --git a/Tcp.NET.Client/Models/ParamsTcpClient.cs b/Tcp.NET.Client/Models/ParamsTcpClient.cs index 4e17d4e..15d1ace 100644 --- a/Tcp.NET.Client/Models/ParamsTcpClient.cs +++ b/Tcp.NET.Client/Models/ParamsTcpClient.cs @@ -1,5 +1,6 @@ using PHS.Networking.Utilities; using System; +using System.Security.Cryptography.X509Certificates; using System.Text; namespace Tcp.NET.Client.Models @@ -17,8 +18,9 @@ public class ParamsTcpClient : IParamsTcpClient public byte[] Token { get; protected set; } public bool UseDisconnectBytes { get; protected set; } public byte[] DisconnectBytes { get; protected set; } + public X509CertificateCollection ClientCertificates { get; protected set; } - public ParamsTcpClient(string host, int port, string endOfLineCharacters, string token = "", bool isSSL = true, bool onlyEmitBytes = false, bool usePingPong = true, string pingCharacters = "ping", string pongCharacters = "pong", bool useDisconnectBytes = true, byte[] disconnectBytes = null) + public ParamsTcpClient(string host, int port, string endOfLineCharacters, string token = "", bool isSSL = true, bool onlyEmitBytes = false, bool usePingPong = true, string pingCharacters = "ping", string pongCharacters = "pong", bool useDisconnectBytes = true, byte[] disconnectBytes = null, X509CertificateCollection clientCertificates = null) { if (string.IsNullOrWhiteSpace(host)) { @@ -55,6 +57,7 @@ public ParamsTcpClient(string host, int port, string endOfLineCharacters, string OnlyEmitBytes = onlyEmitBytes; UseDisconnectBytes = useDisconnectBytes; DisconnectBytes = disconnectBytes; + ClientCertificates = clientCertificates; if (!string.IsNullOrWhiteSpace(token)) { diff --git a/Tcp.NET.Client/Models/ParamsTcpClientBytes.cs b/Tcp.NET.Client/Models/ParamsTcpClientBytes.cs index 8ace0a1..42cfd6a 100644 --- a/Tcp.NET.Client/Models/ParamsTcpClientBytes.cs +++ b/Tcp.NET.Client/Models/ParamsTcpClientBytes.cs @@ -1,6 +1,7 @@ using PHS.Networking.Utilities; using System; using System.Linq; +using System.Security.Cryptography.X509Certificates; using System.Text; namespace Tcp.NET.Client.Models @@ -18,8 +19,9 @@ public class ParamsTcpClientBytes : IParamsTcpClient public byte[] Token { get; protected set; } public bool UseDisconnectBytes { get; protected set; } public byte[] DisconnectBytes { get; protected set; } + public X509CertificateCollection ClientCertificates { get; protected set; } - public ParamsTcpClientBytes(string host, int port, byte[] endOfLineBytes, byte[] token = null, bool isSSL = true, bool onlyEmitBytes = false, bool usePingPong = true, byte[] pingBytes = null, byte[] pongBytes = null, bool useDisconnectBytes = true, byte[] disconnectBytes = null) + public ParamsTcpClientBytes(string host, int port, byte[] endOfLineBytes, byte[] token = null, bool isSSL = true, bool onlyEmitBytes = false, bool usePingPong = true, byte[] pingBytes = null, byte[] pongBytes = null, bool useDisconnectBytes = true, byte[] disconnectBytes = null, X509CertificateCollection clientCertificates = null) { if (string.IsNullOrWhiteSpace(host)) { @@ -62,6 +64,7 @@ public ParamsTcpClientBytes(string host, int port, byte[] endOfLineBytes, byte[] UseDisconnectBytes = useDisconnectBytes; DisconnectBytes = disconnectBytes; Token = token; + ClientCertificates = clientCertificates; if (UseDisconnectBytes && (DisconnectBytes == null || Statics.ByteArrayEquals(DisconnectBytes, Array.Empty()))) {