no code change; CRLF line endings, trailing spaces

pull/5978/head
gojimmypi 2023-01-13 16:29:19 -08:00
parent 46ace19111
commit 91d2ff1fe9
36 changed files with 3100 additions and 3100 deletions

View File

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

View File

@ -2,7 +2,7 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("wolfSSL-DTLS-PSK-Server")] [assembly: AssemblyTitle("wolfSSL-DTLS-PSK-Server")]
@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
@ -25,11 +25,11 @@ using System.Runtime.InteropServices;
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")] [assembly: AssemblyVersion("1.1.0.0")]

View File

@ -18,9 +18,9 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/ */
using System; using System;
@ -48,12 +48,12 @@ public class wolfSSL_DTLS_PSK_Server
/// <returns>size of key set</returns> /// <returns>size of key set</returns>
public static uint my_psk_server_cb(IntPtr ssl, string identity, IntPtr key, uint max_key) public static uint my_psk_server_cb(IntPtr ssl, string identity, IntPtr key, uint max_key)
{ {
/* perform a check on the identity sent across /* perform a check on the identity sent across
* log function must be set for print out of logging information * log function must be set for print out of logging information
*/ */
wolfssl.log(wolfssl.INFO_LOG, "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 /* Use desired key, note must be a key smaller than max key size parameter
Replace this with desired key. Is trivial one for testing */ Replace this with desired key. Is trivial one for testing */
if (max_key < 4) if (max_key < 4)
return 0; return 0;

View File

@ -77,7 +77,7 @@
<PreBuildEvent> <PreBuildEvent>
</PreBuildEvent> </PreBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>

View File

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

View File

@ -2,7 +2,7 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("wolfSSL-DTLS-Server")] [assembly: AssemblyTitle("wolfSSL-DTLS-Server")]
@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
@ -25,11 +25,11 @@ using System.Runtime.InteropServices;
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")] [assembly: AssemblyVersion("1.1.0.0")]

View File

@ -18,9 +18,9 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/ */
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;

View File

@ -78,7 +78,7 @@
<PreBuildEvent> <PreBuildEvent>
</PreBuildEvent> </PreBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>

View File

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

View File

@ -2,7 +2,7 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("wolfSSL-Example-IOCallbacks")] [assembly: AssemblyTitle("wolfSSL-Example-IOCallbacks")]
@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
@ -25,11 +25,11 @@ using System.Runtime.InteropServices;
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")] [assembly: AssemblyVersion("1.1.0.0")]

View File

@ -18,8 +18,8 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/ */
using System; using System;
@ -122,12 +122,12 @@ class wolfSSL_Example_IOCallbacks
/// <returns>size of key set</returns> /// <returns>size of key set</returns>
public static uint my_psk_server_cb(IntPtr ssl, string identity, IntPtr key, uint max_key) public static uint my_psk_server_cb(IntPtr ssl, string identity, IntPtr key, uint max_key)
{ {
/* perform a check on the identity sent across /* perform a check on the identity sent across
* log function must be set for print out of logging information * log function must be set for print out of logging information
*/ */
wolfssl.log(wolfssl.INFO_LOG, "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 /* Use desired key, note must be a key smaller than max key size parameter
Replace this with desired key. Is trivial one for testing */ Replace this with desired key. Is trivial one for testing */
if (max_key < 4) if (max_key < 4)
return 0; return 0;

View File

@ -74,7 +74,7 @@
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>

View File

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

View File

@ -1,36 +1,36 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("wolfSSL-TLS-Client")] [assembly: AssemblyTitle("wolfSSL-TLS-Client")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("wolfSSL")] [assembly: AssemblyCompany("wolfSSL")]
[assembly: AssemblyProduct("wolfSSL-TLS-Client")] [assembly: AssemblyProduct("wolfSSL-TLS-Client")]
[assembly: AssemblyCopyright("Copyright wolfSSL 2020")] [assembly: AssemblyCopyright("Copyright wolfSSL 2020")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM // The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("05aad2b4-445e-4f0e-8e16-8f8512696505")] [assembly: Guid("05aad2b4-445e-4f0e-8e16-8f8512696505")]
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")] [assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")] [assembly: AssemblyFileVersion("1.1.0.0")]

View File

@ -1,210 +1,210 @@
/* wolfSSL-TLS-Client.cs /* wolfSSL-TLS-Client.cs
* *
* Copyright (C) 2006-2023 wolfSSL Inc. * Copyright (C) 2006-2023 wolfSSL Inc.
* *
* This file is part of wolfSSL. * This file is part of wolfSSL.
* *
* wolfSSL is free software; you can redistribute it and/or modify * wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* wolfSSL is distributed in the hope that it will be useful, * wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/ */
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using wolfSSL.CSharp; using wolfSSL.CSharp;
public class wolfSSL_TLS_Client public class wolfSSL_TLS_Client
{ {
/// <summary> /// <summary>
/// Example of a logging function /// Example of a logging function
/// </summary> /// </summary>
/// <param name="lvl">level of log</param> /// <param name="lvl">level of log</param>
/// <param name="msg">message to log</param> /// <param name="msg">message to log</param>
public static void standard_log(int lvl, StringBuilder msg) public static void standard_log(int lvl, StringBuilder msg)
{ {
Console.WriteLine(msg); Console.WriteLine(msg);
} }
private static void clean(IntPtr ssl, IntPtr ctx) private static void clean(IntPtr ssl, IntPtr ctx)
{ {
wolfssl.free(ssl); wolfssl.free(ssl);
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
wolfssl.Cleanup(); wolfssl.Cleanup();
} }
/// <summary> /// <summary>
/// Verification callback /// Verification callback
/// </summary> /// </summary>
/// <param name="preverify">1=Verify Okay, 0=Failure</param> /// <param name="preverify">1=Verify Okay, 0=Failure</param>
/// <param name="x509_ctx">Certificate in WOLFSSL_X509_STORE_CTX format</param> /// <param name="x509_ctx">Certificate in WOLFSSL_X509_STORE_CTX format</param>
private static int myVerify(int preverify, IntPtr x509_ctx) private static int myVerify(int preverify, IntPtr x509_ctx)
{ {
/* Use the provided verification */ /* Use the provided verification */
/* Can optionally override failures by returning non-zero value */ /* Can optionally override failures by returning non-zero value */
return preverify; return preverify;
} }
public static void Main(string[] args) public static void Main(string[] args)
{ {
IntPtr ctx; IntPtr ctx;
IntPtr ssl; IntPtr ssl;
Socket tcp; Socket tcp;
/* These paths should be changed for use */ /* These paths should be changed for use */
string caCert = @"ca-cert.pem"; string caCert = @"ca-cert.pem";
StringBuilder dhparam = new StringBuilder("dh2048.pem"); StringBuilder dhparam = new StringBuilder("dh2048.pem");
StringBuilder buff = new StringBuilder(1024); StringBuilder buff = new StringBuilder(1024);
StringBuilder reply = new StringBuilder("Hello, this is the wolfSSL C# wrapper"); StringBuilder reply = new StringBuilder("Hello, this is the wolfSSL C# wrapper");
//example of function used for setting logging //example of function used for setting logging
wolfssl.SetLogging(standard_log); wolfssl.SetLogging(standard_log);
wolfssl.Init(); wolfssl.Init();
Console.WriteLine("Calling ctx Init from wolfSSL"); Console.WriteLine("Calling ctx Init from wolfSSL");
ctx = wolfssl.CTX_new(wolfssl.usev23_client()); ctx = wolfssl.CTX_new(wolfssl.usev23_client());
if (ctx == IntPtr.Zero) if (ctx == IntPtr.Zero)
{ {
Console.WriteLine("Error in creating ctx structure"); Console.WriteLine("Error in creating ctx structure");
return; return;
} }
Console.WriteLine("Finished init of ctx .... now load in CA"); Console.WriteLine("Finished init of ctx .... now load in CA");
if (!File.Exists(caCert)) if (!File.Exists(caCert))
{ {
Console.WriteLine("Could not find CA cert file"); Console.WriteLine("Could not find CA cert file");
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
return; return;
} }
if (wolfssl.CTX_load_verify_locations(ctx, caCert, null) if (wolfssl.CTX_load_verify_locations(ctx, caCert, null)
!= wolfssl.SUCCESS) != wolfssl.SUCCESS)
{ {
Console.WriteLine("Error loading CA cert"); Console.WriteLine("Error loading CA cert");
} }
StringBuilder ciphers = new StringBuilder(new String(' ', 4096)); StringBuilder ciphers = new StringBuilder(new String(' ', 4096));
wolfssl.get_ciphers(ciphers, 4096); wolfssl.get_ciphers(ciphers, 4096);
Console.WriteLine("Ciphers : " + ciphers.ToString()); Console.WriteLine("Ciphers : " + ciphers.ToString());
/* Uncomment Section to enable specific cipher suite */ /* Uncomment Section to enable specific cipher suite */
#if false #if false
ciphers = new StringBuilder("ECDHE-ECDSA-AES128-GCM-SHA256"); ciphers = new StringBuilder("ECDHE-ECDSA-AES128-GCM-SHA256");
if (wolfssl.CTX_set_cipher_list(ctx, ciphers) != wolfssl.SUCCESS) if (wolfssl.CTX_set_cipher_list(ctx, ciphers) != wolfssl.SUCCESS)
{ {
Console.WriteLine("ERROR CTX_set_cipher_list()"); Console.WriteLine("ERROR CTX_set_cipher_list()");
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
return; return;
} }
#endif #endif
short minDhKey = 128; short minDhKey = 128;
wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey); wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey);
/* Setup Verify Callback */ /* Setup Verify Callback */
if (wolfssl.CTX_set_verify(ctx, wolfssl.SSL_VERIFY_PEER, myVerify) if (wolfssl.CTX_set_verify(ctx, wolfssl.SSL_VERIFY_PEER, myVerify)
!= wolfssl.SUCCESS) != wolfssl.SUCCESS)
{ {
Console.WriteLine("Error setting verify callback!"); Console.WriteLine("Error setting verify callback!");
} }
/* set up TCP socket */ /* set up TCP socket */
tcp = new Socket(AddressFamily.InterNetwork, SocketType.Stream, tcp = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp); ProtocolType.Tcp);
try try
{ {
tcp.Connect("localhost", 11111); tcp.Connect("localhost", 11111);
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine("tcp.Connect() error " + e.ToString()); Console.WriteLine("tcp.Connect() error " + e.ToString());
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
return; return;
} }
if (!tcp.Connected) if (!tcp.Connected)
{ {
Console.WriteLine("tcp.Connect() failed!"); Console.WriteLine("tcp.Connect() failed!");
tcp.Close(); tcp.Close();
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
return; return;
} }
Console.WriteLine("Connected TCP"); Console.WriteLine("Connected TCP");
ssl = wolfssl.new_ssl(ctx); ssl = wolfssl.new_ssl(ctx);
if (ssl == IntPtr.Zero) if (ssl == IntPtr.Zero)
{ {
Console.WriteLine("Error in creating ssl object"); Console.WriteLine("Error in creating ssl object");
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
return; return;
} }
Console.WriteLine("Connection made wolfSSL_connect "); Console.WriteLine("Connection made wolfSSL_connect ");
if (wolfssl.set_fd(ssl, tcp) != wolfssl.SUCCESS) if (wolfssl.set_fd(ssl, tcp) != wolfssl.SUCCESS)
{ {
/* get and print out the error */ /* get and print out the error */
Console.WriteLine(wolfssl.get_error(ssl)); Console.WriteLine(wolfssl.get_error(ssl));
tcp.Close(); tcp.Close();
clean(ssl, ctx); clean(ssl, ctx);
return; return;
} }
wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM); wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM);
if (wolfssl.connect(ssl) != wolfssl.SUCCESS) if (wolfssl.connect(ssl) != wolfssl.SUCCESS)
{ {
/* get and print out the error */ /* get and print out the error */
Console.WriteLine(wolfssl.get_error(ssl)); Console.WriteLine(wolfssl.get_error(ssl));
tcp.Close(); tcp.Close();
clean(ssl, ctx); clean(ssl, ctx);
return; return;
} }
/* print out results of TLS/SSL accept */ /* print out results of TLS/SSL accept */
Console.WriteLine("SSL version is " + wolfssl.get_version(ssl)); Console.WriteLine("SSL version is " + wolfssl.get_version(ssl));
Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl)); Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl));
if (wolfssl.write(ssl, reply, reply.Length) != reply.Length) if (wolfssl.write(ssl, reply, reply.Length) != reply.Length)
{ {
Console.WriteLine("Error in write"); Console.WriteLine("Error in write");
tcp.Close(); tcp.Close();
clean(ssl, ctx); clean(ssl, ctx);
return; return;
} }
/* read and print out the message then reply */ /* read and print out the message then reply */
if (wolfssl.read(ssl, buff, 1023) < 0) if (wolfssl.read(ssl, buff, 1023) < 0)
{ {
Console.WriteLine("Error in read"); Console.WriteLine("Error in read");
tcp.Close(); tcp.Close();
clean(ssl, ctx); clean(ssl, ctx);
return; return;
} }
Console.WriteLine(buff); Console.WriteLine(buff);
wolfssl.shutdown(ssl); wolfssl.shutdown(ssl);
tcp.Close(); tcp.Close();
clean(ssl, ctx); clean(ssl, ctx);
} }
} }

View File

@ -1,123 +1,123 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <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')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}</ProjectGuid> <ProjectGuid>{B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}</ProjectGuid>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>wolfSSL_TLS_Client</RootNamespace> <RootNamespace>wolfSSL_TLS_Client</RootNamespace>
<AssemblyName>wolfSSL-TLS-Client</AssemblyName> <AssemblyName>wolfSSL-TLS-Client</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<PublishUrl>publish\</PublishUrl> <PublishUrl>publish\</PublishUrl>
<Install>true</Install> <Install>true</Install>
<InstallFrom>Disk</InstallFrom> <InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled> <UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode> <UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval> <UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits> <UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically> <UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired> <UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions> <MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision> <ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper> <IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>..\DLL Debug\Win32\</OutputPath> <OutputPath>..\DLL Debug\Win32\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>3</WarningLevel> <WarningLevel>3</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>..\DLL Release\Win32\</OutputPath> <OutputPath>..\DLL Release\Win32\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<StartupObject /> <StartupObject />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<OutputPath>..\DLL Debug\x64\</OutputPath> <OutputPath>..\DLL Debug\x64\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>..\DLL Release\x64</OutputPath> <OutputPath>..\DLL Release\x64</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="wolfSSL-TLS-Client.cs" /> <Compile Include="wolfSSL-TLS-Client.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\wolfSSL_CSharp\wolfSSL_CSharp.csproj"> <ProjectReference Include="..\wolfSSL_CSharp\wolfSSL_CSharp.csproj">
<Project>{52609808-0418-46d3-8e17-141927a1a39a}</Project> <Project>{52609808-0418-46d3-8e17-141927a1a39a}</Project>
<Name>wolfSSL_CSharp</Name> <Name>wolfSSL_CSharp</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5"> <BootstrapperPackage Include=".NETFramework,Version=v4.5">
<Visible>False</Visible> <Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName> <ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
<Install>true</Install> <Install>true</Install>
</BootstrapperPackage> </BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5"> <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible> <Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install> <Install>false</Install>
</BootstrapperPackage> </BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible> <Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName> <ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install> <Install>false</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PreBuildEvent> <PreBuildEvent>
</PreBuildEvent> </PreBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>

View File

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

View File

@ -1,36 +1,36 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("wolfSSL-TLS-PSK-Client")] [assembly: AssemblyTitle("wolfSSL-TLS-PSK-Client")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("wolfSSL")] [assembly: AssemblyCompany("wolfSSL")]
[assembly: AssemblyProduct("wolfSSL-TLS-PSK-Client")] [assembly: AssemblyProduct("wolfSSL-TLS-PSK-Client")]
[assembly: AssemblyCopyright("Copyright wolfSSL 2020")] [assembly: AssemblyCopyright("Copyright wolfSSL 2020")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM // The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("1de70ade-16d5-4c90-9657-c19c2762bca6")] [assembly: Guid("1de70ade-16d5-4c90-9657-c19c2762bca6")]
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")] [assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")] [assembly: AssemblyFileVersion("1.1.0.0")]

View File

@ -18,8 +18,8 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/ */
using System; using System;
@ -49,13 +49,13 @@ public class wolfSSL_TLS_PSK_Client
/// <returns>size of key set</returns> /// <returns>size of key set</returns>
public static uint my_psk_client_cb(IntPtr ssl, string hint, IntPtr identity, uint id_max, IntPtr key, uint max_key) public static uint my_psk_client_cb(IntPtr ssl, string hint, IntPtr identity, uint id_max, IntPtr key, uint max_key)
{ {
/* C# client */ /* C# client */
byte[] id = { 67, 35, 32, 99, 108, 105, 101, 110, 116 }; byte[] id = { 67, 35, 32, 99, 108, 105, 101, 110, 116 };
if (id_max < 9) if (id_max < 9)
return 0; return 0;
Marshal.Copy(id, 0, identity, 9); Marshal.Copy(id, 0, identity, 9);
/* Use desired key, note must be a key smaller than max key size parameter /* Use desired key, note must be a key smaller than max key size parameter
Replace this with desired key. Is trivial one for testing */ Replace this with desired key. Is trivial one for testing */
if (max_key < 4) if (max_key < 4)
return 0; return 0;
@ -76,9 +76,9 @@ public class wolfSSL_TLS_PSK_Client
public static void Main(string[] args) public static void Main(string[] args)
{ {
IntPtr ctx; IntPtr ctx;
IntPtr ssl; IntPtr ssl;
Socket tcp; Socket tcp;
wolfssl.psk_client_delegate psk_cb = new wolfssl.psk_client_delegate(my_psk_client_cb); wolfssl.psk_client_delegate psk_cb = new wolfssl.psk_client_delegate(my_psk_client_cb);
@ -118,81 +118,81 @@ public class wolfSSL_TLS_PSK_Client
/* Test psk use with DHE */ /* Test psk use with DHE */
wolfssl.CTX_set_psk_client_callback(ctx, psk_cb); wolfssl.CTX_set_psk_client_callback(ctx, psk_cb);
/* set up TCP socket */ /* set up TCP socket */
tcp = new Socket(AddressFamily.InterNetwork, SocketType.Stream, tcp = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp); ProtocolType.Tcp);
try try
{ {
tcp.Connect("localhost", 11111); tcp.Connect("localhost", 11111);
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine("tcp.Connect() error " + e.ToString()); Console.WriteLine("tcp.Connect() error " + e.ToString());
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
return; return;
} }
if (!tcp.Connected) if (!tcp.Connected)
{ {
Console.WriteLine("tcp.Connect() failed!"); Console.WriteLine("tcp.Connect() failed!");
tcp.Close(); tcp.Close();
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
return; return;
} }
Console.WriteLine("Connected TCP"); Console.WriteLine("Connected TCP");
ssl = wolfssl.new_ssl(ctx); ssl = wolfssl.new_ssl(ctx);
if (ssl == IntPtr.Zero) if (ssl == IntPtr.Zero)
{ {
Console.WriteLine("Error in creating ssl object"); Console.WriteLine("Error in creating ssl object");
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
return; return;
} }
if (wolfssl.set_fd(ssl, tcp) != wolfssl.SUCCESS) if (wolfssl.set_fd(ssl, tcp) != wolfssl.SUCCESS)
{ {
/* get and print out the error */ /* get and print out the error */
Console.WriteLine(wolfssl.get_error(ssl)); Console.WriteLine(wolfssl.get_error(ssl));
tcp.Close(); tcp.Close();
clean(ssl, ctx); clean(ssl, ctx);
return; return;
} }
wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM); wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM);
if (wolfssl.connect(ssl) != wolfssl.SUCCESS) if (wolfssl.connect(ssl) != wolfssl.SUCCESS)
{ {
/* get and print out the error */ /* get and print out the error */
Console.WriteLine(wolfssl.get_error(ssl)); Console.WriteLine(wolfssl.get_error(ssl));
tcp.Close(); tcp.Close();
clean(ssl, ctx); clean(ssl, ctx);
return; return;
} }
/* print out results of TLS/SSL accept */ /* print out results of TLS/SSL accept */
Console.WriteLine("SSL version is " + wolfssl.get_version(ssl)); Console.WriteLine("SSL version is " + wolfssl.get_version(ssl));
Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl)); Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl));
if (wolfssl.write(ssl, reply, reply.Length) != reply.Length) if (wolfssl.write(ssl, reply, reply.Length) != reply.Length)
{ {
Console.WriteLine("Error in write"); Console.WriteLine("Error in write");
tcp.Close(); tcp.Close();
clean(ssl, ctx); clean(ssl, ctx);
return; return;
} }
/* read and print out the message then reply */ /* read and print out the message then reply */
if (wolfssl.read(ssl, buff, 1023) < 0) if (wolfssl.read(ssl, buff, 1023) < 0)
{ {
Console.WriteLine("Error in read"); Console.WriteLine("Error in read");
tcp.Close(); tcp.Close();
clean(ssl, ctx); clean(ssl, ctx);
return; return;
} }
Console.WriteLine(buff); Console.WriteLine(buff);
wolfssl.shutdown(ssl); wolfssl.shutdown(ssl);
tcp.Close(); tcp.Close();
clean(ssl, ctx); clean(ssl, ctx);
} }
} }

View File

@ -1,115 +1,115 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="12.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')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{4F92ECF5-A1D8-4A13-AD0C-6571EB03C01C}</ProjectGuid> <ProjectGuid>{4F92ECF5-A1D8-4A13-AD0C-6571EB03C01C}</ProjectGuid>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>wolfSSL_TLS_PSK_Client</RootNamespace> <RootNamespace>wolfSSL_TLS_PSK_Client</RootNamespace>
<AssemblyName>wolfSSL-TLS-PSK-Client</AssemblyName> <AssemblyName>wolfSSL-TLS-PSK-Client</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<PublishUrl>publish\</PublishUrl> <PublishUrl>publish\</PublishUrl>
<Install>true</Install> <Install>true</Install>
<InstallFrom>Disk</InstallFrom> <InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled> <UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode> <UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval> <UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits> <UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically> <UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired> <UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions> <MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision> <ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper> <IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>..\DLL Debug\Win32\</OutputPath> <OutputPath>..\DLL Debug\Win32\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>..\DLL Release\Win32\</OutputPath> <OutputPath>..\DLL Release\Win32\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<OutputPath>..\DLL Debug\x64\</OutputPath> <OutputPath>..\DLL Debug\x64\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>..\DLL Release\x64\</OutputPath> <OutputPath>..\DLL Release\x64\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="wolfSSL-TLS-PSK-Client.cs" /> <Compile Include="wolfSSL-TLS-PSK-Client.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\wolfSSL_CSharp\wolfSSL_CSharp.csproj"> <ProjectReference Include="..\wolfSSL_CSharp\wolfSSL_CSharp.csproj">
<Project>{52609808-0418-46d3-8e17-141927a1a39a}</Project> <Project>{52609808-0418-46d3-8e17-141927a1a39a}</Project>
<Name>wolfSSL_CSharp</Name> <Name>wolfSSL_CSharp</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.8"> <BootstrapperPackage Include=".NETFramework,Version=v4.8">
<Visible>False</Visible> <Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.8 %28x86 and x64%29</ProductName> <ProductName>Microsoft .NET Framework 4.8 %28x86 and x64%29</ProductName>
<Install>true</Install> <Install>true</Install>
</BootstrapperPackage> </BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible> <Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName> <ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install> <Install>false</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PreBuildEvent> <PreBuildEvent>
</PreBuildEvent> </PreBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>

View File

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

View File

@ -2,7 +2,7 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("wolfSSL-TLS-PSK-Server")] [assembly: AssemblyTitle("wolfSSL-TLS-PSK-Server")]
@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
@ -25,11 +25,11 @@ using System.Runtime.InteropServices;
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")] [assembly: AssemblyVersion("1.1.0.0")]

View File

@ -18,8 +18,8 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/ */
using System; using System;
@ -47,12 +47,12 @@ public class wolfSSL_TLS_PSK_Server
/// <returns>size of key set</returns> /// <returns>size of key set</returns>
public static uint my_psk_server_cb(IntPtr ssl, string identity, IntPtr key, uint max_key) public static uint my_psk_server_cb(IntPtr ssl, string identity, IntPtr key, uint max_key)
{ {
/* perform a check on the identity sent across /* perform a check on the identity sent across
* log function must be set for print out of logging information * log function must be set for print out of logging information
*/ */
wolfssl.log(wolfssl.INFO_LOG, "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 /* Use desired key, note must be a key smaller than max key size parameter
Replace this with desired key. Is trivial one for testing */ Replace this with desired key. Is trivial one for testing */
if (max_key < 4) if (max_key < 4)
return 0; return 0;

View File

@ -77,7 +77,7 @@
<PreBuildEvent> <PreBuildEvent>
</PreBuildEvent> </PreBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>

View File

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

View File

@ -2,7 +2,7 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("wolfSSL-TLS-Server")] [assembly: AssemblyTitle("wolfSSL-TLS-Server")]
@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
@ -25,11 +25,11 @@ using System.Runtime.InteropServices;
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")] [assembly: AssemblyVersion("1.1.0.0")]

View File

@ -18,8 +18,8 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/ */
using System; using System;

View File

@ -113,7 +113,7 @@
<PreBuildEvent> <PreBuildEvent>
</PreBuildEvent> </PreBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>

View File

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

View File

@ -1,36 +1,36 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("wolfSSL-TLS-ServerThreaded")] [assembly: AssemblyTitle("wolfSSL-TLS-ServerThreaded")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")] [assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("wolfSSL")] [assembly: AssemblyCompany("wolfSSL")]
[assembly: AssemblyProduct("wolfSSL-TLS-ServerThreaded")] [assembly: AssemblyProduct("wolfSSL-TLS-ServerThreaded")]
[assembly: AssemblyCopyright("Copyright wolfSSL 2020")] [assembly: AssemblyCopyright("Copyright wolfSSL 2020")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM // The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("716e8f30-1318-4e3b-b788-d0380b397a4c")] [assembly: Guid("716e8f30-1318-4e3b-b788-d0380b397a4c")]
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")] [assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")] [assembly: AssemblyFileVersion("1.1.0.0")]

View File

@ -1,194 +1,194 @@
/* wolfSSL-TLS-ServerThreaded.cs /* wolfSSL-TLS-ServerThreaded.cs
* *
* Copyright (C) 2006-2023 wolfSSL Inc. * Copyright (C) 2006-2023 wolfSSL Inc.
* *
* This file is part of wolfSSL. * This file is part of wolfSSL.
* *
* wolfSSL is free software; you can redistribute it and/or modify * wolfSSL is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* wolfSSL is distributed in the hope that it will be useful, * wolfSSL is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/ */
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading; using System.Threading;
using wolfSSL.CSharp; using wolfSSL.CSharp;
public class wolfSSL_TLS_ServerThread public class wolfSSL_TLS_ServerThread
{ {
private IntPtr _ctx; private IntPtr _ctx;
private Socket _fd; private Socket _fd;
public wolfSSL_TLS_ServerThread(IntPtr ctx, Socket fd) public wolfSSL_TLS_ServerThread(IntPtr ctx, Socket fd)
{ {
_ctx = ctx; _ctx = ctx;
_fd = fd; _fd = fd;
} }
private const int kEchoBufSz = 1024; private const int kEchoBufSz = 1024;
public void start_client() public void start_client()
{ {
StringBuilder buff = new StringBuilder(kEchoBufSz); StringBuilder buff = new StringBuilder(kEchoBufSz);
IntPtr ssl = wolfssl.new_ssl(_ctx); IntPtr ssl = wolfssl.new_ssl(_ctx);
if (ssl == IntPtr.Zero) if (ssl == IntPtr.Zero)
{ {
Console.WriteLine("Error in creating ssl object"); Console.WriteLine("Error in creating ssl object");
return; return;
} }
if (wolfssl.set_fd(ssl, _fd) != wolfssl.SUCCESS) if (wolfssl.set_fd(ssl, _fd) != wolfssl.SUCCESS)
{ {
/* get and print out the error */ /* get and print out the error */
Console.WriteLine(wolfssl.get_error(ssl)); Console.WriteLine(wolfssl.get_error(ssl));
_fd.Close(); _fd.Close();
wolfssl.free(ssl); wolfssl.free(ssl);
return; return;
} }
Console.WriteLine("Starting TLS handshake"); Console.WriteLine("Starting TLS handshake");
if (wolfssl.accept(ssl) != wolfssl.SUCCESS) if (wolfssl.accept(ssl) != wolfssl.SUCCESS)
{ {
/* get and print out the error */ /* get and print out the error */
Console.WriteLine("Failed " + wolfssl.get_error(ssl)); Console.WriteLine("Failed " + wolfssl.get_error(ssl));
_fd.Close(); _fd.Close();
wolfssl.free(ssl); wolfssl.free(ssl);
return; return;
} }
/* print out results of TLS/SSL accept */ /* print out results of TLS/SSL accept */
Console.WriteLine("SSL version is " + wolfssl.get_version(ssl)); Console.WriteLine("SSL version is " + wolfssl.get_version(ssl));
Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl)); Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl));
/* echo data until error */ /* echo data until error */
while (true) while (true)
{ {
/* read and print out the message then reply */ /* read and print out the message then reply */
if (wolfssl.read(ssl, buff, kEchoBufSz-1) < 0) if (wolfssl.read(ssl, buff, kEchoBufSz-1) < 0)
{ {
Console.WriteLine("Error in read"); Console.WriteLine("Error in read");
break; break;
} }
Console.WriteLine(buff); Console.WriteLine(buff);
if (wolfssl.write(ssl, buff, buff.Length) != buff.Length) if (wolfssl.write(ssl, buff, buff.Length) != buff.Length)
{ {
Console.WriteLine("Error in write"); Console.WriteLine("Error in write");
break; break;
} }
} }
Console.WriteLine("Closing " + wolfssl.get_error(ssl)); Console.WriteLine("Closing " + wolfssl.get_error(ssl));
_fd.Close(); _fd.Close();
wolfssl.free(ssl); wolfssl.free(ssl);
} }
} }
public class wolfSSL_TLS_ServerThreaded public class wolfSSL_TLS_ServerThreaded
{ {
/// <summary> /// <summary>
/// Example of a logging function /// Example of a logging function
/// </summary> /// </summary>
/// <param name="lvl">level of log</param> /// <param name="lvl">level of log</param>
/// <param name="msg">message to log</param> /// <param name="msg">message to log</param>
public static void standard_log(int lvl, StringBuilder msg) public static void standard_log(int lvl, StringBuilder msg)
{ {
Console.WriteLine(msg); Console.WriteLine(msg);
} }
public static void Main(string[] args) public static void Main(string[] args)
{ {
IntPtr ctx; IntPtr ctx;
/* These paths should be changed for use */ /* These paths should be changed for use */
string fileCert = @"server-cert.pem"; string fileCert = @"server-cert.pem";
string fileKey = @"server-key.pem"; string fileKey = @"server-key.pem";
StringBuilder dhparam = new StringBuilder("dh2048.pem"); StringBuilder dhparam = new StringBuilder("dh2048.pem");
/* example of function used for setting logging */ /* example of function used for setting logging */
wolfssl.SetLogging(standard_log); wolfssl.SetLogging(standard_log);
wolfssl.Init(); wolfssl.Init();
Console.WriteLine("Calling ctx Init from wolfSSL"); Console.WriteLine("Calling ctx Init from wolfSSL");
ctx = wolfssl.CTX_new(wolfssl.usev23_server()); ctx = wolfssl.CTX_new(wolfssl.usev23_server());
if (ctx == IntPtr.Zero) if (ctx == IntPtr.Zero)
{ {
Console.WriteLine("Error in creating ctx structure"); Console.WriteLine("Error in creating ctx structure");
return; return;
} }
Console.WriteLine("Finished init of ctx .... now load in cert and key"); Console.WriteLine("Finished init of ctx .... now load in cert and key");
if (!File.Exists(fileCert) || !File.Exists(fileKey)) if (!File.Exists(fileCert) || !File.Exists(fileKey))
{ {
Console.WriteLine("Could not find cert or key file"); Console.WriteLine("Could not find cert or key file");
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
return; return;
} }
if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS) if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
{ {
Console.WriteLine("Error in setting cert file"); Console.WriteLine("Error in setting cert file");
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
return; return;
} }
if (wolfssl.CTX_use_PrivateKey_file(ctx, fileKey, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS) if (wolfssl.CTX_use_PrivateKey_file(ctx, fileKey, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
{ {
Console.WriteLine("Error in setting key file"); Console.WriteLine("Error in setting key file");
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
return; return;
} }
StringBuilder ciphers = new StringBuilder(new String(' ', 4096)); StringBuilder ciphers = new StringBuilder(new String(' ', 4096));
wolfssl.get_ciphers(ciphers, 4096); wolfssl.get_ciphers(ciphers, 4096);
Console.WriteLine("Ciphers : " + ciphers.ToString()); Console.WriteLine("Ciphers : " + ciphers.ToString());
short minDhKey = 128; short minDhKey = 128;
wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey); wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey);
wolfssl.CTX_SetTmpDH_file(ctx, dhparam, wolfssl.SSL_FILETYPE_PEM); wolfssl.CTX_SetTmpDH_file(ctx, dhparam, wolfssl.SSL_FILETYPE_PEM);
/* set up TCP socket */ /* 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); TcpListener tcp = new TcpListener(ip, 11111);
tcp.Start(); tcp.Start();
Console.WriteLine("Started TCP and waiting for a connection"); Console.WriteLine("Started TCP and waiting for a connection");
while (true) { while (true) {
try try
{ {
Socket fd = tcp.AcceptSocket(); Socket fd = tcp.AcceptSocket();
Console.WriteLine("Got client connection"); Console.WriteLine("Got client connection");
/* Spin up thread for client */ /* Spin up thread for client */
wolfSSL_TLS_ServerThread thread = new wolfSSL_TLS_ServerThread(ctx, fd); wolfSSL_TLS_ServerThread thread = new wolfSSL_TLS_ServerThread(ctx, fd);
Thread thr = new Thread(new ThreadStart(thread.start_client)); Thread thr = new Thread(new ThreadStart(thread.start_client));
thr.Start(); thr.Start();
} }
catch(Exception ex) catch(Exception ex)
{ {
Console.WriteLine("Server Exception " + ex.ToString()); Console.WriteLine("Server Exception " + ex.ToString());
break; break;
} }
} }
tcp.Stop(); tcp.Stop();
wolfssl.CTX_free(ctx); wolfssl.CTX_free(ctx);
wolfssl.Cleanup(); wolfssl.Cleanup();
} }
} }

View File

@ -1,123 +1,123 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <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')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}</ProjectGuid> <ProjectGuid>{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}</ProjectGuid>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>wolfSSL_TLS_ServerThreaded</RootNamespace> <RootNamespace>wolfSSL_TLS_ServerThreaded</RootNamespace>
<AssemblyName>wolfSSL-TLS-ServerThreaded</AssemblyName> <AssemblyName>wolfSSL-TLS-ServerThreaded</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<PublishUrl>publish\</PublishUrl> <PublishUrl>publish\</PublishUrl>
<Install>true</Install> <Install>true</Install>
<InstallFrom>Disk</InstallFrom> <InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled> <UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode> <UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval> <UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits> <UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically> <UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired> <UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions> <MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision> <ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion> <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper> <IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust> <UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled> <BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>..\DLL Debug\Win32\</OutputPath> <OutputPath>..\DLL Debug\Win32\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>3</WarningLevel> <WarningLevel>3</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget> <PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>..\DLL Release\Win32\</OutputPath> <OutputPath>..\DLL Release\Win32\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<StartupObject /> <StartupObject />
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<OutputPath>..\DLL Debug\x64\</OutputPath> <OutputPath>..\DLL Debug\x64\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>..\DLL Release\x64\</OutputPath> <OutputPath>..\DLL Release\x64\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="wolfSSL-TLS-ServerThreaded.cs" /> <Compile Include="wolfSSL-TLS-ServerThreaded.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="App.config" /> <None Include="App.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\wolfSSL_CSharp\wolfSSL_CSharp.csproj"> <ProjectReference Include="..\wolfSSL_CSharp\wolfSSL_CSharp.csproj">
<Project>{52609808-0418-46d3-8e17-141927a1a39a}</Project> <Project>{52609808-0418-46d3-8e17-141927a1a39a}</Project>
<Name>wolfSSL_CSharp</Name> <Name>wolfSSL_CSharp</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.5"> <BootstrapperPackage Include=".NETFramework,Version=v4.5">
<Visible>False</Visible> <Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName> <ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
<Install>true</Install> <Install>true</Install>
</BootstrapperPackage> </BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5"> <BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible> <Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName> <ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install> <Install>false</Install>
</BootstrapperPackage> </BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible> <Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName> <ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install> <Install>false</Install>
</BootstrapperPackage> </BootstrapperPackage>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup> <PropertyGroup>
<PreBuildEvent> <PreBuildEvent>
</PreBuildEvent> </PreBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>

View File

@ -2,7 +2,7 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("wolfSSL.CSharp")] [assembly: AssemblyTitle("wolfSSL.CSharp")]
@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // 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 // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
@ -25,11 +25,11 @@ using System.Runtime.InteropServices;
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")] [assembly: AssemblyVersion("1.1.0.0")]

View File

@ -1,6 +1,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
namespace wolfSSL.CSharp namespace wolfSSL.CSharp
@ -9,21 +9,21 @@ namespace wolfSSL.CSharp
{ {
private const string wolfssl_dll = "wolfssl.dll"; private const string wolfssl_dll = "wolfssl.dll";
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
private extern static int wolfSSL_X509_get_pubkey_buffer(IntPtr x509, IntPtr buf, IntPtr bufSz); private extern static int wolfSSL_X509_get_pubkey_buffer(IntPtr x509, IntPtr buf, IntPtr bufSz);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
private extern static IntPtr wolfSSL_X509_get_der(IntPtr x509, IntPtr bufSz); private extern static IntPtr wolfSSL_X509_get_der(IntPtr x509, IntPtr bufSz);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
private extern static void wolfSSL_X509_free(IntPtr x509); private extern static void wolfSSL_X509_free(IntPtr x509);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
private extern static int wc_DerToPem(IntPtr der, int derSz, IntPtr pem, int pemSz, int type); private extern static int wc_DerToPem(IntPtr der, int derSz, IntPtr pem, int pemSz, int type);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
private extern static IntPtr wolfSSL_X509_get_name_oneline(IntPtr x509Name, IntPtr buf, int bufSz); private extern static IntPtr wolfSSL_X509_get_name_oneline(IntPtr x509Name, IntPtr buf, int bufSz);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
private extern static IntPtr wolfSSL_X509_get_subject_name(IntPtr x509); private extern static IntPtr wolfSSL_X509_get_subject_name(IntPtr x509);
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)] [DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
private extern static IntPtr wolfSSL_X509_get_issuer_name(IntPtr x509); private extern static IntPtr wolfSSL_X509_get_issuer_name(IntPtr x509);
private IntPtr x509; private IntPtr x509;
@ -71,74 +71,74 @@ namespace wolfSSL.CSharp
} }
/// <summary> /// <summary>
/// Used for getting the public key buffer /// Used for getting the public key buffer
/// </summary> /// </summary>
/// <returns>DER public key on success</returns> /// <returns>DER public key on success</returns>
public byte[] GetPublicKey() public byte[] GetPublicKey()
{ {
if (this.x509 == IntPtr.Zero) if (this.x509 == IntPtr.Zero)
{ {
return null; return null;
} }
try try
{ {
IntPtr bufSz; IntPtr bufSz;
IntPtr buf; IntPtr buf;
int keySz = 0; int keySz = 0;
int ret; int ret;
byte[] key = null; byte[] key = null;
bufSz = Marshal.AllocHGlobal(4); /* pointer to 4 bytes */ bufSz = Marshal.AllocHGlobal(4); /* pointer to 4 bytes */
ret = wolfSSL_X509_get_pubkey_buffer(this.x509, IntPtr.Zero, bufSz); ret = wolfSSL_X509_get_pubkey_buffer(this.x509, IntPtr.Zero, bufSz);
if (ret == wolfssl.SUCCESS) if (ret == wolfssl.SUCCESS)
{ {
keySz = Marshal.ReadInt32(bufSz, 0); keySz = Marshal.ReadInt32(bufSz, 0);
buf = Marshal.AllocHGlobal(keySz); buf = Marshal.AllocHGlobal(keySz);
ret = wolfSSL_X509_get_pubkey_buffer(this.x509, buf, bufSz); ret = wolfSSL_X509_get_pubkey_buffer(this.x509, buf, bufSz);
if (ret == wolfssl.SUCCESS) if (ret == wolfssl.SUCCESS)
{ {
key = new byte[keySz]; key = new byte[keySz];
Marshal.Copy(buf, key, 0, keySz); Marshal.Copy(buf, key, 0, keySz);
} }
Marshal.FreeHGlobal(buf); Marshal.FreeHGlobal(buf);
} }
Marshal.FreeHGlobal(bufSz); Marshal.FreeHGlobal(bufSz);
return key; return key;
} }
catch (Exception e) catch (Exception e)
{ {
wolfssl.log(wolfssl.ERROR_LOG, "error getting public key" + e.ToString()); wolfssl.log(wolfssl.ERROR_LOG, "error getting public key" + e.ToString());
return null; return null;
} }
} }
/// <summary> /// <summary>
/// Gets the X509 buffer /// Gets the X509 buffer
/// </summary> /// </summary>
/// <returns>X509 buffer on success</returns> /// <returns>X509 buffer on success</returns>
public byte[] Export(int type) public byte[] Export(int type)
{ {
if (this.x509 == IntPtr.Zero) if (this.x509 == IntPtr.Zero)
return null; return null;
try try
{ {
IntPtr bufSz; IntPtr bufSz;
IntPtr buf; IntPtr buf;
byte[] ret = null; byte[] ret = null;
bufSz = Marshal.AllocHGlobal(4); /* pointer to 4 bytes */ bufSz = Marshal.AllocHGlobal(4); /* pointer to 4 bytes */
buf = wolfSSL_X509_get_der(this.x509, bufSz); buf = wolfSSL_X509_get_der(this.x509, bufSz);
if (buf != IntPtr.Zero) if (buf != IntPtr.Zero)
{ {
int derSz = Marshal.ReadInt32(bufSz, 0); int derSz = Marshal.ReadInt32(bufSz, 0);
if (type == wolfssl.SSL_FILETYPE_ASN1) if (type == wolfssl.SSL_FILETYPE_ASN1)
{ {
ret = new byte[derSz]; ret = new byte[derSz];
Marshal.Copy(buf, ret, 0, derSz); Marshal.Copy(buf, ret, 0, derSz);
} }
else if (type == wolfssl.SSL_FILETYPE_PEM) else if (type == wolfssl.SSL_FILETYPE_PEM)
{ {
int pemSz; int pemSz;
@ -153,41 +153,41 @@ namespace wolfSSL.CSharp
Marshal.FreeHGlobal(pem); Marshal.FreeHGlobal(pem);
} }
} }
else else
{ {
wolfssl.log(wolfssl.ERROR_LOG, "unsupported export type"); wolfssl.log(wolfssl.ERROR_LOG, "unsupported export type");
} }
Marshal.FreeHGlobal(bufSz); Marshal.FreeHGlobal(bufSz);
return ret; return ret;
} }
{ {
wolfssl.log(wolfssl.ERROR_LOG, "unable to get buffer"); wolfssl.log(wolfssl.ERROR_LOG, "unable to get buffer");
} }
Marshal.FreeHGlobal(bufSz); Marshal.FreeHGlobal(bufSz);
return ret; return ret;
} }
catch (Exception e) catch (Exception e)
{ {
wolfssl.log(wolfssl.ERROR_LOG, "error getting x509 DER" + e.ToString()); wolfssl.log(wolfssl.ERROR_LOG, "error getting x509 DER" + e.ToString());
return null; return null;
} }
} }
/// <summary> /// <summary>
/// Gets the X509 buffer using this.type set (default PEM) /// Gets the X509 buffer using this.type set (default PEM)
/// </summary> /// </summary>
/// <returns>X509 buffer on success</returns> /// <returns>X509 buffer on success</returns>
public byte[] Export() public byte[] Export()
{ {
return Export(this.type); return Export(this.type);
} }
/// <summary> /// <summary>
/// Gets the X509 format /// Gets the X509 format
/// </summary> /// </summary>
/// <returns>X509 format on success</returns> /// <returns>X509 format on success</returns>
public string GetFormat() public string GetFormat()
{ {
if (this.type == wolfssl.SSL_FILETYPE_PEM) if (this.type == wolfssl.SSL_FILETYPE_PEM)
{ {

File diff suppressed because it is too large Load Diff

View File

@ -72,7 +72,7 @@ xcopy "$(ProjectDir)..\..\..\certs\server-cert.pem" "$(TargetDir)" /Y /R
xcopy "$(ProjectDir)..\..\..\certs\dh2048.pem" "$(TargetDir)" /Y /R xcopy "$(ProjectDir)..\..\..\certs\dh2048.pem" "$(TargetDir)" /Y /R
xcopy "$(ProjectDir)..\..\..\certs\ca-cert.pem" "$(TargetDir)" /Y /R</PreBuildEvent> xcopy "$(ProjectDir)..\..\..\certs\ca-cert.pem" "$(TargetDir)" /Y /R</PreBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>