From a8f2c97e130f5d14b2de975ef7514749199d74b4 Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 19 Mar 2020 12:56:19 -0700 Subject: [PATCH] Added CSharp example for multi-threaded TLS server. Refactor to separate the ssl and ctx handles. --- wrapper/CSharp/include.am | 41 ++++ .../wolfSSL-Example-IOCallbacks.cs | 6 +- .../wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs | 6 +- .../wolfSSL-TLS-Client.csproj | 2 +- .../wolfSSL-TLS-PSK-Server.cs | 6 +- .../wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs | 6 +- .../wolfSSL-TLS-Server.csproj | 2 +- .../wolfSSL-TLS-ServerThreaded/App.config | 6 + .../Properties/AssemblyInfo.cs | 36 +++ .../Properties/Settings.Designer.cs | 26 ++ .../Properties/Settings.settings | 6 + .../wolfSSL-TLS-ServerThreaded.cs | 194 +++++++++++++++ .../wolfSSL-TLS-ServerThreaded.csproj | 132 +++++++++++ wrapper/CSharp/wolfSSL_CSharp.sln | 26 ++ wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs | 223 ++++++++++++------ wrapper/include.am | 37 +-- 16 files changed, 631 insertions(+), 124 deletions(-) create mode 100644 wrapper/CSharp/include.am create mode 100755 wrapper/CSharp/wolfSSL-TLS-ServerThreaded/App.config create mode 100644 wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/AssemblyInfo.cs create mode 100644 wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.Designer.cs create mode 100755 wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.settings create mode 100755 wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.cs create mode 100755 wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.csproj mode change 100644 => 100755 wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs diff --git a/wrapper/CSharp/include.am b/wrapper/CSharp/include.am new file mode 100644 index 000000000..b0ec4f83d --- /dev/null +++ b/wrapper/CSharp/include.am @@ -0,0 +1,41 @@ +# wolfSSL CSharp wrapper files +EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/App.config +EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/Properties/AssemblyInfo.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/wolfSSL-DTLS-PSK-Server.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/wolfSSL-DTLS-PSK-Server.csproj +EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-Server/App.config +EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-Server/Properties/AssemblyInfo.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-Server/wolfSSL-DTLS-Server.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-Server/wolfSSL-DTLS-Server.csproj +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-PSK-Server/App.config +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-PSK-Server/Properties/AssemblyInfo.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-PSK-Server/wolfSSL-TLS-PSK-Server.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-PSK-Server/wolfSSL-TLS-PSK-Server.csproj +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/App.config +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/Properties/AssemblyInfo.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/Properties/Settings.Designer.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/Properties/Settings.settings +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.csproj +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-ServerThreaded/App.config +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/AssemblyInfo.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.Designer.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.settings +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.csproj +EXTRA_DIST+= wrapper/CSharp/wolfSSL-Example-IOCallbacks/App.config +EXTRA_DIST+= wrapper/CSharp/wolfSSL-Example-IOCallbacks/Properties/AssemblyInfo.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-Example-IOCallbacks/wolfSSL-Example-IOCallbacks.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-Example-IOCallbacks/wolfSSL-Example-IOCallbacks.csproj +EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp.sln +EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/Properties/AssemblyInfo.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/Properties/Resources.Designer.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/Properties/Resources.resx +EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/wolfSSL_CSharp.csproj +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/App.config +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/Properties/AssemblyInfo.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/Properties/Settings.Designer.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/Properties/Settings.settings +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs +EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj diff --git a/wrapper/CSharp/wolfSSL-Example-IOCallbacks/wolfSSL-Example-IOCallbacks.cs b/wrapper/CSharp/wolfSSL-Example-IOCallbacks/wolfSSL-Example-IOCallbacks.cs index 9be5e118c..f57a63224 100644 --- a/wrapper/CSharp/wolfSSL-Example-IOCallbacks/wolfSSL-Example-IOCallbacks.cs +++ b/wrapper/CSharp/wolfSSL-Example-IOCallbacks/wolfSSL-Example-IOCallbacks.cs @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ - + using System; using System.Collections.Generic; @@ -235,7 +235,7 @@ class wolfSSL_Example_IOCallbacks if (wolfssl.set_fd(ssl, fd) != wolfssl.SUCCESS) { /* get and print out the error */ - Console.Write(wolfssl.get_error(ssl)); + Console.WriteLine(wolfssl.get_error(ssl)); tcp.Stop(); clean(ssl, ctx); return; @@ -244,7 +244,7 @@ class wolfSSL_Example_IOCallbacks if (wolfssl.accept(ssl) != wolfssl.SUCCESS) { /* get and print out the error */ - Console.Write(wolfssl.get_error(ssl)); + Console.WriteLine(wolfssl.get_error(ssl)); tcp.Stop(); clean(ssl, ctx); return; diff --git a/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs index c2e3321df..dcba3568e 100755 --- a/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs +++ b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs @@ -28,7 +28,7 @@ using System.Net; using System.Net.Sockets; using wolfSSL.CSharp; -public class wolfSSL_TLS_CSHarp +public class wolfSSL_TLS_Client { /// /// Example of a logging function @@ -163,7 +163,7 @@ public class wolfSSL_TLS_CSHarp if (wolfssl.set_fd(ssl, tcp) != wolfssl.SUCCESS) { /* get and print out the error */ - Console.Write(wolfssl.get_error(ssl)); + Console.WriteLine(wolfssl.get_error(ssl)); tcp.Close(); clean(ssl, ctx); return; @@ -174,7 +174,7 @@ public class wolfSSL_TLS_CSHarp if (wolfssl.connect(ssl) != wolfssl.SUCCESS) { /* get and print out the error */ - Console.Write(wolfssl.get_error(ssl)); + Console.WriteLine(wolfssl.get_error(ssl)); tcp.Close(); clean(ssl, ctx); return; diff --git a/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj index 19544e8a6..2959f6f90 100755 --- a/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj +++ b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj @@ -7,7 +7,7 @@ {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8} Exe Properties - wolfSSL_TLS_CSharp + wolfSSL_TLS_Client wolfSSL-TLS-Client v4.5 512 diff --git a/wrapper/CSharp/wolfSSL-TLS-PSK-Server/wolfSSL-TLS-PSK-Server.cs b/wrapper/CSharp/wolfSSL-TLS-PSK-Server/wolfSSL-TLS-PSK-Server.cs index 0fbe89f35..e8697062a 100644 --- a/wrapper/CSharp/wolfSSL-TLS-PSK-Server/wolfSSL-TLS-PSK-Server.cs +++ b/wrapper/CSharp/wolfSSL-TLS-PSK-Server/wolfSSL-TLS-PSK-Server.cs @@ -18,7 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA */ - + using System; using System.Runtime.InteropServices; @@ -165,7 +165,7 @@ public class wolfSSL_TLS_PSK_Server if (wolfssl.set_fd(ssl, fd) != wolfssl.SUCCESS) { /* get and print out the error */ - Console.Write(wolfssl.get_error(ssl)); + Console.WriteLine(wolfssl.get_error(ssl)); tcp.Stop(); clean(ssl, ctx); return; @@ -176,7 +176,7 @@ public class wolfSSL_TLS_PSK_Server if (wolfssl.accept(ssl) != wolfssl.SUCCESS) { /* get and print out the error */ - Console.Write(wolfssl.get_error(ssl)); + Console.WriteLine(wolfssl.get_error(ssl)); tcp.Stop(); clean(ssl, ctx); return; diff --git a/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs b/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs index feef463d0..262bd74be 100755 --- a/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs +++ b/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs @@ -108,7 +108,7 @@ public class wolfSSL_TLS_CSHarp wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey); /* set up TCP socket */ - IPAddress ip = IPAddress.Parse("0.0.0.0"); //bind to any + IPAddress ip = IPAddress.Parse("0.0.0.0"); /* bind to any */ TcpListener tcp = new TcpListener(ip, 11111); tcp.Start(); @@ -126,7 +126,7 @@ public class wolfSSL_TLS_CSHarp if (wolfssl.set_fd(ssl, fd) != wolfssl.SUCCESS) { /* get and print out the error */ - Console.Write(wolfssl.get_error(ssl)); + Console.WriteLine(wolfssl.get_error(ssl)); tcp.Stop(); clean(ssl, ctx); return; @@ -137,7 +137,7 @@ public class wolfSSL_TLS_CSHarp if (wolfssl.accept(ssl) != wolfssl.SUCCESS) { /* get and print out the error */ - Console.Write(wolfssl.get_error(ssl)); + Console.WriteLine(wolfssl.get_error(ssl)); tcp.Stop(); clean(ssl, ctx); return; diff --git a/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.csproj b/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.csproj index b5b5006ea..7ab3a6f07 100755 --- a/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.csproj +++ b/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.csproj @@ -7,7 +7,7 @@ {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2} Exe Properties - wolfSSL_TLS_CSharp + wolfSSL_TLS_Server wolfSSL-TLS-Server v4.5 512 diff --git a/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/App.config b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/App.config new file mode 100755 index 000000000..8e1564635 --- /dev/null +++ b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/AssemblyInfo.cs b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..e786a4dd2 --- /dev/null +++ b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("wolfSSL-TLS-Server")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("wolfSSL")] +[assembly: AssemblyProduct("wolfSSL-TLS-Server")] +[assembly: AssemblyCopyright("Copyright wolfSSL 2020")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("716e8f30-1318-4e3b-b788-d0380b397a4c")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.1.0.0")] +[assembly: AssemblyFileVersion("1.1.0.0")] diff --git a/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.Designer.cs b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.Designer.cs new file mode 100644 index 000000000..524c01375 --- /dev/null +++ b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.17929 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace wolfSSL_TLS_CSharp.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.settings b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.settings new file mode 100755 index 000000000..049245f40 --- /dev/null +++ b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.settings @@ -0,0 +1,6 @@ + + + + + + diff --git a/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.cs b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.cs new file mode 100755 index 000000000..2f9da4e24 --- /dev/null +++ b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.cs @@ -0,0 +1,194 @@ +/* wolfSSL-TLS-ServerThreaded.cs + * + * Copyright (C) 2006-2020 wolfSSL Inc. + * + * This file is part of wolfSSL. + * + * wolfSSL is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * wolfSSL is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA + */ + + +using System; +using System.Runtime.InteropServices; +using System.Text; +using System.IO; +using System.Net; +using System.Net.Sockets; +using System.Threading; + +using wolfSSL.CSharp; + +public class wolfSSL_TLS_ServerThread +{ + private IntPtr _ctx; + private Socket _fd; + + public wolfSSL_TLS_ServerThread(IntPtr ctx, Socket fd) + { + _ctx = ctx; + _fd = fd; + } + + private const int kEchoBufSz = 1024; + public void start_client() + { + StringBuilder buff = new StringBuilder(kEchoBufSz); + IntPtr ssl = wolfssl.new_ssl(_ctx); + if (ssl == IntPtr.Zero) + { + Console.WriteLine("Error in creating ssl object"); + return; + } + + if (wolfssl.set_fd(ssl, _fd) != wolfssl.SUCCESS) + { + /* get and print out the error */ + Console.WriteLine(wolfssl.get_error(ssl)); + _fd.Close(); + wolfssl.free(ssl); + return; + } + + Console.WriteLine("Starting TLS handshake"); + if (wolfssl.accept(ssl) != wolfssl.SUCCESS) + { + /* get and print out the error */ + Console.WriteLine("Failed " + wolfssl.get_error(ssl)); + _fd.Close(); + wolfssl.free(ssl); + return; + } + + /* print out results of TLS/SSL accept */ + Console.WriteLine("SSL version is " + wolfssl.get_version(ssl)); + Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl)); + + /* echo data until error */ + while (true) + { + /* read and print out the message then reply */ + if (wolfssl.read(ssl, buff, kEchoBufSz-1) < 0) + { + Console.WriteLine("Error in read"); + break; + } + Console.WriteLine(buff); + + if (wolfssl.write(ssl, buff, buff.Length) != buff.Length) + { + Console.WriteLine("Error in write"); + break; + } + } + + Console.WriteLine("Closing " + wolfssl.get_error(ssl)); + _fd.Close(); + wolfssl.free(ssl); + } +} + +public class wolfSSL_TLS_ServerThreaded +{ + /// + /// Example of a logging function + /// + /// level of log + /// message to log + public static void standard_log(int lvl, StringBuilder msg) + { + Console.WriteLine(msg); + } + + public static void Main(string[] args) + { + IntPtr ctx; + + /* These paths should be changed for use */ + string fileCert = @"server-cert.pem"; + string fileKey = @"server-key.pem"; + StringBuilder dhparam = new StringBuilder("dh2048.pem"); + + /* example of function used for setting logging */ + wolfssl.SetLogging(standard_log); + wolfssl.Init(); + + Console.WriteLine("Calling ctx Init from wolfSSL"); + ctx = wolfssl.CTX_new(wolfssl.usev23_server()); + if (ctx == IntPtr.Zero) + { + Console.WriteLine("Error in creating ctx structure"); + return; + } + Console.WriteLine("Finished init of ctx .... now load in cert and key"); + + if (!File.Exists(fileCert) || !File.Exists(fileKey)) + { + Console.WriteLine("Could not find cert or key file"); + wolfssl.CTX_free(ctx); + return; + } + + if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS) + { + Console.WriteLine("Error in setting cert file"); + wolfssl.CTX_free(ctx); + return; + } + + if (wolfssl.CTX_use_PrivateKey_file(ctx, fileKey, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS) + { + Console.WriteLine("Error in setting key file"); + wolfssl.CTX_free(ctx); + return; + } + + StringBuilder ciphers = new StringBuilder(new String(' ', 4096)); + wolfssl.get_ciphers(ciphers, 4096); + Console.WriteLine("Ciphers : " + ciphers.ToString()); + + short minDhKey = 128; + wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey); + wolfssl.CTX_SetTmpDH_file(ctx, dhparam, wolfssl.SSL_FILETYPE_PEM); + + /* set up TCP socket */ + IPAddress ip = IPAddress.Parse("0.0.0.0"); /* bind to any */ + TcpListener tcp = new TcpListener(ip, 11111); + tcp.Start(); + + Console.WriteLine("Started TCP and waiting for a connection"); + + while (true) { + try + { + Socket fd = tcp.AcceptSocket(); + Console.WriteLine("Got client connection"); + + /* Spin up thread for client */ + wolfSSL_TLS_ServerThread thread = new wolfSSL_TLS_ServerThread(ctx, fd); + Thread thr = new Thread(new ThreadStart(thread.start_client)); + thr.Start(); + } + catch(Exception ex) + { + Console.WriteLine("Server Exception " + ex.ToString()); + break; + } + } + + tcp.Stop(); + wolfssl.CTX_free(ctx); + wolfssl.Cleanup(); + } +} diff --git a/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.csproj b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.csproj new file mode 100755 index 000000000..bbbe57a4e --- /dev/null +++ b/wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.csproj @@ -0,0 +1,132 @@ + + + + + Debug + AnyCPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F} + Exe + Properties + wolfSSL_TLS_ServerThreaded + wolfSSL-TLS-ServerThreaded + v4.5 + 512 + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + ..\DLL Debug\ + DEBUG;TRACE + prompt + 3 + + + AnyCPU + pdbonly + true + ..\DLL Release\ + TRACE + prompt + 4 + + + + + + true + ..\x64\DLL Debug\ + DEBUG;TRACE + 4 + full + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + ..\x64\DLL Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + + + + + + + + + + + True + True + Settings.settings + + + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + + + {52609808-0418-46d3-8e17-141927a1a39a} + wolfSSL_CSharp + + + + + False + Microsoft .NET Framework 4.5 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 Client Profile + false + + + False + .NET Framework 3.5 SP1 + false + + + + + + + + + \ No newline at end of file diff --git a/wrapper/CSharp/wolfSSL_CSharp.sln b/wrapper/CSharp/wolfSSL_CSharp.sln index 12e1a828a..a90e05bd2 100755 --- a/wrapper/CSharp/wolfSSL_CSharp.sln +++ b/wrapper/CSharp/wolfSSL_CSharp.sln @@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wolfSSL-Example-IOCallbacks EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wolfSSL-TLS-Client", "wolfSSL-TLS-Client\wolfSSL-TLS-Client.csproj", "{B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wolfSSL-TLS-ServerThreaded", "wolfSSL-TLS-ServerThreaded\wolfSSL-TLS-ServerThreaded.csproj", "{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -251,6 +253,30 @@ Global {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.Release|Win32.Build.0 = Release|Any CPU {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.Release|x64.ActiveCfg = Release|x64 {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.Release|x64.Build.0 = Release|x64 + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Debug|Win32.ActiveCfg = Debug|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Debug|Win32.Build.0 = Debug|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Debug|x64.ActiveCfg = Debug|x64 + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Debug|x64.Build.0 = Debug|x64 + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Debug|Any CPU.Build.0 = Debug|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Debug|Win32.ActiveCfg = Debug|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Debug|Win32.Build.0 = Debug|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Debug|x64.ActiveCfg = Debug|x64 + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Debug|x64.Build.0 = Debug|x64 + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Release|Any CPU.ActiveCfg = Release|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Release|Any CPU.Build.0 = Release|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Release|Win32.ActiveCfg = Release|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Release|Win32.Build.0 = Release|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Release|x64.ActiveCfg = Release|x64 + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Release|x64.Build.0 = Release|x64 + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Release|Any CPU.Build.0 = Release|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Release|Win32.ActiveCfg = Release|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Release|Win32.Build.0 = Release|Any CPU + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Release|x64.ActiveCfg = Release|x64 + {8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs b/wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs old mode 100644 new mode 100755 index 6953c8505..7acbe77ea --- a/wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs +++ b/wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs @@ -50,22 +50,20 @@ namespace wolfSSL.CSharp { /******************************** - * Class for keeping ctx/ssl handles alive + * Class for keeping ctx handles alive */ [StructLayout(LayoutKind.Sequential)] - private class ctx_handles + private class ctx_handle { private GCHandle rec_cb; private GCHandle snd_cb; private GCHandle psk_cb; - private GCHandle fd_pin; private IntPtr ctx; public void set_receive(GCHandle input) { this.rec_cb = input; } - public GCHandle get_receive() { return this.rec_cb; @@ -75,7 +73,6 @@ namespace wolfSSL.CSharp { { this.snd_cb = input; } - public GCHandle get_send() { return this.snd_cb; @@ -85,27 +82,15 @@ namespace wolfSSL.CSharp { { this.psk_cb = input; } - public GCHandle get_psk() { return this.psk_cb; } - public void set_fd(GCHandle input) - { - this.fd_pin = input; - } - - public GCHandle get_fd() - { - return this.fd_pin; - } - public void set_ctx(IntPtr input) { this.ctx = input; } - public IntPtr get_ctx() { return this.ctx; @@ -116,7 +101,7 @@ namespace wolfSSL.CSharp { /// public void free() { - log(INFO_LOG, "freeing handles"); + log(INFO_LOG, "freeing ctx handle"); if (!Object.Equals(this.rec_cb, default(GCHandle))) { this.rec_cb.Free(); @@ -129,10 +114,57 @@ namespace wolfSSL.CSharp { { this.psk_cb.Free(); } + } + } + + /******************************** + * Class for keeping ssl handle alive + */ + [StructLayout(LayoutKind.Sequential)] + private class ssl_handle + { + private GCHandle fd_pin; + private GCHandle psk_cb; + private IntPtr ssl; + + public void set_fd(GCHandle input) + { + this.fd_pin = input; + } + public GCHandle get_fd() + { + return this.fd_pin; + } + + public void set_psk(GCHandle input) + { + this.psk_cb = input; + } + public GCHandle get_psk() + { + return this.psk_cb; + } + + public void set_ssl(IntPtr input) + { + this.ssl = input; + } + public IntPtr get_ssl() + { + return this.ssl; + } + public void free() + { + log(INFO_LOG, "freeing ssl handle"); + if (!Object.Equals(this.fd_pin, default(GCHandle))) { this.fd_pin.Free(); } + if (!Object.Equals(this.psk_cb, default(GCHandle))) + { + this.psk_cb.Free(); + } } } @@ -282,6 +314,8 @@ namespace wolfSSL.CSharp { private extern static int wolfSSL_CTX_SetMinDhKey_Sz(IntPtr ctx, short size); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] private extern static int wolfSSL_SetTmpDH_file(IntPtr ssl, StringBuilder dhParam, int type); + [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] + private extern static int wolfSSL_CTX_SetTmpDH_file(IntPtr ctx, StringBuilder dhParam, int type); /******************************** @@ -325,13 +359,25 @@ namespace wolfSSL.CSharp { public static readonly int FAILURE = 0; - private static IntPtr unwrap(IntPtr ctx) + private static IntPtr unwrap_ctx(IntPtr ctx) { try { GCHandle gch = GCHandle.FromIntPtr(ctx); - ctx_handles handles = (ctx_handles)gch.Target; + ctx_handle handles = (ctx_handle)gch.Target; return handles.get_ctx(); } catch (Exception e) + { + log(ERROR_LOG, "wolfssl ctx pointer is incorrect " + e); + return IntPtr.Zero; + } + } + private static IntPtr unwrap_ssl(IntPtr ssl) + { + try { + GCHandle gch = GCHandle.FromIntPtr(ssl); + ssl_handle handles = (ssl_handle)gch.Target; + return handles.get_ssl(); + } catch (Exception e) { log(ERROR_LOG, "wolfssl pointer is incorrect " + e); return IntPtr.Zero; @@ -517,19 +563,19 @@ namespace wolfSSL.CSharp { try { - ctx_handles io; - IntPtr local_ctx = unwrap(ctx); + ssl_handle io; + IntPtr local_ctx = unwrap_ctx(ctx); if (local_ctx == IntPtr.Zero) { - log(ERROR_LOG, "new_ssl error"); + log(ERROR_LOG, "new_ssl ctx unwrap error"); return IntPtr.Zero; } - io = new ctx_handles(); - io.set_ctx(wolfSSL_new(local_ctx)); + io = new ssl_handle(); + io.set_ssl(wolfSSL_new(local_ctx)); /* check if null */ - if (io.get_ctx() == IntPtr.Zero) + if (io.get_ssl() == IntPtr.Zero) { return IntPtr.Zero; } @@ -556,10 +602,10 @@ namespace wolfSSL.CSharp { return FAILURE; try { - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); if (sslCtx == IntPtr.Zero) { - log(ERROR_LOG, "accept error"); + log(ERROR_LOG, "accept ssl unwrap error"); return FAILURE; } @@ -584,10 +630,10 @@ namespace wolfSSL.CSharp { return FAILURE; try { - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); if (sslCtx == IntPtr.Zero) { - log(ERROR_LOG, "connect error"); + log(ERROR_LOG, "connect ssl unwrap error"); return FAILURE; } @@ -614,14 +660,16 @@ namespace wolfSSL.CSharp { return FAILURE; try { - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); IntPtr data; int ret; byte[] msg; + buf.Clear(); /* Clear incomming buffer */ + if (sslCtx == IntPtr.Zero) { - log(ERROR_LOG, "read error"); + log(ERROR_LOG, "read ssl unwrap error"); return FAILURE; } data = Marshal.AllocHGlobal(sz); @@ -666,13 +714,13 @@ namespace wolfSSL.CSharp { return FAILURE; try { - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); IntPtr data; int ret; if (sslCtx == IntPtr.Zero) { - log(ERROR_LOG, "wolfssl read error"); + log(ERROR_LOG, "read ssl unwrap error"); return FAILURE; } data = Marshal.AllocHGlobal(sz); @@ -709,13 +757,13 @@ namespace wolfSSL.CSharp { return FAILURE; try { - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); IntPtr data; int ret; if (sslCtx == IntPtr.Zero) { - log(ERROR_LOG, "write error"); + log(ERROR_LOG, "write ssl unwrap error"); return FAILURE; } @@ -748,13 +796,13 @@ namespace wolfSSL.CSharp { return FAILURE; try { - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); IntPtr data; int ret; if (sslCtx == IntPtr.Zero) { - log(ERROR_LOG, "write error"); + log(ERROR_LOG, "write ssl unwrap error"); return FAILURE; } data = Marshal.AllocHGlobal(sz); @@ -782,9 +830,9 @@ namespace wolfSSL.CSharp { { IntPtr sslCtx; GCHandle gch = GCHandle.FromIntPtr(ssl); - ctx_handles handles = (ctx_handles)gch.Target; + ssl_handle handles = (ssl_handle)gch.Target; - sslCtx = handles.get_ctx(); + sslCtx = handles.get_ssl(); wolfSSL_free(sslCtx); handles.free(); gch.Free(); @@ -807,10 +855,10 @@ namespace wolfSSL.CSharp { return FAILURE; try { - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); if (sslCtx == IntPtr.Zero) { - log(ERROR_LOG, "wolfssl shutdown error"); + log(ERROR_LOG, "shutdown ssl unwrap error"); return FAILURE; } @@ -834,7 +882,7 @@ namespace wolfSSL.CSharp { try { GCHandle gch = GCHandle.FromIntPtr(ctx); - ctx_handles handles = (ctx_handles)gch.Target; + ctx_handle handles = (ctx_handle)gch.Target; /* check if already stored handle needs freed */ gch = handles.get_receive(); @@ -865,7 +913,7 @@ namespace wolfSSL.CSharp { try { GCHandle gch = GCHandle.FromIntPtr(ctx); - ctx_handles handles = (ctx_handles)gch.Target; + ctx_handle handles = (ctx_handle)gch.Target; /* check if already stored handle needs freed */ gch = handles.get_send(); @@ -899,7 +947,7 @@ namespace wolfSSL.CSharp { if (ctx == IntPtr.Zero) return ctx; - ctx_handles io = new ctx_handles(); + ctx_handle io = new ctx_handle(); io.set_ctx(ctx); CallbackIORecv_delegate recv = new CallbackIORecv_delegate(wolfssl.wolfSSLCbIORecv); @@ -934,7 +982,7 @@ namespace wolfSSL.CSharp { if (ctx == IntPtr.Zero) return ctx; - ctx_handles io = new ctx_handles(); + ctx_handle io = new ctx_handle(); io.set_ctx(ctx); CallbackIORecv_delegate recv = new CallbackIORecv_delegate(wolfssl.wolfSSL_dtlsCbIORecv); @@ -965,7 +1013,7 @@ namespace wolfSSL.CSharp { try { GCHandle gch = GCHandle.FromIntPtr(ctx); - ctx_handles handles = (ctx_handles)gch.Target; + ctx_handle handles = (ctx_handle)gch.Target; wolfSSL_CTX_free(handles.get_ctx()); handles.free(); gch.Free(); @@ -987,10 +1035,10 @@ namespace wolfSSL.CSharp { { try { - IntPtr local_ctx = unwrap(ctx); + IntPtr local_ctx = unwrap_ctx(ctx); if (local_ctx == IntPtr.Zero) { - log(ERROR_LOG, "CTX use psk identity hint error"); + log(ERROR_LOG, "CTX use psk identity hint unwrap error"); return FAILURE; } @@ -1014,7 +1062,7 @@ namespace wolfSSL.CSharp { try { GCHandle gch = GCHandle.FromIntPtr(ctx); - ctx_handles handles = (ctx_handles)gch.Target; + ctx_handle handles = (ctx_handle)gch.Target; handles.set_psk(GCHandle.Alloc(psk_cb)); wolfSSL_CTX_set_psk_server_callback(handles.get_ctx(), psk_cb); @@ -1036,7 +1084,7 @@ namespace wolfSSL.CSharp { try { GCHandle gch = GCHandle.FromIntPtr(ctx); - ctx_handles handles = (ctx_handles)gch.Target; + ctx_handle handles = (ctx_handle)gch.Target; handles.set_psk(GCHandle.Alloc(psk_cb)); wolfSSL_CTX_set_psk_client_callback(handles.get_ctx(), psk_cb); @@ -1058,10 +1106,10 @@ namespace wolfSSL.CSharp { try { GCHandle gch = GCHandle.FromIntPtr(ssl); - ctx_handles handles = (ctx_handles)gch.Target; + ssl_handle handles = (ssl_handle)gch.Target; handles.set_psk(GCHandle.Alloc(psk_cb)); - wolfSSL_set_psk_server_callback(handles.get_ctx(), psk_cb); + wolfSSL_set_psk_server_callback(handles.get_ssl(), psk_cb); } catch (Exception e) { @@ -1089,8 +1137,8 @@ namespace wolfSSL.CSharp { if (!fd.Equals(null)) { GCHandle gch = GCHandle.FromIntPtr(ssl); - ctx_handles handles = (ctx_handles)gch.Target; - IntPtr sslCtx = handles.get_ctx(); + ssl_handle handles = (ssl_handle)gch.Target; + IntPtr sslCtx = handles.get_ssl(); IntPtr ptr; GCHandle fd_pin = GCHandle.Alloc(fd); @@ -1128,7 +1176,7 @@ namespace wolfSSL.CSharp { try { IntPtr ptr; - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); if (sslCtx == IntPtr.Zero) { log(ERROR_LOG, "wolfssl get_fd error"); @@ -1174,7 +1222,7 @@ namespace wolfSSL.CSharp { IntPtr ptr; DTLS_con con; GCHandle gch = GCHandle.FromIntPtr(ssl); - ctx_handles handles = (ctx_handles)gch.Target; + ssl_handle handles = (ssl_handle)gch.Target; GCHandle fd_pin; con = new DTLS_con(); @@ -1183,8 +1231,8 @@ namespace wolfSSL.CSharp { fd_pin = GCHandle.Alloc(con); handles.set_fd(fd_pin); ptr = GCHandle.ToIntPtr(fd_pin); - wolfSSL_SetIOWriteCtx(handles.get_ctx(), ptr); //pass along the socket for writing to - wolfSSL_SetIOReadCtx(handles.get_ctx(), ptr); //pass along the socket for reading from + wolfSSL_SetIOWriteCtx(handles.get_ssl(), ptr); //pass along the socket for writing to + wolfSSL_SetIOReadCtx(handles.get_ssl(), ptr); //pass along the socket for reading from return SUCCESS; } @@ -1208,7 +1256,7 @@ namespace wolfSSL.CSharp { try { IntPtr ptr; - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); if (sslCtx == IntPtr.Zero) { log(ERROR_LOG, "wolfssl get_dtls_fd error"); @@ -1443,7 +1491,7 @@ namespace wolfSSL.CSharp { IntPtr ssl_cipher_ptr; string ssl_cipher_str; - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); if (sslCtx == IntPtr.Zero) { log(ERROR_LOG, "wolfssl get_current_cipher error"); @@ -1474,7 +1522,7 @@ namespace wolfSSL.CSharp { { try { - IntPtr local_ctx = unwrap(ctx); + IntPtr local_ctx = unwrap_ctx(ctx); if (local_ctx == IntPtr.Zero) { log(ERROR_LOG, "CTX set cipher list error"); @@ -1501,7 +1549,7 @@ namespace wolfSSL.CSharp { { try { - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); if (sslCtx == IntPtr.Zero) { log(ERROR_LOG, "wolfssl set_cipher_list error"); @@ -1533,7 +1581,7 @@ namespace wolfSSL.CSharp { IntPtr version_ptr; string version; - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); if (sslCtx == IntPtr.Zero) { log(ERROR_LOG, "wolfssl get_version error"); @@ -1569,7 +1617,7 @@ namespace wolfSSL.CSharp { StringBuilder err_name; StringBuilder ret; - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); if (sslCtx == IntPtr.Zero) { log(ERROR_LOG, "wolfssl get_error error"); @@ -1604,7 +1652,7 @@ namespace wolfSSL.CSharp { { try { - IntPtr local_ctx = unwrap(ctx); + IntPtr local_ctx = unwrap_ctx(ctx); if (local_ctx == IntPtr.Zero) { log(ERROR_LOG, "CTX use certificate file error"); @@ -1632,7 +1680,7 @@ namespace wolfSSL.CSharp { { try { - IntPtr local_ctx = unwrap(ctx); + IntPtr local_ctx = unwrap_ctx(ctx); if (local_ctx == IntPtr.Zero) { log(ERROR_LOG, "CTX load verify locations certificate file error"); @@ -1659,7 +1707,7 @@ namespace wolfSSL.CSharp { { try { - IntPtr local_ctx = unwrap(ctx); + IntPtr local_ctx = unwrap_ctx(ctx); if (local_ctx == IntPtr.Zero) { log(ERROR_LOG, "CTX use PrivateKey file error"); @@ -1687,10 +1735,10 @@ namespace wolfSSL.CSharp { { try { - IntPtr sslCtx = unwrap(ssl); + IntPtr sslCtx = unwrap_ssl(ssl); if (sslCtx == IntPtr.Zero) { - log(ERROR_LOG, "wolfssl SetTmpDH_file error"); + log(ERROR_LOG, "SetTmpDH_file ssl unwrap error"); return FAILURE; } @@ -1698,7 +1746,34 @@ namespace wolfSSL.CSharp { } catch (Exception e) { - log(ERROR_LOG, "wolfssl set tmp dh file error " + e.ToString()); + log(ERROR_LOG, "SetTmpDH_file error " + e.ToString()); + return FAILURE; + } + } + + /// + /// Set temporary DH parameters + /// + /// Structure to set in + /// file name + /// type of file ie PEM + /// 1 on success + public static int CTX_SetTmpDH_file(IntPtr ctx, StringBuilder dhparam, int file_type) + { + try + { + IntPtr local_ctx = unwrap_ctx(ctx); + if (local_ctx == IntPtr.Zero) + { + log(ERROR_LOG, "CTX_SetTmpDH_file ctx unwrap error"); + return FAILURE; + } + + return wolfSSL_CTX_SetTmpDH_file(local_ctx, dhparam, file_type); + } + catch (Exception e) + { + log(ERROR_LOG, "CTX_SetTmpDH_file error " + e.ToString()); return FAILURE; } } @@ -1714,7 +1789,7 @@ namespace wolfSSL.CSharp { { try { - IntPtr local_ctx = unwrap(ctx); + IntPtr local_ctx = unwrap_ctx(ctx); if (local_ctx == IntPtr.Zero) { log(ERROR_LOG, "CTX SetMinDhKey_Sz error"); @@ -1740,7 +1815,7 @@ namespace wolfSSL.CSharp { { try { - IntPtr local_ctx = unwrap(ctx); + IntPtr local_ctx = unwrap_ctx(ctx); if (local_ctx == IntPtr.Zero) { log(ERROR_LOG, "CTX set_verify error"); @@ -1767,7 +1842,7 @@ namespace wolfSSL.CSharp { { try { - IntPtr local_ssl = unwrap(ssl); + IntPtr local_ssl = unwrap_ssl(ssl); if (local_ssl == IntPtr.Zero) { log(ERROR_LOG, "set_verify error"); diff --git a/wrapper/include.am b/wrapper/include.am index 9c4fa5d7f..5185523e6 100644 --- a/wrapper/include.am +++ b/wrapper/include.am @@ -4,39 +4,4 @@ include wrapper/python/wolfcrypt/include.am include wrapper/python/wolfssl/include.am - -# wolfSSL CSharp wrapper files -EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/App.config -EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/Properties/AssemblyInfo.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/wolfSSL-DTLS-PSK-Server.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/wolfSSL-DTLS-PSK-Server.csproj -EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-Server/App.config -EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-Server/Properties/AssemblyInfo.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-Server/wolfSSL-DTLS-Server.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-Server/wolfSSL-DTLS-Server.csproj -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-PSK-Server/App.config -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-PSK-Server/Properties/AssemblyInfo.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-PSK-Server/wolfSSL-TLS-PSK-Server.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-PSK-Server/wolfSSL-TLS-PSK-Server.csproj -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/App.config -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/Properties/AssemblyInfo.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/Properties/Settings.Designer.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/Properties/Settings.settings -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.csproj -EXTRA_DIST+= wrapper/CSharp/wolfSSL-Example-IOCallbacks/App.config -EXTRA_DIST+= wrapper/CSharp/wolfSSL-Example-IOCallbacks/Properties/AssemblyInfo.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-Example-IOCallbacks/wolfSSL-Example-IOCallbacks.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-Example-IOCallbacks/wolfSSL-Example-IOCallbacks.csproj -EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp.sln -EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/Properties/AssemblyInfo.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/Properties/Resources.Designer.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/Properties/Resources.resx -EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/wolfSSL_CSharp.csproj -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/App.config -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/Properties/AssemblyInfo.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/Properties/Settings.Designer.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/Properties/Settings.settings -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs -EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj +include wrapper/CSharp/include.am