This is an automated email from the ASF dual-hosted git repository.

jensg pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git


The following commit(s) were added to refs/heads/master by this push:
     new 6378ff6  THRIFT-4825 Aligned the TTlsSocketServerTransport 
constructors with the TSocketServerTransport Client: C# Patch: Kyle Smith 
<[email protected]>
6378ff6 is described below

commit 6378ff69a624594dc4552076c9a24c5ae81b97a5
Author: Kyle Smith <[email protected]>
AuthorDate: Fri Mar 15 07:27:15 2019 -0400

    THRIFT-4825 Aligned the TTlsSocketServerTransport constructors with the 
TSocketServerTransport
    Client: C#
    Patch: Kyle Smith <[email protected]>
    
    This closes #1762
---
 .../Transport/Server/TTlsServerSocketTransport.cs  | 29 ++++++++++++++++------
 test/netstd/Server/TestServer.cs                   |  2 +-
 tutorial/netstd/Server/Program.cs                  |  2 +-
 3 files changed, 24 insertions(+), 9 deletions(-)

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,37 @@ namespace Thrift.Transport.Server
         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(
+            TcpListener listener,
+            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;
+            _localCertificateSelectionCallback = 
localCertificateSelectionCallback;
+            _sslProtocols = sslProtocols;
+            _server = listener;
         }
 
         public TTlsServerSocketTransport(
             int port,
-            Buffering buffering,
             X509Certificate2 certificate,
+            Buffering buffering = Buffering.None,
             RemoteCertificateValidationCallback clientCertValidator = null,
             LocalCertificateSelectionCallback 
localCertificateSelectionCallback = null,
             SslProtocols sslProtocols = SslProtocols.Tls12)
@@ -59,7 +75,6 @@ namespace Thrift.Transport.Server
                     "Your server-certificate needs to have a private key");
             }
 
-            _port = port;
             _serverCertificate = certificate;
             _buffering = buffering;
             _clientCertValidator = clientCertValidator;
@@ -69,7 +84,7 @@ namespace Thrift.Transport.Server
             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 @@ namespace ThriftTest
                         }
 
                         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 @@ Sample:
                     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);

Reply via email to