updated the README & haveSNI function

pull/7610/head
gasbytes 2024-06-04 23:08:56 +02:00
parent 70fc5c97fb
commit f231c7be03
2 changed files with 34 additions and 11 deletions

View File

@ -78,8 +78,14 @@ mono client.exe
### Enabling SNI ### 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 mono client.exe -S hostname
``` ```
And run the server with the `-S` flag:
```
mono server.exe -S
```

View File

@ -65,20 +65,30 @@ public class wolfSSL_TLS_Client
/// wolfSSL. /// wolfSSL.
/// <param name="args">Parameters passed via command line</param> /// <param name="args">Parameters passed via command line</param>
/// </summary> /// </summary>
private static bool haveSNI(string[] args) private static int haveSNI(string[] args)
{ {
bool sniON = false;
for (int i = 0; i < args.Length; i++) { for (int i = 0; i < args.Length; i++) {
if (args[i] == "-S") { if (args[i] == "-S") {
sniON = true; Console.WriteLine("SNI IS ON");
break; return i+1;
} }
} }
Console.WriteLine("SNI IS: " + sniON); Console.WriteLine("SNI IS OFF");
return sniON; 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) public static void Main(string[] args)
{ {
@ -88,7 +98,12 @@ public class wolfSSL_TLS_Client
IntPtr sniHostName; IntPtr sniHostName;
/* These paths should be changed for use */ /* 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 dhparam = new StringBuilder("dh2048.pem");
StringBuilder buff = new StringBuilder(1024); StringBuilder buff = new StringBuilder(1024);
@ -108,6 +123,7 @@ public class wolfSSL_TLS_Client
} }
Console.WriteLine("Finished init of ctx .... now load in CA"); Console.WriteLine("Finished init of ctx .... now load in CA");
if (!File.Exists(caCert)) if (!File.Exists(caCert))
{ {
Console.WriteLine("Could not find CA cert file"); Console.WriteLine("Could not find CA cert file");
@ -123,9 +139,10 @@ public class wolfSSL_TLS_Client
return; 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); sniHostName = Marshal.StringToHGlobalAnsi(sniHostNameString);
ushort size = (ushort)sniHostNameString.Length; ushort size = (ushort)sniHostNameString.Length;