1+ using Microsoft . Extensions . Logging ;
12using System ;
23using System . Collections . Generic ;
34using System . Diagnostics ;
67using System . Net ;
78using System . Net . Security ;
89using System . Net . Sockets ;
9- using System . Text ;
1010using System . Threading ;
1111using System . Threading . Tasks ;
12- using Microsoft . Extensions . Logging ;
1312
1413namespace Enyim . Caching . Memcached
1514{
@@ -27,13 +26,24 @@ public partial class PooledSocket : IDisposable
2726
2827 private NetworkStream _inputStream ;
2928 private SslStream _sslStream ;
29+ private readonly SslClientAuthenticationOptions _sslClientAuthOptions ;
3030
31- public PooledSocket ( EndPoint endpoint , TimeSpan connectionTimeout , TimeSpan receiveTimeout , ILogger logger , bool useSslStream , bool useIPv6 )
31+ public PooledSocket ( EndPoint endpoint , TimeSpan connectionTimeout , TimeSpan receiveTimeout , ILogger logger , bool useSslStream , bool useIPv6 , SslClientAuthenticationOptions sslClientAuthOptions )
3232 {
3333 _logger = logger ;
3434 _isAlive = true ;
3535 _useSslStream = useSslStream ;
3636 _useIPv6 = useIPv6 ;
37+ _sslClientAuthOptions = sslClientAuthOptions ;
38+
39+ if ( _useSslStream && _sslClientAuthOptions == null )
40+ {
41+ // When not provided, create a default instance with target host set to the endpoint's host
42+ _sslClientAuthOptions = new SslClientAuthenticationOptions
43+ {
44+ TargetHost = ( ( DnsEndPoint ) _endpoint ) . Host ,
45+ } ;
46+ }
3747
3848 var socket = new Socket ( useIPv6 ? AddressFamily . InterNetworkV6 : AddressFamily . InterNetwork , SocketType . Stream , ProtocolType . Tcp ) ;
3949 socket . SetSocketOption ( SocketOptionLevel . Socket , SocketOptionName . KeepAlive , true ) ;
@@ -99,7 +109,7 @@ void Cancel()
99109 if ( _useSslStream )
100110 {
101111 _sslStream = new SslStream ( new NetworkStream ( _socket ) ) ;
102- _sslStream . AuthenticateAsClient ( ( ( DnsEndPoint ) _endpoint ) . Host ) ;
112+ _sslStream . AuthenticateAsClient ( _sslClientAuthOptions ) ;
103113 }
104114 else
105115 {
@@ -158,7 +168,7 @@ public async Task ConnectAsync()
158168 if ( _useSslStream )
159169 {
160170 _sslStream = new SslStream ( new NetworkStream ( _socket ) ) ;
161- await _sslStream . AuthenticateAsClientAsync ( ( ( DnsEndPoint ) _endpoint ) . Host ) ;
171+ await _sslStream . AuthenticateAsClientAsync ( _sslClientAuthOptions ) ;
162172 }
163173 else
164174 {
0 commit comments