Skip to content

Commit f231c7b

Browse files
committed
updated the README & haveSNI function
1 parent 70fc5c9 commit f231c7b

2 files changed

Lines changed: 34 additions & 11 deletions

File tree

wrapper/CSharp/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,14 @@ mono client.exe
7878

7979
### Enabling SNI
8080

81-
To enable SNI, just pass the `-S` argument with the specified hostname:
81+
To enable SNI, just pass the `-S` argument with the specified hostname to the client:
8282

8383
```
8484
mono client.exe -S hostname
8585
```
86+
87+
And run the server with the `-S` flag:
88+
89+
```
90+
mono server.exe -S
91+
```

wrapper/CSharp/wolfSSL-TLS-Client/wolfSSL-TLS-Client.cs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,30 @@ private static int myVerify(int preverify, IntPtr x509_ctx)
6565
/// wolfSSL.
6666
/// <param name="args">Parameters passed via command line</param>
6767
/// </summary>
68-
private static bool haveSNI(string[] args)
68+
private static int haveSNI(string[] args)
6969
{
70-
bool sniON = false;
7170
for (int i = 0; i < args.Length; i++) {
7271
if (args[i] == "-S") {
73-
sniON = true;
74-
break;
72+
Console.WriteLine("SNI IS ON");
73+
return i+1;
7574
}
7675
}
77-
Console.WriteLine("SNI IS: " + sniON);
78-
return sniON;
76+
Console.WriteLine("SNI IS OFF");
77+
return -1;
7978
}
8079

81-
80+
public static string setPath() {
81+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
82+
{
83+
return @"../../certs/ca-cert.pem";
84+
} else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
85+
{
86+
return @"../../../../certs/ca-cert.pem";
87+
} else
88+
{
89+
return "";
90+
}
91+
}
8292

8393
public static void Main(string[] args)
8494
{
@@ -88,7 +98,12 @@ public static void Main(string[] args)
8898
IntPtr sniHostName;
8999

90100
/* These paths should be changed for use */
91-
string caCert = @"../../certs/ca-cert.pem";
101+
string caCert = setPath();
102+
if (caCert == "") {
103+
Console.WriteLine("Platform not supported.");
104+
return;
105+
}
106+
92107
StringBuilder dhparam = new StringBuilder("dh2048.pem");
93108

94109
StringBuilder buff = new StringBuilder(1024);
@@ -108,6 +123,7 @@ public static void Main(string[] args)
108123
}
109124
Console.WriteLine("Finished init of ctx .... now load in CA");
110125

126+
111127
if (!File.Exists(caCert))
112128
{
113129
Console.WriteLine("Could not find CA cert file");
@@ -123,9 +139,10 @@ public static void Main(string[] args)
123139
return;
124140
}
125141

126-
if (haveSNI(args))
142+
int sniArg = haveSNI(args);
143+
if (sniArg >= 0)
127144
{
128-
string sniHostNameString = args[1].Trim();
145+
string sniHostNameString = args[sniArg].Trim();
129146
sniHostName = Marshal.StringToHGlobalAnsi(sniHostNameString);
130147

131148
ushort size = (ushort)sniHostNameString.Length;

0 commit comments

Comments
 (0)