mirror of https://github.com/wolfSSL/wolfssl.git
no code change; CRLF line endings, trailing spaces
parent
46ace19111
commit
91d2ff1fe9
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -2,7 +2,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
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
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("wolfSSL-DTLS-PSK-Server")]
|
||||
|
@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
|
|||
[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
|
||||
// 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)]
|
||||
|
||||
|
@ -25,11 +25,11 @@ using System.Runtime.InteropServices;
|
|||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// 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:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* 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;
|
||||
|
||||
|
@ -48,12 +48,12 @@ public class wolfSSL_DTLS_PSK_Server
|
|||
/// <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
|
||||
/* 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
|
||||
/* 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;
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</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.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -2,7 +2,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
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
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("wolfSSL-DTLS-Server")]
|
||||
|
@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
|
|||
[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
|
||||
// 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)]
|
||||
|
||||
|
@ -25,11 +25,11 @@ using System.Runtime.InteropServices;
|
|||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// 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:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
* 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;
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</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.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -2,7 +2,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
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
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("wolfSSL-Example-IOCallbacks")]
|
||||
|
@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
|
|||
[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
|
||||
// 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)]
|
||||
|
||||
|
@ -25,11 +25,11 @@ using System.Runtime.InteropServices;
|
|||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// 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:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* 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;
|
||||
|
@ -122,12 +122,12 @@ class wolfSSL_Example_IOCallbacks
|
|||
/// <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
|
||||
/* 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
|
||||
/* 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;
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
<!-- 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>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -1,36 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("wolfSSL-TLS-Client")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("wolfSSL")]
|
||||
[assembly: AssemblyProduct("wolfSSL-TLS-Client")]
|
||||
[assembly: AssemblyCopyright("Copyright wolfSSL 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("05aad2b4-445e-4f0e-8e16-8f8512696505")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("wolfSSL-TLS-Client")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("wolfSSL")]
|
||||
[assembly: AssemblyProduct("wolfSSL-TLS-Client")]
|
||||
[assembly: AssemblyCopyright("Copyright wolfSSL 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("05aad2b4-445e-4f0e-8e16-8f8512696505")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
|
|
|
@ -1,210 +1,210 @@
|
|||
/* wolfSSL-TLS-Client.cs
|
||||
*
|
||||
* Copyright (C) 2006-2023 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL.
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using wolfSSL.CSharp;
|
||||
|
||||
public class wolfSSL_TLS_Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Example of a logging function
|
||||
/// </summary>
|
||||
/// <param name="lvl">level of log</param>
|
||||
/// <param name="msg">message to log</param>
|
||||
public static void standard_log(int lvl, StringBuilder msg)
|
||||
{
|
||||
Console.WriteLine(msg);
|
||||
}
|
||||
|
||||
|
||||
private static void clean(IntPtr ssl, IntPtr ctx)
|
||||
{
|
||||
wolfssl.free(ssl);
|
||||
wolfssl.CTX_free(ctx);
|
||||
wolfssl.Cleanup();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verification callback
|
||||
/// </summary>
|
||||
/// <param name="preverify">1=Verify Okay, 0=Failure</param>
|
||||
/// <param name="x509_ctx">Certificate in WOLFSSL_X509_STORE_CTX format</param>
|
||||
private static int myVerify(int preverify, IntPtr x509_ctx)
|
||||
{
|
||||
/* Use the provided verification */
|
||||
/* Can optionally override failures by returning non-zero value */
|
||||
return preverify;
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
IntPtr ctx;
|
||||
IntPtr ssl;
|
||||
Socket tcp;
|
||||
|
||||
/* These paths should be changed for use */
|
||||
string caCert = @"ca-cert.pem";
|
||||
StringBuilder dhparam = new StringBuilder("dh2048.pem");
|
||||
|
||||
StringBuilder buff = new StringBuilder(1024);
|
||||
StringBuilder reply = new StringBuilder("Hello, this is the wolfSSL C# wrapper");
|
||||
|
||||
//example of function used for setting logging
|
||||
wolfssl.SetLogging(standard_log);
|
||||
|
||||
wolfssl.Init();
|
||||
|
||||
|
||||
Console.WriteLine("Calling ctx Init from wolfSSL");
|
||||
ctx = wolfssl.CTX_new(wolfssl.usev23_client());
|
||||
if (ctx == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Error in creating ctx structure");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("Finished init of ctx .... now load in CA");
|
||||
|
||||
|
||||
if (!File.Exists(caCert))
|
||||
{
|
||||
Console.WriteLine("Could not find CA cert file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (wolfssl.CTX_load_verify_locations(ctx, caCert, null)
|
||||
!= wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error loading CA cert");
|
||||
}
|
||||
|
||||
StringBuilder ciphers = new StringBuilder(new String(' ', 4096));
|
||||
wolfssl.get_ciphers(ciphers, 4096);
|
||||
Console.WriteLine("Ciphers : " + ciphers.ToString());
|
||||
|
||||
/* Uncomment Section to enable specific cipher suite */
|
||||
#if false
|
||||
ciphers = new StringBuilder("ECDHE-ECDSA-AES128-GCM-SHA256");
|
||||
if (wolfssl.CTX_set_cipher_list(ctx, ciphers) != wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("ERROR CTX_set_cipher_list()");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
short minDhKey = 128;
|
||||
wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey);
|
||||
|
||||
/* Setup Verify Callback */
|
||||
if (wolfssl.CTX_set_verify(ctx, wolfssl.SSL_VERIFY_PEER, myVerify)
|
||||
!= wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error setting verify callback!");
|
||||
}
|
||||
|
||||
|
||||
/* set up TCP socket */
|
||||
tcp = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
|
||||
ProtocolType.Tcp);
|
||||
try
|
||||
{
|
||||
tcp.Connect("localhost", 11111);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("tcp.Connect() error " + e.ToString());
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
if (!tcp.Connected)
|
||||
{
|
||||
Console.WriteLine("tcp.Connect() failed!");
|
||||
tcp.Close();
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Connected TCP");
|
||||
ssl = wolfssl.new_ssl(ctx);
|
||||
if (ssl == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Error in creating ssl object");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Connection made wolfSSL_connect ");
|
||||
if (wolfssl.set_fd(ssl, tcp) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM);
|
||||
|
||||
if (wolfssl.connect(ssl) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* print out results of TLS/SSL accept */
|
||||
Console.WriteLine("SSL version is " + wolfssl.get_version(ssl));
|
||||
Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl));
|
||||
|
||||
|
||||
if (wolfssl.write(ssl, reply, reply.Length) != reply.Length)
|
||||
{
|
||||
Console.WriteLine("Error in write");
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* read and print out the message then reply */
|
||||
if (wolfssl.read(ssl, buff, 1023) < 0)
|
||||
{
|
||||
Console.WriteLine("Error in read");
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
Console.WriteLine(buff);
|
||||
|
||||
wolfssl.shutdown(ssl);
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
}
|
||||
}
|
||||
/* wolfSSL-TLS-Client.cs
|
||||
*
|
||||
* Copyright (C) 2006-2023 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL.
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using wolfSSL.CSharp;
|
||||
|
||||
public class wolfSSL_TLS_Client
|
||||
{
|
||||
/// <summary>
|
||||
/// Example of a logging function
|
||||
/// </summary>
|
||||
/// <param name="lvl">level of log</param>
|
||||
/// <param name="msg">message to log</param>
|
||||
public static void standard_log(int lvl, StringBuilder msg)
|
||||
{
|
||||
Console.WriteLine(msg);
|
||||
}
|
||||
|
||||
|
||||
private static void clean(IntPtr ssl, IntPtr ctx)
|
||||
{
|
||||
wolfssl.free(ssl);
|
||||
wolfssl.CTX_free(ctx);
|
||||
wolfssl.Cleanup();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verification callback
|
||||
/// </summary>
|
||||
/// <param name="preverify">1=Verify Okay, 0=Failure</param>
|
||||
/// <param name="x509_ctx">Certificate in WOLFSSL_X509_STORE_CTX format</param>
|
||||
private static int myVerify(int preverify, IntPtr x509_ctx)
|
||||
{
|
||||
/* Use the provided verification */
|
||||
/* Can optionally override failures by returning non-zero value */
|
||||
return preverify;
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
IntPtr ctx;
|
||||
IntPtr ssl;
|
||||
Socket tcp;
|
||||
|
||||
/* These paths should be changed for use */
|
||||
string caCert = @"ca-cert.pem";
|
||||
StringBuilder dhparam = new StringBuilder("dh2048.pem");
|
||||
|
||||
StringBuilder buff = new StringBuilder(1024);
|
||||
StringBuilder reply = new StringBuilder("Hello, this is the wolfSSL C# wrapper");
|
||||
|
||||
//example of function used for setting logging
|
||||
wolfssl.SetLogging(standard_log);
|
||||
|
||||
wolfssl.Init();
|
||||
|
||||
|
||||
Console.WriteLine("Calling ctx Init from wolfSSL");
|
||||
ctx = wolfssl.CTX_new(wolfssl.usev23_client());
|
||||
if (ctx == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Error in creating ctx structure");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("Finished init of ctx .... now load in CA");
|
||||
|
||||
|
||||
if (!File.Exists(caCert))
|
||||
{
|
||||
Console.WriteLine("Could not find CA cert file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (wolfssl.CTX_load_verify_locations(ctx, caCert, null)
|
||||
!= wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error loading CA cert");
|
||||
}
|
||||
|
||||
StringBuilder ciphers = new StringBuilder(new String(' ', 4096));
|
||||
wolfssl.get_ciphers(ciphers, 4096);
|
||||
Console.WriteLine("Ciphers : " + ciphers.ToString());
|
||||
|
||||
/* Uncomment Section to enable specific cipher suite */
|
||||
#if false
|
||||
ciphers = new StringBuilder("ECDHE-ECDSA-AES128-GCM-SHA256");
|
||||
if (wolfssl.CTX_set_cipher_list(ctx, ciphers) != wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("ERROR CTX_set_cipher_list()");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
short minDhKey = 128;
|
||||
wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey);
|
||||
|
||||
/* Setup Verify Callback */
|
||||
if (wolfssl.CTX_set_verify(ctx, wolfssl.SSL_VERIFY_PEER, myVerify)
|
||||
!= wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error setting verify callback!");
|
||||
}
|
||||
|
||||
|
||||
/* set up TCP socket */
|
||||
tcp = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
|
||||
ProtocolType.Tcp);
|
||||
try
|
||||
{
|
||||
tcp.Connect("localhost", 11111);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("tcp.Connect() error " + e.ToString());
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
if (!tcp.Connected)
|
||||
{
|
||||
Console.WriteLine("tcp.Connect() failed!");
|
||||
tcp.Close();
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Connected TCP");
|
||||
ssl = wolfssl.new_ssl(ctx);
|
||||
if (ssl == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Error in creating ssl object");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Connection made wolfSSL_connect ");
|
||||
if (wolfssl.set_fd(ssl, tcp) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM);
|
||||
|
||||
if (wolfssl.connect(ssl) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* print out results of TLS/SSL accept */
|
||||
Console.WriteLine("SSL version is " + wolfssl.get_version(ssl));
|
||||
Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl));
|
||||
|
||||
|
||||
if (wolfssl.write(ssl, reply, reply.Length) != reply.Length)
|
||||
{
|
||||
Console.WriteLine("Error in write");
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* read and print out the message then reply */
|
||||
if (wolfssl.read(ssl, buff, 1023) < 0)
|
||||
{
|
||||
Console.WriteLine("Error in read");
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
Console.WriteLine(buff);
|
||||
|
||||
wolfssl.shutdown(ssl);
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,123 +1,123 @@
|
|||
<?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>{B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>wolfSSL_TLS_Client</RootNamespace>
|
||||
<AssemblyName>wolfSSL-TLS-Client</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\DLL Debug\Win32\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>3</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\DLL Release\Win32\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\DLL Debug\x64\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>..\DLL Release\x64</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-TLS-Client.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>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
<?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>{B9DF2972-38F6-4B42-B228-E3C1A47DF8E8}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>wolfSSL_TLS_Client</RootNamespace>
|
||||
<AssemblyName>wolfSSL-TLS-Client</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\DLL Debug\Win32\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>3</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\DLL Release\Win32\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\DLL Debug\x64\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>..\DLL Release\x64</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-TLS-Client.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>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
|
||||
</startup>
|
||||
</configuration>
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("wolfSSL-TLS-PSK-Client")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("wolfSSL")]
|
||||
[assembly: AssemblyProduct("wolfSSL-TLS-PSK-Client")]
|
||||
[assembly: AssemblyCopyright("Copyright wolfSSL 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1de70ade-16d5-4c90-9657-c19c2762bca6")]
|
||||
|
||||
// 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")]
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("wolfSSL-TLS-PSK-Client")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("wolfSSL")]
|
||||
[assembly: AssemblyProduct("wolfSSL-TLS-PSK-Client")]
|
||||
[assembly: AssemblyCopyright("Copyright wolfSSL 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1de70ade-16d5-4c90-9657-c19c2762bca6")]
|
||||
|
||||
// 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")]
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* 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;
|
||||
|
@ -49,13 +49,13 @@ public class wolfSSL_TLS_PSK_Client
|
|||
/// <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)
|
||||
{
|
||||
/* C# client */
|
||||
byte[] id = { 67, 35, 32, 99, 108, 105, 101, 110, 116 };
|
||||
/* C# client */
|
||||
byte[] id = { 67, 35, 32, 99, 108, 105, 101, 110, 116 };
|
||||
if (id_max < 9)
|
||||
return 0;
|
||||
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 */
|
||||
if (max_key < 4)
|
||||
return 0;
|
||||
|
@ -76,9 +76,9 @@ public class wolfSSL_TLS_PSK_Client
|
|||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
IntPtr ctx;
|
||||
IntPtr ssl;
|
||||
Socket tcp;
|
||||
IntPtr ctx;
|
||||
IntPtr ssl;
|
||||
Socket tcp;
|
||||
|
||||
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 */
|
||||
wolfssl.CTX_set_psk_client_callback(ctx, psk_cb);
|
||||
|
||||
/* set up TCP socket */
|
||||
tcp = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
|
||||
ProtocolType.Tcp);
|
||||
try
|
||||
{
|
||||
tcp.Connect("localhost", 11111);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("tcp.Connect() error " + e.ToString());
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
if (!tcp.Connected)
|
||||
{
|
||||
Console.WriteLine("tcp.Connect() failed!");
|
||||
tcp.Close();
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
/* set up TCP socket */
|
||||
tcp = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
|
||||
ProtocolType.Tcp);
|
||||
try
|
||||
{
|
||||
tcp.Connect("localhost", 11111);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("tcp.Connect() error " + e.ToString());
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
if (!tcp.Connected)
|
||||
{
|
||||
Console.WriteLine("tcp.Connect() failed!");
|
||||
tcp.Close();
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Connected TCP");
|
||||
ssl = wolfssl.new_ssl(ctx);
|
||||
if (ssl == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Error in creating ssl object");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.set_fd(ssl, tcp) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("Connected TCP");
|
||||
ssl = wolfssl.new_ssl(ctx);
|
||||
if (ssl == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Error in creating ssl object");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.set_fd(ssl, tcp) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
wolfssl.SetTmpDH_file(ssl, dhparam, wolfssl.SSL_FILETYPE_PEM);
|
||||
|
||||
if (wolfssl.connect(ssl) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* print out results of TLS/SSL accept */
|
||||
Console.WriteLine("SSL version is " + wolfssl.get_version(ssl));
|
||||
Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl));
|
||||
|
||||
|
||||
if (wolfssl.write(ssl, reply, reply.Length) != reply.Length)
|
||||
{
|
||||
Console.WriteLine("Error in write");
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* read and print out the message then reply */
|
||||
if (wolfssl.read(ssl, buff, 1023) < 0)
|
||||
{
|
||||
Console.WriteLine("Error in read");
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
Console.WriteLine(buff);
|
||||
|
||||
wolfssl.shutdown(ssl);
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
if (wolfssl.connect(ssl) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* print out results of TLS/SSL accept */
|
||||
Console.WriteLine("SSL version is " + wolfssl.get_version(ssl));
|
||||
Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl));
|
||||
|
||||
|
||||
if (wolfssl.write(ssl, reply, reply.Length) != reply.Length)
|
||||
{
|
||||
Console.WriteLine("Error in write");
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
/* read and print out the message then reply */
|
||||
if (wolfssl.read(ssl, buff, 1023) < 0)
|
||||
{
|
||||
Console.WriteLine("Error in read");
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
return;
|
||||
}
|
||||
Console.WriteLine(buff);
|
||||
|
||||
wolfssl.shutdown(ssl);
|
||||
tcp.Close();
|
||||
clean(ssl, ctx);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,115 +1,115 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{4F92ECF5-A1D8-4A13-AD0C-6571EB03C01C}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>wolfSSL_TLS_PSK_Client</RootNamespace>
|
||||
<AssemblyName>wolfSSL-TLS-PSK-Client</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\DLL Debug\Win32\</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\Win32\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\DLL Debug\x64\</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>..\DLL Release\x64\</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-TLS-PSK-Client.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>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.8 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{4F92ECF5-A1D8-4A13-AD0C-6571EB03C01C}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>wolfSSL_TLS_PSK_Client</RootNamespace>
|
||||
<AssemblyName>wolfSSL-TLS-PSK-Client</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\DLL Debug\Win32\</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\Win32\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\DLL Debug\x64\</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>..\DLL Release\x64\</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-TLS-PSK-Client.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>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.8">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.8 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -2,7 +2,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
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
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("wolfSSL-TLS-PSK-Server")]
|
||||
|
@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
|
|||
[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
|
||||
// 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)]
|
||||
|
||||
|
@ -25,11 +25,11 @@ using System.Runtime.InteropServices;
|
|||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// 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:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* 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;
|
||||
|
@ -47,12 +47,12 @@ public class wolfSSL_TLS_PSK_Server
|
|||
/// <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
|
||||
/* 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
|
||||
/* 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;
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</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.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -2,7 +2,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
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
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("wolfSSL-TLS-Server")]
|
||||
|
@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
|
|||
[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
|
||||
// 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)]
|
||||
|
||||
|
@ -25,11 +25,11 @@ using System.Runtime.InteropServices;
|
|||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// 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:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
* 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;
|
||||
|
|
|
@ -113,7 +113,7 @@
|
|||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</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.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -1,36 +1,36 @@
|
|||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("wolfSSL-TLS-ServerThreaded")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("wolfSSL")]
|
||||
[assembly: AssemblyProduct("wolfSSL-TLS-ServerThreaded")]
|
||||
[assembly: AssemblyCopyright("Copyright wolfSSL 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("716e8f30-1318-4e3b-b788-d0380b397a4c")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("wolfSSL-TLS-ServerThreaded")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("wolfSSL")]
|
||||
[assembly: AssemblyProduct("wolfSSL-TLS-ServerThreaded")]
|
||||
[assembly: AssemblyCopyright("Copyright wolfSSL 2020")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("716e8f30-1318-4e3b-b788-d0380b397a4c")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.1.0.0")]
|
||||
|
|
|
@ -1,194 +1,194 @@
|
|||
/* wolfSSL-TLS-ServerThreaded.cs
|
||||
*
|
||||
* Copyright (C) 2006-2023 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL.
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
||||
using wolfSSL.CSharp;
|
||||
|
||||
public class wolfSSL_TLS_ServerThread
|
||||
{
|
||||
private IntPtr _ctx;
|
||||
private Socket _fd;
|
||||
|
||||
public wolfSSL_TLS_ServerThread(IntPtr ctx, Socket fd)
|
||||
{
|
||||
_ctx = ctx;
|
||||
_fd = fd;
|
||||
}
|
||||
|
||||
private const int kEchoBufSz = 1024;
|
||||
public void start_client()
|
||||
{
|
||||
StringBuilder buff = new StringBuilder(kEchoBufSz);
|
||||
IntPtr ssl = wolfssl.new_ssl(_ctx);
|
||||
if (ssl == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Error in creating ssl object");
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.set_fd(ssl, _fd) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
_fd.Close();
|
||||
wolfssl.free(ssl);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Starting TLS handshake");
|
||||
if (wolfssl.accept(ssl) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.WriteLine("Failed " + wolfssl.get_error(ssl));
|
||||
_fd.Close();
|
||||
wolfssl.free(ssl);
|
||||
return;
|
||||
}
|
||||
|
||||
/* print out results of TLS/SSL accept */
|
||||
Console.WriteLine("SSL version is " + wolfssl.get_version(ssl));
|
||||
Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl));
|
||||
|
||||
/* echo data until error */
|
||||
while (true)
|
||||
{
|
||||
/* read and print out the message then reply */
|
||||
if (wolfssl.read(ssl, buff, kEchoBufSz-1) < 0)
|
||||
{
|
||||
Console.WriteLine("Error in read");
|
||||
break;
|
||||
}
|
||||
Console.WriteLine(buff);
|
||||
|
||||
if (wolfssl.write(ssl, buff, buff.Length) != buff.Length)
|
||||
{
|
||||
Console.WriteLine("Error in write");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Closing " + wolfssl.get_error(ssl));
|
||||
_fd.Close();
|
||||
wolfssl.free(ssl);
|
||||
}
|
||||
}
|
||||
|
||||
public class wolfSSL_TLS_ServerThreaded
|
||||
{
|
||||
/// <summary>
|
||||
/// Example of a logging function
|
||||
/// </summary>
|
||||
/// <param name="lvl">level of log</param>
|
||||
/// <param name="msg">message to log</param>
|
||||
public static void standard_log(int lvl, StringBuilder msg)
|
||||
{
|
||||
Console.WriteLine(msg);
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
IntPtr ctx;
|
||||
|
||||
/* These paths should be changed for use */
|
||||
string fileCert = @"server-cert.pem";
|
||||
string fileKey = @"server-key.pem";
|
||||
StringBuilder dhparam = new StringBuilder("dh2048.pem");
|
||||
|
||||
/* example of function used for setting logging */
|
||||
wolfssl.SetLogging(standard_log);
|
||||
wolfssl.Init();
|
||||
|
||||
Console.WriteLine("Calling ctx Init from wolfSSL");
|
||||
ctx = wolfssl.CTX_new(wolfssl.usev23_server());
|
||||
if (ctx == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Error in creating ctx structure");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("Finished init of ctx .... now load in cert and key");
|
||||
|
||||
if (!File.Exists(fileCert) || !File.Exists(fileKey))
|
||||
{
|
||||
Console.WriteLine("Could not find cert or key file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error in setting cert file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.CTX_use_PrivateKey_file(ctx, fileKey, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error in setting key file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder ciphers = new StringBuilder(new String(' ', 4096));
|
||||
wolfssl.get_ciphers(ciphers, 4096);
|
||||
Console.WriteLine("Ciphers : " + ciphers.ToString());
|
||||
|
||||
short minDhKey = 128;
|
||||
wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey);
|
||||
wolfssl.CTX_SetTmpDH_file(ctx, dhparam, wolfssl.SSL_FILETYPE_PEM);
|
||||
|
||||
/* set up TCP socket */
|
||||
IPAddress ip = IPAddress.Parse("0.0.0.0"); /* bind to any */
|
||||
TcpListener tcp = new TcpListener(ip, 11111);
|
||||
tcp.Start();
|
||||
|
||||
Console.WriteLine("Started TCP and waiting for a connection");
|
||||
|
||||
while (true) {
|
||||
try
|
||||
{
|
||||
Socket fd = tcp.AcceptSocket();
|
||||
Console.WriteLine("Got client connection");
|
||||
|
||||
/* Spin up thread for client */
|
||||
wolfSSL_TLS_ServerThread thread = new wolfSSL_TLS_ServerThread(ctx, fd);
|
||||
Thread thr = new Thread(new ThreadStart(thread.start_client));
|
||||
thr.Start();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Server Exception " + ex.ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tcp.Stop();
|
||||
wolfssl.CTX_free(ctx);
|
||||
wolfssl.Cleanup();
|
||||
}
|
||||
}
|
||||
/* wolfSSL-TLS-ServerThreaded.cs
|
||||
*
|
||||
* Copyright (C) 2006-2023 wolfSSL Inc.
|
||||
*
|
||||
* This file is part of wolfSSL.
|
||||
*
|
||||
* wolfSSL is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* wolfSSL is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
|
||||
using wolfSSL.CSharp;
|
||||
|
||||
public class wolfSSL_TLS_ServerThread
|
||||
{
|
||||
private IntPtr _ctx;
|
||||
private Socket _fd;
|
||||
|
||||
public wolfSSL_TLS_ServerThread(IntPtr ctx, Socket fd)
|
||||
{
|
||||
_ctx = ctx;
|
||||
_fd = fd;
|
||||
}
|
||||
|
||||
private const int kEchoBufSz = 1024;
|
||||
public void start_client()
|
||||
{
|
||||
StringBuilder buff = new StringBuilder(kEchoBufSz);
|
||||
IntPtr ssl = wolfssl.new_ssl(_ctx);
|
||||
if (ssl == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Error in creating ssl object");
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.set_fd(ssl, _fd) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.WriteLine(wolfssl.get_error(ssl));
|
||||
_fd.Close();
|
||||
wolfssl.free(ssl);
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("Starting TLS handshake");
|
||||
if (wolfssl.accept(ssl) != wolfssl.SUCCESS)
|
||||
{
|
||||
/* get and print out the error */
|
||||
Console.WriteLine("Failed " + wolfssl.get_error(ssl));
|
||||
_fd.Close();
|
||||
wolfssl.free(ssl);
|
||||
return;
|
||||
}
|
||||
|
||||
/* print out results of TLS/SSL accept */
|
||||
Console.WriteLine("SSL version is " + wolfssl.get_version(ssl));
|
||||
Console.WriteLine("SSL cipher suite is " + wolfssl.get_current_cipher(ssl));
|
||||
|
||||
/* echo data until error */
|
||||
while (true)
|
||||
{
|
||||
/* read and print out the message then reply */
|
||||
if (wolfssl.read(ssl, buff, kEchoBufSz-1) < 0)
|
||||
{
|
||||
Console.WriteLine("Error in read");
|
||||
break;
|
||||
}
|
||||
Console.WriteLine(buff);
|
||||
|
||||
if (wolfssl.write(ssl, buff, buff.Length) != buff.Length)
|
||||
{
|
||||
Console.WriteLine("Error in write");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Closing " + wolfssl.get_error(ssl));
|
||||
_fd.Close();
|
||||
wolfssl.free(ssl);
|
||||
}
|
||||
}
|
||||
|
||||
public class wolfSSL_TLS_ServerThreaded
|
||||
{
|
||||
/// <summary>
|
||||
/// Example of a logging function
|
||||
/// </summary>
|
||||
/// <param name="lvl">level of log</param>
|
||||
/// <param name="msg">message to log</param>
|
||||
public static void standard_log(int lvl, StringBuilder msg)
|
||||
{
|
||||
Console.WriteLine(msg);
|
||||
}
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
IntPtr ctx;
|
||||
|
||||
/* These paths should be changed for use */
|
||||
string fileCert = @"server-cert.pem";
|
||||
string fileKey = @"server-key.pem";
|
||||
StringBuilder dhparam = new StringBuilder("dh2048.pem");
|
||||
|
||||
/* example of function used for setting logging */
|
||||
wolfssl.SetLogging(standard_log);
|
||||
wolfssl.Init();
|
||||
|
||||
Console.WriteLine("Calling ctx Init from wolfSSL");
|
||||
ctx = wolfssl.CTX_new(wolfssl.usev23_server());
|
||||
if (ctx == IntPtr.Zero)
|
||||
{
|
||||
Console.WriteLine("Error in creating ctx structure");
|
||||
return;
|
||||
}
|
||||
Console.WriteLine("Finished init of ctx .... now load in cert and key");
|
||||
|
||||
if (!File.Exists(fileCert) || !File.Exists(fileKey))
|
||||
{
|
||||
Console.WriteLine("Could not find cert or key file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.CTX_use_certificate_file(ctx, fileCert, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error in setting cert file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (wolfssl.CTX_use_PrivateKey_file(ctx, fileKey, wolfssl.SSL_FILETYPE_PEM) != wolfssl.SUCCESS)
|
||||
{
|
||||
Console.WriteLine("Error in setting key file");
|
||||
wolfssl.CTX_free(ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
StringBuilder ciphers = new StringBuilder(new String(' ', 4096));
|
||||
wolfssl.get_ciphers(ciphers, 4096);
|
||||
Console.WriteLine("Ciphers : " + ciphers.ToString());
|
||||
|
||||
short minDhKey = 128;
|
||||
wolfssl.CTX_SetMinDhKey_Sz(ctx, minDhKey);
|
||||
wolfssl.CTX_SetTmpDH_file(ctx, dhparam, wolfssl.SSL_FILETYPE_PEM);
|
||||
|
||||
/* set up TCP socket */
|
||||
IPAddress ip = IPAddress.Parse("0.0.0.0"); /* bind to any */
|
||||
TcpListener tcp = new TcpListener(ip, 11111);
|
||||
tcp.Start();
|
||||
|
||||
Console.WriteLine("Started TCP and waiting for a connection");
|
||||
|
||||
while (true) {
|
||||
try
|
||||
{
|
||||
Socket fd = tcp.AcceptSocket();
|
||||
Console.WriteLine("Got client connection");
|
||||
|
||||
/* Spin up thread for client */
|
||||
wolfSSL_TLS_ServerThread thread = new wolfSSL_TLS_ServerThread(ctx, fd);
|
||||
Thread thr = new Thread(new ThreadStart(thread.start_client));
|
||||
thr.Start();
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
Console.WriteLine("Server Exception " + ex.ToString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tcp.Stop();
|
||||
wolfssl.CTX_free(ctx);
|
||||
wolfssl.Cleanup();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,123 +1,123 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>wolfSSL_TLS_ServerThreaded</RootNamespace>
|
||||
<AssemblyName>wolfSSL-TLS-ServerThreaded</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\DLL Debug\Win32\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>3</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\DLL Release\Win32\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\DLL Debug\x64\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>..\DLL Release\x64\</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-TLS-ServerThreaded.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>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{8ABD2E8F-AEE7-40ED-A966-900ACFAE555F}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>wolfSSL_TLS_ServerThreaded</RootNamespace>
|
||||
<AssemblyName>wolfSSL-TLS-ServerThreaded</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\DLL Debug\Win32\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>3</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\DLL Release\Win32\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>..\DLL Debug\x64\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>true</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>..\DLL Release\x64\</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-TLS-ServerThreaded.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>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Microsoft .NET Framework 4.5 %28x86 and x64%29</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
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
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("wolfSSL.CSharp")]
|
||||
|
@ -14,8 +14,8 @@ using System.Runtime.InteropServices;
|
|||
[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
|
||||
// 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)]
|
||||
|
||||
|
@ -25,11 +25,11 @@ using System.Runtime.InteropServices;
|
|||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// 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:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.1.0.0")]
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace wolfSSL.CSharp
|
||||
|
@ -9,21 +9,21 @@ namespace wolfSSL.CSharp
|
|||
{
|
||||
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);
|
||||
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
|
||||
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
|
||||
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);
|
||||
[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);
|
||||
|
||||
|
||||
[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);
|
||||
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
|
||||
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
|
||||
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 IntPtr x509;
|
||||
|
@ -71,74 +71,74 @@ namespace wolfSSL.CSharp
|
|||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Used for getting the public key buffer
|
||||
/// </summary>
|
||||
/// <returns>DER public key on success</returns>
|
||||
public byte[] GetPublicKey()
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for getting the public key buffer
|
||||
/// </summary>
|
||||
/// <returns>DER public key on success</returns>
|
||||
public byte[] GetPublicKey()
|
||||
{
|
||||
if (this.x509 == IntPtr.Zero)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IntPtr bufSz;
|
||||
IntPtr buf;
|
||||
|
||||
int keySz = 0;
|
||||
int ret;
|
||||
byte[] key = null;
|
||||
|
||||
bufSz = Marshal.AllocHGlobal(4); /* pointer to 4 bytes */
|
||||
ret = wolfSSL_X509_get_pubkey_buffer(this.x509, IntPtr.Zero, bufSz);
|
||||
if (ret == wolfssl.SUCCESS)
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IntPtr bufSz;
|
||||
IntPtr buf;
|
||||
|
||||
int keySz = 0;
|
||||
int ret;
|
||||
byte[] key = null;
|
||||
|
||||
bufSz = Marshal.AllocHGlobal(4); /* pointer to 4 bytes */
|
||||
ret = wolfSSL_X509_get_pubkey_buffer(this.x509, IntPtr.Zero, bufSz);
|
||||
if (ret == wolfssl.SUCCESS)
|
||||
{
|
||||
keySz = Marshal.ReadInt32(bufSz, 0);
|
||||
buf = Marshal.AllocHGlobal(keySz);
|
||||
ret = wolfSSL_X509_get_pubkey_buffer(this.x509, buf, bufSz);
|
||||
keySz = Marshal.ReadInt32(bufSz, 0);
|
||||
buf = Marshal.AllocHGlobal(keySz);
|
||||
ret = wolfSSL_X509_get_pubkey_buffer(this.x509, buf, bufSz);
|
||||
if (ret == wolfssl.SUCCESS)
|
||||
{
|
||||
key = new byte[keySz];
|
||||
Marshal.Copy(buf, key, 0, keySz);
|
||||
}
|
||||
Marshal.FreeHGlobal(buf);
|
||||
Marshal.FreeHGlobal(buf);
|
||||
}
|
||||
Marshal.FreeHGlobal(bufSz);
|
||||
return key;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
wolfssl.log(wolfssl.ERROR_LOG, "error getting public key" + e.ToString());
|
||||
return null;
|
||||
}
|
||||
Marshal.FreeHGlobal(bufSz);
|
||||
return key;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
wolfssl.log(wolfssl.ERROR_LOG, "error getting public key" + e.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the X509 buffer
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Gets the X509 buffer
|
||||
/// </summary>
|
||||
/// <returns>X509 buffer on success</returns>
|
||||
public byte[] Export(int type)
|
||||
{
|
||||
if (this.x509 == IntPtr.Zero)
|
||||
return null;
|
||||
try
|
||||
{
|
||||
IntPtr bufSz;
|
||||
IntPtr buf;
|
||||
if (this.x509 == IntPtr.Zero)
|
||||
return null;
|
||||
try
|
||||
{
|
||||
IntPtr bufSz;
|
||||
IntPtr buf;
|
||||
byte[] ret = null;
|
||||
|
||||
bufSz = Marshal.AllocHGlobal(4); /* pointer to 4 bytes */
|
||||
buf = wolfSSL_X509_get_der(this.x509, bufSz);
|
||||
if (buf != IntPtr.Zero)
|
||||
bufSz = Marshal.AllocHGlobal(4); /* pointer to 4 bytes */
|
||||
buf = wolfSSL_X509_get_der(this.x509, bufSz);
|
||||
if (buf != IntPtr.Zero)
|
||||
{
|
||||
int derSz = Marshal.ReadInt32(bufSz, 0);
|
||||
if (type == wolfssl.SSL_FILETYPE_ASN1)
|
||||
{
|
||||
ret = new byte[derSz];
|
||||
Marshal.Copy(buf, ret, 0, derSz);
|
||||
}
|
||||
}
|
||||
else if (type == wolfssl.SSL_FILETYPE_PEM)
|
||||
{
|
||||
int pemSz;
|
||||
|
@ -153,41 +153,41 @@ namespace wolfSSL.CSharp
|
|||
Marshal.FreeHGlobal(pem);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wolfssl.log(wolfssl.ERROR_LOG, "unsupported export type");
|
||||
}
|
||||
Marshal.FreeHGlobal(bufSz);
|
||||
return ret;
|
||||
Marshal.FreeHGlobal(bufSz);
|
||||
return ret;
|
||||
}
|
||||
{
|
||||
wolfssl.log(wolfssl.ERROR_LOG, "unable to get buffer");
|
||||
}
|
||||
Marshal.FreeHGlobal(bufSz);
|
||||
return ret;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
wolfssl.log(wolfssl.ERROR_LOG, "error getting x509 DER" + e.ToString());
|
||||
return null;
|
||||
Marshal.FreeHGlobal(bufSz);
|
||||
return ret;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
wolfssl.log(wolfssl.ERROR_LOG, "error getting x509 DER" + e.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the X509 buffer using this.type set (default PEM)
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// Gets the X509 buffer using this.type set (default PEM)
|
||||
/// </summary>
|
||||
/// <returns>X509 buffer on success</returns>
|
||||
public byte[] Export()
|
||||
{
|
||||
return Export(this.type);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the X509 format
|
||||
/// </summary>
|
||||
/// <returns>X509 format on success</returns>
|
||||
public string GetFormat()
|
||||
/// <summary>
|
||||
/// Gets the X509 format
|
||||
/// </summary>
|
||||
/// <returns>X509 format on success</returns>
|
||||
public string GetFormat()
|
||||
{
|
||||
if (this.type == wolfssl.SSL_FILETYPE_PEM)
|
||||
{
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -72,7 +72,7 @@ xcopy "$(ProjectDir)..\..\..\certs\server-cert.pem" "$(TargetDir)" /Y /R
|
|||
xcopy "$(ProjectDir)..\..\..\certs\dh2048.pem" "$(TargetDir)" /Y /R
|
||||
xcopy "$(ProjectDir)..\..\..\certs\ca-cert.pem" "$(TargetDir)" /Y /R</PreBuildEvent>
|
||||
</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.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
|
|
Loading…
Reference in New Issue