Skip to content

Commit 52f1caf

Browse files
committed
minor changes to the prototypes and actual implementation
1 parent 0956091 commit 52f1caf

1 file changed

Lines changed: 61 additions & 2 deletions

File tree

wrapper/CSharp/wolfSSL_CSharp/wolfSSL.cs

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ private class ctx_handle
5959
private GCHandle rec_cb;
6060
private GCHandle snd_cb;
6161
private GCHandle psk_cb;
62+
private GCHandle sni_cb;
63+
private GCHandle sni_arg;
6264
private GCHandle vrf_cb;
6365
private IntPtr ctx;
6466

@@ -89,6 +91,22 @@ public GCHandle get_psk()
8991
return this.psk_cb;
9092
}
9193

94+
public void set_sni(GCHandle input) {
95+
this.sni_cb = input;
96+
}
97+
98+
public GCHandle get_sni(GCHandle input) {
99+
return this.sni_cb;
100+
}
101+
102+
public void set_arg(GCHandle input) {
103+
this.sni_arg= input;
104+
}
105+
106+
public GCHandle get_arg(GCHandle input) {
107+
return this.sni_arg;
108+
}
109+
92110
public void set_vrf(GCHandle input)
93111
{
94112
if (!Object.Equals(this.vrf_cb, default(GCHandle)))
@@ -144,6 +162,7 @@ private class ssl_handle
144162
{
145163
private GCHandle fd_pin;
146164
private GCHandle psk_cb;
165+
private GCHandle sni_cb;
147166
private GCHandle vrf_cb;
148167
private IntPtr ssl;
149168

@@ -298,9 +317,9 @@ public void free()
298317
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
299318
private extern static void wolfSSL_CTX_set_servername_callback(IntPtr ctx, sni_delegate sni_cb);
300319
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
301-
private extern static void wolfSSL_CTX_set_tlsext_servername_callback(IntPtr ctx, sni_delegate sni_cb);
320+
private extern static int wolfSSL_CTX_set_tlsext_servername_callback(IntPtr ctx, sni_delegate sni_cb);
302321
[DllImport(wolfssl_dll, CallingConvention = CallingConvention.Cdecl)]
303-
private extern static void wolfSSL_CTX_set_servername_arg(IntPtr ctx, IntPtr arg);
322+
private extern static int wolfSSL_CTX_set_servername_arg(IntPtr ctx, IntPtr arg);
304323

305324
/********************************
306325
* SSL Structure
@@ -1095,6 +1114,46 @@ public static void CTX_free(IntPtr ctx)
10951114
}
10961115
}
10971116

1117+
public static void CTX_set_servername_callback(IntPtr ctx, sni_delegate sni_cb) {
1118+
try {
1119+
GCHandle gch = GCHandle.FromIntPtr(ctx);
1120+
ctx_handle handles = (ctx_handle)gch.Target;
1121+
1122+
handles.set_sni(GCHandle.Alloc(sni_cb));
1123+
1124+
wolfSSL_CTX_set_servername_callback(handles.get_ctx(), sni_cb);
1125+
} catch (Exception e) {
1126+
log(ERROR_LOG, "wolfssl servername callback error: " + e.ToString());
1127+
}
1128+
}
1129+
1130+
public static int CTX_set_tlsext_servername_callback(IntPtr ctx, sni_delegate sni_cb) {
1131+
try {
1132+
GCHandle gch = GCHandle.FromIntPtr(ctx);
1133+
ctx_handle handles = (ctx_handle)gch.Target;
1134+
1135+
handles.set_sni(GCHandle.Alloc(sni_cb));
1136+
1137+
return wolfSSL_CTX_set_tlsext_servername_callback(handles.get_ctx(), sni_cb);
1138+
} catch (Exception e) {
1139+
log(ERROR_LOG, "wolfssl tlsext servername callback error: " + e.ToString());
1140+
return FAILURE;
1141+
}
1142+
}
1143+
1144+
public static int CTX_set_servername_arg(IntPtr ctx, IntPtr arg) {
1145+
try {
1146+
GCHandle gch = GCHandle.FromIntPtr(ctx);
1147+
ctx_handle handles = (ctx_handle)gch.Target;
1148+
1149+
handles.set_arg(GCHandle.Alloc(arg));
1150+
1151+
return wolfSSL_CTX_set_servername_arg(handles.get_ctx(), arg);
1152+
} catch (Exception e) {
1153+
log(ERROR_LOG, "wolfssl arg servername callback error: " + e.ToString());
1154+
return FAILURE;
1155+
}
1156+
}
10981157

10991158
/// <summary>
11001159
/// Set identity hint to use

0 commit comments

Comments
 (0)