From f231c7be0374b4920548e3a79b18faf9ebbe34d6 Mon Sep 17 00:00:00 2001 From: gasbytes Date: Tue, 4 Jun 2024 23:08:56 +0200 Subject: [PATCH] updated the README & haveSNI function --- wrapper/CSharp/README.md | 8 +++- .../wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs | 37 ++++++++++++++----- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/wrapper/CSharp/README.md b/wrapper/CSharp/README.md index 1d70ba939..4a2c1455e 100644 --- a/wrapper/CSharp/README.md +++ b/wrapper/CSharp/README.md @@ -78,8 +78,14 @@ mono client.exe ### Enabling SNI -To enable SNI, just pass the `-S` argument with the specified hostname: +To enable SNI, just pass the `-S` argument with the specified hostname to the client: ``` mono client.exe -S hostname ``` + +And run the server with the `-S` flag: + +``` +mono server.exe -S +``` diff --git a/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs index 3086c3cae..fde1026bc 100644 --- a/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs +++ b/wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs @@ -65,20 +65,30 @@ public class wolfSSL_TLS_Client /// wolfSSL. /// Parameters passed via command line /// - private static bool haveSNI(string[] args) + private static int haveSNI(string[] args) { - bool sniON = false; for (int i = 0; i < args.Length; i++) { if (args[i] == "-S") { - sniON = true; - break; + Console.WriteLine("SNI IS ON"); + return i+1; } } - Console.WriteLine("SNI IS: " + sniON); - return sniON; + Console.WriteLine("SNI IS OFF"); + return -1; } - + public static string setPath() { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return @"../../certs/ca-cert.pem"; + } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return @"../../../../certs/ca-cert.pem"; + } else + { + return ""; + } + } public static void Main(string[] args) { @@ -88,7 +98,12 @@ public class wolfSSL_TLS_Client IntPtr sniHostName; /* These paths should be changed for use */ - string caCert = @"../../certs/ca-cert.pem"; + string caCert = setPath(); + if (caCert == "") { + Console.WriteLine("Platform not supported."); + return; + } + StringBuilder dhparam = new StringBuilder("dh2048.pem"); StringBuilder buff = new StringBuilder(1024); @@ -108,6 +123,7 @@ public class wolfSSL_TLS_Client } Console.WriteLine("Finished init of ctx .... now load in CA"); + if (!File.Exists(caCert)) { Console.WriteLine("Could not find CA cert file"); @@ -123,9 +139,10 @@ public class wolfSSL_TLS_Client return; } - if (haveSNI(args)) + int sniArg = haveSNI(args); + if (sniArg >= 0) { - string sniHostNameString = args[1].Trim(); + string sniHostNameString = args[sniArg].Trim(); sniHostName = Marshal.StringToHGlobalAnsi(sniHostNameString); ushort size = (ushort)sniHostNameString.Length;