THRIFT-2347 C# TLS Transport based on THRIFT-181
Client: C#
Patch: Beat Käslin
This closes #104
commit 21c33abd59a2333c48722933c6894d8ed145e638
Author: Beat Kaeslin <beat.kaeslin@siemens.com>
Date: 2014-04-16T14:07:58Z
Add TLS transport for C#
commit 60a0baa1797b0ef0ea6f8c21e5b81a78cdfcdf16
Author: Beat Kaeslin <beat.kaeslin@siemens.com>
Date: 2014-04-17T06:23:57Z
csharp tests moved to the end
diff --git a/lib/csharp/test/ThriftTest/TestServer.cs b/lib/csharp/test/ThriftTest/TestServer.cs
index 965a7de..f0e9abb 100644
--- a/lib/csharp/test/ThriftTest/TestServer.cs
+++ b/lib/csharp/test/ThriftTest/TestServer.cs
@@ -23,6 +23,7 @@
// http://developers.facebook.com/thrift/
using System;
using System.Collections.Generic;
+using System.Security.Cryptography.X509Certificates;
using Thrift.Collections;
using Thrift.Test; //generated code
using Thrift.Transport;
@@ -321,7 +322,7 @@
{
try
{
- bool useBufferedSockets = false, useFramed = false;
+ bool useBufferedSockets = false, useFramed = false, useEncryption = false, compact = false, json = false;
int port = 9090, i = 0;
string pipe = null;
if (args.Length > 0)
@@ -343,7 +344,7 @@
{
// as default
}
- else if ( args[i] == "buffered" )
+ else if (args[i] == "buffered")
{
useBufferedSockets = true;
}
@@ -351,6 +352,18 @@
{
useFramed = true;
}
+ else if (args[i] == "ssl")
+ {
+ useEncryption = true;
+ }
+ else if (args[i] == "compact" )
+ {
+ compact = true;
+ }
+ else if (args[i] == "json" )
+ {
+ json = true;
+ }
else
{
// Fall back to the older boolean syntax
@@ -371,15 +384,30 @@
}
else
{
- trans = new TServerSocket(port, 0, useBufferedSockets);
+ if (useEncryption)
+ {
+ trans = new TTLSServerSocket(port, 0, useBufferedSockets, new X509Certificate2("../../../../../keys/server.pem"));
+ }
+ else
+ {
+ trans = new TServerSocket(port, 0, useBufferedSockets);
+ }
}
+ TProtocolFactory proto;
+ if ( compact )
+ proto = new TCompactProtocol.Factory();
+ else if ( json )
+ proto = new TJSONProtocol.Factory();
+ else
+ proto = new TBinaryProtocol.Factory();
+
// Simple Server
TServer serverEngine;
if ( useFramed )
- serverEngine = new TSimpleServer(testProcessor, trans, new TFramedTransport.Factory());
+ serverEngine = new TSimpleServer(testProcessor, trans, new TFramedTransport.Factory(), proto);
else
- serverEngine = new TSimpleServer(testProcessor, trans);
+ serverEngine = new TSimpleServer(testProcessor, trans, new TTransportFactory(), proto);
// ThreadPool Server
// serverEngine = new TThreadPoolServer(testProcessor, tServerSocket);
@@ -391,9 +419,11 @@
// Run it
string where = ( pipe != null ? "on pipe "+pipe : "on port " + port);
- Console.WriteLine("Starting the server " +where+
+ Console.WriteLine("Starting the server " + where +
(useBufferedSockets ? " with buffered socket" : "") +
(useFramed ? " with framed transport" : "") +
+ (useEncryption ? " with encryption" : "") +
+ (compact ? " with compact protocol" : "") +
"...");
serverEngine.Serve();