Added CSharp example for multi-threaded TLS server. Refactor to separate the ssl and ctx handles.
This commit is contained in:
parent
a28fc5e70b
commit
a8f2c97e13
41
wrapper/CSharp/include.am
Normal file
41
wrapper/CSharp/include.am
Normal file
@ -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
|
@ -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;
|
||||
|
@ -28,7 +28,7 @@ using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using wolfSSL.CSharp;
|
||||
|
||||
public class wolfSSL_TLS_CSHarp
|
||||
public class wolfSSL_TLS_Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Example of a logging function
|
||||
@ -163,7 +163,7 @@ public class wolfSSL_TLS_CSHarp
|
||||
if (wolfssl.set_fd(ssl, tcp) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.Write(wolfssl.get_error(ssl));
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
@ -174,7 +174,7 @@ public class wolfSSL_TLS_CSHarp
|
||||
if (wolfssl.connect(ssl) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.Write(wolfssl.get_error(ssl));
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<ProjectGuid>{B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>wolfSSL_TLS_CSharp</RootNamespace>
|
||||
<RootNamespace>wolfSSL_TLS_Client</RootNamespace>
|
||||
<AssemblyName>wolfSSL-TLS-Client</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -7,7 +7,7 @@
|
||||
<ProjectGuid>{8921AD35-4E62-4DAC-8FEE-8C9F8E57DDD2}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>wolfSSL_TLS_CSharp</RootNamespace>
|
||||
<RootNamespace>wolfSSL_TLS_Server</RootNamespace>
|
||||
<AssemblyName>wolfSSL-TLS-Server</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
|
6
wrapper/CSharp/wolfSSL-TLS-ServerThreaded/App.config
Executable file
6
wrapper/CSharp/wolfSSL-TLS-ServerThreaded/App.config
Executable file
@ -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-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")]
|
26
wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.Designer.cs
generated
Normal file
26
wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.Designer.cs
generated
Normal file
@ -0,0 +1,26 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// 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.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
6
wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.settings
Executable file
6
wrapper/CSharp/wolfSSL-TLS-ServerThreaded/Properties/Settings.settings
Executable file
@ -0,0 +1,6 @@
|
||||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
</SettingsFile>
|
194
wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.cs
Executable file
194
wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.cs
Executable file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// Example of a logging function
|
||||
/// </summary>
|
||||
/// <param name="lvl">level of log</param>
|
||||
/// <param name="msg">message to log</param>
|
||||
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();
|
||||
}
|
||||
}
|
132
wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.csproj
Executable file
132
wrapper/CSharp/wolfSSL-TLS-ServerThreaded/wolfSSL-TLS-ServerThreaded.csproj
Executable file
@ -0,0 +1,132 @@
|
||||
<?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>{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>wolfSSL_TLS_ServerThreaded</RootNamespace>
|
||||
<AssemblyName>wolfSSL-TLS-ServerThreaded</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</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>3</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>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\x64\DLL Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<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>
|
||||
</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="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="wolfSSL-TLS-ServerThreaded.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\wolfSSL_CSharp\wolfSSL_CSharp.csproj">
|
||||
<Project>{52609808-0418-46d3-8e17-141927a1a39a}</Project>
|
||||
<Name>wolfSSL_CSharp</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- 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>
|
@ -27,6 +27,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wolfSSL-Example-IOCallbacks
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wolfSSL-TLS-Client", "wolfSSL-TLS-Client\wolfSSL-TLS-Client.csproj", "{B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "wolfSSL-TLS-ServerThreaded", "wolfSSL-TLS-ServerThreaded\wolfSSL-TLS-ServerThreaded.csproj", "{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -251,6 +253,30 @@ Global
|
||||
{B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.Release|Win32.Build.0 = Release|Any CPU
|
||||
{B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.Release|x64.ActiveCfg = Release|x64
|
||||
{B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}.Release|x64.Build.0 = Release|x64
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Debug|Win32.ActiveCfg = Debug|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Debug|Win32.Build.0 = Debug|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Debug|x64.Build.0 = Debug|x64
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Debug|Win32.ActiveCfg = Debug|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Debug|Win32.Build.0 = Debug|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Debug|x64.ActiveCfg = Debug|x64
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Debug|x64.Build.0 = Debug|x64
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Release|Win32.ActiveCfg = Release|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Release|Win32.Build.0 = Release|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Release|x64.ActiveCfg = Release|x64
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.DLL Release|x64.Build.0 = Release|x64
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Release|Win32.ActiveCfg = Release|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Release|Win32.Build.0 = Release|Any CPU
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Release|x64.ActiveCfg = Release|x64
|
||||
{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
223
wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs
Normal file → Executable file
223
wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs
Normal file → Executable file
@ -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 {
|
||||
/// </summary>
|
||||
public void free()
|
||||
{
|
||||
log(INFO_LOG, "freeing handles");
|
||||
log(INFO_LOG, "freeing ctx handle");
|
||||
if (!Object.Equals(this.rec_cb, default(GCHandle)))
|
||||
{
|
||||
this.rec_cb.Free();
|
||||
@ -129,10 +114,57 @@ namespace wolfSSL.CSharp {
|
||||
{
|
||||
this.psk_cb.Free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/********************************
|
||||
* Class for keeping ssl handle alive
|
||||
*/
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private class ssl_handle
|
||||
{
|
||||
private GCHandle fd_pin;
|
||||
private GCHandle psk_cb;
|
||||
private IntPtr ssl;
|
||||
|
||||
public void set_fd(GCHandle input)
|
||||
{
|
||||
this.fd_pin = input;
|
||||
}
|
||||
public GCHandle get_fd()
|
||||
{
|
||||
return this.fd_pin;
|
||||
}
|
||||
|
||||
public void set_psk(GCHandle input)
|
||||
{
|
||||
this.psk_cb = input;
|
||||
}
|
||||
public GCHandle get_psk()
|
||||
{
|
||||
return this.psk_cb;
|
||||
}
|
||||
|
||||
public void set_ssl(IntPtr input)
|
||||
{
|
||||
this.ssl = input;
|
||||
}
|
||||
public IntPtr get_ssl()
|
||||
{
|
||||
return this.ssl;
|
||||
}
|
||||
public void free()
|
||||
{
|
||||
log(INFO_LOG, "freeing ssl handle");
|
||||
|
||||
if (!Object.Equals(this.fd_pin, default(GCHandle)))
|
||||
{
|
||||
this.fd_pin.Free();
|
||||
}
|
||||
if (!Object.Equals(this.psk_cb, default(GCHandle)))
|
||||
{
|
||||
this.psk_cb.Free();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,6 +314,8 @@ namespace wolfSSL.CSharp {
|
||||
private extern static int wolfSSL_CTX_SetMinDhKey_Sz(IntPtr ctx, short size);
|
||||
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
|
||||
private extern static int wolfSSL_SetTmpDH_file(IntPtr ssl, StringBuilder dhParam, int type);
|
||||
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
|
||||
private extern static int wolfSSL_CTX_SetTmpDH_file(IntPtr ctx, StringBuilder dhParam, int type);
|
||||
|
||||
|
||||
/********************************
|
||||
@ -325,13 +359,25 @@ namespace wolfSSL.CSharp {
|
||||
public static readonly int FAILURE = 0;
|
||||
|
||||
|
||||
private static IntPtr unwrap(IntPtr ctx)
|
||||
private static IntPtr unwrap_ctx(IntPtr ctx)
|
||||
{
|
||||
try {
|
||||
GCHandle gch = GCHandle.FromIntPtr(ctx);
|
||||
ctx_handles handles = (ctx_handles)gch.Target;
|
||||
ctx_handle handles = (ctx_handle)gch.Target;
|
||||
return handles.get_ctx();
|
||||
} catch (Exception e)
|
||||
{
|
||||
log(ERROR_LOG, "wolfssl ctx pointer is incorrect " + e);
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
private static IntPtr unwrap_ssl(IntPtr ssl)
|
||||
{
|
||||
try {
|
||||
GCHandle gch = GCHandle.FromIntPtr(ssl);
|
||||
ssl_handle handles = (ssl_handle)gch.Target;
|
||||
return handles.get_ssl();
|
||||
} catch (Exception e)
|
||||
{
|
||||
log(ERROR_LOG, "wolfssl pointer is incorrect " + e);
|
||||
return IntPtr.Zero;
|
||||
@ -517,19 +563,19 @@ namespace wolfSSL.CSharp {
|
||||
|
||||
try
|
||||
{
|
||||
ctx_handles io;
|
||||
IntPtr local_ctx = unwrap(ctx);
|
||||
ssl_handle io;
|
||||
IntPtr local_ctx = unwrap_ctx(ctx);
|
||||
if (local_ctx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "new_ssl error");
|
||||
log(ERROR_LOG, "new_ssl ctx unwrap error");
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
|
||||
io = new ctx_handles();
|
||||
io.set_ctx(wolfSSL_new(local_ctx));
|
||||
io = new ssl_handle();
|
||||
io.set_ssl(wolfSSL_new(local_ctx));
|
||||
|
||||
/* check if null */
|
||||
if (io.get_ctx() == IntPtr.Zero)
|
||||
if (io.get_ssl() == IntPtr.Zero)
|
||||
{
|
||||
return IntPtr.Zero;
|
||||
}
|
||||
@ -556,10 +602,10 @@ namespace wolfSSL.CSharp {
|
||||
return FAILURE;
|
||||
try
|
||||
{
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "accept error");
|
||||
log(ERROR_LOG, "accept ssl unwrap error");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
@ -584,10 +630,10 @@ namespace wolfSSL.CSharp {
|
||||
return FAILURE;
|
||||
try
|
||||
{
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "connect error");
|
||||
log(ERROR_LOG, "connect ssl unwrap error");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
@ -614,14 +660,16 @@ namespace wolfSSL.CSharp {
|
||||
return FAILURE;
|
||||
try
|
||||
{
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
IntPtr data;
|
||||
int ret;
|
||||
byte[] msg;
|
||||
|
||||
buf.Clear(); /* Clear incomming buffer */
|
||||
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "read error");
|
||||
log(ERROR_LOG, "read ssl unwrap error");
|
||||
return FAILURE;
|
||||
}
|
||||
data = Marshal.AllocHGlobal(sz);
|
||||
@ -666,13 +714,13 @@ namespace wolfSSL.CSharp {
|
||||
return FAILURE;
|
||||
try
|
||||
{
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
IntPtr data;
|
||||
int ret;
|
||||
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "wolfssl read error");
|
||||
log(ERROR_LOG, "read ssl unwrap error");
|
||||
return FAILURE;
|
||||
}
|
||||
data = Marshal.AllocHGlobal(sz);
|
||||
@ -709,13 +757,13 @@ namespace wolfSSL.CSharp {
|
||||
return FAILURE;
|
||||
try
|
||||
{
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
IntPtr data;
|
||||
int ret;
|
||||
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "write error");
|
||||
log(ERROR_LOG, "write ssl unwrap error");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
@ -748,13 +796,13 @@ namespace wolfSSL.CSharp {
|
||||
return FAILURE;
|
||||
try
|
||||
{
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
IntPtr data;
|
||||
int ret;
|
||||
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "write error");
|
||||
log(ERROR_LOG, "write ssl unwrap error");
|
||||
return FAILURE;
|
||||
}
|
||||
data = Marshal.AllocHGlobal(sz);
|
||||
@ -782,9 +830,9 @@ namespace wolfSSL.CSharp {
|
||||
{
|
||||
IntPtr sslCtx;
|
||||
GCHandle gch = GCHandle.FromIntPtr(ssl);
|
||||
ctx_handles handles = (ctx_handles)gch.Target;
|
||||
ssl_handle handles = (ssl_handle)gch.Target;
|
||||
|
||||
sslCtx = handles.get_ctx();
|
||||
sslCtx = handles.get_ssl();
|
||||
wolfSSL_free(sslCtx);
|
||||
handles.free();
|
||||
gch.Free();
|
||||
@ -807,10 +855,10 @@ namespace wolfSSL.CSharp {
|
||||
return FAILURE;
|
||||
try
|
||||
{
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "wolfssl shutdown error");
|
||||
log(ERROR_LOG, "shutdown ssl unwrap error");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
@ -834,7 +882,7 @@ namespace wolfSSL.CSharp {
|
||||
try
|
||||
{
|
||||
GCHandle gch = GCHandle.FromIntPtr(ctx);
|
||||
ctx_handles handles = (ctx_handles)gch.Target;
|
||||
ctx_handle handles = (ctx_handle)gch.Target;
|
||||
|
||||
/* check if already stored handle needs freed */
|
||||
gch = handles.get_receive();
|
||||
@ -865,7 +913,7 @@ namespace wolfSSL.CSharp {
|
||||
try
|
||||
{
|
||||
GCHandle gch = GCHandle.FromIntPtr(ctx);
|
||||
ctx_handles handles = (ctx_handles)gch.Target;
|
||||
ctx_handle handles = (ctx_handle)gch.Target;
|
||||
|
||||
/* check if already stored handle needs freed */
|
||||
gch = handles.get_send();
|
||||
@ -899,7 +947,7 @@ namespace wolfSSL.CSharp {
|
||||
if (ctx == IntPtr.Zero)
|
||||
return ctx;
|
||||
|
||||
ctx_handles io = new ctx_handles();
|
||||
ctx_handle io = new ctx_handle();
|
||||
io.set_ctx(ctx);
|
||||
|
||||
CallbackIORecv_delegate recv = new CallbackIORecv_delegate(wolfssl.wolfSSLCbIORecv);
|
||||
@ -934,7 +982,7 @@ namespace wolfSSL.CSharp {
|
||||
if (ctx == IntPtr.Zero)
|
||||
return ctx;
|
||||
|
||||
ctx_handles io = new ctx_handles();
|
||||
ctx_handle io = new ctx_handle();
|
||||
io.set_ctx(ctx);
|
||||
|
||||
CallbackIORecv_delegate recv = new CallbackIORecv_delegate(wolfssl.wolfSSL_dtlsCbIORecv);
|
||||
@ -965,7 +1013,7 @@ namespace wolfSSL.CSharp {
|
||||
try
|
||||
{
|
||||
GCHandle gch = GCHandle.FromIntPtr(ctx);
|
||||
ctx_handles handles = (ctx_handles)gch.Target;
|
||||
ctx_handle handles = (ctx_handle)gch.Target;
|
||||
wolfSSL_CTX_free(handles.get_ctx());
|
||||
handles.free();
|
||||
gch.Free();
|
||||
@ -987,10 +1035,10 @@ namespace wolfSSL.CSharp {
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr local_ctx = unwrap(ctx);
|
||||
IntPtr local_ctx = unwrap_ctx(ctx);
|
||||
if (local_ctx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "CTX use psk identity hint error");
|
||||
log(ERROR_LOG, "CTX use psk identity hint unwrap error");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
@ -1014,7 +1062,7 @@ namespace wolfSSL.CSharp {
|
||||
try
|
||||
{
|
||||
GCHandle gch = GCHandle.FromIntPtr(ctx);
|
||||
ctx_handles handles = (ctx_handles)gch.Target;
|
||||
ctx_handle handles = (ctx_handle)gch.Target;
|
||||
|
||||
handles.set_psk(GCHandle.Alloc(psk_cb));
|
||||
wolfSSL_CTX_set_psk_server_callback(handles.get_ctx(), psk_cb);
|
||||
@ -1036,7 +1084,7 @@ namespace wolfSSL.CSharp {
|
||||
try
|
||||
{
|
||||
GCHandle gch = GCHandle.FromIntPtr(ctx);
|
||||
ctx_handles handles = (ctx_handles)gch.Target;
|
||||
ctx_handle handles = (ctx_handle)gch.Target;
|
||||
|
||||
handles.set_psk(GCHandle.Alloc(psk_cb));
|
||||
wolfSSL_CTX_set_psk_client_callback(handles.get_ctx(), psk_cb);
|
||||
@ -1058,10 +1106,10 @@ namespace wolfSSL.CSharp {
|
||||
try
|
||||
{
|
||||
GCHandle gch = GCHandle.FromIntPtr(ssl);
|
||||
ctx_handles handles = (ctx_handles)gch.Target;
|
||||
ssl_handle handles = (ssl_handle)gch.Target;
|
||||
|
||||
handles.set_psk(GCHandle.Alloc(psk_cb));
|
||||
wolfSSL_set_psk_server_callback(handles.get_ctx(), psk_cb);
|
||||
wolfSSL_set_psk_server_callback(handles.get_ssl(), psk_cb);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@ -1089,8 +1137,8 @@ namespace wolfSSL.CSharp {
|
||||
if (!fd.Equals(null))
|
||||
{
|
||||
GCHandle gch = GCHandle.FromIntPtr(ssl);
|
||||
ctx_handles handles = (ctx_handles)gch.Target;
|
||||
IntPtr sslCtx = handles.get_ctx();
|
||||
ssl_handle handles = (ssl_handle)gch.Target;
|
||||
IntPtr sslCtx = handles.get_ssl();
|
||||
IntPtr ptr;
|
||||
GCHandle fd_pin = GCHandle.Alloc(fd);
|
||||
|
||||
@ -1128,7 +1176,7 @@ namespace wolfSSL.CSharp {
|
||||
try
|
||||
{
|
||||
IntPtr ptr;
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "wolfssl get_fd error");
|
||||
@ -1174,7 +1222,7 @@ namespace wolfSSL.CSharp {
|
||||
IntPtr ptr;
|
||||
DTLS_con con;
|
||||
GCHandle gch = GCHandle.FromIntPtr(ssl);
|
||||
ctx_handles handles = (ctx_handles)gch.Target;
|
||||
ssl_handle handles = (ssl_handle)gch.Target;
|
||||
GCHandle fd_pin;
|
||||
|
||||
con = new DTLS_con();
|
||||
@ -1183,8 +1231,8 @@ namespace wolfSSL.CSharp {
|
||||
fd_pin = GCHandle.Alloc(con);
|
||||
handles.set_fd(fd_pin);
|
||||
ptr = GCHandle.ToIntPtr(fd_pin);
|
||||
wolfSSL_SetIOWriteCtx(handles.get_ctx(), ptr); //pass along the socket for writing to
|
||||
wolfSSL_SetIOReadCtx(handles.get_ctx(), ptr); //pass along the socket for reading from
|
||||
wolfSSL_SetIOWriteCtx(handles.get_ssl(), ptr); //pass along the socket for writing to
|
||||
wolfSSL_SetIOReadCtx(handles.get_ssl(), ptr); //pass along the socket for reading from
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
@ -1208,7 +1256,7 @@ namespace wolfSSL.CSharp {
|
||||
try
|
||||
{
|
||||
IntPtr ptr;
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "wolfssl get_dtls_fd error");
|
||||
@ -1443,7 +1491,7 @@ namespace wolfSSL.CSharp {
|
||||
IntPtr ssl_cipher_ptr;
|
||||
string ssl_cipher_str;
|
||||
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "wolfssl get_current_cipher error");
|
||||
@ -1474,7 +1522,7 @@ namespace wolfSSL.CSharp {
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr local_ctx = unwrap(ctx);
|
||||
IntPtr local_ctx = unwrap_ctx(ctx);
|
||||
if (local_ctx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "CTX set cipher list error");
|
||||
@ -1501,7 +1549,7 @@ namespace wolfSSL.CSharp {
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "wolfssl set_cipher_list error");
|
||||
@ -1533,7 +1581,7 @@ namespace wolfSSL.CSharp {
|
||||
IntPtr version_ptr;
|
||||
string version;
|
||||
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "wolfssl get_version error");
|
||||
@ -1569,7 +1617,7 @@ namespace wolfSSL.CSharp {
|
||||
StringBuilder err_name;
|
||||
StringBuilder ret;
|
||||
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "wolfssl get_error error");
|
||||
@ -1604,7 +1652,7 @@ namespace wolfSSL.CSharp {
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr local_ctx = unwrap(ctx);
|
||||
IntPtr local_ctx = unwrap_ctx(ctx);
|
||||
if (local_ctx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "CTX use certificate file error");
|
||||
@ -1632,7 +1680,7 @@ namespace wolfSSL.CSharp {
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr local_ctx = unwrap(ctx);
|
||||
IntPtr local_ctx = unwrap_ctx(ctx);
|
||||
if (local_ctx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "CTX load verify locations certificate file error");
|
||||
@ -1659,7 +1707,7 @@ namespace wolfSSL.CSharp {
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr local_ctx = unwrap(ctx);
|
||||
IntPtr local_ctx = unwrap_ctx(ctx);
|
||||
if (local_ctx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "CTX use PrivateKey file error");
|
||||
@ -1687,10 +1735,10 @@ namespace wolfSSL.CSharp {
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr sslCtx = unwrap(ssl);
|
||||
IntPtr sslCtx = unwrap_ssl(ssl);
|
||||
if (sslCtx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "wolfssl SetTmpDH_file error");
|
||||
log(ERROR_LOG, "SetTmpDH_file ssl unwrap error");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
@ -1698,7 +1746,34 @@ namespace wolfSSL.CSharp {
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log(ERROR_LOG, "wolfssl set tmp dh file error " + e.ToString());
|
||||
log(ERROR_LOG, "SetTmpDH_file error " + e.ToString());
|
||||
return FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set temporary DH parameters
|
||||
/// </summary>
|
||||
/// <param name="ctx">Structure to set in</param>
|
||||
/// <param name="dhparam">file name</param>
|
||||
/// <param name="file_type">type of file ie PEM</param>
|
||||
/// <returns>1 on success</returns>
|
||||
public static int CTX_SetTmpDH_file(IntPtr ctx, StringBuilder dhparam, int file_type)
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr local_ctx = unwrap_ctx(ctx);
|
||||
if (local_ctx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "CTX_SetTmpDH_file ctx unwrap error");
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
return wolfSSL_CTX_SetTmpDH_file(local_ctx, dhparam, file_type);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log(ERROR_LOG, "CTX_SetTmpDH_file error " + e.ToString());
|
||||
return FAILURE;
|
||||
}
|
||||
}
|
||||
@ -1714,7 +1789,7 @@ namespace wolfSSL.CSharp {
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr local_ctx = unwrap(ctx);
|
||||
IntPtr local_ctx = unwrap_ctx(ctx);
|
||||
if (local_ctx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "CTX SetMinDhKey_Sz error");
|
||||
@ -1740,7 +1815,7 @@ namespace wolfSSL.CSharp {
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr local_ctx = unwrap(ctx);
|
||||
IntPtr local_ctx = unwrap_ctx(ctx);
|
||||
if (local_ctx == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "CTX set_verify error");
|
||||
@ -1767,7 +1842,7 @@ namespace wolfSSL.CSharp {
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr local_ssl = unwrap(ssl);
|
||||
IntPtr local_ssl = unwrap_ssl(ssl);
|
||||
if (local_ssl == IntPtr.Zero)
|
||||
{
|
||||
log(ERROR_LOG, "set_verify error");
|
||||
|
@ -4,39 +4,4 @@
|
||||
|
||||
include wrapper/python/wolfcrypt/include.am
|
||||
include wrapper/python/wolfssl/include.am
|
||||
|
||||
# wolfSSL CSharp wrapper files
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/App.config
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/Properties/AssemblyInfo.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/wolfSSL-DTLS-PSK-Server.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-PSK-Server/wolfSSL-DTLS-PSK-Server.csproj
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-Server/App.config
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-Server/Properties/AssemblyInfo.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-Server/wolfSSL-DTLS-Server.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-DTLS-Server/wolfSSL-DTLS-Server.csproj
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-PSK-Server/App.config
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-PSK-Server/Properties/AssemblyInfo.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-PSK-Server/wolfSSL-TLS-PSK-Server.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-PSK-Server/wolfSSL-TLS-PSK-Server.csproj
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/App.config
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/Properties/AssemblyInfo.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/Properties/Settings.Designer.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/Properties/Settings.settings
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Server/wolfSSL-TLS-Server.csproj
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-Example-IOCallbacks/App.config
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-Example-IOCallbacks/Properties/AssemblyInfo.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-Example-IOCallbacks/wolfSSL-Example-IOCallbacks.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-Example-IOCallbacks/wolfSSL-Example-IOCallbacks.csproj
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp.sln
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/Properties/AssemblyInfo.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/Properties/Resources.Designer.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/Properties/Resources.resx
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL_CSharp/wolfSSL_CSharp.csproj
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/App.config
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/Properties/AssemblyInfo.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/Properties/Settings.Designer.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/Properties/Settings.settings
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs
|
||||
EXTRA_DIST+= wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.csproj
|
||||
include wrapper/CSharp/include.am
|
||||
|
Loading…
Reference in New Issue
Block a user