Imported Upstream version 3.10.2+dfsg
This commit is contained in:
6
wrapper/CSharp/wolfSSL-DTLS-PSK-Server/App.config
Executable file
6
wrapper/CSharp/wolfSSL-DTLS-PSK-Server/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-DTLS-PSK-Server")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("wolfSSL")]
|
||||
[assembly: AssemblyProduct("wolfSSL-DTLS-PSK-Server")]
|
||||
[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("77149dab-52f6-4b83-a9bd-da5beb402621")]
|
||||
|
||||
// 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,220 @@
|
||||
/* wolfSSL-DTLS-PSK-Server.cs
|
||||
*
|
||||
* Copyright (C) 2006-2016 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.Threading;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using wolfSSL.CSharp;
|
||||
|
||||
|
||||
|
||||
public class wolfSSL_DTLS_PSK_Server
|
||||
{
|
||||
|
||||
|
||||
/// <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();
|
||||
}
|
||||
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
IntPtr ctx;
|
||||
IntPtr ssl;
|
||||
|
||||
/* These paths should be changed according to use */
|
||||
string fileCert = @"server-cert.pem";
|
||||
string fileKey = @"server-key.pem";
|
||||
StringBuilder dhparam = new StringBuilder("dh2048.pem");
|
||||
|
||||
wolfssl.psk_delegate psk_cb = new wolfssl.psk_delegate(my_psk_server_cb);
|
||||
|
||||
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_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;
|
||||
}
|
||||
|
||||
|
||||
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, 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");
|
||||
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;
|
||||
wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey);
|
||||
Console.Write("Setting cipher suite to ");
|
||||
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)
|
||||
{
|
||||
Console.WriteLine("Failed to set cipher suite");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
IPAddress ip = IPAddress.Parse("0.0.0.0");
|
||||
UdpClient udp = new UdpClient(11111);
|
||||
IPEndPoint ep = new IPEndPoint(ip, 11111);
|
||||
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;
|
||||
}
|
||||
|
||||
/* 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));
|
||||
|
||||
/* get connection information and print ip - port */
|
||||
wolfssl.DTLS_con con = wolfssl.get_dtls_fd(ssl);
|
||||
Console.Write("Connected to ip ");
|
||||
Console.Write(con.ep.Address.ToString());
|
||||
Console.Write(" on port ");
|
||||
Console.WriteLine(con.ep.Port.ToString());
|
||||
|
||||
/* read information sent and send a reply */
|
||||
if (wolfssl.read(ssl, buff, 1023) < 0)
|
||||
{
|
||||
Console.WriteLine("Error reading message");
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
udp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
Console.WriteLine(buff);
|
||||
|
||||
if (wolfssl.write(ssl, reply, reply.Length) != reply.Length)
|
||||
{
|
||||
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);
|
||||
udp.Close();
|
||||
clean(ssl, ctx);
|
||||
}
|
||||
}
|
||||
87
wrapper/CSharp/wolfSSL-DTLS-PSK-Server/wolfSSL-DTLS-PSK-Server.csproj
Executable file
87
wrapper/CSharp/wolfSSL-DTLS-PSK-Server/wolfSSL-DTLS-PSK-Server.csproj
Executable file
@@ -0,0 +1,87 @@
|
||||
<?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>{77AEF1BE-4BE3-4837-8188-2A06E4D963F5}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>wolfSSL_DTLS_PSK_Server</RootNamespace>
|
||||
<AssemblyName>wolfSSL-DTLS-PSK-Server</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>
|
||||
</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="wolfSSL-DTLS-PSK-Server.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" />
|
||||
<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>
|
||||
Reference in New Issue
Block a user