Skip to content

Commit 55016bf

Browse files
peneninJens-G
authored andcommitted
THRIFT-5343: TTlsSocketTransport does not resolve IPv4 addresses or validate hostnames correctly
Client: netstd Patch: James Lacey This closes #2322
1 parent 4aaef75 commit 55016bf

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/netstd/Thrift/Transport/Client/TTlsSocketTransport.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class TTlsSocketTransport : TStreamTransport
3838
private readonly LocalCertificateSelectionCallback _localCertificateSelectionCallback;
3939
private readonly int _port;
4040
private readonly SslProtocols _sslProtocols;
41+
private readonly string _targetHost;
4142
private TcpClient _client;
4243
private SslStream _secureStream;
4344
private int _timeout;
@@ -122,13 +123,13 @@ public TTlsSocketTransport(string host, int port, TConfiguration config, int tim
122123
{
123124
try
124125
{
126+
_targetHost = host;
127+
125128
var entry = Dns.GetHostEntry(host);
126129
if (entry.AddressList.Length == 0)
127130
throw new TTransportException(TTransportException.ExceptionType.Unknown, "unable to resolve host name");
128131

129-
var addr = entry.AddressList[0];
130-
131-
_host = new IPAddress(addr.GetAddressBytes(), addr.ScopeId);
132+
_host = entry.AddressList[0];
132133
_port = port;
133134
_timeout = timeout;
134135
_certificate = certificate;
@@ -239,7 +240,7 @@ public async Task SetupTlsAsync()
239240
? new X509CertificateCollection {_certificate}
240241
: new X509CertificateCollection();
241242

242-
var targetHost = _host.ToString();
243+
var targetHost = _targetHost ?? _host.ToString();
243244
await _secureStream.AuthenticateAsClientAsync(targetHost, certs, _sslProtocols, true);
244245
}
245246
}

0 commit comments

Comments
 (0)