THRIFT-4825 Aligned the TTlsSocketServerTransport constructors with the TSocketServerTransport
Client: C#
Patch: Kyle Smith <ksmith@jrautomation.com>
This closes #1762
diff --git a/lib/netstd/Thrift/Transport/Server/TTlsServerSocketTransport.cs b/lib/netstd/Thrift/Transport/Server/TTlsServerSocketTransport.cs
index 2025b65..edfaced 100644
--- a/lib/netstd/Thrift/Transport/Server/TTlsServerSocketTransport.cs
+++ b/lib/netstd/Thrift/Transport/Server/TTlsServerSocketTransport.cs
@@ -34,21 +34,15 @@
private readonly RemoteCertificateValidationCallback _clientCertValidator;
private readonly int _clientTimeout = 0;
private readonly LocalCertificateSelectionCallback _localCertificateSelectionCallback;
- private readonly int _port;
private readonly X509Certificate2 _serverCertificate;
private readonly SslProtocols _sslProtocols;
private readonly Buffering _buffering;
private TcpListener _server;
-
- public TTlsServerSocketTransport(int port, X509Certificate2 certificate)
- : this(port, Buffering.None, certificate)
- {
- }
-
+
public TTlsServerSocketTransport(
- int port,
- Buffering buffering,
+ TcpListener listener,
X509Certificate2 certificate,
+ Buffering buffering = Buffering.None,
RemoteCertificateValidationCallback clientCertValidator = null,
LocalCertificateSelectionCallback localCertificateSelectionCallback = null,
SslProtocols sslProtocols = SslProtocols.Tls12)
@@ -59,7 +53,28 @@
"Your server-certificate needs to have a private key");
}
- _port = port;
+ _serverCertificate = certificate;
+ _buffering = buffering;
+ _clientCertValidator = clientCertValidator;
+ _localCertificateSelectionCallback = localCertificateSelectionCallback;
+ _sslProtocols = sslProtocols;
+ _server = listener;
+ }
+
+ public TTlsServerSocketTransport(
+ int port,
+ X509Certificate2 certificate,
+ Buffering buffering = Buffering.None,
+ RemoteCertificateValidationCallback clientCertValidator = null,
+ LocalCertificateSelectionCallback localCertificateSelectionCallback = null,
+ SslProtocols sslProtocols = SslProtocols.Tls12)
+ {
+ if (!certificate.HasPrivateKey)
+ {
+ throw new TTransportException(TTransportException.ExceptionType.Unknown,
+ "Your server-certificate needs to have a private key");
+ }
+
_serverCertificate = certificate;
_buffering = buffering;
_clientCertValidator = clientCertValidator;
@@ -69,7 +84,7 @@
try
{
// Create server socket
- _server = new TcpListener(IPAddress.Any, _port);
+ _server = new TcpListener(IPAddress.Any, port);
_server.Server.NoDelay = true;
}
catch (Exception)
diff --git a/test/netstd/Server/TestServer.cs b/test/netstd/Server/TestServer.cs
index 8db92dc..d15ca71 100644
--- a/test/netstd/Server/TestServer.cs
+++ b/test/netstd/Server/TestServer.cs
@@ -560,7 +560,7 @@
}
transFactory = new TTransportFactory(); // framed/buffered is built into socket transports
- trans = new TTlsServerSocketTransport( param.port, param.buffering, cert,
+ trans = new TTlsServerSocketTransport( param.port, cert, param.buffering,
(sender, certificate, chain, errors) => true,
null, SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12);
break;
diff --git a/tutorial/netstd/Server/Program.cs b/tutorial/netstd/Server/Program.cs
index d27e90d..e74a042 100644
--- a/tutorial/netstd/Server/Program.cs
+++ b/tutorial/netstd/Server/Program.cs
@@ -159,7 +159,7 @@
serverTransport = new TNamedPipeServerTransport(".test");
break;
case Transport.TcpTls:
- serverTransport = new TTlsServerSocketTransport(9090, Buffering.None, GetCertificate(), ClientCertValidator, LocalCertificateSelectionCallback);
+ serverTransport = new TTlsServerSocketTransport(9090, GetCertificate(), Buffering.None, ClientCertValidator, LocalCertificateSelectionCallback);
break;
case Transport.Framed:
serverTransport = new TServerFramedTransport(9090);