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-DTLS-PSK-Server/Properties/AssemblyInfo.cs b/wrapper/CSharp/wolfSSL-DTLS-PSK-Server/Properties/AssemblyInfo.cs index 7e22f5faf..2ee49afdb 100644 --- a/wrapper/CSharp/wolfSSL-DTLS-PSK-Server/Properties/AssemblyInfo.cs +++ b/wrapper/CSharp/wolfSSL-DTLS-PSK-Server/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("wolfSSL")] [assembly: AssemblyProduct("wolfSSL-DTLS-PSK-Server")] -[assembly: AssemblyCopyright("Copyright wolfSSL 2015")] +[assembly: AssemblyCopyright("Copyright wolfSSL 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/wrapper/CSharp/wolfSSL-DTLS-Server/Properties/AssemblyInfo.cs b/wrapper/CSharp/wolfSSL-DTLS-Server/Properties/AssemblyInfo.cs index f047e5351..56a4dcf9e 100644 --- a/wrapper/CSharp/wolfSSL-DTLS-Server/Properties/AssemblyInfo.cs +++ b/wrapper/CSharp/wolfSSL-DTLS-Server/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("wolfSSL")] [assembly: AssemblyProduct("wolfSSL-DTLS-Server")] -[assembly: AssemblyCopyright("Copyright wolfSSL 2015")] +[assembly: AssemblyCopyright("Copyright wolfSSL 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/wrapper/CSharp/wolfSSL-Example-IOCallbacks/Properties/AssemblyInfo.cs b/wrapper/CSharp/wolfSSL-Example-IOCallbacks/Properties/AssemblyInfo.cs index a19cd0ad7..066aa71c2 100644 --- a/wrapper/CSharp/wolfSSL-Example-IOCallbacks/Properties/AssemblyInfo.cs +++ b/wrapper/CSharp/wolfSSL-Example-IOCallbacks/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("wolfSSL")] [assembly: AssemblyProduct("wolfSSL-Example-IOCallbacks")] -[assembly: AssemblyCopyright("Copyright wolfSSL 2015")] +[assembly: AssemblyCopyright("Copyright wolfSSL 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] 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/App.config b/wrapper/CSharp/wolfSSL-TLS-Client/App.config new file mode 100644 index 000000000..b540b1fdf --- /dev/null +++ b/wrapper/CSharp/wolfSSL-TLS-Client/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/wrapper/CSharp/wolfSSL-TLS-Client/Properties/AssemblyInfo.cs b/wrapper/CSharp/wolfSSL-TLS-Client/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..a1063125b --- /dev/null +++ b/wrapper/CSharp/wolfSSL-TLS-Client/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-Client")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("wolfSSL")] +[assembly: AssemblyProduct("wolfSSL-TLS-Client")] +[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("05aad2b4-445e-4f0e-8e16-8f8512696505")] + +// 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-Client/Properties/Settings.Designer.cs b/wrapper/CSharp/wolfSSL-TLS-Client/Properties/Settings.Designer.cs new file mode 100644 index 000000000..524c01375 --- /dev/null +++ b/wrapper/CSharp/wolfSSL-TLS-Client/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-Client/Properties/Settings.settings b/wrapper/CSharp/wolfSSL-TLS-Client/Properties/Settings.settings new file mode 100755 index 000000000..049245f40 --- /dev/null +++ b/wrapper/CSharp/wolfSSL-TLS-Client/Properties/Settings.settings @@ -0,0 +1,6 @@ + + + + + + diff --git a/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs new file mode 100755 index 000000000..dcba3568e --- /dev/null +++ b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs @@ -0,0 +1,210 @@ +/* wolfSSL-TLS-Client.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 wolfSSL.CSharp; + +public class wolfSSL_TLS_Client +{ + /// + /// Example of a logging function + /// + /// level of log + /// message to log + public static void standard_log(int lvl, StringBuilder msg) + { + Console.WriteLine(msg); + } + + + private static void clean(IntPtr ssl, IntPtr ctx) + { + wolfssl.free(ssl); + wolfssl.CTX_free(ctx); + wolfssl.Cleanup(); + } + + /// + /// Verification callback + /// + /// 1=Verify Okay, 0=Failure + /// Certificate in WOLFSSL_X509_STORE_CTX format + private static int myVerify(int preverify, IntPtr x509_ctx) + { + /* Use the provided verification */ + /* Can optionally override failures by returning non-zero value */ + return preverify; + } + + public static void Main(string[] args) + { + IntPtr ctx; + IntPtr ssl; + Socket tcp; + + /* These paths should be changed for use */ + string caCert = @"ca-cert.pem"; + StringBuilder dhparam = new StringBuilder("dh2048.pem"); + + StringBuilder buff = new StringBuilder(1024); + StringBuilder reply = new StringBuilder("Hello, this is the wolfSSL C# wrapper"); + + //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_client()); + if (ctx == IntPtr.Zero) + { + Console.WriteLine("Error in creating ctx structure"); + return; + } + Console.WriteLine("Finished init of ctx .... now load in CA"); + + + if (!File.Exists(caCert)) + { + Console.WriteLine("Could not find CA cert file"); + wolfssl.CTX_free(ctx); + return; + } + + + if (wolfssl.CTX_load_verify_locations(ctx, caCert, null) + != wolfssl.SUCCESS) + { + Console.WriteLine("Error loading CA cert"); + } + + StringBuilder ciphers = new StringBuilder(new String(' ', 4096)); + wolfssl.get_ciphers(ciphers, 4096); + Console.WriteLine("Ciphers : " + ciphers.ToString()); + + /* Uncomment Section to enable specific cipher suite */ +#if false + ciphers = new StringBuilder("ECDHE-ECDSA-AES128-GCM-SHA256"); + if (wolfssl.CTX_set_cipher_list(ctx, ciphers) != wolfssl.SUCCESS) + { + Console.WriteLine("ERROR CTX_set_cipher_list()"); + wolfssl.CTX_free(ctx); + return; + } +#endif + + short minDhKey = 128; + wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey); + + /* Setup Verify Callback */ + if (wolfssl.CTX_set_verify(ctx, wolfssl.SSL_VERIFY_PEER, myVerify) + != wolfssl.SUCCESS) + { + Console.WriteLine("Error setting verify callback!"); + } + + + /* set up TCP socket */ + tcp = new Socket(AddressFamily.InterNetwork, SocketType.Stream, + ProtocolType.Tcp); + try + { + tcp.Connect("localhost", 11111); + } + catch (Exception e) + { + Console.WriteLine("tcp.Connect() error " + e.ToString()); + wolfssl.CTX_free(ctx); + return; + } + if (!tcp.Connected) + { + Console.WriteLine("tcp.Connect() failed!"); + tcp.Close(); + wolfssl.CTX_free(ctx); + return; + } + + Console.WriteLine("Connected TCP"); + ssl = wolfssl.new_ssl(ctx); + if (ssl == IntPtr.Zero) + { + Console.WriteLine("Error in creating ssl object"); + wolfssl.CTX_free(ctx); + return; + } + + Console.WriteLine("Connection made wolfSSL_connect "); + if (wolfssl.set_fd(ssl, tcp) != wolfssl.SUCCESS) + { + /* get and print out the error */ + Console.WriteLine(wolfssl.get_error(ssl)); + tcp.Close(); + clean(ssl, ctx); + return; + } + + wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM); + + if (wolfssl.connect(ssl) != wolfssl.SUCCESS) + { + /* get and print out the error */ + Console.WriteLine(wolfssl.get_error(ssl)); + tcp.Close(); + clean(ssl, ctx); + 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)); + + + if (wolfssl.write(ssl, reply, reply.Length) != reply.Length) + { + Console.WriteLine("Error in write"); + tcp.Close(); + clean(ssl, ctx); + return; + } + + /* read and print out the message then reply */ + if (wolfssl.read(ssl, buff, 1023) < 0) + { + Console.WriteLine("Error in read"); + tcp.Close(); + clean(ssl, ctx); + return; + } + Console.WriteLine(buff); + + wolfssl.shutdown(ssl); + tcp.Close(); + clean(ssl, ctx); + } +} diff --git a/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj new file mode 100755 index 000000000..2959f6f90 --- /dev/null +++ b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj @@ -0,0 +1,132 @@ + + + + + Debug + AnyCPU + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8} + Exe + Properties + wolfSSL_TLS_Client + wolfSSL-TLS-Client + 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-TLS-PSK-Server/Properties/AssemblyInfo.cs b/wrapper/CSharp/wolfSSL-TLS-PSK-Server/Properties/AssemblyInfo.cs index 35acba0e3..5704ac236 100644 --- a/wrapper/CSharp/wolfSSL-TLS-PSK-Server/Properties/AssemblyInfo.cs +++ b/wrapper/CSharp/wolfSSL-TLS-PSK-Server/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("wolfSSL")] [assembly: AssemblyProduct("wolfSSL-TLS-PSK-Server")] -[assembly: AssemblyCopyright("Copyright wolfSSL 2015")] +[assembly: AssemblyCopyright("Copyright wolfSSL 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] 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/Properties/AssemblyInfo.cs b/wrapper/CSharp/wolfSSL-TLS-Server/Properties/AssemblyInfo.cs index cab955e7d..ef8b02522 100644 --- a/wrapper/CSharp/wolfSSL-TLS-Server/Properties/AssemblyInfo.cs +++ b/wrapper/CSharp/wolfSSL-TLS-Server/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("wolfSSL")] [assembly: AssemblyProduct("wolfSSL-TLS-Server")] -[assembly: AssemblyCopyright("Copyright wolfSSL 2015")] +[assembly: AssemblyCopyright("Copyright wolfSSL 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs b/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs old mode 100644 new mode 100755 index 4cc828465..262bd74be --- a/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs +++ b/wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-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; @@ -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 f7c63d7c1..f3b4dc707 100755 --- a/wrapper/CSharp/wolfSSL_CSharp.sln +++ b/wrapper/CSharp/wolfSSL_CSharp.sln @@ -25,78 +25,140 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testsuite", "..\..\testsuit EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wolfSSL-Example-IOCallbacks", "wolfSSL-Example-IOCallbacks\wolfSSL-Example-IOCallbacks.csproj", "{E2415718-0A15-48DB-A774-01FB0093B626}" 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 + DLL Debug|Any CPU = DLL Debug|Any CPU DLL Debug|Win32 = DLL Debug|Win32 DLL Debug|x64 = DLL Debug|x64 + DLL Release|Any CPU = DLL Release|Any CPU DLL Release|Win32 = DLL Release|Win32 DLL Release|x64 = DLL Release|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {52609808-0418-46D3-8E17-141927A1A39A}.DLL Debug|Any CPU.ActiveCfg = Debug|Any CPU + {52609808-0418-46D3-8E17-141927A1A39A}.DLL Debug|Any CPU.Build.0 = Debug|Any CPU {52609808-0418-46D3-8E17-141927A1A39A}.DLL Debug|Win32.ActiveCfg = Debug|Any CPU {52609808-0418-46D3-8E17-141927A1A39A}.DLL Debug|Win32.Build.0 = Debug|Any CPU {52609808-0418-46D3-8E17-141927A1A39A}.DLL Debug|x64.ActiveCfg = Debug|x64 {52609808-0418-46D3-8E17-141927A1A39A}.DLL Debug|x64.Build.0 = Debug|x64 + {52609808-0418-46D3-8E17-141927A1A39A}.DLL Release|Any CPU.ActiveCfg = Release|Any CPU + {52609808-0418-46D3-8E17-141927A1A39A}.DLL Release|Any CPU.Build.0 = Release|Any CPU {52609808-0418-46D3-8E17-141927A1A39A}.DLL Release|Win32.ActiveCfg = Release|Any CPU {52609808-0418-46D3-8E17-141927A1A39A}.DLL Release|Win32.Build.0 = Release|Any CPU {52609808-0418-46D3-8E17-141927A1A39A}.DLL Release|x64.ActiveCfg = Release|x64 {52609808-0418-46D3-8E17-141927A1A39A}.DLL Release|x64.Build.0 = Release|x64 + {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Debug|Any CPU.Build.0 = Debug|Any CPU {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Debug|Win32.ActiveCfg = Debug|Any CPU {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Debug|Win32.Build.0 = Debug|Any CPU {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Debug|x64.ActiveCfg = Debug|x64 {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Debug|x64.Build.0 = Debug|x64 + {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Release|Any CPU.ActiveCfg = Release|Any CPU + {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Release|Any CPU.Build.0 = Release|Any CPU {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Release|Win32.ActiveCfg = Release|Any CPU {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Release|Win32.Build.0 = Release|Any CPU {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Release|x64.ActiveCfg = Release|x64 {8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Release|x64.Build.0 = Release|x64 + {030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Debug|Any CPU.ActiveCfg = Debug|Any CPU + {030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Debug|Any CPU.Build.0 = Debug|Any CPU {030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Debug|Win32.ActiveCfg = Debug|Any CPU {030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Debug|Win32.Build.0 = Debug|Any CPU {030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Debug|x64.ActiveCfg = Debug|x64 {030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Debug|x64.Build.0 = Debug|x64 + {030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Release|Any CPU.ActiveCfg = Release|Any CPU + {030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Release|Any CPU.Build.0 = Release|Any CPU {030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Release|Win32.ActiveCfg = Release|Any CPU {030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Release|Win32.Build.0 = Release|Any CPU {030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Release|x64.ActiveCfg = Release|x64 {030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Release|x64.Build.0 = Release|x64 + {730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Debug|Any CPU.ActiveCfg = Debug|Any CPU + {730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Debug|Any CPU.Build.0 = Debug|Any CPU {730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Debug|Win32.ActiveCfg = Debug|Any CPU {730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Debug|Win32.Build.0 = Debug|Any CPU {730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Debug|x64.ActiveCfg = Debug|x64 {730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Debug|x64.Build.0 = Debug|x64 + {730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Release|Any CPU.ActiveCfg = Release|Any CPU + {730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Release|Any CPU.Build.0 = Release|Any CPU {730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Release|Win32.ActiveCfg = Release|Any CPU {730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Release|Win32.Build.0 = Release|Any CPU {730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Release|x64.ActiveCfg = Release|x64 {730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Release|x64.Build.0 = Release|x64 + {77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Debug|Any CPU.ActiveCfg = Debug|Any CPU + {77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Debug|Any CPU.Build.0 = Debug|Any CPU {77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Debug|Win32.ActiveCfg = Debug|Any CPU {77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Debug|Win32.Build.0 = Debug|Any CPU {77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Debug|x64.ActiveCfg = Debug|x64 {77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Debug|x64.Build.0 = Debug|x64 + {77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Release|Any CPU.ActiveCfg = Release|Any CPU + {77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Release|Any CPU.Build.0 = Release|Any CPU {77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Release|Win32.ActiveCfg = Release|Any CPU {77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Release|Win32.Build.0 = Release|Any CPU {77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Release|x64.ActiveCfg = Release|x64 {77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Release|x64.Build.0 = Release|x64 + {73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Debug|Any CPU.ActiveCfg = DLL Debug|Win32 + {73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Debug|Any CPU.Build.0 = DLL Debug|Win32 {73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Debug|Win32.ActiveCfg = DLL Debug|Win32 {73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Debug|Win32.Build.0 = DLL Debug|Win32 {73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Debug|x64.ActiveCfg = DLL Debug|x64 {73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Debug|x64.Build.0 = DLL Debug|x64 + {73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Release|Any CPU.ActiveCfg = DLL Release|Win32 + {73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Release|Any CPU.Build.0 = DLL Release|Win32 {73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Release|Win32.ActiveCfg = DLL Release|Win32 {73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Release|Win32.Build.0 = DLL Release|Win32 {73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Release|x64.ActiveCfg = DLL Release|x64 {73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Release|x64.Build.0 = DLL Release|x64 + {611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Debug|Any CPU.ActiveCfg = DLL Debug|Win32 + {611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Debug|Any CPU.Build.0 = DLL Debug|Win32 {611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Debug|Win32.ActiveCfg = DLL Debug|Win32 {611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Debug|Win32.Build.0 = DLL Debug|Win32 {611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Debug|x64.ActiveCfg = DLL Debug|x64 {611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Debug|x64.Build.0 = DLL Debug|x64 + {611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Release|Any CPU.ActiveCfg = DLL Release|Win32 + {611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Release|Any CPU.Build.0 = DLL Release|Win32 {611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Release|Win32.ActiveCfg = DLL Release|Win32 {611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Release|Win32.Build.0 = DLL Release|Win32 {611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Release|x64.ActiveCfg = DLL Release|x64 {611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Release|x64.Build.0 = DLL Release|x64 + {E2415718-0A15-48DB-A774-01FB0093B626}.DLL Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E2415718-0A15-48DB-A774-01FB0093B626}.DLL Debug|Any CPU.Build.0 = Debug|Any CPU {E2415718-0A15-48DB-A774-01FB0093B626}.DLL Debug|Win32.ActiveCfg = Debug|Any CPU {E2415718-0A15-48DB-A774-01FB0093B626}.DLL Debug|Win32.Build.0 = Debug|Any CPU {E2415718-0A15-48DB-A774-01FB0093B626}.DLL Debug|x64.ActiveCfg = Debug|x64 {E2415718-0A15-48DB-A774-01FB0093B626}.DLL Debug|x64.Build.0 = Debug|x64 + {E2415718-0A15-48DB-A774-01FB0093B626}.DLL Release|Any CPU.ActiveCfg = Release|Any CPU + {E2415718-0A15-48DB-A774-01FB0093B626}.DLL Release|Any CPU.Build.0 = Release|Any CPU {E2415718-0A15-48DB-A774-01FB0093B626}.DLL Release|Win32.ActiveCfg = Release|Any CPU {E2415718-0A15-48DB-A774-01FB0093B626}.DLL Release|Win32.Build.0 = Release|Any CPU {E2415718-0A15-48DB-A774-01FB0093B626}.DLL Release|x64.ActiveCfg = Release|x64 {E2415718-0A15-48DB-A774-01FB0093B626}.DLL Release|x64.Build.0 = Release|x64 + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.DLL Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.DLL Debug|Any CPU.Build.0 = Debug|Any CPU + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.DLL Debug|Win32.ActiveCfg = Debug|Any CPU + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.DLL Debug|Win32.Build.0 = Debug|Any CPU + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.DLL Debug|x64.ActiveCfg = Debug|x64 + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.DLL Debug|x64.Build.0 = Debug|x64 + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.DLL Release|Any CPU.ActiveCfg = Release|Any CPU + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.DLL Release|Any CPU.Build.0 = Release|Any CPU + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.DLL Release|Win32.ActiveCfg = Release|Any CPU + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.DLL Release|Win32.Build.0 = Release|Any CPU + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.DLL Release|x64.ActiveCfg = Release|x64 + {B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.DLL Release|x64.Build.0 = Release|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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -105,4 +167,7 @@ Global {73973223-5EE8-41CA-8E88-1D60E89A237B} = {252D09D0-D007-4AEB-9F7A-A74408039A8A} {611E8971-46E0-4D0A-B5A1-632C3B00CB80} = {252D09D0-D007-4AEB-9F7A-A74408039A8A} EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {63D316F8-C4EE-449A-B9A6-FC673C4D5D31} + EndGlobalSection EndGlobal diff --git a/wrapper/CSharp/wolfSSL_CSharp/Properties/AssemblyInfo.cs b/wrapper/CSharp/wolfSSL_CSharp/Properties/AssemblyInfo.cs index b4df96b9d..d34afd6b9 100644 --- a/wrapper/CSharp/wolfSSL_CSharp/Properties/AssemblyInfo.cs +++ b/wrapper/CSharp/wolfSSL_CSharp/Properties/AssemblyInfo.cs @@ -10,7 +10,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("wolfSSL")] [assembly: AssemblyProduct("wolfSSL.CSharp")] -[assembly: AssemblyCopyright("Copyright wolfSSL 2015")] +[assembly: AssemblyCopyright("Copyright wolfSSL 2020")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs b/wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs old mode 100644 new mode 100755 index f0c555b2d..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(); + } } } @@ -152,10 +184,14 @@ namespace wolfSSL.CSharp { [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] private extern static IntPtr wolfTLSv1_2_server_method(); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] + private extern static IntPtr wolfTLSv1_3_server_method(); + [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] private extern static IntPtr wolfSSLv23_server_method(); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] private extern static IntPtr wolfTLSv1_2_client_method(); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] + private extern static IntPtr wolfTLSv1_3_client_method(); + [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] private extern static IntPtr wolfSSLv23_client_method(); [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] private extern static IntPtr wolfDTLSv1_2_server_method(); @@ -278,6 +314,18 @@ 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); + + + /******************************** + * Verify Callback + */ + public delegate int CallbackVerify_delegate(int ret, IntPtr x509_ctx); + [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] + private extern static void wolfSSL_CTX_set_verify(IntPtr ctx, int mode, CallbackVerify_delegate vc); + [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] + private extern static void wolfSSL_set_verify(IntPtr ssl, int mode, CallbackVerify_delegate vc); /******************************** @@ -286,6 +334,13 @@ namespace wolfSSL.CSharp { public static readonly int SSL_FILETYPE_PEM = 1; public static readonly int SSL_FILETYPE_ASN1= 2; public static readonly int SSL_FILETYPE_RAW = 3; + + public static readonly int SSL_VERIFY_NONE = 0; + public static readonly int SSL_VERIFY_PEER = 1; + public static readonly int SSL_VERIFY_FAIL_IF_NO_PEER_CERT = 2; + public static readonly int SSL_VERIFY_CLIENT_ONCE = 4; + public static readonly int SSL_VERIFY_FAIL_EXCEPT_PSK = 8; + public static readonly int CBIO_ERR_GENERAL = -1; public static readonly int CBIO_ERR_WANT_READ = -2; public static readonly int CBIO_ERR_WANT_WRITE = -2; @@ -304,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; @@ -496,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; } @@ -535,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; } @@ -563,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; } @@ -593,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); @@ -645,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); @@ -688,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; } @@ -727,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); @@ -761,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(); @@ -786,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; } @@ -813,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(); @@ -844,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(); @@ -878,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); @@ -913,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); @@ -944,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(); @@ -966,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; } @@ -993,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); @@ -1015,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); @@ -1037,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) { @@ -1068,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); @@ -1107,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"); @@ -1153,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(); @@ -1162,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; } @@ -1187,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"); @@ -1283,6 +1352,23 @@ namespace wolfSSL.CSharp { } } + /// + /// Set up TLS version 1.3 method + /// + /// pointer to TLSv1.3 method + public static IntPtr useTLSv1_3_server() + { + try + { + return wolfTLSv1_3_server_method(); + } + catch (Exception e) + { + log(ERROR_LOG, "wolfssl error " + e.ToString()); + return IntPtr.Zero; + } + } + /// /// Use any TLS version @@ -1319,6 +1405,22 @@ namespace wolfSSL.CSharp { } } + /// + /// Set up TLS version 1.3 method + /// + /// pointer to TLSv1.3 method + public static IntPtr useTLSv1_3_client() + { + try + { + return wolfTLSv1_3_client_method(); + } + catch (Exception e) + { + log(ERROR_LOG, "wolfssl error " + e.ToString()); + return IntPtr.Zero; + } + } /// /// Use any TLS version @@ -1389,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"); @@ -1420,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"); @@ -1447,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"); @@ -1479,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"); @@ -1515,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"); @@ -1550,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"); @@ -1578,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"); @@ -1605,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"); @@ -1633,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; } @@ -1644,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; } } @@ -1660,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"); @@ -1676,6 +1805,60 @@ namespace wolfSSL.CSharp { } } + /// + /// Set the certificate verification mode and optional callback function + /// + /// pointer to CTX that the function is set in + /// See SSL_VERIFY options + /// Optional verify callback function to use + public static int CTX_set_verify(IntPtr ctx, int mode, CallbackVerify_delegate vc) + { + try + { + IntPtr local_ctx = unwrap_ctx(ctx); + if (local_ctx == IntPtr.Zero) + { + log(ERROR_LOG, "CTX set_verify error"); + return FAILURE; + } + + wolfSSL_CTX_set_verify(local_ctx, mode, vc); + return SUCCESS; + } + catch (Exception e) + { + log(ERROR_LOG, "wolfssl ctx set verify error " + e.ToString()); + return FAILURE; + } + } + + /// + /// Set the certificate verification mode and optional callback function + /// + /// pointer to SSL object that the function is set in + /// See SSL_VERIFY options + /// Optional verify callback function to use + public static int set_verify(IntPtr ssl, int mode, CallbackVerify_delegate vc) + { + try + { + IntPtr local_ssl = unwrap_ssl(ssl); + if (local_ssl == IntPtr.Zero) + { + log(ERROR_LOG, "set_verify error"); + return FAILURE; + } + + wolfSSL_set_verify(local_ssl, mode, vc); + return SUCCESS; + } + catch (Exception e) + { + log(ERROR_LOG, "wolfssl set verify error " + e.ToString()); + return FAILURE; + } + + } /// /// Set the function to use for logging diff --git a/wrapper/CSharp/wolfSSL_CSharp/wolfSSL_CSharp.csproj b/wrapper/CSharp/wolfSSL_CSharp/wolfSSL_CSharp.csproj index d5eabceba..128b84a37 100755 --- a/wrapper/CSharp/wolfSSL_CSharp/wolfSSL_CSharp.csproj +++ b/wrapper/CSharp/wolfSSL_CSharp/wolfSSL_CSharp.csproj @@ -67,7 +67,8 @@ xcopy "$(ProjectDir)..\..\..\certs\server-key.pem" "$(TargetDir)" /Y /R xcopy "$(ProjectDir)..\..\..\certs\server-cert.pem" "$(TargetDir)" /Y /R -xcopy "$(ProjectDir)..\..\..\certs\dh2048.pem" "$(TargetDir)" /Y /R +xcopy "$(ProjectDir)..\..\..\certs\dh2048.pem" "$(TargetDir)" /Y /R +xcopy "$(ProjectDir)..\..\..\certs\ca-cert.pem" "$(TargetDir)" /Y /R