Merge pull request from JacobBarthelmeh/master

example IO callback and keep memory alive when needed
This commit is contained in:
toddouska 2015-12-07 09:12:07 -08:00
commit beebc87bc8
21 changed files with 1017 additions and 336 deletions

@ -8,9 +8,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle("wolfSSL-DTLS-PSK-Server")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyCompany("wolfSSL")]
[assembly: AssemblyProduct("wolfSSL-DTLS-PSK-Server")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
[assembly: AssemblyCopyright("Copyright wolfSSL 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 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.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

@ -48,7 +48,7 @@ public class wolfSSL_DTLS_PSK_Server
/* perform a check on the identity sent across
* log function must be set for print out of logging information
*/
wolfssl.log(1, "PSK Client Identity = " + identity);
wolfssl.log(wolfssl.INFO_LOG, "PSK Client Identity = " + identity);
/* Use desired key, note must be a key smaller than max key size parameter
Replace this with desired key. Is trivial one for testing */
@ -61,6 +61,14 @@ public class wolfSSL_DTLS_PSK_Server
}
private static void clean(IntPtr ssl, IntPtr ctx)
{
wolfssl.free(ssl);
wolfssl.CTX_free(ctx);
wolfssl.Cleanup();
}
public static void Main(string[] args)
{
IntPtr ctx;
@ -80,11 +88,18 @@ public class wolfSSL_DTLS_PSK_Server
Console.WriteLine("Calling ctx Init from wolfSSL");
ctx = wolfssl.CTX_dtls_new(wolfssl.useDTLSv1_2_server());
if (ctx == IntPtr.Zero)
{
Console.WriteLine("Error 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;
}
@ -92,20 +107,27 @@ public class wolfSSL_DTLS_PSK_Server
if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
{
Console.WriteLine("Error setting cert file");
wolfssl.CTX_free(ctx);
return;
}
if (wolfssl.CTX_use_PrivateKey_file(ctx, fileKey, 1) != wolfssl.SUCCESS)
if (wolfssl.CTX_use_PrivateKey_file(ctx, fileKey, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
{
Console.WriteLine("Error setting key file");
wolfssl.CTX_free(ctx);
return;
}
/* Test psk use with DHE */
StringBuilder hint = new StringBuilder("cyassl server");
wolfssl.CTX_use_psk_identity_hint(ctx, hint);
if (wolfssl.CTX_use_psk_identity_hint(ctx, hint) != wolfssl.SUCCESS)
{
Console.WriteLine("Error setting hint");
wolfssl.CTX_free(ctx);
return;
}
wolfssl.CTX_set_psk_server_callback(ctx, psk_cb);
short minDhKey = 128;
@ -116,6 +138,7 @@ public class wolfSSL_DTLS_PSK_Server
if (wolfssl.CTX_set_cipher_list(ctx, set_cipher) != wolfssl.SUCCESS)
{
Console.WriteLine("Failed to set cipher suite");
wolfssl.CTX_free(ctx);
return;
}
@ -125,23 +148,36 @@ public class wolfSSL_DTLS_PSK_Server
Console.WriteLine("Started UDP and waiting for a connection");
ssl = wolfssl.new_ssl(ctx);
if (ssl == IntPtr.Zero)
{
Console.WriteLine("Error creating ssl object");
udp.Close();
wolfssl.CTX_free(ctx);
return;
}
if (wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
{
Console.WriteLine("Error in setting dhparam");
Console.WriteLine(wolfssl.get_error(ssl));
udp.Close();
clean(ssl, ctx);
return;
}
if (wolfssl.set_dtls_fd(ssl, udp, ep) != wolfssl.SUCCESS)
{
Console.WriteLine(wolfssl.get_error(ssl));
udp.Close();
clean(ssl, ctx);
return;
}
if (wolfssl.accept(ssl) != wolfssl.SUCCESS)
{
Console.WriteLine(wolfssl.get_error(ssl));
udp.Close();
clean(ssl, ctx);
return;
}
@ -161,6 +197,8 @@ public class wolfSSL_DTLS_PSK_Server
{
Console.WriteLine("Error reading message");
Console.WriteLine(wolfssl.get_error(ssl));
udp.Close();
clean(ssl, ctx);
return;
}
Console.WriteLine(buff);
@ -169,15 +207,14 @@ public class wolfSSL_DTLS_PSK_Server
{
Console.WriteLine("Error writing message");
Console.WriteLine(wolfssl.get_error(ssl));
udp.Close();
clean(ssl, ctx);
return;
}
Console.WriteLine("At the end freeing stuff");
wolfssl.shutdown(ssl);
wolfssl.free(ssl);
udp.Close();
wolfssl.CTX_free(ctx);
wolfssl.Cleanup();
clean(ssl, ctx);
}
}

@ -56,7 +56,6 @@
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>

@ -8,9 +8,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle("wolfSSL-DTLS-Server")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyCompany("wolfSSL")]
[assembly: AssemblyProduct("wolfSSL-DTLS-Server")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
[assembly: AssemblyCopyright("Copyright wolfSSL 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 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.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

@ -41,6 +41,14 @@ public class wolfSSL_DTLS_Server
}
private static void clean(IntPtr ssl, IntPtr ctx)
{
wolfssl.free(ssl);
wolfssl.CTX_free(ctx);
wolfssl.Cleanup();
}
public static void Main(string[] args)
{
IntPtr ctx;
@ -61,11 +69,18 @@ public class wolfSSL_DTLS_Server
Console.WriteLine("Calling ctx Init from wolfSSL");
ctx = wolfssl.CTX_dtls_new(wolfssl.useDTLSv1_2_server());
Console.WriteLine("Finished init of ctx .... now load in cert and key");
if (ctx == IntPtr.Zero)
{
Console.WriteLine("Error creating ctx structure");
wolfssl.CTX_free(ctx);
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;
}
@ -73,13 +88,15 @@ public class wolfSSL_DTLS_Server
if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
{
Console.WriteLine("Error setting cert file");
wolfssl.CTX_free(ctx);
return;
}
if (wolfssl.CTX_use_PrivateKey_file(ctx, fileKey, 1) != wolfssl.SUCCESS)
if (wolfssl.CTX_use_PrivateKey_file(ctx, fileKey, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
{
Console.WriteLine("Error setting key file");
wolfssl.CTX_free(ctx);
return;
}
@ -92,24 +109,36 @@ public class wolfSSL_DTLS_Server
Console.WriteLine("Started UDP and waiting for a connection");
ssl = wolfssl.new_ssl(ctx);
if (ssl == IntPtr.Zero)
{
Console.WriteLine("Error creating ssl object");
wolfssl.CTX_free(ctx);
return;
}
if (wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
{
Console.WriteLine("Error in setting dhparam");
Console.WriteLine(wolfssl.get_error(ssl));
udp.Close();
clean(ssl, ctx);
return;
}
if (wolfssl.set_dtls_fd(ssl, udp, ep) != wolfssl.SUCCESS)
{
Console.WriteLine(wolfssl.get_error(ssl));
udp.Close();
clean(ssl, ctx);
return;
}
if (wolfssl.accept(ssl) != wolfssl.SUCCESS)
{
Console.WriteLine(wolfssl.get_error(ssl));
return;
Console.WriteLine(wolfssl.get_error(ssl));
udp.Close();
clean(ssl, ctx);
return;
}
/* print out results of TLS/SSL accept */
@ -128,6 +157,8 @@ public class wolfSSL_DTLS_Server
{
Console.WriteLine("Error reading message");
Console.WriteLine(wolfssl.get_error(ssl));
udp.Close();
clean(ssl, ctx);
return;
}
Console.WriteLine(buff);
@ -136,15 +167,14 @@ public class wolfSSL_DTLS_Server
{
Console.WriteLine("Error writing message");
Console.WriteLine(wolfssl.get_error(ssl));
udp.Close();
clean(ssl, ctx);
return;
}
Console.WriteLine("At the end freeing stuff");
wolfssl.shutdown(ssl);
wolfssl.free(ssl);
udp.Close();
wolfssl.CTX_free(ctx);
wolfssl.Cleanup();
wolfssl.shutdown(ssl);
clean(ssl, ctx);
}
}

@ -57,7 +57,6 @@
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>

@ -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-Example-IOCallbacks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("wolfSSL")]
[assembly: AssemblyProduct("wolfSSL-Example-IOCallbacks")]
[assembly: AssemblyCopyright("Copyright wolfSSL 2015")]
[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("c0ac38b1-1984-4659-b36a-20362dc47f99")]
// 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")]

@ -0,0 +1,258 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.IO;
using wolfSSL.CSharp;
class wolfSSL_Example_IOCallbacks
{
/// <summary>
/// Example call back to allow recieving TLS information
/// </summary>
/// <param name="ssl">structure of ssl passed in</param>
/// <param name="buf">buffer to contain recieved msg</param>
/// <param name="sz">size of buffer for receiving</param>
/// <param name="ctx">information passed in from set_fd</param>
/// <returns>size of message recieved</returns>
private static int wolfSSLCbIORecv(IntPtr ssl, IntPtr buf, int sz, IntPtr ctx)
{
if (sz <= 0)
{
wolfssl.log(wolfssl.ERROR_LOG, "wolfssl recieve error, size less than 0");
return wolfssl.CBIO_ERR_GENERAL;
}
int amtRecv = 0;
try
{
System.Runtime.InteropServices.GCHandle gch;
gch = GCHandle.FromIntPtr(ctx);
Socket con = (System.Net.Sockets.Socket)gch.Target;
Byte[] msg = new Byte[sz];
amtRecv = con.Receive(msg, msg.Length, 0);
Marshal.Copy(msg, 0, buf, sz);
}
catch (Exception e)
{
wolfssl.log(wolfssl.ENTER_LOG, "Error in recive " + e.ToString());
return wolfssl.CBIO_ERR_CONN_CLOSE;
}
Console.WriteLine("Example custom receive got {0:D} bytes", amtRecv);
return amtRecv;
}
/// <summary>
/// Example call back used for sending TLS information
/// </summary>
/// <param name="ssl">pointer to ssl struct</param>
/// <param name="buf">buffer containing information to send</param>
/// <param name="sz">size of buffer to send</param>
/// <param name="ctx">object that was set as fd</param>
/// <returns>amount of information sent</returns>
private static int wolfSSLCbIOSend(IntPtr ssl, IntPtr buf, int sz, IntPtr ctx)
{
if (sz <= 0)
{
wolfssl.log(wolfssl.ERROR_LOG, "wolfssl send error, size less than 0");
return wolfssl.CBIO_ERR_GENERAL;
}
try
{
System.Runtime.InteropServices.GCHandle gch;
gch = GCHandle.FromIntPtr(ctx);
Socket con = (System.Net.Sockets.Socket)gch.Target;
Byte[] msg = new Byte[sz];
Marshal.Copy(buf, msg, 0, sz);
con.Send(msg, 0, msg.Length, SocketFlags.None);
Console.WriteLine("Example custom send sent {0:D} bytes", sz);
return sz;
}
catch (Exception e)
{
wolfssl.log(wolfssl.ERROR_LOG, "socket connection issue " + e.ToString());
return wolfssl.CBIO_ERR_CONN_CLOSE;
}
}
/// <summary>
/// Example of a PSK function call back
/// </summary>
/// <param name="ssl">pointer to ssl structure</param>
/// <param name="identity">identity of client connecting</param>
/// <param name="key">buffer to hold key</param>
/// <param name="max_key">max key size</param>
/// <returns>size of key set</returns>
public static uint my_psk_server_cb(IntPtr ssl, string identity, IntPtr key, uint max_key)
{
/* perform a check on the identity sent across
* log function must be set for print out of logging information
*/
wolfssl.log(wolfssl.INFO_LOG, "PSK Client Identity = " + identity);
/* Use desired key, note must be a key smaller than max key size parameter
Replace this with desired key. Is trivial one for testing */
if (max_key < 4)
return 0;
byte[] tmp = { 26, 43, 60, 77 };
Marshal.Copy(tmp, 0, key, 4);
return (uint)4;
}
private static void clean(IntPtr ssl, IntPtr ctx)
{
wolfssl.free(ssl);
wolfssl.CTX_free(ctx);
wolfssl.Cleanup();
}
static void Main(string[] args)
{
IntPtr ctx;
IntPtr ssl;
Socket fd;
wolfssl.psk_delegate psk_cb = new wolfssl.psk_delegate(my_psk_server_cb);
/* These paths should be changed according to use */
string fileCert = @"server-cert.pem";
string fileKey = @"server-key.pem";
StringBuilder buff = new StringBuilder(1024);
StringBuilder reply = new StringBuilder("Hello, this is the wolfSSL C# wrapper");
wolfssl.Init();
Console.WriteLine("Calling ctx Init from wolfSSL");
ctx = wolfssl.CTX_new(wolfssl.useTLSv1_2_server());
if (ctx == IntPtr.Zero)
{
Console.WriteLine("Error 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());
Console.Write("Setting cipher suite to ");
/* To use static PSK build wolfSSL with WOLFSSL_STATIC_PSK preprocessor flag */
StringBuilder set_cipher = new StringBuilder("PSK-AES128-CBC-SHA256");
Console.WriteLine(set_cipher);
if (wolfssl.CTX_set_cipher_list(ctx, set_cipher) != wolfssl.SUCCESS)
{
Console.WriteLine("Failed to set cipher suite");
Console.WriteLine("If using static PSK make sure wolfSSL was built with preprocessor flag WOLFSSL_STATIC_PSK");
wolfssl.CTX_free(ctx);
return;
}
/* Test psk use */
StringBuilder hint = new StringBuilder("cyassl server");
if (wolfssl.CTX_use_psk_identity_hint(ctx, hint) != wolfssl.SUCCESS)
{
Console.WriteLine("Error setting hint");
return;
}
wolfssl.CTX_set_psk_server_callback(ctx, psk_cb);
/* Set using custom IO callbacks
delegate memory is allocated when calling SetIO**** function and freed with ctx free
*/
wolfssl.SetIORecv(ctx, new wolfssl.CallbackIORecv_delegate(wolfSSLCbIORecv));
wolfssl.SetIOSend(ctx, new wolfssl.CallbackIOSend_delegate(wolfSSLCbIOSend));
/* 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");
fd = tcp.AcceptSocket();
ssl = wolfssl.new_ssl(ctx);
Console.WriteLine("Connection made wolfSSL_accept ");
if (wolfssl.set_fd(ssl, fd) != wolfssl.SUCCESS)
{
/* get and print out the error */
Console.Write(wolfssl.get_error(ssl));
tcp.Stop();
clean(ssl, ctx);
return;
}
if (wolfssl.accept(ssl) != wolfssl.SUCCESS)
{
/* get and print out the error */
Console.Write(wolfssl.get_error(ssl));
tcp.Stop();
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));
/* read and print out the message then reply */
if (wolfssl.read(ssl, buff, 1023) < 0)
{
Console.WriteLine("Error in read");
tcp.Stop();
clean(ssl, ctx);
return;
}
Console.WriteLine(buff);
if (wolfssl.write(ssl, reply, reply.Length) != reply.Length)
{
Console.WriteLine("Error in write");
tcp.Stop();
clean(ssl, ctx);
return;
}
wolfssl.shutdown(ssl);
fd.Close();
tcp.Stop();
clean(ssl, ctx);
}
}

@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E2415718-0A15-48DB-A774-01FB0093B626}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>wolfSSL_Example_IOCallbacks</RootNamespace>
<AssemblyName>wolfSSL-Example-IOCallbacks</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\DLL Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\DLL Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>..\x64\DLL Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>..\x64\DLL Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
<WarningLevel>0</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="wolfSSL-Example-IOCallbacks.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\wolfSSL_CSharp\wolfSSL_CSharp.csproj">
<Project>{52609808-0418-46d3-8e17-141927a1a39a}</Project>
<Name>wolfSSL_CSharp</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

@ -8,9 +8,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle("wolfSSL-TLS-PSK-Server")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyCompany("wolfSSL")]
[assembly: AssemblyProduct("wolfSSL-TLS-PSK-Server")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
[assembly: AssemblyCopyright("Copyright wolfSSL 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 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.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

@ -47,7 +47,7 @@ public class wolfSSL_TLS_PSK_Server
/* perform a check on the identity sent across
* log function must be set for print out of logging information
*/
wolfssl.log(1, "PSK Client Identity = " + identity);
wolfssl.log(wolfssl.INFO_LOG, "PSK Client Identity = " + identity);
/* Use desired key, note must be a key smaller than max key size parameter
Replace this with desired key. Is trivial one for testing */
@ -60,6 +60,14 @@ public class wolfSSL_TLS_PSK_Server
}
private static void clean(IntPtr ssl, IntPtr ctx)
{
wolfssl.free(ssl);
wolfssl.CTX_free(ctx);
wolfssl.Cleanup();
}
public static void Main(string[] args)
{
IntPtr ctx;
@ -80,23 +88,31 @@ public class wolfSSL_TLS_PSK_Server
Console.WriteLine("Calling ctx Init from wolfSSL");
ctx = wolfssl.CTX_new(wolfssl.useTLSv1_2_server());
if (ctx == IntPtr.Zero)
{
Console.WriteLine("Error 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;
}
@ -108,6 +124,8 @@ public class wolfSSL_TLS_PSK_Server
short minDhKey = 128;
wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey);
Console.Write("Setting cipher suite to ");
/* In order to use static PSK build wolfSSL with the preprocessor flag WOLFSSL_STATIC_PSK */
StringBuilder set_cipher = new StringBuilder("DHE-PSK-AES128-CBC-SHA256");
Console.WriteLine(set_cipher);
if (wolfssl.CTX_set_cipher_list(ctx, set_cipher) != wolfssl.SUCCESS)
@ -121,6 +139,7 @@ public class wolfSSL_TLS_PSK_Server
if (wolfssl.CTX_use_psk_identity_hint(ctx, hint) != wolfssl.SUCCESS)
{
Console.WriteLine("Error setting hint");
wolfssl.CTX_free(ctx);
return;
}
wolfssl.CTX_set_psk_server_callback(ctx, psk_cb);
@ -133,12 +152,21 @@ public class wolfSSL_TLS_PSK_Server
Console.WriteLine("Started TCP and waiting for a connection");
fd = tcp.AcceptSocket();
ssl = wolfssl.new_ssl(ctx);
if (ssl == IntPtr.Zero)
{
Console.WriteLine("Error creating ssl object");
tcp.Stop();
wolfssl.CTX_free(ctx);
return;
}
Console.WriteLine("Connection made wolfSSL_accept ");
if (wolfssl.set_fd(ssl, fd) != wolfssl.SUCCESS)
{
/* get and print out the error */
Console.Write(wolfssl.get_error(ssl));
tcp.Stop();
clean(ssl, ctx);
return;
}
@ -148,6 +176,8 @@ public class wolfSSL_TLS_PSK_Server
{
/* get and print out the error */
Console.Write(wolfssl.get_error(ssl));
tcp.Stop();
clean(ssl, ctx);
return;
}
@ -159,6 +189,8 @@ public class wolfSSL_TLS_PSK_Server
if (wolfssl.read(ssl, buff, 1023) < 0)
{
Console.WriteLine("Error in read");
tcp.Stop();
clean(ssl, ctx);
return;
}
Console.WriteLine(buff);
@ -166,14 +198,14 @@ public class wolfSSL_TLS_PSK_Server
if (wolfssl.write(ssl, reply, reply.Length) != reply.Length)
{
Console.WriteLine("Error in write");
tcp.Stop();
clean(ssl, ctx);
return;
}
wolfssl.shutdown(ssl);
wolfssl.free(ssl);
fd.Close();
wolfssl.CTX_free(ctx);
wolfssl.Cleanup();
tcp.Stop();
clean(ssl, ctx);
}
}

@ -56,7 +56,6 @@
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>

@ -8,9 +8,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle("wolfSSL-TLS-Server")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyCompany("wolfSSL")]
[assembly: AssemblyProduct("wolfSSL-TLS-Server")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
[assembly: AssemblyCopyright("Copyright wolfSSL 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 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.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

@ -39,6 +39,15 @@ public class wolfSSL_TLS_CSHarp
Console.WriteLine(msg);
}
private static void clean(IntPtr ssl, IntPtr ctx)
{
wolfssl.free(ssl);
wolfssl.CTX_free(ctx);
wolfssl.Cleanup();
}
public static void Main(string[] args)
{
IntPtr ctx;
@ -58,25 +67,34 @@ public class wolfSSL_TLS_CSHarp
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;
}
@ -96,21 +114,31 @@ public class wolfSSL_TLS_CSHarp
Console.WriteLine("Started TCP and waiting for a connection");
fd = tcp.AcceptSocket();
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_accept ");
if (wolfssl.set_fd(ssl, fd) != wolfssl.SUCCESS)
{
/* get and print out the error */
Console.Write(wolfssl.get_error(ssl));
tcp.Stop();
clean(ssl, ctx);
return;
}
wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM);
if (wolfssl.accept(ssl) != 1)
if (wolfssl.accept(ssl) != wolfssl.SUCCESS)
{
/* get and print out the error */
Console.Write(wolfssl.get_error(ssl));
tcp.Stop();
clean(ssl, ctx);
return;
}
@ -122,6 +150,8 @@ public class wolfSSL_TLS_CSHarp
if (wolfssl.read(ssl, buff, 1023) < 0)
{
Console.WriteLine("Error in read");
tcp.Stop();
clean(ssl, ctx);
return;
}
Console.WriteLine(buff);
@ -129,14 +159,14 @@ public class wolfSSL_TLS_CSHarp
if (wolfssl.write(ssl, reply, reply.Length) != reply.Length)
{
Console.WriteLine("Error in write");
tcp.Stop();
clean(ssl, ctx);
return;
}
wolfssl.shutdown(ssl);
wolfssl.free(ssl);
fd.Close();
wolfssl.CTX_free(ctx);
wolfssl.Cleanup();
tcp.Stop();
clean(ssl, ctx);
}
}

@ -75,7 +75,6 @@
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>

@ -23,224 +23,80 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wolfssl", "..\..\wolfssl.vc
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testsuite", "..\..\testsuite\testsuite.vcxproj", "{611E8971-46E0-4D0A-B5A1-632C3B00CB80}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wolfSSL-Example-IOCallbacks", "wolfSSL-Example-IOCallbacks\wolfSSL-Example-IOCallbacks.csproj", "{E2415718-0A15-48DB-A774-01FB0093B626}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
DLL Debug|Any CPU = DLL Debug|Any CPU
DLL Debug|Mixed Platforms = DLL Debug|Mixed Platforms
DLL Debug|Win32 = DLL Debug|Win32
DLL Debug|x64 = DLL Debug|x64
DLL Release|Any CPU = DLL Release|Any CPU
DLL Release|Mixed Platforms = DLL Release|Mixed Platforms
DLL Release|Win32 = DLL Release|Win32
DLL Release|x64 = DLL Release|x64
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{52609808-0418-46D3-8E17-141927A1A39A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{52609808-0418-46D3-8E17-141927A1A39A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{52609808-0418-46D3-8E17-141927A1A39A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{52609808-0418-46D3-8E17-141927A1A39A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{52609808-0418-46D3-8E17-141927A1A39A}.Debug|Win32.ActiveCfg = Debug|Any CPU
{52609808-0418-46D3-8E17-141927A1A39A}.Debug|x64.ActiveCfg = Debug|x64
{52609808-0418-46D3-8E17-141927A1A39A}.Debug|x64.Build.0 = Debug|x64
{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|Mixed Platforms.ActiveCfg = Debug|Any CPU
{52609808-0418-46D3-8E17-141927A1A39A}.DLL Debug|Mixed Platforms.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|Mixed Platforms.ActiveCfg = Release|Any CPU
{52609808-0418-46D3-8E17-141927A1A39A}.DLL Release|Mixed Platforms.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
{52609808-0418-46D3-8E17-141927A1A39A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{52609808-0418-46D3-8E17-141927A1A39A}.Release|Any CPU.Build.0 = Release|Any CPU
{52609808-0418-46D3-8E17-141927A1A39A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{52609808-0418-46D3-8E17-141927A1A39A}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{52609808-0418-46D3-8E17-141927A1A39A}.Release|Win32.ActiveCfg = Release|Any CPU
{52609808-0418-46D3-8E17-141927A1A39A}.Release|x64.ActiveCfg = Release|x64
{52609808-0418-46D3-8E17-141927A1A39A}.Release|x64.Build.0 = Release|x64
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Debug|Win32.ActiveCfg = Debug|Any CPU
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Debug|x64.ActiveCfg = Debug|x64
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Debug|x64.Build.0 = Debug|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|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Debug|Mixed Platforms.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|Mixed Platforms.ActiveCfg = Release|Any CPU
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.DLL Release|Mixed Platforms.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
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Release|Any CPU.Build.0 = Release|Any CPU
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Release|Win32.ActiveCfg = Release|Any CPU
{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}.Release|x64.ActiveCfg = Release|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Debug|Win32.ActiveCfg = Debug|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Debug|x64.ActiveCfg = Debug|x64
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Debug|x64.Build.0 = Debug|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|Mixed Platforms.ActiveCfg = Debug|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Debug|Mixed Platforms.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|Mixed Platforms.ActiveCfg = Release|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.DLL Release|Mixed Platforms.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
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Release|Any CPU.Build.0 = Release|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Release|Win32.ActiveCfg = Release|Any CPU
{030431C7-26AB-4447-815B-F27E88BE5D5B}.Release|x64.ActiveCfg = Release|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.Debug|Any CPU.Build.0 = Debug|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.Debug|Win32.ActiveCfg = Debug|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.Debug|x64.ActiveCfg = Debug|x64
{730F047E-37A6-498F-A543-B6C98AA7B338}.Debug|x64.Build.0 = Debug|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|Mixed Platforms.ActiveCfg = Debug|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Debug|Mixed Platforms.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|Mixed Platforms.ActiveCfg = Release|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.DLL Release|Mixed Platforms.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
{730F047E-37A6-498F-A543-B6C98AA7B338}.Release|Any CPU.ActiveCfg = Release|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.Release|Any CPU.Build.0 = Release|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.Release|Win32.ActiveCfg = Release|Any CPU
{730F047E-37A6-498F-A543-B6C98AA7B338}.Release|x64.ActiveCfg = Release|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Debug|Win32.ActiveCfg = Debug|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Debug|x64.ActiveCfg = Debug|x64
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Debug|x64.Build.0 = Debug|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|Mixed Platforms.ActiveCfg = Debug|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Debug|Mixed Platforms.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|Mixed Platforms.ActiveCfg = Release|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.DLL Release|Mixed Platforms.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
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Release|Any CPU.Build.0 = Release|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Release|Win32.ActiveCfg = Release|Any CPU
{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}.Release|x64.ActiveCfg = Release|Any CPU
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Debug|Any CPU.ActiveCfg = Debug|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Debug|Mixed Platforms.Build.0 = Debug|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Debug|Win32.ActiveCfg = Debug|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Debug|Win32.Build.0 = Debug|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Debug|x64.ActiveCfg = DLL Debug|x64
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Debug|x64.Build.0 = DLL Debug|x64
{73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Debug|Any CPU.ActiveCfg = DLL Debug|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Debug|Mixed Platforms.ActiveCfg = DLL Debug|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Debug|Mixed Platforms.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|Mixed Platforms.ActiveCfg = DLL Release|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.DLL Release|Mixed Platforms.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
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Release|Any CPU.ActiveCfg = Release|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Release|Mixed Platforms.Build.0 = Release|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Release|Win32.ActiveCfg = Release|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Release|Win32.Build.0 = Release|Win32
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Release|x64.ActiveCfg = Release|x64
{73973223-5EE8-41CA-8E88-1D60E89A237B}.Release|x64.Build.0 = Release|x64
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.Debug|Any CPU.ActiveCfg = Debug|Win32
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.Debug|Win32.ActiveCfg = Debug|Win32
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.Debug|Win32.Build.0 = Debug|Win32
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.Debug|x64.ActiveCfg = Debug|x64
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Debug|Any CPU.ActiveCfg = DLL Debug|Win32
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Debug|Mixed Platforms.ActiveCfg = DLL Debug|Win32
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Debug|Mixed Platforms.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|Mixed Platforms.ActiveCfg = DLL Release|Win32
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.DLL Release|Mixed Platforms.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
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.Release|Any CPU.ActiveCfg = Release|Win32
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.Release|Mixed Platforms.ActiveCfg = Release|Win32
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.Release|Mixed Platforms.Build.0 = Release|Win32
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.Release|Win32.ActiveCfg = Release|Win32
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.Release|Win32.Build.0 = Release|Win32
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.Release|x64.ActiveCfg = Release|x64
{611E8971-46E0-4D0A-B5A1-632C3B00CB80}.Release|x64.Build.0 = Release|x64
{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|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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -8,9 +8,9 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTitle("wolfSSL.CSharp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyCompany("wolfSSL")]
[assembly: AssemblyProduct("wolfSSL.CSharp")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2015")]
[assembly: AssemblyCopyright("Copyright wolfSSL 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 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.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

@ -35,6 +35,10 @@ namespace wolfSSL.CSharp {
/********************************
* Class for DTLS connections
*/
/// <summary>
/// Contains information regarding a DTLS conection having UdpClient udp and IPEndPoint ep.
/// Used to keep memory alive.
/// </summary>
public class DTLS_con
{
public UdpClient udp;
@ -42,30 +46,118 @@ namespace wolfSSL.CSharp {
}
/********************************
* Class for keeping ctx/ssl handles alive
*/
[StructLayout(LayoutKind.Sequential)]
private class ctx_handles
{
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;
}
public void set_send(GCHandle input)
{
this.snd_cb = input;
}
public GCHandle get_send()
{
return this.snd_cb;
}
public void set_psk(GCHandle input)
{
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;
}
/// <summary>
/// Called to free the pointers keeping handles alive
/// </summary>
public void free()
{
log(INFO_LOG, "freeing handles");
if (!Object.Equals(this.rec_cb, default(GCHandle)))
{
this.rec_cb.Free();
}
if (!Object.Equals(this.snd_cb, default(GCHandle)))
{
this.snd_cb.Free();
}
if (!Object.Equals(this.psk_cb, default(GCHandle)))
{
this.psk_cb.Free();
}
if (!Object.Equals(this.fd_pin, default(GCHandle)))
{
this.fd_pin.Free();
}
}
}
/********************************
* Init wolfSSL library
*/
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_Init();
private extern static int wolfSSL_Init();
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_Cleanup();
private extern static int wolfSSL_Cleanup();
/********************************
* Methods of connection
*/
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfTLSv1_2_server_method();
private extern static IntPtr wolfTLSv1_2_server_method();
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfSSLv23_server_method();
private extern static IntPtr wolfSSLv23_server_method();
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfTLSv1_2_client_method();
private extern static IntPtr wolfTLSv1_2_client_method();
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfSSLv23_client_method();
private extern static IntPtr wolfSSLv23_client_method();
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfDTLSv1_2_server_method();
private extern static IntPtr wolfDTLSv1_2_server_method();
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfDTLSv1_2_client_method();
private extern static IntPtr wolfDTLSv1_2_client_method();
/********************************
@ -74,33 +166,33 @@ namespace wolfSSL.CSharp {
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int CallbackIORecv_delegate(IntPtr ssl, IntPtr buf, int sz, IntPtr ctx);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_SetIORecv(IntPtr ctx, CallbackIORecv_delegate recv);
private extern static int wolfSSL_SetIORecv(IntPtr ctx, CallbackIORecv_delegate recv);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_SetIOReadCtx(IntPtr ssl, IntPtr rctx);
private extern static int wolfSSL_SetIOReadCtx(IntPtr ssl, IntPtr rctx);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfSSL_GetIOReadCtx(IntPtr ssl);
private extern static IntPtr wolfSSL_GetIOReadCtx(IntPtr ssl);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int CallbackIOSend_delegate(IntPtr ssl, IntPtr buf, int sz, IntPtr ctx);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_SetIOSend(IntPtr ctx, CallbackIOSend_delegate send);
private extern static int wolfSSL_SetIOSend(IntPtr ctx, CallbackIOSend_delegate send);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_SetIOWriteCtx(IntPtr ssl, IntPtr wctx);
private extern static int wolfSSL_SetIOWriteCtx(IntPtr ssl, IntPtr wctx);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfSSL_GetIOWriteCtx(IntPtr ssl);
private extern static IntPtr wolfSSL_GetIOWriteCtx(IntPtr ssl);
/********************************
* CTX structure
*/
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfSSL_CTX_new(IntPtr method);
private extern static IntPtr wolfSSL_CTX_new(IntPtr method);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_CTX_use_certificate_file(IntPtr ctx, string file, int type);
private extern static int wolfSSL_CTX_use_certificate_file(IntPtr ctx, string file, int type);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_CTX_use_PrivateKey_file(IntPtr ctx, string file, int type);
private extern static int wolfSSL_CTX_use_PrivateKey_file(IntPtr ctx, string file, int type);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static void wolfSSL_CTX_free(IntPtr ctx);
private extern static void wolfSSL_CTX_free(IntPtr ctx);
/********************************
@ -109,30 +201,30 @@ namespace wolfSSL.CSharp {
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate uint psk_delegate(IntPtr ssl, string identity, IntPtr key, uint max_sz);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static void wolfSSL_set_psk_server_callback(IntPtr ssl, psk_delegate psk_cb);
private extern static void wolfSSL_set_psk_server_callback(IntPtr ssl, psk_delegate psk_cb);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static void wolfSSL_CTX_set_psk_server_callback(IntPtr ctx, psk_delegate psk_cb);
private extern static void wolfSSL_CTX_set_psk_server_callback(IntPtr ctx, psk_delegate psk_cb);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_CTX_use_psk_identity_hint(IntPtr ctx, StringBuilder identity);
private extern static int wolfSSL_CTX_use_psk_identity_hint(IntPtr ctx, StringBuilder identity);
/********************************
* SSL Structure
*/
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfSSL_new(IntPtr ctx);
private extern static IntPtr wolfSSL_new(IntPtr ctx);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_accept(IntPtr ssl);
private extern static int wolfSSL_accept(IntPtr ssl);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_connect(IntPtr ssl);
private extern static int wolfSSL_connect(IntPtr ssl);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_read(IntPtr ssl, StringBuilder buf, int sz);
private extern static int wolfSSL_read(IntPtr ssl, StringBuilder buf, int sz);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_write(IntPtr ssl, StringBuilder buf, int sz);
private extern static int wolfSSL_write(IntPtr ssl, StringBuilder buf, int sz);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_shutdown(IntPtr ssl);
private extern static int wolfSSL_shutdown(IntPtr ssl);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static void wolfSSL_free(IntPtr ssl);
private extern static void wolfSSL_free(IntPtr ssl);
/********************************
@ -140,30 +232,30 @@ namespace wolfSSL.CSharp {
*/
/* only supports full name from cipher_name[] delimited by : */
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_CTX_set_cipher_list(IntPtr ctx, StringBuilder ciphers);
private extern static int wolfSSL_CTX_set_cipher_list(IntPtr ctx, StringBuilder ciphers);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_set_cipher_list(IntPtr ssl, StringBuilder ciphers);
private extern static int wolfSSL_set_cipher_list(IntPtr ssl, StringBuilder ciphers);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_get_ciphers(StringBuilder ciphers, int sz);
private extern static int wolfSSL_get_ciphers(StringBuilder ciphers, int sz);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfSSL_get_cipher(IntPtr ssl);
private extern static IntPtr wolfSSL_get_cipher(IntPtr ssl);
[DllImport(wolfssl_dll, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfSSL_CIPHER_get_name(IntPtr cipher);
private extern static IntPtr wolfSSL_CIPHER_get_name(IntPtr cipher);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfSSL_get_current_cipher(IntPtr ssl);
private extern static IntPtr wolfSSL_get_current_cipher(IntPtr ssl);
[DllImport(wolfssl_dll, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfSSL_get_version(IntPtr ssl);
private extern static IntPtr wolfSSL_get_version(IntPtr ssl);
[DllImport(wolfssl_dll, CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfSSL_get_cipher_list(IntPtr ssl);
private extern static IntPtr wolfSSL_get_cipher_list(IntPtr ssl);
/********************************
* Error logging
*/
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl, CharSet=CharSet.Ansi)]
private extern static IntPtr wolfSSL_ERR_error_string(uint err, StringBuilder errOut);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static IntPtr wolfSSL_ERR_error_string(int err, StringBuilder errOut);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_get_error(IntPtr ssl, int err);
private extern static int wolfSSL_get_error(IntPtr ssl, int err);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void loggingCb(int lvl, StringBuilder msg);
private static loggingCb internal_log;
@ -173,9 +265,9 @@ namespace wolfSSL.CSharp {
* DH
*/
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_CTX_SetMinDhKey_Sz(IntPtr ctx, short size);
private extern static int wolfSSL_CTX_SetMinDhKey_Sz(IntPtr ctx, short size);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
public extern static int wolfSSL_SetTmpDH_file(IntPtr ssl, StringBuilder dhParam, int type);
private extern static int wolfSSL_SetTmpDH_file(IntPtr ssl, StringBuilder dhParam, int type);
/********************************
@ -202,6 +294,20 @@ namespace wolfSSL.CSharp {
public static readonly int FAILURE = 0;
private static IntPtr unwrap(IntPtr ctx)
{
try {
GCHandle gch = GCHandle.FromIntPtr(ctx);
ctx_handles handles = (ctx_handles)gch.Target;
return handles.get_ctx();
} catch (Exception e)
{
log(ERROR_LOG, "wolfssl pointer is incorrect " + e);
return IntPtr.Zero;
}
}
/// <summary>
/// Call back to allow recieving TLS information
/// </summary>
@ -220,19 +326,19 @@ namespace wolfSSL.CSharp {
int amtRecv = 0;
System.Runtime.InteropServices.GCHandle gch;
gch = GCHandle.FromIntPtr(ctx);
Socket con = (System.Net.Sockets.Socket)gch.Target;
try
{
System.Runtime.InteropServices.GCHandle gch;
gch = GCHandle.FromIntPtr(ctx);
Socket con = (System.Net.Sockets.Socket)gch.Target;
Byte[] msg = new Byte[sz];
amtRecv = con.Receive(msg, msg.Length, 0);
Marshal.Copy(msg, 0, buf, sz);
}
catch (Exception e)
{
log(1, "Error in recive " + e.ToString());
log(ERROR_LOG, "Error in recive " + e.ToString());
return wolfssl.CBIO_ERR_CONN_CLOSE;
}
@ -256,16 +362,15 @@ namespace wolfSSL.CSharp {
return wolfssl.CBIO_ERR_GENERAL;
}
System.Runtime.InteropServices.GCHandle gch;
gch = GCHandle.FromIntPtr(ctx);
Socket con = (System.Net.Sockets.Socket)gch.Target;
Byte[] msg = new Byte[sz];
Marshal.Copy(buf, msg, 0, sz);
try
{
System.Runtime.InteropServices.GCHandle gch;
gch = GCHandle.FromIntPtr(ctx);
Socket con = (System.Net.Sockets.Socket)gch.Target;
Byte[] msg = new Byte[sz];
Marshal.Copy(buf, msg, 0, sz);
con.Send(msg, 0, msg.Length, SocketFlags.None);
return sz;
}
@ -293,16 +398,15 @@ namespace wolfSSL.CSharp {
return wolfssl.CBIO_ERR_GENERAL;
}
System.Runtime.InteropServices.GCHandle gch;
gch = GCHandle.FromIntPtr(ctx);
DTLS_con con = (DTLS_con)gch.Target;
Byte[] msg = new Byte[sz];
Marshal.Copy(buf, msg, 0, sz);
try
{
System.Runtime.InteropServices.GCHandle gch;
gch = GCHandle.FromIntPtr(ctx);
DTLS_con con = (DTLS_con)gch.Target;
Byte[] msg = new Byte[sz];
Marshal.Copy(buf, msg, 0, sz);
con.udp.Send(msg, msg.Length, con.ep);
return msg.Length;
}
@ -324,21 +428,27 @@ namespace wolfSSL.CSharp {
/// <returns>size of message recieved</returns>
private static int wolfSSL_dtlsCbIORecv(IntPtr ssl, IntPtr buf, int sz, IntPtr ctx)
{
if (sz <= 0)
{
log(ERROR_LOG, "wolfssl dtls recieve error, size less than 0");
return wolfssl.CBIO_ERR_GENERAL;
}
System.Runtime.InteropServices.GCHandle gch;
gch = GCHandle.FromIntPtr(ctx);
DTLS_con con = (DTLS_con)gch.Target;
Byte[] msg = new Byte[sz];
try
{
msg = con.udp.Receive(ref con.ep);
System.Runtime.InteropServices.GCHandle gch;
gch = GCHandle.FromIntPtr(ctx);
DTLS_con con = (DTLS_con)gch.Target;
Byte[] msg = con.udp.Receive(ref con.ep);
if (msg.Length > sz)
{
log(ERROR_LOG, "wolfssl DTLS packet received was larger than buffer");
return wolfssl.CBIO_ERR_GENERAL;
}
Marshal.Copy(msg, 0, buf, msg.Length);
return msg.Length;
}
catch (Exception e)
{
@ -346,10 +456,6 @@ namespace wolfSSL.CSharp {
log(ERROR_LOG, "socket read issue "+ e.ToString());
return wolfssl.CBIO_ERR_CONN_CLOSE;
}
Marshal.Copy(msg, 0, buf, msg.Length);
return msg.Length;
}
@ -360,9 +466,30 @@ namespace wolfSSL.CSharp {
/// <returns>pointer to ssl structure</returns>
public static IntPtr new_ssl(IntPtr ctx)
{
if (ctx == IntPtr.Zero)
return IntPtr.Zero;
try
{
return wolfSSL_new(ctx);
ctx_handles io;
IntPtr local_ctx = unwrap(ctx);
if (local_ctx == IntPtr.Zero)
{
log(ERROR_LOG, "new_ssl error");
return IntPtr.Zero;
}
io = new ctx_handles();
io.set_ctx(wolfSSL_new(local_ctx));
/* check if null */
if (io.get_ctx() == IntPtr.Zero)
{
return IntPtr.Zero;
}
/* keep memory pinned to be able to refrence by address */
return GCHandle.ToIntPtr(GCHandle.Alloc(io, GCHandleType.Pinned));
}
catch (Exception e)
{
@ -383,7 +510,14 @@ namespace wolfSSL.CSharp {
return FAILURE;
try
{
return wolfSSL_accept(ssl);
IntPtr sslCtx = unwrap(ssl);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "accept error");
return FAILURE;
}
return wolfSSL_accept(sslCtx);
}
catch (Exception e)
{
@ -404,7 +538,14 @@ namespace wolfSSL.CSharp {
return FAILURE;
try
{
return wolfSSL_connect(ssl);
IntPtr sslCtx = unwrap(ssl);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "connect error");
return FAILURE;
}
return wolfSSL_connect(sslCtx);
}
catch (Exception e)
{
@ -427,7 +568,14 @@ namespace wolfSSL.CSharp {
return FAILURE;
try
{
return wolfSSL_read(ssl, buf, sz);
IntPtr sslCtx = unwrap(ssl);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "connect error");
return FAILURE;
}
return wolfSSL_read(sslCtx, buf, sz);
}
catch (Exception e)
{
@ -450,7 +598,14 @@ namespace wolfSSL.CSharp {
return FAILURE;
try
{
return wolfSSL_write(ssl, buf, sz);
IntPtr sslCtx = unwrap(ssl);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "connect error");
return FAILURE;
}
return wolfSSL_write(sslCtx, buf, sz);
}
catch (Exception e)
{
@ -468,20 +623,14 @@ namespace wolfSSL.CSharp {
{
try
{
/* free the handle for the socket */
IntPtr ptr = wolfSSL_GetIOReadCtx(ssl);
if (ptr != IntPtr.Zero)
{
GCHandle gch = GCHandle.FromIntPtr(ptr);
gch.Free();
}
ptr = wolfSSL_GetIOWriteCtx(ssl);
if (ptr != IntPtr.Zero)
{
GCHandle gch = GCHandle.FromIntPtr(ptr);
gch.Free();
}
wolfSSL_free(ssl);
IntPtr sslCtx;
GCHandle gch = GCHandle.FromIntPtr(ssl);
ctx_handles handles = (ctx_handles)gch.Target;
sslCtx = handles.get_ctx();
wolfSSL_free(sslCtx);
handles.free();
gch.Free();
}
catch (Exception e)
{
@ -501,7 +650,14 @@ namespace wolfSSL.CSharp {
return FAILURE;
try
{
return wolfSSL_shutdown(ssl);
IntPtr sslCtx = unwrap(ssl);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "wolfssl shutdown error");
return FAILURE;
}
return wolfSSL_shutdown(sslCtx);
}
catch (Exception e)
{
@ -520,7 +676,20 @@ namespace wolfSSL.CSharp {
{
try
{
wolfSSL_SetIORecv(ctx, func);
GCHandle gch = GCHandle.FromIntPtr(ctx);
ctx_handles handles = (ctx_handles)gch.Target;
/* check if already stored handle needs freed */
gch = handles.get_receive();
if (!Object.Equals(gch, default(GCHandle)))
{
gch.Free();
}
/* keep new function alive */
handles.set_receive(GCHandle.Alloc(func));
wolfSSL_SetIORecv(handles.get_ctx(), func);
}
catch (Exception e)
{
@ -538,7 +707,20 @@ namespace wolfSSL.CSharp {
{
try
{
wolfSSL_SetIOSend(ctx, func);
GCHandle gch = GCHandle.FromIntPtr(ctx);
ctx_handles handles = (ctx_handles)gch.Target;
/* check if already stored handle needs freed */
gch = handles.get_send();
if (!Object.Equals(gch, default(GCHandle)))
{
gch.Free();
}
/* keep new function alive */
handles.set_send(GCHandle.Alloc(func));
wolfSSL_SetIOSend(handles.get_ctx(), func);
}
catch (Exception e)
{
@ -560,13 +742,19 @@ namespace wolfSSL.CSharp {
if (ctx == IntPtr.Zero)
return ctx;
ctx_handles io = new ctx_handles();
io.set_ctx(ctx);
CallbackIORecv_delegate recv = new CallbackIORecv_delegate(wolfssl.wolfSSLCbIORecv);
io.set_receive(GCHandle.Alloc(recv));
wolfSSL_SetIORecv(ctx, recv);
CallbackIOSend_delegate send = new CallbackIOSend_delegate(wolfssl.wolfSSLCbIOSend);
io.set_send(GCHandle.Alloc(send));
wolfSSL_SetIOSend(ctx, send);
return ctx;
/* keep memory pinned */
return GCHandle.ToIntPtr(GCHandle.Alloc(io, GCHandleType.Pinned));
}
catch (Exception e)
{
@ -589,13 +777,19 @@ namespace wolfSSL.CSharp {
if (ctx == IntPtr.Zero)
return ctx;
ctx_handles io = new ctx_handles();
io.set_ctx(ctx);
CallbackIORecv_delegate recv = new CallbackIORecv_delegate(wolfssl.wolfSSL_dtlsCbIORecv);
io.set_receive(GCHandle.Alloc(recv));
wolfSSL_SetIORecv(ctx, recv);
CallbackIOSend_delegate send = new CallbackIOSend_delegate(wolfssl.wolfSSL_dtlsCbIOSend);
io.set_send(GCHandle.Alloc(send));
wolfSSL_SetIOSend(ctx, send);
return ctx;
/* keep memory pinned */
return GCHandle.ToIntPtr(GCHandle.Alloc(io, GCHandleType.Pinned));
}
catch (Exception e)
{
@ -613,7 +807,11 @@ namespace wolfSSL.CSharp {
{
try
{
wolfSSL_CTX_free(ctx);
GCHandle gch = GCHandle.FromIntPtr(ctx);
ctx_handles handles = (ctx_handles)gch.Target;
wolfSSL_CTX_free(handles.get_ctx());
handles.free();
gch.Free();
}
catch (Exception e)
{
@ -632,7 +830,14 @@ namespace wolfSSL.CSharp {
{
try
{
return wolfSSL_CTX_use_psk_identity_hint(ctx, hint);
IntPtr local_ctx = unwrap(ctx);
if (local_ctx == IntPtr.Zero)
{
log(ERROR_LOG, "CTX use psk identity hint error");
return FAILURE;
}
return wolfSSL_CTX_use_psk_identity_hint(local_ctx, hint);
}
catch (Exception e)
{
@ -651,7 +856,11 @@ namespace wolfSSL.CSharp {
{
try
{
wolfSSL_CTX_set_psk_server_callback(ctx, psk_cb);
GCHandle gch = GCHandle.FromIntPtr(ctx);
ctx_handles handles = (ctx_handles)gch.Target;
handles.set_psk(GCHandle.Alloc(psk_cb));
wolfSSL_CTX_set_psk_server_callback(handles.get_ctx(), psk_cb);
}
catch (Exception e)
{
@ -669,7 +878,11 @@ namespace wolfSSL.CSharp {
{
try
{
wolfSSL_set_psk_server_callback(ssl, psk_cb);
GCHandle gch = GCHandle.FromIntPtr(ssl);
ctx_handles handles = (ctx_handles)gch.Target;
handles.set_psk(GCHandle.Alloc(psk_cb));
wolfSSL_set_psk_server_callback(handles.get_ctx(), psk_cb);
}
catch (Exception e)
{
@ -696,18 +909,33 @@ namespace wolfSSL.CSharp {
{
if (!fd.Equals(null))
{
IntPtr ptr = GCHandle.ToIntPtr(GCHandle.Alloc(fd));
wolfSSL_SetIOWriteCtx(ssl, ptr); //pass along the socket for writing to
wolfSSL_SetIOReadCtx(ssl, ptr); //pass along the socket for reading from
GCHandle gch = GCHandle.FromIntPtr(ssl);
ctx_handles handles = (ctx_handles)gch.Target;
IntPtr sslCtx = handles.get_ctx();
IntPtr ptr;
GCHandle fd_pin = GCHandle.Alloc(fd);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "wolfssl error setting up fd!!");
return FAILURE;
}
handles.set_fd(fd_pin);
ptr = GCHandle.ToIntPtr(fd_pin);
wolfSSL_SetIOWriteCtx(sslCtx, ptr); //pass along the socket for writing to
wolfSSL_SetIOReadCtx(sslCtx, ptr); //pass along the socket for reading from
return SUCCESS;
}
return FAILURE;
}
catch (Exception e)
{
log(ERROR_LOG, "Error setting up fd!! " + e.ToString());
return FAILURE;
}
return 1;
}
@ -720,7 +948,15 @@ namespace wolfSSL.CSharp {
{
try
{
IntPtr ptr = wolfSSL_GetIOReadCtx(ssl);
IntPtr ptr;
IntPtr sslCtx = unwrap(ssl);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "wolfssl get_fd error");
return null;
}
ptr = wolfSSL_GetIOReadCtx(sslCtx);
if (ptr != IntPtr.Zero)
{
GCHandle gch = GCHandle.FromIntPtr(ptr);
@ -746,9 +982,6 @@ namespace wolfSSL.CSharp {
/// <returns>1 on success</returns>
public static int set_dtls_fd(IntPtr ssl, UdpClient udp, IPEndPoint ep)
{
IntPtr ptr;
DTLS_con con;
/* sanity check on inputs */
if (ssl == IntPtr.Zero)
{
@ -759,21 +992,30 @@ namespace wolfSSL.CSharp {
{
if (!udp.Equals(null) && !ep.Equals(null))
{
IntPtr ptr;
DTLS_con con;
GCHandle gch = GCHandle.FromIntPtr(ssl);
ctx_handles handles = (ctx_handles)gch.Target;
GCHandle fd_pin;
con = new DTLS_con();
con.udp = udp;
con.ep = ep;
ptr = GCHandle.ToIntPtr(GCHandle.Alloc(con));
wolfSSL_SetIOWriteCtx(ssl, ptr); //pass along the socket for writing to
wolfSSL_SetIOReadCtx(ssl, ptr); //pass along the socket for reading from
con.ep = ep;
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
return SUCCESS;
}
return FAILURE;
}
catch (Exception e)
{
log(ERROR_LOG, "Error setting up fd!! " + e.ToString());
return FAILURE;
}
return 1;
}
@ -786,7 +1028,15 @@ namespace wolfSSL.CSharp {
{
try
{
IntPtr ptr = wolfSSL_GetIOReadCtx(ssl);
IntPtr ptr;
IntPtr sslCtx = unwrap(ssl);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "wolfssl get_dtls_fd error");
return null;
}
ptr = wolfSSL_GetIOReadCtx(sslCtx);
if (ptr != IntPtr.Zero)
{
GCHandle gch = GCHandle.FromIntPtr(ptr);
@ -981,7 +1231,14 @@ namespace wolfSSL.CSharp {
IntPtr ssl_cipher_ptr;
string ssl_cipher_str;
ssl_cipher = wolfSSL_get_current_cipher(ssl);
IntPtr sslCtx = unwrap(ssl);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "wolfssl get_current_cipher error");
return null;
}
ssl_cipher = wolfSSL_get_current_cipher(sslCtx);
ssl_cipher_ptr = wolfSSL_CIPHER_get_name(ssl_cipher);
ssl_cipher_str = Marshal.PtrToStringAnsi(ssl_cipher_ptr);
@ -1005,7 +1262,14 @@ namespace wolfSSL.CSharp {
{
try
{
return wolfSSL_CTX_set_cipher_list(ctx, list);
IntPtr local_ctx = unwrap(ctx);
if (local_ctx == IntPtr.Zero)
{
log(ERROR_LOG, "CTX set cipher list error");
return FAILURE;
}
return wolfSSL_CTX_set_cipher_list(local_ctx, list);
}
catch (Exception e)
{
@ -1025,7 +1289,14 @@ namespace wolfSSL.CSharp {
{
try
{
return wolfSSL_set_cipher_list(ssl, list);
IntPtr sslCtx = unwrap(ssl);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "wolfssl set_cipher_list error");
return FAILURE;
}
return wolfSSL_set_cipher_list(sslCtx, list);
}
catch (Exception e)
{
@ -1050,7 +1321,14 @@ namespace wolfSSL.CSharp {
IntPtr version_ptr;
string version;
version_ptr = wolfSSL_get_version(ssl);
IntPtr sslCtx = unwrap(ssl);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "wolfssl get_version error");
return null;
}
version_ptr = wolfSSL_get_version(sslCtx);
version = Marshal.PtrToStringAnsi(version_ptr);
return version;
@ -1079,12 +1357,19 @@ namespace wolfSSL.CSharp {
StringBuilder err_name;
StringBuilder ret;
IntPtr sslCtx = unwrap(ssl);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "wolfssl get_error error");
return null;
}
/* wolfSSL max error length is 80 */
ret = new StringBuilder(' ', 100);
err = wolfSSL_get_error(ssl, 0);
err_name = new StringBuilder(' ', 80);
wolfSSL_ERR_error_string(err, err_name);
ret.Append("Error " + err + " " + err_name);
err = wolfSSL_get_error(sslCtx, 0);
err_name = new StringBuilder(new String(' ', 80));
wolfSSL_ERR_error_string((uint)err, err_name);
ret.Append("Error " + err + " " + err_name.ToString());
return ret.ToString();
}
@ -1107,7 +1392,14 @@ namespace wolfSSL.CSharp {
{
try
{
return wolfSSL_CTX_use_certificate_file(ctx, fileCert, type);
IntPtr local_ctx = unwrap(ctx);
if (local_ctx == IntPtr.Zero)
{
log(ERROR_LOG, "CTX use certificate file error");
return FAILURE;
}
return wolfSSL_CTX_use_certificate_file(local_ctx, fileCert, type);
}
catch (Exception e)
{
@ -1128,7 +1420,14 @@ namespace wolfSSL.CSharp {
{
try
{
return wolfSSL_CTX_use_PrivateKey_file(ctx, fileKey, type);
IntPtr local_ctx = unwrap(ctx);
if (local_ctx == IntPtr.Zero)
{
log(ERROR_LOG, "CTX use PrivateKey file error");
return FAILURE;
}
return wolfSSL_CTX_use_PrivateKey_file(local_ctx, fileKey, type);
}
catch (Exception e)
{
@ -1149,7 +1448,14 @@ namespace wolfSSL.CSharp {
{
try
{
return wolfSSL_SetTmpDH_file(ssl, dhparam, file_type);
IntPtr sslCtx = unwrap(ssl);
if (sslCtx == IntPtr.Zero)
{
log(ERROR_LOG, "wolfssl SetTmpDH_file error");
return FAILURE;
}
return wolfSSL_SetTmpDH_file(sslCtx, dhparam, file_type);
}
catch (Exception e)
{
@ -1169,7 +1475,14 @@ namespace wolfSSL.CSharp {
{
try
{
return wolfSSL_CTX_SetMinDhKey_Sz(ctx, minDhKey);
IntPtr local_ctx = unwrap(ctx);
if (local_ctx == IntPtr.Zero)
{
log(ERROR_LOG, "CTX SetMinDhKey_Sz error");
return FAILURE;
}
return wolfSSL_CTX_SetMinDhKey_Sz(local_ctx, minDhKey);
}
catch (Exception e)
{

@ -53,7 +53,6 @@
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>

@ -18,6 +18,10 @@ 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